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 */
111 uuid
[64]; /* Printer UUID */
115 * Range check input...
118 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdAddPrinter(\"%s\")", name
);
121 * Create a new printer entity...
124 if ((p
= calloc(1, sizeof(cupsd_printer_t
))) == NULL
)
126 cupsdLogMessage(CUPSD_LOG_CRIT
, "Unable to allocate memory for printer - %s",
131 cupsdSetString(&p
->name
, name
);
132 cupsdSetString(&p
->info
, name
);
133 cupsdSetString(&p
->hostname
, ServerName
);
135 httpAssembleURIf(HTTP_URI_CODING_ALL
, uri
, sizeof(uri
), "ipp", NULL
,
136 ServerName
, RemotePort
, "/printers/%s", name
);
137 cupsdSetString(&p
->uri
, uri
);
138 cupsdSetString(&p
->uuid
, cupsdMakeUUID(name
, 0, uuid
, sizeof(uuid
)));
139 cupsdSetDeviceURI(p
, "file:///dev/null");
141 p
->state
= IPP_PRINTER_STOPPED
;
142 p
->state_time
= time(NULL
);
144 p
->shared
= DefaultShared
;
145 p
->filetype
= mimeAddType(MimeDatabase
, "printer", name
);
147 cupsdSetString(&p
->job_sheets
[0], "none");
148 cupsdSetString(&p
->job_sheets
[1], "none");
150 cupsdSetString(&p
->error_policy
, ErrorPolicy
);
151 cupsdSetString(&p
->op_policy
, DefaultPolicy
);
153 p
->op_policy_ptr
= DefaultPolicyPtr
;
156 * Insert the printer in the printer list alphabetically...
160 Printers
= cupsArrayNew(compare_printers
, NULL
);
162 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
163 "cupsdAddPrinter: Adding %s to Printers", p
->name
);
164 cupsArrayAdd(Printers
, p
);
166 if (!ImplicitPrinters
)
167 ImplicitPrinters
= cupsArrayNew(compare_printers
, NULL
);
170 * Return the new printer...
178 * 'cupsdCreateCommonData()' - Create the common printer data.
182 cupsdCreateCommonData(void)
184 int i
; /* Looping var */
185 ipp_attribute_t
*attr
; /* Attribute data */
186 cups_dir_t
*dir
; /* Notifier directory */
187 cups_dentry_t
*dent
; /* Notifier directory entry */
188 cups_array_t
*notifiers
; /* Notifier array */
189 char filename
[1024], /* Filename */
190 *notifier
; /* Current notifier */
191 cupsd_policy_t
*p
; /* Current policy */
192 int k_supported
; /* Maximum file size supported */
194 struct statvfs spoolinfo
; /* FS info for spool directory */
195 double spoolsize
; /* FS size */
196 #elif defined(HAVE_STATFS)
197 struct statfs spoolinfo
; /* FS info for spool directory */
198 double spoolsize
; /* FS size */
199 #endif /* HAVE_STATVFS */
200 static const int nups
[] = /* number-up-supported values */
201 { 1, 2, 4, 6, 9, 16 };
202 static const int orients
[4] =/* orientation-requested-supported values */
206 IPP_REVERSE_LANDSCAPE
,
209 static const char * const holds
[] = /* job-hold-until-supported values */
220 static const char * const versions
[] =/* ipp-versions-supported values */
227 static const int ops
[] = /* operations-supported values */
234 IPP_GET_JOB_ATTRIBUTES
,
236 IPP_GET_PRINTER_ATTRIBUTES
,
243 IPP_SET_PRINTER_ATTRIBUTES
,
244 IPP_SET_JOB_ATTRIBUTES
,
245 IPP_GET_PRINTER_SUPPORTED_VALUES
,
246 IPP_CREATE_PRINTER_SUBSCRIPTION
,
247 IPP_CREATE_JOB_SUBSCRIPTION
,
248 IPP_GET_SUBSCRIPTION_ATTRIBUTES
,
249 IPP_GET_SUBSCRIPTIONS
,
250 IPP_RENEW_SUBSCRIPTION
,
251 IPP_CANCEL_SUBSCRIPTION
,
252 IPP_GET_NOTIFICATIONS
,
256 IPP_RELEASE_HELD_NEW_JOBS
,
273 CUPS_AUTHENTICATE_JOB
,
278 static const char * const charsets
[] =/* charset-supported values */
283 static const char * const compressions
[] =
284 { /* document-compression-supported values */
288 #endif /* HAVE_LIBZ */
290 static const char * const media_col_supported
[] =
291 { /* media-col-supported values */
292 "media-bottom-margin",
294 "media-right-margin",
300 static const char * const multiple_document_handling
[] =
301 { /* multiple-document-handling-supported values */
302 "separate-documents-uncollated-copies",
303 "separate-documents-collated-copies"
305 static const char * const notify_attrs
[] =
306 { /* notify-attributes-supported values */
307 "printer-state-change-time",
308 "notify-lease-expiration-time",
309 "notify-subscriber-user-name"
311 static const char * const notify_events
[] =
312 { /* notify-events-supported values */
314 "job-config-changed",
321 "printer-config-changed",
323 "printer-finishings-changed",
324 "printer-media-changed",
328 "printer-state-changed",
335 static const char * const job_creation
[] =
336 { /* job-creation-attributes-supported */
339 "ipp-attribute-fidelity",
346 "multiple-document-handling",
350 "orientation-requested",
353 "printer-resolution",
356 static const char * const job_settable
[] =
357 { /* job-settable-attributes-supported */
365 "multiple-document-handling",
369 "orientation-requested",
372 "printer-resolution",
375 static const char * const pdf_versions
[] =
376 { /* pdf-versions-supported */
387 static const char * const printer_settable
[] =
388 { /* printer-settable-attributes-supported */
392 static const char * const which_jobs
[] =
393 { /* which-jobs-supported values */
407 ippDelete(CommonData
);
409 CommonData
= ippNew();
412 * Get the maximum spool size based on the size of the filesystem used for
413 * the RequestRoot directory. If the host OS doesn't support the statfs call
414 * or the filesystem is larger than 2TiB, always report INT_MAX.
418 if (statvfs(RequestRoot
, &spoolinfo
))
419 k_supported
= INT_MAX
;
420 else if ((spoolsize
= (double)spoolinfo
.f_frsize
* spoolinfo
.f_blocks
/ 1024) >
422 k_supported
= INT_MAX
;
424 k_supported
= (int)spoolsize
;
426 #elif defined(HAVE_STATFS)
427 if (statfs(RequestRoot
, &spoolinfo
))
428 k_supported
= INT_MAX
;
429 else if ((spoolsize
= (double)spoolinfo
.f_bsize
* spoolinfo
.f_blocks
/ 1024) >
431 k_supported
= INT_MAX
;
433 k_supported
= (int)spoolsize
;
436 k_supported
= INT_MAX
;
437 #endif /* HAVE_STATVFS */
440 * This list of attributes is sorted to improve performance when the
441 * client provides a requested-attributes attribute...
444 /* charset-configured */
445 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_CHARSET
| IPP_TAG_COPY
,
446 "charset-configured", NULL
, "utf-8");
448 /* charset-supported */
449 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_CHARSET
| IPP_TAG_COPY
,
450 "charset-supported", sizeof(charsets
) / sizeof(charsets
[0]),
453 /* compression-supported */
454 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
455 "compression-supported",
456 sizeof(compressions
) / sizeof(compressions
[0]),
459 /* copies-supported */
460 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "copies-supported", 1, MaxCopies
);
463 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
| IPP_TAG_COPY
,
464 "cups-version", NULL
, CUPS_SVERSION
+ 6);
466 /* generated-natural-language-supported (no IPP_TAG_COPY) */
467 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_LANGUAGE
,
468 "generated-natural-language-supported", NULL
, DefaultLanguage
);
470 /* ipp-versions-supported */
471 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
472 "ipp-versions-supported", sizeof(versions
) / sizeof(versions
[0]),
475 /* ippget-event-life */
476 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
477 "ippget-event-life", 15);
479 /* job-creation-attributes-supported */
480 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
481 "job-creation-attributes-supported",
482 sizeof(job_creation
) / sizeof(job_creation
[0]),
485 /* job-hold-until-supported */
486 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
487 "job-hold-until-supported", sizeof(holds
) / sizeof(holds
[0]),
490 /* job-ids-supported */
491 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
, "job-ids-supported", 1);
493 /* job-k-octets-supported */
494 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
495 "job-k-octets-supported", k_supported
);
497 /* job-priority-supported */
498 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
499 "job-priority-supported", 100);
501 /* job-settable-attributes-supported */
502 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
503 "job-settable-attributes-supported",
504 sizeof(job_settable
) / sizeof(job_settable
[0]),
507 /* job-sheets-supported */
508 if (cupsArrayCount(Banners
) > 0)
511 * Setup the job-sheets-supported attribute...
514 if (Classification
&& !ClassifyOverride
)
515 attr
= ippAddString(CommonData
, IPP_TAG_PRINTER
,
516 IPP_TAG_NAME
| IPP_TAG_COPY
,
517 "job-sheets-supported", NULL
, Classification
);
519 attr
= ippAddStrings(CommonData
, IPP_TAG_PRINTER
,
520 IPP_TAG_NAME
| IPP_TAG_COPY
,
521 "job-sheets-supported", cupsArrayCount(Banners
) + 1,
525 cupsdLogMessage(CUPSD_LOG_EMERG
,
526 "Unable to allocate memory for "
527 "job-sheets-supported attribute: %s!", strerror(errno
));
528 else if (!Classification
|| ClassifyOverride
)
530 cupsd_banner_t
*banner
; /* Current banner */
533 attr
->values
[0].string
.text
= _cupsStrAlloc("none");
535 for (i
= 1, banner
= (cupsd_banner_t
*)cupsArrayFirst(Banners
);
537 i
++, banner
= (cupsd_banner_t
*)cupsArrayNext(Banners
))
538 attr
->values
[i
].string
.text
= banner
->name
;
542 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
543 "job-sheets-supported", NULL
, "none");
545 /* jpeg-k-octets-supported */
546 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "jpeg-k-octets-supported", 0,
549 /* jpeg-x-dimension-supported */
550 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "jpeg-x-dimension-supported", 0,
553 /* jpeg-y-dimension-supported */
554 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "jpeg-y-dimension-supported", 1,
557 /* media-col-supported */
558 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
559 "media-col-supported",
560 sizeof(media_col_supported
) /
561 sizeof(media_col_supported
[0]), NULL
,
562 media_col_supported
);
564 /* multiple-document-handling-supported */
565 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
566 "multiple-document-handling-supported",
567 sizeof(multiple_document_handling
) /
568 sizeof(multiple_document_handling
[0]), NULL
,
569 multiple_document_handling
);
571 /* multiple-document-jobs-supported */
572 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
,
573 "multiple-document-jobs-supported", 1);
575 /* multiple-operation-time-out */
576 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
577 "multiple-operation-time-out", MultipleOperationTimeout
);
579 /* natural-language-configured (no IPP_TAG_COPY) */
580 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_LANGUAGE
,
581 "natural-language-configured", NULL
, DefaultLanguage
);
583 /* notify-attributes-supported */
584 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
585 "notify-attributes-supported",
586 (int)(sizeof(notify_attrs
) / sizeof(notify_attrs
[0])),
589 /* notify-lease-duration-supported */
590 ippAddRange(CommonData
, IPP_TAG_PRINTER
,
591 "notify-lease-duration-supported", 0,
592 MaxLeaseDuration
? MaxLeaseDuration
: 2147483647);
594 /* notify-max-events-supported */
595 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
596 "notify-max-events-supported", MaxEvents
);
598 /* notify-events-supported */
599 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
600 "notify-events-supported",
601 (int)(sizeof(notify_events
) / sizeof(notify_events
[0])),
602 NULL
, notify_events
);
604 /* notify-pull-method-supported */
605 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
606 "notify-pull-method-supported", NULL
, "ippget");
608 /* notify-schemes-supported */
609 snprintf(filename
, sizeof(filename
), "%s/notifier", ServerBin
);
610 if ((dir
= cupsDirOpen(filename
)) != NULL
)
612 notifiers
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
614 while ((dent
= cupsDirRead(dir
)) != NULL
)
615 if (S_ISREG(dent
->fileinfo
.st_mode
) &&
616 (dent
->fileinfo
.st_mode
& S_IXOTH
) != 0)
617 cupsArrayAdd(notifiers
, _cupsStrAlloc(dent
->filename
));
619 if (cupsArrayCount(notifiers
) > 0)
621 attr
= ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
622 "notify-schemes-supported",
623 cupsArrayCount(notifiers
), NULL
, NULL
);
625 for (i
= 0, notifier
= (char *)cupsArrayFirst(notifiers
);
627 i
++, notifier
= (char *)cupsArrayNext(notifiers
))
628 attr
->values
[i
].string
.text
= notifier
;
631 cupsArrayDelete(notifiers
);
635 /* number-up-supported */
636 ippAddIntegers(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
637 "number-up-supported", sizeof(nups
) / sizeof(nups
[0]), nups
);
639 /* operations-supported */
640 ippAddIntegers(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
641 "operations-supported",
642 sizeof(ops
) / sizeof(ops
[0]) + JobFiles
- 1, ops
);
644 /* orientation-requested-supported */
645 ippAddIntegers(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
646 "orientation-requested-supported", 4, orients
);
648 /* page-ranges-supported */
649 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
, "page-ranges-supported", 1);
651 /* pdf-k-octets-supported */
652 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "pdf-k-octets-supported", 0,
655 /* pdf-versions-supported */
656 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
657 "pdf-versions-supported",
658 sizeof(pdf_versions
) / sizeof(pdf_versions
[0]), NULL
,
661 /* pdl-override-supported */
662 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
663 "pdl-override-supported", NULL
, "attempted");
665 /* printer-op-policy-supported */
666 attr
= ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
667 "printer-op-policy-supported", cupsArrayCount(Policies
),
669 for (i
= 0, p
= (cupsd_policy_t
*)cupsArrayFirst(Policies
);
671 i
++, p
= (cupsd_policy_t
*)cupsArrayNext(Policies
))
672 attr
->values
[i
].string
.text
= p
->name
;
674 /* printer-settable-attributes-supported */
675 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
676 "printer-settable-attributes-supported",
677 sizeof(printer_settable
) / sizeof(printer_settable
[0]),
678 NULL
, printer_settable
);
680 /* server-is-sharing-printers */
681 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
, "server-is-sharing-printers",
682 BrowseLocalProtocols
!= 0 && Browsing
);
684 /* which-jobs-supported */
685 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
686 "which-jobs-supported",
687 sizeof(which_jobs
) / sizeof(which_jobs
[0]), NULL
, which_jobs
);
692 * 'cupsdDeleteAllPrinters()' - Delete all printers from the system.
696 cupsdDeleteAllPrinters(void)
698 cupsd_printer_t
*p
; /* Pointer to current printer/class */
701 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
703 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
705 p
->op_policy_ptr
= DefaultPolicyPtr
;
706 cupsdDeletePrinter(p
, 0);
712 * 'cupsdDeletePrinter()' - Delete a printer from the system.
715 int /* O - 1 if classes affected, 0 otherwise */
717 cupsd_printer_t
*p
, /* I - Printer to delete */
718 int update
) /* I - Update printers.conf? */
720 int i
, /* Looping var */
721 changed
= 0; /* Class changed? */
723 char filename
[1024]; /* Interface script filename */
727 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdDeletePrinter(p=%p(%s), update=%d)",
731 * Save the current position in the Printers array...
734 cupsArraySave(Printers
);
737 * Stop printing on this printer...
740 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, update
);
742 p
->state
= IPP_PRINTER_STOPPED
; /* Force for browsed printers */
745 cupsdSetJobState(p
->job
, IPP_JOB_PENDING
, CUPSD_JOB_FORCE
,
746 update
? "Job stopped due to printer being deleted." :
750 * If this printer is the next for browsing, point to the next one...
755 cupsArrayFind(Printers
, p
);
756 BrowseNext
= (cupsd_printer_t
*)cupsArrayNext(Printers
);
760 * Remove the printer from the list...
763 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
764 "cupsdDeletePrinter: Removing %s from Printers", p
->name
);
765 cupsArrayRemove(Printers
, p
);
767 if (p
->type
& CUPS_PRINTER_IMPLICIT
)
769 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
770 "cupsdDeletePrinter: Removing %s from ImplicitPrinters",
772 cupsArrayRemove(ImplicitPrinters
, p
);
776 * Remove the dummy interface/icon/option files under IRIX...
780 snprintf(filename
, sizeof(filename
), "/var/spool/lp/interface/%s", p
->name
);
783 snprintf(filename
, sizeof(filename
), "/var/spool/lp/gui_interface/ELF/%s.gui",
787 snprintf(filename
, sizeof(filename
), "/var/spool/lp/activeicons/%s", p
->name
);
790 snprintf(filename
, sizeof(filename
), "/var/spool/lp/pod/%s.config", p
->name
);
793 snprintf(filename
, sizeof(filename
), "/var/spool/lp/pod/%s.status", p
->name
);
796 snprintf(filename
, sizeof(filename
), "/var/spool/lp/member/%s", p
->name
);
801 * If p is the default printer, assign a different one...
804 if (p
== DefaultPrinter
)
806 DefaultPrinter
= NULL
;
808 if (UseNetworkDefault
)
811 * Find the first network default printer and use it...
814 cupsd_printer_t
*dp
; /* New default printer */
817 for (dp
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
819 dp
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
820 if (dp
!= p
&& (dp
->type
& CUPS_PRINTER_DEFAULT
))
829 * Remove this printer from any classes...
832 if (!(p
->type
& CUPS_PRINTER_IMPLICIT
))
834 changed
= cupsdDeletePrinterFromClasses(p
);
837 * Deregister from any browse protocols...
840 cupsdDeregisterPrinter(p
, 1);
844 * Free all memory used by the printer...
847 if (p
->printers
!= NULL
)
850 delete_printer_filters(p
);
852 for (i
= 0; i
< p
->num_reasons
; i
++)
853 _cupsStrFree(p
->reasons
[i
]);
856 ippDelete(p
->ppd_attrs
);
858 mimeDeleteType(MimeDatabase
, p
->filetype
);
859 mimeDeleteType(MimeDatabase
, p
->prefiltertype
);
861 cupsdFreeStrings(&(p
->users
));
864 cupsdClearString(&p
->uri
);
865 cupsdClearString(&p
->hostname
);
866 cupsdClearString(&p
->name
);
867 cupsdClearString(&p
->location
);
868 cupsdClearString(&p
->make_model
);
869 cupsdClearString(&p
->info
);
870 cupsdClearString(&p
->job_sheets
[0]);
871 cupsdClearString(&p
->job_sheets
[1]);
872 cupsdClearString(&p
->device_uri
);
873 cupsdClearString(&p
->sanitized_device_uri
);
874 cupsdClearString(&p
->port_monitor
);
875 cupsdClearString(&p
->op_policy
);
876 cupsdClearString(&p
->error_policy
);
878 cupsdClearString(&p
->alert
);
879 cupsdClearString(&p
->alert_description
);
882 cupsdClearString(&p
->pdl
);
883 #endif /* HAVE_DNSSD */
885 cupsArrayDelete(p
->filetypes
);
888 free(p
->browse_attrs
);
890 cupsFreeOptions(p
->num_options
, p
->options
);
895 * Restore the previous position in the Printers array...
898 cupsArrayRestore(Printers
);
905 * 'cupsdFindDest()' - Find a destination in the list.
908 cupsd_printer_t
* /* O - Destination in list */
909 cupsdFindDest(const char *name
) /* I - Name of printer or class to find */
911 cupsd_printer_t key
; /* Search key */
914 key
.name
= (char *)name
;
915 return ((cupsd_printer_t
*)cupsArrayFind(Printers
, &key
));
920 * 'cupsdFindPrinter()' - Find a printer in the list.
923 cupsd_printer_t
* /* O - Printer in list */
924 cupsdFindPrinter(const char *name
) /* I - Name of printer to find */
926 cupsd_printer_t
*p
; /* Printer in list */
929 if ((p
= cupsdFindDest(name
)) != NULL
&& (p
->type
& CUPS_PRINTER_CLASS
))
937 * 'cupsdLoadAllPrinters()' - Load printers from the printers.conf file.
941 cupsdLoadAllPrinters(void)
943 int i
; /* Looping var */
944 cups_file_t
*fp
; /* printers.conf file */
945 int linenum
; /* Current line number */
946 char line
[4096], /* Line from file */
947 *value
, /* Pointer to value */
948 *valueptr
; /* Pointer into value */
949 cupsd_printer_t
*p
; /* Current printer */
953 * Open the printers.conf file...
956 snprintf(line
, sizeof(line
), "%s/printers.conf", ServerRoot
);
957 if ((fp
= cupsFileOpen(line
, "r")) == NULL
)
960 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to open %s - %s", line
,
966 * Read printer configurations until we hit EOF...
972 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
975 * Decode the directive...
978 if (!strcasecmp(line
, "<Printer") ||
979 !strcasecmp(line
, "<DefaultPrinter"))
982 * <Printer name> or <DefaultPrinter name>
985 if (p
== NULL
&& value
)
988 * Add the printer and a base file type...
991 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Loading printer %s...", value
);
993 p
= cupsdAddPrinter(value
);
995 p
->state
= IPP_PRINTER_IDLE
;
998 * Set the default printer as needed...
1001 if (!strcasecmp(line
, "<DefaultPrinter"))
1005 cupsdLogMessage(CUPSD_LOG_ERROR
,
1006 "Syntax error on line %d of printers.conf.", linenum
);
1008 else if (!strcasecmp(line
, "</Printer>"))
1013 * Close out the current printer...
1016 cupsdSetPrinterAttrs(p
);
1018 if (strncmp(p
->device_uri
, "file:", 5) &&
1019 p
->state
!= IPP_PRINTER_STOPPED
)
1022 * See if the backend exists...
1025 snprintf(line
, sizeof(line
), "%s/backend/%s", ServerBin
,
1028 if ((valueptr
= strchr(line
+ strlen(ServerBin
), ':')) != NULL
)
1029 *valueptr
= '\0'; /* Chop everything but URI scheme */
1031 if (access(line
, 0))
1034 * Backend does not exist, stop printer...
1037 p
->state
= IPP_PRINTER_STOPPED
;
1038 snprintf(p
->state_message
, sizeof(p
->state_message
),
1039 "Backend %s does not exist!", line
);
1046 cupsdLogMessage(CUPSD_LOG_ERROR
,
1047 "Syntax error on line %d of printers.conf.", linenum
);
1051 cupsdLogMessage(CUPSD_LOG_ERROR
,
1052 "Syntax error on line %d of printers.conf.", linenum
);
1054 else if (!strcasecmp(line
, "UUID"))
1056 if (value
&& !strncmp(value
, "urn:uuid:", 9))
1057 cupsdSetString(&(p
->uuid
), value
);
1059 cupsdLogMessage(CUPSD_LOG_ERROR
,
1060 "Bad UUID on line %d of printers.conf.", linenum
);
1062 else if (!strcasecmp(line
, "AuthInfoRequired"))
1064 if (!cupsdSetAuthInfoRequired(p
, value
, NULL
))
1065 cupsdLogMessage(CUPSD_LOG_ERROR
,
1066 "Bad AuthInfoRequired on line %d of printers.conf.",
1069 else if (!strcasecmp(line
, "Info"))
1072 cupsdSetString(&p
->info
, value
);
1074 else if (!strcasecmp(line
, "MakeModel"))
1077 cupsdSetString(&p
->make_model
, value
);
1079 else if (!strcasecmp(line
, "Location"))
1082 cupsdSetString(&p
->location
, value
);
1084 else if (!strcasecmp(line
, "DeviceURI"))
1087 cupsdSetDeviceURI(p
, value
);
1089 cupsdLogMessage(CUPSD_LOG_ERROR
,
1090 "Syntax error on line %d of printers.conf.", linenum
);
1092 else if (!strcasecmp(line
, "Option") && value
)
1098 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1101 cupsdLogMessage(CUPSD_LOG_ERROR
,
1102 "Syntax error on line %d of printers.conf.", linenum
);
1105 for (; *valueptr
&& isspace(*valueptr
& 255); *valueptr
++ = '\0');
1107 p
->num_options
= cupsAddOption(value
, valueptr
, p
->num_options
,
1111 else if (!strcasecmp(line
, "PortMonitor"))
1113 if (value
&& strcmp(value
, "none"))
1114 cupsdSetString(&p
->port_monitor
, value
);
1116 cupsdClearString(&p
->port_monitor
);
1118 cupsdLogMessage(CUPSD_LOG_ERROR
,
1119 "Syntax error on line %d of printers.conf.", linenum
);
1121 else if (!strcasecmp(line
, "Reason"))
1124 strcmp(value
, "connecting-to-device") &&
1125 strcmp(value
, "cups-insecure-filter-warning") &&
1126 strcmp(value
, "cups-missing-filter-warning"))
1128 for (i
= 0 ; i
< p
->num_reasons
; i
++)
1129 if (!strcmp(value
, p
->reasons
[i
]))
1132 if (i
>= p
->num_reasons
&&
1133 p
->num_reasons
< (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
1135 p
->reasons
[p
->num_reasons
] = _cupsStrAlloc(value
);
1140 cupsdLogMessage(CUPSD_LOG_ERROR
,
1141 "Syntax error on line %d of printers.conf.", linenum
);
1143 else if (!strcasecmp(line
, "State"))
1146 * Set the initial queue state...
1149 if (value
&& !strcasecmp(value
, "idle"))
1150 p
->state
= IPP_PRINTER_IDLE
;
1151 else if (value
&& !strcasecmp(value
, "stopped"))
1153 p
->state
= IPP_PRINTER_STOPPED
;
1155 for (i
= 0 ; i
< p
->num_reasons
; i
++)
1156 if (!strcmp("paused", p
->reasons
[i
]))
1159 if (i
>= p
->num_reasons
&&
1160 p
->num_reasons
< (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
1162 p
->reasons
[p
->num_reasons
] = _cupsStrAlloc("paused");
1167 cupsdLogMessage(CUPSD_LOG_ERROR
,
1168 "Syntax error on line %d of printers.conf.", linenum
);
1170 else if (!strcasecmp(line
, "StateMessage"))
1173 * Set the initial queue state message...
1177 strlcpy(p
->state_message
, value
, sizeof(p
->state_message
));
1179 else if (!strcasecmp(line
, "StateTime"))
1182 * Set the state time...
1186 p
->state_time
= atoi(value
);
1188 else if (!strcasecmp(line
, "Accepting"))
1191 * Set the initial accepting state...
1195 (!strcasecmp(value
, "yes") ||
1196 !strcasecmp(value
, "on") ||
1197 !strcasecmp(value
, "true")))
1200 (!strcasecmp(value
, "no") ||
1201 !strcasecmp(value
, "off") ||
1202 !strcasecmp(value
, "false")))
1205 cupsdLogMessage(CUPSD_LOG_ERROR
,
1206 "Syntax error on line %d of printers.conf.", linenum
);
1208 else if (!strcasecmp(line
, "Type"))
1211 p
->type
= atoi(value
);
1213 cupsdLogMessage(CUPSD_LOG_ERROR
,
1214 "Syntax error on line %d of printers.conf.", linenum
);
1216 else if (!strcasecmp(line
, "Shared"))
1219 * Set the initial shared state...
1223 (!strcasecmp(value
, "yes") ||
1224 !strcasecmp(value
, "on") ||
1225 !strcasecmp(value
, "true")))
1228 (!strcasecmp(value
, "no") ||
1229 !strcasecmp(value
, "off") ||
1230 !strcasecmp(value
, "false")))
1233 cupsdLogMessage(CUPSD_LOG_ERROR
,
1234 "Syntax error on line %d of printers.conf.", linenum
);
1236 else if (!strcasecmp(line
, "JobSheets"))
1239 * Set the initial job sheets...
1244 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1249 cupsdSetString(&p
->job_sheets
[0], value
);
1251 while (isspace(*valueptr
& 255))
1256 for (value
= valueptr
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1261 cupsdSetString(&p
->job_sheets
[1], value
);
1265 cupsdLogMessage(CUPSD_LOG_ERROR
,
1266 "Syntax error on line %d of printers.conf.", linenum
);
1268 else if (!strcasecmp(line
, "AllowUser"))
1273 cupsdAddString(&(p
->users
), value
);
1276 cupsdLogMessage(CUPSD_LOG_ERROR
,
1277 "Syntax error on line %d of printers.conf.", linenum
);
1279 else if (!strcasecmp(line
, "DenyUser"))
1284 cupsdAddString(&(p
->users
), value
);
1287 cupsdLogMessage(CUPSD_LOG_ERROR
,
1288 "Syntax error on line %d of printers.conf.", linenum
);
1290 else if (!strcasecmp(line
, "QuotaPeriod"))
1293 p
->quota_period
= atoi(value
);
1295 cupsdLogMessage(CUPSD_LOG_ERROR
,
1296 "Syntax error on line %d of printers.conf.", linenum
);
1298 else if (!strcasecmp(line
, "PageLimit"))
1301 p
->page_limit
= atoi(value
);
1303 cupsdLogMessage(CUPSD_LOG_ERROR
,
1304 "Syntax error on line %d of printers.conf.", linenum
);
1306 else if (!strcasecmp(line
, "KLimit"))
1309 p
->k_limit
= atoi(value
);
1311 cupsdLogMessage(CUPSD_LOG_ERROR
,
1312 "Syntax error on line %d of printers.conf.", linenum
);
1314 else if (!strcasecmp(line
, "OpPolicy"))
1318 cupsd_policy_t
*pol
; /* Policy */
1321 if ((pol
= cupsdFindPolicy(value
)) != NULL
)
1323 cupsdSetString(&p
->op_policy
, value
);
1324 p
->op_policy_ptr
= pol
;
1327 cupsdLogMessage(CUPSD_LOG_ERROR
,
1328 "Bad policy \"%s\" on line %d of printers.conf",
1332 cupsdLogMessage(CUPSD_LOG_ERROR
,
1333 "Syntax error on line %d of printers.conf.", linenum
);
1335 else if (!strcasecmp(line
, "ErrorPolicy"))
1338 cupsdSetString(&p
->error_policy
, value
);
1340 cupsdLogMessage(CUPSD_LOG_ERROR
,
1341 "Syntax error on line %d of printers.conf.", linenum
);
1343 else if (!strcasecmp(line
, "Attribute") && value
)
1345 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1348 cupsdLogMessage(CUPSD_LOG_ERROR
,
1349 "Syntax error on line %d of printers.conf.", linenum
);
1352 for (; *valueptr
&& isspace(*valueptr
& 255); *valueptr
++ = '\0');
1355 cupsdSetPrinterAttrs(p
);
1357 if (!strcmp(value
, "marker-change-time"))
1358 p
->marker_time
= atoi(valueptr
);
1360 cupsdSetPrinterAttr(p
, value
, valueptr
);
1366 * Something else we don't understand...
1369 cupsdLogMessage(CUPSD_LOG_ERROR
,
1370 "Unknown configuration directive %s on line %d of printers.conf.",
1380 * 'cupsdRenamePrinter()' - Rename a printer.
1385 cupsd_printer_t
*p
, /* I - Printer */
1386 const char *name
) /* I - New name */
1389 * Remove the printer from the array(s) first...
1392 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1393 "cupsdRenamePrinter: Removing %s from Printers", p
->name
);
1394 cupsArrayRemove(Printers
, p
);
1396 if (p
->type
& CUPS_PRINTER_IMPLICIT
)
1398 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1399 "cupsdRenamePrinter: Removing %s from ImplicitPrinters",
1401 cupsArrayRemove(ImplicitPrinters
, p
);
1405 * Rename the printer type...
1408 mimeDeleteType(MimeDatabase
, p
->filetype
);
1409 p
->filetype
= mimeAddType(MimeDatabase
, "printer", name
);
1411 mimeDeleteType(MimeDatabase
, p
->prefiltertype
);
1412 p
->prefiltertype
= mimeAddType(MimeDatabase
, "prefilter", name
);
1415 * Rename the printer...
1418 cupsdSetString(&p
->name
, name
);
1421 * Reset printer attributes...
1424 cupsdSetPrinterAttrs(p
);
1427 * Add the printer back to the printer array(s)...
1430 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1431 "cupsdRenamePrinter: Adding %s to Printers", p
->name
);
1432 cupsArrayAdd(Printers
, p
);
1434 if (p
->type
& CUPS_PRINTER_IMPLICIT
)
1436 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1437 "cupsdRenamePrinter: Adding %s to ImplicitPrinters",
1439 cupsArrayAdd(ImplicitPrinters
, p
);
1445 * 'cupsdSaveAllPrinters()' - Save all printer definitions to the printers.conf
1450 cupsdSaveAllPrinters(void)
1452 int i
; /* Looping var */
1453 cups_file_t
*fp
; /* printers.conf file */
1454 char temp
[1024], /* Temporary string */
1455 backup
[1024], /* printers.conf.O file */
1456 value
[2048], /* Value string */
1457 *ptr
, /* Pointer into value */
1458 *name
; /* Current user/group name */
1459 cupsd_printer_t
*printer
; /* Current printer class */
1460 time_t curtime
; /* Current time */
1461 struct tm
*curdate
; /* Current date */
1462 cups_option_t
*option
; /* Current option */
1463 ipp_attribute_t
*marker
; /* Current marker attribute */
1467 * Create the printers.conf file...
1470 snprintf(temp
, sizeof(temp
), "%s/printers.conf", ServerRoot
);
1471 snprintf(backup
, sizeof(backup
), "%s/printers.conf.O", ServerRoot
);
1473 if (rename(temp
, backup
))
1475 if (errno
!= ENOENT
)
1476 cupsdLogMessage(CUPSD_LOG_ERROR
,
1477 "Unable to backup printers.conf - %s", strerror(errno
));
1480 if ((fp
= cupsFileOpen(temp
, "w")) == NULL
)
1482 cupsdLogMessage(CUPSD_LOG_ERROR
,
1483 "Unable to save printers.conf - %s", strerror(errno
));
1485 if (rename(backup
, temp
))
1486 cupsdLogMessage(CUPSD_LOG_ERROR
,
1487 "Unable to restore printers.conf - %s", strerror(errno
));
1491 cupsdLogMessage(CUPSD_LOG_INFO
, "Saving printers.conf...");
1494 * Restrict access to the file...
1497 fchown(cupsFileNumber(fp
), getuid(), Group
);
1498 fchmod(cupsFileNumber(fp
), ConfigFilePerm
& 0600);
1501 * Write a small header to the file...
1504 curtime
= time(NULL
);
1505 curdate
= localtime(&curtime
);
1506 strftime(temp
, sizeof(temp
) - 1, "%Y-%m-%d %H:%M", curdate
);
1508 cupsFilePuts(fp
, "# Printer configuration file for " CUPS_SVERSION
"\n");
1509 cupsFilePrintf(fp
, "# Written by cupsd on %s\n", temp
);
1510 cupsFilePuts(fp
, "# DO NOT EDIT THIS FILE WHEN CUPSD IS RUNNING\n");
1513 * Write each local printer known to the system...
1516 for (printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
1518 printer
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
1521 * Skip remote destinations and printer classes...
1524 if ((printer
->type
& CUPS_PRINTER_DISCOVERED
) ||
1525 (printer
->type
& CUPS_PRINTER_CLASS
) ||
1526 (printer
->type
& CUPS_PRINTER_IMPLICIT
))
1530 * Write printers as needed...
1533 if (printer
== DefaultPrinter
)
1534 cupsFilePrintf(fp
, "<DefaultPrinter %s>\n", printer
->name
);
1536 cupsFilePrintf(fp
, "<Printer %s>\n", printer
->name
);
1538 cupsFilePrintf(fp
, "UUID %s\n", printer
->uuid
);
1540 if (printer
->num_auth_info_required
> 0)
1542 switch (printer
->num_auth_info_required
)
1545 strlcpy(value
, printer
->auth_info_required
[0], sizeof(value
));
1549 snprintf(value
, sizeof(value
), "%s,%s",
1550 printer
->auth_info_required
[0],
1551 printer
->auth_info_required
[1]);
1556 snprintf(value
, sizeof(value
), "%s,%s,%s",
1557 printer
->auth_info_required
[0],
1558 printer
->auth_info_required
[1],
1559 printer
->auth_info_required
[2]);
1563 cupsFilePutConf(fp
, "AuthInfoRequired", value
);
1567 cupsFilePutConf(fp
, "Info", printer
->info
);
1569 if (printer
->location
)
1570 cupsFilePutConf(fp
, "Location", printer
->location
);
1572 if (printer
->make_model
)
1573 cupsFilePutConf(fp
, "MakeModel", printer
->make_model
);
1575 cupsFilePutConf(fp
, "DeviceURI", printer
->device_uri
);
1577 if (printer
->port_monitor
)
1578 cupsFilePutConf(fp
, "PortMonitor", printer
->port_monitor
);
1580 if (printer
->state
== IPP_PRINTER_STOPPED
)
1582 cupsFilePuts(fp
, "State Stopped\n");
1584 if (printer
->state_message
)
1585 cupsFilePutConf(fp
, "StateMessage", printer
->state_message
);
1588 cupsFilePuts(fp
, "State Idle\n");
1590 cupsFilePrintf(fp
, "StateTime %d\n", (int)printer
->state_time
);
1592 for (i
= 0; i
< printer
->num_reasons
; i
++)
1593 if (strcmp(printer
->reasons
[i
], "connecting-to-device") &&
1594 strcmp(printer
->reasons
[i
], "cups-insecure-filter-warning") &&
1595 strcmp(printer
->reasons
[i
], "cups-missing-filter-warning"))
1596 cupsFilePutConf(fp
, "Reason", printer
->reasons
[i
]);
1598 cupsFilePrintf(fp
, "Type %d\n", printer
->type
);
1600 if (printer
->accepting
)
1601 cupsFilePuts(fp
, "Accepting Yes\n");
1603 cupsFilePuts(fp
, "Accepting No\n");
1605 if (printer
->shared
)
1606 cupsFilePuts(fp
, "Shared Yes\n");
1608 cupsFilePuts(fp
, "Shared No\n");
1610 snprintf(value
, sizeof(value
), "%s %s", printer
->job_sheets
[0],
1611 printer
->job_sheets
[1]);
1612 cupsFilePutConf(fp
, "JobSheets", value
);
1614 cupsFilePrintf(fp
, "QuotaPeriod %d\n", printer
->quota_period
);
1615 cupsFilePrintf(fp
, "PageLimit %d\n", printer
->page_limit
);
1616 cupsFilePrintf(fp
, "KLimit %d\n", printer
->k_limit
);
1618 for (name
= (char *)cupsArrayFirst(printer
->users
);
1620 name
= (char *)cupsArrayNext(printer
->users
))
1621 cupsFilePutConf(fp
, printer
->deny_users
? "DenyUser" : "AllowUser", name
);
1623 if (printer
->op_policy
)
1624 cupsFilePutConf(fp
, "OpPolicy", printer
->op_policy
);
1625 if (printer
->error_policy
)
1626 cupsFilePutConf(fp
, "ErrorPolicy", printer
->error_policy
);
1628 for (i
= printer
->num_options
, option
= printer
->options
;
1632 snprintf(value
, sizeof(value
), "%s %s", option
->name
, option
->value
);
1633 cupsFilePutConf(fp
, "Option", value
);
1636 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-colors",
1637 IPP_TAG_NAME
)) != NULL
)
1639 snprintf(value
, sizeof(value
), "%s ", marker
->name
);
1641 for (i
= 0, ptr
= value
+ strlen(value
);
1642 i
< marker
->num_values
&& ptr
< (value
+ sizeof(value
) - 1);
1648 strlcpy(ptr
, marker
->values
[i
].string
.text
,
1649 value
+ sizeof(value
) - ptr
);
1654 cupsFilePutConf(fp
, "Attribute", value
);
1657 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-levels",
1658 IPP_TAG_INTEGER
)) != NULL
)
1660 cupsFilePrintf(fp
, "Attribute %s %d", marker
->name
,
1661 marker
->values
[0].integer
);
1662 for (i
= 1; i
< marker
->num_values
; i
++)
1663 cupsFilePrintf(fp
, ",%d", marker
->values
[i
].integer
);
1664 cupsFilePuts(fp
, "\n");
1667 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-low-levels",
1668 IPP_TAG_INTEGER
)) != NULL
)
1670 cupsFilePrintf(fp
, "Attribute %s %d", marker
->name
,
1671 marker
->values
[0].integer
);
1672 for (i
= 1; i
< marker
->num_values
; i
++)
1673 cupsFilePrintf(fp
, ",%d", marker
->values
[i
].integer
);
1674 cupsFilePuts(fp
, "\n");
1677 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-high-levels",
1678 IPP_TAG_INTEGER
)) != NULL
)
1680 cupsFilePrintf(fp
, "Attribute %s %d", marker
->name
,
1681 marker
->values
[0].integer
);
1682 for (i
= 1; i
< marker
->num_values
; i
++)
1683 cupsFilePrintf(fp
, ",%d", marker
->values
[i
].integer
);
1684 cupsFilePuts(fp
, "\n");
1687 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-message",
1688 IPP_TAG_TEXT
)) != NULL
)
1690 snprintf(value
, sizeof(value
), "%s %s", marker
->name
,
1691 marker
->values
[0].string
.text
);
1693 cupsFilePutConf(fp
, "Attribute", value
);
1696 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-names",
1697 IPP_TAG_NAME
)) != NULL
)
1699 snprintf(value
, sizeof(value
), "%s ", marker
->name
);
1701 for (i
= 0, ptr
= value
+ strlen(value
);
1702 i
< marker
->num_values
&& ptr
< (value
+ sizeof(value
) - 1);
1708 strlcpy(ptr
, marker
->values
[i
].string
.text
,
1709 value
+ sizeof(value
) - ptr
);
1714 cupsFilePutConf(fp
, "Attribute", value
);
1717 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-types",
1718 IPP_TAG_KEYWORD
)) != NULL
)
1720 snprintf(value
, sizeof(value
), "%s ", marker
->name
);
1722 for (i
= 0, ptr
= value
+ strlen(value
);
1723 i
< marker
->num_values
&& ptr
< (value
+ sizeof(value
) - 1);
1729 strlcpy(ptr
, marker
->values
[i
].string
.text
,
1730 value
+ sizeof(value
) - ptr
);
1735 cupsFilePutConf(fp
, "Attribute", value
);
1738 if (printer
->marker_time
)
1739 cupsFilePrintf(fp
, "Attribute marker-change-time %ld\n",
1740 (long)printer
->marker_time
);
1742 cupsFilePuts(fp
, "</Printer>\n");
1746 * Make IRIX desktop & printer status happy
1749 write_irix_state(printer
);
1758 * 'cupsdSetAuthInfoRequired()' - Set the required authentication info.
1761 int /* O - 1 if value OK, 0 otherwise */
1762 cupsdSetAuthInfoRequired(
1763 cupsd_printer_t
*p
, /* I - Printer */
1764 const char *values
, /* I - Plain text value (or NULL) */
1765 ipp_attribute_t
*attr
) /* I - IPP attribute value (or NULL) */
1767 int i
; /* Looping var */
1770 p
->num_auth_info_required
= 0;
1773 * Do we have a plain text value?
1779 * Yes, grab the keywords...
1782 const char *end
; /* End of current value */
1785 while (*values
&& p
->num_auth_info_required
< 4)
1787 if ((end
= strchr(values
, ',')) == NULL
)
1788 end
= values
+ strlen(values
);
1790 if ((end
- values
) == 4 && !strncmp(values
, "none", 4))
1792 if (p
->num_auth_info_required
!= 0 || *end
)
1795 p
->auth_info_required
[p
->num_auth_info_required
] = "none";
1796 p
->num_auth_info_required
++;
1800 else if ((end
- values
) == 9 && !strncmp(values
, "negotiate", 9))
1802 if (p
->num_auth_info_required
!= 0 || *end
)
1805 p
->auth_info_required
[p
->num_auth_info_required
] = "negotiate";
1806 p
->num_auth_info_required
++;
1808 else if ((end
- values
) == 6 && !strncmp(values
, "domain", 6))
1810 p
->auth_info_required
[p
->num_auth_info_required
] = "domain";
1811 p
->num_auth_info_required
++;
1813 else if ((end
- values
) == 8 && !strncmp(values
, "password", 8))
1815 p
->auth_info_required
[p
->num_auth_info_required
] = "password";
1816 p
->num_auth_info_required
++;
1818 else if ((end
- values
) == 8 && !strncmp(values
, "username", 8))
1820 p
->auth_info_required
[p
->num_auth_info_required
] = "username";
1821 p
->num_auth_info_required
++;
1826 values
= (*end
) ? end
+ 1 : end
;
1829 if (p
->num_auth_info_required
== 0)
1831 p
->auth_info_required
[0] = "none";
1832 p
->num_auth_info_required
= 1;
1836 * Update the printer-type value as needed...
1839 if (p
->num_auth_info_required
> 1 ||
1840 strcmp(p
->auth_info_required
[0], "none"))
1841 p
->type
|= CUPS_PRINTER_AUTHENTICATED
;
1843 p
->type
&= ~CUPS_PRINTER_AUTHENTICATED
;
1849 * Grab values from an attribute instead...
1852 if (!attr
|| attr
->num_values
> 4)
1856 * Update the printer-type value as needed...
1859 if (attr
->num_values
> 1 ||
1860 strcmp(attr
->values
[0].string
.text
, "none"))
1861 p
->type
|= CUPS_PRINTER_AUTHENTICATED
;
1863 p
->type
&= ~CUPS_PRINTER_AUTHENTICATED
;
1865 for (i
= 0; i
< attr
->num_values
; i
++)
1867 if (!strcmp(attr
->values
[i
].string
.text
, "none"))
1869 if (p
->num_auth_info_required
!= 0 || attr
->num_values
!= 1)
1872 p
->auth_info_required
[p
->num_auth_info_required
] = "none";
1873 p
->num_auth_info_required
++;
1877 else if (!strcmp(attr
->values
[i
].string
.text
, "negotiate"))
1879 if (p
->num_auth_info_required
!= 0 || attr
->num_values
!= 1)
1882 p
->auth_info_required
[p
->num_auth_info_required
] = "negotiate";
1883 p
->num_auth_info_required
++;
1887 else if (!strcmp(attr
->values
[i
].string
.text
, "domain"))
1889 p
->auth_info_required
[p
->num_auth_info_required
] = "domain";
1890 p
->num_auth_info_required
++;
1892 else if (!strcmp(attr
->values
[i
].string
.text
, "password"))
1894 p
->auth_info_required
[p
->num_auth_info_required
] = "password";
1895 p
->num_auth_info_required
++;
1897 else if (!strcmp(attr
->values
[i
].string
.text
, "username"))
1899 p
->auth_info_required
[p
->num_auth_info_required
] = "username";
1900 p
->num_auth_info_required
++;
1911 * 'cupsdSetDeviceURI()' - Set the device URI for a printer.
1915 cupsdSetDeviceURI(cupsd_printer_t
*p
, /* I - Printer */
1916 const char *uri
) /* I - Device URI */
1918 char buffer
[1024], /* URI buffer */
1919 *start
, /* Start of data after scheme */
1920 *slash
, /* First slash after scheme:// */
1921 *ptr
; /* Pointer into user@host:port part */
1925 * Set the full device URI..
1928 cupsdSetString(&(p
->device_uri
), uri
);
1931 * Copy the device URI to a temporary buffer so we can sanitize any auth
1935 strlcpy(buffer
, uri
, sizeof(buffer
));
1938 * Find the end of the scheme:// part...
1941 if ((ptr
= strchr(buffer
, ':')) != NULL
)
1943 for (start
= ptr
+ 1; *start
; start
++)
1948 * Find the next slash (/) in the URI...
1951 if ((slash
= strchr(start
, '/')) == NULL
)
1952 slash
= start
+ strlen(start
); /* No slash, point to the end */
1955 * Check for an @ sign before the slash...
1958 if ((ptr
= strchr(start
, '@')) != NULL
&& ptr
< slash
)
1961 * Found an @ sign and it is before the resource part, so we have
1962 * an authentication string. Copy the remaining URI over the
1963 * authentication string...
1966 _cups_strcpy(start
, ptr
+ 1);
1971 * Save the sanitized URI...
1974 cupsdSetString(&(p
->sanitized_device_uri
), buffer
);
1979 * 'cupsdSetPrinterAttr()' - Set a printer attribute.
1983 cupsdSetPrinterAttr(
1984 cupsd_printer_t
*p
, /* I - Printer */
1985 const char *name
, /* I - Attribute name */
1986 char *value
) /* I - Attribute value string */
1988 ipp_attribute_t
*attr
; /* Attribute */
1989 int i
, /* Looping var */
1990 count
; /* Number of values */
1991 char *ptr
; /* Pointer into value */
1992 ipp_tag_t value_tag
; /* Value tag for this attribute */
1996 * Don't allow empty values...
1999 if (!*value
&& strcmp(name
, "marker-message"))
2001 cupsdLogMessage(CUPSD_LOG_ERROR
, "Ignoring empty \"%s\" attribute", name
);
2006 * Count the number of values...
2009 for (count
= 1, ptr
= value
;
2010 (ptr
= strchr(ptr
, ',')) != NULL
;
2014 * Then add or update the attribute as needed...
2017 if (!strcmp(name
, "marker-levels") || !strcmp(name
, "marker-low-levels") ||
2018 !strcmp(name
, "marker-high-levels"))
2024 if ((attr
= ippFindAttribute(p
->attrs
, name
, IPP_TAG_INTEGER
)) != NULL
&&
2025 attr
->num_values
< count
)
2027 ippDeleteAttribute(p
->attrs
, attr
);
2032 attr
->num_values
= count
;
2034 attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
, name
,
2039 cupsdLogMessage(CUPSD_LOG_ERROR
,
2040 "Unable to allocate memory for printer attribute "
2041 "(%d values)", count
);
2045 for (i
= 0; i
< count
; i
++)
2047 if ((ptr
= strchr(value
, ',')) != NULL
)
2050 attr
->values
[i
].integer
= strtol(value
, NULL
, 10);
2059 * Name or keyword values...
2062 if (!strcmp(name
, "marker-types"))
2063 value_tag
= IPP_TAG_KEYWORD
;
2064 else if (!strcmp(name
, "marker-message"))
2065 value_tag
= IPP_TAG_TEXT
;
2067 value_tag
= IPP_TAG_NAME
;
2069 if ((attr
= ippFindAttribute(p
->attrs
, name
, value_tag
)) != NULL
&&
2070 attr
->num_values
< count
)
2072 ippDeleteAttribute(p
->attrs
, attr
);
2078 for (i
= 0; i
< attr
->num_values
; i
++)
2079 _cupsStrFree(attr
->values
[i
].string
.text
);
2081 attr
->num_values
= count
;
2084 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, value_tag
, name
,
2089 cupsdLogMessage(CUPSD_LOG_ERROR
,
2090 "Unable to allocate memory for printer attribute "
2091 "(%d values)", count
);
2095 for (i
= 0; i
< count
; i
++)
2097 if ((ptr
= strchr(value
, ',')) != NULL
)
2100 attr
->values
[i
].string
.text
= _cupsStrAlloc(value
);
2110 * 'cupsdSetPrinterAttrs()' - Set printer attributes based upon the PPD file.
2114 cupsdSetPrinterAttrs(cupsd_printer_t
*p
)/* I - Printer to setup */
2116 int i
, /* Looping var */
2117 length
; /* Length of browse attributes */
2118 char resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
2119 int num_air
; /* Number of auth-info-required values */
2120 const char * const *air
; /* auth-info-required values */
2121 cupsd_location_t
*auth
; /* Pointer to authentication element */
2122 const char *auth_supported
; /* Authentication supported */
2123 ipp_t
*oldattrs
; /* Old printer attributes */
2124 ipp_attribute_t
*attr
; /* Attribute data */
2125 cups_option_t
*option
; /* Current printer option */
2126 char *name
, /* Current user/group name */
2127 *filter
; /* Current filter */
2128 static const char * const air_none
[] =
2129 { /* No authentication */
2132 static const char * const air_userpass
[] =
2133 { /* Basic/Digest authentication */
2139 DEBUG_printf(("cupsdSetPrinterAttrs: entering name = %s, type = %x\n", p
->name
,
2143 * Make sure that we have the common attributes defined...
2147 cupsdCreateCommonData();
2150 * Clear out old filters, if any...
2153 delete_printer_filters(p
);
2156 * Figure out the authentication that is required for the printer.
2159 auth_supported
= "requesting-user-name";
2163 if (p
->num_auth_info_required
> 0 && strcmp(p
->auth_info_required
[0], "none"))
2165 num_air
= p
->num_auth_info_required
;
2166 air
= p
->auth_info_required
;
2168 else if ((p
->type
& CUPS_PRINTER_AUTHENTICATED
) &&
2169 (p
->type
& CUPS_PRINTER_DISCOVERED
))
2175 if (p
->type
& CUPS_PRINTER_CLASS
)
2176 snprintf(resource
, sizeof(resource
), "/classes/%s", p
->name
);
2178 snprintf(resource
, sizeof(resource
), "/printers/%s", p
->name
);
2180 if ((auth
= cupsdFindBest(resource
, HTTP_POST
)) == NULL
||
2181 auth
->type
== CUPSD_AUTH_NONE
)
2182 auth
= cupsdFindPolicyOp(p
->op_policy_ptr
, IPP_PRINT_JOB
);
2186 int auth_type
; /* Authentication type */
2189 if ((auth_type
= auth
->type
) == CUPSD_AUTH_DEFAULT
)
2190 auth_type
= DefaultAuthType
;
2192 if (auth_type
== CUPSD_AUTH_BASIC
|| auth_type
== CUPSD_AUTH_BASICDIGEST
)
2193 auth_supported
= "basic";
2194 else if (auth_type
== CUPSD_AUTH_DIGEST
)
2195 auth_supported
= "digest";
2197 else if (auth_type
== CUPSD_AUTH_NEGOTIATE
)
2198 auth_supported
= "negotiate";
2199 #endif /* HAVE_GSSAPI */
2201 if (!(p
->type
& CUPS_PRINTER_DISCOVERED
))
2203 if (auth_type
!= CUPSD_AUTH_NONE
)
2204 p
->type
|= CUPS_PRINTER_AUTHENTICATED
;
2206 p
->type
&= ~CUPS_PRINTER_AUTHENTICATED
;
2209 else if (!(p
->type
& CUPS_PRINTER_DISCOVERED
))
2210 p
->type
&= ~CUPS_PRINTER_AUTHENTICATED
;
2213 * Create the required IPP attributes for a printer...
2216 oldattrs
= p
->attrs
;
2217 p
->attrs
= ippNew();
2219 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2220 "uri-authentication-supported", NULL
, auth_supported
);
2221 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2222 "uri-security-supported", NULL
, "none");
2223 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
, "printer-name", NULL
,
2225 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-location",
2226 NULL
, p
->location
? p
->location
: "");
2227 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-info",
2228 NULL
, p
->info
? p
->info
: "");
2229 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "printer-uuid", NULL
,
2232 if (cupsArrayCount(p
->users
) > 0)
2235 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2236 "requesting-user-name-denied",
2237 cupsArrayCount(p
->users
), NULL
, NULL
);
2239 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2240 "requesting-user-name-allowed",
2241 cupsArrayCount(p
->users
), NULL
, NULL
);
2243 for (i
= 0, name
= (char *)cupsArrayFirst(p
->users
);
2245 i
++, name
= (char *)cupsArrayNext(p
->users
))
2246 attr
->values
[i
].string
.text
= _cupsStrRetain(name
);
2249 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2250 "job-quota-period", p
->quota_period
);
2251 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2252 "job-k-limit", p
->k_limit
);
2253 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2254 "job-page-limit", p
->page_limit
);
2255 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2256 "auth-info-required", num_air
, NULL
, air
);
2258 if (cupsArrayCount(Banners
) > 0 && !(p
->type
& CUPS_PRINTER_DISCOVERED
))
2261 * Setup the job-sheets-default attribute...
2264 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2265 "job-sheets-default", 2, NULL
, NULL
);
2269 attr
->values
[0].string
.text
= _cupsStrAlloc(Classification
?
2270 Classification
: p
->job_sheets
[0]);
2271 attr
->values
[1].string
.text
= _cupsStrAlloc(Classification
?
2272 Classification
: p
->job_sheets
[1]);
2279 if (p
->type
& CUPS_PRINTER_DISCOVERED
)
2282 * Tell the client this is a remote printer of some type...
2285 if (strchr(p
->uri
, '?'))
2288 * Strip trailing "?options" from URI...
2291 char *ptr
; /* Pointer into URI */
2293 strlcpy(resource
, p
->uri
, sizeof(resource
));
2294 if ((ptr
= strchr(resource
, '?')) != NULL
)
2297 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
2298 "printer-uri-supported", NULL
, resource
);
2301 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
2302 "printer-uri-supported", NULL
, p
->uri
);
2304 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "printer-more-info",
2308 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
2309 "printer-make-and-model", NULL
, p
->make_model
);
2311 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "device-uri", NULL
,
2320 * Assign additional attributes depending on whether this is a printer
2324 if (p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
))
2327 p
->type
&= ~CUPS_PRINTER_OPTIONS
;
2330 * Add class-specific attributes...
2333 if ((p
->type
& CUPS_PRINTER_IMPLICIT
) && p
->num_printers
> 0 &&
2334 p
->printers
[0]->make_model
)
2335 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
2336 "printer-make-and-model", NULL
, p
->printers
[0]->make_model
);
2338 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
2339 "printer-make-and-model", NULL
, "Local Printer Class");
2341 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "device-uri", NULL
,
2342 "file:///dev/null");
2344 if (p
->num_printers
> 0)
2347 * Add a list of member names; URIs are added in copy_printer_attrs...
2350 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2351 "member-names", p
->num_printers
, NULL
, NULL
);
2352 p
->type
|= CUPS_PRINTER_OPTIONS
;
2354 for (i
= 0; i
< p
->num_printers
; i
++)
2357 attr
->values
[i
].string
.text
= _cupsStrRetain(p
->printers
[i
]->name
);
2359 p
->type
&= ~CUPS_PRINTER_OPTIONS
| p
->printers
[i
]->type
;
2366 * Add printer-specific attributes...
2369 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "device-uri", NULL
,
2370 p
->sanitized_device_uri
);
2373 * Assign additional attributes from the PPD file (if any)...
2379 * Add filters for printer...
2382 cupsdSetPrinterReasons(p
, "-cups-missing-filter-warning,"
2383 "cups-insecure-filter-warning");
2385 if (p
->pc
&& p
->pc
->filters
)
2387 for (filter
= (char *)cupsArrayFirst(p
->pc
->filters
);
2389 filter
= (char *)cupsArrayNext(p
->pc
->filters
))
2390 add_printer_filter(p
, p
->filetype
, filter
);
2392 else if (!(p
->type
& CUPS_PRINTER_REMOTE
))
2394 char interface
[1024]; /* Interface script */
2397 snprintf(interface
, sizeof(interface
), "%s/interfaces/%s", ServerRoot
,
2399 if (!access(interface
, X_OK
))
2402 * Yes, we have a System V style interface script; use it!
2405 snprintf(interface
, sizeof(interface
), "*/* 0 %s/interfaces/%s",
2406 ServerRoot
, p
->name
);
2407 add_printer_filter(p
, p
->filetype
, interface
);
2412 * Add a filter from application/vnd.cups-raw to printer/name to
2413 * handle "raw" printing by users.
2416 add_printer_filter(p
, p
->filetype
, "application/vnd.cups-raw 0 -");
2419 * Add a PostScript filter, since this is still possibly PS printer.
2422 add_printer_filter(p
, p
->filetype
,
2423 "application/vnd.cups-postscript 0 -");
2427 if (p
->pc
&& p
->pc
->prefilters
)
2429 p
->prefiltertype
= mimeAddType(MimeDatabase
, "prefilter", p
->name
);
2431 for (filter
= (char *)cupsArrayFirst(p
->pc
->prefilters
);
2433 filter
= (char *)cupsArrayNext(p
->pc
->prefilters
))
2434 add_printer_filter(p
, p
->prefiltertype
, filter
);
2440 * Copy marker attributes as needed...
2445 ipp_attribute_t
*oldattr
; /* Old attribute */
2448 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-colors",
2449 IPP_TAG_NAME
)) != NULL
)
2451 if ((attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2452 "marker-colors", oldattr
->num_values
, NULL
,
2455 for (i
= 0; i
< oldattr
->num_values
; i
++)
2456 attr
->values
[i
].string
.text
=
2457 _cupsStrRetain(oldattr
->values
[i
].string
.text
);
2461 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-levels",
2462 IPP_TAG_INTEGER
)) != NULL
)
2464 if ((attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2465 "marker-levels", oldattr
->num_values
,
2468 for (i
= 0; i
< oldattr
->num_values
; i
++)
2469 attr
->values
[i
].integer
= oldattr
->values
[i
].integer
;
2473 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-message",
2474 IPP_TAG_TEXT
)) != NULL
)
2475 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "marker-message",
2476 NULL
, oldattr
->values
[0].string
.text
);
2478 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-low-levels",
2479 IPP_TAG_INTEGER
)) != NULL
)
2481 if ((attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2482 "marker-low-levels", oldattr
->num_values
,
2485 for (i
= 0; i
< oldattr
->num_values
; i
++)
2486 attr
->values
[i
].integer
= oldattr
->values
[i
].integer
;
2490 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-high-levels",
2491 IPP_TAG_INTEGER
)) != NULL
)
2493 if ((attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2494 "marker-high-levels", oldattr
->num_values
,
2497 for (i
= 0; i
< oldattr
->num_values
; i
++)
2498 attr
->values
[i
].integer
= oldattr
->values
[i
].integer
;
2502 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-names",
2503 IPP_TAG_NAME
)) != NULL
)
2505 if ((attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2506 "marker-names", oldattr
->num_values
, NULL
,
2509 for (i
= 0; i
< oldattr
->num_values
; i
++)
2510 attr
->values
[i
].string
.text
=
2511 _cupsStrRetain(oldattr
->values
[i
].string
.text
);
2515 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-types",
2516 IPP_TAG_KEYWORD
)) != NULL
)
2518 if ((attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2519 "marker-types", oldattr
->num_values
, NULL
,
2522 for (i
= 0; i
< oldattr
->num_values
; i
++)
2523 attr
->values
[i
].string
.text
=
2524 _cupsStrRetain(oldattr
->values
[i
].string
.text
);
2528 ippDelete(oldattrs
);
2532 * Force sharing off for remote queues...
2535 if (p
->type
& (CUPS_PRINTER_REMOTE
| CUPS_PRINTER_IMPLICIT
))
2540 * Copy the printer options into a browse attributes string we can re-use.
2543 const char *valptr
; /* Pointer into value */
2544 char *attrptr
; /* Pointer into attribute string */
2548 * Free the old browse attributes as needed...
2551 if (p
->browse_attrs
)
2552 free(p
->browse_attrs
);
2555 * Compute the length of all attributes + job-sheets, lease-duration,
2556 * and BrowseLocalOptions.
2559 for (length
= 1, i
= p
->num_options
, option
= p
->options
;
2563 length
+= strlen(option
->name
) + 2;
2567 for (valptr
= option
->value
; *valptr
; valptr
++)
2568 if (strchr(" \"\'\\", *valptr
))
2575 length
+= 13 + strlen(p
->job_sheets
[0]) + strlen(p
->job_sheets
[1]);
2577 if (BrowseLocalOptions
)
2578 length
+= 12 + strlen(BrowseLocalOptions
);
2581 * Allocate the new string...
2584 if ((p
->browse_attrs
= calloc(1, length
)) == NULL
)
2585 cupsdLogMessage(CUPSD_LOG_ERROR
,
2586 "Unable to allocate %d bytes for browse data!",
2591 * Got the allocated string, now copy the options and attributes over...
2594 sprintf(p
->browse_attrs
, "job-sheets=%s,%s lease-duration=%d",
2595 p
->job_sheets
[0], p
->job_sheets
[1], BrowseTimeout
);
2596 attrptr
= p
->browse_attrs
+ strlen(p
->browse_attrs
);
2598 if (BrowseLocalOptions
)
2600 sprintf(attrptr
, " ipp-options=%s", BrowseLocalOptions
);
2601 attrptr
+= strlen(attrptr
);
2604 for (i
= p
->num_options
, option
= p
->options
;
2609 strcpy(attrptr
, option
->name
);
2610 attrptr
+= strlen(attrptr
);
2616 for (valptr
= option
->value
; *valptr
; valptr
++)
2618 if (strchr(" \"\'\\", *valptr
))
2621 *attrptr
++ = *valptr
;
2629 * Populate the document-format-supported attribute...
2632 add_printer_formats(p
);
2634 DEBUG_printf(("cupsdSetPrinterAttrs: leaving name = %s, type = %x\n", p
->name
,
2638 * Add name-default attributes...
2641 add_printer_defaults(p
);
2645 * Write the IRIX printer config and status files...
2648 write_irix_config(p
);
2649 write_irix_state(p
);
2653 * Let the browse protocols reflect the change
2656 cupsdRegisterPrinter(p
);
2661 * 'cupsdSetPrinterReasons()' - Set/update the reasons strings.
2664 int /* O - 1 if something changed, 0 otherwise */
2665 cupsdSetPrinterReasons(
2666 cupsd_printer_t
*p
, /* I - Printer */
2667 const char *s
) /* I - Reasons strings */
2669 int i
, /* Looping var */
2670 changed
= 0; /* Did something change? */
2671 const char *sptr
; /* Pointer into reasons */
2672 char reason
[255], /* Reason string */
2673 *rptr
; /* Pointer into reason */
2676 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
2677 "cupsdSetPrinterReasons(p=%p(%s),s=\"%s\"", p
, p
->name
, s
);
2679 if (s
[0] == '-' || s
[0] == '+')
2682 * Add/remove reasons...
2690 * Replace reasons...
2695 for (i
= 0; i
< p
->num_reasons
; i
++)
2696 _cupsStrFree(p
->reasons
[i
]);
2704 if (!strcmp(s
, "none"))
2708 * Loop through all of the reasons...
2714 * Skip leading whitespace and commas...
2717 while (isspace(*sptr
& 255) || *sptr
== ',')
2720 for (rptr
= reason
; *sptr
&& !isspace(*sptr
& 255) && *sptr
!= ','; sptr
++)
2721 if (rptr
< (reason
+ sizeof(reason
) - 1))
2735 for (i
= 0; i
< p
->num_reasons
; i
++)
2736 if (!strcmp(reason
, p
->reasons
[i
]))
2739 * Found a match, so remove it...
2744 _cupsStrFree(p
->reasons
[i
]);
2746 if (i
< p
->num_reasons
)
2747 memmove(p
->reasons
+ i
, p
->reasons
+ i
+ 1,
2748 (p
->num_reasons
- i
) * sizeof(char *));
2750 if (!strcmp(reason
, "paused") && p
->state
== IPP_PRINTER_STOPPED
)
2751 cupsdSetPrinterState(p
, IPP_PRINTER_IDLE
, 1);
2753 if (strcmp(reason
, "connecting-to-device"))
2758 else if (p
->num_reasons
< (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
2764 for (i
= 0; i
< p
->num_reasons
; i
++)
2765 if (!strcmp(reason
, p
->reasons
[i
]))
2768 if (i
>= p
->num_reasons
)
2770 if (i
>= (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
2772 cupsdLogMessage(CUPSD_LOG_ALERT
,
2773 "Too many printer-state-reasons values for %s (%d)",
2778 p
->reasons
[i
] = _cupsStrAlloc(reason
);
2782 if (!strcmp(reason
, "paused") && p
->state
!= IPP_PRINTER_STOPPED
)
2783 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, 1);
2785 if (strcmp(reason
, "connecting-to-device"))
2796 * 'cupsdSetPrinterState()' - Update the current state of a printer.
2800 cupsdSetPrinterState(
2801 cupsd_printer_t
*p
, /* I - Printer to change */
2802 ipp_pstate_t s
, /* I - New state */
2803 int update
) /* I - Update printers.conf? */
2805 ipp_pstate_t old_state
; /* Old printer state */
2806 static const char * const printer_states
[] =
2807 { /* State strings */
2815 * Can't set status of remote printers...
2818 if (p
->type
& CUPS_PRINTER_DISCOVERED
)
2822 * Set the new state...
2825 old_state
= p
->state
;
2830 cupsdAddEvent(s
== IPP_PRINTER_STOPPED
? CUPSD_EVENT_PRINTER_STOPPED
:
2831 CUPSD_EVENT_PRINTER_STATE
, p
, NULL
,
2832 "%s \"%s\" state changed to %s.",
2833 (p
->type
& CUPS_PRINTER_CLASS
) ? "Class" : "Printer",
2834 p
->name
, printer_states
[p
->state
- IPP_PRINTER_IDLE
]);
2837 * Let the browse code know this needs to be updated...
2841 p
->state_time
= time(NULL
);
2845 write_irix_state(p
);
2850 * Set/clear the paused reason as needed...
2853 if (s
== IPP_PRINTER_STOPPED
)
2854 cupsdSetPrinterReasons(p
, "+paused");
2856 cupsdSetPrinterReasons(p
, "-paused");
2859 * Clear the message for the queue when going to processing...
2862 if (s
== IPP_PRINTER_PROCESSING
)
2863 p
->state_message
[0] = '\0';
2866 * Let the browse protocols reflect the change...
2870 cupsdRegisterPrinter(p
);
2873 * Save the printer configuration if a printer goes from idle or processing
2874 * to stopped (or visa-versa)...
2878 (old_state
== IPP_PRINTER_STOPPED
) != (s
== IPP_PRINTER_STOPPED
))
2884 * 'cupsdStopPrinter()' - Stop a printer from printing any jobs...
2888 cupsdStopPrinter(cupsd_printer_t
*p
, /* I - Printer to stop */
2889 int update
)/* I - Update printers.conf? */
2892 * Set the printer state...
2895 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, update
);
2898 * See if we have a job printing on this printer...
2901 if (p
->job
&& p
->job
->state_value
== IPP_JOB_PROCESSING
)
2902 cupsdSetJobState(p
->job
, IPP_JOB_PENDING
, CUPSD_JOB_DEFAULT
,
2903 "Job stopped due to printer being paused.");
2908 * 'cupsdUpdatePrinterPPD()' - Update keywords in a printer's PPD file.
2911 int /* O - 1 if successful, 0 otherwise */
2912 cupsdUpdatePrinterPPD(
2913 cupsd_printer_t
*p
, /* I - Printer */
2914 int num_keywords
, /* I - Number of keywords */
2915 cups_option_t
*keywords
) /* I - Keywords */
2917 int i
; /* Looping var */
2918 cups_file_t
*src
, /* Original file */
2919 *dst
; /* New file */
2920 char srcfile
[1024], /* Original filename */
2921 dstfile
[1024], /* New filename */
2922 line
[1024], /* Line from file */
2923 keystring
[41]; /* Keyword from line */
2924 cups_option_t
*keyword
; /* Current keyword */
2927 cupsdLogMessage(CUPSD_LOG_INFO
, "Updating keywords in PPD file for %s...",
2931 * Get the old and new PPD filenames...
2934 snprintf(srcfile
, sizeof(srcfile
), "%s/ppd/%s.ppd.O", ServerRoot
, p
->name
);
2935 snprintf(dstfile
, sizeof(srcfile
), "%s/ppd/%s.ppd", ServerRoot
, p
->name
);
2938 * Rename the old file and open the old and new...
2941 if (rename(dstfile
, srcfile
))
2943 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to backup PPD file for %s: %s",
2944 p
->name
, strerror(errno
));
2948 if ((src
= cupsFileOpen(srcfile
, "r")) == NULL
)
2950 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to open PPD file \"%s\": %s",
2951 srcfile
, strerror(errno
));
2952 rename(srcfile
, dstfile
);
2956 if ((dst
= cupsFileOpen(dstfile
, "w")) == NULL
)
2958 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to create PPD file \"%s\": %s",
2959 dstfile
, strerror(errno
));
2961 rename(srcfile
, dstfile
);
2966 * Copy the first line and then write out all of the keywords...
2969 if (!cupsFileGets(src
, line
, sizeof(line
)))
2971 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to read PPD file \"%s\": %s",
2972 srcfile
, strerror(errno
));
2975 rename(srcfile
, dstfile
);
2979 cupsFilePrintf(dst
, "%s\n", line
);
2981 for (i
= num_keywords
, keyword
= keywords
; i
> 0; i
--, keyword
++)
2983 cupsdLogMessage(CUPSD_LOG_DEBUG
, "*%s: %s", keyword
->name
, keyword
->value
);
2984 cupsFilePrintf(dst
, "*%s: %s\n", keyword
->name
, keyword
->value
);
2988 * Then copy the rest of the PPD file, dropping any keywords we changed.
2991 while (cupsFileGets(src
, line
, sizeof(line
)))
2994 * Skip keywords we've already set...
2997 if (sscanf(line
, "*%40[^:]:", keystring
) == 1 &&
2998 cupsGetOption(keystring
, num_keywords
, keywords
))
3002 * Otherwise write the line...
3005 cupsFilePrintf(dst
, "%s\n", line
);
3009 * Close files and return...
3020 * 'cupsdUpdatePrinters()' - Update printers after a partial reload.
3024 cupsdUpdatePrinters(void)
3026 cupsd_printer_t
*p
; /* Current printer */
3030 * Loop through the printers and recreate the printer attributes
3031 * for any local printers since the policy and/or access control
3032 * stuff may have changed. Also, if browsing is disabled, remove
3033 * any remote printers...
3036 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3038 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3041 * Remove remote printers if we are no longer browsing...
3045 (p
->type
& (CUPS_PRINTER_IMPLICIT
| CUPS_PRINTER_DISCOVERED
)))
3047 if (p
->type
& CUPS_PRINTER_IMPLICIT
)
3048 cupsArrayRemove(ImplicitPrinters
, p
);
3050 cupsArraySave(Printers
);
3051 cupsdDeletePrinter(p
, 0);
3052 cupsArrayRestore(Printers
);
3057 * Update the operation policy pointer...
3060 if ((p
->op_policy_ptr
= cupsdFindPolicy(p
->op_policy
)) == NULL
)
3061 p
->op_policy_ptr
= DefaultPolicyPtr
;
3064 * Update printer attributes as needed...
3067 if (!(p
->type
& CUPS_PRINTER_DISCOVERED
))
3068 cupsdSetPrinterAttrs(p
);
3074 * 'cupsdValidateDest()' - Validate a printer/class destination.
3077 const char * /* O - Printer or class name */
3079 const char *uri
, /* I - Printer URI */
3080 cups_ptype_t
*dtype
, /* O - Type (printer or class) */
3081 cupsd_printer_t
**printer
) /* O - Printer pointer */
3083 cupsd_printer_t
*p
; /* Current printer */
3084 char localname
[1024],/* Localized hostname */
3085 *lptr
, /* Pointer into localized hostname */
3086 *sptr
, /* Pointer into server name */
3087 *rptr
, /* Pointer into resource */
3088 scheme
[32], /* Scheme portion of URI */
3089 username
[64], /* Username portion of URI */
3090 hostname
[HTTP_MAX_HOST
],
3091 /* Host portion of URI */
3092 resource
[HTTP_MAX_URI
];
3093 /* Resource portion of URI */
3094 int port
; /* Port portion of URI */
3097 DEBUG_printf(("cupsdValidateDest(uri=\"%s\", dtype=%p, printer=%p)\n", uri
,
3101 * Initialize return values...
3108 *dtype
= (cups_ptype_t
)0;
3111 * Pull the hostname and resource from the URI...
3114 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
, scheme
, sizeof(scheme
),
3115 username
, sizeof(username
), hostname
, sizeof(hostname
),
3116 &port
, resource
, sizeof(resource
));
3119 * See if the resource is a class or printer...
3122 if (!strncmp(resource
, "/classes/", 9))
3128 rptr
= resource
+ 9;
3130 else if (!strncmp(resource
, "/printers/", 10))
3136 rptr
= resource
+ 10;
3141 * Bad resource name...
3148 * See if the printer or class name exists...
3151 p
= cupsdFindDest(rptr
);
3153 if (p
== NULL
&& strchr(rptr
, '@') == NULL
)
3161 *dtype
= p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
|
3162 CUPS_PRINTER_REMOTE
| CUPS_PRINTER_DISCOVERED
);
3168 * Change localhost to the server name...
3171 if (!strcasecmp(hostname
, "localhost"))
3172 strlcpy(hostname
, ServerName
, sizeof(hostname
));
3174 strlcpy(localname
, hostname
, sizeof(localname
));
3176 if (!strcasecmp(hostname
, ServerName
))
3179 * Localize the hostname...
3182 lptr
= strchr(localname
, '.');
3183 sptr
= strchr(ServerName
, '.');
3185 if (sptr
!= NULL
&& lptr
!= NULL
)
3188 * Strip the common domain name components...
3191 while (lptr
!= NULL
)
3193 if (!strcasecmp(lptr
, sptr
))
3199 lptr
= strchr(lptr
+ 1, '.');
3204 DEBUG_printf(("localized hostname is \"%s\"...\n", localname
));
3207 * Find a matching printer or class...
3210 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3212 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3213 if (!strcasecmp(p
->hostname
, localname
) &&
3214 !strcasecmp(p
->name
, rptr
))
3220 *dtype
= p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
|
3221 CUPS_PRINTER_REMOTE
| CUPS_PRINTER_DISCOVERED
);
3231 * 'cupsdWritePrintcap()' - Write a pseudo-printcap file for older applications
3236 cupsdWritePrintcap(void)
3238 int i
; /* Looping var */
3239 cups_file_t
*fp
; /* Printcap file */
3240 cupsd_printer_t
*p
; /* Current printer */
3245 * Update the IRIX printer state for the default printer; if
3246 * no printers remain, then the default printer file will be
3250 write_irix_state(DefaultPrinter
);
3254 * See if we have a printcap file; if not, don't bother writing it.
3257 if (!Printcap
|| !*Printcap
)
3260 cupsdLogMessage(CUPSD_LOG_INFO
, "Generating printcap %s...", Printcap
);
3263 * Open the printcap file...
3266 if ((fp
= cupsFileOpen(Printcap
, "w")) == NULL
)
3270 * Put a comment header at the top so that users will know where the
3271 * data has come from...
3274 if (PrintcapFormat
!= PRINTCAP_PLIST
)
3275 cupsFilePrintf(fp
, "# This file was automatically generated by cupsd(8) "
3277 "# %s/printers.conf file. All changes to this file\n"
3278 "# will be lost.\n", ServerRoot
);
3281 * Write a new printcap with the current list of printers.
3284 switch (PrintcapFormat
)
3288 * Each printer is put in the file as:
3298 cupsFilePrintf(fp
, "%s|%s:rm=%s:rp=%s:\n", DefaultPrinter
->name
,
3299 DefaultPrinter
->info
, ServerName
,
3300 DefaultPrinter
->name
);
3302 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3304 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3305 if (p
!= DefaultPrinter
)
3306 cupsFilePrintf(fp
, "%s|%s:rm=%s:rp=%s:\n", p
->name
, p
->info
,
3307 ServerName
, p
->name
);
3310 case PRINTCAP_PLIST
:
3312 * Each printer is written as a dictionary in a plist file.
3313 * Currently the printer-name, printer-info, printer-is-accepting-jobs,
3314 * printer-location, printer-make-and-model, printer-state,
3315 * printer-state-reasons, printer-type, and (sanitized) device-uri.
3318 cupsFilePuts(fp
, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
3319 "<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD "
3320 "PLIST 1.0//EN\" \"http://www.apple.com/DTDs/"
3321 "PropertyList-1.0.dtd\">\n"
3322 "<plist version=\"1.0\">\n"
3325 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3327 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3329 cupsFilePuts(fp
, "\t<dict>\n"
3330 "\t\t<key>printer-name</key>\n"
3332 write_xml_string(fp
, p
->name
);
3333 cupsFilePuts(fp
, "</string>\n"
3334 "\t\t<key>printer-info</key>\n"
3336 write_xml_string(fp
, p
->info
);
3337 cupsFilePrintf(fp
, "</string>\n"
3338 "\t\t<key>printer-is-accepting-jobs</key>\n"
3340 "\t\t<key>printer-location</key>\n"
3341 "\t\t<string>", p
->accepting
? "true" : "false");
3342 write_xml_string(fp
, p
->location
);
3343 cupsFilePuts(fp
, "</string>\n"
3344 "\t\t<key>printer-make-and-model</key>\n"
3346 write_xml_string(fp
, p
->make_model
);
3347 cupsFilePrintf(fp
, "</string>\n"
3348 "\t\t<key>printer-state</key>\n"
3349 "\t\t<integer>%d</integer>\n"
3350 "\t\t<key>printer-state-reasons</key>\n"
3351 "\t\t<array>\n", p
->state
);
3352 for (i
= 0; i
< p
->num_reasons
; i
++)
3354 cupsFilePuts(fp
, "\t\t\t<string>");
3355 write_xml_string(fp
, p
->reasons
[i
]);
3356 cupsFilePuts(fp
, "</string>\n");
3358 cupsFilePrintf(fp
, "\t\t</array>\n"
3359 "\t\t<key>printer-type</key>\n"
3360 "\t\t<integer>%d</integer>\n"
3361 "\t\t<key>device-uri</key>\n"
3362 "\t\t<string>", p
->type
);
3363 write_xml_string(fp
, p
->sanitized_device_uri
);
3364 cupsFilePuts(fp
, "</string>\n"
3367 cupsFilePuts(fp
, "</array>\n"
3371 case PRINTCAP_SOLARIS
:
3373 * Each printer is put in the file as:
3375 * _all:all=Printer1,Printer2,Printer3,...,PrinterN
3376 * _default:use=DefaultPrinter
3378 * :bsdaddr=ServerName,Printer1:\
3379 * :description=Description:
3381 * :bsdaddr=ServerName,Printer2:\
3382 * :description=Description:
3384 * :bsdaddr=ServerName,Printer3:\
3385 * :description=Description:
3388 * :bsdaddr=ServerName,PrinterN:\
3389 * :description=Description:
3392 cupsFilePuts(fp
, "_all:all=");
3393 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3395 p
= (cupsd_printer_t
*)cupsArrayCurrent(Printers
))
3396 cupsFilePrintf(fp
, "%s%c", p
->name
,
3397 cupsArrayNext(Printers
) ? ',' : '\n');
3400 cupsFilePrintf(fp
, "_default:use=%s\n", DefaultPrinter
->name
);
3402 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3404 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3405 cupsFilePrintf(fp
, "%s:\\\n"
3406 "\t:bsdaddr=%s,%s:\\\n"
3407 "\t:description=%s:\n",
3408 p
->name
, ServerName
, p
->name
,
3409 p
->info
? p
->info
: "");
3422 * 'add_printer_defaults()' - Add name-default attributes to the printer attributes.
3426 add_printer_defaults(cupsd_printer_t
*p
)/* I - Printer */
3428 int i
; /* Looping var */
3429 int num_options
; /* Number of default options */
3430 cups_option_t
*options
, /* Default options */
3431 *option
; /* Current option */
3432 char name
[256]; /* name-default */
3436 * Maintain a common array of default attribute names...
3439 if (!CommonDefaults
)
3441 CommonDefaults
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
3443 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("copies-default"));
3444 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("document-format-default"));
3445 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("finishings-default"));
3446 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-hold-until-default"));
3447 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-priority-default"));
3448 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-sheets-default"));
3449 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("media-col-default"));
3450 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("number-up-default"));
3451 cupsArrayAdd(CommonDefaults
,
3452 _cupsStrAlloc("orientation-requested-default"));
3456 * Add all of the default options from the .conf files...
3459 for (num_options
= 0, options
= NULL
, i
= p
->num_options
, option
= p
->options
;
3463 if (strcmp(option
->name
, "ipp-options") &&
3464 strcmp(option
->name
, "job-sheets") &&
3465 strcmp(option
->name
, "lease-duration"))
3467 snprintf(name
, sizeof(name
), "%s-default", option
->name
);
3468 num_options
= cupsAddOption(name
, option
->value
, num_options
, &options
);
3470 if (!cupsArrayFind(CommonDefaults
, name
))
3471 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc(name
));
3476 * Convert options to IPP attributes...
3479 cupsEncodeOptions2(p
->attrs
, num_options
, options
, IPP_TAG_PRINTER
);
3480 cupsFreeOptions(num_options
, options
);
3483 * Add standard -default attributes as needed...
3486 if (!cupsGetOption("copies", p
->num_options
, p
->options
))
3487 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
, "copies-default",
3490 if (!cupsGetOption("document-format", p
->num_options
, p
->options
))
3491 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_MIMETYPE
,
3492 "document-format-default", NULL
, "application/octet-stream");
3494 if (!cupsGetOption("job-hold-until", p
->num_options
, p
->options
))
3495 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3496 "job-hold-until-default", NULL
, "no-hold");
3498 if (!cupsGetOption("job-priority", p
->num_options
, p
->options
))
3499 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3500 "job-priority-default", 50);
3502 if (!cupsGetOption("number-up", p
->num_options
, p
->options
))
3503 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3504 "number-up-default", 1);
3506 if (!cupsGetOption("notify-lease-duration", p
->num_options
, p
->options
))
3507 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3508 "notify-lease-duration-default", DefaultLeaseDuration
);
3510 if (!cupsGetOption("notify-events", p
->num_options
, p
->options
))
3511 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3512 "notify-events-default", NULL
, "job-completed");
3514 if (!cupsGetOption("orientation-requested", p
->num_options
, p
->options
))
3515 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NOVALUE
,
3516 "orientation-requested-default", NULL
, NULL
);
3518 if (!cupsGetOption("print-quality", p
->num_options
, p
->options
))
3519 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
3520 "print-quality-default", IPP_QUALITY_NORMAL
);
3525 * 'add_printer_filter()' - Add a MIME filter for a printer.
3530 cupsd_printer_t
*p
, /* I - Printer to add to */
3531 mime_type_t
*filtertype
, /* I - Filter or prefilter MIME type */
3532 const char *filter
) /* I - Filter to add */
3534 char super
[MIME_MAX_SUPER
], /* Super-type for filter */
3535 type
[MIME_MAX_TYPE
], /* Type for filter */
3536 dsuper
[MIME_MAX_SUPER
], /* Destination super-type for filter */
3537 dtype
[MIME_MAX_TYPE
], /* Destination type for filter */
3538 dest
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2],
3539 /* Destination super/type */
3540 program
[1024]; /* Program/filter name */
3541 int cost
; /* Cost of filter */
3542 mime_type_t
*temptype
, /* MIME type looping var */
3543 *desttype
; /* Destination MIME type */
3544 char filename
[1024], /* Full filter filename */
3545 *dirsep
; /* Pointer to directory separator */
3546 struct stat fileinfo
; /* File information */
3549 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3550 "add_printer_filter(p=%p(%s), filtertype=%p(%s/%s), "
3551 "filter=\"%s\")", p
, p
->name
, filtertype
, filtertype
->super
,
3552 filtertype
->type
, filter
);
3555 * Parse the filter string; it should be in one of the following formats:
3557 * source/type cost program
3558 * source/type dest/type cost program
3561 if (sscanf(filter
, "%15[^/]/%255s%*[ \t]%15[^/]/%255s%d%*[ \t]%1023[^\n]",
3562 super
, type
, dsuper
, dtype
, &cost
, program
) == 6)
3564 snprintf(dest
, sizeof(dest
), "%s/%s/%s", p
->name
, dsuper
, dtype
);
3566 if ((desttype
= mimeType(MimeDatabase
, "printer", dest
)) == NULL
)
3568 desttype
= mimeAddType(MimeDatabase
, "printer", dest
);
3570 p
->dest_types
= cupsArrayNew(NULL
, NULL
);
3572 cupsArrayAdd(p
->dest_types
, desttype
);
3578 if (sscanf(filter
, "%15[^/]/%255s%d%*[ \t]%1023[^\n]", super
, type
, &cost
,
3581 desttype
= filtertype
;
3585 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: invalid filter string \"%s\"!",
3592 * See if the filter program exists; if not, stop the printer and flag
3596 if (strcmp(program
, "-"))
3598 if (program
[0] == '/')
3599 strlcpy(filename
, program
, sizeof(filename
));
3601 snprintf(filename
, sizeof(filename
), "%s/filter/%s", ServerBin
, program
);
3603 if (stat(filename
, &fileinfo
))
3605 memset(&fileinfo
, 0, sizeof(fileinfo
));
3607 snprintf(p
->state_message
, sizeof(p
->state_message
),
3608 "Printer driver \"%s\" not available: %s", filename
,
3610 cupsdSetPrinterReasons(p
, "+cups-missing-filter-warning");
3612 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: %s", p
->name
, p
->state_message
);
3616 * When running as root, do additional security checks...
3622 * Only use filters that are owned by root and do not have world write
3626 if (fileinfo
.st_uid
||
3627 (fileinfo
.st_gid
&& (fileinfo
.st_mode
& S_IWGRP
)) ||
3628 (fileinfo
.st_mode
& (S_ISUID
| S_IWOTH
)) != 0)
3630 snprintf(p
->state_message
, sizeof(p
->state_message
),
3631 "Printer driver \"%s\" has insecure permissions "
3632 "(0%o/uid=%d/gid=%d).", filename
, fileinfo
.st_mode
,
3633 (int)fileinfo
.st_uid
, (int)fileinfo
.st_gid
);
3635 cupsdSetPrinterReasons(p
, "+cups-insecure-filter-warning");
3637 cupsdLogMessage(CUPSD_LOG_WARN
, "%s: %s", p
->name
, p
->state_message
);
3639 else if (fileinfo
.st_mode
)
3642 * Similarly, check that the parent directory is also owned by root and
3643 * does not have world write permissions.
3646 if ((dirsep
= strrchr(filename
, '/')) != NULL
)
3649 if (!stat(filename
, &fileinfo
) &&
3651 (fileinfo
.st_gid
&& (fileinfo
.st_mode
& S_IWGRP
)) ||
3652 (fileinfo
.st_mode
& (S_ISUID
| S_IWOTH
)) != 0))
3654 snprintf(p
->state_message
, sizeof(p
->state_message
),
3655 "Printer driver directory \"%s\" has insecure permissions "
3656 "(0%o/uid=%d/gid=%d).", filename
, fileinfo
.st_mode
,
3657 (int)fileinfo
.st_uid
, (int)fileinfo
.st_gid
);
3659 cupsdSetPrinterReasons(p
, "+cups-insecure-filter-warning");
3661 cupsdLogMessage(CUPSD_LOG_WARN
, "%s: %s", p
->name
, p
->state_message
);
3668 * Add the filter to the MIME database, supporting wildcards as needed...
3671 for (temptype
= mimeFirstType(MimeDatabase
);
3673 temptype
= mimeNextType(MimeDatabase
))
3674 if (((super
[0] == '*' && strcasecmp(temptype
->super
, "printer")) ||
3675 !strcasecmp(temptype
->super
, super
)) &&
3676 (type
[0] == '*' || !strcasecmp(temptype
->type
, type
)))
3678 if (desttype
!= filtertype
)
3680 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3681 "add_printer_filter: %s: adding filter %s/%s %s/%s %d "
3682 "%s", p
->name
, temptype
->super
, temptype
->type
,
3683 desttype
->super
, desttype
->type
,
3685 mimeAddFilter(MimeDatabase
, temptype
, desttype
, cost
, program
);
3687 if (!mimeFilterLookup(MimeDatabase
, desttype
, filtertype
))
3689 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3690 "add_printer_filter: %s: adding filter %s/%s %s/%s "
3691 "0 -", p
->name
, desttype
->super
, desttype
->type
,
3692 filtertype
->super
, filtertype
->type
);
3693 mimeAddFilter(MimeDatabase
, desttype
, filtertype
, cost
, "-");
3698 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3699 "add_printer_filter: %s: adding filter %s/%s %s/%s %d "
3700 "%s", p
->name
, temptype
->super
, temptype
->type
,
3701 filtertype
->super
, filtertype
->type
,
3703 mimeAddFilter(MimeDatabase
, temptype
, filtertype
, cost
, program
);
3710 * 'add_printer_formats()' - Add document-format-supported values for a printer.
3714 add_printer_formats(cupsd_printer_t
*p
) /* I - Printer */
3716 int i
; /* Looping var */
3717 mime_type_t
*type
; /* Current MIME type */
3718 cups_array_t
*filters
; /* Filters */
3719 ipp_attribute_t
*attr
; /* document-format-supported attribute */
3720 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
3721 /* MIME type name */
3725 * Raw (and remote) queues advertise all of the supported MIME
3729 cupsArrayDelete(p
->filetypes
);
3730 p
->filetypes
= NULL
;
3734 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
,
3735 (ipp_tag_t
)(IPP_TAG_MIMETYPE
| IPP_TAG_COPY
),
3736 "document-format-supported", NumMimeTypes
, NULL
, MimeTypes
);
3741 * Otherwise, loop through the supported MIME types and see if there
3742 * are filters for them...
3745 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_printer_formats: %d types, %d filters",
3746 mimeNumTypes(MimeDatabase
), mimeNumFilters(MimeDatabase
));
3748 p
->filetypes
= cupsArrayNew(NULL
, NULL
);
3750 for (type
= mimeFirstType(MimeDatabase
);
3752 type
= mimeNextType(MimeDatabase
))
3754 if (!strcasecmp(type
->super
, "printer"))
3757 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
3759 if ((filters
= mimeFilter(MimeDatabase
, type
, p
->filetype
, NULL
)) != NULL
)
3761 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3762 "add_printer_formats: %s: %s needs %d filters",
3763 p
->name
, mimetype
, cupsArrayCount(filters
));
3765 cupsArrayDelete(filters
);
3766 cupsArrayAdd(p
->filetypes
, type
);
3769 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3770 "add_printer_formats: %s: %s not supported",
3775 * Add the file formats that can be filtered...
3778 if ((type
= mimeType(MimeDatabase
, "application", "octet-stream")) == NULL
||
3779 !cupsArrayFind(p
->filetypes
, type
))
3784 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3785 "add_printer_formats: %s: %d supported types",
3786 p
->name
, cupsArrayCount(p
->filetypes
) + i
);
3788 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_MIMETYPE
,
3789 "document-format-supported",
3790 cupsArrayCount(p
->filetypes
) + i
, NULL
, NULL
);
3793 attr
->values
[0].string
.text
= _cupsStrAlloc("application/octet-stream");
3795 for (type
= (mime_type_t
*)cupsArrayFirst(p
->filetypes
);
3797 i
++, type
= (mime_type_t
*)cupsArrayNext(p
->filetypes
))
3799 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
3801 attr
->values
[i
].string
.text
= _cupsStrAlloc(mimetype
);
3806 char pdl
[1024]; /* Buffer to build pdl list */
3807 mime_filter_t
*filter
; /* MIME filter looping var */
3811 * We only support raw printing if this is not a Tioga PrintJobMgr based
3812 * queue and if application/octet-stream is a known type...
3815 for (filter
= (mime_filter_t
*)cupsArrayFirst(MimeDatabase
->filters
);
3817 filter
= (mime_filter_t
*)cupsArrayNext(MimeDatabase
->filters
))
3819 if (filter
->dst
== p
->filetype
&& filter
->filter
&&
3820 strstr(filter
->filter
, "PrintJobMgr"))
3826 if (!filter
&& mimeType(MimeDatabase
, "application", "octet-stream"))
3827 strlcat(pdl
, "application/octet-stream,", sizeof(pdl
));
3830 * Then list a bunch of formats that are supported by the printer...
3833 for (type
= (mime_type_t
*)cupsArrayFirst(p
->filetypes
);
3835 type
= (mime_type_t
*)cupsArrayNext(p
->filetypes
))
3837 if (!strcasecmp(type
->super
, "application"))
3839 if (!strcasecmp(type
->type
, "pdf"))
3840 strlcat(pdl
, "application/pdf,", sizeof(pdl
));
3841 else if (!strcasecmp(type
->type
, "postscript"))
3842 strlcat(pdl
, "application/postscript,", sizeof(pdl
));
3844 else if (!strcasecmp(type
->super
, "image"))
3846 if (!strcasecmp(type
->type
, "jpeg"))
3847 strlcat(pdl
, "image/jpeg,", sizeof(pdl
));
3848 else if (!strcasecmp(type
->type
, "png"))
3849 strlcat(pdl
, "image/png,", sizeof(pdl
));
3850 else if (!strcasecmp(type
->type
, "pwg-raster"))
3851 strlcat(pdl
, "image/pwg-raster,", sizeof(pdl
));
3856 pdl
[strlen(pdl
) - 1] = '\0'; /* Remove trailing comma */
3858 cupsdSetString(&p
->pdl
, pdl
);
3860 #endif /* HAVE_DNSSD */
3865 * 'compare_printers()' - Compare two printers.
3868 static int /* O - Result of comparison */
3869 compare_printers(void *first
, /* I - First printer */
3870 void *second
, /* I - Second printer */
3871 void *data
) /* I - App data (not used) */
3873 return (strcasecmp(((cupsd_printer_t
*)first
)->name
,
3874 ((cupsd_printer_t
*)second
)->name
));
3879 * 'delete_printer_filters()' - Delete all MIME filters for a printer.
3883 delete_printer_filters(
3884 cupsd_printer_t
*p
) /* I - Printer to remove from */
3886 mime_filter_t
*filter
; /* MIME filter looping var */
3887 mime_type_t
*type
; /* Destination types for filters */
3891 * Range check input...
3898 * Remove all filters from the MIME database that have a destination
3899 * type == printer...
3902 for (filter
= mimeFirstFilter(MimeDatabase
);
3904 filter
= mimeNextFilter(MimeDatabase
))
3905 if (filter
->dst
== p
->filetype
|| filter
->dst
== p
->prefiltertype
||
3906 cupsArrayFind(p
->dest_types
, filter
->dst
))
3909 * Delete the current filter...
3912 mimeDeleteFilter(MimeDatabase
, filter
);
3915 for (type
= (mime_type_t
*)cupsArrayFirst(p
->dest_types
);
3917 type
= (mime_type_t
*)cupsArrayNext(p
->dest_types
))
3918 mimeDeleteType(MimeDatabase
, type
);
3920 cupsArrayDelete(p
->dest_types
);
3921 p
->dest_types
= NULL
;
3923 cupsdSetPrinterReasons(p
, "-cups-insecure-filter-warning"
3924 ",cups-missing-filter-warning");
3929 * 'dirty_printer()' - Mark config and state files dirty for the specified
3934 dirty_printer(cupsd_printer_t
*p
) /* I - Printer */
3936 if (p
->type
& CUPS_PRINTER_DISCOVERED
)
3937 cupsdMarkDirty(CUPSD_DIRTY_REMOTE
);
3938 else if (p
->type
& CUPS_PRINTER_CLASS
)
3939 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
3941 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
3943 if (PrintcapFormat
== PRINTCAP_PLIST
)
3944 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
3949 * 'load_ppd()' - Load a cached PPD file, updating the cache as needed.
3953 load_ppd(cupsd_printer_t
*p
) /* I - Printer */
3955 int i
, j
, k
; /* Looping vars */
3956 char cache_name
[1024]; /* Cache filename */
3957 struct stat cache_info
; /* Cache file info */
3958 ppd_file_t
*ppd
; /* PPD file */
3959 char ppd_name
[1024]; /* PPD filename */
3960 struct stat ppd_info
; /* PPD file info */
3961 int num_media
; /* Number of media options */
3962 ppd_size_t
*size
; /* Current PPD size */
3963 ppd_option_t
*duplex
, /* Duplex option */
3964 *output_bin
, /* OutputBin option */
3965 *output_mode
, /* OutputMode option */
3966 *resolution
; /* (Set|JCL|)Resolution option */
3967 ppd_choice_t
*choice
, /* Current PPD choice */
3968 *input_slot
, /* Current input slot */
3969 *media_type
; /* Current media type */
3970 ppd_attr_t
*ppd_attr
; /* PPD attribute */
3971 int xdpi
, /* Horizontal resolution */
3972 ydpi
; /* Vertical resolution */
3973 const char *resptr
; /* Pointer into resolution keyword */
3974 _pwg_size_t
*pwgsize
; /* Current PWG size */
3975 _pwg_map_t
*pwgsource
, /* Current PWG source */
3976 *pwgtype
; /* Current PWG type */
3977 ipp_attribute_t
*attr
; /* Attribute data */
3978 ipp_value_t
*val
; /* Attribute value */
3979 int num_finishings
, /* Number of finishings */
3980 finishings
[5]; /* finishings-supported values */
3981 int num_qualities
, /* Number of print-quality values */
3982 qualities
[3]; /* print-quality values */
3983 int num_margins
, /* Number of media-*-margin-supported values */
3984 margins
[16]; /* media-*-margin-supported values */
3985 const char *filter
; /* Current filter */
3986 static const char * const sides
[3] = /* sides-supported values */
3989 "two-sided-long-edge",
3990 "two-sided-short-edge"
3992 static const char * const standard_commands
[] =
3993 { /* Standard CUPS commands */
4001 * Check to see if the cache is up-to-date...
4004 snprintf(cache_name
, sizeof(cache_name
), "%s/%s.data", CacheDir
, p
->name
);
4005 if (stat(cache_name
, &cache_info
))
4006 cache_info
.st_mtime
= 0;
4008 snprintf(ppd_name
, sizeof(ppd_name
), "%s/ppd/%s.ppd", ServerRoot
, p
->name
);
4009 if (stat(ppd_name
, &ppd_info
))
4010 ppd_info
.st_mtime
= 1;
4012 ippDelete(p
->ppd_attrs
);
4013 p
->ppd_attrs
= ippNew();
4015 _ppdCacheDestroy(p
->pc
);
4018 if (cache_info
.st_mtime
>= ppd_info
.st_mtime
)
4020 cupsdLogMessage(CUPSD_LOG_DEBUG
, "load_ppd: Loading %s...", cache_name
);
4022 if ((p
->pc
= _ppdCacheCreateWithFile(cache_name
, &p
->ppd_attrs
)) != NULL
&&
4026 * Loaded successfully!
4034 * Reload PPD attributes from disk...
4037 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
4039 cupsdLogMessage(CUPSD_LOG_DEBUG
, "load_ppd: Loading %s...", ppd_name
);
4041 p
->type
&= ~CUPS_PRINTER_OPTIONS
;
4042 p
->type
|= CUPS_PRINTER_BW
;
4044 finishings
[0] = IPP_FINISHINGS_NONE
;
4047 if ((ppd
= ppdOpenFile(ppd_name
)) != NULL
)
4050 * Add make/model and other various attributes...
4053 p
->pc
= _ppdCacheCreateWithPPD(ppd
);
4055 ppdMarkDefaults(ppd
);
4057 if (ppd
->color_device
)
4058 p
->type
|= CUPS_PRINTER_COLOR
;
4059 if (ppd
->variable_sizes
)
4060 p
->type
|= CUPS_PRINTER_VARIABLE
;
4061 if (!ppd
->manual_copies
)
4062 p
->type
|= CUPS_PRINTER_COPIES
;
4063 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsFax", NULL
)) != NULL
)
4064 if (ppd_attr
->value
&& !strcasecmp(ppd_attr
->value
, "true"))
4065 p
->type
|= CUPS_PRINTER_FAX
;
4067 ippAddBoolean(p
->ppd_attrs
, IPP_TAG_PRINTER
, "color-supported",
4069 if (ppd
->throughput
)
4071 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4072 "pages-per-minute", ppd
->throughput
);
4073 if (ppd
->color_device
)
4074 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4075 "pages-per-minute-color", ppd
->throughput
);
4080 * When there is no speed information, just say "1 page per minute".
4083 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4084 "pages-per-minute", 1);
4085 if (ppd
->color_device
)
4086 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4087 "pages-per-minute-color", 1);
4092 if ((output_mode
= ppdFindOption(ppd
, "OutputMode")) != NULL
)
4094 if (ppdFindChoice(output_mode
, "draft") ||
4095 ppdFindChoice(output_mode
, "fast"))
4096 qualities
[num_qualities
++] = IPP_QUALITY_DRAFT
;
4098 qualities
[num_qualities
++] = IPP_QUALITY_NORMAL
;
4100 if (ppdFindChoice(output_mode
, "best") ||
4101 ppdFindChoice(output_mode
, "high"))
4102 qualities
[num_qualities
++] = IPP_QUALITY_HIGH
;
4104 else if ((ppd_attr
= ppdFindAttr(ppd
, "APPrinterPreset", NULL
)) != NULL
)
4108 if (strstr(ppd_attr
->spec
, "draft") ||
4109 strstr(ppd_attr
->spec
, "Draft"))
4111 qualities
[num_qualities
++] = IPP_QUALITY_DRAFT
;
4115 while ((ppd_attr
= ppdFindNextAttr(ppd
, "APPrinterPreset",
4118 qualities
[num_qualities
++] = IPP_QUALITY_NORMAL
;
4119 qualities
[num_qualities
++] = IPP_QUALITY_HIGH
;
4122 qualities
[num_qualities
++] = IPP_QUALITY_NORMAL
;
4124 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
4125 "print-quality-supported", num_qualities
, qualities
);
4130 * The NickName can be localized in the character set specified
4131 * by the LanugageEncoding attribute. However, ppdOpen2() has
4132 * already converted the ppd->nickname member to UTF-8 for us
4133 * (the original attribute value is available separately)
4136 cupsdSetString(&p
->make_model
, ppd
->nickname
);
4138 else if (ppd
->modelname
)
4141 * Model name can only contain specific characters...
4144 cupsdSetString(&p
->make_model
, ppd
->modelname
);
4147 cupsdSetString(&p
->make_model
, "Bad PPD File");
4149 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
4150 "printer-make-and-model", NULL
, p
->make_model
);
4153 * Add media options from the PPD file...
4156 if (ppd
->num_sizes
== 0 || !p
->pc
)
4158 if (!ppdFindAttr(ppd
, "APScannerOnly", NULL
))
4159 cupsdLogMessage(CUPSD_LOG_CRIT
,
4160 "The PPD file for printer %s contains no media "
4161 "options and is therefore invalid!", p
->name
);
4163 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4164 "media-default", NULL
, "unknown");
4165 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4166 "media-supported", NULL
, "unknown");
4174 if ((size
= ppdPageSize(ppd
, NULL
)) != NULL
)
4175 pwgsize
= _ppdCacheGetSize(p
->pc
, size
->name
);
4179 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4180 "media-default", NULL
,
4181 pwgsize
? pwgsize
->map
.pwg
: "unknown");
4189 ipp_t
*col
; /* Collection value */
4191 input_slot
= ppdFindMarkedChoice(ppd
, "InputSlot");
4192 media_type
= ppdFindMarkedChoice(ppd
, "MediaType");
4193 col
= new_media_col(pwgsize
,
4195 _ppdCacheGetSource(p
->pc
,
4196 input_slot
->choice
) :
4199 _ppdCacheGetType(p
->pc
,
4200 media_type
->choice
) :
4203 ippAddCollection(p
->ppd_attrs
, IPP_TAG_PRINTER
, "media-col-default",
4212 num_media
= p
->pc
->num_sizes
;
4213 if (p
->pc
->custom_min_keyword
)
4216 if ((attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4217 "media-supported", num_media
, NULL
,
4222 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
;
4224 i
--, pwgsize
++, val
++)
4225 val
->string
.text
= _cupsStrRetain(pwgsize
->map
.pwg
);
4227 if (p
->pc
->custom_min_keyword
)
4229 val
->string
.text
= _cupsStrRetain(p
->pc
->custom_min_keyword
);
4231 val
->string
.text
= _cupsStrRetain(p
->pc
->custom_max_keyword
);
4236 * media-source-supported
4239 if (p
->pc
->num_sources
> 0 &&
4240 (attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4241 "media-source-supported", p
->pc
->num_sources
,
4242 NULL
, NULL
)) != NULL
)
4244 for (i
= p
->pc
->num_sources
, pwgsource
= p
->pc
->sources
,
4247 i
--, pwgsource
++, val
++)
4248 val
->string
.text
= _cupsStrRetain(pwgsource
->pwg
);
4252 * media-type-supported
4255 if (p
->pc
->num_types
> 0 &&
4256 (attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4257 "media-type-supported", p
->pc
->num_types
,
4258 NULL
, NULL
)) != NULL
)
4260 for (i
= p
->pc
->num_types
, pwgtype
= p
->pc
->types
,
4263 i
--, pwgtype
++, val
++)
4264 val
->string
.text
= _cupsStrRetain(pwgtype
->pwg
);
4268 * media-*-margin-supported
4271 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, num_margins
= 0;
4272 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4275 for (j
= 0; j
< num_margins
; j
++)
4276 if (pwgsize
->bottom
== margins
[j
])
4279 if (j
>= num_margins
)
4281 margins
[num_margins
] = pwgsize
->bottom
;
4286 if (num_margins
> 0)
4287 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4288 "media-bottom-margin-supported", num_margins
, margins
);
4290 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4291 "media-bottom-margin-supported", 0);
4293 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, num_margins
= 0;
4294 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4297 for (j
= 0; j
< num_margins
; j
++)
4298 if (pwgsize
->left
== margins
[j
])
4301 if (j
>= num_margins
)
4303 margins
[num_margins
] = pwgsize
->left
;
4308 if (num_margins
> 0)
4309 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4310 "media-left-margin-supported", num_margins
, margins
);
4312 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4313 "media-left-margin-supported", 0);
4315 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, num_margins
= 0;
4316 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4319 for (j
= 0; j
< num_margins
; j
++)
4320 if (pwgsize
->right
== margins
[j
])
4323 if (j
>= num_margins
)
4325 margins
[num_margins
] = pwgsize
->right
;
4330 if (num_margins
> 0)
4331 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4332 "media-right-margin-supported", num_margins
, margins
);
4334 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4335 "media-right-margin-supported", 0);
4337 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, num_margins
= 0;
4338 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4341 for (j
= 0; j
< num_margins
; j
++)
4342 if (pwgsize
->top
== margins
[j
])
4345 if (j
>= num_margins
)
4347 margins
[num_margins
] = pwgsize
->top
;
4352 if (num_margins
> 0)
4353 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4354 "media-top-margin-supported", num_margins
, margins
);
4356 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4357 "media-top-margin-supported", 0);
4360 * media-col-database
4363 num_media
= p
->pc
->num_sizes
;
4364 if (p
->pc
->num_sources
)
4366 if (p
->pc
->num_types
> 0)
4367 num_media
+= p
->pc
->num_sizes
* p
->pc
->num_sources
*
4370 num_media
+= p
->pc
->num_sizes
* p
->pc
->num_sources
;
4372 else if (p
->pc
->num_types
)
4373 num_media
+= p
->pc
->num_sizes
* p
->pc
->num_types
;
4375 if ((attr
= ippAddCollections(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4376 "media-col-database", num_media
,
4379 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, val
= attr
->values
;
4384 * Start by adding the page size without source or type...
4387 ppdMarkOption(ppd
, "PageSize", pwgsize
->map
.ppd
);
4389 val
->collection
= new_media_col(pwgsize
, NULL
, NULL
);
4393 * Then add the specific, supported combinations of size, source, and
4397 if (p
->pc
->num_sources
> 0)
4399 for (j
= p
->pc
->num_sources
, pwgsource
= p
->pc
->sources
;
4403 ppdMarkOption(ppd
, "InputSlot", pwgsource
->ppd
);
4405 if (p
->pc
->num_types
> 0)
4407 for (k
= p
->pc
->num_types
, pwgtype
= p
->pc
->types
;
4411 if (!ppdMarkOption(ppd
, "MediaType", pwgtype
->ppd
))
4413 val
->collection
= new_media_col(pwgsize
, pwgsource
->pwg
,
4419 else if (!ppdConflicts(ppd
))
4421 val
->collection
= new_media_col(pwgsize
, pwgsource
->pwg
, NULL
);
4426 else if (p
->pc
->num_types
> 0)
4428 for (j
= p
->pc
->num_types
, pwgtype
= p
->pc
->types
;
4432 if (!ppdMarkOption(ppd
, "MediaType", pwgtype
->ppd
))
4434 val
->collection
= new_media_col(pwgsize
, NULL
, pwgtype
->pwg
);
4442 * Update the number of media-col-database values...
4445 attr
->num_values
= val
- attr
->values
;
4453 if (p
->pc
&& p
->pc
->num_bins
> 0)
4455 attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4456 "output-bin-supported", p
->pc
->num_bins
,
4461 for (i
= 0, val
= attr
->values
;
4462 i
< p
->pc
->num_bins
;
4464 val
->string
.text
= _cupsStrAlloc(p
->pc
->bins
[i
].pwg
);
4467 if ((output_bin
= ppdFindOption(ppd
, "OutputBin")) != NULL
)
4469 for (i
= 0; i
< p
->pc
->num_bins
; i
++)
4470 if (!strcmp(p
->pc
->bins
[i
].ppd
, output_bin
->defchoice
))
4473 if (i
>= p
->pc
->num_bins
)
4476 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4477 "output-bin-default", NULL
, p
->pc
->bins
[i
].pwg
);
4480 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4481 "output-bin-default", NULL
, p
->pc
->bins
[0].pwg
);
4483 else if (((ppd_attr
= ppdFindAttr(ppd
, "DefaultOutputOrder",
4485 !strcasecmp(ppd_attr
->value
, "Reverse")) ||
4486 (!ppd_attr
&& ppd
->manufacturer
&& /* "Compatibility heuristic" */
4487 (!strcasecmp(ppd
->manufacturer
, "epson") ||
4488 !strcasecmp(ppd
->manufacturer
, "lexmark"))))
4491 * Report that this printer has a single output bin that leaves pages face
4495 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4496 "output-bin-supported", NULL
, "face-up");
4497 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4498 "output-bin-default", NULL
, "face-up");
4502 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4503 "output-bin-supported", NULL
, "face-down");
4504 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4505 "output-bin-default", NULL
, "face-down");
4509 * output-mode and print-color-mode...
4512 if (ppd
->color_device
)
4514 static const char * const output_modes
[] =
4520 ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4521 "output-mode-supported", 2, NULL
, output_modes
);
4522 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4523 "output-mode-default", NULL
, "color");
4525 ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4526 "print-color-mode-supported", 2, NULL
, output_modes
);
4527 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4528 "print-color-mode-default", NULL
, "color");
4532 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4533 "output-mode-supported", NULL
, "monochrome");
4534 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4535 "output-mode-default", NULL
, "monochrome");
4537 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4538 "print-color-mode-supported", NULL
, "monochrome");
4539 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4540 "print-color-mode-default", NULL
, "monochrome");
4544 * Printer resolutions...
4547 if ((resolution
= ppdFindOption(ppd
, "Resolution")) == NULL
)
4548 if ((resolution
= ppdFindOption(ppd
, "JCLResolution")) == NULL
)
4549 if ((resolution
= ppdFindOption(ppd
, "SetResolution")) == NULL
)
4550 resolution
= ppdFindOption(ppd
, "CNRes_PGP");
4555 * Report all supported resolutions...
4558 attr
= ippAddResolutions(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4559 "printer-resolution-supported",
4560 resolution
->num_choices
, IPP_RES_PER_INCH
,
4563 for (i
= 0, choice
= resolution
->choices
;
4564 i
< resolution
->num_choices
;
4567 xdpi
= ydpi
= (int)strtol(choice
->choice
, (char **)&resptr
, 10);
4568 if (resptr
> choice
->choice
&& xdpi
> 0 && *resptr
== 'x')
4569 ydpi
= (int)strtol(resptr
+ 1, (char **)&resptr
, 10);
4571 if (xdpi
<= 0 || ydpi
<= 0)
4573 cupsdLogMessage(CUPSD_LOG_WARN
,
4574 "Bad resolution \"%s\" for printer %s.",
4575 choice
->choice
, p
->name
);
4579 attr
->values
[i
].resolution
.xres
= xdpi
;
4580 attr
->values
[i
].resolution
.yres
= ydpi
;
4581 attr
->values
[i
].resolution
.units
= IPP_RES_PER_INCH
;
4584 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4585 "printer-resolution-default", IPP_RES_PER_INCH
,
4589 else if ((ppd_attr
= ppdFindAttr(ppd
, "DefaultResolution", NULL
)) != NULL
&&
4593 * Just the DefaultResolution to report...
4596 xdpi
= ydpi
= (int)strtol(ppd_attr
->value
, (char **)&resptr
, 10);
4597 if (resptr
> ppd_attr
->value
&& xdpi
> 0)
4600 ydpi
= (int)strtol(resptr
+ 1, (char **)&resptr
, 10);
4605 if (xdpi
<= 0 || ydpi
<= 0)
4607 cupsdLogMessage(CUPSD_LOG_WARN
,
4608 "Bad default resolution \"%s\" for printer %s.",
4609 ppd_attr
->value
, p
->name
);
4613 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4614 "printer-resolution-default", IPP_RES_PER_INCH
,
4616 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4617 "printer-resolution-supported", IPP_RES_PER_INCH
,
4623 * No resolutions in PPD - make one up...
4626 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4627 "printer-resolution-default", IPP_RES_PER_INCH
,
4629 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4630 "printer-resolution-supported", IPP_RES_PER_INCH
,
4638 ppdMarkDefaults(ppd
);
4640 if ((duplex
= ppdFindOption(ppd
, "Duplex")) == NULL
)
4641 if ((duplex
= ppdFindOption(ppd
, "EFDuplex")) == NULL
)
4642 if ((duplex
= ppdFindOption(ppd
, "EFDuplexing")) == NULL
)
4643 if ((duplex
= ppdFindOption(ppd
, "KD03Duplex")) == NULL
)
4644 duplex
= ppdFindOption(ppd
, "JCLDuplex");
4646 if (duplex
&& duplex
->num_choices
> 1 &&
4647 !ppdInstallableConflict(ppd
, duplex
->keyword
, "DuplexTumble"))
4649 p
->type
|= CUPS_PRINTER_DUPLEX
;
4651 ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4652 "sides-supported", 3, NULL
, sides
);
4654 if (!strcasecmp(duplex
->defchoice
, "DuplexTumble"))
4655 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4656 "sides-default", NULL
, "two-sided-short-edge");
4657 else if (!strcasecmp(duplex
->defchoice
, "DuplexNoTumble"))
4658 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4659 "sides-default", NULL
, "two-sided-long-edge");
4661 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4662 "sides-default", NULL
, "one-sided");
4666 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4667 "sides-supported", NULL
, "one-sided");
4668 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4669 "sides-default", NULL
, "one-sided");
4672 if (ppdFindOption(ppd
, "Collate") != NULL
)
4673 p
->type
|= CUPS_PRINTER_COLLATE
;
4675 if (ppdFindOption(ppd
, "StapleLocation") != NULL
)
4677 p
->type
|= CUPS_PRINTER_STAPLE
;
4678 finishings
[num_finishings
++] = IPP_FINISHINGS_STAPLE
;
4681 if (ppdFindOption(ppd
, "BindEdge") != NULL
)
4683 p
->type
|= CUPS_PRINTER_BIND
;
4684 finishings
[num_finishings
++] = IPP_FINISHINGS_BIND
;
4687 for (i
= 0; i
< ppd
->num_sizes
; i
++)
4688 if (ppd
->sizes
[i
].length
> 1728)
4689 p
->type
|= CUPS_PRINTER_LARGE
;
4690 else if (ppd
->sizes
[i
].length
> 1008)
4691 p
->type
|= CUPS_PRINTER_MEDIUM
;
4693 p
->type
|= CUPS_PRINTER_SMALL
;
4695 if ((ppd_attr
= ppdFindAttr(ppd
, "APICADriver", NULL
)) != NULL
&&
4696 ppd_attr
->value
&& !strcasecmp(ppd_attr
->value
, "true"))
4698 if ((ppd_attr
= ppdFindAttr(ppd
, "APScannerOnly", NULL
)) != NULL
&&
4699 ppd_attr
->value
&& !strcasecmp(ppd_attr
->value
, "true"))
4700 p
->type
|= CUPS_PRINTER_SCANNER
;
4702 p
->type
|= CUPS_PRINTER_MFP
;
4706 * Scan the filters in the PPD file...
4711 for (filter
= (const char *)cupsArrayFirst(p
->pc
->filters
);
4713 filter
= (const char *)cupsArrayNext(p
->pc
->filters
))
4715 if (!strncasecmp(filter
, "application/vnd.cups-command", 28) &&
4716 _cups_isspace(filter
[28]))
4718 p
->type
|= CUPS_PRINTER_COMMANDS
;
4724 if (p
->type
& CUPS_PRINTER_COMMANDS
)
4726 char *commands
, /* Copy of commands */
4727 *start
, /* Start of name */
4728 *end
; /* End of name */
4729 int count
; /* Number of commands */
4731 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsCommands", NULL
)) != NULL
)
4733 for (count
= 0, start
= ppd_attr
->value
; *start
; count
++)
4735 while (_cups_isspace(*start
))
4741 while (*start
&& !isspace(*start
& 255))
4751 * Make a copy of the commands string and count how many commands there
4755 attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4756 "printer-commands", count
, NULL
, NULL
);
4758 commands
= strdup(ppd_attr
->value
);
4760 for (count
= 0, start
= commands
; *start
; count
++)
4762 while (isspace(*start
& 255))
4769 while (*end
&& !isspace(*end
& 255))
4775 attr
->values
[count
].string
.text
= _cupsStrAlloc(start
);
4785 * Add the standard list of commands...
4788 ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4790 (int)(sizeof(standard_commands
) /
4791 sizeof(standard_commands
[0])), NULL
,
4798 * No commands supported...
4801 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4802 "printer-commands", NULL
, "none");
4806 * Show current and available port monitors for this printer...
4809 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
, "port-monitor",
4810 NULL
, p
->port_monitor
? p
->port_monitor
: "none");
4812 for (i
= 1, ppd_attr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
4814 i
++, ppd_attr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
));
4818 if (strstr(ppd
->protocols
, "TBCP"))
4820 else if (strstr(ppd
->protocols
, "BCP"))
4824 attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
4825 "port-monitor-supported", i
, NULL
, NULL
);
4827 attr
->values
[0].string
.text
= _cupsStrAlloc("none");
4829 for (i
= 1, ppd_attr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
4831 i
++, ppd_attr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
))
4832 attr
->values
[i
].string
.text
= _cupsStrAlloc(ppd_attr
->value
);
4836 if (strstr(ppd
->protocols
, "TBCP"))
4837 attr
->values
[i
].string
.text
= _cupsStrAlloc("tbcp");
4838 else if (strstr(ppd
->protocols
, "BCP"))
4839 attr
->values
[i
].string
.text
= _cupsStrAlloc("bcp");
4842 if (ppdFindAttr(ppd
, "APRemoteQueueID", NULL
))
4843 p
->type
|= CUPS_PRINTER_REMOTE
;
4845 #ifdef HAVE_APPLICATIONSERVICES_H
4847 * Convert the file referenced in APPrinterIconPath to a 128x128 PNG
4848 * and save it as cacheDir/printername.png
4851 if ((ppd_attr
= ppdFindAttr(ppd
, "APPrinterIconPath", NULL
)) != NULL
&&
4854 CGImageRef imageRef
= NULL
;/* Current icon image */
4855 CGImageRef biggestIconRef
= NULL
;
4856 /* Biggest icon image */
4857 CGImageRef closestTo128IconRef
= NULL
;
4858 /* Icon image closest to and >= 128 */
4859 CGImageSourceRef sourceRef
; /* The file's image source */
4860 char outPath
[HTTP_MAX_URI
];
4861 /* The path to the PNG file */
4862 CFURLRef outUrl
; /* The URL made from the outPath */
4863 CFURLRef icnsFileUrl
; /* The URL of the original ICNS icon file */
4864 CGImageDestinationRef destRef
; /* The image destination to write */
4865 size_t bytesPerRow
; /* The bytes per row used for resizing */
4866 CGContextRef context
; /* The CG context used for resizing */
4868 snprintf(outPath
, sizeof(outPath
), "%s/%s.png", CacheDir
, p
->name
);
4869 outUrl
= CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault
,
4873 icnsFileUrl
= CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault
,
4874 (UInt8
*)ppd_attr
->value
,
4875 strlen(ppd_attr
->value
),
4877 if (outUrl
&& icnsFileUrl
)
4879 sourceRef
= CGImageSourceCreateWithURL(icnsFileUrl
, NULL
);
4882 for (i
= 0; i
< CGImageSourceGetCount(sourceRef
); i
++)
4884 imageRef
= CGImageSourceCreateImageAtIndex(sourceRef
, i
, NULL
);
4888 if (CGImageGetWidth(imageRef
) == CGImageGetHeight(imageRef
))
4891 * Loop through remembering the icon closest to 128 but >= 128
4892 * and then remember the largest icon.
4895 if (CGImageGetWidth(imageRef
) >= 128 &&
4896 (!closestTo128IconRef
||
4897 CGImageGetWidth(imageRef
) <
4898 CGImageGetWidth(closestTo128IconRef
)))
4900 CGImageRelease(closestTo128IconRef
);
4901 CGImageRetain(imageRef
);
4902 closestTo128IconRef
= imageRef
;
4905 if (!biggestIconRef
||
4906 CGImageGetWidth(imageRef
) > CGImageGetWidth(biggestIconRef
))
4908 CGImageRelease(biggestIconRef
);
4909 CGImageRetain(imageRef
);
4910 biggestIconRef
= imageRef
;
4914 CGImageRelease(imageRef
);
4920 * If biggestIconRef is NULL, we found no icons. Otherwise we first
4921 * want the closest to 128, but if none are larger than 128, we want
4922 * the largest icon available.
4925 imageRef
= closestTo128IconRef
? closestTo128IconRef
:
4927 CGImageRetain(imageRef
);
4928 CGImageRelease(biggestIconRef
);
4929 if (closestTo128IconRef
)
4930 CGImageRelease(closestTo128IconRef
);
4931 destRef
= CGImageDestinationCreateWithURL(outUrl
, kUTTypePNG
, 1,
4935 if (CGImageGetWidth(imageRef
) != 128)
4937 bytesPerRow
= CGImageGetBytesPerRow(imageRef
) /
4938 CGImageGetWidth(imageRef
) * 128;
4939 context
= CGBitmapContextCreate(NULL
, 128, 128,
4940 CGImageGetBitsPerComponent(imageRef
),
4942 CGImageGetColorSpace(imageRef
),
4943 kCGImageAlphaPremultipliedFirst
);
4946 CGContextDrawImage(context
, CGRectMake(0, 0, 128, 128),
4948 CGImageRelease(imageRef
);
4949 imageRef
= CGBitmapContextCreateImage(context
);
4950 CGContextRelease(context
);
4954 CGImageDestinationAddImage(destRef
, imageRef
, NULL
);
4955 CGImageDestinationFinalize(destRef
);
4959 CGImageRelease(imageRef
);
4962 CFRelease(sourceRef
);
4970 CFRelease(icnsFileUrl
);
4972 #endif /* HAVE_APPLICATIONSERVICES_H */
4975 * Close the PPD and set the type...
4980 else if (!access(ppd_name
, 0))
4982 int pline
; /* PPD line number */
4983 ppd_status_t pstatus
; /* PPD load status */
4986 pstatus
= ppdLastError(&pline
);
4988 cupsdLogMessage(CUPSD_LOG_ERROR
, "PPD file for %s cannot be loaded!",
4991 if (pstatus
<= PPD_ALLOC_ERROR
)
4992 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s", strerror(errno
));
4994 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s on line %d.",
4995 ppdErrorString(pstatus
), pline
);
4997 cupsdLogMessage(CUPSD_LOG_INFO
,
4998 "Hint: Run \"cupstestppd %s\" and fix any errors.",
5004 * If we have an interface script, add a filter entry for it...
5007 char interface
[1024]; /* Interface script */
5010 snprintf(interface
, sizeof(interface
), "%s/interfaces/%s", ServerRoot
,
5012 if (!access(interface
, X_OK
))
5015 * Yes, we have a System V style interface script; use it!
5018 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
5019 "printer-make-and-model", NULL
,
5020 "Local System V Printer");
5022 else if (!strncmp(p
->device_uri
, "ipp://", 6) &&
5023 (strstr(p
->device_uri
, "/printers/") != NULL
||
5024 strstr(p
->device_uri
, "/classes/") != NULL
||
5025 (strstr(p
->device_uri
, "._ipp.") != NULL
&&
5026 !strcmp(p
->device_uri
+ strlen(p
->device_uri
) - 5,
5030 * Tell the client this is really a hard-wired remote printer.
5033 p
->type
|= CUPS_PRINTER_REMOTE
;
5036 * Point the printer-uri-supported attribute to the
5040 if (strchr(p
->device_uri
, '?'))
5043 * Strip trailing "?options" from URI...
5046 char resource
[HTTP_MAX_URI
], /* New URI */
5047 *ptr
; /* Pointer into URI */
5049 strlcpy(resource
, p
->device_uri
, sizeof(resource
));
5050 if ((ptr
= strchr(resource
, '?')) != NULL
)
5053 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
5054 "printer-uri-supported", NULL
, resource
);
5057 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
5058 "printer-uri-supported", NULL
, p
->device_uri
);
5061 * Then set the make-and-model accordingly...
5064 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
5065 "printer-make-and-model", NULL
, "Remote Printer");
5068 * Print all files directly...
5077 * Otherwise we have neither - treat this as a "dumb" printer
5078 * with no PPD file...
5081 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
5082 "printer-make-and-model", NULL
, "Local Raw Printer");
5088 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
5089 "finishings-supported", num_finishings
, finishings
);
5090 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
5091 "finishings-default", IPP_FINISHINGS_NONE
);
5096 * Save cached PPD attributes to disk...
5099 cupsdLogMessage(CUPSD_LOG_DEBUG
, "load_ppd: Saving %s...", cache_name
);
5101 _ppdCacheWriteFile(p
->pc
, cache_name
, p
->ppd_attrs
);
5106 * Remove cache files...
5109 if (cache_info
.st_mtime
)
5116 * 'new_media_col()' - Create a media-col collection value.
5119 static ipp_t
* /* O - Collection value */
5120 new_media_col(_pwg_size_t
*size
, /* I - media-size/margin values */
5121 const char *source
, /* I - media-source value */
5122 const char *type
) /* I - media-type value */
5124 ipp_t
*media_col
, /* Collection value */
5125 *media_size
; /* media-size value */
5128 media_col
= ippNew();
5130 media_size
= ippNew();
5131 ippAddInteger(media_size
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5132 "x-dimension", size
->width
);
5133 ippAddInteger(media_size
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5134 "y-dimension", size
->length
);
5135 ippAddCollection(media_col
, IPP_TAG_PRINTER
, "media-size", media_size
);
5136 ippDelete(media_size
);
5138 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5139 "media-bottom-margin", size
->bottom
);
5140 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5141 "media-left-margin", size
->left
);
5142 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5143 "media-right-margin", size
->right
);
5144 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5145 "media-top-margin", size
->top
);
5148 ippAddString(media_col
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
, "media-source",
5152 ippAddString(media_col
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
, "media-type",
5161 * 'write_irix_config()' - Update the config files used by the IRIX
5166 write_irix_config(cupsd_printer_t
*p
) /* I - Printer to update */
5168 char filename
[1024]; /* Interface script filename */
5169 cups_file_t
*fp
; /* Interface script file */
5170 ipp_attribute_t
*attr
; /* Attribute data */
5174 * Add dummy interface and GUI scripts to fool SGI's "challenged" printing
5175 * tools. First the interface script that tells the tools what kind of
5176 * printer we have...
5179 snprintf(filename
, sizeof(filename
), "/var/spool/lp/interface/%s", p
->name
);
5181 if (p
->type
& CUPS_PRINTER_CLASS
)
5183 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
5185 cupsFilePuts(fp
, "#!/bin/sh\n");
5187 if ((attr
= ippFindAttribute(p
->attrs
, "printer-make-and-model",
5188 IPP_TAG_TEXT
)) != NULL
)
5189 cupsFilePrintf(fp
, "NAME=\"%s\"\n", attr
->values
[0].string
.text
);
5190 else if (p
->type
& CUPS_PRINTER_CLASS
)
5191 cupsFilePuts(fp
, "NAME=\"Printer Class\"\n");
5193 cupsFilePuts(fp
, "NAME=\"Remote Destination\"\n");
5195 if (p
->type
& CUPS_PRINTER_COLOR
)
5196 cupsFilePuts(fp
, "TYPE=ColorPostScript\n");
5198 cupsFilePuts(fp
, "TYPE=MonoPostScript\n");
5200 cupsFilePrintf(fp
, "HOSTNAME=%s\n", ServerName
);
5201 cupsFilePrintf(fp
, "HOSTPRINTER=%s\n", p
->name
);
5205 chmod(filename
, 0755);
5206 chown(filename
, User
, Group
);
5210 * Then the member file that tells which device file the queue is connected
5211 * to... Networked printers use "/dev/null" in this file, so that's what
5212 * we use (the actual device URI can confuse some apps...)
5215 snprintf(filename
, sizeof(filename
), "/var/spool/lp/member/%s", p
->name
);
5217 if (p
->type
& CUPS_PRINTER_CLASS
)
5219 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
5221 cupsFilePuts(fp
, "/dev/null\n");
5225 chmod(filename
, 0644);
5226 chown(filename
, User
, Group
);
5230 * The gui_interface file is a script or program that launches a GUI
5231 * option panel for the printer, using options specified on the
5232 * command-line in the third argument. The option panel must send
5233 * any printing options to stdout on a single line when the user
5234 * accepts them, or nothing if the user cancels the dialog.
5236 * The default options panel program is /usr/bin/glpoptions, from
5237 * the ESP Print Pro software. You can select another using the
5238 * PrintcapGUI option.
5241 snprintf(filename
, sizeof(filename
), "/var/spool/lp/gui_interface/ELF/%s.gui", p
->name
);
5243 if (p
->type
& CUPS_PRINTER_CLASS
)
5245 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
5247 cupsFilePuts(fp
, "#!/bin/sh\n");
5248 cupsFilePrintf(fp
, "%s -d %s -o \"$3\"\n", PrintcapGUI
, p
->name
);
5252 chmod(filename
, 0755);
5253 chown(filename
, User
, Group
);
5257 * The POD config file is needed by the printstatus command to show
5258 * the printer location and device.
5261 snprintf(filename
, sizeof(filename
), "/var/spool/lp/pod/%s.config", p
->name
);
5263 if (p
->type
& CUPS_PRINTER_CLASS
)
5265 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
5267 cupsFilePrintf(fp
, "Printer Class | %s\n",
5268 (p
->type
& CUPS_PRINTER_COLOR
) ? "ColorPostScript" : "MonoPostScript");
5269 cupsFilePrintf(fp
, "Printer Model | %s\n", p
->make_model
? p
->make_model
: "");
5270 cupsFilePrintf(fp
, "Location Code | %s\n", p
->location
? p
->location
: "");
5271 cupsFilePrintf(fp
, "Physical Location | %s\n", p
->info
? p
->info
: "");
5272 cupsFilePrintf(fp
, "Port Path | %s\n", p
->device_uri
);
5273 cupsFilePrintf(fp
, "Config Path | /var/spool/lp/pod/%s.config\n", p
->name
);
5274 cupsFilePrintf(fp
, "Active Status Path | /var/spool/lp/pod/%s.status\n", p
->name
);
5275 cupsFilePuts(fp
, "Status Update Wait | 10 seconds\n");
5279 chmod(filename
, 0664);
5280 chown(filename
, User
, Group
);
5286 * 'write_irix_state()' - Update the status files used by IRIX printing
5291 write_irix_state(cupsd_printer_t
*p
) /* I - Printer to update */
5293 char filename
[1024]; /* Interface script filename */
5294 cups_file_t
*fp
; /* Interface script file */
5295 int tag
; /* Status tag value */
5301 * The POD status file is needed for the printstatus window to
5302 * provide the current status of the printer.
5305 snprintf(filename
, sizeof(filename
), "/var/spool/lp/pod/%s.status", p
->name
);
5307 if (p
->type
& CUPS_PRINTER_CLASS
)
5309 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
5311 cupsFilePrintf(fp
, "Operational Status | %s\n",
5312 (p
->state
== IPP_PRINTER_IDLE
) ? "Idle" :
5313 (p
->state
== IPP_PRINTER_PROCESSING
) ? "Busy" :
5315 cupsFilePrintf(fp
, "Information | 01 00 00 | %s\n", CUPS_SVERSION
);
5316 cupsFilePrintf(fp
, "Information | 02 00 00 | Device URI: %s\n",
5318 cupsFilePrintf(fp
, "Information | 03 00 00 | %s jobs\n",
5319 p
->accepting
? "Accepting" : "Not accepting");
5320 cupsFilePrintf(fp
, "Information | 04 00 00 | %s\n", p
->state_message
);
5324 chmod(filename
, 0664);
5325 chown(filename
, User
, Group
);
5329 * The activeicons file is needed to provide desktop icons for printers:
5331 * [ quoted from /usr/lib/print/tagit ]
5333 * --- Type of printer tags (base values)
5335 * Dumb=66048 # 0x10200
5336 * DumbColor=66080 # 0x10220
5337 * Raster=66112 # 0x10240
5338 * ColorRaster=66144 # 0x10260
5339 * Plotter=66176 # 0x10280
5340 * PostScript=66208 # 0x102A0
5341 * ColorPostScript=66240 # 0x102C0
5342 * MonoPostScript=66272 # 0x102E0
5344 * --- Printer state modifiers for local printers
5349 * Unknown=3 # 0x3 (Faulted due to unknown reason)
5351 * --- Printer state modifiers for network printers
5355 * NetFaulted=10 # 0xA
5356 * NetUnknown=11 # 0xB (Faulted due to unknown reason)
5359 snprintf(filename
, sizeof(filename
), "/var/spool/lp/activeicons/%s", p
->name
);
5361 if (p
->type
& CUPS_PRINTER_CLASS
)
5363 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
5365 if (p
->type
& CUPS_PRINTER_COLOR
)
5370 if (p
->type
& CUPS_PRINTER_REMOTE
)
5373 if (p
->state
== IPP_PRINTER_PROCESSING
)
5376 else if (p
->state
== IPP_PRINTER_STOPPED
)
5379 cupsFilePuts(fp
, "#!/bin/sh\n");
5380 cupsFilePrintf(fp
, "#Tag %d\n", tag
);
5384 chmod(filename
, 0755);
5385 chown(filename
, User
, Group
);
5390 * The default file is needed by the printers window to show
5391 * the default printer.
5394 snprintf(filename
, sizeof(filename
), "/var/spool/lp/default");
5396 if (DefaultPrinter
!= NULL
)
5398 if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
5400 cupsFilePrintf(fp
, "%s\n", DefaultPrinter
->name
);
5404 chmod(filename
, 0644);
5405 chown(filename
, User
, Group
);
5415 * 'write_xml_string()' - Write a string with XML escaping.
5419 write_xml_string(cups_file_t
*fp
, /* I - File to write to */
5420 const char *s
) /* I - String to write */
5422 const char *start
; /* Start of current sequence */
5428 for (start
= s
; *s
; s
++)
5433 cupsFileWrite(fp
, start
, s
- start
);
5435 cupsFilePuts(fp
, "&");
5441 cupsFileWrite(fp
, start
, s
- start
);
5443 cupsFilePuts(fp
, "<");
5449 cupsFilePuts(fp
, start
);
5454 * End of "$Id: printers.c 7968 2008-09-19 23:03:01Z mike $".