2 * Printer routines for the CUPS scheduler.
4 * Copyright 2007-2017 by Apple Inc.
5 * Copyright 1997-2007 by Easy Software Products, all rights reserved.
7 * These coded instructions, statements, and computer programs are the
8 * property of Apple Inc. and are protected by Federal copyright
9 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
10 * which should have been included with this file. If this file is
11 * missing or damaged, see the license at "http://www.cups.org/".
15 * Include necessary headers...
20 #ifdef HAVE_APPLICATIONSERVICES_H
21 # include <ApplicationServices/ApplicationServices.h>
22 #endif /* HAVE_APPLICATIONSERVICES_H */
23 #ifdef HAVE_SYS_MOUNT_H
24 # include <sys/mount.h>
25 #endif /* HAVE_SYS_MOUNT_H */
26 #ifdef HAVE_SYS_STATVFS_H
27 # include <sys/statvfs.h>
28 #elif defined(HAVE_SYS_STATFS_H)
29 # include <sys/statfs.h>
30 #endif /* HAVE_SYS_STATVFS_H */
33 #endif /* HAVE_SYS_VFS_H */
36 #endif /* __APPLE__ */
43 static void add_printer_defaults(cupsd_printer_t
*p
);
44 static void add_printer_filter(cupsd_printer_t
*p
, mime_type_t
*type
,
46 static void add_printer_formats(cupsd_printer_t
*p
);
47 static int compare_printers(void *first
, void *second
, void *data
);
48 static void delete_printer_filters(cupsd_printer_t
*p
);
49 static void dirty_printer(cupsd_printer_t
*p
);
50 static void load_ppd(cupsd_printer_t
*p
);
51 static ipp_t
*new_media_col(pwg_size_t
*size
, const char *source
,
53 static void write_xml_string(cups_file_t
*fp
, const char *s
);
57 * 'cupsdAddPrinter()' - Add a printer to the system.
60 cupsd_printer_t
* /* O - New printer */
61 cupsdAddPrinter(const char *name
) /* I - Name of printer */
63 cupsd_printer_t
*p
; /* New printer */
64 char uri
[1024], /* Printer URI */
65 uuid
[64]; /* Printer UUID */
69 * Range check input...
72 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdAddPrinter(\"%s\")", name
);
75 * Create a new printer entity...
78 if ((p
= calloc(1, sizeof(cupsd_printer_t
))) == NULL
)
80 cupsdLogMessage(CUPSD_LOG_CRIT
, "Unable to allocate memory for printer - %s",
85 _cupsRWInit(&p
->lock
);
87 cupsdSetString(&p
->name
, name
);
88 cupsdSetString(&p
->info
, name
);
89 cupsdSetString(&p
->hostname
, ServerName
);
91 httpAssembleURIf(HTTP_URI_CODING_ALL
, uri
, sizeof(uri
), "ipp", NULL
,
92 ServerName
, RemotePort
, "/printers/%s", name
);
93 cupsdSetString(&p
->uri
, uri
);
94 cupsdSetString(&p
->uuid
, httpAssembleUUID(ServerName
, RemotePort
, name
, 0,
96 cupsdSetDeviceURI(p
, "file:///dev/null");
98 p
->config_time
= time(NULL
);
99 p
->state
= IPP_PRINTER_STOPPED
;
100 p
->state_time
= time(NULL
);
102 p
->shared
= DefaultShared
;
103 p
->filetype
= mimeAddType(MimeDatabase
, "printer", name
);
105 cupsdSetString(&p
->job_sheets
[0], "none");
106 cupsdSetString(&p
->job_sheets
[1], "none");
108 cupsdSetString(&p
->error_policy
, ErrorPolicy
);
109 cupsdSetString(&p
->op_policy
, DefaultPolicy
);
111 p
->op_policy_ptr
= DefaultPolicyPtr
;
114 * Insert the printer in the printer list alphabetically...
118 Printers
= cupsArrayNew(compare_printers
, NULL
);
120 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
121 "cupsdAddPrinter: Adding %s to Printers", p
->name
);
122 cupsArrayAdd(Printers
, p
);
125 * Return the new printer...
133 * 'cupsdCreateCommonData()' - Create the common printer data.
137 cupsdCreateCommonData(void)
139 int i
; /* Looping var */
140 ipp_attribute_t
*attr
; /* Attribute data */
141 cups_dir_t
*dir
; /* Notifier directory */
142 cups_dentry_t
*dent
; /* Notifier directory entry */
143 cups_array_t
*notifiers
; /* Notifier array */
144 char filename
[1024], /* Filename */
145 *notifier
; /* Current notifier */
146 cupsd_policy_t
*p
; /* Current policy */
147 int k_supported
; /* Maximum file size supported */
149 struct statvfs spoolinfo
; /* FS info for spool directory */
150 double spoolsize
; /* FS size */
151 #elif defined(HAVE_STATFS)
152 struct statfs spoolinfo
; /* FS info for spool directory */
153 double spoolsize
; /* FS size */
154 #endif /* HAVE_STATVFS */
155 static const int nups
[] = /* number-up-supported values */
156 { 1, 2, 4, 6, 9, 16 };
157 static const int orients
[4] =/* orientation-requested-supported values */
161 IPP_REVERSE_LANDSCAPE
,
164 static const char * const holds
[] = /* job-hold-until-supported values */
175 static const char * const features
[] =/* ipp-features-supported values */
177 "subscription-object"
179 static const char * const versions
[] =/* ipp-versions-supported values */
186 static const int ops
[] = /* operations-supported values */
191 IPP_OP_SEND_DOCUMENT
,
193 IPP_OP_GET_JOB_ATTRIBUTES
,
195 IPP_OP_GET_PRINTER_ATTRIBUTES
,
198 IPP_OP_PAUSE_PRINTER
,
199 IPP_OP_RESUME_PRINTER
,
201 IPP_OP_SET_PRINTER_ATTRIBUTES
,
202 IPP_OP_SET_JOB_ATTRIBUTES
,
203 IPP_OP_GET_PRINTER_SUPPORTED_VALUES
,
204 IPP_OP_CREATE_PRINTER_SUBSCRIPTIONS
,
205 IPP_OP_CREATE_JOB_SUBSCRIPTIONS
,
206 IPP_OP_GET_SUBSCRIPTION_ATTRIBUTES
,
207 IPP_OP_GET_SUBSCRIPTIONS
,
208 IPP_OP_RENEW_SUBSCRIPTION
,
209 IPP_OP_CANCEL_SUBSCRIPTION
,
210 IPP_OP_GET_NOTIFICATIONS
,
211 IPP_OP_ENABLE_PRINTER
,
212 IPP_OP_DISABLE_PRINTER
,
213 IPP_OP_HOLD_NEW_JOBS
,
214 IPP_OP_RELEASE_HELD_NEW_JOBS
,
216 IPP_OP_CANCEL_MY_JOBS
,
218 IPP_OP_CUPS_GET_DEFAULT
,
219 IPP_OP_CUPS_GET_PRINTERS
,
220 IPP_OP_CUPS_ADD_MODIFY_PRINTER
,
221 IPP_OP_CUPS_DELETE_PRINTER
,
222 IPP_OP_CUPS_GET_CLASSES
,
223 IPP_OP_CUPS_ADD_MODIFY_CLASS
,
224 IPP_OP_CUPS_DELETE_CLASS
,
225 IPP_OP_CUPS_ACCEPT_JOBS
,
226 IPP_OP_CUPS_REJECT_JOBS
,
227 IPP_OP_CUPS_SET_DEFAULT
,
228 IPP_OP_CUPS_GET_DEVICES
,
229 IPP_OP_CUPS_GET_PPDS
,
230 IPP_OP_CUPS_MOVE_JOB
,
231 IPP_OP_CUPS_AUTHENTICATE_JOB
,
233 IPP_OP_CUPS_GET_DOCUMENT
,
236 static const char * const charsets
[] =/* charset-supported values */
241 static const char * const compressions
[] =
242 { /* document-compression-supported values */
246 #endif /* HAVE_LIBZ */
248 static const char * const media_col_supported
[] =
249 { /* media-col-supported values */
250 "media-bottom-margin",
252 "media-right-margin",
258 static const char * const multiple_document_handling
[] =
259 { /* multiple-document-handling-supported values */
260 "separate-documents-uncollated-copies",
261 "separate-documents-collated-copies"
263 static const char * const notify_attrs
[] =
264 { /* notify-attributes-supported values */
265 "printer-state-change-time",
266 "notify-lease-expiration-time",
267 "notify-subscriber-user-name"
269 static const char * const notify_events
[] =
270 { /* notify-events-supported values */
272 "job-config-changed",
279 "printer-config-changed",
281 "printer-finishings-changed",
282 "printer-media-changed",
286 "printer-state-changed",
293 static const char * const job_creation
[] =
294 { /* job-creation-attributes-supported */
297 "ipp-attribute-fidelity",
304 "multiple-document-handling",
307 "orientation-requested",
311 "printer-resolution",
314 static const char * const job_settable
[] =
315 { /* job-settable-attributes-supported */
323 "multiple-document-handling",
326 "orientation-requested",
330 "printer-resolution",
333 static const char * const pdf_versions
[] =
334 { /* pdf-versions-supported */
345 static const char * const printer_settable
[] =
346 { /* printer-settable-attributes-supported */
347 "printer-geo-location",
350 "printer-organization",
351 "printer-organizational-unit"
353 static const char * const which_jobs
[] =
354 { /* which-jobs-supported values */
368 ippDelete(CommonData
);
370 CommonData
= ippNew();
373 * Get the maximum spool size based on the size of the filesystem used for
374 * the RequestRoot directory. If the host OS doesn't support the statfs call
375 * or the filesystem is larger than 2TiB, always report INT_MAX.
379 if (statvfs(RequestRoot
, &spoolinfo
))
380 k_supported
= INT_MAX
;
381 else if ((spoolsize
= (double)spoolinfo
.f_frsize
* spoolinfo
.f_blocks
/ 1024) >
383 k_supported
= INT_MAX
;
385 k_supported
= (int)spoolsize
;
387 #elif defined(HAVE_STATFS)
388 if (statfs(RequestRoot
, &spoolinfo
))
389 k_supported
= INT_MAX
;
390 else if ((spoolsize
= (double)spoolinfo
.f_bsize
* spoolinfo
.f_blocks
/ 1024) >
392 k_supported
= INT_MAX
;
394 k_supported
= (int)spoolsize
;
397 k_supported
= INT_MAX
;
398 #endif /* HAVE_STATVFS */
401 * This list of attributes is sorted to improve performance when the
402 * client provides a requested-attributes attribute...
405 /* charset-configured */
406 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_CHARSET
| IPP_TAG_COPY
,
407 "charset-configured", NULL
, "utf-8");
409 /* charset-supported */
410 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_CHARSET
| IPP_TAG_COPY
,
411 "charset-supported", sizeof(charsets
) / sizeof(charsets
[0]),
414 /* compression-supported */
415 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
416 "compression-supported",
417 sizeof(compressions
) / sizeof(compressions
[0]),
420 /* copies-supported */
421 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "copies-supported", 1, MaxCopies
);
424 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
| IPP_TAG_COPY
,
425 "cups-version", NULL
, CUPS_SVERSION
+ 6);
427 /* generated-natural-language-supported (no IPP_TAG_COPY) */
428 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_LANGUAGE
,
429 "generated-natural-language-supported", NULL
, DefaultLanguage
);
431 /* ipp-features-supported */
432 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_CONST_TAG(IPP_TAG_KEYWORD
), "ipp-features-supported", sizeof(features
) / sizeof(features
[0]), NULL
, features
);
434 /* ipp-versions-supported */
435 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
436 "ipp-versions-supported", sizeof(versions
) / sizeof(versions
[0]),
439 /* ippget-event-life */
440 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
441 "ippget-event-life", 15);
443 /* job-cancel-after-supported */
444 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "job-cancel-after-supported",
447 /* job-creation-attributes-supported */
448 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
449 "job-creation-attributes-supported",
450 sizeof(job_creation
) / sizeof(job_creation
[0]),
453 /* job-hold-until-supported */
454 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
455 "job-hold-until-supported", sizeof(holds
) / sizeof(holds
[0]),
458 /* job-ids-supported */
459 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
, "job-ids-supported", 1);
461 /* job-k-octets-supported */
462 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "job-k-octets-supported", 0,
465 /* job-priority-supported */
466 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
467 "job-priority-supported", 100);
469 /* job-settable-attributes-supported */
470 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
471 "job-settable-attributes-supported",
472 sizeof(job_settable
) / sizeof(job_settable
[0]),
475 /* job-sheets-supported */
476 if (cupsArrayCount(Banners
) > 0)
479 * Setup the job-sheets-supported attribute...
482 if (Classification
&& !ClassifyOverride
)
483 attr
= ippAddString(CommonData
, IPP_TAG_PRINTER
,
484 IPP_TAG_NAME
| IPP_TAG_COPY
,
485 "job-sheets-supported", NULL
, Classification
);
487 attr
= ippAddStrings(CommonData
, IPP_TAG_PRINTER
,
488 IPP_TAG_NAME
| IPP_TAG_COPY
,
489 "job-sheets-supported", cupsArrayCount(Banners
) + 1,
493 cupsdLogMessage(CUPSD_LOG_EMERG
,
494 "Unable to allocate memory for "
495 "job-sheets-supported attribute: %s!", strerror(errno
));
496 else if (!Classification
|| ClassifyOverride
)
498 cupsd_banner_t
*banner
; /* Current banner */
501 attr
->values
[0].string
.text
= _cupsStrAlloc("none");
503 for (i
= 1, banner
= (cupsd_banner_t
*)cupsArrayFirst(Banners
);
505 i
++, banner
= (cupsd_banner_t
*)cupsArrayNext(Banners
))
506 attr
->values
[i
].string
.text
= banner
->name
;
510 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
511 "job-sheets-supported", NULL
, "none");
513 /* jpeg-k-octets-supported */
514 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "jpeg-k-octets-supported", 0,
517 /* jpeg-x-dimension-supported */
518 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "jpeg-x-dimension-supported", 0,
521 /* jpeg-y-dimension-supported */
522 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "jpeg-y-dimension-supported", 1,
525 /* media-col-supported */
526 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
527 "media-col-supported",
528 sizeof(media_col_supported
) /
529 sizeof(media_col_supported
[0]), NULL
,
530 media_col_supported
);
532 /* multiple-document-handling-supported */
533 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
534 "multiple-document-handling-supported",
535 sizeof(multiple_document_handling
) /
536 sizeof(multiple_document_handling
[0]), NULL
,
537 multiple_document_handling
);
539 /* multiple-document-jobs-supported */
540 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
,
541 "multiple-document-jobs-supported", 1);
543 /* multiple-operation-time-out */
544 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
545 "multiple-operation-time-out", MultipleOperationTimeout
);
547 /* multiple-operation-time-out-action */
548 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_CONST_TAG(IPP_TAG_KEYWORD
), "multiple-operation-time-out-action", NULL
, "process-job");
550 /* natural-language-configured (no IPP_TAG_COPY) */
551 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_LANGUAGE
,
552 "natural-language-configured", NULL
, DefaultLanguage
);
554 /* notify-attributes-supported */
555 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
556 "notify-attributes-supported",
557 (int)(sizeof(notify_attrs
) / sizeof(notify_attrs
[0])),
560 /* notify-lease-duration-supported */
561 ippAddRange(CommonData
, IPP_TAG_PRINTER
,
562 "notify-lease-duration-supported", 0,
563 MaxLeaseDuration
? MaxLeaseDuration
: 2147483647);
565 /* notify-max-events-supported */
566 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
567 "notify-max-events-supported", MaxEvents
);
569 /* notify-events-supported */
570 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
571 "notify-events-supported",
572 (int)(sizeof(notify_events
) / sizeof(notify_events
[0])),
573 NULL
, notify_events
);
575 /* notify-pull-method-supported */
576 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
577 "notify-pull-method-supported", NULL
, "ippget");
579 /* notify-schemes-supported */
580 snprintf(filename
, sizeof(filename
), "%s/notifier", ServerBin
);
581 if ((dir
= cupsDirOpen(filename
)) != NULL
)
583 notifiers
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
585 while ((dent
= cupsDirRead(dir
)) != NULL
)
586 if (S_ISREG(dent
->fileinfo
.st_mode
) &&
587 (dent
->fileinfo
.st_mode
& S_IXOTH
) != 0)
588 cupsArrayAdd(notifiers
, _cupsStrAlloc(dent
->filename
));
590 if (cupsArrayCount(notifiers
) > 0)
592 attr
= ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
593 "notify-schemes-supported",
594 cupsArrayCount(notifiers
), NULL
, NULL
);
596 for (i
= 0, notifier
= (char *)cupsArrayFirst(notifiers
);
598 i
++, notifier
= (char *)cupsArrayNext(notifiers
))
599 attr
->values
[i
].string
.text
= notifier
;
602 cupsArrayDelete(notifiers
);
606 /* number-up-supported */
607 ippAddIntegers(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
608 "number-up-supported", sizeof(nups
) / sizeof(nups
[0]), nups
);
610 /* operations-supported */
611 ippAddIntegers(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
612 "operations-supported", sizeof(ops
) / sizeof(ops
[0]), ops
);
614 /* orientation-requested-supported */
615 ippAddIntegers(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
616 "orientation-requested-supported", 4, orients
);
618 /* page-ranges-supported */
619 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
, "page-ranges-supported", 1);
621 /* pdf-k-octets-supported */
622 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "pdf-k-octets-supported", 0,
625 /* pdf-versions-supported */
626 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
627 "pdf-versions-supported",
628 sizeof(pdf_versions
) / sizeof(pdf_versions
[0]), NULL
,
631 /* pdl-override-supported */
632 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
633 "pdl-override-supported", NULL
, "attempted");
635 /* printer-get-attributes-supported */
636 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_CONST_TAG(IPP_TAG_KEYWORD
), "printer-get-attributes-supported", NULL
, "document-format");
638 /* printer-op-policy-supported */
639 attr
= ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
640 "printer-op-policy-supported", cupsArrayCount(Policies
),
642 for (i
= 0, p
= (cupsd_policy_t
*)cupsArrayFirst(Policies
);
644 i
++, p
= (cupsd_policy_t
*)cupsArrayNext(Policies
))
645 attr
->values
[i
].string
.text
= p
->name
;
647 /* printer-settable-attributes-supported */
648 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
649 "printer-settable-attributes-supported",
650 sizeof(printer_settable
) / sizeof(printer_settable
[0]),
651 NULL
, printer_settable
);
653 /* server-is-sharing-printers */
654 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
, "server-is-sharing-printers",
655 BrowseLocalProtocols
!= 0 && Browsing
);
657 /* which-jobs-supported */
658 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
659 "which-jobs-supported",
660 sizeof(which_jobs
) / sizeof(which_jobs
[0]), NULL
, which_jobs
);
665 * 'cupsdDeleteAllPrinters()' - Delete all printers from the system.
669 cupsdDeleteAllPrinters(void)
671 cupsd_printer_t
*p
; /* Pointer to current printer/class */
674 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
676 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
678 p
->op_policy_ptr
= DefaultPolicyPtr
;
679 cupsdDeletePrinter(p
, 0);
685 * 'cupsdDeletePrinter()' - Delete a printer from the system.
688 int /* O - 1 if classes affected, 0 otherwise */
690 cupsd_printer_t
*p
, /* I - Printer to delete */
691 int update
) /* I - Update printers.conf? */
693 int i
, /* Looping var */
694 changed
= 0; /* Class changed? */
697 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdDeletePrinter(p=%p(%s), update=%d)",
701 * Save the current position in the Printers array...
704 cupsArraySave(Printers
);
707 * Stop printing on this printer...
710 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, update
);
712 p
->state
= IPP_PRINTER_STOPPED
; /* Force for browsed printers */
715 cupsdSetJobState(p
->job
, IPP_JOB_PENDING
, CUPSD_JOB_FORCE
,
716 update
? "Job stopped due to printer being deleted." :
720 * Remove the printer from the list...
723 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
724 "cupsdDeletePrinter: Removing %s from Printers", p
->name
);
725 cupsArrayRemove(Printers
, p
);
728 * If p is the default printer, assign a different one...
731 if (p
== DefaultPrinter
)
732 DefaultPrinter
= NULL
;
735 * Remove this printer from any classes...
738 changed
= cupsdDeletePrinterFromClasses(p
);
741 * Deregister from any browse protocols...
744 cupsdDeregisterPrinter(p
, 1);
747 * Remove support files if this is a temporary queue and deregister color
753 char filename
[1024]; /* Script/PPD filename */
756 * Remove any old PPD or script files...
759 snprintf(filename
, sizeof(filename
), "%s/interfaces/%s", ServerRoot
, p
->name
);
761 snprintf(filename
, sizeof(filename
), "%s/interfaces/%s.O", ServerRoot
, p
->name
);
764 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
, p
->name
);
766 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd.O", ServerRoot
, p
->name
);
769 snprintf(filename
, sizeof(filename
), "%s/%s.png", CacheDir
, p
->name
);
772 snprintf(filename
, sizeof(filename
), "%s/%s.data", CacheDir
, p
->name
);
776 * Unregister color profiles...
779 cupsdUnregisterColor(p
);
783 * Free all memory used by the printer...
786 if (p
->printers
!= NULL
)
789 delete_printer_filters(p
);
791 for (i
= 0; i
< p
->num_reasons
; i
++)
792 _cupsStrFree(p
->reasons
[i
]);
795 ippDelete(p
->ppd_attrs
);
797 mimeDeleteType(MimeDatabase
, p
->filetype
);
798 mimeDeleteType(MimeDatabase
, p
->prefiltertype
);
800 cupsdFreeStrings(&(p
->users
));
803 cupsdClearString(&p
->uri
);
804 cupsdClearString(&p
->hostname
);
805 cupsdClearString(&p
->name
);
806 cupsdClearString(&p
->location
);
807 cupsdClearString(&p
->geo_location
);
808 cupsdClearString(&p
->make_model
);
809 cupsdClearString(&p
->info
);
810 cupsdClearString(&p
->job_sheets
[0]);
811 cupsdClearString(&p
->job_sheets
[1]);
812 cupsdClearString(&p
->device_uri
);
813 cupsdClearString(&p
->sanitized_device_uri
);
814 cupsdClearString(&p
->port_monitor
);
815 cupsdClearString(&p
->op_policy
);
816 cupsdClearString(&p
->error_policy
);
818 cupsdClearString(&p
->alert
);
819 cupsdClearString(&p
->alert_description
);
821 #if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
822 cupsdClearString(&p
->pdl
);
823 cupsdClearString(&p
->reg_name
);
824 #endif /* HAVE_DNSSD || HAVE_AVAHI */
826 cupsArrayDelete(p
->filetypes
);
828 cupsFreeOptions(p
->num_options
, p
->options
);
833 * Restore the previous position in the Printers array...
836 cupsArrayRestore(Printers
);
843 * 'cupsdFindDest()' - Find a destination in the list.
846 cupsd_printer_t
* /* O - Destination in list */
847 cupsdFindDest(const char *name
) /* I - Name of printer or class to find */
849 cupsd_printer_t key
; /* Search key */
852 key
.name
= (char *)name
;
853 return ((cupsd_printer_t
*)cupsArrayFind(Printers
, &key
));
858 * 'cupsdFindPrinter()' - Find a printer in the list.
861 cupsd_printer_t
* /* O - Printer in list */
862 cupsdFindPrinter(const char *name
) /* I - Name of printer to find */
864 cupsd_printer_t
*p
; /* Printer in list */
867 if ((p
= cupsdFindDest(name
)) != NULL
&& (p
->type
& CUPS_PRINTER_CLASS
))
875 * 'cupsdLoadAllPrinters()' - Load printers from the printers.conf file.
879 cupsdLoadAllPrinters(void)
881 int i
; /* Looping var */
882 cups_file_t
*fp
; /* printers.conf file */
883 int linenum
; /* Current line number */
884 char line
[4096], /* Line from file */
885 *value
, /* Pointer to value */
886 *valueptr
; /* Pointer into value */
887 cupsd_printer_t
*p
; /* Current printer */
891 * Open the printers.conf file...
894 snprintf(line
, sizeof(line
), "%s/printers.conf", ServerRoot
);
895 if ((fp
= cupsdOpenConfFile(line
)) == NULL
)
899 * Read printer configurations until we hit EOF...
905 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
908 * Decode the directive...
911 if (!_cups_strcasecmp(line
, "<Printer") ||
912 !_cups_strcasecmp(line
, "<DefaultPrinter"))
915 * <Printer name> or <DefaultPrinter name>
918 if (p
== NULL
&& value
)
921 * Add the printer and a base file type...
924 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Loading printer %s...", value
);
926 p
= cupsdAddPrinter(value
);
928 p
->state
= IPP_PRINTER_IDLE
;
931 * Set the default printer as needed...
934 if (!_cups_strcasecmp(line
, "<DefaultPrinter"))
938 cupsdLogMessage(CUPSD_LOG_ERROR
,
939 "Syntax error on line %d of printers.conf.", linenum
);
941 else if (!_cups_strcasecmp(line
, "</Printer>") || !_cups_strcasecmp(line
, "</DefaultPrinter>"))
946 * Close out the current printer...
949 cupsdSetPrinterAttrs(p
);
951 if (strncmp(p
->device_uri
, "file:", 5) &&
952 p
->state
!= IPP_PRINTER_STOPPED
)
955 * See if the backend exists...
958 snprintf(line
, sizeof(line
), "%s/backend/%s", ServerBin
,
961 if ((valueptr
= strchr(line
+ strlen(ServerBin
), ':')) != NULL
)
962 *valueptr
= '\0'; /* Chop everything but URI scheme */
967 * Backend does not exist, stop printer...
970 p
->state
= IPP_PRINTER_STOPPED
;
971 snprintf(p
->state_message
, sizeof(p
->state_message
),
972 "Backend %s does not exist!", line
);
979 cupsdLogMessage(CUPSD_LOG_ERROR
,
980 "Syntax error on line %d of printers.conf.", linenum
);
984 cupsdLogMessage(CUPSD_LOG_ERROR
,
985 "Syntax error on line %d of printers.conf.", linenum
);
987 else if (!_cups_strcasecmp(line
, "UUID"))
989 if (value
&& !strncmp(value
, "urn:uuid:", 9))
990 cupsdSetString(&(p
->uuid
), value
);
992 cupsdLogMessage(CUPSD_LOG_ERROR
,
993 "Bad UUID on line %d of printers.conf.", linenum
);
995 else if (!_cups_strcasecmp(line
, "AuthInfoRequired"))
997 if (!cupsdSetAuthInfoRequired(p
, value
, NULL
))
998 cupsdLogMessage(CUPSD_LOG_ERROR
,
999 "Bad AuthInfoRequired on line %d of printers.conf.",
1002 else if (!_cups_strcasecmp(line
, "Info"))
1005 cupsdSetString(&p
->info
, value
);
1007 else if (!_cups_strcasecmp(line
, "MakeModel"))
1010 cupsdSetString(&p
->make_model
, value
);
1012 else if (!_cups_strcasecmp(line
, "Location"))
1015 cupsdSetString(&p
->location
, value
);
1017 else if (!_cups_strcasecmp(line
, "GeoLocation"))
1020 cupsdSetString(&p
->geo_location
, value
);
1022 else if (!_cups_strcasecmp(line
, "Organization"))
1025 cupsdSetString(&p
->organization
, value
);
1027 else if (!_cups_strcasecmp(line
, "OrganizationalUnit"))
1030 cupsdSetString(&p
->organizational_unit
, value
);
1032 else if (!_cups_strcasecmp(line
, "DeviceURI"))
1035 cupsdSetDeviceURI(p
, value
);
1037 cupsdLogMessage(CUPSD_LOG_ERROR
,
1038 "Syntax error on line %d of printers.conf.", linenum
);
1040 else if (!_cups_strcasecmp(line
, "Option") && value
)
1046 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1049 cupsdLogMessage(CUPSD_LOG_ERROR
,
1050 "Syntax error on line %d of printers.conf.", linenum
);
1053 for (; *valueptr
&& isspace(*valueptr
& 255); *valueptr
++ = '\0');
1055 p
->num_options
= cupsAddOption(value
, valueptr
, p
->num_options
,
1059 else if (!_cups_strcasecmp(line
, "PortMonitor"))
1061 if (value
&& strcmp(value
, "none"))
1062 cupsdSetString(&p
->port_monitor
, value
);
1064 cupsdClearString(&p
->port_monitor
);
1066 cupsdLogMessage(CUPSD_LOG_ERROR
,
1067 "Syntax error on line %d of printers.conf.", linenum
);
1069 else if (!_cups_strcasecmp(line
, "Reason"))
1072 strcmp(value
, "connecting-to-device") &&
1073 strcmp(value
, "cups-insecure-filter-warning") &&
1074 strcmp(value
, "cups-missing-filter-warning"))
1076 for (i
= 0 ; i
< p
->num_reasons
; i
++)
1077 if (!strcmp(value
, p
->reasons
[i
]))
1080 if (i
>= p
->num_reasons
&&
1081 p
->num_reasons
< (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
1083 p
->reasons
[p
->num_reasons
] = _cupsStrAlloc(value
);
1088 cupsdLogMessage(CUPSD_LOG_ERROR
,
1089 "Syntax error on line %d of printers.conf.", linenum
);
1091 else if (!_cups_strcasecmp(line
, "State"))
1094 * Set the initial queue state...
1097 if (value
&& !_cups_strcasecmp(value
, "idle"))
1098 p
->state
= IPP_PRINTER_IDLE
;
1099 else if (value
&& !_cups_strcasecmp(value
, "stopped"))
1101 p
->state
= IPP_PRINTER_STOPPED
;
1103 for (i
= 0 ; i
< p
->num_reasons
; i
++)
1104 if (!strcmp("paused", p
->reasons
[i
]))
1107 if (i
>= p
->num_reasons
&&
1108 p
->num_reasons
< (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
1110 p
->reasons
[p
->num_reasons
] = _cupsStrAlloc("paused");
1115 cupsdLogMessage(CUPSD_LOG_ERROR
,
1116 "Syntax error on line %d of printers.conf.", linenum
);
1118 else if (!_cups_strcasecmp(line
, "StateMessage"))
1121 * Set the initial queue state message...
1125 strlcpy(p
->state_message
, value
, sizeof(p
->state_message
));
1127 else if (!_cups_strcasecmp(line
, "StateTime"))
1130 * Set the state time...
1134 p
->state_time
= atoi(value
);
1136 else if (!_cups_strcasecmp(line
, "ConfigTime"))
1139 * Set the config time...
1143 p
->config_time
= atoi(value
);
1145 else if (!_cups_strcasecmp(line
, "Accepting"))
1148 * Set the initial accepting state...
1152 (!_cups_strcasecmp(value
, "yes") ||
1153 !_cups_strcasecmp(value
, "on") ||
1154 !_cups_strcasecmp(value
, "true")))
1157 (!_cups_strcasecmp(value
, "no") ||
1158 !_cups_strcasecmp(value
, "off") ||
1159 !_cups_strcasecmp(value
, "false")))
1162 cupsdLogMessage(CUPSD_LOG_ERROR
,
1163 "Syntax error on line %d of printers.conf.", linenum
);
1165 else if (!_cups_strcasecmp(line
, "Type"))
1168 p
->type
= (cups_ptype_t
)atoi(value
);
1170 cupsdLogMessage(CUPSD_LOG_ERROR
,
1171 "Syntax error on line %d of printers.conf.", linenum
);
1173 else if (!_cups_strcasecmp(line
, "Shared"))
1176 * Set the initial shared state...
1180 (!_cups_strcasecmp(value
, "yes") ||
1181 !_cups_strcasecmp(value
, "on") ||
1182 !_cups_strcasecmp(value
, "true")))
1185 (!_cups_strcasecmp(value
, "no") ||
1186 !_cups_strcasecmp(value
, "off") ||
1187 !_cups_strcasecmp(value
, "false")))
1190 cupsdLogMessage(CUPSD_LOG_ERROR
,
1191 "Syntax error on line %d of printers.conf.", linenum
);
1193 else if (!_cups_strcasecmp(line
, "JobSheets"))
1196 * Set the initial job sheets...
1201 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1206 cupsdSetString(&p
->job_sheets
[0], value
);
1208 while (isspace(*valueptr
& 255))
1213 for (value
= valueptr
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1218 cupsdSetString(&p
->job_sheets
[1], value
);
1222 cupsdLogMessage(CUPSD_LOG_ERROR
,
1223 "Syntax error on line %d of printers.conf.", linenum
);
1225 else if (!_cups_strcasecmp(line
, "AllowUser"))
1230 cupsdAddString(&(p
->users
), value
);
1233 cupsdLogMessage(CUPSD_LOG_ERROR
,
1234 "Syntax error on line %d of printers.conf.", linenum
);
1236 else if (!_cups_strcasecmp(line
, "DenyUser"))
1241 cupsdAddString(&(p
->users
), value
);
1244 cupsdLogMessage(CUPSD_LOG_ERROR
,
1245 "Syntax error on line %d of printers.conf.", linenum
);
1247 else if (!_cups_strcasecmp(line
, "QuotaPeriod"))
1250 p
->quota_period
= atoi(value
);
1252 cupsdLogMessage(CUPSD_LOG_ERROR
,
1253 "Syntax error on line %d of printers.conf.", linenum
);
1255 else if (!_cups_strcasecmp(line
, "PageLimit"))
1258 p
->page_limit
= atoi(value
);
1260 cupsdLogMessage(CUPSD_LOG_ERROR
,
1261 "Syntax error on line %d of printers.conf.", linenum
);
1263 else if (!_cups_strcasecmp(line
, "KLimit"))
1266 p
->k_limit
= atoi(value
);
1268 cupsdLogMessage(CUPSD_LOG_ERROR
,
1269 "Syntax error on line %d of printers.conf.", linenum
);
1271 else if (!_cups_strcasecmp(line
, "OpPolicy"))
1275 cupsd_policy_t
*pol
; /* Policy */
1278 if ((pol
= cupsdFindPolicy(value
)) != NULL
)
1280 cupsdSetString(&p
->op_policy
, value
);
1281 p
->op_policy_ptr
= pol
;
1284 cupsdLogMessage(CUPSD_LOG_ERROR
,
1285 "Bad policy \"%s\" on line %d of printers.conf",
1289 cupsdLogMessage(CUPSD_LOG_ERROR
,
1290 "Syntax error on line %d of printers.conf.", linenum
);
1292 else if (!_cups_strcasecmp(line
, "ErrorPolicy"))
1296 if (strcmp(value
, "retry-current-job") &&
1297 strcmp(value
, "abort-job") &&
1298 strcmp(value
, "retry-job") &&
1299 strcmp(value
, "stop-printer"))
1300 cupsdLogMessage(CUPSD_LOG_ALERT
, "Invalid ErrorPolicy \"%s\" on line %d or printers.conf.", ErrorPolicy
, linenum
);
1302 cupsdSetString(&p
->error_policy
, value
);
1305 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d of printers.conf.", linenum
);
1307 else if (!_cups_strcasecmp(line
, "Attribute") && value
)
1309 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1312 cupsdLogMessage(CUPSD_LOG_ERROR
,
1313 "Syntax error on line %d of printers.conf.", linenum
);
1316 for (; *valueptr
&& isspace(*valueptr
& 255); *valueptr
++ = '\0');
1319 cupsdSetPrinterAttrs(p
);
1321 if (!strcmp(value
, "marker-change-time"))
1322 p
->marker_time
= atoi(valueptr
);
1324 cupsdSetPrinterAttr(p
, value
, valueptr
);
1327 else if (_cups_strcasecmp(line
, "Filter") &&
1328 _cups_strcasecmp(line
, "Prefilter") &&
1329 _cups_strcasecmp(line
, "Product"))
1332 * Something else we don't understand (and that wasn't used in a prior
1333 * release of CUPS...
1336 cupsdLogMessage(CUPSD_LOG_ERROR
,
1337 "Unknown configuration directive %s on line %d of "
1338 "printers.conf.", line
, linenum
);
1347 * 'cupsdRenamePrinter()' - Rename a printer.
1352 cupsd_printer_t
*p
, /* I - Printer */
1353 const char *name
) /* I - New name */
1356 * Remove the printer from the array(s) first...
1359 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1360 "cupsdRenamePrinter: Removing %s from Printers", p
->name
);
1361 cupsArrayRemove(Printers
, p
);
1364 * Rename the printer type...
1367 mimeDeleteType(MimeDatabase
, p
->filetype
);
1368 p
->filetype
= mimeAddType(MimeDatabase
, "printer", name
);
1370 if (p
->prefiltertype
)
1372 mimeDeleteType(MimeDatabase
, p
->prefiltertype
);
1373 p
->prefiltertype
= mimeAddType(MimeDatabase
, "prefilter", name
);
1377 * Rename the printer...
1380 cupsdSetString(&p
->name
, name
);
1383 * Reset printer attributes...
1386 cupsdSetPrinterAttrs(p
);
1389 * Add the printer back to the printer array(s)...
1392 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1393 "cupsdRenamePrinter: Adding %s to Printers", p
->name
);
1394 cupsArrayAdd(Printers
, p
);
1399 * 'cupsdSaveAllPrinters()' - Save all printer definitions to the printers.conf
1404 cupsdSaveAllPrinters(void)
1406 int i
; /* Looping var */
1407 cups_file_t
*fp
; /* printers.conf file */
1408 char filename
[1024], /* printers.conf filename */
1409 temp
[1024], /* Temporary string */
1410 value
[2048], /* Value string */
1411 *ptr
, /* Pointer into value */
1412 *name
; /* Current user/group name */
1413 cupsd_printer_t
*printer
; /* Current printer class */
1414 time_t curtime
; /* Current time */
1415 struct tm
*curdate
; /* Current date */
1416 cups_option_t
*option
; /* Current option */
1417 ipp_attribute_t
*marker
; /* Current marker attribute */
1421 * Create the printers.conf file...
1424 snprintf(filename
, sizeof(filename
), "%s/printers.conf", ServerRoot
);
1426 if ((fp
= cupsdCreateConfFile(filename
, ConfigFilePerm
& 0600)) == NULL
)
1429 cupsdLogMessage(CUPSD_LOG_INFO
, "Saving printers.conf...");
1432 * Write a small header to the file...
1435 curtime
= time(NULL
);
1436 curdate
= localtime(&curtime
);
1437 strftime(temp
, sizeof(temp
) - 1, "%Y-%m-%d %H:%M", curdate
);
1439 cupsFilePuts(fp
, "# Printer configuration file for " CUPS_SVERSION
"\n");
1440 cupsFilePrintf(fp
, "# Written by cupsd on %s\n", temp
);
1441 cupsFilePuts(fp
, "# DO NOT EDIT THIS FILE WHEN CUPSD IS RUNNING\n");
1444 * Write each local printer known to the system...
1447 for (printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
1449 printer
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
1452 * Skip printer classes and temporary queues...
1455 if ((printer
->type
& CUPS_PRINTER_CLASS
) || printer
->temporary
)
1459 * Write printers as needed...
1462 if (printer
== DefaultPrinter
)
1463 cupsFilePrintf(fp
, "<DefaultPrinter %s>\n", printer
->name
);
1465 cupsFilePrintf(fp
, "<Printer %s>\n", printer
->name
);
1467 cupsFilePrintf(fp
, "UUID %s\n", printer
->uuid
);
1469 if (printer
->num_auth_info_required
> 0)
1471 switch (printer
->num_auth_info_required
)
1474 strlcpy(value
, printer
->auth_info_required
[0], sizeof(value
));
1478 snprintf(value
, sizeof(value
), "%s,%s",
1479 printer
->auth_info_required
[0],
1480 printer
->auth_info_required
[1]);
1485 snprintf(value
, sizeof(value
), "%s,%s,%s",
1486 printer
->auth_info_required
[0],
1487 printer
->auth_info_required
[1],
1488 printer
->auth_info_required
[2]);
1492 cupsFilePutConf(fp
, "AuthInfoRequired", value
);
1496 cupsFilePutConf(fp
, "Info", printer
->info
);
1498 if (printer
->location
)
1499 cupsFilePutConf(fp
, "Location", printer
->location
);
1501 if (printer
->geo_location
)
1502 cupsFilePutConf(fp
, "GeoLocation", printer
->geo_location
);
1504 if (printer
->make_model
)
1505 cupsFilePutConf(fp
, "MakeModel", printer
->make_model
);
1507 if (printer
->organization
)
1508 cupsFilePutConf(fp
, "Organization", printer
->organization
);
1510 if (printer
->organizational_unit
)
1511 cupsFilePutConf(fp
, "OrganizationalUnit", printer
->organizational_unit
);
1513 cupsFilePutConf(fp
, "DeviceURI", printer
->device_uri
);
1515 if (printer
->port_monitor
)
1516 cupsFilePutConf(fp
, "PortMonitor", printer
->port_monitor
);
1518 if (printer
->state
== IPP_PRINTER_STOPPED
)
1520 cupsFilePuts(fp
, "State Stopped\n");
1522 if (printer
->state_message
[0])
1523 cupsFilePutConf(fp
, "StateMessage", printer
->state_message
);
1526 cupsFilePuts(fp
, "State Idle\n");
1528 cupsFilePrintf(fp
, "StateTime %d\n", (int)printer
->state_time
);
1529 cupsFilePrintf(fp
, "ConfigTime %d\n", (int)printer
->config_time
);
1531 for (i
= 0; i
< printer
->num_reasons
; i
++)
1532 if (strcmp(printer
->reasons
[i
], "connecting-to-device") &&
1533 strcmp(printer
->reasons
[i
], "cups-insecure-filter-warning") &&
1534 strcmp(printer
->reasons
[i
], "cups-missing-filter-warning"))
1535 cupsFilePutConf(fp
, "Reason", printer
->reasons
[i
]);
1537 cupsFilePrintf(fp
, "Type %d\n", printer
->type
);
1539 if (printer
->accepting
)
1540 cupsFilePuts(fp
, "Accepting Yes\n");
1542 cupsFilePuts(fp
, "Accepting No\n");
1544 if (printer
->shared
)
1545 cupsFilePuts(fp
, "Shared Yes\n");
1547 cupsFilePuts(fp
, "Shared No\n");
1549 snprintf(value
, sizeof(value
), "%s %s", printer
->job_sheets
[0],
1550 printer
->job_sheets
[1]);
1551 cupsFilePutConf(fp
, "JobSheets", value
);
1553 cupsFilePrintf(fp
, "QuotaPeriod %d\n", printer
->quota_period
);
1554 cupsFilePrintf(fp
, "PageLimit %d\n", printer
->page_limit
);
1555 cupsFilePrintf(fp
, "KLimit %d\n", printer
->k_limit
);
1557 for (name
= (char *)cupsArrayFirst(printer
->users
);
1559 name
= (char *)cupsArrayNext(printer
->users
))
1560 cupsFilePutConf(fp
, printer
->deny_users
? "DenyUser" : "AllowUser", name
);
1562 if (printer
->op_policy
)
1563 cupsFilePutConf(fp
, "OpPolicy", printer
->op_policy
);
1564 if (printer
->error_policy
)
1565 cupsFilePutConf(fp
, "ErrorPolicy", printer
->error_policy
);
1567 for (i
= printer
->num_options
, option
= printer
->options
;
1571 snprintf(value
, sizeof(value
), "%s %s", option
->name
, option
->value
);
1572 cupsFilePutConf(fp
, "Option", value
);
1575 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-colors",
1576 IPP_TAG_NAME
)) != NULL
)
1578 snprintf(value
, sizeof(value
), "%s ", marker
->name
);
1580 for (i
= 0, ptr
= value
+ strlen(value
);
1581 i
< marker
->num_values
&& ptr
< (value
+ sizeof(value
) - 1);
1587 strlcpy(ptr
, marker
->values
[i
].string
.text
, (size_t)(value
+ sizeof(value
) - ptr
));
1592 cupsFilePutConf(fp
, "Attribute", value
);
1595 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-levels",
1596 IPP_TAG_INTEGER
)) != NULL
)
1598 cupsFilePrintf(fp
, "Attribute %s %d", marker
->name
,
1599 marker
->values
[0].integer
);
1600 for (i
= 1; i
< marker
->num_values
; i
++)
1601 cupsFilePrintf(fp
, ",%d", marker
->values
[i
].integer
);
1602 cupsFilePuts(fp
, "\n");
1605 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-low-levels",
1606 IPP_TAG_INTEGER
)) != NULL
)
1608 cupsFilePrintf(fp
, "Attribute %s %d", marker
->name
,
1609 marker
->values
[0].integer
);
1610 for (i
= 1; i
< marker
->num_values
; i
++)
1611 cupsFilePrintf(fp
, ",%d", marker
->values
[i
].integer
);
1612 cupsFilePuts(fp
, "\n");
1615 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-high-levels",
1616 IPP_TAG_INTEGER
)) != NULL
)
1618 cupsFilePrintf(fp
, "Attribute %s %d", marker
->name
,
1619 marker
->values
[0].integer
);
1620 for (i
= 1; i
< marker
->num_values
; i
++)
1621 cupsFilePrintf(fp
, ",%d", marker
->values
[i
].integer
);
1622 cupsFilePuts(fp
, "\n");
1625 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-message",
1626 IPP_TAG_TEXT
)) != NULL
)
1628 snprintf(value
, sizeof(value
), "%s %s", marker
->name
,
1629 marker
->values
[0].string
.text
);
1631 cupsFilePutConf(fp
, "Attribute", value
);
1634 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-names",
1635 IPP_TAG_NAME
)) != NULL
)
1637 snprintf(value
, sizeof(value
), "%s ", marker
->name
);
1639 for (i
= 0, ptr
= value
+ strlen(value
);
1640 i
< marker
->num_values
&& ptr
< (value
+ sizeof(value
) - 1);
1646 strlcpy(ptr
, marker
->values
[i
].string
.text
, (size_t)(value
+ sizeof(value
) - ptr
));
1651 cupsFilePutConf(fp
, "Attribute", value
);
1654 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-types",
1655 IPP_TAG_KEYWORD
)) != NULL
)
1657 snprintf(value
, sizeof(value
), "%s ", marker
->name
);
1659 for (i
= 0, ptr
= value
+ strlen(value
);
1660 i
< marker
->num_values
&& ptr
< (value
+ sizeof(value
) - 1);
1666 strlcpy(ptr
, marker
->values
[i
].string
.text
, (size_t)(value
+ sizeof(value
) - ptr
));
1671 cupsFilePutConf(fp
, "Attribute", value
);
1674 if (printer
->marker_time
)
1675 cupsFilePrintf(fp
, "Attribute marker-change-time %ld\n",
1676 (long)printer
->marker_time
);
1678 if (printer
== DefaultPrinter
)
1679 cupsFilePuts(fp
, "</DefaultPrinter>\n");
1681 cupsFilePuts(fp
, "</Printer>\n");
1684 cupsdCloseCreatedConfFile(fp
, filename
);
1689 * 'cupsdSetAuthInfoRequired()' - Set the required authentication info.
1692 int /* O - 1 if value OK, 0 otherwise */
1693 cupsdSetAuthInfoRequired(
1694 cupsd_printer_t
*p
, /* I - Printer */
1695 const char *values
, /* I - Plain text value (or NULL) */
1696 ipp_attribute_t
*attr
) /* I - IPP attribute value (or NULL) */
1698 int i
; /* Looping var */
1701 p
->num_auth_info_required
= 0;
1704 * Do we have a plain text value?
1710 * Yes, grab the keywords...
1713 const char *end
; /* End of current value */
1716 while (*values
&& p
->num_auth_info_required
< 4)
1718 if ((end
= strchr(values
, ',')) == NULL
)
1719 end
= values
+ strlen(values
);
1721 if ((end
- values
) == 4 && !strncmp(values
, "none", 4))
1723 if (p
->num_auth_info_required
!= 0 || *end
)
1726 p
->auth_info_required
[p
->num_auth_info_required
] = "none";
1727 p
->num_auth_info_required
++;
1731 else if ((end
- values
) == 9 && !strncmp(values
, "negotiate", 9))
1733 if (p
->num_auth_info_required
!= 0 || *end
)
1736 p
->auth_info_required
[p
->num_auth_info_required
] = "negotiate";
1737 p
->num_auth_info_required
++;
1740 * Don't allow sharing of queues that require Kerberos authentication.
1745 cupsdDeregisterPrinter(p
, 1);
1749 else if ((end
- values
) == 6 && !strncmp(values
, "domain", 6))
1751 p
->auth_info_required
[p
->num_auth_info_required
] = "domain";
1752 p
->num_auth_info_required
++;
1754 else if ((end
- values
) == 8 && !strncmp(values
, "password", 8))
1756 p
->auth_info_required
[p
->num_auth_info_required
] = "password";
1757 p
->num_auth_info_required
++;
1759 else if ((end
- values
) == 8 && !strncmp(values
, "username", 8))
1761 p
->auth_info_required
[p
->num_auth_info_required
] = "username";
1762 p
->num_auth_info_required
++;
1767 values
= (*end
) ? end
+ 1 : end
;
1770 if (p
->num_auth_info_required
== 0)
1772 p
->auth_info_required
[0] = "none";
1773 p
->num_auth_info_required
= 1;
1777 * Update the printer-type value as needed...
1780 if (p
->num_auth_info_required
> 1 ||
1781 strcmp(p
->auth_info_required
[0], "none"))
1782 p
->type
|= CUPS_PRINTER_AUTHENTICATED
;
1784 p
->type
&= (cups_ptype_t
)~CUPS_PRINTER_AUTHENTICATED
;
1790 * Grab values from an attribute instead...
1793 if (!attr
|| attr
->num_values
> 4)
1796 for (i
= 0; i
< attr
->num_values
; i
++)
1798 if (!strcmp(attr
->values
[i
].string
.text
, "none"))
1800 if (p
->num_auth_info_required
!= 0 || attr
->num_values
!= 1)
1803 p
->auth_info_required
[p
->num_auth_info_required
] = "none";
1804 p
->num_auth_info_required
++;
1808 else if (!strcmp(attr
->values
[i
].string
.text
, "negotiate"))
1810 if (p
->num_auth_info_required
!= 0 || attr
->num_values
!= 1)
1813 p
->auth_info_required
[p
->num_auth_info_required
] = "negotiate";
1814 p
->num_auth_info_required
++;
1817 * Don't allow sharing of queues that require Kerberos authentication.
1822 cupsdDeregisterPrinter(p
, 1);
1828 else if (!strcmp(attr
->values
[i
].string
.text
, "domain"))
1830 p
->auth_info_required
[p
->num_auth_info_required
] = "domain";
1831 p
->num_auth_info_required
++;
1833 else if (!strcmp(attr
->values
[i
].string
.text
, "password"))
1835 p
->auth_info_required
[p
->num_auth_info_required
] = "password";
1836 p
->num_auth_info_required
++;
1838 else if (!strcmp(attr
->values
[i
].string
.text
, "username"))
1840 p
->auth_info_required
[p
->num_auth_info_required
] = "username";
1841 p
->num_auth_info_required
++;
1852 * 'cupsdSetDeviceURI()' - Set the device URI for a printer.
1856 cupsdSetDeviceURI(cupsd_printer_t
*p
, /* I - Printer */
1857 const char *uri
) /* I - Device URI */
1859 char buffer
[1024], /* URI buffer */
1860 *start
, /* Start of data after scheme */
1861 *slash
, /* First slash after scheme:// */
1862 *ptr
; /* Pointer into user@host:port part */
1866 * Set the full device URI..
1869 cupsdSetString(&(p
->device_uri
), uri
);
1872 * Copy the device URI to a temporary buffer so we can sanitize any auth
1876 strlcpy(buffer
, uri
, sizeof(buffer
));
1879 * Find the end of the scheme:// part...
1882 if ((ptr
= strchr(buffer
, ':')) != NULL
)
1884 for (start
= ptr
+ 1; *start
; start
++)
1889 * Find the next slash (/) in the URI...
1892 if ((slash
= strchr(start
, '/')) == NULL
)
1893 slash
= start
+ strlen(start
); /* No slash, point to the end */
1896 * Check for an @ sign before the slash...
1899 if ((ptr
= strchr(start
, '@')) != NULL
&& ptr
< slash
)
1902 * Found an @ sign and it is before the resource part, so we have
1903 * an authentication string. Copy the remaining URI over the
1904 * authentication string...
1907 _cups_strcpy(start
, ptr
+ 1);
1912 * Save the sanitized URI...
1915 cupsdSetString(&(p
->sanitized_device_uri
), buffer
);
1920 * 'cupsdSetPrinterAttr()' - Set a printer attribute.
1924 cupsdSetPrinterAttr(
1925 cupsd_printer_t
*p
, /* I - Printer */
1926 const char *name
, /* I - Attribute name */
1927 const char *value
) /* I - Attribute value string */
1929 ipp_attribute_t
*attr
; /* Attribute */
1930 int i
, /* Looping var */
1931 count
; /* Number of values */
1932 char *temp
, /* Temporary copy of value string */
1933 *ptr
, /* Pointer into value */
1934 *start
, /* Start of value */
1935 quote
; /* Quote character */
1936 ipp_tag_t value_tag
; /* Value tag for this attribute */
1940 * Don't allow empty values...
1943 if (!*value
&& strcmp(name
, "marker-message"))
1945 cupsdLogMessage(CUPSD_LOG_ERROR
, "Ignoring empty \"%s\" attribute", name
);
1950 * Copy the value string so we can do what we want with it...
1953 if ((temp
= strdup(value
)) == NULL
)
1955 cupsdLogMessage(CUPSD_LOG_ERROR
,
1956 "Unable to duplicate value for \"%s\" attribute.", name
);
1961 * Count the number of values...
1964 for (count
= 1, quote
= '\0', ptr
= temp
;
1972 else if (*ptr
== '\\' && ptr
[1])
1974 else if (*ptr
== '\'' || *ptr
== '\"')
1976 else if (*ptr
== ',')
1981 * Then add or update the attribute as needed...
1984 if (!strcmp(name
, "marker-levels") || !strcmp(name
, "marker-low-levels") ||
1985 !strcmp(name
, "marker-high-levels"))
1991 if ((attr
= ippFindAttribute(p
->attrs
, name
, IPP_TAG_INTEGER
)) != NULL
&&
1992 attr
->num_values
< count
)
1994 ippDeleteAttribute(p
->attrs
, attr
);
1999 attr
->num_values
= count
;
2001 attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
, name
,
2007 cupsdLogMessage(CUPSD_LOG_ERROR
,
2008 "Unable to allocate memory for printer attribute "
2009 "(%d values)", count
);
2013 for (i
= 0, start
= temp
; i
< count
; i
++)
2015 if ((ptr
= strchr(start
, ',')) != NULL
)
2018 attr
->values
[i
].integer
= strtol(start
, NULL
, 10);
2027 * Name or keyword values...
2030 if (!strcmp(name
, "marker-types"))
2031 value_tag
= IPP_TAG_KEYWORD
;
2032 else if (!strcmp(name
, "marker-message"))
2033 value_tag
= IPP_TAG_TEXT
;
2035 value_tag
= IPP_TAG_NAME
;
2037 if ((attr
= ippFindAttribute(p
->attrs
, name
, value_tag
)) != NULL
&&
2038 attr
->num_values
< count
)
2040 ippDeleteAttribute(p
->attrs
, attr
);
2046 for (i
= 0; i
< attr
->num_values
; i
++)
2047 _cupsStrFree(attr
->values
[i
].string
.text
);
2049 attr
->num_values
= count
;
2052 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, value_tag
, name
,
2058 cupsdLogMessage(CUPSD_LOG_ERROR
,
2059 "Unable to allocate memory for printer attribute "
2060 "(%d values)", count
);
2064 for (i
= 0, quote
= '\0', ptr
= temp
; i
< count
; i
++)
2066 for (start
= ptr
; *ptr
; ptr
++)
2069 *ptr
= quote
= '\0';
2072 else if (*ptr
== '\\' && ptr
[1])
2073 _cups_strcpy(ptr
, ptr
+ 1);
2074 else if (*ptr
== '\'' || *ptr
== '\"')
2081 _cups_strcpy(ptr
, ptr
+ 1);
2083 else if (*ptr
== ',')
2090 attr
->values
[i
].string
.text
= _cupsStrAlloc(start
);
2097 * Update the printer-supply and printer-supply-description, as needed...
2100 if (!strcmp(name
, "marker-names"))
2102 ipp_attribute_t
*supply_desc
= ippFindAttribute(p
->attrs
, "printer-supply-description", IPP_TAG_TEXT
);
2103 /* printer-supply-description attribute */
2105 if (supply_desc
!= NULL
)
2106 ippDeleteAttribute(p
->attrs
, supply_desc
);
2108 supply_desc
= ippCopyAttribute(p
->attrs
, attr
, 0);
2109 ippSetName(p
->attrs
, &supply_desc
, "printer-supply-description");
2110 ippSetValueTag(p
->attrs
, &supply_desc
, IPP_TAG_TEXT
);
2112 else if (!strcmp(name
, "marker-colors") || !strcmp(name
, "marker-levels") || !strcmp(name
, "marker-types"))
2114 char buffer
[256], /* printer-supply values */
2115 pstype
[64], /* printer-supply type value */
2116 *psptr
; /* Pointer into type */
2117 const char *color
, /* marker-colors value */
2118 *type
; /* marker-types value */
2119 int level
; /* marker-levels value */
2120 ipp_attribute_t
*colors
= ippFindAttribute(p
->attrs
, "marker-colors", IPP_TAG_NAME
);
2121 /* marker-colors attribute */
2122 ipp_attribute_t
*levels
= ippFindAttribute(p
->attrs
, "marker-levels", IPP_TAG_INTEGER
);
2123 /* marker-levels attribute */
2124 ipp_attribute_t
*types
= ippFindAttribute(p
->attrs
, "marker-types", IPP_TAG_KEYWORD
);
2125 /* marker-types attribute */
2126 ipp_attribute_t
*supply
= ippFindAttribute(p
->attrs
, "printer-supply", IPP_TAG_STRING
);
2127 /* printer-supply attribute */
2131 ippDeleteAttribute(p
->attrs
, supply
);
2135 if (!colors
|| !levels
|| !types
)
2138 count
= ippGetCount(colors
);
2139 if (count
!= ippGetCount(levels
) || count
!= ippGetCount(types
))
2142 for (i
= 0; i
< count
; i
++)
2144 color
= ippGetString(colors
, i
, NULL
);
2145 level
= ippGetInteger(levels
, i
);
2146 type
= ippGetString(types
, i
, NULL
);
2148 for (psptr
= pstype
; *type
&& psptr
< (pstype
+ sizeof(pstype
) - 1); type
++)
2152 *psptr
++ = (char)toupper(*type
& 255);
2158 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
);
2161 supply
= ippAddOctetString(p
->attrs
, IPP_TAG_PRINTER
, "printer-supply", buffer
, (int)strlen(buffer
));
2163 ippSetOctetString(p
->attrs
, &supply
, i
, buffer
, (int)strlen(buffer
));
2170 * 'cupsdSetPrinterAttrs()' - Set printer attributes based upon the PPD file.
2174 cupsdSetPrinterAttrs(cupsd_printer_t
*p
)/* I - Printer to setup */
2176 int i
; /* Looping var */
2177 char resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
2178 cupsd_location_t
*auth
; /* Pointer to authentication element */
2179 const char *auth_supported
; /* Authentication supported */
2180 ipp_t
*oldattrs
; /* Old printer attributes */
2181 ipp_attribute_t
*attr
; /* Attribute data */
2182 char *name
, /* Current user/group name */
2183 *filter
; /* Current filter */
2186 DEBUG_printf(("cupsdSetPrinterAttrs: entering name = %s, type = %x\n", p
->name
,
2190 * Make sure that we have the common attributes defined...
2194 cupsdCreateCommonData();
2196 _cupsRWLockWrite(&p
->lock
);
2199 * Clear out old filters, if any...
2202 delete_printer_filters(p
);
2205 * Figure out the authentication that is required for the printer.
2208 auth_supported
= "requesting-user-name";
2210 if (p
->type
& CUPS_PRINTER_CLASS
)
2211 snprintf(resource
, sizeof(resource
), "/classes/%s", p
->name
);
2213 snprintf(resource
, sizeof(resource
), "/printers/%s", p
->name
);
2215 if ((auth
= cupsdFindBest(resource
, HTTP_POST
)) == NULL
||
2216 auth
->type
== CUPSD_AUTH_NONE
)
2217 auth
= cupsdFindPolicyOp(p
->op_policy_ptr
, IPP_PRINT_JOB
);
2221 int auth_type
; /* Authentication type */
2224 if ((auth_type
= auth
->type
) == CUPSD_AUTH_DEFAULT
)
2225 auth_type
= cupsdDefaultAuthType();
2227 if (auth_type
== CUPSD_AUTH_BASIC
)
2228 auth_supported
= "basic";
2230 else if (auth_type
== CUPSD_AUTH_NEGOTIATE
)
2231 auth_supported
= "negotiate";
2232 #endif /* HAVE_GSSAPI */
2234 if (auth_type
!= CUPSD_AUTH_NONE
)
2235 p
->type
|= CUPS_PRINTER_AUTHENTICATED
;
2237 p
->type
&= (cups_ptype_t
)~CUPS_PRINTER_AUTHENTICATED
;
2240 p
->type
&= (cups_ptype_t
)~CUPS_PRINTER_AUTHENTICATED
;
2243 * Create the required IPP attributes for a printer...
2246 oldattrs
= p
->attrs
;
2247 p
->attrs
= ippNew();
2249 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2250 "uri-authentication-supported", NULL
, auth_supported
);
2251 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2252 "uri-security-supported", NULL
, "none");
2253 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
, "printer-name", NULL
,
2255 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-location",
2256 NULL
, p
->location
? p
->location
: "");
2257 if (p
->geo_location
)
2258 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "printer-geo-location", NULL
, p
->geo_location
);
2260 ippAddOutOfBand(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_UNKNOWN
, "printer-geo-location");
2261 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-info",
2262 NULL
, p
->info
? p
->info
: "");
2263 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-organization", NULL
, p
->organization
? p
->organization
: "");
2264 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-organizational-unit", NULL
, p
->organizational_unit
? p
->organizational_unit
: "");
2265 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "printer-uuid", NULL
, p
->uuid
);
2267 if (cupsArrayCount(p
->users
) > 0)
2270 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2271 "requesting-user-name-denied",
2272 cupsArrayCount(p
->users
), NULL
, NULL
);
2274 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2275 "requesting-user-name-allowed",
2276 cupsArrayCount(p
->users
), NULL
, NULL
);
2278 for (i
= 0, name
= (char *)cupsArrayFirst(p
->users
);
2280 i
++, name
= (char *)cupsArrayNext(p
->users
))
2281 attr
->values
[i
].string
.text
= _cupsStrAlloc(name
);
2284 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2285 "job-quota-period", p
->quota_period
);
2286 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2287 "job-k-limit", p
->k_limit
);
2288 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2289 "job-page-limit", p
->page_limit
);
2290 if (p
->num_auth_info_required
> 0 && strcmp(p
->auth_info_required
[0], "none"))
2291 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2292 "auth-info-required", p
->num_auth_info_required
, NULL
,
2293 p
->auth_info_required
);
2295 if (cupsArrayCount(Banners
) > 0)
2298 * Setup the job-sheets-default attribute...
2301 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2302 "job-sheets-default", 2, NULL
, NULL
);
2306 attr
->values
[0].string
.text
= _cupsStrAlloc(Classification
?
2307 Classification
: p
->job_sheets
[0]);
2308 attr
->values
[1].string
.text
= _cupsStrAlloc(Classification
?
2309 Classification
: p
->job_sheets
[1]);
2317 * Assign additional attributes depending on whether this is a printer
2321 if (p
->type
& CUPS_PRINTER_CLASS
)
2324 p
->type
&= (cups_ptype_t
)~CUPS_PRINTER_OPTIONS
;
2327 * Add class-specific attributes...
2330 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
2331 "printer-make-and-model", NULL
, "Local Printer Class");
2332 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "device-uri", NULL
,
2333 "file:///dev/null");
2335 if (p
->num_printers
> 0)
2338 * Add a list of member names; URIs are added in copy_printer_attrs...
2341 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2342 "member-names", p
->num_printers
, NULL
, NULL
);
2343 p
->type
|= CUPS_PRINTER_OPTIONS
;
2345 for (i
= 0; i
< p
->num_printers
; i
++)
2348 attr
->values
[i
].string
.text
= _cupsStrAlloc(p
->printers
[i
]->name
);
2350 p
->type
&= (cups_ptype_t
)~CUPS_PRINTER_OPTIONS
| p
->printers
[i
]->type
;
2357 * Add printer-specific attributes...
2360 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "device-uri", NULL
,
2361 p
->sanitized_device_uri
);
2364 * Assign additional attributes from the PPD file (if any)...
2370 * Add filters for printer...
2373 cupsdSetPrinterReasons(p
, "-cups-missing-filter-warning,"
2374 "cups-insecure-filter-warning");
2376 if (p
->pc
&& p
->pc
->filters
)
2378 for (filter
= (char *)cupsArrayFirst(p
->pc
->filters
);
2380 filter
= (char *)cupsArrayNext(p
->pc
->filters
))
2381 add_printer_filter(p
, p
->filetype
, filter
);
2383 else if (!(p
->type
& CUPS_PRINTER_REMOTE
))
2386 * Add a filter from application/vnd.cups-raw to printer/name to
2387 * handle "raw" printing by users.
2390 add_printer_filter(p
, p
->filetype
, "application/vnd.cups-raw 0 -");
2393 * Add a PostScript filter, since this is still possibly PS printer.
2396 add_printer_filter(p
, p
->filetype
,
2397 "application/vnd.cups-postscript 0 -");
2400 if (p
->pc
&& p
->pc
->prefilters
)
2402 if (!p
->prefiltertype
)
2403 p
->prefiltertype
= mimeAddType(MimeDatabase
, "prefilter", p
->name
);
2405 for (filter
= (char *)cupsArrayFirst(p
->pc
->prefilters
);
2407 filter
= (char *)cupsArrayNext(p
->pc
->prefilters
))
2408 add_printer_filter(p
, p
->prefiltertype
, filter
);
2413 * Copy marker attributes as needed...
2418 ipp_attribute_t
*oldattr
; /* Old attribute */
2421 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-colors",
2422 IPP_TAG_NAME
)) != NULL
)
2424 if ((attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2425 "marker-colors", oldattr
->num_values
, NULL
,
2428 for (i
= 0; i
< oldattr
->num_values
; i
++)
2429 attr
->values
[i
].string
.text
=
2430 _cupsStrAlloc(oldattr
->values
[i
].string
.text
);
2434 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-levels",
2435 IPP_TAG_INTEGER
)) != NULL
)
2437 if ((attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2438 "marker-levels", oldattr
->num_values
,
2441 for (i
= 0; i
< oldattr
->num_values
; i
++)
2442 attr
->values
[i
].integer
= oldattr
->values
[i
].integer
;
2446 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-message",
2447 IPP_TAG_TEXT
)) != NULL
)
2448 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "marker-message",
2449 NULL
, oldattr
->values
[0].string
.text
);
2451 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-low-levels",
2452 IPP_TAG_INTEGER
)) != NULL
)
2454 if ((attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2455 "marker-low-levels", oldattr
->num_values
,
2458 for (i
= 0; i
< oldattr
->num_values
; i
++)
2459 attr
->values
[i
].integer
= oldattr
->values
[i
].integer
;
2463 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-high-levels",
2464 IPP_TAG_INTEGER
)) != NULL
)
2466 if ((attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2467 "marker-high-levels", oldattr
->num_values
,
2470 for (i
= 0; i
< oldattr
->num_values
; i
++)
2471 attr
->values
[i
].integer
= oldattr
->values
[i
].integer
;
2475 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-names",
2476 IPP_TAG_NAME
)) != NULL
)
2478 if ((attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2479 "marker-names", oldattr
->num_values
, NULL
,
2482 for (i
= 0; i
< oldattr
->num_values
; i
++)
2483 attr
->values
[i
].string
.text
=
2484 _cupsStrAlloc(oldattr
->values
[i
].string
.text
);
2488 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-types",
2489 IPP_TAG_KEYWORD
)) != NULL
)
2491 if ((attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2492 "marker-types", oldattr
->num_values
, NULL
,
2495 for (i
= 0; i
< oldattr
->num_values
; i
++)
2496 attr
->values
[i
].string
.text
=
2497 _cupsStrAlloc(oldattr
->values
[i
].string
.text
);
2501 ippDelete(oldattrs
);
2505 * Force sharing off for remote queues...
2508 if (p
->type
& CUPS_PRINTER_REMOTE
)
2512 * Populate the document-format-supported attribute...
2515 add_printer_formats(p
);
2517 DEBUG_printf(("cupsdSetPrinterAttrs: leaving name = %s, type = %x\n", p
->name
,
2521 * Add name-default attributes...
2524 add_printer_defaults(p
);
2526 _cupsRWUnlock(&p
->lock
);
2529 * Let the browse protocols reflect the change
2532 cupsdRegisterPrinter(p
);
2537 * 'cupsdSetPrinterReasons()' - Set/update the reasons strings.
2540 int /* O - 1 if something changed, 0 otherwise */
2541 cupsdSetPrinterReasons(
2542 cupsd_printer_t
*p
, /* I - Printer */
2543 const char *s
) /* I - Reasons strings */
2545 int i
, /* Looping var */
2546 changed
= 0; /* Did something change? */
2547 const char *sptr
; /* Pointer into reasons */
2548 char reason
[255], /* Reason string */
2549 *rptr
; /* Pointer into reason */
2552 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
2553 "cupsdSetPrinterReasons(p=%p(%s),s=\"%s\"", p
, p
->name
, s
);
2555 if (s
[0] == '-' || s
[0] == '+')
2558 * Add/remove reasons...
2566 * Replace reasons...
2571 for (i
= 0; i
< p
->num_reasons
; i
++)
2572 _cupsStrFree(p
->reasons
[i
]);
2580 if (!strcmp(s
, "none"))
2584 * Loop through all of the reasons...
2590 * Skip leading whitespace and commas...
2593 while (isspace(*sptr
& 255) || *sptr
== ',')
2596 for (rptr
= reason
; *sptr
&& !isspace(*sptr
& 255) && *sptr
!= ','; sptr
++)
2597 if (rptr
< (reason
+ sizeof(reason
) - 1))
2611 for (i
= 0; i
< p
->num_reasons
; i
++)
2612 if (!strcmp(reason
, p
->reasons
[i
]))
2615 * Found a match, so remove it...
2620 _cupsStrFree(p
->reasons
[i
]);
2622 if (i
< p
->num_reasons
)
2623 memmove(p
->reasons
+ i
, p
->reasons
+ i
+ 1, (size_t)(p
->num_reasons
- i
) * sizeof(char *));
2625 if (!strcmp(reason
, "paused") && p
->state
== IPP_PRINTER_STOPPED
)
2626 cupsdSetPrinterState(p
, IPP_PRINTER_IDLE
, 1);
2628 if (!strcmp(reason
, "cups-waiting-for-job-completed") && p
->job
)
2629 p
->job
->completed
= 0;
2631 if (strcmp(reason
, "connecting-to-device"))
2637 else if (p
->num_reasons
< (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
2643 for (i
= 0; i
< p
->num_reasons
; i
++)
2644 if (!strcmp(reason
, p
->reasons
[i
]))
2647 if (i
>= p
->num_reasons
)
2649 if (i
>= (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
2651 cupsdLogMessage(CUPSD_LOG_ALERT
,
2652 "Too many printer-state-reasons values for %s (%d)",
2657 p
->reasons
[i
] = _cupsStrAlloc(reason
);
2661 if (!strcmp(reason
, "paused") && p
->state
!= IPP_PRINTER_STOPPED
)
2662 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, 1);
2664 if (!strcmp(reason
, "cups-waiting-for-job-completed") && p
->job
)
2665 p
->job
->completed
= 1;
2667 if (strcmp(reason
, "connecting-to-device"))
2678 * 'cupsdSetPrinterState()' - Update the current state of a printer.
2682 cupsdSetPrinterState(
2683 cupsd_printer_t
*p
, /* I - Printer to change */
2684 ipp_pstate_t s
, /* I - New state */
2685 int update
) /* I - Update printers.conf? */
2687 cupsd_job_t
*job
; /* Current job */
2688 ipp_pstate_t old_state
; /* Old printer state */
2689 static const char * const printer_states
[] =
2690 { /* State strings */
2698 * Set the new state...
2701 old_state
= p
->state
;
2706 cupsdAddEvent(s
== IPP_PRINTER_STOPPED
? CUPSD_EVENT_PRINTER_STOPPED
:
2707 CUPSD_EVENT_PRINTER_STATE
, p
, NULL
,
2708 "%s \"%s\" state changed to %s.",
2709 (p
->type
& CUPS_PRINTER_CLASS
) ? "Class" : "Printer",
2710 p
->name
, printer_states
[p
->state
- IPP_PRINTER_IDLE
]);
2713 * Let the browse code know this needs to be updated...
2716 p
->state_time
= time(NULL
);
2720 * Set/clear the paused reason as needed...
2723 if (s
== IPP_PRINTER_STOPPED
)
2724 cupsdSetPrinterReasons(p
, "+paused");
2726 cupsdSetPrinterReasons(p
, "-paused");
2730 for (job
= (cupsd_job_t
*)cupsArrayFirst(ActiveJobs
);
2732 job
= (cupsd_job_t
*)cupsArrayNext(ActiveJobs
))
2733 if (job
->reasons
&& job
->state_value
== IPP_JOB_PENDING
&&
2734 !_cups_strcasecmp(job
->dest
, p
->name
))
2735 ippSetString(job
->attrs
, &job
->reasons
, 0,
2736 s
== IPP_PRINTER_STOPPED
? "printer-stopped" : "none");
2740 * Clear the message for the queue when going to processing...
2743 if (s
== IPP_PRINTER_PROCESSING
)
2744 p
->state_message
[0] = '\0';
2747 * Let the browse protocols reflect the change...
2751 cupsdRegisterPrinter(p
);
2754 * Save the printer configuration if a printer goes from idle or processing
2755 * to stopped (or visa-versa)...
2759 (old_state
== IPP_PRINTER_STOPPED
) != (s
== IPP_PRINTER_STOPPED
))
2765 * 'cupsdStopPrinter()' - Stop a printer from printing any jobs...
2769 cupsdStopPrinter(cupsd_printer_t
*p
, /* I - Printer to stop */
2770 int update
)/* I - Update printers.conf? */
2773 * Set the printer state...
2776 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, update
);
2779 * See if we have a job printing on this printer...
2782 if (p
->job
&& p
->job
->state_value
== IPP_JOB_PROCESSING
)
2783 cupsdSetJobState(p
->job
, IPP_JOB_PENDING
, CUPSD_JOB_DEFAULT
,
2784 "Job stopped due to printer being paused.");
2789 * 'cupsdUpdatePrinterPPD()' - Update keywords in a printer's PPD file.
2792 int /* O - 1 if successful, 0 otherwise */
2793 cupsdUpdatePrinterPPD(
2794 cupsd_printer_t
*p
, /* I - Printer */
2795 int num_keywords
, /* I - Number of keywords */
2796 cups_option_t
*keywords
) /* I - Keywords */
2798 int i
; /* Looping var */
2799 cups_file_t
*src
, /* Original file */
2800 *dst
; /* New file */
2801 char srcfile
[1024], /* Original filename */
2802 dstfile
[1024], /* New filename */
2803 line
[1024], /* Line from file */
2804 keystring
[41]; /* Keyword from line */
2805 cups_option_t
*keyword
; /* Current keyword */
2808 cupsdLogMessage(CUPSD_LOG_INFO
, "Updating keywords in PPD file for %s...",
2812 * Get the old and new PPD filenames...
2815 snprintf(srcfile
, sizeof(srcfile
), "%s/ppd/%s.ppd.O", ServerRoot
, p
->name
);
2816 snprintf(dstfile
, sizeof(srcfile
), "%s/ppd/%s.ppd", ServerRoot
, p
->name
);
2819 * Rename the old file and open the old and new...
2822 if (rename(dstfile
, srcfile
))
2824 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to backup PPD file for %s: %s",
2825 p
->name
, strerror(errno
));
2829 if ((src
= cupsFileOpen(srcfile
, "r")) == NULL
)
2831 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to open PPD file \"%s\": %s",
2832 srcfile
, strerror(errno
));
2833 rename(srcfile
, dstfile
);
2837 if ((dst
= cupsFileOpen(dstfile
, "w")) == NULL
)
2839 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to create PPD file \"%s\": %s",
2840 dstfile
, strerror(errno
));
2842 rename(srcfile
, dstfile
);
2847 * Copy the first line and then write out all of the keywords...
2850 if (!cupsFileGets(src
, line
, sizeof(line
)))
2852 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to read PPD file \"%s\": %s",
2853 srcfile
, strerror(errno
));
2856 rename(srcfile
, dstfile
);
2860 cupsFilePrintf(dst
, "%s\n", line
);
2862 for (i
= num_keywords
, keyword
= keywords
; i
> 0; i
--, keyword
++)
2864 cupsdLogMessage(CUPSD_LOG_DEBUG
, "*%s: %s", keyword
->name
, keyword
->value
);
2865 cupsFilePrintf(dst
, "*%s: %s\n", keyword
->name
, keyword
->value
);
2869 * Then copy the rest of the PPD file, dropping any keywords we changed.
2872 while (cupsFileGets(src
, line
, sizeof(line
)))
2875 * Skip keywords we've already set...
2878 if (sscanf(line
, "*%40[^:]:", keystring
) == 1 &&
2879 cupsGetOption(keystring
, num_keywords
, keywords
))
2883 * Otherwise write the line...
2886 cupsFilePrintf(dst
, "%s\n", line
);
2890 * Close files and return...
2901 * 'cupsdUpdatePrinters()' - Update printers after a partial reload.
2905 cupsdUpdatePrinters(void)
2907 cupsd_printer_t
*p
; /* Current printer */
2911 * Loop through the printers and recreate the printer attributes
2912 * for any local printers since the policy and/or access control
2913 * stuff may have changed. Also, if browsing is disabled, remove
2914 * any remote printers...
2917 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
2919 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
2922 * Update the operation policy pointer...
2925 if ((p
->op_policy_ptr
= cupsdFindPolicy(p
->op_policy
)) == NULL
)
2926 p
->op_policy_ptr
= DefaultPolicyPtr
;
2929 * Update printer attributes...
2932 cupsdSetPrinterAttrs(p
);
2938 * 'cupsdValidateDest()' - Validate a printer/class destination.
2941 const char * /* O - Printer or class name */
2943 const char *uri
, /* I - Printer URI */
2944 cups_ptype_t
*dtype
, /* O - Type (printer or class) */
2945 cupsd_printer_t
**printer
) /* O - Printer pointer */
2947 cupsd_printer_t
*p
; /* Current printer */
2948 char localname
[1024],/* Localized hostname */
2949 *lptr
, /* Pointer into localized hostname */
2950 *sptr
, /* Pointer into server name */
2951 *rptr
, /* Pointer into resource */
2952 scheme
[32], /* Scheme portion of URI */
2953 username
[64], /* Username portion of URI */
2954 hostname
[HTTP_MAX_HOST
],
2955 /* Host portion of URI */
2956 resource
[HTTP_MAX_URI
];
2957 /* Resource portion of URI */
2958 int port
; /* Port portion of URI */
2961 DEBUG_printf(("cupsdValidateDest(uri=\"%s\", dtype=%p, printer=%p)\n", uri
,
2965 * Initialize return values...
2972 *dtype
= (cups_ptype_t
)0;
2975 * Pull the hostname and resource from the URI...
2978 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
, scheme
, sizeof(scheme
),
2979 username
, sizeof(username
), hostname
, sizeof(hostname
),
2980 &port
, resource
, sizeof(resource
));
2983 * See if the resource is a class or printer...
2986 if (!strncmp(resource
, "/classes/", 9))
2992 rptr
= resource
+ 9;
2994 else if (!strncmp(resource
, "/printers/", 10))
3000 rptr
= resource
+ 10;
3005 * Bad resource name...
3012 * See if the printer or class name exists...
3015 p
= cupsdFindDest(rptr
);
3017 if (p
== NULL
&& strchr(rptr
, '@') == NULL
)
3025 *dtype
= p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_REMOTE
);
3031 * Change localhost to the server name...
3034 if (!_cups_strcasecmp(hostname
, "localhost"))
3035 strlcpy(hostname
, ServerName
, sizeof(hostname
));
3037 strlcpy(localname
, hostname
, sizeof(localname
));
3039 if (!_cups_strcasecmp(hostname
, ServerName
))
3042 * Localize the hostname...
3045 lptr
= strchr(localname
, '.');
3046 sptr
= strchr(ServerName
, '.');
3048 if (sptr
!= NULL
&& lptr
!= NULL
)
3051 * Strip the common domain name components...
3054 while (lptr
!= NULL
)
3056 if (!_cups_strcasecmp(lptr
, sptr
))
3062 lptr
= strchr(lptr
+ 1, '.');
3067 DEBUG_printf(("localized hostname is \"%s\"...\n", localname
));
3070 * Find a matching printer or class...
3073 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3075 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3076 if (!_cups_strcasecmp(p
->hostname
, localname
) &&
3077 !_cups_strcasecmp(p
->name
, rptr
))
3083 *dtype
= p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_REMOTE
);
3093 * 'cupsdWritePrintcap()' - Write a pseudo-printcap file for older applications
3098 cupsdWritePrintcap(void)
3100 int i
; /* Looping var */
3101 cups_file_t
*fp
; /* Printcap file */
3102 cupsd_printer_t
*p
; /* Current printer */
3106 * See if we have a printcap file; if not, don't bother writing it.
3109 if (!Printcap
|| !*Printcap
)
3112 cupsdLogMessage(CUPSD_LOG_INFO
, "Generating printcap %s...", Printcap
);
3115 * Open the printcap file...
3118 if ((fp
= cupsFileOpen(Printcap
, "w")) == NULL
)
3122 * Put a comment header at the top so that users will know where the
3123 * data has come from...
3126 if (PrintcapFormat
!= PRINTCAP_PLIST
)
3127 cupsFilePrintf(fp
, "# This file was automatically generated by cupsd(8) "
3129 "# %s/printers.conf file. All changes to this file\n"
3130 "# will be lost.\n", ServerRoot
);
3133 * Write a new printcap with the current list of printers.
3136 switch (PrintcapFormat
)
3140 * Each printer is put in the file as:
3150 cupsFilePrintf(fp
, "%s|%s:rm=%s:rp=%s:\n", DefaultPrinter
->name
,
3151 DefaultPrinter
->info
, ServerName
,
3152 DefaultPrinter
->name
);
3154 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3156 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3157 if (p
!= DefaultPrinter
)
3158 cupsFilePrintf(fp
, "%s|%s:rm=%s:rp=%s:\n", p
->name
, p
->info
,
3159 ServerName
, p
->name
);
3162 case PRINTCAP_PLIST
:
3164 * Each printer is written as a dictionary in a plist file.
3165 * Currently the printer-name, printer-info, printer-is-accepting-jobs,
3166 * printer-location, printer-make-and-model, printer-state,
3167 * printer-state-reasons, printer-type, and (sanitized) device-uri.
3170 cupsFilePuts(fp
, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
3171 "<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD "
3172 "PLIST 1.0//EN\" \"http://www.apple.com/DTDs/"
3173 "PropertyList-1.0.dtd\">\n"
3174 "<plist version=\"1.0\">\n"
3177 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3179 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3181 cupsFilePuts(fp
, "\t<dict>\n"
3182 "\t\t<key>printer-name</key>\n"
3184 write_xml_string(fp
, p
->name
);
3185 cupsFilePuts(fp
, "</string>\n"
3186 "\t\t<key>printer-info</key>\n"
3188 write_xml_string(fp
, p
->info
);
3189 cupsFilePrintf(fp
, "</string>\n"
3190 "\t\t<key>printer-is-accepting-jobs</key>\n"
3192 "\t\t<key>printer-location</key>\n"
3193 "\t\t<string>", p
->accepting
? "true" : "false");
3194 write_xml_string(fp
, p
->location
);
3195 cupsFilePuts(fp
, "</string>\n"
3196 "\t\t<key>printer-make-and-model</key>\n"
3198 write_xml_string(fp
, p
->make_model
);
3199 cupsFilePrintf(fp
, "</string>\n"
3200 "\t\t<key>printer-state</key>\n"
3201 "\t\t<integer>%d</integer>\n"
3202 "\t\t<key>printer-state-reasons</key>\n"
3203 "\t\t<array>\n", p
->state
);
3204 for (i
= 0; i
< p
->num_reasons
; i
++)
3206 cupsFilePuts(fp
, "\t\t\t<string>");
3207 write_xml_string(fp
, p
->reasons
[i
]);
3208 cupsFilePuts(fp
, "</string>\n");
3210 cupsFilePrintf(fp
, "\t\t</array>\n"
3211 "\t\t<key>printer-type</key>\n"
3212 "\t\t<integer>%d</integer>\n"
3213 "\t\t<key>device-uri</key>\n"
3214 "\t\t<string>", p
->type
);
3215 write_xml_string(fp
, p
->sanitized_device_uri
);
3216 cupsFilePuts(fp
, "</string>\n"
3219 cupsFilePuts(fp
, "</array>\n"
3223 case PRINTCAP_SOLARIS
:
3225 * Each printer is put in the file as:
3227 * _all:all=Printer1,Printer2,Printer3,...,PrinterN
3228 * _default:use=DefaultPrinter
3230 * :bsdaddr=ServerName,Printer1:\
3231 * :description=Description:
3233 * :bsdaddr=ServerName,Printer2:\
3234 * :description=Description:
3236 * :bsdaddr=ServerName,Printer3:\
3237 * :description=Description:
3240 * :bsdaddr=ServerName,PrinterN:\
3241 * :description=Description:
3244 cupsFilePuts(fp
, "_all:all=");
3245 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3247 p
= (cupsd_printer_t
*)cupsArrayCurrent(Printers
))
3248 cupsFilePrintf(fp
, "%s%c", p
->name
,
3249 cupsArrayNext(Printers
) ? ',' : '\n');
3252 cupsFilePrintf(fp
, "_default:use=%s\n", DefaultPrinter
->name
);
3254 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3256 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3257 cupsFilePrintf(fp
, "%s:\\\n"
3258 "\t:bsdaddr=%s,%s:\\\n"
3259 "\t:description=%s:\n",
3260 p
->name
, ServerName
, p
->name
,
3261 p
->info
? p
->info
: "");
3274 * 'add_printer_defaults()' - Add name-default attributes to the printer attributes.
3278 add_printer_defaults(cupsd_printer_t
*p
)/* I - Printer */
3280 int i
; /* Looping var */
3281 int num_options
; /* Number of default options */
3282 cups_option_t
*options
, /* Default options */
3283 *option
; /* Current option */
3284 char name
[256]; /* name-default */
3288 * Maintain a common array of default attribute names...
3291 if (!CommonDefaults
)
3293 CommonDefaults
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
3295 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("copies-default"));
3296 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("document-format-default"));
3297 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("finishings-default"));
3298 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-account-id-default"));
3299 cupsArrayAdd(CommonDefaults
,
3300 _cupsStrAlloc("job-accounting-user-id-default"));
3301 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-cancel-after-default"));
3302 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-hold-until-default"));
3303 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-priority-default"));
3304 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-sheets-default"));
3305 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("media-col-default"));
3306 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("number-up-default"));
3307 cupsArrayAdd(CommonDefaults
,
3308 _cupsStrAlloc("orientation-requested-default"));
3312 * Add all of the default options from the .conf files...
3315 for (num_options
= 0, options
= NULL
, i
= p
->num_options
, option
= p
->options
;
3319 if (strcmp(option
->name
, "ipp-options") &&
3320 strcmp(option
->name
, "job-sheets") &&
3321 strcmp(option
->name
, "lease-duration"))
3323 snprintf(name
, sizeof(name
), "%s-default", option
->name
);
3324 num_options
= cupsAddOption(name
, option
->value
, num_options
, &options
);
3326 if (!cupsArrayFind(CommonDefaults
, name
))
3327 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc(name
));
3332 * Convert options to IPP attributes...
3335 cupsEncodeOptions2(p
->attrs
, num_options
, options
, IPP_TAG_PRINTER
);
3336 cupsFreeOptions(num_options
, options
);
3339 * Add standard -default attributes as needed...
3342 if (!cupsGetOption("copies", p
->num_options
, p
->options
))
3343 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
, "copies-default",
3346 if (!cupsGetOption("document-format", p
->num_options
, p
->options
))
3347 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_MIMETYPE
,
3348 "document-format-default", NULL
, "application/octet-stream");
3350 if (!cupsGetOption("job-cancel-after", p
->num_options
, p
->options
))
3351 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3352 "job-cancel-after-default", MaxJobTime
);
3354 if (!cupsGetOption("job-hold-until", p
->num_options
, p
->options
))
3355 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3356 "job-hold-until-default", NULL
, "no-hold");
3358 if (!cupsGetOption("job-priority", p
->num_options
, p
->options
))
3359 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3360 "job-priority-default", 50);
3362 if (!cupsGetOption("number-up", p
->num_options
, p
->options
))
3363 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3364 "number-up-default", 1);
3366 if (!cupsGetOption("notify-lease-duration", p
->num_options
, p
->options
))
3367 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3368 "notify-lease-duration-default", DefaultLeaseDuration
);
3370 if (!cupsGetOption("notify-events", p
->num_options
, p
->options
))
3371 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3372 "notify-events-default", NULL
, "job-completed");
3374 if (!cupsGetOption("orientation-requested", p
->num_options
, p
->options
))
3375 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NOVALUE
,
3376 "orientation-requested-default", NULL
, NULL
);
3378 if (!cupsGetOption("print-quality", p
->num_options
, p
->options
))
3379 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
3380 "print-quality-default", IPP_QUALITY_NORMAL
);
3385 * 'add_printer_filter()' - Add a MIME filter for a printer.
3390 cupsd_printer_t
*p
, /* I - Printer to add to */
3391 mime_type_t
*filtertype
, /* I - Filter or prefilter MIME type */
3392 const char *filter
) /* I - Filter to add */
3394 char super
[MIME_MAX_SUPER
], /* Super-type for filter */
3395 type
[MIME_MAX_TYPE
], /* Type for filter */
3396 dsuper
[MIME_MAX_SUPER
], /* Destination super-type for filter */
3397 dtype
[MIME_MAX_TYPE
], /* Destination type for filter */
3398 dest
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2],
3399 /* Destination super/type */
3400 program
[1024]; /* Program/filter name */
3401 int cost
; /* Cost of filter */
3402 size_t maxsize
= 0; /* Maximum supported file size */
3403 mime_type_t
*temptype
, /* MIME type looping var */
3404 *desttype
; /* Destination MIME type */
3405 mime_filter_t
*filterptr
; /* MIME filter */
3406 char filename
[1024]; /* Full filter filename */
3409 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3410 "add_printer_filter(p=%p(%s), filtertype=%p(%s/%s), "
3411 "filter=\"%s\")", p
, p
->name
, filtertype
, filtertype
->super
,
3412 filtertype
->type
, filter
);
3415 * Parse the filter string; it should be in one of the following formats:
3417 * source/type cost program
3418 * source/type cost maxsize(nnnn) program
3419 * source/type dest/type cost program
3420 * source/type dest/type cost maxsize(nnnn) program
3423 if (sscanf(filter
, "%15[^/]/%255s%*[ \t]%15[^/]/%255s%d%*[ \t]%1023[^\n]",
3424 super
, type
, dsuper
, dtype
, &cost
, program
) == 6)
3426 snprintf(dest
, sizeof(dest
), "%s/%s/%s", p
->name
, dsuper
, dtype
);
3428 if ((desttype
= mimeType(MimeDatabase
, "printer", dest
)) == NULL
)
3430 desttype
= mimeAddType(MimeDatabase
, "printer", dest
);
3432 p
->dest_types
= cupsArrayNew(NULL
, NULL
);
3434 cupsArrayAdd(p
->dest_types
, desttype
);
3440 if (sscanf(filter
, "%15[^/]/%255s%d%*[ \t]%1023[^\n]", super
, type
, &cost
,
3443 desttype
= filtertype
;
3447 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: invalid filter string \"%s\"!",
3453 if (!strncmp(program
, "maxsize(", 8))
3455 char *ptr
; /* Pointer into maxsize(nnnn) program */
3457 maxsize
= (size_t)strtoll(program
+ 8, &ptr
, 10);
3461 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: invalid filter string \"%s\"!",
3467 while (_cups_isspace(*ptr
))
3470 _cups_strcpy(program
, ptr
);
3474 * Check permissions on the filter and its containing directory...
3477 if (strcmp(program
, "-"))
3479 if (program
[0] == '/')
3480 strlcpy(filename
, program
, sizeof(filename
));
3482 snprintf(filename
, sizeof(filename
), "%s/filter/%s", ServerBin
, program
);
3484 _cupsFileCheck(filename
, _CUPS_FILE_CHECK_PROGRAM
, !RunUser
,
3485 cupsdLogFCMessage
, p
);
3489 * Add the filter to the MIME database, supporting wildcards as needed...
3492 for (temptype
= mimeFirstType(MimeDatabase
);
3494 temptype
= mimeNextType(MimeDatabase
))
3495 if (((super
[0] == '*' && _cups_strcasecmp(temptype
->super
, "printer")) ||
3496 !_cups_strcasecmp(temptype
->super
, super
)) &&
3497 (type
[0] == '*' || !_cups_strcasecmp(temptype
->type
, type
)))
3499 if (desttype
!= filtertype
)
3501 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3502 "add_printer_filter: %s: adding filter %s/%s %s/%s %d "
3503 "%s", p
->name
, temptype
->super
, temptype
->type
,
3504 desttype
->super
, desttype
->type
,
3506 filterptr
= mimeAddFilter(MimeDatabase
, temptype
, desttype
, cost
,
3509 if (!mimeFilterLookup(MimeDatabase
, desttype
, filtertype
))
3511 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3512 "add_printer_filter: %s: adding filter %s/%s %s/%s "
3513 "0 -", p
->name
, desttype
->super
, desttype
->type
,
3514 filtertype
->super
, filtertype
->type
);
3515 mimeAddFilter(MimeDatabase
, desttype
, filtertype
, 0, "-");
3520 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3521 "add_printer_filter: %s: adding filter %s/%s %s/%s %d "
3522 "%s", p
->name
, temptype
->super
, temptype
->type
,
3523 filtertype
->super
, filtertype
->type
,
3525 filterptr
= mimeAddFilter(MimeDatabase
, temptype
, filtertype
, cost
,
3530 filterptr
->maxsize
= maxsize
;
3536 * 'add_printer_formats()' - Add document-format-supported values for a printer.
3540 add_printer_formats(cupsd_printer_t
*p
) /* I - Printer */
3542 int i
; /* Looping var */
3543 mime_type_t
*type
; /* Current MIME type */
3544 cups_array_t
*filters
; /* Filters */
3545 ipp_attribute_t
*attr
; /* document-format-supported attribute */
3546 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
3547 /* MIME type name */
3551 * Raw (and remote) queues advertise all of the supported MIME
3555 cupsArrayDelete(p
->filetypes
);
3556 p
->filetypes
= NULL
;
3560 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
,
3561 (ipp_tag_t
)(IPP_TAG_MIMETYPE
| IPP_TAG_COPY
),
3562 "document-format-supported", NumMimeTypes
, NULL
, MimeTypes
);
3567 * Otherwise, loop through the supported MIME types and see if there
3568 * are filters for them...
3571 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_printer_formats: %d types, %d filters",
3572 mimeNumTypes(MimeDatabase
), mimeNumFilters(MimeDatabase
));
3574 p
->filetypes
= cupsArrayNew(NULL
, NULL
);
3576 for (type
= mimeFirstType(MimeDatabase
);
3578 type
= mimeNextType(MimeDatabase
))
3580 if (!_cups_strcasecmp(type
->super
, "printer"))
3583 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
3585 if ((filters
= mimeFilter(MimeDatabase
, type
, p
->filetype
, NULL
)) != NULL
)
3587 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3588 "add_printer_formats: %s: %s needs %d filters",
3589 p
->name
, mimetype
, cupsArrayCount(filters
));
3591 cupsArrayDelete(filters
);
3592 cupsArrayAdd(p
->filetypes
, type
);
3595 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3596 "add_printer_formats: %s: %s not supported",
3601 * Add the file formats that can be filtered...
3604 if ((type
= mimeType(MimeDatabase
, "application", "octet-stream")) == NULL
||
3605 !cupsArrayFind(p
->filetypes
, type
))
3610 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3611 "add_printer_formats: %s: %d supported types",
3612 p
->name
, cupsArrayCount(p
->filetypes
) + i
);
3614 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_MIMETYPE
,
3615 "document-format-supported",
3616 cupsArrayCount(p
->filetypes
) + i
, NULL
, NULL
);
3619 attr
->values
[0].string
.text
= _cupsStrAlloc("application/octet-stream");
3621 for (type
= (mime_type_t
*)cupsArrayFirst(p
->filetypes
);
3623 i
++, type
= (mime_type_t
*)cupsArrayNext(p
->filetypes
))
3625 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
3627 attr
->values
[i
].string
.text
= _cupsStrAlloc(mimetype
);
3630 #if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
3632 char pdl
[1024]; /* Buffer to build pdl list */
3633 mime_filter_t
*filter
; /* MIME filter looping var */
3637 * We only support raw printing if this is not a Tioga PrintJobMgr based
3638 * queue and if application/octet-stream is a known type...
3641 for (filter
= (mime_filter_t
*)cupsArrayFirst(MimeDatabase
->filters
);
3643 filter
= (mime_filter_t
*)cupsArrayNext(MimeDatabase
->filters
))
3645 if (filter
->dst
== p
->filetype
&& strstr(filter
->filter
, "PrintJobMgr"))
3651 if (!filter
&& mimeType(MimeDatabase
, "application", "octet-stream"))
3652 strlcat(pdl
, "application/octet-stream,", sizeof(pdl
));
3655 * Then list a bunch of formats that are supported by the printer...
3658 for (type
= (mime_type_t
*)cupsArrayFirst(p
->filetypes
);
3660 type
= (mime_type_t
*)cupsArrayNext(p
->filetypes
))
3662 if (!_cups_strcasecmp(type
->super
, "application"))
3664 if (!_cups_strcasecmp(type
->type
, "pdf"))
3665 strlcat(pdl
, "application/pdf,", sizeof(pdl
));
3666 else if (!_cups_strcasecmp(type
->type
, "postscript"))
3667 strlcat(pdl
, "application/postscript,", sizeof(pdl
));
3669 else if (!_cups_strcasecmp(type
->super
, "image"))
3671 if (!_cups_strcasecmp(type
->type
, "jpeg"))
3672 strlcat(pdl
, "image/jpeg,", sizeof(pdl
));
3673 else if (!_cups_strcasecmp(type
->type
, "png"))
3674 strlcat(pdl
, "image/png,", sizeof(pdl
));
3675 else if (!_cups_strcasecmp(type
->type
, "pwg-raster"))
3676 strlcat(pdl
, "image/pwg-raster,", sizeof(pdl
));
3681 pdl
[strlen(pdl
) - 1] = '\0'; /* Remove trailing comma */
3683 cupsdSetString(&p
->pdl
, pdl
);
3685 #endif /* HAVE_DNSSD || HAVE_AVAHI */
3690 * 'compare_printers()' - Compare two printers.
3693 static int /* O - Result of comparison */
3694 compare_printers(void *first
, /* I - First printer */
3695 void *second
, /* I - Second printer */
3696 void *data
) /* I - App data (not used) */
3700 return (_cups_strcasecmp(((cupsd_printer_t
*)first
)->name
,
3701 ((cupsd_printer_t
*)second
)->name
));
3706 * 'delete_printer_filters()' - Delete all MIME filters for a printer.
3710 delete_printer_filters(
3711 cupsd_printer_t
*p
) /* I - Printer to remove from */
3713 mime_filter_t
*filter
; /* MIME filter looping var */
3714 mime_type_t
*type
; /* Destination types for filters */
3718 * Range check input...
3725 * Remove all filters from the MIME database that have a destination
3726 * type == printer...
3729 for (filter
= mimeFirstFilter(MimeDatabase
);
3731 filter
= mimeNextFilter(MimeDatabase
))
3732 if (filter
->dst
== p
->filetype
|| filter
->dst
== p
->prefiltertype
||
3733 cupsArrayFind(p
->dest_types
, filter
->dst
))
3736 * Delete the current filter...
3739 mimeDeleteFilter(MimeDatabase
, filter
);
3742 for (type
= (mime_type_t
*)cupsArrayFirst(p
->dest_types
);
3744 type
= (mime_type_t
*)cupsArrayNext(p
->dest_types
))
3745 mimeDeleteType(MimeDatabase
, type
);
3747 cupsArrayDelete(p
->dest_types
);
3748 p
->dest_types
= NULL
;
3750 cupsdSetPrinterReasons(p
, "-cups-insecure-filter-warning"
3751 ",cups-missing-filter-warning");
3756 * 'dirty_printer()' - Mark config and state files dirty for the specified
3761 dirty_printer(cupsd_printer_t
*p
) /* I - Printer */
3763 if (p
->type
& CUPS_PRINTER_CLASS
)
3764 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
3766 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
3768 if (PrintcapFormat
== PRINTCAP_PLIST
)
3769 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
3774 * 'load_ppd()' - Load a cached PPD file, updating the cache as needed.
3778 load_ppd(cupsd_printer_t
*p
) /* I - Printer */
3780 int i
, j
, k
; /* Looping vars */
3781 char cache_name
[1024]; /* Cache filename */
3782 struct stat cache_info
; /* Cache file info */
3783 ppd_file_t
*ppd
; /* PPD file */
3784 char ppd_name
[1024]; /* PPD filename */
3785 struct stat ppd_info
; /* PPD file info */
3786 int num_media
; /* Number of media options */
3787 ppd_size_t
*size
; /* Current PPD size */
3788 ppd_option_t
*duplex
, /* Duplex option */
3789 *output_bin
, /* OutputBin option */
3790 *output_mode
, /* OutputMode option */
3791 *resolution
; /* (Set|JCL|)Resolution option */
3792 ppd_choice_t
*choice
, /* Current PPD choice */
3793 *input_slot
, /* Current input slot */
3794 *media_type
; /* Current media type */
3795 ppd_attr_t
*ppd_attr
; /* PPD attribute */
3796 int xdpi
, /* Horizontal resolution */
3797 ydpi
; /* Vertical resolution */
3798 const char *resptr
; /* Pointer into resolution keyword */
3799 pwg_size_t
*pwgsize
; /* Current PWG size */
3800 pwg_map_t
*pwgsource
, /* Current PWG source */
3801 *pwgtype
; /* Current PWG type */
3802 ipp_attribute_t
*attr
; /* Attribute data */
3803 _ipp_value_t
*val
; /* Attribute value */
3804 int num_finishings
, /* Number of finishings */
3805 finishings
[100]; /* finishings-supported values */
3806 int num_qualities
, /* Number of print-quality values */
3807 qualities
[3]; /* print-quality values */
3808 int num_margins
, /* Number of media-*-margin-supported values */
3809 margins
[16]; /* media-*-margin-supported values */
3810 const char *filter
, /* Current filter */
3811 *mandatory
; /* Current mandatory attribute */
3812 static const char * const pwg_raster_document_types
[] =
3818 static const char * const sides
[3] = /* sides-supported values */
3821 "two-sided-long-edge",
3822 "two-sided-short-edge"
3824 static const char * const standard_commands
[] =
3825 { /* Standard CUPS commands */
3833 * Check to see if the cache is up-to-date...
3836 snprintf(cache_name
, sizeof(cache_name
), "%s/%s.data", CacheDir
, p
->name
);
3837 if (stat(cache_name
, &cache_info
))
3838 cache_info
.st_mtime
= 0;
3840 snprintf(ppd_name
, sizeof(ppd_name
), "%s/ppd/%s.ppd", ServerRoot
, p
->name
);
3841 if (stat(ppd_name
, &ppd_info
))
3842 ppd_info
.st_mtime
= 1;
3844 ippDelete(p
->ppd_attrs
);
3845 p
->ppd_attrs
= NULL
;
3847 _ppdCacheDestroy(p
->pc
);
3850 if (cache_info
.st_mtime
>= ppd_info
.st_mtime
)
3852 cupsdLogMessage(CUPSD_LOG_DEBUG
, "load_ppd: Loading %s...", cache_name
);
3854 if ((p
->pc
= _ppdCacheCreateWithFile(cache_name
, &p
->ppd_attrs
)) != NULL
&&
3858 * Loaded successfully!
3866 * Reload PPD attributes from disk...
3869 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
3871 cupsdLogMessage(CUPSD_LOG_DEBUG
, "load_ppd: Loading %s...", ppd_name
);
3873 cupsdClearString(&(p
->make_model
));
3875 p
->type
&= (cups_ptype_t
)~CUPS_PRINTER_OPTIONS
;
3876 p
->type
|= CUPS_PRINTER_BW
;
3878 finishings
[0] = IPP_FINISHINGS_NONE
;
3881 p
->ppd_attrs
= ippNew();
3883 if ((ppd
= _ppdOpenFile(ppd_name
, _PPD_LOCALIZATION_NONE
)) != NULL
)
3886 * Add make/model and other various attributes...
3889 p
->pc
= _ppdCacheCreateWithPPD(ppd
);
3892 cupsdLogMessage(CUPSD_LOG_WARN
, "Unable to create cache of \"%s\": %s",
3893 ppd_name
, cupsLastErrorString());
3895 ppdMarkDefaults(ppd
);
3897 if (ppd
->color_device
)
3898 p
->type
|= CUPS_PRINTER_COLOR
;
3899 if (ppd
->variable_sizes
)
3900 p
->type
|= CUPS_PRINTER_VARIABLE
;
3901 if (!ppd
->manual_copies
)
3902 p
->type
|= CUPS_PRINTER_COPIES
;
3903 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsFax", NULL
)) != NULL
)
3904 if (ppd_attr
->value
&& !_cups_strcasecmp(ppd_attr
->value
, "true"))
3905 p
->type
|= CUPS_PRINTER_FAX
;
3907 ippAddBoolean(p
->ppd_attrs
, IPP_TAG_PRINTER
, "color-supported", (char)ppd
->color_device
);
3909 if (p
->pc
&& p
->pc
->charge_info_uri
)
3910 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
3911 "printer-charge-info-uri", NULL
, p
->pc
->charge_info_uri
);
3913 if (p
->pc
&& p
->pc
->account_id
)
3914 ippAddBoolean(p
->ppd_attrs
, IPP_TAG_PRINTER
, "job-account-id-supported",
3917 if (p
->pc
&& p
->pc
->accounting_user_id
)
3918 ippAddBoolean(p
->ppd_attrs
, IPP_TAG_PRINTER
,
3919 "job-accounting-user-id-supported", 1);
3921 if (p
->pc
&& p
->pc
->password
)
3923 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3924 "job-password-encryption-supported", NULL
, "none");
3925 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3926 "job-password-supported", (int)strlen(p
->pc
->password
));
3929 if (ppd
->throughput
)
3931 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3932 "pages-per-minute", ppd
->throughput
);
3933 if (ppd
->color_device
)
3934 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3935 "pages-per-minute-color", ppd
->throughput
);
3940 * When there is no speed information, just say "1 page per minute".
3943 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3944 "pages-per-minute", 1);
3945 if (ppd
->color_device
)
3946 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3947 "pages-per-minute-color", 1);
3950 if ((ppd_attr
= ppdFindAttr(ppd
, "1284DeviceId", NULL
)) != NULL
)
3951 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-device-id", NULL
, ppd_attr
->value
);
3955 if ((output_mode
= ppdFindOption(ppd
, "OutputMode")) != NULL
)
3957 if (ppdFindChoice(output_mode
, "draft") ||
3958 ppdFindChoice(output_mode
, "fast"))
3959 qualities
[num_qualities
++] = IPP_QUALITY_DRAFT
;
3961 qualities
[num_qualities
++] = IPP_QUALITY_NORMAL
;
3963 if (ppdFindChoice(output_mode
, "best") ||
3964 ppdFindChoice(output_mode
, "high"))
3965 qualities
[num_qualities
++] = IPP_QUALITY_HIGH
;
3967 else if ((ppd_attr
= ppdFindAttr(ppd
, "APPrinterPreset", NULL
)) != NULL
)
3971 if (strstr(ppd_attr
->spec
, "draft") ||
3972 strstr(ppd_attr
->spec
, "Draft"))
3974 qualities
[num_qualities
++] = IPP_QUALITY_DRAFT
;
3978 while ((ppd_attr
= ppdFindNextAttr(ppd
, "APPrinterPreset",
3981 qualities
[num_qualities
++] = IPP_QUALITY_NORMAL
;
3982 qualities
[num_qualities
++] = IPP_QUALITY_HIGH
;
3985 qualities
[num_qualities
++] = IPP_QUALITY_NORMAL
;
3987 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
3988 "print-quality-supported", num_qualities
, qualities
);
3993 * The NickName can be localized in the character set specified
3994 * by the LanugageEncoding attribute. However, ppdOpen2() has
3995 * already converted the ppd->nickname member to UTF-8 for us
3996 * (the original attribute value is available separately)
3999 cupsdSetString(&p
->make_model
, ppd
->nickname
);
4001 else if (ppd
->modelname
)
4004 * Model name can only contain specific characters...
4007 cupsdSetString(&p
->make_model
, ppd
->modelname
);
4010 cupsdSetString(&p
->make_model
, "Bad PPD File");
4012 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
4013 "printer-make-and-model", NULL
, p
->make_model
);
4016 * Add media options from the PPD file...
4019 if (ppd
->num_sizes
== 0 || !p
->pc
)
4021 if (!ppdFindAttr(ppd
, "APScannerOnly", NULL
) && !ppdFindAttr(ppd
, "cups3D", NULL
))
4022 cupsdLogMessage(CUPSD_LOG_CRIT
,
4023 "The PPD file for printer %s contains no media "
4024 "options and is therefore invalid.", p
->name
);
4026 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4027 "media-default", NULL
, "unknown");
4028 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4029 "media-supported", NULL
, "unknown");
4037 if ((size
= ppdPageSize(ppd
, NULL
)) != NULL
)
4038 pwgsize
= _ppdCacheGetSize(p
->pc
, size
->name
);
4042 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4043 "media-default", NULL
,
4044 pwgsize
? pwgsize
->map
.pwg
: "unknown");
4052 ipp_t
*col
; /* Collection value */
4054 input_slot
= ppdFindMarkedChoice(ppd
, "InputSlot");
4055 media_type
= ppdFindMarkedChoice(ppd
, "MediaType");
4056 col
= new_media_col(pwgsize
,
4058 _ppdCacheGetSource(p
->pc
,
4059 input_slot
->choice
) :
4062 _ppdCacheGetType(p
->pc
,
4063 media_type
->choice
) :
4066 ippAddCollection(p
->ppd_attrs
, IPP_TAG_PRINTER
, "media-col-default",
4075 num_media
= p
->pc
->num_sizes
;
4076 if (p
->pc
->custom_min_keyword
)
4079 if ((attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4080 "media-supported", num_media
, NULL
,
4085 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
;
4087 i
--, pwgsize
++, val
++)
4088 val
->string
.text
= _cupsStrAlloc(pwgsize
->map
.pwg
);
4090 if (p
->pc
->custom_min_keyword
)
4092 val
->string
.text
= _cupsStrAlloc(p
->pc
->custom_min_keyword
);
4094 val
->string
.text
= _cupsStrAlloc(p
->pc
->custom_max_keyword
);
4099 * media-size-supported
4102 num_media
= p
->pc
->num_sizes
;
4103 if (p
->pc
->custom_min_keyword
)
4106 if ((attr
= ippAddCollections(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4107 "media-size-supported", num_media
,
4112 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
;
4114 i
--, pwgsize
++, val
++)
4116 val
->collection
= ippNew();
4117 ippAddInteger(val
->collection
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4118 "x-dimension", pwgsize
->width
);
4119 ippAddInteger(val
->collection
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4120 "y-dimension", pwgsize
->length
);
4123 if (p
->pc
->custom_min_keyword
)
4125 val
->collection
= ippNew();
4126 ippAddRange(val
->collection
, IPP_TAG_PRINTER
, "x-dimension",
4127 p
->pc
->custom_min_width
, p
->pc
->custom_max_width
);
4128 ippAddRange(val
->collection
, IPP_TAG_PRINTER
, "y-dimension",
4129 p
->pc
->custom_min_length
, p
->pc
->custom_max_length
);
4134 * media-source-supported
4137 if (p
->pc
->num_sources
> 0 &&
4138 (attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4139 "media-source-supported", p
->pc
->num_sources
,
4140 NULL
, NULL
)) != NULL
)
4142 for (i
= p
->pc
->num_sources
, pwgsource
= p
->pc
->sources
,
4145 i
--, pwgsource
++, val
++)
4146 val
->string
.text
= _cupsStrAlloc(pwgsource
->pwg
);
4150 * media-type-supported
4153 if (p
->pc
->num_types
> 0 &&
4154 (attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4155 "media-type-supported", p
->pc
->num_types
,
4156 NULL
, NULL
)) != NULL
)
4158 for (i
= p
->pc
->num_types
, pwgtype
= p
->pc
->types
,
4161 i
--, pwgtype
++, val
++)
4162 val
->string
.text
= _cupsStrAlloc(pwgtype
->pwg
);
4166 * media-*-margin-supported
4169 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, num_margins
= 0;
4170 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4173 for (j
= 0; j
< num_margins
; j
++)
4174 if (pwgsize
->bottom
== margins
[j
])
4177 if (j
>= num_margins
)
4179 margins
[num_margins
] = pwgsize
->bottom
;
4184 if (num_margins
> 0)
4185 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4186 "media-bottom-margin-supported", num_margins
, margins
);
4188 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4189 "media-bottom-margin-supported", 0);
4191 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, num_margins
= 0;
4192 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4195 for (j
= 0; j
< num_margins
; j
++)
4196 if (pwgsize
->left
== margins
[j
])
4199 if (j
>= num_margins
)
4201 margins
[num_margins
] = pwgsize
->left
;
4206 if (num_margins
> 0)
4207 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4208 "media-left-margin-supported", num_margins
, margins
);
4210 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4211 "media-left-margin-supported", 0);
4213 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, num_margins
= 0;
4214 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4217 for (j
= 0; j
< num_margins
; j
++)
4218 if (pwgsize
->right
== margins
[j
])
4221 if (j
>= num_margins
)
4223 margins
[num_margins
] = pwgsize
->right
;
4228 if (num_margins
> 0)
4229 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4230 "media-right-margin-supported", num_margins
, margins
);
4232 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4233 "media-right-margin-supported", 0);
4235 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, num_margins
= 0;
4236 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4239 for (j
= 0; j
< num_margins
; j
++)
4240 if (pwgsize
->top
== margins
[j
])
4243 if (j
>= num_margins
)
4245 margins
[num_margins
] = pwgsize
->top
;
4250 if (num_margins
> 0)
4251 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4252 "media-top-margin-supported", num_margins
, margins
);
4254 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4255 "media-top-margin-supported", 0);
4258 * media-col-database
4261 num_media
= p
->pc
->num_sizes
;
4262 if (p
->pc
->num_sources
)
4264 if (p
->pc
->num_types
> 0)
4265 num_media
+= p
->pc
->num_sizes
* p
->pc
->num_sources
*
4268 num_media
+= p
->pc
->num_sizes
* p
->pc
->num_sources
;
4270 else if (p
->pc
->num_types
)
4271 num_media
+= p
->pc
->num_sizes
* p
->pc
->num_types
;
4273 if ((attr
= ippAddCollections(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4274 "media-col-database", num_media
,
4277 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, val
= attr
->values
;
4282 * Start by adding the page size without source or type...
4285 ppdMarkOption(ppd
, "PageSize", pwgsize
->map
.ppd
);
4287 val
->collection
= new_media_col(pwgsize
, NULL
, NULL
);
4291 * Then add the specific, supported combinations of size, source, and
4295 if (p
->pc
->num_sources
> 0)
4297 for (j
= p
->pc
->num_sources
, pwgsource
= p
->pc
->sources
;
4301 ppdMarkOption(ppd
, "InputSlot", pwgsource
->ppd
);
4303 if (p
->pc
->num_types
> 0)
4305 for (k
= p
->pc
->num_types
, pwgtype
= p
->pc
->types
;
4309 if (!ppdMarkOption(ppd
, "MediaType", pwgtype
->ppd
))
4311 val
->collection
= new_media_col(pwgsize
, pwgsource
->pwg
,
4317 else if (!ppdConflicts(ppd
))
4319 val
->collection
= new_media_col(pwgsize
, pwgsource
->pwg
, NULL
);
4324 else if (p
->pc
->num_types
> 0)
4326 for (j
= p
->pc
->num_types
, pwgtype
= p
->pc
->types
;
4330 if (!ppdMarkOption(ppd
, "MediaType", pwgtype
->ppd
))
4332 val
->collection
= new_media_col(pwgsize
, NULL
, pwgtype
->pwg
);
4340 * Update the number of media-col-database values...
4343 attr
->num_values
= val
- attr
->values
;
4351 if (p
->pc
&& p
->pc
->num_bins
> 0)
4353 attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4354 "output-bin-supported", p
->pc
->num_bins
,
4359 for (i
= 0, val
= attr
->values
;
4360 i
< p
->pc
->num_bins
;
4362 val
->string
.text
= _cupsStrAlloc(p
->pc
->bins
[i
].pwg
);
4365 if ((output_bin
= ppdFindOption(ppd
, "OutputBin")) != NULL
)
4367 for (i
= 0; i
< p
->pc
->num_bins
; i
++)
4368 if (!strcmp(p
->pc
->bins
[i
].ppd
, output_bin
->defchoice
))
4371 if (i
>= p
->pc
->num_bins
)
4374 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4375 "output-bin-default", NULL
, p
->pc
->bins
[i
].pwg
);
4378 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4379 "output-bin-default", NULL
, p
->pc
->bins
[0].pwg
);
4381 else if (((ppd_attr
= ppdFindAttr(ppd
, "DefaultOutputOrder",
4383 !_cups_strcasecmp(ppd_attr
->value
, "Reverse")) ||
4384 (!ppd_attr
&& ppd
->manufacturer
&& /* "Compatibility heuristic" */
4385 (!_cups_strcasecmp(ppd
->manufacturer
, "epson") ||
4386 !_cups_strcasecmp(ppd
->manufacturer
, "lexmark"))))
4389 * Report that this printer has a single output bin that leaves pages face
4393 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4394 "output-bin-supported", NULL
, "face-up");
4395 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4396 "output-bin-default", NULL
, "face-up");
4400 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4401 "output-bin-supported", NULL
, "face-down");
4402 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4403 "output-bin-default", NULL
, "face-down");
4407 * print-color-mode...
4410 if (ppd
->color_device
)
4412 static const char * const color_modes
[] =
4418 ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4419 "print-color-mode-supported", 2, NULL
, color_modes
);
4420 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4421 "print-color-mode-default", NULL
, "color");
4422 ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
, "pwg-raster-document-type-supported", 3, NULL
, pwg_raster_document_types
);
4426 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4427 "print-color-mode-supported", NULL
, "monochrome");
4428 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4429 "print-color-mode-default", NULL
, "monochrome");
4430 ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
, "pwg-raster-document-type-supported", 2, NULL
, pwg_raster_document_types
);
4434 * Mandatory job attributes, if any...
4437 if (p
->pc
&& cupsArrayCount(p
->pc
->mandatory
) > 0)
4439 int count
= cupsArrayCount(p
->pc
->mandatory
);
4440 /* Number of mandatory attributes */
4442 attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4443 "printer-mandatory-job-attributes", count
, NULL
,
4446 for (val
= attr
->values
,
4447 mandatory
= (char *)cupsArrayFirst(p
->pc
->mandatory
);
4449 val
++, mandatory
= (char *)cupsArrayNext(p
->pc
->mandatory
))
4450 val
->string
.text
= _cupsStrAlloc(mandatory
);
4454 * Printer resolutions...
4457 if ((resolution
= ppdFindOption(ppd
, "Resolution")) == NULL
)
4458 if ((resolution
= ppdFindOption(ppd
, "JCLResolution")) == NULL
)
4459 if ((resolution
= ppdFindOption(ppd
, "SetResolution")) == NULL
)
4460 resolution
= ppdFindOption(ppd
, "CNRes_PGP");
4465 * Report all supported resolutions...
4468 attr
= ippAddResolutions(p
->ppd_attrs
, IPP_TAG_PRINTER
, "printer-resolution-supported", resolution
->num_choices
, IPP_RES_PER_INCH
, NULL
, NULL
);
4470 for (i
= 0, choice
= resolution
->choices
;
4471 i
< resolution
->num_choices
;
4474 xdpi
= ydpi
= (int)strtol(choice
->choice
, (char **)&resptr
, 10);
4475 if (resptr
> choice
->choice
&& xdpi
> 0 && *resptr
== 'x')
4476 ydpi
= (int)strtol(resptr
+ 1, (char **)&resptr
, 10);
4478 if (xdpi
<= 0 || ydpi
<= 0)
4480 cupsdLogMessage(CUPSD_LOG_WARN
,
4481 "Bad resolution \"%s\" for printer %s.",
4482 choice
->choice
, p
->name
);
4486 attr
->values
[i
].resolution
.xres
= xdpi
;
4487 attr
->values
[i
].resolution
.yres
= ydpi
;
4488 attr
->values
[i
].resolution
.units
= IPP_RES_PER_INCH
;
4491 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
, "printer-resolution-default", IPP_RES_PER_INCH
, xdpi
, ydpi
);
4494 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
, "pwg-raster-document-resolution-supported", IPP_RES_PER_INCH
, xdpi
, ydpi
);
4497 else if ((ppd_attr
= ppdFindAttr(ppd
, "DefaultResolution", NULL
)) != NULL
&&
4501 * Just the DefaultResolution to report...
4504 xdpi
= ydpi
= (int)strtol(ppd_attr
->value
, (char **)&resptr
, 10);
4505 if (resptr
> ppd_attr
->value
&& xdpi
> 0)
4508 ydpi
= (int)strtol(resptr
+ 1, (char **)&resptr
, 10);
4513 if (xdpi
<= 0 || ydpi
<= 0)
4515 cupsdLogMessage(CUPSD_LOG_WARN
,
4516 "Bad default resolution \"%s\" for printer %s.",
4517 ppd_attr
->value
, p
->name
);
4521 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4522 "printer-resolution-default", IPP_RES_PER_INCH
,
4524 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4525 "printer-resolution-supported", IPP_RES_PER_INCH
,
4527 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
, "pwg-raster-document-resolution-supported", IPP_RES_PER_INCH
, xdpi
, ydpi
);
4532 * No resolutions in PPD - make one up...
4535 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4536 "printer-resolution-default", IPP_RES_PER_INCH
,
4538 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4539 "printer-resolution-supported", IPP_RES_PER_INCH
,
4541 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
, "pwg-raster-document-resolution-supported", IPP_RES_PER_INCH
, 300, 300);
4548 ppdMarkDefaults(ppd
);
4550 if ((duplex
= ppdFindOption(ppd
, "Duplex")) == NULL
)
4551 if ((duplex
= ppdFindOption(ppd
, "EFDuplex")) == NULL
)
4552 if ((duplex
= ppdFindOption(ppd
, "EFDuplexing")) == NULL
)
4553 if ((duplex
= ppdFindOption(ppd
, "KD03Duplex")) == NULL
)
4554 duplex
= ppdFindOption(ppd
, "JCLDuplex");
4556 if (duplex
&& duplex
->num_choices
> 1 &&
4557 !ppdInstallableConflict(ppd
, duplex
->keyword
, "DuplexTumble"))
4559 p
->type
|= CUPS_PRINTER_DUPLEX
;
4561 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
, "pwg-raster-document-sheet-back", NULL
, "normal");
4563 ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4564 "sides-supported", 3, NULL
, sides
);
4566 if (!_cups_strcasecmp(duplex
->defchoice
, "DuplexTumble"))
4567 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4568 "sides-default", NULL
, "two-sided-short-edge");
4569 else if (!_cups_strcasecmp(duplex
->defchoice
, "DuplexNoTumble"))
4570 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4571 "sides-default", NULL
, "two-sided-long-edge");
4573 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4574 "sides-default", NULL
, "one-sided");
4578 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4579 "sides-supported", NULL
, "one-sided");
4580 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4581 "sides-default", NULL
, "one-sided");
4584 if (ppdFindOption(ppd
, "Collate") != NULL
)
4585 p
->type
|= CUPS_PRINTER_COLLATE
;
4587 if (p
->pc
&& p
->pc
->finishings
)
4589 _pwg_finishings_t
*fin
; /* Current finishing value */
4591 for (fin
= (_pwg_finishings_t
*)cupsArrayFirst(p
->pc
->finishings
); fin
; fin
= (_pwg_finishings_t
*)cupsArrayNext(p
->pc
->finishings
))
4593 if (num_finishings
< (int)(sizeof(finishings
) / sizeof(finishings
[0])))
4594 finishings
[num_finishings
++] = fin
->value
;
4598 case IPP_FINISHINGS_BIND
:
4599 case IPP_FINISHINGS_BIND_LEFT
:
4600 case IPP_FINISHINGS_BIND_TOP
:
4601 case IPP_FINISHINGS_BIND_RIGHT
:
4602 case IPP_FINISHINGS_BIND_BOTTOM
:
4603 case IPP_FINISHINGS_EDGE_STITCH
:
4604 case IPP_FINISHINGS_EDGE_STITCH_LEFT
:
4605 case IPP_FINISHINGS_EDGE_STITCH_TOP
:
4606 case IPP_FINISHINGS_EDGE_STITCH_RIGHT
:
4607 case IPP_FINISHINGS_EDGE_STITCH_BOTTOM
:
4608 p
->type
|= CUPS_PRINTER_BIND
;
4611 case IPP_FINISHINGS_COVER
:
4612 p
->type
|= CUPS_PRINTER_COVER
;
4615 case IPP_FINISHINGS_PUNCH
:
4616 case IPP_FINISHINGS_PUNCH_TOP_LEFT
:
4617 case IPP_FINISHINGS_PUNCH_BOTTOM_LEFT
:
4618 case IPP_FINISHINGS_PUNCH_TOP_RIGHT
:
4619 case IPP_FINISHINGS_PUNCH_BOTTOM_RIGHT
:
4620 case IPP_FINISHINGS_PUNCH_DUAL_LEFT
:
4621 case IPP_FINISHINGS_PUNCH_DUAL_TOP
:
4622 case IPP_FINISHINGS_PUNCH_DUAL_RIGHT
:
4623 case IPP_FINISHINGS_PUNCH_DUAL_BOTTOM
:
4624 case IPP_FINISHINGS_PUNCH_TRIPLE_LEFT
:
4625 case IPP_FINISHINGS_PUNCH_TRIPLE_TOP
:
4626 case IPP_FINISHINGS_PUNCH_TRIPLE_RIGHT
:
4627 case IPP_FINISHINGS_PUNCH_TRIPLE_BOTTOM
:
4628 case IPP_FINISHINGS_PUNCH_QUAD_LEFT
:
4629 case IPP_FINISHINGS_PUNCH_QUAD_TOP
:
4630 case IPP_FINISHINGS_PUNCH_QUAD_RIGHT
:
4631 case IPP_FINISHINGS_PUNCH_QUAD_BOTTOM
:
4632 p
->type
|= CUPS_PRINTER_PUNCH
;
4635 case IPP_FINISHINGS_STAPLE
:
4636 case IPP_FINISHINGS_STAPLE_TOP_LEFT
:
4637 case IPP_FINISHINGS_STAPLE_BOTTOM_LEFT
:
4638 case IPP_FINISHINGS_STAPLE_TOP_RIGHT
:
4639 case IPP_FINISHINGS_STAPLE_BOTTOM_RIGHT
:
4640 case IPP_FINISHINGS_STAPLE_DUAL_LEFT
:
4641 case IPP_FINISHINGS_STAPLE_DUAL_TOP
:
4642 case IPP_FINISHINGS_STAPLE_DUAL_RIGHT
:
4643 case IPP_FINISHINGS_STAPLE_DUAL_BOTTOM
:
4644 case IPP_FINISHINGS_STAPLE_TRIPLE_LEFT
:
4645 case IPP_FINISHINGS_STAPLE_TRIPLE_TOP
:
4646 case IPP_FINISHINGS_STAPLE_TRIPLE_RIGHT
:
4647 case IPP_FINISHINGS_STAPLE_TRIPLE_BOTTOM
:
4648 p
->type
|= CUPS_PRINTER_STAPLE
;
4657 for (i
= 0; i
< ppd
->num_sizes
; i
++)
4658 if (ppd
->sizes
[i
].length
> 1728)
4659 p
->type
|= CUPS_PRINTER_LARGE
;
4660 else if (ppd
->sizes
[i
].length
> 1008)
4661 p
->type
|= CUPS_PRINTER_MEDIUM
;
4663 p
->type
|= CUPS_PRINTER_SMALL
;
4665 if ((ppd_attr
= ppdFindAttr(ppd
, "APICADriver", NULL
)) != NULL
&&
4666 ppd_attr
->value
&& !_cups_strcasecmp(ppd_attr
->value
, "true"))
4668 if ((ppd_attr
= ppdFindAttr(ppd
, "APScannerOnly", NULL
)) != NULL
&&
4669 ppd_attr
->value
&& !_cups_strcasecmp(ppd_attr
->value
, "true"))
4670 p
->type
|= CUPS_PRINTER_SCANNER
;
4672 p
->type
|= CUPS_PRINTER_MFP
;
4676 * Scan the filters in the PPD file...
4681 for (filter
= (const char *)cupsArrayFirst(p
->pc
->filters
);
4683 filter
= (const char *)cupsArrayNext(p
->pc
->filters
))
4685 if (!_cups_strncasecmp(filter
, "application/vnd.cups-command", 28) &&
4686 _cups_isspace(filter
[28]))
4688 p
->type
|= CUPS_PRINTER_COMMANDS
;
4694 if (p
->type
& CUPS_PRINTER_COMMANDS
)
4696 char *commands
, /* Copy of commands */
4697 *start
, /* Start of name */
4698 *end
; /* End of name */
4699 int count
; /* Number of commands */
4701 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsCommands", NULL
)) != NULL
)
4703 for (count
= 0, start
= ppd_attr
->value
; *start
; count
++)
4705 while (_cups_isspace(*start
))
4711 while (*start
&& !isspace(*start
& 255))
4721 * Make a copy of the commands string and count how many commands there
4725 attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4726 "printer-commands", count
, NULL
, NULL
);
4728 commands
= strdup(ppd_attr
->value
);
4730 for (count
= 0, start
= commands
; *start
; count
++)
4732 while (isspace(*start
& 255))
4739 while (*end
&& !isspace(*end
& 255))
4745 attr
->values
[count
].string
.text
= _cupsStrAlloc(start
);
4755 * Add the standard list of commands...
4758 ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4760 (int)(sizeof(standard_commands
) /
4761 sizeof(standard_commands
[0])), NULL
,
4768 * No commands supported...
4771 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4772 "printer-commands", NULL
, "none");
4776 * Show current and available port monitors for this printer...
4779 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
, "port-monitor",
4780 NULL
, p
->port_monitor
? p
->port_monitor
: "none");
4782 for (i
= 1, ppd_attr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
4784 i
++, ppd_attr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
));
4788 if (strstr(ppd
->protocols
, "TBCP"))
4790 else if (strstr(ppd
->protocols
, "BCP"))
4794 attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
4795 "port-monitor-supported", i
, NULL
, NULL
);
4797 attr
->values
[0].string
.text
= _cupsStrAlloc("none");
4799 for (i
= 1, ppd_attr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
4801 i
++, ppd_attr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
))
4802 attr
->values
[i
].string
.text
= _cupsStrAlloc(ppd_attr
->value
);
4806 if (strstr(ppd
->protocols
, "TBCP"))
4807 attr
->values
[i
].string
.text
= _cupsStrAlloc("tbcp");
4808 else if (strstr(ppd
->protocols
, "BCP"))
4809 attr
->values
[i
].string
.text
= _cupsStrAlloc("bcp");
4812 if (ppdFindAttr(ppd
, "APRemoteQueueID", NULL
))
4813 p
->type
|= CUPS_PRINTER_REMOTE
;
4815 #ifdef HAVE_APPLICATIONSERVICES_H
4817 * Convert the file referenced in APPrinterIconPath to a 128x128 PNG
4818 * and save it as cacheDir/printername.png
4821 if ((ppd_attr
= ppdFindAttr(ppd
, "APPrinterIconPath", NULL
)) != NULL
&&
4823 !_cupsFileCheck(ppd_attr
->value
, _CUPS_FILE_CHECK_FILE
, !RunUser
,
4824 cupsdLogFCMessage
, p
))
4826 CGImageRef imageRef
= NULL
;/* Current icon image */
4827 CGImageRef biggestIconRef
= NULL
;
4828 /* Biggest icon image */
4829 CGImageRef closestTo128IconRef
= NULL
;
4830 /* Icon image closest to and >= 128 */
4831 CGImageSourceRef sourceRef
; /* The file's image source */
4832 char outPath
[HTTP_MAX_URI
];
4833 /* The path to the PNG file */
4834 CFURLRef outUrl
; /* The URL made from the outPath */
4835 CFURLRef icnsFileUrl
; /* The URL of the original ICNS icon file */
4836 CGImageDestinationRef destRef
; /* The image destination to write */
4837 size_t bytesPerRow
; /* The bytes per row used for resizing */
4838 CGContextRef context
; /* The CG context used for resizing */
4840 snprintf(outPath
, sizeof(outPath
), "%s/%s.png", CacheDir
, p
->name
);
4841 outUrl
= CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault
, (UInt8
*)outPath
, (CFIndex
)strlen(outPath
), FALSE
);
4842 icnsFileUrl
= CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault
, (UInt8
*)ppd_attr
->value
, (CFIndex
)strlen(ppd_attr
->value
), FALSE
);
4843 if (outUrl
&& icnsFileUrl
)
4845 sourceRef
= CGImageSourceCreateWithURL(icnsFileUrl
, NULL
);
4848 for (i
= 0; i
< (int)CGImageSourceGetCount(sourceRef
); i
++)
4850 imageRef
= CGImageSourceCreateImageAtIndex(sourceRef
, (size_t)i
, NULL
);
4854 if (CGImageGetWidth(imageRef
) == CGImageGetHeight(imageRef
))
4857 * Loop through remembering the icon closest to 128 but >= 128
4858 * and then remember the largest icon.
4861 if (CGImageGetWidth(imageRef
) >= 128 &&
4862 (!closestTo128IconRef
||
4863 CGImageGetWidth(imageRef
) <
4864 CGImageGetWidth(closestTo128IconRef
)))
4866 CGImageRelease(closestTo128IconRef
);
4867 CGImageRetain(imageRef
);
4868 closestTo128IconRef
= imageRef
;
4871 if (!biggestIconRef
||
4872 CGImageGetWidth(imageRef
) > CGImageGetWidth(biggestIconRef
))
4874 CGImageRelease(biggestIconRef
);
4875 CGImageRetain(imageRef
);
4876 biggestIconRef
= imageRef
;
4880 CGImageRelease(imageRef
);
4886 * If biggestIconRef is NULL, we found no icons. Otherwise we first
4887 * want the closest to 128, but if none are larger than 128, we want
4888 * the largest icon available.
4891 imageRef
= closestTo128IconRef
? closestTo128IconRef
:
4893 CGImageRetain(imageRef
);
4894 CGImageRelease(biggestIconRef
);
4895 if (closestTo128IconRef
)
4896 CGImageRelease(closestTo128IconRef
);
4897 destRef
= CGImageDestinationCreateWithURL(outUrl
, kUTTypePNG
, 1,
4901 if (CGImageGetWidth(imageRef
) != 128)
4903 bytesPerRow
= CGImageGetBytesPerRow(imageRef
) /
4904 CGImageGetWidth(imageRef
) * 128;
4905 context
= CGBitmapContextCreate(NULL
, 128, 128,
4906 CGImageGetBitsPerComponent(imageRef
),
4908 CGImageGetColorSpace(imageRef
),
4909 kCGImageAlphaPremultipliedFirst
);
4912 CGContextDrawImage(context
, CGRectMake(0, 0, 128, 128),
4914 CGImageRelease(imageRef
);
4915 imageRef
= CGBitmapContextCreateImage(context
);
4916 CGContextRelease(context
);
4920 CGImageDestinationAddImage(destRef
, imageRef
, NULL
);
4921 CGImageDestinationFinalize(destRef
);
4925 CGImageRelease(imageRef
);
4928 CFRelease(sourceRef
);
4936 CFRelease(icnsFileUrl
);
4938 #endif /* HAVE_APPLICATIONSERVICES_H */
4941 * Close the PPD and set the type...
4946 else if (!access(ppd_name
, 0))
4948 int pline
; /* PPD line number */
4949 ppd_status_t pstatus
; /* PPD load status */
4952 pstatus
= ppdLastError(&pline
);
4954 cupsdLogMessage(CUPSD_LOG_ERROR
, "PPD file for %s cannot be loaded.", p
->name
);
4956 if (pstatus
<= PPD_ALLOC_ERROR
)
4957 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: %s", ppd_name
, strerror(errno
));
4959 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s on line %d of %s.", ppdErrorString(pstatus
), pline
, ppd_name
);
4961 cupsdLogMessage(CUPSD_LOG_INFO
,
4962 "Hint: Run \"cupstestppd %s\" and fix any errors.",
4967 if (((!strncmp(p
->device_uri
, "ipp://", 6) ||
4968 !strncmp(p
->device_uri
, "ipps://", 7)) &&
4969 (strstr(p
->device_uri
, "/printers/") != NULL
||
4970 strstr(p
->device_uri
, "/classes/") != NULL
)) ||
4971 ((strstr(p
->device_uri
, "._ipp.") != NULL
||
4972 strstr(p
->device_uri
, "._ipps.") != NULL
) &&
4973 !strcmp(p
->device_uri
+ strlen(p
->device_uri
) - 5, "/cups")))
4976 * Tell the client this is really a hard-wired remote printer.
4979 p
->type
|= CUPS_PRINTER_REMOTE
;
4982 * Point the printer-uri-supported attribute to the
4986 if (strchr(p
->device_uri
, '?'))
4989 * Strip trailing "?options" from URI...
4992 char resource
[HTTP_MAX_URI
], /* New URI */
4993 *ptr
; /* Pointer into URI */
4995 strlcpy(resource
, p
->device_uri
, sizeof(resource
));
4996 if ((ptr
= strchr(resource
, '?')) != NULL
)
4999 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
5000 "printer-uri-supported", NULL
, resource
);
5003 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
5004 "printer-uri-supported", NULL
, p
->device_uri
);
5007 * Then set the make-and-model accordingly...
5010 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
5011 "printer-make-and-model", NULL
, "Remote Printer");
5014 * Print all files directly...
5023 * Otherwise we have neither - treat this as a "dumb" printer
5024 * with no PPD file...
5027 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
5028 "printer-make-and-model", NULL
, "Local Raw Printer");
5034 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
5035 "finishings-supported", num_finishings
, finishings
);
5036 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
5037 "finishings-default", IPP_FINISHINGS_NONE
);
5042 * Save cached PPD attributes to disk...
5045 cupsdLogMessage(CUPSD_LOG_DEBUG
, "load_ppd: Saving %s...", cache_name
);
5047 _ppdCacheWriteFile(p
->pc
, cache_name
, p
->ppd_attrs
);
5052 * Remove cache files...
5055 if (cache_info
.st_mtime
)
5062 * 'new_media_col()' - Create a media-col collection value.
5065 static ipp_t
* /* O - Collection value */
5066 new_media_col(pwg_size_t
*size
, /* I - media-size/margin values */
5067 const char *source
, /* I - media-source value */
5068 const char *type
) /* I - media-type value */
5070 ipp_t
*media_col
, /* Collection value */
5071 *media_size
; /* media-size value */
5074 media_col
= ippNew();
5076 media_size
= ippNew();
5077 ippAddInteger(media_size
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5078 "x-dimension", size
->width
);
5079 ippAddInteger(media_size
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5080 "y-dimension", size
->length
);
5081 ippAddCollection(media_col
, IPP_TAG_PRINTER
, "media-size", media_size
);
5082 ippDelete(media_size
);
5084 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5085 "media-bottom-margin", size
->bottom
);
5086 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5087 "media-left-margin", size
->left
);
5088 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5089 "media-right-margin", size
->right
);
5090 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5091 "media-top-margin", size
->top
);
5094 ippAddString(media_col
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
, "media-source",
5098 ippAddString(media_col
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
, "media-type",
5106 * 'write_xml_string()' - Write a string with XML escaping.
5110 write_xml_string(cups_file_t
*fp
, /* I - File to write to */
5111 const char *s
) /* I - String to write */
5113 const char *start
; /* Start of current sequence */
5119 for (start
= s
; *s
; s
++)
5124 cupsFileWrite(fp
, start
, (size_t)(s
- start
));
5126 cupsFilePuts(fp
, "&");
5132 cupsFileWrite(fp
, start
, (size_t)(s
- start
));
5134 cupsFilePuts(fp
, "<");
5140 cupsFilePuts(fp
, start
);