2 * "$Id: printers.c 7968 2008-09-19 23:03:01Z mike $"
4 * Printer routines for the CUPS scheduler.
6 * Copyright 2007-2010 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 * cupsdAddPrinter() - Add a printer to the system.
18 * cupsdAddPrinterHistory() - Add the current printer state to the history.
19 * cupsdCreateCommonData() - Create the common printer data.
20 * cupsdDeleteAllPrinters() - Delete all printers from the system.
21 * cupsdDeletePrinter() - Delete a printer from the system.
22 * cupsdFindDest() - Find a destination in the list.
23 * cupsdFindPrinter() - Find a printer in the list.
24 * cupsdLoadAllPrinters() - Load printers from the printers.conf file.
25 * cupsdRenamePrinter() - Rename a printer.
26 * cupsdSaveAllPrinters() - Save all printer definitions to the
28 * cupsdSetAuthInfoRequired() - Set the required authentication info.
29 * cupsdSetDeviceURI() - Set the device URI for a printer.
30 * cupsdSetPrinterAttr() - Set a printer attribute.
31 * cupsdSetPrinterAttrs() - Set printer attributes based upon the PPD
33 * cupsdSetPrinterReasons() - Set/update the reasons strings.
34 * cupsdSetPrinterState() - Update the current state of a printer.
35 * cupsdStopPrinter() - Stop a printer from printing any jobs...
36 * cupsdUpdatePrinterPPD() - Update keywords in a printer's PPD file.
37 * cupsdUpdatePrinters() - Update printers after a partial reload.
38 * cupsdValidateDest() - Validate a printer/class destination.
39 * cupsdWritePrintcap() - Write a pseudo-printcap file for older
40 * applications that need it...
41 * add_printer_defaults() - Add name-default attributes to the printer
43 * add_printer_filter() - Add a MIME filter for a printer.
44 * add_printer_formats() - Add document-format-supported values for a
46 * add_string_array() - Add a string to an array of CUPS strings.
47 * compare_printers() - Compare two printers.
48 * delete_printer_filters() - Delete all MIME filters for a printer.
49 * delete_string_array() - Delete an array of CUPS strings.
50 * load_ppd() - Load a cached PPD file, updating the cache as
52 * new_media_col() - Create a media-col collection value.
53 * write_irix_config() - Update the config files used by the IRIX
55 * write_irix_state() - Update the status files used by IRIX printing
57 * write_xml_string() - Write a string with XML escaping.
61 * Include necessary headers...
66 #ifdef HAVE_APPLICATIONSERVICES_H
67 # include <ApplicationServices/ApplicationServices.h>
68 #endif /* HAVE_APPLICATIONSERVICES_H */
69 #ifdef HAVE_SYS_MOUNT_H
70 # include <sys/mount.h>
71 #endif /* HAVE_SYS_MOUNT_H */
72 #ifdef HAVE_SYS_STATFS_H
73 # include <sys/statfs.h>
74 #endif /* HAVE_SYS_STATFS_H */
75 #ifdef HAVE_SYS_STATVFS_H
76 # include <sys/statvfs.h>
77 #endif /* HAVE_SYS_STATVFS_H */
80 #endif /* HAVE_SYS_VFS_H */
87 static void add_printer_defaults(cupsd_printer_t
*p
);
88 static void add_printer_filter(cupsd_printer_t
*p
, mime_type_t
*type
,
90 static void add_printer_formats(cupsd_printer_t
*p
);
91 static void add_string_array(cups_array_t
**a
, const char *s
);
92 static int compare_printers(void *first
, void *second
, void *data
);
93 static void delete_printer_filters(cupsd_printer_t
*p
);
94 static void delete_string_array(cups_array_t
**a
);
95 static void load_ppd(cupsd_printer_t
*p
);
96 static ipp_t
*new_media_col(_pwg_size_t
*size
, const char *source
,
99 static void write_irix_config(cupsd_printer_t
*p
);
100 static void write_irix_state(cupsd_printer_t
*p
);
102 static void write_xml_string(cups_file_t
*fp
, const char *s
);
106 * 'cupsdAddPrinter()' - Add a printer to the system.
109 cupsd_printer_t
* /* O - New printer */
110 cupsdAddPrinter(const char *name
) /* I - Name of printer */
112 cupsd_printer_t
*p
; /* New printer */
113 char uri
[1024]; /* Printer URI */
117 * Range check input...
120 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdAddPrinter(\"%s\")", name
);
123 * Create a new printer entity...
126 if ((p
= calloc(1, sizeof(cupsd_printer_t
))) == NULL
)
128 cupsdLogMessage(CUPSD_LOG_CRIT
, "Unable to allocate memory for printer - %s",
133 cupsdSetString(&p
->name
, name
);
134 cupsdSetString(&p
->info
, name
);
135 cupsdSetString(&p
->hostname
, ServerName
);
137 httpAssembleURIf(HTTP_URI_CODING_ALL
, uri
, sizeof(uri
), "ipp", NULL
,
138 ServerName
, RemotePort
, "/printers/%s", name
);
139 cupsdSetString(&p
->uri
, uri
);
140 cupsdSetDeviceURI(p
, "file:///dev/null");
142 p
->state
= IPP_PRINTER_STOPPED
;
143 p
->state_time
= time(NULL
);
145 p
->shared
= DefaultShared
;
146 p
->filetype
= mimeAddType(MimeDatabase
, "printer", name
);
148 cupsdSetString(&p
->job_sheets
[0], "none");
149 cupsdSetString(&p
->job_sheets
[1], "none");
151 cupsdSetString(&p
->error_policy
, ErrorPolicy
);
152 cupsdSetString(&p
->op_policy
, DefaultPolicy
);
154 p
->op_policy_ptr
= DefaultPolicyPtr
;
156 if (MaxPrinterHistory
)
157 p
->history
= calloc(MaxPrinterHistory
, sizeof(ipp_t
*));
160 * Insert the printer in the printer list alphabetically...
164 Printers
= cupsArrayNew(compare_printers
, NULL
);
166 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
167 "cupsdAddPrinter: Adding %s to Printers", p
->name
);
168 cupsArrayAdd(Printers
, p
);
170 if (!ImplicitPrinters
)
171 ImplicitPrinters
= cupsArrayNew(compare_printers
, NULL
);
174 * Return the new printer...
182 * 'cupsdAddPrinterHistory()' - Add the current printer state to the history.
186 cupsdAddPrinterHistory(
187 cupsd_printer_t
*p
) /* I - Printer */
189 ipp_t
*history
; /* History collection */
193 * Stop early if we aren't keeping history data...
196 if (MaxPrinterHistory
<= 0)
200 * Retire old history data as needed...
203 p
->sequence_number
++;
205 if (p
->num_history
>= MaxPrinterHistory
)
208 ippDelete(p
->history
[0]);
209 memmove(p
->history
, p
->history
+ 1, p
->num_history
* sizeof(ipp_t
*));
213 * Create a collection containing the current printer-state, printer-up-time,
214 * printer-state-message, and printer-state-reasons attributes.
218 ippAddInteger(history
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-state",
220 ippAddBoolean(history
, IPP_TAG_PRINTER
, "printer-is-accepting-jobs",
222 ippAddBoolean(history
, IPP_TAG_PRINTER
, "printer-is-shared", p
->shared
);
223 ippAddString(history
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-state-message",
224 NULL
, p
->state_message
);
225 if (p
->num_reasons
== 0)
226 ippAddString(history
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
227 "printer-state-reasons", NULL
, "none");
229 ippAddStrings(history
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
230 "printer-state-reasons", p
->num_reasons
, NULL
,
231 (const char * const *)p
->reasons
);
232 ippAddInteger(history
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
233 "printer-state-change-time", p
->state_time
);
234 ippAddInteger(history
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
235 "printer-state-sequence-number", p
->sequence_number
);
237 p
->history
[p
->num_history
] = history
;
243 * 'cupsdCreateCommonData()' - Create the common printer data.
247 cupsdCreateCommonData(void)
249 int i
; /* Looping var */
250 ipp_attribute_t
*attr
; /* Attribute data */
251 cups_dir_t
*dir
; /* Notifier directory */
252 cups_dentry_t
*dent
; /* Notifier directory entry */
253 cups_array_t
*notifiers
; /* Notifier array */
254 char filename
[1024], /* Filename */
255 *notifier
; /* Current notifier */
256 cupsd_policy_t
*p
; /* Current policy */
257 int k_supported
; /* Maximum file size supported */
259 struct statfs spoolinfo
; /* FS info for spool directory */
260 double spoolsize
; /* FS size */
261 #elif defined(HAVE_STATVFS)
262 struct statvfs spoolinfo
; /* FS info for spool directory */
263 double spoolsize
; /* FS size */
264 #endif /* HAVE_STATFS */
265 static const int nups
[] = /* number-up-supported values */
266 { 1, 2, 4, 6, 9, 16 };
267 static const int orients
[4] =/* orientation-requested-supported values */
271 IPP_REVERSE_LANDSCAPE
,
274 static const char * const holds
[] = /* job-hold-until-supported values */
285 static const char * const versions
[] =/* ipp-versions-supported values */
292 static const int ops
[] = /* operations-supported values */
299 IPP_GET_JOB_ATTRIBUTES
,
301 IPP_GET_PRINTER_ATTRIBUTES
,
308 IPP_SET_PRINTER_ATTRIBUTES
,
309 IPP_SET_JOB_ATTRIBUTES
,
310 IPP_GET_PRINTER_SUPPORTED_VALUES
,
311 IPP_CREATE_PRINTER_SUBSCRIPTION
,
312 IPP_CREATE_JOB_SUBSCRIPTION
,
313 IPP_GET_SUBSCRIPTION_ATTRIBUTES
,
314 IPP_GET_SUBSCRIPTIONS
,
315 IPP_RENEW_SUBSCRIPTION
,
316 IPP_CANCEL_SUBSCRIPTION
,
317 IPP_GET_NOTIFICATIONS
,
321 IPP_RELEASE_HELD_NEW_JOBS
,
338 CUPS_AUTHENTICATE_JOB
,
343 static const char * const charsets
[] =/* charset-supported values */
348 static const char * const compressions
[] =
349 { /* document-compression-supported values */
353 #endif /* HAVE_LIBZ */
355 static const char * const media_col_supported
[] =
356 { /* media-col-supported values */
357 "media-bottom-margin",
359 "media-right-margin",
365 static const char * const multiple_document_handling
[] =
366 { /* multiple-document-handling-supported values */
367 "separate-documents-uncollated-copies",
368 "separate-documents-collated-copies"
370 static const char * const notify_attrs
[] =
371 { /* notify-attributes-supported values */
372 "printer-state-change-time",
373 "notify-lease-expiration-time",
374 "notify-subscriber-user-name"
376 static const char * const notify_events
[] =
377 { /* notify-events-supported values */
379 "job-config-changed",
386 "printer-config-changed",
388 "printer-finishings-changed",
389 "printer-media-changed",
393 "printer-state-changed",
400 static const char * const job_creation
[] =
401 { /* job-creation-attributes-supported */
404 "ipp-attribute-fidelity",
411 "multiple-document-handling",
415 "orientation-requested",
418 "printer-resolution",
421 static const char * const job_settable
[] =
422 { /* job-settable-attributes-supported */
430 "multiple-document-handling",
434 "orientation-requested",
437 "printer-resolution",
440 static const char * const printer_settable
[] =
441 { /* printer-settable-attributes-supported */
445 static const char * const which_jobs
[] =
446 { /* which-jobs-supported values */
460 ippDelete(CommonData
);
462 CommonData
= ippNew();
465 * Get the maximum spool size based on the size of the filesystem used for
466 * the RequestRoot directory. If the host OS doesn't support the statfs call
467 * or the filesystem is larger than 2TiB, always report INT_MAX.
471 if (statfs(RequestRoot
, &spoolinfo
))
472 k_supported
= INT_MAX
;
473 else if ((spoolsize
= (double)spoolinfo
.f_bsize
* spoolinfo
.f_blocks
/ 1024) >
475 k_supported
= INT_MAX
;
477 k_supported
= (int)spoolsize
;
479 #elif defined(HAVE_STATVFS)
480 if (statvfs(RequestRoot
, &spoolinfo
))
481 k_supported
= INT_MAX
;
482 else if ((spoolsize
= (double)spoolinfo
.f_frsize
* spoolinfo
.f_blocks
/ 1024) >
484 k_supported
= INT_MAX
;
486 k_supported
= (int)spoolsize
;
489 k_supported
= INT_MAX
;
490 #endif /* HAVE_STATFS */
493 * This list of attributes is sorted to improve performance when the
494 * client provides a requested-attributes attribute...
497 /* charset-configured */
498 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_CHARSET
| IPP_TAG_COPY
,
499 "charset-configured", NULL
, "utf-8");
501 /* charset-supported */
502 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_CHARSET
| IPP_TAG_COPY
,
503 "charset-supported", sizeof(charsets
) / sizeof(charsets
[0]),
506 /* compression-supported */
507 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
508 "compression-supported",
509 sizeof(compressions
) / sizeof(compressions
[0]),
512 /* copies-supported */
513 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "copies-supported", 1, MaxCopies
);
516 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
| IPP_TAG_COPY
,
517 "cups-version", NULL
, CUPS_SVERSION
+ 6);
519 /* generated-natural-language-supported (no IPP_TAG_COPY) */
520 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_LANGUAGE
,
521 "generated-natural-language-supported", NULL
, DefaultLanguage
);
523 /* ipp-versions-supported */
524 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
525 "ipp-versions-supported", sizeof(versions
) / sizeof(versions
[0]),
528 /* ippget-event-life */
529 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
530 "ippget-event-life", 15);
532 /* job-creation-attributes-supported */
533 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
534 "job-creation-attributes-supported",
535 sizeof(job_creation
) / sizeof(job_creation
[0]),
538 /* job-hold-until-supported */
539 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
540 "job-hold-until-supported", sizeof(holds
) / sizeof(holds
[0]),
543 /* job-ids-supported */
544 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
, "job-ids-supported", 1);
546 /* job-k-octets-supported */
547 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
548 "job-k-octets-supported", k_supported
);
550 /* job-priority-supported */
551 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
552 "job-priority-supported", 100);
554 /* job-settable-attributes-supported */
555 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
556 "job-settable-attributes-supported",
557 sizeof(job_settable
) / sizeof(job_settable
[0]),
560 /* job-sheets-supported */
561 if (cupsArrayCount(Banners
) > 0)
564 * Setup the job-sheets-supported attribute...
567 if (Classification
&& !ClassifyOverride
)
568 attr
= ippAddString(CommonData
, IPP_TAG_PRINTER
,
569 IPP_TAG_NAME
| IPP_TAG_COPY
,
570 "job-sheets-supported", NULL
, Classification
);
572 attr
= ippAddStrings(CommonData
, IPP_TAG_PRINTER
,
573 IPP_TAG_NAME
| IPP_TAG_COPY
,
574 "job-sheets-supported", cupsArrayCount(Banners
) + 1,
578 cupsdLogMessage(CUPSD_LOG_EMERG
,
579 "Unable to allocate memory for "
580 "job-sheets-supported attribute: %s!", strerror(errno
));
581 else if (!Classification
|| ClassifyOverride
)
583 cupsd_banner_t
*banner
; /* Current banner */
586 attr
->values
[0].string
.text
= _cupsStrAlloc("none");
588 for (i
= 1, banner
= (cupsd_banner_t
*)cupsArrayFirst(Banners
);
590 i
++, banner
= (cupsd_banner_t
*)cupsArrayNext(Banners
))
591 attr
->values
[i
].string
.text
= banner
->name
;
595 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
596 "job-sheets-supported", NULL
, "none");
598 /* media-col-supported */
599 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
600 "media-col-supported",
601 sizeof(media_col_supported
) /
602 sizeof(media_col_supported
[0]), NULL
,
603 media_col_supported
);
605 /* multiple-document-handling-supported */
606 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
607 "multiple-document-handling-supported",
608 sizeof(multiple_document_handling
) /
609 sizeof(multiple_document_handling
[0]), NULL
,
610 multiple_document_handling
);
612 /* multiple-document-jobs-supported */
613 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
,
614 "multiple-document-jobs-supported", 1);
616 /* multiple-operation-time-out */
617 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
618 "multiple-operation-time-out", MultipleOperationTimeout
);
620 /* natural-language-configured (no IPP_TAG_COPY) */
621 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_LANGUAGE
,
622 "natural-language-configured", NULL
, DefaultLanguage
);
624 /* notify-attributes-supported */
625 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
626 "notify-attributes-supported",
627 (int)(sizeof(notify_attrs
) / sizeof(notify_attrs
[0])),
630 /* notify-lease-duration-supported */
631 ippAddRange(CommonData
, IPP_TAG_PRINTER
,
632 "notify-lease-duration-supported", 0,
633 MaxLeaseDuration
? MaxLeaseDuration
: 2147483647);
635 /* notify-max-events-supported */
636 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
637 "notify-max-events-supported", MaxEvents
);
639 /* notify-events-supported */
640 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
641 "notify-events-supported",
642 (int)(sizeof(notify_events
) / sizeof(notify_events
[0])),
643 NULL
, notify_events
);
645 /* notify-pull-method-supported */
646 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
647 "notify-pull-method-supported", NULL
, "ippget");
649 /* notify-schemes-supported */
650 snprintf(filename
, sizeof(filename
), "%s/notifier", ServerBin
);
651 if ((dir
= cupsDirOpen(filename
)) != NULL
)
653 notifiers
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
655 while ((dent
= cupsDirRead(dir
)) != NULL
)
656 if (S_ISREG(dent
->fileinfo
.st_mode
) &&
657 (dent
->fileinfo
.st_mode
& S_IXOTH
) != 0)
658 cupsArrayAdd(notifiers
, _cupsStrAlloc(dent
->filename
));
660 if (cupsArrayCount(notifiers
) > 0)
662 attr
= ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
663 "notify-schemes-supported",
664 cupsArrayCount(notifiers
), NULL
, NULL
);
666 for (i
= 0, notifier
= (char *)cupsArrayFirst(notifiers
);
668 i
++, notifier
= (char *)cupsArrayNext(notifiers
))
669 attr
->values
[i
].string
.text
= notifier
;
672 cupsArrayDelete(notifiers
);
676 /* number-up-supported */
677 ippAddIntegers(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
678 "number-up-supported", sizeof(nups
) / sizeof(nups
[0]), nups
);
680 /* operations-supported */
681 ippAddIntegers(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
682 "operations-supported",
683 sizeof(ops
) / sizeof(ops
[0]) + JobFiles
- 1, ops
);
685 /* orientation-requested-supported */
686 ippAddIntegers(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
687 "orientation-requested-supported", 4, orients
);
689 /* page-ranges-supported */
690 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
, "page-ranges-supported", 1);
692 /* pdl-override-supported */
693 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
694 "pdl-override-supported", NULL
, "attempted");
696 /* printer-op-policy-supported */
697 attr
= ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
698 "printer-op-policy-supported", cupsArrayCount(Policies
),
700 for (i
= 0, p
= (cupsd_policy_t
*)cupsArrayFirst(Policies
);
702 i
++, p
= (cupsd_policy_t
*)cupsArrayNext(Policies
))
703 attr
->values
[i
].string
.text
= p
->name
;
705 /* printer-settable-attributes-supported */
706 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
707 "printer-settable-attributes-supported",
708 sizeof(printer_settable
) / sizeof(printer_settable
[0]),
709 NULL
, printer_settable
);
711 /* server-is-sharing-printers */
712 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
, "server-is-sharing-printers",
713 BrowseLocalProtocols
!= 0 && Browsing
);
715 /* which-jobs-supported */
716 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
717 "which-jobs-supported",
718 sizeof(which_jobs
) / sizeof(which_jobs
[0]), NULL
, which_jobs
);
723 * 'cupsdDeleteAllPrinters()' - Delete all printers from the system.
727 cupsdDeleteAllPrinters(void)
729 cupsd_printer_t
*p
; /* Pointer to current printer/class */
732 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
734 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
736 p
->op_policy_ptr
= DefaultPolicyPtr
;
737 cupsdDeletePrinter(p
, 0);
743 * 'cupsdDeletePrinter()' - Delete a printer from the system.
746 int /* O - 1 if classes affected, 0 otherwise */
748 cupsd_printer_t
*p
, /* I - Printer to delete */
749 int update
) /* I - Update printers.conf? */
751 int i
, /* Looping var */
752 changed
= 0; /* Class changed? */
754 char filename
[1024]; /* Interface script filename */
758 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdDeletePrinter(p=%p(%s), update=%d)",
762 * Save the current position in the Printers array...
765 cupsArraySave(Printers
);
768 * Stop printing on this printer...
771 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, update
);
774 cupsdSetJobState(p
->job
, IPP_JOB_PENDING
, CUPSD_JOB_FORCE
,
775 update
? "Job stopped due to printer being deleted." :
779 * If this printer is the next for browsing, point to the next one...
784 cupsArrayFind(Printers
, p
);
785 BrowseNext
= (cupsd_printer_t
*)cupsArrayNext(Printers
);
789 * Remove the printer from the list...
792 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
793 "cupsdDeletePrinter: Removing %s from Printers", p
->name
);
794 cupsArrayRemove(Printers
, p
);
796 if (p
->type
& CUPS_PRINTER_IMPLICIT
)
798 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
799 "cupsdDeletePrinter: Removing %s from ImplicitPrinters",
801 cupsArrayRemove(ImplicitPrinters
, p
);
805 * Remove the dummy interface/icon/option files under IRIX...
809 snprintf(filename
, sizeof(filename
), "/var/spool/lp/interface/%s", p
->name
);
812 snprintf(filename
, sizeof(filename
), "/var/spool/lp/gui_interface/ELF/%s.gui",
816 snprintf(filename
, sizeof(filename
), "/var/spool/lp/activeicons/%s", p
->name
);
819 snprintf(filename
, sizeof(filename
), "/var/spool/lp/pod/%s.config", p
->name
);
822 snprintf(filename
, sizeof(filename
), "/var/spool/lp/pod/%s.status", p
->name
);
825 snprintf(filename
, sizeof(filename
), "/var/spool/lp/member/%s", p
->name
);
830 * If p is the default printer, assign a different one...
833 if (p
== DefaultPrinter
)
835 DefaultPrinter
= NULL
;
837 if (UseNetworkDefault
)
840 * Find the first network default printer and use it...
843 cupsd_printer_t
*dp
; /* New default printer */
846 for (dp
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
848 dp
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
849 if (dp
!= p
&& (dp
->type
& CUPS_PRINTER_DEFAULT
))
858 * Remove this printer from any classes...
861 if (!(p
->type
& CUPS_PRINTER_IMPLICIT
))
863 changed
= cupsdDeletePrinterFromClasses(p
);
866 * Deregister from any browse protocols...
869 cupsdDeregisterPrinter(p
, 1);
873 * Free all memory used by the printer...
876 if (p
->printers
!= NULL
)
879 if (MaxPrinterHistory
)
881 for (i
= 0; i
< p
->num_history
; i
++)
882 ippDelete(p
->history
[i
]);
887 delete_printer_filters(p
);
889 for (i
= 0; i
< p
->num_reasons
; i
++)
890 _cupsStrFree(p
->reasons
[i
]);
893 ippDelete(p
->ppd_attrs
);
895 mimeDeleteType(MimeDatabase
, p
->filetype
);
896 mimeDeleteType(MimeDatabase
, p
->prefiltertype
);
898 delete_string_array(&(p
->filters
));
899 delete_string_array(&(p
->pre_filters
));
901 cupsdFreeStrings(&(p
->users
));
904 cupsdClearString(&p
->uri
);
905 cupsdClearString(&p
->hostname
);
906 cupsdClearString(&p
->name
);
907 cupsdClearString(&p
->location
);
908 cupsdClearString(&p
->make_model
);
909 cupsdClearString(&p
->info
);
910 cupsdClearString(&p
->job_sheets
[0]);
911 cupsdClearString(&p
->job_sheets
[1]);
912 cupsdClearString(&p
->device_uri
);
913 cupsdClearString(&p
->sanitized_device_uri
);
914 cupsdClearString(&p
->port_monitor
);
915 cupsdClearString(&p
->op_policy
);
916 cupsdClearString(&p
->error_policy
);
918 cupsdClearString(&p
->alert
);
919 cupsdClearString(&p
->alert_description
);
922 cupsdClearString(&p
->product
);
923 cupsdClearString(&p
->pdl
);
924 #endif /* HAVE_DNSSD */
926 cupsArrayDelete(p
->filetypes
);
929 free(p
->browse_attrs
);
931 cupsFreeOptions(p
->num_options
, p
->options
);
936 * Restore the previous position in the Printers array...
939 cupsArrayRestore(Printers
);
946 * 'cupsdFindDest()' - Find a destination in the list.
949 cupsd_printer_t
* /* O - Destination in list */
950 cupsdFindDest(const char *name
) /* I - Name of printer or class to find */
952 cupsd_printer_t key
; /* Search key */
955 key
.name
= (char *)name
;
956 return ((cupsd_printer_t
*)cupsArrayFind(Printers
, &key
));
961 * 'cupsdFindPrinter()' - Find a printer in the list.
964 cupsd_printer_t
* /* O - Printer in list */
965 cupsdFindPrinter(const char *name
) /* I - Name of printer to find */
967 cupsd_printer_t
*p
; /* Printer in list */
970 if ((p
= cupsdFindDest(name
)) != NULL
&& (p
->type
& CUPS_PRINTER_CLASS
))
978 * 'cupsdLoadAllPrinters()' - Load printers from the printers.conf file.
982 cupsdLoadAllPrinters(void)
984 int i
; /* Looping var */
985 cups_file_t
*fp
; /* printers.conf file */
986 int linenum
; /* Current line number */
987 char line
[4096], /* Line from file */
988 *value
, /* Pointer to value */
989 *valueptr
; /* Pointer into value */
990 cupsd_printer_t
*p
; /* Current printer */
994 * Open the printers.conf file...
997 snprintf(line
, sizeof(line
), "%s/printers.conf", ServerRoot
);
998 if ((fp
= cupsFileOpen(line
, "r")) == NULL
)
1000 if (errno
!= ENOENT
)
1001 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to open %s - %s", line
,
1007 * Read printer configurations until we hit EOF...
1013 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
1016 * Decode the directive...
1019 if (!strcasecmp(line
, "<Printer") ||
1020 !strcasecmp(line
, "<DefaultPrinter"))
1023 * <Printer name> or <DefaultPrinter name>
1026 if (p
== NULL
&& value
)
1029 * Add the printer and a base file type...
1032 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Loading printer %s...", value
);
1034 p
= cupsdAddPrinter(value
);
1036 p
->state
= IPP_PRINTER_IDLE
;
1039 * Set the default printer as needed...
1042 if (!strcasecmp(line
, "<DefaultPrinter"))
1046 cupsdLogMessage(CUPSD_LOG_ERROR
,
1047 "Syntax error on line %d of printers.conf.", linenum
);
1049 else if (!strcasecmp(line
, "</Printer>"))
1054 * Close out the current printer...
1057 cupsdSetPrinterAttrs(p
);
1058 cupsdAddPrinterHistory(p
);
1060 if (strncmp(p
->device_uri
, "file:", 5) &&
1061 p
->state
!= IPP_PRINTER_STOPPED
)
1064 * See if the backend exists...
1067 snprintf(line
, sizeof(line
), "%s/backend/%s", ServerBin
,
1070 if ((valueptr
= strchr(line
+ strlen(ServerBin
), ':')) != NULL
)
1071 *valueptr
= '\0'; /* Chop everything but URI scheme */
1073 if (access(line
, 0))
1076 * Backend does not exist, stop printer...
1079 p
->state
= IPP_PRINTER_STOPPED
;
1080 snprintf(p
->state_message
, sizeof(p
->state_message
),
1081 "Backend %s does not exist!", line
);
1088 cupsdLogMessage(CUPSD_LOG_ERROR
,
1089 "Syntax error on line %d of printers.conf.", linenum
);
1093 cupsdLogMessage(CUPSD_LOG_ERROR
,
1094 "Syntax error on line %d of printers.conf.", linenum
);
1096 else if (!strcasecmp(line
, "AuthInfoRequired"))
1098 if (!cupsdSetAuthInfoRequired(p
, value
, NULL
))
1099 cupsdLogMessage(CUPSD_LOG_ERROR
,
1100 "Bad AuthInfoRequired on line %d of printers.conf.",
1103 else if (!strcasecmp(line
, "Info"))
1106 cupsdSetString(&p
->info
, value
);
1108 else if (!strcasecmp(line
, "MakeModel"))
1111 cupsdSetString(&p
->make_model
, value
);
1113 else if (!strcasecmp(line
, "Location"))
1116 cupsdSetString(&p
->location
, value
);
1118 else if (!strcasecmp(line
, "DeviceURI"))
1121 cupsdSetDeviceURI(p
, value
);
1123 cupsdLogMessage(CUPSD_LOG_ERROR
,
1124 "Syntax error on line %d of printers.conf.", linenum
);
1126 else if (!strcasecmp(line
, "Option") && value
)
1132 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1135 cupsdLogMessage(CUPSD_LOG_ERROR
,
1136 "Syntax error on line %d of printers.conf.", linenum
);
1139 for (; *valueptr
&& isspace(*valueptr
& 255); *valueptr
++ = '\0');
1141 p
->num_options
= cupsAddOption(value
, valueptr
, p
->num_options
,
1145 else if (!strcasecmp(line
, "PortMonitor"))
1147 if (value
&& strcmp(value
, "none"))
1148 cupsdSetString(&p
->port_monitor
, value
);
1150 cupsdClearString(&p
->port_monitor
);
1152 cupsdLogMessage(CUPSD_LOG_ERROR
,
1153 "Syntax error on line %d of printers.conf.", linenum
);
1155 else if (!strcasecmp(line
, "Reason"))
1158 strcmp(value
, "connecting-to-device") &&
1159 strcmp(value
, "cups-insecure-filter-warning") &&
1160 strcmp(value
, "cups-missing-filter-warning"))
1162 for (i
= 0 ; i
< p
->num_reasons
; i
++)
1163 if (!strcmp(value
, p
->reasons
[i
]))
1166 if (i
>= p
->num_reasons
&&
1167 p
->num_reasons
< (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
1169 p
->reasons
[p
->num_reasons
] = _cupsStrAlloc(value
);
1174 cupsdLogMessage(CUPSD_LOG_ERROR
,
1175 "Syntax error on line %d of printers.conf.", linenum
);
1177 else if (!strcasecmp(line
, "State"))
1180 * Set the initial queue state...
1183 if (value
&& !strcasecmp(value
, "idle"))
1184 p
->state
= IPP_PRINTER_IDLE
;
1185 else if (value
&& !strcasecmp(value
, "stopped"))
1187 p
->state
= IPP_PRINTER_STOPPED
;
1189 for (i
= 0 ; i
< p
->num_reasons
; i
++)
1190 if (!strcmp("paused", p
->reasons
[i
]))
1193 if (i
>= p
->num_reasons
&&
1194 p
->num_reasons
< (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
1196 p
->reasons
[p
->num_reasons
] = _cupsStrAlloc("paused");
1201 cupsdLogMessage(CUPSD_LOG_ERROR
,
1202 "Syntax error on line %d of printers.conf.", linenum
);
1204 else if (!strcasecmp(line
, "StateMessage"))
1207 * Set the initial queue state message...
1211 strlcpy(p
->state_message
, value
, sizeof(p
->state_message
));
1213 else if (!strcasecmp(line
, "StateTime"))
1216 * Set the state time...
1220 p
->state_time
= atoi(value
);
1222 else if (!strcasecmp(line
, "Accepting"))
1225 * Set the initial accepting state...
1229 (!strcasecmp(value
, "yes") ||
1230 !strcasecmp(value
, "on") ||
1231 !strcasecmp(value
, "true")))
1234 (!strcasecmp(value
, "no") ||
1235 !strcasecmp(value
, "off") ||
1236 !strcasecmp(value
, "false")))
1239 cupsdLogMessage(CUPSD_LOG_ERROR
,
1240 "Syntax error on line %d of printers.conf.", linenum
);
1242 else if (!strcasecmp(line
, "Type"))
1245 p
->type
= atoi(value
);
1247 cupsdLogMessage(CUPSD_LOG_ERROR
,
1248 "Syntax error on line %d of printers.conf.", linenum
);
1250 else if (!strcasecmp(line
, "Product"))
1255 p
->product
= _cupsStrAlloc(value
);
1256 #endif /* HAVE_DNSSD */
1259 cupsdLogMessage(CUPSD_LOG_ERROR
,
1260 "Syntax error on line %d of printers.conf.", linenum
);
1262 else if (!strcasecmp(line
, "Filter"))
1267 p
->filters
= cupsArrayNew(NULL
, NULL
);
1269 cupsArrayAdd(p
->filters
, _cupsStrAlloc(value
));
1272 cupsdLogMessage(CUPSD_LOG_ERROR
,
1273 "Syntax error on line %d of printers.conf.", linenum
);
1275 else if (!strcasecmp(line
, "PreFilter"))
1279 if (!p
->pre_filters
)
1280 p
->pre_filters
= cupsArrayNew(NULL
, NULL
);
1282 cupsArrayAdd(p
->pre_filters
, _cupsStrAlloc(value
));
1285 cupsdLogMessage(CUPSD_LOG_ERROR
,
1286 "Syntax error on line %d of printers.conf.", linenum
);
1288 else if (!strcasecmp(line
, "Shared"))
1291 * Set the initial shared state...
1295 (!strcasecmp(value
, "yes") ||
1296 !strcasecmp(value
, "on") ||
1297 !strcasecmp(value
, "true")))
1300 (!strcasecmp(value
, "no") ||
1301 !strcasecmp(value
, "off") ||
1302 !strcasecmp(value
, "false")))
1305 cupsdLogMessage(CUPSD_LOG_ERROR
,
1306 "Syntax error on line %d of printers.conf.", linenum
);
1308 else if (!strcasecmp(line
, "JobSheets"))
1311 * Set the initial job sheets...
1316 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1321 cupsdSetString(&p
->job_sheets
[0], value
);
1323 while (isspace(*valueptr
& 255))
1328 for (value
= valueptr
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1333 cupsdSetString(&p
->job_sheets
[1], value
);
1337 cupsdLogMessage(CUPSD_LOG_ERROR
,
1338 "Syntax error on line %d of printers.conf.", linenum
);
1340 else if (!strcasecmp(line
, "AllowUser"))
1345 cupsdAddString(&(p
->users
), value
);
1348 cupsdLogMessage(CUPSD_LOG_ERROR
,
1349 "Syntax error on line %d of printers.conf.", linenum
);
1351 else if (!strcasecmp(line
, "DenyUser"))
1356 cupsdAddString(&(p
->users
), value
);
1359 cupsdLogMessage(CUPSD_LOG_ERROR
,
1360 "Syntax error on line %d of printers.conf.", linenum
);
1362 else if (!strcasecmp(line
, "QuotaPeriod"))
1365 p
->quota_period
= atoi(value
);
1367 cupsdLogMessage(CUPSD_LOG_ERROR
,
1368 "Syntax error on line %d of printers.conf.", linenum
);
1370 else if (!strcasecmp(line
, "PageLimit"))
1373 p
->page_limit
= atoi(value
);
1375 cupsdLogMessage(CUPSD_LOG_ERROR
,
1376 "Syntax error on line %d of printers.conf.", linenum
);
1378 else if (!strcasecmp(line
, "KLimit"))
1381 p
->k_limit
= atoi(value
);
1383 cupsdLogMessage(CUPSD_LOG_ERROR
,
1384 "Syntax error on line %d of printers.conf.", linenum
);
1386 else if (!strcasecmp(line
, "OpPolicy"))
1390 cupsd_policy_t
*pol
; /* Policy */
1393 if ((pol
= cupsdFindPolicy(value
)) != NULL
)
1395 cupsdSetString(&p
->op_policy
, value
);
1396 p
->op_policy_ptr
= pol
;
1399 cupsdLogMessage(CUPSD_LOG_ERROR
,
1400 "Bad policy \"%s\" on line %d of printers.conf",
1404 cupsdLogMessage(CUPSD_LOG_ERROR
,
1405 "Syntax error on line %d of printers.conf.", linenum
);
1407 else if (!strcasecmp(line
, "ErrorPolicy"))
1410 cupsdSetString(&p
->error_policy
, value
);
1412 cupsdLogMessage(CUPSD_LOG_ERROR
,
1413 "Syntax error on line %d of printers.conf.", linenum
);
1415 else if (!strcasecmp(line
, "Attribute") && value
)
1417 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1420 cupsdLogMessage(CUPSD_LOG_ERROR
,
1421 "Syntax error on line %d of printers.conf.", linenum
);
1424 for (; *valueptr
&& isspace(*valueptr
& 255); *valueptr
++ = '\0');
1427 cupsdSetPrinterAttrs(p
);
1429 if (!strcmp(value
, "marker-change-time"))
1430 p
->marker_time
= atoi(valueptr
);
1432 cupsdSetPrinterAttr(p
, value
, valueptr
);
1438 * Something else we don't understand...
1441 cupsdLogMessage(CUPSD_LOG_ERROR
,
1442 "Unknown configuration directive %s on line %d of printers.conf.",
1452 * 'cupsdRenamePrinter()' - Rename a printer.
1457 cupsd_printer_t
*p
, /* I - Printer */
1458 const char *name
) /* I - New name */
1461 * Remove the printer from the array(s) first...
1464 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1465 "cupsdRenamePrinter: Removing %s from Printers", p
->name
);
1466 cupsArrayRemove(Printers
, p
);
1468 if (p
->type
& CUPS_PRINTER_IMPLICIT
)
1470 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1471 "cupsdRenamePrinter: Removing %s from ImplicitPrinters",
1473 cupsArrayRemove(ImplicitPrinters
, p
);
1477 * Rename the printer type...
1480 mimeDeleteType(MimeDatabase
, p
->filetype
);
1481 p
->filetype
= mimeAddType(MimeDatabase
, "printer", name
);
1483 mimeDeleteType(MimeDatabase
, p
->prefiltertype
);
1484 p
->prefiltertype
= mimeAddType(MimeDatabase
, "prefilter", name
);
1487 * Rename the printer...
1490 cupsdSetString(&p
->name
, name
);
1493 * Reset printer attributes...
1496 cupsdSetPrinterAttrs(p
);
1499 * Add the printer back to the printer array(s)...
1502 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1503 "cupsdRenamePrinter: Adding %s to Printers", p
->name
);
1504 cupsArrayAdd(Printers
, p
);
1506 if (p
->type
& CUPS_PRINTER_IMPLICIT
)
1508 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1509 "cupsdRenamePrinter: Adding %s to ImplicitPrinters",
1511 cupsArrayAdd(ImplicitPrinters
, p
);
1517 * 'cupsdSaveAllPrinters()' - Save all printer definitions to the printers.conf
1522 cupsdSaveAllPrinters(void)
1524 int i
; /* Looping var */
1525 cups_file_t
*fp
; /* printers.conf file */
1526 char temp
[1024], /* Temporary string */
1527 backup
[1024], /* printers.conf.O file */
1528 value
[2048], /* Value string */
1529 *ptr
, /* Pointer into value */
1530 *name
; /* Current user/group name */
1531 cupsd_printer_t
*printer
; /* Current printer class */
1532 time_t curtime
; /* Current time */
1533 struct tm
*curdate
; /* Current date */
1534 cups_option_t
*option
; /* Current option */
1535 ipp_attribute_t
*marker
; /* Current marker attribute */
1539 * Create the printers.conf file...
1542 snprintf(temp
, sizeof(temp
), "%s/printers.conf", ServerRoot
);
1543 snprintf(backup
, sizeof(backup
), "%s/printers.conf.O", ServerRoot
);
1545 if (rename(temp
, backup
))
1547 if (errno
!= ENOENT
)
1548 cupsdLogMessage(CUPSD_LOG_ERROR
,
1549 "Unable to backup printers.conf - %s", strerror(errno
));
1552 if ((fp
= cupsFileOpen(temp
, "w")) == NULL
)
1554 cupsdLogMessage(CUPSD_LOG_ERROR
,
1555 "Unable to save printers.conf - %s", strerror(errno
));
1557 if (rename(backup
, temp
))
1558 cupsdLogMessage(CUPSD_LOG_ERROR
,
1559 "Unable to restore printers.conf - %s", strerror(errno
));
1563 cupsdLogMessage(CUPSD_LOG_INFO
, "Saving printers.conf...");
1566 * Restrict access to the file...
1569 fchown(cupsFileNumber(fp
), getuid(), Group
);
1570 fchmod(cupsFileNumber(fp
), ConfigFilePerm
& 0600);
1573 * Write a small header to the file...
1576 curtime
= time(NULL
);
1577 curdate
= localtime(&curtime
);
1578 strftime(temp
, sizeof(temp
) - 1, "%Y-%m-%d %H:%M", curdate
);
1580 cupsFilePuts(fp
, "# Printer configuration file for " CUPS_SVERSION
"\n");
1581 cupsFilePrintf(fp
, "# Written by cupsd on %s\n", temp
);
1582 cupsFilePuts(fp
, "# DO NOT EDIT THIS FILE WHEN CUPSD IS RUNNING\n");
1585 * Write each local printer known to the system...
1588 for (printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
1590 printer
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
1593 * Skip remote destinations and printer classes...
1596 if ((printer
->type
& CUPS_PRINTER_DISCOVERED
) ||
1597 (printer
->type
& CUPS_PRINTER_CLASS
) ||
1598 (printer
->type
& CUPS_PRINTER_IMPLICIT
))
1602 * Write printers as needed...
1605 if (printer
== DefaultPrinter
)
1606 cupsFilePrintf(fp
, "<DefaultPrinter %s>\n", printer
->name
);
1608 cupsFilePrintf(fp
, "<Printer %s>\n", printer
->name
);
1610 if (printer
->num_auth_info_required
> 0)
1612 switch (printer
->num_auth_info_required
)
1615 strlcpy(value
, printer
->auth_info_required
[0], sizeof(value
));
1619 snprintf(value
, sizeof(value
), "%s,%s",
1620 printer
->auth_info_required
[0],
1621 printer
->auth_info_required
[1]);
1626 snprintf(value
, sizeof(value
), "%s,%s,%s",
1627 printer
->auth_info_required
[0],
1628 printer
->auth_info_required
[1],
1629 printer
->auth_info_required
[2]);
1633 cupsFilePutConf(fp
, "AuthInfoRequired", value
);
1637 cupsFilePutConf(fp
, "Info", printer
->info
);
1639 if (printer
->location
)
1640 cupsFilePutConf(fp
, "Location", printer
->location
);
1642 if (printer
->make_model
)
1643 cupsFilePutConf(fp
, "MakeModel", printer
->make_model
);
1645 cupsFilePutConf(fp
, "DeviceURI", printer
->device_uri
);
1647 if (printer
->port_monitor
)
1648 cupsFilePutConf(fp
, "PortMonitor", printer
->port_monitor
);
1650 if (printer
->state
== IPP_PRINTER_STOPPED
)
1652 cupsFilePuts(fp
, "State Stopped\n");
1654 if (printer
->state_message
)
1655 cupsFilePutConf(fp
, "StateMessage", printer
->state_message
);
1658 cupsFilePuts(fp
, "State Idle\n");
1660 cupsFilePrintf(fp
, "StateTime %d\n", (int)printer
->state_time
);
1662 for (i
= 0; i
< printer
->num_reasons
; i
++)
1663 if (strcmp(printer
->reasons
[i
], "connecting-to-device") &&
1664 strcmp(printer
->reasons
[i
], "cups-insecure-filter-warning") &&
1665 strcmp(printer
->reasons
[i
], "cups-missing-filter-warning"))
1666 cupsFilePutConf(fp
, "Reason", printer
->reasons
[i
]);
1668 cupsFilePrintf(fp
, "Type %d\n", printer
->type
);
1671 if (printer
->product
)
1672 cupsFilePutConf(fp
, "Product", printer
->product
);
1673 #endif /* HAVE_DNSSD */
1675 for (ptr
= (char *)cupsArrayFirst(printer
->filters
);
1677 ptr
= (char *)cupsArrayNext(printer
->filters
))
1678 cupsFilePutConf(fp
, "Filter", ptr
);
1680 for (ptr
= (char *)cupsArrayFirst(printer
->pre_filters
);
1682 ptr
= (char *)cupsArrayNext(printer
->pre_filters
))
1683 cupsFilePutConf(fp
, "PreFilter", ptr
);
1685 if (printer
->accepting
)
1686 cupsFilePuts(fp
, "Accepting Yes\n");
1688 cupsFilePuts(fp
, "Accepting No\n");
1690 if (printer
->shared
)
1691 cupsFilePuts(fp
, "Shared Yes\n");
1693 cupsFilePuts(fp
, "Shared No\n");
1695 snprintf(value
, sizeof(value
), "%s %s", printer
->job_sheets
[0],
1696 printer
->job_sheets
[1]);
1697 cupsFilePutConf(fp
, "JobSheets", value
);
1699 cupsFilePrintf(fp
, "QuotaPeriod %d\n", printer
->quota_period
);
1700 cupsFilePrintf(fp
, "PageLimit %d\n", printer
->page_limit
);
1701 cupsFilePrintf(fp
, "KLimit %d\n", printer
->k_limit
);
1703 for (name
= (char *)cupsArrayFirst(printer
->users
);
1705 name
= (char *)cupsArrayNext(printer
->users
))
1706 cupsFilePutConf(fp
, printer
->deny_users
? "DenyUser" : "AllowUser", name
);
1708 if (printer
->op_policy
)
1709 cupsFilePutConf(fp
, "OpPolicy", printer
->op_policy
);
1710 if (printer
->error_policy
)
1711 cupsFilePutConf(fp
, "ErrorPolicy", printer
->error_policy
);
1713 for (i
= printer
->num_options
, option
= printer
->options
;
1717 snprintf(value
, sizeof(value
), "%s %s", option
->name
, option
->value
);
1718 cupsFilePutConf(fp
, "Option", value
);
1721 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-colors",
1722 IPP_TAG_NAME
)) != NULL
)
1724 snprintf(value
, sizeof(value
), "%s ", marker
->name
);
1726 for (i
= 0, ptr
= value
+ strlen(value
);
1727 i
< marker
->num_values
&& ptr
< (value
+ sizeof(value
) - 1);
1733 strlcpy(ptr
, marker
->values
[i
].string
.text
,
1734 value
+ sizeof(value
) - ptr
);
1739 cupsFilePutConf(fp
, "Attribute", value
);
1742 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-levels",
1743 IPP_TAG_INTEGER
)) != NULL
)
1745 cupsFilePrintf(fp
, "Attribute %s %d", marker
->name
,
1746 marker
->values
[0].integer
);
1747 for (i
= 1; i
< marker
->num_values
; i
++)
1748 cupsFilePrintf(fp
, ",%d", marker
->values
[i
].integer
);
1749 cupsFilePuts(fp
, "\n");
1752 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-low-levels",
1753 IPP_TAG_INTEGER
)) != NULL
)
1755 cupsFilePrintf(fp
, "Attribute %s %d", marker
->name
,
1756 marker
->values
[0].integer
);
1757 for (i
= 1; i
< marker
->num_values
; i
++)
1758 cupsFilePrintf(fp
, ",%d", marker
->values
[i
].integer
);
1759 cupsFilePuts(fp
, "\n");
1762 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-high-levels",
1763 IPP_TAG_INTEGER
)) != NULL
)
1765 cupsFilePrintf(fp
, "Attribute %s %d", marker
->name
,
1766 marker
->values
[0].integer
);
1767 for (i
= 1; i
< marker
->num_values
; i
++)
1768 cupsFilePrintf(fp
, ",%d", marker
->values
[i
].integer
);
1769 cupsFilePuts(fp
, "\n");
1772 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-message",
1773 IPP_TAG_TEXT
)) != NULL
)
1775 snprintf(value
, sizeof(value
), "%s %s", marker
->name
,
1776 marker
->values
[0].string
.text
);
1778 cupsFilePutConf(fp
, "Attribute", value
);
1781 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-names",
1782 IPP_TAG_NAME
)) != NULL
)
1784 snprintf(value
, sizeof(value
), "%s ", marker
->name
);
1786 for (i
= 0, ptr
= value
+ strlen(value
);
1787 i
< marker
->num_values
&& ptr
< (value
+ sizeof(value
) - 1);
1793 strlcpy(ptr
, marker
->values
[i
].string
.text
,
1794 value
+ sizeof(value
) - ptr
);
1799 cupsFilePutConf(fp
, "Attribute", value
);
1802 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-types",
1803 IPP_TAG_KEYWORD
)) != NULL
)
1805 snprintf(value
, sizeof(value
), "%s ", marker
->name
);
1807 for (i
= 0, ptr
= value
+ strlen(value
);
1808 i
< marker
->num_values
&& ptr
< (value
+ sizeof(value
) - 1);
1814 strlcpy(ptr
, marker
->values
[i
].string
.text
,
1815 value
+ sizeof(value
) - ptr
);
1820 cupsFilePutConf(fp
, "Attribute", value
);
1823 if (printer
->marker_time
)
1824 cupsFilePrintf(fp
, "Attribute marker-change-time %ld\n",
1825 (long)printer
->marker_time
);
1827 cupsFilePuts(fp
, "</Printer>\n");
1831 * Make IRIX desktop & printer status happy
1834 write_irix_state(printer
);
1843 * 'cupsdSetAuthInfoRequired()' - Set the required authentication info.
1846 int /* O - 1 if value OK, 0 otherwise */
1847 cupsdSetAuthInfoRequired(
1848 cupsd_printer_t
*p
, /* I - Printer */
1849 const char *values
, /* I - Plain text value (or NULL) */
1850 ipp_attribute_t
*attr
) /* I - IPP attribute value (or NULL) */
1852 int i
; /* Looping var */
1855 p
->num_auth_info_required
= 0;
1858 * Do we have a plain text value?
1864 * Yes, grab the keywords...
1867 const char *end
; /* End of current value */
1870 while (*values
&& p
->num_auth_info_required
< 4)
1872 if ((end
= strchr(values
, ',')) == NULL
)
1873 end
= values
+ strlen(values
);
1875 if ((end
- values
) == 4 && !strncmp(values
, "none", 4))
1877 if (p
->num_auth_info_required
!= 0 || *end
)
1880 p
->auth_info_required
[p
->num_auth_info_required
] = "none";
1881 p
->num_auth_info_required
++;
1885 else if ((end
- values
) == 9 && !strncmp(values
, "negotiate", 9))
1887 if (p
->num_auth_info_required
!= 0 || *end
)
1890 p
->auth_info_required
[p
->num_auth_info_required
] = "negotiate";
1891 p
->num_auth_info_required
++;
1893 else if ((end
- values
) == 6 && !strncmp(values
, "domain", 6))
1895 p
->auth_info_required
[p
->num_auth_info_required
] = "domain";
1896 p
->num_auth_info_required
++;
1898 else if ((end
- values
) == 8 && !strncmp(values
, "password", 8))
1900 p
->auth_info_required
[p
->num_auth_info_required
] = "password";
1901 p
->num_auth_info_required
++;
1903 else if ((end
- values
) == 8 && !strncmp(values
, "username", 8))
1905 p
->auth_info_required
[p
->num_auth_info_required
] = "username";
1906 p
->num_auth_info_required
++;
1911 values
= (*end
) ? end
+ 1 : end
;
1914 if (p
->num_auth_info_required
== 0)
1916 p
->auth_info_required
[0] = "none";
1917 p
->num_auth_info_required
= 1;
1921 * Update the printer-type value as needed...
1924 if (p
->num_auth_info_required
> 1 ||
1925 strcmp(p
->auth_info_required
[0], "none"))
1926 p
->type
|= CUPS_PRINTER_AUTHENTICATED
;
1928 p
->type
&= ~CUPS_PRINTER_AUTHENTICATED
;
1934 * Grab values from an attribute instead...
1937 if (!attr
|| attr
->num_values
> 4)
1941 * Update the printer-type value as needed...
1944 if (attr
->num_values
> 1 ||
1945 strcmp(attr
->values
[0].string
.text
, "none"))
1946 p
->type
|= CUPS_PRINTER_AUTHENTICATED
;
1948 p
->type
&= ~CUPS_PRINTER_AUTHENTICATED
;
1950 for (i
= 0; i
< attr
->num_values
; i
++)
1952 if (!strcmp(attr
->values
[i
].string
.text
, "none"))
1954 if (p
->num_auth_info_required
!= 0 || attr
->num_values
!= 1)
1957 p
->auth_info_required
[p
->num_auth_info_required
] = "none";
1958 p
->num_auth_info_required
++;
1962 else if (!strcmp(attr
->values
[i
].string
.text
, "negotiate"))
1964 if (p
->num_auth_info_required
!= 0 || attr
->num_values
!= 1)
1967 p
->auth_info_required
[p
->num_auth_info_required
] = "negotiate";
1968 p
->num_auth_info_required
++;
1972 else if (!strcmp(attr
->values
[i
].string
.text
, "domain"))
1974 p
->auth_info_required
[p
->num_auth_info_required
] = "domain";
1975 p
->num_auth_info_required
++;
1977 else if (!strcmp(attr
->values
[i
].string
.text
, "password"))
1979 p
->auth_info_required
[p
->num_auth_info_required
] = "password";
1980 p
->num_auth_info_required
++;
1982 else if (!strcmp(attr
->values
[i
].string
.text
, "username"))
1984 p
->auth_info_required
[p
->num_auth_info_required
] = "username";
1985 p
->num_auth_info_required
++;
1996 * 'cupsdSetDeviceURI()' - Set the device URI for a printer.
2000 cupsdSetDeviceURI(cupsd_printer_t
*p
, /* I - Printer */
2001 const char *uri
) /* I - Device URI */
2003 char buffer
[1024], /* URI buffer */
2004 *start
, /* Start of data after scheme */
2005 *slash
, /* First slash after scheme:// */
2006 *ptr
; /* Pointer into user@host:port part */
2010 * Set the full device URI..
2013 cupsdSetString(&(p
->device_uri
), uri
);
2016 * Copy the device URI to a temporary buffer so we can sanitize any auth
2020 strlcpy(buffer
, uri
, sizeof(buffer
));
2023 * Find the end of the scheme:// part...
2026 if ((ptr
= strchr(buffer
, ':')) != NULL
)
2028 for (start
= ptr
+ 1; *start
; start
++)
2033 * Find the next slash (/) in the URI...
2036 if ((slash
= strchr(start
, '/')) == NULL
)
2037 slash
= start
+ strlen(start
); /* No slash, point to the end */
2040 * Check for an @ sign before the slash...
2043 if ((ptr
= strchr(start
, '@')) != NULL
&& ptr
< slash
)
2046 * Found an @ sign and it is before the resource part, so we have
2047 * an authentication string. Copy the remaining URI over the
2048 * authentication string...
2051 _cups_strcpy(start
, ptr
+ 1);
2056 * Save the sanitized URI...
2059 cupsdSetString(&(p
->sanitized_device_uri
), buffer
);
2064 * 'cupsdSetPrinterAttr()' - Set a printer attribute.
2068 cupsdSetPrinterAttr(
2069 cupsd_printer_t
*p
, /* I - Printer */
2070 const char *name
, /* I - Attribute name */
2071 char *value
) /* I - Attribute value string */
2073 ipp_attribute_t
*attr
; /* Attribute */
2074 int i
, /* Looping var */
2075 count
; /* Number of values */
2076 char *ptr
; /* Pointer into value */
2077 ipp_tag_t value_tag
; /* Value tag for this attribute */
2081 * Don't allow empty values...
2084 if (!*value
&& strcmp(name
, "marker-message"))
2086 cupsdLogMessage(CUPSD_LOG_ERROR
, "Ignoring empty \"%s\" attribute", name
);
2091 * Count the number of values...
2094 for (count
= 1, ptr
= value
;
2095 (ptr
= strchr(ptr
, ',')) != NULL
;
2099 * Then add or update the attribute as needed...
2102 if (!strcmp(name
, "marker-levels") || !strcmp(name
, "marker-low-levels") ||
2103 !strcmp(name
, "marker-high-levels"))
2109 if ((attr
= ippFindAttribute(p
->attrs
, name
, IPP_TAG_INTEGER
)) != NULL
&&
2110 attr
->num_values
< count
)
2112 ippDeleteAttribute(p
->attrs
, attr
);
2117 attr
->num_values
= count
;
2119 attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
, name
,
2124 cupsdLogMessage(CUPSD_LOG_ERROR
,
2125 "Unable to allocate memory for printer attribute "
2126 "(%d values)", count
);
2130 for (i
= 0; i
< count
; i
++)
2132 if ((ptr
= strchr(value
, ',')) != NULL
)
2135 attr
->values
[i
].integer
= strtol(value
, NULL
, 10);
2144 * Name or keyword values...
2147 if (!strcmp(name
, "marker-types"))
2148 value_tag
= IPP_TAG_KEYWORD
;
2149 else if (!strcmp(name
, "marker-message"))
2150 value_tag
= IPP_TAG_TEXT
;
2152 value_tag
= IPP_TAG_NAME
;
2154 if ((attr
= ippFindAttribute(p
->attrs
, name
, value_tag
)) != NULL
&&
2155 attr
->num_values
< count
)
2157 ippDeleteAttribute(p
->attrs
, attr
);
2163 for (i
= 0; i
< attr
->num_values
; i
++)
2164 _cupsStrFree(attr
->values
[i
].string
.text
);
2166 attr
->num_values
= count
;
2169 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, value_tag
, name
,
2174 cupsdLogMessage(CUPSD_LOG_ERROR
,
2175 "Unable to allocate memory for printer attribute "
2176 "(%d values)", count
);
2180 for (i
= 0; i
< count
; i
++)
2182 if ((ptr
= strchr(value
, ',')) != NULL
)
2185 attr
->values
[i
].string
.text
= _cupsStrAlloc(value
);
2195 * 'cupsdSetPrinterAttrs()' - Set printer attributes based upon the PPD file.
2199 cupsdSetPrinterAttrs(cupsd_printer_t
*p
)/* I - Printer to setup */
2201 int i
, /* Looping var */
2202 length
; /* Length of browse attributes */
2203 char resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
2204 int num_air
; /* Number of auth-info-required values */
2205 const char * const *air
; /* auth-info-required values */
2206 cupsd_location_t
*auth
; /* Pointer to authentication element */
2207 const char *auth_supported
; /* Authentication supported */
2208 ipp_t
*oldattrs
; /* Old printer attributes */
2209 ipp_attribute_t
*attr
; /* Attribute data */
2210 cups_option_t
*option
; /* Current printer option */
2211 char *name
, /* Current user/group name */
2212 *filter
; /* Current filter */
2213 static const char * const air_none
[] =
2214 { /* No authentication */
2217 static const char * const air_userpass
[] =
2218 { /* Basic/Digest authentication */
2224 DEBUG_printf(("cupsdSetPrinterAttrs: entering name = %s, type = %x\n", p
->name
,
2228 * Make sure that we have the common attributes defined...
2232 cupsdCreateCommonData();
2235 * Clear out old filters, if any...
2238 delete_printer_filters(p
);
2241 * Figure out the authentication that is required for the printer.
2244 auth_supported
= "requesting-user-name";
2248 if (p
->num_auth_info_required
> 0 && strcmp(p
->auth_info_required
[0], "none"))
2250 num_air
= p
->num_auth_info_required
;
2251 air
= p
->auth_info_required
;
2253 else if ((p
->type
& CUPS_PRINTER_AUTHENTICATED
) &&
2254 (p
->type
& CUPS_PRINTER_DISCOVERED
))
2260 if (p
->type
& CUPS_PRINTER_CLASS
)
2261 snprintf(resource
, sizeof(resource
), "/classes/%s", p
->name
);
2263 snprintf(resource
, sizeof(resource
), "/printers/%s", p
->name
);
2265 if ((auth
= cupsdFindBest(resource
, HTTP_POST
)) == NULL
||
2266 auth
->type
== CUPSD_AUTH_NONE
)
2267 auth
= cupsdFindPolicyOp(p
->op_policy_ptr
, IPP_PRINT_JOB
);
2271 int auth_type
; /* Authentication type */
2274 if ((auth_type
= auth
->type
) == CUPSD_AUTH_DEFAULT
)
2275 auth_type
= DefaultAuthType
;
2277 if (auth_type
== CUPSD_AUTH_BASIC
|| auth_type
== CUPSD_AUTH_BASICDIGEST
)
2278 auth_supported
= "basic";
2279 else if (auth_type
== CUPSD_AUTH_DIGEST
)
2280 auth_supported
= "digest";
2282 else if (auth_type
== CUPSD_AUTH_NEGOTIATE
)
2283 auth_supported
= "negotiate";
2284 #endif /* HAVE_GSSAPI */
2286 if (!(p
->type
& CUPS_PRINTER_DISCOVERED
))
2288 if (auth_type
!= CUPSD_AUTH_NONE
)
2289 p
->type
|= CUPS_PRINTER_AUTHENTICATED
;
2291 p
->type
&= ~CUPS_PRINTER_AUTHENTICATED
;
2294 else if (!(p
->type
& CUPS_PRINTER_DISCOVERED
))
2295 p
->type
&= ~CUPS_PRINTER_AUTHENTICATED
;
2298 * Create the required IPP attributes for a printer...
2301 oldattrs
= p
->attrs
;
2302 p
->attrs
= ippNew();
2304 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2305 "uri-authentication-supported", NULL
, auth_supported
);
2306 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2307 "uri-security-supported", NULL
, "none");
2308 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
, "printer-name", NULL
,
2310 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-location",
2311 NULL
, p
->location
? p
->location
: "");
2312 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-info",
2313 NULL
, p
->info
? p
->info
: "");
2315 if (cupsArrayCount(p
->users
) > 0)
2318 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2319 "requesting-user-name-denied",
2320 cupsArrayCount(p
->users
), NULL
, NULL
);
2322 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2323 "requesting-user-name-allowed",
2324 cupsArrayCount(p
->users
), NULL
, NULL
);
2326 for (i
= 0, name
= (char *)cupsArrayFirst(p
->users
);
2328 i
++, name
= (char *)cupsArrayNext(p
->users
))
2329 attr
->values
[i
].string
.text
= _cupsStrRetain(name
);
2332 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2333 "job-quota-period", p
->quota_period
);
2334 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2335 "job-k-limit", p
->k_limit
);
2336 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2337 "job-page-limit", p
->page_limit
);
2338 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2339 "auth-info-required", num_air
, NULL
, air
);
2341 if (cupsArrayCount(Banners
) > 0 && !(p
->type
& CUPS_PRINTER_DISCOVERED
))
2344 * Setup the job-sheets-default attribute...
2347 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2348 "job-sheets-default", 2, NULL
, NULL
);
2352 attr
->values
[0].string
.text
= _cupsStrAlloc(Classification
?
2353 Classification
: p
->job_sheets
[0]);
2354 attr
->values
[1].string
.text
= _cupsStrAlloc(Classification
?
2355 Classification
: p
->job_sheets
[1]);
2362 if (p
->type
& CUPS_PRINTER_DISCOVERED
)
2365 * Tell the client this is a remote printer of some type...
2368 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
2369 "printer-uri-supported", NULL
, p
->uri
);
2371 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "printer-more-info",
2375 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
2376 "printer-make-and-model", NULL
, p
->make_model
);
2378 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "device-uri", NULL
,
2387 * Assign additional attributes depending on whether this is a printer
2391 if (p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
))
2394 p
->type
&= ~CUPS_PRINTER_OPTIONS
;
2397 * Add class-specific attributes...
2400 if ((p
->type
& CUPS_PRINTER_IMPLICIT
) && p
->num_printers
> 0 &&
2401 p
->printers
[0]->make_model
)
2402 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
2403 "printer-make-and-model", NULL
, p
->printers
[0]->make_model
);
2405 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
2406 "printer-make-and-model", NULL
, "Local Printer Class");
2408 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "device-uri", NULL
,
2409 "file:///dev/null");
2411 if (p
->num_printers
> 0)
2414 * Add a list of member names; URIs are added in copy_printer_attrs...
2417 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2418 "member-names", p
->num_printers
, NULL
, NULL
);
2419 p
->type
|= CUPS_PRINTER_OPTIONS
;
2421 for (i
= 0; i
< p
->num_printers
; i
++)
2424 attr
->values
[i
].string
.text
= _cupsStrRetain(p
->printers
[i
]->name
);
2426 p
->type
&= ~CUPS_PRINTER_OPTIONS
| p
->printers
[i
]->type
;
2433 * Add printer-specific attributes...
2436 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "device-uri", NULL
,
2437 p
->sanitized_device_uri
);
2440 * Assign additional attributes from the PPD file (if any)...
2446 * Add filters for printer...
2449 cupsdSetPrinterReasons(p
, "-cups-missing-filter-warning,"
2450 "cups-insecure-filter-warning");
2452 for (filter
= (char *)cupsArrayFirst(p
->filters
);
2454 filter
= (char *)cupsArrayNext(p
->filters
))
2455 add_printer_filter(p
, p
->filetype
, filter
);
2459 p
->prefiltertype
= mimeAddType(MimeDatabase
, "prefilter", p
->name
);
2461 for (filter
= (char *)cupsArrayFirst(p
->pre_filters
);
2463 filter
= (char *)cupsArrayNext(p
->pre_filters
))
2464 add_printer_filter(p
, p
->prefiltertype
, filter
);
2470 * Copy marker attributes as needed...
2475 ipp_attribute_t
*oldattr
; /* Old attribute */
2478 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-colors",
2479 IPP_TAG_NAME
)) != NULL
)
2481 if ((attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2482 "marker-colors", oldattr
->num_values
, NULL
,
2485 for (i
= 0; i
< oldattr
->num_values
; i
++)
2486 attr
->values
[i
].string
.text
=
2487 _cupsStrRetain(oldattr
->values
[i
].string
.text
);
2491 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-levels",
2492 IPP_TAG_INTEGER
)) != NULL
)
2494 if ((attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2495 "marker-levels", oldattr
->num_values
,
2498 for (i
= 0; i
< oldattr
->num_values
; i
++)
2499 attr
->values
[i
].integer
= oldattr
->values
[i
].integer
;
2503 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-message",
2504 IPP_TAG_TEXT
)) != NULL
)
2505 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "marker-message",
2506 NULL
, oldattr
->values
[0].string
.text
);
2508 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-low-levels",
2509 IPP_TAG_INTEGER
)) != NULL
)
2511 if ((attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2512 "marker-low-levels", oldattr
->num_values
,
2515 for (i
= 0; i
< oldattr
->num_values
; i
++)
2516 attr
->values
[i
].integer
= oldattr
->values
[i
].integer
;
2520 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-high-levels",
2521 IPP_TAG_INTEGER
)) != NULL
)
2523 if ((attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2524 "marker-high-levels", oldattr
->num_values
,
2527 for (i
= 0; i
< oldattr
->num_values
; i
++)
2528 attr
->values
[i
].integer
= oldattr
->values
[i
].integer
;
2532 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-names",
2533 IPP_TAG_NAME
)) != NULL
)
2535 if ((attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2536 "marker-names", oldattr
->num_values
, NULL
,
2539 for (i
= 0; i
< oldattr
->num_values
; i
++)
2540 attr
->values
[i
].string
.text
=
2541 _cupsStrRetain(oldattr
->values
[i
].string
.text
);
2545 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-types",
2546 IPP_TAG_KEYWORD
)) != NULL
)
2548 if ((attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2549 "marker-types", oldattr
->num_values
, NULL
,
2552 for (i
= 0; i
< oldattr
->num_values
; i
++)
2553 attr
->values
[i
].string
.text
=
2554 _cupsStrRetain(oldattr
->values
[i
].string
.text
);
2558 ippDelete(oldattrs
);
2562 * Force sharing off for remote queues...
2565 if (p
->type
& (CUPS_PRINTER_REMOTE
| CUPS_PRINTER_IMPLICIT
))
2570 * Copy the printer options into a browse attributes string we can re-use.
2573 const char *valptr
; /* Pointer into value */
2574 char *attrptr
; /* Pointer into attribute string */
2578 * Free the old browse attributes as needed...
2581 if (p
->browse_attrs
)
2582 free(p
->browse_attrs
);
2585 * Compute the length of all attributes + job-sheets, lease-duration,
2586 * and BrowseLocalOptions.
2589 for (length
= 1, i
= p
->num_options
, option
= p
->options
;
2593 length
+= strlen(option
->name
) + 2;
2597 for (valptr
= option
->value
; *valptr
; valptr
++)
2598 if (strchr(" \"\'\\", *valptr
))
2605 length
+= 13 + strlen(p
->job_sheets
[0]) + strlen(p
->job_sheets
[1]);
2607 if (BrowseLocalOptions
)
2608 length
+= 12 + strlen(BrowseLocalOptions
);
2611 * Allocate the new string...
2614 if ((p
->browse_attrs
= calloc(1, length
)) == NULL
)
2615 cupsdLogMessage(CUPSD_LOG_ERROR
,
2616 "Unable to allocate %d bytes for browse data!",
2621 * Got the allocated string, now copy the options and attributes over...
2624 sprintf(p
->browse_attrs
, "job-sheets=%s,%s lease-duration=%d",
2625 p
->job_sheets
[0], p
->job_sheets
[1], BrowseTimeout
);
2626 attrptr
= p
->browse_attrs
+ strlen(p
->browse_attrs
);
2628 if (BrowseLocalOptions
)
2630 sprintf(attrptr
, " ipp-options=%s", BrowseLocalOptions
);
2631 attrptr
+= strlen(attrptr
);
2634 for (i
= p
->num_options
, option
= p
->options
;
2639 strcpy(attrptr
, option
->name
);
2640 attrptr
+= strlen(attrptr
);
2646 for (valptr
= option
->value
; *valptr
; valptr
++)
2648 if (strchr(" \"\'\\", *valptr
))
2651 *attrptr
++ = *valptr
;
2659 * Populate the document-format-supported attribute...
2662 add_printer_formats(p
);
2664 DEBUG_printf(("cupsdSetPrinterAttrs: leaving name = %s, type = %x\n", p
->name
,
2668 * Add name-default attributes...
2671 add_printer_defaults(p
);
2675 * Write the IRIX printer config and status files...
2678 write_irix_config(p
);
2679 write_irix_state(p
);
2683 * Let the browse protocols reflect the change
2686 cupsdRegisterPrinter(p
);
2691 * 'cupsdSetPrinterReasons()' - Set/update the reasons strings.
2694 int /* O - 1 if something changed, 0 otherwise */
2695 cupsdSetPrinterReasons(
2696 cupsd_printer_t
*p
, /* I - Printer */
2697 const char *s
) /* I - Reasons strings */
2699 int i
, /* Looping var */
2700 changed
= 0; /* Did something change? */
2701 const char *sptr
; /* Pointer into reasons */
2702 char reason
[255], /* Reason string */
2703 *rptr
; /* Pointer into reason */
2706 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
2707 "cupsdSetPrinterReasons(p=%p(%s),s=\"%s\"", p
, p
->name
, s
);
2709 if (s
[0] == '-' || s
[0] == '+')
2712 * Add/remove reasons...
2720 * Replace reasons...
2725 for (i
= 0; i
< p
->num_reasons
; i
++)
2726 _cupsStrFree(p
->reasons
[i
]);
2731 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
2733 if (PrintcapFormat
== PRINTCAP_PLIST
)
2734 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
2737 if (!strcmp(s
, "none"))
2741 * Loop through all of the reasons...
2747 * Skip leading whitespace and commas...
2750 while (isspace(*sptr
& 255) || *sptr
== ',')
2753 for (rptr
= reason
; *sptr
&& !isspace(*sptr
& 255) && *sptr
!= ','; sptr
++)
2754 if (rptr
< (reason
+ sizeof(reason
) - 1))
2768 for (i
= 0; i
< p
->num_reasons
; i
++)
2769 if (!strcmp(reason
, p
->reasons
[i
]))
2772 * Found a match, so remove it...
2777 _cupsStrFree(p
->reasons
[i
]);
2779 if (i
< p
->num_reasons
)
2780 memmove(p
->reasons
+ i
, p
->reasons
+ i
+ 1,
2781 (p
->num_reasons
- i
) * sizeof(char *));
2783 if (!strcmp(reason
, "paused") && p
->state
== IPP_PRINTER_STOPPED
)
2784 cupsdSetPrinterState(p
, IPP_PRINTER_IDLE
, 1);
2786 if (strcmp(reason
, "connecting-to-device"))
2788 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
2790 if (PrintcapFormat
== PRINTCAP_PLIST
)
2791 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
2796 else if (p
->num_reasons
< (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
2802 for (i
= 0; i
< p
->num_reasons
; i
++)
2803 if (!strcmp(reason
, p
->reasons
[i
]))
2806 if (i
>= p
->num_reasons
)
2808 if (i
>= (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
2810 cupsdLogMessage(CUPSD_LOG_ALERT
,
2811 "Too many printer-state-reasons values for %s (%d)",
2816 p
->reasons
[i
] = _cupsStrAlloc(reason
);
2820 if (!strcmp(reason
, "paused") && p
->state
!= IPP_PRINTER_STOPPED
)
2821 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, 1);
2823 if (strcmp(reason
, "connecting-to-device"))
2825 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
2827 if (PrintcapFormat
== PRINTCAP_PLIST
)
2828 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
2839 * 'cupsdSetPrinterState()' - Update the current state of a printer.
2843 cupsdSetPrinterState(
2844 cupsd_printer_t
*p
, /* I - Printer to change */
2845 ipp_pstate_t s
, /* I - New state */
2846 int update
) /* I - Update printers.conf? */
2848 ipp_pstate_t old_state
; /* Old printer state */
2849 static const char * const printer_states
[] =
2850 { /* State strings */
2858 * Can't set status of remote printers...
2861 if (p
->type
& CUPS_PRINTER_DISCOVERED
)
2865 * Set the new state...
2868 if (PrintcapFormat
== PRINTCAP_PLIST
)
2869 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
2871 old_state
= p
->state
;
2876 cupsdAddEvent(s
== IPP_PRINTER_STOPPED
? CUPSD_EVENT_PRINTER_STOPPED
:
2877 CUPSD_EVENT_PRINTER_STATE
, p
, NULL
,
2878 "%s \"%s\" state changed to %s.",
2879 (p
->type
& CUPS_PRINTER_CLASS
) ? "Class" : "Printer",
2880 p
->name
, printer_states
[p
->state
]);
2883 * Let the browse code know this needs to be updated...
2887 p
->state_time
= time(NULL
);
2891 write_irix_state(p
);
2896 * Set/clear the paused reason as needed...
2899 if (s
== IPP_PRINTER_STOPPED
)
2900 cupsdSetPrinterReasons(p
, "+paused");
2902 cupsdSetPrinterReasons(p
, "-paused");
2905 * Clear the message for the queue when going to processing...
2908 if (s
== IPP_PRINTER_PROCESSING
)
2909 p
->state_message
[0] = '\0';
2912 * Update the printer history...
2915 cupsdAddPrinterHistory(p
);
2918 * Let the browse protocols reflect the change...
2922 cupsdRegisterPrinter(p
);
2925 * Save the printer configuration if a printer goes from idle or processing
2926 * to stopped (or visa-versa)...
2930 (old_state
== IPP_PRINTER_STOPPED
) != (s
== IPP_PRINTER_STOPPED
))
2932 if (p
->type
& CUPS_PRINTER_CLASS
)
2933 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
2935 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
2941 * 'cupsdStopPrinter()' - Stop a printer from printing any jobs...
2945 cupsdStopPrinter(cupsd_printer_t
*p
, /* I - Printer to stop */
2946 int update
)/* I - Update printers.conf? */
2949 * Set the printer state...
2952 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, update
);
2955 * See if we have a job printing on this printer...
2958 if (p
->job
&& p
->job
->state_value
== IPP_JOB_PROCESSING
)
2959 cupsdSetJobState(p
->job
, IPP_JOB_PENDING
, CUPSD_JOB_DEFAULT
,
2960 "Job stopped due to printer being paused.");
2965 * 'cupsdUpdatePrinterPPD()' - Update keywords in a printer's PPD file.
2968 int /* O - 1 if successful, 0 otherwise */
2969 cupsdUpdatePrinterPPD(
2970 cupsd_printer_t
*p
, /* I - Printer */
2971 int num_keywords
, /* I - Number of keywords */
2972 cups_option_t
*keywords
) /* I - Keywords */
2974 int i
; /* Looping var */
2975 cups_file_t
*src
, /* Original file */
2976 *dst
; /* New file */
2977 char srcfile
[1024], /* Original filename */
2978 dstfile
[1024], /* New filename */
2979 line
[1024], /* Line from file */
2980 keystring
[41]; /* Keyword from line */
2981 cups_option_t
*keyword
; /* Current keyword */
2984 cupsdLogMessage(CUPSD_LOG_INFO
, "Updating keywords in PPD file for %s...",
2988 * Get the old and new PPD filenames...
2991 snprintf(srcfile
, sizeof(srcfile
), "%s/ppd/%s.ppd.O", ServerRoot
, p
->name
);
2992 snprintf(dstfile
, sizeof(srcfile
), "%s/ppd/%s.ppd", ServerRoot
, p
->name
);
2995 * Rename the old file and open the old and new...
2998 if (rename(dstfile
, srcfile
))
3000 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to backup PPD file for %s: %s",
3001 p
->name
, strerror(errno
));
3005 if ((src
= cupsFileOpen(srcfile
, "r")) == NULL
)
3007 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to open PPD file \"%s\": %s",
3008 srcfile
, strerror(errno
));
3009 rename(srcfile
, dstfile
);
3013 if ((dst
= cupsFileOpen(dstfile
, "w")) == NULL
)
3015 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to create PPD file \"%s\": %s",
3016 dstfile
, strerror(errno
));
3018 rename(srcfile
, dstfile
);
3023 * Copy the first line and then write out all of the keywords...
3026 if (!cupsFileGets(src
, line
, sizeof(line
)))
3028 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to read PPD file \"%s\": %s",
3029 srcfile
, strerror(errno
));
3032 rename(srcfile
, dstfile
);
3036 cupsFilePrintf(dst
, "%s\n", line
);
3038 for (i
= num_keywords
, keyword
= keywords
; i
> 0; i
--, keyword
++)
3040 cupsdLogMessage(CUPSD_LOG_DEBUG
, "*%s: %s", keyword
->name
, keyword
->value
);
3041 cupsFilePrintf(dst
, "*%s: %s\n", keyword
->name
, keyword
->value
);
3045 * Then copy the rest of the PPD file, dropping any keywords we changed.
3048 while (cupsFileGets(src
, line
, sizeof(line
)))
3051 * Skip keywords we've already set...
3054 if (sscanf(line
, "*%40[^:]:", keystring
) == 1 &&
3055 cupsGetOption(keystring
, num_keywords
, keywords
))
3059 * Otherwise write the line...
3062 cupsFilePrintf(dst
, "%s\n", line
);
3066 * Close files and return...
3077 * 'cupsdUpdatePrinters()' - Update printers after a partial reload.
3081 cupsdUpdatePrinters(void)
3083 cupsd_printer_t
*p
; /* Current printer */
3087 * Loop through the printers and recreate the printer attributes
3088 * for any local printers since the policy and/or access control
3089 * stuff may have changed. Also, if browsing is disabled, remove
3090 * any remote printers...
3093 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3095 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3098 * Remove remote printers if we are no longer browsing...
3102 (p
->type
& (CUPS_PRINTER_IMPLICIT
| CUPS_PRINTER_DISCOVERED
)))
3104 if (p
->type
& CUPS_PRINTER_IMPLICIT
)
3105 cupsArrayRemove(ImplicitPrinters
, p
);
3107 cupsArraySave(Printers
);
3108 cupsdDeletePrinter(p
, 0);
3109 cupsArrayRestore(Printers
);
3114 * Update the operation policy pointer...
3117 if ((p
->op_policy_ptr
= cupsdFindPolicy(p
->op_policy
)) == NULL
)
3118 p
->op_policy_ptr
= DefaultPolicyPtr
;
3121 * Update printer attributes as needed...
3124 if (!(p
->type
& CUPS_PRINTER_DISCOVERED
))
3125 cupsdSetPrinterAttrs(p
);
3131 * 'cupsdValidateDest()' - Validate a printer/class destination.
3134 const char * /* O - Printer or class name */
3136 const char *uri
, /* I - Printer URI */
3137 cups_ptype_t
*dtype
, /* O - Type (printer or class) */
3138 cupsd_printer_t
**printer
) /* O - Printer pointer */
3140 cupsd_printer_t
*p
; /* Current printer */
3141 char localname
[1024],/* Localized hostname */
3142 *lptr
, /* Pointer into localized hostname */
3143 *sptr
, /* Pointer into server name */
3144 *rptr
, /* Pointer into resource */
3145 scheme
[32], /* Scheme portion of URI */
3146 username
[64], /* Username portion of URI */
3147 hostname
[HTTP_MAX_HOST
],
3148 /* Host portion of URI */
3149 resource
[HTTP_MAX_URI
];
3150 /* Resource portion of URI */
3151 int port
; /* Port portion of URI */
3154 DEBUG_printf(("cupsdValidateDest(uri=\"%s\", dtype=%p, printer=%p)\n", uri
,
3158 * Initialize return values...
3165 *dtype
= (cups_ptype_t
)0;
3168 * Pull the hostname and resource from the URI...
3171 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
, scheme
, sizeof(scheme
),
3172 username
, sizeof(username
), hostname
, sizeof(hostname
),
3173 &port
, resource
, sizeof(resource
));
3176 * See if the resource is a class or printer...
3179 if (!strncmp(resource
, "/classes/", 9))
3185 rptr
= resource
+ 9;
3187 else if (!strncmp(resource
, "/printers/", 10))
3193 rptr
= resource
+ 10;
3198 * Bad resource name...
3205 * See if the printer or class name exists...
3208 p
= cupsdFindDest(rptr
);
3210 if (p
== NULL
&& strchr(rptr
, '@') == NULL
)
3218 *dtype
= p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
|
3219 CUPS_PRINTER_REMOTE
| CUPS_PRINTER_DISCOVERED
);
3225 * Change localhost to the server name...
3228 if (!strcasecmp(hostname
, "localhost"))
3229 strlcpy(hostname
, ServerName
, sizeof(hostname
));
3231 strlcpy(localname
, hostname
, sizeof(localname
));
3233 if (!strcasecmp(hostname
, ServerName
))
3236 * Localize the hostname...
3239 lptr
= strchr(localname
, '.');
3240 sptr
= strchr(ServerName
, '.');
3242 if (sptr
!= NULL
&& lptr
!= NULL
)
3245 * Strip the common domain name components...
3248 while (lptr
!= NULL
)
3250 if (!strcasecmp(lptr
, sptr
))
3256 lptr
= strchr(lptr
+ 1, '.');
3261 DEBUG_printf(("localized hostname is \"%s\"...\n", localname
));
3264 * Find a matching printer or class...
3267 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3269 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3270 if (!strcasecmp(p
->hostname
, localname
) &&
3271 !strcasecmp(p
->name
, rptr
))
3277 *dtype
= p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
|
3278 CUPS_PRINTER_REMOTE
| CUPS_PRINTER_DISCOVERED
);
3288 * 'cupsdWritePrintcap()' - Write a pseudo-printcap file for older applications
3293 cupsdWritePrintcap(void)
3295 int i
; /* Looping var */
3296 cups_file_t
*fp
; /* Printcap file */
3297 cupsd_printer_t
*p
; /* Current printer */
3302 * Update the IRIX printer state for the default printer; if
3303 * no printers remain, then the default printer file will be
3307 write_irix_state(DefaultPrinter
);
3311 * See if we have a printcap file; if not, don't bother writing it.
3314 if (!Printcap
|| !*Printcap
)
3317 cupsdLogMessage(CUPSD_LOG_INFO
, "Generating printcap %s...", Printcap
);
3320 * Open the printcap file...
3323 if ((fp
= cupsFileOpen(Printcap
, "w")) == NULL
)
3327 * Put a comment header at the top so that users will know where the
3328 * data has come from...
3331 if (PrintcapFormat
!= PRINTCAP_PLIST
)
3332 cupsFilePrintf(fp
, "# This file was automatically generated by cupsd(8) "
3334 "# %s/printers.conf file. All changes to this file\n"
3335 "# will be lost.\n", ServerRoot
);
3338 * Write a new printcap with the current list of printers.
3341 switch (PrintcapFormat
)
3345 * Each printer is put in the file as:
3355 cupsFilePrintf(fp
, "%s|%s:rm=%s:rp=%s:\n", DefaultPrinter
->name
,
3356 DefaultPrinter
->info
, ServerName
,
3357 DefaultPrinter
->name
);
3359 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3361 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3362 if (p
!= DefaultPrinter
)
3363 cupsFilePrintf(fp
, "%s|%s:rm=%s:rp=%s:\n", p
->name
, p
->info
,
3364 ServerName
, p
->name
);
3367 case PRINTCAP_PLIST
:
3369 * Each printer is written as a dictionary in a plist file.
3370 * Currently the printer-name, printer-info, printer-is-accepting-jobs,
3371 * printer-location, printer-make-and-model, printer-state,
3372 * printer-state-reasons, printer-type, and (sanitized) device-uri.
3375 cupsFilePuts(fp
, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
3376 "<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD "
3377 "PLIST 1.0//EN\" \"http://www.apple.com/DTDs/"
3378 "PropertyList-1.0.dtd\">\n"
3379 "<plist version=\"1.0\">\n"
3382 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3384 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3386 cupsFilePuts(fp
, "\t<dict>\n"
3387 "\t\t<key>printer-name</key>\n"
3389 write_xml_string(fp
, p
->name
);
3390 cupsFilePuts(fp
, "</string>\n"
3391 "\t\t<key>printer-info</key>\n"
3393 write_xml_string(fp
, p
->info
);
3394 cupsFilePrintf(fp
, "</string>\n"
3395 "\t\t<key>printer-is-accepting-jobs</key>\n"
3397 "\t\t<key>printer-location</key>\n"
3398 "\t\t<string>", p
->accepting
? "true" : "false");
3399 write_xml_string(fp
, p
->location
);
3400 cupsFilePuts(fp
, "</string>\n"
3401 "\t\t<key>printer-make-and-model</key>\n"
3403 write_xml_string(fp
, p
->make_model
);
3404 cupsFilePrintf(fp
, "</string>\n"
3405 "\t\t<key>printer-state</key>\n"
3406 "\t\t<integer>%d</integer>\n"
3407 "\t\t<key>printer-state-reasons</key>\n"
3408 "\t\t<array>\n", p
->state
);
3409 for (i
= 0; i
< p
->num_reasons
; i
++)
3411 cupsFilePuts(fp
, "\t\t\t<string>");
3412 write_xml_string(fp
, p
->reasons
[i
]);
3413 cupsFilePuts(fp
, "</string>\n");
3415 cupsFilePrintf(fp
, "\t\t</array>\n"
3416 "\t\t<key>printer-type</key>\n"
3417 "\t\t<integer>%d</integer>\n"
3418 "\t\t<key>device-uri</key>\n"
3419 "\t\t<string>", p
->type
);
3420 write_xml_string(fp
, p
->sanitized_device_uri
);
3421 cupsFilePuts(fp
, "</string>\n"
3424 cupsFilePuts(fp
, "</array>\n"
3428 case PRINTCAP_SOLARIS
:
3430 * Each printer is put in the file as:
3432 * _all:all=Printer1,Printer2,Printer3,...,PrinterN
3433 * _default:use=DefaultPrinter
3435 * :bsdaddr=ServerName,Printer1:\
3436 * :description=Description:
3438 * :bsdaddr=ServerName,Printer2:\
3439 * :description=Description:
3441 * :bsdaddr=ServerName,Printer3:\
3442 * :description=Description:
3445 * :bsdaddr=ServerName,PrinterN:\
3446 * :description=Description:
3449 cupsFilePuts(fp
, "_all:all=");
3450 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3452 p
= (cupsd_printer_t
*)cupsArrayCurrent(Printers
))
3453 cupsFilePrintf(fp
, "%s%c", p
->name
,
3454 cupsArrayNext(Printers
) ? ',' : '\n');
3457 cupsFilePrintf(fp
, "_default:use=%s\n", DefaultPrinter
->name
);
3459 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3461 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3462 cupsFilePrintf(fp
, "%s:\\\n"
3463 "\t:bsdaddr=%s,%s:\\\n"
3464 "\t:description=%s:\n",
3465 p
->name
, ServerName
, p
->name
,
3466 p
->info
? p
->info
: "");
3479 * 'add_printer_defaults()' - Add name-default attributes to the printer attributes.
3483 add_printer_defaults(cupsd_printer_t
*p
)/* I - Printer */
3485 int i
; /* Looping var */
3486 int num_options
; /* Number of default options */
3487 cups_option_t
*options
, /* Default options */
3488 *option
; /* Current option */
3489 char name
[256]; /* name-default */
3493 * Maintain a common array of default attribute names...
3496 if (!CommonDefaults
)
3498 CommonDefaults
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
3500 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("copies-default"));
3501 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("document-format-default"));
3502 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("finishings-default"));
3503 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-hold-until-default"));
3504 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-priority-default"));
3505 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-sheets-default"));
3506 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("media-col-default"));
3507 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("number-up-default"));
3508 cupsArrayAdd(CommonDefaults
,
3509 _cupsStrAlloc("orientation-requested-default"));
3513 * Add all of the default options from the .conf files...
3516 for (num_options
= 0, options
= NULL
, i
= p
->num_options
, option
= p
->options
;
3520 if (strcmp(option
->name
, "ipp-options") &&
3521 strcmp(option
->name
, "job-sheets") &&
3522 strcmp(option
->name
, "lease-duration"))
3524 snprintf(name
, sizeof(name
), "%s-default", option
->name
);
3525 num_options
= cupsAddOption(name
, option
->value
, num_options
, &options
);
3527 if (!cupsArrayFind(CommonDefaults
, name
))
3528 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc(name
));
3533 * Convert options to IPP attributes...
3536 cupsEncodeOptions2(p
->attrs
, num_options
, options
, IPP_TAG_PRINTER
);
3537 cupsFreeOptions(num_options
, options
);
3540 * Add standard -default attributes as needed...
3543 if (!cupsGetOption("copies", p
->num_options
, p
->options
))
3544 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
, "copies-default",
3547 if (!cupsGetOption("document-format", p
->num_options
, p
->options
))
3548 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_MIMETYPE
,
3549 "document-format-default", NULL
, "application/octet-stream");
3551 if (!cupsGetOption("job-hold-until", p
->num_options
, p
->options
))
3552 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3553 "job-hold-until-default", NULL
, "no-hold");
3555 if (!cupsGetOption("job-priority", p
->num_options
, p
->options
))
3556 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3557 "job-priority-default", 50);
3559 if (!cupsGetOption("number-up", p
->num_options
, p
->options
))
3560 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3561 "number-up-default", 1);
3563 if (!cupsGetOption("notify-lease-duration", p
->num_options
, p
->options
))
3564 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3565 "notify-lease-duration-default", DefaultLeaseDuration
);
3567 if (!cupsGetOption("notify-events", p
->num_options
, p
->options
))
3568 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3569 "notify-events-default", NULL
, "job-completed");
3571 if (!cupsGetOption("orientation-requested", p
->num_options
, p
->options
))
3572 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NOVALUE
,
3573 "orientation-requested-default", NULL
, NULL
);
3575 if (!cupsGetOption("print-quality", p
->num_options
, p
->options
))
3576 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
3577 "print-quality-default", IPP_QUALITY_NORMAL
);
3582 * 'add_printer_filter()' - Add a MIME filter for a printer.
3587 cupsd_printer_t
*p
, /* I - Printer to add to */
3588 mime_type_t
*filtertype
, /* I - Filter or prefilter MIME type */
3589 const char *filter
) /* I - Filter to add */
3591 char super
[MIME_MAX_SUPER
], /* Super-type for filter */
3592 type
[MIME_MAX_TYPE
], /* Type for filter */
3593 program
[1024]; /* Program/filter name */
3594 int cost
; /* Cost of filter */
3595 mime_type_t
*temptype
; /* MIME type looping var */
3596 char filename
[1024], /* Full filter filename */
3597 *dirsep
; /* Pointer to directory separator */
3598 struct stat fileinfo
; /* File information */
3602 * Parse the filter string; it should be in the following format:
3604 * super/type cost program
3607 if (sscanf(filter
, "%15[^/]/%31s%d%*[ \t]%1023[^\n]", super
, type
, &cost
,
3610 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: invalid filter string \"%s\"!",
3616 * See if the filter program exists; if not, stop the printer and flag
3620 if (strcmp(program
, "-"))
3622 if (program
[0] == '/')
3623 strlcpy(filename
, program
, sizeof(filename
));
3625 snprintf(filename
, sizeof(filename
), "%s/filter/%s", ServerBin
, program
);
3627 if (stat(filename
, &fileinfo
))
3629 memset(&fileinfo
, 0, sizeof(fileinfo
));
3631 snprintf(p
->state_message
, sizeof(p
->state_message
),
3632 "Filter \"%s\" for printer \"%s\" not available: %s",
3633 filename
, p
->name
, strerror(errno
));
3634 cupsdSetPrinterReasons(p
, "+cups-missing-filter-warning");
3636 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s", p
->state_message
);
3640 * When running as root, do additional security checks...
3646 * Only use filters that are owned by root and do not have world write
3650 if (fileinfo
.st_uid
|| (fileinfo
.st_mode
& (S_ISUID
| S_IWOTH
)) != 0)
3652 if (fileinfo
.st_uid
)
3653 snprintf(p
->state_message
, sizeof(p
->state_message
),
3654 "Filter \"%s\" for printer \"%s\" not owned by root",
3657 snprintf(p
->state_message
, sizeof(p
->state_message
),
3658 "Filter \"%s\" for printer \"%s\" has insecure permissions "
3659 "(0%o)", filename
, p
->name
, fileinfo
.st_mode
);
3661 cupsdSetPrinterReasons(p
, "+cups-insecure-filter-warning");
3663 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s", p
->state_message
);
3665 else if (fileinfo
.st_mode
)
3668 * Similarly, check that the parent directory is also owned by root and
3669 * does not have world write permissions.
3672 if ((dirsep
= strrchr(filename
, '/')) != NULL
)
3675 if (!stat(filename
, &fileinfo
) &&
3677 (fileinfo
.st_mode
& (S_ISUID
| S_IWOTH
)) != 0))
3679 if (fileinfo
.st_uid
)
3680 snprintf(p
->state_message
, sizeof(p
->state_message
),
3681 "Filter directory \"%s\" for printer \"%s\" not owned by "
3682 "root", filename
, p
->name
);
3684 snprintf(p
->state_message
, sizeof(p
->state_message
),
3685 "Filter directory \"%s\" for printer \"%s\" has insecure "
3686 "permissions (0%o)", filename
, p
->name
, fileinfo
.st_mode
);
3688 cupsdSetPrinterReasons(p
, "+cups-insecure-filter-warning");
3690 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s", p
->state_message
);
3697 * Add the filter to the MIME database, supporting wildcards as needed...
3700 for (temptype
= mimeFirstType(MimeDatabase
);
3702 temptype
= mimeNextType(MimeDatabase
))
3703 if (((super
[0] == '*' && strcasecmp(temptype
->super
, "printer")) ||
3704 !strcasecmp(temptype
->super
, super
)) &&
3705 (type
[0] == '*' || !strcasecmp(temptype
->type
, type
)))
3707 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3708 "add_printer_filter: %s: adding filter %s/%s %s/%s %d %s",
3709 p
->name
, temptype
->super
, temptype
->type
,
3710 filtertype
->super
, filtertype
->type
,
3712 mimeAddFilter(MimeDatabase
, temptype
, filtertype
, cost
, program
);
3718 * 'add_printer_formats()' - Add document-format-supported values for a printer.
3722 add_printer_formats(cupsd_printer_t
*p
) /* I - Printer */
3724 int i
; /* Looping var */
3725 mime_type_t
*type
; /* Current MIME type */
3726 cups_array_t
*filters
; /* Filters */
3727 ipp_attribute_t
*attr
; /* document-format-supported attribute */
3728 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
3729 /* MIME type name */
3733 * Raw (and remote) queues advertise all of the supported MIME
3737 cupsArrayDelete(p
->filetypes
);
3738 p
->filetypes
= NULL
;
3742 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
,
3743 (ipp_tag_t
)(IPP_TAG_MIMETYPE
| IPP_TAG_COPY
),
3744 "document-format-supported", NumMimeTypes
, NULL
, MimeTypes
);
3749 * Otherwise, loop through the supported MIME types and see if there
3750 * are filters for them...
3753 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_printer_formats: %d types, %d filters",
3754 mimeNumTypes(MimeDatabase
), mimeNumFilters(MimeDatabase
));
3756 p
->filetypes
= cupsArrayNew(NULL
, NULL
);
3758 for (type
= mimeFirstType(MimeDatabase
);
3760 type
= mimeNextType(MimeDatabase
))
3762 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
3764 if ((filters
= mimeFilter(MimeDatabase
, type
, p
->filetype
, NULL
)) != NULL
)
3766 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3767 "add_printer_formats: %s: %s needs %d filters",
3768 p
->name
, mimetype
, cupsArrayCount(filters
));
3770 cupsArrayDelete(filters
);
3771 cupsArrayAdd(p
->filetypes
, type
);
3774 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3775 "add_printer_formats: %s: %s not supported",
3780 * Add the file formats that can be filtered...
3783 if ((type
= mimeType(MimeDatabase
, "application", "octet-stream")) == NULL
||
3784 !cupsArrayFind(p
->filetypes
, type
))
3789 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3790 "add_printer_formats: %s: %d supported types",
3791 p
->name
, cupsArrayCount(p
->filetypes
) + i
);
3793 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_MIMETYPE
,
3794 "document-format-supported",
3795 cupsArrayCount(p
->filetypes
) + i
, NULL
, NULL
);
3798 attr
->values
[0].string
.text
= _cupsStrAlloc("application/octet-stream");
3800 for (type
= (mime_type_t
*)cupsArrayFirst(p
->filetypes
);
3802 i
++, type
= (mime_type_t
*)cupsArrayNext(p
->filetypes
))
3804 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
3806 attr
->values
[i
].string
.text
= _cupsStrAlloc(mimetype
);
3811 char pdl
[1024]; /* Buffer to build pdl list */
3812 mime_filter_t
*filter
; /* MIME filter looping var */
3816 * We only support raw printing if this is not a Tioga PrintJobMgr based
3817 * queue and if application/octet-stream is a known type...
3820 for (filter
= (mime_filter_t
*)cupsArrayFirst(MimeDatabase
->filters
);
3822 filter
= (mime_filter_t
*)cupsArrayNext(MimeDatabase
->filters
))
3824 if (filter
->dst
== p
->filetype
&& filter
->filter
&&
3825 strstr(filter
->filter
, "PrintJobMgr"))
3831 if (!filter
&& mimeType(MimeDatabase
, "application", "octet-stream"))
3832 strlcat(pdl
, "application/octet-stream,", sizeof(pdl
));
3835 * Then list a bunch of formats that are supported by the printer...
3838 for (type
= (mime_type_t
*)cupsArrayFirst(p
->filetypes
);
3840 type
= (mime_type_t
*)cupsArrayNext(p
->filetypes
))
3842 if (!strcasecmp(type
->super
, "application"))
3844 if (!strcasecmp(type
->type
, "pdf"))
3845 strlcat(pdl
, "application/pdf,", sizeof(pdl
));
3846 else if (!strcasecmp(type
->type
, "postscript"))
3847 strlcat(pdl
, "application/postscript,", sizeof(pdl
));
3849 else if (!strcasecmp(type
->super
, "image"))
3851 if (!strcasecmp(type
->type
, "jpeg"))
3852 strlcat(pdl
, "image/jpeg,", sizeof(pdl
));
3853 else if (!strcasecmp(type
->type
, "png"))
3854 strlcat(pdl
, "image/png,", sizeof(pdl
));
3859 pdl
[strlen(pdl
) - 1] = '\0'; /* Remove trailing comma */
3861 cupsdSetString(&p
->pdl
, pdl
);
3863 #endif /* HAVE_DNSSD */
3868 * 'add_string_array()' - Add a string to an array of CUPS strings.
3872 add_string_array(cups_array_t
**a
, /* I - Array */
3873 const char *s
) /* I - String */
3876 *a
= cupsArrayNew(NULL
, NULL
);
3878 cupsArrayAdd(*a
, _cupsStrAlloc(s
));
3883 * 'compare_printers()' - Compare two printers.
3886 static int /* O - Result of comparison */
3887 compare_printers(void *first
, /* I - First printer */
3888 void *second
, /* I - Second printer */
3889 void *data
) /* I - App data (not used) */
3891 return (strcasecmp(((cupsd_printer_t
*)first
)->name
,
3892 ((cupsd_printer_t
*)second
)->name
));
3897 * 'delete_printer_filters()' - Delete all MIME filters for a printer.
3901 delete_printer_filters(
3902 cupsd_printer_t
*p
) /* I - Printer to remove from */
3904 mime_filter_t
*filter
; /* MIME filter looping var */
3908 * Range check input...
3915 * Remove all filters from the MIME database that have a destination
3916 * type == printer...
3919 for (filter
= mimeFirstFilter(MimeDatabase
);
3921 filter
= mimeNextFilter(MimeDatabase
))
3922 if (filter
->dst
== p
->filetype
|| filter
->dst
== p
->prefiltertype
)
3925 * Delete the current filter...
3928 mimeDeleteFilter(MimeDatabase
, filter
);
3931 cupsdSetPrinterReasons(p
, "-cups-insecure-filter-warning"
3932 ",cups-missing-filter-warning");
3937 * 'delete_string_array()' - Delete an array of CUPS strings.
3941 delete_string_array(cups_array_t
**a
) /* I - Array */
3943 char *ptr
; /* Current string */
3946 for (ptr
= (char *)cupsArrayFirst(*a
);
3948 ptr
= (char *)cupsArrayNext(*a
))
3951 cupsArrayDelete(*a
);
3957 * 'load_ppd()' - Load a cached PPD file, updating the cache as needed.
3961 load_ppd(cupsd_printer_t
*p
) /* I - Printer */
3963 int i
, j
, k
; /* Looping vars */
3964 cups_file_t
*cache
; /* IPP cache file */
3965 char cache_name
[1024]; /* IPP cache filename */
3966 struct stat cache_info
; /* IPP cache file info */
3967 char pwg_name
[1024]; /* PWG cache filename */
3968 struct stat pwg_info
; /* PWG cache file info */
3969 ppd_file_t
*ppd
; /* PPD file */
3970 char ppd_name
[1024]; /* PPD filename */
3971 struct stat ppd_info
; /* PPD file info */
3972 int num_media
; /* Number of media options */
3973 ppd_size_t
*size
; /* Current PPD size */
3974 ppd_option_t
*duplex
, /* Duplex option */
3975 *output_bin
, /* OutputBin option */
3976 *output_mode
, /* OutputMode option */
3977 *resolution
; /* (Set|JCL|)Resolution option */
3978 ppd_choice_t
*choice
, /* Current PPD choice */
3979 *input_slot
, /* Current input slot */
3980 *media_type
; /* Current media type */
3981 ppd_attr_t
*ppd_attr
; /* PPD attribute */
3982 int xdpi
, /* Horizontal resolution */
3983 ydpi
; /* Vertical resolution */
3984 const char *resptr
; /* Pointer into resolution keyword */
3985 _pwg_size_t
*pwgsize
; /* Current PWG size */
3986 _pwg_map_t
*pwgsource
, /* Current PWG source */
3987 *pwgtype
; /* Current PWG type */
3988 ipp_attribute_t
*attr
; /* Attribute data */
3989 ipp_value_t
*val
; /* Attribute value */
3990 int num_finishings
, /* Number of finishings */
3991 finishings
[5]; /* finishings-supported values */
3992 int num_qualities
, /* Number of print-quality values */
3993 qualities
[3]; /* print-quality values */
3994 int num_margins
, /* Number of media-*-margin-supported values */
3995 margins
[16]; /* media-*-margin-supported values */
3996 static const char * const sides
[3] = /* sides-supported values */
3999 "two-sided-long-edge",
4000 "two-sided-short-edge"
4002 static const char * const standard_commands
[] =
4003 { /* Standard CUPS commands */
4011 * Check to see if the cache is up-to-date...
4014 snprintf(cache_name
, sizeof(cache_name
), "%s/%s.ipp4", CacheDir
, p
->name
);
4015 if (stat(cache_name
, &cache_info
))
4016 cache_info
.st_mtime
= 0;
4018 snprintf(pwg_name
, sizeof(pwg_name
), "%s/%s.pwg3", CacheDir
, p
->name
);
4019 if (stat(pwg_name
, &pwg_info
))
4020 pwg_info
.st_mtime
= 0;
4022 snprintf(ppd_name
, sizeof(ppd_name
), "%s/ppd/%s.ppd", ServerRoot
, p
->name
);
4023 if (stat(ppd_name
, &ppd_info
))
4024 ppd_info
.st_mtime
= 1;
4026 ippDelete(p
->ppd_attrs
);
4027 p
->ppd_attrs
= ippNew();
4029 _pwgDestroy(p
->pwg
);
4032 if (pwg_info
.st_mtime
>= ppd_info
.st_mtime
)
4033 p
->pwg
= _pwgCreateWithFile(pwg_name
);
4035 if (cache_info
.st_mtime
>= ppd_info
.st_mtime
&& p
->pwg
&&
4036 (cache
= cupsFileOpen(cache_name
, "r")) != NULL
)
4039 * Load cached information and return...
4042 cupsdLogMessage(CUPSD_LOG_DEBUG
, "load_ppd: Loading %s...", cache_name
);
4044 if (ippReadIO(cache
, (ipp_iocb_t
)cupsFileRead
, 1, NULL
,
4045 p
->ppd_attrs
) == IPP_DATA
)
4047 cupsFileClose(cache
);
4051 cupsFileClose(cache
);
4055 * Reload PPD attributes from disk...
4058 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
4060 _pwgDestroy(p
->pwg
);
4063 cupsdLogMessage(CUPSD_LOG_DEBUG
, "load_ppd: Loading %s...", ppd_name
);
4065 delete_string_array(&(p
->filters
));
4066 delete_string_array(&(p
->pre_filters
));
4068 p
->type
&= ~CUPS_PRINTER_OPTIONS
;
4069 p
->type
|= CUPS_PRINTER_BW
;
4071 finishings
[0] = IPP_FINISHINGS_NONE
;
4074 if ((ppd
= ppdOpenFile(ppd_name
)) != NULL
)
4077 * Add make/model and other various attributes...
4080 p
->pwg
= _pwgCreateWithPPD(ppd
);
4082 ppdMarkDefaults(ppd
);
4084 if (ppd
->color_device
)
4085 p
->type
|= CUPS_PRINTER_COLOR
;
4086 if (ppd
->variable_sizes
)
4087 p
->type
|= CUPS_PRINTER_VARIABLE
;
4088 if (!ppd
->manual_copies
)
4089 p
->type
|= CUPS_PRINTER_COPIES
;
4090 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsFax", NULL
)) != NULL
)
4091 if (ppd_attr
->value
&& !strcasecmp(ppd_attr
->value
, "true"))
4092 p
->type
|= CUPS_PRINTER_FAX
;
4094 ippAddBoolean(p
->ppd_attrs
, IPP_TAG_PRINTER
, "color-supported",
4096 if (ppd
->throughput
)
4098 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4099 "pages-per-minute", ppd
->throughput
);
4100 if (ppd
->color_device
)
4101 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4102 "pages-per-minute-color", ppd
->throughput
);
4107 if ((output_mode
= ppdFindOption(ppd
, "OutputMode")) != NULL
)
4109 if (ppdFindChoice(output_mode
, "draft") ||
4110 ppdFindChoice(output_mode
, "fast"))
4111 qualities
[num_qualities
++] = IPP_QUALITY_DRAFT
;
4112 if (ppdFindChoice(output_mode
, "normal") ||
4113 ppdFindChoice(output_mode
, "good"))
4114 qualities
[num_qualities
++] = IPP_QUALITY_NORMAL
;
4115 if (ppdFindChoice(output_mode
, "best") ||
4116 ppdFindChoice(output_mode
, "high"))
4117 qualities
[num_qualities
++] = IPP_QUALITY_HIGH
;
4119 else if ((ppd_attr
= ppdFindAttr(ppd
, "APPrinterPreset", NULL
)) != NULL
)
4123 if (strstr(ppd_attr
->spec
, "draft") ||
4124 strstr(ppd_attr
->spec
, "Draft"))
4126 qualities
[num_qualities
++] = IPP_QUALITY_DRAFT
;
4130 while ((ppd_attr
= ppdFindNextAttr(ppd
, "APPrinterPreset",
4133 qualities
[num_qualities
++] = IPP_QUALITY_NORMAL
;
4134 qualities
[num_qualities
++] = IPP_QUALITY_HIGH
;
4137 if (num_qualities
== 0)
4138 qualities
[num_qualities
++] = IPP_QUALITY_NORMAL
;
4140 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
4141 "print-quality-supported", num_qualities
, qualities
);
4146 * The NickName can be localized in the character set specified
4147 * by the LanugageEncoding attribute. However, ppdOpen2() has
4148 * already converted the ppd->nickname member to UTF-8 for us
4149 * (the original attribute value is available separately)
4152 cupsdSetString(&p
->make_model
, ppd
->nickname
);
4154 else if (ppd
->modelname
)
4157 * Model name can only contain specific characters...
4160 cupsdSetString(&p
->make_model
, ppd
->modelname
);
4163 cupsdSetString(&p
->make_model
, "Bad PPD File");
4165 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
4166 "printer-make-and-model", NULL
, p
->make_model
);
4169 * Add media options from the PPD file...
4172 if (ppd
->num_sizes
== 0 || !p
->pwg
)
4174 if (!ppdFindAttr(ppd
, "APScannerOnly", NULL
))
4175 cupsdLogMessage(CUPSD_LOG_CRIT
,
4176 "The PPD file for printer %s contains no media "
4177 "options and is therefore invalid!", p
->name
);
4179 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4180 "media-default", NULL
, "unknown");
4181 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4182 "media-supported", NULL
, "unknown");
4190 if ((size
= ppdPageSize(ppd
, NULL
)) != NULL
)
4191 pwgsize
= _pwgGetSize(p
->pwg
, size
->name
);
4195 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4196 "media-default", NULL
,
4197 pwgsize
? pwgsize
->map
.pwg
: "unknown");
4205 ipp_t
*col
; /* Collection value */
4207 input_slot
= ppdFindMarkedChoice(ppd
, "InputSlot");
4208 media_type
= ppdFindMarkedChoice(ppd
, "MediaType");
4209 col
= new_media_col(pwgsize
,
4211 _pwgGetSource(p
->pwg
,
4212 input_slot
->choice
) :
4216 media_type
->choice
) :
4219 ippAddCollection(p
->ppd_attrs
, IPP_TAG_PRINTER
, "media-col-default",
4228 num_media
= p
->pwg
->num_sizes
;
4229 if (p
->pwg
->custom_min_keyword
)
4232 if ((attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4233 "media-supported", num_media
, NULL
,
4238 for (i
= p
->pwg
->num_sizes
, pwgsize
= p
->pwg
->sizes
;
4240 i
--, pwgsize
++, val
++)
4241 val
->string
.text
= _cupsStrRetain(pwgsize
->map
.pwg
);
4243 if (p
->pwg
->custom_min_keyword
)
4245 val
->string
.text
= _cupsStrRetain(p
->pwg
->custom_min_keyword
);
4247 val
->string
.text
= _cupsStrRetain(p
->pwg
->custom_max_keyword
);
4252 * media-source-supported
4255 if (p
->pwg
->num_sources
> 0 &&
4256 (attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4257 "media-source-supported", p
->pwg
->num_sources
,
4258 NULL
, NULL
)) != NULL
)
4260 for (i
= p
->pwg
->num_sources
, pwgsource
= p
->pwg
->sources
,
4263 i
--, pwgsource
++, val
++)
4264 val
->string
.text
= _cupsStrRetain(pwgsource
->pwg
);
4268 * media-type-supported
4271 if (p
->pwg
->num_types
> 0 &&
4272 (attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4273 "media-type-supported", p
->pwg
->num_types
,
4274 NULL
, NULL
)) != NULL
)
4276 for (i
= p
->pwg
->num_types
, pwgtype
= p
->pwg
->types
,
4279 i
--, pwgtype
++, val
++)
4280 val
->string
.text
= _cupsStrRetain(pwgtype
->pwg
);
4284 * media-*-margin-supported
4287 for (i
= p
->pwg
->num_sizes
, pwgsize
= p
->pwg
->sizes
, num_margins
= 0;
4288 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4291 for (j
= 0; j
< num_margins
; j
++)
4292 if (pwgsize
->bottom
== margins
[j
])
4295 if (j
>= num_margins
)
4297 margins
[num_margins
] = pwgsize
->bottom
;
4302 if (num_margins
> 0)
4303 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4304 "media-bottom-margin-supported", num_margins
, margins
);
4306 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4307 "media-bottom-margin-supported", 0);
4309 for (i
= p
->pwg
->num_sizes
, pwgsize
= p
->pwg
->sizes
, num_margins
= 0;
4310 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4313 for (j
= 0; j
< num_margins
; j
++)
4314 if (pwgsize
->left
== margins
[j
])
4317 if (j
>= num_margins
)
4319 margins
[num_margins
] = pwgsize
->left
;
4324 if (num_margins
> 0)
4325 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4326 "media-left-margin-supported", num_margins
, margins
);
4328 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4329 "media-left-margin-supported", 0);
4331 for (i
= p
->pwg
->num_sizes
, pwgsize
= p
->pwg
->sizes
, num_margins
= 0;
4332 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4335 for (j
= 0; j
< num_margins
; j
++)
4336 if (pwgsize
->right
== margins
[j
])
4339 if (j
>= num_margins
)
4341 margins
[num_margins
] = pwgsize
->right
;
4346 if (num_margins
> 0)
4347 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4348 "media-right-margin-supported", num_margins
, margins
);
4350 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4351 "media-right-margin-supported", 0);
4353 for (i
= p
->pwg
->num_sizes
, pwgsize
= p
->pwg
->sizes
, num_margins
= 0;
4354 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4357 for (j
= 0; j
< num_margins
; j
++)
4358 if (pwgsize
->top
== margins
[j
])
4361 if (j
>= num_margins
)
4363 margins
[num_margins
] = pwgsize
->top
;
4368 if (num_margins
> 0)
4369 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4370 "media-top-margin-supported", num_margins
, margins
);
4372 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4373 "media-top-margin-supported", 0);
4376 * media-col-database
4379 num_media
= p
->pwg
->num_sizes
;
4380 if (p
->pwg
->num_sources
)
4382 if (p
->pwg
->num_types
> 0)
4383 num_media
+= p
->pwg
->num_sizes
* p
->pwg
->num_sources
*
4386 num_media
+= p
->pwg
->num_sizes
* p
->pwg
->num_sources
;
4388 else if (p
->pwg
->num_types
)
4389 num_media
+= p
->pwg
->num_sizes
* p
->pwg
->num_types
;
4391 if ((attr
= ippAddCollections(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4392 "media-col-database", num_media
,
4395 for (i
= p
->pwg
->num_sizes
, pwgsize
= p
->pwg
->sizes
, val
= attr
->values
;
4400 * Start by adding the page size without source or type...
4403 ppdMarkOption(ppd
, "PageSize", pwgsize
->map
.ppd
);
4405 val
->collection
= new_media_col(pwgsize
, NULL
, NULL
);
4409 * Then add the specific, supported combinations of size, source, and
4413 if (p
->pwg
->num_sources
> 0)
4415 for (j
= p
->pwg
->num_sources
, pwgsource
= p
->pwg
->sources
;
4419 ppdMarkOption(ppd
, "InputSlot", pwgsource
->ppd
);
4421 if (p
->pwg
->num_types
> 0)
4423 for (k
= p
->pwg
->num_types
, pwgtype
= p
->pwg
->types
;
4427 if (!ppdMarkOption(ppd
, "MediaType", pwgtype
->ppd
))
4429 val
->collection
= new_media_col(pwgsize
, pwgsource
->pwg
,
4435 else if (!ppdConflicts(ppd
))
4437 val
->collection
= new_media_col(pwgsize
, pwgsource
->pwg
, NULL
);
4442 else if (p
->pwg
->num_types
> 0)
4444 for (j
= p
->pwg
->num_types
, pwgtype
= p
->pwg
->types
;
4448 if (!ppdMarkOption(ppd
, "MediaType", pwgtype
->ppd
))
4450 val
->collection
= new_media_col(pwgsize
, NULL
, pwgtype
->pwg
);
4458 * Update the number of media-col-database values...
4461 attr
->num_values
= val
- attr
->values
;
4469 if (p
->pwg
&& p
->pwg
->num_bins
> 0)
4471 attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4472 "output-bin-supported", p
->pwg
->num_bins
,
4477 for (i
= 0, val
= attr
->values
;
4478 i
< p
->pwg
->num_bins
;
4480 val
->string
.text
= _cupsStrAlloc(p
->pwg
->bins
[i
].pwg
);
4483 if ((output_bin
= ppdFindOption(ppd
, "OutputBin")) != NULL
)
4485 for (i
= 0; i
< p
->pwg
->num_bins
; i
++)
4486 if (!strcmp(p
->pwg
->bins
[i
].ppd
, output_bin
->defchoice
))
4489 if (i
>= p
->pwg
->num_bins
)
4492 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4493 "output-bin-default", NULL
, p
->pwg
->bins
[i
].pwg
);
4496 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4497 "output-bin-default", NULL
, p
->pwg
->bins
[0].pwg
);
4499 else if (((ppd_attr
= ppdFindAttr(ppd
, "DefaultOutputOrder",
4501 !strcasecmp(ppd_attr
->value
, "Reverse")) ||
4502 (!ppd_attr
&& ppd
->manufacturer
&& /* "Compatibility heuristic" */
4503 (!strcasecmp(ppd
->manufacturer
, "epson") ||
4504 !strcasecmp(ppd
->manufacturer
, "lexmark"))))
4507 * Report that this printer has a single output bin that leaves pages face
4511 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4512 "output-bin-supported", NULL
, "face-up");
4513 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4514 "output-bin-default", NULL
, "face-up");
4518 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4519 "output-bin-supported", NULL
, "face-down");
4520 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4521 "output-bin-default", NULL
, "face-down");
4528 if (ppd
->color_device
)
4530 static const char * const output_modes
[] =
4536 ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4537 "output-mode-supported", 2, NULL
, output_modes
);
4538 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4539 "output-mode-default", NULL
, "color");
4543 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4544 "output-mode-supported", NULL
, "monochrome");
4545 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4546 "output-mode-default", NULL
, "monochrome");
4550 * Printer resolutions...
4553 if ((resolution
= ppdFindOption(ppd
, "Resolution")) == NULL
)
4554 if ((resolution
= ppdFindOption(ppd
, "JCLResolution")) == NULL
)
4555 if ((resolution
= ppdFindOption(ppd
, "SetResolution")) == NULL
)
4556 resolution
= ppdFindOption(ppd
, "CNRes_PGP");
4561 * Report all supported resolutions...
4564 attr
= ippAddResolutions(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4565 "printer-resolution-supported",
4566 resolution
->num_choices
, IPP_RES_PER_INCH
,
4569 for (i
= 0, choice
= resolution
->choices
;
4570 i
< resolution
->num_choices
;
4573 xdpi
= ydpi
= (int)strtol(choice
->choice
, (char **)&resptr
, 10);
4574 if (resptr
> choice
->choice
&& xdpi
> 0 && *resptr
== 'x')
4575 ydpi
= (int)strtol(resptr
+ 1, (char **)&resptr
, 10);
4577 if (xdpi
<= 0 || ydpi
<= 0)
4579 cupsdLogMessage(CUPSD_LOG_WARN
,
4580 "Bad resolution \"%s\" for printer %s.",
4581 choice
->choice
, p
->name
);
4585 attr
->values
[i
].resolution
.xres
= xdpi
;
4586 attr
->values
[i
].resolution
.yres
= ydpi
;
4587 attr
->values
[i
].resolution
.units
= IPP_RES_PER_INCH
;
4590 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4591 "printer-resolution-default", IPP_RES_PER_INCH
,
4595 else if ((ppd_attr
= ppdFindAttr(ppd
, "DefaultResolution", NULL
)) != NULL
&&
4599 * Just the DefaultResolution to report...
4602 xdpi
= ydpi
= (int)strtol(ppd_attr
->value
, (char **)&resptr
, 10);
4603 if (resptr
> ppd_attr
->value
&& xdpi
> 0)
4606 ydpi
= (int)strtol(resptr
+ 1, (char **)&resptr
, 10);
4611 if (xdpi
<= 0 || ydpi
<= 0)
4613 cupsdLogMessage(CUPSD_LOG_WARN
,
4614 "Bad default resolution \"%s\" for printer %s.",
4615 ppd_attr
->value
, p
->name
);
4619 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4620 "printer-resolution-default", IPP_RES_PER_INCH
,
4622 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4623 "printer-resolution-supported", IPP_RES_PER_INCH
,
4629 * No resolutions in PPD - make one up...
4632 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4633 "printer-resolution-default", IPP_RES_PER_INCH
,
4635 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4636 "printer-resolution-supported", IPP_RES_PER_INCH
,
4644 ppdMarkDefaults(ppd
);
4646 if ((duplex
= ppdFindOption(ppd
, "Duplex")) == NULL
)
4647 if ((duplex
= ppdFindOption(ppd
, "EFDuplex")) == NULL
)
4648 if ((duplex
= ppdFindOption(ppd
, "EFDuplexing")) == NULL
)
4649 if ((duplex
= ppdFindOption(ppd
, "KD03Duplex")) == NULL
)
4650 duplex
= ppdFindOption(ppd
, "JCLDuplex");
4652 if (duplex
&& duplex
->num_choices
> 1 &&
4653 !ppdInstallableConflict(ppd
, duplex
->keyword
, "DuplexTumble"))
4655 p
->type
|= CUPS_PRINTER_DUPLEX
;
4657 ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4658 "sides-supported", 3, NULL
, sides
);
4660 if (!strcasecmp(duplex
->defchoice
, "DuplexTumble"))
4661 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4662 "sides-default", NULL
, "two-sided-short-edge");
4663 else if (!strcasecmp(duplex
->defchoice
, "DuplexNoTumble"))
4664 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4665 "sides-default", NULL
, "two-sided-long-edge");
4667 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4668 "sides-default", NULL
, "one-sided");
4672 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4673 "sides-supported", NULL
, "one-sided");
4674 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4675 "sides-default", NULL
, "one-sided");
4678 if (ppdFindOption(ppd
, "Collate") != NULL
)
4679 p
->type
|= CUPS_PRINTER_COLLATE
;
4681 if (ppdFindOption(ppd
, "StapleLocation") != NULL
)
4683 p
->type
|= CUPS_PRINTER_STAPLE
;
4684 finishings
[num_finishings
++] = IPP_FINISHINGS_STAPLE
;
4687 if (ppdFindOption(ppd
, "BindEdge") != NULL
)
4689 p
->type
|= CUPS_PRINTER_BIND
;
4690 finishings
[num_finishings
++] = IPP_FINISHINGS_BIND
;
4693 for (i
= 0; i
< ppd
->num_sizes
; i
++)
4694 if (ppd
->sizes
[i
].length
> 1728)
4695 p
->type
|= CUPS_PRINTER_LARGE
;
4696 else if (ppd
->sizes
[i
].length
> 1008)
4697 p
->type
|= CUPS_PRINTER_MEDIUM
;
4699 p
->type
|= CUPS_PRINTER_SMALL
;
4701 if ((ppd_attr
= ppdFindAttr(ppd
, "APICADriver", NULL
)) != NULL
&&
4702 ppd_attr
->value
&& !strcasecmp(ppd_attr
->value
, "true"))
4704 if ((ppd_attr
= ppdFindAttr(ppd
, "APScannerOnly", NULL
)) != NULL
&&
4705 ppd_attr
->value
&& !strcasecmp(ppd_attr
->value
, "true"))
4706 p
->type
|= CUPS_PRINTER_SCANNER
;
4708 p
->type
|= CUPS_PRINTER_MFP
;
4712 * Add a filter from application/vnd.cups-raw to printer/name to
4713 * handle "raw" printing by users.
4716 add_string_array(&(p
->filters
), "application/vnd.cups-raw 0 -");
4719 * Add any pre-filters in the PPD file...
4722 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsPreFilter", NULL
)) != NULL
)
4724 for (; ppd_attr
; ppd_attr
= ppdFindNextAttr(ppd
, "cupsPreFilter", NULL
))
4725 if (ppd_attr
->value
)
4726 add_string_array(&(p
->pre_filters
), ppd_attr
->value
);
4730 * Add any filters in the PPD file...
4733 DEBUG_printf(("ppd->num_filters = %d\n", ppd
->num_filters
));
4734 for (i
= 0; i
< ppd
->num_filters
; i
++)
4736 DEBUG_printf(("ppd->filters[%d] = \"%s\"\n", i
, ppd
->filters
[i
]));
4737 add_string_array(&(p
->filters
), ppd
->filters
[i
]);
4739 if (!strncasecmp(ppd
->filters
[i
], "application/vnd.cups-command", 28) &&
4740 isspace(ppd
->filters
[i
][28] & 255))
4741 p
->type
|= CUPS_PRINTER_COMMANDS
;
4744 if (ppd
->num_filters
== 0)
4747 * If there are no filters, add PostScript printing filters.
4750 add_string_array(&(p
->filters
),
4751 "application/vnd.cups-command 0 commandtops");
4752 add_string_array(&(p
->filters
),
4753 "application/vnd.cups-postscript 0 -");
4755 p
->type
|= CUPS_PRINTER_COMMANDS
;
4757 else if (!(p
->type
& CUPS_PRINTER_COMMANDS
))
4760 * See if this is a PostScript device without a command filter...
4763 for (i
= 0; i
< ppd
->num_filters
; i
++)
4764 if (!strncasecmp(ppd
->filters
[i
],
4765 "application/vnd.cups-postscript", 31) &&
4766 isspace(ppd
->filters
[i
][31] & 255))
4769 if (i
< ppd
->num_filters
)
4772 * Add the generic PostScript command filter...
4775 add_string_array(&(p
->filters
),
4776 "application/vnd.cups-command 0 commandtops");
4777 p
->type
|= CUPS_PRINTER_COMMANDS
;
4781 if (p
->type
& CUPS_PRINTER_COMMANDS
)
4783 char *commands
, /* Copy of commands */
4784 *start
, /* Start of name */
4785 *end
; /* End of name */
4786 int count
; /* Number of commands */
4789 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsCommands", NULL
)) != NULL
&&
4790 ppd_attr
->value
&& ppd_attr
->value
[0])
4792 for (count
= 0, start
= ppd_attr
->value
; *start
; count
++)
4794 while (isspace(*start
& 255))
4800 while (*start
&& !isspace(*start
& 255))
4810 * Make a copy of the commands string and count how many ...
4813 attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4814 "printer-commands", count
, NULL
, NULL
);
4816 commands
= strdup(ppd_attr
->value
);
4818 for (count
= 0, start
= commands
; *start
; count
++)
4820 while (isspace(*start
& 255))
4827 while (*end
&& !isspace(*end
& 255))
4833 attr
->values
[count
].string
.text
= _cupsStrAlloc(start
);
4843 * Add the standard list of commands...
4846 ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4848 (int)(sizeof(standard_commands
) /
4849 sizeof(standard_commands
[0])), NULL
,
4856 * No commands supported...
4859 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4860 "printer-commands", NULL
, "none");
4864 * Show current and available port monitors for this printer...
4867 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
, "port-monitor",
4868 NULL
, p
->port_monitor
? p
->port_monitor
: "none");
4870 for (i
= 1, ppd_attr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
4872 i
++, ppd_attr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
));
4876 if (strstr(ppd
->protocols
, "TBCP"))
4878 else if (strstr(ppd
->protocols
, "BCP"))
4882 attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
4883 "port-monitor-supported", i
, NULL
, NULL
);
4885 attr
->values
[0].string
.text
= _cupsStrAlloc("none");
4887 for (i
= 1, ppd_attr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
4889 i
++, ppd_attr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
))
4890 attr
->values
[i
].string
.text
= _cupsStrAlloc(ppd_attr
->value
);
4894 if (strstr(ppd
->protocols
, "TBCP"))
4895 attr
->values
[i
].string
.text
= _cupsStrAlloc("tbcp");
4896 else if (strstr(ppd
->protocols
, "BCP"))
4897 attr
->values
[i
].string
.text
= _cupsStrAlloc("bcp");
4901 cupsdSetString(&p
->product
, ppd
->product
);
4902 #endif /* HAVE_DNSSD */
4904 if (ppdFindAttr(ppd
, "APRemoteQueueID", NULL
))
4905 p
->type
|= CUPS_PRINTER_REMOTE
;
4907 #ifdef HAVE_APPLICATIONSERVICES_H
4909 * Convert the file referenced in APPrinterIconPath to a 128x128 PNG
4910 * and save it as cacheDir/printername.png
4913 if ((ppd_attr
= ppdFindAttr(ppd
, "APPrinterIconPath", NULL
)) != NULL
&&
4916 CGImageRef imageRef
= NULL
;/* Current icon image */
4917 CGImageRef biggestIconRef
= NULL
;
4918 /* Biggest icon image */
4919 CGImageRef closestTo128IconRef
= NULL
;
4920 /* Icon image closest to and >= 128 */
4921 CGImageSourceRef sourceRef
; /* The file's image source */
4922 char outPath
[HTTP_MAX_URI
];
4923 /* The path to the PNG file */
4924 CFURLRef outUrl
; /* The URL made from the outPath */
4925 CFURLRef icnsFileUrl
; /* The URL of the original ICNS icon file */
4926 CGImageDestinationRef destRef
; /* The image destination to write */
4927 size_t bytesPerRow
; /* The bytes per row used for resizing */
4928 CGContextRef context
; /* The CG context used for resizing */
4930 snprintf(outPath
, sizeof(outPath
), "%s/%s.png", CacheDir
, p
->name
);
4931 outUrl
= CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault
,
4935 icnsFileUrl
= CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault
,
4936 (UInt8
*)ppd_attr
->value
,
4937 strlen(ppd_attr
->value
),
4939 if (outUrl
&& icnsFileUrl
)
4941 sourceRef
= CGImageSourceCreateWithURL(icnsFileUrl
, NULL
);
4944 for (i
= 0; i
< CGImageSourceGetCount(sourceRef
); i
++)
4946 imageRef
= CGImageSourceCreateImageAtIndex(sourceRef
, i
, NULL
);
4948 CGImageGetWidth(imageRef
) == CGImageGetHeight(imageRef
))
4951 * Loop through remembering the icon closest to 128 but >= 128
4952 * and then remember the largest icon.
4955 if (CGImageGetWidth(imageRef
) >= 128 &&
4956 (!closestTo128IconRef
||
4957 CGImageGetWidth(imageRef
) <
4958 CGImageGetWidth(closestTo128IconRef
)))
4960 CGImageRelease(closestTo128IconRef
);
4961 CGImageRetain(imageRef
);
4962 closestTo128IconRef
= imageRef
;
4965 if (!biggestIconRef
||
4966 CGImageGetWidth(imageRef
) > CGImageGetWidth(biggestIconRef
))
4968 CGImageRelease(biggestIconRef
);
4969 CGImageRetain(imageRef
);
4970 biggestIconRef
= imageRef
;
4973 CGImageRelease(imageRef
);
4980 * If biggestIconRef is NULL, we found no icons. Otherwise we first
4981 * want the closest to 128, but if none are larger than 128, we want
4982 * the largest icon available.
4985 imageRef
= closestTo128IconRef
? closestTo128IconRef
:
4987 CGImageRetain(imageRef
);
4988 CGImageRelease(biggestIconRef
);
4989 CGImageRelease(closestTo128IconRef
);
4990 destRef
= CGImageDestinationCreateWithURL(outUrl
, kUTTypePNG
, 1,
4994 if (CGImageGetWidth(imageRef
) != 128)
4996 bytesPerRow
= CGImageGetBytesPerRow(imageRef
) /
4997 CGImageGetWidth(imageRef
) * 128;
4998 context
= CGBitmapContextCreate(NULL
, 128, 128,
4999 CGImageGetBitsPerComponent(imageRef
),
5001 CGImageGetColorSpace(imageRef
),
5002 kCGImageAlphaPremultipliedFirst
);
5005 CGContextDrawImage(context
, CGRectMake(0, 0, 128, 128),
5007 CGImageRelease(imageRef
);
5008 imageRef
= CGBitmapContextCreateImage(context
);
5009 CGContextRelease(context
);
5013 CGImageDestinationAddImage(destRef
, imageRef
, NULL
);
5014 CGImageDestinationFinalize(destRef
);
5018 CGImageRelease(imageRef
);
5021 CFRelease(sourceRef
);
5022 CFRelease(icnsFileUrl
);
5028 #endif /* HAVE_APPLICATIONSERVICES_H */
5031 * Close the PPD and set the type...
5036 else if (!access(ppd_name
, 0))
5038 int pline
; /* PPD line number */
5039 ppd_status_t pstatus
; /* PPD load status */
5042 pstatus
= ppdLastError(&pline
);
5044 cupsdLogMessage(CUPSD_LOG_ERROR
, "PPD file for %s cannot be loaded!",
5047 if (pstatus
<= PPD_ALLOC_ERROR
)
5048 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s", strerror(errno
));
5050 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s on line %d.",
5051 ppdErrorString(pstatus
), pline
);
5053 cupsdLogMessage(CUPSD_LOG_INFO
,
5054 "Hint: Run \"cupstestppd %s\" and fix any errors.",
5058 * Add a filter from application/vnd.cups-raw to printer/name to
5059 * handle "raw" printing by users.
5062 add_string_array(&(p
->filters
), "application/vnd.cups-raw 0 -");
5065 * Add a PostScript filter, since this is still possibly PS printer.
5068 add_string_array(&(p
->filters
), "application/vnd.cups-postscript 0 -");
5073 * If we have an interface script, add a filter entry for it...
5076 char interface
[1024]; /* Interface script */
5079 snprintf(interface
, sizeof(interface
), "%s/interfaces/%s", ServerRoot
,
5081 if (!access(interface
, X_OK
))
5084 * Yes, we have a System V style interface script; use it!
5087 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
5088 "printer-make-and-model", NULL
,
5089 "Local System V Printer");
5091 snprintf(interface
, sizeof(interface
), "*/* 0 %s/interfaces/%s",
5092 ServerRoot
, p
->name
);
5093 add_string_array(&(p
->filters
), interface
);
5095 else if (!strncmp(p
->device_uri
, "ipp://", 6) &&
5096 (strstr(p
->device_uri
, "/printers/") != NULL
||
5097 strstr(p
->device_uri
, "/classes/") != NULL
||
5098 (strstr(p
->device_uri
, "._ipp.") != NULL
&&
5099 !strcmp(p
->device_uri
+ strlen(p
->device_uri
) - 5,
5103 * Tell the client this is really a hard-wired remote printer.
5106 p
->type
|= CUPS_PRINTER_REMOTE
;
5109 * Point the printer-uri-supported attribute to the
5113 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
5114 "printer-uri-supported", NULL
, p
->device_uri
);
5117 * Then set the make-and-model accordingly...
5120 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
5121 "printer-make-and-model", NULL
, "Remote Printer");
5124 * Print all files directly...
5133 * Otherwise we have neither - treat this as a "dumb" printer
5134 * with no PPD file...
5137 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
5138 "printer-make-and-model", NULL
, "Local Raw Printer");
5144 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
5145 "finishings-supported", num_finishings
, finishings
);
5146 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
5147 "finishings-default", IPP_FINISHINGS_NONE
);
5149 if (ppd
&& (cache
= cupsFileOpen(cache_name
, "w9")) != NULL
)
5152 * Save cached PPD attributes to disk...
5155 cupsdLogMessage(CUPSD_LOG_DEBUG
, "load_ppd: Saving %s...", cache_name
);
5157 p
->ppd_attrs
->state
= IPP_IDLE
;
5159 if (ippWriteIO(cache
, (ipp_iocb_t
)cupsFileWrite
, 1, NULL
,
5160 p
->ppd_attrs
) != IPP_DATA
)
5162 cupsdLogMessage(CUPSD_LOG_ERROR
,
5163 "Unable to save PPD cache file \"%s\" - %s", cache_name
,
5168 cupsFileClose(cache
);
5170 _pwgWriteFile(p
->pwg
, pwg_name
);
5175 * Remove cache files...
5178 if (cache_info
.st_mtime
)
5181 if (pwg_info
.st_mtime
)
5188 * 'new_media_col()' - Create a media-col collection value.
5191 static ipp_t
* /* O - Collection value */
5192 new_media_col(_pwg_size_t
*size
, /* I - media-size/margin values */
5193 const char *source
, /* I - media-source value */
5194 const char *type
) /* I - media-type value */
5196 ipp_t
*media_col
, /* Collection value */
5197 *media_size
; /* media-size value */
5200 media_col
= ippNew();
5202 media_size
= ippNew();
5203 ippAddInteger(media_size
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5204 "x-dimension", size
->width
);
5205 ippAddInteger(media_size
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5206 "y-dimension", size
->length
);
5207 ippAddCollection(media_col
, IPP_TAG_PRINTER
, "media-size", media_size
);
5208 ippDelete(media_size
);
5210 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5211 "media-bottom-margin", size
->bottom
);
5212 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5213 "media-left-margin", size
->left
);
5214 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5215 "media-right-margin", size
->right
);
5216 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5217 "media-top-margin", size
->top
);
5220 ippAddString(media_col
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
, "media-source",
5224 ippAddString(media_col
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
, "media-type",
5233 * 'write_irix_config()' - Update the config files used by the IRIX
5238 write_irix_config(cupsd_printer_t
*p
) /* I - Printer to update */
5240 char filename
[1024]; /* Interface script filename */
5241 cups_file_t
*fp
; /* Interface script file */
5242 ipp_attribute_t
*attr
; /* Attribute data */
5246 * Add dummy interface and GUI scripts to fool SGI's "challenged" printing
5247 * tools. First the interface script that tells the tools what kind of
5248 * printer we have...
5251 snprintf(filename
, sizeof(filename
), "/var/spool/lp/interface/%s", p
->name
);
5253 if (p
->type
& CUPS_PRINTER_CLASS
)
5255 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
5257 cupsFilePuts(fp
, "#!/bin/sh\n");
5259 if ((attr
= ippFindAttribute(p
->attrs
, "printer-make-and-model",
5260 IPP_TAG_TEXT
)) != NULL
)
5261 cupsFilePrintf(fp
, "NAME=\"%s\"\n", attr
->values
[0].string
.text
);
5262 else if (p
->type
& CUPS_PRINTER_CLASS
)
5263 cupsFilePuts(fp
, "NAME=\"Printer Class\"\n");
5265 cupsFilePuts(fp
, "NAME=\"Remote Destination\"\n");
5267 if (p
->type
& CUPS_PRINTER_COLOR
)
5268 cupsFilePuts(fp
, "TYPE=ColorPostScript\n");
5270 cupsFilePuts(fp
, "TYPE=MonoPostScript\n");
5272 cupsFilePrintf(fp
, "HOSTNAME=%s\n", ServerName
);
5273 cupsFilePrintf(fp
, "HOSTPRINTER=%s\n", p
->name
);
5277 chmod(filename
, 0755);
5278 chown(filename
, User
, Group
);
5282 * Then the member file that tells which device file the queue is connected
5283 * to... Networked printers use "/dev/null" in this file, so that's what
5284 * we use (the actual device URI can confuse some apps...)
5287 snprintf(filename
, sizeof(filename
), "/var/spool/lp/member/%s", p
->name
);
5289 if (p
->type
& CUPS_PRINTER_CLASS
)
5291 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
5293 cupsFilePuts(fp
, "/dev/null\n");
5297 chmod(filename
, 0644);
5298 chown(filename
, User
, Group
);
5302 * The gui_interface file is a script or program that launches a GUI
5303 * option panel for the printer, using options specified on the
5304 * command-line in the third argument. The option panel must send
5305 * any printing options to stdout on a single line when the user
5306 * accepts them, or nothing if the user cancels the dialog.
5308 * The default options panel program is /usr/bin/glpoptions, from
5309 * the ESP Print Pro software. You can select another using the
5310 * PrintcapGUI option.
5313 snprintf(filename
, sizeof(filename
), "/var/spool/lp/gui_interface/ELF/%s.gui", p
->name
);
5315 if (p
->type
& CUPS_PRINTER_CLASS
)
5317 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
5319 cupsFilePuts(fp
, "#!/bin/sh\n");
5320 cupsFilePrintf(fp
, "%s -d %s -o \"$3\"\n", PrintcapGUI
, p
->name
);
5324 chmod(filename
, 0755);
5325 chown(filename
, User
, Group
);
5329 * The POD config file is needed by the printstatus command to show
5330 * the printer location and device.
5333 snprintf(filename
, sizeof(filename
), "/var/spool/lp/pod/%s.config", p
->name
);
5335 if (p
->type
& CUPS_PRINTER_CLASS
)
5337 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
5339 cupsFilePrintf(fp
, "Printer Class | %s\n",
5340 (p
->type
& CUPS_PRINTER_COLOR
) ? "ColorPostScript" : "MonoPostScript");
5341 cupsFilePrintf(fp
, "Printer Model | %s\n", p
->make_model
? p
->make_model
: "");
5342 cupsFilePrintf(fp
, "Location Code | %s\n", p
->location
? p
->location
: "");
5343 cupsFilePrintf(fp
, "Physical Location | %s\n", p
->info
? p
->info
: "");
5344 cupsFilePrintf(fp
, "Port Path | %s\n", p
->device_uri
);
5345 cupsFilePrintf(fp
, "Config Path | /var/spool/lp/pod/%s.config\n", p
->name
);
5346 cupsFilePrintf(fp
, "Active Status Path | /var/spool/lp/pod/%s.status\n", p
->name
);
5347 cupsFilePuts(fp
, "Status Update Wait | 10 seconds\n");
5351 chmod(filename
, 0664);
5352 chown(filename
, User
, Group
);
5358 * 'write_irix_state()' - Update the status files used by IRIX printing
5363 write_irix_state(cupsd_printer_t
*p
) /* I - Printer to update */
5365 char filename
[1024]; /* Interface script filename */
5366 cups_file_t
*fp
; /* Interface script file */
5367 int tag
; /* Status tag value */
5373 * The POD status file is needed for the printstatus window to
5374 * provide the current status of the printer.
5377 snprintf(filename
, sizeof(filename
), "/var/spool/lp/pod/%s.status", p
->name
);
5379 if (p
->type
& CUPS_PRINTER_CLASS
)
5381 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
5383 cupsFilePrintf(fp
, "Operational Status | %s\n",
5384 (p
->state
== IPP_PRINTER_IDLE
) ? "Idle" :
5385 (p
->state
== IPP_PRINTER_PROCESSING
) ? "Busy" :
5387 cupsFilePrintf(fp
, "Information | 01 00 00 | %s\n", CUPS_SVERSION
);
5388 cupsFilePrintf(fp
, "Information | 02 00 00 | Device URI: %s\n",
5390 cupsFilePrintf(fp
, "Information | 03 00 00 | %s jobs\n",
5391 p
->accepting
? "Accepting" : "Not accepting");
5392 cupsFilePrintf(fp
, "Information | 04 00 00 | %s\n", p
->state_message
);
5396 chmod(filename
, 0664);
5397 chown(filename
, User
, Group
);
5401 * The activeicons file is needed to provide desktop icons for printers:
5403 * [ quoted from /usr/lib/print/tagit ]
5405 * --- Type of printer tags (base values)
5407 * Dumb=66048 # 0x10200
5408 * DumbColor=66080 # 0x10220
5409 * Raster=66112 # 0x10240
5410 * ColorRaster=66144 # 0x10260
5411 * Plotter=66176 # 0x10280
5412 * PostScript=66208 # 0x102A0
5413 * ColorPostScript=66240 # 0x102C0
5414 * MonoPostScript=66272 # 0x102E0
5416 * --- Printer state modifiers for local printers
5421 * Unknown=3 # 0x3 (Faulted due to unknown reason)
5423 * --- Printer state modifiers for network printers
5427 * NetFaulted=10 # 0xA
5428 * NetUnknown=11 # 0xB (Faulted due to unknown reason)
5431 snprintf(filename
, sizeof(filename
), "/var/spool/lp/activeicons/%s", p
->name
);
5433 if (p
->type
& CUPS_PRINTER_CLASS
)
5435 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
5437 if (p
->type
& CUPS_PRINTER_COLOR
)
5442 if (p
->type
& CUPS_PRINTER_REMOTE
)
5445 if (p
->state
== IPP_PRINTER_PROCESSING
)
5448 else if (p
->state
== IPP_PRINTER_STOPPED
)
5451 cupsFilePuts(fp
, "#!/bin/sh\n");
5452 cupsFilePrintf(fp
, "#Tag %d\n", tag
);
5456 chmod(filename
, 0755);
5457 chown(filename
, User
, Group
);
5462 * The default file is needed by the printers window to show
5463 * the default printer.
5466 snprintf(filename
, sizeof(filename
), "/var/spool/lp/default");
5468 if (DefaultPrinter
!= NULL
)
5470 if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
5472 cupsFilePrintf(fp
, "%s\n", DefaultPrinter
->name
);
5476 chmod(filename
, 0644);
5477 chown(filename
, User
, Group
);
5487 * 'write_xml_string()' - Write a string with XML escaping.
5491 write_xml_string(cups_file_t
*fp
, /* I - File to write to */
5492 const char *s
) /* I - String to write */
5494 const char *start
; /* Start of current sequence */
5500 for (start
= s
; *s
; s
++)
5505 cupsFileWrite(fp
, start
, s
- start
);
5507 cupsFilePuts(fp
, "&");
5513 cupsFileWrite(fp
, start
, s
- start
);
5515 cupsFilePuts(fp
, "<");
5521 cupsFilePuts(fp
, start
);
5526 * End of "$Id: printers.c 7968 2008-09-19 23:03:01Z mike $".