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 */
85 static void add_printer_defaults(cupsd_printer_t
*p
);
86 static void add_printer_filter(cupsd_printer_t
*p
, mime_type_t
*type
,
88 static void add_printer_formats(cupsd_printer_t
*p
);
89 static int compare_printers(void *first
, void *second
, void *data
);
90 static void delete_printer_filters(cupsd_printer_t
*p
);
91 static void dirty_printer(cupsd_printer_t
*p
);
92 static void load_ppd(cupsd_printer_t
*p
);
93 static ipp_t
*new_media_col(_pwg_size_t
*size
, const char *source
,
96 static void write_irix_config(cupsd_printer_t
*p
);
97 static void write_irix_state(cupsd_printer_t
*p
);
99 static void write_xml_string(cups_file_t
*fp
, const char *s
);
103 * 'cupsdAddPrinter()' - Add a printer to the system.
106 cupsd_printer_t
* /* O - New printer */
107 cupsdAddPrinter(const char *name
) /* I - Name of printer */
109 cupsd_printer_t
*p
; /* New printer */
110 char uri
[1024]; /* Printer URI */
114 * Range check input...
117 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdAddPrinter(\"%s\")", name
);
120 * Create a new printer entity...
123 if ((p
= calloc(1, sizeof(cupsd_printer_t
))) == NULL
)
125 cupsdLogMessage(CUPSD_LOG_CRIT
, "Unable to allocate memory for printer - %s",
130 cupsdSetString(&p
->name
, name
);
131 cupsdSetString(&p
->info
, name
);
132 cupsdSetString(&p
->hostname
, ServerName
);
134 httpAssembleURIf(HTTP_URI_CODING_ALL
, uri
, sizeof(uri
), "ipp", NULL
,
135 ServerName
, RemotePort
, "/printers/%s", name
);
136 cupsdSetString(&p
->uri
, uri
);
137 cupsdSetDeviceURI(p
, "file:///dev/null");
139 p
->state
= IPP_PRINTER_STOPPED
;
140 p
->state_time
= time(NULL
);
142 p
->shared
= DefaultShared
;
143 p
->filetype
= mimeAddType(MimeDatabase
, "printer", name
);
145 cupsdSetString(&p
->job_sheets
[0], "none");
146 cupsdSetString(&p
->job_sheets
[1], "none");
148 cupsdSetString(&p
->error_policy
, ErrorPolicy
);
149 cupsdSetString(&p
->op_policy
, DefaultPolicy
);
151 p
->op_policy_ptr
= DefaultPolicyPtr
;
154 * Insert the printer in the printer list alphabetically...
158 Printers
= cupsArrayNew(compare_printers
, NULL
);
160 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
161 "cupsdAddPrinter: Adding %s to Printers", p
->name
);
162 cupsArrayAdd(Printers
, p
);
164 if (!ImplicitPrinters
)
165 ImplicitPrinters
= cupsArrayNew(compare_printers
, NULL
);
168 * Return the new printer...
176 * 'cupsdCreateCommonData()' - Create the common printer data.
180 cupsdCreateCommonData(void)
182 int i
; /* Looping var */
183 ipp_attribute_t
*attr
; /* Attribute data */
184 cups_dir_t
*dir
; /* Notifier directory */
185 cups_dentry_t
*dent
; /* Notifier directory entry */
186 cups_array_t
*notifiers
; /* Notifier array */
187 char filename
[1024], /* Filename */
188 *notifier
; /* Current notifier */
189 cupsd_policy_t
*p
; /* Current policy */
190 int k_supported
; /* Maximum file size supported */
192 struct statvfs spoolinfo
; /* FS info for spool directory */
193 double spoolsize
; /* FS size */
194 #elif defined(HAVE_STATFS)
195 struct statfs spoolinfo
; /* FS info for spool directory */
196 double spoolsize
; /* FS size */
197 #endif /* HAVE_STATVFS */
198 static const int nups
[] = /* number-up-supported values */
199 { 1, 2, 4, 6, 9, 16 };
200 static const int orients
[4] =/* orientation-requested-supported values */
204 IPP_REVERSE_LANDSCAPE
,
207 static const char * const holds
[] = /* job-hold-until-supported values */
218 static const char * const versions
[] =/* ipp-versions-supported values */
225 static const int ops
[] = /* operations-supported values */
232 IPP_GET_JOB_ATTRIBUTES
,
234 IPP_GET_PRINTER_ATTRIBUTES
,
241 IPP_SET_PRINTER_ATTRIBUTES
,
242 IPP_SET_JOB_ATTRIBUTES
,
243 IPP_GET_PRINTER_SUPPORTED_VALUES
,
244 IPP_CREATE_PRINTER_SUBSCRIPTION
,
245 IPP_CREATE_JOB_SUBSCRIPTION
,
246 IPP_GET_SUBSCRIPTION_ATTRIBUTES
,
247 IPP_GET_SUBSCRIPTIONS
,
248 IPP_RENEW_SUBSCRIPTION
,
249 IPP_CANCEL_SUBSCRIPTION
,
250 IPP_GET_NOTIFICATIONS
,
254 IPP_RELEASE_HELD_NEW_JOBS
,
271 CUPS_AUTHENTICATE_JOB
,
276 static const char * const charsets
[] =/* charset-supported values */
281 static const char * const compressions
[] =
282 { /* document-compression-supported values */
286 #endif /* HAVE_LIBZ */
288 static const char * const media_col_supported
[] =
289 { /* media-col-supported values */
290 "media-bottom-margin",
292 "media-right-margin",
298 static const char * const multiple_document_handling
[] =
299 { /* multiple-document-handling-supported values */
300 "separate-documents-uncollated-copies",
301 "separate-documents-collated-copies"
303 static const char * const notify_attrs
[] =
304 { /* notify-attributes-supported values */
305 "printer-state-change-time",
306 "notify-lease-expiration-time",
307 "notify-subscriber-user-name"
309 static const char * const notify_events
[] =
310 { /* notify-events-supported values */
312 "job-config-changed",
319 "printer-config-changed",
321 "printer-finishings-changed",
322 "printer-media-changed",
326 "printer-state-changed",
333 static const char * const job_creation
[] =
334 { /* job-creation-attributes-supported */
337 "ipp-attribute-fidelity",
344 "multiple-document-handling",
348 "orientation-requested",
351 "printer-resolution",
354 static const char * const job_settable
[] =
355 { /* job-settable-attributes-supported */
363 "multiple-document-handling",
367 "orientation-requested",
370 "printer-resolution",
373 static const char * const printer_settable
[] =
374 { /* printer-settable-attributes-supported */
378 static const char * const which_jobs
[] =
379 { /* which-jobs-supported values */
393 ippDelete(CommonData
);
395 CommonData
= ippNew();
398 * Get the maximum spool size based on the size of the filesystem used for
399 * the RequestRoot directory. If the host OS doesn't support the statfs call
400 * or the filesystem is larger than 2TiB, always report INT_MAX.
404 if (statvfs(RequestRoot
, &spoolinfo
))
405 k_supported
= INT_MAX
;
406 else if ((spoolsize
= (double)spoolinfo
.f_frsize
* spoolinfo
.f_blocks
/ 1024) >
408 k_supported
= INT_MAX
;
410 k_supported
= (int)spoolsize
;
412 #elif defined(HAVE_STATFS)
413 if (statfs(RequestRoot
, &spoolinfo
))
414 k_supported
= INT_MAX
;
415 else if ((spoolsize
= (double)spoolinfo
.f_bsize
* spoolinfo
.f_blocks
/ 1024) >
417 k_supported
= INT_MAX
;
419 k_supported
= (int)spoolsize
;
422 k_supported
= INT_MAX
;
423 #endif /* HAVE_STATVFS */
426 * This list of attributes is sorted to improve performance when the
427 * client provides a requested-attributes attribute...
430 /* charset-configured */
431 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_CHARSET
| IPP_TAG_COPY
,
432 "charset-configured", NULL
, "utf-8");
434 /* charset-supported */
435 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_CHARSET
| IPP_TAG_COPY
,
436 "charset-supported", sizeof(charsets
) / sizeof(charsets
[0]),
439 /* compression-supported */
440 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
441 "compression-supported",
442 sizeof(compressions
) / sizeof(compressions
[0]),
445 /* copies-supported */
446 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "copies-supported", 1, MaxCopies
);
449 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
| IPP_TAG_COPY
,
450 "cups-version", NULL
, CUPS_SVERSION
+ 6);
452 /* generated-natural-language-supported (no IPP_TAG_COPY) */
453 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_LANGUAGE
,
454 "generated-natural-language-supported", NULL
, DefaultLanguage
);
456 /* ipp-versions-supported */
457 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
458 "ipp-versions-supported", sizeof(versions
) / sizeof(versions
[0]),
461 /* ippget-event-life */
462 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
463 "ippget-event-life", 15);
465 /* job-creation-attributes-supported */
466 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
467 "job-creation-attributes-supported",
468 sizeof(job_creation
) / sizeof(job_creation
[0]),
471 /* job-hold-until-supported */
472 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
473 "job-hold-until-supported", sizeof(holds
) / sizeof(holds
[0]),
476 /* job-ids-supported */
477 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
, "job-ids-supported", 1);
479 /* job-k-octets-supported */
480 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
481 "job-k-octets-supported", k_supported
);
483 /* job-priority-supported */
484 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
485 "job-priority-supported", 100);
487 /* job-settable-attributes-supported */
488 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
489 "job-settable-attributes-supported",
490 sizeof(job_settable
) / sizeof(job_settable
[0]),
493 /* job-sheets-supported */
494 if (cupsArrayCount(Banners
) > 0)
497 * Setup the job-sheets-supported attribute...
500 if (Classification
&& !ClassifyOverride
)
501 attr
= ippAddString(CommonData
, IPP_TAG_PRINTER
,
502 IPP_TAG_NAME
| IPP_TAG_COPY
,
503 "job-sheets-supported", NULL
, Classification
);
505 attr
= ippAddStrings(CommonData
, IPP_TAG_PRINTER
,
506 IPP_TAG_NAME
| IPP_TAG_COPY
,
507 "job-sheets-supported", cupsArrayCount(Banners
) + 1,
511 cupsdLogMessage(CUPSD_LOG_EMERG
,
512 "Unable to allocate memory for "
513 "job-sheets-supported attribute: %s!", strerror(errno
));
514 else if (!Classification
|| ClassifyOverride
)
516 cupsd_banner_t
*banner
; /* Current banner */
519 attr
->values
[0].string
.text
= _cupsStrAlloc("none");
521 for (i
= 1, banner
= (cupsd_banner_t
*)cupsArrayFirst(Banners
);
523 i
++, banner
= (cupsd_banner_t
*)cupsArrayNext(Banners
))
524 attr
->values
[i
].string
.text
= banner
->name
;
528 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
529 "job-sheets-supported", NULL
, "none");
531 /* media-col-supported */
532 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
533 "media-col-supported",
534 sizeof(media_col_supported
) /
535 sizeof(media_col_supported
[0]), NULL
,
536 media_col_supported
);
538 /* multiple-document-handling-supported */
539 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
540 "multiple-document-handling-supported",
541 sizeof(multiple_document_handling
) /
542 sizeof(multiple_document_handling
[0]), NULL
,
543 multiple_document_handling
);
545 /* multiple-document-jobs-supported */
546 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
,
547 "multiple-document-jobs-supported", 1);
549 /* multiple-operation-time-out */
550 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
551 "multiple-operation-time-out", MultipleOperationTimeout
);
553 /* natural-language-configured (no IPP_TAG_COPY) */
554 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_LANGUAGE
,
555 "natural-language-configured", NULL
, DefaultLanguage
);
557 /* notify-attributes-supported */
558 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
559 "notify-attributes-supported",
560 (int)(sizeof(notify_attrs
) / sizeof(notify_attrs
[0])),
563 /* notify-lease-duration-supported */
564 ippAddRange(CommonData
, IPP_TAG_PRINTER
,
565 "notify-lease-duration-supported", 0,
566 MaxLeaseDuration
? MaxLeaseDuration
: 2147483647);
568 /* notify-max-events-supported */
569 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
570 "notify-max-events-supported", MaxEvents
);
572 /* notify-events-supported */
573 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
574 "notify-events-supported",
575 (int)(sizeof(notify_events
) / sizeof(notify_events
[0])),
576 NULL
, notify_events
);
578 /* notify-pull-method-supported */
579 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
580 "notify-pull-method-supported", NULL
, "ippget");
582 /* notify-schemes-supported */
583 snprintf(filename
, sizeof(filename
), "%s/notifier", ServerBin
);
584 if ((dir
= cupsDirOpen(filename
)) != NULL
)
586 notifiers
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
588 while ((dent
= cupsDirRead(dir
)) != NULL
)
589 if (S_ISREG(dent
->fileinfo
.st_mode
) &&
590 (dent
->fileinfo
.st_mode
& S_IXOTH
) != 0)
591 cupsArrayAdd(notifiers
, _cupsStrAlloc(dent
->filename
));
593 if (cupsArrayCount(notifiers
) > 0)
595 attr
= ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
596 "notify-schemes-supported",
597 cupsArrayCount(notifiers
), NULL
, NULL
);
599 for (i
= 0, notifier
= (char *)cupsArrayFirst(notifiers
);
601 i
++, notifier
= (char *)cupsArrayNext(notifiers
))
602 attr
->values
[i
].string
.text
= notifier
;
605 cupsArrayDelete(notifiers
);
609 /* number-up-supported */
610 ippAddIntegers(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
611 "number-up-supported", sizeof(nups
) / sizeof(nups
[0]), nups
);
613 /* operations-supported */
614 ippAddIntegers(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
615 "operations-supported",
616 sizeof(ops
) / sizeof(ops
[0]) + JobFiles
- 1, ops
);
618 /* orientation-requested-supported */
619 ippAddIntegers(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
620 "orientation-requested-supported", 4, orients
);
622 /* page-ranges-supported */
623 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
, "page-ranges-supported", 1);
625 /* pdl-override-supported */
626 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
627 "pdl-override-supported", NULL
, "attempted");
629 /* printer-op-policy-supported */
630 attr
= ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
631 "printer-op-policy-supported", cupsArrayCount(Policies
),
633 for (i
= 0, p
= (cupsd_policy_t
*)cupsArrayFirst(Policies
);
635 i
++, p
= (cupsd_policy_t
*)cupsArrayNext(Policies
))
636 attr
->values
[i
].string
.text
= p
->name
;
638 /* printer-settable-attributes-supported */
639 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
640 "printer-settable-attributes-supported",
641 sizeof(printer_settable
) / sizeof(printer_settable
[0]),
642 NULL
, printer_settable
);
644 /* server-is-sharing-printers */
645 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
, "server-is-sharing-printers",
646 BrowseLocalProtocols
!= 0 && Browsing
);
648 /* which-jobs-supported */
649 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
650 "which-jobs-supported",
651 sizeof(which_jobs
) / sizeof(which_jobs
[0]), NULL
, which_jobs
);
656 * 'cupsdDeleteAllPrinters()' - Delete all printers from the system.
660 cupsdDeleteAllPrinters(void)
662 cupsd_printer_t
*p
; /* Pointer to current printer/class */
665 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
667 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
669 p
->op_policy_ptr
= DefaultPolicyPtr
;
670 cupsdDeletePrinter(p
, 0);
676 * 'cupsdDeletePrinter()' - Delete a printer from the system.
679 int /* O - 1 if classes affected, 0 otherwise */
681 cupsd_printer_t
*p
, /* I - Printer to delete */
682 int update
) /* I - Update printers.conf? */
684 int i
, /* Looping var */
685 changed
= 0; /* Class changed? */
687 char filename
[1024]; /* Interface script filename */
691 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdDeletePrinter(p=%p(%s), update=%d)",
695 * Save the current position in the Printers array...
698 cupsArraySave(Printers
);
701 * Stop printing on this printer...
704 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, update
);
706 p
->state
= IPP_PRINTER_STOPPED
; /* Force for browsed printers */
709 cupsdSetJobState(p
->job
, IPP_JOB_PENDING
, CUPSD_JOB_FORCE
,
710 update
? "Job stopped due to printer being deleted." :
714 * If this printer is the next for browsing, point to the next one...
719 cupsArrayFind(Printers
, p
);
720 BrowseNext
= (cupsd_printer_t
*)cupsArrayNext(Printers
);
724 * Remove the printer from the list...
727 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
728 "cupsdDeletePrinter: Removing %s from Printers", p
->name
);
729 cupsArrayRemove(Printers
, p
);
731 if (p
->type
& CUPS_PRINTER_IMPLICIT
)
733 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
734 "cupsdDeletePrinter: Removing %s from ImplicitPrinters",
736 cupsArrayRemove(ImplicitPrinters
, p
);
740 * Remove the dummy interface/icon/option files under IRIX...
744 snprintf(filename
, sizeof(filename
), "/var/spool/lp/interface/%s", p
->name
);
747 snprintf(filename
, sizeof(filename
), "/var/spool/lp/gui_interface/ELF/%s.gui",
751 snprintf(filename
, sizeof(filename
), "/var/spool/lp/activeicons/%s", p
->name
);
754 snprintf(filename
, sizeof(filename
), "/var/spool/lp/pod/%s.config", p
->name
);
757 snprintf(filename
, sizeof(filename
), "/var/spool/lp/pod/%s.status", p
->name
);
760 snprintf(filename
, sizeof(filename
), "/var/spool/lp/member/%s", p
->name
);
765 * If p is the default printer, assign a different one...
768 if (p
== DefaultPrinter
)
770 DefaultPrinter
= NULL
;
772 if (UseNetworkDefault
)
775 * Find the first network default printer and use it...
778 cupsd_printer_t
*dp
; /* New default printer */
781 for (dp
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
783 dp
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
784 if (dp
!= p
&& (dp
->type
& CUPS_PRINTER_DEFAULT
))
793 * Remove this printer from any classes...
796 if (!(p
->type
& CUPS_PRINTER_IMPLICIT
))
798 changed
= cupsdDeletePrinterFromClasses(p
);
801 * Deregister from any browse protocols...
804 cupsdDeregisterPrinter(p
, 1);
808 * Free all memory used by the printer...
811 if (p
->printers
!= NULL
)
814 delete_printer_filters(p
);
816 for (i
= 0; i
< p
->num_reasons
; i
++)
817 _cupsStrFree(p
->reasons
[i
]);
820 ippDelete(p
->ppd_attrs
);
822 mimeDeleteType(MimeDatabase
, p
->filetype
);
823 mimeDeleteType(MimeDatabase
, p
->prefiltertype
);
825 cupsdFreeStrings(&(p
->users
));
828 cupsdClearString(&p
->uri
);
829 cupsdClearString(&p
->hostname
);
830 cupsdClearString(&p
->name
);
831 cupsdClearString(&p
->location
);
832 cupsdClearString(&p
->make_model
);
833 cupsdClearString(&p
->info
);
834 cupsdClearString(&p
->job_sheets
[0]);
835 cupsdClearString(&p
->job_sheets
[1]);
836 cupsdClearString(&p
->device_uri
);
837 cupsdClearString(&p
->sanitized_device_uri
);
838 cupsdClearString(&p
->port_monitor
);
839 cupsdClearString(&p
->op_policy
);
840 cupsdClearString(&p
->error_policy
);
842 cupsdClearString(&p
->alert
);
843 cupsdClearString(&p
->alert_description
);
846 cupsdClearString(&p
->pdl
);
847 #endif /* HAVE_DNSSD */
849 cupsArrayDelete(p
->filetypes
);
852 free(p
->browse_attrs
);
854 cupsFreeOptions(p
->num_options
, p
->options
);
859 * Restore the previous position in the Printers array...
862 cupsArrayRestore(Printers
);
869 * 'cupsdFindDest()' - Find a destination in the list.
872 cupsd_printer_t
* /* O - Destination in list */
873 cupsdFindDest(const char *name
) /* I - Name of printer or class to find */
875 cupsd_printer_t key
; /* Search key */
878 key
.name
= (char *)name
;
879 return ((cupsd_printer_t
*)cupsArrayFind(Printers
, &key
));
884 * 'cupsdFindPrinter()' - Find a printer in the list.
887 cupsd_printer_t
* /* O - Printer in list */
888 cupsdFindPrinter(const char *name
) /* I - Name of printer to find */
890 cupsd_printer_t
*p
; /* Printer in list */
893 if ((p
= cupsdFindDest(name
)) != NULL
&& (p
->type
& CUPS_PRINTER_CLASS
))
901 * 'cupsdLoadAllPrinters()' - Load printers from the printers.conf file.
905 cupsdLoadAllPrinters(void)
907 int i
; /* Looping var */
908 cups_file_t
*fp
; /* printers.conf file */
909 int linenum
; /* Current line number */
910 char line
[4096], /* Line from file */
911 *value
, /* Pointer to value */
912 *valueptr
; /* Pointer into value */
913 cupsd_printer_t
*p
; /* Current printer */
917 * Open the printers.conf file...
920 snprintf(line
, sizeof(line
), "%s/printers.conf", ServerRoot
);
921 if ((fp
= cupsFileOpen(line
, "r")) == NULL
)
924 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to open %s - %s", line
,
930 * Read printer configurations until we hit EOF...
936 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
939 * Decode the directive...
942 if (!strcasecmp(line
, "<Printer") ||
943 !strcasecmp(line
, "<DefaultPrinter"))
946 * <Printer name> or <DefaultPrinter name>
949 if (p
== NULL
&& value
)
952 * Add the printer and a base file type...
955 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Loading printer %s...", value
);
957 p
= cupsdAddPrinter(value
);
959 p
->state
= IPP_PRINTER_IDLE
;
962 * Set the default printer as needed...
965 if (!strcasecmp(line
, "<DefaultPrinter"))
969 cupsdLogMessage(CUPSD_LOG_ERROR
,
970 "Syntax error on line %d of printers.conf.", linenum
);
972 else if (!strcasecmp(line
, "</Printer>"))
977 * Close out the current printer...
980 cupsdSetPrinterAttrs(p
);
982 if (strncmp(p
->device_uri
, "file:", 5) &&
983 p
->state
!= IPP_PRINTER_STOPPED
)
986 * See if the backend exists...
989 snprintf(line
, sizeof(line
), "%s/backend/%s", ServerBin
,
992 if ((valueptr
= strchr(line
+ strlen(ServerBin
), ':')) != NULL
)
993 *valueptr
= '\0'; /* Chop everything but URI scheme */
998 * Backend does not exist, stop printer...
1001 p
->state
= IPP_PRINTER_STOPPED
;
1002 snprintf(p
->state_message
, sizeof(p
->state_message
),
1003 "Backend %s does not exist!", line
);
1010 cupsdLogMessage(CUPSD_LOG_ERROR
,
1011 "Syntax error on line %d of printers.conf.", linenum
);
1015 cupsdLogMessage(CUPSD_LOG_ERROR
,
1016 "Syntax error on line %d of printers.conf.", linenum
);
1018 else if (!strcasecmp(line
, "AuthInfoRequired"))
1020 if (!cupsdSetAuthInfoRequired(p
, value
, NULL
))
1021 cupsdLogMessage(CUPSD_LOG_ERROR
,
1022 "Bad AuthInfoRequired on line %d of printers.conf.",
1025 else if (!strcasecmp(line
, "Info"))
1028 cupsdSetString(&p
->info
, value
);
1030 else if (!strcasecmp(line
, "MakeModel"))
1033 cupsdSetString(&p
->make_model
, value
);
1035 else if (!strcasecmp(line
, "Location"))
1038 cupsdSetString(&p
->location
, value
);
1040 else if (!strcasecmp(line
, "DeviceURI"))
1043 cupsdSetDeviceURI(p
, value
);
1045 cupsdLogMessage(CUPSD_LOG_ERROR
,
1046 "Syntax error on line %d of printers.conf.", linenum
);
1048 else if (!strcasecmp(line
, "Option") && value
)
1054 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1057 cupsdLogMessage(CUPSD_LOG_ERROR
,
1058 "Syntax error on line %d of printers.conf.", linenum
);
1061 for (; *valueptr
&& isspace(*valueptr
& 255); *valueptr
++ = '\0');
1063 p
->num_options
= cupsAddOption(value
, valueptr
, p
->num_options
,
1067 else if (!strcasecmp(line
, "PortMonitor"))
1069 if (value
&& strcmp(value
, "none"))
1070 cupsdSetString(&p
->port_monitor
, value
);
1072 cupsdClearString(&p
->port_monitor
);
1074 cupsdLogMessage(CUPSD_LOG_ERROR
,
1075 "Syntax error on line %d of printers.conf.", linenum
);
1077 else if (!strcasecmp(line
, "Reason"))
1080 strcmp(value
, "connecting-to-device") &&
1081 strcmp(value
, "cups-insecure-filter-warning") &&
1082 strcmp(value
, "cups-missing-filter-warning"))
1084 for (i
= 0 ; i
< p
->num_reasons
; i
++)
1085 if (!strcmp(value
, p
->reasons
[i
]))
1088 if (i
>= p
->num_reasons
&&
1089 p
->num_reasons
< (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
1091 p
->reasons
[p
->num_reasons
] = _cupsStrAlloc(value
);
1096 cupsdLogMessage(CUPSD_LOG_ERROR
,
1097 "Syntax error on line %d of printers.conf.", linenum
);
1099 else if (!strcasecmp(line
, "State"))
1102 * Set the initial queue state...
1105 if (value
&& !strcasecmp(value
, "idle"))
1106 p
->state
= IPP_PRINTER_IDLE
;
1107 else if (value
&& !strcasecmp(value
, "stopped"))
1109 p
->state
= IPP_PRINTER_STOPPED
;
1111 for (i
= 0 ; i
< p
->num_reasons
; i
++)
1112 if (!strcmp("paused", p
->reasons
[i
]))
1115 if (i
>= p
->num_reasons
&&
1116 p
->num_reasons
< (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
1118 p
->reasons
[p
->num_reasons
] = _cupsStrAlloc("paused");
1123 cupsdLogMessage(CUPSD_LOG_ERROR
,
1124 "Syntax error on line %d of printers.conf.", linenum
);
1126 else if (!strcasecmp(line
, "StateMessage"))
1129 * Set the initial queue state message...
1133 strlcpy(p
->state_message
, value
, sizeof(p
->state_message
));
1135 else if (!strcasecmp(line
, "StateTime"))
1138 * Set the state time...
1142 p
->state_time
= atoi(value
);
1144 else if (!strcasecmp(line
, "Accepting"))
1147 * Set the initial accepting state...
1151 (!strcasecmp(value
, "yes") ||
1152 !strcasecmp(value
, "on") ||
1153 !strcasecmp(value
, "true")))
1156 (!strcasecmp(value
, "no") ||
1157 !strcasecmp(value
, "off") ||
1158 !strcasecmp(value
, "false")))
1161 cupsdLogMessage(CUPSD_LOG_ERROR
,
1162 "Syntax error on line %d of printers.conf.", linenum
);
1164 else if (!strcasecmp(line
, "Type"))
1167 p
->type
= atoi(value
);
1169 cupsdLogMessage(CUPSD_LOG_ERROR
,
1170 "Syntax error on line %d of printers.conf.", linenum
);
1172 else if (!strcasecmp(line
, "Shared"))
1175 * Set the initial shared state...
1179 (!strcasecmp(value
, "yes") ||
1180 !strcasecmp(value
, "on") ||
1181 !strcasecmp(value
, "true")))
1184 (!strcasecmp(value
, "no") ||
1185 !strcasecmp(value
, "off") ||
1186 !strcasecmp(value
, "false")))
1189 cupsdLogMessage(CUPSD_LOG_ERROR
,
1190 "Syntax error on line %d of printers.conf.", linenum
);
1192 else if (!strcasecmp(line
, "JobSheets"))
1195 * Set the initial job sheets...
1200 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1205 cupsdSetString(&p
->job_sheets
[0], value
);
1207 while (isspace(*valueptr
& 255))
1212 for (value
= valueptr
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1217 cupsdSetString(&p
->job_sheets
[1], value
);
1221 cupsdLogMessage(CUPSD_LOG_ERROR
,
1222 "Syntax error on line %d of printers.conf.", linenum
);
1224 else if (!strcasecmp(line
, "AllowUser"))
1229 cupsdAddString(&(p
->users
), value
);
1232 cupsdLogMessage(CUPSD_LOG_ERROR
,
1233 "Syntax error on line %d of printers.conf.", linenum
);
1235 else if (!strcasecmp(line
, "DenyUser"))
1240 cupsdAddString(&(p
->users
), value
);
1243 cupsdLogMessage(CUPSD_LOG_ERROR
,
1244 "Syntax error on line %d of printers.conf.", linenum
);
1246 else if (!strcasecmp(line
, "QuotaPeriod"))
1249 p
->quota_period
= atoi(value
);
1251 cupsdLogMessage(CUPSD_LOG_ERROR
,
1252 "Syntax error on line %d of printers.conf.", linenum
);
1254 else if (!strcasecmp(line
, "PageLimit"))
1257 p
->page_limit
= atoi(value
);
1259 cupsdLogMessage(CUPSD_LOG_ERROR
,
1260 "Syntax error on line %d of printers.conf.", linenum
);
1262 else if (!strcasecmp(line
, "KLimit"))
1265 p
->k_limit
= atoi(value
);
1267 cupsdLogMessage(CUPSD_LOG_ERROR
,
1268 "Syntax error on line %d of printers.conf.", linenum
);
1270 else if (!strcasecmp(line
, "OpPolicy"))
1274 cupsd_policy_t
*pol
; /* Policy */
1277 if ((pol
= cupsdFindPolicy(value
)) != NULL
)
1279 cupsdSetString(&p
->op_policy
, value
);
1280 p
->op_policy_ptr
= pol
;
1283 cupsdLogMessage(CUPSD_LOG_ERROR
,
1284 "Bad policy \"%s\" on line %d of printers.conf",
1288 cupsdLogMessage(CUPSD_LOG_ERROR
,
1289 "Syntax error on line %d of printers.conf.", linenum
);
1291 else if (!strcasecmp(line
, "ErrorPolicy"))
1294 cupsdSetString(&p
->error_policy
, value
);
1296 cupsdLogMessage(CUPSD_LOG_ERROR
,
1297 "Syntax error on line %d of printers.conf.", linenum
);
1299 else if (!strcasecmp(line
, "Attribute") && value
)
1301 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1304 cupsdLogMessage(CUPSD_LOG_ERROR
,
1305 "Syntax error on line %d of printers.conf.", linenum
);
1308 for (; *valueptr
&& isspace(*valueptr
& 255); *valueptr
++ = '\0');
1311 cupsdSetPrinterAttrs(p
);
1313 if (!strcmp(value
, "marker-change-time"))
1314 p
->marker_time
= atoi(valueptr
);
1316 cupsdSetPrinterAttr(p
, value
, valueptr
);
1322 * Something else we don't understand...
1325 cupsdLogMessage(CUPSD_LOG_ERROR
,
1326 "Unknown configuration directive %s on line %d of printers.conf.",
1336 * 'cupsdRenamePrinter()' - Rename a printer.
1341 cupsd_printer_t
*p
, /* I - Printer */
1342 const char *name
) /* I - New name */
1345 * Remove the printer from the array(s) first...
1348 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1349 "cupsdRenamePrinter: Removing %s from Printers", p
->name
);
1350 cupsArrayRemove(Printers
, p
);
1352 if (p
->type
& CUPS_PRINTER_IMPLICIT
)
1354 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1355 "cupsdRenamePrinter: Removing %s from ImplicitPrinters",
1357 cupsArrayRemove(ImplicitPrinters
, p
);
1361 * Rename the printer type...
1364 mimeDeleteType(MimeDatabase
, p
->filetype
);
1365 p
->filetype
= mimeAddType(MimeDatabase
, "printer", name
);
1367 mimeDeleteType(MimeDatabase
, p
->prefiltertype
);
1368 p
->prefiltertype
= mimeAddType(MimeDatabase
, "prefilter", name
);
1371 * Rename the printer...
1374 cupsdSetString(&p
->name
, name
);
1377 * Reset printer attributes...
1380 cupsdSetPrinterAttrs(p
);
1383 * Add the printer back to the printer array(s)...
1386 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1387 "cupsdRenamePrinter: Adding %s to Printers", p
->name
);
1388 cupsArrayAdd(Printers
, p
);
1390 if (p
->type
& CUPS_PRINTER_IMPLICIT
)
1392 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1393 "cupsdRenamePrinter: Adding %s to ImplicitPrinters",
1395 cupsArrayAdd(ImplicitPrinters
, p
);
1401 * 'cupsdSaveAllPrinters()' - Save all printer definitions to the printers.conf
1406 cupsdSaveAllPrinters(void)
1408 int i
; /* Looping var */
1409 cups_file_t
*fp
; /* printers.conf file */
1410 char temp
[1024], /* Temporary string */
1411 backup
[1024], /* printers.conf.O file */
1412 value
[2048], /* Value string */
1413 *ptr
, /* Pointer into value */
1414 *name
; /* Current user/group name */
1415 cupsd_printer_t
*printer
; /* Current printer class */
1416 time_t curtime
; /* Current time */
1417 struct tm
*curdate
; /* Current date */
1418 cups_option_t
*option
; /* Current option */
1419 ipp_attribute_t
*marker
; /* Current marker attribute */
1423 * Create the printers.conf file...
1426 snprintf(temp
, sizeof(temp
), "%s/printers.conf", ServerRoot
);
1427 snprintf(backup
, sizeof(backup
), "%s/printers.conf.O", ServerRoot
);
1429 if (rename(temp
, backup
))
1431 if (errno
!= ENOENT
)
1432 cupsdLogMessage(CUPSD_LOG_ERROR
,
1433 "Unable to backup printers.conf - %s", strerror(errno
));
1436 if ((fp
= cupsFileOpen(temp
, "w")) == NULL
)
1438 cupsdLogMessage(CUPSD_LOG_ERROR
,
1439 "Unable to save printers.conf - %s", strerror(errno
));
1441 if (rename(backup
, temp
))
1442 cupsdLogMessage(CUPSD_LOG_ERROR
,
1443 "Unable to restore printers.conf - %s", strerror(errno
));
1447 cupsdLogMessage(CUPSD_LOG_INFO
, "Saving printers.conf...");
1450 * Restrict access to the file...
1453 fchown(cupsFileNumber(fp
), getuid(), Group
);
1454 fchmod(cupsFileNumber(fp
), ConfigFilePerm
& 0600);
1457 * Write a small header to the file...
1460 curtime
= time(NULL
);
1461 curdate
= localtime(&curtime
);
1462 strftime(temp
, sizeof(temp
) - 1, "%Y-%m-%d %H:%M", curdate
);
1464 cupsFilePuts(fp
, "# Printer configuration file for " CUPS_SVERSION
"\n");
1465 cupsFilePrintf(fp
, "# Written by cupsd on %s\n", temp
);
1466 cupsFilePuts(fp
, "# DO NOT EDIT THIS FILE WHEN CUPSD IS RUNNING\n");
1469 * Write each local printer known to the system...
1472 for (printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
1474 printer
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
1477 * Skip remote destinations and printer classes...
1480 if ((printer
->type
& CUPS_PRINTER_DISCOVERED
) ||
1481 (printer
->type
& CUPS_PRINTER_CLASS
) ||
1482 (printer
->type
& CUPS_PRINTER_IMPLICIT
))
1486 * Write printers as needed...
1489 if (printer
== DefaultPrinter
)
1490 cupsFilePrintf(fp
, "<DefaultPrinter %s>\n", printer
->name
);
1492 cupsFilePrintf(fp
, "<Printer %s>\n", printer
->name
);
1494 if (printer
->num_auth_info_required
> 0)
1496 switch (printer
->num_auth_info_required
)
1499 strlcpy(value
, printer
->auth_info_required
[0], sizeof(value
));
1503 snprintf(value
, sizeof(value
), "%s,%s",
1504 printer
->auth_info_required
[0],
1505 printer
->auth_info_required
[1]);
1510 snprintf(value
, sizeof(value
), "%s,%s,%s",
1511 printer
->auth_info_required
[0],
1512 printer
->auth_info_required
[1],
1513 printer
->auth_info_required
[2]);
1517 cupsFilePutConf(fp
, "AuthInfoRequired", value
);
1521 cupsFilePutConf(fp
, "Info", printer
->info
);
1523 if (printer
->location
)
1524 cupsFilePutConf(fp
, "Location", printer
->location
);
1526 if (printer
->make_model
)
1527 cupsFilePutConf(fp
, "MakeModel", printer
->make_model
);
1529 cupsFilePutConf(fp
, "DeviceURI", printer
->device_uri
);
1531 if (printer
->port_monitor
)
1532 cupsFilePutConf(fp
, "PortMonitor", printer
->port_monitor
);
1534 if (printer
->state
== IPP_PRINTER_STOPPED
)
1536 cupsFilePuts(fp
, "State Stopped\n");
1538 if (printer
->state_message
)
1539 cupsFilePutConf(fp
, "StateMessage", printer
->state_message
);
1542 cupsFilePuts(fp
, "State Idle\n");
1544 cupsFilePrintf(fp
, "StateTime %d\n", (int)printer
->state_time
);
1546 for (i
= 0; i
< printer
->num_reasons
; i
++)
1547 if (strcmp(printer
->reasons
[i
], "connecting-to-device") &&
1548 strcmp(printer
->reasons
[i
], "cups-insecure-filter-warning") &&
1549 strcmp(printer
->reasons
[i
], "cups-missing-filter-warning"))
1550 cupsFilePutConf(fp
, "Reason", printer
->reasons
[i
]);
1552 cupsFilePrintf(fp
, "Type %d\n", printer
->type
);
1554 if (printer
->accepting
)
1555 cupsFilePuts(fp
, "Accepting Yes\n");
1557 cupsFilePuts(fp
, "Accepting No\n");
1559 if (printer
->shared
)
1560 cupsFilePuts(fp
, "Shared Yes\n");
1562 cupsFilePuts(fp
, "Shared No\n");
1564 snprintf(value
, sizeof(value
), "%s %s", printer
->job_sheets
[0],
1565 printer
->job_sheets
[1]);
1566 cupsFilePutConf(fp
, "JobSheets", value
);
1568 cupsFilePrintf(fp
, "QuotaPeriod %d\n", printer
->quota_period
);
1569 cupsFilePrintf(fp
, "PageLimit %d\n", printer
->page_limit
);
1570 cupsFilePrintf(fp
, "KLimit %d\n", printer
->k_limit
);
1572 for (name
= (char *)cupsArrayFirst(printer
->users
);
1574 name
= (char *)cupsArrayNext(printer
->users
))
1575 cupsFilePutConf(fp
, printer
->deny_users
? "DenyUser" : "AllowUser", name
);
1577 if (printer
->op_policy
)
1578 cupsFilePutConf(fp
, "OpPolicy", printer
->op_policy
);
1579 if (printer
->error_policy
)
1580 cupsFilePutConf(fp
, "ErrorPolicy", printer
->error_policy
);
1582 for (i
= printer
->num_options
, option
= printer
->options
;
1586 snprintf(value
, sizeof(value
), "%s %s", option
->name
, option
->value
);
1587 cupsFilePutConf(fp
, "Option", value
);
1590 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-colors",
1591 IPP_TAG_NAME
)) != NULL
)
1593 snprintf(value
, sizeof(value
), "%s ", marker
->name
);
1595 for (i
= 0, ptr
= value
+ strlen(value
);
1596 i
< marker
->num_values
&& ptr
< (value
+ sizeof(value
) - 1);
1602 strlcpy(ptr
, marker
->values
[i
].string
.text
,
1603 value
+ sizeof(value
) - ptr
);
1608 cupsFilePutConf(fp
, "Attribute", value
);
1611 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-levels",
1612 IPP_TAG_INTEGER
)) != NULL
)
1614 cupsFilePrintf(fp
, "Attribute %s %d", marker
->name
,
1615 marker
->values
[0].integer
);
1616 for (i
= 1; i
< marker
->num_values
; i
++)
1617 cupsFilePrintf(fp
, ",%d", marker
->values
[i
].integer
);
1618 cupsFilePuts(fp
, "\n");
1621 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-low-levels",
1622 IPP_TAG_INTEGER
)) != NULL
)
1624 cupsFilePrintf(fp
, "Attribute %s %d", marker
->name
,
1625 marker
->values
[0].integer
);
1626 for (i
= 1; i
< marker
->num_values
; i
++)
1627 cupsFilePrintf(fp
, ",%d", marker
->values
[i
].integer
);
1628 cupsFilePuts(fp
, "\n");
1631 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-high-levels",
1632 IPP_TAG_INTEGER
)) != NULL
)
1634 cupsFilePrintf(fp
, "Attribute %s %d", marker
->name
,
1635 marker
->values
[0].integer
);
1636 for (i
= 1; i
< marker
->num_values
; i
++)
1637 cupsFilePrintf(fp
, ",%d", marker
->values
[i
].integer
);
1638 cupsFilePuts(fp
, "\n");
1641 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-message",
1642 IPP_TAG_TEXT
)) != NULL
)
1644 snprintf(value
, sizeof(value
), "%s %s", marker
->name
,
1645 marker
->values
[0].string
.text
);
1647 cupsFilePutConf(fp
, "Attribute", value
);
1650 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-names",
1651 IPP_TAG_NAME
)) != NULL
)
1653 snprintf(value
, sizeof(value
), "%s ", marker
->name
);
1655 for (i
= 0, ptr
= value
+ strlen(value
);
1656 i
< marker
->num_values
&& ptr
< (value
+ sizeof(value
) - 1);
1662 strlcpy(ptr
, marker
->values
[i
].string
.text
,
1663 value
+ sizeof(value
) - ptr
);
1668 cupsFilePutConf(fp
, "Attribute", value
);
1671 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-types",
1672 IPP_TAG_KEYWORD
)) != NULL
)
1674 snprintf(value
, sizeof(value
), "%s ", marker
->name
);
1676 for (i
= 0, ptr
= value
+ strlen(value
);
1677 i
< marker
->num_values
&& ptr
< (value
+ sizeof(value
) - 1);
1683 strlcpy(ptr
, marker
->values
[i
].string
.text
,
1684 value
+ sizeof(value
) - ptr
);
1689 cupsFilePutConf(fp
, "Attribute", value
);
1692 if (printer
->marker_time
)
1693 cupsFilePrintf(fp
, "Attribute marker-change-time %ld\n",
1694 (long)printer
->marker_time
);
1696 cupsFilePuts(fp
, "</Printer>\n");
1700 * Make IRIX desktop & printer status happy
1703 write_irix_state(printer
);
1712 * 'cupsdSetAuthInfoRequired()' - Set the required authentication info.
1715 int /* O - 1 if value OK, 0 otherwise */
1716 cupsdSetAuthInfoRequired(
1717 cupsd_printer_t
*p
, /* I - Printer */
1718 const char *values
, /* I - Plain text value (or NULL) */
1719 ipp_attribute_t
*attr
) /* I - IPP attribute value (or NULL) */
1721 int i
; /* Looping var */
1724 p
->num_auth_info_required
= 0;
1727 * Do we have a plain text value?
1733 * Yes, grab the keywords...
1736 const char *end
; /* End of current value */
1739 while (*values
&& p
->num_auth_info_required
< 4)
1741 if ((end
= strchr(values
, ',')) == NULL
)
1742 end
= values
+ strlen(values
);
1744 if ((end
- values
) == 4 && !strncmp(values
, "none", 4))
1746 if (p
->num_auth_info_required
!= 0 || *end
)
1749 p
->auth_info_required
[p
->num_auth_info_required
] = "none";
1750 p
->num_auth_info_required
++;
1754 else if ((end
- values
) == 9 && !strncmp(values
, "negotiate", 9))
1756 if (p
->num_auth_info_required
!= 0 || *end
)
1759 p
->auth_info_required
[p
->num_auth_info_required
] = "negotiate";
1760 p
->num_auth_info_required
++;
1762 else if ((end
- values
) == 6 && !strncmp(values
, "domain", 6))
1764 p
->auth_info_required
[p
->num_auth_info_required
] = "domain";
1765 p
->num_auth_info_required
++;
1767 else if ((end
- values
) == 8 && !strncmp(values
, "password", 8))
1769 p
->auth_info_required
[p
->num_auth_info_required
] = "password";
1770 p
->num_auth_info_required
++;
1772 else if ((end
- values
) == 8 && !strncmp(values
, "username", 8))
1774 p
->auth_info_required
[p
->num_auth_info_required
] = "username";
1775 p
->num_auth_info_required
++;
1780 values
= (*end
) ? end
+ 1 : end
;
1783 if (p
->num_auth_info_required
== 0)
1785 p
->auth_info_required
[0] = "none";
1786 p
->num_auth_info_required
= 1;
1790 * Update the printer-type value as needed...
1793 if (p
->num_auth_info_required
> 1 ||
1794 strcmp(p
->auth_info_required
[0], "none"))
1795 p
->type
|= CUPS_PRINTER_AUTHENTICATED
;
1797 p
->type
&= ~CUPS_PRINTER_AUTHENTICATED
;
1803 * Grab values from an attribute instead...
1806 if (!attr
|| attr
->num_values
> 4)
1810 * Update the printer-type value as needed...
1813 if (attr
->num_values
> 1 ||
1814 strcmp(attr
->values
[0].string
.text
, "none"))
1815 p
->type
|= CUPS_PRINTER_AUTHENTICATED
;
1817 p
->type
&= ~CUPS_PRINTER_AUTHENTICATED
;
1819 for (i
= 0; i
< attr
->num_values
; i
++)
1821 if (!strcmp(attr
->values
[i
].string
.text
, "none"))
1823 if (p
->num_auth_info_required
!= 0 || attr
->num_values
!= 1)
1826 p
->auth_info_required
[p
->num_auth_info_required
] = "none";
1827 p
->num_auth_info_required
++;
1831 else if (!strcmp(attr
->values
[i
].string
.text
, "negotiate"))
1833 if (p
->num_auth_info_required
!= 0 || attr
->num_values
!= 1)
1836 p
->auth_info_required
[p
->num_auth_info_required
] = "negotiate";
1837 p
->num_auth_info_required
++;
1841 else if (!strcmp(attr
->values
[i
].string
.text
, "domain"))
1843 p
->auth_info_required
[p
->num_auth_info_required
] = "domain";
1844 p
->num_auth_info_required
++;
1846 else if (!strcmp(attr
->values
[i
].string
.text
, "password"))
1848 p
->auth_info_required
[p
->num_auth_info_required
] = "password";
1849 p
->num_auth_info_required
++;
1851 else if (!strcmp(attr
->values
[i
].string
.text
, "username"))
1853 p
->auth_info_required
[p
->num_auth_info_required
] = "username";
1854 p
->num_auth_info_required
++;
1865 * 'cupsdSetDeviceURI()' - Set the device URI for a printer.
1869 cupsdSetDeviceURI(cupsd_printer_t
*p
, /* I - Printer */
1870 const char *uri
) /* I - Device URI */
1872 char buffer
[1024], /* URI buffer */
1873 *start
, /* Start of data after scheme */
1874 *slash
, /* First slash after scheme:// */
1875 *ptr
; /* Pointer into user@host:port part */
1879 * Set the full device URI..
1882 cupsdSetString(&(p
->device_uri
), uri
);
1885 * Copy the device URI to a temporary buffer so we can sanitize any auth
1889 strlcpy(buffer
, uri
, sizeof(buffer
));
1892 * Find the end of the scheme:// part...
1895 if ((ptr
= strchr(buffer
, ':')) != NULL
)
1897 for (start
= ptr
+ 1; *start
; start
++)
1902 * Find the next slash (/) in the URI...
1905 if ((slash
= strchr(start
, '/')) == NULL
)
1906 slash
= start
+ strlen(start
); /* No slash, point to the end */
1909 * Check for an @ sign before the slash...
1912 if ((ptr
= strchr(start
, '@')) != NULL
&& ptr
< slash
)
1915 * Found an @ sign and it is before the resource part, so we have
1916 * an authentication string. Copy the remaining URI over the
1917 * authentication string...
1920 _cups_strcpy(start
, ptr
+ 1);
1925 * Save the sanitized URI...
1928 cupsdSetString(&(p
->sanitized_device_uri
), buffer
);
1933 * 'cupsdSetPrinterAttr()' - Set a printer attribute.
1937 cupsdSetPrinterAttr(
1938 cupsd_printer_t
*p
, /* I - Printer */
1939 const char *name
, /* I - Attribute name */
1940 char *value
) /* I - Attribute value string */
1942 ipp_attribute_t
*attr
; /* Attribute */
1943 int i
, /* Looping var */
1944 count
; /* Number of values */
1945 char *ptr
; /* Pointer into value */
1946 ipp_tag_t value_tag
; /* Value tag for this attribute */
1950 * Don't allow empty values...
1953 if (!*value
&& strcmp(name
, "marker-message"))
1955 cupsdLogMessage(CUPSD_LOG_ERROR
, "Ignoring empty \"%s\" attribute", name
);
1960 * Count the number of values...
1963 for (count
= 1, ptr
= value
;
1964 (ptr
= strchr(ptr
, ',')) != NULL
;
1968 * Then add or update the attribute as needed...
1971 if (!strcmp(name
, "marker-levels") || !strcmp(name
, "marker-low-levels") ||
1972 !strcmp(name
, "marker-high-levels"))
1978 if ((attr
= ippFindAttribute(p
->attrs
, name
, IPP_TAG_INTEGER
)) != NULL
&&
1979 attr
->num_values
< count
)
1981 ippDeleteAttribute(p
->attrs
, attr
);
1986 attr
->num_values
= count
;
1988 attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
, name
,
1993 cupsdLogMessage(CUPSD_LOG_ERROR
,
1994 "Unable to allocate memory for printer attribute "
1995 "(%d values)", count
);
1999 for (i
= 0; i
< count
; i
++)
2001 if ((ptr
= strchr(value
, ',')) != NULL
)
2004 attr
->values
[i
].integer
= strtol(value
, NULL
, 10);
2013 * Name or keyword values...
2016 if (!strcmp(name
, "marker-types"))
2017 value_tag
= IPP_TAG_KEYWORD
;
2018 else if (!strcmp(name
, "marker-message"))
2019 value_tag
= IPP_TAG_TEXT
;
2021 value_tag
= IPP_TAG_NAME
;
2023 if ((attr
= ippFindAttribute(p
->attrs
, name
, value_tag
)) != NULL
&&
2024 attr
->num_values
< count
)
2026 ippDeleteAttribute(p
->attrs
, attr
);
2032 for (i
= 0; i
< attr
->num_values
; i
++)
2033 _cupsStrFree(attr
->values
[i
].string
.text
);
2035 attr
->num_values
= count
;
2038 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, value_tag
, name
,
2043 cupsdLogMessage(CUPSD_LOG_ERROR
,
2044 "Unable to allocate memory for printer attribute "
2045 "(%d values)", count
);
2049 for (i
= 0; i
< count
; i
++)
2051 if ((ptr
= strchr(value
, ',')) != NULL
)
2054 attr
->values
[i
].string
.text
= _cupsStrAlloc(value
);
2064 * 'cupsdSetPrinterAttrs()' - Set printer attributes based upon the PPD file.
2068 cupsdSetPrinterAttrs(cupsd_printer_t
*p
)/* I - Printer to setup */
2070 int i
, /* Looping var */
2071 length
; /* Length of browse attributes */
2072 char resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
2073 int num_air
; /* Number of auth-info-required values */
2074 const char * const *air
; /* auth-info-required values */
2075 cupsd_location_t
*auth
; /* Pointer to authentication element */
2076 const char *auth_supported
; /* Authentication supported */
2077 ipp_t
*oldattrs
; /* Old printer attributes */
2078 ipp_attribute_t
*attr
; /* Attribute data */
2079 cups_option_t
*option
; /* Current printer option */
2080 char *name
, /* Current user/group name */
2081 *filter
; /* Current filter */
2082 static const char * const air_none
[] =
2083 { /* No authentication */
2086 static const char * const air_userpass
[] =
2087 { /* Basic/Digest authentication */
2093 DEBUG_printf(("cupsdSetPrinterAttrs: entering name = %s, type = %x\n", p
->name
,
2097 * Make sure that we have the common attributes defined...
2101 cupsdCreateCommonData();
2104 * Clear out old filters, if any...
2107 delete_printer_filters(p
);
2110 * Figure out the authentication that is required for the printer.
2113 auth_supported
= "requesting-user-name";
2117 if (p
->num_auth_info_required
> 0 && strcmp(p
->auth_info_required
[0], "none"))
2119 num_air
= p
->num_auth_info_required
;
2120 air
= p
->auth_info_required
;
2122 else if ((p
->type
& CUPS_PRINTER_AUTHENTICATED
) &&
2123 (p
->type
& CUPS_PRINTER_DISCOVERED
))
2129 if (p
->type
& CUPS_PRINTER_CLASS
)
2130 snprintf(resource
, sizeof(resource
), "/classes/%s", p
->name
);
2132 snprintf(resource
, sizeof(resource
), "/printers/%s", p
->name
);
2134 if ((auth
= cupsdFindBest(resource
, HTTP_POST
)) == NULL
||
2135 auth
->type
== CUPSD_AUTH_NONE
)
2136 auth
= cupsdFindPolicyOp(p
->op_policy_ptr
, IPP_PRINT_JOB
);
2140 int auth_type
; /* Authentication type */
2143 if ((auth_type
= auth
->type
) == CUPSD_AUTH_DEFAULT
)
2144 auth_type
= DefaultAuthType
;
2146 if (auth_type
== CUPSD_AUTH_BASIC
|| auth_type
== CUPSD_AUTH_BASICDIGEST
)
2147 auth_supported
= "basic";
2148 else if (auth_type
== CUPSD_AUTH_DIGEST
)
2149 auth_supported
= "digest";
2151 else if (auth_type
== CUPSD_AUTH_NEGOTIATE
)
2152 auth_supported
= "negotiate";
2153 #endif /* HAVE_GSSAPI */
2155 if (!(p
->type
& CUPS_PRINTER_DISCOVERED
))
2157 if (auth_type
!= CUPSD_AUTH_NONE
)
2158 p
->type
|= CUPS_PRINTER_AUTHENTICATED
;
2160 p
->type
&= ~CUPS_PRINTER_AUTHENTICATED
;
2163 else if (!(p
->type
& CUPS_PRINTER_DISCOVERED
))
2164 p
->type
&= ~CUPS_PRINTER_AUTHENTICATED
;
2167 * Create the required IPP attributes for a printer...
2170 oldattrs
= p
->attrs
;
2171 p
->attrs
= ippNew();
2173 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2174 "uri-authentication-supported", NULL
, auth_supported
);
2175 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2176 "uri-security-supported", NULL
, "none");
2177 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
, "printer-name", NULL
,
2179 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-location",
2180 NULL
, p
->location
? p
->location
: "");
2181 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-info",
2182 NULL
, p
->info
? p
->info
: "");
2184 if (cupsArrayCount(p
->users
) > 0)
2187 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2188 "requesting-user-name-denied",
2189 cupsArrayCount(p
->users
), NULL
, NULL
);
2191 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2192 "requesting-user-name-allowed",
2193 cupsArrayCount(p
->users
), NULL
, NULL
);
2195 for (i
= 0, name
= (char *)cupsArrayFirst(p
->users
);
2197 i
++, name
= (char *)cupsArrayNext(p
->users
))
2198 attr
->values
[i
].string
.text
= _cupsStrRetain(name
);
2201 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2202 "job-quota-period", p
->quota_period
);
2203 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2204 "job-k-limit", p
->k_limit
);
2205 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2206 "job-page-limit", p
->page_limit
);
2207 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2208 "auth-info-required", num_air
, NULL
, air
);
2210 if (cupsArrayCount(Banners
) > 0 && !(p
->type
& CUPS_PRINTER_DISCOVERED
))
2213 * Setup the job-sheets-default attribute...
2216 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2217 "job-sheets-default", 2, NULL
, NULL
);
2221 attr
->values
[0].string
.text
= _cupsStrAlloc(Classification
?
2222 Classification
: p
->job_sheets
[0]);
2223 attr
->values
[1].string
.text
= _cupsStrAlloc(Classification
?
2224 Classification
: p
->job_sheets
[1]);
2231 if (p
->type
& CUPS_PRINTER_DISCOVERED
)
2234 * Tell the client this is a remote printer of some type...
2237 if (strchr(p
->uri
, '?'))
2240 * Strip trailing "?options" from URI...
2243 char *ptr
; /* Pointer into URI */
2245 strlcpy(resource
, p
->uri
, sizeof(resource
));
2246 if ((ptr
= strchr(resource
, '?')) != NULL
)
2249 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
2250 "printer-uri-supported", NULL
, resource
);
2253 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
2254 "printer-uri-supported", NULL
, p
->uri
);
2256 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "printer-more-info",
2260 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
2261 "printer-make-and-model", NULL
, p
->make_model
);
2263 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "device-uri", NULL
,
2272 * Assign additional attributes depending on whether this is a printer
2276 if (p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
))
2279 p
->type
&= ~CUPS_PRINTER_OPTIONS
;
2282 * Add class-specific attributes...
2285 if ((p
->type
& CUPS_PRINTER_IMPLICIT
) && p
->num_printers
> 0 &&
2286 p
->printers
[0]->make_model
)
2287 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
2288 "printer-make-and-model", NULL
, p
->printers
[0]->make_model
);
2290 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
2291 "printer-make-and-model", NULL
, "Local Printer Class");
2293 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "device-uri", NULL
,
2294 "file:///dev/null");
2296 if (p
->num_printers
> 0)
2299 * Add a list of member names; URIs are added in copy_printer_attrs...
2302 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2303 "member-names", p
->num_printers
, NULL
, NULL
);
2304 p
->type
|= CUPS_PRINTER_OPTIONS
;
2306 for (i
= 0; i
< p
->num_printers
; i
++)
2309 attr
->values
[i
].string
.text
= _cupsStrRetain(p
->printers
[i
]->name
);
2311 p
->type
&= ~CUPS_PRINTER_OPTIONS
| p
->printers
[i
]->type
;
2318 * Add printer-specific attributes...
2321 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "device-uri", NULL
,
2322 p
->sanitized_device_uri
);
2325 * Assign additional attributes from the PPD file (if any)...
2331 * Add filters for printer...
2334 cupsdSetPrinterReasons(p
, "-cups-missing-filter-warning,"
2335 "cups-insecure-filter-warning");
2337 if (p
->pc
&& p
->pc
->filters
)
2339 for (filter
= (char *)cupsArrayFirst(p
->pc
->filters
);
2341 filter
= (char *)cupsArrayNext(p
->pc
->filters
))
2342 add_printer_filter(p
, p
->filetype
, filter
);
2344 else if (!(p
->type
& CUPS_PRINTER_REMOTE
))
2346 char interface
[1024]; /* Interface script */
2349 snprintf(interface
, sizeof(interface
), "%s/interfaces/%s", ServerRoot
,
2351 if (!access(interface
, X_OK
))
2354 * Yes, we have a System V style interface script; use it!
2357 snprintf(interface
, sizeof(interface
), "*/* 0 %s/interfaces/%s",
2358 ServerRoot
, p
->name
);
2359 add_printer_filter(p
, p
->filetype
, interface
);
2364 * Add a filter from application/vnd.cups-raw to printer/name to
2365 * handle "raw" printing by users.
2368 add_printer_filter(p
, p
->filetype
, "application/vnd.cups-raw 0 -");
2371 * Add a PostScript filter, since this is still possibly PS printer.
2374 add_printer_filter(p
, p
->filetype
,
2375 "application/vnd.cups-postscript 0 -");
2379 if (p
->pc
&& p
->pc
->prefilters
)
2381 p
->prefiltertype
= mimeAddType(MimeDatabase
, "prefilter", p
->name
);
2383 for (filter
= (char *)cupsArrayFirst(p
->pc
->prefilters
);
2385 filter
= (char *)cupsArrayNext(p
->pc
->prefilters
))
2386 add_printer_filter(p
, p
->prefiltertype
, filter
);
2392 * Copy marker attributes as needed...
2397 ipp_attribute_t
*oldattr
; /* Old attribute */
2400 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-colors",
2401 IPP_TAG_NAME
)) != NULL
)
2403 if ((attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2404 "marker-colors", oldattr
->num_values
, NULL
,
2407 for (i
= 0; i
< oldattr
->num_values
; i
++)
2408 attr
->values
[i
].string
.text
=
2409 _cupsStrRetain(oldattr
->values
[i
].string
.text
);
2413 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-levels",
2414 IPP_TAG_INTEGER
)) != NULL
)
2416 if ((attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2417 "marker-levels", oldattr
->num_values
,
2420 for (i
= 0; i
< oldattr
->num_values
; i
++)
2421 attr
->values
[i
].integer
= oldattr
->values
[i
].integer
;
2425 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-message",
2426 IPP_TAG_TEXT
)) != NULL
)
2427 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "marker-message",
2428 NULL
, oldattr
->values
[0].string
.text
);
2430 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-low-levels",
2431 IPP_TAG_INTEGER
)) != NULL
)
2433 if ((attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2434 "marker-low-levels", oldattr
->num_values
,
2437 for (i
= 0; i
< oldattr
->num_values
; i
++)
2438 attr
->values
[i
].integer
= oldattr
->values
[i
].integer
;
2442 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-high-levels",
2443 IPP_TAG_INTEGER
)) != NULL
)
2445 if ((attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2446 "marker-high-levels", oldattr
->num_values
,
2449 for (i
= 0; i
< oldattr
->num_values
; i
++)
2450 attr
->values
[i
].integer
= oldattr
->values
[i
].integer
;
2454 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-names",
2455 IPP_TAG_NAME
)) != NULL
)
2457 if ((attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2458 "marker-names", oldattr
->num_values
, NULL
,
2461 for (i
= 0; i
< oldattr
->num_values
; i
++)
2462 attr
->values
[i
].string
.text
=
2463 _cupsStrRetain(oldattr
->values
[i
].string
.text
);
2467 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-types",
2468 IPP_TAG_KEYWORD
)) != NULL
)
2470 if ((attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2471 "marker-types", oldattr
->num_values
, NULL
,
2474 for (i
= 0; i
< oldattr
->num_values
; i
++)
2475 attr
->values
[i
].string
.text
=
2476 _cupsStrRetain(oldattr
->values
[i
].string
.text
);
2480 ippDelete(oldattrs
);
2484 * Force sharing off for remote queues...
2487 if (p
->type
& (CUPS_PRINTER_REMOTE
| CUPS_PRINTER_IMPLICIT
))
2492 * Copy the printer options into a browse attributes string we can re-use.
2495 const char *valptr
; /* Pointer into value */
2496 char *attrptr
; /* Pointer into attribute string */
2500 * Free the old browse attributes as needed...
2503 if (p
->browse_attrs
)
2504 free(p
->browse_attrs
);
2507 * Compute the length of all attributes + job-sheets, lease-duration,
2508 * and BrowseLocalOptions.
2511 for (length
= 1, i
= p
->num_options
, option
= p
->options
;
2515 length
+= strlen(option
->name
) + 2;
2519 for (valptr
= option
->value
; *valptr
; valptr
++)
2520 if (strchr(" \"\'\\", *valptr
))
2527 length
+= 13 + strlen(p
->job_sheets
[0]) + strlen(p
->job_sheets
[1]);
2529 if (BrowseLocalOptions
)
2530 length
+= 12 + strlen(BrowseLocalOptions
);
2533 * Allocate the new string...
2536 if ((p
->browse_attrs
= calloc(1, length
)) == NULL
)
2537 cupsdLogMessage(CUPSD_LOG_ERROR
,
2538 "Unable to allocate %d bytes for browse data!",
2543 * Got the allocated string, now copy the options and attributes over...
2546 sprintf(p
->browse_attrs
, "job-sheets=%s,%s lease-duration=%d",
2547 p
->job_sheets
[0], p
->job_sheets
[1], BrowseTimeout
);
2548 attrptr
= p
->browse_attrs
+ strlen(p
->browse_attrs
);
2550 if (BrowseLocalOptions
)
2552 sprintf(attrptr
, " ipp-options=%s", BrowseLocalOptions
);
2553 attrptr
+= strlen(attrptr
);
2556 for (i
= p
->num_options
, option
= p
->options
;
2561 strcpy(attrptr
, option
->name
);
2562 attrptr
+= strlen(attrptr
);
2568 for (valptr
= option
->value
; *valptr
; valptr
++)
2570 if (strchr(" \"\'\\", *valptr
))
2573 *attrptr
++ = *valptr
;
2581 * Populate the document-format-supported attribute...
2584 add_printer_formats(p
);
2586 DEBUG_printf(("cupsdSetPrinterAttrs: leaving name = %s, type = %x\n", p
->name
,
2590 * Add name-default attributes...
2593 add_printer_defaults(p
);
2597 * Write the IRIX printer config and status files...
2600 write_irix_config(p
);
2601 write_irix_state(p
);
2605 * Let the browse protocols reflect the change
2608 cupsdRegisterPrinter(p
);
2613 * 'cupsdSetPrinterReasons()' - Set/update the reasons strings.
2616 int /* O - 1 if something changed, 0 otherwise */
2617 cupsdSetPrinterReasons(
2618 cupsd_printer_t
*p
, /* I - Printer */
2619 const char *s
) /* I - Reasons strings */
2621 int i
, /* Looping var */
2622 changed
= 0; /* Did something change? */
2623 const char *sptr
; /* Pointer into reasons */
2624 char reason
[255], /* Reason string */
2625 *rptr
; /* Pointer into reason */
2628 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
2629 "cupsdSetPrinterReasons(p=%p(%s),s=\"%s\"", p
, p
->name
, s
);
2631 if (s
[0] == '-' || s
[0] == '+')
2634 * Add/remove reasons...
2642 * Replace reasons...
2647 for (i
= 0; i
< p
->num_reasons
; i
++)
2648 _cupsStrFree(p
->reasons
[i
]);
2656 if (!strcmp(s
, "none"))
2660 * Loop through all of the reasons...
2666 * Skip leading whitespace and commas...
2669 while (isspace(*sptr
& 255) || *sptr
== ',')
2672 for (rptr
= reason
; *sptr
&& !isspace(*sptr
& 255) && *sptr
!= ','; sptr
++)
2673 if (rptr
< (reason
+ sizeof(reason
) - 1))
2687 for (i
= 0; i
< p
->num_reasons
; i
++)
2688 if (!strcmp(reason
, p
->reasons
[i
]))
2691 * Found a match, so remove it...
2696 _cupsStrFree(p
->reasons
[i
]);
2698 if (i
< p
->num_reasons
)
2699 memmove(p
->reasons
+ i
, p
->reasons
+ i
+ 1,
2700 (p
->num_reasons
- i
) * sizeof(char *));
2702 if (!strcmp(reason
, "paused") && p
->state
== IPP_PRINTER_STOPPED
)
2703 cupsdSetPrinterState(p
, IPP_PRINTER_IDLE
, 1);
2705 if (strcmp(reason
, "connecting-to-device"))
2710 else if (p
->num_reasons
< (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
2716 for (i
= 0; i
< p
->num_reasons
; i
++)
2717 if (!strcmp(reason
, p
->reasons
[i
]))
2720 if (i
>= p
->num_reasons
)
2722 if (i
>= (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
2724 cupsdLogMessage(CUPSD_LOG_ALERT
,
2725 "Too many printer-state-reasons values for %s (%d)",
2730 p
->reasons
[i
] = _cupsStrAlloc(reason
);
2734 if (!strcmp(reason
, "paused") && p
->state
!= IPP_PRINTER_STOPPED
)
2735 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, 1);
2737 if (strcmp(reason
, "connecting-to-device"))
2748 * 'cupsdSetPrinterState()' - Update the current state of a printer.
2752 cupsdSetPrinterState(
2753 cupsd_printer_t
*p
, /* I - Printer to change */
2754 ipp_pstate_t s
, /* I - New state */
2755 int update
) /* I - Update printers.conf? */
2757 ipp_pstate_t old_state
; /* Old printer state */
2758 static const char * const printer_states
[] =
2759 { /* State strings */
2767 * Can't set status of remote printers...
2770 if (p
->type
& CUPS_PRINTER_DISCOVERED
)
2774 * Set the new state...
2777 old_state
= p
->state
;
2782 cupsdAddEvent(s
== IPP_PRINTER_STOPPED
? CUPSD_EVENT_PRINTER_STOPPED
:
2783 CUPSD_EVENT_PRINTER_STATE
, p
, NULL
,
2784 "%s \"%s\" state changed to %s.",
2785 (p
->type
& CUPS_PRINTER_CLASS
) ? "Class" : "Printer",
2786 p
->name
, printer_states
[p
->state
- IPP_PRINTER_IDLE
]);
2789 * Let the browse code know this needs to be updated...
2793 p
->state_time
= time(NULL
);
2797 write_irix_state(p
);
2802 * Set/clear the paused reason as needed...
2805 if (s
== IPP_PRINTER_STOPPED
)
2806 cupsdSetPrinterReasons(p
, "+paused");
2808 cupsdSetPrinterReasons(p
, "-paused");
2811 * Clear the message for the queue when going to processing...
2814 if (s
== IPP_PRINTER_PROCESSING
)
2815 p
->state_message
[0] = '\0';
2818 * Let the browse protocols reflect the change...
2822 cupsdRegisterPrinter(p
);
2825 * Save the printer configuration if a printer goes from idle or processing
2826 * to stopped (or visa-versa)...
2830 (old_state
== IPP_PRINTER_STOPPED
) != (s
== IPP_PRINTER_STOPPED
))
2836 * 'cupsdStopPrinter()' - Stop a printer from printing any jobs...
2840 cupsdStopPrinter(cupsd_printer_t
*p
, /* I - Printer to stop */
2841 int update
)/* I - Update printers.conf? */
2844 * Set the printer state...
2847 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, update
);
2850 * See if we have a job printing on this printer...
2853 if (p
->job
&& p
->job
->state_value
== IPP_JOB_PROCESSING
)
2854 cupsdSetJobState(p
->job
, IPP_JOB_PENDING
, CUPSD_JOB_DEFAULT
,
2855 "Job stopped due to printer being paused.");
2860 * 'cupsdUpdatePrinterPPD()' - Update keywords in a printer's PPD file.
2863 int /* O - 1 if successful, 0 otherwise */
2864 cupsdUpdatePrinterPPD(
2865 cupsd_printer_t
*p
, /* I - Printer */
2866 int num_keywords
, /* I - Number of keywords */
2867 cups_option_t
*keywords
) /* I - Keywords */
2869 int i
; /* Looping var */
2870 cups_file_t
*src
, /* Original file */
2871 *dst
; /* New file */
2872 char srcfile
[1024], /* Original filename */
2873 dstfile
[1024], /* New filename */
2874 line
[1024], /* Line from file */
2875 keystring
[41]; /* Keyword from line */
2876 cups_option_t
*keyword
; /* Current keyword */
2879 cupsdLogMessage(CUPSD_LOG_INFO
, "Updating keywords in PPD file for %s...",
2883 * Get the old and new PPD filenames...
2886 snprintf(srcfile
, sizeof(srcfile
), "%s/ppd/%s.ppd.O", ServerRoot
, p
->name
);
2887 snprintf(dstfile
, sizeof(srcfile
), "%s/ppd/%s.ppd", ServerRoot
, p
->name
);
2890 * Rename the old file and open the old and new...
2893 if (rename(dstfile
, srcfile
))
2895 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to backup PPD file for %s: %s",
2896 p
->name
, strerror(errno
));
2900 if ((src
= cupsFileOpen(srcfile
, "r")) == NULL
)
2902 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to open PPD file \"%s\": %s",
2903 srcfile
, strerror(errno
));
2904 rename(srcfile
, dstfile
);
2908 if ((dst
= cupsFileOpen(dstfile
, "w")) == NULL
)
2910 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to create PPD file \"%s\": %s",
2911 dstfile
, strerror(errno
));
2913 rename(srcfile
, dstfile
);
2918 * Copy the first line and then write out all of the keywords...
2921 if (!cupsFileGets(src
, line
, sizeof(line
)))
2923 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to read PPD file \"%s\": %s",
2924 srcfile
, strerror(errno
));
2927 rename(srcfile
, dstfile
);
2931 cupsFilePrintf(dst
, "%s\n", line
);
2933 for (i
= num_keywords
, keyword
= keywords
; i
> 0; i
--, keyword
++)
2935 cupsdLogMessage(CUPSD_LOG_DEBUG
, "*%s: %s", keyword
->name
, keyword
->value
);
2936 cupsFilePrintf(dst
, "*%s: %s\n", keyword
->name
, keyword
->value
);
2940 * Then copy the rest of the PPD file, dropping any keywords we changed.
2943 while (cupsFileGets(src
, line
, sizeof(line
)))
2946 * Skip keywords we've already set...
2949 if (sscanf(line
, "*%40[^:]:", keystring
) == 1 &&
2950 cupsGetOption(keystring
, num_keywords
, keywords
))
2954 * Otherwise write the line...
2957 cupsFilePrintf(dst
, "%s\n", line
);
2961 * Close files and return...
2972 * 'cupsdUpdatePrinters()' - Update printers after a partial reload.
2976 cupsdUpdatePrinters(void)
2978 cupsd_printer_t
*p
; /* Current printer */
2982 * Loop through the printers and recreate the printer attributes
2983 * for any local printers since the policy and/or access control
2984 * stuff may have changed. Also, if browsing is disabled, remove
2985 * any remote printers...
2988 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
2990 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
2993 * Remove remote printers if we are no longer browsing...
2997 (p
->type
& (CUPS_PRINTER_IMPLICIT
| CUPS_PRINTER_DISCOVERED
)))
2999 if (p
->type
& CUPS_PRINTER_IMPLICIT
)
3000 cupsArrayRemove(ImplicitPrinters
, p
);
3002 cupsArraySave(Printers
);
3003 cupsdDeletePrinter(p
, 0);
3004 cupsArrayRestore(Printers
);
3009 * Update the operation policy pointer...
3012 if ((p
->op_policy_ptr
= cupsdFindPolicy(p
->op_policy
)) == NULL
)
3013 p
->op_policy_ptr
= DefaultPolicyPtr
;
3016 * Update printer attributes as needed...
3019 if (!(p
->type
& CUPS_PRINTER_DISCOVERED
))
3020 cupsdSetPrinterAttrs(p
);
3026 * 'cupsdValidateDest()' - Validate a printer/class destination.
3029 const char * /* O - Printer or class name */
3031 const char *uri
, /* I - Printer URI */
3032 cups_ptype_t
*dtype
, /* O - Type (printer or class) */
3033 cupsd_printer_t
**printer
) /* O - Printer pointer */
3035 cupsd_printer_t
*p
; /* Current printer */
3036 char localname
[1024],/* Localized hostname */
3037 *lptr
, /* Pointer into localized hostname */
3038 *sptr
, /* Pointer into server name */
3039 *rptr
, /* Pointer into resource */
3040 scheme
[32], /* Scheme portion of URI */
3041 username
[64], /* Username portion of URI */
3042 hostname
[HTTP_MAX_HOST
],
3043 /* Host portion of URI */
3044 resource
[HTTP_MAX_URI
];
3045 /* Resource portion of URI */
3046 int port
; /* Port portion of URI */
3049 DEBUG_printf(("cupsdValidateDest(uri=\"%s\", dtype=%p, printer=%p)\n", uri
,
3053 * Initialize return values...
3060 *dtype
= (cups_ptype_t
)0;
3063 * Pull the hostname and resource from the URI...
3066 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
, scheme
, sizeof(scheme
),
3067 username
, sizeof(username
), hostname
, sizeof(hostname
),
3068 &port
, resource
, sizeof(resource
));
3071 * See if the resource is a class or printer...
3074 if (!strncmp(resource
, "/classes/", 9))
3080 rptr
= resource
+ 9;
3082 else if (!strncmp(resource
, "/printers/", 10))
3088 rptr
= resource
+ 10;
3093 * Bad resource name...
3100 * See if the printer or class name exists...
3103 p
= cupsdFindDest(rptr
);
3105 if (p
== NULL
&& strchr(rptr
, '@') == NULL
)
3113 *dtype
= p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
|
3114 CUPS_PRINTER_REMOTE
| CUPS_PRINTER_DISCOVERED
);
3120 * Change localhost to the server name...
3123 if (!strcasecmp(hostname
, "localhost"))
3124 strlcpy(hostname
, ServerName
, sizeof(hostname
));
3126 strlcpy(localname
, hostname
, sizeof(localname
));
3128 if (!strcasecmp(hostname
, ServerName
))
3131 * Localize the hostname...
3134 lptr
= strchr(localname
, '.');
3135 sptr
= strchr(ServerName
, '.');
3137 if (sptr
!= NULL
&& lptr
!= NULL
)
3140 * Strip the common domain name components...
3143 while (lptr
!= NULL
)
3145 if (!strcasecmp(lptr
, sptr
))
3151 lptr
= strchr(lptr
+ 1, '.');
3156 DEBUG_printf(("localized hostname is \"%s\"...\n", localname
));
3159 * Find a matching printer or class...
3162 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3164 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3165 if (!strcasecmp(p
->hostname
, localname
) &&
3166 !strcasecmp(p
->name
, rptr
))
3172 *dtype
= p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
|
3173 CUPS_PRINTER_REMOTE
| CUPS_PRINTER_DISCOVERED
);
3183 * 'cupsdWritePrintcap()' - Write a pseudo-printcap file for older applications
3188 cupsdWritePrintcap(void)
3190 int i
; /* Looping var */
3191 cups_file_t
*fp
; /* Printcap file */
3192 cupsd_printer_t
*p
; /* Current printer */
3197 * Update the IRIX printer state for the default printer; if
3198 * no printers remain, then the default printer file will be
3202 write_irix_state(DefaultPrinter
);
3206 * See if we have a printcap file; if not, don't bother writing it.
3209 if (!Printcap
|| !*Printcap
)
3212 cupsdLogMessage(CUPSD_LOG_INFO
, "Generating printcap %s...", Printcap
);
3215 * Open the printcap file...
3218 if ((fp
= cupsFileOpen(Printcap
, "w")) == NULL
)
3222 * Put a comment header at the top so that users will know where the
3223 * data has come from...
3226 if (PrintcapFormat
!= PRINTCAP_PLIST
)
3227 cupsFilePrintf(fp
, "# This file was automatically generated by cupsd(8) "
3229 "# %s/printers.conf file. All changes to this file\n"
3230 "# will be lost.\n", ServerRoot
);
3233 * Write a new printcap with the current list of printers.
3236 switch (PrintcapFormat
)
3240 * Each printer is put in the file as:
3250 cupsFilePrintf(fp
, "%s|%s:rm=%s:rp=%s:\n", DefaultPrinter
->name
,
3251 DefaultPrinter
->info
, ServerName
,
3252 DefaultPrinter
->name
);
3254 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3256 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3257 if (p
!= DefaultPrinter
)
3258 cupsFilePrintf(fp
, "%s|%s:rm=%s:rp=%s:\n", p
->name
, p
->info
,
3259 ServerName
, p
->name
);
3262 case PRINTCAP_PLIST
:
3264 * Each printer is written as a dictionary in a plist file.
3265 * Currently the printer-name, printer-info, printer-is-accepting-jobs,
3266 * printer-location, printer-make-and-model, printer-state,
3267 * printer-state-reasons, printer-type, and (sanitized) device-uri.
3270 cupsFilePuts(fp
, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
3271 "<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD "
3272 "PLIST 1.0//EN\" \"http://www.apple.com/DTDs/"
3273 "PropertyList-1.0.dtd\">\n"
3274 "<plist version=\"1.0\">\n"
3277 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3279 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3281 cupsFilePuts(fp
, "\t<dict>\n"
3282 "\t\t<key>printer-name</key>\n"
3284 write_xml_string(fp
, p
->name
);
3285 cupsFilePuts(fp
, "</string>\n"
3286 "\t\t<key>printer-info</key>\n"
3288 write_xml_string(fp
, p
->info
);
3289 cupsFilePrintf(fp
, "</string>\n"
3290 "\t\t<key>printer-is-accepting-jobs</key>\n"
3292 "\t\t<key>printer-location</key>\n"
3293 "\t\t<string>", p
->accepting
? "true" : "false");
3294 write_xml_string(fp
, p
->location
);
3295 cupsFilePuts(fp
, "</string>\n"
3296 "\t\t<key>printer-make-and-model</key>\n"
3298 write_xml_string(fp
, p
->make_model
);
3299 cupsFilePrintf(fp
, "</string>\n"
3300 "\t\t<key>printer-state</key>\n"
3301 "\t\t<integer>%d</integer>\n"
3302 "\t\t<key>printer-state-reasons</key>\n"
3303 "\t\t<array>\n", p
->state
);
3304 for (i
= 0; i
< p
->num_reasons
; i
++)
3306 cupsFilePuts(fp
, "\t\t\t<string>");
3307 write_xml_string(fp
, p
->reasons
[i
]);
3308 cupsFilePuts(fp
, "</string>\n");
3310 cupsFilePrintf(fp
, "\t\t</array>\n"
3311 "\t\t<key>printer-type</key>\n"
3312 "\t\t<integer>%d</integer>\n"
3313 "\t\t<key>device-uri</key>\n"
3314 "\t\t<string>", p
->type
);
3315 write_xml_string(fp
, p
->sanitized_device_uri
);
3316 cupsFilePuts(fp
, "</string>\n"
3319 cupsFilePuts(fp
, "</array>\n"
3323 case PRINTCAP_SOLARIS
:
3325 * Each printer is put in the file as:
3327 * _all:all=Printer1,Printer2,Printer3,...,PrinterN
3328 * _default:use=DefaultPrinter
3330 * :bsdaddr=ServerName,Printer1:\
3331 * :description=Description:
3333 * :bsdaddr=ServerName,Printer2:\
3334 * :description=Description:
3336 * :bsdaddr=ServerName,Printer3:\
3337 * :description=Description:
3340 * :bsdaddr=ServerName,PrinterN:\
3341 * :description=Description:
3344 cupsFilePuts(fp
, "_all:all=");
3345 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3347 p
= (cupsd_printer_t
*)cupsArrayCurrent(Printers
))
3348 cupsFilePrintf(fp
, "%s%c", p
->name
,
3349 cupsArrayNext(Printers
) ? ',' : '\n');
3352 cupsFilePrintf(fp
, "_default:use=%s\n", DefaultPrinter
->name
);
3354 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3356 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3357 cupsFilePrintf(fp
, "%s:\\\n"
3358 "\t:bsdaddr=%s,%s:\\\n"
3359 "\t:description=%s:\n",
3360 p
->name
, ServerName
, p
->name
,
3361 p
->info
? p
->info
: "");
3374 * 'add_printer_defaults()' - Add name-default attributes to the printer attributes.
3378 add_printer_defaults(cupsd_printer_t
*p
)/* I - Printer */
3380 int i
; /* Looping var */
3381 int num_options
; /* Number of default options */
3382 cups_option_t
*options
, /* Default options */
3383 *option
; /* Current option */
3384 char name
[256]; /* name-default */
3388 * Maintain a common array of default attribute names...
3391 if (!CommonDefaults
)
3393 CommonDefaults
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
3395 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("copies-default"));
3396 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("document-format-default"));
3397 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("finishings-default"));
3398 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-hold-until-default"));
3399 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-priority-default"));
3400 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-sheets-default"));
3401 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("media-col-default"));
3402 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("number-up-default"));
3403 cupsArrayAdd(CommonDefaults
,
3404 _cupsStrAlloc("orientation-requested-default"));
3408 * Add all of the default options from the .conf files...
3411 for (num_options
= 0, options
= NULL
, i
= p
->num_options
, option
= p
->options
;
3415 if (strcmp(option
->name
, "ipp-options") &&
3416 strcmp(option
->name
, "job-sheets") &&
3417 strcmp(option
->name
, "lease-duration"))
3419 snprintf(name
, sizeof(name
), "%s-default", option
->name
);
3420 num_options
= cupsAddOption(name
, option
->value
, num_options
, &options
);
3422 if (!cupsArrayFind(CommonDefaults
, name
))
3423 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc(name
));
3428 * Convert options to IPP attributes...
3431 cupsEncodeOptions2(p
->attrs
, num_options
, options
, IPP_TAG_PRINTER
);
3432 cupsFreeOptions(num_options
, options
);
3435 * Add standard -default attributes as needed...
3438 if (!cupsGetOption("copies", p
->num_options
, p
->options
))
3439 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
, "copies-default",
3442 if (!cupsGetOption("document-format", p
->num_options
, p
->options
))
3443 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_MIMETYPE
,
3444 "document-format-default", NULL
, "application/octet-stream");
3446 if (!cupsGetOption("job-hold-until", p
->num_options
, p
->options
))
3447 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3448 "job-hold-until-default", NULL
, "no-hold");
3450 if (!cupsGetOption("job-priority", p
->num_options
, p
->options
))
3451 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3452 "job-priority-default", 50);
3454 if (!cupsGetOption("number-up", p
->num_options
, p
->options
))
3455 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3456 "number-up-default", 1);
3458 if (!cupsGetOption("notify-lease-duration", p
->num_options
, p
->options
))
3459 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3460 "notify-lease-duration-default", DefaultLeaseDuration
);
3462 if (!cupsGetOption("notify-events", p
->num_options
, p
->options
))
3463 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3464 "notify-events-default", NULL
, "job-completed");
3466 if (!cupsGetOption("orientation-requested", p
->num_options
, p
->options
))
3467 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NOVALUE
,
3468 "orientation-requested-default", NULL
, NULL
);
3470 if (!cupsGetOption("print-quality", p
->num_options
, p
->options
))
3471 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
3472 "print-quality-default", IPP_QUALITY_NORMAL
);
3477 * 'add_printer_filter()' - Add a MIME filter for a printer.
3482 cupsd_printer_t
*p
, /* I - Printer to add to */
3483 mime_type_t
*filtertype
, /* I - Filter or prefilter MIME type */
3484 const char *filter
) /* I - Filter to add */
3486 char super
[MIME_MAX_SUPER
], /* Super-type for filter */
3487 type
[MIME_MAX_TYPE
], /* Type for filter */
3488 dsuper
[MIME_MAX_SUPER
], /* Destination super-type for filter */
3489 dtype
[MIME_MAX_TYPE
], /* Destination type for filter */
3490 dest
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2],
3491 /* Destination super/type */
3492 program
[1024]; /* Program/filter name */
3493 int cost
; /* Cost of filter */
3494 mime_type_t
*temptype
, /* MIME type looping var */
3495 *desttype
; /* Destination MIME type */
3496 char filename
[1024], /* Full filter filename */
3497 *dirsep
; /* Pointer to directory separator */
3498 struct stat fileinfo
; /* File information */
3501 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3502 "add_printer_filter(p=%p(%s), filtertype=%p(%s/%s), "
3503 "filter=\"%s\")", p
, p
->name
, filtertype
, filtertype
->super
,
3504 filtertype
->type
, filter
);
3507 * Parse the filter string; it should be in one of the following formats:
3509 * source/type cost program
3510 * source/type dest/type cost program
3513 if (sscanf(filter
, "%15[^/]/%255s%*[ \t]%15[^/]/%255s%d%*[ \t]%1023[^\n]",
3514 super
, type
, dsuper
, dtype
, &cost
, program
) == 6)
3516 snprintf(dest
, sizeof(dest
), "%s/%s/%s", p
->name
, dsuper
, dtype
);
3518 if ((desttype
= mimeType(MimeDatabase
, "printer", dest
)) == NULL
)
3520 desttype
= mimeAddType(MimeDatabase
, "printer", dest
);
3522 p
->dest_types
= cupsArrayNew(NULL
, NULL
);
3524 cupsArrayAdd(p
->dest_types
, desttype
);
3530 if (sscanf(filter
, "%15[^/]/%255s%d%*[ \t]%1023[^\n]", super
, type
, &cost
,
3533 desttype
= filtertype
;
3537 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: invalid filter string \"%s\"!",
3544 * See if the filter program exists; if not, stop the printer and flag
3548 if (strcmp(program
, "-"))
3550 if (program
[0] == '/')
3551 strlcpy(filename
, program
, sizeof(filename
));
3553 snprintf(filename
, sizeof(filename
), "%s/filter/%s", ServerBin
, program
);
3555 if (stat(filename
, &fileinfo
))
3557 memset(&fileinfo
, 0, sizeof(fileinfo
));
3559 snprintf(p
->state_message
, sizeof(p
->state_message
),
3560 "Printer driver \"%s\" not available: %s", filename
,
3562 cupsdSetPrinterReasons(p
, "+cups-missing-filter-warning");
3564 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: %s", p
->name
, p
->state_message
);
3568 * When running as root, do additional security checks...
3574 * Only use filters that are owned by root and do not have world write
3578 if (fileinfo
.st_uid
||
3579 (fileinfo
.st_mode
& (S_ISUID
| S_IWGRP
| S_IWOTH
)) != 0)
3581 snprintf(p
->state_message
, sizeof(p
->state_message
),
3582 "Printer driver \"%s\" has insecure permissions (%d/0%o).",
3583 filename
, (int)fileinfo
.st_uid
, fileinfo
.st_mode
);
3585 cupsdSetPrinterReasons(p
, "+cups-insecure-filter-warning");
3587 cupsdLogMessage(CUPSD_LOG_WARN
, "%s: %s", p
->name
, p
->state_message
);
3589 else if (fileinfo
.st_mode
)
3592 * Similarly, check that the parent directory is also owned by root and
3593 * does not have world write permissions.
3596 if ((dirsep
= strrchr(filename
, '/')) != NULL
)
3599 if (!stat(filename
, &fileinfo
) &&
3601 (fileinfo
.st_mode
& (S_ISUID
| S_IWOTH
)) != 0))
3603 snprintf(p
->state_message
, sizeof(p
->state_message
),
3604 "Printer driver directory \"%s\" has insecure permissions "
3605 "(%d/0%o).", filename
, (int)fileinfo
.st_uid
,
3608 cupsdSetPrinterReasons(p
, "+cups-insecure-filter-warning");
3610 cupsdLogMessage(CUPSD_LOG_WARN
, "%s: %s", p
->name
, p
->state_message
);
3617 * Add the filter to the MIME database, supporting wildcards as needed...
3620 for (temptype
= mimeFirstType(MimeDatabase
);
3622 temptype
= mimeNextType(MimeDatabase
))
3623 if (((super
[0] == '*' && strcasecmp(temptype
->super
, "printer")) ||
3624 !strcasecmp(temptype
->super
, super
)) &&
3625 (type
[0] == '*' || !strcasecmp(temptype
->type
, type
)))
3627 if (desttype
!= filtertype
)
3629 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3630 "add_printer_filter: %s: adding filter %s/%s %s/%s %d "
3631 "%s", p
->name
, temptype
->super
, temptype
->type
,
3632 desttype
->super
, desttype
->type
,
3634 mimeAddFilter(MimeDatabase
, temptype
, desttype
, cost
, program
);
3636 if (!mimeFilterLookup(MimeDatabase
, desttype
, filtertype
))
3638 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3639 "add_printer_filter: %s: adding filter %s/%s %s/%s "
3640 "0 -", p
->name
, desttype
->super
, desttype
->type
,
3641 filtertype
->super
, filtertype
->type
);
3642 mimeAddFilter(MimeDatabase
, desttype
, filtertype
, cost
, "-");
3647 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3648 "add_printer_filter: %s: adding filter %s/%s %s/%s %d "
3649 "%s", p
->name
, temptype
->super
, temptype
->type
,
3650 filtertype
->super
, filtertype
->type
,
3652 mimeAddFilter(MimeDatabase
, temptype
, filtertype
, cost
, program
);
3659 * 'add_printer_formats()' - Add document-format-supported values for a printer.
3663 add_printer_formats(cupsd_printer_t
*p
) /* I - Printer */
3665 int i
; /* Looping var */
3666 mime_type_t
*type
; /* Current MIME type */
3667 cups_array_t
*filters
; /* Filters */
3668 ipp_attribute_t
*attr
; /* document-format-supported attribute */
3669 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
3670 /* MIME type name */
3674 * Raw (and remote) queues advertise all of the supported MIME
3678 cupsArrayDelete(p
->filetypes
);
3679 p
->filetypes
= NULL
;
3683 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
,
3684 (ipp_tag_t
)(IPP_TAG_MIMETYPE
| IPP_TAG_COPY
),
3685 "document-format-supported", NumMimeTypes
, NULL
, MimeTypes
);
3690 * Otherwise, loop through the supported MIME types and see if there
3691 * are filters for them...
3694 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_printer_formats: %d types, %d filters",
3695 mimeNumTypes(MimeDatabase
), mimeNumFilters(MimeDatabase
));
3697 p
->filetypes
= cupsArrayNew(NULL
, NULL
);
3699 for (type
= mimeFirstType(MimeDatabase
);
3701 type
= mimeNextType(MimeDatabase
))
3703 if (!strcasecmp(type
->super
, "printer"))
3706 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
3708 if ((filters
= mimeFilter(MimeDatabase
, type
, p
->filetype
, NULL
)) != NULL
)
3710 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3711 "add_printer_formats: %s: %s needs %d filters",
3712 p
->name
, mimetype
, cupsArrayCount(filters
));
3714 cupsArrayDelete(filters
);
3715 cupsArrayAdd(p
->filetypes
, type
);
3718 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3719 "add_printer_formats: %s: %s not supported",
3724 * Add the file formats that can be filtered...
3727 if ((type
= mimeType(MimeDatabase
, "application", "octet-stream")) == NULL
||
3728 !cupsArrayFind(p
->filetypes
, type
))
3733 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3734 "add_printer_formats: %s: %d supported types",
3735 p
->name
, cupsArrayCount(p
->filetypes
) + i
);
3737 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_MIMETYPE
,
3738 "document-format-supported",
3739 cupsArrayCount(p
->filetypes
) + i
, NULL
, NULL
);
3742 attr
->values
[0].string
.text
= _cupsStrAlloc("application/octet-stream");
3744 for (type
= (mime_type_t
*)cupsArrayFirst(p
->filetypes
);
3746 i
++, type
= (mime_type_t
*)cupsArrayNext(p
->filetypes
))
3748 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
3750 attr
->values
[i
].string
.text
= _cupsStrAlloc(mimetype
);
3755 char pdl
[1024]; /* Buffer to build pdl list */
3756 mime_filter_t
*filter
; /* MIME filter looping var */
3760 * We only support raw printing if this is not a Tioga PrintJobMgr based
3761 * queue and if application/octet-stream is a known type...
3764 for (filter
= (mime_filter_t
*)cupsArrayFirst(MimeDatabase
->filters
);
3766 filter
= (mime_filter_t
*)cupsArrayNext(MimeDatabase
->filters
))
3768 if (filter
->dst
== p
->filetype
&& filter
->filter
&&
3769 strstr(filter
->filter
, "PrintJobMgr"))
3775 if (!filter
&& mimeType(MimeDatabase
, "application", "octet-stream"))
3776 strlcat(pdl
, "application/octet-stream,", sizeof(pdl
));
3779 * Then list a bunch of formats that are supported by the printer...
3782 for (type
= (mime_type_t
*)cupsArrayFirst(p
->filetypes
);
3784 type
= (mime_type_t
*)cupsArrayNext(p
->filetypes
))
3786 if (!strcasecmp(type
->super
, "application"))
3788 if (!strcasecmp(type
->type
, "pdf"))
3789 strlcat(pdl
, "application/pdf,", sizeof(pdl
));
3790 else if (!strcasecmp(type
->type
, "postscript"))
3791 strlcat(pdl
, "application/postscript,", sizeof(pdl
));
3793 else if (!strcasecmp(type
->super
, "image"))
3795 if (!strcasecmp(type
->type
, "jpeg"))
3796 strlcat(pdl
, "image/jpeg,", sizeof(pdl
));
3797 else if (!strcasecmp(type
->type
, "png"))
3798 strlcat(pdl
, "image/png,", sizeof(pdl
));
3799 else if (!strcasecmp(type
->type
, "pwg-raster"))
3800 strlcat(pdl
, "image/pwg-raster,", sizeof(pdl
));
3805 pdl
[strlen(pdl
) - 1] = '\0'; /* Remove trailing comma */
3807 cupsdSetString(&p
->pdl
, pdl
);
3809 #endif /* HAVE_DNSSD */
3814 * 'compare_printers()' - Compare two printers.
3817 static int /* O - Result of comparison */
3818 compare_printers(void *first
, /* I - First printer */
3819 void *second
, /* I - Second printer */
3820 void *data
) /* I - App data (not used) */
3822 return (strcasecmp(((cupsd_printer_t
*)first
)->name
,
3823 ((cupsd_printer_t
*)second
)->name
));
3828 * 'delete_printer_filters()' - Delete all MIME filters for a printer.
3832 delete_printer_filters(
3833 cupsd_printer_t
*p
) /* I - Printer to remove from */
3835 mime_filter_t
*filter
; /* MIME filter looping var */
3836 mime_type_t
*type
; /* Destination types for filters */
3840 * Range check input...
3847 * Remove all filters from the MIME database that have a destination
3848 * type == printer...
3851 for (filter
= mimeFirstFilter(MimeDatabase
);
3853 filter
= mimeNextFilter(MimeDatabase
))
3854 if (filter
->dst
== p
->filetype
|| filter
->dst
== p
->prefiltertype
||
3855 cupsArrayFind(p
->dest_types
, filter
->dst
))
3858 * Delete the current filter...
3861 mimeDeleteFilter(MimeDatabase
, filter
);
3864 for (type
= (mime_type_t
*)cupsArrayFirst(p
->dest_types
);
3866 type
= (mime_type_t
*)cupsArrayNext(p
->dest_types
))
3867 mimeDeleteType(MimeDatabase
, type
);
3869 cupsArrayDelete(p
->dest_types
);
3870 p
->dest_types
= NULL
;
3872 cupsdSetPrinterReasons(p
, "-cups-insecure-filter-warning"
3873 ",cups-missing-filter-warning");
3878 * 'dirty_printer()' - Mark config and state files dirty for the specified
3883 dirty_printer(cupsd_printer_t
*p
) /* I - Printer */
3885 if (p
->type
& CUPS_PRINTER_DISCOVERED
)
3886 cupsdMarkDirty(CUPSD_DIRTY_REMOTE
);
3887 else if (p
->type
& CUPS_PRINTER_CLASS
)
3888 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
3890 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
3892 if (PrintcapFormat
== PRINTCAP_PLIST
)
3893 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
3898 * 'load_ppd()' - Load a cached PPD file, updating the cache as needed.
3902 load_ppd(cupsd_printer_t
*p
) /* I - Printer */
3904 int i
, j
, k
; /* Looping vars */
3905 char cache_name
[1024]; /* Cache filename */
3906 struct stat cache_info
; /* Cache file info */
3907 ppd_file_t
*ppd
; /* PPD file */
3908 char ppd_name
[1024]; /* PPD filename */
3909 struct stat ppd_info
; /* PPD file info */
3910 int num_media
; /* Number of media options */
3911 ppd_size_t
*size
; /* Current PPD size */
3912 ppd_option_t
*duplex
, /* Duplex option */
3913 *output_bin
, /* OutputBin option */
3914 *output_mode
, /* OutputMode option */
3915 *resolution
; /* (Set|JCL|)Resolution option */
3916 ppd_choice_t
*choice
, /* Current PPD choice */
3917 *input_slot
, /* Current input slot */
3918 *media_type
; /* Current media type */
3919 ppd_attr_t
*ppd_attr
; /* PPD attribute */
3920 int xdpi
, /* Horizontal resolution */
3921 ydpi
; /* Vertical resolution */
3922 const char *resptr
; /* Pointer into resolution keyword */
3923 _pwg_size_t
*pwgsize
; /* Current PWG size */
3924 _pwg_map_t
*pwgsource
, /* Current PWG source */
3925 *pwgtype
; /* Current PWG type */
3926 ipp_attribute_t
*attr
; /* Attribute data */
3927 ipp_value_t
*val
; /* Attribute value */
3928 int num_finishings
, /* Number of finishings */
3929 finishings
[5]; /* finishings-supported values */
3930 int num_qualities
, /* Number of print-quality values */
3931 qualities
[3]; /* print-quality values */
3932 int num_margins
, /* Number of media-*-margin-supported values */
3933 margins
[16]; /* media-*-margin-supported values */
3934 const char *filter
; /* Current filter */
3935 static const char * const sides
[3] = /* sides-supported values */
3938 "two-sided-long-edge",
3939 "two-sided-short-edge"
3941 static const char * const standard_commands
[] =
3942 { /* Standard CUPS commands */
3950 * Check to see if the cache is up-to-date...
3953 snprintf(cache_name
, sizeof(cache_name
), "%s/%s.data", CacheDir
, p
->name
);
3954 if (stat(cache_name
, &cache_info
))
3955 cache_info
.st_mtime
= 0;
3957 snprintf(ppd_name
, sizeof(ppd_name
), "%s/ppd/%s.ppd", ServerRoot
, p
->name
);
3958 if (stat(ppd_name
, &ppd_info
))
3959 ppd_info
.st_mtime
= 1;
3961 ippDelete(p
->ppd_attrs
);
3962 p
->ppd_attrs
= ippNew();
3964 _ppdCacheDestroy(p
->pc
);
3967 if (cache_info
.st_mtime
>= ppd_info
.st_mtime
)
3969 cupsdLogMessage(CUPSD_LOG_DEBUG
, "load_ppd: Loading %s...", cache_name
);
3971 if ((p
->pc
= _ppdCacheCreateWithFile(cache_name
, &p
->ppd_attrs
)) != NULL
&&
3975 * Loaded successfully!
3983 * Reload PPD attributes from disk...
3986 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
3988 cupsdLogMessage(CUPSD_LOG_DEBUG
, "load_ppd: Loading %s...", ppd_name
);
3990 p
->type
&= ~CUPS_PRINTER_OPTIONS
;
3991 p
->type
|= CUPS_PRINTER_BW
;
3993 finishings
[0] = IPP_FINISHINGS_NONE
;
3996 if ((ppd
= ppdOpenFile(ppd_name
)) != NULL
)
3999 * Add make/model and other various attributes...
4002 p
->pc
= _ppdCacheCreateWithPPD(ppd
);
4004 ppdMarkDefaults(ppd
);
4006 if (ppd
->color_device
)
4007 p
->type
|= CUPS_PRINTER_COLOR
;
4008 if (ppd
->variable_sizes
)
4009 p
->type
|= CUPS_PRINTER_VARIABLE
;
4010 if (!ppd
->manual_copies
)
4011 p
->type
|= CUPS_PRINTER_COPIES
;
4012 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsFax", NULL
)) != NULL
)
4013 if (ppd_attr
->value
&& !strcasecmp(ppd_attr
->value
, "true"))
4014 p
->type
|= CUPS_PRINTER_FAX
;
4016 ippAddBoolean(p
->ppd_attrs
, IPP_TAG_PRINTER
, "color-supported",
4018 if (ppd
->throughput
)
4020 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4021 "pages-per-minute", ppd
->throughput
);
4022 if (ppd
->color_device
)
4023 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4024 "pages-per-minute-color", ppd
->throughput
);
4029 * When there is no speed information, just say "1 page per minute".
4032 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4033 "pages-per-minute", 1);
4034 if (ppd
->color_device
)
4035 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4036 "pages-per-minute-color", 1);
4041 if ((output_mode
= ppdFindOption(ppd
, "OutputMode")) != NULL
)
4043 if (ppdFindChoice(output_mode
, "draft") ||
4044 ppdFindChoice(output_mode
, "fast"))
4045 qualities
[num_qualities
++] = IPP_QUALITY_DRAFT
;
4047 qualities
[num_qualities
++] = IPP_QUALITY_NORMAL
;
4049 if (ppdFindChoice(output_mode
, "best") ||
4050 ppdFindChoice(output_mode
, "high"))
4051 qualities
[num_qualities
++] = IPP_QUALITY_HIGH
;
4053 else if ((ppd_attr
= ppdFindAttr(ppd
, "APPrinterPreset", NULL
)) != NULL
)
4057 if (strstr(ppd_attr
->spec
, "draft") ||
4058 strstr(ppd_attr
->spec
, "Draft"))
4060 qualities
[num_qualities
++] = IPP_QUALITY_DRAFT
;
4064 while ((ppd_attr
= ppdFindNextAttr(ppd
, "APPrinterPreset",
4067 qualities
[num_qualities
++] = IPP_QUALITY_NORMAL
;
4068 qualities
[num_qualities
++] = IPP_QUALITY_HIGH
;
4071 qualities
[num_qualities
++] = IPP_QUALITY_NORMAL
;
4073 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
4074 "print-quality-supported", num_qualities
, qualities
);
4079 * The NickName can be localized in the character set specified
4080 * by the LanugageEncoding attribute. However, ppdOpen2() has
4081 * already converted the ppd->nickname member to UTF-8 for us
4082 * (the original attribute value is available separately)
4085 cupsdSetString(&p
->make_model
, ppd
->nickname
);
4087 else if (ppd
->modelname
)
4090 * Model name can only contain specific characters...
4093 cupsdSetString(&p
->make_model
, ppd
->modelname
);
4096 cupsdSetString(&p
->make_model
, "Bad PPD File");
4098 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
4099 "printer-make-and-model", NULL
, p
->make_model
);
4102 * Add media options from the PPD file...
4105 if (ppd
->num_sizes
== 0 || !p
->pc
)
4107 if (!ppdFindAttr(ppd
, "APScannerOnly", NULL
))
4108 cupsdLogMessage(CUPSD_LOG_CRIT
,
4109 "The PPD file for printer %s contains no media "
4110 "options and is therefore invalid!", p
->name
);
4112 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4113 "media-default", NULL
, "unknown");
4114 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4115 "media-supported", NULL
, "unknown");
4123 if ((size
= ppdPageSize(ppd
, NULL
)) != NULL
)
4124 pwgsize
= _ppdCacheGetSize(p
->pc
, size
->name
);
4128 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4129 "media-default", NULL
,
4130 pwgsize
? pwgsize
->map
.pwg
: "unknown");
4138 ipp_t
*col
; /* Collection value */
4140 input_slot
= ppdFindMarkedChoice(ppd
, "InputSlot");
4141 media_type
= ppdFindMarkedChoice(ppd
, "MediaType");
4142 col
= new_media_col(pwgsize
,
4144 _ppdCacheGetSource(p
->pc
,
4145 input_slot
->choice
) :
4148 _ppdCacheGetType(p
->pc
,
4149 media_type
->choice
) :
4152 ippAddCollection(p
->ppd_attrs
, IPP_TAG_PRINTER
, "media-col-default",
4161 num_media
= p
->pc
->num_sizes
;
4162 if (p
->pc
->custom_min_keyword
)
4165 if ((attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4166 "media-supported", num_media
, NULL
,
4171 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
;
4173 i
--, pwgsize
++, val
++)
4174 val
->string
.text
= _cupsStrRetain(pwgsize
->map
.pwg
);
4176 if (p
->pc
->custom_min_keyword
)
4178 val
->string
.text
= _cupsStrRetain(p
->pc
->custom_min_keyword
);
4180 val
->string
.text
= _cupsStrRetain(p
->pc
->custom_max_keyword
);
4185 * media-source-supported
4188 if (p
->pc
->num_sources
> 0 &&
4189 (attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4190 "media-source-supported", p
->pc
->num_sources
,
4191 NULL
, NULL
)) != NULL
)
4193 for (i
= p
->pc
->num_sources
, pwgsource
= p
->pc
->sources
,
4196 i
--, pwgsource
++, val
++)
4197 val
->string
.text
= _cupsStrRetain(pwgsource
->pwg
);
4201 * media-type-supported
4204 if (p
->pc
->num_types
> 0 &&
4205 (attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4206 "media-type-supported", p
->pc
->num_types
,
4207 NULL
, NULL
)) != NULL
)
4209 for (i
= p
->pc
->num_types
, pwgtype
= p
->pc
->types
,
4212 i
--, pwgtype
++, val
++)
4213 val
->string
.text
= _cupsStrRetain(pwgtype
->pwg
);
4217 * media-*-margin-supported
4220 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, num_margins
= 0;
4221 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4224 for (j
= 0; j
< num_margins
; j
++)
4225 if (pwgsize
->bottom
== margins
[j
])
4228 if (j
>= num_margins
)
4230 margins
[num_margins
] = pwgsize
->bottom
;
4235 if (num_margins
> 0)
4236 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4237 "media-bottom-margin-supported", num_margins
, margins
);
4239 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4240 "media-bottom-margin-supported", 0);
4242 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, num_margins
= 0;
4243 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4246 for (j
= 0; j
< num_margins
; j
++)
4247 if (pwgsize
->left
== margins
[j
])
4250 if (j
>= num_margins
)
4252 margins
[num_margins
] = pwgsize
->left
;
4257 if (num_margins
> 0)
4258 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4259 "media-left-margin-supported", num_margins
, margins
);
4261 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4262 "media-left-margin-supported", 0);
4264 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, num_margins
= 0;
4265 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4268 for (j
= 0; j
< num_margins
; j
++)
4269 if (pwgsize
->right
== margins
[j
])
4272 if (j
>= num_margins
)
4274 margins
[num_margins
] = pwgsize
->right
;
4279 if (num_margins
> 0)
4280 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4281 "media-right-margin-supported", num_margins
, margins
);
4283 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4284 "media-right-margin-supported", 0);
4286 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, num_margins
= 0;
4287 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4290 for (j
= 0; j
< num_margins
; j
++)
4291 if (pwgsize
->top
== margins
[j
])
4294 if (j
>= num_margins
)
4296 margins
[num_margins
] = pwgsize
->top
;
4301 if (num_margins
> 0)
4302 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4303 "media-top-margin-supported", num_margins
, margins
);
4305 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4306 "media-top-margin-supported", 0);
4309 * media-col-database
4312 num_media
= p
->pc
->num_sizes
;
4313 if (p
->pc
->num_sources
)
4315 if (p
->pc
->num_types
> 0)
4316 num_media
+= p
->pc
->num_sizes
* p
->pc
->num_sources
*
4319 num_media
+= p
->pc
->num_sizes
* p
->pc
->num_sources
;
4321 else if (p
->pc
->num_types
)
4322 num_media
+= p
->pc
->num_sizes
* p
->pc
->num_types
;
4324 if ((attr
= ippAddCollections(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4325 "media-col-database", num_media
,
4328 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, val
= attr
->values
;
4333 * Start by adding the page size without source or type...
4336 ppdMarkOption(ppd
, "PageSize", pwgsize
->map
.ppd
);
4338 val
->collection
= new_media_col(pwgsize
, NULL
, NULL
);
4342 * Then add the specific, supported combinations of size, source, and
4346 if (p
->pc
->num_sources
> 0)
4348 for (j
= p
->pc
->num_sources
, pwgsource
= p
->pc
->sources
;
4352 ppdMarkOption(ppd
, "InputSlot", pwgsource
->ppd
);
4354 if (p
->pc
->num_types
> 0)
4356 for (k
= p
->pc
->num_types
, pwgtype
= p
->pc
->types
;
4360 if (!ppdMarkOption(ppd
, "MediaType", pwgtype
->ppd
))
4362 val
->collection
= new_media_col(pwgsize
, pwgsource
->pwg
,
4368 else if (!ppdConflicts(ppd
))
4370 val
->collection
= new_media_col(pwgsize
, pwgsource
->pwg
, NULL
);
4375 else if (p
->pc
->num_types
> 0)
4377 for (j
= p
->pc
->num_types
, pwgtype
= p
->pc
->types
;
4381 if (!ppdMarkOption(ppd
, "MediaType", pwgtype
->ppd
))
4383 val
->collection
= new_media_col(pwgsize
, NULL
, pwgtype
->pwg
);
4391 * Update the number of media-col-database values...
4394 attr
->num_values
= val
- attr
->values
;
4402 if (p
->pc
&& p
->pc
->num_bins
> 0)
4404 attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4405 "output-bin-supported", p
->pc
->num_bins
,
4410 for (i
= 0, val
= attr
->values
;
4411 i
< p
->pc
->num_bins
;
4413 val
->string
.text
= _cupsStrAlloc(p
->pc
->bins
[i
].pwg
);
4416 if ((output_bin
= ppdFindOption(ppd
, "OutputBin")) != NULL
)
4418 for (i
= 0; i
< p
->pc
->num_bins
; i
++)
4419 if (!strcmp(p
->pc
->bins
[i
].ppd
, output_bin
->defchoice
))
4422 if (i
>= p
->pc
->num_bins
)
4425 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4426 "output-bin-default", NULL
, p
->pc
->bins
[i
].pwg
);
4429 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4430 "output-bin-default", NULL
, p
->pc
->bins
[0].pwg
);
4432 else if (((ppd_attr
= ppdFindAttr(ppd
, "DefaultOutputOrder",
4434 !strcasecmp(ppd_attr
->value
, "Reverse")) ||
4435 (!ppd_attr
&& ppd
->manufacturer
&& /* "Compatibility heuristic" */
4436 (!strcasecmp(ppd
->manufacturer
, "epson") ||
4437 !strcasecmp(ppd
->manufacturer
, "lexmark"))))
4440 * Report that this printer has a single output bin that leaves pages face
4444 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4445 "output-bin-supported", NULL
, "face-up");
4446 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4447 "output-bin-default", NULL
, "face-up");
4451 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4452 "output-bin-supported", NULL
, "face-down");
4453 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4454 "output-bin-default", NULL
, "face-down");
4458 * output-mode and print-color-mode...
4461 if (ppd
->color_device
)
4463 static const char * const output_modes
[] =
4469 ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4470 "output-mode-supported", 2, NULL
, output_modes
);
4471 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4472 "output-mode-default", NULL
, "color");
4474 ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4475 "print-color-mode-supported", 2, NULL
, output_modes
);
4476 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4477 "print-color-mode-default", NULL
, "color");
4481 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4482 "output-mode-supported", NULL
, "monochrome");
4483 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4484 "output-mode-default", NULL
, "monochrome");
4486 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4487 "print-color-mode-supported", NULL
, "monochrome");
4488 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4489 "print-color-mode-default", NULL
, "monochrome");
4493 * Printer resolutions...
4496 if ((resolution
= ppdFindOption(ppd
, "Resolution")) == NULL
)
4497 if ((resolution
= ppdFindOption(ppd
, "JCLResolution")) == NULL
)
4498 if ((resolution
= ppdFindOption(ppd
, "SetResolution")) == NULL
)
4499 resolution
= ppdFindOption(ppd
, "CNRes_PGP");
4504 * Report all supported resolutions...
4507 attr
= ippAddResolutions(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4508 "printer-resolution-supported",
4509 resolution
->num_choices
, IPP_RES_PER_INCH
,
4512 for (i
= 0, choice
= resolution
->choices
;
4513 i
< resolution
->num_choices
;
4516 xdpi
= ydpi
= (int)strtol(choice
->choice
, (char **)&resptr
, 10);
4517 if (resptr
> choice
->choice
&& xdpi
> 0 && *resptr
== 'x')
4518 ydpi
= (int)strtol(resptr
+ 1, (char **)&resptr
, 10);
4520 if (xdpi
<= 0 || ydpi
<= 0)
4522 cupsdLogMessage(CUPSD_LOG_WARN
,
4523 "Bad resolution \"%s\" for printer %s.",
4524 choice
->choice
, p
->name
);
4528 attr
->values
[i
].resolution
.xres
= xdpi
;
4529 attr
->values
[i
].resolution
.yres
= ydpi
;
4530 attr
->values
[i
].resolution
.units
= IPP_RES_PER_INCH
;
4533 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4534 "printer-resolution-default", IPP_RES_PER_INCH
,
4538 else if ((ppd_attr
= ppdFindAttr(ppd
, "DefaultResolution", NULL
)) != NULL
&&
4542 * Just the DefaultResolution to report...
4545 xdpi
= ydpi
= (int)strtol(ppd_attr
->value
, (char **)&resptr
, 10);
4546 if (resptr
> ppd_attr
->value
&& xdpi
> 0)
4549 ydpi
= (int)strtol(resptr
+ 1, (char **)&resptr
, 10);
4554 if (xdpi
<= 0 || ydpi
<= 0)
4556 cupsdLogMessage(CUPSD_LOG_WARN
,
4557 "Bad default resolution \"%s\" for printer %s.",
4558 ppd_attr
->value
, p
->name
);
4562 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4563 "printer-resolution-default", IPP_RES_PER_INCH
,
4565 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4566 "printer-resolution-supported", IPP_RES_PER_INCH
,
4572 * No resolutions in PPD - make one up...
4575 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4576 "printer-resolution-default", IPP_RES_PER_INCH
,
4578 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4579 "printer-resolution-supported", IPP_RES_PER_INCH
,
4587 ppdMarkDefaults(ppd
);
4589 if ((duplex
= ppdFindOption(ppd
, "Duplex")) == NULL
)
4590 if ((duplex
= ppdFindOption(ppd
, "EFDuplex")) == NULL
)
4591 if ((duplex
= ppdFindOption(ppd
, "EFDuplexing")) == NULL
)
4592 if ((duplex
= ppdFindOption(ppd
, "KD03Duplex")) == NULL
)
4593 duplex
= ppdFindOption(ppd
, "JCLDuplex");
4595 if (duplex
&& duplex
->num_choices
> 1 &&
4596 !ppdInstallableConflict(ppd
, duplex
->keyword
, "DuplexTumble"))
4598 p
->type
|= CUPS_PRINTER_DUPLEX
;
4600 ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4601 "sides-supported", 3, NULL
, sides
);
4603 if (!strcasecmp(duplex
->defchoice
, "DuplexTumble"))
4604 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4605 "sides-default", NULL
, "two-sided-short-edge");
4606 else if (!strcasecmp(duplex
->defchoice
, "DuplexNoTumble"))
4607 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4608 "sides-default", NULL
, "two-sided-long-edge");
4610 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4611 "sides-default", NULL
, "one-sided");
4615 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4616 "sides-supported", NULL
, "one-sided");
4617 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4618 "sides-default", NULL
, "one-sided");
4621 if (ppdFindOption(ppd
, "Collate") != NULL
)
4622 p
->type
|= CUPS_PRINTER_COLLATE
;
4624 if (ppdFindOption(ppd
, "StapleLocation") != NULL
)
4626 p
->type
|= CUPS_PRINTER_STAPLE
;
4627 finishings
[num_finishings
++] = IPP_FINISHINGS_STAPLE
;
4630 if (ppdFindOption(ppd
, "BindEdge") != NULL
)
4632 p
->type
|= CUPS_PRINTER_BIND
;
4633 finishings
[num_finishings
++] = IPP_FINISHINGS_BIND
;
4636 for (i
= 0; i
< ppd
->num_sizes
; i
++)
4637 if (ppd
->sizes
[i
].length
> 1728)
4638 p
->type
|= CUPS_PRINTER_LARGE
;
4639 else if (ppd
->sizes
[i
].length
> 1008)
4640 p
->type
|= CUPS_PRINTER_MEDIUM
;
4642 p
->type
|= CUPS_PRINTER_SMALL
;
4644 if ((ppd_attr
= ppdFindAttr(ppd
, "APICADriver", NULL
)) != NULL
&&
4645 ppd_attr
->value
&& !strcasecmp(ppd_attr
->value
, "true"))
4647 if ((ppd_attr
= ppdFindAttr(ppd
, "APScannerOnly", NULL
)) != NULL
&&
4648 ppd_attr
->value
&& !strcasecmp(ppd_attr
->value
, "true"))
4649 p
->type
|= CUPS_PRINTER_SCANNER
;
4651 p
->type
|= CUPS_PRINTER_MFP
;
4655 * Scan the filters in the PPD file...
4660 for (filter
= (const char *)cupsArrayFirst(p
->pc
->filters
);
4662 filter
= (const char *)cupsArrayNext(p
->pc
->filters
))
4664 if (!strncasecmp(filter
, "application/vnd.cups-command", 28) &&
4665 _cups_isspace(filter
[28]))
4667 p
->type
|= CUPS_PRINTER_COMMANDS
;
4673 if (p
->type
& CUPS_PRINTER_COMMANDS
)
4675 char *commands
, /* Copy of commands */
4676 *start
, /* Start of name */
4677 *end
; /* End of name */
4678 int count
; /* Number of commands */
4680 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsCommands", NULL
)) != NULL
)
4682 for (count
= 0, start
= ppd_attr
->value
; *start
; count
++)
4684 while (_cups_isspace(*start
))
4690 while (*start
&& !isspace(*start
& 255))
4700 * Make a copy of the commands string and count how many commands there
4704 attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4705 "printer-commands", count
, NULL
, NULL
);
4707 commands
= strdup(ppd_attr
->value
);
4709 for (count
= 0, start
= commands
; *start
; count
++)
4711 while (isspace(*start
& 255))
4718 while (*end
&& !isspace(*end
& 255))
4724 attr
->values
[count
].string
.text
= _cupsStrAlloc(start
);
4734 * Add the standard list of commands...
4737 ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4739 (int)(sizeof(standard_commands
) /
4740 sizeof(standard_commands
[0])), NULL
,
4747 * No commands supported...
4750 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4751 "printer-commands", NULL
, "none");
4755 * Show current and available port monitors for this printer...
4758 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
, "port-monitor",
4759 NULL
, p
->port_monitor
? p
->port_monitor
: "none");
4761 for (i
= 1, ppd_attr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
4763 i
++, ppd_attr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
));
4767 if (strstr(ppd
->protocols
, "TBCP"))
4769 else if (strstr(ppd
->protocols
, "BCP"))
4773 attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
4774 "port-monitor-supported", i
, NULL
, NULL
);
4776 attr
->values
[0].string
.text
= _cupsStrAlloc("none");
4778 for (i
= 1, ppd_attr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
4780 i
++, ppd_attr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
))
4781 attr
->values
[i
].string
.text
= _cupsStrAlloc(ppd_attr
->value
);
4785 if (strstr(ppd
->protocols
, "TBCP"))
4786 attr
->values
[i
].string
.text
= _cupsStrAlloc("tbcp");
4787 else if (strstr(ppd
->protocols
, "BCP"))
4788 attr
->values
[i
].string
.text
= _cupsStrAlloc("bcp");
4791 if (ppdFindAttr(ppd
, "APRemoteQueueID", NULL
))
4792 p
->type
|= CUPS_PRINTER_REMOTE
;
4794 #ifdef HAVE_APPLICATIONSERVICES_H
4796 * Convert the file referenced in APPrinterIconPath to a 128x128 PNG
4797 * and save it as cacheDir/printername.png
4800 if ((ppd_attr
= ppdFindAttr(ppd
, "APPrinterIconPath", NULL
)) != NULL
&&
4803 CGImageRef imageRef
= NULL
;/* Current icon image */
4804 CGImageRef biggestIconRef
= NULL
;
4805 /* Biggest icon image */
4806 CGImageRef closestTo128IconRef
= NULL
;
4807 /* Icon image closest to and >= 128 */
4808 CGImageSourceRef sourceRef
; /* The file's image source */
4809 char outPath
[HTTP_MAX_URI
];
4810 /* The path to the PNG file */
4811 CFURLRef outUrl
; /* The URL made from the outPath */
4812 CFURLRef icnsFileUrl
; /* The URL of the original ICNS icon file */
4813 CGImageDestinationRef destRef
; /* The image destination to write */
4814 size_t bytesPerRow
; /* The bytes per row used for resizing */
4815 CGContextRef context
; /* The CG context used for resizing */
4817 snprintf(outPath
, sizeof(outPath
), "%s/%s.png", CacheDir
, p
->name
);
4818 outUrl
= CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault
,
4822 icnsFileUrl
= CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault
,
4823 (UInt8
*)ppd_attr
->value
,
4824 strlen(ppd_attr
->value
),
4826 if (outUrl
&& icnsFileUrl
)
4828 sourceRef
= CGImageSourceCreateWithURL(icnsFileUrl
, NULL
);
4831 for (i
= 0; i
< CGImageSourceGetCount(sourceRef
); i
++)
4833 imageRef
= CGImageSourceCreateImageAtIndex(sourceRef
, i
, NULL
);
4837 if (CGImageGetWidth(imageRef
) == CGImageGetHeight(imageRef
))
4840 * Loop through remembering the icon closest to 128 but >= 128
4841 * and then remember the largest icon.
4844 if (CGImageGetWidth(imageRef
) >= 128 &&
4845 (!closestTo128IconRef
||
4846 CGImageGetWidth(imageRef
) <
4847 CGImageGetWidth(closestTo128IconRef
)))
4849 CGImageRelease(closestTo128IconRef
);
4850 CGImageRetain(imageRef
);
4851 closestTo128IconRef
= imageRef
;
4854 if (!biggestIconRef
||
4855 CGImageGetWidth(imageRef
) > CGImageGetWidth(biggestIconRef
))
4857 CGImageRelease(biggestIconRef
);
4858 CGImageRetain(imageRef
);
4859 biggestIconRef
= imageRef
;
4863 CGImageRelease(imageRef
);
4869 * If biggestIconRef is NULL, we found no icons. Otherwise we first
4870 * want the closest to 128, but if none are larger than 128, we want
4871 * the largest icon available.
4874 imageRef
= closestTo128IconRef
? closestTo128IconRef
:
4876 CGImageRetain(imageRef
);
4877 CGImageRelease(biggestIconRef
);
4878 if (closestTo128IconRef
)
4879 CGImageRelease(closestTo128IconRef
);
4880 destRef
= CGImageDestinationCreateWithURL(outUrl
, kUTTypePNG
, 1,
4884 if (CGImageGetWidth(imageRef
) != 128)
4886 bytesPerRow
= CGImageGetBytesPerRow(imageRef
) /
4887 CGImageGetWidth(imageRef
) * 128;
4888 context
= CGBitmapContextCreate(NULL
, 128, 128,
4889 CGImageGetBitsPerComponent(imageRef
),
4891 CGImageGetColorSpace(imageRef
),
4892 kCGImageAlphaPremultipliedFirst
);
4895 CGContextDrawImage(context
, CGRectMake(0, 0, 128, 128),
4897 CGImageRelease(imageRef
);
4898 imageRef
= CGBitmapContextCreateImage(context
);
4899 CGContextRelease(context
);
4903 CGImageDestinationAddImage(destRef
, imageRef
, NULL
);
4904 CGImageDestinationFinalize(destRef
);
4908 CGImageRelease(imageRef
);
4911 CFRelease(sourceRef
);
4919 CFRelease(icnsFileUrl
);
4921 #endif /* HAVE_APPLICATIONSERVICES_H */
4924 * Close the PPD and set the type...
4929 else if (!access(ppd_name
, 0))
4931 int pline
; /* PPD line number */
4932 ppd_status_t pstatus
; /* PPD load status */
4935 pstatus
= ppdLastError(&pline
);
4937 cupsdLogMessage(CUPSD_LOG_ERROR
, "PPD file for %s cannot be loaded!",
4940 if (pstatus
<= PPD_ALLOC_ERROR
)
4941 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s", strerror(errno
));
4943 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s on line %d.",
4944 ppdErrorString(pstatus
), pline
);
4946 cupsdLogMessage(CUPSD_LOG_INFO
,
4947 "Hint: Run \"cupstestppd %s\" and fix any errors.",
4953 * If we have an interface script, add a filter entry for it...
4956 char interface
[1024]; /* Interface script */
4959 snprintf(interface
, sizeof(interface
), "%s/interfaces/%s", ServerRoot
,
4961 if (!access(interface
, X_OK
))
4964 * Yes, we have a System V style interface script; use it!
4967 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
4968 "printer-make-and-model", NULL
,
4969 "Local System V Printer");
4971 else if (!strncmp(p
->device_uri
, "ipp://", 6) &&
4972 (strstr(p
->device_uri
, "/printers/") != NULL
||
4973 strstr(p
->device_uri
, "/classes/") != NULL
||
4974 (strstr(p
->device_uri
, "._ipp.") != NULL
&&
4975 !strcmp(p
->device_uri
+ strlen(p
->device_uri
) - 5,
4979 * Tell the client this is really a hard-wired remote printer.
4982 p
->type
|= CUPS_PRINTER_REMOTE
;
4985 * Point the printer-uri-supported attribute to the
4989 if (strchr(p
->device_uri
, '?'))
4992 * Strip trailing "?options" from URI...
4995 char resource
[HTTP_MAX_URI
], /* New URI */
4996 *ptr
; /* Pointer into URI */
4998 strlcpy(resource
, p
->device_uri
, sizeof(resource
));
4999 if ((ptr
= strchr(resource
, '?')) != NULL
)
5002 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
5003 "printer-uri-supported", NULL
, resource
);
5006 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
5007 "printer-uri-supported", NULL
, p
->device_uri
);
5010 * Then set the make-and-model accordingly...
5013 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
5014 "printer-make-and-model", NULL
, "Remote Printer");
5017 * Print all files directly...
5026 * Otherwise we have neither - treat this as a "dumb" printer
5027 * with no PPD file...
5030 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
5031 "printer-make-and-model", NULL
, "Local Raw Printer");
5037 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
5038 "finishings-supported", num_finishings
, finishings
);
5039 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
5040 "finishings-default", IPP_FINISHINGS_NONE
);
5045 * Save cached PPD attributes to disk...
5048 cupsdLogMessage(CUPSD_LOG_DEBUG
, "load_ppd: Saving %s...", cache_name
);
5050 _ppdCacheWriteFile(p
->pc
, cache_name
, p
->ppd_attrs
);
5055 * Remove cache files...
5058 if (cache_info
.st_mtime
)
5065 * 'new_media_col()' - Create a media-col collection value.
5068 static ipp_t
* /* O - Collection value */
5069 new_media_col(_pwg_size_t
*size
, /* I - media-size/margin values */
5070 const char *source
, /* I - media-source value */
5071 const char *type
) /* I - media-type value */
5073 ipp_t
*media_col
, /* Collection value */
5074 *media_size
; /* media-size value */
5077 media_col
= ippNew();
5079 media_size
= ippNew();
5080 ippAddInteger(media_size
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5081 "x-dimension", size
->width
);
5082 ippAddInteger(media_size
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5083 "y-dimension", size
->length
);
5084 ippAddCollection(media_col
, IPP_TAG_PRINTER
, "media-size", media_size
);
5085 ippDelete(media_size
);
5087 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5088 "media-bottom-margin", size
->bottom
);
5089 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5090 "media-left-margin", size
->left
);
5091 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5092 "media-right-margin", size
->right
);
5093 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5094 "media-top-margin", size
->top
);
5097 ippAddString(media_col
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
, "media-source",
5101 ippAddString(media_col
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
, "media-type",
5110 * 'write_irix_config()' - Update the config files used by the IRIX
5115 write_irix_config(cupsd_printer_t
*p
) /* I - Printer to update */
5117 char filename
[1024]; /* Interface script filename */
5118 cups_file_t
*fp
; /* Interface script file */
5119 ipp_attribute_t
*attr
; /* Attribute data */
5123 * Add dummy interface and GUI scripts to fool SGI's "challenged" printing
5124 * tools. First the interface script that tells the tools what kind of
5125 * printer we have...
5128 snprintf(filename
, sizeof(filename
), "/var/spool/lp/interface/%s", p
->name
);
5130 if (p
->type
& CUPS_PRINTER_CLASS
)
5132 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
5134 cupsFilePuts(fp
, "#!/bin/sh\n");
5136 if ((attr
= ippFindAttribute(p
->attrs
, "printer-make-and-model",
5137 IPP_TAG_TEXT
)) != NULL
)
5138 cupsFilePrintf(fp
, "NAME=\"%s\"\n", attr
->values
[0].string
.text
);
5139 else if (p
->type
& CUPS_PRINTER_CLASS
)
5140 cupsFilePuts(fp
, "NAME=\"Printer Class\"\n");
5142 cupsFilePuts(fp
, "NAME=\"Remote Destination\"\n");
5144 if (p
->type
& CUPS_PRINTER_COLOR
)
5145 cupsFilePuts(fp
, "TYPE=ColorPostScript\n");
5147 cupsFilePuts(fp
, "TYPE=MonoPostScript\n");
5149 cupsFilePrintf(fp
, "HOSTNAME=%s\n", ServerName
);
5150 cupsFilePrintf(fp
, "HOSTPRINTER=%s\n", p
->name
);
5154 chmod(filename
, 0755);
5155 chown(filename
, User
, Group
);
5159 * Then the member file that tells which device file the queue is connected
5160 * to... Networked printers use "/dev/null" in this file, so that's what
5161 * we use (the actual device URI can confuse some apps...)
5164 snprintf(filename
, sizeof(filename
), "/var/spool/lp/member/%s", p
->name
);
5166 if (p
->type
& CUPS_PRINTER_CLASS
)
5168 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
5170 cupsFilePuts(fp
, "/dev/null\n");
5174 chmod(filename
, 0644);
5175 chown(filename
, User
, Group
);
5179 * The gui_interface file is a script or program that launches a GUI
5180 * option panel for the printer, using options specified on the
5181 * command-line in the third argument. The option panel must send
5182 * any printing options to stdout on a single line when the user
5183 * accepts them, or nothing if the user cancels the dialog.
5185 * The default options panel program is /usr/bin/glpoptions, from
5186 * the ESP Print Pro software. You can select another using the
5187 * PrintcapGUI option.
5190 snprintf(filename
, sizeof(filename
), "/var/spool/lp/gui_interface/ELF/%s.gui", p
->name
);
5192 if (p
->type
& CUPS_PRINTER_CLASS
)
5194 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
5196 cupsFilePuts(fp
, "#!/bin/sh\n");
5197 cupsFilePrintf(fp
, "%s -d %s -o \"$3\"\n", PrintcapGUI
, p
->name
);
5201 chmod(filename
, 0755);
5202 chown(filename
, User
, Group
);
5206 * The POD config file is needed by the printstatus command to show
5207 * the printer location and device.
5210 snprintf(filename
, sizeof(filename
), "/var/spool/lp/pod/%s.config", p
->name
);
5212 if (p
->type
& CUPS_PRINTER_CLASS
)
5214 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
5216 cupsFilePrintf(fp
, "Printer Class | %s\n",
5217 (p
->type
& CUPS_PRINTER_COLOR
) ? "ColorPostScript" : "MonoPostScript");
5218 cupsFilePrintf(fp
, "Printer Model | %s\n", p
->make_model
? p
->make_model
: "");
5219 cupsFilePrintf(fp
, "Location Code | %s\n", p
->location
? p
->location
: "");
5220 cupsFilePrintf(fp
, "Physical Location | %s\n", p
->info
? p
->info
: "");
5221 cupsFilePrintf(fp
, "Port Path | %s\n", p
->device_uri
);
5222 cupsFilePrintf(fp
, "Config Path | /var/spool/lp/pod/%s.config\n", p
->name
);
5223 cupsFilePrintf(fp
, "Active Status Path | /var/spool/lp/pod/%s.status\n", p
->name
);
5224 cupsFilePuts(fp
, "Status Update Wait | 10 seconds\n");
5228 chmod(filename
, 0664);
5229 chown(filename
, User
, Group
);
5235 * 'write_irix_state()' - Update the status files used by IRIX printing
5240 write_irix_state(cupsd_printer_t
*p
) /* I - Printer to update */
5242 char filename
[1024]; /* Interface script filename */
5243 cups_file_t
*fp
; /* Interface script file */
5244 int tag
; /* Status tag value */
5250 * The POD status file is needed for the printstatus window to
5251 * provide the current status of the printer.
5254 snprintf(filename
, sizeof(filename
), "/var/spool/lp/pod/%s.status", p
->name
);
5256 if (p
->type
& CUPS_PRINTER_CLASS
)
5258 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
5260 cupsFilePrintf(fp
, "Operational Status | %s\n",
5261 (p
->state
== IPP_PRINTER_IDLE
) ? "Idle" :
5262 (p
->state
== IPP_PRINTER_PROCESSING
) ? "Busy" :
5264 cupsFilePrintf(fp
, "Information | 01 00 00 | %s\n", CUPS_SVERSION
);
5265 cupsFilePrintf(fp
, "Information | 02 00 00 | Device URI: %s\n",
5267 cupsFilePrintf(fp
, "Information | 03 00 00 | %s jobs\n",
5268 p
->accepting
? "Accepting" : "Not accepting");
5269 cupsFilePrintf(fp
, "Information | 04 00 00 | %s\n", p
->state_message
);
5273 chmod(filename
, 0664);
5274 chown(filename
, User
, Group
);
5278 * The activeicons file is needed to provide desktop icons for printers:
5280 * [ quoted from /usr/lib/print/tagit ]
5282 * --- Type of printer tags (base values)
5284 * Dumb=66048 # 0x10200
5285 * DumbColor=66080 # 0x10220
5286 * Raster=66112 # 0x10240
5287 * ColorRaster=66144 # 0x10260
5288 * Plotter=66176 # 0x10280
5289 * PostScript=66208 # 0x102A0
5290 * ColorPostScript=66240 # 0x102C0
5291 * MonoPostScript=66272 # 0x102E0
5293 * --- Printer state modifiers for local printers
5298 * Unknown=3 # 0x3 (Faulted due to unknown reason)
5300 * --- Printer state modifiers for network printers
5304 * NetFaulted=10 # 0xA
5305 * NetUnknown=11 # 0xB (Faulted due to unknown reason)
5308 snprintf(filename
, sizeof(filename
), "/var/spool/lp/activeicons/%s", p
->name
);
5310 if (p
->type
& CUPS_PRINTER_CLASS
)
5312 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
5314 if (p
->type
& CUPS_PRINTER_COLOR
)
5319 if (p
->type
& CUPS_PRINTER_REMOTE
)
5322 if (p
->state
== IPP_PRINTER_PROCESSING
)
5325 else if (p
->state
== IPP_PRINTER_STOPPED
)
5328 cupsFilePuts(fp
, "#!/bin/sh\n");
5329 cupsFilePrintf(fp
, "#Tag %d\n", tag
);
5333 chmod(filename
, 0755);
5334 chown(filename
, User
, Group
);
5339 * The default file is needed by the printers window to show
5340 * the default printer.
5343 snprintf(filename
, sizeof(filename
), "/var/spool/lp/default");
5345 if (DefaultPrinter
!= NULL
)
5347 if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
5349 cupsFilePrintf(fp
, "%s\n", DefaultPrinter
->name
);
5353 chmod(filename
, 0644);
5354 chown(filename
, User
, Group
);
5364 * 'write_xml_string()' - Write a string with XML escaping.
5368 write_xml_string(cups_file_t
*fp
, /* I - File to write to */
5369 const char *s
) /* I - String to write */
5371 const char *start
; /* Start of current sequence */
5377 for (start
= s
; *s
; s
++)
5382 cupsFileWrite(fp
, start
, s
- start
);
5384 cupsFilePuts(fp
, "&");
5390 cupsFileWrite(fp
, start
, s
- start
);
5392 cupsFilePuts(fp
, "<");
5398 cupsFilePuts(fp
, start
);
5403 * End of "$Id: printers.c 7968 2008-09-19 23:03:01Z mike $".