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 * cupsdCreateCommonData() - Create the common printer data.
19 * cupsdDeleteAllPrinters() - Delete all printers from the system.
20 * cupsdDeletePrinter() - Delete a printer from the system.
21 * cupsdFindDest() - Find a destination in the list.
22 * cupsdFindPrinter() - Find a printer in the list.
23 * cupsdLoadAllPrinters() - Load printers from the printers.conf file.
24 * cupsdRenamePrinter() - Rename a printer.
25 * cupsdSaveAllPrinters() - Save all printer definitions to the
27 * cupsdSetAuthInfoRequired() - Set the required authentication info.
28 * cupsdSetDeviceURI() - Set the device URI for a printer.
29 * cupsdSetPrinterAttr() - Set a printer attribute.
30 * cupsdSetPrinterAttrs() - Set printer attributes based upon the PPD
32 * cupsdSetPrinterReasons() - Set/update the reasons strings.
33 * cupsdSetPrinterState() - Update the current state of a printer.
34 * cupsdStopPrinter() - Stop a printer from printing any jobs...
35 * cupsdUpdatePrinterPPD() - Update keywords in a printer's PPD file.
36 * cupsdUpdatePrinters() - Update printers after a partial reload.
37 * cupsdValidateDest() - Validate a printer/class destination.
38 * cupsdWritePrintcap() - Write a pseudo-printcap file for older
39 * applications that need it...
40 * add_printer_defaults() - Add name-default attributes to the printer
42 * add_printer_filter() - Add a MIME filter for a printer.
43 * add_printer_formats() - Add document-format-supported values for a
45 * compare_printers() - Compare two printers.
46 * delete_printer_filters() - Delete all MIME filters for a printer.
47 * dirty_printer() - Mark config and state files dirty for the
49 * load_ppd() - Load a cached PPD file, updating the cache as
51 * new_media_col() - Create a media-col collection value.
52 * write_irix_config() - Update the config files used by the IRIX
54 * write_irix_state() - Update the status files used by IRIX printing
56 * write_xml_string() - Write a string with XML escaping.
60 * Include necessary headers...
65 #ifdef HAVE_APPLICATIONSERVICES_H
66 # include <ApplicationServices/ApplicationServices.h>
67 #endif /* HAVE_APPLICATIONSERVICES_H */
68 #ifdef HAVE_SYS_MOUNT_H
69 # include <sys/mount.h>
70 #endif /* HAVE_SYS_MOUNT_H */
71 #ifdef HAVE_SYS_STATVFS_H
72 # include <sys/statvfs.h>
73 #elif defined(HAVE_SYS_STATFS_H)
74 # include <sys/statfs.h>
75 #endif /* HAVE_SYS_STATVFS_H */
78 #endif /* HAVE_SYS_VFS_H */
81 #endif /* __APPLE__ */
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 int compare_printers(void *first
, void *second
, void *data
);
93 static void delete_printer_filters(cupsd_printer_t
*p
);
94 static void dirty_printer(cupsd_printer_t
*p
);
95 static void load_ppd(cupsd_printer_t
*p
);
96 static void log_ipp_conformance(cupsd_printer_t
*p
, const char *reason
);
97 static ipp_t
*new_media_col(_pwg_size_t
*size
, const char *source
,
100 static void write_irix_config(cupsd_printer_t
*p
);
101 static void write_irix_state(cupsd_printer_t
*p
);
103 static void write_xml_string(cups_file_t
*fp
, const char *s
);
107 * 'cupsdAddPrinter()' - Add a printer to the system.
110 cupsd_printer_t
* /* O - New printer */
111 cupsdAddPrinter(const char *name
) /* I - Name of printer */
113 cupsd_printer_t
*p
; /* New printer */
114 char uri
[1024], /* Printer URI */
115 uuid
[64]; /* Printer UUID */
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 cupsdSetString(&p
->uuid
, _httpAssembleUUID(ServerName
, RemotePort
, name
, 0,
143 uuid
, sizeof(uuid
)));
144 cupsdSetDeviceURI(p
, "file:///dev/null");
146 p
->state
= IPP_PRINTER_STOPPED
;
147 p
->state_time
= time(NULL
);
149 p
->shared
= DefaultShared
;
150 p
->filetype
= mimeAddType(MimeDatabase
, "printer", name
);
152 cupsdSetString(&p
->job_sheets
[0], "none");
153 cupsdSetString(&p
->job_sheets
[1], "none");
155 cupsdSetString(&p
->error_policy
, ErrorPolicy
);
156 cupsdSetString(&p
->op_policy
, DefaultPolicy
);
158 p
->op_policy_ptr
= DefaultPolicyPtr
;
161 * Insert the printer in the printer list alphabetically...
165 Printers
= cupsArrayNew(compare_printers
, NULL
);
167 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
168 "cupsdAddPrinter: Adding %s to Printers", p
->name
);
169 cupsArrayAdd(Printers
, p
);
171 if (!ImplicitPrinters
)
172 ImplicitPrinters
= cupsArrayNew(compare_printers
, NULL
);
175 * Return the new printer...
183 * 'cupsdCreateCommonData()' - Create the common printer data.
187 cupsdCreateCommonData(void)
189 int i
; /* Looping var */
190 ipp_attribute_t
*attr
; /* Attribute data */
191 cups_dir_t
*dir
; /* Notifier directory */
192 cups_dentry_t
*dent
; /* Notifier directory entry */
193 cups_array_t
*notifiers
; /* Notifier array */
194 char filename
[1024], /* Filename */
195 *notifier
; /* Current notifier */
196 cupsd_policy_t
*p
; /* Current policy */
197 int k_supported
; /* Maximum file size supported */
199 struct statvfs spoolinfo
; /* FS info for spool directory */
200 double spoolsize
; /* FS size */
201 #elif defined(HAVE_STATFS)
202 struct statfs spoolinfo
; /* FS info for spool directory */
203 double spoolsize
; /* FS size */
204 #endif /* HAVE_STATVFS */
205 static const int nups
[] = /* number-up-supported values */
206 { 1, 2, 4, 6, 9, 16 };
207 static const int orients
[4] =/* orientation-requested-supported values */
211 IPP_REVERSE_LANDSCAPE
,
214 static const char * const holds
[] = /* job-hold-until-supported values */
225 static const char * const versions
[] =/* ipp-versions-supported values */
232 static const int ops
[] = /* operations-supported values */
239 IPP_GET_JOB_ATTRIBUTES
,
241 IPP_GET_PRINTER_ATTRIBUTES
,
248 IPP_SET_PRINTER_ATTRIBUTES
,
249 IPP_SET_JOB_ATTRIBUTES
,
250 IPP_GET_PRINTER_SUPPORTED_VALUES
,
251 IPP_CREATE_PRINTER_SUBSCRIPTION
,
252 IPP_CREATE_JOB_SUBSCRIPTION
,
253 IPP_GET_SUBSCRIPTION_ATTRIBUTES
,
254 IPP_GET_SUBSCRIPTIONS
,
255 IPP_RENEW_SUBSCRIPTION
,
256 IPP_CANCEL_SUBSCRIPTION
,
257 IPP_GET_NOTIFICATIONS
,
261 IPP_RELEASE_HELD_NEW_JOBS
,
278 CUPS_AUTHENTICATE_JOB
,
283 static const char * const charsets
[] =/* charset-supported values */
288 static const char * const compressions
[] =
289 { /* document-compression-supported values */
293 #endif /* HAVE_LIBZ */
295 static const char * const media_col_supported
[] =
296 { /* media-col-supported values */
297 "media-bottom-margin",
299 "media-right-margin",
305 static const char * const multiple_document_handling
[] =
306 { /* multiple-document-handling-supported values */
307 "separate-documents-uncollated-copies",
308 "separate-documents-collated-copies"
310 static const char * const notify_attrs
[] =
311 { /* notify-attributes-supported values */
312 "printer-state-change-time",
313 "notify-lease-expiration-time",
314 "notify-subscriber-user-name"
316 static const char * const notify_events
[] =
317 { /* notify-events-supported values */
319 "job-config-changed",
326 "printer-config-changed",
328 "printer-finishings-changed",
329 "printer-media-changed",
333 "printer-state-changed",
340 static const char * const job_creation
[] =
341 { /* job-creation-attributes-supported */
344 "ipp-attribute-fidelity",
351 "multiple-document-handling",
355 "orientation-requested",
358 "printer-resolution",
361 static const char * const job_settable
[] =
362 { /* job-settable-attributes-supported */
370 "multiple-document-handling",
374 "orientation-requested",
377 "printer-resolution",
380 static const char * const pdf_versions
[] =
381 { /* pdf-versions-supported */
392 static const char * const printer_settable
[] =
393 { /* printer-settable-attributes-supported */
397 static const char * const which_jobs
[] =
398 { /* which-jobs-supported values */
412 ippDelete(CommonData
);
414 CommonData
= ippNew();
417 * Get the maximum spool size based on the size of the filesystem used for
418 * the RequestRoot directory. If the host OS doesn't support the statfs call
419 * or the filesystem is larger than 2TiB, always report INT_MAX.
423 if (statvfs(RequestRoot
, &spoolinfo
))
424 k_supported
= INT_MAX
;
425 else if ((spoolsize
= (double)spoolinfo
.f_frsize
* spoolinfo
.f_blocks
/ 1024) >
427 k_supported
= INT_MAX
;
429 k_supported
= (int)spoolsize
;
431 #elif defined(HAVE_STATFS)
432 if (statfs(RequestRoot
, &spoolinfo
))
433 k_supported
= INT_MAX
;
434 else if ((spoolsize
= (double)spoolinfo
.f_bsize
* spoolinfo
.f_blocks
/ 1024) >
436 k_supported
= INT_MAX
;
438 k_supported
= (int)spoolsize
;
441 k_supported
= INT_MAX
;
442 #endif /* HAVE_STATVFS */
445 * This list of attributes is sorted to improve performance when the
446 * client provides a requested-attributes attribute...
449 /* charset-configured */
450 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_CHARSET
| IPP_TAG_COPY
,
451 "charset-configured", NULL
, "utf-8");
453 /* charset-supported */
454 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_CHARSET
| IPP_TAG_COPY
,
455 "charset-supported", sizeof(charsets
) / sizeof(charsets
[0]),
458 /* compression-supported */
459 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
460 "compression-supported",
461 sizeof(compressions
) / sizeof(compressions
[0]),
464 /* copies-supported */
465 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "copies-supported", 1, MaxCopies
);
468 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
| IPP_TAG_COPY
,
469 "cups-version", NULL
, CUPS_SVERSION
+ 6);
471 /* generated-natural-language-supported (no IPP_TAG_COPY) */
472 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_LANGUAGE
,
473 "generated-natural-language-supported", NULL
, DefaultLanguage
);
475 /* ipp-versions-supported */
476 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
477 "ipp-versions-supported", sizeof(versions
) / sizeof(versions
[0]),
480 /* ippget-event-life */
481 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
482 "ippget-event-life", 15);
484 /* job-creation-attributes-supported */
485 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
486 "job-creation-attributes-supported",
487 sizeof(job_creation
) / sizeof(job_creation
[0]),
490 /* job-hold-until-supported */
491 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
492 "job-hold-until-supported", sizeof(holds
) / sizeof(holds
[0]),
495 /* job-ids-supported */
496 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
, "job-ids-supported", 1);
498 /* job-k-octets-supported */
499 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
500 "job-k-octets-supported", k_supported
);
502 /* job-priority-supported */
503 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
504 "job-priority-supported", 100);
506 /* job-settable-attributes-supported */
507 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
508 "job-settable-attributes-supported",
509 sizeof(job_settable
) / sizeof(job_settable
[0]),
512 /* job-sheets-supported */
513 if (cupsArrayCount(Banners
) > 0)
516 * Setup the job-sheets-supported attribute...
519 if (Classification
&& !ClassifyOverride
)
520 attr
= ippAddString(CommonData
, IPP_TAG_PRINTER
,
521 IPP_TAG_NAME
| IPP_TAG_COPY
,
522 "job-sheets-supported", NULL
, Classification
);
524 attr
= ippAddStrings(CommonData
, IPP_TAG_PRINTER
,
525 IPP_TAG_NAME
| IPP_TAG_COPY
,
526 "job-sheets-supported", cupsArrayCount(Banners
) + 1,
530 cupsdLogMessage(CUPSD_LOG_EMERG
,
531 "Unable to allocate memory for "
532 "job-sheets-supported attribute: %s!", strerror(errno
));
533 else if (!Classification
|| ClassifyOverride
)
535 cupsd_banner_t
*banner
; /* Current banner */
538 attr
->values
[0].string
.text
= _cupsStrAlloc("none");
540 for (i
= 1, banner
= (cupsd_banner_t
*)cupsArrayFirst(Banners
);
542 i
++, banner
= (cupsd_banner_t
*)cupsArrayNext(Banners
))
543 attr
->values
[i
].string
.text
= banner
->name
;
547 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
548 "job-sheets-supported", NULL
, "none");
550 /* jpeg-k-octets-supported */
551 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "jpeg-k-octets-supported", 0,
554 /* jpeg-x-dimension-supported */
555 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "jpeg-x-dimension-supported", 0,
558 /* jpeg-y-dimension-supported */
559 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "jpeg-y-dimension-supported", 1,
562 /* media-col-supported */
563 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
564 "media-col-supported",
565 sizeof(media_col_supported
) /
566 sizeof(media_col_supported
[0]), NULL
,
567 media_col_supported
);
569 /* multiple-document-handling-supported */
570 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
571 "multiple-document-handling-supported",
572 sizeof(multiple_document_handling
) /
573 sizeof(multiple_document_handling
[0]), NULL
,
574 multiple_document_handling
);
576 /* multiple-document-jobs-supported */
577 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
,
578 "multiple-document-jobs-supported", 1);
580 /* multiple-operation-time-out */
581 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
582 "multiple-operation-time-out", MultipleOperationTimeout
);
584 /* natural-language-configured (no IPP_TAG_COPY) */
585 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_LANGUAGE
,
586 "natural-language-configured", NULL
, DefaultLanguage
);
588 /* notify-attributes-supported */
589 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
590 "notify-attributes-supported",
591 (int)(sizeof(notify_attrs
) / sizeof(notify_attrs
[0])),
594 /* notify-lease-duration-supported */
595 ippAddRange(CommonData
, IPP_TAG_PRINTER
,
596 "notify-lease-duration-supported", 0,
597 MaxLeaseDuration
? MaxLeaseDuration
: 2147483647);
599 /* notify-max-events-supported */
600 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
601 "notify-max-events-supported", MaxEvents
);
603 /* notify-events-supported */
604 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
605 "notify-events-supported",
606 (int)(sizeof(notify_events
) / sizeof(notify_events
[0])),
607 NULL
, notify_events
);
609 /* notify-pull-method-supported */
610 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
611 "notify-pull-method-supported", NULL
, "ippget");
613 /* notify-schemes-supported */
614 snprintf(filename
, sizeof(filename
), "%s/notifier", ServerBin
);
615 if ((dir
= cupsDirOpen(filename
)) != NULL
)
617 notifiers
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
619 while ((dent
= cupsDirRead(dir
)) != NULL
)
620 if (S_ISREG(dent
->fileinfo
.st_mode
) &&
621 (dent
->fileinfo
.st_mode
& S_IXOTH
) != 0)
622 cupsArrayAdd(notifiers
, _cupsStrAlloc(dent
->filename
));
624 if (cupsArrayCount(notifiers
) > 0)
626 attr
= ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
627 "notify-schemes-supported",
628 cupsArrayCount(notifiers
), NULL
, NULL
);
630 for (i
= 0, notifier
= (char *)cupsArrayFirst(notifiers
);
632 i
++, notifier
= (char *)cupsArrayNext(notifiers
))
633 attr
->values
[i
].string
.text
= notifier
;
636 cupsArrayDelete(notifiers
);
640 /* number-up-supported */
641 ippAddIntegers(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
642 "number-up-supported", sizeof(nups
) / sizeof(nups
[0]), nups
);
644 /* operations-supported */
645 ippAddIntegers(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
646 "operations-supported",
647 sizeof(ops
) / sizeof(ops
[0]) + JobFiles
- 1, ops
);
649 /* orientation-requested-supported */
650 ippAddIntegers(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
651 "orientation-requested-supported", 4, orients
);
653 /* page-ranges-supported */
654 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
, "page-ranges-supported", 1);
656 /* pdf-k-octets-supported */
657 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "pdf-k-octets-supported", 0,
660 /* pdf-versions-supported */
661 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
662 "pdf-versions-supported",
663 sizeof(pdf_versions
) / sizeof(pdf_versions
[0]), NULL
,
666 /* pdl-override-supported */
667 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
668 "pdl-override-supported", NULL
, "attempted");
670 /* printer-op-policy-supported */
671 attr
= ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
672 "printer-op-policy-supported", cupsArrayCount(Policies
),
674 for (i
= 0, p
= (cupsd_policy_t
*)cupsArrayFirst(Policies
);
676 i
++, p
= (cupsd_policy_t
*)cupsArrayNext(Policies
))
677 attr
->values
[i
].string
.text
= p
->name
;
679 /* printer-settable-attributes-supported */
680 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
681 "printer-settable-attributes-supported",
682 sizeof(printer_settable
) / sizeof(printer_settable
[0]),
683 NULL
, printer_settable
);
685 /* server-is-sharing-printers */
686 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
, "server-is-sharing-printers",
687 BrowseLocalProtocols
!= 0 && Browsing
);
689 /* which-jobs-supported */
690 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
691 "which-jobs-supported",
692 sizeof(which_jobs
) / sizeof(which_jobs
[0]), NULL
, which_jobs
);
697 * 'cupsdDeleteAllPrinters()' - Delete all printers from the system.
701 cupsdDeleteAllPrinters(void)
703 cupsd_printer_t
*p
; /* Pointer to current printer/class */
706 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
708 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
710 p
->op_policy_ptr
= DefaultPolicyPtr
;
711 cupsdDeletePrinter(p
, 0);
717 * 'cupsdDeletePrinter()' - Delete a printer from the system.
720 int /* O - 1 if classes affected, 0 otherwise */
722 cupsd_printer_t
*p
, /* I - Printer to delete */
723 int update
) /* I - Update printers.conf? */
725 int i
, /* Looping var */
726 changed
= 0; /* Class changed? */
728 char filename
[1024]; /* Interface script filename */
732 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdDeletePrinter(p=%p(%s), update=%d)",
736 * Save the current position in the Printers array...
739 cupsArraySave(Printers
);
742 * Stop printing on this printer...
745 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, update
);
747 p
->state
= IPP_PRINTER_STOPPED
; /* Force for browsed printers */
750 cupsdSetJobState(p
->job
, IPP_JOB_PENDING
, CUPSD_JOB_FORCE
,
751 update
? "Job stopped due to printer being deleted." :
755 * If this printer is the next for browsing, point to the next one...
760 cupsArrayFind(Printers
, p
);
761 BrowseNext
= (cupsd_printer_t
*)cupsArrayNext(Printers
);
765 * Remove the printer from the list...
768 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
769 "cupsdDeletePrinter: Removing %s from Printers", p
->name
);
770 cupsArrayRemove(Printers
, p
);
772 if (p
->type
& CUPS_PRINTER_IMPLICIT
)
774 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
775 "cupsdDeletePrinter: Removing %s from ImplicitPrinters",
777 cupsArrayRemove(ImplicitPrinters
, p
);
781 * Remove the dummy interface/icon/option files under IRIX...
785 snprintf(filename
, sizeof(filename
), "/var/spool/lp/interface/%s", p
->name
);
788 snprintf(filename
, sizeof(filename
), "/var/spool/lp/gui_interface/ELF/%s.gui",
792 snprintf(filename
, sizeof(filename
), "/var/spool/lp/activeicons/%s", p
->name
);
795 snprintf(filename
, sizeof(filename
), "/var/spool/lp/pod/%s.config", p
->name
);
798 snprintf(filename
, sizeof(filename
), "/var/spool/lp/pod/%s.status", p
->name
);
801 snprintf(filename
, sizeof(filename
), "/var/spool/lp/member/%s", p
->name
);
806 * If p is the default printer, assign a different one...
809 if (p
== DefaultPrinter
)
811 DefaultPrinter
= NULL
;
813 if (UseNetworkDefault
)
816 * Find the first network default printer and use it...
819 cupsd_printer_t
*dp
; /* New default printer */
822 for (dp
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
824 dp
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
825 if (dp
!= p
&& (dp
->type
& CUPS_PRINTER_DEFAULT
))
834 * Remove this printer from any classes...
837 if (!(p
->type
& CUPS_PRINTER_IMPLICIT
))
839 changed
= cupsdDeletePrinterFromClasses(p
);
842 * Deregister from any browse protocols...
845 cupsdDeregisterPrinter(p
, 1);
849 * Free all memory used by the printer...
852 if (p
->printers
!= NULL
)
855 delete_printer_filters(p
);
857 for (i
= 0; i
< p
->num_reasons
; i
++)
858 _cupsStrFree(p
->reasons
[i
]);
861 ippDelete(p
->ppd_attrs
);
863 mimeDeleteType(MimeDatabase
, p
->filetype
);
864 mimeDeleteType(MimeDatabase
, p
->prefiltertype
);
866 cupsdFreeStrings(&(p
->users
));
869 cupsdClearString(&p
->uri
);
870 cupsdClearString(&p
->hostname
);
871 cupsdClearString(&p
->name
);
872 cupsdClearString(&p
->location
);
873 cupsdClearString(&p
->make_model
);
874 cupsdClearString(&p
->info
);
875 cupsdClearString(&p
->job_sheets
[0]);
876 cupsdClearString(&p
->job_sheets
[1]);
877 cupsdClearString(&p
->device_uri
);
878 cupsdClearString(&p
->sanitized_device_uri
);
879 cupsdClearString(&p
->port_monitor
);
880 cupsdClearString(&p
->op_policy
);
881 cupsdClearString(&p
->error_policy
);
883 cupsdClearString(&p
->alert
);
884 cupsdClearString(&p
->alert_description
);
887 cupsdClearString(&p
->pdl
);
888 #endif /* HAVE_DNSSD */
890 cupsArrayDelete(p
->filetypes
);
893 free(p
->browse_attrs
);
895 cupsFreeOptions(p
->num_options
, p
->options
);
900 * Restore the previous position in the Printers array...
903 cupsArrayRestore(Printers
);
910 * 'cupsdFindDest()' - Find a destination in the list.
913 cupsd_printer_t
* /* O - Destination in list */
914 cupsdFindDest(const char *name
) /* I - Name of printer or class to find */
916 cupsd_printer_t key
; /* Search key */
919 key
.name
= (char *)name
;
920 return ((cupsd_printer_t
*)cupsArrayFind(Printers
, &key
));
925 * 'cupsdFindPrinter()' - Find a printer in the list.
928 cupsd_printer_t
* /* O - Printer in list */
929 cupsdFindPrinter(const char *name
) /* I - Name of printer to find */
931 cupsd_printer_t
*p
; /* Printer in list */
934 if ((p
= cupsdFindDest(name
)) != NULL
&& (p
->type
& CUPS_PRINTER_CLASS
))
942 * 'cupsdLoadAllPrinters()' - Load printers from the printers.conf file.
946 cupsdLoadAllPrinters(void)
948 int i
; /* Looping var */
949 cups_file_t
*fp
; /* printers.conf file */
950 int linenum
; /* Current line number */
951 char line
[4096], /* Line from file */
952 *value
, /* Pointer to value */
953 *valueptr
; /* Pointer into value */
954 cupsd_printer_t
*p
; /* Current printer */
958 * Open the printers.conf file...
961 snprintf(line
, sizeof(line
), "%s/printers.conf", ServerRoot
);
962 if ((fp
= cupsdOpenConfFile(line
)) == NULL
)
966 * Read printer configurations until we hit EOF...
972 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
975 * Decode the directive...
978 if (!_cups_strcasecmp(line
, "<Printer") ||
979 !_cups_strcasecmp(line
, "<DefaultPrinter"))
982 * <Printer name> or <DefaultPrinter name>
985 if (p
== NULL
&& value
)
988 * Add the printer and a base file type...
991 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Loading printer %s...", value
);
993 p
= cupsdAddPrinter(value
);
995 p
->state
= IPP_PRINTER_IDLE
;
998 * Set the default printer as needed...
1001 if (!_cups_strcasecmp(line
, "<DefaultPrinter"))
1005 cupsdLogMessage(CUPSD_LOG_ERROR
,
1006 "Syntax error on line %d of printers.conf.", linenum
);
1008 else if (!_cups_strcasecmp(line
, "</Printer>"))
1013 * Close out the current printer...
1016 cupsdSetPrinterAttrs(p
);
1018 if (strncmp(p
->device_uri
, "file:", 5) &&
1019 p
->state
!= IPP_PRINTER_STOPPED
)
1022 * See if the backend exists...
1025 snprintf(line
, sizeof(line
), "%s/backend/%s", ServerBin
,
1028 if ((valueptr
= strchr(line
+ strlen(ServerBin
), ':')) != NULL
)
1029 *valueptr
= '\0'; /* Chop everything but URI scheme */
1031 if (access(line
, 0))
1034 * Backend does not exist, stop printer...
1037 p
->state
= IPP_PRINTER_STOPPED
;
1038 snprintf(p
->state_message
, sizeof(p
->state_message
),
1039 "Backend %s does not exist!", line
);
1046 cupsdLogMessage(CUPSD_LOG_ERROR
,
1047 "Syntax error on line %d of printers.conf.", linenum
);
1051 cupsdLogMessage(CUPSD_LOG_ERROR
,
1052 "Syntax error on line %d of printers.conf.", linenum
);
1054 else if (!_cups_strcasecmp(line
, "UUID"))
1056 if (value
&& !strncmp(value
, "urn:uuid:", 9))
1057 cupsdSetString(&(p
->uuid
), value
);
1059 cupsdLogMessage(CUPSD_LOG_ERROR
,
1060 "Bad UUID on line %d of printers.conf.", linenum
);
1062 else if (!_cups_strcasecmp(line
, "AuthInfoRequired"))
1064 if (!cupsdSetAuthInfoRequired(p
, value
, NULL
))
1065 cupsdLogMessage(CUPSD_LOG_ERROR
,
1066 "Bad AuthInfoRequired on line %d of printers.conf.",
1069 else if (!_cups_strcasecmp(line
, "Info"))
1072 cupsdSetString(&p
->info
, value
);
1074 else if (!_cups_strcasecmp(line
, "MakeModel"))
1077 cupsdSetString(&p
->make_model
, value
);
1079 else if (!_cups_strcasecmp(line
, "Location"))
1082 cupsdSetString(&p
->location
, value
);
1084 else if (!_cups_strcasecmp(line
, "DeviceURI"))
1087 cupsdSetDeviceURI(p
, value
);
1089 cupsdLogMessage(CUPSD_LOG_ERROR
,
1090 "Syntax error on line %d of printers.conf.", linenum
);
1092 else if (!_cups_strcasecmp(line
, "Option") && value
)
1098 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1101 cupsdLogMessage(CUPSD_LOG_ERROR
,
1102 "Syntax error on line %d of printers.conf.", linenum
);
1105 for (; *valueptr
&& isspace(*valueptr
& 255); *valueptr
++ = '\0');
1107 p
->num_options
= cupsAddOption(value
, valueptr
, p
->num_options
,
1111 else if (!_cups_strcasecmp(line
, "PortMonitor"))
1113 if (value
&& strcmp(value
, "none"))
1114 cupsdSetString(&p
->port_monitor
, value
);
1116 cupsdClearString(&p
->port_monitor
);
1118 cupsdLogMessage(CUPSD_LOG_ERROR
,
1119 "Syntax error on line %d of printers.conf.", linenum
);
1121 else if (!_cups_strcasecmp(line
, "Reason"))
1124 strcmp(value
, "connecting-to-device") &&
1125 strcmp(value
, "cups-insecure-filter-warning") &&
1126 strcmp(value
, "cups-missing-filter-warning"))
1128 for (i
= 0 ; i
< p
->num_reasons
; i
++)
1129 if (!strcmp(value
, p
->reasons
[i
]))
1132 if (i
>= p
->num_reasons
&&
1133 p
->num_reasons
< (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
1135 p
->reasons
[p
->num_reasons
] = _cupsStrAlloc(value
);
1140 cupsdLogMessage(CUPSD_LOG_ERROR
,
1141 "Syntax error on line %d of printers.conf.", linenum
);
1143 else if (!_cups_strcasecmp(line
, "State"))
1146 * Set the initial queue state...
1149 if (value
&& !_cups_strcasecmp(value
, "idle"))
1150 p
->state
= IPP_PRINTER_IDLE
;
1151 else if (value
&& !_cups_strcasecmp(value
, "stopped"))
1153 p
->state
= IPP_PRINTER_STOPPED
;
1155 for (i
= 0 ; i
< p
->num_reasons
; i
++)
1156 if (!strcmp("paused", p
->reasons
[i
]))
1159 if (i
>= p
->num_reasons
&&
1160 p
->num_reasons
< (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
1162 p
->reasons
[p
->num_reasons
] = _cupsStrAlloc("paused");
1167 cupsdLogMessage(CUPSD_LOG_ERROR
,
1168 "Syntax error on line %d of printers.conf.", linenum
);
1170 else if (!_cups_strcasecmp(line
, "StateMessage"))
1173 * Set the initial queue state message...
1177 strlcpy(p
->state_message
, value
, sizeof(p
->state_message
));
1179 else if (!_cups_strcasecmp(line
, "StateTime"))
1182 * Set the state time...
1186 p
->state_time
= atoi(value
);
1188 else if (!_cups_strcasecmp(line
, "Accepting"))
1191 * Set the initial accepting state...
1195 (!_cups_strcasecmp(value
, "yes") ||
1196 !_cups_strcasecmp(value
, "on") ||
1197 !_cups_strcasecmp(value
, "true")))
1200 (!_cups_strcasecmp(value
, "no") ||
1201 !_cups_strcasecmp(value
, "off") ||
1202 !_cups_strcasecmp(value
, "false")))
1205 cupsdLogMessage(CUPSD_LOG_ERROR
,
1206 "Syntax error on line %d of printers.conf.", linenum
);
1208 else if (!_cups_strcasecmp(line
, "Type"))
1211 p
->type
= atoi(value
);
1213 cupsdLogMessage(CUPSD_LOG_ERROR
,
1214 "Syntax error on line %d of printers.conf.", linenum
);
1216 else if (!_cups_strcasecmp(line
, "Shared"))
1219 * Set the initial shared state...
1223 (!_cups_strcasecmp(value
, "yes") ||
1224 !_cups_strcasecmp(value
, "on") ||
1225 !_cups_strcasecmp(value
, "true")))
1228 (!_cups_strcasecmp(value
, "no") ||
1229 !_cups_strcasecmp(value
, "off") ||
1230 !_cups_strcasecmp(value
, "false")))
1233 cupsdLogMessage(CUPSD_LOG_ERROR
,
1234 "Syntax error on line %d of printers.conf.", linenum
);
1236 else if (!_cups_strcasecmp(line
, "JobSheets"))
1239 * Set the initial job sheets...
1244 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1249 cupsdSetString(&p
->job_sheets
[0], value
);
1251 while (isspace(*valueptr
& 255))
1256 for (value
= valueptr
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1261 cupsdSetString(&p
->job_sheets
[1], value
);
1265 cupsdLogMessage(CUPSD_LOG_ERROR
,
1266 "Syntax error on line %d of printers.conf.", linenum
);
1268 else if (!_cups_strcasecmp(line
, "AllowUser"))
1273 cupsdAddString(&(p
->users
), value
);
1276 cupsdLogMessage(CUPSD_LOG_ERROR
,
1277 "Syntax error on line %d of printers.conf.", linenum
);
1279 else if (!_cups_strcasecmp(line
, "DenyUser"))
1284 cupsdAddString(&(p
->users
), value
);
1287 cupsdLogMessage(CUPSD_LOG_ERROR
,
1288 "Syntax error on line %d of printers.conf.", linenum
);
1290 else if (!_cups_strcasecmp(line
, "QuotaPeriod"))
1293 p
->quota_period
= atoi(value
);
1295 cupsdLogMessage(CUPSD_LOG_ERROR
,
1296 "Syntax error on line %d of printers.conf.", linenum
);
1298 else if (!_cups_strcasecmp(line
, "PageLimit"))
1301 p
->page_limit
= atoi(value
);
1303 cupsdLogMessage(CUPSD_LOG_ERROR
,
1304 "Syntax error on line %d of printers.conf.", linenum
);
1306 else if (!_cups_strcasecmp(line
, "KLimit"))
1309 p
->k_limit
= atoi(value
);
1311 cupsdLogMessage(CUPSD_LOG_ERROR
,
1312 "Syntax error on line %d of printers.conf.", linenum
);
1314 else if (!_cups_strcasecmp(line
, "OpPolicy"))
1318 cupsd_policy_t
*pol
; /* Policy */
1321 if ((pol
= cupsdFindPolicy(value
)) != NULL
)
1323 cupsdSetString(&p
->op_policy
, value
);
1324 p
->op_policy_ptr
= pol
;
1327 cupsdLogMessage(CUPSD_LOG_ERROR
,
1328 "Bad policy \"%s\" on line %d of printers.conf",
1332 cupsdLogMessage(CUPSD_LOG_ERROR
,
1333 "Syntax error on line %d of printers.conf.", linenum
);
1335 else if (!_cups_strcasecmp(line
, "ErrorPolicy"))
1338 cupsdSetString(&p
->error_policy
, value
);
1340 cupsdLogMessage(CUPSD_LOG_ERROR
,
1341 "Syntax error on line %d of printers.conf.", linenum
);
1343 else if (!_cups_strcasecmp(line
, "Attribute") && value
)
1345 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1348 cupsdLogMessage(CUPSD_LOG_ERROR
,
1349 "Syntax error on line %d of printers.conf.", linenum
);
1352 for (; *valueptr
&& isspace(*valueptr
& 255); *valueptr
++ = '\0');
1355 cupsdSetPrinterAttrs(p
);
1357 if (!strcmp(value
, "marker-change-time"))
1358 p
->marker_time
= atoi(valueptr
);
1360 cupsdSetPrinterAttr(p
, value
, valueptr
);
1363 else if (_cups_strcasecmp(line
, "Filter") &&
1364 _cups_strcasecmp(line
, "Prefilter") &&
1365 _cups_strcasecmp(line
, "Product"))
1368 * Something else we don't understand (and that wasn't used in a prior
1369 * release of CUPS...
1372 cupsdLogMessage(CUPSD_LOG_ERROR
,
1373 "Unknown configuration directive %s on line %d of "
1374 "printers.conf.", line
, linenum
);
1383 * 'cupsdRenamePrinter()' - Rename a printer.
1388 cupsd_printer_t
*p
, /* I - Printer */
1389 const char *name
) /* I - New name */
1392 * Remove the printer from the array(s) first...
1395 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1396 "cupsdRenamePrinter: Removing %s from Printers", p
->name
);
1397 cupsArrayRemove(Printers
, p
);
1399 if (p
->type
& CUPS_PRINTER_IMPLICIT
)
1401 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1402 "cupsdRenamePrinter: Removing %s from ImplicitPrinters",
1404 cupsArrayRemove(ImplicitPrinters
, p
);
1408 * Rename the printer type...
1411 mimeDeleteType(MimeDatabase
, p
->filetype
);
1412 p
->filetype
= mimeAddType(MimeDatabase
, "printer", name
);
1414 if (p
->prefiltertype
)
1416 mimeDeleteType(MimeDatabase
, p
->prefiltertype
);
1417 p
->prefiltertype
= mimeAddType(MimeDatabase
, "prefilter", name
);
1421 * Rename the printer...
1424 cupsdSetString(&p
->name
, name
);
1427 * Reset printer attributes...
1430 cupsdSetPrinterAttrs(p
);
1433 * Add the printer back to the printer array(s)...
1436 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1437 "cupsdRenamePrinter: Adding %s to Printers", p
->name
);
1438 cupsArrayAdd(Printers
, p
);
1440 if (p
->type
& CUPS_PRINTER_IMPLICIT
)
1442 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1443 "cupsdRenamePrinter: Adding %s to ImplicitPrinters",
1445 cupsArrayAdd(ImplicitPrinters
, p
);
1451 * 'cupsdSaveAllPrinters()' - Save all printer definitions to the printers.conf
1456 cupsdSaveAllPrinters(void)
1458 int i
; /* Looping var */
1459 cups_file_t
*fp
; /* printers.conf file */
1460 char filename
[1024], /* printers.conf filename */
1461 temp
[1024], /* Temporary string */
1462 value
[2048], /* Value string */
1463 *ptr
, /* Pointer into value */
1464 *name
; /* Current user/group name */
1465 cupsd_printer_t
*printer
; /* Current printer class */
1466 time_t curtime
; /* Current time */
1467 struct tm
*curdate
; /* Current date */
1468 cups_option_t
*option
; /* Current option */
1469 ipp_attribute_t
*marker
; /* Current marker attribute */
1473 * Create the printers.conf file...
1476 snprintf(filename
, sizeof(filename
), "%s/printers.conf", ServerRoot
);
1478 if ((fp
= cupsdCreateConfFile(filename
, ConfigFilePerm
& 0600)) == NULL
)
1481 cupsdLogMessage(CUPSD_LOG_INFO
, "Saving printers.conf...");
1484 * Write a small header to the file...
1487 curtime
= time(NULL
);
1488 curdate
= localtime(&curtime
);
1489 strftime(temp
, sizeof(temp
) - 1, "%Y-%m-%d %H:%M", curdate
);
1491 cupsFilePuts(fp
, "# Printer configuration file for " CUPS_SVERSION
"\n");
1492 cupsFilePrintf(fp
, "# Written by cupsd on %s\n", temp
);
1493 cupsFilePuts(fp
, "# DO NOT EDIT THIS FILE WHEN CUPSD IS RUNNING\n");
1496 * Write each local printer known to the system...
1499 for (printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
1501 printer
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
1504 * Skip remote destinations and printer classes...
1507 if ((printer
->type
& CUPS_PRINTER_DISCOVERED
) ||
1508 (printer
->type
& CUPS_PRINTER_CLASS
) ||
1509 (printer
->type
& CUPS_PRINTER_IMPLICIT
))
1513 * Write printers as needed...
1516 if (printer
== DefaultPrinter
)
1517 cupsFilePrintf(fp
, "<DefaultPrinter %s>\n", printer
->name
);
1519 cupsFilePrintf(fp
, "<Printer %s>\n", printer
->name
);
1521 cupsFilePrintf(fp
, "UUID %s\n", printer
->uuid
);
1523 if (printer
->num_auth_info_required
> 0)
1525 switch (printer
->num_auth_info_required
)
1528 strlcpy(value
, printer
->auth_info_required
[0], sizeof(value
));
1532 snprintf(value
, sizeof(value
), "%s,%s",
1533 printer
->auth_info_required
[0],
1534 printer
->auth_info_required
[1]);
1539 snprintf(value
, sizeof(value
), "%s,%s,%s",
1540 printer
->auth_info_required
[0],
1541 printer
->auth_info_required
[1],
1542 printer
->auth_info_required
[2]);
1546 cupsFilePutConf(fp
, "AuthInfoRequired", value
);
1550 cupsFilePutConf(fp
, "Info", printer
->info
);
1552 if (printer
->location
)
1553 cupsFilePutConf(fp
, "Location", printer
->location
);
1555 if (printer
->make_model
)
1556 cupsFilePutConf(fp
, "MakeModel", printer
->make_model
);
1558 cupsFilePutConf(fp
, "DeviceURI", printer
->device_uri
);
1560 if (printer
->port_monitor
)
1561 cupsFilePutConf(fp
, "PortMonitor", printer
->port_monitor
);
1563 if (printer
->state
== IPP_PRINTER_STOPPED
)
1565 cupsFilePuts(fp
, "State Stopped\n");
1567 if (printer
->state_message
)
1568 cupsFilePutConf(fp
, "StateMessage", printer
->state_message
);
1571 cupsFilePuts(fp
, "State Idle\n");
1573 cupsFilePrintf(fp
, "StateTime %d\n", (int)printer
->state_time
);
1575 for (i
= 0; i
< printer
->num_reasons
; i
++)
1576 if (strcmp(printer
->reasons
[i
], "connecting-to-device") &&
1577 strcmp(printer
->reasons
[i
], "cups-insecure-filter-warning") &&
1578 strcmp(printer
->reasons
[i
], "cups-missing-filter-warning"))
1579 cupsFilePutConf(fp
, "Reason", printer
->reasons
[i
]);
1581 cupsFilePrintf(fp
, "Type %d\n", printer
->type
);
1583 if (printer
->accepting
)
1584 cupsFilePuts(fp
, "Accepting Yes\n");
1586 cupsFilePuts(fp
, "Accepting No\n");
1588 if (printer
->shared
)
1589 cupsFilePuts(fp
, "Shared Yes\n");
1591 cupsFilePuts(fp
, "Shared No\n");
1593 snprintf(value
, sizeof(value
), "%s %s", printer
->job_sheets
[0],
1594 printer
->job_sheets
[1]);
1595 cupsFilePutConf(fp
, "JobSheets", value
);
1597 cupsFilePrintf(fp
, "QuotaPeriod %d\n", printer
->quota_period
);
1598 cupsFilePrintf(fp
, "PageLimit %d\n", printer
->page_limit
);
1599 cupsFilePrintf(fp
, "KLimit %d\n", printer
->k_limit
);
1601 for (name
= (char *)cupsArrayFirst(printer
->users
);
1603 name
= (char *)cupsArrayNext(printer
->users
))
1604 cupsFilePutConf(fp
, printer
->deny_users
? "DenyUser" : "AllowUser", name
);
1606 if (printer
->op_policy
)
1607 cupsFilePutConf(fp
, "OpPolicy", printer
->op_policy
);
1608 if (printer
->error_policy
)
1609 cupsFilePutConf(fp
, "ErrorPolicy", printer
->error_policy
);
1611 for (i
= printer
->num_options
, option
= printer
->options
;
1615 snprintf(value
, sizeof(value
), "%s %s", option
->name
, option
->value
);
1616 cupsFilePutConf(fp
, "Option", value
);
1619 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-colors",
1620 IPP_TAG_NAME
)) != NULL
)
1622 snprintf(value
, sizeof(value
), "%s ", marker
->name
);
1624 for (i
= 0, ptr
= value
+ strlen(value
);
1625 i
< marker
->num_values
&& ptr
< (value
+ sizeof(value
) - 1);
1631 strlcpy(ptr
, marker
->values
[i
].string
.text
,
1632 value
+ sizeof(value
) - ptr
);
1637 cupsFilePutConf(fp
, "Attribute", value
);
1640 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-levels",
1641 IPP_TAG_INTEGER
)) != NULL
)
1643 cupsFilePrintf(fp
, "Attribute %s %d", marker
->name
,
1644 marker
->values
[0].integer
);
1645 for (i
= 1; i
< marker
->num_values
; i
++)
1646 cupsFilePrintf(fp
, ",%d", marker
->values
[i
].integer
);
1647 cupsFilePuts(fp
, "\n");
1650 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-low-levels",
1651 IPP_TAG_INTEGER
)) != NULL
)
1653 cupsFilePrintf(fp
, "Attribute %s %d", marker
->name
,
1654 marker
->values
[0].integer
);
1655 for (i
= 1; i
< marker
->num_values
; i
++)
1656 cupsFilePrintf(fp
, ",%d", marker
->values
[i
].integer
);
1657 cupsFilePuts(fp
, "\n");
1660 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-high-levels",
1661 IPP_TAG_INTEGER
)) != NULL
)
1663 cupsFilePrintf(fp
, "Attribute %s %d", marker
->name
,
1664 marker
->values
[0].integer
);
1665 for (i
= 1; i
< marker
->num_values
; i
++)
1666 cupsFilePrintf(fp
, ",%d", marker
->values
[i
].integer
);
1667 cupsFilePuts(fp
, "\n");
1670 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-message",
1671 IPP_TAG_TEXT
)) != NULL
)
1673 snprintf(value
, sizeof(value
), "%s %s", marker
->name
,
1674 marker
->values
[0].string
.text
);
1676 cupsFilePutConf(fp
, "Attribute", value
);
1679 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-names",
1680 IPP_TAG_NAME
)) != NULL
)
1682 snprintf(value
, sizeof(value
), "%s ", marker
->name
);
1684 for (i
= 0, ptr
= value
+ strlen(value
);
1685 i
< marker
->num_values
&& ptr
< (value
+ sizeof(value
) - 1);
1691 strlcpy(ptr
, marker
->values
[i
].string
.text
,
1692 value
+ sizeof(value
) - ptr
);
1697 cupsFilePutConf(fp
, "Attribute", value
);
1700 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-types",
1701 IPP_TAG_KEYWORD
)) != NULL
)
1703 snprintf(value
, sizeof(value
), "%s ", marker
->name
);
1705 for (i
= 0, ptr
= value
+ strlen(value
);
1706 i
< marker
->num_values
&& ptr
< (value
+ sizeof(value
) - 1);
1712 strlcpy(ptr
, marker
->values
[i
].string
.text
,
1713 value
+ sizeof(value
) - ptr
);
1718 cupsFilePutConf(fp
, "Attribute", value
);
1721 if (printer
->marker_time
)
1722 cupsFilePrintf(fp
, "Attribute marker-change-time %ld\n",
1723 (long)printer
->marker_time
);
1725 cupsFilePuts(fp
, "</Printer>\n");
1729 * Make IRIX desktop & printer status happy
1732 write_irix_state(printer
);
1736 cupsdCloseCreatedConfFile(fp
, filename
);
1741 * 'cupsdSetAuthInfoRequired()' - Set the required authentication info.
1744 int /* O - 1 if value OK, 0 otherwise */
1745 cupsdSetAuthInfoRequired(
1746 cupsd_printer_t
*p
, /* I - Printer */
1747 const char *values
, /* I - Plain text value (or NULL) */
1748 ipp_attribute_t
*attr
) /* I - IPP attribute value (or NULL) */
1750 int i
; /* Looping var */
1753 p
->num_auth_info_required
= 0;
1756 * Do we have a plain text value?
1762 * Yes, grab the keywords...
1765 const char *end
; /* End of current value */
1768 while (*values
&& p
->num_auth_info_required
< 4)
1770 if ((end
= strchr(values
, ',')) == NULL
)
1771 end
= values
+ strlen(values
);
1773 if ((end
- values
) == 4 && !strncmp(values
, "none", 4))
1775 if (p
->num_auth_info_required
!= 0 || *end
)
1778 p
->auth_info_required
[p
->num_auth_info_required
] = "none";
1779 p
->num_auth_info_required
++;
1783 else if ((end
- values
) == 9 && !strncmp(values
, "negotiate", 9))
1785 if (p
->num_auth_info_required
!= 0 || *end
)
1788 p
->auth_info_required
[p
->num_auth_info_required
] = "negotiate";
1789 p
->num_auth_info_required
++;
1792 * Don't allow sharing of queues that require Kerberos authentication.
1797 cupsdDeregisterPrinter(p
, 1);
1801 else if ((end
- values
) == 6 && !strncmp(values
, "domain", 6))
1803 p
->auth_info_required
[p
->num_auth_info_required
] = "domain";
1804 p
->num_auth_info_required
++;
1806 else if ((end
- values
) == 8 && !strncmp(values
, "password", 8))
1808 p
->auth_info_required
[p
->num_auth_info_required
] = "password";
1809 p
->num_auth_info_required
++;
1811 else if ((end
- values
) == 8 && !strncmp(values
, "username", 8))
1813 p
->auth_info_required
[p
->num_auth_info_required
] = "username";
1814 p
->num_auth_info_required
++;
1819 values
= (*end
) ? end
+ 1 : end
;
1822 if (p
->num_auth_info_required
== 0)
1824 p
->auth_info_required
[0] = "none";
1825 p
->num_auth_info_required
= 1;
1829 * Update the printer-type value as needed...
1832 if (p
->num_auth_info_required
> 1 ||
1833 strcmp(p
->auth_info_required
[0], "none"))
1834 p
->type
|= CUPS_PRINTER_AUTHENTICATED
;
1836 p
->type
&= ~CUPS_PRINTER_AUTHENTICATED
;
1842 * Grab values from an attribute instead...
1845 if (!attr
|| attr
->num_values
> 4)
1848 for (i
= 0; i
< attr
->num_values
; i
++)
1850 if (!strcmp(attr
->values
[i
].string
.text
, "none"))
1852 if (p
->num_auth_info_required
!= 0 || attr
->num_values
!= 1)
1855 p
->auth_info_required
[p
->num_auth_info_required
] = "none";
1856 p
->num_auth_info_required
++;
1860 else if (!strcmp(attr
->values
[i
].string
.text
, "negotiate"))
1862 if (p
->num_auth_info_required
!= 0 || attr
->num_values
!= 1)
1865 p
->auth_info_required
[p
->num_auth_info_required
] = "negotiate";
1866 p
->num_auth_info_required
++;
1869 * Don't allow sharing of queues that require Kerberos authentication.
1874 cupsdDeregisterPrinter(p
, 1);
1880 else if (!strcmp(attr
->values
[i
].string
.text
, "domain"))
1882 p
->auth_info_required
[p
->num_auth_info_required
] = "domain";
1883 p
->num_auth_info_required
++;
1885 else if (!strcmp(attr
->values
[i
].string
.text
, "password"))
1887 p
->auth_info_required
[p
->num_auth_info_required
] = "password";
1888 p
->num_auth_info_required
++;
1890 else if (!strcmp(attr
->values
[i
].string
.text
, "username"))
1892 p
->auth_info_required
[p
->num_auth_info_required
] = "username";
1893 p
->num_auth_info_required
++;
1904 * 'cupsdSetDeviceURI()' - Set the device URI for a printer.
1908 cupsdSetDeviceURI(cupsd_printer_t
*p
, /* I - Printer */
1909 const char *uri
) /* I - Device URI */
1911 char buffer
[1024], /* URI buffer */
1912 *start
, /* Start of data after scheme */
1913 *slash
, /* First slash after scheme:// */
1914 *ptr
; /* Pointer into user@host:port part */
1918 * Set the full device URI..
1921 cupsdSetString(&(p
->device_uri
), uri
);
1924 * Copy the device URI to a temporary buffer so we can sanitize any auth
1928 strlcpy(buffer
, uri
, sizeof(buffer
));
1931 * Find the end of the scheme:// part...
1934 if ((ptr
= strchr(buffer
, ':')) != NULL
)
1936 for (start
= ptr
+ 1; *start
; start
++)
1941 * Find the next slash (/) in the URI...
1944 if ((slash
= strchr(start
, '/')) == NULL
)
1945 slash
= start
+ strlen(start
); /* No slash, point to the end */
1948 * Check for an @ sign before the slash...
1951 if ((ptr
= strchr(start
, '@')) != NULL
&& ptr
< slash
)
1954 * Found an @ sign and it is before the resource part, so we have
1955 * an authentication string. Copy the remaining URI over the
1956 * authentication string...
1959 _cups_strcpy(start
, ptr
+ 1);
1964 * Save the sanitized URI...
1967 cupsdSetString(&(p
->sanitized_device_uri
), buffer
);
1972 * 'cupsdSetPrinterAttr()' - Set a printer attribute.
1976 cupsdSetPrinterAttr(
1977 cupsd_printer_t
*p
, /* I - Printer */
1978 const char *name
, /* I - Attribute name */
1979 char *value
) /* I - Attribute value string */
1981 ipp_attribute_t
*attr
; /* Attribute */
1982 int i
, /* Looping var */
1983 count
; /* Number of values */
1984 char *ptr
; /* Pointer into value */
1985 ipp_tag_t value_tag
; /* Value tag for this attribute */
1989 * Don't allow empty values...
1992 if (!*value
&& strcmp(name
, "marker-message"))
1994 cupsdLogMessage(CUPSD_LOG_ERROR
, "Ignoring empty \"%s\" attribute", name
);
1999 * Count the number of values...
2002 for (count
= 1, ptr
= value
;
2003 (ptr
= strchr(ptr
, ',')) != NULL
;
2007 * Then add or update the attribute as needed...
2010 if (!strcmp(name
, "marker-levels") || !strcmp(name
, "marker-low-levels") ||
2011 !strcmp(name
, "marker-high-levels"))
2017 if ((attr
= ippFindAttribute(p
->attrs
, name
, IPP_TAG_INTEGER
)) != NULL
&&
2018 attr
->num_values
< count
)
2020 ippDeleteAttribute(p
->attrs
, attr
);
2025 attr
->num_values
= count
;
2027 attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
, name
,
2032 cupsdLogMessage(CUPSD_LOG_ERROR
,
2033 "Unable to allocate memory for printer attribute "
2034 "(%d values)", count
);
2038 for (i
= 0; i
< count
; i
++)
2040 if ((ptr
= strchr(value
, ',')) != NULL
)
2043 attr
->values
[i
].integer
= strtol(value
, NULL
, 10);
2052 * Name or keyword values...
2055 if (!strcmp(name
, "marker-types"))
2056 value_tag
= IPP_TAG_KEYWORD
;
2057 else if (!strcmp(name
, "marker-message"))
2058 value_tag
= IPP_TAG_TEXT
;
2060 value_tag
= IPP_TAG_NAME
;
2062 if ((attr
= ippFindAttribute(p
->attrs
, name
, value_tag
)) != NULL
&&
2063 attr
->num_values
< count
)
2065 ippDeleteAttribute(p
->attrs
, attr
);
2071 for (i
= 0; i
< attr
->num_values
; i
++)
2072 _cupsStrFree(attr
->values
[i
].string
.text
);
2074 attr
->num_values
= count
;
2077 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, value_tag
, name
,
2082 cupsdLogMessage(CUPSD_LOG_ERROR
,
2083 "Unable to allocate memory for printer attribute "
2084 "(%d values)", count
);
2088 for (i
= 0; i
< count
; i
++)
2090 if ((ptr
= strchr(value
, ',')) != NULL
)
2093 attr
->values
[i
].string
.text
= _cupsStrAlloc(value
);
2103 * 'cupsdSetPrinterAttrs()' - Set printer attributes based upon the PPD file.
2107 cupsdSetPrinterAttrs(cupsd_printer_t
*p
)/* I - Printer to setup */
2109 int i
, /* Looping var */
2110 length
; /* Length of browse attributes */
2111 char resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
2112 int num_air
; /* Number of auth-info-required values */
2113 const char * const *air
; /* auth-info-required values */
2114 cupsd_location_t
*auth
; /* Pointer to authentication element */
2115 const char *auth_supported
; /* Authentication supported */
2116 ipp_t
*oldattrs
; /* Old printer attributes */
2117 ipp_attribute_t
*attr
; /* Attribute data */
2118 cups_option_t
*option
; /* Current printer option */
2119 char *name
, /* Current user/group name */
2120 *filter
; /* Current filter */
2121 static const char * const air_none
[] =
2122 { /* No authentication */
2125 static const char * const air_userpass
[] =
2126 { /* Basic/Digest authentication */
2132 DEBUG_printf(("cupsdSetPrinterAttrs: entering name = %s, type = %x\n", p
->name
,
2136 * Make sure that we have the common attributes defined...
2140 cupsdCreateCommonData();
2143 * Clear out old filters, if any...
2146 delete_printer_filters(p
);
2149 * Figure out the authentication that is required for the printer.
2152 auth_supported
= "requesting-user-name";
2156 if (p
->num_auth_info_required
> 0 && strcmp(p
->auth_info_required
[0], "none"))
2158 num_air
= p
->num_auth_info_required
;
2159 air
= p
->auth_info_required
;
2161 else if ((p
->type
& CUPS_PRINTER_AUTHENTICATED
) &&
2162 (p
->type
& CUPS_PRINTER_DISCOVERED
))
2168 if (p
->type
& CUPS_PRINTER_CLASS
)
2169 snprintf(resource
, sizeof(resource
), "/classes/%s", p
->name
);
2171 snprintf(resource
, sizeof(resource
), "/printers/%s", p
->name
);
2173 if ((auth
= cupsdFindBest(resource
, HTTP_POST
)) == NULL
||
2174 auth
->type
== CUPSD_AUTH_NONE
)
2175 auth
= cupsdFindPolicyOp(p
->op_policy_ptr
, IPP_PRINT_JOB
);
2179 int auth_type
; /* Authentication type */
2182 if ((auth_type
= auth
->type
) == CUPSD_AUTH_DEFAULT
)
2183 auth_type
= DefaultAuthType
;
2185 if (auth_type
== CUPSD_AUTH_BASIC
|| auth_type
== CUPSD_AUTH_BASICDIGEST
)
2186 auth_supported
= "basic";
2187 else if (auth_type
== CUPSD_AUTH_DIGEST
)
2188 auth_supported
= "digest";
2190 else if (auth_type
== CUPSD_AUTH_NEGOTIATE
)
2191 auth_supported
= "negotiate";
2192 #endif /* HAVE_GSSAPI */
2194 if (!(p
->type
& CUPS_PRINTER_DISCOVERED
))
2196 if (auth_type
!= CUPSD_AUTH_NONE
)
2197 p
->type
|= CUPS_PRINTER_AUTHENTICATED
;
2199 p
->type
&= ~CUPS_PRINTER_AUTHENTICATED
;
2202 else if (!(p
->type
& CUPS_PRINTER_DISCOVERED
))
2203 p
->type
&= ~CUPS_PRINTER_AUTHENTICATED
;
2206 * Create the required IPP attributes for a printer...
2209 oldattrs
= p
->attrs
;
2210 p
->attrs
= ippNew();
2212 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2213 "uri-authentication-supported", NULL
, auth_supported
);
2214 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2215 "uri-security-supported", NULL
, "none");
2216 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
, "printer-name", NULL
,
2218 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-location",
2219 NULL
, p
->location
? p
->location
: "");
2220 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-info",
2221 NULL
, p
->info
? p
->info
: "");
2222 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "printer-uuid", NULL
,
2225 if (cupsArrayCount(p
->users
) > 0)
2228 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2229 "requesting-user-name-denied",
2230 cupsArrayCount(p
->users
), NULL
, NULL
);
2232 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2233 "requesting-user-name-allowed",
2234 cupsArrayCount(p
->users
), NULL
, NULL
);
2236 for (i
= 0, name
= (char *)cupsArrayFirst(p
->users
);
2238 i
++, name
= (char *)cupsArrayNext(p
->users
))
2239 attr
->values
[i
].string
.text
= _cupsStrRetain(name
);
2242 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2243 "job-quota-period", p
->quota_period
);
2244 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2245 "job-k-limit", p
->k_limit
);
2246 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2247 "job-page-limit", p
->page_limit
);
2248 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2249 "auth-info-required", num_air
, NULL
, air
);
2251 if (cupsArrayCount(Banners
) > 0 && !(p
->type
& CUPS_PRINTER_DISCOVERED
))
2254 * Setup the job-sheets-default attribute...
2257 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2258 "job-sheets-default", 2, NULL
, NULL
);
2262 attr
->values
[0].string
.text
= _cupsStrAlloc(Classification
?
2263 Classification
: p
->job_sheets
[0]);
2264 attr
->values
[1].string
.text
= _cupsStrAlloc(Classification
?
2265 Classification
: p
->job_sheets
[1]);
2272 if (p
->type
& CUPS_PRINTER_DISCOVERED
)
2275 * Tell the client this is a remote printer of some type...
2278 if (strchr(p
->uri
, '?'))
2281 * Strip trailing "?options" from URI...
2284 char *ptr
; /* Pointer into URI */
2286 strlcpy(resource
, p
->uri
, sizeof(resource
));
2287 if ((ptr
= strchr(resource
, '?')) != NULL
)
2290 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
2291 "printer-uri-supported", NULL
, resource
);
2294 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
2295 "printer-uri-supported", NULL
, p
->uri
);
2297 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "printer-more-info",
2301 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
2302 "printer-make-and-model", NULL
, p
->make_model
);
2304 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "device-uri", NULL
,
2313 * Assign additional attributes depending on whether this is a printer
2317 if (p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
))
2320 p
->type
&= ~CUPS_PRINTER_OPTIONS
;
2323 * Add class-specific attributes...
2326 if ((p
->type
& CUPS_PRINTER_IMPLICIT
) && p
->num_printers
> 0 &&
2327 p
->printers
[0]->make_model
)
2328 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
2329 "printer-make-and-model", NULL
, p
->printers
[0]->make_model
);
2331 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
2332 "printer-make-and-model", NULL
, "Local Printer Class");
2334 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "device-uri", NULL
,
2335 "file:///dev/null");
2337 if (p
->num_printers
> 0)
2340 * Add a list of member names; URIs are added in copy_printer_attrs...
2343 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2344 "member-names", p
->num_printers
, NULL
, NULL
);
2345 p
->type
|= CUPS_PRINTER_OPTIONS
;
2347 for (i
= 0; i
< p
->num_printers
; i
++)
2350 attr
->values
[i
].string
.text
= _cupsStrRetain(p
->printers
[i
]->name
);
2352 p
->type
&= ~CUPS_PRINTER_OPTIONS
| p
->printers
[i
]->type
;
2359 * Add printer-specific attributes...
2362 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "device-uri", NULL
,
2363 p
->sanitized_device_uri
);
2366 * Assign additional attributes from the PPD file (if any)...
2372 * Add filters for printer...
2375 cupsdSetPrinterReasons(p
, "-cups-missing-filter-warning,"
2376 "cups-insecure-filter-warning");
2378 if (p
->pc
&& p
->pc
->filters
)
2380 for (filter
= (char *)cupsArrayFirst(p
->pc
->filters
);
2382 filter
= (char *)cupsArrayNext(p
->pc
->filters
))
2383 add_printer_filter(p
, p
->filetype
, filter
);
2385 else if (!(p
->type
& CUPS_PRINTER_REMOTE
))
2387 char interface
[1024]; /* Interface script */
2390 snprintf(interface
, sizeof(interface
), "%s/interfaces/%s", ServerRoot
,
2392 if (!access(interface
, X_OK
))
2395 * Yes, we have a System V style interface script; use it!
2398 snprintf(interface
, sizeof(interface
), "*/* 0 %s/interfaces/%s",
2399 ServerRoot
, p
->name
);
2400 add_printer_filter(p
, p
->filetype
, interface
);
2405 * Add a filter from application/vnd.cups-raw to printer/name to
2406 * handle "raw" printing by users.
2409 add_printer_filter(p
, p
->filetype
, "application/vnd.cups-raw 0 -");
2412 * Add a PostScript filter, since this is still possibly PS printer.
2415 add_printer_filter(p
, p
->filetype
,
2416 "application/vnd.cups-postscript 0 -");
2420 if (p
->pc
&& p
->pc
->prefilters
)
2422 if (!p
->prefiltertype
)
2423 p
->prefiltertype
= mimeAddType(MimeDatabase
, "prefilter", p
->name
);
2425 for (filter
= (char *)cupsArrayFirst(p
->pc
->prefilters
);
2427 filter
= (char *)cupsArrayNext(p
->pc
->prefilters
))
2428 add_printer_filter(p
, p
->prefiltertype
, filter
);
2434 * Copy marker attributes as needed...
2439 ipp_attribute_t
*oldattr
; /* Old attribute */
2442 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-colors",
2443 IPP_TAG_NAME
)) != NULL
)
2445 if ((attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2446 "marker-colors", oldattr
->num_values
, NULL
,
2449 for (i
= 0; i
< oldattr
->num_values
; i
++)
2450 attr
->values
[i
].string
.text
=
2451 _cupsStrRetain(oldattr
->values
[i
].string
.text
);
2455 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-levels",
2456 IPP_TAG_INTEGER
)) != NULL
)
2458 if ((attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2459 "marker-levels", oldattr
->num_values
,
2462 for (i
= 0; i
< oldattr
->num_values
; i
++)
2463 attr
->values
[i
].integer
= oldattr
->values
[i
].integer
;
2467 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-message",
2468 IPP_TAG_TEXT
)) != NULL
)
2469 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "marker-message",
2470 NULL
, oldattr
->values
[0].string
.text
);
2472 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-low-levels",
2473 IPP_TAG_INTEGER
)) != NULL
)
2475 if ((attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2476 "marker-low-levels", oldattr
->num_values
,
2479 for (i
= 0; i
< oldattr
->num_values
; i
++)
2480 attr
->values
[i
].integer
= oldattr
->values
[i
].integer
;
2484 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-high-levels",
2485 IPP_TAG_INTEGER
)) != NULL
)
2487 if ((attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2488 "marker-high-levels", oldattr
->num_values
,
2491 for (i
= 0; i
< oldattr
->num_values
; i
++)
2492 attr
->values
[i
].integer
= oldattr
->values
[i
].integer
;
2496 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-names",
2497 IPP_TAG_NAME
)) != NULL
)
2499 if ((attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2500 "marker-names", oldattr
->num_values
, NULL
,
2503 for (i
= 0; i
< oldattr
->num_values
; i
++)
2504 attr
->values
[i
].string
.text
=
2505 _cupsStrRetain(oldattr
->values
[i
].string
.text
);
2509 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-types",
2510 IPP_TAG_KEYWORD
)) != NULL
)
2512 if ((attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2513 "marker-types", oldattr
->num_values
, NULL
,
2516 for (i
= 0; i
< oldattr
->num_values
; i
++)
2517 attr
->values
[i
].string
.text
=
2518 _cupsStrRetain(oldattr
->values
[i
].string
.text
);
2522 ippDelete(oldattrs
);
2526 * Force sharing off for remote queues...
2529 if (p
->type
& (CUPS_PRINTER_REMOTE
| CUPS_PRINTER_IMPLICIT
))
2534 * Copy the printer options into a browse attributes string we can re-use.
2537 const char *valptr
; /* Pointer into value */
2538 char *attrptr
; /* Pointer into attribute string */
2542 * Free the old browse attributes as needed...
2545 if (p
->browse_attrs
)
2546 free(p
->browse_attrs
);
2549 * Compute the length of all attributes + job-sheets, lease-duration,
2550 * and BrowseLocalOptions.
2553 for (length
= 1, i
= p
->num_options
, option
= p
->options
;
2557 length
+= strlen(option
->name
) + 2;
2561 for (valptr
= option
->value
; *valptr
; valptr
++)
2562 if (strchr(" \"\'\\", *valptr
))
2569 length
+= 13 + strlen(p
->job_sheets
[0]) + strlen(p
->job_sheets
[1]);
2571 if (BrowseLocalOptions
)
2572 length
+= 12 + strlen(BrowseLocalOptions
);
2575 * Allocate the new string...
2578 if ((p
->browse_attrs
= calloc(1, length
)) == NULL
)
2579 cupsdLogMessage(CUPSD_LOG_ERROR
,
2580 "Unable to allocate %d bytes for browse data!",
2585 * Got the allocated string, now copy the options and attributes over...
2588 sprintf(p
->browse_attrs
, "job-sheets=%s,%s lease-duration=%d",
2589 p
->job_sheets
[0], p
->job_sheets
[1], BrowseTimeout
);
2590 attrptr
= p
->browse_attrs
+ strlen(p
->browse_attrs
);
2592 if (BrowseLocalOptions
)
2594 sprintf(attrptr
, " ipp-options=%s", BrowseLocalOptions
);
2595 attrptr
+= strlen(attrptr
);
2598 for (i
= p
->num_options
, option
= p
->options
;
2603 strcpy(attrptr
, option
->name
);
2604 attrptr
+= strlen(attrptr
);
2610 for (valptr
= option
->value
; *valptr
; valptr
++)
2612 if (strchr(" \"\'\\", *valptr
))
2615 *attrptr
++ = *valptr
;
2623 * Populate the document-format-supported attribute...
2626 add_printer_formats(p
);
2628 DEBUG_printf(("cupsdSetPrinterAttrs: leaving name = %s, type = %x\n", p
->name
,
2632 * Add name-default attributes...
2635 add_printer_defaults(p
);
2639 * Write the IRIX printer config and status files...
2642 write_irix_config(p
);
2643 write_irix_state(p
);
2647 * Let the browse protocols reflect the change
2650 cupsdRegisterPrinter(p
);
2655 * 'cupsdSetPrinterReasons()' - Set/update the reasons strings.
2658 int /* O - 1 if something changed, 0 otherwise */
2659 cupsdSetPrinterReasons(
2660 cupsd_printer_t
*p
, /* I - Printer */
2661 const char *s
) /* I - Reasons strings */
2663 int i
, /* Looping var */
2664 changed
= 0; /* Did something change? */
2665 const char *sptr
; /* Pointer into reasons */
2666 char reason
[255], /* Reason string */
2667 *rptr
; /* Pointer into reason */
2670 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
2671 "cupsdSetPrinterReasons(p=%p(%s),s=\"%s\"", p
, p
->name
, s
);
2673 if (s
[0] == '-' || s
[0] == '+')
2676 * Add/remove reasons...
2684 * Replace reasons...
2689 for (i
= 0; i
< p
->num_reasons
; i
++)
2690 _cupsStrFree(p
->reasons
[i
]);
2698 if (!strcmp(s
, "none"))
2702 * Loop through all of the reasons...
2708 * Skip leading whitespace and commas...
2711 while (isspace(*sptr
& 255) || *sptr
== ',')
2714 for (rptr
= reason
; *sptr
&& !isspace(*sptr
& 255) && *sptr
!= ','; sptr
++)
2715 if (rptr
< (reason
+ sizeof(reason
) - 1))
2729 for (i
= 0; i
< p
->num_reasons
; i
++)
2730 if (!strcmp(reason
, p
->reasons
[i
]))
2733 * Found a match, so remove it...
2738 _cupsStrFree(p
->reasons
[i
]);
2740 if (i
< p
->num_reasons
)
2741 memmove(p
->reasons
+ i
, p
->reasons
+ i
+ 1,
2742 (p
->num_reasons
- i
) * sizeof(char *));
2744 if (!strcmp(reason
, "paused") && p
->state
== IPP_PRINTER_STOPPED
)
2745 cupsdSetPrinterState(p
, IPP_PRINTER_IDLE
, 1);
2747 if (strcmp(reason
, "connecting-to-device"))
2752 else if (p
->num_reasons
< (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
2758 for (i
= 0; i
< p
->num_reasons
; i
++)
2759 if (!strcmp(reason
, p
->reasons
[i
]))
2762 if (i
>= p
->num_reasons
)
2764 if (!strncmp(reason
, "cups-ipp-missing-", 17) ||
2765 !strncmp(reason
, "cups-ipp-wrong-", 15))
2766 log_ipp_conformance(p
, reason
);
2768 if (i
>= (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
2770 cupsdLogMessage(CUPSD_LOG_ALERT
,
2771 "Too many printer-state-reasons values for %s (%d)",
2776 p
->reasons
[i
] = _cupsStrAlloc(reason
);
2780 if (!strcmp(reason
, "paused") && p
->state
!= IPP_PRINTER_STOPPED
)
2781 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, 1);
2783 if (strcmp(reason
, "connecting-to-device"))
2794 * 'cupsdSetPrinterState()' - Update the current state of a printer.
2798 cupsdSetPrinterState(
2799 cupsd_printer_t
*p
, /* I - Printer to change */
2800 ipp_pstate_t s
, /* I - New state */
2801 int update
) /* I - Update printers.conf? */
2803 ipp_pstate_t old_state
; /* Old printer state */
2804 static const char * const printer_states
[] =
2805 { /* State strings */
2813 * Can't set status of remote printers...
2816 if (p
->type
& CUPS_PRINTER_DISCOVERED
)
2820 * Set the new state...
2823 old_state
= p
->state
;
2828 cupsdAddEvent(s
== IPP_PRINTER_STOPPED
? CUPSD_EVENT_PRINTER_STOPPED
:
2829 CUPSD_EVENT_PRINTER_STATE
, p
, NULL
,
2830 "%s \"%s\" state changed to %s.",
2831 (p
->type
& CUPS_PRINTER_CLASS
) ? "Class" : "Printer",
2832 p
->name
, printer_states
[p
->state
- IPP_PRINTER_IDLE
]);
2835 * Let the browse code know this needs to be updated...
2839 p
->state_time
= time(NULL
);
2843 write_irix_state(p
);
2848 * Set/clear the paused reason as needed...
2851 if (s
== IPP_PRINTER_STOPPED
)
2852 cupsdSetPrinterReasons(p
, "+paused");
2854 cupsdSetPrinterReasons(p
, "-paused");
2857 * Clear the message for the queue when going to processing...
2860 if (s
== IPP_PRINTER_PROCESSING
)
2861 p
->state_message
[0] = '\0';
2864 * Let the browse protocols reflect the change...
2868 cupsdRegisterPrinter(p
);
2871 * Save the printer configuration if a printer goes from idle or processing
2872 * to stopped (or visa-versa)...
2876 (old_state
== IPP_PRINTER_STOPPED
) != (s
== IPP_PRINTER_STOPPED
))
2882 * 'cupsdStopPrinter()' - Stop a printer from printing any jobs...
2886 cupsdStopPrinter(cupsd_printer_t
*p
, /* I - Printer to stop */
2887 int update
)/* I - Update printers.conf? */
2890 * Set the printer state...
2893 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, update
);
2896 * See if we have a job printing on this printer...
2899 if (p
->job
&& p
->job
->state_value
== IPP_JOB_PROCESSING
)
2900 cupsdSetJobState(p
->job
, IPP_JOB_PENDING
, CUPSD_JOB_DEFAULT
,
2901 "Job stopped due to printer being paused.");
2906 * 'cupsdUpdatePrinterPPD()' - Update keywords in a printer's PPD file.
2909 int /* O - 1 if successful, 0 otherwise */
2910 cupsdUpdatePrinterPPD(
2911 cupsd_printer_t
*p
, /* I - Printer */
2912 int num_keywords
, /* I - Number of keywords */
2913 cups_option_t
*keywords
) /* I - Keywords */
2915 int i
; /* Looping var */
2916 cups_file_t
*src
, /* Original file */
2917 *dst
; /* New file */
2918 char srcfile
[1024], /* Original filename */
2919 dstfile
[1024], /* New filename */
2920 line
[1024], /* Line from file */
2921 keystring
[41]; /* Keyword from line */
2922 cups_option_t
*keyword
; /* Current keyword */
2925 cupsdLogMessage(CUPSD_LOG_INFO
, "Updating keywords in PPD file for %s...",
2929 * Get the old and new PPD filenames...
2932 snprintf(srcfile
, sizeof(srcfile
), "%s/ppd/%s.ppd.O", ServerRoot
, p
->name
);
2933 snprintf(dstfile
, sizeof(srcfile
), "%s/ppd/%s.ppd", ServerRoot
, p
->name
);
2936 * Rename the old file and open the old and new...
2939 if (rename(dstfile
, srcfile
))
2941 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to backup PPD file for %s: %s",
2942 p
->name
, strerror(errno
));
2946 if ((src
= cupsFileOpen(srcfile
, "r")) == NULL
)
2948 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to open PPD file \"%s\": %s",
2949 srcfile
, strerror(errno
));
2950 rename(srcfile
, dstfile
);
2954 if ((dst
= cupsFileOpen(dstfile
, "w")) == NULL
)
2956 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to create PPD file \"%s\": %s",
2957 dstfile
, strerror(errno
));
2959 rename(srcfile
, dstfile
);
2964 * Copy the first line and then write out all of the keywords...
2967 if (!cupsFileGets(src
, line
, sizeof(line
)))
2969 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to read PPD file \"%s\": %s",
2970 srcfile
, strerror(errno
));
2973 rename(srcfile
, dstfile
);
2977 cupsFilePrintf(dst
, "%s\n", line
);
2979 for (i
= num_keywords
, keyword
= keywords
; i
> 0; i
--, keyword
++)
2981 cupsdLogMessage(CUPSD_LOG_DEBUG
, "*%s: %s", keyword
->name
, keyword
->value
);
2982 cupsFilePrintf(dst
, "*%s: %s\n", keyword
->name
, keyword
->value
);
2986 * Then copy the rest of the PPD file, dropping any keywords we changed.
2989 while (cupsFileGets(src
, line
, sizeof(line
)))
2992 * Skip keywords we've already set...
2995 if (sscanf(line
, "*%40[^:]:", keystring
) == 1 &&
2996 cupsGetOption(keystring
, num_keywords
, keywords
))
3000 * Otherwise write the line...
3003 cupsFilePrintf(dst
, "%s\n", line
);
3007 * Close files and return...
3018 * 'cupsdUpdatePrinters()' - Update printers after a partial reload.
3022 cupsdUpdatePrinters(void)
3024 cupsd_printer_t
*p
; /* Current printer */
3028 * Loop through the printers and recreate the printer attributes
3029 * for any local printers since the policy and/or access control
3030 * stuff may have changed. Also, if browsing is disabled, remove
3031 * any remote printers...
3034 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3036 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3039 * Remove remote printers if we are no longer browsing...
3043 (p
->type
& (CUPS_PRINTER_IMPLICIT
| CUPS_PRINTER_DISCOVERED
)))
3045 if (p
->type
& CUPS_PRINTER_IMPLICIT
)
3046 cupsArrayRemove(ImplicitPrinters
, p
);
3048 cupsArraySave(Printers
);
3049 cupsdDeletePrinter(p
, 0);
3050 cupsArrayRestore(Printers
);
3055 * Update the operation policy pointer...
3058 if ((p
->op_policy_ptr
= cupsdFindPolicy(p
->op_policy
)) == NULL
)
3059 p
->op_policy_ptr
= DefaultPolicyPtr
;
3062 * Update printer attributes as needed...
3065 if (!(p
->type
& CUPS_PRINTER_DISCOVERED
))
3066 cupsdSetPrinterAttrs(p
);
3072 * 'cupsdValidateDest()' - Validate a printer/class destination.
3075 const char * /* O - Printer or class name */
3077 const char *uri
, /* I - Printer URI */
3078 cups_ptype_t
*dtype
, /* O - Type (printer or class) */
3079 cupsd_printer_t
**printer
) /* O - Printer pointer */
3081 cupsd_printer_t
*p
; /* Current printer */
3082 char localname
[1024],/* Localized hostname */
3083 *lptr
, /* Pointer into localized hostname */
3084 *sptr
, /* Pointer into server name */
3085 *rptr
, /* Pointer into resource */
3086 scheme
[32], /* Scheme portion of URI */
3087 username
[64], /* Username portion of URI */
3088 hostname
[HTTP_MAX_HOST
],
3089 /* Host portion of URI */
3090 resource
[HTTP_MAX_URI
];
3091 /* Resource portion of URI */
3092 int port
; /* Port portion of URI */
3095 DEBUG_printf(("cupsdValidateDest(uri=\"%s\", dtype=%p, printer=%p)\n", uri
,
3099 * Initialize return values...
3106 *dtype
= (cups_ptype_t
)0;
3109 * Pull the hostname and resource from the URI...
3112 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
, scheme
, sizeof(scheme
),
3113 username
, sizeof(username
), hostname
, sizeof(hostname
),
3114 &port
, resource
, sizeof(resource
));
3117 * See if the resource is a class or printer...
3120 if (!strncmp(resource
, "/classes/", 9))
3126 rptr
= resource
+ 9;
3128 else if (!strncmp(resource
, "/printers/", 10))
3134 rptr
= resource
+ 10;
3139 * Bad resource name...
3146 * See if the printer or class name exists...
3149 p
= cupsdFindDest(rptr
);
3151 if (p
== NULL
&& strchr(rptr
, '@') == NULL
)
3159 *dtype
= p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
|
3160 CUPS_PRINTER_REMOTE
| CUPS_PRINTER_DISCOVERED
);
3166 * Change localhost to the server name...
3169 if (!_cups_strcasecmp(hostname
, "localhost"))
3170 strlcpy(hostname
, ServerName
, sizeof(hostname
));
3172 strlcpy(localname
, hostname
, sizeof(localname
));
3174 if (!_cups_strcasecmp(hostname
, ServerName
))
3177 * Localize the hostname...
3180 lptr
= strchr(localname
, '.');
3181 sptr
= strchr(ServerName
, '.');
3183 if (sptr
!= NULL
&& lptr
!= NULL
)
3186 * Strip the common domain name components...
3189 while (lptr
!= NULL
)
3191 if (!_cups_strcasecmp(lptr
, sptr
))
3197 lptr
= strchr(lptr
+ 1, '.');
3202 DEBUG_printf(("localized hostname is \"%s\"...\n", localname
));
3205 * Find a matching printer or class...
3208 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3210 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3211 if (!_cups_strcasecmp(p
->hostname
, localname
) &&
3212 !_cups_strcasecmp(p
->name
, rptr
))
3218 *dtype
= p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
|
3219 CUPS_PRINTER_REMOTE
| CUPS_PRINTER_DISCOVERED
);
3229 * 'cupsdWritePrintcap()' - Write a pseudo-printcap file for older applications
3234 cupsdWritePrintcap(void)
3236 int i
; /* Looping var */
3237 cups_file_t
*fp
; /* Printcap file */
3238 cupsd_printer_t
*p
; /* Current printer */
3243 * Update the IRIX printer state for the default printer; if
3244 * no printers remain, then the default printer file will be
3248 write_irix_state(DefaultPrinter
);
3252 * See if we have a printcap file; if not, don't bother writing it.
3255 if (!Printcap
|| !*Printcap
)
3258 cupsdLogMessage(CUPSD_LOG_INFO
, "Generating printcap %s...", Printcap
);
3261 * Open the printcap file...
3264 if ((fp
= cupsFileOpen(Printcap
, "w")) == NULL
)
3268 * Put a comment header at the top so that users will know where the
3269 * data has come from...
3272 if (PrintcapFormat
!= PRINTCAP_PLIST
)
3273 cupsFilePrintf(fp
, "# This file was automatically generated by cupsd(8) "
3275 "# %s/printers.conf file. All changes to this file\n"
3276 "# will be lost.\n", ServerRoot
);
3279 * Write a new printcap with the current list of printers.
3282 switch (PrintcapFormat
)
3286 * Each printer is put in the file as:
3296 cupsFilePrintf(fp
, "%s|%s:rm=%s:rp=%s:\n", DefaultPrinter
->name
,
3297 DefaultPrinter
->info
, ServerName
,
3298 DefaultPrinter
->name
);
3300 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3302 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3303 if (p
!= DefaultPrinter
)
3304 cupsFilePrintf(fp
, "%s|%s:rm=%s:rp=%s:\n", p
->name
, p
->info
,
3305 ServerName
, p
->name
);
3308 case PRINTCAP_PLIST
:
3310 * Each printer is written as a dictionary in a plist file.
3311 * Currently the printer-name, printer-info, printer-is-accepting-jobs,
3312 * printer-location, printer-make-and-model, printer-state,
3313 * printer-state-reasons, printer-type, and (sanitized) device-uri.
3316 cupsFilePuts(fp
, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
3317 "<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD "
3318 "PLIST 1.0//EN\" \"http://www.apple.com/DTDs/"
3319 "PropertyList-1.0.dtd\">\n"
3320 "<plist version=\"1.0\">\n"
3323 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3325 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3327 cupsFilePuts(fp
, "\t<dict>\n"
3328 "\t\t<key>printer-name</key>\n"
3330 write_xml_string(fp
, p
->name
);
3331 cupsFilePuts(fp
, "</string>\n"
3332 "\t\t<key>printer-info</key>\n"
3334 write_xml_string(fp
, p
->info
);
3335 cupsFilePrintf(fp
, "</string>\n"
3336 "\t\t<key>printer-is-accepting-jobs</key>\n"
3338 "\t\t<key>printer-location</key>\n"
3339 "\t\t<string>", p
->accepting
? "true" : "false");
3340 write_xml_string(fp
, p
->location
);
3341 cupsFilePuts(fp
, "</string>\n"
3342 "\t\t<key>printer-make-and-model</key>\n"
3344 write_xml_string(fp
, p
->make_model
);
3345 cupsFilePrintf(fp
, "</string>\n"
3346 "\t\t<key>printer-state</key>\n"
3347 "\t\t<integer>%d</integer>\n"
3348 "\t\t<key>printer-state-reasons</key>\n"
3349 "\t\t<array>\n", p
->state
);
3350 for (i
= 0; i
< p
->num_reasons
; i
++)
3352 cupsFilePuts(fp
, "\t\t\t<string>");
3353 write_xml_string(fp
, p
->reasons
[i
]);
3354 cupsFilePuts(fp
, "</string>\n");
3356 cupsFilePrintf(fp
, "\t\t</array>\n"
3357 "\t\t<key>printer-type</key>\n"
3358 "\t\t<integer>%d</integer>\n"
3359 "\t\t<key>device-uri</key>\n"
3360 "\t\t<string>", p
->type
);
3361 write_xml_string(fp
, p
->sanitized_device_uri
);
3362 cupsFilePuts(fp
, "</string>\n"
3365 cupsFilePuts(fp
, "</array>\n"
3369 case PRINTCAP_SOLARIS
:
3371 * Each printer is put in the file as:
3373 * _all:all=Printer1,Printer2,Printer3,...,PrinterN
3374 * _default:use=DefaultPrinter
3376 * :bsdaddr=ServerName,Printer1:\
3377 * :description=Description:
3379 * :bsdaddr=ServerName,Printer2:\
3380 * :description=Description:
3382 * :bsdaddr=ServerName,Printer3:\
3383 * :description=Description:
3386 * :bsdaddr=ServerName,PrinterN:\
3387 * :description=Description:
3390 cupsFilePuts(fp
, "_all:all=");
3391 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3393 p
= (cupsd_printer_t
*)cupsArrayCurrent(Printers
))
3394 cupsFilePrintf(fp
, "%s%c", p
->name
,
3395 cupsArrayNext(Printers
) ? ',' : '\n');
3398 cupsFilePrintf(fp
, "_default:use=%s\n", DefaultPrinter
->name
);
3400 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3402 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3403 cupsFilePrintf(fp
, "%s:\\\n"
3404 "\t:bsdaddr=%s,%s:\\\n"
3405 "\t:description=%s:\n",
3406 p
->name
, ServerName
, p
->name
,
3407 p
->info
? p
->info
: "");
3420 * 'add_printer_defaults()' - Add name-default attributes to the printer attributes.
3424 add_printer_defaults(cupsd_printer_t
*p
)/* I - Printer */
3426 int i
; /* Looping var */
3427 int num_options
; /* Number of default options */
3428 cups_option_t
*options
, /* Default options */
3429 *option
; /* Current option */
3430 char name
[256]; /* name-default */
3434 * Maintain a common array of default attribute names...
3437 if (!CommonDefaults
)
3439 CommonDefaults
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
3441 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("copies-default"));
3442 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("document-format-default"));
3443 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("finishings-default"));
3444 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-hold-until-default"));
3445 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-priority-default"));
3446 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-sheets-default"));
3447 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("media-col-default"));
3448 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("number-up-default"));
3449 cupsArrayAdd(CommonDefaults
,
3450 _cupsStrAlloc("orientation-requested-default"));
3454 * Add all of the default options from the .conf files...
3457 for (num_options
= 0, options
= NULL
, i
= p
->num_options
, option
= p
->options
;
3461 if (strcmp(option
->name
, "ipp-options") &&
3462 strcmp(option
->name
, "job-sheets") &&
3463 strcmp(option
->name
, "lease-duration"))
3465 snprintf(name
, sizeof(name
), "%s-default", option
->name
);
3466 num_options
= cupsAddOption(name
, option
->value
, num_options
, &options
);
3468 if (!cupsArrayFind(CommonDefaults
, name
))
3469 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc(name
));
3474 * Convert options to IPP attributes...
3477 cupsEncodeOptions2(p
->attrs
, num_options
, options
, IPP_TAG_PRINTER
);
3478 cupsFreeOptions(num_options
, options
);
3481 * Add standard -default attributes as needed...
3484 if (!cupsGetOption("copies", p
->num_options
, p
->options
))
3485 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
, "copies-default",
3488 if (!cupsGetOption("document-format", p
->num_options
, p
->options
))
3489 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_MIMETYPE
,
3490 "document-format-default", NULL
, "application/octet-stream");
3492 if (!cupsGetOption("job-hold-until", p
->num_options
, p
->options
))
3493 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3494 "job-hold-until-default", NULL
, "no-hold");
3496 if (!cupsGetOption("job-priority", p
->num_options
, p
->options
))
3497 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3498 "job-priority-default", 50);
3500 if (!cupsGetOption("number-up", p
->num_options
, p
->options
))
3501 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3502 "number-up-default", 1);
3504 if (!cupsGetOption("notify-lease-duration", p
->num_options
, p
->options
))
3505 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3506 "notify-lease-duration-default", DefaultLeaseDuration
);
3508 if (!cupsGetOption("notify-events", p
->num_options
, p
->options
))
3509 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3510 "notify-events-default", NULL
, "job-completed");
3512 if (!cupsGetOption("orientation-requested", p
->num_options
, p
->options
))
3513 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NOVALUE
,
3514 "orientation-requested-default", NULL
, NULL
);
3516 if (!cupsGetOption("print-quality", p
->num_options
, p
->options
))
3517 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
3518 "print-quality-default", IPP_QUALITY_NORMAL
);
3523 * 'add_printer_filter()' - Add a MIME filter for a printer.
3528 cupsd_printer_t
*p
, /* I - Printer to add to */
3529 mime_type_t
*filtertype
, /* I - Filter or prefilter MIME type */
3530 const char *filter
) /* I - Filter to add */
3532 char super
[MIME_MAX_SUPER
], /* Super-type for filter */
3533 type
[MIME_MAX_TYPE
], /* Type for filter */
3534 dsuper
[MIME_MAX_SUPER
], /* Destination super-type for filter */
3535 dtype
[MIME_MAX_TYPE
], /* Destination type for filter */
3536 dest
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2],
3537 /* Destination super/type */
3538 program
[1024]; /* Program/filter name */
3539 int cost
; /* Cost of filter */
3540 size_t maxsize
= 0; /* Maximum supported file size */
3541 mime_type_t
*temptype
, /* MIME type looping var */
3542 *desttype
; /* Destination MIME type */
3543 mime_filter_t
*filterptr
; /* MIME filter */
3544 char filename
[1024]; /* Full filter filename */
3547 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3548 "add_printer_filter(p=%p(%s), filtertype=%p(%s/%s), "
3549 "filter=\"%s\")", p
, p
->name
, filtertype
, filtertype
->super
,
3550 filtertype
->type
, filter
);
3553 * Parse the filter string; it should be in one of the following formats:
3555 * source/type cost program
3556 * source/type cost maxsize(nnnn) program
3557 * source/type dest/type cost program
3558 * source/type dest/type cost maxsize(nnnn) program
3561 if (sscanf(filter
, "%15[^/]/%255s%*[ \t]%15[^/]/%255s%d%*[ \t]%1023[^\n]",
3562 super
, type
, dsuper
, dtype
, &cost
, program
) == 6)
3564 snprintf(dest
, sizeof(dest
), "%s/%s/%s", p
->name
, dsuper
, dtype
);
3566 if ((desttype
= mimeType(MimeDatabase
, "printer", dest
)) == NULL
)
3568 desttype
= mimeAddType(MimeDatabase
, "printer", dest
);
3570 p
->dest_types
= cupsArrayNew(NULL
, NULL
);
3572 cupsArrayAdd(p
->dest_types
, desttype
);
3578 if (sscanf(filter
, "%15[^/]/%255s%d%*[ \t]%1023[^\n]", super
, type
, &cost
,
3581 desttype
= filtertype
;
3585 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: invalid filter string \"%s\"!",
3591 if (!strncmp(program
, "maxsize(", 8))
3593 char *ptr
; /* Pointer into maxsize(nnnn) program */
3595 maxsize
= strtoll(program
+ 8, &ptr
, 10);
3599 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: invalid filter string \"%s\"!",
3605 while (_cups_isspace(*ptr
))
3608 _cups_strcpy(program
, ptr
);
3612 * Check permissions on the filter and its containing directory...
3615 if (strcmp(program
, "-"))
3617 if (program
[0] == '/')
3618 strlcpy(filename
, program
, sizeof(filename
));
3620 snprintf(filename
, sizeof(filename
), "%s/filter/%s", ServerBin
, program
);
3622 _cupsFileCheck(filename
, _CUPS_FILE_CHECK_PROGRAM
, !RunUser
,
3623 cupsdLogFCMessage
, p
);
3627 * Add the filter to the MIME database, supporting wildcards as needed...
3630 for (temptype
= mimeFirstType(MimeDatabase
);
3632 temptype
= mimeNextType(MimeDatabase
))
3633 if (((super
[0] == '*' && _cups_strcasecmp(temptype
->super
, "printer")) ||
3634 !_cups_strcasecmp(temptype
->super
, super
)) &&
3635 (type
[0] == '*' || !_cups_strcasecmp(temptype
->type
, type
)))
3637 if (desttype
!= filtertype
)
3639 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3640 "add_printer_filter: %s: adding filter %s/%s %s/%s %d "
3641 "%s", p
->name
, temptype
->super
, temptype
->type
,
3642 desttype
->super
, desttype
->type
,
3644 filterptr
= mimeAddFilter(MimeDatabase
, temptype
, desttype
, cost
,
3647 if (!mimeFilterLookup(MimeDatabase
, desttype
, filtertype
))
3649 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3650 "add_printer_filter: %s: adding filter %s/%s %s/%s "
3651 "0 -", p
->name
, desttype
->super
, desttype
->type
,
3652 filtertype
->super
, filtertype
->type
);
3653 mimeAddFilter(MimeDatabase
, desttype
, filtertype
, 0, "-");
3658 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3659 "add_printer_filter: %s: adding filter %s/%s %s/%s %d "
3660 "%s", p
->name
, temptype
->super
, temptype
->type
,
3661 filtertype
->super
, filtertype
->type
,
3663 filterptr
= mimeAddFilter(MimeDatabase
, temptype
, filtertype
, cost
,
3668 filterptr
->maxsize
= maxsize
;
3674 * 'add_printer_formats()' - Add document-format-supported values for a printer.
3678 add_printer_formats(cupsd_printer_t
*p
) /* I - Printer */
3680 int i
; /* Looping var */
3681 mime_type_t
*type
; /* Current MIME type */
3682 cups_array_t
*filters
; /* Filters */
3683 ipp_attribute_t
*attr
; /* document-format-supported attribute */
3684 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
3685 /* MIME type name */
3689 * Raw (and remote) queues advertise all of the supported MIME
3693 cupsArrayDelete(p
->filetypes
);
3694 p
->filetypes
= NULL
;
3698 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
,
3699 (ipp_tag_t
)(IPP_TAG_MIMETYPE
| IPP_TAG_COPY
),
3700 "document-format-supported", NumMimeTypes
, NULL
, MimeTypes
);
3705 * Otherwise, loop through the supported MIME types and see if there
3706 * are filters for them...
3709 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_printer_formats: %d types, %d filters",
3710 mimeNumTypes(MimeDatabase
), mimeNumFilters(MimeDatabase
));
3712 p
->filetypes
= cupsArrayNew(NULL
, NULL
);
3714 for (type
= mimeFirstType(MimeDatabase
);
3716 type
= mimeNextType(MimeDatabase
))
3718 if (!_cups_strcasecmp(type
->super
, "printer"))
3721 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
3723 if ((filters
= mimeFilter(MimeDatabase
, type
, p
->filetype
, NULL
)) != NULL
)
3725 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3726 "add_printer_formats: %s: %s needs %d filters",
3727 p
->name
, mimetype
, cupsArrayCount(filters
));
3729 cupsArrayDelete(filters
);
3730 cupsArrayAdd(p
->filetypes
, type
);
3733 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3734 "add_printer_formats: %s: %s not supported",
3739 * Add the file formats that can be filtered...
3742 if ((type
= mimeType(MimeDatabase
, "application", "octet-stream")) == NULL
||
3743 !cupsArrayFind(p
->filetypes
, type
))
3748 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3749 "add_printer_formats: %s: %d supported types",
3750 p
->name
, cupsArrayCount(p
->filetypes
) + i
);
3752 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_MIMETYPE
,
3753 "document-format-supported",
3754 cupsArrayCount(p
->filetypes
) + i
, NULL
, NULL
);
3757 attr
->values
[0].string
.text
= _cupsStrAlloc("application/octet-stream");
3759 for (type
= (mime_type_t
*)cupsArrayFirst(p
->filetypes
);
3761 i
++, type
= (mime_type_t
*)cupsArrayNext(p
->filetypes
))
3763 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
3765 attr
->values
[i
].string
.text
= _cupsStrAlloc(mimetype
);
3770 char pdl
[1024]; /* Buffer to build pdl list */
3771 mime_filter_t
*filter
; /* MIME filter looping var */
3775 * We only support raw printing if this is not a Tioga PrintJobMgr based
3776 * queue and if application/octet-stream is a known type...
3779 for (filter
= (mime_filter_t
*)cupsArrayFirst(MimeDatabase
->filters
);
3781 filter
= (mime_filter_t
*)cupsArrayNext(MimeDatabase
->filters
))
3783 if (filter
->dst
== p
->filetype
&& filter
->filter
&&
3784 strstr(filter
->filter
, "PrintJobMgr"))
3790 if (!filter
&& mimeType(MimeDatabase
, "application", "octet-stream"))
3791 strlcat(pdl
, "application/octet-stream,", sizeof(pdl
));
3794 * Then list a bunch of formats that are supported by the printer...
3797 for (type
= (mime_type_t
*)cupsArrayFirst(p
->filetypes
);
3799 type
= (mime_type_t
*)cupsArrayNext(p
->filetypes
))
3801 if (!_cups_strcasecmp(type
->super
, "application"))
3803 if (!_cups_strcasecmp(type
->type
, "pdf"))
3804 strlcat(pdl
, "application/pdf,", sizeof(pdl
));
3805 else if (!_cups_strcasecmp(type
->type
, "postscript"))
3806 strlcat(pdl
, "application/postscript,", sizeof(pdl
));
3808 else if (!_cups_strcasecmp(type
->super
, "image"))
3810 if (!_cups_strcasecmp(type
->type
, "jpeg"))
3811 strlcat(pdl
, "image/jpeg,", sizeof(pdl
));
3812 else if (!_cups_strcasecmp(type
->type
, "png"))
3813 strlcat(pdl
, "image/png,", sizeof(pdl
));
3814 else if (!_cups_strcasecmp(type
->type
, "pwg-raster"))
3815 strlcat(pdl
, "image/pwg-raster,", sizeof(pdl
));
3820 pdl
[strlen(pdl
) - 1] = '\0'; /* Remove trailing comma */
3822 cupsdSetString(&p
->pdl
, pdl
);
3824 #endif /* HAVE_DNSSD */
3829 * 'compare_printers()' - Compare two printers.
3832 static int /* O - Result of comparison */
3833 compare_printers(void *first
, /* I - First printer */
3834 void *second
, /* I - Second printer */
3835 void *data
) /* I - App data (not used) */
3839 return (_cups_strcasecmp(((cupsd_printer_t
*)first
)->name
,
3840 ((cupsd_printer_t
*)second
)->name
));
3845 * 'delete_printer_filters()' - Delete all MIME filters for a printer.
3849 delete_printer_filters(
3850 cupsd_printer_t
*p
) /* I - Printer to remove from */
3852 mime_filter_t
*filter
; /* MIME filter looping var */
3853 mime_type_t
*type
; /* Destination types for filters */
3857 * Range check input...
3864 * Remove all filters from the MIME database that have a destination
3865 * type == printer...
3868 for (filter
= mimeFirstFilter(MimeDatabase
);
3870 filter
= mimeNextFilter(MimeDatabase
))
3871 if (filter
->dst
== p
->filetype
|| filter
->dst
== p
->prefiltertype
||
3872 cupsArrayFind(p
->dest_types
, filter
->dst
))
3875 * Delete the current filter...
3878 mimeDeleteFilter(MimeDatabase
, filter
);
3881 for (type
= (mime_type_t
*)cupsArrayFirst(p
->dest_types
);
3883 type
= (mime_type_t
*)cupsArrayNext(p
->dest_types
))
3884 mimeDeleteType(MimeDatabase
, type
);
3886 cupsArrayDelete(p
->dest_types
);
3887 p
->dest_types
= NULL
;
3889 cupsdSetPrinterReasons(p
, "-cups-insecure-filter-warning"
3890 ",cups-missing-filter-warning");
3895 * 'dirty_printer()' - Mark config and state files dirty for the specified
3900 dirty_printer(cupsd_printer_t
*p
) /* I - Printer */
3902 if (p
->type
& CUPS_PRINTER_DISCOVERED
)
3903 cupsdMarkDirty(CUPSD_DIRTY_REMOTE
);
3904 else if (p
->type
& CUPS_PRINTER_CLASS
)
3905 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
3907 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
3909 if (PrintcapFormat
== PRINTCAP_PLIST
)
3910 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
3915 * 'load_ppd()' - Load a cached PPD file, updating the cache as needed.
3919 load_ppd(cupsd_printer_t
*p
) /* I - Printer */
3921 int i
, j
, k
; /* Looping vars */
3922 char cache_name
[1024]; /* Cache filename */
3923 struct stat cache_info
; /* Cache file info */
3924 ppd_file_t
*ppd
; /* PPD file */
3925 char ppd_name
[1024]; /* PPD filename */
3926 struct stat ppd_info
; /* PPD file info */
3927 int num_media
; /* Number of media options */
3928 ppd_size_t
*size
; /* Current PPD size */
3929 ppd_option_t
*duplex
, /* Duplex option */
3930 *output_bin
, /* OutputBin option */
3931 *output_mode
, /* OutputMode option */
3932 *resolution
; /* (Set|JCL|)Resolution option */
3933 ppd_choice_t
*choice
, /* Current PPD choice */
3934 *input_slot
, /* Current input slot */
3935 *media_type
; /* Current media type */
3936 ppd_attr_t
*ppd_attr
; /* PPD attribute */
3937 int xdpi
, /* Horizontal resolution */
3938 ydpi
; /* Vertical resolution */
3939 const char *resptr
; /* Pointer into resolution keyword */
3940 _pwg_size_t
*pwgsize
; /* Current PWG size */
3941 _pwg_map_t
*pwgsource
, /* Current PWG source */
3942 *pwgtype
; /* Current PWG type */
3943 ipp_attribute_t
*attr
; /* Attribute data */
3944 ipp_value_t
*val
; /* Attribute value */
3945 int num_finishings
, /* Number of finishings */
3946 finishings
[5]; /* finishings-supported values */
3947 int num_qualities
, /* Number of print-quality values */
3948 qualities
[3]; /* print-quality values */
3949 int num_margins
, /* Number of media-*-margin-supported values */
3950 margins
[16]; /* media-*-margin-supported values */
3951 const char *filter
; /* Current filter */
3952 static const char * const sides
[3] = /* sides-supported values */
3955 "two-sided-long-edge",
3956 "two-sided-short-edge"
3958 static const char * const standard_commands
[] =
3959 { /* Standard CUPS commands */
3967 * Check to see if the cache is up-to-date...
3970 snprintf(cache_name
, sizeof(cache_name
), "%s/%s.data", CacheDir
, p
->name
);
3971 if (stat(cache_name
, &cache_info
))
3972 cache_info
.st_mtime
= 0;
3974 snprintf(ppd_name
, sizeof(ppd_name
), "%s/ppd/%s.ppd", ServerRoot
, p
->name
);
3975 if (stat(ppd_name
, &ppd_info
))
3976 ppd_info
.st_mtime
= 1;
3978 ippDelete(p
->ppd_attrs
);
3979 p
->ppd_attrs
= NULL
;
3981 _ppdCacheDestroy(p
->pc
);
3984 if (cache_info
.st_mtime
>= ppd_info
.st_mtime
)
3986 cupsdLogMessage(CUPSD_LOG_DEBUG
, "load_ppd: Loading %s...", cache_name
);
3988 if ((p
->pc
= _ppdCacheCreateWithFile(cache_name
, &p
->ppd_attrs
)) != NULL
&&
3992 * Loaded successfully!
4000 * Reload PPD attributes from disk...
4003 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
4005 cupsdLogMessage(CUPSD_LOG_DEBUG
, "load_ppd: Loading %s...", ppd_name
);
4007 p
->type
&= ~CUPS_PRINTER_OPTIONS
;
4008 p
->type
|= CUPS_PRINTER_BW
;
4010 finishings
[0] = IPP_FINISHINGS_NONE
;
4013 p
->ppd_attrs
= ippNew();
4015 if ((ppd
= ppdOpenFile(ppd_name
)) != NULL
)
4018 * Add make/model and other various attributes...
4021 p
->pc
= _ppdCacheCreateWithPPD(ppd
);
4023 ppdMarkDefaults(ppd
);
4025 if (ppd
->color_device
)
4026 p
->type
|= CUPS_PRINTER_COLOR
;
4027 if (ppd
->variable_sizes
)
4028 p
->type
|= CUPS_PRINTER_VARIABLE
;
4029 if (!ppd
->manual_copies
)
4030 p
->type
|= CUPS_PRINTER_COPIES
;
4031 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsFax", NULL
)) != NULL
)
4032 if (ppd_attr
->value
&& !_cups_strcasecmp(ppd_attr
->value
, "true"))
4033 p
->type
|= CUPS_PRINTER_FAX
;
4035 ippAddBoolean(p
->ppd_attrs
, IPP_TAG_PRINTER
, "color-supported",
4037 if (ppd
->throughput
)
4039 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4040 "pages-per-minute", ppd
->throughput
);
4041 if (ppd
->color_device
)
4042 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4043 "pages-per-minute-color", ppd
->throughput
);
4048 * When there is no speed information, just say "1 page per minute".
4051 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4052 "pages-per-minute", 1);
4053 if (ppd
->color_device
)
4054 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4055 "pages-per-minute-color", 1);
4060 if ((output_mode
= ppdFindOption(ppd
, "OutputMode")) != NULL
)
4062 if (ppdFindChoice(output_mode
, "draft") ||
4063 ppdFindChoice(output_mode
, "fast"))
4064 qualities
[num_qualities
++] = IPP_QUALITY_DRAFT
;
4066 qualities
[num_qualities
++] = IPP_QUALITY_NORMAL
;
4068 if (ppdFindChoice(output_mode
, "best") ||
4069 ppdFindChoice(output_mode
, "high"))
4070 qualities
[num_qualities
++] = IPP_QUALITY_HIGH
;
4072 else if ((ppd_attr
= ppdFindAttr(ppd
, "APPrinterPreset", NULL
)) != NULL
)
4076 if (strstr(ppd_attr
->spec
, "draft") ||
4077 strstr(ppd_attr
->spec
, "Draft"))
4079 qualities
[num_qualities
++] = IPP_QUALITY_DRAFT
;
4083 while ((ppd_attr
= ppdFindNextAttr(ppd
, "APPrinterPreset",
4086 qualities
[num_qualities
++] = IPP_QUALITY_NORMAL
;
4087 qualities
[num_qualities
++] = IPP_QUALITY_HIGH
;
4090 qualities
[num_qualities
++] = IPP_QUALITY_NORMAL
;
4092 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
4093 "print-quality-supported", num_qualities
, qualities
);
4098 * The NickName can be localized in the character set specified
4099 * by the LanugageEncoding attribute. However, ppdOpen2() has
4100 * already converted the ppd->nickname member to UTF-8 for us
4101 * (the original attribute value is available separately)
4104 cupsdSetString(&p
->make_model
, ppd
->nickname
);
4106 else if (ppd
->modelname
)
4109 * Model name can only contain specific characters...
4112 cupsdSetString(&p
->make_model
, ppd
->modelname
);
4115 cupsdSetString(&p
->make_model
, "Bad PPD File");
4117 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
4118 "printer-make-and-model", NULL
, p
->make_model
);
4121 * Add media options from the PPD file...
4124 if (ppd
->num_sizes
== 0 || !p
->pc
)
4126 if (!ppdFindAttr(ppd
, "APScannerOnly", NULL
))
4127 cupsdLogMessage(CUPSD_LOG_CRIT
,
4128 "The PPD file for printer %s contains no media "
4129 "options and is therefore invalid!", p
->name
);
4131 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4132 "media-default", NULL
, "unknown");
4133 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4134 "media-supported", NULL
, "unknown");
4142 if ((size
= ppdPageSize(ppd
, NULL
)) != NULL
)
4143 pwgsize
= _ppdCacheGetSize(p
->pc
, size
->name
);
4147 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4148 "media-default", NULL
,
4149 pwgsize
? pwgsize
->map
.pwg
: "unknown");
4157 ipp_t
*col
; /* Collection value */
4159 input_slot
= ppdFindMarkedChoice(ppd
, "InputSlot");
4160 media_type
= ppdFindMarkedChoice(ppd
, "MediaType");
4161 col
= new_media_col(pwgsize
,
4163 _ppdCacheGetSource(p
->pc
,
4164 input_slot
->choice
) :
4167 _ppdCacheGetType(p
->pc
,
4168 media_type
->choice
) :
4171 ippAddCollection(p
->ppd_attrs
, IPP_TAG_PRINTER
, "media-col-default",
4180 num_media
= p
->pc
->num_sizes
;
4181 if (p
->pc
->custom_min_keyword
)
4184 if ((attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4185 "media-supported", num_media
, NULL
,
4190 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
;
4192 i
--, pwgsize
++, val
++)
4193 val
->string
.text
= _cupsStrRetain(pwgsize
->map
.pwg
);
4195 if (p
->pc
->custom_min_keyword
)
4197 val
->string
.text
= _cupsStrRetain(p
->pc
->custom_min_keyword
);
4199 val
->string
.text
= _cupsStrRetain(p
->pc
->custom_max_keyword
);
4204 * media-source-supported
4207 if (p
->pc
->num_sources
> 0 &&
4208 (attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4209 "media-source-supported", p
->pc
->num_sources
,
4210 NULL
, NULL
)) != NULL
)
4212 for (i
= p
->pc
->num_sources
, pwgsource
= p
->pc
->sources
,
4215 i
--, pwgsource
++, val
++)
4216 val
->string
.text
= _cupsStrRetain(pwgsource
->pwg
);
4220 * media-type-supported
4223 if (p
->pc
->num_types
> 0 &&
4224 (attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4225 "media-type-supported", p
->pc
->num_types
,
4226 NULL
, NULL
)) != NULL
)
4228 for (i
= p
->pc
->num_types
, pwgtype
= p
->pc
->types
,
4231 i
--, pwgtype
++, val
++)
4232 val
->string
.text
= _cupsStrRetain(pwgtype
->pwg
);
4236 * media-*-margin-supported
4239 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, num_margins
= 0;
4240 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4243 for (j
= 0; j
< num_margins
; j
++)
4244 if (pwgsize
->bottom
== margins
[j
])
4247 if (j
>= num_margins
)
4249 margins
[num_margins
] = pwgsize
->bottom
;
4254 if (num_margins
> 0)
4255 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4256 "media-bottom-margin-supported", num_margins
, margins
);
4258 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4259 "media-bottom-margin-supported", 0);
4261 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, num_margins
= 0;
4262 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4265 for (j
= 0; j
< num_margins
; j
++)
4266 if (pwgsize
->left
== margins
[j
])
4269 if (j
>= num_margins
)
4271 margins
[num_margins
] = pwgsize
->left
;
4276 if (num_margins
> 0)
4277 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4278 "media-left-margin-supported", num_margins
, margins
);
4280 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4281 "media-left-margin-supported", 0);
4283 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, num_margins
= 0;
4284 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4287 for (j
= 0; j
< num_margins
; j
++)
4288 if (pwgsize
->right
== margins
[j
])
4291 if (j
>= num_margins
)
4293 margins
[num_margins
] = pwgsize
->right
;
4298 if (num_margins
> 0)
4299 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4300 "media-right-margin-supported", num_margins
, margins
);
4302 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4303 "media-right-margin-supported", 0);
4305 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, num_margins
= 0;
4306 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4309 for (j
= 0; j
< num_margins
; j
++)
4310 if (pwgsize
->top
== margins
[j
])
4313 if (j
>= num_margins
)
4315 margins
[num_margins
] = pwgsize
->top
;
4320 if (num_margins
> 0)
4321 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4322 "media-top-margin-supported", num_margins
, margins
);
4324 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4325 "media-top-margin-supported", 0);
4328 * media-col-database
4331 num_media
= p
->pc
->num_sizes
;
4332 if (p
->pc
->num_sources
)
4334 if (p
->pc
->num_types
> 0)
4335 num_media
+= p
->pc
->num_sizes
* p
->pc
->num_sources
*
4338 num_media
+= p
->pc
->num_sizes
* p
->pc
->num_sources
;
4340 else if (p
->pc
->num_types
)
4341 num_media
+= p
->pc
->num_sizes
* p
->pc
->num_types
;
4343 if ((attr
= ippAddCollections(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4344 "media-col-database", num_media
,
4347 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, val
= attr
->values
;
4352 * Start by adding the page size without source or type...
4355 ppdMarkOption(ppd
, "PageSize", pwgsize
->map
.ppd
);
4357 val
->collection
= new_media_col(pwgsize
, NULL
, NULL
);
4361 * Then add the specific, supported combinations of size, source, and
4365 if (p
->pc
->num_sources
> 0)
4367 for (j
= p
->pc
->num_sources
, pwgsource
= p
->pc
->sources
;
4371 ppdMarkOption(ppd
, "InputSlot", pwgsource
->ppd
);
4373 if (p
->pc
->num_types
> 0)
4375 for (k
= p
->pc
->num_types
, pwgtype
= p
->pc
->types
;
4379 if (!ppdMarkOption(ppd
, "MediaType", pwgtype
->ppd
))
4381 val
->collection
= new_media_col(pwgsize
, pwgsource
->pwg
,
4387 else if (!ppdConflicts(ppd
))
4389 val
->collection
= new_media_col(pwgsize
, pwgsource
->pwg
, NULL
);
4394 else if (p
->pc
->num_types
> 0)
4396 for (j
= p
->pc
->num_types
, pwgtype
= p
->pc
->types
;
4400 if (!ppdMarkOption(ppd
, "MediaType", pwgtype
->ppd
))
4402 val
->collection
= new_media_col(pwgsize
, NULL
, pwgtype
->pwg
);
4410 * Update the number of media-col-database values...
4413 attr
->num_values
= val
- attr
->values
;
4421 if (p
->pc
&& p
->pc
->num_bins
> 0)
4423 attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4424 "output-bin-supported", p
->pc
->num_bins
,
4429 for (i
= 0, val
= attr
->values
;
4430 i
< p
->pc
->num_bins
;
4432 val
->string
.text
= _cupsStrAlloc(p
->pc
->bins
[i
].pwg
);
4435 if ((output_bin
= ppdFindOption(ppd
, "OutputBin")) != NULL
)
4437 for (i
= 0; i
< p
->pc
->num_bins
; i
++)
4438 if (!strcmp(p
->pc
->bins
[i
].ppd
, output_bin
->defchoice
))
4441 if (i
>= p
->pc
->num_bins
)
4444 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4445 "output-bin-default", NULL
, p
->pc
->bins
[i
].pwg
);
4448 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4449 "output-bin-default", NULL
, p
->pc
->bins
[0].pwg
);
4451 else if (((ppd_attr
= ppdFindAttr(ppd
, "DefaultOutputOrder",
4453 !_cups_strcasecmp(ppd_attr
->value
, "Reverse")) ||
4454 (!ppd_attr
&& ppd
->manufacturer
&& /* "Compatibility heuristic" */
4455 (!_cups_strcasecmp(ppd
->manufacturer
, "epson") ||
4456 !_cups_strcasecmp(ppd
->manufacturer
, "lexmark"))))
4459 * Report that this printer has a single output bin that leaves pages face
4463 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4464 "output-bin-supported", NULL
, "face-up");
4465 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4466 "output-bin-default", NULL
, "face-up");
4470 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4471 "output-bin-supported", NULL
, "face-down");
4472 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4473 "output-bin-default", NULL
, "face-down");
4477 * output-mode and print-color-mode...
4480 if (ppd
->color_device
)
4482 static const char * const output_modes
[] =
4488 ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4489 "output-mode-supported", 2, NULL
, output_modes
);
4490 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4491 "output-mode-default", NULL
, "color");
4493 ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4494 "print-color-mode-supported", 2, NULL
, output_modes
);
4495 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4496 "print-color-mode-default", NULL
, "color");
4500 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4501 "output-mode-supported", NULL
, "monochrome");
4502 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4503 "output-mode-default", NULL
, "monochrome");
4505 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4506 "print-color-mode-supported", NULL
, "monochrome");
4507 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4508 "print-color-mode-default", NULL
, "monochrome");
4512 * Printer resolutions...
4515 if ((resolution
= ppdFindOption(ppd
, "Resolution")) == NULL
)
4516 if ((resolution
= ppdFindOption(ppd
, "JCLResolution")) == NULL
)
4517 if ((resolution
= ppdFindOption(ppd
, "SetResolution")) == NULL
)
4518 resolution
= ppdFindOption(ppd
, "CNRes_PGP");
4523 * Report all supported resolutions...
4526 attr
= ippAddResolutions(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4527 "printer-resolution-supported",
4528 resolution
->num_choices
, IPP_RES_PER_INCH
,
4531 for (i
= 0, choice
= resolution
->choices
;
4532 i
< resolution
->num_choices
;
4535 xdpi
= ydpi
= (int)strtol(choice
->choice
, (char **)&resptr
, 10);
4536 if (resptr
> choice
->choice
&& xdpi
> 0 && *resptr
== 'x')
4537 ydpi
= (int)strtol(resptr
+ 1, (char **)&resptr
, 10);
4539 if (xdpi
<= 0 || ydpi
<= 0)
4541 cupsdLogMessage(CUPSD_LOG_WARN
,
4542 "Bad resolution \"%s\" for printer %s.",
4543 choice
->choice
, p
->name
);
4547 attr
->values
[i
].resolution
.xres
= xdpi
;
4548 attr
->values
[i
].resolution
.yres
= ydpi
;
4549 attr
->values
[i
].resolution
.units
= IPP_RES_PER_INCH
;
4552 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4553 "printer-resolution-default", IPP_RES_PER_INCH
,
4557 else if ((ppd_attr
= ppdFindAttr(ppd
, "DefaultResolution", NULL
)) != NULL
&&
4561 * Just the DefaultResolution to report...
4564 xdpi
= ydpi
= (int)strtol(ppd_attr
->value
, (char **)&resptr
, 10);
4565 if (resptr
> ppd_attr
->value
&& xdpi
> 0)
4568 ydpi
= (int)strtol(resptr
+ 1, (char **)&resptr
, 10);
4573 if (xdpi
<= 0 || ydpi
<= 0)
4575 cupsdLogMessage(CUPSD_LOG_WARN
,
4576 "Bad default resolution \"%s\" for printer %s.",
4577 ppd_attr
->value
, p
->name
);
4581 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4582 "printer-resolution-default", IPP_RES_PER_INCH
,
4584 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4585 "printer-resolution-supported", IPP_RES_PER_INCH
,
4591 * No resolutions in PPD - make one up...
4594 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4595 "printer-resolution-default", IPP_RES_PER_INCH
,
4597 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4598 "printer-resolution-supported", IPP_RES_PER_INCH
,
4606 ppdMarkDefaults(ppd
);
4608 if ((duplex
= ppdFindOption(ppd
, "Duplex")) == NULL
)
4609 if ((duplex
= ppdFindOption(ppd
, "EFDuplex")) == NULL
)
4610 if ((duplex
= ppdFindOption(ppd
, "EFDuplexing")) == NULL
)
4611 if ((duplex
= ppdFindOption(ppd
, "KD03Duplex")) == NULL
)
4612 duplex
= ppdFindOption(ppd
, "JCLDuplex");
4614 if (duplex
&& duplex
->num_choices
> 1 &&
4615 !ppdInstallableConflict(ppd
, duplex
->keyword
, "DuplexTumble"))
4617 p
->type
|= CUPS_PRINTER_DUPLEX
;
4619 ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4620 "sides-supported", 3, NULL
, sides
);
4622 if (!_cups_strcasecmp(duplex
->defchoice
, "DuplexTumble"))
4623 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4624 "sides-default", NULL
, "two-sided-short-edge");
4625 else if (!_cups_strcasecmp(duplex
->defchoice
, "DuplexNoTumble"))
4626 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4627 "sides-default", NULL
, "two-sided-long-edge");
4629 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4630 "sides-default", NULL
, "one-sided");
4634 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4635 "sides-supported", NULL
, "one-sided");
4636 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4637 "sides-default", NULL
, "one-sided");
4640 if (ppdFindOption(ppd
, "Collate") != NULL
)
4641 p
->type
|= CUPS_PRINTER_COLLATE
;
4643 if (ppdFindOption(ppd
, "StapleLocation") != NULL
)
4645 p
->type
|= CUPS_PRINTER_STAPLE
;
4646 finishings
[num_finishings
++] = IPP_FINISHINGS_STAPLE
;
4649 if (ppdFindOption(ppd
, "BindEdge") != NULL
)
4651 p
->type
|= CUPS_PRINTER_BIND
;
4652 finishings
[num_finishings
++] = IPP_FINISHINGS_BIND
;
4655 for (i
= 0; i
< ppd
->num_sizes
; i
++)
4656 if (ppd
->sizes
[i
].length
> 1728)
4657 p
->type
|= CUPS_PRINTER_LARGE
;
4658 else if (ppd
->sizes
[i
].length
> 1008)
4659 p
->type
|= CUPS_PRINTER_MEDIUM
;
4661 p
->type
|= CUPS_PRINTER_SMALL
;
4663 if ((ppd_attr
= ppdFindAttr(ppd
, "APICADriver", NULL
)) != NULL
&&
4664 ppd_attr
->value
&& !_cups_strcasecmp(ppd_attr
->value
, "true"))
4666 if ((ppd_attr
= ppdFindAttr(ppd
, "APScannerOnly", NULL
)) != NULL
&&
4667 ppd_attr
->value
&& !_cups_strcasecmp(ppd_attr
->value
, "true"))
4668 p
->type
|= CUPS_PRINTER_SCANNER
;
4670 p
->type
|= CUPS_PRINTER_MFP
;
4674 * Scan the filters in the PPD file...
4679 for (filter
= (const char *)cupsArrayFirst(p
->pc
->filters
);
4681 filter
= (const char *)cupsArrayNext(p
->pc
->filters
))
4683 if (!_cups_strncasecmp(filter
, "application/vnd.cups-command", 28) &&
4684 _cups_isspace(filter
[28]))
4686 p
->type
|= CUPS_PRINTER_COMMANDS
;
4692 if (p
->type
& CUPS_PRINTER_COMMANDS
)
4694 char *commands
, /* Copy of commands */
4695 *start
, /* Start of name */
4696 *end
; /* End of name */
4697 int count
; /* Number of commands */
4699 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsCommands", NULL
)) != NULL
)
4701 for (count
= 0, start
= ppd_attr
->value
; *start
; count
++)
4703 while (_cups_isspace(*start
))
4709 while (*start
&& !isspace(*start
& 255))
4719 * Make a copy of the commands string and count how many commands there
4723 attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4724 "printer-commands", count
, NULL
, NULL
);
4726 commands
= strdup(ppd_attr
->value
);
4728 for (count
= 0, start
= commands
; *start
; count
++)
4730 while (isspace(*start
& 255))
4737 while (*end
&& !isspace(*end
& 255))
4743 attr
->values
[count
].string
.text
= _cupsStrAlloc(start
);
4753 * Add the standard list of commands...
4756 ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4758 (int)(sizeof(standard_commands
) /
4759 sizeof(standard_commands
[0])), NULL
,
4766 * No commands supported...
4769 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4770 "printer-commands", NULL
, "none");
4774 * Show current and available port monitors for this printer...
4777 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
, "port-monitor",
4778 NULL
, p
->port_monitor
? p
->port_monitor
: "none");
4780 for (i
= 1, ppd_attr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
4782 i
++, ppd_attr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
));
4786 if (strstr(ppd
->protocols
, "TBCP"))
4788 else if (strstr(ppd
->protocols
, "BCP"))
4792 attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
4793 "port-monitor-supported", i
, NULL
, NULL
);
4795 attr
->values
[0].string
.text
= _cupsStrAlloc("none");
4797 for (i
= 1, ppd_attr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
4799 i
++, ppd_attr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
))
4800 attr
->values
[i
].string
.text
= _cupsStrAlloc(ppd_attr
->value
);
4804 if (strstr(ppd
->protocols
, "TBCP"))
4805 attr
->values
[i
].string
.text
= _cupsStrAlloc("tbcp");
4806 else if (strstr(ppd
->protocols
, "BCP"))
4807 attr
->values
[i
].string
.text
= _cupsStrAlloc("bcp");
4810 if (ppdFindAttr(ppd
, "APRemoteQueueID", NULL
))
4811 p
->type
|= CUPS_PRINTER_REMOTE
;
4813 #ifdef HAVE_APPLICATIONSERVICES_H
4815 * Convert the file referenced in APPrinterIconPath to a 128x128 PNG
4816 * and save it as cacheDir/printername.png
4819 if ((ppd_attr
= ppdFindAttr(ppd
, "APPrinterIconPath", NULL
)) != NULL
&&
4821 !_cupsFileCheck(ppd_attr
->value
, _CUPS_FILE_CHECK_FILE
, !RunUser
,
4822 cupsdLogFCMessage
, p
))
4824 CGImageRef imageRef
= NULL
;/* Current icon image */
4825 CGImageRef biggestIconRef
= NULL
;
4826 /* Biggest icon image */
4827 CGImageRef closestTo128IconRef
= NULL
;
4828 /* Icon image closest to and >= 128 */
4829 CGImageSourceRef sourceRef
; /* The file's image source */
4830 char outPath
[HTTP_MAX_URI
];
4831 /* The path to the PNG file */
4832 CFURLRef outUrl
; /* The URL made from the outPath */
4833 CFURLRef icnsFileUrl
; /* The URL of the original ICNS icon file */
4834 CGImageDestinationRef destRef
; /* The image destination to write */
4835 size_t bytesPerRow
; /* The bytes per row used for resizing */
4836 CGContextRef context
; /* The CG context used for resizing */
4838 snprintf(outPath
, sizeof(outPath
), "%s/%s.png", CacheDir
, p
->name
);
4839 outUrl
= CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault
,
4843 icnsFileUrl
= CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault
,
4844 (UInt8
*)ppd_attr
->value
,
4845 strlen(ppd_attr
->value
),
4847 if (outUrl
&& icnsFileUrl
)
4849 sourceRef
= CGImageSourceCreateWithURL(icnsFileUrl
, NULL
);
4852 for (i
= 0; i
< CGImageSourceGetCount(sourceRef
); i
++)
4854 imageRef
= CGImageSourceCreateImageAtIndex(sourceRef
, i
, NULL
);
4858 if (CGImageGetWidth(imageRef
) == CGImageGetHeight(imageRef
))
4861 * Loop through remembering the icon closest to 128 but >= 128
4862 * and then remember the largest icon.
4865 if (CGImageGetWidth(imageRef
) >= 128 &&
4866 (!closestTo128IconRef
||
4867 CGImageGetWidth(imageRef
) <
4868 CGImageGetWidth(closestTo128IconRef
)))
4870 CGImageRelease(closestTo128IconRef
);
4871 CGImageRetain(imageRef
);
4872 closestTo128IconRef
= imageRef
;
4875 if (!biggestIconRef
||
4876 CGImageGetWidth(imageRef
) > CGImageGetWidth(biggestIconRef
))
4878 CGImageRelease(biggestIconRef
);
4879 CGImageRetain(imageRef
);
4880 biggestIconRef
= imageRef
;
4884 CGImageRelease(imageRef
);
4890 * If biggestIconRef is NULL, we found no icons. Otherwise we first
4891 * want the closest to 128, but if none are larger than 128, we want
4892 * the largest icon available.
4895 imageRef
= closestTo128IconRef
? closestTo128IconRef
:
4897 CGImageRetain(imageRef
);
4898 CGImageRelease(biggestIconRef
);
4899 if (closestTo128IconRef
)
4900 CGImageRelease(closestTo128IconRef
);
4901 destRef
= CGImageDestinationCreateWithURL(outUrl
, kUTTypePNG
, 1,
4905 if (CGImageGetWidth(imageRef
) != 128)
4907 bytesPerRow
= CGImageGetBytesPerRow(imageRef
) /
4908 CGImageGetWidth(imageRef
) * 128;
4909 context
= CGBitmapContextCreate(NULL
, 128, 128,
4910 CGImageGetBitsPerComponent(imageRef
),
4912 CGImageGetColorSpace(imageRef
),
4913 kCGImageAlphaPremultipliedFirst
);
4916 CGContextDrawImage(context
, CGRectMake(0, 0, 128, 128),
4918 CGImageRelease(imageRef
);
4919 imageRef
= CGBitmapContextCreateImage(context
);
4920 CGContextRelease(context
);
4924 CGImageDestinationAddImage(destRef
, imageRef
, NULL
);
4925 CGImageDestinationFinalize(destRef
);
4929 CGImageRelease(imageRef
);
4932 CFRelease(sourceRef
);
4940 CFRelease(icnsFileUrl
);
4942 #endif /* HAVE_APPLICATIONSERVICES_H */
4945 * Close the PPD and set the type...
4950 else if (!access(ppd_name
, 0))
4952 int pline
; /* PPD line number */
4953 ppd_status_t pstatus
; /* PPD load status */
4956 pstatus
= ppdLastError(&pline
);
4958 cupsdLogMessage(CUPSD_LOG_ERROR
, "PPD file for %s cannot be loaded!",
4961 if (pstatus
<= PPD_ALLOC_ERROR
)
4962 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s", strerror(errno
));
4964 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s on line %d.",
4965 ppdErrorString(pstatus
), pline
);
4967 cupsdLogMessage(CUPSD_LOG_INFO
,
4968 "Hint: Run \"cupstestppd %s\" and fix any errors.",
4974 * If we have an interface script, add a filter entry for it...
4977 char interface
[1024]; /* Interface script */
4980 snprintf(interface
, sizeof(interface
), "%s/interfaces/%s", ServerRoot
,
4982 if (!access(interface
, X_OK
))
4985 * Yes, we have a System V style interface script; use it!
4988 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
4989 "printer-make-and-model", NULL
,
4990 "Local System V Printer");
4992 else if (!strncmp(p
->device_uri
, "ipp://", 6) &&
4993 (strstr(p
->device_uri
, "/printers/") != NULL
||
4994 strstr(p
->device_uri
, "/classes/") != NULL
||
4995 (strstr(p
->device_uri
, "._ipp.") != NULL
&&
4996 !strcmp(p
->device_uri
+ strlen(p
->device_uri
) - 5,
5000 * Tell the client this is really a hard-wired remote printer.
5003 p
->type
|= CUPS_PRINTER_REMOTE
;
5006 * Point the printer-uri-supported attribute to the
5010 if (strchr(p
->device_uri
, '?'))
5013 * Strip trailing "?options" from URI...
5016 char resource
[HTTP_MAX_URI
], /* New URI */
5017 *ptr
; /* Pointer into URI */
5019 strlcpy(resource
, p
->device_uri
, sizeof(resource
));
5020 if ((ptr
= strchr(resource
, '?')) != NULL
)
5023 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
5024 "printer-uri-supported", NULL
, resource
);
5027 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
5028 "printer-uri-supported", NULL
, p
->device_uri
);
5031 * Then set the make-and-model accordingly...
5034 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
5035 "printer-make-and-model", NULL
, "Remote Printer");
5038 * Print all files directly...
5047 * Otherwise we have neither - treat this as a "dumb" printer
5048 * with no PPD file...
5051 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
5052 "printer-make-and-model", NULL
, "Local Raw Printer");
5058 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
5059 "finishings-supported", num_finishings
, finishings
);
5060 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
5061 "finishings-default", IPP_FINISHINGS_NONE
);
5066 * Save cached PPD attributes to disk...
5069 cupsdLogMessage(CUPSD_LOG_DEBUG
, "load_ppd: Saving %s...", cache_name
);
5071 _ppdCacheWriteFile(p
->pc
, cache_name
, p
->ppd_attrs
);
5076 * Remove cache files...
5079 if (cache_info
.st_mtime
)
5086 * 'log_ipp_conformance()' - Log an IPP conformance issue with a printer.
5090 log_ipp_conformance(
5091 cupsd_printer_t
*p
, /* I - Printer */
5092 const char *reason
) /* I - Printer state reason */
5094 const char *message
; /* Message to log */
5096 aslmsg aslm
; /* Apple System Log message */
5097 #endif /* __APPLE__ */
5101 * Strip the leading "cups-ipp-" from the reason and create a log message for
5106 if (!strcmp(reason
, "missing-cancel-job"))
5107 message
= "Printer does not support REQUIRED Cancel-Job operation.";
5108 else if (!strcmp(reason
, "missing-get-job-attributes"))
5109 message
= "Printer does not support REQUIRED Get-Job-Attributes operation.";
5110 else if (!strcmp(reason
, "missing-print-job"))
5111 message
= "Printer does not support REQUIRED Print-Job operation.";
5112 else if (!strcmp(reason
, "missing-validate-job"))
5113 message
= "Printer does not support REQUIRED Validate-Job operation.";
5114 else if (!strcmp(reason
, "missing-get-printer-attributes"))
5115 message
= "Printer does not support REQUIRED Get-Printer-Attributes operation.";
5116 else if (!strcmp(reason
, "missing-job-history"))
5117 message
= "Printer does not provide REQUIRED job history.";
5118 else if (!strcmp(reason
, "missing-job-id"))
5119 message
= "Printer does not provide REQUIRED job-id attribute.";
5120 else if (!strcmp(reason
, "missing-job-state"))
5121 message
= "Printer does not provide REQUIRED job-state attribute.";
5122 else if (!strcmp(reason
, "missing-operations-supported"))
5123 message
= "Printer does not provide REQUIRED operations-supported "
5125 else if (!strcmp(reason
, "missing-printer-is-accepting-jobs"))
5126 message
= "Printer does not provide REQUIRED printer-is-accepting-jobs "
5128 else if (!strcmp(reason
, "missing-printer-state-reasons"))
5129 message
= "Printer does not provide REQUIRED printer-state-reasons "
5131 else if (!strcmp(reason
, "wrong-http-version"))
5132 message
= "Printer does not use REQUIRED HTTP/1.1 transport.";
5134 message
= "Unknown IPP conformance failure.";
5136 cupsdLogMessage(CUPSD_LOG_WARN
, "%s: %s", p
->name
, message
);
5140 * Report the failure information to Apple if the user opts into providing
5141 * feedback to Apple...
5144 aslm
= asl_new(ASL_TYPE_MSG
);
5147 asl_set(aslm
, "com.apple.message.domain", "com.apple.printing.ipp.conformance");
5148 asl_set(aslm
, "com.apple.message.domain_scope", "com.apple.printing.ipp.conformance");
5149 asl_set(aslm
, "com.apple.message.signature", reason
);
5150 asl_set(aslm
, "com.apple.message.signature2",
5151 p
->make_model
? p
->make_model
: "Unknown");
5152 asl_log(NULL
, aslm
, ASL_LEVEL_NOTICE
, "%s: %s",
5153 p
->make_model
? p
->make_model
: "Unknown", message
);
5156 #endif /* __APPLE__ */
5161 * 'new_media_col()' - Create a media-col collection value.
5164 static ipp_t
* /* O - Collection value */
5165 new_media_col(_pwg_size_t
*size
, /* I - media-size/margin values */
5166 const char *source
, /* I - media-source value */
5167 const char *type
) /* I - media-type value */
5169 ipp_t
*media_col
, /* Collection value */
5170 *media_size
; /* media-size value */
5173 media_col
= ippNew();
5175 media_size
= ippNew();
5176 ippAddInteger(media_size
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5177 "x-dimension", size
->width
);
5178 ippAddInteger(media_size
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5179 "y-dimension", size
->length
);
5180 ippAddCollection(media_col
, IPP_TAG_PRINTER
, "media-size", media_size
);
5181 ippDelete(media_size
);
5183 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5184 "media-bottom-margin", size
->bottom
);
5185 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5186 "media-left-margin", size
->left
);
5187 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5188 "media-right-margin", size
->right
);
5189 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5190 "media-top-margin", size
->top
);
5193 ippAddString(media_col
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
, "media-source",
5197 ippAddString(media_col
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
, "media-type",
5206 * 'write_irix_config()' - Update the config files used by the IRIX
5211 write_irix_config(cupsd_printer_t
*p
) /* I - Printer to update */
5213 char filename
[1024]; /* Interface script filename */
5214 cups_file_t
*fp
; /* Interface script file */
5215 ipp_attribute_t
*attr
; /* Attribute data */
5219 * Add dummy interface and GUI scripts to fool SGI's "challenged" printing
5220 * tools. First the interface script that tells the tools what kind of
5221 * printer we have...
5224 snprintf(filename
, sizeof(filename
), "/var/spool/lp/interface/%s", p
->name
);
5226 if (p
->type
& CUPS_PRINTER_CLASS
)
5228 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
5230 cupsFilePuts(fp
, "#!/bin/sh\n");
5232 if ((attr
= ippFindAttribute(p
->attrs
, "printer-make-and-model",
5233 IPP_TAG_TEXT
)) != NULL
)
5234 cupsFilePrintf(fp
, "NAME=\"%s\"\n", attr
->values
[0].string
.text
);
5235 else if (p
->type
& CUPS_PRINTER_CLASS
)
5236 cupsFilePuts(fp
, "NAME=\"Printer Class\"\n");
5238 cupsFilePuts(fp
, "NAME=\"Remote Destination\"\n");
5240 if (p
->type
& CUPS_PRINTER_COLOR
)
5241 cupsFilePuts(fp
, "TYPE=ColorPostScript\n");
5243 cupsFilePuts(fp
, "TYPE=MonoPostScript\n");
5245 cupsFilePrintf(fp
, "HOSTNAME=%s\n", ServerName
);
5246 cupsFilePrintf(fp
, "HOSTPRINTER=%s\n", p
->name
);
5250 chmod(filename
, 0755);
5251 chown(filename
, User
, Group
);
5255 * Then the member file that tells which device file the queue is connected
5256 * to... Networked printers use "/dev/null" in this file, so that's what
5257 * we use (the actual device URI can confuse some apps...)
5260 snprintf(filename
, sizeof(filename
), "/var/spool/lp/member/%s", p
->name
);
5262 if (p
->type
& CUPS_PRINTER_CLASS
)
5264 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
5266 cupsFilePuts(fp
, "/dev/null\n");
5270 chmod(filename
, 0644);
5271 chown(filename
, User
, Group
);
5275 * The gui_interface file is a script or program that launches a GUI
5276 * option panel for the printer, using options specified on the
5277 * command-line in the third argument. The option panel must send
5278 * any printing options to stdout on a single line when the user
5279 * accepts them, or nothing if the user cancels the dialog.
5281 * The default options panel program is /usr/bin/glpoptions, from
5282 * the ESP Print Pro software. You can select another using the
5283 * PrintcapGUI option.
5286 snprintf(filename
, sizeof(filename
), "/var/spool/lp/gui_interface/ELF/%s.gui", p
->name
);
5288 if (p
->type
& CUPS_PRINTER_CLASS
)
5290 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
5292 cupsFilePuts(fp
, "#!/bin/sh\n");
5293 cupsFilePrintf(fp
, "%s -d %s -o \"$3\"\n", PrintcapGUI
, p
->name
);
5297 chmod(filename
, 0755);
5298 chown(filename
, User
, Group
);
5302 * The POD config file is needed by the printstatus command to show
5303 * the printer location and device.
5306 snprintf(filename
, sizeof(filename
), "/var/spool/lp/pod/%s.config", p
->name
);
5308 if (p
->type
& CUPS_PRINTER_CLASS
)
5310 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
5312 cupsFilePrintf(fp
, "Printer Class | %s\n",
5313 (p
->type
& CUPS_PRINTER_COLOR
) ? "ColorPostScript" : "MonoPostScript");
5314 cupsFilePrintf(fp
, "Printer Model | %s\n", p
->make_model
? p
->make_model
: "");
5315 cupsFilePrintf(fp
, "Location Code | %s\n", p
->location
? p
->location
: "");
5316 cupsFilePrintf(fp
, "Physical Location | %s\n", p
->info
? p
->info
: "");
5317 cupsFilePrintf(fp
, "Port Path | %s\n", p
->device_uri
);
5318 cupsFilePrintf(fp
, "Config Path | /var/spool/lp/pod/%s.config\n", p
->name
);
5319 cupsFilePrintf(fp
, "Active Status Path | /var/spool/lp/pod/%s.status\n", p
->name
);
5320 cupsFilePuts(fp
, "Status Update Wait | 10 seconds\n");
5324 chmod(filename
, 0664);
5325 chown(filename
, User
, Group
);
5331 * 'write_irix_state()' - Update the status files used by IRIX printing
5336 write_irix_state(cupsd_printer_t
*p
) /* I - Printer to update */
5338 char filename
[1024]; /* Interface script filename */
5339 cups_file_t
*fp
; /* Interface script file */
5340 int tag
; /* Status tag value */
5346 * The POD status file is needed for the printstatus window to
5347 * provide the current status of the printer.
5350 snprintf(filename
, sizeof(filename
), "/var/spool/lp/pod/%s.status", p
->name
);
5352 if (p
->type
& CUPS_PRINTER_CLASS
)
5354 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
5356 cupsFilePrintf(fp
, "Operational Status | %s\n",
5357 (p
->state
== IPP_PRINTER_IDLE
) ? "Idle" :
5358 (p
->state
== IPP_PRINTER_PROCESSING
) ? "Busy" :
5360 cupsFilePrintf(fp
, "Information | 01 00 00 | %s\n", CUPS_SVERSION
);
5361 cupsFilePrintf(fp
, "Information | 02 00 00 | Device URI: %s\n",
5363 cupsFilePrintf(fp
, "Information | 03 00 00 | %s jobs\n",
5364 p
->accepting
? "Accepting" : "Not accepting");
5365 cupsFilePrintf(fp
, "Information | 04 00 00 | %s\n", p
->state_message
);
5369 chmod(filename
, 0664);
5370 chown(filename
, User
, Group
);
5374 * The activeicons file is needed to provide desktop icons for printers:
5376 * [ quoted from /usr/lib/print/tagit ]
5378 * --- Type of printer tags (base values)
5380 * Dumb=66048 # 0x10200
5381 * DumbColor=66080 # 0x10220
5382 * Raster=66112 # 0x10240
5383 * ColorRaster=66144 # 0x10260
5384 * Plotter=66176 # 0x10280
5385 * PostScript=66208 # 0x102A0
5386 * ColorPostScript=66240 # 0x102C0
5387 * MonoPostScript=66272 # 0x102E0
5389 * --- Printer state modifiers for local printers
5394 * Unknown=3 # 0x3 (Faulted due to unknown reason)
5396 * --- Printer state modifiers for network printers
5400 * NetFaulted=10 # 0xA
5401 * NetUnknown=11 # 0xB (Faulted due to unknown reason)
5404 snprintf(filename
, sizeof(filename
), "/var/spool/lp/activeicons/%s", p
->name
);
5406 if (p
->type
& CUPS_PRINTER_CLASS
)
5408 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
5410 if (p
->type
& CUPS_PRINTER_COLOR
)
5415 if (p
->type
& CUPS_PRINTER_REMOTE
)
5418 if (p
->state
== IPP_PRINTER_PROCESSING
)
5421 else if (p
->state
== IPP_PRINTER_STOPPED
)
5424 cupsFilePuts(fp
, "#!/bin/sh\n");
5425 cupsFilePrintf(fp
, "#Tag %d\n", tag
);
5429 chmod(filename
, 0755);
5430 chown(filename
, User
, Group
);
5435 * The default file is needed by the printers window to show
5436 * the default printer.
5439 snprintf(filename
, sizeof(filename
), "/var/spool/lp/default");
5441 if (DefaultPrinter
!= NULL
)
5443 if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
5445 cupsFilePrintf(fp
, "%s\n", DefaultPrinter
->name
);
5449 chmod(filename
, 0644);
5450 chown(filename
, User
, Group
);
5460 * 'write_xml_string()' - Write a string with XML escaping.
5464 write_xml_string(cups_file_t
*fp
, /* I - File to write to */
5465 const char *s
) /* I - String to write */
5467 const char *start
; /* Start of current sequence */
5473 for (start
= s
; *s
; s
++)
5478 cupsFileWrite(fp
, start
, s
- start
);
5480 cupsFilePuts(fp
, "&");
5486 cupsFileWrite(fp
, start
, s
- start
);
5488 cupsFilePuts(fp
, "<");
5494 cupsFilePuts(fp
, start
);
5499 * End of "$Id: printers.c 7968 2008-09-19 23:03:01Z mike $".