2 * "$Id: printers.c 7968 2008-09-19 23:03:01Z mike $"
4 * Printer routines for the CUPS scheduler.
6 * Copyright 2007-2011 by Apple Inc.
7 * Copyright 1997-2007 by Easy Software Products, all rights reserved.
9 * These coded instructions, statements, and computer programs are the
10 * property of Apple Inc. and are protected by Federal copyright
11 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
12 * which should have been included with this file. If this file is
13 * file is missing or damaged, see the license at "http://www.cups.org/".
17 * cupsdAddPrinter() - Add a printer to the system.
18 * cupsdCreateCommonData() - Create the common printer data.
19 * cupsdDeleteAllPrinters() - Delete all printers from the system.
20 * cupsdDeletePrinter() - Delete a printer from the system.
21 * cupsdFindDest() - Find a destination in the list.
22 * cupsdFindPrinter() - Find a printer in the list.
23 * cupsdLoadAllPrinters() - Load printers from the printers.conf file.
24 * cupsdRenamePrinter() - Rename a printer.
25 * cupsdSaveAllPrinters() - Save all printer definitions to the
27 * cupsdSetAuthInfoRequired() - Set the required authentication info.
28 * cupsdSetDeviceURI() - Set the device URI for a printer.
29 * cupsdSetPrinterAttr() - Set a printer attribute.
30 * cupsdSetPrinterAttrs() - Set printer attributes based upon the PPD
32 * cupsdSetPrinterReasons() - Set/update the reasons strings.
33 * cupsdSetPrinterState() - Update the current state of a printer.
34 * cupsdStopPrinter() - Stop a printer from printing any jobs...
35 * cupsdUpdatePrinterPPD() - Update keywords in a printer's PPD file.
36 * cupsdUpdatePrinters() - Update printers after a partial reload.
37 * cupsdValidateDest() - Validate a printer/class destination.
38 * cupsdWritePrintcap() - Write a pseudo-printcap file for older
39 * applications that need it...
40 * add_printer_defaults() - Add name-default attributes to the printer
42 * add_printer_filter() - Add a MIME filter for a printer.
43 * add_printer_formats() - Add document-format-supported values for a
45 * compare_printers() - Compare two printers.
46 * delete_printer_filters() - Delete all MIME filters for a printer.
47 * dirty_printer() - Mark config and state files dirty for the
49 * load_ppd() - Load a cached PPD file, updating the cache as
51 * new_media_col() - Create a media-col collection value.
52 * write_irix_config() - Update the config files used by the IRIX
54 * write_irix_state() - Update the status files used by IRIX printing
56 * write_xml_string() - Write a string with XML escaping.
60 * Include necessary headers...
65 #ifdef HAVE_APPLICATIONSERVICES_H
66 # include <ApplicationServices/ApplicationServices.h>
67 #endif /* HAVE_APPLICATIONSERVICES_H */
68 #ifdef HAVE_SYS_MOUNT_H
69 # include <sys/mount.h>
70 #endif /* HAVE_SYS_MOUNT_H */
71 #ifdef HAVE_SYS_STATVFS_H
72 # include <sys/statvfs.h>
73 #elif defined(HAVE_SYS_STATFS_H)
74 # include <sys/statfs.h>
75 #endif /* HAVE_SYS_STATVFS_H */
78 #endif /* HAVE_SYS_VFS_H */
81 #endif /* __APPLE__ */
88 static void add_printer_defaults(cupsd_printer_t
*p
);
89 static void add_printer_filter(cupsd_printer_t
*p
, mime_type_t
*type
,
91 static void add_printer_formats(cupsd_printer_t
*p
);
92 static int compare_printers(void *first
, void *second
, void *data
);
93 static void delete_printer_filters(cupsd_printer_t
*p
);
94 static void dirty_printer(cupsd_printer_t
*p
);
95 static void load_ppd(cupsd_printer_t
*p
);
96 static void log_ipp_conformance(cupsd_printer_t
*p
, const char *reason
);
97 static ipp_t
*new_media_col(_pwg_size_t
*size
, const char *source
,
100 static void write_irix_config(cupsd_printer_t
*p
);
101 static void write_irix_state(cupsd_printer_t
*p
);
103 static void write_xml_string(cups_file_t
*fp
, const char *s
);
107 * 'cupsdAddPrinter()' - Add a printer to the system.
110 cupsd_printer_t
* /* O - New printer */
111 cupsdAddPrinter(const char *name
) /* I - Name of printer */
113 cupsd_printer_t
*p
; /* New printer */
114 char uri
[1024], /* Printer URI */
115 uuid
[64]; /* Printer UUID */
119 * Range check input...
122 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdAddPrinter(\"%s\")", name
);
125 * Create a new printer entity...
128 if ((p
= calloc(1, sizeof(cupsd_printer_t
))) == NULL
)
130 cupsdLogMessage(CUPSD_LOG_CRIT
, "Unable to allocate memory for printer - %s",
135 cupsdSetString(&p
->name
, name
);
136 cupsdSetString(&p
->info
, name
);
137 cupsdSetString(&p
->hostname
, ServerName
);
139 httpAssembleURIf(HTTP_URI_CODING_ALL
, uri
, sizeof(uri
), "ipp", NULL
,
140 ServerName
, RemotePort
, "/printers/%s", name
);
141 cupsdSetString(&p
->uri
, uri
);
142 cupsdSetString(&p
->uuid
, _httpAssembleUUID(ServerName
, RemotePort
, name
, 0,
143 uuid
, sizeof(uuid
)));
144 cupsdSetDeviceURI(p
, "file:///dev/null");
146 p
->state
= IPP_PRINTER_STOPPED
;
147 p
->state_time
= time(NULL
);
149 p
->shared
= DefaultShared
;
150 p
->filetype
= mimeAddType(MimeDatabase
, "printer", name
);
152 cupsdSetString(&p
->job_sheets
[0], "none");
153 cupsdSetString(&p
->job_sheets
[1], "none");
155 cupsdSetString(&p
->error_policy
, ErrorPolicy
);
156 cupsdSetString(&p
->op_policy
, DefaultPolicy
);
158 p
->op_policy_ptr
= DefaultPolicyPtr
;
161 * Insert the printer in the printer list alphabetically...
165 Printers
= cupsArrayNew(compare_printers
, NULL
);
167 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
168 "cupsdAddPrinter: Adding %s to Printers", p
->name
);
169 cupsArrayAdd(Printers
, p
);
172 * Return the new printer...
180 * 'cupsdCreateCommonData()' - Create the common printer data.
184 cupsdCreateCommonData(void)
186 int i
; /* Looping var */
187 ipp_attribute_t
*attr
; /* Attribute data */
188 cups_dir_t
*dir
; /* Notifier directory */
189 cups_dentry_t
*dent
; /* Notifier directory entry */
190 cups_array_t
*notifiers
; /* Notifier array */
191 char filename
[1024], /* Filename */
192 *notifier
; /* Current notifier */
193 cupsd_policy_t
*p
; /* Current policy */
194 int k_supported
; /* Maximum file size supported */
196 struct statvfs spoolinfo
; /* FS info for spool directory */
197 double spoolsize
; /* FS size */
198 #elif defined(HAVE_STATFS)
199 struct statfs spoolinfo
; /* FS info for spool directory */
200 double spoolsize
; /* FS size */
201 #endif /* HAVE_STATVFS */
202 static const int nups
[] = /* number-up-supported values */
203 { 1, 2, 4, 6, 9, 16 };
204 static const int orients
[4] =/* orientation-requested-supported values */
208 IPP_REVERSE_LANDSCAPE
,
211 static const char * const holds
[] = /* job-hold-until-supported values */
222 static const char * const versions
[] =/* ipp-versions-supported values */
229 static const int ops
[] = /* operations-supported values */
236 IPP_GET_JOB_ATTRIBUTES
,
238 IPP_GET_PRINTER_ATTRIBUTES
,
245 IPP_SET_PRINTER_ATTRIBUTES
,
246 IPP_SET_JOB_ATTRIBUTES
,
247 IPP_GET_PRINTER_SUPPORTED_VALUES
,
248 IPP_CREATE_PRINTER_SUBSCRIPTION
,
249 IPP_CREATE_JOB_SUBSCRIPTION
,
250 IPP_GET_SUBSCRIPTION_ATTRIBUTES
,
251 IPP_GET_SUBSCRIPTIONS
,
252 IPP_RENEW_SUBSCRIPTION
,
253 IPP_CANCEL_SUBSCRIPTION
,
254 IPP_GET_NOTIFICATIONS
,
258 IPP_RELEASE_HELD_NEW_JOBS
,
275 CUPS_AUTHENTICATE_JOB
,
280 static const char * const charsets
[] =/* charset-supported values */
285 static const char * const compressions
[] =
286 { /* document-compression-supported values */
290 #endif /* HAVE_LIBZ */
292 static const char * const media_col_supported
[] =
293 { /* media-col-supported values */
294 "media-bottom-margin",
296 "media-right-margin",
302 static const char * const multiple_document_handling
[] =
303 { /* multiple-document-handling-supported values */
304 "separate-documents-uncollated-copies",
305 "separate-documents-collated-copies"
307 static const char * const notify_attrs
[] =
308 { /* notify-attributes-supported values */
309 "printer-state-change-time",
310 "notify-lease-expiration-time",
311 "notify-subscriber-user-name"
313 static const char * const notify_events
[] =
314 { /* notify-events-supported values */
316 "job-config-changed",
323 "printer-config-changed",
325 "printer-finishings-changed",
326 "printer-media-changed",
330 "printer-state-changed",
337 static const char * const job_creation
[] =
338 { /* job-creation-attributes-supported */
341 "ipp-attribute-fidelity",
348 "multiple-document-handling",
352 "orientation-requested",
355 "printer-resolution",
358 static const char * const job_settable
[] =
359 { /* job-settable-attributes-supported */
367 "multiple-document-handling",
371 "orientation-requested",
374 "printer-resolution",
377 static const char * const pdf_versions
[] =
378 { /* pdf-versions-supported */
389 static const char * const printer_settable
[] =
390 { /* printer-settable-attributes-supported */
394 static const char * const which_jobs
[] =
395 { /* which-jobs-supported values */
409 ippDelete(CommonData
);
411 CommonData
= ippNew();
414 * Get the maximum spool size based on the size of the filesystem used for
415 * the RequestRoot directory. If the host OS doesn't support the statfs call
416 * or the filesystem is larger than 2TiB, always report INT_MAX.
420 if (statvfs(RequestRoot
, &spoolinfo
))
421 k_supported
= INT_MAX
;
422 else if ((spoolsize
= (double)spoolinfo
.f_frsize
* spoolinfo
.f_blocks
/ 1024) >
424 k_supported
= INT_MAX
;
426 k_supported
= (int)spoolsize
;
428 #elif defined(HAVE_STATFS)
429 if (statfs(RequestRoot
, &spoolinfo
))
430 k_supported
= INT_MAX
;
431 else if ((spoolsize
= (double)spoolinfo
.f_bsize
* spoolinfo
.f_blocks
/ 1024) >
433 k_supported
= INT_MAX
;
435 k_supported
= (int)spoolsize
;
438 k_supported
= INT_MAX
;
439 #endif /* HAVE_STATVFS */
442 * This list of attributes is sorted to improve performance when the
443 * client provides a requested-attributes attribute...
446 /* charset-configured */
447 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_CHARSET
| IPP_TAG_COPY
,
448 "charset-configured", NULL
, "utf-8");
450 /* charset-supported */
451 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_CHARSET
| IPP_TAG_COPY
,
452 "charset-supported", sizeof(charsets
) / sizeof(charsets
[0]),
455 /* compression-supported */
456 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
457 "compression-supported",
458 sizeof(compressions
) / sizeof(compressions
[0]),
461 /* copies-supported */
462 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "copies-supported", 1, MaxCopies
);
465 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
| IPP_TAG_COPY
,
466 "cups-version", NULL
, CUPS_SVERSION
+ 6);
468 /* generated-natural-language-supported (no IPP_TAG_COPY) */
469 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_LANGUAGE
,
470 "generated-natural-language-supported", NULL
, DefaultLanguage
);
472 /* ipp-versions-supported */
473 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
474 "ipp-versions-supported", sizeof(versions
) / sizeof(versions
[0]),
477 /* ippget-event-life */
478 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
479 "ippget-event-life", 15);
481 /* job-creation-attributes-supported */
482 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
483 "job-creation-attributes-supported",
484 sizeof(job_creation
) / sizeof(job_creation
[0]),
487 /* job-hold-until-supported */
488 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
489 "job-hold-until-supported", sizeof(holds
) / sizeof(holds
[0]),
492 /* job-ids-supported */
493 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
, "job-ids-supported", 1);
495 /* job-k-octets-supported */
496 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "job-k-octets-supported", 0,
499 /* job-priority-supported */
500 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
501 "job-priority-supported", 100);
503 /* job-settable-attributes-supported */
504 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
505 "job-settable-attributes-supported",
506 sizeof(job_settable
) / sizeof(job_settable
[0]),
509 /* job-sheets-supported */
510 if (cupsArrayCount(Banners
) > 0)
513 * Setup the job-sheets-supported attribute...
516 if (Classification
&& !ClassifyOverride
)
517 attr
= ippAddString(CommonData
, IPP_TAG_PRINTER
,
518 IPP_TAG_NAME
| IPP_TAG_COPY
,
519 "job-sheets-supported", NULL
, Classification
);
521 attr
= ippAddStrings(CommonData
, IPP_TAG_PRINTER
,
522 IPP_TAG_NAME
| IPP_TAG_COPY
,
523 "job-sheets-supported", cupsArrayCount(Banners
) + 1,
527 cupsdLogMessage(CUPSD_LOG_EMERG
,
528 "Unable to allocate memory for "
529 "job-sheets-supported attribute: %s!", strerror(errno
));
530 else if (!Classification
|| ClassifyOverride
)
532 cupsd_banner_t
*banner
; /* Current banner */
535 attr
->values
[0].string
.text
= _cupsStrAlloc("none");
537 for (i
= 1, banner
= (cupsd_banner_t
*)cupsArrayFirst(Banners
);
539 i
++, banner
= (cupsd_banner_t
*)cupsArrayNext(Banners
))
540 attr
->values
[i
].string
.text
= banner
->name
;
544 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
545 "job-sheets-supported", NULL
, "none");
547 /* jpeg-k-octets-supported */
548 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "jpeg-k-octets-supported", 0,
551 /* jpeg-x-dimension-supported */
552 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "jpeg-x-dimension-supported", 0,
555 /* jpeg-y-dimension-supported */
556 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "jpeg-y-dimension-supported", 1,
559 /* media-col-supported */
560 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
561 "media-col-supported",
562 sizeof(media_col_supported
) /
563 sizeof(media_col_supported
[0]), NULL
,
564 media_col_supported
);
566 /* multiple-document-handling-supported */
567 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
568 "multiple-document-handling-supported",
569 sizeof(multiple_document_handling
) /
570 sizeof(multiple_document_handling
[0]), NULL
,
571 multiple_document_handling
);
573 /* multiple-document-jobs-supported */
574 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
,
575 "multiple-document-jobs-supported", 1);
577 /* multiple-operation-time-out */
578 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
579 "multiple-operation-time-out", MultipleOperationTimeout
);
581 /* natural-language-configured (no IPP_TAG_COPY) */
582 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_LANGUAGE
,
583 "natural-language-configured", NULL
, DefaultLanguage
);
585 /* notify-attributes-supported */
586 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
587 "notify-attributes-supported",
588 (int)(sizeof(notify_attrs
) / sizeof(notify_attrs
[0])),
591 /* notify-lease-duration-supported */
592 ippAddRange(CommonData
, IPP_TAG_PRINTER
,
593 "notify-lease-duration-supported", 0,
594 MaxLeaseDuration
? MaxLeaseDuration
: 2147483647);
596 /* notify-max-events-supported */
597 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
598 "notify-max-events-supported", MaxEvents
);
600 /* notify-events-supported */
601 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
602 "notify-events-supported",
603 (int)(sizeof(notify_events
) / sizeof(notify_events
[0])),
604 NULL
, notify_events
);
606 /* notify-pull-method-supported */
607 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
608 "notify-pull-method-supported", NULL
, "ippget");
610 /* notify-schemes-supported */
611 snprintf(filename
, sizeof(filename
), "%s/notifier", ServerBin
);
612 if ((dir
= cupsDirOpen(filename
)) != NULL
)
614 notifiers
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
616 while ((dent
= cupsDirRead(dir
)) != NULL
)
617 if (S_ISREG(dent
->fileinfo
.st_mode
) &&
618 (dent
->fileinfo
.st_mode
& S_IXOTH
) != 0)
619 cupsArrayAdd(notifiers
, _cupsStrAlloc(dent
->filename
));
621 if (cupsArrayCount(notifiers
) > 0)
623 attr
= ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
624 "notify-schemes-supported",
625 cupsArrayCount(notifiers
), NULL
, NULL
);
627 for (i
= 0, notifier
= (char *)cupsArrayFirst(notifiers
);
629 i
++, notifier
= (char *)cupsArrayNext(notifiers
))
630 attr
->values
[i
].string
.text
= notifier
;
633 cupsArrayDelete(notifiers
);
637 /* number-up-supported */
638 ippAddIntegers(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
639 "number-up-supported", sizeof(nups
) / sizeof(nups
[0]), nups
);
641 /* operations-supported */
642 ippAddIntegers(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
643 "operations-supported",
644 sizeof(ops
) / sizeof(ops
[0]) + JobFiles
- 1, ops
);
646 /* orientation-requested-supported */
647 ippAddIntegers(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
648 "orientation-requested-supported", 4, orients
);
650 /* page-ranges-supported */
651 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
, "page-ranges-supported", 1);
653 /* pdf-k-octets-supported */
654 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "pdf-k-octets-supported", 0,
657 /* pdf-versions-supported */
658 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
659 "pdf-versions-supported",
660 sizeof(pdf_versions
) / sizeof(pdf_versions
[0]), NULL
,
663 /* pdl-override-supported */
664 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
665 "pdl-override-supported", NULL
, "attempted");
667 /* printer-op-policy-supported */
668 attr
= ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
669 "printer-op-policy-supported", cupsArrayCount(Policies
),
671 for (i
= 0, p
= (cupsd_policy_t
*)cupsArrayFirst(Policies
);
673 i
++, p
= (cupsd_policy_t
*)cupsArrayNext(Policies
))
674 attr
->values
[i
].string
.text
= p
->name
;
676 /* printer-settable-attributes-supported */
677 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
678 "printer-settable-attributes-supported",
679 sizeof(printer_settable
) / sizeof(printer_settable
[0]),
680 NULL
, printer_settable
);
682 /* server-is-sharing-printers */
683 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
, "server-is-sharing-printers",
684 BrowseLocalProtocols
!= 0 && Browsing
);
686 /* which-jobs-supported */
687 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
688 "which-jobs-supported",
689 sizeof(which_jobs
) / sizeof(which_jobs
[0]), NULL
, which_jobs
);
694 * 'cupsdDeleteAllPrinters()' - Delete all printers from the system.
698 cupsdDeleteAllPrinters(void)
700 cupsd_printer_t
*p
; /* Pointer to current printer/class */
703 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
705 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
707 p
->op_policy_ptr
= DefaultPolicyPtr
;
708 cupsdDeletePrinter(p
, 0);
714 * 'cupsdDeletePrinter()' - Delete a printer from the system.
717 int /* O - 1 if classes affected, 0 otherwise */
719 cupsd_printer_t
*p
, /* I - Printer to delete */
720 int update
) /* I - Update printers.conf? */
722 int i
, /* Looping var */
723 changed
= 0; /* Class changed? */
725 char filename
[1024]; /* Interface script filename */
729 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdDeletePrinter(p=%p(%s), update=%d)",
733 * Save the current position in the Printers array...
736 cupsArraySave(Printers
);
739 * Stop printing on this printer...
742 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, update
);
744 p
->state
= IPP_PRINTER_STOPPED
; /* Force for browsed printers */
747 cupsdSetJobState(p
->job
, IPP_JOB_PENDING
, CUPSD_JOB_FORCE
,
748 update
? "Job stopped due to printer being deleted." :
752 * Remove the printer from the list...
755 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
756 "cupsdDeletePrinter: Removing %s from Printers", p
->name
);
757 cupsArrayRemove(Printers
, p
);
760 * Remove the dummy interface/icon/option files under IRIX...
764 snprintf(filename
, sizeof(filename
), "/var/spool/lp/interface/%s", p
->name
);
767 snprintf(filename
, sizeof(filename
), "/var/spool/lp/gui_interface/ELF/%s.gui",
771 snprintf(filename
, sizeof(filename
), "/var/spool/lp/activeicons/%s", p
->name
);
774 snprintf(filename
, sizeof(filename
), "/var/spool/lp/pod/%s.config", p
->name
);
777 snprintf(filename
, sizeof(filename
), "/var/spool/lp/pod/%s.status", p
->name
);
780 snprintf(filename
, sizeof(filename
), "/var/spool/lp/member/%s", p
->name
);
785 * If p is the default printer, assign a different one...
788 if (p
== DefaultPrinter
)
789 DefaultPrinter
= NULL
;
792 * Remove this printer from any classes...
795 changed
= cupsdDeletePrinterFromClasses(p
);
798 * Deregister from any browse protocols...
801 cupsdDeregisterPrinter(p
, 1);
804 * Free all memory used by the printer...
807 if (p
->printers
!= NULL
)
810 delete_printer_filters(p
);
812 for (i
= 0; i
< p
->num_reasons
; i
++)
813 _cupsStrFree(p
->reasons
[i
]);
816 ippDelete(p
->ppd_attrs
);
818 mimeDeleteType(MimeDatabase
, p
->filetype
);
819 mimeDeleteType(MimeDatabase
, p
->prefiltertype
);
821 cupsdFreeStrings(&(p
->users
));
824 cupsdClearString(&p
->uri
);
825 cupsdClearString(&p
->hostname
);
826 cupsdClearString(&p
->name
);
827 cupsdClearString(&p
->location
);
828 cupsdClearString(&p
->make_model
);
829 cupsdClearString(&p
->info
);
830 cupsdClearString(&p
->job_sheets
[0]);
831 cupsdClearString(&p
->job_sheets
[1]);
832 cupsdClearString(&p
->device_uri
);
833 cupsdClearString(&p
->sanitized_device_uri
);
834 cupsdClearString(&p
->port_monitor
);
835 cupsdClearString(&p
->op_policy
);
836 cupsdClearString(&p
->error_policy
);
838 cupsdClearString(&p
->alert
);
839 cupsdClearString(&p
->alert_description
);
842 cupsdClearString(&p
->pdl
);
843 #endif /* HAVE_DNSSD */
845 cupsArrayDelete(p
->filetypes
);
847 cupsFreeOptions(p
->num_options
, p
->options
);
852 * Restore the previous position in the Printers array...
855 cupsArrayRestore(Printers
);
862 * 'cupsdFindDest()' - Find a destination in the list.
865 cupsd_printer_t
* /* O - Destination in list */
866 cupsdFindDest(const char *name
) /* I - Name of printer or class to find */
868 cupsd_printer_t key
; /* Search key */
871 key
.name
= (char *)name
;
872 return ((cupsd_printer_t
*)cupsArrayFind(Printers
, &key
));
877 * 'cupsdFindPrinter()' - Find a printer in the list.
880 cupsd_printer_t
* /* O - Printer in list */
881 cupsdFindPrinter(const char *name
) /* I - Name of printer to find */
883 cupsd_printer_t
*p
; /* Printer in list */
886 if ((p
= cupsdFindDest(name
)) != NULL
&& (p
->type
& CUPS_PRINTER_CLASS
))
894 * 'cupsdLoadAllPrinters()' - Load printers from the printers.conf file.
898 cupsdLoadAllPrinters(void)
900 int i
; /* Looping var */
901 cups_file_t
*fp
; /* printers.conf file */
902 int linenum
; /* Current line number */
903 char line
[4096], /* Line from file */
904 *value
, /* Pointer to value */
905 *valueptr
; /* Pointer into value */
906 cupsd_printer_t
*p
; /* Current printer */
910 * Open the printers.conf file...
913 snprintf(line
, sizeof(line
), "%s/printers.conf", ServerRoot
);
914 if ((fp
= cupsdOpenConfFile(line
)) == NULL
)
918 * Read printer configurations until we hit EOF...
924 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
927 * Decode the directive...
930 if (!_cups_strcasecmp(line
, "<Printer") ||
931 !_cups_strcasecmp(line
, "<DefaultPrinter"))
934 * <Printer name> or <DefaultPrinter name>
937 if (p
== NULL
&& value
)
940 * Add the printer and a base file type...
943 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Loading printer %s...", value
);
945 p
= cupsdAddPrinter(value
);
947 p
->state
= IPP_PRINTER_IDLE
;
950 * Set the default printer as needed...
953 if (!_cups_strcasecmp(line
, "<DefaultPrinter"))
957 cupsdLogMessage(CUPSD_LOG_ERROR
,
958 "Syntax error on line %d of printers.conf.", linenum
);
960 else if (!_cups_strcasecmp(line
, "</Printer>"))
965 * Close out the current printer...
968 cupsdSetPrinterAttrs(p
);
970 if (strncmp(p
->device_uri
, "file:", 5) &&
971 p
->state
!= IPP_PRINTER_STOPPED
)
974 * See if the backend exists...
977 snprintf(line
, sizeof(line
), "%s/backend/%s", ServerBin
,
980 if ((valueptr
= strchr(line
+ strlen(ServerBin
), ':')) != NULL
)
981 *valueptr
= '\0'; /* Chop everything but URI scheme */
986 * Backend does not exist, stop printer...
989 p
->state
= IPP_PRINTER_STOPPED
;
990 snprintf(p
->state_message
, sizeof(p
->state_message
),
991 "Backend %s does not exist!", line
);
998 cupsdLogMessage(CUPSD_LOG_ERROR
,
999 "Syntax error on line %d of printers.conf.", linenum
);
1003 cupsdLogMessage(CUPSD_LOG_ERROR
,
1004 "Syntax error on line %d of printers.conf.", linenum
);
1006 else if (!_cups_strcasecmp(line
, "UUID"))
1008 if (value
&& !strncmp(value
, "urn:uuid:", 9))
1009 cupsdSetString(&(p
->uuid
), value
);
1011 cupsdLogMessage(CUPSD_LOG_ERROR
,
1012 "Bad UUID on line %d of printers.conf.", linenum
);
1014 else if (!_cups_strcasecmp(line
, "AuthInfoRequired"))
1016 if (!cupsdSetAuthInfoRequired(p
, value
, NULL
))
1017 cupsdLogMessage(CUPSD_LOG_ERROR
,
1018 "Bad AuthInfoRequired on line %d of printers.conf.",
1021 else if (!_cups_strcasecmp(line
, "Info"))
1024 cupsdSetString(&p
->info
, value
);
1026 else if (!_cups_strcasecmp(line
, "MakeModel"))
1029 cupsdSetString(&p
->make_model
, value
);
1031 else if (!_cups_strcasecmp(line
, "Location"))
1034 cupsdSetString(&p
->location
, value
);
1036 else if (!_cups_strcasecmp(line
, "DeviceURI"))
1039 cupsdSetDeviceURI(p
, value
);
1041 cupsdLogMessage(CUPSD_LOG_ERROR
,
1042 "Syntax error on line %d of printers.conf.", linenum
);
1044 else if (!_cups_strcasecmp(line
, "Option") && value
)
1050 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1053 cupsdLogMessage(CUPSD_LOG_ERROR
,
1054 "Syntax error on line %d of printers.conf.", linenum
);
1057 for (; *valueptr
&& isspace(*valueptr
& 255); *valueptr
++ = '\0');
1059 p
->num_options
= cupsAddOption(value
, valueptr
, p
->num_options
,
1063 else if (!_cups_strcasecmp(line
, "PortMonitor"))
1065 if (value
&& strcmp(value
, "none"))
1066 cupsdSetString(&p
->port_monitor
, value
);
1068 cupsdClearString(&p
->port_monitor
);
1070 cupsdLogMessage(CUPSD_LOG_ERROR
,
1071 "Syntax error on line %d of printers.conf.", linenum
);
1073 else if (!_cups_strcasecmp(line
, "Reason"))
1076 strcmp(value
, "connecting-to-device") &&
1077 strcmp(value
, "cups-insecure-filter-warning") &&
1078 strcmp(value
, "cups-missing-filter-warning"))
1080 for (i
= 0 ; i
< p
->num_reasons
; i
++)
1081 if (!strcmp(value
, p
->reasons
[i
]))
1084 if (i
>= p
->num_reasons
&&
1085 p
->num_reasons
< (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
1087 p
->reasons
[p
->num_reasons
] = _cupsStrAlloc(value
);
1092 cupsdLogMessage(CUPSD_LOG_ERROR
,
1093 "Syntax error on line %d of printers.conf.", linenum
);
1095 else if (!_cups_strcasecmp(line
, "State"))
1098 * Set the initial queue state...
1101 if (value
&& !_cups_strcasecmp(value
, "idle"))
1102 p
->state
= IPP_PRINTER_IDLE
;
1103 else if (value
&& !_cups_strcasecmp(value
, "stopped"))
1105 p
->state
= IPP_PRINTER_STOPPED
;
1107 for (i
= 0 ; i
< p
->num_reasons
; i
++)
1108 if (!strcmp("paused", p
->reasons
[i
]))
1111 if (i
>= p
->num_reasons
&&
1112 p
->num_reasons
< (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
1114 p
->reasons
[p
->num_reasons
] = _cupsStrAlloc("paused");
1119 cupsdLogMessage(CUPSD_LOG_ERROR
,
1120 "Syntax error on line %d of printers.conf.", linenum
);
1122 else if (!_cups_strcasecmp(line
, "StateMessage"))
1125 * Set the initial queue state message...
1129 strlcpy(p
->state_message
, value
, sizeof(p
->state_message
));
1131 else if (!_cups_strcasecmp(line
, "StateTime"))
1134 * Set the state time...
1138 p
->state_time
= atoi(value
);
1140 else if (!_cups_strcasecmp(line
, "Accepting"))
1143 * Set the initial accepting state...
1147 (!_cups_strcasecmp(value
, "yes") ||
1148 !_cups_strcasecmp(value
, "on") ||
1149 !_cups_strcasecmp(value
, "true")))
1152 (!_cups_strcasecmp(value
, "no") ||
1153 !_cups_strcasecmp(value
, "off") ||
1154 !_cups_strcasecmp(value
, "false")))
1157 cupsdLogMessage(CUPSD_LOG_ERROR
,
1158 "Syntax error on line %d of printers.conf.", linenum
);
1160 else if (!_cups_strcasecmp(line
, "Type"))
1163 p
->type
= atoi(value
);
1165 cupsdLogMessage(CUPSD_LOG_ERROR
,
1166 "Syntax error on line %d of printers.conf.", linenum
);
1168 else if (!_cups_strcasecmp(line
, "Shared"))
1171 * Set the initial shared state...
1175 (!_cups_strcasecmp(value
, "yes") ||
1176 !_cups_strcasecmp(value
, "on") ||
1177 !_cups_strcasecmp(value
, "true")))
1180 (!_cups_strcasecmp(value
, "no") ||
1181 !_cups_strcasecmp(value
, "off") ||
1182 !_cups_strcasecmp(value
, "false")))
1185 cupsdLogMessage(CUPSD_LOG_ERROR
,
1186 "Syntax error on line %d of printers.conf.", linenum
);
1188 else if (!_cups_strcasecmp(line
, "JobSheets"))
1191 * Set the initial job sheets...
1196 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1201 cupsdSetString(&p
->job_sheets
[0], value
);
1203 while (isspace(*valueptr
& 255))
1208 for (value
= valueptr
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1213 cupsdSetString(&p
->job_sheets
[1], value
);
1217 cupsdLogMessage(CUPSD_LOG_ERROR
,
1218 "Syntax error on line %d of printers.conf.", linenum
);
1220 else if (!_cups_strcasecmp(line
, "AllowUser"))
1225 cupsdAddString(&(p
->users
), value
);
1228 cupsdLogMessage(CUPSD_LOG_ERROR
,
1229 "Syntax error on line %d of printers.conf.", linenum
);
1231 else if (!_cups_strcasecmp(line
, "DenyUser"))
1236 cupsdAddString(&(p
->users
), value
);
1239 cupsdLogMessage(CUPSD_LOG_ERROR
,
1240 "Syntax error on line %d of printers.conf.", linenum
);
1242 else if (!_cups_strcasecmp(line
, "QuotaPeriod"))
1245 p
->quota_period
= atoi(value
);
1247 cupsdLogMessage(CUPSD_LOG_ERROR
,
1248 "Syntax error on line %d of printers.conf.", linenum
);
1250 else if (!_cups_strcasecmp(line
, "PageLimit"))
1253 p
->page_limit
= atoi(value
);
1255 cupsdLogMessage(CUPSD_LOG_ERROR
,
1256 "Syntax error on line %d of printers.conf.", linenum
);
1258 else if (!_cups_strcasecmp(line
, "KLimit"))
1261 p
->k_limit
= atoi(value
);
1263 cupsdLogMessage(CUPSD_LOG_ERROR
,
1264 "Syntax error on line %d of printers.conf.", linenum
);
1266 else if (!_cups_strcasecmp(line
, "OpPolicy"))
1270 cupsd_policy_t
*pol
; /* Policy */
1273 if ((pol
= cupsdFindPolicy(value
)) != NULL
)
1275 cupsdSetString(&p
->op_policy
, value
);
1276 p
->op_policy_ptr
= pol
;
1279 cupsdLogMessage(CUPSD_LOG_ERROR
,
1280 "Bad policy \"%s\" on line %d of printers.conf",
1284 cupsdLogMessage(CUPSD_LOG_ERROR
,
1285 "Syntax error on line %d of printers.conf.", linenum
);
1287 else if (!_cups_strcasecmp(line
, "ErrorPolicy"))
1290 cupsdSetString(&p
->error_policy
, value
);
1292 cupsdLogMessage(CUPSD_LOG_ERROR
,
1293 "Syntax error on line %d of printers.conf.", linenum
);
1295 else if (!_cups_strcasecmp(line
, "Attribute") && value
)
1297 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1300 cupsdLogMessage(CUPSD_LOG_ERROR
,
1301 "Syntax error on line %d of printers.conf.", linenum
);
1304 for (; *valueptr
&& isspace(*valueptr
& 255); *valueptr
++ = '\0');
1307 cupsdSetPrinterAttrs(p
);
1309 if (!strcmp(value
, "marker-change-time"))
1310 p
->marker_time
= atoi(valueptr
);
1312 cupsdSetPrinterAttr(p
, value
, valueptr
);
1315 else if (_cups_strcasecmp(line
, "Filter") &&
1316 _cups_strcasecmp(line
, "Prefilter") &&
1317 _cups_strcasecmp(line
, "Product"))
1320 * Something else we don't understand (and that wasn't used in a prior
1321 * release of CUPS...
1324 cupsdLogMessage(CUPSD_LOG_ERROR
,
1325 "Unknown configuration directive %s on line %d of "
1326 "printers.conf.", line
, linenum
);
1335 * 'cupsdRenamePrinter()' - Rename a printer.
1340 cupsd_printer_t
*p
, /* I - Printer */
1341 const char *name
) /* I - New name */
1344 * Remove the printer from the array(s) first...
1347 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1348 "cupsdRenamePrinter: Removing %s from Printers", p
->name
);
1349 cupsArrayRemove(Printers
, p
);
1352 * Rename the printer type...
1355 mimeDeleteType(MimeDatabase
, p
->filetype
);
1356 p
->filetype
= mimeAddType(MimeDatabase
, "printer", name
);
1358 if (p
->prefiltertype
)
1360 mimeDeleteType(MimeDatabase
, p
->prefiltertype
);
1361 p
->prefiltertype
= mimeAddType(MimeDatabase
, "prefilter", name
);
1365 * Rename the printer...
1368 cupsdSetString(&p
->name
, name
);
1371 * Reset printer attributes...
1374 cupsdSetPrinterAttrs(p
);
1377 * Add the printer back to the printer array(s)...
1380 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1381 "cupsdRenamePrinter: Adding %s to Printers", p
->name
);
1382 cupsArrayAdd(Printers
, p
);
1387 * 'cupsdSaveAllPrinters()' - Save all printer definitions to the printers.conf
1392 cupsdSaveAllPrinters(void)
1394 int i
; /* Looping var */
1395 cups_file_t
*fp
; /* printers.conf file */
1396 char filename
[1024], /* printers.conf filename */
1397 temp
[1024], /* Temporary string */
1398 value
[2048], /* Value string */
1399 *ptr
, /* Pointer into value */
1400 *name
; /* Current user/group name */
1401 cupsd_printer_t
*printer
; /* Current printer class */
1402 time_t curtime
; /* Current time */
1403 struct tm
*curdate
; /* Current date */
1404 cups_option_t
*option
; /* Current option */
1405 ipp_attribute_t
*marker
; /* Current marker attribute */
1409 * Create the printers.conf file...
1412 snprintf(filename
, sizeof(filename
), "%s/printers.conf", ServerRoot
);
1414 if ((fp
= cupsdCreateConfFile(filename
, ConfigFilePerm
& 0600)) == NULL
)
1417 cupsdLogMessage(CUPSD_LOG_INFO
, "Saving printers.conf...");
1420 * Write a small header to the file...
1423 curtime
= time(NULL
);
1424 curdate
= localtime(&curtime
);
1425 strftime(temp
, sizeof(temp
) - 1, "%Y-%m-%d %H:%M", curdate
);
1427 cupsFilePuts(fp
, "# Printer configuration file for " CUPS_SVERSION
"\n");
1428 cupsFilePrintf(fp
, "# Written by cupsd on %s\n", temp
);
1429 cupsFilePuts(fp
, "# DO NOT EDIT THIS FILE WHEN CUPSD IS RUNNING\n");
1432 * Write each local printer known to the system...
1435 for (printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
1437 printer
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
1440 * Skip printer classes...
1443 if (printer
->type
& CUPS_PRINTER_CLASS
)
1447 * Write printers as needed...
1450 if (printer
== DefaultPrinter
)
1451 cupsFilePrintf(fp
, "<DefaultPrinter %s>\n", printer
->name
);
1453 cupsFilePrintf(fp
, "<Printer %s>\n", printer
->name
);
1455 cupsFilePrintf(fp
, "UUID %s\n", printer
->uuid
);
1457 if (printer
->num_auth_info_required
> 0)
1459 switch (printer
->num_auth_info_required
)
1462 strlcpy(value
, printer
->auth_info_required
[0], sizeof(value
));
1466 snprintf(value
, sizeof(value
), "%s,%s",
1467 printer
->auth_info_required
[0],
1468 printer
->auth_info_required
[1]);
1473 snprintf(value
, sizeof(value
), "%s,%s,%s",
1474 printer
->auth_info_required
[0],
1475 printer
->auth_info_required
[1],
1476 printer
->auth_info_required
[2]);
1480 cupsFilePutConf(fp
, "AuthInfoRequired", value
);
1484 cupsFilePutConf(fp
, "Info", printer
->info
);
1486 if (printer
->location
)
1487 cupsFilePutConf(fp
, "Location", printer
->location
);
1489 if (printer
->make_model
)
1490 cupsFilePutConf(fp
, "MakeModel", printer
->make_model
);
1492 cupsFilePutConf(fp
, "DeviceURI", printer
->device_uri
);
1494 if (printer
->port_monitor
)
1495 cupsFilePutConf(fp
, "PortMonitor", printer
->port_monitor
);
1497 if (printer
->state
== IPP_PRINTER_STOPPED
)
1499 cupsFilePuts(fp
, "State Stopped\n");
1501 if (printer
->state_message
)
1502 cupsFilePutConf(fp
, "StateMessage", printer
->state_message
);
1505 cupsFilePuts(fp
, "State Idle\n");
1507 cupsFilePrintf(fp
, "StateTime %d\n", (int)printer
->state_time
);
1509 for (i
= 0; i
< printer
->num_reasons
; i
++)
1510 if (strcmp(printer
->reasons
[i
], "connecting-to-device") &&
1511 strcmp(printer
->reasons
[i
], "cups-insecure-filter-warning") &&
1512 strcmp(printer
->reasons
[i
], "cups-missing-filter-warning"))
1513 cupsFilePutConf(fp
, "Reason", printer
->reasons
[i
]);
1515 cupsFilePrintf(fp
, "Type %d\n", printer
->type
);
1517 if (printer
->accepting
)
1518 cupsFilePuts(fp
, "Accepting Yes\n");
1520 cupsFilePuts(fp
, "Accepting No\n");
1522 if (printer
->shared
)
1523 cupsFilePuts(fp
, "Shared Yes\n");
1525 cupsFilePuts(fp
, "Shared No\n");
1527 snprintf(value
, sizeof(value
), "%s %s", printer
->job_sheets
[0],
1528 printer
->job_sheets
[1]);
1529 cupsFilePutConf(fp
, "JobSheets", value
);
1531 cupsFilePrintf(fp
, "QuotaPeriod %d\n", printer
->quota_period
);
1532 cupsFilePrintf(fp
, "PageLimit %d\n", printer
->page_limit
);
1533 cupsFilePrintf(fp
, "KLimit %d\n", printer
->k_limit
);
1535 for (name
= (char *)cupsArrayFirst(printer
->users
);
1537 name
= (char *)cupsArrayNext(printer
->users
))
1538 cupsFilePutConf(fp
, printer
->deny_users
? "DenyUser" : "AllowUser", name
);
1540 if (printer
->op_policy
)
1541 cupsFilePutConf(fp
, "OpPolicy", printer
->op_policy
);
1542 if (printer
->error_policy
)
1543 cupsFilePutConf(fp
, "ErrorPolicy", printer
->error_policy
);
1545 for (i
= printer
->num_options
, option
= printer
->options
;
1549 snprintf(value
, sizeof(value
), "%s %s", option
->name
, option
->value
);
1550 cupsFilePutConf(fp
, "Option", value
);
1553 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-colors",
1554 IPP_TAG_NAME
)) != NULL
)
1556 snprintf(value
, sizeof(value
), "%s ", marker
->name
);
1558 for (i
= 0, ptr
= value
+ strlen(value
);
1559 i
< marker
->num_values
&& ptr
< (value
+ sizeof(value
) - 1);
1565 strlcpy(ptr
, marker
->values
[i
].string
.text
,
1566 value
+ sizeof(value
) - ptr
);
1571 cupsFilePutConf(fp
, "Attribute", value
);
1574 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-levels",
1575 IPP_TAG_INTEGER
)) != NULL
)
1577 cupsFilePrintf(fp
, "Attribute %s %d", marker
->name
,
1578 marker
->values
[0].integer
);
1579 for (i
= 1; i
< marker
->num_values
; i
++)
1580 cupsFilePrintf(fp
, ",%d", marker
->values
[i
].integer
);
1581 cupsFilePuts(fp
, "\n");
1584 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-low-levels",
1585 IPP_TAG_INTEGER
)) != NULL
)
1587 cupsFilePrintf(fp
, "Attribute %s %d", marker
->name
,
1588 marker
->values
[0].integer
);
1589 for (i
= 1; i
< marker
->num_values
; i
++)
1590 cupsFilePrintf(fp
, ",%d", marker
->values
[i
].integer
);
1591 cupsFilePuts(fp
, "\n");
1594 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-high-levels",
1595 IPP_TAG_INTEGER
)) != NULL
)
1597 cupsFilePrintf(fp
, "Attribute %s %d", marker
->name
,
1598 marker
->values
[0].integer
);
1599 for (i
= 1; i
< marker
->num_values
; i
++)
1600 cupsFilePrintf(fp
, ",%d", marker
->values
[i
].integer
);
1601 cupsFilePuts(fp
, "\n");
1604 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-message",
1605 IPP_TAG_TEXT
)) != NULL
)
1607 snprintf(value
, sizeof(value
), "%s %s", marker
->name
,
1608 marker
->values
[0].string
.text
);
1610 cupsFilePutConf(fp
, "Attribute", value
);
1613 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-names",
1614 IPP_TAG_NAME
)) != NULL
)
1616 snprintf(value
, sizeof(value
), "%s ", marker
->name
);
1618 for (i
= 0, ptr
= value
+ strlen(value
);
1619 i
< marker
->num_values
&& ptr
< (value
+ sizeof(value
) - 1);
1625 strlcpy(ptr
, marker
->values
[i
].string
.text
,
1626 value
+ sizeof(value
) - ptr
);
1631 cupsFilePutConf(fp
, "Attribute", value
);
1634 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-types",
1635 IPP_TAG_KEYWORD
)) != NULL
)
1637 snprintf(value
, sizeof(value
), "%s ", marker
->name
);
1639 for (i
= 0, ptr
= value
+ strlen(value
);
1640 i
< marker
->num_values
&& ptr
< (value
+ sizeof(value
) - 1);
1646 strlcpy(ptr
, marker
->values
[i
].string
.text
,
1647 value
+ sizeof(value
) - ptr
);
1652 cupsFilePutConf(fp
, "Attribute", value
);
1655 if (printer
->marker_time
)
1656 cupsFilePrintf(fp
, "Attribute marker-change-time %ld\n",
1657 (long)printer
->marker_time
);
1659 cupsFilePuts(fp
, "</Printer>\n");
1663 * Make IRIX desktop & printer status happy
1666 write_irix_state(printer
);
1670 cupsdCloseCreatedConfFile(fp
, filename
);
1675 * 'cupsdSetAuthInfoRequired()' - Set the required authentication info.
1678 int /* O - 1 if value OK, 0 otherwise */
1679 cupsdSetAuthInfoRequired(
1680 cupsd_printer_t
*p
, /* I - Printer */
1681 const char *values
, /* I - Plain text value (or NULL) */
1682 ipp_attribute_t
*attr
) /* I - IPP attribute value (or NULL) */
1684 int i
; /* Looping var */
1687 p
->num_auth_info_required
= 0;
1690 * Do we have a plain text value?
1696 * Yes, grab the keywords...
1699 const char *end
; /* End of current value */
1702 while (*values
&& p
->num_auth_info_required
< 4)
1704 if ((end
= strchr(values
, ',')) == NULL
)
1705 end
= values
+ strlen(values
);
1707 if ((end
- values
) == 4 && !strncmp(values
, "none", 4))
1709 if (p
->num_auth_info_required
!= 0 || *end
)
1712 p
->auth_info_required
[p
->num_auth_info_required
] = "none";
1713 p
->num_auth_info_required
++;
1717 else if ((end
- values
) == 9 && !strncmp(values
, "negotiate", 9))
1719 if (p
->num_auth_info_required
!= 0 || *end
)
1722 p
->auth_info_required
[p
->num_auth_info_required
] = "negotiate";
1723 p
->num_auth_info_required
++;
1726 * Don't allow sharing of queues that require Kerberos authentication.
1731 cupsdDeregisterPrinter(p
, 1);
1735 else if ((end
- values
) == 6 && !strncmp(values
, "domain", 6))
1737 p
->auth_info_required
[p
->num_auth_info_required
] = "domain";
1738 p
->num_auth_info_required
++;
1740 else if ((end
- values
) == 8 && !strncmp(values
, "password", 8))
1742 p
->auth_info_required
[p
->num_auth_info_required
] = "password";
1743 p
->num_auth_info_required
++;
1745 else if ((end
- values
) == 8 && !strncmp(values
, "username", 8))
1747 p
->auth_info_required
[p
->num_auth_info_required
] = "username";
1748 p
->num_auth_info_required
++;
1753 values
= (*end
) ? end
+ 1 : end
;
1756 if (p
->num_auth_info_required
== 0)
1758 p
->auth_info_required
[0] = "none";
1759 p
->num_auth_info_required
= 1;
1763 * Update the printer-type value as needed...
1766 if (p
->num_auth_info_required
> 1 ||
1767 strcmp(p
->auth_info_required
[0], "none"))
1768 p
->type
|= CUPS_PRINTER_AUTHENTICATED
;
1770 p
->type
&= ~CUPS_PRINTER_AUTHENTICATED
;
1776 * Grab values from an attribute instead...
1779 if (!attr
|| attr
->num_values
> 4)
1782 for (i
= 0; i
< attr
->num_values
; i
++)
1784 if (!strcmp(attr
->values
[i
].string
.text
, "none"))
1786 if (p
->num_auth_info_required
!= 0 || attr
->num_values
!= 1)
1789 p
->auth_info_required
[p
->num_auth_info_required
] = "none";
1790 p
->num_auth_info_required
++;
1794 else if (!strcmp(attr
->values
[i
].string
.text
, "negotiate"))
1796 if (p
->num_auth_info_required
!= 0 || attr
->num_values
!= 1)
1799 p
->auth_info_required
[p
->num_auth_info_required
] = "negotiate";
1800 p
->num_auth_info_required
++;
1803 * Don't allow sharing of queues that require Kerberos authentication.
1808 cupsdDeregisterPrinter(p
, 1);
1814 else if (!strcmp(attr
->values
[i
].string
.text
, "domain"))
1816 p
->auth_info_required
[p
->num_auth_info_required
] = "domain";
1817 p
->num_auth_info_required
++;
1819 else if (!strcmp(attr
->values
[i
].string
.text
, "password"))
1821 p
->auth_info_required
[p
->num_auth_info_required
] = "password";
1822 p
->num_auth_info_required
++;
1824 else if (!strcmp(attr
->values
[i
].string
.text
, "username"))
1826 p
->auth_info_required
[p
->num_auth_info_required
] = "username";
1827 p
->num_auth_info_required
++;
1838 * 'cupsdSetDeviceURI()' - Set the device URI for a printer.
1842 cupsdSetDeviceURI(cupsd_printer_t
*p
, /* I - Printer */
1843 const char *uri
) /* I - Device URI */
1845 char buffer
[1024], /* URI buffer */
1846 *start
, /* Start of data after scheme */
1847 *slash
, /* First slash after scheme:// */
1848 *ptr
; /* Pointer into user@host:port part */
1852 * Set the full device URI..
1855 cupsdSetString(&(p
->device_uri
), uri
);
1858 * Copy the device URI to a temporary buffer so we can sanitize any auth
1862 strlcpy(buffer
, uri
, sizeof(buffer
));
1865 * Find the end of the scheme:// part...
1868 if ((ptr
= strchr(buffer
, ':')) != NULL
)
1870 for (start
= ptr
+ 1; *start
; start
++)
1875 * Find the next slash (/) in the URI...
1878 if ((slash
= strchr(start
, '/')) == NULL
)
1879 slash
= start
+ strlen(start
); /* No slash, point to the end */
1882 * Check for an @ sign before the slash...
1885 if ((ptr
= strchr(start
, '@')) != NULL
&& ptr
< slash
)
1888 * Found an @ sign and it is before the resource part, so we have
1889 * an authentication string. Copy the remaining URI over the
1890 * authentication string...
1893 _cups_strcpy(start
, ptr
+ 1);
1898 * Save the sanitized URI...
1901 cupsdSetString(&(p
->sanitized_device_uri
), buffer
);
1906 * 'cupsdSetPrinterAttr()' - Set a printer attribute.
1910 cupsdSetPrinterAttr(
1911 cupsd_printer_t
*p
, /* I - Printer */
1912 const char *name
, /* I - Attribute name */
1913 char *value
) /* I - Attribute value string */
1915 ipp_attribute_t
*attr
; /* Attribute */
1916 int i
, /* Looping var */
1917 count
; /* Number of values */
1918 char *ptr
; /* Pointer into value */
1919 ipp_tag_t value_tag
; /* Value tag for this attribute */
1923 * Don't allow empty values...
1926 if (!*value
&& strcmp(name
, "marker-message"))
1928 cupsdLogMessage(CUPSD_LOG_ERROR
, "Ignoring empty \"%s\" attribute", name
);
1933 * Count the number of values...
1936 for (count
= 1, ptr
= value
;
1937 (ptr
= strchr(ptr
, ',')) != NULL
;
1941 * Then add or update the attribute as needed...
1944 if (!strcmp(name
, "marker-levels") || !strcmp(name
, "marker-low-levels") ||
1945 !strcmp(name
, "marker-high-levels"))
1951 if ((attr
= ippFindAttribute(p
->attrs
, name
, IPP_TAG_INTEGER
)) != NULL
&&
1952 attr
->num_values
< count
)
1954 ippDeleteAttribute(p
->attrs
, attr
);
1959 attr
->num_values
= count
;
1961 attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
, name
,
1966 cupsdLogMessage(CUPSD_LOG_ERROR
,
1967 "Unable to allocate memory for printer attribute "
1968 "(%d values)", count
);
1972 for (i
= 0; i
< count
; i
++)
1974 if ((ptr
= strchr(value
, ',')) != NULL
)
1977 attr
->values
[i
].integer
= strtol(value
, NULL
, 10);
1986 * Name or keyword values...
1989 if (!strcmp(name
, "marker-types"))
1990 value_tag
= IPP_TAG_KEYWORD
;
1991 else if (!strcmp(name
, "marker-message"))
1992 value_tag
= IPP_TAG_TEXT
;
1994 value_tag
= IPP_TAG_NAME
;
1996 if ((attr
= ippFindAttribute(p
->attrs
, name
, value_tag
)) != NULL
&&
1997 attr
->num_values
< count
)
1999 ippDeleteAttribute(p
->attrs
, attr
);
2005 for (i
= 0; i
< attr
->num_values
; i
++)
2006 _cupsStrFree(attr
->values
[i
].string
.text
);
2008 attr
->num_values
= count
;
2011 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, value_tag
, name
,
2016 cupsdLogMessage(CUPSD_LOG_ERROR
,
2017 "Unable to allocate memory for printer attribute "
2018 "(%d values)", count
);
2022 for (i
= 0; i
< count
; i
++)
2024 if ((ptr
= strchr(value
, ',')) != NULL
)
2027 attr
->values
[i
].string
.text
= _cupsStrAlloc(value
);
2037 * 'cupsdSetPrinterAttrs()' - Set printer attributes based upon the PPD file.
2041 cupsdSetPrinterAttrs(cupsd_printer_t
*p
)/* I - Printer to setup */
2043 int i
; /* Looping var */
2044 char resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
2045 int num_air
; /* Number of auth-info-required values */
2046 const char * const *air
; /* auth-info-required values */
2047 cupsd_location_t
*auth
; /* Pointer to authentication element */
2048 const char *auth_supported
; /* Authentication supported */
2049 ipp_t
*oldattrs
; /* Old printer attributes */
2050 ipp_attribute_t
*attr
; /* Attribute data */
2051 char *name
, /* Current user/group name */
2052 *filter
; /* Current filter */
2053 static const char * const air_none
[] =
2054 { /* No authentication */
2057 static const char * const air_userpass
[] =
2058 { /* Basic/Digest authentication */
2064 DEBUG_printf(("cupsdSetPrinterAttrs: entering name = %s, type = %x\n", p
->name
,
2068 * Make sure that we have the common attributes defined...
2072 cupsdCreateCommonData();
2075 * Clear out old filters, if any...
2078 delete_printer_filters(p
);
2081 * Figure out the authentication that is required for the printer.
2084 auth_supported
= "requesting-user-name";
2088 if (p
->num_auth_info_required
> 0 && strcmp(p
->auth_info_required
[0], "none"))
2090 num_air
= p
->num_auth_info_required
;
2091 air
= p
->auth_info_required
;
2093 else if (p
->type
& CUPS_PRINTER_AUTHENTICATED
)
2099 if (p
->type
& CUPS_PRINTER_CLASS
)
2100 snprintf(resource
, sizeof(resource
), "/classes/%s", p
->name
);
2102 snprintf(resource
, sizeof(resource
), "/printers/%s", p
->name
);
2104 if ((auth
= cupsdFindBest(resource
, HTTP_POST
)) == NULL
||
2105 auth
->type
== CUPSD_AUTH_NONE
)
2106 auth
= cupsdFindPolicyOp(p
->op_policy_ptr
, IPP_PRINT_JOB
);
2110 int auth_type
; /* Authentication type */
2113 if ((auth_type
= auth
->type
) == CUPSD_AUTH_DEFAULT
)
2114 auth_type
= DefaultAuthType
;
2116 if (auth_type
== CUPSD_AUTH_BASIC
|| auth_type
== CUPSD_AUTH_BASICDIGEST
)
2117 auth_supported
= "basic";
2118 else if (auth_type
== CUPSD_AUTH_DIGEST
)
2119 auth_supported
= "digest";
2121 else if (auth_type
== CUPSD_AUTH_NEGOTIATE
)
2122 auth_supported
= "negotiate";
2123 #endif /* HAVE_GSSAPI */
2125 if (auth_type
!= CUPSD_AUTH_NONE
)
2126 p
->type
|= CUPS_PRINTER_AUTHENTICATED
;
2128 p
->type
&= ~CUPS_PRINTER_AUTHENTICATED
;
2131 p
->type
&= ~CUPS_PRINTER_AUTHENTICATED
;
2134 * Create the required IPP attributes for a printer...
2137 oldattrs
= p
->attrs
;
2138 p
->attrs
= ippNew();
2140 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2141 "uri-authentication-supported", NULL
, auth_supported
);
2142 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2143 "uri-security-supported", NULL
, "none");
2144 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
, "printer-name", NULL
,
2146 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-location",
2147 NULL
, p
->location
? p
->location
: "");
2148 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-info",
2149 NULL
, p
->info
? p
->info
: "");
2150 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "printer-uuid", NULL
,
2153 if (cupsArrayCount(p
->users
) > 0)
2156 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2157 "requesting-user-name-denied",
2158 cupsArrayCount(p
->users
), NULL
, NULL
);
2160 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2161 "requesting-user-name-allowed",
2162 cupsArrayCount(p
->users
), NULL
, NULL
);
2164 for (i
= 0, name
= (char *)cupsArrayFirst(p
->users
);
2166 i
++, name
= (char *)cupsArrayNext(p
->users
))
2167 attr
->values
[i
].string
.text
= _cupsStrRetain(name
);
2170 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2171 "job-quota-period", p
->quota_period
);
2172 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2173 "job-k-limit", p
->k_limit
);
2174 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2175 "job-page-limit", p
->page_limit
);
2176 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2177 "auth-info-required", num_air
, NULL
, air
);
2179 if (cupsArrayCount(Banners
) > 0)
2182 * Setup the job-sheets-default attribute...
2185 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2186 "job-sheets-default", 2, NULL
, NULL
);
2190 attr
->values
[0].string
.text
= _cupsStrAlloc(Classification
?
2191 Classification
: p
->job_sheets
[0]);
2192 attr
->values
[1].string
.text
= _cupsStrAlloc(Classification
?
2193 Classification
: p
->job_sheets
[1]);
2201 * Assign additional attributes depending on whether this is a printer
2205 if (p
->type
& CUPS_PRINTER_CLASS
)
2208 p
->type
&= ~CUPS_PRINTER_OPTIONS
;
2211 * Add class-specific attributes...
2214 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
2215 "printer-make-and-model", NULL
, "Local Printer Class");
2216 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "device-uri", NULL
,
2217 "file:///dev/null");
2219 if (p
->num_printers
> 0)
2222 * Add a list of member names; URIs are added in copy_printer_attrs...
2225 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2226 "member-names", p
->num_printers
, NULL
, NULL
);
2227 p
->type
|= CUPS_PRINTER_OPTIONS
;
2229 for (i
= 0; i
< p
->num_printers
; i
++)
2232 attr
->values
[i
].string
.text
= _cupsStrRetain(p
->printers
[i
]->name
);
2234 p
->type
&= ~CUPS_PRINTER_OPTIONS
| p
->printers
[i
]->type
;
2241 * Add printer-specific attributes...
2244 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "device-uri", NULL
,
2245 p
->sanitized_device_uri
);
2248 * Assign additional attributes from the PPD file (if any)...
2254 * Add filters for printer...
2257 cupsdSetPrinterReasons(p
, "-cups-missing-filter-warning,"
2258 "cups-insecure-filter-warning");
2260 if (p
->pc
&& p
->pc
->filters
)
2262 for (filter
= (char *)cupsArrayFirst(p
->pc
->filters
);
2264 filter
= (char *)cupsArrayNext(p
->pc
->filters
))
2265 add_printer_filter(p
, p
->filetype
, filter
);
2267 else if (!(p
->type
& CUPS_PRINTER_REMOTE
))
2269 char interface
[1024]; /* Interface script */
2272 snprintf(interface
, sizeof(interface
), "%s/interfaces/%s", ServerRoot
,
2274 if (!access(interface
, X_OK
))
2277 * Yes, we have a System V style interface script; use it!
2280 snprintf(interface
, sizeof(interface
), "*/* 0 %s/interfaces/%s",
2281 ServerRoot
, p
->name
);
2282 add_printer_filter(p
, p
->filetype
, interface
);
2287 * Add a filter from application/vnd.cups-raw to printer/name to
2288 * handle "raw" printing by users.
2291 add_printer_filter(p
, p
->filetype
, "application/vnd.cups-raw 0 -");
2294 * Add a PostScript filter, since this is still possibly PS printer.
2297 add_printer_filter(p
, p
->filetype
,
2298 "application/vnd.cups-postscript 0 -");
2302 if (p
->pc
&& p
->pc
->prefilters
)
2304 if (!p
->prefiltertype
)
2305 p
->prefiltertype
= mimeAddType(MimeDatabase
, "prefilter", p
->name
);
2307 for (filter
= (char *)cupsArrayFirst(p
->pc
->prefilters
);
2309 filter
= (char *)cupsArrayNext(p
->pc
->prefilters
))
2310 add_printer_filter(p
, p
->prefiltertype
, filter
);
2315 * Copy marker attributes as needed...
2320 ipp_attribute_t
*oldattr
; /* Old attribute */
2323 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-colors",
2324 IPP_TAG_NAME
)) != NULL
)
2326 if ((attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2327 "marker-colors", oldattr
->num_values
, NULL
,
2330 for (i
= 0; i
< oldattr
->num_values
; i
++)
2331 attr
->values
[i
].string
.text
=
2332 _cupsStrRetain(oldattr
->values
[i
].string
.text
);
2336 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-levels",
2337 IPP_TAG_INTEGER
)) != NULL
)
2339 if ((attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2340 "marker-levels", oldattr
->num_values
,
2343 for (i
= 0; i
< oldattr
->num_values
; i
++)
2344 attr
->values
[i
].integer
= oldattr
->values
[i
].integer
;
2348 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-message",
2349 IPP_TAG_TEXT
)) != NULL
)
2350 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "marker-message",
2351 NULL
, oldattr
->values
[0].string
.text
);
2353 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-low-levels",
2354 IPP_TAG_INTEGER
)) != NULL
)
2356 if ((attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2357 "marker-low-levels", oldattr
->num_values
,
2360 for (i
= 0; i
< oldattr
->num_values
; i
++)
2361 attr
->values
[i
].integer
= oldattr
->values
[i
].integer
;
2365 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-high-levels",
2366 IPP_TAG_INTEGER
)) != NULL
)
2368 if ((attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2369 "marker-high-levels", oldattr
->num_values
,
2372 for (i
= 0; i
< oldattr
->num_values
; i
++)
2373 attr
->values
[i
].integer
= oldattr
->values
[i
].integer
;
2377 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-names",
2378 IPP_TAG_NAME
)) != NULL
)
2380 if ((attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2381 "marker-names", oldattr
->num_values
, NULL
,
2384 for (i
= 0; i
< oldattr
->num_values
; i
++)
2385 attr
->values
[i
].string
.text
=
2386 _cupsStrRetain(oldattr
->values
[i
].string
.text
);
2390 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-types",
2391 IPP_TAG_KEYWORD
)) != NULL
)
2393 if ((attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2394 "marker-types", oldattr
->num_values
, NULL
,
2397 for (i
= 0; i
< oldattr
->num_values
; i
++)
2398 attr
->values
[i
].string
.text
=
2399 _cupsStrRetain(oldattr
->values
[i
].string
.text
);
2403 ippDelete(oldattrs
);
2407 * Force sharing off for remote queues...
2410 if (p
->type
& CUPS_PRINTER_REMOTE
)
2414 * Populate the document-format-supported attribute...
2417 add_printer_formats(p
);
2419 DEBUG_printf(("cupsdSetPrinterAttrs: leaving name = %s, type = %x\n", p
->name
,
2423 * Add name-default attributes...
2426 add_printer_defaults(p
);
2430 * Write the IRIX printer config and status files...
2433 write_irix_config(p
);
2434 write_irix_state(p
);
2438 * Let the browse protocols reflect the change
2441 cupsdRegisterPrinter(p
);
2446 * 'cupsdSetPrinterReasons()' - Set/update the reasons strings.
2449 int /* O - 1 if something changed, 0 otherwise */
2450 cupsdSetPrinterReasons(
2451 cupsd_printer_t
*p
, /* I - Printer */
2452 const char *s
) /* I - Reasons strings */
2454 int i
, /* Looping var */
2455 changed
= 0; /* Did something change? */
2456 const char *sptr
; /* Pointer into reasons */
2457 char reason
[255], /* Reason string */
2458 *rptr
; /* Pointer into reason */
2461 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
2462 "cupsdSetPrinterReasons(p=%p(%s),s=\"%s\"", p
, p
->name
, s
);
2464 if (s
[0] == '-' || s
[0] == '+')
2467 * Add/remove reasons...
2475 * Replace reasons...
2480 for (i
= 0; i
< p
->num_reasons
; i
++)
2481 _cupsStrFree(p
->reasons
[i
]);
2489 if (!strcmp(s
, "none"))
2493 * Loop through all of the reasons...
2499 * Skip leading whitespace and commas...
2502 while (isspace(*sptr
& 255) || *sptr
== ',')
2505 for (rptr
= reason
; *sptr
&& !isspace(*sptr
& 255) && *sptr
!= ','; sptr
++)
2506 if (rptr
< (reason
+ sizeof(reason
) - 1))
2520 for (i
= 0; i
< p
->num_reasons
; i
++)
2521 if (!strcmp(reason
, p
->reasons
[i
]))
2524 * Found a match, so remove it...
2529 _cupsStrFree(p
->reasons
[i
]);
2531 if (i
< p
->num_reasons
)
2532 memmove(p
->reasons
+ i
, p
->reasons
+ i
+ 1,
2533 (p
->num_reasons
- i
) * sizeof(char *));
2535 if (!strcmp(reason
, "paused") && p
->state
== IPP_PRINTER_STOPPED
)
2536 cupsdSetPrinterState(p
, IPP_PRINTER_IDLE
, 1);
2538 if (strcmp(reason
, "connecting-to-device"))
2543 else if (p
->num_reasons
< (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
2549 for (i
= 0; i
< p
->num_reasons
; i
++)
2550 if (!strcmp(reason
, p
->reasons
[i
]))
2553 if (i
>= p
->num_reasons
)
2555 if (!strncmp(reason
, "cups-ipp-missing-", 17) ||
2556 !strncmp(reason
, "cups-ipp-wrong-", 15))
2557 log_ipp_conformance(p
, reason
);
2559 if (i
>= (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
2561 cupsdLogMessage(CUPSD_LOG_ALERT
,
2562 "Too many printer-state-reasons values for %s (%d)",
2567 p
->reasons
[i
] = _cupsStrAlloc(reason
);
2571 if (!strcmp(reason
, "paused") && p
->state
!= IPP_PRINTER_STOPPED
)
2572 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, 1);
2574 if (strcmp(reason
, "connecting-to-device"))
2585 * 'cupsdSetPrinterState()' - Update the current state of a printer.
2589 cupsdSetPrinterState(
2590 cupsd_printer_t
*p
, /* I - Printer to change */
2591 ipp_pstate_t s
, /* I - New state */
2592 int update
) /* I - Update printers.conf? */
2594 ipp_pstate_t old_state
; /* Old printer state */
2595 static const char * const printer_states
[] =
2596 { /* State strings */
2604 * Set the new state...
2607 old_state
= p
->state
;
2612 cupsdAddEvent(s
== IPP_PRINTER_STOPPED
? CUPSD_EVENT_PRINTER_STOPPED
:
2613 CUPSD_EVENT_PRINTER_STATE
, p
, NULL
,
2614 "%s \"%s\" state changed to %s.",
2615 (p
->type
& CUPS_PRINTER_CLASS
) ? "Class" : "Printer",
2616 p
->name
, printer_states
[p
->state
- IPP_PRINTER_IDLE
]);
2619 * Let the browse code know this needs to be updated...
2622 p
->state_time
= time(NULL
);
2625 write_irix_state(p
);
2630 * Set/clear the paused reason as needed...
2633 if (s
== IPP_PRINTER_STOPPED
)
2634 cupsdSetPrinterReasons(p
, "+paused");
2636 cupsdSetPrinterReasons(p
, "-paused");
2639 * Clear the message for the queue when going to processing...
2642 if (s
== IPP_PRINTER_PROCESSING
)
2643 p
->state_message
[0] = '\0';
2646 * Let the browse protocols reflect the change...
2650 cupsdRegisterPrinter(p
);
2653 * Save the printer configuration if a printer goes from idle or processing
2654 * to stopped (or visa-versa)...
2658 (old_state
== IPP_PRINTER_STOPPED
) != (s
== IPP_PRINTER_STOPPED
))
2664 * 'cupsdStopPrinter()' - Stop a printer from printing any jobs...
2668 cupsdStopPrinter(cupsd_printer_t
*p
, /* I - Printer to stop */
2669 int update
)/* I - Update printers.conf? */
2672 * Set the printer state...
2675 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, update
);
2678 * See if we have a job printing on this printer...
2681 if (p
->job
&& p
->job
->state_value
== IPP_JOB_PROCESSING
)
2682 cupsdSetJobState(p
->job
, IPP_JOB_PENDING
, CUPSD_JOB_DEFAULT
,
2683 "Job stopped due to printer being paused.");
2688 * 'cupsdUpdatePrinterPPD()' - Update keywords in a printer's PPD file.
2691 int /* O - 1 if successful, 0 otherwise */
2692 cupsdUpdatePrinterPPD(
2693 cupsd_printer_t
*p
, /* I - Printer */
2694 int num_keywords
, /* I - Number of keywords */
2695 cups_option_t
*keywords
) /* I - Keywords */
2697 int i
; /* Looping var */
2698 cups_file_t
*src
, /* Original file */
2699 *dst
; /* New file */
2700 char srcfile
[1024], /* Original filename */
2701 dstfile
[1024], /* New filename */
2702 line
[1024], /* Line from file */
2703 keystring
[41]; /* Keyword from line */
2704 cups_option_t
*keyword
; /* Current keyword */
2707 cupsdLogMessage(CUPSD_LOG_INFO
, "Updating keywords in PPD file for %s...",
2711 * Get the old and new PPD filenames...
2714 snprintf(srcfile
, sizeof(srcfile
), "%s/ppd/%s.ppd.O", ServerRoot
, p
->name
);
2715 snprintf(dstfile
, sizeof(srcfile
), "%s/ppd/%s.ppd", ServerRoot
, p
->name
);
2718 * Rename the old file and open the old and new...
2721 if (rename(dstfile
, srcfile
))
2723 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to backup PPD file for %s: %s",
2724 p
->name
, strerror(errno
));
2728 if ((src
= cupsFileOpen(srcfile
, "r")) == NULL
)
2730 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to open PPD file \"%s\": %s",
2731 srcfile
, strerror(errno
));
2732 rename(srcfile
, dstfile
);
2736 if ((dst
= cupsFileOpen(dstfile
, "w")) == NULL
)
2738 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to create PPD file \"%s\": %s",
2739 dstfile
, strerror(errno
));
2741 rename(srcfile
, dstfile
);
2746 * Copy the first line and then write out all of the keywords...
2749 if (!cupsFileGets(src
, line
, sizeof(line
)))
2751 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to read PPD file \"%s\": %s",
2752 srcfile
, strerror(errno
));
2755 rename(srcfile
, dstfile
);
2759 cupsFilePrintf(dst
, "%s\n", line
);
2761 for (i
= num_keywords
, keyword
= keywords
; i
> 0; i
--, keyword
++)
2763 cupsdLogMessage(CUPSD_LOG_DEBUG
, "*%s: %s", keyword
->name
, keyword
->value
);
2764 cupsFilePrintf(dst
, "*%s: %s\n", keyword
->name
, keyword
->value
);
2768 * Then copy the rest of the PPD file, dropping any keywords we changed.
2771 while (cupsFileGets(src
, line
, sizeof(line
)))
2774 * Skip keywords we've already set...
2777 if (sscanf(line
, "*%40[^:]:", keystring
) == 1 &&
2778 cupsGetOption(keystring
, num_keywords
, keywords
))
2782 * Otherwise write the line...
2785 cupsFilePrintf(dst
, "%s\n", line
);
2789 * Close files and return...
2800 * 'cupsdUpdatePrinters()' - Update printers after a partial reload.
2804 cupsdUpdatePrinters(void)
2806 cupsd_printer_t
*p
; /* Current printer */
2810 * Loop through the printers and recreate the printer attributes
2811 * for any local printers since the policy and/or access control
2812 * stuff may have changed. Also, if browsing is disabled, remove
2813 * any remote printers...
2816 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
2818 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
2821 * Update the operation policy pointer...
2824 if ((p
->op_policy_ptr
= cupsdFindPolicy(p
->op_policy
)) == NULL
)
2825 p
->op_policy_ptr
= DefaultPolicyPtr
;
2828 * Update printer attributes...
2831 cupsdSetPrinterAttrs(p
);
2837 * 'cupsdValidateDest()' - Validate a printer/class destination.
2840 const char * /* O - Printer or class name */
2842 const char *uri
, /* I - Printer URI */
2843 cups_ptype_t
*dtype
, /* O - Type (printer or class) */
2844 cupsd_printer_t
**printer
) /* O - Printer pointer */
2846 cupsd_printer_t
*p
; /* Current printer */
2847 char localname
[1024],/* Localized hostname */
2848 *lptr
, /* Pointer into localized hostname */
2849 *sptr
, /* Pointer into server name */
2850 *rptr
, /* Pointer into resource */
2851 scheme
[32], /* Scheme portion of URI */
2852 username
[64], /* Username portion of URI */
2853 hostname
[HTTP_MAX_HOST
],
2854 /* Host portion of URI */
2855 resource
[HTTP_MAX_URI
];
2856 /* Resource portion of URI */
2857 int port
; /* Port portion of URI */
2860 DEBUG_printf(("cupsdValidateDest(uri=\"%s\", dtype=%p, printer=%p)\n", uri
,
2864 * Initialize return values...
2871 *dtype
= (cups_ptype_t
)0;
2874 * Pull the hostname and resource from the URI...
2877 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
, scheme
, sizeof(scheme
),
2878 username
, sizeof(username
), hostname
, sizeof(hostname
),
2879 &port
, resource
, sizeof(resource
));
2882 * See if the resource is a class or printer...
2885 if (!strncmp(resource
, "/classes/", 9))
2891 rptr
= resource
+ 9;
2893 else if (!strncmp(resource
, "/printers/", 10))
2899 rptr
= resource
+ 10;
2904 * Bad resource name...
2911 * See if the printer or class name exists...
2914 p
= cupsdFindDest(rptr
);
2916 if (p
== NULL
&& strchr(rptr
, '@') == NULL
)
2924 *dtype
= p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_REMOTE
);
2930 * Change localhost to the server name...
2933 if (!_cups_strcasecmp(hostname
, "localhost"))
2934 strlcpy(hostname
, ServerName
, sizeof(hostname
));
2936 strlcpy(localname
, hostname
, sizeof(localname
));
2938 if (!_cups_strcasecmp(hostname
, ServerName
))
2941 * Localize the hostname...
2944 lptr
= strchr(localname
, '.');
2945 sptr
= strchr(ServerName
, '.');
2947 if (sptr
!= NULL
&& lptr
!= NULL
)
2950 * Strip the common domain name components...
2953 while (lptr
!= NULL
)
2955 if (!_cups_strcasecmp(lptr
, sptr
))
2961 lptr
= strchr(lptr
+ 1, '.');
2966 DEBUG_printf(("localized hostname is \"%s\"...\n", localname
));
2969 * Find a matching printer or class...
2972 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
2974 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
2975 if (!_cups_strcasecmp(p
->hostname
, localname
) &&
2976 !_cups_strcasecmp(p
->name
, rptr
))
2982 *dtype
= p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_REMOTE
);
2992 * 'cupsdWritePrintcap()' - Write a pseudo-printcap file for older applications
2997 cupsdWritePrintcap(void)
2999 int i
; /* Looping var */
3000 cups_file_t
*fp
; /* Printcap file */
3001 cupsd_printer_t
*p
; /* Current printer */
3006 * Update the IRIX printer state for the default printer; if
3007 * no printers remain, then the default printer file will be
3011 write_irix_state(DefaultPrinter
);
3015 * See if we have a printcap file; if not, don't bother writing it.
3018 if (!Printcap
|| !*Printcap
)
3021 cupsdLogMessage(CUPSD_LOG_INFO
, "Generating printcap %s...", Printcap
);
3024 * Open the printcap file...
3027 if ((fp
= cupsFileOpen(Printcap
, "w")) == NULL
)
3031 * Put a comment header at the top so that users will know where the
3032 * data has come from...
3035 if (PrintcapFormat
!= PRINTCAP_PLIST
)
3036 cupsFilePrintf(fp
, "# This file was automatically generated by cupsd(8) "
3038 "# %s/printers.conf file. All changes to this file\n"
3039 "# will be lost.\n", ServerRoot
);
3042 * Write a new printcap with the current list of printers.
3045 switch (PrintcapFormat
)
3049 * Each printer is put in the file as:
3059 cupsFilePrintf(fp
, "%s|%s:rm=%s:rp=%s:\n", DefaultPrinter
->name
,
3060 DefaultPrinter
->info
, ServerName
,
3061 DefaultPrinter
->name
);
3063 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3065 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3066 if (p
!= DefaultPrinter
)
3067 cupsFilePrintf(fp
, "%s|%s:rm=%s:rp=%s:\n", p
->name
, p
->info
,
3068 ServerName
, p
->name
);
3071 case PRINTCAP_PLIST
:
3073 * Each printer is written as a dictionary in a plist file.
3074 * Currently the printer-name, printer-info, printer-is-accepting-jobs,
3075 * printer-location, printer-make-and-model, printer-state,
3076 * printer-state-reasons, printer-type, and (sanitized) device-uri.
3079 cupsFilePuts(fp
, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
3080 "<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD "
3081 "PLIST 1.0//EN\" \"http://www.apple.com/DTDs/"
3082 "PropertyList-1.0.dtd\">\n"
3083 "<plist version=\"1.0\">\n"
3086 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3088 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3090 cupsFilePuts(fp
, "\t<dict>\n"
3091 "\t\t<key>printer-name</key>\n"
3093 write_xml_string(fp
, p
->name
);
3094 cupsFilePuts(fp
, "</string>\n"
3095 "\t\t<key>printer-info</key>\n"
3097 write_xml_string(fp
, p
->info
);
3098 cupsFilePrintf(fp
, "</string>\n"
3099 "\t\t<key>printer-is-accepting-jobs</key>\n"
3101 "\t\t<key>printer-location</key>\n"
3102 "\t\t<string>", p
->accepting
? "true" : "false");
3103 write_xml_string(fp
, p
->location
);
3104 cupsFilePuts(fp
, "</string>\n"
3105 "\t\t<key>printer-make-and-model</key>\n"
3107 write_xml_string(fp
, p
->make_model
);
3108 cupsFilePrintf(fp
, "</string>\n"
3109 "\t\t<key>printer-state</key>\n"
3110 "\t\t<integer>%d</integer>\n"
3111 "\t\t<key>printer-state-reasons</key>\n"
3112 "\t\t<array>\n", p
->state
);
3113 for (i
= 0; i
< p
->num_reasons
; i
++)
3115 cupsFilePuts(fp
, "\t\t\t<string>");
3116 write_xml_string(fp
, p
->reasons
[i
]);
3117 cupsFilePuts(fp
, "</string>\n");
3119 cupsFilePrintf(fp
, "\t\t</array>\n"
3120 "\t\t<key>printer-type</key>\n"
3121 "\t\t<integer>%d</integer>\n"
3122 "\t\t<key>device-uri</key>\n"
3123 "\t\t<string>", p
->type
);
3124 write_xml_string(fp
, p
->sanitized_device_uri
);
3125 cupsFilePuts(fp
, "</string>\n"
3128 cupsFilePuts(fp
, "</array>\n"
3132 case PRINTCAP_SOLARIS
:
3134 * Each printer is put in the file as:
3136 * _all:all=Printer1,Printer2,Printer3,...,PrinterN
3137 * _default:use=DefaultPrinter
3139 * :bsdaddr=ServerName,Printer1:\
3140 * :description=Description:
3142 * :bsdaddr=ServerName,Printer2:\
3143 * :description=Description:
3145 * :bsdaddr=ServerName,Printer3:\
3146 * :description=Description:
3149 * :bsdaddr=ServerName,PrinterN:\
3150 * :description=Description:
3153 cupsFilePuts(fp
, "_all:all=");
3154 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3156 p
= (cupsd_printer_t
*)cupsArrayCurrent(Printers
))
3157 cupsFilePrintf(fp
, "%s%c", p
->name
,
3158 cupsArrayNext(Printers
) ? ',' : '\n');
3161 cupsFilePrintf(fp
, "_default:use=%s\n", DefaultPrinter
->name
);
3163 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3165 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3166 cupsFilePrintf(fp
, "%s:\\\n"
3167 "\t:bsdaddr=%s,%s:\\\n"
3168 "\t:description=%s:\n",
3169 p
->name
, ServerName
, p
->name
,
3170 p
->info
? p
->info
: "");
3183 * 'add_printer_defaults()' - Add name-default attributes to the printer attributes.
3187 add_printer_defaults(cupsd_printer_t
*p
)/* I - Printer */
3189 int i
; /* Looping var */
3190 int num_options
; /* Number of default options */
3191 cups_option_t
*options
, /* Default options */
3192 *option
; /* Current option */
3193 char name
[256]; /* name-default */
3197 * Maintain a common array of default attribute names...
3200 if (!CommonDefaults
)
3202 CommonDefaults
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
3204 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("copies-default"));
3205 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("document-format-default"));
3206 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("finishings-default"));
3207 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-hold-until-default"));
3208 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-priority-default"));
3209 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-sheets-default"));
3210 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("media-col-default"));
3211 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("number-up-default"));
3212 cupsArrayAdd(CommonDefaults
,
3213 _cupsStrAlloc("orientation-requested-default"));
3217 * Add all of the default options from the .conf files...
3220 for (num_options
= 0, options
= NULL
, i
= p
->num_options
, option
= p
->options
;
3224 if (strcmp(option
->name
, "ipp-options") &&
3225 strcmp(option
->name
, "job-sheets") &&
3226 strcmp(option
->name
, "lease-duration"))
3228 snprintf(name
, sizeof(name
), "%s-default", option
->name
);
3229 num_options
= cupsAddOption(name
, option
->value
, num_options
, &options
);
3231 if (!cupsArrayFind(CommonDefaults
, name
))
3232 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc(name
));
3237 * Convert options to IPP attributes...
3240 cupsEncodeOptions2(p
->attrs
, num_options
, options
, IPP_TAG_PRINTER
);
3241 cupsFreeOptions(num_options
, options
);
3244 * Add standard -default attributes as needed...
3247 if (!cupsGetOption("copies", p
->num_options
, p
->options
))
3248 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
, "copies-default",
3251 if (!cupsGetOption("document-format", p
->num_options
, p
->options
))
3252 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_MIMETYPE
,
3253 "document-format-default", NULL
, "application/octet-stream");
3255 if (!cupsGetOption("job-hold-until", p
->num_options
, p
->options
))
3256 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3257 "job-hold-until-default", NULL
, "no-hold");
3259 if (!cupsGetOption("job-priority", p
->num_options
, p
->options
))
3260 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3261 "job-priority-default", 50);
3263 if (!cupsGetOption("number-up", p
->num_options
, p
->options
))
3264 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3265 "number-up-default", 1);
3267 if (!cupsGetOption("notify-lease-duration", p
->num_options
, p
->options
))
3268 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3269 "notify-lease-duration-default", DefaultLeaseDuration
);
3271 if (!cupsGetOption("notify-events", p
->num_options
, p
->options
))
3272 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3273 "notify-events-default", NULL
, "job-completed");
3275 if (!cupsGetOption("orientation-requested", p
->num_options
, p
->options
))
3276 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NOVALUE
,
3277 "orientation-requested-default", NULL
, NULL
);
3279 if (!cupsGetOption("print-quality", p
->num_options
, p
->options
))
3280 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
3281 "print-quality-default", IPP_QUALITY_NORMAL
);
3286 * 'add_printer_filter()' - Add a MIME filter for a printer.
3291 cupsd_printer_t
*p
, /* I - Printer to add to */
3292 mime_type_t
*filtertype
, /* I - Filter or prefilter MIME type */
3293 const char *filter
) /* I - Filter to add */
3295 char super
[MIME_MAX_SUPER
], /* Super-type for filter */
3296 type
[MIME_MAX_TYPE
], /* Type for filter */
3297 dsuper
[MIME_MAX_SUPER
], /* Destination super-type for filter */
3298 dtype
[MIME_MAX_TYPE
], /* Destination type for filter */
3299 dest
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2],
3300 /* Destination super/type */
3301 program
[1024]; /* Program/filter name */
3302 int cost
; /* Cost of filter */
3303 size_t maxsize
= 0; /* Maximum supported file size */
3304 mime_type_t
*temptype
, /* MIME type looping var */
3305 *desttype
; /* Destination MIME type */
3306 mime_filter_t
*filterptr
; /* MIME filter */
3307 char filename
[1024]; /* Full filter filename */
3310 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3311 "add_printer_filter(p=%p(%s), filtertype=%p(%s/%s), "
3312 "filter=\"%s\")", p
, p
->name
, filtertype
, filtertype
->super
,
3313 filtertype
->type
, filter
);
3316 * Parse the filter string; it should be in one of the following formats:
3318 * source/type cost program
3319 * source/type cost maxsize(nnnn) program
3320 * source/type dest/type cost program
3321 * source/type dest/type cost maxsize(nnnn) program
3324 if (sscanf(filter
, "%15[^/]/%255s%*[ \t]%15[^/]/%255s%d%*[ \t]%1023[^\n]",
3325 super
, type
, dsuper
, dtype
, &cost
, program
) == 6)
3327 snprintf(dest
, sizeof(dest
), "%s/%s/%s", p
->name
, dsuper
, dtype
);
3329 if ((desttype
= mimeType(MimeDatabase
, "printer", dest
)) == NULL
)
3331 desttype
= mimeAddType(MimeDatabase
, "printer", dest
);
3333 p
->dest_types
= cupsArrayNew(NULL
, NULL
);
3335 cupsArrayAdd(p
->dest_types
, desttype
);
3341 if (sscanf(filter
, "%15[^/]/%255s%d%*[ \t]%1023[^\n]", super
, type
, &cost
,
3344 desttype
= filtertype
;
3348 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: invalid filter string \"%s\"!",
3354 if (!strncmp(program
, "maxsize(", 8))
3356 char *ptr
; /* Pointer into maxsize(nnnn) program */
3358 maxsize
= strtoll(program
+ 8, &ptr
, 10);
3362 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: invalid filter string \"%s\"!",
3368 while (_cups_isspace(*ptr
))
3371 _cups_strcpy(program
, ptr
);
3375 * Check permissions on the filter and its containing directory...
3378 if (strcmp(program
, "-"))
3380 if (program
[0] == '/')
3381 strlcpy(filename
, program
, sizeof(filename
));
3383 snprintf(filename
, sizeof(filename
), "%s/filter/%s", ServerBin
, program
);
3385 _cupsFileCheck(filename
, _CUPS_FILE_CHECK_PROGRAM
, !RunUser
,
3386 cupsdLogFCMessage
, p
);
3390 * Add the filter to the MIME database, supporting wildcards as needed...
3393 for (temptype
= mimeFirstType(MimeDatabase
);
3395 temptype
= mimeNextType(MimeDatabase
))
3396 if (((super
[0] == '*' && _cups_strcasecmp(temptype
->super
, "printer")) ||
3397 !_cups_strcasecmp(temptype
->super
, super
)) &&
3398 (type
[0] == '*' || !_cups_strcasecmp(temptype
->type
, type
)))
3400 if (desttype
!= filtertype
)
3402 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3403 "add_printer_filter: %s: adding filter %s/%s %s/%s %d "
3404 "%s", p
->name
, temptype
->super
, temptype
->type
,
3405 desttype
->super
, desttype
->type
,
3407 filterptr
= mimeAddFilter(MimeDatabase
, temptype
, desttype
, cost
,
3410 if (!mimeFilterLookup(MimeDatabase
, desttype
, filtertype
))
3412 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3413 "add_printer_filter: %s: adding filter %s/%s %s/%s "
3414 "0 -", p
->name
, desttype
->super
, desttype
->type
,
3415 filtertype
->super
, filtertype
->type
);
3416 mimeAddFilter(MimeDatabase
, desttype
, filtertype
, 0, "-");
3421 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3422 "add_printer_filter: %s: adding filter %s/%s %s/%s %d "
3423 "%s", p
->name
, temptype
->super
, temptype
->type
,
3424 filtertype
->super
, filtertype
->type
,
3426 filterptr
= mimeAddFilter(MimeDatabase
, temptype
, filtertype
, cost
,
3431 filterptr
->maxsize
= maxsize
;
3437 * 'add_printer_formats()' - Add document-format-supported values for a printer.
3441 add_printer_formats(cupsd_printer_t
*p
) /* I - Printer */
3443 int i
; /* Looping var */
3444 mime_type_t
*type
; /* Current MIME type */
3445 cups_array_t
*filters
; /* Filters */
3446 ipp_attribute_t
*attr
; /* document-format-supported attribute */
3447 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
3448 /* MIME type name */
3452 * Raw (and remote) queues advertise all of the supported MIME
3456 cupsArrayDelete(p
->filetypes
);
3457 p
->filetypes
= NULL
;
3461 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
,
3462 (ipp_tag_t
)(IPP_TAG_MIMETYPE
| IPP_TAG_COPY
),
3463 "document-format-supported", NumMimeTypes
, NULL
, MimeTypes
);
3468 * Otherwise, loop through the supported MIME types and see if there
3469 * are filters for them...
3472 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_printer_formats: %d types, %d filters",
3473 mimeNumTypes(MimeDatabase
), mimeNumFilters(MimeDatabase
));
3475 p
->filetypes
= cupsArrayNew(NULL
, NULL
);
3477 for (type
= mimeFirstType(MimeDatabase
);
3479 type
= mimeNextType(MimeDatabase
))
3481 if (!_cups_strcasecmp(type
->super
, "printer"))
3484 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
3486 if ((filters
= mimeFilter(MimeDatabase
, type
, p
->filetype
, NULL
)) != NULL
)
3488 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3489 "add_printer_formats: %s: %s needs %d filters",
3490 p
->name
, mimetype
, cupsArrayCount(filters
));
3492 cupsArrayDelete(filters
);
3493 cupsArrayAdd(p
->filetypes
, type
);
3496 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3497 "add_printer_formats: %s: %s not supported",
3502 * Add the file formats that can be filtered...
3505 if ((type
= mimeType(MimeDatabase
, "application", "octet-stream")) == NULL
||
3506 !cupsArrayFind(p
->filetypes
, type
))
3511 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3512 "add_printer_formats: %s: %d supported types",
3513 p
->name
, cupsArrayCount(p
->filetypes
) + i
);
3515 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_MIMETYPE
,
3516 "document-format-supported",
3517 cupsArrayCount(p
->filetypes
) + i
, NULL
, NULL
);
3520 attr
->values
[0].string
.text
= _cupsStrAlloc("application/octet-stream");
3522 for (type
= (mime_type_t
*)cupsArrayFirst(p
->filetypes
);
3524 i
++, type
= (mime_type_t
*)cupsArrayNext(p
->filetypes
))
3526 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
3528 attr
->values
[i
].string
.text
= _cupsStrAlloc(mimetype
);
3533 char pdl
[1024]; /* Buffer to build pdl list */
3534 mime_filter_t
*filter
; /* MIME filter looping var */
3538 * We only support raw printing if this is not a Tioga PrintJobMgr based
3539 * queue and if application/octet-stream is a known type...
3542 for (filter
= (mime_filter_t
*)cupsArrayFirst(MimeDatabase
->filters
);
3544 filter
= (mime_filter_t
*)cupsArrayNext(MimeDatabase
->filters
))
3546 if (filter
->dst
== p
->filetype
&& filter
->filter
&&
3547 strstr(filter
->filter
, "PrintJobMgr"))
3553 if (!filter
&& mimeType(MimeDatabase
, "application", "octet-stream"))
3554 strlcat(pdl
, "application/octet-stream,", sizeof(pdl
));
3557 * Then list a bunch of formats that are supported by the printer...
3560 for (type
= (mime_type_t
*)cupsArrayFirst(p
->filetypes
);
3562 type
= (mime_type_t
*)cupsArrayNext(p
->filetypes
))
3564 if (!_cups_strcasecmp(type
->super
, "application"))
3566 if (!_cups_strcasecmp(type
->type
, "pdf"))
3567 strlcat(pdl
, "application/pdf,", sizeof(pdl
));
3568 else if (!_cups_strcasecmp(type
->type
, "postscript"))
3569 strlcat(pdl
, "application/postscript,", sizeof(pdl
));
3571 else if (!_cups_strcasecmp(type
->super
, "image"))
3573 if (!_cups_strcasecmp(type
->type
, "jpeg"))
3574 strlcat(pdl
, "image/jpeg,", sizeof(pdl
));
3575 else if (!_cups_strcasecmp(type
->type
, "png"))
3576 strlcat(pdl
, "image/png,", sizeof(pdl
));
3577 else if (!_cups_strcasecmp(type
->type
, "pwg-raster"))
3578 strlcat(pdl
, "image/pwg-raster,", sizeof(pdl
));
3583 pdl
[strlen(pdl
) - 1] = '\0'; /* Remove trailing comma */
3585 cupsdSetString(&p
->pdl
, pdl
);
3587 #endif /* HAVE_DNSSD */
3592 * 'compare_printers()' - Compare two printers.
3595 static int /* O - Result of comparison */
3596 compare_printers(void *first
, /* I - First printer */
3597 void *second
, /* I - Second printer */
3598 void *data
) /* I - App data (not used) */
3602 return (_cups_strcasecmp(((cupsd_printer_t
*)first
)->name
,
3603 ((cupsd_printer_t
*)second
)->name
));
3608 * 'delete_printer_filters()' - Delete all MIME filters for a printer.
3612 delete_printer_filters(
3613 cupsd_printer_t
*p
) /* I - Printer to remove from */
3615 mime_filter_t
*filter
; /* MIME filter looping var */
3616 mime_type_t
*type
; /* Destination types for filters */
3620 * Range check input...
3627 * Remove all filters from the MIME database that have a destination
3628 * type == printer...
3631 for (filter
= mimeFirstFilter(MimeDatabase
);
3633 filter
= mimeNextFilter(MimeDatabase
))
3634 if (filter
->dst
== p
->filetype
|| filter
->dst
== p
->prefiltertype
||
3635 cupsArrayFind(p
->dest_types
, filter
->dst
))
3638 * Delete the current filter...
3641 mimeDeleteFilter(MimeDatabase
, filter
);
3644 for (type
= (mime_type_t
*)cupsArrayFirst(p
->dest_types
);
3646 type
= (mime_type_t
*)cupsArrayNext(p
->dest_types
))
3647 mimeDeleteType(MimeDatabase
, type
);
3649 cupsArrayDelete(p
->dest_types
);
3650 p
->dest_types
= NULL
;
3652 cupsdSetPrinterReasons(p
, "-cups-insecure-filter-warning"
3653 ",cups-missing-filter-warning");
3658 * 'dirty_printer()' - Mark config and state files dirty for the specified
3663 dirty_printer(cupsd_printer_t
*p
) /* I - Printer */
3665 if (p
->type
& CUPS_PRINTER_CLASS
)
3666 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
3668 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
3670 if (PrintcapFormat
== PRINTCAP_PLIST
)
3671 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
3676 * 'load_ppd()' - Load a cached PPD file, updating the cache as needed.
3680 load_ppd(cupsd_printer_t
*p
) /* I - Printer */
3682 int i
, j
, k
; /* Looping vars */
3683 char cache_name
[1024]; /* Cache filename */
3684 struct stat cache_info
; /* Cache file info */
3685 ppd_file_t
*ppd
; /* PPD file */
3686 char ppd_name
[1024]; /* PPD filename */
3687 struct stat ppd_info
; /* PPD file info */
3688 int num_media
; /* Number of media options */
3689 ppd_size_t
*size
; /* Current PPD size */
3690 ppd_option_t
*duplex
, /* Duplex option */
3691 *output_bin
, /* OutputBin option */
3692 *output_mode
, /* OutputMode option */
3693 *resolution
; /* (Set|JCL|)Resolution option */
3694 ppd_choice_t
*choice
, /* Current PPD choice */
3695 *input_slot
, /* Current input slot */
3696 *media_type
; /* Current media type */
3697 ppd_attr_t
*ppd_attr
; /* PPD attribute */
3698 int xdpi
, /* Horizontal resolution */
3699 ydpi
; /* Vertical resolution */
3700 const char *resptr
; /* Pointer into resolution keyword */
3701 _pwg_size_t
*pwgsize
; /* Current PWG size */
3702 _pwg_map_t
*pwgsource
, /* Current PWG source */
3703 *pwgtype
; /* Current PWG type */
3704 ipp_attribute_t
*attr
; /* Attribute data */
3705 _ipp_value_t
*val
; /* Attribute value */
3706 int num_finishings
, /* Number of finishings */
3707 finishings
[5]; /* finishings-supported values */
3708 int num_qualities
, /* Number of print-quality values */
3709 qualities
[3]; /* print-quality values */
3710 int num_margins
, /* Number of media-*-margin-supported values */
3711 margins
[16]; /* media-*-margin-supported values */
3712 const char *filter
; /* Current filter */
3713 static const char * const sides
[3] = /* sides-supported values */
3716 "two-sided-long-edge",
3717 "two-sided-short-edge"
3719 static const char * const standard_commands
[] =
3720 { /* Standard CUPS commands */
3728 * Check to see if the cache is up-to-date...
3731 snprintf(cache_name
, sizeof(cache_name
), "%s/%s.data", CacheDir
, p
->name
);
3732 if (stat(cache_name
, &cache_info
))
3733 cache_info
.st_mtime
= 0;
3735 snprintf(ppd_name
, sizeof(ppd_name
), "%s/ppd/%s.ppd", ServerRoot
, p
->name
);
3736 if (stat(ppd_name
, &ppd_info
))
3737 ppd_info
.st_mtime
= 1;
3739 ippDelete(p
->ppd_attrs
);
3740 p
->ppd_attrs
= NULL
;
3742 _ppdCacheDestroy(p
->pc
);
3745 if (cache_info
.st_mtime
>= ppd_info
.st_mtime
)
3747 cupsdLogMessage(CUPSD_LOG_DEBUG
, "load_ppd: Loading %s...", cache_name
);
3749 if ((p
->pc
= _ppdCacheCreateWithFile(cache_name
, &p
->ppd_attrs
)) != NULL
&&
3753 * Loaded successfully!
3761 * Reload PPD attributes from disk...
3764 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
3766 cupsdLogMessage(CUPSD_LOG_DEBUG
, "load_ppd: Loading %s...", ppd_name
);
3768 p
->type
&= ~CUPS_PRINTER_OPTIONS
;
3769 p
->type
|= CUPS_PRINTER_BW
;
3771 finishings
[0] = IPP_FINISHINGS_NONE
;
3774 p
->ppd_attrs
= ippNew();
3776 if ((ppd
= _ppdOpenFile(ppd_name
, _PPD_LOCALIZATION_NONE
)) != NULL
)
3779 * Add make/model and other various attributes...
3782 p
->pc
= _ppdCacheCreateWithPPD(ppd
);
3784 ppdMarkDefaults(ppd
);
3786 if (ppd
->color_device
)
3787 p
->type
|= CUPS_PRINTER_COLOR
;
3788 if (ppd
->variable_sizes
)
3789 p
->type
|= CUPS_PRINTER_VARIABLE
;
3790 if (!ppd
->manual_copies
)
3791 p
->type
|= CUPS_PRINTER_COPIES
;
3792 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsFax", NULL
)) != NULL
)
3793 if (ppd_attr
->value
&& !_cups_strcasecmp(ppd_attr
->value
, "true"))
3794 p
->type
|= CUPS_PRINTER_FAX
;
3796 ippAddBoolean(p
->ppd_attrs
, IPP_TAG_PRINTER
, "color-supported",
3798 if (ppd
->throughput
)
3800 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3801 "pages-per-minute", ppd
->throughput
);
3802 if (ppd
->color_device
)
3803 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3804 "pages-per-minute-color", ppd
->throughput
);
3809 * When there is no speed information, just say "1 page per minute".
3812 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3813 "pages-per-minute", 1);
3814 if (ppd
->color_device
)
3815 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3816 "pages-per-minute-color", 1);
3821 if ((output_mode
= ppdFindOption(ppd
, "OutputMode")) != NULL
)
3823 if (ppdFindChoice(output_mode
, "draft") ||
3824 ppdFindChoice(output_mode
, "fast"))
3825 qualities
[num_qualities
++] = IPP_QUALITY_DRAFT
;
3827 qualities
[num_qualities
++] = IPP_QUALITY_NORMAL
;
3829 if (ppdFindChoice(output_mode
, "best") ||
3830 ppdFindChoice(output_mode
, "high"))
3831 qualities
[num_qualities
++] = IPP_QUALITY_HIGH
;
3833 else if ((ppd_attr
= ppdFindAttr(ppd
, "APPrinterPreset", NULL
)) != NULL
)
3837 if (strstr(ppd_attr
->spec
, "draft") ||
3838 strstr(ppd_attr
->spec
, "Draft"))
3840 qualities
[num_qualities
++] = IPP_QUALITY_DRAFT
;
3844 while ((ppd_attr
= ppdFindNextAttr(ppd
, "APPrinterPreset",
3847 qualities
[num_qualities
++] = IPP_QUALITY_NORMAL
;
3848 qualities
[num_qualities
++] = IPP_QUALITY_HIGH
;
3851 qualities
[num_qualities
++] = IPP_QUALITY_NORMAL
;
3853 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
3854 "print-quality-supported", num_qualities
, qualities
);
3859 * The NickName can be localized in the character set specified
3860 * by the LanugageEncoding attribute. However, ppdOpen2() has
3861 * already converted the ppd->nickname member to UTF-8 for us
3862 * (the original attribute value is available separately)
3865 cupsdSetString(&p
->make_model
, ppd
->nickname
);
3867 else if (ppd
->modelname
)
3870 * Model name can only contain specific characters...
3873 cupsdSetString(&p
->make_model
, ppd
->modelname
);
3876 cupsdSetString(&p
->make_model
, "Bad PPD File");
3878 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
3879 "printer-make-and-model", NULL
, p
->make_model
);
3882 * Add media options from the PPD file...
3885 if (ppd
->num_sizes
== 0 || !p
->pc
)
3887 if (!ppdFindAttr(ppd
, "APScannerOnly", NULL
))
3888 cupsdLogMessage(CUPSD_LOG_CRIT
,
3889 "The PPD file for printer %s contains no media "
3890 "options and is therefore invalid!", p
->name
);
3892 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3893 "media-default", NULL
, "unknown");
3894 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3895 "media-supported", NULL
, "unknown");
3903 if ((size
= ppdPageSize(ppd
, NULL
)) != NULL
)
3904 pwgsize
= _ppdCacheGetSize(p
->pc
, size
->name
);
3908 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3909 "media-default", NULL
,
3910 pwgsize
? pwgsize
->map
.pwg
: "unknown");
3918 ipp_t
*col
; /* Collection value */
3920 input_slot
= ppdFindMarkedChoice(ppd
, "InputSlot");
3921 media_type
= ppdFindMarkedChoice(ppd
, "MediaType");
3922 col
= new_media_col(pwgsize
,
3924 _ppdCacheGetSource(p
->pc
,
3925 input_slot
->choice
) :
3928 _ppdCacheGetType(p
->pc
,
3929 media_type
->choice
) :
3932 ippAddCollection(p
->ppd_attrs
, IPP_TAG_PRINTER
, "media-col-default",
3941 num_media
= p
->pc
->num_sizes
;
3942 if (p
->pc
->custom_min_keyword
)
3945 if ((attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3946 "media-supported", num_media
, NULL
,
3951 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
;
3953 i
--, pwgsize
++, val
++)
3954 val
->string
.text
= _cupsStrRetain(pwgsize
->map
.pwg
);
3956 if (p
->pc
->custom_min_keyword
)
3958 val
->string
.text
= _cupsStrRetain(p
->pc
->custom_min_keyword
);
3960 val
->string
.text
= _cupsStrRetain(p
->pc
->custom_max_keyword
);
3965 * media-source-supported
3968 if (p
->pc
->num_sources
> 0 &&
3969 (attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3970 "media-source-supported", p
->pc
->num_sources
,
3971 NULL
, NULL
)) != NULL
)
3973 for (i
= p
->pc
->num_sources
, pwgsource
= p
->pc
->sources
,
3976 i
--, pwgsource
++, val
++)
3977 val
->string
.text
= _cupsStrRetain(pwgsource
->pwg
);
3981 * media-type-supported
3984 if (p
->pc
->num_types
> 0 &&
3985 (attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3986 "media-type-supported", p
->pc
->num_types
,
3987 NULL
, NULL
)) != NULL
)
3989 for (i
= p
->pc
->num_types
, pwgtype
= p
->pc
->types
,
3992 i
--, pwgtype
++, val
++)
3993 val
->string
.text
= _cupsStrRetain(pwgtype
->pwg
);
3997 * media-*-margin-supported
4000 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, num_margins
= 0;
4001 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4004 for (j
= 0; j
< num_margins
; j
++)
4005 if (pwgsize
->bottom
== margins
[j
])
4008 if (j
>= num_margins
)
4010 margins
[num_margins
] = pwgsize
->bottom
;
4015 if (num_margins
> 0)
4016 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4017 "media-bottom-margin-supported", num_margins
, margins
);
4019 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4020 "media-bottom-margin-supported", 0);
4022 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, num_margins
= 0;
4023 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4026 for (j
= 0; j
< num_margins
; j
++)
4027 if (pwgsize
->left
== margins
[j
])
4030 if (j
>= num_margins
)
4032 margins
[num_margins
] = pwgsize
->left
;
4037 if (num_margins
> 0)
4038 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4039 "media-left-margin-supported", num_margins
, margins
);
4041 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4042 "media-left-margin-supported", 0);
4044 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, num_margins
= 0;
4045 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4048 for (j
= 0; j
< num_margins
; j
++)
4049 if (pwgsize
->right
== margins
[j
])
4052 if (j
>= num_margins
)
4054 margins
[num_margins
] = pwgsize
->right
;
4059 if (num_margins
> 0)
4060 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4061 "media-right-margin-supported", num_margins
, margins
);
4063 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4064 "media-right-margin-supported", 0);
4066 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, num_margins
= 0;
4067 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4070 for (j
= 0; j
< num_margins
; j
++)
4071 if (pwgsize
->top
== margins
[j
])
4074 if (j
>= num_margins
)
4076 margins
[num_margins
] = pwgsize
->top
;
4081 if (num_margins
> 0)
4082 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4083 "media-top-margin-supported", num_margins
, margins
);
4085 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4086 "media-top-margin-supported", 0);
4089 * media-col-database
4092 num_media
= p
->pc
->num_sizes
;
4093 if (p
->pc
->num_sources
)
4095 if (p
->pc
->num_types
> 0)
4096 num_media
+= p
->pc
->num_sizes
* p
->pc
->num_sources
*
4099 num_media
+= p
->pc
->num_sizes
* p
->pc
->num_sources
;
4101 else if (p
->pc
->num_types
)
4102 num_media
+= p
->pc
->num_sizes
* p
->pc
->num_types
;
4104 if ((attr
= ippAddCollections(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4105 "media-col-database", num_media
,
4108 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, val
= attr
->values
;
4113 * Start by adding the page size without source or type...
4116 ppdMarkOption(ppd
, "PageSize", pwgsize
->map
.ppd
);
4118 val
->collection
= new_media_col(pwgsize
, NULL
, NULL
);
4122 * Then add the specific, supported combinations of size, source, and
4126 if (p
->pc
->num_sources
> 0)
4128 for (j
= p
->pc
->num_sources
, pwgsource
= p
->pc
->sources
;
4132 ppdMarkOption(ppd
, "InputSlot", pwgsource
->ppd
);
4134 if (p
->pc
->num_types
> 0)
4136 for (k
= p
->pc
->num_types
, pwgtype
= p
->pc
->types
;
4140 if (!ppdMarkOption(ppd
, "MediaType", pwgtype
->ppd
))
4142 val
->collection
= new_media_col(pwgsize
, pwgsource
->pwg
,
4148 else if (!ppdConflicts(ppd
))
4150 val
->collection
= new_media_col(pwgsize
, pwgsource
->pwg
, NULL
);
4155 else if (p
->pc
->num_types
> 0)
4157 for (j
= p
->pc
->num_types
, pwgtype
= p
->pc
->types
;
4161 if (!ppdMarkOption(ppd
, "MediaType", pwgtype
->ppd
))
4163 val
->collection
= new_media_col(pwgsize
, NULL
, pwgtype
->pwg
);
4171 * Update the number of media-col-database values...
4174 attr
->num_values
= val
- attr
->values
;
4182 if (p
->pc
&& p
->pc
->num_bins
> 0)
4184 attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4185 "output-bin-supported", p
->pc
->num_bins
,
4190 for (i
= 0, val
= attr
->values
;
4191 i
< p
->pc
->num_bins
;
4193 val
->string
.text
= _cupsStrAlloc(p
->pc
->bins
[i
].pwg
);
4196 if ((output_bin
= ppdFindOption(ppd
, "OutputBin")) != NULL
)
4198 for (i
= 0; i
< p
->pc
->num_bins
; i
++)
4199 if (!strcmp(p
->pc
->bins
[i
].ppd
, output_bin
->defchoice
))
4202 if (i
>= p
->pc
->num_bins
)
4205 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4206 "output-bin-default", NULL
, p
->pc
->bins
[i
].pwg
);
4209 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4210 "output-bin-default", NULL
, p
->pc
->bins
[0].pwg
);
4212 else if (((ppd_attr
= ppdFindAttr(ppd
, "DefaultOutputOrder",
4214 !_cups_strcasecmp(ppd_attr
->value
, "Reverse")) ||
4215 (!ppd_attr
&& ppd
->manufacturer
&& /* "Compatibility heuristic" */
4216 (!_cups_strcasecmp(ppd
->manufacturer
, "epson") ||
4217 !_cups_strcasecmp(ppd
->manufacturer
, "lexmark"))))
4220 * Report that this printer has a single output bin that leaves pages face
4224 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4225 "output-bin-supported", NULL
, "face-up");
4226 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4227 "output-bin-default", NULL
, "face-up");
4231 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4232 "output-bin-supported", NULL
, "face-down");
4233 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4234 "output-bin-default", NULL
, "face-down");
4238 * output-mode and print-color-mode...
4241 if (ppd
->color_device
)
4243 static const char * const output_modes
[] =
4249 ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4250 "output-mode-supported", 2, NULL
, output_modes
);
4251 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4252 "output-mode-default", NULL
, "color");
4254 ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4255 "print-color-mode-supported", 2, NULL
, output_modes
);
4256 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4257 "print-color-mode-default", NULL
, "color");
4261 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4262 "output-mode-supported", NULL
, "monochrome");
4263 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4264 "output-mode-default", NULL
, "monochrome");
4266 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4267 "print-color-mode-supported", NULL
, "monochrome");
4268 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4269 "print-color-mode-default", NULL
, "monochrome");
4273 * Printer resolutions...
4276 if ((resolution
= ppdFindOption(ppd
, "Resolution")) == NULL
)
4277 if ((resolution
= ppdFindOption(ppd
, "JCLResolution")) == NULL
)
4278 if ((resolution
= ppdFindOption(ppd
, "SetResolution")) == NULL
)
4279 resolution
= ppdFindOption(ppd
, "CNRes_PGP");
4284 * Report all supported resolutions...
4287 attr
= ippAddResolutions(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4288 "printer-resolution-supported",
4289 resolution
->num_choices
, IPP_RES_PER_INCH
,
4292 for (i
= 0, choice
= resolution
->choices
;
4293 i
< resolution
->num_choices
;
4296 xdpi
= ydpi
= (int)strtol(choice
->choice
, (char **)&resptr
, 10);
4297 if (resptr
> choice
->choice
&& xdpi
> 0 && *resptr
== 'x')
4298 ydpi
= (int)strtol(resptr
+ 1, (char **)&resptr
, 10);
4300 if (xdpi
<= 0 || ydpi
<= 0)
4302 cupsdLogMessage(CUPSD_LOG_WARN
,
4303 "Bad resolution \"%s\" for printer %s.",
4304 choice
->choice
, p
->name
);
4308 attr
->values
[i
].resolution
.xres
= xdpi
;
4309 attr
->values
[i
].resolution
.yres
= ydpi
;
4310 attr
->values
[i
].resolution
.units
= IPP_RES_PER_INCH
;
4313 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4314 "printer-resolution-default", IPP_RES_PER_INCH
,
4318 else if ((ppd_attr
= ppdFindAttr(ppd
, "DefaultResolution", NULL
)) != NULL
&&
4322 * Just the DefaultResolution to report...
4325 xdpi
= ydpi
= (int)strtol(ppd_attr
->value
, (char **)&resptr
, 10);
4326 if (resptr
> ppd_attr
->value
&& xdpi
> 0)
4329 ydpi
= (int)strtol(resptr
+ 1, (char **)&resptr
, 10);
4334 if (xdpi
<= 0 || ydpi
<= 0)
4336 cupsdLogMessage(CUPSD_LOG_WARN
,
4337 "Bad default resolution \"%s\" for printer %s.",
4338 ppd_attr
->value
, p
->name
);
4342 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4343 "printer-resolution-default", IPP_RES_PER_INCH
,
4345 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4346 "printer-resolution-supported", IPP_RES_PER_INCH
,
4352 * No resolutions in PPD - make one up...
4355 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4356 "printer-resolution-default", IPP_RES_PER_INCH
,
4358 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4359 "printer-resolution-supported", IPP_RES_PER_INCH
,
4367 ppdMarkDefaults(ppd
);
4369 if ((duplex
= ppdFindOption(ppd
, "Duplex")) == NULL
)
4370 if ((duplex
= ppdFindOption(ppd
, "EFDuplex")) == NULL
)
4371 if ((duplex
= ppdFindOption(ppd
, "EFDuplexing")) == NULL
)
4372 if ((duplex
= ppdFindOption(ppd
, "KD03Duplex")) == NULL
)
4373 duplex
= ppdFindOption(ppd
, "JCLDuplex");
4375 if (duplex
&& duplex
->num_choices
> 1 &&
4376 !ppdInstallableConflict(ppd
, duplex
->keyword
, "DuplexTumble"))
4378 p
->type
|= CUPS_PRINTER_DUPLEX
;
4380 ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4381 "sides-supported", 3, NULL
, sides
);
4383 if (!_cups_strcasecmp(duplex
->defchoice
, "DuplexTumble"))
4384 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4385 "sides-default", NULL
, "two-sided-short-edge");
4386 else if (!_cups_strcasecmp(duplex
->defchoice
, "DuplexNoTumble"))
4387 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4388 "sides-default", NULL
, "two-sided-long-edge");
4390 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4391 "sides-default", NULL
, "one-sided");
4395 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4396 "sides-supported", NULL
, "one-sided");
4397 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4398 "sides-default", NULL
, "one-sided");
4401 if (ppdFindOption(ppd
, "Collate") != NULL
)
4402 p
->type
|= CUPS_PRINTER_COLLATE
;
4404 if (ppdFindOption(ppd
, "StapleLocation") != NULL
)
4406 p
->type
|= CUPS_PRINTER_STAPLE
;
4407 finishings
[num_finishings
++] = IPP_FINISHINGS_STAPLE
;
4410 if (ppdFindOption(ppd
, "BindEdge") != NULL
)
4412 p
->type
|= CUPS_PRINTER_BIND
;
4413 finishings
[num_finishings
++] = IPP_FINISHINGS_BIND
;
4416 for (i
= 0; i
< ppd
->num_sizes
; i
++)
4417 if (ppd
->sizes
[i
].length
> 1728)
4418 p
->type
|= CUPS_PRINTER_LARGE
;
4419 else if (ppd
->sizes
[i
].length
> 1008)
4420 p
->type
|= CUPS_PRINTER_MEDIUM
;
4422 p
->type
|= CUPS_PRINTER_SMALL
;
4424 if ((ppd_attr
= ppdFindAttr(ppd
, "APICADriver", NULL
)) != NULL
&&
4425 ppd_attr
->value
&& !_cups_strcasecmp(ppd_attr
->value
, "true"))
4427 if ((ppd_attr
= ppdFindAttr(ppd
, "APScannerOnly", NULL
)) != NULL
&&
4428 ppd_attr
->value
&& !_cups_strcasecmp(ppd_attr
->value
, "true"))
4429 p
->type
|= CUPS_PRINTER_SCANNER
;
4431 p
->type
|= CUPS_PRINTER_MFP
;
4435 * Scan the filters in the PPD file...
4440 for (filter
= (const char *)cupsArrayFirst(p
->pc
->filters
);
4442 filter
= (const char *)cupsArrayNext(p
->pc
->filters
))
4444 if (!_cups_strncasecmp(filter
, "application/vnd.cups-command", 28) &&
4445 _cups_isspace(filter
[28]))
4447 p
->type
|= CUPS_PRINTER_COMMANDS
;
4453 if (p
->type
& CUPS_PRINTER_COMMANDS
)
4455 char *commands
, /* Copy of commands */
4456 *start
, /* Start of name */
4457 *end
; /* End of name */
4458 int count
; /* Number of commands */
4460 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsCommands", NULL
)) != NULL
)
4462 for (count
= 0, start
= ppd_attr
->value
; *start
; count
++)
4464 while (_cups_isspace(*start
))
4470 while (*start
&& !isspace(*start
& 255))
4480 * Make a copy of the commands string and count how many commands there
4484 attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4485 "printer-commands", count
, NULL
, NULL
);
4487 commands
= strdup(ppd_attr
->value
);
4489 for (count
= 0, start
= commands
; *start
; count
++)
4491 while (isspace(*start
& 255))
4498 while (*end
&& !isspace(*end
& 255))
4504 attr
->values
[count
].string
.text
= _cupsStrAlloc(start
);
4514 * Add the standard list of commands...
4517 ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4519 (int)(sizeof(standard_commands
) /
4520 sizeof(standard_commands
[0])), NULL
,
4527 * No commands supported...
4530 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4531 "printer-commands", NULL
, "none");
4535 * Show current and available port monitors for this printer...
4538 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
, "port-monitor",
4539 NULL
, p
->port_monitor
? p
->port_monitor
: "none");
4541 for (i
= 1, ppd_attr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
4543 i
++, ppd_attr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
));
4547 if (strstr(ppd
->protocols
, "TBCP"))
4549 else if (strstr(ppd
->protocols
, "BCP"))
4553 attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
4554 "port-monitor-supported", i
, NULL
, NULL
);
4556 attr
->values
[0].string
.text
= _cupsStrAlloc("none");
4558 for (i
= 1, ppd_attr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
4560 i
++, ppd_attr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
))
4561 attr
->values
[i
].string
.text
= _cupsStrAlloc(ppd_attr
->value
);
4565 if (strstr(ppd
->protocols
, "TBCP"))
4566 attr
->values
[i
].string
.text
= _cupsStrAlloc("tbcp");
4567 else if (strstr(ppd
->protocols
, "BCP"))
4568 attr
->values
[i
].string
.text
= _cupsStrAlloc("bcp");
4571 if (ppdFindAttr(ppd
, "APRemoteQueueID", NULL
))
4572 p
->type
|= CUPS_PRINTER_REMOTE
;
4574 #ifdef HAVE_APPLICATIONSERVICES_H
4576 * Convert the file referenced in APPrinterIconPath to a 128x128 PNG
4577 * and save it as cacheDir/printername.png
4580 if ((ppd_attr
= ppdFindAttr(ppd
, "APPrinterIconPath", NULL
)) != NULL
&&
4582 !_cupsFileCheck(ppd_attr
->value
, _CUPS_FILE_CHECK_FILE
, !RunUser
,
4583 cupsdLogFCMessage
, p
))
4585 CGImageRef imageRef
= NULL
;/* Current icon image */
4586 CGImageRef biggestIconRef
= NULL
;
4587 /* Biggest icon image */
4588 CGImageRef closestTo128IconRef
= NULL
;
4589 /* Icon image closest to and >= 128 */
4590 CGImageSourceRef sourceRef
; /* The file's image source */
4591 char outPath
[HTTP_MAX_URI
];
4592 /* The path to the PNG file */
4593 CFURLRef outUrl
; /* The URL made from the outPath */
4594 CFURLRef icnsFileUrl
; /* The URL of the original ICNS icon file */
4595 CGImageDestinationRef destRef
; /* The image destination to write */
4596 size_t bytesPerRow
; /* The bytes per row used for resizing */
4597 CGContextRef context
; /* The CG context used for resizing */
4599 snprintf(outPath
, sizeof(outPath
), "%s/%s.png", CacheDir
, p
->name
);
4600 outUrl
= CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault
,
4604 icnsFileUrl
= CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault
,
4605 (UInt8
*)ppd_attr
->value
,
4606 strlen(ppd_attr
->value
),
4608 if (outUrl
&& icnsFileUrl
)
4610 sourceRef
= CGImageSourceCreateWithURL(icnsFileUrl
, NULL
);
4613 for (i
= 0; i
< CGImageSourceGetCount(sourceRef
); i
++)
4615 imageRef
= CGImageSourceCreateImageAtIndex(sourceRef
, i
, NULL
);
4619 if (CGImageGetWidth(imageRef
) == CGImageGetHeight(imageRef
))
4622 * Loop through remembering the icon closest to 128 but >= 128
4623 * and then remember the largest icon.
4626 if (CGImageGetWidth(imageRef
) >= 128 &&
4627 (!closestTo128IconRef
||
4628 CGImageGetWidth(imageRef
) <
4629 CGImageGetWidth(closestTo128IconRef
)))
4631 CGImageRelease(closestTo128IconRef
);
4632 CGImageRetain(imageRef
);
4633 closestTo128IconRef
= imageRef
;
4636 if (!biggestIconRef
||
4637 CGImageGetWidth(imageRef
) > CGImageGetWidth(biggestIconRef
))
4639 CGImageRelease(biggestIconRef
);
4640 CGImageRetain(imageRef
);
4641 biggestIconRef
= imageRef
;
4645 CGImageRelease(imageRef
);
4651 * If biggestIconRef is NULL, we found no icons. Otherwise we first
4652 * want the closest to 128, but if none are larger than 128, we want
4653 * the largest icon available.
4656 imageRef
= closestTo128IconRef
? closestTo128IconRef
:
4658 CGImageRetain(imageRef
);
4659 CGImageRelease(biggestIconRef
);
4660 if (closestTo128IconRef
)
4661 CGImageRelease(closestTo128IconRef
);
4662 destRef
= CGImageDestinationCreateWithURL(outUrl
, kUTTypePNG
, 1,
4666 if (CGImageGetWidth(imageRef
) != 128)
4668 bytesPerRow
= CGImageGetBytesPerRow(imageRef
) /
4669 CGImageGetWidth(imageRef
) * 128;
4670 context
= CGBitmapContextCreate(NULL
, 128, 128,
4671 CGImageGetBitsPerComponent(imageRef
),
4673 CGImageGetColorSpace(imageRef
),
4674 kCGImageAlphaPremultipliedFirst
);
4677 CGContextDrawImage(context
, CGRectMake(0, 0, 128, 128),
4679 CGImageRelease(imageRef
);
4680 imageRef
= CGBitmapContextCreateImage(context
);
4681 CGContextRelease(context
);
4685 CGImageDestinationAddImage(destRef
, imageRef
, NULL
);
4686 CGImageDestinationFinalize(destRef
);
4690 CGImageRelease(imageRef
);
4693 CFRelease(sourceRef
);
4701 CFRelease(icnsFileUrl
);
4703 #endif /* HAVE_APPLICATIONSERVICES_H */
4706 * Close the PPD and set the type...
4711 else if (!access(ppd_name
, 0))
4713 int pline
; /* PPD line number */
4714 ppd_status_t pstatus
; /* PPD load status */
4717 pstatus
= ppdLastError(&pline
);
4719 cupsdLogMessage(CUPSD_LOG_ERROR
, "PPD file for %s cannot be loaded!",
4722 if (pstatus
<= PPD_ALLOC_ERROR
)
4723 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s", strerror(errno
));
4725 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s on line %d.",
4726 ppdErrorString(pstatus
), pline
);
4728 cupsdLogMessage(CUPSD_LOG_INFO
,
4729 "Hint: Run \"cupstestppd %s\" and fix any errors.",
4735 * If we have an interface script, add a filter entry for it...
4738 char interface
[1024]; /* Interface script */
4741 snprintf(interface
, sizeof(interface
), "%s/interfaces/%s", ServerRoot
,
4743 if (!access(interface
, X_OK
))
4746 * Yes, we have a System V style interface script; use it!
4749 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
4750 "printer-make-and-model", NULL
,
4751 "Local System V Printer");
4753 else if (!strncmp(p
->device_uri
, "ipp://", 6) &&
4754 (strstr(p
->device_uri
, "/printers/") != NULL
||
4755 strstr(p
->device_uri
, "/classes/") != NULL
||
4756 (strstr(p
->device_uri
, "._ipp.") != NULL
&&
4757 !strcmp(p
->device_uri
+ strlen(p
->device_uri
) - 5,
4761 * Tell the client this is really a hard-wired remote printer.
4764 p
->type
|= CUPS_PRINTER_REMOTE
;
4767 * Point the printer-uri-supported attribute to the
4771 if (strchr(p
->device_uri
, '?'))
4774 * Strip trailing "?options" from URI...
4777 char resource
[HTTP_MAX_URI
], /* New URI */
4778 *ptr
; /* Pointer into URI */
4780 strlcpy(resource
, p
->device_uri
, sizeof(resource
));
4781 if ((ptr
= strchr(resource
, '?')) != NULL
)
4784 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
4785 "printer-uri-supported", NULL
, resource
);
4788 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
4789 "printer-uri-supported", NULL
, p
->device_uri
);
4792 * Then set the make-and-model accordingly...
4795 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
4796 "printer-make-and-model", NULL
, "Remote Printer");
4799 * Print all files directly...
4808 * Otherwise we have neither - treat this as a "dumb" printer
4809 * with no PPD file...
4812 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
4813 "printer-make-and-model", NULL
, "Local Raw Printer");
4819 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
4820 "finishings-supported", num_finishings
, finishings
);
4821 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
4822 "finishings-default", IPP_FINISHINGS_NONE
);
4827 * Save cached PPD attributes to disk...
4830 cupsdLogMessage(CUPSD_LOG_DEBUG
, "load_ppd: Saving %s...", cache_name
);
4832 _ppdCacheWriteFile(p
->pc
, cache_name
, p
->ppd_attrs
);
4837 * Remove cache files...
4840 if (cache_info
.st_mtime
)
4847 * 'log_ipp_conformance()' - Log an IPP conformance issue with a printer.
4851 log_ipp_conformance(
4852 cupsd_printer_t
*p
, /* I - Printer */
4853 const char *reason
) /* I - Printer state reason */
4855 const char *message
; /* Message to log */
4857 aslmsg aslm
; /* Apple System Log message */
4858 #endif /* __APPLE__ */
4862 * Strip the leading "cups-ipp-" from the reason and create a log message for
4867 if (!strcmp(reason
, "missing-cancel-job"))
4868 message
= "Printer does not support REQUIRED Cancel-Job operation.";
4869 else if (!strcmp(reason
, "missing-get-job-attributes"))
4870 message
= "Printer does not support REQUIRED Get-Job-Attributes operation.";
4871 else if (!strcmp(reason
, "missing-print-job"))
4872 message
= "Printer does not support REQUIRED Print-Job operation.";
4873 else if (!strcmp(reason
, "missing-validate-job"))
4874 message
= "Printer does not support REQUIRED Validate-Job operation.";
4875 else if (!strcmp(reason
, "missing-get-printer-attributes"))
4876 message
= "Printer does not support REQUIRED Get-Printer-Attributes operation.";
4877 else if (!strcmp(reason
, "missing-job-history"))
4878 message
= "Printer does not provide REQUIRED job history.";
4879 else if (!strcmp(reason
, "missing-job-id"))
4880 message
= "Printer does not provide REQUIRED job-id attribute.";
4881 else if (!strcmp(reason
, "missing-job-state"))
4882 message
= "Printer does not provide REQUIRED job-state attribute.";
4883 else if (!strcmp(reason
, "missing-operations-supported"))
4884 message
= "Printer does not provide REQUIRED operations-supported "
4886 else if (!strcmp(reason
, "missing-printer-is-accepting-jobs"))
4887 message
= "Printer does not provide REQUIRED printer-is-accepting-jobs "
4889 else if (!strcmp(reason
, "missing-printer-state-reasons"))
4890 message
= "Printer does not provide REQUIRED printer-state-reasons "
4892 else if (!strcmp(reason
, "wrong-http-version"))
4893 message
= "Printer does not use REQUIRED HTTP/1.1 transport.";
4895 message
= "Unknown IPP conformance failure.";
4897 cupsdLogMessage(CUPSD_LOG_WARN
, "%s: %s", p
->name
, message
);
4901 * Report the failure information to Apple if the user opts into providing
4902 * feedback to Apple...
4905 aslm
= asl_new(ASL_TYPE_MSG
);
4908 asl_set(aslm
, "com.apple.message.domain", "com.apple.printing.ipp.conformance");
4909 asl_set(aslm
, "com.apple.message.domain_scope", "com.apple.printing.ipp.conformance");
4910 asl_set(aslm
, "com.apple.message.signature", reason
);
4911 asl_set(aslm
, "com.apple.message.signature2",
4912 p
->make_model
? p
->make_model
: "Unknown");
4913 asl_log(NULL
, aslm
, ASL_LEVEL_NOTICE
, "%s: %s",
4914 p
->make_model
? p
->make_model
: "Unknown", message
);
4917 #endif /* __APPLE__ */
4922 * 'new_media_col()' - Create a media-col collection value.
4925 static ipp_t
* /* O - Collection value */
4926 new_media_col(_pwg_size_t
*size
, /* I - media-size/margin values */
4927 const char *source
, /* I - media-source value */
4928 const char *type
) /* I - media-type value */
4930 ipp_t
*media_col
, /* Collection value */
4931 *media_size
; /* media-size value */
4934 media_col
= ippNew();
4936 media_size
= ippNew();
4937 ippAddInteger(media_size
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4938 "x-dimension", size
->width
);
4939 ippAddInteger(media_size
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4940 "y-dimension", size
->length
);
4941 ippAddCollection(media_col
, IPP_TAG_PRINTER
, "media-size", media_size
);
4942 ippDelete(media_size
);
4944 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4945 "media-bottom-margin", size
->bottom
);
4946 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4947 "media-left-margin", size
->left
);
4948 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4949 "media-right-margin", size
->right
);
4950 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4951 "media-top-margin", size
->top
);
4954 ippAddString(media_col
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
, "media-source",
4958 ippAddString(media_col
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
, "media-type",
4967 * 'write_irix_config()' - Update the config files used by the IRIX
4972 write_irix_config(cupsd_printer_t
*p
) /* I - Printer to update */
4974 char filename
[1024]; /* Interface script filename */
4975 cups_file_t
*fp
; /* Interface script file */
4976 ipp_attribute_t
*attr
; /* Attribute data */
4980 * Add dummy interface and GUI scripts to fool SGI's "challenged" printing
4981 * tools. First the interface script that tells the tools what kind of
4982 * printer we have...
4985 snprintf(filename
, sizeof(filename
), "/var/spool/lp/interface/%s", p
->name
);
4987 if (p
->type
& CUPS_PRINTER_CLASS
)
4989 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
4991 cupsFilePuts(fp
, "#!/bin/sh\n");
4993 if ((attr
= ippFindAttribute(p
->attrs
, "printer-make-and-model",
4994 IPP_TAG_TEXT
)) != NULL
)
4995 cupsFilePrintf(fp
, "NAME=\"%s\"\n", attr
->values
[0].string
.text
);
4996 else if (p
->type
& CUPS_PRINTER_CLASS
)
4997 cupsFilePuts(fp
, "NAME=\"Printer Class\"\n");
4999 cupsFilePuts(fp
, "NAME=\"Remote Destination\"\n");
5001 if (p
->type
& CUPS_PRINTER_COLOR
)
5002 cupsFilePuts(fp
, "TYPE=ColorPostScript\n");
5004 cupsFilePuts(fp
, "TYPE=MonoPostScript\n");
5006 cupsFilePrintf(fp
, "HOSTNAME=%s\n", ServerName
);
5007 cupsFilePrintf(fp
, "HOSTPRINTER=%s\n", p
->name
);
5011 chmod(filename
, 0755);
5012 chown(filename
, User
, Group
);
5016 * Then the member file that tells which device file the queue is connected
5017 * to... Networked printers use "/dev/null" in this file, so that's what
5018 * we use (the actual device URI can confuse some apps...)
5021 snprintf(filename
, sizeof(filename
), "/var/spool/lp/member/%s", p
->name
);
5023 if (p
->type
& CUPS_PRINTER_CLASS
)
5025 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
5027 cupsFilePuts(fp
, "/dev/null\n");
5031 chmod(filename
, 0644);
5032 chown(filename
, User
, Group
);
5036 * The gui_interface file is a script or program that launches a GUI
5037 * option panel for the printer, using options specified on the
5038 * command-line in the third argument. The option panel must send
5039 * any printing options to stdout on a single line when the user
5040 * accepts them, or nothing if the user cancels the dialog.
5042 * The default options panel program is /usr/bin/glpoptions, from
5043 * the ESP Print Pro software. You can select another using the
5044 * PrintcapGUI option.
5047 snprintf(filename
, sizeof(filename
), "/var/spool/lp/gui_interface/ELF/%s.gui", p
->name
);
5049 if (p
->type
& CUPS_PRINTER_CLASS
)
5051 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
5053 cupsFilePuts(fp
, "#!/bin/sh\n");
5054 cupsFilePrintf(fp
, "%s -d %s -o \"$3\"\n", PrintcapGUI
, p
->name
);
5058 chmod(filename
, 0755);
5059 chown(filename
, User
, Group
);
5063 * The POD config file is needed by the printstatus command to show
5064 * the printer location and device.
5067 snprintf(filename
, sizeof(filename
), "/var/spool/lp/pod/%s.config", p
->name
);
5069 if (p
->type
& CUPS_PRINTER_CLASS
)
5071 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
5073 cupsFilePrintf(fp
, "Printer Class | %s\n",
5074 (p
->type
& CUPS_PRINTER_COLOR
) ? "ColorPostScript" : "MonoPostScript");
5075 cupsFilePrintf(fp
, "Printer Model | %s\n", p
->make_model
? p
->make_model
: "");
5076 cupsFilePrintf(fp
, "Location Code | %s\n", p
->location
? p
->location
: "");
5077 cupsFilePrintf(fp
, "Physical Location | %s\n", p
->info
? p
->info
: "");
5078 cupsFilePrintf(fp
, "Port Path | %s\n", p
->device_uri
);
5079 cupsFilePrintf(fp
, "Config Path | /var/spool/lp/pod/%s.config\n", p
->name
);
5080 cupsFilePrintf(fp
, "Active Status Path | /var/spool/lp/pod/%s.status\n", p
->name
);
5081 cupsFilePuts(fp
, "Status Update Wait | 10 seconds\n");
5085 chmod(filename
, 0664);
5086 chown(filename
, User
, Group
);
5092 * 'write_irix_state()' - Update the status files used by IRIX printing
5097 write_irix_state(cupsd_printer_t
*p
) /* I - Printer to update */
5099 char filename
[1024]; /* Interface script filename */
5100 cups_file_t
*fp
; /* Interface script file */
5101 int tag
; /* Status tag value */
5107 * The POD status file is needed for the printstatus window to
5108 * provide the current status of the printer.
5111 snprintf(filename
, sizeof(filename
), "/var/spool/lp/pod/%s.status", p
->name
);
5113 if (p
->type
& CUPS_PRINTER_CLASS
)
5115 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
5117 cupsFilePrintf(fp
, "Operational Status | %s\n",
5118 (p
->state
== IPP_PRINTER_IDLE
) ? "Idle" :
5119 (p
->state
== IPP_PRINTER_PROCESSING
) ? "Busy" :
5121 cupsFilePrintf(fp
, "Information | 01 00 00 | %s\n", CUPS_SVERSION
);
5122 cupsFilePrintf(fp
, "Information | 02 00 00 | Device URI: %s\n",
5124 cupsFilePrintf(fp
, "Information | 03 00 00 | %s jobs\n",
5125 p
->accepting
? "Accepting" : "Not accepting");
5126 cupsFilePrintf(fp
, "Information | 04 00 00 | %s\n", p
->state_message
);
5130 chmod(filename
, 0664);
5131 chown(filename
, User
, Group
);
5135 * The activeicons file is needed to provide desktop icons for printers:
5137 * [ quoted from /usr/lib/print/tagit ]
5139 * --- Type of printer tags (base values)
5141 * Dumb=66048 # 0x10200
5142 * DumbColor=66080 # 0x10220
5143 * Raster=66112 # 0x10240
5144 * ColorRaster=66144 # 0x10260
5145 * Plotter=66176 # 0x10280
5146 * PostScript=66208 # 0x102A0
5147 * ColorPostScript=66240 # 0x102C0
5148 * MonoPostScript=66272 # 0x102E0
5150 * --- Printer state modifiers for local printers
5155 * Unknown=3 # 0x3 (Faulted due to unknown reason)
5157 * --- Printer state modifiers for network printers
5161 * NetFaulted=10 # 0xA
5162 * NetUnknown=11 # 0xB (Faulted due to unknown reason)
5165 snprintf(filename
, sizeof(filename
), "/var/spool/lp/activeicons/%s", p
->name
);
5167 if (p
->type
& CUPS_PRINTER_CLASS
)
5169 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
5171 if (p
->type
& CUPS_PRINTER_COLOR
)
5176 if (p
->type
& CUPS_PRINTER_REMOTE
)
5179 if (p
->state
== IPP_PRINTER_PROCESSING
)
5182 else if (p
->state
== IPP_PRINTER_STOPPED
)
5185 cupsFilePuts(fp
, "#!/bin/sh\n");
5186 cupsFilePrintf(fp
, "#Tag %d\n", tag
);
5190 chmod(filename
, 0755);
5191 chown(filename
, User
, Group
);
5196 * The default file is needed by the printers window to show
5197 * the default printer.
5200 snprintf(filename
, sizeof(filename
), "/var/spool/lp/default");
5202 if (DefaultPrinter
!= NULL
)
5204 if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
5206 cupsFilePrintf(fp
, "%s\n", DefaultPrinter
->name
);
5210 chmod(filename
, 0644);
5211 chown(filename
, User
, Group
);
5221 * 'write_xml_string()' - Write a string with XML escaping.
5225 write_xml_string(cups_file_t
*fp
, /* I - File to write to */
5226 const char *s
) /* I - String to write */
5228 const char *start
; /* Start of current sequence */
5234 for (start
= s
; *s
; s
++)
5239 cupsFileWrite(fp
, start
, s
- start
);
5241 cupsFilePuts(fp
, "&");
5247 cupsFileWrite(fp
, start
, s
- start
);
5249 cupsFilePuts(fp
, "<");
5255 cupsFilePuts(fp
, start
);
5260 * End of "$Id: printers.c 7968 2008-09-19 23:03:01Z mike $".