2 * "$Id: printers.c 7968 2008-09-19 23:03:01Z mike $"
4 * Printer routines for the CUPS scheduler.
6 * Copyright 2007-2011 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 * dirty_printer() - Mark config and state files dirty for the
52 * load_ppd() - Load a cached PPD file, updating the cache as
54 * new_media_col() - Create a media-col collection value.
55 * write_irix_config() - Update the config files used by the IRIX
57 * write_irix_state() - Update the status files used by IRIX printing
59 * write_xml_string() - Write a string with XML escaping.
63 * Include necessary headers...
68 #ifdef HAVE_APPLICATIONSERVICES_H
69 # include <ApplicationServices/ApplicationServices.h>
70 #endif /* HAVE_APPLICATIONSERVICES_H */
71 #ifdef HAVE_SYS_MOUNT_H
72 # include <sys/mount.h>
73 #endif /* HAVE_SYS_MOUNT_H */
74 #ifdef HAVE_SYS_STATVFS_H
75 # include <sys/statvfs.h>
76 #elif defined(HAVE_SYS_STATFS_H)
77 # include <sys/statfs.h>
78 #endif /* HAVE_SYS_STATVFS_H */
81 #endif /* HAVE_SYS_VFS_H */
88 static void add_printer_defaults(cupsd_printer_t
*p
);
89 static void add_printer_filter(cupsd_printer_t
*p
, mime_type_t
*type
,
91 static void add_printer_formats(cupsd_printer_t
*p
);
92 static void add_string_array(cups_array_t
**a
, const char *s
);
93 static int compare_printers(void *first
, void *second
, void *data
);
94 static void delete_printer_filters(cupsd_printer_t
*p
);
95 static void delete_string_array(cups_array_t
**a
);
96 static void dirty_printer(cupsd_printer_t
*p
);
97 static void load_ppd(cupsd_printer_t
*p
);
98 static ipp_t
*new_media_col(_pwg_size_t
*size
, const char *source
,
101 static void write_irix_config(cupsd_printer_t
*p
);
102 static void write_irix_state(cupsd_printer_t
*p
);
104 static void write_xml_string(cups_file_t
*fp
, const char *s
);
108 * 'cupsdAddPrinter()' - Add a printer to the system.
111 cupsd_printer_t
* /* O - New printer */
112 cupsdAddPrinter(const char *name
) /* I - Name of printer */
114 cupsd_printer_t
*p
; /* New printer */
115 char uri
[1024]; /* Printer URI */
119 * Range check input...
122 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdAddPrinter(\"%s\")", name
);
125 * Create a new printer entity...
128 if ((p
= calloc(1, sizeof(cupsd_printer_t
))) == NULL
)
130 cupsdLogMessage(CUPSD_LOG_CRIT
, "Unable to allocate memory for printer - %s",
135 cupsdSetString(&p
->name
, name
);
136 cupsdSetString(&p
->info
, name
);
137 cupsdSetString(&p
->hostname
, ServerName
);
139 httpAssembleURIf(HTTP_URI_CODING_ALL
, uri
, sizeof(uri
), "ipp", NULL
,
140 ServerName
, RemotePort
, "/printers/%s", name
);
141 cupsdSetString(&p
->uri
, uri
);
142 cupsdSetDeviceURI(p
, "file:///dev/null");
144 p
->state
= IPP_PRINTER_STOPPED
;
145 p
->state_time
= time(NULL
);
147 p
->shared
= DefaultShared
;
148 p
->filetype
= mimeAddType(MimeDatabase
, "printer", name
);
150 cupsdSetString(&p
->job_sheets
[0], "none");
151 cupsdSetString(&p
->job_sheets
[1], "none");
153 cupsdSetString(&p
->error_policy
, ErrorPolicy
);
154 cupsdSetString(&p
->op_policy
, DefaultPolicy
);
156 p
->op_policy_ptr
= DefaultPolicyPtr
;
158 if (MaxPrinterHistory
)
159 p
->history
= calloc(MaxPrinterHistory
, sizeof(ipp_t
*));
162 * Insert the printer in the printer list alphabetically...
166 Printers
= cupsArrayNew(compare_printers
, NULL
);
168 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
169 "cupsdAddPrinter: Adding %s to Printers", p
->name
);
170 cupsArrayAdd(Printers
, p
);
172 if (!ImplicitPrinters
)
173 ImplicitPrinters
= cupsArrayNew(compare_printers
, NULL
);
176 * Return the new printer...
184 * 'cupsdAddPrinterHistory()' - Add the current printer state to the history.
188 cupsdAddPrinterHistory(
189 cupsd_printer_t
*p
) /* I - Printer */
191 ipp_t
*history
; /* History collection */
195 * Stop early if we aren't keeping history data...
198 if (MaxPrinterHistory
<= 0)
202 * Retire old history data as needed...
205 p
->sequence_number
++;
207 if (p
->num_history
>= MaxPrinterHistory
)
210 ippDelete(p
->history
[0]);
211 memmove(p
->history
, p
->history
+ 1, p
->num_history
* sizeof(ipp_t
*));
215 * Create a collection containing the current printer-state, printer-up-time,
216 * printer-state-message, and printer-state-reasons attributes.
220 ippAddInteger(history
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-state",
222 ippAddBoolean(history
, IPP_TAG_PRINTER
, "printer-is-accepting-jobs",
224 ippAddBoolean(history
, IPP_TAG_PRINTER
, "printer-is-shared", p
->shared
);
225 ippAddString(history
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-state-message",
226 NULL
, p
->state_message
);
227 if (p
->num_reasons
== 0)
228 ippAddString(history
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
229 "printer-state-reasons", NULL
, "none");
231 ippAddStrings(history
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
232 "printer-state-reasons", p
->num_reasons
, NULL
,
233 (const char * const *)p
->reasons
);
234 ippAddInteger(history
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
235 "printer-state-change-time", p
->state_time
);
236 ippAddInteger(history
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
237 "printer-state-sequence-number", p
->sequence_number
);
239 p
->history
[p
->num_history
] = history
;
245 * 'cupsdCreateCommonData()' - Create the common printer data.
249 cupsdCreateCommonData(void)
251 int i
; /* Looping var */
252 ipp_attribute_t
*attr
; /* Attribute data */
253 cups_dir_t
*dir
; /* Notifier directory */
254 cups_dentry_t
*dent
; /* Notifier directory entry */
255 cups_array_t
*notifiers
; /* Notifier array */
256 char filename
[1024], /* Filename */
257 *notifier
; /* Current notifier */
258 cupsd_policy_t
*p
; /* Current policy */
259 int k_supported
; /* Maximum file size supported */
261 struct statvfs spoolinfo
; /* FS info for spool directory */
262 double spoolsize
; /* FS size */
263 #elif defined(HAVE_STATFS)
264 struct statfs spoolinfo
; /* FS info for spool directory */
265 double spoolsize
; /* FS size */
266 #endif /* HAVE_STATVFS */
267 static const int nups
[] = /* number-up-supported values */
268 { 1, 2, 4, 6, 9, 16 };
269 static const int orients
[4] =/* orientation-requested-supported values */
273 IPP_REVERSE_LANDSCAPE
,
276 static const char * const holds
[] = /* job-hold-until-supported values */
287 static const char * const versions
[] =/* ipp-versions-supported values */
294 static const int ops
[] = /* operations-supported values */
301 IPP_GET_JOB_ATTRIBUTES
,
303 IPP_GET_PRINTER_ATTRIBUTES
,
310 IPP_SET_PRINTER_ATTRIBUTES
,
311 IPP_SET_JOB_ATTRIBUTES
,
312 IPP_GET_PRINTER_SUPPORTED_VALUES
,
313 IPP_CREATE_PRINTER_SUBSCRIPTION
,
314 IPP_CREATE_JOB_SUBSCRIPTION
,
315 IPP_GET_SUBSCRIPTION_ATTRIBUTES
,
316 IPP_GET_SUBSCRIPTIONS
,
317 IPP_RENEW_SUBSCRIPTION
,
318 IPP_CANCEL_SUBSCRIPTION
,
319 IPP_GET_NOTIFICATIONS
,
323 IPP_RELEASE_HELD_NEW_JOBS
,
340 CUPS_AUTHENTICATE_JOB
,
345 static const char * const charsets
[] =/* charset-supported values */
350 static const char * const compressions
[] =
351 { /* document-compression-supported values */
355 #endif /* HAVE_LIBZ */
357 static const char * const media_col_supported
[] =
358 { /* media-col-supported values */
359 "media-bottom-margin",
361 "media-right-margin",
367 static const char * const multiple_document_handling
[] =
368 { /* multiple-document-handling-supported values */
369 "separate-documents-uncollated-copies",
370 "separate-documents-collated-copies"
372 static const char * const notify_attrs
[] =
373 { /* notify-attributes-supported values */
374 "printer-state-change-time",
375 "notify-lease-expiration-time",
376 "notify-subscriber-user-name"
378 static const char * const notify_events
[] =
379 { /* notify-events-supported values */
381 "job-config-changed",
388 "printer-config-changed",
390 "printer-finishings-changed",
391 "printer-media-changed",
395 "printer-state-changed",
402 static const char * const job_creation
[] =
403 { /* job-creation-attributes-supported */
406 "ipp-attribute-fidelity",
413 "multiple-document-handling",
417 "orientation-requested",
420 "printer-resolution",
423 static const char * const job_settable
[] =
424 { /* job-settable-attributes-supported */
432 "multiple-document-handling",
436 "orientation-requested",
439 "printer-resolution",
442 static const char * const printer_settable
[] =
443 { /* printer-settable-attributes-supported */
447 static const char * const which_jobs
[] =
448 { /* which-jobs-supported values */
462 ippDelete(CommonData
);
464 CommonData
= ippNew();
467 * Get the maximum spool size based on the size of the filesystem used for
468 * the RequestRoot directory. If the host OS doesn't support the statfs call
469 * or the filesystem is larger than 2TiB, always report INT_MAX.
473 if (statvfs(RequestRoot
, &spoolinfo
))
474 k_supported
= INT_MAX
;
475 else if ((spoolsize
= (double)spoolinfo
.f_frsize
* spoolinfo
.f_blocks
/ 1024) >
477 k_supported
= INT_MAX
;
479 k_supported
= (int)spoolsize
;
481 #elif defined(HAVE_STATFS)
482 if (statfs(RequestRoot
, &spoolinfo
))
483 k_supported
= INT_MAX
;
484 else if ((spoolsize
= (double)spoolinfo
.f_bsize
* spoolinfo
.f_blocks
/ 1024) >
486 k_supported
= INT_MAX
;
488 k_supported
= (int)spoolsize
;
491 k_supported
= INT_MAX
;
492 #endif /* HAVE_STATVFS */
495 * This list of attributes is sorted to improve performance when the
496 * client provides a requested-attributes attribute...
499 /* charset-configured */
500 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_CHARSET
| IPP_TAG_COPY
,
501 "charset-configured", NULL
, "utf-8");
503 /* charset-supported */
504 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_CHARSET
| IPP_TAG_COPY
,
505 "charset-supported", sizeof(charsets
) / sizeof(charsets
[0]),
508 /* compression-supported */
509 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
510 "compression-supported",
511 sizeof(compressions
) / sizeof(compressions
[0]),
514 /* copies-supported */
515 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "copies-supported", 1, MaxCopies
);
518 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
| IPP_TAG_COPY
,
519 "cups-version", NULL
, CUPS_SVERSION
+ 6);
521 /* generated-natural-language-supported (no IPP_TAG_COPY) */
522 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_LANGUAGE
,
523 "generated-natural-language-supported", NULL
, DefaultLanguage
);
525 /* ipp-versions-supported */
526 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
527 "ipp-versions-supported", sizeof(versions
) / sizeof(versions
[0]),
530 /* ippget-event-life */
531 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
532 "ippget-event-life", 15);
534 /* job-creation-attributes-supported */
535 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
536 "job-creation-attributes-supported",
537 sizeof(job_creation
) / sizeof(job_creation
[0]),
540 /* job-hold-until-supported */
541 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
542 "job-hold-until-supported", sizeof(holds
) / sizeof(holds
[0]),
545 /* job-ids-supported */
546 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
, "job-ids-supported", 1);
548 /* job-k-octets-supported */
549 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
550 "job-k-octets-supported", k_supported
);
552 /* job-priority-supported */
553 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
554 "job-priority-supported", 100);
556 /* job-settable-attributes-supported */
557 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
558 "job-settable-attributes-supported",
559 sizeof(job_settable
) / sizeof(job_settable
[0]),
562 /* job-sheets-supported */
563 if (cupsArrayCount(Banners
) > 0)
566 * Setup the job-sheets-supported attribute...
569 if (Classification
&& !ClassifyOverride
)
570 attr
= ippAddString(CommonData
, IPP_TAG_PRINTER
,
571 IPP_TAG_NAME
| IPP_TAG_COPY
,
572 "job-sheets-supported", NULL
, Classification
);
574 attr
= ippAddStrings(CommonData
, IPP_TAG_PRINTER
,
575 IPP_TAG_NAME
| IPP_TAG_COPY
,
576 "job-sheets-supported", cupsArrayCount(Banners
) + 1,
580 cupsdLogMessage(CUPSD_LOG_EMERG
,
581 "Unable to allocate memory for "
582 "job-sheets-supported attribute: %s!", strerror(errno
));
583 else if (!Classification
|| ClassifyOverride
)
585 cupsd_banner_t
*banner
; /* Current banner */
588 attr
->values
[0].string
.text
= _cupsStrAlloc("none");
590 for (i
= 1, banner
= (cupsd_banner_t
*)cupsArrayFirst(Banners
);
592 i
++, banner
= (cupsd_banner_t
*)cupsArrayNext(Banners
))
593 attr
->values
[i
].string
.text
= banner
->name
;
597 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
598 "job-sheets-supported", NULL
, "none");
600 /* media-col-supported */
601 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
602 "media-col-supported",
603 sizeof(media_col_supported
) /
604 sizeof(media_col_supported
[0]), NULL
,
605 media_col_supported
);
607 /* multiple-document-handling-supported */
608 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
609 "multiple-document-handling-supported",
610 sizeof(multiple_document_handling
) /
611 sizeof(multiple_document_handling
[0]), NULL
,
612 multiple_document_handling
);
614 /* multiple-document-jobs-supported */
615 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
,
616 "multiple-document-jobs-supported", 1);
618 /* multiple-operation-time-out */
619 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
620 "multiple-operation-time-out", MultipleOperationTimeout
);
622 /* natural-language-configured (no IPP_TAG_COPY) */
623 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_LANGUAGE
,
624 "natural-language-configured", NULL
, DefaultLanguage
);
626 /* notify-attributes-supported */
627 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
628 "notify-attributes-supported",
629 (int)(sizeof(notify_attrs
) / sizeof(notify_attrs
[0])),
632 /* notify-lease-duration-supported */
633 ippAddRange(CommonData
, IPP_TAG_PRINTER
,
634 "notify-lease-duration-supported", 0,
635 MaxLeaseDuration
? MaxLeaseDuration
: 2147483647);
637 /* notify-max-events-supported */
638 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
639 "notify-max-events-supported", MaxEvents
);
641 /* notify-events-supported */
642 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
643 "notify-events-supported",
644 (int)(sizeof(notify_events
) / sizeof(notify_events
[0])),
645 NULL
, notify_events
);
647 /* notify-pull-method-supported */
648 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
649 "notify-pull-method-supported", NULL
, "ippget");
651 /* notify-schemes-supported */
652 snprintf(filename
, sizeof(filename
), "%s/notifier", ServerBin
);
653 if ((dir
= cupsDirOpen(filename
)) != NULL
)
655 notifiers
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
657 while ((dent
= cupsDirRead(dir
)) != NULL
)
658 if (S_ISREG(dent
->fileinfo
.st_mode
) &&
659 (dent
->fileinfo
.st_mode
& S_IXOTH
) != 0)
660 cupsArrayAdd(notifiers
, _cupsStrAlloc(dent
->filename
));
662 if (cupsArrayCount(notifiers
) > 0)
664 attr
= ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
665 "notify-schemes-supported",
666 cupsArrayCount(notifiers
), NULL
, NULL
);
668 for (i
= 0, notifier
= (char *)cupsArrayFirst(notifiers
);
670 i
++, notifier
= (char *)cupsArrayNext(notifiers
))
671 attr
->values
[i
].string
.text
= notifier
;
674 cupsArrayDelete(notifiers
);
678 /* number-up-supported */
679 ippAddIntegers(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
680 "number-up-supported", sizeof(nups
) / sizeof(nups
[0]), nups
);
682 /* operations-supported */
683 ippAddIntegers(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
684 "operations-supported",
685 sizeof(ops
) / sizeof(ops
[0]) + JobFiles
- 1, ops
);
687 /* orientation-requested-supported */
688 ippAddIntegers(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
689 "orientation-requested-supported", 4, orients
);
691 /* page-ranges-supported */
692 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
, "page-ranges-supported", 1);
694 /* pdl-override-supported */
695 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
696 "pdl-override-supported", NULL
, "attempted");
698 /* printer-op-policy-supported */
699 attr
= ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
700 "printer-op-policy-supported", cupsArrayCount(Policies
),
702 for (i
= 0, p
= (cupsd_policy_t
*)cupsArrayFirst(Policies
);
704 i
++, p
= (cupsd_policy_t
*)cupsArrayNext(Policies
))
705 attr
->values
[i
].string
.text
= p
->name
;
707 /* printer-settable-attributes-supported */
708 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
709 "printer-settable-attributes-supported",
710 sizeof(printer_settable
) / sizeof(printer_settable
[0]),
711 NULL
, printer_settable
);
713 /* server-is-sharing-printers */
714 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
, "server-is-sharing-printers",
715 BrowseLocalProtocols
!= 0 && Browsing
);
717 /* which-jobs-supported */
718 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
719 "which-jobs-supported",
720 sizeof(which_jobs
) / sizeof(which_jobs
[0]), NULL
, which_jobs
);
725 * 'cupsdDeleteAllPrinters()' - Delete all printers from the system.
729 cupsdDeleteAllPrinters(void)
731 cupsd_printer_t
*p
; /* Pointer to current printer/class */
734 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
736 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
738 p
->op_policy_ptr
= DefaultPolicyPtr
;
739 cupsdDeletePrinter(p
, 0);
745 * 'cupsdDeletePrinter()' - Delete a printer from the system.
748 int /* O - 1 if classes affected, 0 otherwise */
750 cupsd_printer_t
*p
, /* I - Printer to delete */
751 int update
) /* I - Update printers.conf? */
753 int i
, /* Looping var */
754 changed
= 0; /* Class changed? */
756 char filename
[1024]; /* Interface script filename */
760 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdDeletePrinter(p=%p(%s), update=%d)",
764 * Save the current position in the Printers array...
767 cupsArraySave(Printers
);
770 * Stop printing on this printer...
773 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, update
);
775 p
->state
= IPP_PRINTER_STOPPED
; /* Force for browsed printers */
778 cupsdSetJobState(p
->job
, IPP_JOB_PENDING
, CUPSD_JOB_FORCE
,
779 update
? "Job stopped due to printer being deleted." :
783 * If this printer is the next for browsing, point to the next one...
788 cupsArrayFind(Printers
, p
);
789 BrowseNext
= (cupsd_printer_t
*)cupsArrayNext(Printers
);
793 * Remove the printer from the list...
796 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
797 "cupsdDeletePrinter: Removing %s from Printers", p
->name
);
798 cupsArrayRemove(Printers
, p
);
800 if (p
->type
& CUPS_PRINTER_IMPLICIT
)
802 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
803 "cupsdDeletePrinter: Removing %s from ImplicitPrinters",
805 cupsArrayRemove(ImplicitPrinters
, p
);
809 * Remove the dummy interface/icon/option files under IRIX...
813 snprintf(filename
, sizeof(filename
), "/var/spool/lp/interface/%s", p
->name
);
816 snprintf(filename
, sizeof(filename
), "/var/spool/lp/gui_interface/ELF/%s.gui",
820 snprintf(filename
, sizeof(filename
), "/var/spool/lp/activeicons/%s", p
->name
);
823 snprintf(filename
, sizeof(filename
), "/var/spool/lp/pod/%s.config", p
->name
);
826 snprintf(filename
, sizeof(filename
), "/var/spool/lp/pod/%s.status", p
->name
);
829 snprintf(filename
, sizeof(filename
), "/var/spool/lp/member/%s", p
->name
);
834 * If p is the default printer, assign a different one...
837 if (p
== DefaultPrinter
)
839 DefaultPrinter
= NULL
;
841 if (UseNetworkDefault
)
844 * Find the first network default printer and use it...
847 cupsd_printer_t
*dp
; /* New default printer */
850 for (dp
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
852 dp
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
853 if (dp
!= p
&& (dp
->type
& CUPS_PRINTER_DEFAULT
))
862 * Remove this printer from any classes...
865 if (!(p
->type
& CUPS_PRINTER_IMPLICIT
))
867 changed
= cupsdDeletePrinterFromClasses(p
);
870 * Deregister from any browse protocols...
873 cupsdDeregisterPrinter(p
, 1);
877 * Free all memory used by the printer...
880 if (p
->printers
!= NULL
)
883 if (MaxPrinterHistory
)
885 for (i
= 0; i
< p
->num_history
; i
++)
886 ippDelete(p
->history
[i
]);
891 delete_printer_filters(p
);
893 for (i
= 0; i
< p
->num_reasons
; i
++)
894 _cupsStrFree(p
->reasons
[i
]);
897 ippDelete(p
->ppd_attrs
);
899 mimeDeleteType(MimeDatabase
, p
->filetype
);
900 mimeDeleteType(MimeDatabase
, p
->prefiltertype
);
902 delete_string_array(&(p
->filters
));
903 delete_string_array(&(p
->pre_filters
));
905 cupsdFreeStrings(&(p
->users
));
908 cupsdClearString(&p
->uri
);
909 cupsdClearString(&p
->hostname
);
910 cupsdClearString(&p
->name
);
911 cupsdClearString(&p
->location
);
912 cupsdClearString(&p
->make_model
);
913 cupsdClearString(&p
->info
);
914 cupsdClearString(&p
->job_sheets
[0]);
915 cupsdClearString(&p
->job_sheets
[1]);
916 cupsdClearString(&p
->device_uri
);
917 cupsdClearString(&p
->sanitized_device_uri
);
918 cupsdClearString(&p
->port_monitor
);
919 cupsdClearString(&p
->op_policy
);
920 cupsdClearString(&p
->error_policy
);
922 cupsdClearString(&p
->alert
);
923 cupsdClearString(&p
->alert_description
);
926 cupsdClearString(&p
->product
);
927 cupsdClearString(&p
->pdl
);
928 #endif /* HAVE_DNSSD */
930 cupsArrayDelete(p
->filetypes
);
933 free(p
->browse_attrs
);
935 cupsFreeOptions(p
->num_options
, p
->options
);
940 * Restore the previous position in the Printers array...
943 cupsArrayRestore(Printers
);
950 * 'cupsdFindDest()' - Find a destination in the list.
953 cupsd_printer_t
* /* O - Destination in list */
954 cupsdFindDest(const char *name
) /* I - Name of printer or class to find */
956 cupsd_printer_t key
; /* Search key */
959 key
.name
= (char *)name
;
960 return ((cupsd_printer_t
*)cupsArrayFind(Printers
, &key
));
965 * 'cupsdFindPrinter()' - Find a printer in the list.
968 cupsd_printer_t
* /* O - Printer in list */
969 cupsdFindPrinter(const char *name
) /* I - Name of printer to find */
971 cupsd_printer_t
*p
; /* Printer in list */
974 if ((p
= cupsdFindDest(name
)) != NULL
&& (p
->type
& CUPS_PRINTER_CLASS
))
982 * 'cupsdLoadAllPrinters()' - Load printers from the printers.conf file.
986 cupsdLoadAllPrinters(void)
988 int i
; /* Looping var */
989 cups_file_t
*fp
; /* printers.conf file */
990 int linenum
; /* Current line number */
991 char line
[4096], /* Line from file */
992 *value
, /* Pointer to value */
993 *valueptr
; /* Pointer into value */
994 cupsd_printer_t
*p
; /* Current printer */
998 * Open the printers.conf file...
1001 snprintf(line
, sizeof(line
), "%s/printers.conf", ServerRoot
);
1002 if ((fp
= cupsFileOpen(line
, "r")) == NULL
)
1004 if (errno
!= ENOENT
)
1005 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to open %s - %s", line
,
1011 * Read printer configurations until we hit EOF...
1017 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
1020 * Decode the directive...
1023 if (!strcasecmp(line
, "<Printer") ||
1024 !strcasecmp(line
, "<DefaultPrinter"))
1027 * <Printer name> or <DefaultPrinter name>
1030 if (p
== NULL
&& value
)
1033 * Add the printer and a base file type...
1036 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Loading printer %s...", value
);
1038 p
= cupsdAddPrinter(value
);
1040 p
->state
= IPP_PRINTER_IDLE
;
1043 * Set the default printer as needed...
1046 if (!strcasecmp(line
, "<DefaultPrinter"))
1050 cupsdLogMessage(CUPSD_LOG_ERROR
,
1051 "Syntax error on line %d of printers.conf.", linenum
);
1053 else if (!strcasecmp(line
, "</Printer>"))
1058 * Close out the current printer...
1061 cupsdSetPrinterAttrs(p
);
1062 cupsdAddPrinterHistory(p
);
1064 if (strncmp(p
->device_uri
, "file:", 5) &&
1065 p
->state
!= IPP_PRINTER_STOPPED
)
1068 * See if the backend exists...
1071 snprintf(line
, sizeof(line
), "%s/backend/%s", ServerBin
,
1074 if ((valueptr
= strchr(line
+ strlen(ServerBin
), ':')) != NULL
)
1075 *valueptr
= '\0'; /* Chop everything but URI scheme */
1077 if (access(line
, 0))
1080 * Backend does not exist, stop printer...
1083 p
->state
= IPP_PRINTER_STOPPED
;
1084 snprintf(p
->state_message
, sizeof(p
->state_message
),
1085 "Backend %s does not exist!", line
);
1092 cupsdLogMessage(CUPSD_LOG_ERROR
,
1093 "Syntax error on line %d of printers.conf.", linenum
);
1097 cupsdLogMessage(CUPSD_LOG_ERROR
,
1098 "Syntax error on line %d of printers.conf.", linenum
);
1100 else if (!strcasecmp(line
, "AuthInfoRequired"))
1102 if (!cupsdSetAuthInfoRequired(p
, value
, NULL
))
1103 cupsdLogMessage(CUPSD_LOG_ERROR
,
1104 "Bad AuthInfoRequired on line %d of printers.conf.",
1107 else if (!strcasecmp(line
, "Info"))
1110 cupsdSetString(&p
->info
, value
);
1112 else if (!strcasecmp(line
, "MakeModel"))
1115 cupsdSetString(&p
->make_model
, value
);
1117 else if (!strcasecmp(line
, "Location"))
1120 cupsdSetString(&p
->location
, value
);
1122 else if (!strcasecmp(line
, "DeviceURI"))
1125 cupsdSetDeviceURI(p
, value
);
1127 cupsdLogMessage(CUPSD_LOG_ERROR
,
1128 "Syntax error on line %d of printers.conf.", linenum
);
1130 else if (!strcasecmp(line
, "Option") && value
)
1136 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1139 cupsdLogMessage(CUPSD_LOG_ERROR
,
1140 "Syntax error on line %d of printers.conf.", linenum
);
1143 for (; *valueptr
&& isspace(*valueptr
& 255); *valueptr
++ = '\0');
1145 p
->num_options
= cupsAddOption(value
, valueptr
, p
->num_options
,
1149 else if (!strcasecmp(line
, "PortMonitor"))
1151 if (value
&& strcmp(value
, "none"))
1152 cupsdSetString(&p
->port_monitor
, value
);
1154 cupsdClearString(&p
->port_monitor
);
1156 cupsdLogMessage(CUPSD_LOG_ERROR
,
1157 "Syntax error on line %d of printers.conf.", linenum
);
1159 else if (!strcasecmp(line
, "Reason"))
1162 strcmp(value
, "connecting-to-device") &&
1163 strcmp(value
, "cups-insecure-filter-warning") &&
1164 strcmp(value
, "cups-missing-filter-warning"))
1166 for (i
= 0 ; i
< p
->num_reasons
; i
++)
1167 if (!strcmp(value
, p
->reasons
[i
]))
1170 if (i
>= p
->num_reasons
&&
1171 p
->num_reasons
< (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
1173 p
->reasons
[p
->num_reasons
] = _cupsStrAlloc(value
);
1178 cupsdLogMessage(CUPSD_LOG_ERROR
,
1179 "Syntax error on line %d of printers.conf.", linenum
);
1181 else if (!strcasecmp(line
, "State"))
1184 * Set the initial queue state...
1187 if (value
&& !strcasecmp(value
, "idle"))
1188 p
->state
= IPP_PRINTER_IDLE
;
1189 else if (value
&& !strcasecmp(value
, "stopped"))
1191 p
->state
= IPP_PRINTER_STOPPED
;
1193 for (i
= 0 ; i
< p
->num_reasons
; i
++)
1194 if (!strcmp("paused", p
->reasons
[i
]))
1197 if (i
>= p
->num_reasons
&&
1198 p
->num_reasons
< (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
1200 p
->reasons
[p
->num_reasons
] = _cupsStrAlloc("paused");
1205 cupsdLogMessage(CUPSD_LOG_ERROR
,
1206 "Syntax error on line %d of printers.conf.", linenum
);
1208 else if (!strcasecmp(line
, "StateMessage"))
1211 * Set the initial queue state message...
1215 strlcpy(p
->state_message
, value
, sizeof(p
->state_message
));
1217 else if (!strcasecmp(line
, "StateTime"))
1220 * Set the state time...
1224 p
->state_time
= atoi(value
);
1226 else if (!strcasecmp(line
, "Accepting"))
1229 * Set the initial accepting state...
1233 (!strcasecmp(value
, "yes") ||
1234 !strcasecmp(value
, "on") ||
1235 !strcasecmp(value
, "true")))
1238 (!strcasecmp(value
, "no") ||
1239 !strcasecmp(value
, "off") ||
1240 !strcasecmp(value
, "false")))
1243 cupsdLogMessage(CUPSD_LOG_ERROR
,
1244 "Syntax error on line %d of printers.conf.", linenum
);
1246 else if (!strcasecmp(line
, "Type"))
1249 p
->type
= atoi(value
);
1251 cupsdLogMessage(CUPSD_LOG_ERROR
,
1252 "Syntax error on line %d of printers.conf.", linenum
);
1254 else if (!strcasecmp(line
, "Product"))
1259 p
->product
= _cupsStrAlloc(value
);
1260 #endif /* HAVE_DNSSD */
1263 cupsdLogMessage(CUPSD_LOG_ERROR
,
1264 "Syntax error on line %d of printers.conf.", linenum
);
1266 else if (!strcasecmp(line
, "Filter"))
1271 p
->filters
= cupsArrayNew(NULL
, NULL
);
1273 cupsArrayAdd(p
->filters
, _cupsStrAlloc(value
));
1276 cupsdLogMessage(CUPSD_LOG_ERROR
,
1277 "Syntax error on line %d of printers.conf.", linenum
);
1279 else if (!strcasecmp(line
, "PreFilter"))
1283 if (!p
->pre_filters
)
1284 p
->pre_filters
= cupsArrayNew(NULL
, NULL
);
1286 cupsArrayAdd(p
->pre_filters
, _cupsStrAlloc(value
));
1289 cupsdLogMessage(CUPSD_LOG_ERROR
,
1290 "Syntax error on line %d of printers.conf.", linenum
);
1292 else if (!strcasecmp(line
, "Shared"))
1295 * Set the initial shared state...
1299 (!strcasecmp(value
, "yes") ||
1300 !strcasecmp(value
, "on") ||
1301 !strcasecmp(value
, "true")))
1304 (!strcasecmp(value
, "no") ||
1305 !strcasecmp(value
, "off") ||
1306 !strcasecmp(value
, "false")))
1309 cupsdLogMessage(CUPSD_LOG_ERROR
,
1310 "Syntax error on line %d of printers.conf.", linenum
);
1312 else if (!strcasecmp(line
, "JobSheets"))
1315 * Set the initial job sheets...
1320 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1325 cupsdSetString(&p
->job_sheets
[0], value
);
1327 while (isspace(*valueptr
& 255))
1332 for (value
= valueptr
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1337 cupsdSetString(&p
->job_sheets
[1], value
);
1341 cupsdLogMessage(CUPSD_LOG_ERROR
,
1342 "Syntax error on line %d of printers.conf.", linenum
);
1344 else if (!strcasecmp(line
, "AllowUser"))
1349 cupsdAddString(&(p
->users
), value
);
1352 cupsdLogMessage(CUPSD_LOG_ERROR
,
1353 "Syntax error on line %d of printers.conf.", linenum
);
1355 else if (!strcasecmp(line
, "DenyUser"))
1360 cupsdAddString(&(p
->users
), value
);
1363 cupsdLogMessage(CUPSD_LOG_ERROR
,
1364 "Syntax error on line %d of printers.conf.", linenum
);
1366 else if (!strcasecmp(line
, "QuotaPeriod"))
1369 p
->quota_period
= atoi(value
);
1371 cupsdLogMessage(CUPSD_LOG_ERROR
,
1372 "Syntax error on line %d of printers.conf.", linenum
);
1374 else if (!strcasecmp(line
, "PageLimit"))
1377 p
->page_limit
= atoi(value
);
1379 cupsdLogMessage(CUPSD_LOG_ERROR
,
1380 "Syntax error on line %d of printers.conf.", linenum
);
1382 else if (!strcasecmp(line
, "KLimit"))
1385 p
->k_limit
= atoi(value
);
1387 cupsdLogMessage(CUPSD_LOG_ERROR
,
1388 "Syntax error on line %d of printers.conf.", linenum
);
1390 else if (!strcasecmp(line
, "OpPolicy"))
1394 cupsd_policy_t
*pol
; /* Policy */
1397 if ((pol
= cupsdFindPolicy(value
)) != NULL
)
1399 cupsdSetString(&p
->op_policy
, value
);
1400 p
->op_policy_ptr
= pol
;
1403 cupsdLogMessage(CUPSD_LOG_ERROR
,
1404 "Bad policy \"%s\" on line %d of printers.conf",
1408 cupsdLogMessage(CUPSD_LOG_ERROR
,
1409 "Syntax error on line %d of printers.conf.", linenum
);
1411 else if (!strcasecmp(line
, "ErrorPolicy"))
1414 cupsdSetString(&p
->error_policy
, value
);
1416 cupsdLogMessage(CUPSD_LOG_ERROR
,
1417 "Syntax error on line %d of printers.conf.", linenum
);
1419 else if (!strcasecmp(line
, "Attribute") && value
)
1421 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1424 cupsdLogMessage(CUPSD_LOG_ERROR
,
1425 "Syntax error on line %d of printers.conf.", linenum
);
1428 for (; *valueptr
&& isspace(*valueptr
& 255); *valueptr
++ = '\0');
1431 cupsdSetPrinterAttrs(p
);
1433 if (!strcmp(value
, "marker-change-time"))
1434 p
->marker_time
= atoi(valueptr
);
1436 cupsdSetPrinterAttr(p
, value
, valueptr
);
1442 * Something else we don't understand...
1445 cupsdLogMessage(CUPSD_LOG_ERROR
,
1446 "Unknown configuration directive %s on line %d of printers.conf.",
1456 * 'cupsdRenamePrinter()' - Rename a printer.
1461 cupsd_printer_t
*p
, /* I - Printer */
1462 const char *name
) /* I - New name */
1465 * Remove the printer from the array(s) first...
1468 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1469 "cupsdRenamePrinter: Removing %s from Printers", p
->name
);
1470 cupsArrayRemove(Printers
, p
);
1472 if (p
->type
& CUPS_PRINTER_IMPLICIT
)
1474 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1475 "cupsdRenamePrinter: Removing %s from ImplicitPrinters",
1477 cupsArrayRemove(ImplicitPrinters
, p
);
1481 * Rename the printer type...
1484 mimeDeleteType(MimeDatabase
, p
->filetype
);
1485 p
->filetype
= mimeAddType(MimeDatabase
, "printer", name
);
1487 mimeDeleteType(MimeDatabase
, p
->prefiltertype
);
1488 p
->prefiltertype
= mimeAddType(MimeDatabase
, "prefilter", name
);
1491 * Rename the printer...
1494 cupsdSetString(&p
->name
, name
);
1497 * Reset printer attributes...
1500 cupsdSetPrinterAttrs(p
);
1503 * Add the printer back to the printer array(s)...
1506 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1507 "cupsdRenamePrinter: Adding %s to Printers", p
->name
);
1508 cupsArrayAdd(Printers
, p
);
1510 if (p
->type
& CUPS_PRINTER_IMPLICIT
)
1512 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1513 "cupsdRenamePrinter: Adding %s to ImplicitPrinters",
1515 cupsArrayAdd(ImplicitPrinters
, p
);
1521 * 'cupsdSaveAllPrinters()' - Save all printer definitions to the printers.conf
1526 cupsdSaveAllPrinters(void)
1528 int i
; /* Looping var */
1529 cups_file_t
*fp
; /* printers.conf file */
1530 char temp
[1024], /* Temporary string */
1531 backup
[1024], /* printers.conf.O file */
1532 value
[2048], /* Value string */
1533 *ptr
, /* Pointer into value */
1534 *name
; /* Current user/group name */
1535 cupsd_printer_t
*printer
; /* Current printer class */
1536 time_t curtime
; /* Current time */
1537 struct tm
*curdate
; /* Current date */
1538 cups_option_t
*option
; /* Current option */
1539 ipp_attribute_t
*marker
; /* Current marker attribute */
1543 * Create the printers.conf file...
1546 snprintf(temp
, sizeof(temp
), "%s/printers.conf", ServerRoot
);
1547 snprintf(backup
, sizeof(backup
), "%s/printers.conf.O", ServerRoot
);
1549 if (rename(temp
, backup
))
1551 if (errno
!= ENOENT
)
1552 cupsdLogMessage(CUPSD_LOG_ERROR
,
1553 "Unable to backup printers.conf - %s", strerror(errno
));
1556 if ((fp
= cupsFileOpen(temp
, "w")) == NULL
)
1558 cupsdLogMessage(CUPSD_LOG_ERROR
,
1559 "Unable to save printers.conf - %s", strerror(errno
));
1561 if (rename(backup
, temp
))
1562 cupsdLogMessage(CUPSD_LOG_ERROR
,
1563 "Unable to restore printers.conf - %s", strerror(errno
));
1567 cupsdLogMessage(CUPSD_LOG_INFO
, "Saving printers.conf...");
1570 * Restrict access to the file...
1573 fchown(cupsFileNumber(fp
), getuid(), Group
);
1574 fchmod(cupsFileNumber(fp
), ConfigFilePerm
& 0600);
1577 * Write a small header to the file...
1580 curtime
= time(NULL
);
1581 curdate
= localtime(&curtime
);
1582 strftime(temp
, sizeof(temp
) - 1, "%Y-%m-%d %H:%M", curdate
);
1584 cupsFilePuts(fp
, "# Printer configuration file for " CUPS_SVERSION
"\n");
1585 cupsFilePrintf(fp
, "# Written by cupsd on %s\n", temp
);
1586 cupsFilePuts(fp
, "# DO NOT EDIT THIS FILE WHEN CUPSD IS RUNNING\n");
1589 * Write each local printer known to the system...
1592 for (printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
1594 printer
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
1597 * Skip remote destinations and printer classes...
1600 if ((printer
->type
& CUPS_PRINTER_DISCOVERED
) ||
1601 (printer
->type
& CUPS_PRINTER_CLASS
) ||
1602 (printer
->type
& CUPS_PRINTER_IMPLICIT
))
1606 * Write printers as needed...
1609 if (printer
== DefaultPrinter
)
1610 cupsFilePrintf(fp
, "<DefaultPrinter %s>\n", printer
->name
);
1612 cupsFilePrintf(fp
, "<Printer %s>\n", printer
->name
);
1614 if (printer
->num_auth_info_required
> 0)
1616 switch (printer
->num_auth_info_required
)
1619 strlcpy(value
, printer
->auth_info_required
[0], sizeof(value
));
1623 snprintf(value
, sizeof(value
), "%s,%s",
1624 printer
->auth_info_required
[0],
1625 printer
->auth_info_required
[1]);
1630 snprintf(value
, sizeof(value
), "%s,%s,%s",
1631 printer
->auth_info_required
[0],
1632 printer
->auth_info_required
[1],
1633 printer
->auth_info_required
[2]);
1637 cupsFilePutConf(fp
, "AuthInfoRequired", value
);
1641 cupsFilePutConf(fp
, "Info", printer
->info
);
1643 if (printer
->location
)
1644 cupsFilePutConf(fp
, "Location", printer
->location
);
1646 if (printer
->make_model
)
1647 cupsFilePutConf(fp
, "MakeModel", printer
->make_model
);
1649 cupsFilePutConf(fp
, "DeviceURI", printer
->device_uri
);
1651 if (printer
->port_monitor
)
1652 cupsFilePutConf(fp
, "PortMonitor", printer
->port_monitor
);
1654 if (printer
->state
== IPP_PRINTER_STOPPED
)
1656 cupsFilePuts(fp
, "State Stopped\n");
1658 if (printer
->state_message
)
1659 cupsFilePutConf(fp
, "StateMessage", printer
->state_message
);
1662 cupsFilePuts(fp
, "State Idle\n");
1664 cupsFilePrintf(fp
, "StateTime %d\n", (int)printer
->state_time
);
1666 for (i
= 0; i
< printer
->num_reasons
; i
++)
1667 if (strcmp(printer
->reasons
[i
], "connecting-to-device") &&
1668 strcmp(printer
->reasons
[i
], "cups-insecure-filter-warning") &&
1669 strcmp(printer
->reasons
[i
], "cups-missing-filter-warning"))
1670 cupsFilePutConf(fp
, "Reason", printer
->reasons
[i
]);
1672 cupsFilePrintf(fp
, "Type %d\n", printer
->type
);
1675 if (printer
->product
)
1676 cupsFilePutConf(fp
, "Product", printer
->product
);
1677 #endif /* HAVE_DNSSD */
1679 for (ptr
= (char *)cupsArrayFirst(printer
->filters
);
1681 ptr
= (char *)cupsArrayNext(printer
->filters
))
1682 cupsFilePutConf(fp
, "Filter", ptr
);
1684 for (ptr
= (char *)cupsArrayFirst(printer
->pre_filters
);
1686 ptr
= (char *)cupsArrayNext(printer
->pre_filters
))
1687 cupsFilePutConf(fp
, "PreFilter", ptr
);
1689 if (printer
->accepting
)
1690 cupsFilePuts(fp
, "Accepting Yes\n");
1692 cupsFilePuts(fp
, "Accepting No\n");
1694 if (printer
->shared
)
1695 cupsFilePuts(fp
, "Shared Yes\n");
1697 cupsFilePuts(fp
, "Shared No\n");
1699 snprintf(value
, sizeof(value
), "%s %s", printer
->job_sheets
[0],
1700 printer
->job_sheets
[1]);
1701 cupsFilePutConf(fp
, "JobSheets", value
);
1703 cupsFilePrintf(fp
, "QuotaPeriod %d\n", printer
->quota_period
);
1704 cupsFilePrintf(fp
, "PageLimit %d\n", printer
->page_limit
);
1705 cupsFilePrintf(fp
, "KLimit %d\n", printer
->k_limit
);
1707 for (name
= (char *)cupsArrayFirst(printer
->users
);
1709 name
= (char *)cupsArrayNext(printer
->users
))
1710 cupsFilePutConf(fp
, printer
->deny_users
? "DenyUser" : "AllowUser", name
);
1712 if (printer
->op_policy
)
1713 cupsFilePutConf(fp
, "OpPolicy", printer
->op_policy
);
1714 if (printer
->error_policy
)
1715 cupsFilePutConf(fp
, "ErrorPolicy", printer
->error_policy
);
1717 for (i
= printer
->num_options
, option
= printer
->options
;
1721 snprintf(value
, sizeof(value
), "%s %s", option
->name
, option
->value
);
1722 cupsFilePutConf(fp
, "Option", value
);
1725 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-colors",
1726 IPP_TAG_NAME
)) != NULL
)
1728 snprintf(value
, sizeof(value
), "%s ", marker
->name
);
1730 for (i
= 0, ptr
= value
+ strlen(value
);
1731 i
< marker
->num_values
&& ptr
< (value
+ sizeof(value
) - 1);
1737 strlcpy(ptr
, marker
->values
[i
].string
.text
,
1738 value
+ sizeof(value
) - ptr
);
1743 cupsFilePutConf(fp
, "Attribute", value
);
1746 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-levels",
1747 IPP_TAG_INTEGER
)) != NULL
)
1749 cupsFilePrintf(fp
, "Attribute %s %d", marker
->name
,
1750 marker
->values
[0].integer
);
1751 for (i
= 1; i
< marker
->num_values
; i
++)
1752 cupsFilePrintf(fp
, ",%d", marker
->values
[i
].integer
);
1753 cupsFilePuts(fp
, "\n");
1756 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-low-levels",
1757 IPP_TAG_INTEGER
)) != NULL
)
1759 cupsFilePrintf(fp
, "Attribute %s %d", marker
->name
,
1760 marker
->values
[0].integer
);
1761 for (i
= 1; i
< marker
->num_values
; i
++)
1762 cupsFilePrintf(fp
, ",%d", marker
->values
[i
].integer
);
1763 cupsFilePuts(fp
, "\n");
1766 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-high-levels",
1767 IPP_TAG_INTEGER
)) != NULL
)
1769 cupsFilePrintf(fp
, "Attribute %s %d", marker
->name
,
1770 marker
->values
[0].integer
);
1771 for (i
= 1; i
< marker
->num_values
; i
++)
1772 cupsFilePrintf(fp
, ",%d", marker
->values
[i
].integer
);
1773 cupsFilePuts(fp
, "\n");
1776 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-message",
1777 IPP_TAG_TEXT
)) != NULL
)
1779 snprintf(value
, sizeof(value
), "%s %s", marker
->name
,
1780 marker
->values
[0].string
.text
);
1782 cupsFilePutConf(fp
, "Attribute", value
);
1785 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-names",
1786 IPP_TAG_NAME
)) != NULL
)
1788 snprintf(value
, sizeof(value
), "%s ", marker
->name
);
1790 for (i
= 0, ptr
= value
+ strlen(value
);
1791 i
< marker
->num_values
&& ptr
< (value
+ sizeof(value
) - 1);
1797 strlcpy(ptr
, marker
->values
[i
].string
.text
,
1798 value
+ sizeof(value
) - ptr
);
1803 cupsFilePutConf(fp
, "Attribute", value
);
1806 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-types",
1807 IPP_TAG_KEYWORD
)) != NULL
)
1809 snprintf(value
, sizeof(value
), "%s ", marker
->name
);
1811 for (i
= 0, ptr
= value
+ strlen(value
);
1812 i
< marker
->num_values
&& ptr
< (value
+ sizeof(value
) - 1);
1818 strlcpy(ptr
, marker
->values
[i
].string
.text
,
1819 value
+ sizeof(value
) - ptr
);
1824 cupsFilePutConf(fp
, "Attribute", value
);
1827 if (printer
->marker_time
)
1828 cupsFilePrintf(fp
, "Attribute marker-change-time %ld\n",
1829 (long)printer
->marker_time
);
1831 cupsFilePuts(fp
, "</Printer>\n");
1835 * Make IRIX desktop & printer status happy
1838 write_irix_state(printer
);
1847 * 'cupsdSetAuthInfoRequired()' - Set the required authentication info.
1850 int /* O - 1 if value OK, 0 otherwise */
1851 cupsdSetAuthInfoRequired(
1852 cupsd_printer_t
*p
, /* I - Printer */
1853 const char *values
, /* I - Plain text value (or NULL) */
1854 ipp_attribute_t
*attr
) /* I - IPP attribute value (or NULL) */
1856 int i
; /* Looping var */
1859 p
->num_auth_info_required
= 0;
1862 * Do we have a plain text value?
1868 * Yes, grab the keywords...
1871 const char *end
; /* End of current value */
1874 while (*values
&& p
->num_auth_info_required
< 4)
1876 if ((end
= strchr(values
, ',')) == NULL
)
1877 end
= values
+ strlen(values
);
1879 if ((end
- values
) == 4 && !strncmp(values
, "none", 4))
1881 if (p
->num_auth_info_required
!= 0 || *end
)
1884 p
->auth_info_required
[p
->num_auth_info_required
] = "none";
1885 p
->num_auth_info_required
++;
1889 else if ((end
- values
) == 9 && !strncmp(values
, "negotiate", 9))
1891 if (p
->num_auth_info_required
!= 0 || *end
)
1894 p
->auth_info_required
[p
->num_auth_info_required
] = "negotiate";
1895 p
->num_auth_info_required
++;
1897 else if ((end
- values
) == 6 && !strncmp(values
, "domain", 6))
1899 p
->auth_info_required
[p
->num_auth_info_required
] = "domain";
1900 p
->num_auth_info_required
++;
1902 else if ((end
- values
) == 8 && !strncmp(values
, "password", 8))
1904 p
->auth_info_required
[p
->num_auth_info_required
] = "password";
1905 p
->num_auth_info_required
++;
1907 else if ((end
- values
) == 8 && !strncmp(values
, "username", 8))
1909 p
->auth_info_required
[p
->num_auth_info_required
] = "username";
1910 p
->num_auth_info_required
++;
1915 values
= (*end
) ? end
+ 1 : end
;
1918 if (p
->num_auth_info_required
== 0)
1920 p
->auth_info_required
[0] = "none";
1921 p
->num_auth_info_required
= 1;
1925 * Update the printer-type value as needed...
1928 if (p
->num_auth_info_required
> 1 ||
1929 strcmp(p
->auth_info_required
[0], "none"))
1930 p
->type
|= CUPS_PRINTER_AUTHENTICATED
;
1932 p
->type
&= ~CUPS_PRINTER_AUTHENTICATED
;
1938 * Grab values from an attribute instead...
1941 if (!attr
|| attr
->num_values
> 4)
1945 * Update the printer-type value as needed...
1948 if (attr
->num_values
> 1 ||
1949 strcmp(attr
->values
[0].string
.text
, "none"))
1950 p
->type
|= CUPS_PRINTER_AUTHENTICATED
;
1952 p
->type
&= ~CUPS_PRINTER_AUTHENTICATED
;
1954 for (i
= 0; i
< attr
->num_values
; i
++)
1956 if (!strcmp(attr
->values
[i
].string
.text
, "none"))
1958 if (p
->num_auth_info_required
!= 0 || attr
->num_values
!= 1)
1961 p
->auth_info_required
[p
->num_auth_info_required
] = "none";
1962 p
->num_auth_info_required
++;
1966 else if (!strcmp(attr
->values
[i
].string
.text
, "negotiate"))
1968 if (p
->num_auth_info_required
!= 0 || attr
->num_values
!= 1)
1971 p
->auth_info_required
[p
->num_auth_info_required
] = "negotiate";
1972 p
->num_auth_info_required
++;
1976 else if (!strcmp(attr
->values
[i
].string
.text
, "domain"))
1978 p
->auth_info_required
[p
->num_auth_info_required
] = "domain";
1979 p
->num_auth_info_required
++;
1981 else if (!strcmp(attr
->values
[i
].string
.text
, "password"))
1983 p
->auth_info_required
[p
->num_auth_info_required
] = "password";
1984 p
->num_auth_info_required
++;
1986 else if (!strcmp(attr
->values
[i
].string
.text
, "username"))
1988 p
->auth_info_required
[p
->num_auth_info_required
] = "username";
1989 p
->num_auth_info_required
++;
2000 * 'cupsdSetDeviceURI()' - Set the device URI for a printer.
2004 cupsdSetDeviceURI(cupsd_printer_t
*p
, /* I - Printer */
2005 const char *uri
) /* I - Device URI */
2007 char buffer
[1024], /* URI buffer */
2008 *start
, /* Start of data after scheme */
2009 *slash
, /* First slash after scheme:// */
2010 *ptr
; /* Pointer into user@host:port part */
2014 * Set the full device URI..
2017 cupsdSetString(&(p
->device_uri
), uri
);
2020 * Copy the device URI to a temporary buffer so we can sanitize any auth
2024 strlcpy(buffer
, uri
, sizeof(buffer
));
2027 * Find the end of the scheme:// part...
2030 if ((ptr
= strchr(buffer
, ':')) != NULL
)
2032 for (start
= ptr
+ 1; *start
; start
++)
2037 * Find the next slash (/) in the URI...
2040 if ((slash
= strchr(start
, '/')) == NULL
)
2041 slash
= start
+ strlen(start
); /* No slash, point to the end */
2044 * Check for an @ sign before the slash...
2047 if ((ptr
= strchr(start
, '@')) != NULL
&& ptr
< slash
)
2050 * Found an @ sign and it is before the resource part, so we have
2051 * an authentication string. Copy the remaining URI over the
2052 * authentication string...
2055 _cups_strcpy(start
, ptr
+ 1);
2060 * Save the sanitized URI...
2063 cupsdSetString(&(p
->sanitized_device_uri
), buffer
);
2068 * 'cupsdSetPrinterAttr()' - Set a printer attribute.
2072 cupsdSetPrinterAttr(
2073 cupsd_printer_t
*p
, /* I - Printer */
2074 const char *name
, /* I - Attribute name */
2075 char *value
) /* I - Attribute value string */
2077 ipp_attribute_t
*attr
; /* Attribute */
2078 int i
, /* Looping var */
2079 count
; /* Number of values */
2080 char *ptr
; /* Pointer into value */
2081 ipp_tag_t value_tag
; /* Value tag for this attribute */
2085 * Don't allow empty values...
2088 if (!*value
&& strcmp(name
, "marker-message"))
2090 cupsdLogMessage(CUPSD_LOG_ERROR
, "Ignoring empty \"%s\" attribute", name
);
2095 * Count the number of values...
2098 for (count
= 1, ptr
= value
;
2099 (ptr
= strchr(ptr
, ',')) != NULL
;
2103 * Then add or update the attribute as needed...
2106 if (!strcmp(name
, "marker-levels") || !strcmp(name
, "marker-low-levels") ||
2107 !strcmp(name
, "marker-high-levels"))
2113 if ((attr
= ippFindAttribute(p
->attrs
, name
, IPP_TAG_INTEGER
)) != NULL
&&
2114 attr
->num_values
< count
)
2116 ippDeleteAttribute(p
->attrs
, attr
);
2121 attr
->num_values
= count
;
2123 attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
, name
,
2128 cupsdLogMessage(CUPSD_LOG_ERROR
,
2129 "Unable to allocate memory for printer attribute "
2130 "(%d values)", count
);
2134 for (i
= 0; i
< count
; i
++)
2136 if ((ptr
= strchr(value
, ',')) != NULL
)
2139 attr
->values
[i
].integer
= strtol(value
, NULL
, 10);
2148 * Name or keyword values...
2151 if (!strcmp(name
, "marker-types"))
2152 value_tag
= IPP_TAG_KEYWORD
;
2153 else if (!strcmp(name
, "marker-message"))
2154 value_tag
= IPP_TAG_TEXT
;
2156 value_tag
= IPP_TAG_NAME
;
2158 if ((attr
= ippFindAttribute(p
->attrs
, name
, value_tag
)) != NULL
&&
2159 attr
->num_values
< count
)
2161 ippDeleteAttribute(p
->attrs
, attr
);
2167 for (i
= 0; i
< attr
->num_values
; i
++)
2168 _cupsStrFree(attr
->values
[i
].string
.text
);
2170 attr
->num_values
= count
;
2173 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, value_tag
, name
,
2178 cupsdLogMessage(CUPSD_LOG_ERROR
,
2179 "Unable to allocate memory for printer attribute "
2180 "(%d values)", count
);
2184 for (i
= 0; i
< count
; i
++)
2186 if ((ptr
= strchr(value
, ',')) != NULL
)
2189 attr
->values
[i
].string
.text
= _cupsStrAlloc(value
);
2199 * 'cupsdSetPrinterAttrs()' - Set printer attributes based upon the PPD file.
2203 cupsdSetPrinterAttrs(cupsd_printer_t
*p
)/* I - Printer to setup */
2205 int i
, /* Looping var */
2206 length
; /* Length of browse attributes */
2207 char resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
2208 int num_air
; /* Number of auth-info-required values */
2209 const char * const *air
; /* auth-info-required values */
2210 cupsd_location_t
*auth
; /* Pointer to authentication element */
2211 const char *auth_supported
; /* Authentication supported */
2212 ipp_t
*oldattrs
; /* Old printer attributes */
2213 ipp_attribute_t
*attr
; /* Attribute data */
2214 cups_option_t
*option
; /* Current printer option */
2215 char *name
, /* Current user/group name */
2216 *filter
; /* Current filter */
2217 static const char * const air_none
[] =
2218 { /* No authentication */
2221 static const char * const air_userpass
[] =
2222 { /* Basic/Digest authentication */
2228 DEBUG_printf(("cupsdSetPrinterAttrs: entering name = %s, type = %x\n", p
->name
,
2232 * Make sure that we have the common attributes defined...
2236 cupsdCreateCommonData();
2239 * Clear out old filters, if any...
2242 delete_printer_filters(p
);
2245 * Figure out the authentication that is required for the printer.
2248 auth_supported
= "requesting-user-name";
2252 if (p
->num_auth_info_required
> 0 && strcmp(p
->auth_info_required
[0], "none"))
2254 num_air
= p
->num_auth_info_required
;
2255 air
= p
->auth_info_required
;
2257 else if ((p
->type
& CUPS_PRINTER_AUTHENTICATED
) &&
2258 (p
->type
& CUPS_PRINTER_DISCOVERED
))
2264 if (p
->type
& CUPS_PRINTER_CLASS
)
2265 snprintf(resource
, sizeof(resource
), "/classes/%s", p
->name
);
2267 snprintf(resource
, sizeof(resource
), "/printers/%s", p
->name
);
2269 if ((auth
= cupsdFindBest(resource
, HTTP_POST
)) == NULL
||
2270 auth
->type
== CUPSD_AUTH_NONE
)
2271 auth
= cupsdFindPolicyOp(p
->op_policy_ptr
, IPP_PRINT_JOB
);
2275 int auth_type
; /* Authentication type */
2278 if ((auth_type
= auth
->type
) == CUPSD_AUTH_DEFAULT
)
2279 auth_type
= DefaultAuthType
;
2281 if (auth_type
== CUPSD_AUTH_BASIC
|| auth_type
== CUPSD_AUTH_BASICDIGEST
)
2282 auth_supported
= "basic";
2283 else if (auth_type
== CUPSD_AUTH_DIGEST
)
2284 auth_supported
= "digest";
2286 else if (auth_type
== CUPSD_AUTH_NEGOTIATE
)
2287 auth_supported
= "negotiate";
2288 #endif /* HAVE_GSSAPI */
2290 if (!(p
->type
& CUPS_PRINTER_DISCOVERED
))
2292 if (auth_type
!= CUPSD_AUTH_NONE
)
2293 p
->type
|= CUPS_PRINTER_AUTHENTICATED
;
2295 p
->type
&= ~CUPS_PRINTER_AUTHENTICATED
;
2298 else if (!(p
->type
& CUPS_PRINTER_DISCOVERED
))
2299 p
->type
&= ~CUPS_PRINTER_AUTHENTICATED
;
2302 * Create the required IPP attributes for a printer...
2305 oldattrs
= p
->attrs
;
2306 p
->attrs
= ippNew();
2308 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2309 "uri-authentication-supported", NULL
, auth_supported
);
2310 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2311 "uri-security-supported", NULL
, "none");
2312 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
, "printer-name", NULL
,
2314 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-location",
2315 NULL
, p
->location
? p
->location
: "");
2316 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-info",
2317 NULL
, p
->info
? p
->info
: "");
2319 if (cupsArrayCount(p
->users
) > 0)
2322 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2323 "requesting-user-name-denied",
2324 cupsArrayCount(p
->users
), NULL
, NULL
);
2326 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2327 "requesting-user-name-allowed",
2328 cupsArrayCount(p
->users
), NULL
, NULL
);
2330 for (i
= 0, name
= (char *)cupsArrayFirst(p
->users
);
2332 i
++, name
= (char *)cupsArrayNext(p
->users
))
2333 attr
->values
[i
].string
.text
= _cupsStrRetain(name
);
2336 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2337 "job-quota-period", p
->quota_period
);
2338 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2339 "job-k-limit", p
->k_limit
);
2340 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2341 "job-page-limit", p
->page_limit
);
2342 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2343 "auth-info-required", num_air
, NULL
, air
);
2345 if (cupsArrayCount(Banners
) > 0 && !(p
->type
& CUPS_PRINTER_DISCOVERED
))
2348 * Setup the job-sheets-default attribute...
2351 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2352 "job-sheets-default", 2, NULL
, NULL
);
2356 attr
->values
[0].string
.text
= _cupsStrAlloc(Classification
?
2357 Classification
: p
->job_sheets
[0]);
2358 attr
->values
[1].string
.text
= _cupsStrAlloc(Classification
?
2359 Classification
: p
->job_sheets
[1]);
2366 if (p
->type
& CUPS_PRINTER_DISCOVERED
)
2369 * Tell the client this is a remote printer of some type...
2372 if (strchr(p
->uri
, '?'))
2375 * Strip trailing "?options" from URI...
2378 char *ptr
; /* Pointer into URI */
2380 strlcpy(resource
, p
->uri
, sizeof(resource
));
2381 if ((ptr
= strchr(resource
, '?')) != NULL
)
2384 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
2385 "printer-uri-supported", NULL
, resource
);
2388 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
2389 "printer-uri-supported", NULL
, p
->uri
);
2391 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "printer-more-info",
2395 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
2396 "printer-make-and-model", NULL
, p
->make_model
);
2398 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "device-uri", NULL
,
2407 * Assign additional attributes depending on whether this is a printer
2411 if (p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
))
2414 p
->type
&= ~CUPS_PRINTER_OPTIONS
;
2417 * Add class-specific attributes...
2420 if ((p
->type
& CUPS_PRINTER_IMPLICIT
) && p
->num_printers
> 0 &&
2421 p
->printers
[0]->make_model
)
2422 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
2423 "printer-make-and-model", NULL
, p
->printers
[0]->make_model
);
2425 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
2426 "printer-make-and-model", NULL
, "Local Printer Class");
2428 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "device-uri", NULL
,
2429 "file:///dev/null");
2431 if (p
->num_printers
> 0)
2434 * Add a list of member names; URIs are added in copy_printer_attrs...
2437 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2438 "member-names", p
->num_printers
, NULL
, NULL
);
2439 p
->type
|= CUPS_PRINTER_OPTIONS
;
2441 for (i
= 0; i
< p
->num_printers
; i
++)
2444 attr
->values
[i
].string
.text
= _cupsStrRetain(p
->printers
[i
]->name
);
2446 p
->type
&= ~CUPS_PRINTER_OPTIONS
| p
->printers
[i
]->type
;
2453 * Add printer-specific attributes...
2456 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "device-uri", NULL
,
2457 p
->sanitized_device_uri
);
2460 * Assign additional attributes from the PPD file (if any)...
2466 * Add filters for printer...
2469 cupsdSetPrinterReasons(p
, "-cups-missing-filter-warning,"
2470 "cups-insecure-filter-warning");
2472 for (filter
= (char *)cupsArrayFirst(p
->filters
);
2474 filter
= (char *)cupsArrayNext(p
->filters
))
2475 add_printer_filter(p
, p
->filetype
, filter
);
2479 p
->prefiltertype
= mimeAddType(MimeDatabase
, "prefilter", p
->name
);
2481 for (filter
= (char *)cupsArrayFirst(p
->pre_filters
);
2483 filter
= (char *)cupsArrayNext(p
->pre_filters
))
2484 add_printer_filter(p
, p
->prefiltertype
, filter
);
2490 * Copy marker attributes as needed...
2495 ipp_attribute_t
*oldattr
; /* Old attribute */
2498 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-colors",
2499 IPP_TAG_NAME
)) != NULL
)
2501 if ((attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2502 "marker-colors", oldattr
->num_values
, NULL
,
2505 for (i
= 0; i
< oldattr
->num_values
; i
++)
2506 attr
->values
[i
].string
.text
=
2507 _cupsStrRetain(oldattr
->values
[i
].string
.text
);
2511 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-levels",
2512 IPP_TAG_INTEGER
)) != NULL
)
2514 if ((attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2515 "marker-levels", oldattr
->num_values
,
2518 for (i
= 0; i
< oldattr
->num_values
; i
++)
2519 attr
->values
[i
].integer
= oldattr
->values
[i
].integer
;
2523 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-message",
2524 IPP_TAG_TEXT
)) != NULL
)
2525 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "marker-message",
2526 NULL
, oldattr
->values
[0].string
.text
);
2528 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-low-levels",
2529 IPP_TAG_INTEGER
)) != NULL
)
2531 if ((attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2532 "marker-low-levels", oldattr
->num_values
,
2535 for (i
= 0; i
< oldattr
->num_values
; i
++)
2536 attr
->values
[i
].integer
= oldattr
->values
[i
].integer
;
2540 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-high-levels",
2541 IPP_TAG_INTEGER
)) != NULL
)
2543 if ((attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2544 "marker-high-levels", oldattr
->num_values
,
2547 for (i
= 0; i
< oldattr
->num_values
; i
++)
2548 attr
->values
[i
].integer
= oldattr
->values
[i
].integer
;
2552 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-names",
2553 IPP_TAG_NAME
)) != NULL
)
2555 if ((attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2556 "marker-names", oldattr
->num_values
, NULL
,
2559 for (i
= 0; i
< oldattr
->num_values
; i
++)
2560 attr
->values
[i
].string
.text
=
2561 _cupsStrRetain(oldattr
->values
[i
].string
.text
);
2565 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-types",
2566 IPP_TAG_KEYWORD
)) != NULL
)
2568 if ((attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2569 "marker-types", oldattr
->num_values
, NULL
,
2572 for (i
= 0; i
< oldattr
->num_values
; i
++)
2573 attr
->values
[i
].string
.text
=
2574 _cupsStrRetain(oldattr
->values
[i
].string
.text
);
2578 ippDelete(oldattrs
);
2582 * Force sharing off for remote queues...
2585 if (p
->type
& (CUPS_PRINTER_REMOTE
| CUPS_PRINTER_IMPLICIT
))
2590 * Copy the printer options into a browse attributes string we can re-use.
2593 const char *valptr
; /* Pointer into value */
2594 char *attrptr
; /* Pointer into attribute string */
2598 * Free the old browse attributes as needed...
2601 if (p
->browse_attrs
)
2602 free(p
->browse_attrs
);
2605 * Compute the length of all attributes + job-sheets, lease-duration,
2606 * and BrowseLocalOptions.
2609 for (length
= 1, i
= p
->num_options
, option
= p
->options
;
2613 length
+= strlen(option
->name
) + 2;
2617 for (valptr
= option
->value
; *valptr
; valptr
++)
2618 if (strchr(" \"\'\\", *valptr
))
2625 length
+= 13 + strlen(p
->job_sheets
[0]) + strlen(p
->job_sheets
[1]);
2627 if (BrowseLocalOptions
)
2628 length
+= 12 + strlen(BrowseLocalOptions
);
2631 * Allocate the new string...
2634 if ((p
->browse_attrs
= calloc(1, length
)) == NULL
)
2635 cupsdLogMessage(CUPSD_LOG_ERROR
,
2636 "Unable to allocate %d bytes for browse data!",
2641 * Got the allocated string, now copy the options and attributes over...
2644 sprintf(p
->browse_attrs
, "job-sheets=%s,%s lease-duration=%d",
2645 p
->job_sheets
[0], p
->job_sheets
[1], BrowseTimeout
);
2646 attrptr
= p
->browse_attrs
+ strlen(p
->browse_attrs
);
2648 if (BrowseLocalOptions
)
2650 sprintf(attrptr
, " ipp-options=%s", BrowseLocalOptions
);
2651 attrptr
+= strlen(attrptr
);
2654 for (i
= p
->num_options
, option
= p
->options
;
2659 strcpy(attrptr
, option
->name
);
2660 attrptr
+= strlen(attrptr
);
2666 for (valptr
= option
->value
; *valptr
; valptr
++)
2668 if (strchr(" \"\'\\", *valptr
))
2671 *attrptr
++ = *valptr
;
2679 * Populate the document-format-supported attribute...
2682 add_printer_formats(p
);
2684 DEBUG_printf(("cupsdSetPrinterAttrs: leaving name = %s, type = %x\n", p
->name
,
2688 * Add name-default attributes...
2691 add_printer_defaults(p
);
2695 * Write the IRIX printer config and status files...
2698 write_irix_config(p
);
2699 write_irix_state(p
);
2703 * Let the browse protocols reflect the change
2706 cupsdRegisterPrinter(p
);
2711 * 'cupsdSetPrinterReasons()' - Set/update the reasons strings.
2714 int /* O - 1 if something changed, 0 otherwise */
2715 cupsdSetPrinterReasons(
2716 cupsd_printer_t
*p
, /* I - Printer */
2717 const char *s
) /* I - Reasons strings */
2719 int i
, /* Looping var */
2720 changed
= 0; /* Did something change? */
2721 const char *sptr
; /* Pointer into reasons */
2722 char reason
[255], /* Reason string */
2723 *rptr
; /* Pointer into reason */
2726 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
2727 "cupsdSetPrinterReasons(p=%p(%s),s=\"%s\"", p
, p
->name
, s
);
2729 if (s
[0] == '-' || s
[0] == '+')
2732 * Add/remove reasons...
2740 * Replace reasons...
2745 for (i
= 0; i
< p
->num_reasons
; i
++)
2746 _cupsStrFree(p
->reasons
[i
]);
2754 if (!strcmp(s
, "none"))
2758 * Loop through all of the reasons...
2764 * Skip leading whitespace and commas...
2767 while (isspace(*sptr
& 255) || *sptr
== ',')
2770 for (rptr
= reason
; *sptr
&& !isspace(*sptr
& 255) && *sptr
!= ','; sptr
++)
2771 if (rptr
< (reason
+ sizeof(reason
) - 1))
2785 for (i
= 0; i
< p
->num_reasons
; i
++)
2786 if (!strcmp(reason
, p
->reasons
[i
]))
2789 * Found a match, so remove it...
2794 _cupsStrFree(p
->reasons
[i
]);
2796 if (i
< p
->num_reasons
)
2797 memmove(p
->reasons
+ i
, p
->reasons
+ i
+ 1,
2798 (p
->num_reasons
- i
) * sizeof(char *));
2800 if (!strcmp(reason
, "paused") && p
->state
== IPP_PRINTER_STOPPED
)
2801 cupsdSetPrinterState(p
, IPP_PRINTER_IDLE
, 1);
2803 if (strcmp(reason
, "connecting-to-device"))
2808 else if (p
->num_reasons
< (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
2814 for (i
= 0; i
< p
->num_reasons
; i
++)
2815 if (!strcmp(reason
, p
->reasons
[i
]))
2818 if (i
>= p
->num_reasons
)
2820 if (i
>= (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
2822 cupsdLogMessage(CUPSD_LOG_ALERT
,
2823 "Too many printer-state-reasons values for %s (%d)",
2828 p
->reasons
[i
] = _cupsStrAlloc(reason
);
2832 if (!strcmp(reason
, "paused") && p
->state
!= IPP_PRINTER_STOPPED
)
2833 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, 1);
2835 if (strcmp(reason
, "connecting-to-device"))
2846 * 'cupsdSetPrinterState()' - Update the current state of a printer.
2850 cupsdSetPrinterState(
2851 cupsd_printer_t
*p
, /* I - Printer to change */
2852 ipp_pstate_t s
, /* I - New state */
2853 int update
) /* I - Update printers.conf? */
2855 ipp_pstate_t old_state
; /* Old printer state */
2856 static const char * const printer_states
[] =
2857 { /* State strings */
2865 * Can't set status of remote printers...
2868 if (p
->type
& CUPS_PRINTER_DISCOVERED
)
2872 * Set the new state...
2875 old_state
= p
->state
;
2880 cupsdAddEvent(s
== IPP_PRINTER_STOPPED
? CUPSD_EVENT_PRINTER_STOPPED
:
2881 CUPSD_EVENT_PRINTER_STATE
, p
, NULL
,
2882 "%s \"%s\" state changed to %s.",
2883 (p
->type
& CUPS_PRINTER_CLASS
) ? "Class" : "Printer",
2884 p
->name
, printer_states
[p
->state
- IPP_PRINTER_IDLE
]);
2887 * Let the browse code know this needs to be updated...
2891 p
->state_time
= time(NULL
);
2895 write_irix_state(p
);
2900 * Set/clear the paused reason as needed...
2903 if (s
== IPP_PRINTER_STOPPED
)
2904 cupsdSetPrinterReasons(p
, "+paused");
2906 cupsdSetPrinterReasons(p
, "-paused");
2909 * Clear the message for the queue when going to processing...
2912 if (s
== IPP_PRINTER_PROCESSING
)
2913 p
->state_message
[0] = '\0';
2916 * Update the printer history...
2919 cupsdAddPrinterHistory(p
);
2922 * Let the browse protocols reflect the change...
2926 cupsdRegisterPrinter(p
);
2929 * Save the printer configuration if a printer goes from idle or processing
2930 * to stopped (or visa-versa)...
2934 (old_state
== IPP_PRINTER_STOPPED
) != (s
== IPP_PRINTER_STOPPED
))
2940 * 'cupsdStopPrinter()' - Stop a printer from printing any jobs...
2944 cupsdStopPrinter(cupsd_printer_t
*p
, /* I - Printer to stop */
2945 int update
)/* I - Update printers.conf? */
2948 * Set the printer state...
2951 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, update
);
2954 * See if we have a job printing on this printer...
2957 if (p
->job
&& p
->job
->state_value
== IPP_JOB_PROCESSING
)
2958 cupsdSetJobState(p
->job
, IPP_JOB_PENDING
, CUPSD_JOB_DEFAULT
,
2959 "Job stopped due to printer being paused.");
2964 * 'cupsdUpdatePrinterPPD()' - Update keywords in a printer's PPD file.
2967 int /* O - 1 if successful, 0 otherwise */
2968 cupsdUpdatePrinterPPD(
2969 cupsd_printer_t
*p
, /* I - Printer */
2970 int num_keywords
, /* I - Number of keywords */
2971 cups_option_t
*keywords
) /* I - Keywords */
2973 int i
; /* Looping var */
2974 cups_file_t
*src
, /* Original file */
2975 *dst
; /* New file */
2976 char srcfile
[1024], /* Original filename */
2977 dstfile
[1024], /* New filename */
2978 line
[1024], /* Line from file */
2979 keystring
[41]; /* Keyword from line */
2980 cups_option_t
*keyword
; /* Current keyword */
2983 cupsdLogMessage(CUPSD_LOG_INFO
, "Updating keywords in PPD file for %s...",
2987 * Get the old and new PPD filenames...
2990 snprintf(srcfile
, sizeof(srcfile
), "%s/ppd/%s.ppd.O", ServerRoot
, p
->name
);
2991 snprintf(dstfile
, sizeof(srcfile
), "%s/ppd/%s.ppd", ServerRoot
, p
->name
);
2994 * Rename the old file and open the old and new...
2997 if (rename(dstfile
, srcfile
))
2999 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to backup PPD file for %s: %s",
3000 p
->name
, strerror(errno
));
3004 if ((src
= cupsFileOpen(srcfile
, "r")) == NULL
)
3006 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to open PPD file \"%s\": %s",
3007 srcfile
, strerror(errno
));
3008 rename(srcfile
, dstfile
);
3012 if ((dst
= cupsFileOpen(dstfile
, "w")) == NULL
)
3014 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to create PPD file \"%s\": %s",
3015 dstfile
, strerror(errno
));
3017 rename(srcfile
, dstfile
);
3022 * Copy the first line and then write out all of the keywords...
3025 if (!cupsFileGets(src
, line
, sizeof(line
)))
3027 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to read PPD file \"%s\": %s",
3028 srcfile
, strerror(errno
));
3031 rename(srcfile
, dstfile
);
3035 cupsFilePrintf(dst
, "%s\n", line
);
3037 for (i
= num_keywords
, keyword
= keywords
; i
> 0; i
--, keyword
++)
3039 cupsdLogMessage(CUPSD_LOG_DEBUG
, "*%s: %s", keyword
->name
, keyword
->value
);
3040 cupsFilePrintf(dst
, "*%s: %s\n", keyword
->name
, keyword
->value
);
3044 * Then copy the rest of the PPD file, dropping any keywords we changed.
3047 while (cupsFileGets(src
, line
, sizeof(line
)))
3050 * Skip keywords we've already set...
3053 if (sscanf(line
, "*%40[^:]:", keystring
) == 1 &&
3054 cupsGetOption(keystring
, num_keywords
, keywords
))
3058 * Otherwise write the line...
3061 cupsFilePrintf(dst
, "%s\n", line
);
3065 * Close files and return...
3076 * 'cupsdUpdatePrinters()' - Update printers after a partial reload.
3080 cupsdUpdatePrinters(void)
3082 cupsd_printer_t
*p
; /* Current printer */
3086 * Loop through the printers and recreate the printer attributes
3087 * for any local printers since the policy and/or access control
3088 * stuff may have changed. Also, if browsing is disabled, remove
3089 * any remote printers...
3092 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3094 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3097 * Remove remote printers if we are no longer browsing...
3101 (p
->type
& (CUPS_PRINTER_IMPLICIT
| CUPS_PRINTER_DISCOVERED
)))
3103 if (p
->type
& CUPS_PRINTER_IMPLICIT
)
3104 cupsArrayRemove(ImplicitPrinters
, p
);
3106 cupsArraySave(Printers
);
3107 cupsdDeletePrinter(p
, 0);
3108 cupsArrayRestore(Printers
);
3113 * Update the operation policy pointer...
3116 if ((p
->op_policy_ptr
= cupsdFindPolicy(p
->op_policy
)) == NULL
)
3117 p
->op_policy_ptr
= DefaultPolicyPtr
;
3120 * Update printer attributes as needed...
3123 if (!(p
->type
& CUPS_PRINTER_DISCOVERED
))
3124 cupsdSetPrinterAttrs(p
);
3130 * 'cupsdValidateDest()' - Validate a printer/class destination.
3133 const char * /* O - Printer or class name */
3135 const char *uri
, /* I - Printer URI */
3136 cups_ptype_t
*dtype
, /* O - Type (printer or class) */
3137 cupsd_printer_t
**printer
) /* O - Printer pointer */
3139 cupsd_printer_t
*p
; /* Current printer */
3140 char localname
[1024],/* Localized hostname */
3141 *lptr
, /* Pointer into localized hostname */
3142 *sptr
, /* Pointer into server name */
3143 *rptr
, /* Pointer into resource */
3144 scheme
[32], /* Scheme portion of URI */
3145 username
[64], /* Username portion of URI */
3146 hostname
[HTTP_MAX_HOST
],
3147 /* Host portion of URI */
3148 resource
[HTTP_MAX_URI
];
3149 /* Resource portion of URI */
3150 int port
; /* Port portion of URI */
3153 DEBUG_printf(("cupsdValidateDest(uri=\"%s\", dtype=%p, printer=%p)\n", uri
,
3157 * Initialize return values...
3164 *dtype
= (cups_ptype_t
)0;
3167 * Pull the hostname and resource from the URI...
3170 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
, scheme
, sizeof(scheme
),
3171 username
, sizeof(username
), hostname
, sizeof(hostname
),
3172 &port
, resource
, sizeof(resource
));
3175 * See if the resource is a class or printer...
3178 if (!strncmp(resource
, "/classes/", 9))
3184 rptr
= resource
+ 9;
3186 else if (!strncmp(resource
, "/printers/", 10))
3192 rptr
= resource
+ 10;
3197 * Bad resource name...
3204 * See if the printer or class name exists...
3207 p
= cupsdFindDest(rptr
);
3209 if (p
== NULL
&& strchr(rptr
, '@') == NULL
)
3217 *dtype
= p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
|
3218 CUPS_PRINTER_REMOTE
| CUPS_PRINTER_DISCOVERED
);
3224 * Change localhost to the server name...
3227 if (!strcasecmp(hostname
, "localhost"))
3228 strlcpy(hostname
, ServerName
, sizeof(hostname
));
3230 strlcpy(localname
, hostname
, sizeof(localname
));
3232 if (!strcasecmp(hostname
, ServerName
))
3235 * Localize the hostname...
3238 lptr
= strchr(localname
, '.');
3239 sptr
= strchr(ServerName
, '.');
3241 if (sptr
!= NULL
&& lptr
!= NULL
)
3244 * Strip the common domain name components...
3247 while (lptr
!= NULL
)
3249 if (!strcasecmp(lptr
, sptr
))
3255 lptr
= strchr(lptr
+ 1, '.');
3260 DEBUG_printf(("localized hostname is \"%s\"...\n", localname
));
3263 * Find a matching printer or class...
3266 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3268 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3269 if (!strcasecmp(p
->hostname
, localname
) &&
3270 !strcasecmp(p
->name
, rptr
))
3276 *dtype
= p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
|
3277 CUPS_PRINTER_REMOTE
| CUPS_PRINTER_DISCOVERED
);
3287 * 'cupsdWritePrintcap()' - Write a pseudo-printcap file for older applications
3292 cupsdWritePrintcap(void)
3294 int i
; /* Looping var */
3295 cups_file_t
*fp
; /* Printcap file */
3296 cupsd_printer_t
*p
; /* Current printer */
3301 * Update the IRIX printer state for the default printer; if
3302 * no printers remain, then the default printer file will be
3306 write_irix_state(DefaultPrinter
);
3310 * See if we have a printcap file; if not, don't bother writing it.
3313 if (!Printcap
|| !*Printcap
)
3316 cupsdLogMessage(CUPSD_LOG_INFO
, "Generating printcap %s...", Printcap
);
3319 * Open the printcap file...
3322 if ((fp
= cupsFileOpen(Printcap
, "w")) == NULL
)
3326 * Put a comment header at the top so that users will know where the
3327 * data has come from...
3330 if (PrintcapFormat
!= PRINTCAP_PLIST
)
3331 cupsFilePrintf(fp
, "# This file was automatically generated by cupsd(8) "
3333 "# %s/printers.conf file. All changes to this file\n"
3334 "# will be lost.\n", ServerRoot
);
3337 * Write a new printcap with the current list of printers.
3340 switch (PrintcapFormat
)
3344 * Each printer is put in the file as:
3354 cupsFilePrintf(fp
, "%s|%s:rm=%s:rp=%s:\n", DefaultPrinter
->name
,
3355 DefaultPrinter
->info
, ServerName
,
3356 DefaultPrinter
->name
);
3358 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3360 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3361 if (p
!= DefaultPrinter
)
3362 cupsFilePrintf(fp
, "%s|%s:rm=%s:rp=%s:\n", p
->name
, p
->info
,
3363 ServerName
, p
->name
);
3366 case PRINTCAP_PLIST
:
3368 * Each printer is written as a dictionary in a plist file.
3369 * Currently the printer-name, printer-info, printer-is-accepting-jobs,
3370 * printer-location, printer-make-and-model, printer-state,
3371 * printer-state-reasons, printer-type, and (sanitized) device-uri.
3374 cupsFilePuts(fp
, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
3375 "<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD "
3376 "PLIST 1.0//EN\" \"http://www.apple.com/DTDs/"
3377 "PropertyList-1.0.dtd\">\n"
3378 "<plist version=\"1.0\">\n"
3381 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3383 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3385 cupsFilePuts(fp
, "\t<dict>\n"
3386 "\t\t<key>printer-name</key>\n"
3388 write_xml_string(fp
, p
->name
);
3389 cupsFilePuts(fp
, "</string>\n"
3390 "\t\t<key>printer-info</key>\n"
3392 write_xml_string(fp
, p
->info
);
3393 cupsFilePrintf(fp
, "</string>\n"
3394 "\t\t<key>printer-is-accepting-jobs</key>\n"
3396 "\t\t<key>printer-location</key>\n"
3397 "\t\t<string>", p
->accepting
? "true" : "false");
3398 write_xml_string(fp
, p
->location
);
3399 cupsFilePuts(fp
, "</string>\n"
3400 "\t\t<key>printer-make-and-model</key>\n"
3402 write_xml_string(fp
, p
->make_model
);
3403 cupsFilePrintf(fp
, "</string>\n"
3404 "\t\t<key>printer-state</key>\n"
3405 "\t\t<integer>%d</integer>\n"
3406 "\t\t<key>printer-state-reasons</key>\n"
3407 "\t\t<array>\n", p
->state
);
3408 for (i
= 0; i
< p
->num_reasons
; i
++)
3410 cupsFilePuts(fp
, "\t\t\t<string>");
3411 write_xml_string(fp
, p
->reasons
[i
]);
3412 cupsFilePuts(fp
, "</string>\n");
3414 cupsFilePrintf(fp
, "\t\t</array>\n"
3415 "\t\t<key>printer-type</key>\n"
3416 "\t\t<integer>%d</integer>\n"
3417 "\t\t<key>device-uri</key>\n"
3418 "\t\t<string>", p
->type
);
3419 write_xml_string(fp
, p
->sanitized_device_uri
);
3420 cupsFilePuts(fp
, "</string>\n"
3423 cupsFilePuts(fp
, "</array>\n"
3427 case PRINTCAP_SOLARIS
:
3429 * Each printer is put in the file as:
3431 * _all:all=Printer1,Printer2,Printer3,...,PrinterN
3432 * _default:use=DefaultPrinter
3434 * :bsdaddr=ServerName,Printer1:\
3435 * :description=Description:
3437 * :bsdaddr=ServerName,Printer2:\
3438 * :description=Description:
3440 * :bsdaddr=ServerName,Printer3:\
3441 * :description=Description:
3444 * :bsdaddr=ServerName,PrinterN:\
3445 * :description=Description:
3448 cupsFilePuts(fp
, "_all:all=");
3449 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3451 p
= (cupsd_printer_t
*)cupsArrayCurrent(Printers
))
3452 cupsFilePrintf(fp
, "%s%c", p
->name
,
3453 cupsArrayNext(Printers
) ? ',' : '\n');
3456 cupsFilePrintf(fp
, "_default:use=%s\n", DefaultPrinter
->name
);
3458 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3460 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3461 cupsFilePrintf(fp
, "%s:\\\n"
3462 "\t:bsdaddr=%s,%s:\\\n"
3463 "\t:description=%s:\n",
3464 p
->name
, ServerName
, p
->name
,
3465 p
->info
? p
->info
: "");
3478 * 'add_printer_defaults()' - Add name-default attributes to the printer attributes.
3482 add_printer_defaults(cupsd_printer_t
*p
)/* I - Printer */
3484 int i
; /* Looping var */
3485 int num_options
; /* Number of default options */
3486 cups_option_t
*options
, /* Default options */
3487 *option
; /* Current option */
3488 char name
[256]; /* name-default */
3492 * Maintain a common array of default attribute names...
3495 if (!CommonDefaults
)
3497 CommonDefaults
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
3499 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("copies-default"));
3500 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("document-format-default"));
3501 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("finishings-default"));
3502 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-hold-until-default"));
3503 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-priority-default"));
3504 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-sheets-default"));
3505 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("media-col-default"));
3506 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("number-up-default"));
3507 cupsArrayAdd(CommonDefaults
,
3508 _cupsStrAlloc("orientation-requested-default"));
3512 * Add all of the default options from the .conf files...
3515 for (num_options
= 0, options
= NULL
, i
= p
->num_options
, option
= p
->options
;
3519 if (strcmp(option
->name
, "ipp-options") &&
3520 strcmp(option
->name
, "job-sheets") &&
3521 strcmp(option
->name
, "lease-duration"))
3523 snprintf(name
, sizeof(name
), "%s-default", option
->name
);
3524 num_options
= cupsAddOption(name
, option
->value
, num_options
, &options
);
3526 if (!cupsArrayFind(CommonDefaults
, name
))
3527 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc(name
));
3532 * Convert options to IPP attributes...
3535 cupsEncodeOptions2(p
->attrs
, num_options
, options
, IPP_TAG_PRINTER
);
3536 cupsFreeOptions(num_options
, options
);
3539 * Add standard -default attributes as needed...
3542 if (!cupsGetOption("copies", p
->num_options
, p
->options
))
3543 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
, "copies-default",
3546 if (!cupsGetOption("document-format", p
->num_options
, p
->options
))
3547 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_MIMETYPE
,
3548 "document-format-default", NULL
, "application/octet-stream");
3550 if (!cupsGetOption("job-hold-until", p
->num_options
, p
->options
))
3551 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3552 "job-hold-until-default", NULL
, "no-hold");
3554 if (!cupsGetOption("job-priority", p
->num_options
, p
->options
))
3555 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3556 "job-priority-default", 50);
3558 if (!cupsGetOption("number-up", p
->num_options
, p
->options
))
3559 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3560 "number-up-default", 1);
3562 if (!cupsGetOption("notify-lease-duration", p
->num_options
, p
->options
))
3563 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3564 "notify-lease-duration-default", DefaultLeaseDuration
);
3566 if (!cupsGetOption("notify-events", p
->num_options
, p
->options
))
3567 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3568 "notify-events-default", NULL
, "job-completed");
3570 if (!cupsGetOption("orientation-requested", p
->num_options
, p
->options
))
3571 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NOVALUE
,
3572 "orientation-requested-default", NULL
, NULL
);
3574 if (!cupsGetOption("print-quality", p
->num_options
, p
->options
))
3575 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
3576 "print-quality-default", IPP_QUALITY_NORMAL
);
3581 * 'add_printer_filter()' - Add a MIME filter for a printer.
3586 cupsd_printer_t
*p
, /* I - Printer to add to */
3587 mime_type_t
*filtertype
, /* I - Filter or prefilter MIME type */
3588 const char *filter
) /* I - Filter to add */
3590 char super
[MIME_MAX_SUPER
], /* Super-type for filter */
3591 type
[MIME_MAX_TYPE
], /* Type for filter */
3592 program
[1024]; /* Program/filter name */
3593 int cost
; /* Cost of filter */
3594 mime_type_t
*temptype
; /* MIME type looping var */
3595 char filename
[1024], /* Full filter filename */
3596 *dirsep
; /* Pointer to directory separator */
3597 struct stat fileinfo
; /* File information */
3601 * Parse the filter string; it should be in the following format:
3603 * super/type cost program
3606 if (sscanf(filter
, "%15[^/]/%31s%d%*[ \t]%1023[^\n]", super
, type
, &cost
,
3609 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: invalid filter string \"%s\"!",
3615 * See if the filter program exists; if not, stop the printer and flag
3619 if (strcmp(program
, "-"))
3621 if (program
[0] == '/')
3622 strlcpy(filename
, program
, sizeof(filename
));
3624 snprintf(filename
, sizeof(filename
), "%s/filter/%s", ServerBin
, program
);
3626 if (stat(filename
, &fileinfo
))
3628 memset(&fileinfo
, 0, sizeof(fileinfo
));
3630 snprintf(p
->state_message
, sizeof(p
->state_message
),
3631 "Filter \"%s\" for printer \"%s\" not available: %s",
3632 filename
, p
->name
, strerror(errno
));
3633 cupsdSetPrinterReasons(p
, "+cups-missing-filter-warning");
3635 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s", p
->state_message
);
3639 * When running as root, do additional security checks...
3645 * Only use filters that are owned by root and do not have world write
3649 if (fileinfo
.st_uid
|| (fileinfo
.st_mode
& (S_ISUID
| S_IWOTH
)) != 0)
3651 if (fileinfo
.st_uid
)
3652 snprintf(p
->state_message
, sizeof(p
->state_message
),
3653 "Filter \"%s\" for printer \"%s\" not owned by root",
3656 snprintf(p
->state_message
, sizeof(p
->state_message
),
3657 "Filter \"%s\" for printer \"%s\" has insecure permissions "
3658 "(0%o)", filename
, p
->name
, fileinfo
.st_mode
);
3660 cupsdSetPrinterReasons(p
, "+cups-insecure-filter-warning");
3662 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s", p
->state_message
);
3664 else if (fileinfo
.st_mode
)
3667 * Similarly, check that the parent directory is also owned by root and
3668 * does not have world write permissions.
3671 if ((dirsep
= strrchr(filename
, '/')) != NULL
)
3674 if (!stat(filename
, &fileinfo
) &&
3676 (fileinfo
.st_mode
& (S_ISUID
| S_IWOTH
)) != 0))
3678 if (fileinfo
.st_uid
)
3679 snprintf(p
->state_message
, sizeof(p
->state_message
),
3680 "Filter directory \"%s\" for printer \"%s\" not owned by "
3681 "root", filename
, p
->name
);
3683 snprintf(p
->state_message
, sizeof(p
->state_message
),
3684 "Filter directory \"%s\" for printer \"%s\" has insecure "
3685 "permissions (0%o)", filename
, p
->name
, fileinfo
.st_mode
);
3687 cupsdSetPrinterReasons(p
, "+cups-insecure-filter-warning");
3689 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s", p
->state_message
);
3696 * Add the filter to the MIME database, supporting wildcards as needed...
3699 for (temptype
= mimeFirstType(MimeDatabase
);
3701 temptype
= mimeNextType(MimeDatabase
))
3702 if (((super
[0] == '*' && strcasecmp(temptype
->super
, "printer")) ||
3703 !strcasecmp(temptype
->super
, super
)) &&
3704 (type
[0] == '*' || !strcasecmp(temptype
->type
, type
)))
3706 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3707 "add_printer_filter: %s: adding filter %s/%s %s/%s %d %s",
3708 p
->name
, temptype
->super
, temptype
->type
,
3709 filtertype
->super
, filtertype
->type
,
3711 mimeAddFilter(MimeDatabase
, temptype
, filtertype
, cost
, program
);
3717 * 'add_printer_formats()' - Add document-format-supported values for a printer.
3721 add_printer_formats(cupsd_printer_t
*p
) /* I - Printer */
3723 int i
; /* Looping var */
3724 mime_type_t
*type
; /* Current MIME type */
3725 cups_array_t
*filters
; /* Filters */
3726 ipp_attribute_t
*attr
; /* document-format-supported attribute */
3727 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
3728 /* MIME type name */
3732 * Raw (and remote) queues advertise all of the supported MIME
3736 cupsArrayDelete(p
->filetypes
);
3737 p
->filetypes
= NULL
;
3741 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
,
3742 (ipp_tag_t
)(IPP_TAG_MIMETYPE
| IPP_TAG_COPY
),
3743 "document-format-supported", NumMimeTypes
, NULL
, MimeTypes
);
3748 * Otherwise, loop through the supported MIME types and see if there
3749 * are filters for them...
3752 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_printer_formats: %d types, %d filters",
3753 mimeNumTypes(MimeDatabase
), mimeNumFilters(MimeDatabase
));
3755 p
->filetypes
= cupsArrayNew(NULL
, NULL
);
3757 for (type
= mimeFirstType(MimeDatabase
);
3759 type
= mimeNextType(MimeDatabase
))
3761 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
3763 if ((filters
= mimeFilter(MimeDatabase
, type
, p
->filetype
, NULL
)) != NULL
)
3765 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3766 "add_printer_formats: %s: %s needs %d filters",
3767 p
->name
, mimetype
, cupsArrayCount(filters
));
3769 cupsArrayDelete(filters
);
3770 cupsArrayAdd(p
->filetypes
, type
);
3773 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3774 "add_printer_formats: %s: %s not supported",
3779 * Add the file formats that can be filtered...
3782 if ((type
= mimeType(MimeDatabase
, "application", "octet-stream")) == NULL
||
3783 !cupsArrayFind(p
->filetypes
, type
))
3788 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3789 "add_printer_formats: %s: %d supported types",
3790 p
->name
, cupsArrayCount(p
->filetypes
) + i
);
3792 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_MIMETYPE
,
3793 "document-format-supported",
3794 cupsArrayCount(p
->filetypes
) + i
, NULL
, NULL
);
3797 attr
->values
[0].string
.text
= _cupsStrAlloc("application/octet-stream");
3799 for (type
= (mime_type_t
*)cupsArrayFirst(p
->filetypes
);
3801 i
++, type
= (mime_type_t
*)cupsArrayNext(p
->filetypes
))
3803 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
3805 attr
->values
[i
].string
.text
= _cupsStrAlloc(mimetype
);
3810 char pdl
[1024]; /* Buffer to build pdl list */
3811 mime_filter_t
*filter
; /* MIME filter looping var */
3815 * We only support raw printing if this is not a Tioga PrintJobMgr based
3816 * queue and if application/octet-stream is a known type...
3819 for (filter
= (mime_filter_t
*)cupsArrayFirst(MimeDatabase
->filters
);
3821 filter
= (mime_filter_t
*)cupsArrayNext(MimeDatabase
->filters
))
3823 if (filter
->dst
== p
->filetype
&& filter
->filter
&&
3824 strstr(filter
->filter
, "PrintJobMgr"))
3830 if (!filter
&& mimeType(MimeDatabase
, "application", "octet-stream"))
3831 strlcat(pdl
, "application/octet-stream,", sizeof(pdl
));
3834 * Then list a bunch of formats that are supported by the printer...
3837 for (type
= (mime_type_t
*)cupsArrayFirst(p
->filetypes
);
3839 type
= (mime_type_t
*)cupsArrayNext(p
->filetypes
))
3841 if (!strcasecmp(type
->super
, "application"))
3843 if (!strcasecmp(type
->type
, "pdf"))
3844 strlcat(pdl
, "application/pdf,", sizeof(pdl
));
3845 else if (!strcasecmp(type
->type
, "postscript"))
3846 strlcat(pdl
, "application/postscript,", sizeof(pdl
));
3848 else if (!strcasecmp(type
->super
, "image"))
3850 if (!strcasecmp(type
->type
, "jpeg"))
3851 strlcat(pdl
, "image/jpeg,", sizeof(pdl
));
3852 else if (!strcasecmp(type
->type
, "png"))
3853 strlcat(pdl
, "image/png,", sizeof(pdl
));
3858 pdl
[strlen(pdl
) - 1] = '\0'; /* Remove trailing comma */
3860 cupsdSetString(&p
->pdl
, pdl
);
3862 #endif /* HAVE_DNSSD */
3867 * 'add_string_array()' - Add a string to an array of CUPS strings.
3871 add_string_array(cups_array_t
**a
, /* I - Array */
3872 const char *s
) /* I - String */
3875 *a
= cupsArrayNew(NULL
, NULL
);
3877 cupsArrayAdd(*a
, _cupsStrAlloc(s
));
3882 * 'compare_printers()' - Compare two printers.
3885 static int /* O - Result of comparison */
3886 compare_printers(void *first
, /* I - First printer */
3887 void *second
, /* I - Second printer */
3888 void *data
) /* I - App data (not used) */
3890 return (strcasecmp(((cupsd_printer_t
*)first
)->name
,
3891 ((cupsd_printer_t
*)second
)->name
));
3896 * 'delete_printer_filters()' - Delete all MIME filters for a printer.
3900 delete_printer_filters(
3901 cupsd_printer_t
*p
) /* I - Printer to remove from */
3903 mime_filter_t
*filter
; /* MIME filter looping var */
3907 * Range check input...
3914 * Remove all filters from the MIME database that have a destination
3915 * type == printer...
3918 for (filter
= mimeFirstFilter(MimeDatabase
);
3920 filter
= mimeNextFilter(MimeDatabase
))
3921 if (filter
->dst
== p
->filetype
|| filter
->dst
== p
->prefiltertype
)
3924 * Delete the current filter...
3927 mimeDeleteFilter(MimeDatabase
, filter
);
3930 cupsdSetPrinterReasons(p
, "-cups-insecure-filter-warning"
3931 ",cups-missing-filter-warning");
3936 * 'delete_string_array()' - Delete an array of CUPS strings.
3940 delete_string_array(cups_array_t
**a
) /* I - Array */
3942 char *ptr
; /* Current string */
3945 for (ptr
= (char *)cupsArrayFirst(*a
);
3947 ptr
= (char *)cupsArrayNext(*a
))
3950 cupsArrayDelete(*a
);
3956 * 'dirty_printer()' - Mark config and state files dirty for the specified
3961 dirty_printer(cupsd_printer_t
*p
) /* I - Printer */
3963 if (p
->type
& CUPS_PRINTER_DISCOVERED
)
3964 cupsdMarkDirty(CUPSD_DIRTY_REMOTE
);
3965 else if (p
->type
& CUPS_PRINTER_CLASS
)
3966 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
3968 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
3970 if (PrintcapFormat
== PRINTCAP_PLIST
)
3971 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
3976 * 'load_ppd()' - Load a cached PPD file, updating the cache as needed.
3980 load_ppd(cupsd_printer_t
*p
) /* I - Printer */
3982 int i
, j
, k
; /* Looping vars */
3983 cups_file_t
*cache
; /* IPP cache file */
3984 char cache_name
[1024]; /* IPP cache filename */
3985 struct stat cache_info
; /* IPP cache file info */
3986 char pwg_name
[1024]; /* PWG cache filename */
3987 struct stat pwg_info
; /* PWG cache file info */
3988 ppd_file_t
*ppd
; /* PPD file */
3989 char ppd_name
[1024]; /* PPD filename */
3990 struct stat ppd_info
; /* PPD file info */
3991 int num_media
; /* Number of media options */
3992 ppd_size_t
*size
; /* Current PPD size */
3993 ppd_option_t
*duplex
, /* Duplex option */
3994 *output_bin
, /* OutputBin option */
3995 *output_mode
, /* OutputMode option */
3996 *resolution
; /* (Set|JCL|)Resolution option */
3997 ppd_choice_t
*choice
, /* Current PPD choice */
3998 *input_slot
, /* Current input slot */
3999 *media_type
; /* Current media type */
4000 ppd_attr_t
*ppd_attr
; /* PPD attribute */
4001 int xdpi
, /* Horizontal resolution */
4002 ydpi
; /* Vertical resolution */
4003 const char *resptr
; /* Pointer into resolution keyword */
4004 _pwg_size_t
*pwgsize
; /* Current PWG size */
4005 _pwg_map_t
*pwgsource
, /* Current PWG source */
4006 *pwgtype
; /* Current PWG type */
4007 ipp_attribute_t
*attr
; /* Attribute data */
4008 ipp_value_t
*val
; /* Attribute value */
4009 int num_finishings
, /* Number of finishings */
4010 finishings
[5]; /* finishings-supported values */
4011 int num_qualities
, /* Number of print-quality values */
4012 qualities
[3]; /* print-quality values */
4013 int num_margins
, /* Number of media-*-margin-supported values */
4014 margins
[16]; /* media-*-margin-supported values */
4015 static const char * const sides
[3] = /* sides-supported values */
4018 "two-sided-long-edge",
4019 "two-sided-short-edge"
4021 static const char * const standard_commands
[] =
4022 { /* Standard CUPS commands */
4030 * Check to see if the cache is up-to-date...
4033 snprintf(cache_name
, sizeof(cache_name
), "%s/%s.ipp4", CacheDir
, p
->name
);
4034 if (stat(cache_name
, &cache_info
))
4035 cache_info
.st_mtime
= 0;
4037 snprintf(pwg_name
, sizeof(pwg_name
), "%s/%s.pwg3", CacheDir
, p
->name
);
4038 if (stat(pwg_name
, &pwg_info
))
4039 pwg_info
.st_mtime
= 0;
4041 snprintf(ppd_name
, sizeof(ppd_name
), "%s/ppd/%s.ppd", ServerRoot
, p
->name
);
4042 if (stat(ppd_name
, &ppd_info
))
4043 ppd_info
.st_mtime
= 1;
4045 ippDelete(p
->ppd_attrs
);
4046 p
->ppd_attrs
= ippNew();
4048 _pwgDestroy(p
->pwg
);
4051 if (pwg_info
.st_mtime
>= ppd_info
.st_mtime
)
4052 p
->pwg
= _pwgCreateWithFile(pwg_name
);
4054 if (cache_info
.st_mtime
>= ppd_info
.st_mtime
&& p
->pwg
&&
4055 (cache
= cupsFileOpen(cache_name
, "r")) != NULL
)
4058 * Load cached information and return...
4061 cupsdLogMessage(CUPSD_LOG_DEBUG
, "load_ppd: Loading %s...", cache_name
);
4063 if (ippReadIO(cache
, (ipp_iocb_t
)cupsFileRead
, 1, NULL
,
4064 p
->ppd_attrs
) == IPP_DATA
)
4066 cupsFileClose(cache
);
4070 cupsFileClose(cache
);
4074 * Reload PPD attributes from disk...
4077 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
4079 _pwgDestroy(p
->pwg
);
4082 cupsdLogMessage(CUPSD_LOG_DEBUG
, "load_ppd: Loading %s...", ppd_name
);
4084 delete_string_array(&(p
->filters
));
4085 delete_string_array(&(p
->pre_filters
));
4087 p
->type
&= ~CUPS_PRINTER_OPTIONS
;
4088 p
->type
|= CUPS_PRINTER_BW
;
4090 finishings
[0] = IPP_FINISHINGS_NONE
;
4093 if ((ppd
= ppdOpenFile(ppd_name
)) != NULL
)
4096 * Add make/model and other various attributes...
4099 p
->pwg
= _pwgCreateWithPPD(ppd
);
4101 ppdMarkDefaults(ppd
);
4103 if (ppd
->color_device
)
4104 p
->type
|= CUPS_PRINTER_COLOR
;
4105 if (ppd
->variable_sizes
)
4106 p
->type
|= CUPS_PRINTER_VARIABLE
;
4107 if (!ppd
->manual_copies
)
4108 p
->type
|= CUPS_PRINTER_COPIES
;
4109 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsFax", NULL
)) != NULL
)
4110 if (ppd_attr
->value
&& !strcasecmp(ppd_attr
->value
, "true"))
4111 p
->type
|= CUPS_PRINTER_FAX
;
4113 ippAddBoolean(p
->ppd_attrs
, IPP_TAG_PRINTER
, "color-supported",
4115 if (ppd
->throughput
)
4117 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4118 "pages-per-minute", ppd
->throughput
);
4119 if (ppd
->color_device
)
4120 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4121 "pages-per-minute-color", ppd
->throughput
);
4126 if ((output_mode
= ppdFindOption(ppd
, "OutputMode")) != NULL
)
4128 if (ppdFindChoice(output_mode
, "draft") ||
4129 ppdFindChoice(output_mode
, "fast"))
4130 qualities
[num_qualities
++] = IPP_QUALITY_DRAFT
;
4131 if (ppdFindChoice(output_mode
, "normal") ||
4132 ppdFindChoice(output_mode
, "good"))
4133 qualities
[num_qualities
++] = IPP_QUALITY_NORMAL
;
4134 if (ppdFindChoice(output_mode
, "best") ||
4135 ppdFindChoice(output_mode
, "high"))
4136 qualities
[num_qualities
++] = IPP_QUALITY_HIGH
;
4138 else if ((ppd_attr
= ppdFindAttr(ppd
, "APPrinterPreset", NULL
)) != NULL
)
4142 if (strstr(ppd_attr
->spec
, "draft") ||
4143 strstr(ppd_attr
->spec
, "Draft"))
4145 qualities
[num_qualities
++] = IPP_QUALITY_DRAFT
;
4149 while ((ppd_attr
= ppdFindNextAttr(ppd
, "APPrinterPreset",
4152 qualities
[num_qualities
++] = IPP_QUALITY_NORMAL
;
4153 qualities
[num_qualities
++] = IPP_QUALITY_HIGH
;
4156 if (num_qualities
== 0)
4157 qualities
[num_qualities
++] = IPP_QUALITY_NORMAL
;
4159 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
4160 "print-quality-supported", num_qualities
, qualities
);
4165 * The NickName can be localized in the character set specified
4166 * by the LanugageEncoding attribute. However, ppdOpen2() has
4167 * already converted the ppd->nickname member to UTF-8 for us
4168 * (the original attribute value is available separately)
4171 cupsdSetString(&p
->make_model
, ppd
->nickname
);
4173 else if (ppd
->modelname
)
4176 * Model name can only contain specific characters...
4179 cupsdSetString(&p
->make_model
, ppd
->modelname
);
4182 cupsdSetString(&p
->make_model
, "Bad PPD File");
4184 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
4185 "printer-make-and-model", NULL
, p
->make_model
);
4188 * Add media options from the PPD file...
4191 if (ppd
->num_sizes
== 0 || !p
->pwg
)
4193 if (!ppdFindAttr(ppd
, "APScannerOnly", NULL
))
4194 cupsdLogMessage(CUPSD_LOG_CRIT
,
4195 "The PPD file for printer %s contains no media "
4196 "options and is therefore invalid!", p
->name
);
4198 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4199 "media-default", NULL
, "unknown");
4200 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4201 "media-supported", NULL
, "unknown");
4209 if ((size
= ppdPageSize(ppd
, NULL
)) != NULL
)
4210 pwgsize
= _pwgGetSize(p
->pwg
, size
->name
);
4214 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4215 "media-default", NULL
,
4216 pwgsize
? pwgsize
->map
.pwg
: "unknown");
4224 ipp_t
*col
; /* Collection value */
4226 input_slot
= ppdFindMarkedChoice(ppd
, "InputSlot");
4227 media_type
= ppdFindMarkedChoice(ppd
, "MediaType");
4228 col
= new_media_col(pwgsize
,
4230 _pwgGetSource(p
->pwg
,
4231 input_slot
->choice
) :
4235 media_type
->choice
) :
4238 ippAddCollection(p
->ppd_attrs
, IPP_TAG_PRINTER
, "media-col-default",
4247 num_media
= p
->pwg
->num_sizes
;
4248 if (p
->pwg
->custom_min_keyword
)
4251 if ((attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4252 "media-supported", num_media
, NULL
,
4257 for (i
= p
->pwg
->num_sizes
, pwgsize
= p
->pwg
->sizes
;
4259 i
--, pwgsize
++, val
++)
4260 val
->string
.text
= _cupsStrRetain(pwgsize
->map
.pwg
);
4262 if (p
->pwg
->custom_min_keyword
)
4264 val
->string
.text
= _cupsStrRetain(p
->pwg
->custom_min_keyword
);
4266 val
->string
.text
= _cupsStrRetain(p
->pwg
->custom_max_keyword
);
4271 * media-source-supported
4274 if (p
->pwg
->num_sources
> 0 &&
4275 (attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4276 "media-source-supported", p
->pwg
->num_sources
,
4277 NULL
, NULL
)) != NULL
)
4279 for (i
= p
->pwg
->num_sources
, pwgsource
= p
->pwg
->sources
,
4282 i
--, pwgsource
++, val
++)
4283 val
->string
.text
= _cupsStrRetain(pwgsource
->pwg
);
4287 * media-type-supported
4290 if (p
->pwg
->num_types
> 0 &&
4291 (attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4292 "media-type-supported", p
->pwg
->num_types
,
4293 NULL
, NULL
)) != NULL
)
4295 for (i
= p
->pwg
->num_types
, pwgtype
= p
->pwg
->types
,
4298 i
--, pwgtype
++, val
++)
4299 val
->string
.text
= _cupsStrRetain(pwgtype
->pwg
);
4303 * media-*-margin-supported
4306 for (i
= p
->pwg
->num_sizes
, pwgsize
= p
->pwg
->sizes
, num_margins
= 0;
4307 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4310 for (j
= 0; j
< num_margins
; j
++)
4311 if (pwgsize
->bottom
== margins
[j
])
4314 if (j
>= num_margins
)
4316 margins
[num_margins
] = pwgsize
->bottom
;
4321 if (num_margins
> 0)
4322 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4323 "media-bottom-margin-supported", num_margins
, margins
);
4325 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4326 "media-bottom-margin-supported", 0);
4328 for (i
= p
->pwg
->num_sizes
, pwgsize
= p
->pwg
->sizes
, num_margins
= 0;
4329 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4332 for (j
= 0; j
< num_margins
; j
++)
4333 if (pwgsize
->left
== margins
[j
])
4336 if (j
>= num_margins
)
4338 margins
[num_margins
] = pwgsize
->left
;
4343 if (num_margins
> 0)
4344 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4345 "media-left-margin-supported", num_margins
, margins
);
4347 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4348 "media-left-margin-supported", 0);
4350 for (i
= p
->pwg
->num_sizes
, pwgsize
= p
->pwg
->sizes
, num_margins
= 0;
4351 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4354 for (j
= 0; j
< num_margins
; j
++)
4355 if (pwgsize
->right
== margins
[j
])
4358 if (j
>= num_margins
)
4360 margins
[num_margins
] = pwgsize
->right
;
4365 if (num_margins
> 0)
4366 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4367 "media-right-margin-supported", num_margins
, margins
);
4369 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4370 "media-right-margin-supported", 0);
4372 for (i
= p
->pwg
->num_sizes
, pwgsize
= p
->pwg
->sizes
, num_margins
= 0;
4373 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4376 for (j
= 0; j
< num_margins
; j
++)
4377 if (pwgsize
->top
== margins
[j
])
4380 if (j
>= num_margins
)
4382 margins
[num_margins
] = pwgsize
->top
;
4387 if (num_margins
> 0)
4388 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4389 "media-top-margin-supported", num_margins
, margins
);
4391 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4392 "media-top-margin-supported", 0);
4395 * media-col-database
4398 num_media
= p
->pwg
->num_sizes
;
4399 if (p
->pwg
->num_sources
)
4401 if (p
->pwg
->num_types
> 0)
4402 num_media
+= p
->pwg
->num_sizes
* p
->pwg
->num_sources
*
4405 num_media
+= p
->pwg
->num_sizes
* p
->pwg
->num_sources
;
4407 else if (p
->pwg
->num_types
)
4408 num_media
+= p
->pwg
->num_sizes
* p
->pwg
->num_types
;
4410 if ((attr
= ippAddCollections(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4411 "media-col-database", num_media
,
4414 for (i
= p
->pwg
->num_sizes
, pwgsize
= p
->pwg
->sizes
, val
= attr
->values
;
4419 * Start by adding the page size without source or type...
4422 ppdMarkOption(ppd
, "PageSize", pwgsize
->map
.ppd
);
4424 val
->collection
= new_media_col(pwgsize
, NULL
, NULL
);
4428 * Then add the specific, supported combinations of size, source, and
4432 if (p
->pwg
->num_sources
> 0)
4434 for (j
= p
->pwg
->num_sources
, pwgsource
= p
->pwg
->sources
;
4438 ppdMarkOption(ppd
, "InputSlot", pwgsource
->ppd
);
4440 if (p
->pwg
->num_types
> 0)
4442 for (k
= p
->pwg
->num_types
, pwgtype
= p
->pwg
->types
;
4446 if (!ppdMarkOption(ppd
, "MediaType", pwgtype
->ppd
))
4448 val
->collection
= new_media_col(pwgsize
, pwgsource
->pwg
,
4454 else if (!ppdConflicts(ppd
))
4456 val
->collection
= new_media_col(pwgsize
, pwgsource
->pwg
, NULL
);
4461 else if (p
->pwg
->num_types
> 0)
4463 for (j
= p
->pwg
->num_types
, pwgtype
= p
->pwg
->types
;
4467 if (!ppdMarkOption(ppd
, "MediaType", pwgtype
->ppd
))
4469 val
->collection
= new_media_col(pwgsize
, NULL
, pwgtype
->pwg
);
4477 * Update the number of media-col-database values...
4480 attr
->num_values
= val
- attr
->values
;
4488 if (p
->pwg
&& p
->pwg
->num_bins
> 0)
4490 attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4491 "output-bin-supported", p
->pwg
->num_bins
,
4496 for (i
= 0, val
= attr
->values
;
4497 i
< p
->pwg
->num_bins
;
4499 val
->string
.text
= _cupsStrAlloc(p
->pwg
->bins
[i
].pwg
);
4502 if ((output_bin
= ppdFindOption(ppd
, "OutputBin")) != NULL
)
4504 for (i
= 0; i
< p
->pwg
->num_bins
; i
++)
4505 if (!strcmp(p
->pwg
->bins
[i
].ppd
, output_bin
->defchoice
))
4508 if (i
>= p
->pwg
->num_bins
)
4511 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4512 "output-bin-default", NULL
, p
->pwg
->bins
[i
].pwg
);
4515 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4516 "output-bin-default", NULL
, p
->pwg
->bins
[0].pwg
);
4518 else if (((ppd_attr
= ppdFindAttr(ppd
, "DefaultOutputOrder",
4520 !strcasecmp(ppd_attr
->value
, "Reverse")) ||
4521 (!ppd_attr
&& ppd
->manufacturer
&& /* "Compatibility heuristic" */
4522 (!strcasecmp(ppd
->manufacturer
, "epson") ||
4523 !strcasecmp(ppd
->manufacturer
, "lexmark"))))
4526 * Report that this printer has a single output bin that leaves pages face
4530 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4531 "output-bin-supported", NULL
, "face-up");
4532 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4533 "output-bin-default", NULL
, "face-up");
4537 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4538 "output-bin-supported", NULL
, "face-down");
4539 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4540 "output-bin-default", NULL
, "face-down");
4547 if (ppd
->color_device
)
4549 static const char * const output_modes
[] =
4555 ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4556 "output-mode-supported", 2, NULL
, output_modes
);
4557 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4558 "output-mode-default", NULL
, "color");
4562 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4563 "output-mode-supported", NULL
, "monochrome");
4564 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4565 "output-mode-default", NULL
, "monochrome");
4569 * Printer resolutions...
4572 if ((resolution
= ppdFindOption(ppd
, "Resolution")) == NULL
)
4573 if ((resolution
= ppdFindOption(ppd
, "JCLResolution")) == NULL
)
4574 if ((resolution
= ppdFindOption(ppd
, "SetResolution")) == NULL
)
4575 resolution
= ppdFindOption(ppd
, "CNRes_PGP");
4580 * Report all supported resolutions...
4583 attr
= ippAddResolutions(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4584 "printer-resolution-supported",
4585 resolution
->num_choices
, IPP_RES_PER_INCH
,
4588 for (i
= 0, choice
= resolution
->choices
;
4589 i
< resolution
->num_choices
;
4592 xdpi
= ydpi
= (int)strtol(choice
->choice
, (char **)&resptr
, 10);
4593 if (resptr
> choice
->choice
&& xdpi
> 0 && *resptr
== 'x')
4594 ydpi
= (int)strtol(resptr
+ 1, (char **)&resptr
, 10);
4596 if (xdpi
<= 0 || ydpi
<= 0)
4598 cupsdLogMessage(CUPSD_LOG_WARN
,
4599 "Bad resolution \"%s\" for printer %s.",
4600 choice
->choice
, p
->name
);
4604 attr
->values
[i
].resolution
.xres
= xdpi
;
4605 attr
->values
[i
].resolution
.yres
= ydpi
;
4606 attr
->values
[i
].resolution
.units
= IPP_RES_PER_INCH
;
4609 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4610 "printer-resolution-default", IPP_RES_PER_INCH
,
4614 else if ((ppd_attr
= ppdFindAttr(ppd
, "DefaultResolution", NULL
)) != NULL
&&
4618 * Just the DefaultResolution to report...
4621 xdpi
= ydpi
= (int)strtol(ppd_attr
->value
, (char **)&resptr
, 10);
4622 if (resptr
> ppd_attr
->value
&& xdpi
> 0)
4625 ydpi
= (int)strtol(resptr
+ 1, (char **)&resptr
, 10);
4630 if (xdpi
<= 0 || ydpi
<= 0)
4632 cupsdLogMessage(CUPSD_LOG_WARN
,
4633 "Bad default resolution \"%s\" for printer %s.",
4634 ppd_attr
->value
, p
->name
);
4638 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4639 "printer-resolution-default", IPP_RES_PER_INCH
,
4641 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4642 "printer-resolution-supported", IPP_RES_PER_INCH
,
4648 * No resolutions in PPD - make one up...
4651 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4652 "printer-resolution-default", IPP_RES_PER_INCH
,
4654 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4655 "printer-resolution-supported", IPP_RES_PER_INCH
,
4663 ppdMarkDefaults(ppd
);
4665 if ((duplex
= ppdFindOption(ppd
, "Duplex")) == NULL
)
4666 if ((duplex
= ppdFindOption(ppd
, "EFDuplex")) == NULL
)
4667 if ((duplex
= ppdFindOption(ppd
, "EFDuplexing")) == NULL
)
4668 if ((duplex
= ppdFindOption(ppd
, "KD03Duplex")) == NULL
)
4669 duplex
= ppdFindOption(ppd
, "JCLDuplex");
4671 if (duplex
&& duplex
->num_choices
> 1 &&
4672 !ppdInstallableConflict(ppd
, duplex
->keyword
, "DuplexTumble"))
4674 p
->type
|= CUPS_PRINTER_DUPLEX
;
4676 ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4677 "sides-supported", 3, NULL
, sides
);
4679 if (!strcasecmp(duplex
->defchoice
, "DuplexTumble"))
4680 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4681 "sides-default", NULL
, "two-sided-short-edge");
4682 else if (!strcasecmp(duplex
->defchoice
, "DuplexNoTumble"))
4683 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4684 "sides-default", NULL
, "two-sided-long-edge");
4686 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4687 "sides-default", NULL
, "one-sided");
4691 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4692 "sides-supported", NULL
, "one-sided");
4693 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4694 "sides-default", NULL
, "one-sided");
4697 if (ppdFindOption(ppd
, "Collate") != NULL
)
4698 p
->type
|= CUPS_PRINTER_COLLATE
;
4700 if (ppdFindOption(ppd
, "StapleLocation") != NULL
)
4702 p
->type
|= CUPS_PRINTER_STAPLE
;
4703 finishings
[num_finishings
++] = IPP_FINISHINGS_STAPLE
;
4706 if (ppdFindOption(ppd
, "BindEdge") != NULL
)
4708 p
->type
|= CUPS_PRINTER_BIND
;
4709 finishings
[num_finishings
++] = IPP_FINISHINGS_BIND
;
4712 for (i
= 0; i
< ppd
->num_sizes
; i
++)
4713 if (ppd
->sizes
[i
].length
> 1728)
4714 p
->type
|= CUPS_PRINTER_LARGE
;
4715 else if (ppd
->sizes
[i
].length
> 1008)
4716 p
->type
|= CUPS_PRINTER_MEDIUM
;
4718 p
->type
|= CUPS_PRINTER_SMALL
;
4720 if ((ppd_attr
= ppdFindAttr(ppd
, "APICADriver", NULL
)) != NULL
&&
4721 ppd_attr
->value
&& !strcasecmp(ppd_attr
->value
, "true"))
4723 if ((ppd_attr
= ppdFindAttr(ppd
, "APScannerOnly", NULL
)) != NULL
&&
4724 ppd_attr
->value
&& !strcasecmp(ppd_attr
->value
, "true"))
4725 p
->type
|= CUPS_PRINTER_SCANNER
;
4727 p
->type
|= CUPS_PRINTER_MFP
;
4731 * Add a filter from application/vnd.cups-raw to printer/name to
4732 * handle "raw" printing by users.
4735 add_string_array(&(p
->filters
), "application/vnd.cups-raw 0 -");
4738 * Add any pre-filters in the PPD file...
4741 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsPreFilter", NULL
)) != NULL
)
4743 for (; ppd_attr
; ppd_attr
= ppdFindNextAttr(ppd
, "cupsPreFilter", NULL
))
4744 if (ppd_attr
->value
)
4745 add_string_array(&(p
->pre_filters
), ppd_attr
->value
);
4749 * Add any filters in the PPD file...
4752 DEBUG_printf(("ppd->num_filters = %d\n", ppd
->num_filters
));
4753 for (i
= 0; i
< ppd
->num_filters
; i
++)
4755 DEBUG_printf(("ppd->filters[%d] = \"%s\"\n", i
, ppd
->filters
[i
]));
4756 add_string_array(&(p
->filters
), ppd
->filters
[i
]);
4758 if (!strncasecmp(ppd
->filters
[i
], "application/vnd.cups-command", 28) &&
4759 isspace(ppd
->filters
[i
][28] & 255))
4760 p
->type
|= CUPS_PRINTER_COMMANDS
;
4763 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsCommands", NULL
)) != NULL
&&
4765 (!ppd_attr
->value
[0] || !strcasecmp(ppd_attr
->value
, "none")))
4768 * Printer does not support CUPS command files (or any commands as far as
4769 * CUPS is concerned...
4772 p
->type
&= ~CUPS_PRINTER_COMMANDS
;
4774 else if (ppd
->num_filters
== 0)
4777 * If there are no filters, add PostScript printing filters.
4780 add_string_array(&(p
->filters
),
4781 "application/vnd.cups-command 0 commandtops");
4782 add_string_array(&(p
->filters
),
4783 "application/vnd.cups-postscript 0 -");
4785 p
->type
|= CUPS_PRINTER_COMMANDS
;
4787 else if (!(p
->type
& CUPS_PRINTER_COMMANDS
))
4790 * See if this is a PostScript device without a command filter...
4793 for (i
= 0; i
< ppd
->num_filters
; i
++)
4794 if (!strncasecmp(ppd
->filters
[i
],
4795 "application/vnd.cups-postscript", 31) &&
4796 isspace(ppd
->filters
[i
][31] & 255))
4799 if (i
< ppd
->num_filters
)
4802 * Add the generic PostScript command filter...
4805 add_string_array(&(p
->filters
),
4806 "application/vnd.cups-command 0 commandtops");
4807 p
->type
|= CUPS_PRINTER_COMMANDS
;
4811 if (p
->type
& CUPS_PRINTER_COMMANDS
)
4813 char *commands
, /* Copy of commands */
4814 *start
, /* Start of name */
4815 *end
; /* End of name */
4816 int count
; /* Number of commands */
4819 if (ppd_attr
&& ppd_attr
->value
&& ppd_attr
->value
[0])
4821 for (count
= 0, start
= ppd_attr
->value
; *start
; count
++)
4823 while (isspace(*start
& 255))
4829 while (*start
&& !isspace(*start
& 255))
4839 * Make a copy of the commands string and count how many commands there
4843 attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4844 "printer-commands", count
, NULL
, NULL
);
4846 commands
= strdup(ppd_attr
->value
);
4848 for (count
= 0, start
= commands
; *start
; count
++)
4850 while (isspace(*start
& 255))
4857 while (*end
&& !isspace(*end
& 255))
4863 attr
->values
[count
].string
.text
= _cupsStrAlloc(start
);
4873 * Add the standard list of commands...
4876 ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4878 (int)(sizeof(standard_commands
) /
4879 sizeof(standard_commands
[0])), NULL
,
4886 * No commands supported...
4889 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4890 "printer-commands", NULL
, "none");
4894 * Show current and available port monitors for this printer...
4897 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
, "port-monitor",
4898 NULL
, p
->port_monitor
? p
->port_monitor
: "none");
4900 for (i
= 1, ppd_attr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
4902 i
++, ppd_attr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
));
4906 if (strstr(ppd
->protocols
, "TBCP"))
4908 else if (strstr(ppd
->protocols
, "BCP"))
4912 attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
4913 "port-monitor-supported", i
, NULL
, NULL
);
4915 attr
->values
[0].string
.text
= _cupsStrAlloc("none");
4917 for (i
= 1, ppd_attr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
4919 i
++, ppd_attr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
))
4920 attr
->values
[i
].string
.text
= _cupsStrAlloc(ppd_attr
->value
);
4924 if (strstr(ppd
->protocols
, "TBCP"))
4925 attr
->values
[i
].string
.text
= _cupsStrAlloc("tbcp");
4926 else if (strstr(ppd
->protocols
, "BCP"))
4927 attr
->values
[i
].string
.text
= _cupsStrAlloc("bcp");
4931 cupsdSetString(&p
->product
, ppd
->product
);
4932 #endif /* HAVE_DNSSD */
4934 if (ppdFindAttr(ppd
, "APRemoteQueueID", NULL
))
4935 p
->type
|= CUPS_PRINTER_REMOTE
;
4937 #ifdef HAVE_APPLICATIONSERVICES_H
4939 * Convert the file referenced in APPrinterIconPath to a 128x128 PNG
4940 * and save it as cacheDir/printername.png
4943 if ((ppd_attr
= ppdFindAttr(ppd
, "APPrinterIconPath", NULL
)) != NULL
&&
4946 CGImageRef imageRef
= NULL
;/* Current icon image */
4947 CGImageRef biggestIconRef
= NULL
;
4948 /* Biggest icon image */
4949 CGImageRef closestTo128IconRef
= NULL
;
4950 /* Icon image closest to and >= 128 */
4951 CGImageSourceRef sourceRef
; /* The file's image source */
4952 char outPath
[HTTP_MAX_URI
];
4953 /* The path to the PNG file */
4954 CFURLRef outUrl
; /* The URL made from the outPath */
4955 CFURLRef icnsFileUrl
; /* The URL of the original ICNS icon file */
4956 CGImageDestinationRef destRef
; /* The image destination to write */
4957 size_t bytesPerRow
; /* The bytes per row used for resizing */
4958 CGContextRef context
; /* The CG context used for resizing */
4960 snprintf(outPath
, sizeof(outPath
), "%s/%s.png", CacheDir
, p
->name
);
4961 outUrl
= CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault
,
4965 icnsFileUrl
= CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault
,
4966 (UInt8
*)ppd_attr
->value
,
4967 strlen(ppd_attr
->value
),
4969 if (outUrl
&& icnsFileUrl
)
4971 sourceRef
= CGImageSourceCreateWithURL(icnsFileUrl
, NULL
);
4974 for (i
= 0; i
< CGImageSourceGetCount(sourceRef
); i
++)
4976 imageRef
= CGImageSourceCreateImageAtIndex(sourceRef
, i
, NULL
);
4978 CGImageGetWidth(imageRef
) == CGImageGetHeight(imageRef
))
4981 * Loop through remembering the icon closest to 128 but >= 128
4982 * and then remember the largest icon.
4985 if (CGImageGetWidth(imageRef
) >= 128 &&
4986 (!closestTo128IconRef
||
4987 CGImageGetWidth(imageRef
) <
4988 CGImageGetWidth(closestTo128IconRef
)))
4990 CGImageRelease(closestTo128IconRef
);
4991 CGImageRetain(imageRef
);
4992 closestTo128IconRef
= imageRef
;
4995 if (!biggestIconRef
||
4996 CGImageGetWidth(imageRef
) > CGImageGetWidth(biggestIconRef
))
4998 CGImageRelease(biggestIconRef
);
4999 CGImageRetain(imageRef
);
5000 biggestIconRef
= imageRef
;
5003 CGImageRelease(imageRef
);
5010 * If biggestIconRef is NULL, we found no icons. Otherwise we first
5011 * want the closest to 128, but if none are larger than 128, we want
5012 * the largest icon available.
5015 imageRef
= closestTo128IconRef
? closestTo128IconRef
:
5017 CGImageRetain(imageRef
);
5018 CGImageRelease(biggestIconRef
);
5019 CGImageRelease(closestTo128IconRef
);
5020 destRef
= CGImageDestinationCreateWithURL(outUrl
, kUTTypePNG
, 1,
5024 if (CGImageGetWidth(imageRef
) != 128)
5026 bytesPerRow
= CGImageGetBytesPerRow(imageRef
) /
5027 CGImageGetWidth(imageRef
) * 128;
5028 context
= CGBitmapContextCreate(NULL
, 128, 128,
5029 CGImageGetBitsPerComponent(imageRef
),
5031 CGImageGetColorSpace(imageRef
),
5032 kCGImageAlphaPremultipliedFirst
);
5035 CGContextDrawImage(context
, CGRectMake(0, 0, 128, 128),
5037 CGImageRelease(imageRef
);
5038 imageRef
= CGBitmapContextCreateImage(context
);
5039 CGContextRelease(context
);
5043 CGImageDestinationAddImage(destRef
, imageRef
, NULL
);
5044 CGImageDestinationFinalize(destRef
);
5048 CGImageRelease(imageRef
);
5051 CFRelease(sourceRef
);
5052 CFRelease(icnsFileUrl
);
5058 #endif /* HAVE_APPLICATIONSERVICES_H */
5061 * Close the PPD and set the type...
5066 else if (!access(ppd_name
, 0))
5068 int pline
; /* PPD line number */
5069 ppd_status_t pstatus
; /* PPD load status */
5072 pstatus
= ppdLastError(&pline
);
5074 cupsdLogMessage(CUPSD_LOG_ERROR
, "PPD file for %s cannot be loaded!",
5077 if (pstatus
<= PPD_ALLOC_ERROR
)
5078 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s", strerror(errno
));
5080 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s on line %d.",
5081 ppdErrorString(pstatus
), pline
);
5083 cupsdLogMessage(CUPSD_LOG_INFO
,
5084 "Hint: Run \"cupstestppd %s\" and fix any errors.",
5088 * Add a filter from application/vnd.cups-raw to printer/name to
5089 * handle "raw" printing by users.
5092 add_string_array(&(p
->filters
), "application/vnd.cups-raw 0 -");
5095 * Add a PostScript filter, since this is still possibly PS printer.
5098 add_string_array(&(p
->filters
), "application/vnd.cups-postscript 0 -");
5103 * If we have an interface script, add a filter entry for it...
5106 char interface
[1024]; /* Interface script */
5109 snprintf(interface
, sizeof(interface
), "%s/interfaces/%s", ServerRoot
,
5111 if (!access(interface
, X_OK
))
5114 * Yes, we have a System V style interface script; use it!
5117 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
5118 "printer-make-and-model", NULL
,
5119 "Local System V Printer");
5121 snprintf(interface
, sizeof(interface
), "*/* 0 %s/interfaces/%s",
5122 ServerRoot
, p
->name
);
5123 add_string_array(&(p
->filters
), interface
);
5125 else if (!strncmp(p
->device_uri
, "ipp://", 6) &&
5126 (strstr(p
->device_uri
, "/printers/") != NULL
||
5127 strstr(p
->device_uri
, "/classes/") != NULL
||
5128 (strstr(p
->device_uri
, "._ipp.") != NULL
&&
5129 !strcmp(p
->device_uri
+ strlen(p
->device_uri
) - 5,
5133 * Tell the client this is really a hard-wired remote printer.
5136 p
->type
|= CUPS_PRINTER_REMOTE
;
5139 * Point the printer-uri-supported attribute to the
5143 if (strchr(p
->device_uri
, '?'))
5146 * Strip trailing "?options" from URI...
5149 char resource
[HTTP_MAX_URI
], /* New URI */
5150 *ptr
; /* Pointer into URI */
5152 strlcpy(resource
, p
->device_uri
, sizeof(resource
));
5153 if ((ptr
= strchr(resource
, '?')) != NULL
)
5156 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
5157 "printer-uri-supported", NULL
, resource
);
5160 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
5161 "printer-uri-supported", NULL
, p
->device_uri
);
5164 * Then set the make-and-model accordingly...
5167 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
5168 "printer-make-and-model", NULL
, "Remote Printer");
5171 * Print all files directly...
5180 * Otherwise we have neither - treat this as a "dumb" printer
5181 * with no PPD file...
5184 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
5185 "printer-make-and-model", NULL
, "Local Raw Printer");
5191 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
5192 "finishings-supported", num_finishings
, finishings
);
5193 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
5194 "finishings-default", IPP_FINISHINGS_NONE
);
5196 if (ppd
&& (cache
= cupsFileOpen(cache_name
, "w9")) != NULL
)
5199 * Save cached PPD attributes to disk...
5202 cupsdLogMessage(CUPSD_LOG_DEBUG
, "load_ppd: Saving %s...", cache_name
);
5204 p
->ppd_attrs
->state
= IPP_IDLE
;
5206 if (ippWriteIO(cache
, (ipp_iocb_t
)cupsFileWrite
, 1, NULL
,
5207 p
->ppd_attrs
) != IPP_DATA
)
5209 cupsdLogMessage(CUPSD_LOG_ERROR
,
5210 "Unable to save PPD cache file \"%s\" - %s", cache_name
,
5215 cupsFileClose(cache
);
5217 _pwgWriteFile(p
->pwg
, pwg_name
);
5222 * Remove cache files...
5225 if (cache_info
.st_mtime
)
5228 if (pwg_info
.st_mtime
)
5235 * 'new_media_col()' - Create a media-col collection value.
5238 static ipp_t
* /* O - Collection value */
5239 new_media_col(_pwg_size_t
*size
, /* I - media-size/margin values */
5240 const char *source
, /* I - media-source value */
5241 const char *type
) /* I - media-type value */
5243 ipp_t
*media_col
, /* Collection value */
5244 *media_size
; /* media-size value */
5247 media_col
= ippNew();
5249 media_size
= ippNew();
5250 ippAddInteger(media_size
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5251 "x-dimension", size
->width
);
5252 ippAddInteger(media_size
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5253 "y-dimension", size
->length
);
5254 ippAddCollection(media_col
, IPP_TAG_PRINTER
, "media-size", media_size
);
5255 ippDelete(media_size
);
5257 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5258 "media-bottom-margin", size
->bottom
);
5259 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5260 "media-left-margin", size
->left
);
5261 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5262 "media-right-margin", size
->right
);
5263 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5264 "media-top-margin", size
->top
);
5267 ippAddString(media_col
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
, "media-source",
5271 ippAddString(media_col
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
, "media-type",
5280 * 'write_irix_config()' - Update the config files used by the IRIX
5285 write_irix_config(cupsd_printer_t
*p
) /* I - Printer to update */
5287 char filename
[1024]; /* Interface script filename */
5288 cups_file_t
*fp
; /* Interface script file */
5289 ipp_attribute_t
*attr
; /* Attribute data */
5293 * Add dummy interface and GUI scripts to fool SGI's "challenged" printing
5294 * tools. First the interface script that tells the tools what kind of
5295 * printer we have...
5298 snprintf(filename
, sizeof(filename
), "/var/spool/lp/interface/%s", p
->name
);
5300 if (p
->type
& CUPS_PRINTER_CLASS
)
5302 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
5304 cupsFilePuts(fp
, "#!/bin/sh\n");
5306 if ((attr
= ippFindAttribute(p
->attrs
, "printer-make-and-model",
5307 IPP_TAG_TEXT
)) != NULL
)
5308 cupsFilePrintf(fp
, "NAME=\"%s\"\n", attr
->values
[0].string
.text
);
5309 else if (p
->type
& CUPS_PRINTER_CLASS
)
5310 cupsFilePuts(fp
, "NAME=\"Printer Class\"\n");
5312 cupsFilePuts(fp
, "NAME=\"Remote Destination\"\n");
5314 if (p
->type
& CUPS_PRINTER_COLOR
)
5315 cupsFilePuts(fp
, "TYPE=ColorPostScript\n");
5317 cupsFilePuts(fp
, "TYPE=MonoPostScript\n");
5319 cupsFilePrintf(fp
, "HOSTNAME=%s\n", ServerName
);
5320 cupsFilePrintf(fp
, "HOSTPRINTER=%s\n", p
->name
);
5324 chmod(filename
, 0755);
5325 chown(filename
, User
, Group
);
5329 * Then the member file that tells which device file the queue is connected
5330 * to... Networked printers use "/dev/null" in this file, so that's what
5331 * we use (the actual device URI can confuse some apps...)
5334 snprintf(filename
, sizeof(filename
), "/var/spool/lp/member/%s", p
->name
);
5336 if (p
->type
& CUPS_PRINTER_CLASS
)
5338 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
5340 cupsFilePuts(fp
, "/dev/null\n");
5344 chmod(filename
, 0644);
5345 chown(filename
, User
, Group
);
5349 * The gui_interface file is a script or program that launches a GUI
5350 * option panel for the printer, using options specified on the
5351 * command-line in the third argument. The option panel must send
5352 * any printing options to stdout on a single line when the user
5353 * accepts them, or nothing if the user cancels the dialog.
5355 * The default options panel program is /usr/bin/glpoptions, from
5356 * the ESP Print Pro software. You can select another using the
5357 * PrintcapGUI option.
5360 snprintf(filename
, sizeof(filename
), "/var/spool/lp/gui_interface/ELF/%s.gui", p
->name
);
5362 if (p
->type
& CUPS_PRINTER_CLASS
)
5364 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
5366 cupsFilePuts(fp
, "#!/bin/sh\n");
5367 cupsFilePrintf(fp
, "%s -d %s -o \"$3\"\n", PrintcapGUI
, p
->name
);
5371 chmod(filename
, 0755);
5372 chown(filename
, User
, Group
);
5376 * The POD config file is needed by the printstatus command to show
5377 * the printer location and device.
5380 snprintf(filename
, sizeof(filename
), "/var/spool/lp/pod/%s.config", p
->name
);
5382 if (p
->type
& CUPS_PRINTER_CLASS
)
5384 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
5386 cupsFilePrintf(fp
, "Printer Class | %s\n",
5387 (p
->type
& CUPS_PRINTER_COLOR
) ? "ColorPostScript" : "MonoPostScript");
5388 cupsFilePrintf(fp
, "Printer Model | %s\n", p
->make_model
? p
->make_model
: "");
5389 cupsFilePrintf(fp
, "Location Code | %s\n", p
->location
? p
->location
: "");
5390 cupsFilePrintf(fp
, "Physical Location | %s\n", p
->info
? p
->info
: "");
5391 cupsFilePrintf(fp
, "Port Path | %s\n", p
->device_uri
);
5392 cupsFilePrintf(fp
, "Config Path | /var/spool/lp/pod/%s.config\n", p
->name
);
5393 cupsFilePrintf(fp
, "Active Status Path | /var/spool/lp/pod/%s.status\n", p
->name
);
5394 cupsFilePuts(fp
, "Status Update Wait | 10 seconds\n");
5398 chmod(filename
, 0664);
5399 chown(filename
, User
, Group
);
5405 * 'write_irix_state()' - Update the status files used by IRIX printing
5410 write_irix_state(cupsd_printer_t
*p
) /* I - Printer to update */
5412 char filename
[1024]; /* Interface script filename */
5413 cups_file_t
*fp
; /* Interface script file */
5414 int tag
; /* Status tag value */
5420 * The POD status file is needed for the printstatus window to
5421 * provide the current status of the printer.
5424 snprintf(filename
, sizeof(filename
), "/var/spool/lp/pod/%s.status", p
->name
);
5426 if (p
->type
& CUPS_PRINTER_CLASS
)
5428 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
5430 cupsFilePrintf(fp
, "Operational Status | %s\n",
5431 (p
->state
== IPP_PRINTER_IDLE
) ? "Idle" :
5432 (p
->state
== IPP_PRINTER_PROCESSING
) ? "Busy" :
5434 cupsFilePrintf(fp
, "Information | 01 00 00 | %s\n", CUPS_SVERSION
);
5435 cupsFilePrintf(fp
, "Information | 02 00 00 | Device URI: %s\n",
5437 cupsFilePrintf(fp
, "Information | 03 00 00 | %s jobs\n",
5438 p
->accepting
? "Accepting" : "Not accepting");
5439 cupsFilePrintf(fp
, "Information | 04 00 00 | %s\n", p
->state_message
);
5443 chmod(filename
, 0664);
5444 chown(filename
, User
, Group
);
5448 * The activeicons file is needed to provide desktop icons for printers:
5450 * [ quoted from /usr/lib/print/tagit ]
5452 * --- Type of printer tags (base values)
5454 * Dumb=66048 # 0x10200
5455 * DumbColor=66080 # 0x10220
5456 * Raster=66112 # 0x10240
5457 * ColorRaster=66144 # 0x10260
5458 * Plotter=66176 # 0x10280
5459 * PostScript=66208 # 0x102A0
5460 * ColorPostScript=66240 # 0x102C0
5461 * MonoPostScript=66272 # 0x102E0
5463 * --- Printer state modifiers for local printers
5468 * Unknown=3 # 0x3 (Faulted due to unknown reason)
5470 * --- Printer state modifiers for network printers
5474 * NetFaulted=10 # 0xA
5475 * NetUnknown=11 # 0xB (Faulted due to unknown reason)
5478 snprintf(filename
, sizeof(filename
), "/var/spool/lp/activeicons/%s", p
->name
);
5480 if (p
->type
& CUPS_PRINTER_CLASS
)
5482 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
5484 if (p
->type
& CUPS_PRINTER_COLOR
)
5489 if (p
->type
& CUPS_PRINTER_REMOTE
)
5492 if (p
->state
== IPP_PRINTER_PROCESSING
)
5495 else if (p
->state
== IPP_PRINTER_STOPPED
)
5498 cupsFilePuts(fp
, "#!/bin/sh\n");
5499 cupsFilePrintf(fp
, "#Tag %d\n", tag
);
5503 chmod(filename
, 0755);
5504 chown(filename
, User
, Group
);
5509 * The default file is needed by the printers window to show
5510 * the default printer.
5513 snprintf(filename
, sizeof(filename
), "/var/spool/lp/default");
5515 if (DefaultPrinter
!= NULL
)
5517 if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
5519 cupsFilePrintf(fp
, "%s\n", DefaultPrinter
->name
);
5523 chmod(filename
, 0644);
5524 chown(filename
, User
, Group
);
5534 * 'write_xml_string()' - Write a string with XML escaping.
5538 write_xml_string(cups_file_t
*fp
, /* I - File to write to */
5539 const char *s
) /* I - String to write */
5541 const char *start
; /* Start of current sequence */
5547 for (start
= s
; *s
; s
++)
5552 cupsFileWrite(fp
, start
, s
- start
);
5554 cupsFilePuts(fp
, "&");
5560 cupsFileWrite(fp
, start
, s
- start
);
5562 cupsFilePuts(fp
, "<");
5568 cupsFilePuts(fp
, start
);
5573 * End of "$Id: printers.c 7968 2008-09-19 23:03:01Z mike $".