4 * Printer routines for the CUPS scheduler.
6 * Copyright 2007-2016 by Apple Inc.
7 * Copyright 1997-2007 by Easy Software Products, all rights reserved.
9 * These coded instructions, statements, and computer programs are the
10 * property of Apple Inc. and are protected by Federal copyright
11 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
12 * which should have been included with this file. If this file is
13 * file is missing or damaged, see the license at "http://www.cups.org/".
17 * Include necessary headers...
22 #ifdef HAVE_APPLICATIONSERVICES_H
23 # include <ApplicationServices/ApplicationServices.h>
24 #endif /* HAVE_APPLICATIONSERVICES_H */
25 #ifdef HAVE_SYS_MOUNT_H
26 # include <sys/mount.h>
27 #endif /* HAVE_SYS_MOUNT_H */
28 #ifdef HAVE_SYS_STATVFS_H
29 # include <sys/statvfs.h>
30 #elif defined(HAVE_SYS_STATFS_H)
31 # include <sys/statfs.h>
32 #endif /* HAVE_SYS_STATVFS_H */
35 #endif /* HAVE_SYS_VFS_H */
38 #endif /* __APPLE__ */
45 static void add_printer_defaults(cupsd_printer_t
*p
);
46 static void add_printer_filter(cupsd_printer_t
*p
, mime_type_t
*type
,
48 static void add_printer_formats(cupsd_printer_t
*p
);
49 static int compare_printers(void *first
, void *second
, void *data
);
50 static void delete_printer_filters(cupsd_printer_t
*p
);
51 static void dirty_printer(cupsd_printer_t
*p
);
52 static void load_ppd(cupsd_printer_t
*p
);
53 static ipp_t
*new_media_col(_pwg_size_t
*size
, const char *source
,
55 static void write_xml_string(cups_file_t
*fp
, const char *s
);
59 * 'cupsdAddPrinter()' - Add a printer to the system.
62 cupsd_printer_t
* /* O - New printer */
63 cupsdAddPrinter(const char *name
) /* I - Name of printer */
65 cupsd_printer_t
*p
; /* New printer */
66 char uri
[1024], /* Printer URI */
67 uuid
[64]; /* Printer UUID */
71 * Range check input...
74 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdAddPrinter(\"%s\")", name
);
77 * Create a new printer entity...
80 if ((p
= calloc(1, sizeof(cupsd_printer_t
))) == NULL
)
82 cupsdLogMessage(CUPSD_LOG_CRIT
, "Unable to allocate memory for printer - %s",
87 _cupsRWInit(&p
->lock
);
89 cupsdSetString(&p
->name
, name
);
90 cupsdSetString(&p
->info
, name
);
91 cupsdSetString(&p
->hostname
, ServerName
);
93 httpAssembleURIf(HTTP_URI_CODING_ALL
, uri
, sizeof(uri
), "ipp", NULL
,
94 ServerName
, RemotePort
, "/printers/%s", name
);
95 cupsdSetString(&p
->uri
, uri
);
96 cupsdSetString(&p
->uuid
, httpAssembleUUID(ServerName
, RemotePort
, name
, 0,
98 cupsdSetDeviceURI(p
, "file:///dev/null");
100 p
->config_time
= time(NULL
);
101 p
->state
= IPP_PRINTER_STOPPED
;
102 p
->state_time
= time(NULL
);
104 p
->shared
= DefaultShared
;
105 p
->filetype
= mimeAddType(MimeDatabase
, "printer", name
);
107 cupsdSetString(&p
->job_sheets
[0], "none");
108 cupsdSetString(&p
->job_sheets
[1], "none");
110 cupsdSetString(&p
->error_policy
, ErrorPolicy
);
111 cupsdSetString(&p
->op_policy
, DefaultPolicy
);
113 p
->op_policy_ptr
= DefaultPolicyPtr
;
116 * Insert the printer in the printer list alphabetically...
120 Printers
= cupsArrayNew(compare_printers
, NULL
);
122 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
123 "cupsdAddPrinter: Adding %s to Printers", p
->name
);
124 cupsArrayAdd(Printers
, p
);
127 * Return the new printer...
135 * 'cupsdCreateCommonData()' - Create the common printer data.
139 cupsdCreateCommonData(void)
141 int i
; /* Looping var */
142 ipp_attribute_t
*attr
; /* Attribute data */
143 cups_dir_t
*dir
; /* Notifier directory */
144 cups_dentry_t
*dent
; /* Notifier directory entry */
145 cups_array_t
*notifiers
; /* Notifier array */
146 char filename
[1024], /* Filename */
147 *notifier
; /* Current notifier */
148 cupsd_policy_t
*p
; /* Current policy */
149 int k_supported
; /* Maximum file size supported */
151 struct statvfs spoolinfo
; /* FS info for spool directory */
152 double spoolsize
; /* FS size */
153 #elif defined(HAVE_STATFS)
154 struct statfs spoolinfo
; /* FS info for spool directory */
155 double spoolsize
; /* FS size */
156 #endif /* HAVE_STATVFS */
157 static const int nups
[] = /* number-up-supported values */
158 { 1, 2, 4, 6, 9, 16 };
159 static const int orients
[4] =/* orientation-requested-supported values */
163 IPP_REVERSE_LANDSCAPE
,
166 static const char * const holds
[] = /* job-hold-until-supported values */
177 static const char * const features
[] =/* ipp-features-supported values */
179 "subscription-object"
181 static const char * const versions
[] =/* ipp-versions-supported values */
188 static const int ops
[] = /* operations-supported values */
193 IPP_OP_SEND_DOCUMENT
,
195 IPP_OP_GET_JOB_ATTRIBUTES
,
197 IPP_OP_GET_PRINTER_ATTRIBUTES
,
200 IPP_OP_PAUSE_PRINTER
,
201 IPP_OP_RESUME_PRINTER
,
203 IPP_OP_SET_PRINTER_ATTRIBUTES
,
204 IPP_OP_SET_JOB_ATTRIBUTES
,
205 IPP_OP_GET_PRINTER_SUPPORTED_VALUES
,
206 IPP_OP_CREATE_PRINTER_SUBSCRIPTIONS
,
207 IPP_OP_CREATE_JOB_SUBSCRIPTIONS
,
208 IPP_OP_GET_SUBSCRIPTION_ATTRIBUTES
,
209 IPP_OP_GET_SUBSCRIPTIONS
,
210 IPP_OP_RENEW_SUBSCRIPTION
,
211 IPP_OP_CANCEL_SUBSCRIPTION
,
212 IPP_OP_GET_NOTIFICATIONS
,
213 IPP_OP_ENABLE_PRINTER
,
214 IPP_OP_DISABLE_PRINTER
,
215 IPP_OP_HOLD_NEW_JOBS
,
216 IPP_OP_RELEASE_HELD_NEW_JOBS
,
218 IPP_OP_CANCEL_MY_JOBS
,
220 IPP_OP_CUPS_GET_DEFAULT
,
221 IPP_OP_CUPS_GET_PRINTERS
,
222 IPP_OP_CUPS_ADD_MODIFY_PRINTER
,
223 IPP_OP_CUPS_DELETE_PRINTER
,
224 IPP_OP_CUPS_GET_CLASSES
,
225 IPP_OP_CUPS_ADD_MODIFY_CLASS
,
226 IPP_OP_CUPS_DELETE_CLASS
,
227 IPP_OP_CUPS_ACCEPT_JOBS
,
228 IPP_OP_CUPS_REJECT_JOBS
,
229 IPP_OP_CUPS_SET_DEFAULT
,
230 IPP_OP_CUPS_GET_DEVICES
,
231 IPP_OP_CUPS_GET_PPDS
,
232 IPP_OP_CUPS_MOVE_JOB
,
233 IPP_OP_CUPS_AUTHENTICATE_JOB
,
235 IPP_OP_CUPS_GET_DOCUMENT
,
238 static const char * const charsets
[] =/* charset-supported values */
243 static const char * const compressions
[] =
244 { /* document-compression-supported values */
248 #endif /* HAVE_LIBZ */
250 static const char * const media_col_supported
[] =
251 { /* media-col-supported values */
252 "media-bottom-margin",
254 "media-right-margin",
260 static const char * const multiple_document_handling
[] =
261 { /* multiple-document-handling-supported values */
262 "separate-documents-uncollated-copies",
263 "separate-documents-collated-copies"
265 static const char * const notify_attrs
[] =
266 { /* notify-attributes-supported values */
267 "printer-state-change-time",
268 "notify-lease-expiration-time",
269 "notify-subscriber-user-name"
271 static const char * const notify_events
[] =
272 { /* notify-events-supported values */
274 "job-config-changed",
281 "printer-config-changed",
283 "printer-finishings-changed",
284 "printer-media-changed",
288 "printer-state-changed",
295 static const char * const job_creation
[] =
296 { /* job-creation-attributes-supported */
299 "ipp-attribute-fidelity",
306 "multiple-document-handling",
309 "orientation-requested",
313 "printer-resolution",
316 static const char * const job_settable
[] =
317 { /* job-settable-attributes-supported */
325 "multiple-document-handling",
328 "orientation-requested",
332 "printer-resolution",
335 static const char * const pdf_versions
[] =
336 { /* pdf-versions-supported */
347 static const char * const printer_settable
[] =
348 { /* printer-settable-attributes-supported */
349 "printer-geo-location",
352 "printer-organization",
353 "printer-organizational-unit"
355 static const char * const which_jobs
[] =
356 { /* which-jobs-supported values */
370 ippDelete(CommonData
);
372 CommonData
= ippNew();
375 * Get the maximum spool size based on the size of the filesystem used for
376 * the RequestRoot directory. If the host OS doesn't support the statfs call
377 * or the filesystem is larger than 2TiB, always report INT_MAX.
381 if (statvfs(RequestRoot
, &spoolinfo
))
382 k_supported
= INT_MAX
;
383 else if ((spoolsize
= (double)spoolinfo
.f_frsize
* spoolinfo
.f_blocks
/ 1024) >
385 k_supported
= INT_MAX
;
387 k_supported
= (int)spoolsize
;
389 #elif defined(HAVE_STATFS)
390 if (statfs(RequestRoot
, &spoolinfo
))
391 k_supported
= INT_MAX
;
392 else if ((spoolsize
= (double)spoolinfo
.f_bsize
* spoolinfo
.f_blocks
/ 1024) >
394 k_supported
= INT_MAX
;
396 k_supported
= (int)spoolsize
;
399 k_supported
= INT_MAX
;
400 #endif /* HAVE_STATVFS */
403 * This list of attributes is sorted to improve performance when the
404 * client provides a requested-attributes attribute...
407 /* charset-configured */
408 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_CHARSET
| IPP_TAG_COPY
,
409 "charset-configured", NULL
, "utf-8");
411 /* charset-supported */
412 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_CHARSET
| IPP_TAG_COPY
,
413 "charset-supported", sizeof(charsets
) / sizeof(charsets
[0]),
416 /* compression-supported */
417 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
418 "compression-supported",
419 sizeof(compressions
) / sizeof(compressions
[0]),
422 /* copies-supported */
423 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "copies-supported", 1, MaxCopies
);
426 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
| IPP_TAG_COPY
,
427 "cups-version", NULL
, CUPS_SVERSION
+ 6);
429 /* generated-natural-language-supported (no IPP_TAG_COPY) */
430 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_LANGUAGE
,
431 "generated-natural-language-supported", NULL
, DefaultLanguage
);
433 /* ipp-features-supported */
434 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_CONST_TAG(IPP_TAG_KEYWORD
), "ipp-features-supported", sizeof(features
) / sizeof(features
[0]), NULL
, features
);
436 /* ipp-versions-supported */
437 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
438 "ipp-versions-supported", sizeof(versions
) / sizeof(versions
[0]),
441 /* ippget-event-life */
442 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
443 "ippget-event-life", 15);
445 /* job-cancel-after-supported */
446 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "job-cancel-after-supported",
449 /* job-creation-attributes-supported */
450 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
451 "job-creation-attributes-supported",
452 sizeof(job_creation
) / sizeof(job_creation
[0]),
455 /* job-hold-until-supported */
456 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
457 "job-hold-until-supported", sizeof(holds
) / sizeof(holds
[0]),
460 /* job-ids-supported */
461 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
, "job-ids-supported", 1);
463 /* job-k-octets-supported */
464 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "job-k-octets-supported", 0,
467 /* job-priority-supported */
468 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
469 "job-priority-supported", 100);
471 /* job-settable-attributes-supported */
472 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
473 "job-settable-attributes-supported",
474 sizeof(job_settable
) / sizeof(job_settable
[0]),
477 /* job-sheets-supported */
478 if (cupsArrayCount(Banners
) > 0)
481 * Setup the job-sheets-supported attribute...
484 if (Classification
&& !ClassifyOverride
)
485 attr
= ippAddString(CommonData
, IPP_TAG_PRINTER
,
486 IPP_TAG_NAME
| IPP_TAG_COPY
,
487 "job-sheets-supported", NULL
, Classification
);
489 attr
= ippAddStrings(CommonData
, IPP_TAG_PRINTER
,
490 IPP_TAG_NAME
| IPP_TAG_COPY
,
491 "job-sheets-supported", cupsArrayCount(Banners
) + 1,
495 cupsdLogMessage(CUPSD_LOG_EMERG
,
496 "Unable to allocate memory for "
497 "job-sheets-supported attribute: %s!", strerror(errno
));
498 else if (!Classification
|| ClassifyOverride
)
500 cupsd_banner_t
*banner
; /* Current banner */
503 attr
->values
[0].string
.text
= _cupsStrAlloc("none");
505 for (i
= 1, banner
= (cupsd_banner_t
*)cupsArrayFirst(Banners
);
507 i
++, banner
= (cupsd_banner_t
*)cupsArrayNext(Banners
))
508 attr
->values
[i
].string
.text
= banner
->name
;
512 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
513 "job-sheets-supported", NULL
, "none");
515 /* jpeg-k-octets-supported */
516 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "jpeg-k-octets-supported", 0,
519 /* jpeg-x-dimension-supported */
520 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "jpeg-x-dimension-supported", 0,
523 /* jpeg-y-dimension-supported */
524 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "jpeg-y-dimension-supported", 1,
527 /* media-col-supported */
528 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
529 "media-col-supported",
530 sizeof(media_col_supported
) /
531 sizeof(media_col_supported
[0]), NULL
,
532 media_col_supported
);
534 /* multiple-document-handling-supported */
535 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
536 "multiple-document-handling-supported",
537 sizeof(multiple_document_handling
) /
538 sizeof(multiple_document_handling
[0]), NULL
,
539 multiple_document_handling
);
541 /* multiple-document-jobs-supported */
542 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
,
543 "multiple-document-jobs-supported", 1);
545 /* multiple-operation-time-out */
546 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
547 "multiple-operation-time-out", MultipleOperationTimeout
);
549 /* multiple-operation-time-out-action */
550 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_CONST_TAG(IPP_TAG_KEYWORD
), "multiple-operation-time-out-action", NULL
, "process-job");
552 /* natural-language-configured (no IPP_TAG_COPY) */
553 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_LANGUAGE
,
554 "natural-language-configured", NULL
, DefaultLanguage
);
556 /* notify-attributes-supported */
557 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
558 "notify-attributes-supported",
559 (int)(sizeof(notify_attrs
) / sizeof(notify_attrs
[0])),
562 /* notify-lease-duration-supported */
563 ippAddRange(CommonData
, IPP_TAG_PRINTER
,
564 "notify-lease-duration-supported", 0,
565 MaxLeaseDuration
? MaxLeaseDuration
: 2147483647);
567 /* notify-max-events-supported */
568 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
569 "notify-max-events-supported", MaxEvents
);
571 /* notify-events-supported */
572 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
573 "notify-events-supported",
574 (int)(sizeof(notify_events
) / sizeof(notify_events
[0])),
575 NULL
, notify_events
);
577 /* notify-pull-method-supported */
578 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
579 "notify-pull-method-supported", NULL
, "ippget");
581 /* notify-schemes-supported */
582 snprintf(filename
, sizeof(filename
), "%s/notifier", ServerBin
);
583 if ((dir
= cupsDirOpen(filename
)) != NULL
)
585 notifiers
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
587 while ((dent
= cupsDirRead(dir
)) != NULL
)
588 if (S_ISREG(dent
->fileinfo
.st_mode
) &&
589 (dent
->fileinfo
.st_mode
& S_IXOTH
) != 0)
590 cupsArrayAdd(notifiers
, _cupsStrAlloc(dent
->filename
));
592 if (cupsArrayCount(notifiers
) > 0)
594 attr
= ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
595 "notify-schemes-supported",
596 cupsArrayCount(notifiers
), NULL
, NULL
);
598 for (i
= 0, notifier
= (char *)cupsArrayFirst(notifiers
);
600 i
++, notifier
= (char *)cupsArrayNext(notifiers
))
601 attr
->values
[i
].string
.text
= notifier
;
604 cupsArrayDelete(notifiers
);
608 /* number-up-supported */
609 ippAddIntegers(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
610 "number-up-supported", sizeof(nups
) / sizeof(nups
[0]), nups
);
612 /* operations-supported */
613 ippAddIntegers(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
614 "operations-supported", sizeof(ops
) / sizeof(ops
[0]), ops
);
616 /* orientation-requested-supported */
617 ippAddIntegers(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
618 "orientation-requested-supported", 4, orients
);
620 /* page-ranges-supported */
621 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
, "page-ranges-supported", 1);
623 /* pdf-k-octets-supported */
624 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "pdf-k-octets-supported", 0,
627 /* pdf-versions-supported */
628 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
629 "pdf-versions-supported",
630 sizeof(pdf_versions
) / sizeof(pdf_versions
[0]), NULL
,
633 /* pdl-override-supported */
634 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
635 "pdl-override-supported", NULL
, "attempted");
637 /* printer-get-attributes-supported */
638 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_CONST_TAG(IPP_TAG_KEYWORD
), "printer-get-attributes-supported", NULL
, "document-format");
640 /* printer-op-policy-supported */
641 attr
= ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
642 "printer-op-policy-supported", cupsArrayCount(Policies
),
644 for (i
= 0, p
= (cupsd_policy_t
*)cupsArrayFirst(Policies
);
646 i
++, p
= (cupsd_policy_t
*)cupsArrayNext(Policies
))
647 attr
->values
[i
].string
.text
= p
->name
;
649 /* printer-settable-attributes-supported */
650 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
651 "printer-settable-attributes-supported",
652 sizeof(printer_settable
) / sizeof(printer_settable
[0]),
653 NULL
, printer_settable
);
655 /* server-is-sharing-printers */
656 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
, "server-is-sharing-printers",
657 BrowseLocalProtocols
!= 0 && Browsing
);
659 /* which-jobs-supported */
660 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
661 "which-jobs-supported",
662 sizeof(which_jobs
) / sizeof(which_jobs
[0]), NULL
, which_jobs
);
667 * 'cupsdDeleteAllPrinters()' - Delete all printers from the system.
671 cupsdDeleteAllPrinters(void)
673 cupsd_printer_t
*p
; /* Pointer to current printer/class */
676 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
678 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
680 p
->op_policy_ptr
= DefaultPolicyPtr
;
681 cupsdDeletePrinter(p
, 0);
687 * 'cupsdDeletePrinter()' - Delete a printer from the system.
690 int /* O - 1 if classes affected, 0 otherwise */
692 cupsd_printer_t
*p
, /* I - Printer to delete */
693 int update
) /* I - Update printers.conf? */
695 int i
, /* Looping var */
696 changed
= 0; /* Class changed? */
699 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdDeletePrinter(p=%p(%s), update=%d)",
703 * Save the current position in the Printers array...
706 cupsArraySave(Printers
);
709 * Stop printing on this printer...
712 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, update
);
714 p
->state
= IPP_PRINTER_STOPPED
; /* Force for browsed printers */
717 cupsdSetJobState(p
->job
, IPP_JOB_PENDING
, CUPSD_JOB_FORCE
,
718 update
? "Job stopped due to printer being deleted." :
722 * Remove the printer from the list...
725 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
726 "cupsdDeletePrinter: Removing %s from Printers", p
->name
);
727 cupsArrayRemove(Printers
, p
);
730 * If p is the default printer, assign a different one...
733 if (p
== DefaultPrinter
)
734 DefaultPrinter
= NULL
;
737 * Remove this printer from any classes...
740 changed
= cupsdDeletePrinterFromClasses(p
);
743 * Deregister from any browse protocols...
746 cupsdDeregisterPrinter(p
, 1);
749 * Remove support files if this is a temporary queue and deregister color
755 char filename
[1024]; /* Script/PPD filename */
758 * Remove any old PPD or script files...
761 snprintf(filename
, sizeof(filename
), "%s/interfaces/%s", ServerRoot
, p
->name
);
763 snprintf(filename
, sizeof(filename
), "%s/interfaces/%s.O", ServerRoot
, p
->name
);
766 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
, p
->name
);
768 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd.O", ServerRoot
, p
->name
);
771 snprintf(filename
, sizeof(filename
), "%s/%s.png", CacheDir
, p
->name
);
774 snprintf(filename
, sizeof(filename
), "%s/%s.data", CacheDir
, p
->name
);
778 * Unregister color profiles...
781 cupsdUnregisterColor(p
);
785 * Free all memory used by the printer...
788 if (p
->printers
!= NULL
)
791 delete_printer_filters(p
);
793 for (i
= 0; i
< p
->num_reasons
; i
++)
794 _cupsStrFree(p
->reasons
[i
]);
797 ippDelete(p
->ppd_attrs
);
799 mimeDeleteType(MimeDatabase
, p
->filetype
);
800 mimeDeleteType(MimeDatabase
, p
->prefiltertype
);
802 cupsdFreeStrings(&(p
->users
));
805 cupsdClearString(&p
->uri
);
806 cupsdClearString(&p
->hostname
);
807 cupsdClearString(&p
->name
);
808 cupsdClearString(&p
->location
);
809 cupsdClearString(&p
->geo_location
);
810 cupsdClearString(&p
->make_model
);
811 cupsdClearString(&p
->info
);
812 cupsdClearString(&p
->job_sheets
[0]);
813 cupsdClearString(&p
->job_sheets
[1]);
814 cupsdClearString(&p
->device_uri
);
815 cupsdClearString(&p
->sanitized_device_uri
);
816 cupsdClearString(&p
->port_monitor
);
817 cupsdClearString(&p
->op_policy
);
818 cupsdClearString(&p
->error_policy
);
820 cupsdClearString(&p
->alert
);
821 cupsdClearString(&p
->alert_description
);
823 #if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
824 cupsdClearString(&p
->pdl
);
825 cupsdClearString(&p
->reg_name
);
826 #endif /* HAVE_DNSSD || HAVE_AVAHI */
828 cupsArrayDelete(p
->filetypes
);
830 cupsFreeOptions(p
->num_options
, p
->options
);
835 * Restore the previous position in the Printers array...
838 cupsArrayRestore(Printers
);
845 * 'cupsdFindDest()' - Find a destination in the list.
848 cupsd_printer_t
* /* O - Destination in list */
849 cupsdFindDest(const char *name
) /* I - Name of printer or class to find */
851 cupsd_printer_t key
; /* Search key */
854 key
.name
= (char *)name
;
855 return ((cupsd_printer_t
*)cupsArrayFind(Printers
, &key
));
860 * 'cupsdFindPrinter()' - Find a printer in the list.
863 cupsd_printer_t
* /* O - Printer in list */
864 cupsdFindPrinter(const char *name
) /* I - Name of printer to find */
866 cupsd_printer_t
*p
; /* Printer in list */
869 if ((p
= cupsdFindDest(name
)) != NULL
&& (p
->type
& CUPS_PRINTER_CLASS
))
877 * 'cupsdLoadAllPrinters()' - Load printers from the printers.conf file.
881 cupsdLoadAllPrinters(void)
883 int i
; /* Looping var */
884 cups_file_t
*fp
; /* printers.conf file */
885 int linenum
; /* Current line number */
886 char line
[4096], /* Line from file */
887 *value
, /* Pointer to value */
888 *valueptr
; /* Pointer into value */
889 cupsd_printer_t
*p
; /* Current printer */
893 * Open the printers.conf file...
896 snprintf(line
, sizeof(line
), "%s/printers.conf", ServerRoot
);
897 if ((fp
= cupsdOpenConfFile(line
)) == NULL
)
901 * Read printer configurations until we hit EOF...
907 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
910 * Decode the directive...
913 if (!_cups_strcasecmp(line
, "<Printer") ||
914 !_cups_strcasecmp(line
, "<DefaultPrinter"))
917 * <Printer name> or <DefaultPrinter name>
920 if (p
== NULL
&& value
)
923 * Add the printer and a base file type...
926 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Loading printer %s...", value
);
928 p
= cupsdAddPrinter(value
);
930 p
->state
= IPP_PRINTER_IDLE
;
933 * Set the default printer as needed...
936 if (!_cups_strcasecmp(line
, "<DefaultPrinter"))
940 cupsdLogMessage(CUPSD_LOG_ERROR
,
941 "Syntax error on line %d of printers.conf.", linenum
);
943 else if (!_cups_strcasecmp(line
, "</Printer>") || !_cups_strcasecmp(line
, "</DefaultPrinter>"))
948 * Close out the current printer...
951 cupsdSetPrinterAttrs(p
);
953 if (strncmp(p
->device_uri
, "file:", 5) &&
954 p
->state
!= IPP_PRINTER_STOPPED
)
957 * See if the backend exists...
960 snprintf(line
, sizeof(line
), "%s/backend/%s", ServerBin
,
963 if ((valueptr
= strchr(line
+ strlen(ServerBin
), ':')) != NULL
)
964 *valueptr
= '\0'; /* Chop everything but URI scheme */
969 * Backend does not exist, stop printer...
972 p
->state
= IPP_PRINTER_STOPPED
;
973 snprintf(p
->state_message
, sizeof(p
->state_message
),
974 "Backend %s does not exist!", line
);
981 cupsdLogMessage(CUPSD_LOG_ERROR
,
982 "Syntax error on line %d of printers.conf.", linenum
);
986 cupsdLogMessage(CUPSD_LOG_ERROR
,
987 "Syntax error on line %d of printers.conf.", linenum
);
989 else if (!_cups_strcasecmp(line
, "UUID"))
991 if (value
&& !strncmp(value
, "urn:uuid:", 9))
992 cupsdSetString(&(p
->uuid
), value
);
994 cupsdLogMessage(CUPSD_LOG_ERROR
,
995 "Bad UUID on line %d of printers.conf.", linenum
);
997 else if (!_cups_strcasecmp(line
, "AuthInfoRequired"))
999 if (!cupsdSetAuthInfoRequired(p
, value
, NULL
))
1000 cupsdLogMessage(CUPSD_LOG_ERROR
,
1001 "Bad AuthInfoRequired on line %d of printers.conf.",
1004 else if (!_cups_strcasecmp(line
, "Info"))
1007 cupsdSetString(&p
->info
, value
);
1009 else if (!_cups_strcasecmp(line
, "MakeModel"))
1012 cupsdSetString(&p
->make_model
, value
);
1014 else if (!_cups_strcasecmp(line
, "Location"))
1017 cupsdSetString(&p
->location
, value
);
1019 else if (!_cups_strcasecmp(line
, "GeoLocation"))
1022 cupsdSetString(&p
->geo_location
, value
);
1024 else if (!_cups_strcasecmp(line
, "Organization"))
1027 cupsdSetString(&p
->organization
, value
);
1029 else if (!_cups_strcasecmp(line
, "OrganizationalUnit"))
1032 cupsdSetString(&p
->organizational_unit
, value
);
1034 else if (!_cups_strcasecmp(line
, "DeviceURI"))
1037 cupsdSetDeviceURI(p
, value
);
1039 cupsdLogMessage(CUPSD_LOG_ERROR
,
1040 "Syntax error on line %d of printers.conf.", linenum
);
1042 else if (!_cups_strcasecmp(line
, "Option") && value
)
1048 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1051 cupsdLogMessage(CUPSD_LOG_ERROR
,
1052 "Syntax error on line %d of printers.conf.", linenum
);
1055 for (; *valueptr
&& isspace(*valueptr
& 255); *valueptr
++ = '\0');
1057 p
->num_options
= cupsAddOption(value
, valueptr
, p
->num_options
,
1061 else if (!_cups_strcasecmp(line
, "PortMonitor"))
1063 if (value
&& strcmp(value
, "none"))
1064 cupsdSetString(&p
->port_monitor
, value
);
1066 cupsdClearString(&p
->port_monitor
);
1068 cupsdLogMessage(CUPSD_LOG_ERROR
,
1069 "Syntax error on line %d of printers.conf.", linenum
);
1071 else if (!_cups_strcasecmp(line
, "Reason"))
1074 strcmp(value
, "connecting-to-device") &&
1075 strcmp(value
, "cups-insecure-filter-warning") &&
1076 strcmp(value
, "cups-missing-filter-warning"))
1078 for (i
= 0 ; i
< p
->num_reasons
; i
++)
1079 if (!strcmp(value
, p
->reasons
[i
]))
1082 if (i
>= p
->num_reasons
&&
1083 p
->num_reasons
< (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
1085 p
->reasons
[p
->num_reasons
] = _cupsStrAlloc(value
);
1090 cupsdLogMessage(CUPSD_LOG_ERROR
,
1091 "Syntax error on line %d of printers.conf.", linenum
);
1093 else if (!_cups_strcasecmp(line
, "State"))
1096 * Set the initial queue state...
1099 if (value
&& !_cups_strcasecmp(value
, "idle"))
1100 p
->state
= IPP_PRINTER_IDLE
;
1101 else if (value
&& !_cups_strcasecmp(value
, "stopped"))
1103 p
->state
= IPP_PRINTER_STOPPED
;
1105 for (i
= 0 ; i
< p
->num_reasons
; i
++)
1106 if (!strcmp("paused", p
->reasons
[i
]))
1109 if (i
>= p
->num_reasons
&&
1110 p
->num_reasons
< (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
1112 p
->reasons
[p
->num_reasons
] = _cupsStrAlloc("paused");
1117 cupsdLogMessage(CUPSD_LOG_ERROR
,
1118 "Syntax error on line %d of printers.conf.", linenum
);
1120 else if (!_cups_strcasecmp(line
, "StateMessage"))
1123 * Set the initial queue state message...
1127 strlcpy(p
->state_message
, value
, sizeof(p
->state_message
));
1129 else if (!_cups_strcasecmp(line
, "StateTime"))
1132 * Set the state time...
1136 p
->state_time
= atoi(value
);
1138 else if (!_cups_strcasecmp(line
, "ConfigTime"))
1141 * Set the config time...
1145 p
->config_time
= atoi(value
);
1147 else if (!_cups_strcasecmp(line
, "Accepting"))
1150 * Set the initial accepting state...
1154 (!_cups_strcasecmp(value
, "yes") ||
1155 !_cups_strcasecmp(value
, "on") ||
1156 !_cups_strcasecmp(value
, "true")))
1159 (!_cups_strcasecmp(value
, "no") ||
1160 !_cups_strcasecmp(value
, "off") ||
1161 !_cups_strcasecmp(value
, "false")))
1164 cupsdLogMessage(CUPSD_LOG_ERROR
,
1165 "Syntax error on line %d of printers.conf.", linenum
);
1167 else if (!_cups_strcasecmp(line
, "Type"))
1170 p
->type
= (cups_ptype_t
)atoi(value
);
1172 cupsdLogMessage(CUPSD_LOG_ERROR
,
1173 "Syntax error on line %d of printers.conf.", linenum
);
1175 else if (!_cups_strcasecmp(line
, "Shared"))
1178 * Set the initial shared state...
1182 (!_cups_strcasecmp(value
, "yes") ||
1183 !_cups_strcasecmp(value
, "on") ||
1184 !_cups_strcasecmp(value
, "true")))
1187 (!_cups_strcasecmp(value
, "no") ||
1188 !_cups_strcasecmp(value
, "off") ||
1189 !_cups_strcasecmp(value
, "false")))
1192 cupsdLogMessage(CUPSD_LOG_ERROR
,
1193 "Syntax error on line %d of printers.conf.", linenum
);
1195 else if (!_cups_strcasecmp(line
, "JobSheets"))
1198 * Set the initial job sheets...
1203 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1208 cupsdSetString(&p
->job_sheets
[0], value
);
1210 while (isspace(*valueptr
& 255))
1215 for (value
= valueptr
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1220 cupsdSetString(&p
->job_sheets
[1], value
);
1224 cupsdLogMessage(CUPSD_LOG_ERROR
,
1225 "Syntax error on line %d of printers.conf.", linenum
);
1227 else if (!_cups_strcasecmp(line
, "AllowUser"))
1232 cupsdAddString(&(p
->users
), value
);
1235 cupsdLogMessage(CUPSD_LOG_ERROR
,
1236 "Syntax error on line %d of printers.conf.", linenum
);
1238 else if (!_cups_strcasecmp(line
, "DenyUser"))
1243 cupsdAddString(&(p
->users
), value
);
1246 cupsdLogMessage(CUPSD_LOG_ERROR
,
1247 "Syntax error on line %d of printers.conf.", linenum
);
1249 else if (!_cups_strcasecmp(line
, "QuotaPeriod"))
1252 p
->quota_period
= atoi(value
);
1254 cupsdLogMessage(CUPSD_LOG_ERROR
,
1255 "Syntax error on line %d of printers.conf.", linenum
);
1257 else if (!_cups_strcasecmp(line
, "PageLimit"))
1260 p
->page_limit
= atoi(value
);
1262 cupsdLogMessage(CUPSD_LOG_ERROR
,
1263 "Syntax error on line %d of printers.conf.", linenum
);
1265 else if (!_cups_strcasecmp(line
, "KLimit"))
1268 p
->k_limit
= atoi(value
);
1270 cupsdLogMessage(CUPSD_LOG_ERROR
,
1271 "Syntax error on line %d of printers.conf.", linenum
);
1273 else if (!_cups_strcasecmp(line
, "OpPolicy"))
1277 cupsd_policy_t
*pol
; /* Policy */
1280 if ((pol
= cupsdFindPolicy(value
)) != NULL
)
1282 cupsdSetString(&p
->op_policy
, value
);
1283 p
->op_policy_ptr
= pol
;
1286 cupsdLogMessage(CUPSD_LOG_ERROR
,
1287 "Bad policy \"%s\" on line %d of printers.conf",
1291 cupsdLogMessage(CUPSD_LOG_ERROR
,
1292 "Syntax error on line %d of printers.conf.", linenum
);
1294 else if (!_cups_strcasecmp(line
, "ErrorPolicy"))
1298 if (strcmp(value
, "retry-current-job") &&
1299 strcmp(value
, "abort-job") &&
1300 strcmp(value
, "retry-job") &&
1301 strcmp(value
, "stop-printer"))
1302 cupsdLogMessage(CUPSD_LOG_ALERT
, "Invalid ErrorPolicy \"%s\" on line %d or printers.conf.", ErrorPolicy
, linenum
);
1304 cupsdSetString(&p
->error_policy
, value
);
1307 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d of printers.conf.", linenum
);
1309 else if (!_cups_strcasecmp(line
, "Attribute") && value
)
1311 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1314 cupsdLogMessage(CUPSD_LOG_ERROR
,
1315 "Syntax error on line %d of printers.conf.", linenum
);
1318 for (; *valueptr
&& isspace(*valueptr
& 255); *valueptr
++ = '\0');
1321 cupsdSetPrinterAttrs(p
);
1323 if (!strcmp(value
, "marker-change-time"))
1324 p
->marker_time
= atoi(valueptr
);
1326 cupsdSetPrinterAttr(p
, value
, valueptr
);
1329 else if (_cups_strcasecmp(line
, "Filter") &&
1330 _cups_strcasecmp(line
, "Prefilter") &&
1331 _cups_strcasecmp(line
, "Product"))
1334 * Something else we don't understand (and that wasn't used in a prior
1335 * release of CUPS...
1338 cupsdLogMessage(CUPSD_LOG_ERROR
,
1339 "Unknown configuration directive %s on line %d of "
1340 "printers.conf.", line
, linenum
);
1349 * 'cupsdRenamePrinter()' - Rename a printer.
1354 cupsd_printer_t
*p
, /* I - Printer */
1355 const char *name
) /* I - New name */
1358 * Remove the printer from the array(s) first...
1361 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1362 "cupsdRenamePrinter: Removing %s from Printers", p
->name
);
1363 cupsArrayRemove(Printers
, p
);
1366 * Rename the printer type...
1369 mimeDeleteType(MimeDatabase
, p
->filetype
);
1370 p
->filetype
= mimeAddType(MimeDatabase
, "printer", name
);
1372 if (p
->prefiltertype
)
1374 mimeDeleteType(MimeDatabase
, p
->prefiltertype
);
1375 p
->prefiltertype
= mimeAddType(MimeDatabase
, "prefilter", name
);
1379 * Rename the printer...
1382 cupsdSetString(&p
->name
, name
);
1385 * Reset printer attributes...
1388 cupsdSetPrinterAttrs(p
);
1391 * Add the printer back to the printer array(s)...
1394 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1395 "cupsdRenamePrinter: Adding %s to Printers", p
->name
);
1396 cupsArrayAdd(Printers
, p
);
1401 * 'cupsdSaveAllPrinters()' - Save all printer definitions to the printers.conf
1406 cupsdSaveAllPrinters(void)
1408 int i
; /* Looping var */
1409 cups_file_t
*fp
; /* printers.conf file */
1410 char filename
[1024], /* printers.conf filename */
1411 temp
[1024], /* Temporary string */
1412 value
[2048], /* Value string */
1413 *ptr
, /* Pointer into value */
1414 *name
; /* Current user/group name */
1415 cupsd_printer_t
*printer
; /* Current printer class */
1416 time_t curtime
; /* Current time */
1417 struct tm
*curdate
; /* Current date */
1418 cups_option_t
*option
; /* Current option */
1419 ipp_attribute_t
*marker
; /* Current marker attribute */
1423 * Create the printers.conf file...
1426 snprintf(filename
, sizeof(filename
), "%s/printers.conf", ServerRoot
);
1428 if ((fp
= cupsdCreateConfFile(filename
, ConfigFilePerm
& 0600)) == NULL
)
1431 cupsdLogMessage(CUPSD_LOG_INFO
, "Saving printers.conf...");
1434 * Write a small header to the file...
1437 curtime
= time(NULL
);
1438 curdate
= localtime(&curtime
);
1439 strftime(temp
, sizeof(temp
) - 1, "%Y-%m-%d %H:%M", curdate
);
1441 cupsFilePuts(fp
, "# Printer configuration file for " CUPS_SVERSION
"\n");
1442 cupsFilePrintf(fp
, "# Written by cupsd on %s\n", temp
);
1443 cupsFilePuts(fp
, "# DO NOT EDIT THIS FILE WHEN CUPSD IS RUNNING\n");
1446 * Write each local printer known to the system...
1449 for (printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
1451 printer
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
1454 * Skip printer classes and temporary queues...
1457 if ((printer
->type
& CUPS_PRINTER_CLASS
) || printer
->temporary
)
1461 * Write printers as needed...
1464 if (printer
== DefaultPrinter
)
1465 cupsFilePrintf(fp
, "<DefaultPrinter %s>\n", printer
->name
);
1467 cupsFilePrintf(fp
, "<Printer %s>\n", printer
->name
);
1469 cupsFilePrintf(fp
, "UUID %s\n", printer
->uuid
);
1471 if (printer
->num_auth_info_required
> 0)
1473 switch (printer
->num_auth_info_required
)
1476 strlcpy(value
, printer
->auth_info_required
[0], sizeof(value
));
1480 snprintf(value
, sizeof(value
), "%s,%s",
1481 printer
->auth_info_required
[0],
1482 printer
->auth_info_required
[1]);
1487 snprintf(value
, sizeof(value
), "%s,%s,%s",
1488 printer
->auth_info_required
[0],
1489 printer
->auth_info_required
[1],
1490 printer
->auth_info_required
[2]);
1494 cupsFilePutConf(fp
, "AuthInfoRequired", value
);
1498 cupsFilePutConf(fp
, "Info", printer
->info
);
1500 if (printer
->location
)
1501 cupsFilePutConf(fp
, "Location", printer
->location
);
1503 if (printer
->geo_location
)
1504 cupsFilePutConf(fp
, "GeoLocation", printer
->geo_location
);
1506 if (printer
->make_model
)
1507 cupsFilePutConf(fp
, "MakeModel", printer
->make_model
);
1509 if (printer
->organization
)
1510 cupsFilePutConf(fp
, "Organization", printer
->organization
);
1512 if (printer
->organizational_unit
)
1513 cupsFilePutConf(fp
, "OrganizationalUnit", printer
->organizational_unit
);
1515 cupsFilePutConf(fp
, "DeviceURI", printer
->device_uri
);
1517 if (printer
->port_monitor
)
1518 cupsFilePutConf(fp
, "PortMonitor", printer
->port_monitor
);
1520 if (printer
->state
== IPP_PRINTER_STOPPED
)
1522 cupsFilePuts(fp
, "State Stopped\n");
1524 if (printer
->state_message
[0])
1525 cupsFilePutConf(fp
, "StateMessage", printer
->state_message
);
1528 cupsFilePuts(fp
, "State Idle\n");
1530 cupsFilePrintf(fp
, "StateTime %d\n", (int)printer
->state_time
);
1531 cupsFilePrintf(fp
, "ConfigTime %d\n", (int)printer
->config_time
);
1533 for (i
= 0; i
< printer
->num_reasons
; i
++)
1534 if (strcmp(printer
->reasons
[i
], "connecting-to-device") &&
1535 strcmp(printer
->reasons
[i
], "cups-insecure-filter-warning") &&
1536 strcmp(printer
->reasons
[i
], "cups-missing-filter-warning"))
1537 cupsFilePutConf(fp
, "Reason", printer
->reasons
[i
]);
1539 cupsFilePrintf(fp
, "Type %d\n", printer
->type
);
1541 if (printer
->accepting
)
1542 cupsFilePuts(fp
, "Accepting Yes\n");
1544 cupsFilePuts(fp
, "Accepting No\n");
1546 if (printer
->shared
)
1547 cupsFilePuts(fp
, "Shared Yes\n");
1549 cupsFilePuts(fp
, "Shared No\n");
1551 snprintf(value
, sizeof(value
), "%s %s", printer
->job_sheets
[0],
1552 printer
->job_sheets
[1]);
1553 cupsFilePutConf(fp
, "JobSheets", value
);
1555 cupsFilePrintf(fp
, "QuotaPeriod %d\n", printer
->quota_period
);
1556 cupsFilePrintf(fp
, "PageLimit %d\n", printer
->page_limit
);
1557 cupsFilePrintf(fp
, "KLimit %d\n", printer
->k_limit
);
1559 for (name
= (char *)cupsArrayFirst(printer
->users
);
1561 name
= (char *)cupsArrayNext(printer
->users
))
1562 cupsFilePutConf(fp
, printer
->deny_users
? "DenyUser" : "AllowUser", name
);
1564 if (printer
->op_policy
)
1565 cupsFilePutConf(fp
, "OpPolicy", printer
->op_policy
);
1566 if (printer
->error_policy
)
1567 cupsFilePutConf(fp
, "ErrorPolicy", printer
->error_policy
);
1569 for (i
= printer
->num_options
, option
= printer
->options
;
1573 snprintf(value
, sizeof(value
), "%s %s", option
->name
, option
->value
);
1574 cupsFilePutConf(fp
, "Option", value
);
1577 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-colors",
1578 IPP_TAG_NAME
)) != NULL
)
1580 snprintf(value
, sizeof(value
), "%s ", marker
->name
);
1582 for (i
= 0, ptr
= value
+ strlen(value
);
1583 i
< marker
->num_values
&& ptr
< (value
+ sizeof(value
) - 1);
1589 strlcpy(ptr
, marker
->values
[i
].string
.text
, (size_t)(value
+ sizeof(value
) - ptr
));
1594 cupsFilePutConf(fp
, "Attribute", value
);
1597 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-levels",
1598 IPP_TAG_INTEGER
)) != NULL
)
1600 cupsFilePrintf(fp
, "Attribute %s %d", marker
->name
,
1601 marker
->values
[0].integer
);
1602 for (i
= 1; i
< marker
->num_values
; i
++)
1603 cupsFilePrintf(fp
, ",%d", marker
->values
[i
].integer
);
1604 cupsFilePuts(fp
, "\n");
1607 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-low-levels",
1608 IPP_TAG_INTEGER
)) != NULL
)
1610 cupsFilePrintf(fp
, "Attribute %s %d", marker
->name
,
1611 marker
->values
[0].integer
);
1612 for (i
= 1; i
< marker
->num_values
; i
++)
1613 cupsFilePrintf(fp
, ",%d", marker
->values
[i
].integer
);
1614 cupsFilePuts(fp
, "\n");
1617 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-high-levels",
1618 IPP_TAG_INTEGER
)) != NULL
)
1620 cupsFilePrintf(fp
, "Attribute %s %d", marker
->name
,
1621 marker
->values
[0].integer
);
1622 for (i
= 1; i
< marker
->num_values
; i
++)
1623 cupsFilePrintf(fp
, ",%d", marker
->values
[i
].integer
);
1624 cupsFilePuts(fp
, "\n");
1627 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-message",
1628 IPP_TAG_TEXT
)) != NULL
)
1630 snprintf(value
, sizeof(value
), "%s %s", marker
->name
,
1631 marker
->values
[0].string
.text
);
1633 cupsFilePutConf(fp
, "Attribute", value
);
1636 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-names",
1637 IPP_TAG_NAME
)) != NULL
)
1639 snprintf(value
, sizeof(value
), "%s ", marker
->name
);
1641 for (i
= 0, ptr
= value
+ strlen(value
);
1642 i
< marker
->num_values
&& ptr
< (value
+ sizeof(value
) - 1);
1648 strlcpy(ptr
, marker
->values
[i
].string
.text
, (size_t)(value
+ sizeof(value
) - ptr
));
1653 cupsFilePutConf(fp
, "Attribute", value
);
1656 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-types",
1657 IPP_TAG_KEYWORD
)) != NULL
)
1659 snprintf(value
, sizeof(value
), "%s ", marker
->name
);
1661 for (i
= 0, ptr
= value
+ strlen(value
);
1662 i
< marker
->num_values
&& ptr
< (value
+ sizeof(value
) - 1);
1668 strlcpy(ptr
, marker
->values
[i
].string
.text
, (size_t)(value
+ sizeof(value
) - ptr
));
1673 cupsFilePutConf(fp
, "Attribute", value
);
1676 if (printer
->marker_time
)
1677 cupsFilePrintf(fp
, "Attribute marker-change-time %ld\n",
1678 (long)printer
->marker_time
);
1680 if (printer
== DefaultPrinter
)
1681 cupsFilePuts(fp
, "</DefaultPrinter>\n");
1683 cupsFilePuts(fp
, "</Printer>\n");
1686 cupsdCloseCreatedConfFile(fp
, filename
);
1691 * 'cupsdSetAuthInfoRequired()' - Set the required authentication info.
1694 int /* O - 1 if value OK, 0 otherwise */
1695 cupsdSetAuthInfoRequired(
1696 cupsd_printer_t
*p
, /* I - Printer */
1697 const char *values
, /* I - Plain text value (or NULL) */
1698 ipp_attribute_t
*attr
) /* I - IPP attribute value (or NULL) */
1700 int i
; /* Looping var */
1703 p
->num_auth_info_required
= 0;
1706 * Do we have a plain text value?
1712 * Yes, grab the keywords...
1715 const char *end
; /* End of current value */
1718 while (*values
&& p
->num_auth_info_required
< 4)
1720 if ((end
= strchr(values
, ',')) == NULL
)
1721 end
= values
+ strlen(values
);
1723 if ((end
- values
) == 4 && !strncmp(values
, "none", 4))
1725 if (p
->num_auth_info_required
!= 0 || *end
)
1728 p
->auth_info_required
[p
->num_auth_info_required
] = "none";
1729 p
->num_auth_info_required
++;
1733 else if ((end
- values
) == 9 && !strncmp(values
, "negotiate", 9))
1735 if (p
->num_auth_info_required
!= 0 || *end
)
1738 p
->auth_info_required
[p
->num_auth_info_required
] = "negotiate";
1739 p
->num_auth_info_required
++;
1742 * Don't allow sharing of queues that require Kerberos authentication.
1747 cupsdDeregisterPrinter(p
, 1);
1751 else if ((end
- values
) == 6 && !strncmp(values
, "domain", 6))
1753 p
->auth_info_required
[p
->num_auth_info_required
] = "domain";
1754 p
->num_auth_info_required
++;
1756 else if ((end
- values
) == 8 && !strncmp(values
, "password", 8))
1758 p
->auth_info_required
[p
->num_auth_info_required
] = "password";
1759 p
->num_auth_info_required
++;
1761 else if ((end
- values
) == 8 && !strncmp(values
, "username", 8))
1763 p
->auth_info_required
[p
->num_auth_info_required
] = "username";
1764 p
->num_auth_info_required
++;
1769 values
= (*end
) ? end
+ 1 : end
;
1772 if (p
->num_auth_info_required
== 0)
1774 p
->auth_info_required
[0] = "none";
1775 p
->num_auth_info_required
= 1;
1779 * Update the printer-type value as needed...
1782 if (p
->num_auth_info_required
> 1 ||
1783 strcmp(p
->auth_info_required
[0], "none"))
1784 p
->type
|= CUPS_PRINTER_AUTHENTICATED
;
1786 p
->type
&= (cups_ptype_t
)~CUPS_PRINTER_AUTHENTICATED
;
1792 * Grab values from an attribute instead...
1795 if (!attr
|| attr
->num_values
> 4)
1798 for (i
= 0; i
< attr
->num_values
; i
++)
1800 if (!strcmp(attr
->values
[i
].string
.text
, "none"))
1802 if (p
->num_auth_info_required
!= 0 || attr
->num_values
!= 1)
1805 p
->auth_info_required
[p
->num_auth_info_required
] = "none";
1806 p
->num_auth_info_required
++;
1810 else if (!strcmp(attr
->values
[i
].string
.text
, "negotiate"))
1812 if (p
->num_auth_info_required
!= 0 || attr
->num_values
!= 1)
1815 p
->auth_info_required
[p
->num_auth_info_required
] = "negotiate";
1816 p
->num_auth_info_required
++;
1819 * Don't allow sharing of queues that require Kerberos authentication.
1824 cupsdDeregisterPrinter(p
, 1);
1830 else if (!strcmp(attr
->values
[i
].string
.text
, "domain"))
1832 p
->auth_info_required
[p
->num_auth_info_required
] = "domain";
1833 p
->num_auth_info_required
++;
1835 else if (!strcmp(attr
->values
[i
].string
.text
, "password"))
1837 p
->auth_info_required
[p
->num_auth_info_required
] = "password";
1838 p
->num_auth_info_required
++;
1840 else if (!strcmp(attr
->values
[i
].string
.text
, "username"))
1842 p
->auth_info_required
[p
->num_auth_info_required
] = "username";
1843 p
->num_auth_info_required
++;
1854 * 'cupsdSetDeviceURI()' - Set the device URI for a printer.
1858 cupsdSetDeviceURI(cupsd_printer_t
*p
, /* I - Printer */
1859 const char *uri
) /* I - Device URI */
1861 char buffer
[1024], /* URI buffer */
1862 *start
, /* Start of data after scheme */
1863 *slash
, /* First slash after scheme:// */
1864 *ptr
; /* Pointer into user@host:port part */
1868 * Set the full device URI..
1871 cupsdSetString(&(p
->device_uri
), uri
);
1874 * Copy the device URI to a temporary buffer so we can sanitize any auth
1878 strlcpy(buffer
, uri
, sizeof(buffer
));
1881 * Find the end of the scheme:// part...
1884 if ((ptr
= strchr(buffer
, ':')) != NULL
)
1886 for (start
= ptr
+ 1; *start
; start
++)
1891 * Find the next slash (/) in the URI...
1894 if ((slash
= strchr(start
, '/')) == NULL
)
1895 slash
= start
+ strlen(start
); /* No slash, point to the end */
1898 * Check for an @ sign before the slash...
1901 if ((ptr
= strchr(start
, '@')) != NULL
&& ptr
< slash
)
1904 * Found an @ sign and it is before the resource part, so we have
1905 * an authentication string. Copy the remaining URI over the
1906 * authentication string...
1909 _cups_strcpy(start
, ptr
+ 1);
1914 * Save the sanitized URI...
1917 cupsdSetString(&(p
->sanitized_device_uri
), buffer
);
1922 * 'cupsdSetPrinterAttr()' - Set a printer attribute.
1926 cupsdSetPrinterAttr(
1927 cupsd_printer_t
*p
, /* I - Printer */
1928 const char *name
, /* I - Attribute name */
1929 const char *value
) /* I - Attribute value string */
1931 ipp_attribute_t
*attr
; /* Attribute */
1932 int i
, /* Looping var */
1933 count
; /* Number of values */
1934 char *temp
, /* Temporary copy of value string */
1935 *ptr
, /* Pointer into value */
1936 *start
, /* Start of value */
1937 quote
; /* Quote character */
1938 ipp_tag_t value_tag
; /* Value tag for this attribute */
1942 * Don't allow empty values...
1945 if (!*value
&& strcmp(name
, "marker-message"))
1947 cupsdLogMessage(CUPSD_LOG_ERROR
, "Ignoring empty \"%s\" attribute", name
);
1952 * Copy the value string so we can do what we want with it...
1955 if ((temp
= strdup(value
)) == NULL
)
1957 cupsdLogMessage(CUPSD_LOG_ERROR
,
1958 "Unable to duplicate value for \"%s\" attribute.", name
);
1963 * Count the number of values...
1966 for (count
= 1, quote
= '\0', ptr
= temp
;
1974 else if (*ptr
== '\\' && ptr
[1])
1976 else if (*ptr
== '\'' || *ptr
== '\"')
1978 else if (*ptr
== ',')
1983 * Then add or update the attribute as needed...
1986 if (!strcmp(name
, "marker-levels") || !strcmp(name
, "marker-low-levels") ||
1987 !strcmp(name
, "marker-high-levels"))
1993 if ((attr
= ippFindAttribute(p
->attrs
, name
, IPP_TAG_INTEGER
)) != NULL
&&
1994 attr
->num_values
< count
)
1996 ippDeleteAttribute(p
->attrs
, attr
);
2001 attr
->num_values
= count
;
2003 attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
, name
,
2009 cupsdLogMessage(CUPSD_LOG_ERROR
,
2010 "Unable to allocate memory for printer attribute "
2011 "(%d values)", count
);
2015 for (i
= 0, start
= temp
; i
< count
; i
++)
2017 if ((ptr
= strchr(start
, ',')) != NULL
)
2020 attr
->values
[i
].integer
= strtol(start
, NULL
, 10);
2029 * Name or keyword values...
2032 if (!strcmp(name
, "marker-types"))
2033 value_tag
= IPP_TAG_KEYWORD
;
2034 else if (!strcmp(name
, "marker-message"))
2035 value_tag
= IPP_TAG_TEXT
;
2037 value_tag
= IPP_TAG_NAME
;
2039 if ((attr
= ippFindAttribute(p
->attrs
, name
, value_tag
)) != NULL
&&
2040 attr
->num_values
< count
)
2042 ippDeleteAttribute(p
->attrs
, attr
);
2048 for (i
= 0; i
< attr
->num_values
; i
++)
2049 _cupsStrFree(attr
->values
[i
].string
.text
);
2051 attr
->num_values
= count
;
2054 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, value_tag
, name
,
2060 cupsdLogMessage(CUPSD_LOG_ERROR
,
2061 "Unable to allocate memory for printer attribute "
2062 "(%d values)", count
);
2066 for (i
= 0, quote
= '\0', ptr
= temp
; i
< count
; i
++)
2068 for (start
= ptr
; *ptr
; ptr
++)
2071 *ptr
= quote
= '\0';
2074 else if (*ptr
== '\\' && ptr
[1])
2075 _cups_strcpy(ptr
, ptr
+ 1);
2076 else if (*ptr
== '\'' || *ptr
== '\"')
2083 _cups_strcpy(ptr
, ptr
+ 1);
2085 else if (*ptr
== ',')
2092 attr
->values
[i
].string
.text
= _cupsStrAlloc(start
);
2099 * Update the printer-supply and printer-supply-description, as needed...
2102 if (!strcmp(name
, "marker-names"))
2104 ipp_attribute_t
*supply_desc
= ippFindAttribute(p
->attrs
, "printer-supply-description", IPP_TAG_TEXT
);
2105 /* printer-supply-description attribute */
2107 if (supply_desc
!= NULL
)
2108 ippDeleteAttribute(p
->attrs
, supply_desc
);
2110 supply_desc
= ippCopyAttribute(p
->attrs
, attr
, 0);
2111 ippSetName(p
->attrs
, &supply_desc
, "printer-supply-description");
2112 ippSetValueTag(p
->attrs
, &supply_desc
, IPP_TAG_TEXT
);
2114 else if (!strcmp(name
, "marker-colors") || !strcmp(name
, "marker-levels") || !strcmp(name
, "marker-types"))
2116 char buffer
[256], /* printer-supply values */
2117 pstype
[64], /* printer-supply type value */
2118 *psptr
; /* Pointer into type */
2119 const char *color
, /* marker-colors value */
2120 *type
; /* marker-types value */
2121 int level
; /* marker-levels value */
2122 ipp_attribute_t
*colors
= ippFindAttribute(p
->attrs
, "marker-colors", IPP_TAG_NAME
);
2123 /* marker-colors attribute */
2124 ipp_attribute_t
*levels
= ippFindAttribute(p
->attrs
, "marker-levels", IPP_TAG_INTEGER
);
2125 /* marker-levels attribute */
2126 ipp_attribute_t
*types
= ippFindAttribute(p
->attrs
, "marker-types", IPP_TAG_KEYWORD
);
2127 /* marker-types attribute */
2128 ipp_attribute_t
*supply
= ippFindAttribute(p
->attrs
, "printer-supply", IPP_TAG_STRING
);
2129 /* printer-supply attribute */
2133 ippDeleteAttribute(p
->attrs
, supply
);
2137 if (!colors
|| !levels
|| !types
)
2140 count
= ippGetCount(colors
);
2141 if (count
!= ippGetCount(levels
) || count
!= ippGetCount(types
))
2144 for (i
= 0; i
< count
; i
++)
2146 color
= ippGetString(colors
, i
, NULL
);
2147 level
= ippGetInteger(levels
, i
);
2148 type
= ippGetString(types
, i
, NULL
);
2150 for (psptr
= pstype
; *type
&& psptr
< (pstype
+ sizeof(pstype
) - 1); type
++)
2154 *psptr
++ = (char)toupper(*type
& 255);
2160 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
);
2163 supply
= ippAddOctetString(p
->attrs
, IPP_TAG_PRINTER
, "printer-supply", buffer
, (int)strlen(buffer
));
2165 ippSetOctetString(p
->attrs
, &supply
, i
, buffer
, (int)strlen(buffer
));
2172 * 'cupsdSetPrinterAttrs()' - Set printer attributes based upon the PPD file.
2176 cupsdSetPrinterAttrs(cupsd_printer_t
*p
)/* I - Printer to setup */
2178 int i
; /* Looping var */
2179 char resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
2180 cupsd_location_t
*auth
; /* Pointer to authentication element */
2181 const char *auth_supported
; /* Authentication supported */
2182 ipp_t
*oldattrs
; /* Old printer attributes */
2183 ipp_attribute_t
*attr
; /* Attribute data */
2184 char *name
, /* Current user/group name */
2185 *filter
; /* Current filter */
2188 DEBUG_printf(("cupsdSetPrinterAttrs: entering name = %s, type = %x\n", p
->name
,
2192 * Make sure that we have the common attributes defined...
2196 cupsdCreateCommonData();
2198 _cupsRWLockWrite(&p
->lock
);
2201 * Clear out old filters, if any...
2204 delete_printer_filters(p
);
2207 * Figure out the authentication that is required for the printer.
2210 auth_supported
= "requesting-user-name";
2212 if (p
->type
& CUPS_PRINTER_CLASS
)
2213 snprintf(resource
, sizeof(resource
), "/classes/%s", p
->name
);
2215 snprintf(resource
, sizeof(resource
), "/printers/%s", p
->name
);
2217 if ((auth
= cupsdFindBest(resource
, HTTP_POST
)) == NULL
||
2218 auth
->type
== CUPSD_AUTH_NONE
)
2219 auth
= cupsdFindPolicyOp(p
->op_policy_ptr
, IPP_PRINT_JOB
);
2223 int auth_type
; /* Authentication type */
2226 if ((auth_type
= auth
->type
) == CUPSD_AUTH_DEFAULT
)
2227 auth_type
= cupsdDefaultAuthType();
2229 if (auth_type
== CUPSD_AUTH_BASIC
)
2230 auth_supported
= "basic";
2232 else if (auth_type
== CUPSD_AUTH_NEGOTIATE
)
2233 auth_supported
= "negotiate";
2234 #endif /* HAVE_GSSAPI */
2236 if (auth_type
!= CUPSD_AUTH_NONE
)
2237 p
->type
|= CUPS_PRINTER_AUTHENTICATED
;
2239 p
->type
&= (cups_ptype_t
)~CUPS_PRINTER_AUTHENTICATED
;
2242 p
->type
&= (cups_ptype_t
)~CUPS_PRINTER_AUTHENTICATED
;
2245 * Create the required IPP attributes for a printer...
2248 oldattrs
= p
->attrs
;
2249 p
->attrs
= ippNew();
2251 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2252 "uri-authentication-supported", NULL
, auth_supported
);
2253 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2254 "uri-security-supported", NULL
, "none");
2255 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
, "printer-name", NULL
,
2257 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-location",
2258 NULL
, p
->location
? p
->location
: "");
2259 if (p
->geo_location
)
2260 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "printer-geo-location", NULL
, p
->geo_location
);
2262 ippAddOutOfBand(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_UNKNOWN
, "printer-geo-location");
2263 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-info",
2264 NULL
, p
->info
? p
->info
: "");
2265 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-organization", NULL
, p
->organization
? p
->organization
: "");
2266 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-organizational-unit", NULL
, p
->organizational_unit
? p
->organizational_unit
: "");
2267 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "printer-uuid", NULL
, p
->uuid
);
2269 if (cupsArrayCount(p
->users
) > 0)
2272 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2273 "requesting-user-name-denied",
2274 cupsArrayCount(p
->users
), NULL
, NULL
);
2276 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2277 "requesting-user-name-allowed",
2278 cupsArrayCount(p
->users
), NULL
, NULL
);
2280 for (i
= 0, name
= (char *)cupsArrayFirst(p
->users
);
2282 i
++, name
= (char *)cupsArrayNext(p
->users
))
2283 attr
->values
[i
].string
.text
= _cupsStrAlloc(name
);
2286 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2287 "job-quota-period", p
->quota_period
);
2288 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2289 "job-k-limit", p
->k_limit
);
2290 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2291 "job-page-limit", p
->page_limit
);
2292 if (p
->num_auth_info_required
> 0 && strcmp(p
->auth_info_required
[0], "none"))
2293 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2294 "auth-info-required", p
->num_auth_info_required
, NULL
,
2295 p
->auth_info_required
);
2297 if (cupsArrayCount(Banners
) > 0)
2300 * Setup the job-sheets-default attribute...
2303 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2304 "job-sheets-default", 2, NULL
, NULL
);
2308 attr
->values
[0].string
.text
= _cupsStrAlloc(Classification
?
2309 Classification
: p
->job_sheets
[0]);
2310 attr
->values
[1].string
.text
= _cupsStrAlloc(Classification
?
2311 Classification
: p
->job_sheets
[1]);
2319 * Assign additional attributes depending on whether this is a printer
2323 if (p
->type
& CUPS_PRINTER_CLASS
)
2326 p
->type
&= (cups_ptype_t
)~CUPS_PRINTER_OPTIONS
;
2329 * Add class-specific attributes...
2332 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
2333 "printer-make-and-model", NULL
, "Local Printer Class");
2334 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "device-uri", NULL
,
2335 "file:///dev/null");
2337 if (p
->num_printers
> 0)
2340 * Add a list of member names; URIs are added in copy_printer_attrs...
2343 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2344 "member-names", p
->num_printers
, NULL
, NULL
);
2345 p
->type
|= CUPS_PRINTER_OPTIONS
;
2347 for (i
= 0; i
< p
->num_printers
; i
++)
2350 attr
->values
[i
].string
.text
= _cupsStrAlloc(p
->printers
[i
]->name
);
2352 p
->type
&= (cups_ptype_t
)~CUPS_PRINTER_OPTIONS
| p
->printers
[i
]->type
;
2359 * Add printer-specific attributes...
2362 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "device-uri", NULL
,
2363 p
->sanitized_device_uri
);
2366 * Assign additional attributes from the PPD file (if any)...
2372 * Add filters for printer...
2375 cupsdSetPrinterReasons(p
, "-cups-missing-filter-warning,"
2376 "cups-insecure-filter-warning");
2378 if (p
->pc
&& p
->pc
->filters
)
2380 for (filter
= (char *)cupsArrayFirst(p
->pc
->filters
);
2382 filter
= (char *)cupsArrayNext(p
->pc
->filters
))
2383 add_printer_filter(p
, p
->filetype
, filter
);
2385 else if (!(p
->type
& CUPS_PRINTER_REMOTE
))
2388 * Add a filter from application/vnd.cups-raw to printer/name to
2389 * handle "raw" printing by users.
2392 add_printer_filter(p
, p
->filetype
, "application/vnd.cups-raw 0 -");
2395 * Add a PostScript filter, since this is still possibly PS printer.
2398 add_printer_filter(p
, p
->filetype
,
2399 "application/vnd.cups-postscript 0 -");
2402 if (p
->pc
&& p
->pc
->prefilters
)
2404 if (!p
->prefiltertype
)
2405 p
->prefiltertype
= mimeAddType(MimeDatabase
, "prefilter", p
->name
);
2407 for (filter
= (char *)cupsArrayFirst(p
->pc
->prefilters
);
2409 filter
= (char *)cupsArrayNext(p
->pc
->prefilters
))
2410 add_printer_filter(p
, p
->prefiltertype
, filter
);
2415 * Copy marker attributes as needed...
2420 ipp_attribute_t
*oldattr
; /* Old attribute */
2423 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-colors",
2424 IPP_TAG_NAME
)) != NULL
)
2426 if ((attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2427 "marker-colors", oldattr
->num_values
, NULL
,
2430 for (i
= 0; i
< oldattr
->num_values
; i
++)
2431 attr
->values
[i
].string
.text
=
2432 _cupsStrAlloc(oldattr
->values
[i
].string
.text
);
2436 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-levels",
2437 IPP_TAG_INTEGER
)) != NULL
)
2439 if ((attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2440 "marker-levels", oldattr
->num_values
,
2443 for (i
= 0; i
< oldattr
->num_values
; i
++)
2444 attr
->values
[i
].integer
= oldattr
->values
[i
].integer
;
2448 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-message",
2449 IPP_TAG_TEXT
)) != NULL
)
2450 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "marker-message",
2451 NULL
, oldattr
->values
[0].string
.text
);
2453 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-low-levels",
2454 IPP_TAG_INTEGER
)) != NULL
)
2456 if ((attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2457 "marker-low-levels", oldattr
->num_values
,
2460 for (i
= 0; i
< oldattr
->num_values
; i
++)
2461 attr
->values
[i
].integer
= oldattr
->values
[i
].integer
;
2465 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-high-levels",
2466 IPP_TAG_INTEGER
)) != NULL
)
2468 if ((attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2469 "marker-high-levels", oldattr
->num_values
,
2472 for (i
= 0; i
< oldattr
->num_values
; i
++)
2473 attr
->values
[i
].integer
= oldattr
->values
[i
].integer
;
2477 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-names",
2478 IPP_TAG_NAME
)) != NULL
)
2480 if ((attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2481 "marker-names", oldattr
->num_values
, NULL
,
2484 for (i
= 0; i
< oldattr
->num_values
; i
++)
2485 attr
->values
[i
].string
.text
=
2486 _cupsStrAlloc(oldattr
->values
[i
].string
.text
);
2490 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-types",
2491 IPP_TAG_KEYWORD
)) != NULL
)
2493 if ((attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2494 "marker-types", oldattr
->num_values
, NULL
,
2497 for (i
= 0; i
< oldattr
->num_values
; i
++)
2498 attr
->values
[i
].string
.text
=
2499 _cupsStrAlloc(oldattr
->values
[i
].string
.text
);
2503 ippDelete(oldattrs
);
2507 * Force sharing off for remote queues...
2510 if (p
->type
& CUPS_PRINTER_REMOTE
)
2514 * Populate the document-format-supported attribute...
2517 add_printer_formats(p
);
2519 DEBUG_printf(("cupsdSetPrinterAttrs: leaving name = %s, type = %x\n", p
->name
,
2523 * Add name-default attributes...
2526 add_printer_defaults(p
);
2528 _cupsRWUnlock(&p
->lock
);
2531 * Let the browse protocols reflect the change
2534 cupsdRegisterPrinter(p
);
2539 * 'cupsdSetPrinterReasons()' - Set/update the reasons strings.
2542 int /* O - 1 if something changed, 0 otherwise */
2543 cupsdSetPrinterReasons(
2544 cupsd_printer_t
*p
, /* I - Printer */
2545 const char *s
) /* I - Reasons strings */
2547 int i
, /* Looping var */
2548 changed
= 0; /* Did something change? */
2549 const char *sptr
; /* Pointer into reasons */
2550 char reason
[255], /* Reason string */
2551 *rptr
; /* Pointer into reason */
2554 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
2555 "cupsdSetPrinterReasons(p=%p(%s),s=\"%s\"", p
, p
->name
, s
);
2557 if (s
[0] == '-' || s
[0] == '+')
2560 * Add/remove reasons...
2568 * Replace reasons...
2573 for (i
= 0; i
< p
->num_reasons
; i
++)
2574 _cupsStrFree(p
->reasons
[i
]);
2582 if (!strcmp(s
, "none"))
2586 * Loop through all of the reasons...
2592 * Skip leading whitespace and commas...
2595 while (isspace(*sptr
& 255) || *sptr
== ',')
2598 for (rptr
= reason
; *sptr
&& !isspace(*sptr
& 255) && *sptr
!= ','; sptr
++)
2599 if (rptr
< (reason
+ sizeof(reason
) - 1))
2613 for (i
= 0; i
< p
->num_reasons
; i
++)
2614 if (!strcmp(reason
, p
->reasons
[i
]))
2617 * Found a match, so remove it...
2622 _cupsStrFree(p
->reasons
[i
]);
2624 if (i
< p
->num_reasons
)
2625 memmove(p
->reasons
+ i
, p
->reasons
+ i
+ 1, (size_t)(p
->num_reasons
- i
) * sizeof(char *));
2627 if (!strcmp(reason
, "paused") && p
->state
== IPP_PRINTER_STOPPED
)
2628 cupsdSetPrinterState(p
, IPP_PRINTER_IDLE
, 1);
2630 if (!strcmp(reason
, "cups-waiting-for-job-completed") && p
->job
)
2631 p
->job
->completed
= 0;
2633 if (strcmp(reason
, "connecting-to-device"))
2639 else if (p
->num_reasons
< (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
2645 for (i
= 0; i
< p
->num_reasons
; i
++)
2646 if (!strcmp(reason
, p
->reasons
[i
]))
2649 if (i
>= p
->num_reasons
)
2651 if (i
>= (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
2653 cupsdLogMessage(CUPSD_LOG_ALERT
,
2654 "Too many printer-state-reasons values for %s (%d)",
2659 p
->reasons
[i
] = _cupsStrAlloc(reason
);
2663 if (!strcmp(reason
, "paused") && p
->state
!= IPP_PRINTER_STOPPED
)
2664 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, 1);
2666 if (!strcmp(reason
, "cups-waiting-for-job-completed") && p
->job
)
2667 p
->job
->completed
= 1;
2669 if (strcmp(reason
, "connecting-to-device"))
2680 * 'cupsdSetPrinterState()' - Update the current state of a printer.
2684 cupsdSetPrinterState(
2685 cupsd_printer_t
*p
, /* I - Printer to change */
2686 ipp_pstate_t s
, /* I - New state */
2687 int update
) /* I - Update printers.conf? */
2689 cupsd_job_t
*job
; /* Current job */
2690 ipp_pstate_t old_state
; /* Old printer state */
2691 static const char * const printer_states
[] =
2692 { /* State strings */
2700 * Set the new state...
2703 old_state
= p
->state
;
2708 cupsdAddEvent(s
== IPP_PRINTER_STOPPED
? CUPSD_EVENT_PRINTER_STOPPED
:
2709 CUPSD_EVENT_PRINTER_STATE
, p
, NULL
,
2710 "%s \"%s\" state changed to %s.",
2711 (p
->type
& CUPS_PRINTER_CLASS
) ? "Class" : "Printer",
2712 p
->name
, printer_states
[p
->state
- IPP_PRINTER_IDLE
]);
2715 * Let the browse code know this needs to be updated...
2718 p
->state_time
= time(NULL
);
2722 * Set/clear the paused reason as needed...
2725 if (s
== IPP_PRINTER_STOPPED
)
2726 cupsdSetPrinterReasons(p
, "+paused");
2728 cupsdSetPrinterReasons(p
, "-paused");
2732 for (job
= (cupsd_job_t
*)cupsArrayFirst(ActiveJobs
);
2734 job
= (cupsd_job_t
*)cupsArrayNext(ActiveJobs
))
2735 if (job
->reasons
&& job
->state_value
== IPP_JOB_PENDING
&&
2736 !_cups_strcasecmp(job
->dest
, p
->name
))
2737 ippSetString(job
->attrs
, &job
->reasons
, 0,
2738 s
== IPP_PRINTER_STOPPED
? "printer-stopped" : "none");
2742 * Clear the message for the queue when going to processing...
2745 if (s
== IPP_PRINTER_PROCESSING
)
2746 p
->state_message
[0] = '\0';
2749 * Let the browse protocols reflect the change...
2753 cupsdRegisterPrinter(p
);
2756 * Save the printer configuration if a printer goes from idle or processing
2757 * to stopped (or visa-versa)...
2761 (old_state
== IPP_PRINTER_STOPPED
) != (s
== IPP_PRINTER_STOPPED
))
2767 * 'cupsdStopPrinter()' - Stop a printer from printing any jobs...
2771 cupsdStopPrinter(cupsd_printer_t
*p
, /* I - Printer to stop */
2772 int update
)/* I - Update printers.conf? */
2775 * Set the printer state...
2778 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, update
);
2781 * See if we have a job printing on this printer...
2784 if (p
->job
&& p
->job
->state_value
== IPP_JOB_PROCESSING
)
2785 cupsdSetJobState(p
->job
, IPP_JOB_PENDING
, CUPSD_JOB_DEFAULT
,
2786 "Job stopped due to printer being paused.");
2791 * 'cupsdUpdatePrinterPPD()' - Update keywords in a printer's PPD file.
2794 int /* O - 1 if successful, 0 otherwise */
2795 cupsdUpdatePrinterPPD(
2796 cupsd_printer_t
*p
, /* I - Printer */
2797 int num_keywords
, /* I - Number of keywords */
2798 cups_option_t
*keywords
) /* I - Keywords */
2800 int i
; /* Looping var */
2801 cups_file_t
*src
, /* Original file */
2802 *dst
; /* New file */
2803 char srcfile
[1024], /* Original filename */
2804 dstfile
[1024], /* New filename */
2805 line
[1024], /* Line from file */
2806 keystring
[41]; /* Keyword from line */
2807 cups_option_t
*keyword
; /* Current keyword */
2810 cupsdLogMessage(CUPSD_LOG_INFO
, "Updating keywords in PPD file for %s...",
2814 * Get the old and new PPD filenames...
2817 snprintf(srcfile
, sizeof(srcfile
), "%s/ppd/%s.ppd.O", ServerRoot
, p
->name
);
2818 snprintf(dstfile
, sizeof(srcfile
), "%s/ppd/%s.ppd", ServerRoot
, p
->name
);
2821 * Rename the old file and open the old and new...
2824 if (rename(dstfile
, srcfile
))
2826 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to backup PPD file for %s: %s",
2827 p
->name
, strerror(errno
));
2831 if ((src
= cupsFileOpen(srcfile
, "r")) == NULL
)
2833 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to open PPD file \"%s\": %s",
2834 srcfile
, strerror(errno
));
2835 rename(srcfile
, dstfile
);
2839 if ((dst
= cupsFileOpen(dstfile
, "w")) == NULL
)
2841 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to create PPD file \"%s\": %s",
2842 dstfile
, strerror(errno
));
2844 rename(srcfile
, dstfile
);
2849 * Copy the first line and then write out all of the keywords...
2852 if (!cupsFileGets(src
, line
, sizeof(line
)))
2854 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to read PPD file \"%s\": %s",
2855 srcfile
, strerror(errno
));
2858 rename(srcfile
, dstfile
);
2862 cupsFilePrintf(dst
, "%s\n", line
);
2864 for (i
= num_keywords
, keyword
= keywords
; i
> 0; i
--, keyword
++)
2866 cupsdLogMessage(CUPSD_LOG_DEBUG
, "*%s: %s", keyword
->name
, keyword
->value
);
2867 cupsFilePrintf(dst
, "*%s: %s\n", keyword
->name
, keyword
->value
);
2871 * Then copy the rest of the PPD file, dropping any keywords we changed.
2874 while (cupsFileGets(src
, line
, sizeof(line
)))
2877 * Skip keywords we've already set...
2880 if (sscanf(line
, "*%40[^:]:", keystring
) == 1 &&
2881 cupsGetOption(keystring
, num_keywords
, keywords
))
2885 * Otherwise write the line...
2888 cupsFilePrintf(dst
, "%s\n", line
);
2892 * Close files and return...
2903 * 'cupsdUpdatePrinters()' - Update printers after a partial reload.
2907 cupsdUpdatePrinters(void)
2909 cupsd_printer_t
*p
; /* Current printer */
2913 * Loop through the printers and recreate the printer attributes
2914 * for any local printers since the policy and/or access control
2915 * stuff may have changed. Also, if browsing is disabled, remove
2916 * any remote printers...
2919 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
2921 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
2924 * Update the operation policy pointer...
2927 if ((p
->op_policy_ptr
= cupsdFindPolicy(p
->op_policy
)) == NULL
)
2928 p
->op_policy_ptr
= DefaultPolicyPtr
;
2931 * Update printer attributes...
2934 cupsdSetPrinterAttrs(p
);
2940 * 'cupsdValidateDest()' - Validate a printer/class destination.
2943 const char * /* O - Printer or class name */
2945 const char *uri
, /* I - Printer URI */
2946 cups_ptype_t
*dtype
, /* O - Type (printer or class) */
2947 cupsd_printer_t
**printer
) /* O - Printer pointer */
2949 cupsd_printer_t
*p
; /* Current printer */
2950 char localname
[1024],/* Localized hostname */
2951 *lptr
, /* Pointer into localized hostname */
2952 *sptr
, /* Pointer into server name */
2953 *rptr
, /* Pointer into resource */
2954 scheme
[32], /* Scheme portion of URI */
2955 username
[64], /* Username portion of URI */
2956 hostname
[HTTP_MAX_HOST
],
2957 /* Host portion of URI */
2958 resource
[HTTP_MAX_URI
];
2959 /* Resource portion of URI */
2960 int port
; /* Port portion of URI */
2963 DEBUG_printf(("cupsdValidateDest(uri=\"%s\", dtype=%p, printer=%p)\n", uri
,
2967 * Initialize return values...
2974 *dtype
= (cups_ptype_t
)0;
2977 * Pull the hostname and resource from the URI...
2980 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
, scheme
, sizeof(scheme
),
2981 username
, sizeof(username
), hostname
, sizeof(hostname
),
2982 &port
, resource
, sizeof(resource
));
2985 * See if the resource is a class or printer...
2988 if (!strncmp(resource
, "/classes/", 9))
2994 rptr
= resource
+ 9;
2996 else if (!strncmp(resource
, "/printers/", 10))
3002 rptr
= resource
+ 10;
3007 * Bad resource name...
3014 * See if the printer or class name exists...
3017 p
= cupsdFindDest(rptr
);
3019 if (p
== NULL
&& strchr(rptr
, '@') == NULL
)
3027 *dtype
= p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_REMOTE
);
3033 * Change localhost to the server name...
3036 if (!_cups_strcasecmp(hostname
, "localhost"))
3037 strlcpy(hostname
, ServerName
, sizeof(hostname
));
3039 strlcpy(localname
, hostname
, sizeof(localname
));
3041 if (!_cups_strcasecmp(hostname
, ServerName
))
3044 * Localize the hostname...
3047 lptr
= strchr(localname
, '.');
3048 sptr
= strchr(ServerName
, '.');
3050 if (sptr
!= NULL
&& lptr
!= NULL
)
3053 * Strip the common domain name components...
3056 while (lptr
!= NULL
)
3058 if (!_cups_strcasecmp(lptr
, sptr
))
3064 lptr
= strchr(lptr
+ 1, '.');
3069 DEBUG_printf(("localized hostname is \"%s\"...\n", localname
));
3072 * Find a matching printer or class...
3075 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3077 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3078 if (!_cups_strcasecmp(p
->hostname
, localname
) &&
3079 !_cups_strcasecmp(p
->name
, rptr
))
3085 *dtype
= p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_REMOTE
);
3095 * 'cupsdWritePrintcap()' - Write a pseudo-printcap file for older applications
3100 cupsdWritePrintcap(void)
3102 int i
; /* Looping var */
3103 cups_file_t
*fp
; /* Printcap file */
3104 cupsd_printer_t
*p
; /* Current printer */
3108 * See if we have a printcap file; if not, don't bother writing it.
3111 if (!Printcap
|| !*Printcap
)
3114 cupsdLogMessage(CUPSD_LOG_INFO
, "Generating printcap %s...", Printcap
);
3117 * Open the printcap file...
3120 if ((fp
= cupsFileOpen(Printcap
, "w")) == NULL
)
3124 * Put a comment header at the top so that users will know where the
3125 * data has come from...
3128 if (PrintcapFormat
!= PRINTCAP_PLIST
)
3129 cupsFilePrintf(fp
, "# This file was automatically generated by cupsd(8) "
3131 "# %s/printers.conf file. All changes to this file\n"
3132 "# will be lost.\n", ServerRoot
);
3135 * Write a new printcap with the current list of printers.
3138 switch (PrintcapFormat
)
3142 * Each printer is put in the file as:
3152 cupsFilePrintf(fp
, "%s|%s:rm=%s:rp=%s:\n", DefaultPrinter
->name
,
3153 DefaultPrinter
->info
, ServerName
,
3154 DefaultPrinter
->name
);
3156 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3158 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3159 if (p
!= DefaultPrinter
)
3160 cupsFilePrintf(fp
, "%s|%s:rm=%s:rp=%s:\n", p
->name
, p
->info
,
3161 ServerName
, p
->name
);
3164 case PRINTCAP_PLIST
:
3166 * Each printer is written as a dictionary in a plist file.
3167 * Currently the printer-name, printer-info, printer-is-accepting-jobs,
3168 * printer-location, printer-make-and-model, printer-state,
3169 * printer-state-reasons, printer-type, and (sanitized) device-uri.
3172 cupsFilePuts(fp
, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
3173 "<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD "
3174 "PLIST 1.0//EN\" \"http://www.apple.com/DTDs/"
3175 "PropertyList-1.0.dtd\">\n"
3176 "<plist version=\"1.0\">\n"
3179 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3181 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3183 cupsFilePuts(fp
, "\t<dict>\n"
3184 "\t\t<key>printer-name</key>\n"
3186 write_xml_string(fp
, p
->name
);
3187 cupsFilePuts(fp
, "</string>\n"
3188 "\t\t<key>printer-info</key>\n"
3190 write_xml_string(fp
, p
->info
);
3191 cupsFilePrintf(fp
, "</string>\n"
3192 "\t\t<key>printer-is-accepting-jobs</key>\n"
3194 "\t\t<key>printer-location</key>\n"
3195 "\t\t<string>", p
->accepting
? "true" : "false");
3196 write_xml_string(fp
, p
->location
);
3197 cupsFilePuts(fp
, "</string>\n"
3198 "\t\t<key>printer-make-and-model</key>\n"
3200 write_xml_string(fp
, p
->make_model
);
3201 cupsFilePrintf(fp
, "</string>\n"
3202 "\t\t<key>printer-state</key>\n"
3203 "\t\t<integer>%d</integer>\n"
3204 "\t\t<key>printer-state-reasons</key>\n"
3205 "\t\t<array>\n", p
->state
);
3206 for (i
= 0; i
< p
->num_reasons
; i
++)
3208 cupsFilePuts(fp
, "\t\t\t<string>");
3209 write_xml_string(fp
, p
->reasons
[i
]);
3210 cupsFilePuts(fp
, "</string>\n");
3212 cupsFilePrintf(fp
, "\t\t</array>\n"
3213 "\t\t<key>printer-type</key>\n"
3214 "\t\t<integer>%d</integer>\n"
3215 "\t\t<key>device-uri</key>\n"
3216 "\t\t<string>", p
->type
);
3217 write_xml_string(fp
, p
->sanitized_device_uri
);
3218 cupsFilePuts(fp
, "</string>\n"
3221 cupsFilePuts(fp
, "</array>\n"
3225 case PRINTCAP_SOLARIS
:
3227 * Each printer is put in the file as:
3229 * _all:all=Printer1,Printer2,Printer3,...,PrinterN
3230 * _default:use=DefaultPrinter
3232 * :bsdaddr=ServerName,Printer1:\
3233 * :description=Description:
3235 * :bsdaddr=ServerName,Printer2:\
3236 * :description=Description:
3238 * :bsdaddr=ServerName,Printer3:\
3239 * :description=Description:
3242 * :bsdaddr=ServerName,PrinterN:\
3243 * :description=Description:
3246 cupsFilePuts(fp
, "_all:all=");
3247 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3249 p
= (cupsd_printer_t
*)cupsArrayCurrent(Printers
))
3250 cupsFilePrintf(fp
, "%s%c", p
->name
,
3251 cupsArrayNext(Printers
) ? ',' : '\n');
3254 cupsFilePrintf(fp
, "_default:use=%s\n", DefaultPrinter
->name
);
3256 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3258 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3259 cupsFilePrintf(fp
, "%s:\\\n"
3260 "\t:bsdaddr=%s,%s:\\\n"
3261 "\t:description=%s:\n",
3262 p
->name
, ServerName
, p
->name
,
3263 p
->info
? p
->info
: "");
3276 * 'add_printer_defaults()' - Add name-default attributes to the printer attributes.
3280 add_printer_defaults(cupsd_printer_t
*p
)/* I - Printer */
3282 int i
; /* Looping var */
3283 int num_options
; /* Number of default options */
3284 cups_option_t
*options
, /* Default options */
3285 *option
; /* Current option */
3286 char name
[256]; /* name-default */
3290 * Maintain a common array of default attribute names...
3293 if (!CommonDefaults
)
3295 CommonDefaults
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
3297 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("copies-default"));
3298 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("document-format-default"));
3299 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("finishings-default"));
3300 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-account-id-default"));
3301 cupsArrayAdd(CommonDefaults
,
3302 _cupsStrAlloc("job-accounting-user-id-default"));
3303 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-cancel-after-default"));
3304 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-hold-until-default"));
3305 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-priority-default"));
3306 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-sheets-default"));
3307 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("media-col-default"));
3308 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("number-up-default"));
3309 cupsArrayAdd(CommonDefaults
,
3310 _cupsStrAlloc("orientation-requested-default"));
3314 * Add all of the default options from the .conf files...
3317 for (num_options
= 0, options
= NULL
, i
= p
->num_options
, option
= p
->options
;
3321 if (strcmp(option
->name
, "ipp-options") &&
3322 strcmp(option
->name
, "job-sheets") &&
3323 strcmp(option
->name
, "lease-duration"))
3325 snprintf(name
, sizeof(name
), "%s-default", option
->name
);
3326 num_options
= cupsAddOption(name
, option
->value
, num_options
, &options
);
3328 if (!cupsArrayFind(CommonDefaults
, name
))
3329 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc(name
));
3334 * Convert options to IPP attributes...
3337 cupsEncodeOptions2(p
->attrs
, num_options
, options
, IPP_TAG_PRINTER
);
3338 cupsFreeOptions(num_options
, options
);
3341 * Add standard -default attributes as needed...
3344 if (!cupsGetOption("copies", p
->num_options
, p
->options
))
3345 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
, "copies-default",
3348 if (!cupsGetOption("document-format", p
->num_options
, p
->options
))
3349 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_MIMETYPE
,
3350 "document-format-default", NULL
, "application/octet-stream");
3352 if (!cupsGetOption("job-cancel-after", p
->num_options
, p
->options
))
3353 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3354 "job-cancel-after-default", MaxJobTime
);
3356 if (!cupsGetOption("job-hold-until", p
->num_options
, p
->options
))
3357 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3358 "job-hold-until-default", NULL
, "no-hold");
3360 if (!cupsGetOption("job-priority", p
->num_options
, p
->options
))
3361 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3362 "job-priority-default", 50);
3364 if (!cupsGetOption("number-up", p
->num_options
, p
->options
))
3365 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3366 "number-up-default", 1);
3368 if (!cupsGetOption("notify-lease-duration", p
->num_options
, p
->options
))
3369 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3370 "notify-lease-duration-default", DefaultLeaseDuration
);
3372 if (!cupsGetOption("notify-events", p
->num_options
, p
->options
))
3373 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3374 "notify-events-default", NULL
, "job-completed");
3376 if (!cupsGetOption("orientation-requested", p
->num_options
, p
->options
))
3377 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NOVALUE
,
3378 "orientation-requested-default", NULL
, NULL
);
3380 if (!cupsGetOption("print-quality", p
->num_options
, p
->options
))
3381 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
3382 "print-quality-default", IPP_QUALITY_NORMAL
);
3387 * 'add_printer_filter()' - Add a MIME filter for a printer.
3392 cupsd_printer_t
*p
, /* I - Printer to add to */
3393 mime_type_t
*filtertype
, /* I - Filter or prefilter MIME type */
3394 const char *filter
) /* I - Filter to add */
3396 char super
[MIME_MAX_SUPER
], /* Super-type for filter */
3397 type
[MIME_MAX_TYPE
], /* Type for filter */
3398 dsuper
[MIME_MAX_SUPER
], /* Destination super-type for filter */
3399 dtype
[MIME_MAX_TYPE
], /* Destination type for filter */
3400 dest
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2],
3401 /* Destination super/type */
3402 program
[1024]; /* Program/filter name */
3403 int cost
; /* Cost of filter */
3404 size_t maxsize
= 0; /* Maximum supported file size */
3405 mime_type_t
*temptype
, /* MIME type looping var */
3406 *desttype
; /* Destination MIME type */
3407 mime_filter_t
*filterptr
; /* MIME filter */
3408 char filename
[1024]; /* Full filter filename */
3411 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3412 "add_printer_filter(p=%p(%s), filtertype=%p(%s/%s), "
3413 "filter=\"%s\")", p
, p
->name
, filtertype
, filtertype
->super
,
3414 filtertype
->type
, filter
);
3417 * Parse the filter string; it should be in one of the following formats:
3419 * source/type cost program
3420 * source/type cost maxsize(nnnn) program
3421 * source/type dest/type cost program
3422 * source/type dest/type cost maxsize(nnnn) program
3425 if (sscanf(filter
, "%15[^/]/%255s%*[ \t]%15[^/]/%255s%d%*[ \t]%1023[^\n]",
3426 super
, type
, dsuper
, dtype
, &cost
, program
) == 6)
3428 snprintf(dest
, sizeof(dest
), "%s/%s/%s", p
->name
, dsuper
, dtype
);
3430 if ((desttype
= mimeType(MimeDatabase
, "printer", dest
)) == NULL
)
3432 desttype
= mimeAddType(MimeDatabase
, "printer", dest
);
3434 p
->dest_types
= cupsArrayNew(NULL
, NULL
);
3436 cupsArrayAdd(p
->dest_types
, desttype
);
3442 if (sscanf(filter
, "%15[^/]/%255s%d%*[ \t]%1023[^\n]", super
, type
, &cost
,
3445 desttype
= filtertype
;
3449 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: invalid filter string \"%s\"!",
3455 if (!strncmp(program
, "maxsize(", 8))
3457 char *ptr
; /* Pointer into maxsize(nnnn) program */
3459 maxsize
= (size_t)strtoll(program
+ 8, &ptr
, 10);
3463 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: invalid filter string \"%s\"!",
3469 while (_cups_isspace(*ptr
))
3472 _cups_strcpy(program
, ptr
);
3476 * Check permissions on the filter and its containing directory...
3479 if (strcmp(program
, "-"))
3481 if (program
[0] == '/')
3482 strlcpy(filename
, program
, sizeof(filename
));
3484 snprintf(filename
, sizeof(filename
), "%s/filter/%s", ServerBin
, program
);
3486 _cupsFileCheck(filename
, _CUPS_FILE_CHECK_PROGRAM
, !RunUser
,
3487 cupsdLogFCMessage
, p
);
3491 * Add the filter to the MIME database, supporting wildcards as needed...
3494 for (temptype
= mimeFirstType(MimeDatabase
);
3496 temptype
= mimeNextType(MimeDatabase
))
3497 if (((super
[0] == '*' && _cups_strcasecmp(temptype
->super
, "printer")) ||
3498 !_cups_strcasecmp(temptype
->super
, super
)) &&
3499 (type
[0] == '*' || !_cups_strcasecmp(temptype
->type
, type
)))
3501 if (desttype
!= filtertype
)
3503 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3504 "add_printer_filter: %s: adding filter %s/%s %s/%s %d "
3505 "%s", p
->name
, temptype
->super
, temptype
->type
,
3506 desttype
->super
, desttype
->type
,
3508 filterptr
= mimeAddFilter(MimeDatabase
, temptype
, desttype
, cost
,
3511 if (!mimeFilterLookup(MimeDatabase
, desttype
, filtertype
))
3513 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3514 "add_printer_filter: %s: adding filter %s/%s %s/%s "
3515 "0 -", p
->name
, desttype
->super
, desttype
->type
,
3516 filtertype
->super
, filtertype
->type
);
3517 mimeAddFilter(MimeDatabase
, desttype
, filtertype
, 0, "-");
3522 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3523 "add_printer_filter: %s: adding filter %s/%s %s/%s %d "
3524 "%s", p
->name
, temptype
->super
, temptype
->type
,
3525 filtertype
->super
, filtertype
->type
,
3527 filterptr
= mimeAddFilter(MimeDatabase
, temptype
, filtertype
, cost
,
3532 filterptr
->maxsize
= maxsize
;
3538 * 'add_printer_formats()' - Add document-format-supported values for a printer.
3542 add_printer_formats(cupsd_printer_t
*p
) /* I - Printer */
3544 int i
; /* Looping var */
3545 mime_type_t
*type
; /* Current MIME type */
3546 cups_array_t
*filters
; /* Filters */
3547 ipp_attribute_t
*attr
; /* document-format-supported attribute */
3548 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
3549 /* MIME type name */
3553 * Raw (and remote) queues advertise all of the supported MIME
3557 cupsArrayDelete(p
->filetypes
);
3558 p
->filetypes
= NULL
;
3562 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
,
3563 (ipp_tag_t
)(IPP_TAG_MIMETYPE
| IPP_TAG_COPY
),
3564 "document-format-supported", NumMimeTypes
, NULL
, MimeTypes
);
3569 * Otherwise, loop through the supported MIME types and see if there
3570 * are filters for them...
3573 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_printer_formats: %d types, %d filters",
3574 mimeNumTypes(MimeDatabase
), mimeNumFilters(MimeDatabase
));
3576 p
->filetypes
= cupsArrayNew(NULL
, NULL
);
3578 for (type
= mimeFirstType(MimeDatabase
);
3580 type
= mimeNextType(MimeDatabase
))
3582 if (!_cups_strcasecmp(type
->super
, "printer"))
3585 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
3587 if ((filters
= mimeFilter(MimeDatabase
, type
, p
->filetype
, NULL
)) != NULL
)
3589 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3590 "add_printer_formats: %s: %s needs %d filters",
3591 p
->name
, mimetype
, cupsArrayCount(filters
));
3593 cupsArrayDelete(filters
);
3594 cupsArrayAdd(p
->filetypes
, type
);
3597 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3598 "add_printer_formats: %s: %s not supported",
3603 * Add the file formats that can be filtered...
3606 if ((type
= mimeType(MimeDatabase
, "application", "octet-stream")) == NULL
||
3607 !cupsArrayFind(p
->filetypes
, type
))
3612 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3613 "add_printer_formats: %s: %d supported types",
3614 p
->name
, cupsArrayCount(p
->filetypes
) + i
);
3616 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_MIMETYPE
,
3617 "document-format-supported",
3618 cupsArrayCount(p
->filetypes
) + i
, NULL
, NULL
);
3621 attr
->values
[0].string
.text
= _cupsStrAlloc("application/octet-stream");
3623 for (type
= (mime_type_t
*)cupsArrayFirst(p
->filetypes
);
3625 i
++, type
= (mime_type_t
*)cupsArrayNext(p
->filetypes
))
3627 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
3629 attr
->values
[i
].string
.text
= _cupsStrAlloc(mimetype
);
3632 #if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
3634 char pdl
[1024]; /* Buffer to build pdl list */
3635 mime_filter_t
*filter
; /* MIME filter looping var */
3639 * We only support raw printing if this is not a Tioga PrintJobMgr based
3640 * queue and if application/octet-stream is a known type...
3643 for (filter
= (mime_filter_t
*)cupsArrayFirst(MimeDatabase
->filters
);
3645 filter
= (mime_filter_t
*)cupsArrayNext(MimeDatabase
->filters
))
3647 if (filter
->dst
== p
->filetype
&& strstr(filter
->filter
, "PrintJobMgr"))
3653 if (!filter
&& mimeType(MimeDatabase
, "application", "octet-stream"))
3654 strlcat(pdl
, "application/octet-stream,", sizeof(pdl
));
3657 * Then list a bunch of formats that are supported by the printer...
3660 for (type
= (mime_type_t
*)cupsArrayFirst(p
->filetypes
);
3662 type
= (mime_type_t
*)cupsArrayNext(p
->filetypes
))
3664 if (!_cups_strcasecmp(type
->super
, "application"))
3666 if (!_cups_strcasecmp(type
->type
, "pdf"))
3667 strlcat(pdl
, "application/pdf,", sizeof(pdl
));
3668 else if (!_cups_strcasecmp(type
->type
, "postscript"))
3669 strlcat(pdl
, "application/postscript,", sizeof(pdl
));
3671 else if (!_cups_strcasecmp(type
->super
, "image"))
3673 if (!_cups_strcasecmp(type
->type
, "jpeg"))
3674 strlcat(pdl
, "image/jpeg,", sizeof(pdl
));
3675 else if (!_cups_strcasecmp(type
->type
, "png"))
3676 strlcat(pdl
, "image/png,", sizeof(pdl
));
3677 else if (!_cups_strcasecmp(type
->type
, "pwg-raster"))
3678 strlcat(pdl
, "image/pwg-raster,", sizeof(pdl
));
3683 pdl
[strlen(pdl
) - 1] = '\0'; /* Remove trailing comma */
3685 cupsdSetString(&p
->pdl
, pdl
);
3687 #endif /* HAVE_DNSSD || HAVE_AVAHI */
3692 * 'compare_printers()' - Compare two printers.
3695 static int /* O - Result of comparison */
3696 compare_printers(void *first
, /* I - First printer */
3697 void *second
, /* I - Second printer */
3698 void *data
) /* I - App data (not used) */
3702 return (_cups_strcasecmp(((cupsd_printer_t
*)first
)->name
,
3703 ((cupsd_printer_t
*)second
)->name
));
3708 * 'delete_printer_filters()' - Delete all MIME filters for a printer.
3712 delete_printer_filters(
3713 cupsd_printer_t
*p
) /* I - Printer to remove from */
3715 mime_filter_t
*filter
; /* MIME filter looping var */
3716 mime_type_t
*type
; /* Destination types for filters */
3720 * Range check input...
3727 * Remove all filters from the MIME database that have a destination
3728 * type == printer...
3731 for (filter
= mimeFirstFilter(MimeDatabase
);
3733 filter
= mimeNextFilter(MimeDatabase
))
3734 if (filter
->dst
== p
->filetype
|| filter
->dst
== p
->prefiltertype
||
3735 cupsArrayFind(p
->dest_types
, filter
->dst
))
3738 * Delete the current filter...
3741 mimeDeleteFilter(MimeDatabase
, filter
);
3744 for (type
= (mime_type_t
*)cupsArrayFirst(p
->dest_types
);
3746 type
= (mime_type_t
*)cupsArrayNext(p
->dest_types
))
3747 mimeDeleteType(MimeDatabase
, type
);
3749 cupsArrayDelete(p
->dest_types
);
3750 p
->dest_types
= NULL
;
3752 cupsdSetPrinterReasons(p
, "-cups-insecure-filter-warning"
3753 ",cups-missing-filter-warning");
3758 * 'dirty_printer()' - Mark config and state files dirty for the specified
3763 dirty_printer(cupsd_printer_t
*p
) /* I - Printer */
3765 if (p
->type
& CUPS_PRINTER_CLASS
)
3766 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
3768 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
3770 if (PrintcapFormat
== PRINTCAP_PLIST
)
3771 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
3776 * 'load_ppd()' - Load a cached PPD file, updating the cache as needed.
3780 load_ppd(cupsd_printer_t
*p
) /* I - Printer */
3782 int i
, j
, k
; /* Looping vars */
3783 char cache_name
[1024]; /* Cache filename */
3784 struct stat cache_info
; /* Cache file info */
3785 ppd_file_t
*ppd
; /* PPD file */
3786 char ppd_name
[1024]; /* PPD filename */
3787 struct stat ppd_info
; /* PPD file info */
3788 int num_media
; /* Number of media options */
3789 ppd_size_t
*size
; /* Current PPD size */
3790 ppd_option_t
*duplex
, /* Duplex option */
3791 *output_bin
, /* OutputBin option */
3792 *output_mode
, /* OutputMode option */
3793 *resolution
; /* (Set|JCL|)Resolution option */
3794 ppd_choice_t
*choice
, /* Current PPD choice */
3795 *input_slot
, /* Current input slot */
3796 *media_type
; /* Current media type */
3797 ppd_attr_t
*ppd_attr
; /* PPD attribute */
3798 int xdpi
, /* Horizontal resolution */
3799 ydpi
; /* Vertical resolution */
3800 const char *resptr
; /* Pointer into resolution keyword */
3801 _pwg_size_t
*pwgsize
; /* Current PWG size */
3802 _pwg_map_t
*pwgsource
, /* Current PWG source */
3803 *pwgtype
; /* Current PWG type */
3804 ipp_attribute_t
*attr
; /* Attribute data */
3805 _ipp_value_t
*val
; /* Attribute value */
3806 int num_finishings
, /* Number of finishings */
3807 finishings
[5]; /* finishings-supported values */
3808 int num_qualities
, /* Number of print-quality values */
3809 qualities
[3]; /* print-quality values */
3810 int num_margins
, /* Number of media-*-margin-supported values */
3811 margins
[16]; /* media-*-margin-supported values */
3812 const char *filter
, /* Current filter */
3813 *mandatory
; /* Current mandatory attribute */
3814 static const char * const sides
[3] = /* sides-supported values */
3817 "two-sided-long-edge",
3818 "two-sided-short-edge"
3820 static const char * const standard_commands
[] =
3821 { /* Standard CUPS commands */
3829 * Check to see if the cache is up-to-date...
3832 snprintf(cache_name
, sizeof(cache_name
), "%s/%s.data", CacheDir
, p
->name
);
3833 if (stat(cache_name
, &cache_info
))
3834 cache_info
.st_mtime
= 0;
3836 snprintf(ppd_name
, sizeof(ppd_name
), "%s/ppd/%s.ppd", ServerRoot
, p
->name
);
3837 if (stat(ppd_name
, &ppd_info
))
3838 ppd_info
.st_mtime
= 1;
3840 ippDelete(p
->ppd_attrs
);
3841 p
->ppd_attrs
= NULL
;
3843 _ppdCacheDestroy(p
->pc
);
3846 if (cache_info
.st_mtime
>= ppd_info
.st_mtime
)
3848 cupsdLogMessage(CUPSD_LOG_DEBUG
, "load_ppd: Loading %s...", cache_name
);
3850 if ((p
->pc
= _ppdCacheCreateWithFile(cache_name
, &p
->ppd_attrs
)) != NULL
&&
3854 * Loaded successfully!
3862 * Reload PPD attributes from disk...
3865 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
3867 cupsdLogMessage(CUPSD_LOG_DEBUG
, "load_ppd: Loading %s...", ppd_name
);
3869 cupsdClearString(&(p
->make_model
));
3871 p
->type
&= (cups_ptype_t
)~CUPS_PRINTER_OPTIONS
;
3872 p
->type
|= CUPS_PRINTER_BW
;
3874 finishings
[0] = IPP_FINISHINGS_NONE
;
3877 p
->ppd_attrs
= ippNew();
3879 if ((ppd
= _ppdOpenFile(ppd_name
, _PPD_LOCALIZATION_NONE
)) != NULL
)
3882 * Add make/model and other various attributes...
3885 p
->pc
= _ppdCacheCreateWithPPD(ppd
);
3888 cupsdLogMessage(CUPSD_LOG_WARN
, "Unable to create cache of \"%s\": %s",
3889 ppd_name
, cupsLastErrorString());
3891 ppdMarkDefaults(ppd
);
3893 if (ppd
->color_device
)
3894 p
->type
|= CUPS_PRINTER_COLOR
;
3895 if (ppd
->variable_sizes
)
3896 p
->type
|= CUPS_PRINTER_VARIABLE
;
3897 if (!ppd
->manual_copies
)
3898 p
->type
|= CUPS_PRINTER_COPIES
;
3899 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsFax", NULL
)) != NULL
)
3900 if (ppd_attr
->value
&& !_cups_strcasecmp(ppd_attr
->value
, "true"))
3901 p
->type
|= CUPS_PRINTER_FAX
;
3903 ippAddBoolean(p
->ppd_attrs
, IPP_TAG_PRINTER
, "color-supported", (char)ppd
->color_device
);
3905 if (p
->pc
&& p
->pc
->charge_info_uri
)
3906 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
3907 "printer-charge-info-uri", NULL
, p
->pc
->charge_info_uri
);
3909 if (p
->pc
&& p
->pc
->account_id
)
3910 ippAddBoolean(p
->ppd_attrs
, IPP_TAG_PRINTER
, "job-account-id-supported",
3913 if (p
->pc
&& p
->pc
->accounting_user_id
)
3914 ippAddBoolean(p
->ppd_attrs
, IPP_TAG_PRINTER
,
3915 "job-accounting-user-id-supported", 1);
3917 if (p
->pc
&& p
->pc
->password
)
3919 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3920 "job-password-encryption-supported", NULL
, "none");
3921 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3922 "job-password-supported", (int)strlen(p
->pc
->password
));
3925 if (ppd
->throughput
)
3927 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3928 "pages-per-minute", ppd
->throughput
);
3929 if (ppd
->color_device
)
3930 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3931 "pages-per-minute-color", ppd
->throughput
);
3936 * When there is no speed information, just say "1 page per minute".
3939 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3940 "pages-per-minute", 1);
3941 if (ppd
->color_device
)
3942 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3943 "pages-per-minute-color", 1);
3946 if ((ppd_attr
= ppdFindAttr(ppd
, "1284DeviceId", NULL
)) != NULL
)
3947 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-device-id", NULL
, ppd_attr
->value
);
3951 if ((output_mode
= ppdFindOption(ppd
, "OutputMode")) != NULL
)
3953 if (ppdFindChoice(output_mode
, "draft") ||
3954 ppdFindChoice(output_mode
, "fast"))
3955 qualities
[num_qualities
++] = IPP_QUALITY_DRAFT
;
3957 qualities
[num_qualities
++] = IPP_QUALITY_NORMAL
;
3959 if (ppdFindChoice(output_mode
, "best") ||
3960 ppdFindChoice(output_mode
, "high"))
3961 qualities
[num_qualities
++] = IPP_QUALITY_HIGH
;
3963 else if ((ppd_attr
= ppdFindAttr(ppd
, "APPrinterPreset", NULL
)) != NULL
)
3967 if (strstr(ppd_attr
->spec
, "draft") ||
3968 strstr(ppd_attr
->spec
, "Draft"))
3970 qualities
[num_qualities
++] = IPP_QUALITY_DRAFT
;
3974 while ((ppd_attr
= ppdFindNextAttr(ppd
, "APPrinterPreset",
3977 qualities
[num_qualities
++] = IPP_QUALITY_NORMAL
;
3978 qualities
[num_qualities
++] = IPP_QUALITY_HIGH
;
3981 qualities
[num_qualities
++] = IPP_QUALITY_NORMAL
;
3983 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
3984 "print-quality-supported", num_qualities
, qualities
);
3989 * The NickName can be localized in the character set specified
3990 * by the LanugageEncoding attribute. However, ppdOpen2() has
3991 * already converted the ppd->nickname member to UTF-8 for us
3992 * (the original attribute value is available separately)
3995 cupsdSetString(&p
->make_model
, ppd
->nickname
);
3997 else if (ppd
->modelname
)
4000 * Model name can only contain specific characters...
4003 cupsdSetString(&p
->make_model
, ppd
->modelname
);
4006 cupsdSetString(&p
->make_model
, "Bad PPD File");
4008 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
4009 "printer-make-and-model", NULL
, p
->make_model
);
4012 * Add media options from the PPD file...
4015 if (ppd
->num_sizes
== 0 || !p
->pc
)
4017 if (!ppdFindAttr(ppd
, "APScannerOnly", NULL
) && !ppdFindAttr(ppd
, "cups3D", NULL
))
4018 cupsdLogMessage(CUPSD_LOG_CRIT
,
4019 "The PPD file for printer %s contains no media "
4020 "options and is therefore invalid.", p
->name
);
4022 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4023 "media-default", NULL
, "unknown");
4024 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4025 "media-supported", NULL
, "unknown");
4033 if ((size
= ppdPageSize(ppd
, NULL
)) != NULL
)
4034 pwgsize
= _ppdCacheGetSize(p
->pc
, size
->name
);
4038 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4039 "media-default", NULL
,
4040 pwgsize
? pwgsize
->map
.pwg
: "unknown");
4048 ipp_t
*col
; /* Collection value */
4050 input_slot
= ppdFindMarkedChoice(ppd
, "InputSlot");
4051 media_type
= ppdFindMarkedChoice(ppd
, "MediaType");
4052 col
= new_media_col(pwgsize
,
4054 _ppdCacheGetSource(p
->pc
,
4055 input_slot
->choice
) :
4058 _ppdCacheGetType(p
->pc
,
4059 media_type
->choice
) :
4062 ippAddCollection(p
->ppd_attrs
, IPP_TAG_PRINTER
, "media-col-default",
4071 num_media
= p
->pc
->num_sizes
;
4072 if (p
->pc
->custom_min_keyword
)
4075 if ((attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4076 "media-supported", num_media
, NULL
,
4081 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
;
4083 i
--, pwgsize
++, val
++)
4084 val
->string
.text
= _cupsStrAlloc(pwgsize
->map
.pwg
);
4086 if (p
->pc
->custom_min_keyword
)
4088 val
->string
.text
= _cupsStrAlloc(p
->pc
->custom_min_keyword
);
4090 val
->string
.text
= _cupsStrAlloc(p
->pc
->custom_max_keyword
);
4095 * media-size-supported
4098 num_media
= p
->pc
->num_sizes
;
4099 if (p
->pc
->custom_min_keyword
)
4102 if ((attr
= ippAddCollections(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4103 "media-size-supported", num_media
,
4108 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
;
4110 i
--, pwgsize
++, val
++)
4112 val
->collection
= ippNew();
4113 ippAddInteger(val
->collection
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4114 "x-dimension", pwgsize
->width
);
4115 ippAddInteger(val
->collection
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4116 "y-dimension", pwgsize
->length
);
4119 if (p
->pc
->custom_min_keyword
)
4121 val
->collection
= ippNew();
4122 ippAddRange(val
->collection
, IPP_TAG_PRINTER
, "x-dimension",
4123 p
->pc
->custom_min_width
, p
->pc
->custom_max_width
);
4124 ippAddRange(val
->collection
, IPP_TAG_PRINTER
, "y-dimension",
4125 p
->pc
->custom_min_length
, p
->pc
->custom_max_length
);
4130 * media-source-supported
4133 if (p
->pc
->num_sources
> 0 &&
4134 (attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4135 "media-source-supported", p
->pc
->num_sources
,
4136 NULL
, NULL
)) != NULL
)
4138 for (i
= p
->pc
->num_sources
, pwgsource
= p
->pc
->sources
,
4141 i
--, pwgsource
++, val
++)
4142 val
->string
.text
= _cupsStrAlloc(pwgsource
->pwg
);
4146 * media-type-supported
4149 if (p
->pc
->num_types
> 0 &&
4150 (attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4151 "media-type-supported", p
->pc
->num_types
,
4152 NULL
, NULL
)) != NULL
)
4154 for (i
= p
->pc
->num_types
, pwgtype
= p
->pc
->types
,
4157 i
--, pwgtype
++, val
++)
4158 val
->string
.text
= _cupsStrAlloc(pwgtype
->pwg
);
4162 * media-*-margin-supported
4165 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, num_margins
= 0;
4166 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4169 for (j
= 0; j
< num_margins
; j
++)
4170 if (pwgsize
->bottom
== margins
[j
])
4173 if (j
>= num_margins
)
4175 margins
[num_margins
] = pwgsize
->bottom
;
4180 if (num_margins
> 0)
4181 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4182 "media-bottom-margin-supported", num_margins
, margins
);
4184 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4185 "media-bottom-margin-supported", 0);
4187 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, num_margins
= 0;
4188 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4191 for (j
= 0; j
< num_margins
; j
++)
4192 if (pwgsize
->left
== margins
[j
])
4195 if (j
>= num_margins
)
4197 margins
[num_margins
] = pwgsize
->left
;
4202 if (num_margins
> 0)
4203 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4204 "media-left-margin-supported", num_margins
, margins
);
4206 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4207 "media-left-margin-supported", 0);
4209 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, num_margins
= 0;
4210 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4213 for (j
= 0; j
< num_margins
; j
++)
4214 if (pwgsize
->right
== margins
[j
])
4217 if (j
>= num_margins
)
4219 margins
[num_margins
] = pwgsize
->right
;
4224 if (num_margins
> 0)
4225 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4226 "media-right-margin-supported", num_margins
, margins
);
4228 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4229 "media-right-margin-supported", 0);
4231 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, num_margins
= 0;
4232 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4235 for (j
= 0; j
< num_margins
; j
++)
4236 if (pwgsize
->top
== margins
[j
])
4239 if (j
>= num_margins
)
4241 margins
[num_margins
] = pwgsize
->top
;
4246 if (num_margins
> 0)
4247 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4248 "media-top-margin-supported", num_margins
, margins
);
4250 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4251 "media-top-margin-supported", 0);
4254 * media-col-database
4257 num_media
= p
->pc
->num_sizes
;
4258 if (p
->pc
->num_sources
)
4260 if (p
->pc
->num_types
> 0)
4261 num_media
+= p
->pc
->num_sizes
* p
->pc
->num_sources
*
4264 num_media
+= p
->pc
->num_sizes
* p
->pc
->num_sources
;
4266 else if (p
->pc
->num_types
)
4267 num_media
+= p
->pc
->num_sizes
* p
->pc
->num_types
;
4269 if ((attr
= ippAddCollections(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4270 "media-col-database", num_media
,
4273 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, val
= attr
->values
;
4278 * Start by adding the page size without source or type...
4281 ppdMarkOption(ppd
, "PageSize", pwgsize
->map
.ppd
);
4283 val
->collection
= new_media_col(pwgsize
, NULL
, NULL
);
4287 * Then add the specific, supported combinations of size, source, and
4291 if (p
->pc
->num_sources
> 0)
4293 for (j
= p
->pc
->num_sources
, pwgsource
= p
->pc
->sources
;
4297 ppdMarkOption(ppd
, "InputSlot", pwgsource
->ppd
);
4299 if (p
->pc
->num_types
> 0)
4301 for (k
= p
->pc
->num_types
, pwgtype
= p
->pc
->types
;
4305 if (!ppdMarkOption(ppd
, "MediaType", pwgtype
->ppd
))
4307 val
->collection
= new_media_col(pwgsize
, pwgsource
->pwg
,
4313 else if (!ppdConflicts(ppd
))
4315 val
->collection
= new_media_col(pwgsize
, pwgsource
->pwg
, NULL
);
4320 else if (p
->pc
->num_types
> 0)
4322 for (j
= p
->pc
->num_types
, pwgtype
= p
->pc
->types
;
4326 if (!ppdMarkOption(ppd
, "MediaType", pwgtype
->ppd
))
4328 val
->collection
= new_media_col(pwgsize
, NULL
, pwgtype
->pwg
);
4336 * Update the number of media-col-database values...
4339 attr
->num_values
= val
- attr
->values
;
4347 if (p
->pc
&& p
->pc
->num_bins
> 0)
4349 attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4350 "output-bin-supported", p
->pc
->num_bins
,
4355 for (i
= 0, val
= attr
->values
;
4356 i
< p
->pc
->num_bins
;
4358 val
->string
.text
= _cupsStrAlloc(p
->pc
->bins
[i
].pwg
);
4361 if ((output_bin
= ppdFindOption(ppd
, "OutputBin")) != NULL
)
4363 for (i
= 0; i
< p
->pc
->num_bins
; i
++)
4364 if (!strcmp(p
->pc
->bins
[i
].ppd
, output_bin
->defchoice
))
4367 if (i
>= p
->pc
->num_bins
)
4370 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4371 "output-bin-default", NULL
, p
->pc
->bins
[i
].pwg
);
4374 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4375 "output-bin-default", NULL
, p
->pc
->bins
[0].pwg
);
4377 else if (((ppd_attr
= ppdFindAttr(ppd
, "DefaultOutputOrder",
4379 !_cups_strcasecmp(ppd_attr
->value
, "Reverse")) ||
4380 (!ppd_attr
&& ppd
->manufacturer
&& /* "Compatibility heuristic" */
4381 (!_cups_strcasecmp(ppd
->manufacturer
, "epson") ||
4382 !_cups_strcasecmp(ppd
->manufacturer
, "lexmark"))))
4385 * Report that this printer has a single output bin that leaves pages face
4389 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4390 "output-bin-supported", NULL
, "face-up");
4391 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4392 "output-bin-default", NULL
, "face-up");
4396 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4397 "output-bin-supported", NULL
, "face-down");
4398 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4399 "output-bin-default", NULL
, "face-down");
4403 * print-color-mode...
4406 if (ppd
->color_device
)
4408 static const char * const color_modes
[] =
4414 ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4415 "print-color-mode-supported", 2, NULL
, color_modes
);
4416 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4417 "print-color-mode-default", NULL
, "color");
4421 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4422 "print-color-mode-supported", NULL
, "monochrome");
4423 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4424 "print-color-mode-default", NULL
, "monochrome");
4428 * Mandatory job attributes, if any...
4431 if (p
->pc
&& cupsArrayCount(p
->pc
->mandatory
) > 0)
4433 int count
= cupsArrayCount(p
->pc
->mandatory
);
4434 /* Number of mandatory attributes */
4436 attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4437 "printer-mandatory-job-attributes", count
, NULL
,
4440 for (val
= attr
->values
,
4441 mandatory
= (char *)cupsArrayFirst(p
->pc
->mandatory
);
4443 val
++, mandatory
= (char *)cupsArrayNext(p
->pc
->mandatory
))
4444 val
->string
.text
= _cupsStrAlloc(mandatory
);
4448 * Printer resolutions...
4451 if ((resolution
= ppdFindOption(ppd
, "Resolution")) == NULL
)
4452 if ((resolution
= ppdFindOption(ppd
, "JCLResolution")) == NULL
)
4453 if ((resolution
= ppdFindOption(ppd
, "SetResolution")) == NULL
)
4454 resolution
= ppdFindOption(ppd
, "CNRes_PGP");
4459 * Report all supported resolutions...
4462 attr
= ippAddResolutions(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4463 "printer-resolution-supported",
4464 resolution
->num_choices
, IPP_RES_PER_INCH
,
4467 for (i
= 0, choice
= resolution
->choices
;
4468 i
< resolution
->num_choices
;
4471 xdpi
= ydpi
= (int)strtol(choice
->choice
, (char **)&resptr
, 10);
4472 if (resptr
> choice
->choice
&& xdpi
> 0 && *resptr
== 'x')
4473 ydpi
= (int)strtol(resptr
+ 1, (char **)&resptr
, 10);
4475 if (xdpi
<= 0 || ydpi
<= 0)
4477 cupsdLogMessage(CUPSD_LOG_WARN
,
4478 "Bad resolution \"%s\" for printer %s.",
4479 choice
->choice
, p
->name
);
4483 attr
->values
[i
].resolution
.xres
= xdpi
;
4484 attr
->values
[i
].resolution
.yres
= ydpi
;
4485 attr
->values
[i
].resolution
.units
= IPP_RES_PER_INCH
;
4488 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4489 "printer-resolution-default", IPP_RES_PER_INCH
,
4493 else if ((ppd_attr
= ppdFindAttr(ppd
, "DefaultResolution", NULL
)) != NULL
&&
4497 * Just the DefaultResolution to report...
4500 xdpi
= ydpi
= (int)strtol(ppd_attr
->value
, (char **)&resptr
, 10);
4501 if (resptr
> ppd_attr
->value
&& xdpi
> 0)
4504 ydpi
= (int)strtol(resptr
+ 1, (char **)&resptr
, 10);
4509 if (xdpi
<= 0 || ydpi
<= 0)
4511 cupsdLogMessage(CUPSD_LOG_WARN
,
4512 "Bad default resolution \"%s\" for printer %s.",
4513 ppd_attr
->value
, p
->name
);
4517 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4518 "printer-resolution-default", IPP_RES_PER_INCH
,
4520 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4521 "printer-resolution-supported", IPP_RES_PER_INCH
,
4527 * No resolutions in PPD - make one up...
4530 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4531 "printer-resolution-default", IPP_RES_PER_INCH
,
4533 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4534 "printer-resolution-supported", IPP_RES_PER_INCH
,
4542 ppdMarkDefaults(ppd
);
4544 if ((duplex
= ppdFindOption(ppd
, "Duplex")) == NULL
)
4545 if ((duplex
= ppdFindOption(ppd
, "EFDuplex")) == NULL
)
4546 if ((duplex
= ppdFindOption(ppd
, "EFDuplexing")) == NULL
)
4547 if ((duplex
= ppdFindOption(ppd
, "KD03Duplex")) == NULL
)
4548 duplex
= ppdFindOption(ppd
, "JCLDuplex");
4550 if (duplex
&& duplex
->num_choices
> 1 &&
4551 !ppdInstallableConflict(ppd
, duplex
->keyword
, "DuplexTumble"))
4553 p
->type
|= CUPS_PRINTER_DUPLEX
;
4555 ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4556 "sides-supported", 3, NULL
, sides
);
4558 if (!_cups_strcasecmp(duplex
->defchoice
, "DuplexTumble"))
4559 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4560 "sides-default", NULL
, "two-sided-short-edge");
4561 else if (!_cups_strcasecmp(duplex
->defchoice
, "DuplexNoTumble"))
4562 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4563 "sides-default", NULL
, "two-sided-long-edge");
4565 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4566 "sides-default", NULL
, "one-sided");
4570 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4571 "sides-supported", NULL
, "one-sided");
4572 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4573 "sides-default", NULL
, "one-sided");
4576 if (ppdFindOption(ppd
, "Collate") != NULL
)
4577 p
->type
|= CUPS_PRINTER_COLLATE
;
4579 if (ppdFindOption(ppd
, "StapleLocation") != NULL
)
4581 p
->type
|= CUPS_PRINTER_STAPLE
;
4582 finishings
[num_finishings
++] = IPP_FINISHINGS_STAPLE
;
4585 if (ppdFindOption(ppd
, "BindEdge") != NULL
)
4587 p
->type
|= CUPS_PRINTER_BIND
;
4588 finishings
[num_finishings
++] = IPP_FINISHINGS_BIND
;
4591 for (i
= 0; i
< ppd
->num_sizes
; i
++)
4592 if (ppd
->sizes
[i
].length
> 1728)
4593 p
->type
|= CUPS_PRINTER_LARGE
;
4594 else if (ppd
->sizes
[i
].length
> 1008)
4595 p
->type
|= CUPS_PRINTER_MEDIUM
;
4597 p
->type
|= CUPS_PRINTER_SMALL
;
4599 if ((ppd_attr
= ppdFindAttr(ppd
, "APICADriver", NULL
)) != NULL
&&
4600 ppd_attr
->value
&& !_cups_strcasecmp(ppd_attr
->value
, "true"))
4602 if ((ppd_attr
= ppdFindAttr(ppd
, "APScannerOnly", NULL
)) != NULL
&&
4603 ppd_attr
->value
&& !_cups_strcasecmp(ppd_attr
->value
, "true"))
4604 p
->type
|= CUPS_PRINTER_SCANNER
;
4606 p
->type
|= CUPS_PRINTER_MFP
;
4610 * Scan the filters in the PPD file...
4615 for (filter
= (const char *)cupsArrayFirst(p
->pc
->filters
);
4617 filter
= (const char *)cupsArrayNext(p
->pc
->filters
))
4619 if (!_cups_strncasecmp(filter
, "application/vnd.cups-command", 28) &&
4620 _cups_isspace(filter
[28]))
4622 p
->type
|= CUPS_PRINTER_COMMANDS
;
4628 if (p
->type
& CUPS_PRINTER_COMMANDS
)
4630 char *commands
, /* Copy of commands */
4631 *start
, /* Start of name */
4632 *end
; /* End of name */
4633 int count
; /* Number of commands */
4635 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsCommands", NULL
)) != NULL
)
4637 for (count
= 0, start
= ppd_attr
->value
; *start
; count
++)
4639 while (_cups_isspace(*start
))
4645 while (*start
&& !isspace(*start
& 255))
4655 * Make a copy of the commands string and count how many commands there
4659 attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4660 "printer-commands", count
, NULL
, NULL
);
4662 commands
= strdup(ppd_attr
->value
);
4664 for (count
= 0, start
= commands
; *start
; count
++)
4666 while (isspace(*start
& 255))
4673 while (*end
&& !isspace(*end
& 255))
4679 attr
->values
[count
].string
.text
= _cupsStrAlloc(start
);
4689 * Add the standard list of commands...
4692 ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4694 (int)(sizeof(standard_commands
) /
4695 sizeof(standard_commands
[0])), NULL
,
4702 * No commands supported...
4705 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4706 "printer-commands", NULL
, "none");
4710 * 3D printer support...
4713 if (ppdFindAttr(ppd
, "cups3D", NULL
))
4714 p
->type
|= CUPS_PRINTER_3D
;
4717 * Show current and available port monitors for this printer...
4720 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
, "port-monitor",
4721 NULL
, p
->port_monitor
? p
->port_monitor
: "none");
4723 for (i
= 1, ppd_attr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
4725 i
++, ppd_attr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
));
4729 if (strstr(ppd
->protocols
, "TBCP"))
4731 else if (strstr(ppd
->protocols
, "BCP"))
4735 attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
4736 "port-monitor-supported", i
, NULL
, NULL
);
4738 attr
->values
[0].string
.text
= _cupsStrAlloc("none");
4740 for (i
= 1, ppd_attr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
4742 i
++, ppd_attr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
))
4743 attr
->values
[i
].string
.text
= _cupsStrAlloc(ppd_attr
->value
);
4747 if (strstr(ppd
->protocols
, "TBCP"))
4748 attr
->values
[i
].string
.text
= _cupsStrAlloc("tbcp");
4749 else if (strstr(ppd
->protocols
, "BCP"))
4750 attr
->values
[i
].string
.text
= _cupsStrAlloc("bcp");
4753 if (ppdFindAttr(ppd
, "APRemoteQueueID", NULL
))
4754 p
->type
|= CUPS_PRINTER_REMOTE
;
4756 #ifdef HAVE_APPLICATIONSERVICES_H
4758 * Convert the file referenced in APPrinterIconPath to a 128x128 PNG
4759 * and save it as cacheDir/printername.png
4762 if ((ppd_attr
= ppdFindAttr(ppd
, "APPrinterIconPath", NULL
)) != NULL
&&
4764 !_cupsFileCheck(ppd_attr
->value
, _CUPS_FILE_CHECK_FILE
, !RunUser
,
4765 cupsdLogFCMessage
, p
))
4767 CGImageRef imageRef
= NULL
;/* Current icon image */
4768 CGImageRef biggestIconRef
= NULL
;
4769 /* Biggest icon image */
4770 CGImageRef closestTo128IconRef
= NULL
;
4771 /* Icon image closest to and >= 128 */
4772 CGImageSourceRef sourceRef
; /* The file's image source */
4773 char outPath
[HTTP_MAX_URI
];
4774 /* The path to the PNG file */
4775 CFURLRef outUrl
; /* The URL made from the outPath */
4776 CFURLRef icnsFileUrl
; /* The URL of the original ICNS icon file */
4777 CGImageDestinationRef destRef
; /* The image destination to write */
4778 size_t bytesPerRow
; /* The bytes per row used for resizing */
4779 CGContextRef context
; /* The CG context used for resizing */
4781 snprintf(outPath
, sizeof(outPath
), "%s/%s.png", CacheDir
, p
->name
);
4782 outUrl
= CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault
, (UInt8
*)outPath
, (CFIndex
)strlen(outPath
), FALSE
);
4783 icnsFileUrl
= CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault
, (UInt8
*)ppd_attr
->value
, (CFIndex
)strlen(ppd_attr
->value
), FALSE
);
4784 if (outUrl
&& icnsFileUrl
)
4786 sourceRef
= CGImageSourceCreateWithURL(icnsFileUrl
, NULL
);
4789 for (i
= 0; i
< (int)CGImageSourceGetCount(sourceRef
); i
++)
4791 imageRef
= CGImageSourceCreateImageAtIndex(sourceRef
, (size_t)i
, NULL
);
4795 if (CGImageGetWidth(imageRef
) == CGImageGetHeight(imageRef
))
4798 * Loop through remembering the icon closest to 128 but >= 128
4799 * and then remember the largest icon.
4802 if (CGImageGetWidth(imageRef
) >= 128 &&
4803 (!closestTo128IconRef
||
4804 CGImageGetWidth(imageRef
) <
4805 CGImageGetWidth(closestTo128IconRef
)))
4807 CGImageRelease(closestTo128IconRef
);
4808 CGImageRetain(imageRef
);
4809 closestTo128IconRef
= imageRef
;
4812 if (!biggestIconRef
||
4813 CGImageGetWidth(imageRef
) > CGImageGetWidth(biggestIconRef
))
4815 CGImageRelease(biggestIconRef
);
4816 CGImageRetain(imageRef
);
4817 biggestIconRef
= imageRef
;
4821 CGImageRelease(imageRef
);
4827 * If biggestIconRef is NULL, we found no icons. Otherwise we first
4828 * want the closest to 128, but if none are larger than 128, we want
4829 * the largest icon available.
4832 imageRef
= closestTo128IconRef
? closestTo128IconRef
:
4834 CGImageRetain(imageRef
);
4835 CGImageRelease(biggestIconRef
);
4836 if (closestTo128IconRef
)
4837 CGImageRelease(closestTo128IconRef
);
4838 destRef
= CGImageDestinationCreateWithURL(outUrl
, kUTTypePNG
, 1,
4842 if (CGImageGetWidth(imageRef
) != 128)
4844 bytesPerRow
= CGImageGetBytesPerRow(imageRef
) /
4845 CGImageGetWidth(imageRef
) * 128;
4846 context
= CGBitmapContextCreate(NULL
, 128, 128,
4847 CGImageGetBitsPerComponent(imageRef
),
4849 CGImageGetColorSpace(imageRef
),
4850 kCGImageAlphaPremultipliedFirst
);
4853 CGContextDrawImage(context
, CGRectMake(0, 0, 128, 128),
4855 CGImageRelease(imageRef
);
4856 imageRef
= CGBitmapContextCreateImage(context
);
4857 CGContextRelease(context
);
4861 CGImageDestinationAddImage(destRef
, imageRef
, NULL
);
4862 CGImageDestinationFinalize(destRef
);
4866 CGImageRelease(imageRef
);
4869 CFRelease(sourceRef
);
4877 CFRelease(icnsFileUrl
);
4879 #endif /* HAVE_APPLICATIONSERVICES_H */
4882 * Close the PPD and set the type...
4887 else if (!access(ppd_name
, 0))
4889 int pline
; /* PPD line number */
4890 ppd_status_t pstatus
; /* PPD load status */
4893 pstatus
= ppdLastError(&pline
);
4895 cupsdLogMessage(CUPSD_LOG_ERROR
, "PPD file for %s cannot be loaded.", p
->name
);
4897 if (pstatus
<= PPD_ALLOC_ERROR
)
4898 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: %s", ppd_name
, strerror(errno
));
4900 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s on line %d of %s.", ppdErrorString(pstatus
), pline
, ppd_name
);
4902 cupsdLogMessage(CUPSD_LOG_INFO
,
4903 "Hint: Run \"cupstestppd %s\" and fix any errors.",
4908 if (((!strncmp(p
->device_uri
, "ipp://", 6) ||
4909 !strncmp(p
->device_uri
, "ipps://", 7)) &&
4910 (strstr(p
->device_uri
, "/printers/") != NULL
||
4911 strstr(p
->device_uri
, "/classes/") != NULL
)) ||
4912 ((strstr(p
->device_uri
, "._ipp.") != NULL
||
4913 strstr(p
->device_uri
, "._ipps.") != NULL
) &&
4914 !strcmp(p
->device_uri
+ strlen(p
->device_uri
) - 5, "/cups")))
4917 * Tell the client this is really a hard-wired remote printer.
4920 p
->type
|= CUPS_PRINTER_REMOTE
;
4923 * Point the printer-uri-supported attribute to the
4927 if (strchr(p
->device_uri
, '?'))
4930 * Strip trailing "?options" from URI...
4933 char resource
[HTTP_MAX_URI
], /* New URI */
4934 *ptr
; /* Pointer into URI */
4936 strlcpy(resource
, p
->device_uri
, sizeof(resource
));
4937 if ((ptr
= strchr(resource
, '?')) != NULL
)
4940 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
4941 "printer-uri-supported", NULL
, resource
);
4944 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
4945 "printer-uri-supported", NULL
, p
->device_uri
);
4948 * Then set the make-and-model accordingly...
4951 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
4952 "printer-make-and-model", NULL
, "Remote Printer");
4955 * Print all files directly...
4964 * Otherwise we have neither - treat this as a "dumb" printer
4965 * with no PPD file...
4968 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
4969 "printer-make-and-model", NULL
, "Local Raw Printer");
4975 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
4976 "finishings-supported", num_finishings
, finishings
);
4977 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
4978 "finishings-default", IPP_FINISHINGS_NONE
);
4983 * Save cached PPD attributes to disk...
4986 cupsdLogMessage(CUPSD_LOG_DEBUG
, "load_ppd: Saving %s...", cache_name
);
4988 _ppdCacheWriteFile(p
->pc
, cache_name
, p
->ppd_attrs
);
4993 * Remove cache files...
4996 if (cache_info
.st_mtime
)
5003 * 'new_media_col()' - Create a media-col collection value.
5006 static ipp_t
* /* O - Collection value */
5007 new_media_col(_pwg_size_t
*size
, /* I - media-size/margin values */
5008 const char *source
, /* I - media-source value */
5009 const char *type
) /* I - media-type value */
5011 ipp_t
*media_col
, /* Collection value */
5012 *media_size
; /* media-size value */
5015 media_col
= ippNew();
5017 media_size
= ippNew();
5018 ippAddInteger(media_size
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5019 "x-dimension", size
->width
);
5020 ippAddInteger(media_size
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5021 "y-dimension", size
->length
);
5022 ippAddCollection(media_col
, IPP_TAG_PRINTER
, "media-size", media_size
);
5023 ippDelete(media_size
);
5025 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5026 "media-bottom-margin", size
->bottom
);
5027 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5028 "media-left-margin", size
->left
);
5029 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5030 "media-right-margin", size
->right
);
5031 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5032 "media-top-margin", size
->top
);
5035 ippAddString(media_col
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
, "media-source",
5039 ippAddString(media_col
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
, "media-type",
5047 * 'write_xml_string()' - Write a string with XML escaping.
5051 write_xml_string(cups_file_t
*fp
, /* I - File to write to */
5052 const char *s
) /* I - String to write */
5054 const char *start
; /* Start of current sequence */
5060 for (start
= s
; *s
; s
++)
5065 cupsFileWrite(fp
, start
, (size_t)(s
- start
));
5067 cupsFilePuts(fp
, "&");
5073 cupsFileWrite(fp
, start
, (size_t)(s
- start
));
5075 cupsFilePuts(fp
, "<");
5081 cupsFilePuts(fp
, start
);