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 printer_settable
[] =
376 { /* printer-settable-attributes-supported */
380 static const char * const which_jobs
[] =
381 { /* which-jobs-supported values */
395 ippDelete(CommonData
);
397 CommonData
= ippNew();
400 * Get the maximum spool size based on the size of the filesystem used for
401 * the RequestRoot directory. If the host OS doesn't support the statfs call
402 * or the filesystem is larger than 2TiB, always report INT_MAX.
406 if (statvfs(RequestRoot
, &spoolinfo
))
407 k_supported
= INT_MAX
;
408 else if ((spoolsize
= (double)spoolinfo
.f_frsize
* spoolinfo
.f_blocks
/ 1024) >
410 k_supported
= INT_MAX
;
412 k_supported
= (int)spoolsize
;
414 #elif defined(HAVE_STATFS)
415 if (statfs(RequestRoot
, &spoolinfo
))
416 k_supported
= INT_MAX
;
417 else if ((spoolsize
= (double)spoolinfo
.f_bsize
* spoolinfo
.f_blocks
/ 1024) >
419 k_supported
= INT_MAX
;
421 k_supported
= (int)spoolsize
;
424 k_supported
= INT_MAX
;
425 #endif /* HAVE_STATVFS */
428 * This list of attributes is sorted to improve performance when the
429 * client provides a requested-attributes attribute...
432 /* charset-configured */
433 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_CHARSET
| IPP_TAG_COPY
,
434 "charset-configured", NULL
, "utf-8");
436 /* charset-supported */
437 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_CHARSET
| IPP_TAG_COPY
,
438 "charset-supported", sizeof(charsets
) / sizeof(charsets
[0]),
441 /* compression-supported */
442 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
443 "compression-supported",
444 sizeof(compressions
) / sizeof(compressions
[0]),
447 /* copies-supported */
448 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "copies-supported", 1, MaxCopies
);
451 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
| IPP_TAG_COPY
,
452 "cups-version", NULL
, CUPS_SVERSION
+ 6);
454 /* generated-natural-language-supported (no IPP_TAG_COPY) */
455 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_LANGUAGE
,
456 "generated-natural-language-supported", NULL
, DefaultLanguage
);
458 /* ipp-versions-supported */
459 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
460 "ipp-versions-supported", sizeof(versions
) / sizeof(versions
[0]),
463 /* ippget-event-life */
464 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
465 "ippget-event-life", 15);
467 /* job-creation-attributes-supported */
468 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
469 "job-creation-attributes-supported",
470 sizeof(job_creation
) / sizeof(job_creation
[0]),
473 /* job-hold-until-supported */
474 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
475 "job-hold-until-supported", sizeof(holds
) / sizeof(holds
[0]),
478 /* job-ids-supported */
479 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
, "job-ids-supported", 1);
481 /* job-k-octets-supported */
482 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
483 "job-k-octets-supported", k_supported
);
485 /* job-priority-supported */
486 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
487 "job-priority-supported", 100);
489 /* job-settable-attributes-supported */
490 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
491 "job-settable-attributes-supported",
492 sizeof(job_settable
) / sizeof(job_settable
[0]),
495 /* job-sheets-supported */
496 if (cupsArrayCount(Banners
) > 0)
499 * Setup the job-sheets-supported attribute...
502 if (Classification
&& !ClassifyOverride
)
503 attr
= ippAddString(CommonData
, IPP_TAG_PRINTER
,
504 IPP_TAG_NAME
| IPP_TAG_COPY
,
505 "job-sheets-supported", NULL
, Classification
);
507 attr
= ippAddStrings(CommonData
, IPP_TAG_PRINTER
,
508 IPP_TAG_NAME
| IPP_TAG_COPY
,
509 "job-sheets-supported", cupsArrayCount(Banners
) + 1,
513 cupsdLogMessage(CUPSD_LOG_EMERG
,
514 "Unable to allocate memory for "
515 "job-sheets-supported attribute: %s!", strerror(errno
));
516 else if (!Classification
|| ClassifyOverride
)
518 cupsd_banner_t
*banner
; /* Current banner */
521 attr
->values
[0].string
.text
= _cupsStrAlloc("none");
523 for (i
= 1, banner
= (cupsd_banner_t
*)cupsArrayFirst(Banners
);
525 i
++, banner
= (cupsd_banner_t
*)cupsArrayNext(Banners
))
526 attr
->values
[i
].string
.text
= banner
->name
;
530 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
531 "job-sheets-supported", NULL
, "none");
533 /* media-col-supported */
534 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
535 "media-col-supported",
536 sizeof(media_col_supported
) /
537 sizeof(media_col_supported
[0]), NULL
,
538 media_col_supported
);
540 /* multiple-document-handling-supported */
541 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
542 "multiple-document-handling-supported",
543 sizeof(multiple_document_handling
) /
544 sizeof(multiple_document_handling
[0]), NULL
,
545 multiple_document_handling
);
547 /* multiple-document-jobs-supported */
548 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
,
549 "multiple-document-jobs-supported", 1);
551 /* multiple-operation-time-out */
552 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
553 "multiple-operation-time-out", MultipleOperationTimeout
);
555 /* natural-language-configured (no IPP_TAG_COPY) */
556 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_LANGUAGE
,
557 "natural-language-configured", NULL
, DefaultLanguage
);
559 /* notify-attributes-supported */
560 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
561 "notify-attributes-supported",
562 (int)(sizeof(notify_attrs
) / sizeof(notify_attrs
[0])),
565 /* notify-lease-duration-supported */
566 ippAddRange(CommonData
, IPP_TAG_PRINTER
,
567 "notify-lease-duration-supported", 0,
568 MaxLeaseDuration
? MaxLeaseDuration
: 2147483647);
570 /* notify-max-events-supported */
571 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
572 "notify-max-events-supported", MaxEvents
);
574 /* notify-events-supported */
575 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
576 "notify-events-supported",
577 (int)(sizeof(notify_events
) / sizeof(notify_events
[0])),
578 NULL
, notify_events
);
580 /* notify-pull-method-supported */
581 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
582 "notify-pull-method-supported", NULL
, "ippget");
584 /* notify-schemes-supported */
585 snprintf(filename
, sizeof(filename
), "%s/notifier", ServerBin
);
586 if ((dir
= cupsDirOpen(filename
)) != NULL
)
588 notifiers
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
590 while ((dent
= cupsDirRead(dir
)) != NULL
)
591 if (S_ISREG(dent
->fileinfo
.st_mode
) &&
592 (dent
->fileinfo
.st_mode
& S_IXOTH
) != 0)
593 cupsArrayAdd(notifiers
, _cupsStrAlloc(dent
->filename
));
595 if (cupsArrayCount(notifiers
) > 0)
597 attr
= ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
598 "notify-schemes-supported",
599 cupsArrayCount(notifiers
), NULL
, NULL
);
601 for (i
= 0, notifier
= (char *)cupsArrayFirst(notifiers
);
603 i
++, notifier
= (char *)cupsArrayNext(notifiers
))
604 attr
->values
[i
].string
.text
= notifier
;
607 cupsArrayDelete(notifiers
);
611 /* number-up-supported */
612 ippAddIntegers(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
613 "number-up-supported", sizeof(nups
) / sizeof(nups
[0]), nups
);
615 /* operations-supported */
616 ippAddIntegers(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
617 "operations-supported",
618 sizeof(ops
) / sizeof(ops
[0]) + JobFiles
- 1, ops
);
620 /* orientation-requested-supported */
621 ippAddIntegers(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
622 "orientation-requested-supported", 4, orients
);
624 /* page-ranges-supported */
625 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
, "page-ranges-supported", 1);
627 /* pdl-override-supported */
628 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
629 "pdl-override-supported", NULL
, "attempted");
631 /* printer-op-policy-supported */
632 attr
= ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
633 "printer-op-policy-supported", cupsArrayCount(Policies
),
635 for (i
= 0, p
= (cupsd_policy_t
*)cupsArrayFirst(Policies
);
637 i
++, p
= (cupsd_policy_t
*)cupsArrayNext(Policies
))
638 attr
->values
[i
].string
.text
= p
->name
;
640 /* printer-settable-attributes-supported */
641 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
642 "printer-settable-attributes-supported",
643 sizeof(printer_settable
) / sizeof(printer_settable
[0]),
644 NULL
, printer_settable
);
646 /* server-is-sharing-printers */
647 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
, "server-is-sharing-printers",
648 BrowseLocalProtocols
!= 0 && Browsing
);
650 /* which-jobs-supported */
651 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
652 "which-jobs-supported",
653 sizeof(which_jobs
) / sizeof(which_jobs
[0]), NULL
, which_jobs
);
658 * 'cupsdDeleteAllPrinters()' - Delete all printers from the system.
662 cupsdDeleteAllPrinters(void)
664 cupsd_printer_t
*p
; /* Pointer to current printer/class */
667 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
669 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
671 p
->op_policy_ptr
= DefaultPolicyPtr
;
672 cupsdDeletePrinter(p
, 0);
678 * 'cupsdDeletePrinter()' - Delete a printer from the system.
681 int /* O - 1 if classes affected, 0 otherwise */
683 cupsd_printer_t
*p
, /* I - Printer to delete */
684 int update
) /* I - Update printers.conf? */
686 int i
, /* Looping var */
687 changed
= 0; /* Class changed? */
689 char filename
[1024]; /* Interface script filename */
693 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdDeletePrinter(p=%p(%s), update=%d)",
697 * Save the current position in the Printers array...
700 cupsArraySave(Printers
);
703 * Stop printing on this printer...
706 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, update
);
708 p
->state
= IPP_PRINTER_STOPPED
; /* Force for browsed printers */
711 cupsdSetJobState(p
->job
, IPP_JOB_PENDING
, CUPSD_JOB_FORCE
,
712 update
? "Job stopped due to printer being deleted." :
716 * If this printer is the next for browsing, point to the next one...
721 cupsArrayFind(Printers
, p
);
722 BrowseNext
= (cupsd_printer_t
*)cupsArrayNext(Printers
);
726 * Remove the printer from the list...
729 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
730 "cupsdDeletePrinter: Removing %s from Printers", p
->name
);
731 cupsArrayRemove(Printers
, p
);
733 if (p
->type
& CUPS_PRINTER_IMPLICIT
)
735 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
736 "cupsdDeletePrinter: Removing %s from ImplicitPrinters",
738 cupsArrayRemove(ImplicitPrinters
, p
);
742 * Remove the dummy interface/icon/option files under IRIX...
746 snprintf(filename
, sizeof(filename
), "/var/spool/lp/interface/%s", p
->name
);
749 snprintf(filename
, sizeof(filename
), "/var/spool/lp/gui_interface/ELF/%s.gui",
753 snprintf(filename
, sizeof(filename
), "/var/spool/lp/activeicons/%s", p
->name
);
756 snprintf(filename
, sizeof(filename
), "/var/spool/lp/pod/%s.config", p
->name
);
759 snprintf(filename
, sizeof(filename
), "/var/spool/lp/pod/%s.status", p
->name
);
762 snprintf(filename
, sizeof(filename
), "/var/spool/lp/member/%s", p
->name
);
767 * If p is the default printer, assign a different one...
770 if (p
== DefaultPrinter
)
772 DefaultPrinter
= NULL
;
774 if (UseNetworkDefault
)
777 * Find the first network default printer and use it...
780 cupsd_printer_t
*dp
; /* New default printer */
783 for (dp
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
785 dp
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
786 if (dp
!= p
&& (dp
->type
& CUPS_PRINTER_DEFAULT
))
795 * Remove this printer from any classes...
798 if (!(p
->type
& CUPS_PRINTER_IMPLICIT
))
800 changed
= cupsdDeletePrinterFromClasses(p
);
803 * Deregister from any browse protocols...
806 cupsdDeregisterPrinter(p
, 1);
810 * Free all memory used by the printer...
813 if (p
->printers
!= NULL
)
816 delete_printer_filters(p
);
818 for (i
= 0; i
< p
->num_reasons
; i
++)
819 _cupsStrFree(p
->reasons
[i
]);
822 ippDelete(p
->ppd_attrs
);
824 mimeDeleteType(MimeDatabase
, p
->filetype
);
825 mimeDeleteType(MimeDatabase
, p
->prefiltertype
);
827 cupsdFreeStrings(&(p
->users
));
830 cupsdClearString(&p
->uri
);
831 cupsdClearString(&p
->hostname
);
832 cupsdClearString(&p
->name
);
833 cupsdClearString(&p
->location
);
834 cupsdClearString(&p
->make_model
);
835 cupsdClearString(&p
->info
);
836 cupsdClearString(&p
->job_sheets
[0]);
837 cupsdClearString(&p
->job_sheets
[1]);
838 cupsdClearString(&p
->device_uri
);
839 cupsdClearString(&p
->sanitized_device_uri
);
840 cupsdClearString(&p
->port_monitor
);
841 cupsdClearString(&p
->op_policy
);
842 cupsdClearString(&p
->error_policy
);
844 cupsdClearString(&p
->alert
);
845 cupsdClearString(&p
->alert_description
);
848 cupsdClearString(&p
->pdl
);
849 #endif /* HAVE_DNSSD */
851 cupsArrayDelete(p
->filetypes
);
854 free(p
->browse_attrs
);
856 cupsFreeOptions(p
->num_options
, p
->options
);
861 * Restore the previous position in the Printers array...
864 cupsArrayRestore(Printers
);
871 * 'cupsdFindDest()' - Find a destination in the list.
874 cupsd_printer_t
* /* O - Destination in list */
875 cupsdFindDest(const char *name
) /* I - Name of printer or class to find */
877 cupsd_printer_t key
; /* Search key */
880 key
.name
= (char *)name
;
881 return ((cupsd_printer_t
*)cupsArrayFind(Printers
, &key
));
886 * 'cupsdFindPrinter()' - Find a printer in the list.
889 cupsd_printer_t
* /* O - Printer in list */
890 cupsdFindPrinter(const char *name
) /* I - Name of printer to find */
892 cupsd_printer_t
*p
; /* Printer in list */
895 if ((p
= cupsdFindDest(name
)) != NULL
&& (p
->type
& CUPS_PRINTER_CLASS
))
903 * 'cupsdLoadAllPrinters()' - Load printers from the printers.conf file.
907 cupsdLoadAllPrinters(void)
909 int i
; /* Looping var */
910 cups_file_t
*fp
; /* printers.conf file */
911 int linenum
; /* Current line number */
912 char line
[4096], /* Line from file */
913 *value
, /* Pointer to value */
914 *valueptr
; /* Pointer into value */
915 cupsd_printer_t
*p
; /* Current printer */
919 * Open the printers.conf file...
922 snprintf(line
, sizeof(line
), "%s/printers.conf", ServerRoot
);
923 if ((fp
= cupsFileOpen(line
, "r")) == NULL
)
926 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to open %s - %s", line
,
932 * Read printer configurations until we hit EOF...
938 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
941 * Decode the directive...
944 if (!strcasecmp(line
, "<Printer") ||
945 !strcasecmp(line
, "<DefaultPrinter"))
948 * <Printer name> or <DefaultPrinter name>
951 if (p
== NULL
&& value
)
954 * Add the printer and a base file type...
957 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Loading printer %s...", value
);
959 p
= cupsdAddPrinter(value
);
961 p
->state
= IPP_PRINTER_IDLE
;
964 * Set the default printer as needed...
967 if (!strcasecmp(line
, "<DefaultPrinter"))
971 cupsdLogMessage(CUPSD_LOG_ERROR
,
972 "Syntax error on line %d of printers.conf.", linenum
);
974 else if (!strcasecmp(line
, "</Printer>"))
979 * Close out the current printer...
982 cupsdSetPrinterAttrs(p
);
984 if (strncmp(p
->device_uri
, "file:", 5) &&
985 p
->state
!= IPP_PRINTER_STOPPED
)
988 * See if the backend exists...
991 snprintf(line
, sizeof(line
), "%s/backend/%s", ServerBin
,
994 if ((valueptr
= strchr(line
+ strlen(ServerBin
), ':')) != NULL
)
995 *valueptr
= '\0'; /* Chop everything but URI scheme */
1000 * Backend does not exist, stop printer...
1003 p
->state
= IPP_PRINTER_STOPPED
;
1004 snprintf(p
->state_message
, sizeof(p
->state_message
),
1005 "Backend %s does not exist!", line
);
1012 cupsdLogMessage(CUPSD_LOG_ERROR
,
1013 "Syntax error on line %d of printers.conf.", linenum
);
1017 cupsdLogMessage(CUPSD_LOG_ERROR
,
1018 "Syntax error on line %d of printers.conf.", linenum
);
1020 else if (!strcasecmp(line
, "UUID"))
1022 if (value
&& !strncmp(value
, "urn:uuid:", 9))
1023 cupsdSetString(&(p
->uuid
), value
);
1025 cupsdLogMessage(CUPSD_LOG_ERROR
,
1026 "Bad UUID on line %d of printers.conf.", linenum
);
1028 else if (!strcasecmp(line
, "AuthInfoRequired"))
1030 if (!cupsdSetAuthInfoRequired(p
, value
, NULL
))
1031 cupsdLogMessage(CUPSD_LOG_ERROR
,
1032 "Bad AuthInfoRequired on line %d of printers.conf.",
1035 else if (!strcasecmp(line
, "Info"))
1038 cupsdSetString(&p
->info
, value
);
1040 else if (!strcasecmp(line
, "MakeModel"))
1043 cupsdSetString(&p
->make_model
, value
);
1045 else if (!strcasecmp(line
, "Location"))
1048 cupsdSetString(&p
->location
, value
);
1050 else if (!strcasecmp(line
, "DeviceURI"))
1053 cupsdSetDeviceURI(p
, value
);
1055 cupsdLogMessage(CUPSD_LOG_ERROR
,
1056 "Syntax error on line %d of printers.conf.", linenum
);
1058 else if (!strcasecmp(line
, "Option") && value
)
1064 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1067 cupsdLogMessage(CUPSD_LOG_ERROR
,
1068 "Syntax error on line %d of printers.conf.", linenum
);
1071 for (; *valueptr
&& isspace(*valueptr
& 255); *valueptr
++ = '\0');
1073 p
->num_options
= cupsAddOption(value
, valueptr
, p
->num_options
,
1077 else if (!strcasecmp(line
, "PortMonitor"))
1079 if (value
&& strcmp(value
, "none"))
1080 cupsdSetString(&p
->port_monitor
, value
);
1082 cupsdClearString(&p
->port_monitor
);
1084 cupsdLogMessage(CUPSD_LOG_ERROR
,
1085 "Syntax error on line %d of printers.conf.", linenum
);
1087 else if (!strcasecmp(line
, "Reason"))
1090 strcmp(value
, "connecting-to-device") &&
1091 strcmp(value
, "cups-insecure-filter-warning") &&
1092 strcmp(value
, "cups-missing-filter-warning"))
1094 for (i
= 0 ; i
< p
->num_reasons
; i
++)
1095 if (!strcmp(value
, p
->reasons
[i
]))
1098 if (i
>= p
->num_reasons
&&
1099 p
->num_reasons
< (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
1101 p
->reasons
[p
->num_reasons
] = _cupsStrAlloc(value
);
1106 cupsdLogMessage(CUPSD_LOG_ERROR
,
1107 "Syntax error on line %d of printers.conf.", linenum
);
1109 else if (!strcasecmp(line
, "State"))
1112 * Set the initial queue state...
1115 if (value
&& !strcasecmp(value
, "idle"))
1116 p
->state
= IPP_PRINTER_IDLE
;
1117 else if (value
&& !strcasecmp(value
, "stopped"))
1119 p
->state
= IPP_PRINTER_STOPPED
;
1121 for (i
= 0 ; i
< p
->num_reasons
; i
++)
1122 if (!strcmp("paused", p
->reasons
[i
]))
1125 if (i
>= p
->num_reasons
&&
1126 p
->num_reasons
< (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
1128 p
->reasons
[p
->num_reasons
] = _cupsStrAlloc("paused");
1133 cupsdLogMessage(CUPSD_LOG_ERROR
,
1134 "Syntax error on line %d of printers.conf.", linenum
);
1136 else if (!strcasecmp(line
, "StateMessage"))
1139 * Set the initial queue state message...
1143 strlcpy(p
->state_message
, value
, sizeof(p
->state_message
));
1145 else if (!strcasecmp(line
, "StateTime"))
1148 * Set the state time...
1152 p
->state_time
= atoi(value
);
1154 else if (!strcasecmp(line
, "Accepting"))
1157 * Set the initial accepting state...
1161 (!strcasecmp(value
, "yes") ||
1162 !strcasecmp(value
, "on") ||
1163 !strcasecmp(value
, "true")))
1166 (!strcasecmp(value
, "no") ||
1167 !strcasecmp(value
, "off") ||
1168 !strcasecmp(value
, "false")))
1171 cupsdLogMessage(CUPSD_LOG_ERROR
,
1172 "Syntax error on line %d of printers.conf.", linenum
);
1174 else if (!strcasecmp(line
, "Type"))
1177 p
->type
= atoi(value
);
1179 cupsdLogMessage(CUPSD_LOG_ERROR
,
1180 "Syntax error on line %d of printers.conf.", linenum
);
1182 else if (!strcasecmp(line
, "Shared"))
1185 * Set the initial shared state...
1189 (!strcasecmp(value
, "yes") ||
1190 !strcasecmp(value
, "on") ||
1191 !strcasecmp(value
, "true")))
1194 (!strcasecmp(value
, "no") ||
1195 !strcasecmp(value
, "off") ||
1196 !strcasecmp(value
, "false")))
1199 cupsdLogMessage(CUPSD_LOG_ERROR
,
1200 "Syntax error on line %d of printers.conf.", linenum
);
1202 else if (!strcasecmp(line
, "JobSheets"))
1205 * Set the initial job sheets...
1210 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1215 cupsdSetString(&p
->job_sheets
[0], value
);
1217 while (isspace(*valueptr
& 255))
1222 for (value
= valueptr
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1227 cupsdSetString(&p
->job_sheets
[1], value
);
1231 cupsdLogMessage(CUPSD_LOG_ERROR
,
1232 "Syntax error on line %d of printers.conf.", linenum
);
1234 else if (!strcasecmp(line
, "AllowUser"))
1239 cupsdAddString(&(p
->users
), value
);
1242 cupsdLogMessage(CUPSD_LOG_ERROR
,
1243 "Syntax error on line %d of printers.conf.", linenum
);
1245 else if (!strcasecmp(line
, "DenyUser"))
1250 cupsdAddString(&(p
->users
), value
);
1253 cupsdLogMessage(CUPSD_LOG_ERROR
,
1254 "Syntax error on line %d of printers.conf.", linenum
);
1256 else if (!strcasecmp(line
, "QuotaPeriod"))
1259 p
->quota_period
= atoi(value
);
1261 cupsdLogMessage(CUPSD_LOG_ERROR
,
1262 "Syntax error on line %d of printers.conf.", linenum
);
1264 else if (!strcasecmp(line
, "PageLimit"))
1267 p
->page_limit
= atoi(value
);
1269 cupsdLogMessage(CUPSD_LOG_ERROR
,
1270 "Syntax error on line %d of printers.conf.", linenum
);
1272 else if (!strcasecmp(line
, "KLimit"))
1275 p
->k_limit
= atoi(value
);
1277 cupsdLogMessage(CUPSD_LOG_ERROR
,
1278 "Syntax error on line %d of printers.conf.", linenum
);
1280 else if (!strcasecmp(line
, "OpPolicy"))
1284 cupsd_policy_t
*pol
; /* Policy */
1287 if ((pol
= cupsdFindPolicy(value
)) != NULL
)
1289 cupsdSetString(&p
->op_policy
, value
);
1290 p
->op_policy_ptr
= pol
;
1293 cupsdLogMessage(CUPSD_LOG_ERROR
,
1294 "Bad policy \"%s\" on line %d of printers.conf",
1298 cupsdLogMessage(CUPSD_LOG_ERROR
,
1299 "Syntax error on line %d of printers.conf.", linenum
);
1301 else if (!strcasecmp(line
, "ErrorPolicy"))
1304 cupsdSetString(&p
->error_policy
, value
);
1306 cupsdLogMessage(CUPSD_LOG_ERROR
,
1307 "Syntax error on line %d of printers.conf.", linenum
);
1309 else if (!strcasecmp(line
, "Attribute") && value
)
1311 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1314 cupsdLogMessage(CUPSD_LOG_ERROR
,
1315 "Syntax error on line %d of printers.conf.", linenum
);
1318 for (; *valueptr
&& isspace(*valueptr
& 255); *valueptr
++ = '\0');
1321 cupsdSetPrinterAttrs(p
);
1323 if (!strcmp(value
, "marker-change-time"))
1324 p
->marker_time
= atoi(valueptr
);
1326 cupsdSetPrinterAttr(p
, value
, valueptr
);
1332 * Something else we don't understand...
1335 cupsdLogMessage(CUPSD_LOG_ERROR
,
1336 "Unknown configuration directive %s on line %d of printers.conf.",
1346 * 'cupsdRenamePrinter()' - Rename a printer.
1351 cupsd_printer_t
*p
, /* I - Printer */
1352 const char *name
) /* I - New name */
1355 * Remove the printer from the array(s) first...
1358 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1359 "cupsdRenamePrinter: Removing %s from Printers", p
->name
);
1360 cupsArrayRemove(Printers
, p
);
1362 if (p
->type
& CUPS_PRINTER_IMPLICIT
)
1364 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1365 "cupsdRenamePrinter: Removing %s from ImplicitPrinters",
1367 cupsArrayRemove(ImplicitPrinters
, p
);
1371 * Rename the printer type...
1374 mimeDeleteType(MimeDatabase
, p
->filetype
);
1375 p
->filetype
= mimeAddType(MimeDatabase
, "printer", name
);
1377 mimeDeleteType(MimeDatabase
, p
->prefiltertype
);
1378 p
->prefiltertype
= mimeAddType(MimeDatabase
, "prefilter", name
);
1381 * Rename the printer...
1384 cupsdSetString(&p
->name
, name
);
1387 * Reset printer attributes...
1390 cupsdSetPrinterAttrs(p
);
1393 * Add the printer back to the printer array(s)...
1396 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1397 "cupsdRenamePrinter: Adding %s to Printers", p
->name
);
1398 cupsArrayAdd(Printers
, p
);
1400 if (p
->type
& CUPS_PRINTER_IMPLICIT
)
1402 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1403 "cupsdRenamePrinter: Adding %s to ImplicitPrinters",
1405 cupsArrayAdd(ImplicitPrinters
, p
);
1411 * 'cupsdSaveAllPrinters()' - Save all printer definitions to the printers.conf
1416 cupsdSaveAllPrinters(void)
1418 int i
; /* Looping var */
1419 cups_file_t
*fp
; /* printers.conf file */
1420 char temp
[1024], /* Temporary string */
1421 backup
[1024], /* printers.conf.O file */
1422 value
[2048], /* Value string */
1423 *ptr
, /* Pointer into value */
1424 *name
; /* Current user/group name */
1425 cupsd_printer_t
*printer
; /* Current printer class */
1426 time_t curtime
; /* Current time */
1427 struct tm
*curdate
; /* Current date */
1428 cups_option_t
*option
; /* Current option */
1429 ipp_attribute_t
*marker
; /* Current marker attribute */
1433 * Create the printers.conf file...
1436 snprintf(temp
, sizeof(temp
), "%s/printers.conf", ServerRoot
);
1437 snprintf(backup
, sizeof(backup
), "%s/printers.conf.O", ServerRoot
);
1439 if (rename(temp
, backup
))
1441 if (errno
!= ENOENT
)
1442 cupsdLogMessage(CUPSD_LOG_ERROR
,
1443 "Unable to backup printers.conf - %s", strerror(errno
));
1446 if ((fp
= cupsFileOpen(temp
, "w")) == NULL
)
1448 cupsdLogMessage(CUPSD_LOG_ERROR
,
1449 "Unable to save printers.conf - %s", strerror(errno
));
1451 if (rename(backup
, temp
))
1452 cupsdLogMessage(CUPSD_LOG_ERROR
,
1453 "Unable to restore printers.conf - %s", strerror(errno
));
1457 cupsdLogMessage(CUPSD_LOG_INFO
, "Saving printers.conf...");
1460 * Restrict access to the file...
1463 fchown(cupsFileNumber(fp
), getuid(), Group
);
1464 fchmod(cupsFileNumber(fp
), ConfigFilePerm
& 0600);
1467 * Write a small header to the file...
1470 curtime
= time(NULL
);
1471 curdate
= localtime(&curtime
);
1472 strftime(temp
, sizeof(temp
) - 1, "%Y-%m-%d %H:%M", curdate
);
1474 cupsFilePuts(fp
, "# Printer configuration file for " CUPS_SVERSION
"\n");
1475 cupsFilePrintf(fp
, "# Written by cupsd on %s\n", temp
);
1476 cupsFilePuts(fp
, "# DO NOT EDIT THIS FILE WHEN CUPSD IS RUNNING\n");
1479 * Write each local printer known to the system...
1482 for (printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
1484 printer
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
1487 * Skip remote destinations and printer classes...
1490 if ((printer
->type
& CUPS_PRINTER_DISCOVERED
) ||
1491 (printer
->type
& CUPS_PRINTER_CLASS
) ||
1492 (printer
->type
& CUPS_PRINTER_IMPLICIT
))
1496 * Write printers as needed...
1499 if (printer
== DefaultPrinter
)
1500 cupsFilePrintf(fp
, "<DefaultPrinter %s>\n", printer
->name
);
1502 cupsFilePrintf(fp
, "<Printer %s>\n", printer
->name
);
1504 cupsFilePrintf(fp
, "UUID %s\n", printer
->uuid
);
1506 if (printer
->num_auth_info_required
> 0)
1508 switch (printer
->num_auth_info_required
)
1511 strlcpy(value
, printer
->auth_info_required
[0], sizeof(value
));
1515 snprintf(value
, sizeof(value
), "%s,%s",
1516 printer
->auth_info_required
[0],
1517 printer
->auth_info_required
[1]);
1522 snprintf(value
, sizeof(value
), "%s,%s,%s",
1523 printer
->auth_info_required
[0],
1524 printer
->auth_info_required
[1],
1525 printer
->auth_info_required
[2]);
1529 cupsFilePutConf(fp
, "AuthInfoRequired", value
);
1533 cupsFilePutConf(fp
, "Info", printer
->info
);
1535 if (printer
->location
)
1536 cupsFilePutConf(fp
, "Location", printer
->location
);
1538 if (printer
->make_model
)
1539 cupsFilePutConf(fp
, "MakeModel", printer
->make_model
);
1541 cupsFilePutConf(fp
, "DeviceURI", printer
->device_uri
);
1543 if (printer
->port_monitor
)
1544 cupsFilePutConf(fp
, "PortMonitor", printer
->port_monitor
);
1546 if (printer
->state
== IPP_PRINTER_STOPPED
)
1548 cupsFilePuts(fp
, "State Stopped\n");
1550 if (printer
->state_message
)
1551 cupsFilePutConf(fp
, "StateMessage", printer
->state_message
);
1554 cupsFilePuts(fp
, "State Idle\n");
1556 cupsFilePrintf(fp
, "StateTime %d\n", (int)printer
->state_time
);
1558 for (i
= 0; i
< printer
->num_reasons
; i
++)
1559 if (strcmp(printer
->reasons
[i
], "connecting-to-device") &&
1560 strcmp(printer
->reasons
[i
], "cups-insecure-filter-warning") &&
1561 strcmp(printer
->reasons
[i
], "cups-missing-filter-warning"))
1562 cupsFilePutConf(fp
, "Reason", printer
->reasons
[i
]);
1564 cupsFilePrintf(fp
, "Type %d\n", printer
->type
);
1566 if (printer
->accepting
)
1567 cupsFilePuts(fp
, "Accepting Yes\n");
1569 cupsFilePuts(fp
, "Accepting No\n");
1571 if (printer
->shared
)
1572 cupsFilePuts(fp
, "Shared Yes\n");
1574 cupsFilePuts(fp
, "Shared No\n");
1576 snprintf(value
, sizeof(value
), "%s %s", printer
->job_sheets
[0],
1577 printer
->job_sheets
[1]);
1578 cupsFilePutConf(fp
, "JobSheets", value
);
1580 cupsFilePrintf(fp
, "QuotaPeriod %d\n", printer
->quota_period
);
1581 cupsFilePrintf(fp
, "PageLimit %d\n", printer
->page_limit
);
1582 cupsFilePrintf(fp
, "KLimit %d\n", printer
->k_limit
);
1584 for (name
= (char *)cupsArrayFirst(printer
->users
);
1586 name
= (char *)cupsArrayNext(printer
->users
))
1587 cupsFilePutConf(fp
, printer
->deny_users
? "DenyUser" : "AllowUser", name
);
1589 if (printer
->op_policy
)
1590 cupsFilePutConf(fp
, "OpPolicy", printer
->op_policy
);
1591 if (printer
->error_policy
)
1592 cupsFilePutConf(fp
, "ErrorPolicy", printer
->error_policy
);
1594 for (i
= printer
->num_options
, option
= printer
->options
;
1598 snprintf(value
, sizeof(value
), "%s %s", option
->name
, option
->value
);
1599 cupsFilePutConf(fp
, "Option", value
);
1602 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-colors",
1603 IPP_TAG_NAME
)) != NULL
)
1605 snprintf(value
, sizeof(value
), "%s ", marker
->name
);
1607 for (i
= 0, ptr
= value
+ strlen(value
);
1608 i
< marker
->num_values
&& ptr
< (value
+ sizeof(value
) - 1);
1614 strlcpy(ptr
, marker
->values
[i
].string
.text
,
1615 value
+ sizeof(value
) - ptr
);
1620 cupsFilePutConf(fp
, "Attribute", value
);
1623 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-levels",
1624 IPP_TAG_INTEGER
)) != NULL
)
1626 cupsFilePrintf(fp
, "Attribute %s %d", marker
->name
,
1627 marker
->values
[0].integer
);
1628 for (i
= 1; i
< marker
->num_values
; i
++)
1629 cupsFilePrintf(fp
, ",%d", marker
->values
[i
].integer
);
1630 cupsFilePuts(fp
, "\n");
1633 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-low-levels",
1634 IPP_TAG_INTEGER
)) != NULL
)
1636 cupsFilePrintf(fp
, "Attribute %s %d", marker
->name
,
1637 marker
->values
[0].integer
);
1638 for (i
= 1; i
< marker
->num_values
; i
++)
1639 cupsFilePrintf(fp
, ",%d", marker
->values
[i
].integer
);
1640 cupsFilePuts(fp
, "\n");
1643 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-high-levels",
1644 IPP_TAG_INTEGER
)) != NULL
)
1646 cupsFilePrintf(fp
, "Attribute %s %d", marker
->name
,
1647 marker
->values
[0].integer
);
1648 for (i
= 1; i
< marker
->num_values
; i
++)
1649 cupsFilePrintf(fp
, ",%d", marker
->values
[i
].integer
);
1650 cupsFilePuts(fp
, "\n");
1653 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-message",
1654 IPP_TAG_TEXT
)) != NULL
)
1656 snprintf(value
, sizeof(value
), "%s %s", marker
->name
,
1657 marker
->values
[0].string
.text
);
1659 cupsFilePutConf(fp
, "Attribute", value
);
1662 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-names",
1663 IPP_TAG_NAME
)) != NULL
)
1665 snprintf(value
, sizeof(value
), "%s ", marker
->name
);
1667 for (i
= 0, ptr
= value
+ strlen(value
);
1668 i
< marker
->num_values
&& ptr
< (value
+ sizeof(value
) - 1);
1674 strlcpy(ptr
, marker
->values
[i
].string
.text
,
1675 value
+ sizeof(value
) - ptr
);
1680 cupsFilePutConf(fp
, "Attribute", value
);
1683 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-types",
1684 IPP_TAG_KEYWORD
)) != NULL
)
1686 snprintf(value
, sizeof(value
), "%s ", marker
->name
);
1688 for (i
= 0, ptr
= value
+ strlen(value
);
1689 i
< marker
->num_values
&& ptr
< (value
+ sizeof(value
) - 1);
1695 strlcpy(ptr
, marker
->values
[i
].string
.text
,
1696 value
+ sizeof(value
) - ptr
);
1701 cupsFilePutConf(fp
, "Attribute", value
);
1704 if (printer
->marker_time
)
1705 cupsFilePrintf(fp
, "Attribute marker-change-time %ld\n",
1706 (long)printer
->marker_time
);
1708 cupsFilePuts(fp
, "</Printer>\n");
1712 * Make IRIX desktop & printer status happy
1715 write_irix_state(printer
);
1724 * 'cupsdSetAuthInfoRequired()' - Set the required authentication info.
1727 int /* O - 1 if value OK, 0 otherwise */
1728 cupsdSetAuthInfoRequired(
1729 cupsd_printer_t
*p
, /* I - Printer */
1730 const char *values
, /* I - Plain text value (or NULL) */
1731 ipp_attribute_t
*attr
) /* I - IPP attribute value (or NULL) */
1733 int i
; /* Looping var */
1736 p
->num_auth_info_required
= 0;
1739 * Do we have a plain text value?
1745 * Yes, grab the keywords...
1748 const char *end
; /* End of current value */
1751 while (*values
&& p
->num_auth_info_required
< 4)
1753 if ((end
= strchr(values
, ',')) == NULL
)
1754 end
= values
+ strlen(values
);
1756 if ((end
- values
) == 4 && !strncmp(values
, "none", 4))
1758 if (p
->num_auth_info_required
!= 0 || *end
)
1761 p
->auth_info_required
[p
->num_auth_info_required
] = "none";
1762 p
->num_auth_info_required
++;
1766 else if ((end
- values
) == 9 && !strncmp(values
, "negotiate", 9))
1768 if (p
->num_auth_info_required
!= 0 || *end
)
1771 p
->auth_info_required
[p
->num_auth_info_required
] = "negotiate";
1772 p
->num_auth_info_required
++;
1774 else if ((end
- values
) == 6 && !strncmp(values
, "domain", 6))
1776 p
->auth_info_required
[p
->num_auth_info_required
] = "domain";
1777 p
->num_auth_info_required
++;
1779 else if ((end
- values
) == 8 && !strncmp(values
, "password", 8))
1781 p
->auth_info_required
[p
->num_auth_info_required
] = "password";
1782 p
->num_auth_info_required
++;
1784 else if ((end
- values
) == 8 && !strncmp(values
, "username", 8))
1786 p
->auth_info_required
[p
->num_auth_info_required
] = "username";
1787 p
->num_auth_info_required
++;
1792 values
= (*end
) ? end
+ 1 : end
;
1795 if (p
->num_auth_info_required
== 0)
1797 p
->auth_info_required
[0] = "none";
1798 p
->num_auth_info_required
= 1;
1802 * Update the printer-type value as needed...
1805 if (p
->num_auth_info_required
> 1 ||
1806 strcmp(p
->auth_info_required
[0], "none"))
1807 p
->type
|= CUPS_PRINTER_AUTHENTICATED
;
1809 p
->type
&= ~CUPS_PRINTER_AUTHENTICATED
;
1815 * Grab values from an attribute instead...
1818 if (!attr
|| attr
->num_values
> 4)
1822 * Update the printer-type value as needed...
1825 if (attr
->num_values
> 1 ||
1826 strcmp(attr
->values
[0].string
.text
, "none"))
1827 p
->type
|= CUPS_PRINTER_AUTHENTICATED
;
1829 p
->type
&= ~CUPS_PRINTER_AUTHENTICATED
;
1831 for (i
= 0; i
< attr
->num_values
; i
++)
1833 if (!strcmp(attr
->values
[i
].string
.text
, "none"))
1835 if (p
->num_auth_info_required
!= 0 || attr
->num_values
!= 1)
1838 p
->auth_info_required
[p
->num_auth_info_required
] = "none";
1839 p
->num_auth_info_required
++;
1843 else if (!strcmp(attr
->values
[i
].string
.text
, "negotiate"))
1845 if (p
->num_auth_info_required
!= 0 || attr
->num_values
!= 1)
1848 p
->auth_info_required
[p
->num_auth_info_required
] = "negotiate";
1849 p
->num_auth_info_required
++;
1853 else if (!strcmp(attr
->values
[i
].string
.text
, "domain"))
1855 p
->auth_info_required
[p
->num_auth_info_required
] = "domain";
1856 p
->num_auth_info_required
++;
1858 else if (!strcmp(attr
->values
[i
].string
.text
, "password"))
1860 p
->auth_info_required
[p
->num_auth_info_required
] = "password";
1861 p
->num_auth_info_required
++;
1863 else if (!strcmp(attr
->values
[i
].string
.text
, "username"))
1865 p
->auth_info_required
[p
->num_auth_info_required
] = "username";
1866 p
->num_auth_info_required
++;
1877 * 'cupsdSetDeviceURI()' - Set the device URI for a printer.
1881 cupsdSetDeviceURI(cupsd_printer_t
*p
, /* I - Printer */
1882 const char *uri
) /* I - Device URI */
1884 char buffer
[1024], /* URI buffer */
1885 *start
, /* Start of data after scheme */
1886 *slash
, /* First slash after scheme:// */
1887 *ptr
; /* Pointer into user@host:port part */
1891 * Set the full device URI..
1894 cupsdSetString(&(p
->device_uri
), uri
);
1897 * Copy the device URI to a temporary buffer so we can sanitize any auth
1901 strlcpy(buffer
, uri
, sizeof(buffer
));
1904 * Find the end of the scheme:// part...
1907 if ((ptr
= strchr(buffer
, ':')) != NULL
)
1909 for (start
= ptr
+ 1; *start
; start
++)
1914 * Find the next slash (/) in the URI...
1917 if ((slash
= strchr(start
, '/')) == NULL
)
1918 slash
= start
+ strlen(start
); /* No slash, point to the end */
1921 * Check for an @ sign before the slash...
1924 if ((ptr
= strchr(start
, '@')) != NULL
&& ptr
< slash
)
1927 * Found an @ sign and it is before the resource part, so we have
1928 * an authentication string. Copy the remaining URI over the
1929 * authentication string...
1932 _cups_strcpy(start
, ptr
+ 1);
1937 * Save the sanitized URI...
1940 cupsdSetString(&(p
->sanitized_device_uri
), buffer
);
1945 * 'cupsdSetPrinterAttr()' - Set a printer attribute.
1949 cupsdSetPrinterAttr(
1950 cupsd_printer_t
*p
, /* I - Printer */
1951 const char *name
, /* I - Attribute name */
1952 char *value
) /* I - Attribute value string */
1954 ipp_attribute_t
*attr
; /* Attribute */
1955 int i
, /* Looping var */
1956 count
; /* Number of values */
1957 char *ptr
; /* Pointer into value */
1958 ipp_tag_t value_tag
; /* Value tag for this attribute */
1962 * Don't allow empty values...
1965 if (!*value
&& strcmp(name
, "marker-message"))
1967 cupsdLogMessage(CUPSD_LOG_ERROR
, "Ignoring empty \"%s\" attribute", name
);
1972 * Count the number of values...
1975 for (count
= 1, ptr
= value
;
1976 (ptr
= strchr(ptr
, ',')) != NULL
;
1980 * Then add or update the attribute as needed...
1983 if (!strcmp(name
, "marker-levels") || !strcmp(name
, "marker-low-levels") ||
1984 !strcmp(name
, "marker-high-levels"))
1990 if ((attr
= ippFindAttribute(p
->attrs
, name
, IPP_TAG_INTEGER
)) != NULL
&&
1991 attr
->num_values
< count
)
1993 ippDeleteAttribute(p
->attrs
, attr
);
1998 attr
->num_values
= count
;
2000 attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
, name
,
2005 cupsdLogMessage(CUPSD_LOG_ERROR
,
2006 "Unable to allocate memory for printer attribute "
2007 "(%d values)", count
);
2011 for (i
= 0; i
< count
; i
++)
2013 if ((ptr
= strchr(value
, ',')) != NULL
)
2016 attr
->values
[i
].integer
= strtol(value
, NULL
, 10);
2025 * Name or keyword values...
2028 if (!strcmp(name
, "marker-types"))
2029 value_tag
= IPP_TAG_KEYWORD
;
2030 else if (!strcmp(name
, "marker-message"))
2031 value_tag
= IPP_TAG_TEXT
;
2033 value_tag
= IPP_TAG_NAME
;
2035 if ((attr
= ippFindAttribute(p
->attrs
, name
, value_tag
)) != NULL
&&
2036 attr
->num_values
< count
)
2038 ippDeleteAttribute(p
->attrs
, attr
);
2044 for (i
= 0; i
< attr
->num_values
; i
++)
2045 _cupsStrFree(attr
->values
[i
].string
.text
);
2047 attr
->num_values
= count
;
2050 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, value_tag
, name
,
2055 cupsdLogMessage(CUPSD_LOG_ERROR
,
2056 "Unable to allocate memory for printer attribute "
2057 "(%d values)", count
);
2061 for (i
= 0; i
< count
; i
++)
2063 if ((ptr
= strchr(value
, ',')) != NULL
)
2066 attr
->values
[i
].string
.text
= _cupsStrAlloc(value
);
2076 * 'cupsdSetPrinterAttrs()' - Set printer attributes based upon the PPD file.
2080 cupsdSetPrinterAttrs(cupsd_printer_t
*p
)/* I - Printer to setup */
2082 int i
, /* Looping var */
2083 length
; /* Length of browse attributes */
2084 char resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
2085 int num_air
; /* Number of auth-info-required values */
2086 const char * const *air
; /* auth-info-required values */
2087 cupsd_location_t
*auth
; /* Pointer to authentication element */
2088 const char *auth_supported
; /* Authentication supported */
2089 ipp_t
*oldattrs
; /* Old printer attributes */
2090 ipp_attribute_t
*attr
; /* Attribute data */
2091 cups_option_t
*option
; /* Current printer option */
2092 char *name
, /* Current user/group name */
2093 *filter
; /* Current filter */
2094 static const char * const air_none
[] =
2095 { /* No authentication */
2098 static const char * const air_userpass
[] =
2099 { /* Basic/Digest authentication */
2105 DEBUG_printf(("cupsdSetPrinterAttrs: entering name = %s, type = %x\n", p
->name
,
2109 * Make sure that we have the common attributes defined...
2113 cupsdCreateCommonData();
2116 * Clear out old filters, if any...
2119 delete_printer_filters(p
);
2122 * Figure out the authentication that is required for the printer.
2125 auth_supported
= "requesting-user-name";
2129 if (p
->num_auth_info_required
> 0 && strcmp(p
->auth_info_required
[0], "none"))
2131 num_air
= p
->num_auth_info_required
;
2132 air
= p
->auth_info_required
;
2134 else if ((p
->type
& CUPS_PRINTER_AUTHENTICATED
) &&
2135 (p
->type
& CUPS_PRINTER_DISCOVERED
))
2141 if (p
->type
& CUPS_PRINTER_CLASS
)
2142 snprintf(resource
, sizeof(resource
), "/classes/%s", p
->name
);
2144 snprintf(resource
, sizeof(resource
), "/printers/%s", p
->name
);
2146 if ((auth
= cupsdFindBest(resource
, HTTP_POST
)) == NULL
||
2147 auth
->type
== CUPSD_AUTH_NONE
)
2148 auth
= cupsdFindPolicyOp(p
->op_policy_ptr
, IPP_PRINT_JOB
);
2152 int auth_type
; /* Authentication type */
2155 if ((auth_type
= auth
->type
) == CUPSD_AUTH_DEFAULT
)
2156 auth_type
= DefaultAuthType
;
2158 if (auth_type
== CUPSD_AUTH_BASIC
|| auth_type
== CUPSD_AUTH_BASICDIGEST
)
2159 auth_supported
= "basic";
2160 else if (auth_type
== CUPSD_AUTH_DIGEST
)
2161 auth_supported
= "digest";
2163 else if (auth_type
== CUPSD_AUTH_NEGOTIATE
)
2164 auth_supported
= "negotiate";
2165 #endif /* HAVE_GSSAPI */
2167 if (!(p
->type
& CUPS_PRINTER_DISCOVERED
))
2169 if (auth_type
!= CUPSD_AUTH_NONE
)
2170 p
->type
|= CUPS_PRINTER_AUTHENTICATED
;
2172 p
->type
&= ~CUPS_PRINTER_AUTHENTICATED
;
2175 else if (!(p
->type
& CUPS_PRINTER_DISCOVERED
))
2176 p
->type
&= ~CUPS_PRINTER_AUTHENTICATED
;
2179 * Create the required IPP attributes for a printer...
2182 oldattrs
= p
->attrs
;
2183 p
->attrs
= ippNew();
2185 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2186 "uri-authentication-supported", NULL
, auth_supported
);
2187 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2188 "uri-security-supported", NULL
, "none");
2189 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
, "printer-name", NULL
,
2191 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-location",
2192 NULL
, p
->location
? p
->location
: "");
2193 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-info",
2194 NULL
, p
->info
? p
->info
: "");
2195 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "printer-uuid", NULL
,
2198 if (cupsArrayCount(p
->users
) > 0)
2201 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2202 "requesting-user-name-denied",
2203 cupsArrayCount(p
->users
), NULL
, NULL
);
2205 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2206 "requesting-user-name-allowed",
2207 cupsArrayCount(p
->users
), NULL
, NULL
);
2209 for (i
= 0, name
= (char *)cupsArrayFirst(p
->users
);
2211 i
++, name
= (char *)cupsArrayNext(p
->users
))
2212 attr
->values
[i
].string
.text
= _cupsStrRetain(name
);
2215 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2216 "job-quota-period", p
->quota_period
);
2217 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2218 "job-k-limit", p
->k_limit
);
2219 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2220 "job-page-limit", p
->page_limit
);
2221 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2222 "auth-info-required", num_air
, NULL
, air
);
2224 if (cupsArrayCount(Banners
) > 0 && !(p
->type
& CUPS_PRINTER_DISCOVERED
))
2227 * Setup the job-sheets-default attribute...
2230 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2231 "job-sheets-default", 2, NULL
, NULL
);
2235 attr
->values
[0].string
.text
= _cupsStrAlloc(Classification
?
2236 Classification
: p
->job_sheets
[0]);
2237 attr
->values
[1].string
.text
= _cupsStrAlloc(Classification
?
2238 Classification
: p
->job_sheets
[1]);
2245 if (p
->type
& CUPS_PRINTER_DISCOVERED
)
2248 * Tell the client this is a remote printer of some type...
2251 if (strchr(p
->uri
, '?'))
2254 * Strip trailing "?options" from URI...
2257 char *ptr
; /* Pointer into URI */
2259 strlcpy(resource
, p
->uri
, sizeof(resource
));
2260 if ((ptr
= strchr(resource
, '?')) != NULL
)
2263 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
2264 "printer-uri-supported", NULL
, resource
);
2267 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
2268 "printer-uri-supported", NULL
, p
->uri
);
2270 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "printer-more-info",
2274 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
2275 "printer-make-and-model", NULL
, p
->make_model
);
2277 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "device-uri", NULL
,
2286 * Assign additional attributes depending on whether this is a printer
2290 if (p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
))
2293 p
->type
&= ~CUPS_PRINTER_OPTIONS
;
2296 * Add class-specific attributes...
2299 if ((p
->type
& CUPS_PRINTER_IMPLICIT
) && p
->num_printers
> 0 &&
2300 p
->printers
[0]->make_model
)
2301 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
2302 "printer-make-and-model", NULL
, p
->printers
[0]->make_model
);
2304 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
2305 "printer-make-and-model", NULL
, "Local Printer Class");
2307 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "device-uri", NULL
,
2308 "file:///dev/null");
2310 if (p
->num_printers
> 0)
2313 * Add a list of member names; URIs are added in copy_printer_attrs...
2316 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2317 "member-names", p
->num_printers
, NULL
, NULL
);
2318 p
->type
|= CUPS_PRINTER_OPTIONS
;
2320 for (i
= 0; i
< p
->num_printers
; i
++)
2323 attr
->values
[i
].string
.text
= _cupsStrRetain(p
->printers
[i
]->name
);
2325 p
->type
&= ~CUPS_PRINTER_OPTIONS
| p
->printers
[i
]->type
;
2332 * Add printer-specific attributes...
2335 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "device-uri", NULL
,
2336 p
->sanitized_device_uri
);
2339 * Assign additional attributes from the PPD file (if any)...
2345 * Add filters for printer...
2348 cupsdSetPrinterReasons(p
, "-cups-missing-filter-warning,"
2349 "cups-insecure-filter-warning");
2351 if (p
->pc
&& p
->pc
->filters
)
2353 for (filter
= (char *)cupsArrayFirst(p
->pc
->filters
);
2355 filter
= (char *)cupsArrayNext(p
->pc
->filters
))
2356 add_printer_filter(p
, p
->filetype
, filter
);
2358 else if (!(p
->type
& CUPS_PRINTER_REMOTE
))
2360 char interface
[1024]; /* Interface script */
2363 snprintf(interface
, sizeof(interface
), "%s/interfaces/%s", ServerRoot
,
2365 if (!access(interface
, X_OK
))
2368 * Yes, we have a System V style interface script; use it!
2371 snprintf(interface
, sizeof(interface
), "*/* 0 %s/interfaces/%s",
2372 ServerRoot
, p
->name
);
2373 add_printer_filter(p
, p
->filetype
, interface
);
2378 * Add a filter from application/vnd.cups-raw to printer/name to
2379 * handle "raw" printing by users.
2382 add_printer_filter(p
, p
->filetype
, "application/vnd.cups-raw 0 -");
2385 * Add a PostScript filter, since this is still possibly PS printer.
2388 add_printer_filter(p
, p
->filetype
,
2389 "application/vnd.cups-postscript 0 -");
2393 if (p
->pc
&& p
->pc
->prefilters
)
2395 p
->prefiltertype
= mimeAddType(MimeDatabase
, "prefilter", p
->name
);
2397 for (filter
= (char *)cupsArrayFirst(p
->pc
->prefilters
);
2399 filter
= (char *)cupsArrayNext(p
->pc
->prefilters
))
2400 add_printer_filter(p
, p
->prefiltertype
, filter
);
2406 * Copy marker attributes as needed...
2411 ipp_attribute_t
*oldattr
; /* Old attribute */
2414 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-colors",
2415 IPP_TAG_NAME
)) != NULL
)
2417 if ((attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2418 "marker-colors", oldattr
->num_values
, NULL
,
2421 for (i
= 0; i
< oldattr
->num_values
; i
++)
2422 attr
->values
[i
].string
.text
=
2423 _cupsStrRetain(oldattr
->values
[i
].string
.text
);
2427 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-levels",
2428 IPP_TAG_INTEGER
)) != NULL
)
2430 if ((attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2431 "marker-levels", oldattr
->num_values
,
2434 for (i
= 0; i
< oldattr
->num_values
; i
++)
2435 attr
->values
[i
].integer
= oldattr
->values
[i
].integer
;
2439 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-message",
2440 IPP_TAG_TEXT
)) != NULL
)
2441 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "marker-message",
2442 NULL
, oldattr
->values
[0].string
.text
);
2444 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-low-levels",
2445 IPP_TAG_INTEGER
)) != NULL
)
2447 if ((attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2448 "marker-low-levels", oldattr
->num_values
,
2451 for (i
= 0; i
< oldattr
->num_values
; i
++)
2452 attr
->values
[i
].integer
= oldattr
->values
[i
].integer
;
2456 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-high-levels",
2457 IPP_TAG_INTEGER
)) != NULL
)
2459 if ((attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2460 "marker-high-levels", oldattr
->num_values
,
2463 for (i
= 0; i
< oldattr
->num_values
; i
++)
2464 attr
->values
[i
].integer
= oldattr
->values
[i
].integer
;
2468 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-names",
2469 IPP_TAG_NAME
)) != NULL
)
2471 if ((attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2472 "marker-names", oldattr
->num_values
, NULL
,
2475 for (i
= 0; i
< oldattr
->num_values
; i
++)
2476 attr
->values
[i
].string
.text
=
2477 _cupsStrRetain(oldattr
->values
[i
].string
.text
);
2481 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-types",
2482 IPP_TAG_KEYWORD
)) != NULL
)
2484 if ((attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2485 "marker-types", oldattr
->num_values
, NULL
,
2488 for (i
= 0; i
< oldattr
->num_values
; i
++)
2489 attr
->values
[i
].string
.text
=
2490 _cupsStrRetain(oldattr
->values
[i
].string
.text
);
2494 ippDelete(oldattrs
);
2498 * Force sharing off for remote queues...
2501 if (p
->type
& (CUPS_PRINTER_REMOTE
| CUPS_PRINTER_IMPLICIT
))
2506 * Copy the printer options into a browse attributes string we can re-use.
2509 const char *valptr
; /* Pointer into value */
2510 char *attrptr
; /* Pointer into attribute string */
2514 * Free the old browse attributes as needed...
2517 if (p
->browse_attrs
)
2518 free(p
->browse_attrs
);
2521 * Compute the length of all attributes + job-sheets, lease-duration,
2522 * and BrowseLocalOptions.
2525 for (length
= 1, i
= p
->num_options
, option
= p
->options
;
2529 length
+= strlen(option
->name
) + 2;
2533 for (valptr
= option
->value
; *valptr
; valptr
++)
2534 if (strchr(" \"\'\\", *valptr
))
2541 length
+= 13 + strlen(p
->job_sheets
[0]) + strlen(p
->job_sheets
[1]);
2543 if (BrowseLocalOptions
)
2544 length
+= 12 + strlen(BrowseLocalOptions
);
2547 * Allocate the new string...
2550 if ((p
->browse_attrs
= calloc(1, length
)) == NULL
)
2551 cupsdLogMessage(CUPSD_LOG_ERROR
,
2552 "Unable to allocate %d bytes for browse data!",
2557 * Got the allocated string, now copy the options and attributes over...
2560 sprintf(p
->browse_attrs
, "job-sheets=%s,%s lease-duration=%d",
2561 p
->job_sheets
[0], p
->job_sheets
[1], BrowseTimeout
);
2562 attrptr
= p
->browse_attrs
+ strlen(p
->browse_attrs
);
2564 if (BrowseLocalOptions
)
2566 sprintf(attrptr
, " ipp-options=%s", BrowseLocalOptions
);
2567 attrptr
+= strlen(attrptr
);
2570 for (i
= p
->num_options
, option
= p
->options
;
2575 strcpy(attrptr
, option
->name
);
2576 attrptr
+= strlen(attrptr
);
2582 for (valptr
= option
->value
; *valptr
; valptr
++)
2584 if (strchr(" \"\'\\", *valptr
))
2587 *attrptr
++ = *valptr
;
2595 * Populate the document-format-supported attribute...
2598 add_printer_formats(p
);
2600 DEBUG_printf(("cupsdSetPrinterAttrs: leaving name = %s, type = %x\n", p
->name
,
2604 * Add name-default attributes...
2607 add_printer_defaults(p
);
2611 * Write the IRIX printer config and status files...
2614 write_irix_config(p
);
2615 write_irix_state(p
);
2619 * Let the browse protocols reflect the change
2622 cupsdRegisterPrinter(p
);
2627 * 'cupsdSetPrinterReasons()' - Set/update the reasons strings.
2630 int /* O - 1 if something changed, 0 otherwise */
2631 cupsdSetPrinterReasons(
2632 cupsd_printer_t
*p
, /* I - Printer */
2633 const char *s
) /* I - Reasons strings */
2635 int i
, /* Looping var */
2636 changed
= 0; /* Did something change? */
2637 const char *sptr
; /* Pointer into reasons */
2638 char reason
[255], /* Reason string */
2639 *rptr
; /* Pointer into reason */
2642 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
2643 "cupsdSetPrinterReasons(p=%p(%s),s=\"%s\"", p
, p
->name
, s
);
2645 if (s
[0] == '-' || s
[0] == '+')
2648 * Add/remove reasons...
2656 * Replace reasons...
2661 for (i
= 0; i
< p
->num_reasons
; i
++)
2662 _cupsStrFree(p
->reasons
[i
]);
2670 if (!strcmp(s
, "none"))
2674 * Loop through all of the reasons...
2680 * Skip leading whitespace and commas...
2683 while (isspace(*sptr
& 255) || *sptr
== ',')
2686 for (rptr
= reason
; *sptr
&& !isspace(*sptr
& 255) && *sptr
!= ','; sptr
++)
2687 if (rptr
< (reason
+ sizeof(reason
) - 1))
2701 for (i
= 0; i
< p
->num_reasons
; i
++)
2702 if (!strcmp(reason
, p
->reasons
[i
]))
2705 * Found a match, so remove it...
2710 _cupsStrFree(p
->reasons
[i
]);
2712 if (i
< p
->num_reasons
)
2713 memmove(p
->reasons
+ i
, p
->reasons
+ i
+ 1,
2714 (p
->num_reasons
- i
) * sizeof(char *));
2716 if (!strcmp(reason
, "paused") && p
->state
== IPP_PRINTER_STOPPED
)
2717 cupsdSetPrinterState(p
, IPP_PRINTER_IDLE
, 1);
2719 if (strcmp(reason
, "connecting-to-device"))
2724 else if (p
->num_reasons
< (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
2730 for (i
= 0; i
< p
->num_reasons
; i
++)
2731 if (!strcmp(reason
, p
->reasons
[i
]))
2734 if (i
>= p
->num_reasons
)
2736 if (i
>= (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
2738 cupsdLogMessage(CUPSD_LOG_ALERT
,
2739 "Too many printer-state-reasons values for %s (%d)",
2744 p
->reasons
[i
] = _cupsStrAlloc(reason
);
2748 if (!strcmp(reason
, "paused") && p
->state
!= IPP_PRINTER_STOPPED
)
2749 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, 1);
2751 if (strcmp(reason
, "connecting-to-device"))
2762 * 'cupsdSetPrinterState()' - Update the current state of a printer.
2766 cupsdSetPrinterState(
2767 cupsd_printer_t
*p
, /* I - Printer to change */
2768 ipp_pstate_t s
, /* I - New state */
2769 int update
) /* I - Update printers.conf? */
2771 ipp_pstate_t old_state
; /* Old printer state */
2772 static const char * const printer_states
[] =
2773 { /* State strings */
2781 * Can't set status of remote printers...
2784 if (p
->type
& CUPS_PRINTER_DISCOVERED
)
2788 * Set the new state...
2791 old_state
= p
->state
;
2796 cupsdAddEvent(s
== IPP_PRINTER_STOPPED
? CUPSD_EVENT_PRINTER_STOPPED
:
2797 CUPSD_EVENT_PRINTER_STATE
, p
, NULL
,
2798 "%s \"%s\" state changed to %s.",
2799 (p
->type
& CUPS_PRINTER_CLASS
) ? "Class" : "Printer",
2800 p
->name
, printer_states
[p
->state
- IPP_PRINTER_IDLE
]);
2803 * Let the browse code know this needs to be updated...
2807 p
->state_time
= time(NULL
);
2811 write_irix_state(p
);
2816 * Set/clear the paused reason as needed...
2819 if (s
== IPP_PRINTER_STOPPED
)
2820 cupsdSetPrinterReasons(p
, "+paused");
2822 cupsdSetPrinterReasons(p
, "-paused");
2825 * Clear the message for the queue when going to processing...
2828 if (s
== IPP_PRINTER_PROCESSING
)
2829 p
->state_message
[0] = '\0';
2832 * Let the browse protocols reflect the change...
2836 cupsdRegisterPrinter(p
);
2839 * Save the printer configuration if a printer goes from idle or processing
2840 * to stopped (or visa-versa)...
2844 (old_state
== IPP_PRINTER_STOPPED
) != (s
== IPP_PRINTER_STOPPED
))
2850 * 'cupsdStopPrinter()' - Stop a printer from printing any jobs...
2854 cupsdStopPrinter(cupsd_printer_t
*p
, /* I - Printer to stop */
2855 int update
)/* I - Update printers.conf? */
2858 * Set the printer state...
2861 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, update
);
2864 * See if we have a job printing on this printer...
2867 if (p
->job
&& p
->job
->state_value
== IPP_JOB_PROCESSING
)
2868 cupsdSetJobState(p
->job
, IPP_JOB_PENDING
, CUPSD_JOB_DEFAULT
,
2869 "Job stopped due to printer being paused.");
2874 * 'cupsdUpdatePrinterPPD()' - Update keywords in a printer's PPD file.
2877 int /* O - 1 if successful, 0 otherwise */
2878 cupsdUpdatePrinterPPD(
2879 cupsd_printer_t
*p
, /* I - Printer */
2880 int num_keywords
, /* I - Number of keywords */
2881 cups_option_t
*keywords
) /* I - Keywords */
2883 int i
; /* Looping var */
2884 cups_file_t
*src
, /* Original file */
2885 *dst
; /* New file */
2886 char srcfile
[1024], /* Original filename */
2887 dstfile
[1024], /* New filename */
2888 line
[1024], /* Line from file */
2889 keystring
[41]; /* Keyword from line */
2890 cups_option_t
*keyword
; /* Current keyword */
2893 cupsdLogMessage(CUPSD_LOG_INFO
, "Updating keywords in PPD file for %s...",
2897 * Get the old and new PPD filenames...
2900 snprintf(srcfile
, sizeof(srcfile
), "%s/ppd/%s.ppd.O", ServerRoot
, p
->name
);
2901 snprintf(dstfile
, sizeof(srcfile
), "%s/ppd/%s.ppd", ServerRoot
, p
->name
);
2904 * Rename the old file and open the old and new...
2907 if (rename(dstfile
, srcfile
))
2909 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to backup PPD file for %s: %s",
2910 p
->name
, strerror(errno
));
2914 if ((src
= cupsFileOpen(srcfile
, "r")) == NULL
)
2916 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to open PPD file \"%s\": %s",
2917 srcfile
, strerror(errno
));
2918 rename(srcfile
, dstfile
);
2922 if ((dst
= cupsFileOpen(dstfile
, "w")) == NULL
)
2924 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to create PPD file \"%s\": %s",
2925 dstfile
, strerror(errno
));
2927 rename(srcfile
, dstfile
);
2932 * Copy the first line and then write out all of the keywords...
2935 if (!cupsFileGets(src
, line
, sizeof(line
)))
2937 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to read PPD file \"%s\": %s",
2938 srcfile
, strerror(errno
));
2941 rename(srcfile
, dstfile
);
2945 cupsFilePrintf(dst
, "%s\n", line
);
2947 for (i
= num_keywords
, keyword
= keywords
; i
> 0; i
--, keyword
++)
2949 cupsdLogMessage(CUPSD_LOG_DEBUG
, "*%s: %s", keyword
->name
, keyword
->value
);
2950 cupsFilePrintf(dst
, "*%s: %s\n", keyword
->name
, keyword
->value
);
2954 * Then copy the rest of the PPD file, dropping any keywords we changed.
2957 while (cupsFileGets(src
, line
, sizeof(line
)))
2960 * Skip keywords we've already set...
2963 if (sscanf(line
, "*%40[^:]:", keystring
) == 1 &&
2964 cupsGetOption(keystring
, num_keywords
, keywords
))
2968 * Otherwise write the line...
2971 cupsFilePrintf(dst
, "%s\n", line
);
2975 * Close files and return...
2986 * 'cupsdUpdatePrinters()' - Update printers after a partial reload.
2990 cupsdUpdatePrinters(void)
2992 cupsd_printer_t
*p
; /* Current printer */
2996 * Loop through the printers and recreate the printer attributes
2997 * for any local printers since the policy and/or access control
2998 * stuff may have changed. Also, if browsing is disabled, remove
2999 * any remote printers...
3002 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3004 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3007 * Remove remote printers if we are no longer browsing...
3011 (p
->type
& (CUPS_PRINTER_IMPLICIT
| CUPS_PRINTER_DISCOVERED
)))
3013 if (p
->type
& CUPS_PRINTER_IMPLICIT
)
3014 cupsArrayRemove(ImplicitPrinters
, p
);
3016 cupsArraySave(Printers
);
3017 cupsdDeletePrinter(p
, 0);
3018 cupsArrayRestore(Printers
);
3023 * Update the operation policy pointer...
3026 if ((p
->op_policy_ptr
= cupsdFindPolicy(p
->op_policy
)) == NULL
)
3027 p
->op_policy_ptr
= DefaultPolicyPtr
;
3030 * Update printer attributes as needed...
3033 if (!(p
->type
& CUPS_PRINTER_DISCOVERED
))
3034 cupsdSetPrinterAttrs(p
);
3040 * 'cupsdValidateDest()' - Validate a printer/class destination.
3043 const char * /* O - Printer or class name */
3045 const char *uri
, /* I - Printer URI */
3046 cups_ptype_t
*dtype
, /* O - Type (printer or class) */
3047 cupsd_printer_t
**printer
) /* O - Printer pointer */
3049 cupsd_printer_t
*p
; /* Current printer */
3050 char localname
[1024],/* Localized hostname */
3051 *lptr
, /* Pointer into localized hostname */
3052 *sptr
, /* Pointer into server name */
3053 *rptr
, /* Pointer into resource */
3054 scheme
[32], /* Scheme portion of URI */
3055 username
[64], /* Username portion of URI */
3056 hostname
[HTTP_MAX_HOST
],
3057 /* Host portion of URI */
3058 resource
[HTTP_MAX_URI
];
3059 /* Resource portion of URI */
3060 int port
; /* Port portion of URI */
3063 DEBUG_printf(("cupsdValidateDest(uri=\"%s\", dtype=%p, printer=%p)\n", uri
,
3067 * Initialize return values...
3074 *dtype
= (cups_ptype_t
)0;
3077 * Pull the hostname and resource from the URI...
3080 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
, scheme
, sizeof(scheme
),
3081 username
, sizeof(username
), hostname
, sizeof(hostname
),
3082 &port
, resource
, sizeof(resource
));
3085 * See if the resource is a class or printer...
3088 if (!strncmp(resource
, "/classes/", 9))
3094 rptr
= resource
+ 9;
3096 else if (!strncmp(resource
, "/printers/", 10))
3102 rptr
= resource
+ 10;
3107 * Bad resource name...
3114 * See if the printer or class name exists...
3117 p
= cupsdFindDest(rptr
);
3119 if (p
== NULL
&& strchr(rptr
, '@') == NULL
)
3127 *dtype
= p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
|
3128 CUPS_PRINTER_REMOTE
| CUPS_PRINTER_DISCOVERED
);
3134 * Change localhost to the server name...
3137 if (!strcasecmp(hostname
, "localhost"))
3138 strlcpy(hostname
, ServerName
, sizeof(hostname
));
3140 strlcpy(localname
, hostname
, sizeof(localname
));
3142 if (!strcasecmp(hostname
, ServerName
))
3145 * Localize the hostname...
3148 lptr
= strchr(localname
, '.');
3149 sptr
= strchr(ServerName
, '.');
3151 if (sptr
!= NULL
&& lptr
!= NULL
)
3154 * Strip the common domain name components...
3157 while (lptr
!= NULL
)
3159 if (!strcasecmp(lptr
, sptr
))
3165 lptr
= strchr(lptr
+ 1, '.');
3170 DEBUG_printf(("localized hostname is \"%s\"...\n", localname
));
3173 * Find a matching printer or class...
3176 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3178 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3179 if (!strcasecmp(p
->hostname
, localname
) &&
3180 !strcasecmp(p
->name
, rptr
))
3186 *dtype
= p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
|
3187 CUPS_PRINTER_REMOTE
| CUPS_PRINTER_DISCOVERED
);
3197 * 'cupsdWritePrintcap()' - Write a pseudo-printcap file for older applications
3202 cupsdWritePrintcap(void)
3204 int i
; /* Looping var */
3205 cups_file_t
*fp
; /* Printcap file */
3206 cupsd_printer_t
*p
; /* Current printer */
3211 * Update the IRIX printer state for the default printer; if
3212 * no printers remain, then the default printer file will be
3216 write_irix_state(DefaultPrinter
);
3220 * See if we have a printcap file; if not, don't bother writing it.
3223 if (!Printcap
|| !*Printcap
)
3226 cupsdLogMessage(CUPSD_LOG_INFO
, "Generating printcap %s...", Printcap
);
3229 * Open the printcap file...
3232 if ((fp
= cupsFileOpen(Printcap
, "w")) == NULL
)
3236 * Put a comment header at the top so that users will know where the
3237 * data has come from...
3240 if (PrintcapFormat
!= PRINTCAP_PLIST
)
3241 cupsFilePrintf(fp
, "# This file was automatically generated by cupsd(8) "
3243 "# %s/printers.conf file. All changes to this file\n"
3244 "# will be lost.\n", ServerRoot
);
3247 * Write a new printcap with the current list of printers.
3250 switch (PrintcapFormat
)
3254 * Each printer is put in the file as:
3264 cupsFilePrintf(fp
, "%s|%s:rm=%s:rp=%s:\n", DefaultPrinter
->name
,
3265 DefaultPrinter
->info
, ServerName
,
3266 DefaultPrinter
->name
);
3268 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3270 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3271 if (p
!= DefaultPrinter
)
3272 cupsFilePrintf(fp
, "%s|%s:rm=%s:rp=%s:\n", p
->name
, p
->info
,
3273 ServerName
, p
->name
);
3276 case PRINTCAP_PLIST
:
3278 * Each printer is written as a dictionary in a plist file.
3279 * Currently the printer-name, printer-info, printer-is-accepting-jobs,
3280 * printer-location, printer-make-and-model, printer-state,
3281 * printer-state-reasons, printer-type, and (sanitized) device-uri.
3284 cupsFilePuts(fp
, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
3285 "<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD "
3286 "PLIST 1.0//EN\" \"http://www.apple.com/DTDs/"
3287 "PropertyList-1.0.dtd\">\n"
3288 "<plist version=\"1.0\">\n"
3291 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3293 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3295 cupsFilePuts(fp
, "\t<dict>\n"
3296 "\t\t<key>printer-name</key>\n"
3298 write_xml_string(fp
, p
->name
);
3299 cupsFilePuts(fp
, "</string>\n"
3300 "\t\t<key>printer-info</key>\n"
3302 write_xml_string(fp
, p
->info
);
3303 cupsFilePrintf(fp
, "</string>\n"
3304 "\t\t<key>printer-is-accepting-jobs</key>\n"
3306 "\t\t<key>printer-location</key>\n"
3307 "\t\t<string>", p
->accepting
? "true" : "false");
3308 write_xml_string(fp
, p
->location
);
3309 cupsFilePuts(fp
, "</string>\n"
3310 "\t\t<key>printer-make-and-model</key>\n"
3312 write_xml_string(fp
, p
->make_model
);
3313 cupsFilePrintf(fp
, "</string>\n"
3314 "\t\t<key>printer-state</key>\n"
3315 "\t\t<integer>%d</integer>\n"
3316 "\t\t<key>printer-state-reasons</key>\n"
3317 "\t\t<array>\n", p
->state
);
3318 for (i
= 0; i
< p
->num_reasons
; i
++)
3320 cupsFilePuts(fp
, "\t\t\t<string>");
3321 write_xml_string(fp
, p
->reasons
[i
]);
3322 cupsFilePuts(fp
, "</string>\n");
3324 cupsFilePrintf(fp
, "\t\t</array>\n"
3325 "\t\t<key>printer-type</key>\n"
3326 "\t\t<integer>%d</integer>\n"
3327 "\t\t<key>device-uri</key>\n"
3328 "\t\t<string>", p
->type
);
3329 write_xml_string(fp
, p
->sanitized_device_uri
);
3330 cupsFilePuts(fp
, "</string>\n"
3333 cupsFilePuts(fp
, "</array>\n"
3337 case PRINTCAP_SOLARIS
:
3339 * Each printer is put in the file as:
3341 * _all:all=Printer1,Printer2,Printer3,...,PrinterN
3342 * _default:use=DefaultPrinter
3344 * :bsdaddr=ServerName,Printer1:\
3345 * :description=Description:
3347 * :bsdaddr=ServerName,Printer2:\
3348 * :description=Description:
3350 * :bsdaddr=ServerName,Printer3:\
3351 * :description=Description:
3354 * :bsdaddr=ServerName,PrinterN:\
3355 * :description=Description:
3358 cupsFilePuts(fp
, "_all:all=");
3359 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3361 p
= (cupsd_printer_t
*)cupsArrayCurrent(Printers
))
3362 cupsFilePrintf(fp
, "%s%c", p
->name
,
3363 cupsArrayNext(Printers
) ? ',' : '\n');
3366 cupsFilePrintf(fp
, "_default:use=%s\n", DefaultPrinter
->name
);
3368 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3370 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3371 cupsFilePrintf(fp
, "%s:\\\n"
3372 "\t:bsdaddr=%s,%s:\\\n"
3373 "\t:description=%s:\n",
3374 p
->name
, ServerName
, p
->name
,
3375 p
->info
? p
->info
: "");
3388 * 'add_printer_defaults()' - Add name-default attributes to the printer attributes.
3392 add_printer_defaults(cupsd_printer_t
*p
)/* I - Printer */
3394 int i
; /* Looping var */
3395 int num_options
; /* Number of default options */
3396 cups_option_t
*options
, /* Default options */
3397 *option
; /* Current option */
3398 char name
[256]; /* name-default */
3402 * Maintain a common array of default attribute names...
3405 if (!CommonDefaults
)
3407 CommonDefaults
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
3409 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("copies-default"));
3410 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("document-format-default"));
3411 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("finishings-default"));
3412 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-hold-until-default"));
3413 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-priority-default"));
3414 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-sheets-default"));
3415 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("media-col-default"));
3416 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("number-up-default"));
3417 cupsArrayAdd(CommonDefaults
,
3418 _cupsStrAlloc("orientation-requested-default"));
3422 * Add all of the default options from the .conf files...
3425 for (num_options
= 0, options
= NULL
, i
= p
->num_options
, option
= p
->options
;
3429 if (strcmp(option
->name
, "ipp-options") &&
3430 strcmp(option
->name
, "job-sheets") &&
3431 strcmp(option
->name
, "lease-duration"))
3433 snprintf(name
, sizeof(name
), "%s-default", option
->name
);
3434 num_options
= cupsAddOption(name
, option
->value
, num_options
, &options
);
3436 if (!cupsArrayFind(CommonDefaults
, name
))
3437 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc(name
));
3442 * Convert options to IPP attributes...
3445 cupsEncodeOptions2(p
->attrs
, num_options
, options
, IPP_TAG_PRINTER
);
3446 cupsFreeOptions(num_options
, options
);
3449 * Add standard -default attributes as needed...
3452 if (!cupsGetOption("copies", p
->num_options
, p
->options
))
3453 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
, "copies-default",
3456 if (!cupsGetOption("document-format", p
->num_options
, p
->options
))
3457 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_MIMETYPE
,
3458 "document-format-default", NULL
, "application/octet-stream");
3460 if (!cupsGetOption("job-hold-until", p
->num_options
, p
->options
))
3461 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3462 "job-hold-until-default", NULL
, "no-hold");
3464 if (!cupsGetOption("job-priority", p
->num_options
, p
->options
))
3465 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3466 "job-priority-default", 50);
3468 if (!cupsGetOption("number-up", p
->num_options
, p
->options
))
3469 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3470 "number-up-default", 1);
3472 if (!cupsGetOption("notify-lease-duration", p
->num_options
, p
->options
))
3473 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3474 "notify-lease-duration-default", DefaultLeaseDuration
);
3476 if (!cupsGetOption("notify-events", p
->num_options
, p
->options
))
3477 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3478 "notify-events-default", NULL
, "job-completed");
3480 if (!cupsGetOption("orientation-requested", p
->num_options
, p
->options
))
3481 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NOVALUE
,
3482 "orientation-requested-default", NULL
, NULL
);
3484 if (!cupsGetOption("print-quality", p
->num_options
, p
->options
))
3485 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
3486 "print-quality-default", IPP_QUALITY_NORMAL
);
3491 * 'add_printer_filter()' - Add a MIME filter for a printer.
3496 cupsd_printer_t
*p
, /* I - Printer to add to */
3497 mime_type_t
*filtertype
, /* I - Filter or prefilter MIME type */
3498 const char *filter
) /* I - Filter to add */
3500 char super
[MIME_MAX_SUPER
], /* Super-type for filter */
3501 type
[MIME_MAX_TYPE
], /* Type for filter */
3502 dsuper
[MIME_MAX_SUPER
], /* Destination super-type for filter */
3503 dtype
[MIME_MAX_TYPE
], /* Destination type for filter */
3504 dest
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2],
3505 /* Destination super/type */
3506 program
[1024]; /* Program/filter name */
3507 int cost
; /* Cost of filter */
3508 mime_type_t
*temptype
, /* MIME type looping var */
3509 *desttype
; /* Destination MIME type */
3510 char filename
[1024], /* Full filter filename */
3511 *dirsep
; /* Pointer to directory separator */
3512 struct stat fileinfo
; /* File information */
3515 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3516 "add_printer_filter(p=%p(%s), filtertype=%p(%s/%s), "
3517 "filter=\"%s\")", p
, p
->name
, filtertype
, filtertype
->super
,
3518 filtertype
->type
, filter
);
3521 * Parse the filter string; it should be in one of the following formats:
3523 * source/type cost program
3524 * source/type dest/type cost program
3527 if (sscanf(filter
, "%15[^/]/%255s%*[ \t]%15[^/]/%255s%d%*[ \t]%1023[^\n]",
3528 super
, type
, dsuper
, dtype
, &cost
, program
) == 6)
3530 snprintf(dest
, sizeof(dest
), "%s/%s/%s", p
->name
, dsuper
, dtype
);
3532 if ((desttype
= mimeType(MimeDatabase
, "printer", dest
)) == NULL
)
3534 desttype
= mimeAddType(MimeDatabase
, "printer", dest
);
3536 p
->dest_types
= cupsArrayNew(NULL
, NULL
);
3538 cupsArrayAdd(p
->dest_types
, desttype
);
3544 if (sscanf(filter
, "%15[^/]/%255s%d%*[ \t]%1023[^\n]", super
, type
, &cost
,
3547 desttype
= filtertype
;
3551 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: invalid filter string \"%s\"!",
3558 * See if the filter program exists; if not, stop the printer and flag
3562 if (strcmp(program
, "-"))
3564 if (program
[0] == '/')
3565 strlcpy(filename
, program
, sizeof(filename
));
3567 snprintf(filename
, sizeof(filename
), "%s/filter/%s", ServerBin
, program
);
3569 if (stat(filename
, &fileinfo
))
3571 memset(&fileinfo
, 0, sizeof(fileinfo
));
3573 snprintf(p
->state_message
, sizeof(p
->state_message
),
3574 "Printer driver \"%s\" not available: %s", filename
,
3576 cupsdSetPrinterReasons(p
, "+cups-missing-filter-warning");
3578 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: %s", p
->name
, p
->state_message
);
3582 * When running as root, do additional security checks...
3588 * Only use filters that are owned by root and do not have world write
3592 if (fileinfo
.st_uid
||
3593 (fileinfo
.st_gid
&& (fileinfo
.st_mode
& S_IWGRP
)) ||
3594 (fileinfo
.st_mode
& (S_ISUID
| S_IWOTH
)) != 0)
3596 snprintf(p
->state_message
, sizeof(p
->state_message
),
3597 "Printer driver \"%s\" has insecure permissions "
3598 "(0%o/uid=%d/gid=%d).", filename
, fileinfo
.st_mode
,
3599 (int)fileinfo
.st_uid
, (int)fileinfo
.st_gid
);
3601 cupsdSetPrinterReasons(p
, "+cups-insecure-filter-warning");
3603 cupsdLogMessage(CUPSD_LOG_WARN
, "%s: %s", p
->name
, p
->state_message
);
3605 else if (fileinfo
.st_mode
)
3608 * Similarly, check that the parent directory is also owned by root and
3609 * does not have world write permissions.
3612 if ((dirsep
= strrchr(filename
, '/')) != NULL
)
3615 if (!stat(filename
, &fileinfo
) &&
3617 (fileinfo
.st_gid
&& (fileinfo
.st_mode
& S_IWGRP
)) ||
3618 (fileinfo
.st_mode
& (S_ISUID
| S_IWOTH
)) != 0))
3620 snprintf(p
->state_message
, sizeof(p
->state_message
),
3621 "Printer driver directory \"%s\" has insecure permissions "
3622 "(0%o/uid=%d/gid=%d).", filename
, fileinfo
.st_mode
,
3623 (int)fileinfo
.st_uid
, (int)fileinfo
.st_gid
);
3625 cupsdSetPrinterReasons(p
, "+cups-insecure-filter-warning");
3627 cupsdLogMessage(CUPSD_LOG_WARN
, "%s: %s", p
->name
, p
->state_message
);
3634 * Add the filter to the MIME database, supporting wildcards as needed...
3637 for (temptype
= mimeFirstType(MimeDatabase
);
3639 temptype
= mimeNextType(MimeDatabase
))
3640 if (((super
[0] == '*' && strcasecmp(temptype
->super
, "printer")) ||
3641 !strcasecmp(temptype
->super
, super
)) &&
3642 (type
[0] == '*' || !strcasecmp(temptype
->type
, type
)))
3644 if (desttype
!= filtertype
)
3646 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3647 "add_printer_filter: %s: adding filter %s/%s %s/%s %d "
3648 "%s", p
->name
, temptype
->super
, temptype
->type
,
3649 desttype
->super
, desttype
->type
,
3651 mimeAddFilter(MimeDatabase
, temptype
, desttype
, cost
, program
);
3653 if (!mimeFilterLookup(MimeDatabase
, desttype
, filtertype
))
3655 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3656 "add_printer_filter: %s: adding filter %s/%s %s/%s "
3657 "0 -", p
->name
, desttype
->super
, desttype
->type
,
3658 filtertype
->super
, filtertype
->type
);
3659 mimeAddFilter(MimeDatabase
, desttype
, filtertype
, cost
, "-");
3664 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3665 "add_printer_filter: %s: adding filter %s/%s %s/%s %d "
3666 "%s", p
->name
, temptype
->super
, temptype
->type
,
3667 filtertype
->super
, filtertype
->type
,
3669 mimeAddFilter(MimeDatabase
, temptype
, filtertype
, cost
, program
);
3676 * 'add_printer_formats()' - Add document-format-supported values for a printer.
3680 add_printer_formats(cupsd_printer_t
*p
) /* I - Printer */
3682 int i
; /* Looping var */
3683 mime_type_t
*type
; /* Current MIME type */
3684 cups_array_t
*filters
; /* Filters */
3685 ipp_attribute_t
*attr
; /* document-format-supported attribute */
3686 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
3687 /* MIME type name */
3691 * Raw (and remote) queues advertise all of the supported MIME
3695 cupsArrayDelete(p
->filetypes
);
3696 p
->filetypes
= NULL
;
3700 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
,
3701 (ipp_tag_t
)(IPP_TAG_MIMETYPE
| IPP_TAG_COPY
),
3702 "document-format-supported", NumMimeTypes
, NULL
, MimeTypes
);
3707 * Otherwise, loop through the supported MIME types and see if there
3708 * are filters for them...
3711 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_printer_formats: %d types, %d filters",
3712 mimeNumTypes(MimeDatabase
), mimeNumFilters(MimeDatabase
));
3714 p
->filetypes
= cupsArrayNew(NULL
, NULL
);
3716 for (type
= mimeFirstType(MimeDatabase
);
3718 type
= mimeNextType(MimeDatabase
))
3720 if (!strcasecmp(type
->super
, "printer"))
3723 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
3725 if ((filters
= mimeFilter(MimeDatabase
, type
, p
->filetype
, NULL
)) != NULL
)
3727 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3728 "add_printer_formats: %s: %s needs %d filters",
3729 p
->name
, mimetype
, cupsArrayCount(filters
));
3731 cupsArrayDelete(filters
);
3732 cupsArrayAdd(p
->filetypes
, type
);
3735 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3736 "add_printer_formats: %s: %s not supported",
3741 * Add the file formats that can be filtered...
3744 if ((type
= mimeType(MimeDatabase
, "application", "octet-stream")) == NULL
||
3745 !cupsArrayFind(p
->filetypes
, type
))
3750 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3751 "add_printer_formats: %s: %d supported types",
3752 p
->name
, cupsArrayCount(p
->filetypes
) + i
);
3754 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_MIMETYPE
,
3755 "document-format-supported",
3756 cupsArrayCount(p
->filetypes
) + i
, NULL
, NULL
);
3759 attr
->values
[0].string
.text
= _cupsStrAlloc("application/octet-stream");
3761 for (type
= (mime_type_t
*)cupsArrayFirst(p
->filetypes
);
3763 i
++, type
= (mime_type_t
*)cupsArrayNext(p
->filetypes
))
3765 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
3767 attr
->values
[i
].string
.text
= _cupsStrAlloc(mimetype
);
3772 char pdl
[1024]; /* Buffer to build pdl list */
3773 mime_filter_t
*filter
; /* MIME filter looping var */
3777 * We only support raw printing if this is not a Tioga PrintJobMgr based
3778 * queue and if application/octet-stream is a known type...
3781 for (filter
= (mime_filter_t
*)cupsArrayFirst(MimeDatabase
->filters
);
3783 filter
= (mime_filter_t
*)cupsArrayNext(MimeDatabase
->filters
))
3785 if (filter
->dst
== p
->filetype
&& filter
->filter
&&
3786 strstr(filter
->filter
, "PrintJobMgr"))
3792 if (!filter
&& mimeType(MimeDatabase
, "application", "octet-stream"))
3793 strlcat(pdl
, "application/octet-stream,", sizeof(pdl
));
3796 * Then list a bunch of formats that are supported by the printer...
3799 for (type
= (mime_type_t
*)cupsArrayFirst(p
->filetypes
);
3801 type
= (mime_type_t
*)cupsArrayNext(p
->filetypes
))
3803 if (!strcasecmp(type
->super
, "application"))
3805 if (!strcasecmp(type
->type
, "pdf"))
3806 strlcat(pdl
, "application/pdf,", sizeof(pdl
));
3807 else if (!strcasecmp(type
->type
, "postscript"))
3808 strlcat(pdl
, "application/postscript,", sizeof(pdl
));
3810 else if (!strcasecmp(type
->super
, "image"))
3812 if (!strcasecmp(type
->type
, "jpeg"))
3813 strlcat(pdl
, "image/jpeg,", sizeof(pdl
));
3814 else if (!strcasecmp(type
->type
, "png"))
3815 strlcat(pdl
, "image/png,", sizeof(pdl
));
3816 else if (!strcasecmp(type
->type
, "pwg-raster"))
3817 strlcat(pdl
, "image/pwg-raster,", sizeof(pdl
));
3822 pdl
[strlen(pdl
) - 1] = '\0'; /* Remove trailing comma */
3824 cupsdSetString(&p
->pdl
, pdl
);
3826 #endif /* HAVE_DNSSD */
3831 * 'compare_printers()' - Compare two printers.
3834 static int /* O - Result of comparison */
3835 compare_printers(void *first
, /* I - First printer */
3836 void *second
, /* I - Second printer */
3837 void *data
) /* I - App data (not used) */
3839 return (strcasecmp(((cupsd_printer_t
*)first
)->name
,
3840 ((cupsd_printer_t
*)second
)->name
));
3845 * 'delete_printer_filters()' - Delete all MIME filters for a printer.
3849 delete_printer_filters(
3850 cupsd_printer_t
*p
) /* I - Printer to remove from */
3852 mime_filter_t
*filter
; /* MIME filter looping var */
3853 mime_type_t
*type
; /* Destination types for filters */
3857 * Range check input...
3864 * Remove all filters from the MIME database that have a destination
3865 * type == printer...
3868 for (filter
= mimeFirstFilter(MimeDatabase
);
3870 filter
= mimeNextFilter(MimeDatabase
))
3871 if (filter
->dst
== p
->filetype
|| filter
->dst
== p
->prefiltertype
||
3872 cupsArrayFind(p
->dest_types
, filter
->dst
))
3875 * Delete the current filter...
3878 mimeDeleteFilter(MimeDatabase
, filter
);
3881 for (type
= (mime_type_t
*)cupsArrayFirst(p
->dest_types
);
3883 type
= (mime_type_t
*)cupsArrayNext(p
->dest_types
))
3884 mimeDeleteType(MimeDatabase
, type
);
3886 cupsArrayDelete(p
->dest_types
);
3887 p
->dest_types
= NULL
;
3889 cupsdSetPrinterReasons(p
, "-cups-insecure-filter-warning"
3890 ",cups-missing-filter-warning");
3895 * 'dirty_printer()' - Mark config and state files dirty for the specified
3900 dirty_printer(cupsd_printer_t
*p
) /* I - Printer */
3902 if (p
->type
& CUPS_PRINTER_DISCOVERED
)
3903 cupsdMarkDirty(CUPSD_DIRTY_REMOTE
);
3904 else if (p
->type
& CUPS_PRINTER_CLASS
)
3905 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
3907 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
3909 if (PrintcapFormat
== PRINTCAP_PLIST
)
3910 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
3915 * 'load_ppd()' - Load a cached PPD file, updating the cache as needed.
3919 load_ppd(cupsd_printer_t
*p
) /* I - Printer */
3921 int i
, j
, k
; /* Looping vars */
3922 char cache_name
[1024]; /* Cache filename */
3923 struct stat cache_info
; /* Cache file info */
3924 ppd_file_t
*ppd
; /* PPD file */
3925 char ppd_name
[1024]; /* PPD filename */
3926 struct stat ppd_info
; /* PPD file info */
3927 int num_media
; /* Number of media options */
3928 ppd_size_t
*size
; /* Current PPD size */
3929 ppd_option_t
*duplex
, /* Duplex option */
3930 *output_bin
, /* OutputBin option */
3931 *output_mode
, /* OutputMode option */
3932 *resolution
; /* (Set|JCL|)Resolution option */
3933 ppd_choice_t
*choice
, /* Current PPD choice */
3934 *input_slot
, /* Current input slot */
3935 *media_type
; /* Current media type */
3936 ppd_attr_t
*ppd_attr
; /* PPD attribute */
3937 int xdpi
, /* Horizontal resolution */
3938 ydpi
; /* Vertical resolution */
3939 const char *resptr
; /* Pointer into resolution keyword */
3940 _pwg_size_t
*pwgsize
; /* Current PWG size */
3941 _pwg_map_t
*pwgsource
, /* Current PWG source */
3942 *pwgtype
; /* Current PWG type */
3943 ipp_attribute_t
*attr
; /* Attribute data */
3944 ipp_value_t
*val
; /* Attribute value */
3945 int num_finishings
, /* Number of finishings */
3946 finishings
[5]; /* finishings-supported values */
3947 int num_qualities
, /* Number of print-quality values */
3948 qualities
[3]; /* print-quality values */
3949 int num_margins
, /* Number of media-*-margin-supported values */
3950 margins
[16]; /* media-*-margin-supported values */
3951 const char *filter
; /* Current filter */
3952 static const char * const sides
[3] = /* sides-supported values */
3955 "two-sided-long-edge",
3956 "two-sided-short-edge"
3958 static const char * const standard_commands
[] =
3959 { /* Standard CUPS commands */
3967 * Check to see if the cache is up-to-date...
3970 snprintf(cache_name
, sizeof(cache_name
), "%s/%s.data", CacheDir
, p
->name
);
3971 if (stat(cache_name
, &cache_info
))
3972 cache_info
.st_mtime
= 0;
3974 snprintf(ppd_name
, sizeof(ppd_name
), "%s/ppd/%s.ppd", ServerRoot
, p
->name
);
3975 if (stat(ppd_name
, &ppd_info
))
3976 ppd_info
.st_mtime
= 1;
3978 ippDelete(p
->ppd_attrs
);
3979 p
->ppd_attrs
= ippNew();
3981 _ppdCacheDestroy(p
->pc
);
3984 if (cache_info
.st_mtime
>= ppd_info
.st_mtime
)
3986 cupsdLogMessage(CUPSD_LOG_DEBUG
, "load_ppd: Loading %s...", cache_name
);
3988 if ((p
->pc
= _ppdCacheCreateWithFile(cache_name
, &p
->ppd_attrs
)) != NULL
&&
3992 * Loaded successfully!
4000 * Reload PPD attributes from disk...
4003 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
4005 cupsdLogMessage(CUPSD_LOG_DEBUG
, "load_ppd: Loading %s...", ppd_name
);
4007 p
->type
&= ~CUPS_PRINTER_OPTIONS
;
4008 p
->type
|= CUPS_PRINTER_BW
;
4010 finishings
[0] = IPP_FINISHINGS_NONE
;
4013 if ((ppd
= ppdOpenFile(ppd_name
)) != NULL
)
4016 * Add make/model and other various attributes...
4019 p
->pc
= _ppdCacheCreateWithPPD(ppd
);
4021 ppdMarkDefaults(ppd
);
4023 if (ppd
->color_device
)
4024 p
->type
|= CUPS_PRINTER_COLOR
;
4025 if (ppd
->variable_sizes
)
4026 p
->type
|= CUPS_PRINTER_VARIABLE
;
4027 if (!ppd
->manual_copies
)
4028 p
->type
|= CUPS_PRINTER_COPIES
;
4029 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsFax", NULL
)) != NULL
)
4030 if (ppd_attr
->value
&& !strcasecmp(ppd_attr
->value
, "true"))
4031 p
->type
|= CUPS_PRINTER_FAX
;
4033 ippAddBoolean(p
->ppd_attrs
, IPP_TAG_PRINTER
, "color-supported",
4035 if (ppd
->throughput
)
4037 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4038 "pages-per-minute", ppd
->throughput
);
4039 if (ppd
->color_device
)
4040 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4041 "pages-per-minute-color", ppd
->throughput
);
4046 * When there is no speed information, just say "1 page per minute".
4049 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4050 "pages-per-minute", 1);
4051 if (ppd
->color_device
)
4052 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4053 "pages-per-minute-color", 1);
4058 if ((output_mode
= ppdFindOption(ppd
, "OutputMode")) != NULL
)
4060 if (ppdFindChoice(output_mode
, "draft") ||
4061 ppdFindChoice(output_mode
, "fast"))
4062 qualities
[num_qualities
++] = IPP_QUALITY_DRAFT
;
4064 qualities
[num_qualities
++] = IPP_QUALITY_NORMAL
;
4066 if (ppdFindChoice(output_mode
, "best") ||
4067 ppdFindChoice(output_mode
, "high"))
4068 qualities
[num_qualities
++] = IPP_QUALITY_HIGH
;
4070 else if ((ppd_attr
= ppdFindAttr(ppd
, "APPrinterPreset", NULL
)) != NULL
)
4074 if (strstr(ppd_attr
->spec
, "draft") ||
4075 strstr(ppd_attr
->spec
, "Draft"))
4077 qualities
[num_qualities
++] = IPP_QUALITY_DRAFT
;
4081 while ((ppd_attr
= ppdFindNextAttr(ppd
, "APPrinterPreset",
4084 qualities
[num_qualities
++] = IPP_QUALITY_NORMAL
;
4085 qualities
[num_qualities
++] = IPP_QUALITY_HIGH
;
4088 qualities
[num_qualities
++] = IPP_QUALITY_NORMAL
;
4090 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
4091 "print-quality-supported", num_qualities
, qualities
);
4096 * The NickName can be localized in the character set specified
4097 * by the LanugageEncoding attribute. However, ppdOpen2() has
4098 * already converted the ppd->nickname member to UTF-8 for us
4099 * (the original attribute value is available separately)
4102 cupsdSetString(&p
->make_model
, ppd
->nickname
);
4104 else if (ppd
->modelname
)
4107 * Model name can only contain specific characters...
4110 cupsdSetString(&p
->make_model
, ppd
->modelname
);
4113 cupsdSetString(&p
->make_model
, "Bad PPD File");
4115 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
4116 "printer-make-and-model", NULL
, p
->make_model
);
4119 * Add media options from the PPD file...
4122 if (ppd
->num_sizes
== 0 || !p
->pc
)
4124 if (!ppdFindAttr(ppd
, "APScannerOnly", NULL
))
4125 cupsdLogMessage(CUPSD_LOG_CRIT
,
4126 "The PPD file for printer %s contains no media "
4127 "options and is therefore invalid!", p
->name
);
4129 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4130 "media-default", NULL
, "unknown");
4131 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4132 "media-supported", NULL
, "unknown");
4140 if ((size
= ppdPageSize(ppd
, NULL
)) != NULL
)
4141 pwgsize
= _ppdCacheGetSize(p
->pc
, size
->name
);
4145 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4146 "media-default", NULL
,
4147 pwgsize
? pwgsize
->map
.pwg
: "unknown");
4155 ipp_t
*col
; /* Collection value */
4157 input_slot
= ppdFindMarkedChoice(ppd
, "InputSlot");
4158 media_type
= ppdFindMarkedChoice(ppd
, "MediaType");
4159 col
= new_media_col(pwgsize
,
4161 _ppdCacheGetSource(p
->pc
,
4162 input_slot
->choice
) :
4165 _ppdCacheGetType(p
->pc
,
4166 media_type
->choice
) :
4169 ippAddCollection(p
->ppd_attrs
, IPP_TAG_PRINTER
, "media-col-default",
4178 num_media
= p
->pc
->num_sizes
;
4179 if (p
->pc
->custom_min_keyword
)
4182 if ((attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4183 "media-supported", num_media
, NULL
,
4188 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
;
4190 i
--, pwgsize
++, val
++)
4191 val
->string
.text
= _cupsStrRetain(pwgsize
->map
.pwg
);
4193 if (p
->pc
->custom_min_keyword
)
4195 val
->string
.text
= _cupsStrRetain(p
->pc
->custom_min_keyword
);
4197 val
->string
.text
= _cupsStrRetain(p
->pc
->custom_max_keyword
);
4202 * media-source-supported
4205 if (p
->pc
->num_sources
> 0 &&
4206 (attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4207 "media-source-supported", p
->pc
->num_sources
,
4208 NULL
, NULL
)) != NULL
)
4210 for (i
= p
->pc
->num_sources
, pwgsource
= p
->pc
->sources
,
4213 i
--, pwgsource
++, val
++)
4214 val
->string
.text
= _cupsStrRetain(pwgsource
->pwg
);
4218 * media-type-supported
4221 if (p
->pc
->num_types
> 0 &&
4222 (attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4223 "media-type-supported", p
->pc
->num_types
,
4224 NULL
, NULL
)) != NULL
)
4226 for (i
= p
->pc
->num_types
, pwgtype
= p
->pc
->types
,
4229 i
--, pwgtype
++, val
++)
4230 val
->string
.text
= _cupsStrRetain(pwgtype
->pwg
);
4234 * media-*-margin-supported
4237 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, num_margins
= 0;
4238 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4241 for (j
= 0; j
< num_margins
; j
++)
4242 if (pwgsize
->bottom
== margins
[j
])
4245 if (j
>= num_margins
)
4247 margins
[num_margins
] = pwgsize
->bottom
;
4252 if (num_margins
> 0)
4253 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4254 "media-bottom-margin-supported", num_margins
, margins
);
4256 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4257 "media-bottom-margin-supported", 0);
4259 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, num_margins
= 0;
4260 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4263 for (j
= 0; j
< num_margins
; j
++)
4264 if (pwgsize
->left
== margins
[j
])
4267 if (j
>= num_margins
)
4269 margins
[num_margins
] = pwgsize
->left
;
4274 if (num_margins
> 0)
4275 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4276 "media-left-margin-supported", num_margins
, margins
);
4278 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4279 "media-left-margin-supported", 0);
4281 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, num_margins
= 0;
4282 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4285 for (j
= 0; j
< num_margins
; j
++)
4286 if (pwgsize
->right
== margins
[j
])
4289 if (j
>= num_margins
)
4291 margins
[num_margins
] = pwgsize
->right
;
4296 if (num_margins
> 0)
4297 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4298 "media-right-margin-supported", num_margins
, margins
);
4300 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4301 "media-right-margin-supported", 0);
4303 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, num_margins
= 0;
4304 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4307 for (j
= 0; j
< num_margins
; j
++)
4308 if (pwgsize
->top
== margins
[j
])
4311 if (j
>= num_margins
)
4313 margins
[num_margins
] = pwgsize
->top
;
4318 if (num_margins
> 0)
4319 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4320 "media-top-margin-supported", num_margins
, margins
);
4322 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4323 "media-top-margin-supported", 0);
4326 * media-col-database
4329 num_media
= p
->pc
->num_sizes
;
4330 if (p
->pc
->num_sources
)
4332 if (p
->pc
->num_types
> 0)
4333 num_media
+= p
->pc
->num_sizes
* p
->pc
->num_sources
*
4336 num_media
+= p
->pc
->num_sizes
* p
->pc
->num_sources
;
4338 else if (p
->pc
->num_types
)
4339 num_media
+= p
->pc
->num_sizes
* p
->pc
->num_types
;
4341 if ((attr
= ippAddCollections(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4342 "media-col-database", num_media
,
4345 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, val
= attr
->values
;
4350 * Start by adding the page size without source or type...
4353 ppdMarkOption(ppd
, "PageSize", pwgsize
->map
.ppd
);
4355 val
->collection
= new_media_col(pwgsize
, NULL
, NULL
);
4359 * Then add the specific, supported combinations of size, source, and
4363 if (p
->pc
->num_sources
> 0)
4365 for (j
= p
->pc
->num_sources
, pwgsource
= p
->pc
->sources
;
4369 ppdMarkOption(ppd
, "InputSlot", pwgsource
->ppd
);
4371 if (p
->pc
->num_types
> 0)
4373 for (k
= p
->pc
->num_types
, pwgtype
= p
->pc
->types
;
4377 if (!ppdMarkOption(ppd
, "MediaType", pwgtype
->ppd
))
4379 val
->collection
= new_media_col(pwgsize
, pwgsource
->pwg
,
4385 else if (!ppdConflicts(ppd
))
4387 val
->collection
= new_media_col(pwgsize
, pwgsource
->pwg
, NULL
);
4392 else if (p
->pc
->num_types
> 0)
4394 for (j
= p
->pc
->num_types
, pwgtype
= p
->pc
->types
;
4398 if (!ppdMarkOption(ppd
, "MediaType", pwgtype
->ppd
))
4400 val
->collection
= new_media_col(pwgsize
, NULL
, pwgtype
->pwg
);
4408 * Update the number of media-col-database values...
4411 attr
->num_values
= val
- attr
->values
;
4419 if (p
->pc
&& p
->pc
->num_bins
> 0)
4421 attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4422 "output-bin-supported", p
->pc
->num_bins
,
4427 for (i
= 0, val
= attr
->values
;
4428 i
< p
->pc
->num_bins
;
4430 val
->string
.text
= _cupsStrAlloc(p
->pc
->bins
[i
].pwg
);
4433 if ((output_bin
= ppdFindOption(ppd
, "OutputBin")) != NULL
)
4435 for (i
= 0; i
< p
->pc
->num_bins
; i
++)
4436 if (!strcmp(p
->pc
->bins
[i
].ppd
, output_bin
->defchoice
))
4439 if (i
>= p
->pc
->num_bins
)
4442 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4443 "output-bin-default", NULL
, p
->pc
->bins
[i
].pwg
);
4446 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4447 "output-bin-default", NULL
, p
->pc
->bins
[0].pwg
);
4449 else if (((ppd_attr
= ppdFindAttr(ppd
, "DefaultOutputOrder",
4451 !strcasecmp(ppd_attr
->value
, "Reverse")) ||
4452 (!ppd_attr
&& ppd
->manufacturer
&& /* "Compatibility heuristic" */
4453 (!strcasecmp(ppd
->manufacturer
, "epson") ||
4454 !strcasecmp(ppd
->manufacturer
, "lexmark"))))
4457 * Report that this printer has a single output bin that leaves pages face
4461 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4462 "output-bin-supported", NULL
, "face-up");
4463 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4464 "output-bin-default", NULL
, "face-up");
4468 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4469 "output-bin-supported", NULL
, "face-down");
4470 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4471 "output-bin-default", NULL
, "face-down");
4475 * output-mode and print-color-mode...
4478 if (ppd
->color_device
)
4480 static const char * const output_modes
[] =
4486 ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4487 "output-mode-supported", 2, NULL
, output_modes
);
4488 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4489 "output-mode-default", NULL
, "color");
4491 ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4492 "print-color-mode-supported", 2, NULL
, output_modes
);
4493 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4494 "print-color-mode-default", NULL
, "color");
4498 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4499 "output-mode-supported", NULL
, "monochrome");
4500 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4501 "output-mode-default", NULL
, "monochrome");
4503 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4504 "print-color-mode-supported", NULL
, "monochrome");
4505 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4506 "print-color-mode-default", NULL
, "monochrome");
4510 * Printer resolutions...
4513 if ((resolution
= ppdFindOption(ppd
, "Resolution")) == NULL
)
4514 if ((resolution
= ppdFindOption(ppd
, "JCLResolution")) == NULL
)
4515 if ((resolution
= ppdFindOption(ppd
, "SetResolution")) == NULL
)
4516 resolution
= ppdFindOption(ppd
, "CNRes_PGP");
4521 * Report all supported resolutions...
4524 attr
= ippAddResolutions(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4525 "printer-resolution-supported",
4526 resolution
->num_choices
, IPP_RES_PER_INCH
,
4529 for (i
= 0, choice
= resolution
->choices
;
4530 i
< resolution
->num_choices
;
4533 xdpi
= ydpi
= (int)strtol(choice
->choice
, (char **)&resptr
, 10);
4534 if (resptr
> choice
->choice
&& xdpi
> 0 && *resptr
== 'x')
4535 ydpi
= (int)strtol(resptr
+ 1, (char **)&resptr
, 10);
4537 if (xdpi
<= 0 || ydpi
<= 0)
4539 cupsdLogMessage(CUPSD_LOG_WARN
,
4540 "Bad resolution \"%s\" for printer %s.",
4541 choice
->choice
, p
->name
);
4545 attr
->values
[i
].resolution
.xres
= xdpi
;
4546 attr
->values
[i
].resolution
.yres
= ydpi
;
4547 attr
->values
[i
].resolution
.units
= IPP_RES_PER_INCH
;
4550 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4551 "printer-resolution-default", IPP_RES_PER_INCH
,
4555 else if ((ppd_attr
= ppdFindAttr(ppd
, "DefaultResolution", NULL
)) != NULL
&&
4559 * Just the DefaultResolution to report...
4562 xdpi
= ydpi
= (int)strtol(ppd_attr
->value
, (char **)&resptr
, 10);
4563 if (resptr
> ppd_attr
->value
&& xdpi
> 0)
4566 ydpi
= (int)strtol(resptr
+ 1, (char **)&resptr
, 10);
4571 if (xdpi
<= 0 || ydpi
<= 0)
4573 cupsdLogMessage(CUPSD_LOG_WARN
,
4574 "Bad default resolution \"%s\" for printer %s.",
4575 ppd_attr
->value
, p
->name
);
4579 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4580 "printer-resolution-default", IPP_RES_PER_INCH
,
4582 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4583 "printer-resolution-supported", IPP_RES_PER_INCH
,
4589 * No resolutions in PPD - make one up...
4592 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4593 "printer-resolution-default", IPP_RES_PER_INCH
,
4595 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4596 "printer-resolution-supported", IPP_RES_PER_INCH
,
4604 ppdMarkDefaults(ppd
);
4606 if ((duplex
= ppdFindOption(ppd
, "Duplex")) == NULL
)
4607 if ((duplex
= ppdFindOption(ppd
, "EFDuplex")) == NULL
)
4608 if ((duplex
= ppdFindOption(ppd
, "EFDuplexing")) == NULL
)
4609 if ((duplex
= ppdFindOption(ppd
, "KD03Duplex")) == NULL
)
4610 duplex
= ppdFindOption(ppd
, "JCLDuplex");
4612 if (duplex
&& duplex
->num_choices
> 1 &&
4613 !ppdInstallableConflict(ppd
, duplex
->keyword
, "DuplexTumble"))
4615 p
->type
|= CUPS_PRINTER_DUPLEX
;
4617 ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4618 "sides-supported", 3, NULL
, sides
);
4620 if (!strcasecmp(duplex
->defchoice
, "DuplexTumble"))
4621 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4622 "sides-default", NULL
, "two-sided-short-edge");
4623 else if (!strcasecmp(duplex
->defchoice
, "DuplexNoTumble"))
4624 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4625 "sides-default", NULL
, "two-sided-long-edge");
4627 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4628 "sides-default", NULL
, "one-sided");
4632 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4633 "sides-supported", NULL
, "one-sided");
4634 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4635 "sides-default", NULL
, "one-sided");
4638 if (ppdFindOption(ppd
, "Collate") != NULL
)
4639 p
->type
|= CUPS_PRINTER_COLLATE
;
4641 if (ppdFindOption(ppd
, "StapleLocation") != NULL
)
4643 p
->type
|= CUPS_PRINTER_STAPLE
;
4644 finishings
[num_finishings
++] = IPP_FINISHINGS_STAPLE
;
4647 if (ppdFindOption(ppd
, "BindEdge") != NULL
)
4649 p
->type
|= CUPS_PRINTER_BIND
;
4650 finishings
[num_finishings
++] = IPP_FINISHINGS_BIND
;
4653 for (i
= 0; i
< ppd
->num_sizes
; i
++)
4654 if (ppd
->sizes
[i
].length
> 1728)
4655 p
->type
|= CUPS_PRINTER_LARGE
;
4656 else if (ppd
->sizes
[i
].length
> 1008)
4657 p
->type
|= CUPS_PRINTER_MEDIUM
;
4659 p
->type
|= CUPS_PRINTER_SMALL
;
4661 if ((ppd_attr
= ppdFindAttr(ppd
, "APICADriver", NULL
)) != NULL
&&
4662 ppd_attr
->value
&& !strcasecmp(ppd_attr
->value
, "true"))
4664 if ((ppd_attr
= ppdFindAttr(ppd
, "APScannerOnly", NULL
)) != NULL
&&
4665 ppd_attr
->value
&& !strcasecmp(ppd_attr
->value
, "true"))
4666 p
->type
|= CUPS_PRINTER_SCANNER
;
4668 p
->type
|= CUPS_PRINTER_MFP
;
4672 * Scan the filters in the PPD file...
4677 for (filter
= (const char *)cupsArrayFirst(p
->pc
->filters
);
4679 filter
= (const char *)cupsArrayNext(p
->pc
->filters
))
4681 if (!strncasecmp(filter
, "application/vnd.cups-command", 28) &&
4682 _cups_isspace(filter
[28]))
4684 p
->type
|= CUPS_PRINTER_COMMANDS
;
4690 if (p
->type
& CUPS_PRINTER_COMMANDS
)
4692 char *commands
, /* Copy of commands */
4693 *start
, /* Start of name */
4694 *end
; /* End of name */
4695 int count
; /* Number of commands */
4697 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsCommands", NULL
)) != NULL
)
4699 for (count
= 0, start
= ppd_attr
->value
; *start
; count
++)
4701 while (_cups_isspace(*start
))
4707 while (*start
&& !isspace(*start
& 255))
4717 * Make a copy of the commands string and count how many commands there
4721 attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4722 "printer-commands", count
, NULL
, NULL
);
4724 commands
= strdup(ppd_attr
->value
);
4726 for (count
= 0, start
= commands
; *start
; count
++)
4728 while (isspace(*start
& 255))
4735 while (*end
&& !isspace(*end
& 255))
4741 attr
->values
[count
].string
.text
= _cupsStrAlloc(start
);
4751 * Add the standard list of commands...
4754 ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4756 (int)(sizeof(standard_commands
) /
4757 sizeof(standard_commands
[0])), NULL
,
4764 * No commands supported...
4767 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4768 "printer-commands", NULL
, "none");
4772 * Show current and available port monitors for this printer...
4775 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
, "port-monitor",
4776 NULL
, p
->port_monitor
? p
->port_monitor
: "none");
4778 for (i
= 1, ppd_attr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
4780 i
++, ppd_attr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
));
4784 if (strstr(ppd
->protocols
, "TBCP"))
4786 else if (strstr(ppd
->protocols
, "BCP"))
4790 attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
4791 "port-monitor-supported", i
, NULL
, NULL
);
4793 attr
->values
[0].string
.text
= _cupsStrAlloc("none");
4795 for (i
= 1, ppd_attr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
4797 i
++, ppd_attr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
))
4798 attr
->values
[i
].string
.text
= _cupsStrAlloc(ppd_attr
->value
);
4802 if (strstr(ppd
->protocols
, "TBCP"))
4803 attr
->values
[i
].string
.text
= _cupsStrAlloc("tbcp");
4804 else if (strstr(ppd
->protocols
, "BCP"))
4805 attr
->values
[i
].string
.text
= _cupsStrAlloc("bcp");
4808 if (ppdFindAttr(ppd
, "APRemoteQueueID", NULL
))
4809 p
->type
|= CUPS_PRINTER_REMOTE
;
4811 #ifdef HAVE_APPLICATIONSERVICES_H
4813 * Convert the file referenced in APPrinterIconPath to a 128x128 PNG
4814 * and save it as cacheDir/printername.png
4817 if ((ppd_attr
= ppdFindAttr(ppd
, "APPrinterIconPath", NULL
)) != NULL
&&
4820 CGImageRef imageRef
= NULL
;/* Current icon image */
4821 CGImageRef biggestIconRef
= NULL
;
4822 /* Biggest icon image */
4823 CGImageRef closestTo128IconRef
= NULL
;
4824 /* Icon image closest to and >= 128 */
4825 CGImageSourceRef sourceRef
; /* The file's image source */
4826 char outPath
[HTTP_MAX_URI
];
4827 /* The path to the PNG file */
4828 CFURLRef outUrl
; /* The URL made from the outPath */
4829 CFURLRef icnsFileUrl
; /* The URL of the original ICNS icon file */
4830 CGImageDestinationRef destRef
; /* The image destination to write */
4831 size_t bytesPerRow
; /* The bytes per row used for resizing */
4832 CGContextRef context
; /* The CG context used for resizing */
4834 snprintf(outPath
, sizeof(outPath
), "%s/%s.png", CacheDir
, p
->name
);
4835 outUrl
= CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault
,
4839 icnsFileUrl
= CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault
,
4840 (UInt8
*)ppd_attr
->value
,
4841 strlen(ppd_attr
->value
),
4843 if (outUrl
&& icnsFileUrl
)
4845 sourceRef
= CGImageSourceCreateWithURL(icnsFileUrl
, NULL
);
4848 for (i
= 0; i
< CGImageSourceGetCount(sourceRef
); i
++)
4850 imageRef
= CGImageSourceCreateImageAtIndex(sourceRef
, i
, NULL
);
4854 if (CGImageGetWidth(imageRef
) == CGImageGetHeight(imageRef
))
4857 * Loop through remembering the icon closest to 128 but >= 128
4858 * and then remember the largest icon.
4861 if (CGImageGetWidth(imageRef
) >= 128 &&
4862 (!closestTo128IconRef
||
4863 CGImageGetWidth(imageRef
) <
4864 CGImageGetWidth(closestTo128IconRef
)))
4866 CGImageRelease(closestTo128IconRef
);
4867 CGImageRetain(imageRef
);
4868 closestTo128IconRef
= imageRef
;
4871 if (!biggestIconRef
||
4872 CGImageGetWidth(imageRef
) > CGImageGetWidth(biggestIconRef
))
4874 CGImageRelease(biggestIconRef
);
4875 CGImageRetain(imageRef
);
4876 biggestIconRef
= imageRef
;
4880 CGImageRelease(imageRef
);
4886 * If biggestIconRef is NULL, we found no icons. Otherwise we first
4887 * want the closest to 128, but if none are larger than 128, we want
4888 * the largest icon available.
4891 imageRef
= closestTo128IconRef
? closestTo128IconRef
:
4893 CGImageRetain(imageRef
);
4894 CGImageRelease(biggestIconRef
);
4895 if (closestTo128IconRef
)
4896 CGImageRelease(closestTo128IconRef
);
4897 destRef
= CGImageDestinationCreateWithURL(outUrl
, kUTTypePNG
, 1,
4901 if (CGImageGetWidth(imageRef
) != 128)
4903 bytesPerRow
= CGImageGetBytesPerRow(imageRef
) /
4904 CGImageGetWidth(imageRef
) * 128;
4905 context
= CGBitmapContextCreate(NULL
, 128, 128,
4906 CGImageGetBitsPerComponent(imageRef
),
4908 CGImageGetColorSpace(imageRef
),
4909 kCGImageAlphaPremultipliedFirst
);
4912 CGContextDrawImage(context
, CGRectMake(0, 0, 128, 128),
4914 CGImageRelease(imageRef
);
4915 imageRef
= CGBitmapContextCreateImage(context
);
4916 CGContextRelease(context
);
4920 CGImageDestinationAddImage(destRef
, imageRef
, NULL
);
4921 CGImageDestinationFinalize(destRef
);
4925 CGImageRelease(imageRef
);
4928 CFRelease(sourceRef
);
4936 CFRelease(icnsFileUrl
);
4938 #endif /* HAVE_APPLICATIONSERVICES_H */
4941 * Close the PPD and set the type...
4946 else if (!access(ppd_name
, 0))
4948 int pline
; /* PPD line number */
4949 ppd_status_t pstatus
; /* PPD load status */
4952 pstatus
= ppdLastError(&pline
);
4954 cupsdLogMessage(CUPSD_LOG_ERROR
, "PPD file for %s cannot be loaded!",
4957 if (pstatus
<= PPD_ALLOC_ERROR
)
4958 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s", strerror(errno
));
4960 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s on line %d.",
4961 ppdErrorString(pstatus
), pline
);
4963 cupsdLogMessage(CUPSD_LOG_INFO
,
4964 "Hint: Run \"cupstestppd %s\" and fix any errors.",
4970 * If we have an interface script, add a filter entry for it...
4973 char interface
[1024]; /* Interface script */
4976 snprintf(interface
, sizeof(interface
), "%s/interfaces/%s", ServerRoot
,
4978 if (!access(interface
, X_OK
))
4981 * Yes, we have a System V style interface script; use it!
4984 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
4985 "printer-make-and-model", NULL
,
4986 "Local System V Printer");
4988 else if (!strncmp(p
->device_uri
, "ipp://", 6) &&
4989 (strstr(p
->device_uri
, "/printers/") != NULL
||
4990 strstr(p
->device_uri
, "/classes/") != NULL
||
4991 (strstr(p
->device_uri
, "._ipp.") != NULL
&&
4992 !strcmp(p
->device_uri
+ strlen(p
->device_uri
) - 5,
4996 * Tell the client this is really a hard-wired remote printer.
4999 p
->type
|= CUPS_PRINTER_REMOTE
;
5002 * Point the printer-uri-supported attribute to the
5006 if (strchr(p
->device_uri
, '?'))
5009 * Strip trailing "?options" from URI...
5012 char resource
[HTTP_MAX_URI
], /* New URI */
5013 *ptr
; /* Pointer into URI */
5015 strlcpy(resource
, p
->device_uri
, sizeof(resource
));
5016 if ((ptr
= strchr(resource
, '?')) != NULL
)
5019 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
5020 "printer-uri-supported", NULL
, resource
);
5023 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
5024 "printer-uri-supported", NULL
, p
->device_uri
);
5027 * Then set the make-and-model accordingly...
5030 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
5031 "printer-make-and-model", NULL
, "Remote Printer");
5034 * Print all files directly...
5043 * Otherwise we have neither - treat this as a "dumb" printer
5044 * with no PPD file...
5047 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
5048 "printer-make-and-model", NULL
, "Local Raw Printer");
5054 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
5055 "finishings-supported", num_finishings
, finishings
);
5056 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
5057 "finishings-default", IPP_FINISHINGS_NONE
);
5062 * Save cached PPD attributes to disk...
5065 cupsdLogMessage(CUPSD_LOG_DEBUG
, "load_ppd: Saving %s...", cache_name
);
5067 _ppdCacheWriteFile(p
->pc
, cache_name
, p
->ppd_attrs
);
5072 * Remove cache files...
5075 if (cache_info
.st_mtime
)
5082 * 'new_media_col()' - Create a media-col collection value.
5085 static ipp_t
* /* O - Collection value */
5086 new_media_col(_pwg_size_t
*size
, /* I - media-size/margin values */
5087 const char *source
, /* I - media-source value */
5088 const char *type
) /* I - media-type value */
5090 ipp_t
*media_col
, /* Collection value */
5091 *media_size
; /* media-size value */
5094 media_col
= ippNew();
5096 media_size
= ippNew();
5097 ippAddInteger(media_size
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5098 "x-dimension", size
->width
);
5099 ippAddInteger(media_size
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5100 "y-dimension", size
->length
);
5101 ippAddCollection(media_col
, IPP_TAG_PRINTER
, "media-size", media_size
);
5102 ippDelete(media_size
);
5104 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5105 "media-bottom-margin", size
->bottom
);
5106 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5107 "media-left-margin", size
->left
);
5108 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5109 "media-right-margin", size
->right
);
5110 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5111 "media-top-margin", size
->top
);
5114 ippAddString(media_col
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
, "media-source",
5118 ippAddString(media_col
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
, "media-type",
5127 * 'write_irix_config()' - Update the config files used by the IRIX
5132 write_irix_config(cupsd_printer_t
*p
) /* I - Printer to update */
5134 char filename
[1024]; /* Interface script filename */
5135 cups_file_t
*fp
; /* Interface script file */
5136 ipp_attribute_t
*attr
; /* Attribute data */
5140 * Add dummy interface and GUI scripts to fool SGI's "challenged" printing
5141 * tools. First the interface script that tells the tools what kind of
5142 * printer we have...
5145 snprintf(filename
, sizeof(filename
), "/var/spool/lp/interface/%s", p
->name
);
5147 if (p
->type
& CUPS_PRINTER_CLASS
)
5149 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
5151 cupsFilePuts(fp
, "#!/bin/sh\n");
5153 if ((attr
= ippFindAttribute(p
->attrs
, "printer-make-and-model",
5154 IPP_TAG_TEXT
)) != NULL
)
5155 cupsFilePrintf(fp
, "NAME=\"%s\"\n", attr
->values
[0].string
.text
);
5156 else if (p
->type
& CUPS_PRINTER_CLASS
)
5157 cupsFilePuts(fp
, "NAME=\"Printer Class\"\n");
5159 cupsFilePuts(fp
, "NAME=\"Remote Destination\"\n");
5161 if (p
->type
& CUPS_PRINTER_COLOR
)
5162 cupsFilePuts(fp
, "TYPE=ColorPostScript\n");
5164 cupsFilePuts(fp
, "TYPE=MonoPostScript\n");
5166 cupsFilePrintf(fp
, "HOSTNAME=%s\n", ServerName
);
5167 cupsFilePrintf(fp
, "HOSTPRINTER=%s\n", p
->name
);
5171 chmod(filename
, 0755);
5172 chown(filename
, User
, Group
);
5176 * Then the member file that tells which device file the queue is connected
5177 * to... Networked printers use "/dev/null" in this file, so that's what
5178 * we use (the actual device URI can confuse some apps...)
5181 snprintf(filename
, sizeof(filename
), "/var/spool/lp/member/%s", p
->name
);
5183 if (p
->type
& CUPS_PRINTER_CLASS
)
5185 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
5187 cupsFilePuts(fp
, "/dev/null\n");
5191 chmod(filename
, 0644);
5192 chown(filename
, User
, Group
);
5196 * The gui_interface file is a script or program that launches a GUI
5197 * option panel for the printer, using options specified on the
5198 * command-line in the third argument. The option panel must send
5199 * any printing options to stdout on a single line when the user
5200 * accepts them, or nothing if the user cancels the dialog.
5202 * The default options panel program is /usr/bin/glpoptions, from
5203 * the ESP Print Pro software. You can select another using the
5204 * PrintcapGUI option.
5207 snprintf(filename
, sizeof(filename
), "/var/spool/lp/gui_interface/ELF/%s.gui", p
->name
);
5209 if (p
->type
& CUPS_PRINTER_CLASS
)
5211 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
5213 cupsFilePuts(fp
, "#!/bin/sh\n");
5214 cupsFilePrintf(fp
, "%s -d %s -o \"$3\"\n", PrintcapGUI
, p
->name
);
5218 chmod(filename
, 0755);
5219 chown(filename
, User
, Group
);
5223 * The POD config file is needed by the printstatus command to show
5224 * the printer location and device.
5227 snprintf(filename
, sizeof(filename
), "/var/spool/lp/pod/%s.config", p
->name
);
5229 if (p
->type
& CUPS_PRINTER_CLASS
)
5231 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
5233 cupsFilePrintf(fp
, "Printer Class | %s\n",
5234 (p
->type
& CUPS_PRINTER_COLOR
) ? "ColorPostScript" : "MonoPostScript");
5235 cupsFilePrintf(fp
, "Printer Model | %s\n", p
->make_model
? p
->make_model
: "");
5236 cupsFilePrintf(fp
, "Location Code | %s\n", p
->location
? p
->location
: "");
5237 cupsFilePrintf(fp
, "Physical Location | %s\n", p
->info
? p
->info
: "");
5238 cupsFilePrintf(fp
, "Port Path | %s\n", p
->device_uri
);
5239 cupsFilePrintf(fp
, "Config Path | /var/spool/lp/pod/%s.config\n", p
->name
);
5240 cupsFilePrintf(fp
, "Active Status Path | /var/spool/lp/pod/%s.status\n", p
->name
);
5241 cupsFilePuts(fp
, "Status Update Wait | 10 seconds\n");
5245 chmod(filename
, 0664);
5246 chown(filename
, User
, Group
);
5252 * 'write_irix_state()' - Update the status files used by IRIX printing
5257 write_irix_state(cupsd_printer_t
*p
) /* I - Printer to update */
5259 char filename
[1024]; /* Interface script filename */
5260 cups_file_t
*fp
; /* Interface script file */
5261 int tag
; /* Status tag value */
5267 * The POD status file is needed for the printstatus window to
5268 * provide the current status of the printer.
5271 snprintf(filename
, sizeof(filename
), "/var/spool/lp/pod/%s.status", p
->name
);
5273 if (p
->type
& CUPS_PRINTER_CLASS
)
5275 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
5277 cupsFilePrintf(fp
, "Operational Status | %s\n",
5278 (p
->state
== IPP_PRINTER_IDLE
) ? "Idle" :
5279 (p
->state
== IPP_PRINTER_PROCESSING
) ? "Busy" :
5281 cupsFilePrintf(fp
, "Information | 01 00 00 | %s\n", CUPS_SVERSION
);
5282 cupsFilePrintf(fp
, "Information | 02 00 00 | Device URI: %s\n",
5284 cupsFilePrintf(fp
, "Information | 03 00 00 | %s jobs\n",
5285 p
->accepting
? "Accepting" : "Not accepting");
5286 cupsFilePrintf(fp
, "Information | 04 00 00 | %s\n", p
->state_message
);
5290 chmod(filename
, 0664);
5291 chown(filename
, User
, Group
);
5295 * The activeicons file is needed to provide desktop icons for printers:
5297 * [ quoted from /usr/lib/print/tagit ]
5299 * --- Type of printer tags (base values)
5301 * Dumb=66048 # 0x10200
5302 * DumbColor=66080 # 0x10220
5303 * Raster=66112 # 0x10240
5304 * ColorRaster=66144 # 0x10260
5305 * Plotter=66176 # 0x10280
5306 * PostScript=66208 # 0x102A0
5307 * ColorPostScript=66240 # 0x102C0
5308 * MonoPostScript=66272 # 0x102E0
5310 * --- Printer state modifiers for local printers
5315 * Unknown=3 # 0x3 (Faulted due to unknown reason)
5317 * --- Printer state modifiers for network printers
5321 * NetFaulted=10 # 0xA
5322 * NetUnknown=11 # 0xB (Faulted due to unknown reason)
5325 snprintf(filename
, sizeof(filename
), "/var/spool/lp/activeicons/%s", p
->name
);
5327 if (p
->type
& CUPS_PRINTER_CLASS
)
5329 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
5331 if (p
->type
& CUPS_PRINTER_COLOR
)
5336 if (p
->type
& CUPS_PRINTER_REMOTE
)
5339 if (p
->state
== IPP_PRINTER_PROCESSING
)
5342 else if (p
->state
== IPP_PRINTER_STOPPED
)
5345 cupsFilePuts(fp
, "#!/bin/sh\n");
5346 cupsFilePrintf(fp
, "#Tag %d\n", tag
);
5350 chmod(filename
, 0755);
5351 chown(filename
, User
, Group
);
5356 * The default file is needed by the printers window to show
5357 * the default printer.
5360 snprintf(filename
, sizeof(filename
), "/var/spool/lp/default");
5362 if (DefaultPrinter
!= NULL
)
5364 if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
5366 cupsFilePrintf(fp
, "%s\n", DefaultPrinter
->name
);
5370 chmod(filename
, 0644);
5371 chown(filename
, User
, Group
);
5381 * 'write_xml_string()' - Write a string with XML escaping.
5385 write_xml_string(cups_file_t
*fp
, /* I - File to write to */
5386 const char *s
) /* I - String to write */
5388 const char *start
; /* Start of current sequence */
5394 for (start
= s
; *s
; s
++)
5399 cupsFileWrite(fp
, start
, s
- start
);
5401 cupsFilePuts(fp
, "&");
5407 cupsFileWrite(fp
, start
, s
- start
);
5409 cupsFilePuts(fp
, "<");
5415 cupsFilePuts(fp
, start
);
5420 * End of "$Id: printers.c 7968 2008-09-19 23:03:01Z mike $".