2 * "$Id: printers.c 7968 2008-09-19 23:03:01Z mike $"
4 * Printer routines for the CUPS scheduler.
6 * Copyright 2007-2012 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", sizeof(ops
) / sizeof(ops
[0]), ops
);
645 /* orientation-requested-supported */
646 ippAddIntegers(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
647 "orientation-requested-supported", 4, orients
);
649 /* page-ranges-supported */
650 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
, "page-ranges-supported", 1);
652 /* pdf-k-octets-supported */
653 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "pdf-k-octets-supported", 0,
656 /* pdf-versions-supported */
657 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
658 "pdf-versions-supported",
659 sizeof(pdf_versions
) / sizeof(pdf_versions
[0]), NULL
,
662 /* pdl-override-supported */
663 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
664 "pdl-override-supported", NULL
, "attempted");
666 /* printer-op-policy-supported */
667 attr
= ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
668 "printer-op-policy-supported", cupsArrayCount(Policies
),
670 for (i
= 0, p
= (cupsd_policy_t
*)cupsArrayFirst(Policies
);
672 i
++, p
= (cupsd_policy_t
*)cupsArrayNext(Policies
))
673 attr
->values
[i
].string
.text
= p
->name
;
675 /* printer-settable-attributes-supported */
676 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
677 "printer-settable-attributes-supported",
678 sizeof(printer_settable
) / sizeof(printer_settable
[0]),
679 NULL
, printer_settable
);
681 /* server-is-sharing-printers */
682 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
, "server-is-sharing-printers",
683 BrowseLocalProtocols
!= 0 && Browsing
);
685 /* which-jobs-supported */
686 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
687 "which-jobs-supported",
688 sizeof(which_jobs
) / sizeof(which_jobs
[0]), NULL
, which_jobs
);
693 * 'cupsdDeleteAllPrinters()' - Delete all printers from the system.
697 cupsdDeleteAllPrinters(void)
699 cupsd_printer_t
*p
; /* Pointer to current printer/class */
702 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
704 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
706 p
->op_policy_ptr
= DefaultPolicyPtr
;
707 cupsdDeletePrinter(p
, 0);
713 * 'cupsdDeletePrinter()' - Delete a printer from the system.
716 int /* O - 1 if classes affected, 0 otherwise */
718 cupsd_printer_t
*p
, /* I - Printer to delete */
719 int update
) /* I - Update printers.conf? */
721 int i
, /* Looping var */
722 changed
= 0; /* Class changed? */
724 char filename
[1024]; /* Interface script filename */
728 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdDeletePrinter(p=%p(%s), update=%d)",
732 * Save the current position in the Printers array...
735 cupsArraySave(Printers
);
738 * Stop printing on this printer...
741 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, update
);
743 p
->state
= IPP_PRINTER_STOPPED
; /* Force for browsed printers */
746 cupsdSetJobState(p
->job
, IPP_JOB_PENDING
, CUPSD_JOB_FORCE
,
747 update
? "Job stopped due to printer being deleted." :
751 * Remove the printer from the list...
754 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
755 "cupsdDeletePrinter: Removing %s from Printers", p
->name
);
756 cupsArrayRemove(Printers
, p
);
759 * Remove the dummy interface/icon/option files under IRIX...
763 snprintf(filename
, sizeof(filename
), "/var/spool/lp/interface/%s", p
->name
);
766 snprintf(filename
, sizeof(filename
), "/var/spool/lp/gui_interface/ELF/%s.gui",
770 snprintf(filename
, sizeof(filename
), "/var/spool/lp/activeicons/%s", p
->name
);
773 snprintf(filename
, sizeof(filename
), "/var/spool/lp/pod/%s.config", p
->name
);
776 snprintf(filename
, sizeof(filename
), "/var/spool/lp/pod/%s.status", p
->name
);
779 snprintf(filename
, sizeof(filename
), "/var/spool/lp/member/%s", p
->name
);
784 * If p is the default printer, assign a different one...
787 if (p
== DefaultPrinter
)
788 DefaultPrinter
= NULL
;
791 * Remove this printer from any classes...
794 changed
= cupsdDeletePrinterFromClasses(p
);
797 * Deregister from any browse protocols...
800 cupsdDeregisterPrinter(p
, 1);
803 * Free all memory used by the printer...
806 if (p
->printers
!= NULL
)
809 delete_printer_filters(p
);
811 for (i
= 0; i
< p
->num_reasons
; i
++)
812 _cupsStrFree(p
->reasons
[i
]);
815 ippDelete(p
->ppd_attrs
);
817 mimeDeleteType(MimeDatabase
, p
->filetype
);
818 mimeDeleteType(MimeDatabase
, p
->prefiltertype
);
820 cupsdFreeStrings(&(p
->users
));
823 cupsdClearString(&p
->uri
);
824 cupsdClearString(&p
->hostname
);
825 cupsdClearString(&p
->name
);
826 cupsdClearString(&p
->location
);
827 cupsdClearString(&p
->make_model
);
828 cupsdClearString(&p
->info
);
829 cupsdClearString(&p
->job_sheets
[0]);
830 cupsdClearString(&p
->job_sheets
[1]);
831 cupsdClearString(&p
->device_uri
);
832 cupsdClearString(&p
->sanitized_device_uri
);
833 cupsdClearString(&p
->port_monitor
);
834 cupsdClearString(&p
->op_policy
);
835 cupsdClearString(&p
->error_policy
);
837 cupsdClearString(&p
->alert
);
838 cupsdClearString(&p
->alert_description
);
841 cupsdClearString(&p
->pdl
);
842 #endif /* HAVE_DNSSD */
844 cupsArrayDelete(p
->filetypes
);
846 cupsFreeOptions(p
->num_options
, p
->options
);
851 * Restore the previous position in the Printers array...
854 cupsArrayRestore(Printers
);
861 * 'cupsdFindDest()' - Find a destination in the list.
864 cupsd_printer_t
* /* O - Destination in list */
865 cupsdFindDest(const char *name
) /* I - Name of printer or class to find */
867 cupsd_printer_t key
; /* Search key */
870 key
.name
= (char *)name
;
871 return ((cupsd_printer_t
*)cupsArrayFind(Printers
, &key
));
876 * 'cupsdFindPrinter()' - Find a printer in the list.
879 cupsd_printer_t
* /* O - Printer in list */
880 cupsdFindPrinter(const char *name
) /* I - Name of printer to find */
882 cupsd_printer_t
*p
; /* Printer in list */
885 if ((p
= cupsdFindDest(name
)) != NULL
&& (p
->type
& CUPS_PRINTER_CLASS
))
893 * 'cupsdLoadAllPrinters()' - Load printers from the printers.conf file.
897 cupsdLoadAllPrinters(void)
899 int i
; /* Looping var */
900 cups_file_t
*fp
; /* printers.conf file */
901 int linenum
; /* Current line number */
902 char line
[4096], /* Line from file */
903 *value
, /* Pointer to value */
904 *valueptr
; /* Pointer into value */
905 cupsd_printer_t
*p
; /* Current printer */
909 * Open the printers.conf file...
912 snprintf(line
, sizeof(line
), "%s/printers.conf", ServerRoot
);
913 if ((fp
= cupsdOpenConfFile(line
)) == NULL
)
917 * Read printer configurations until we hit EOF...
923 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
926 * Decode the directive...
929 if (!_cups_strcasecmp(line
, "<Printer") ||
930 !_cups_strcasecmp(line
, "<DefaultPrinter"))
933 * <Printer name> or <DefaultPrinter name>
936 if (p
== NULL
&& value
)
939 * Add the printer and a base file type...
942 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Loading printer %s...", value
);
944 p
= cupsdAddPrinter(value
);
946 p
->state
= IPP_PRINTER_IDLE
;
949 * Set the default printer as needed...
952 if (!_cups_strcasecmp(line
, "<DefaultPrinter"))
956 cupsdLogMessage(CUPSD_LOG_ERROR
,
957 "Syntax error on line %d of printers.conf.", linenum
);
959 else if (!_cups_strcasecmp(line
, "</Printer>"))
964 * Close out the current printer...
967 cupsdSetPrinterAttrs(p
);
969 if (strncmp(p
->device_uri
, "file:", 5) &&
970 p
->state
!= IPP_PRINTER_STOPPED
)
973 * See if the backend exists...
976 snprintf(line
, sizeof(line
), "%s/backend/%s", ServerBin
,
979 if ((valueptr
= strchr(line
+ strlen(ServerBin
), ':')) != NULL
)
980 *valueptr
= '\0'; /* Chop everything but URI scheme */
985 * Backend does not exist, stop printer...
988 p
->state
= IPP_PRINTER_STOPPED
;
989 snprintf(p
->state_message
, sizeof(p
->state_message
),
990 "Backend %s does not exist!", line
);
997 cupsdLogMessage(CUPSD_LOG_ERROR
,
998 "Syntax error on line %d of printers.conf.", linenum
);
1002 cupsdLogMessage(CUPSD_LOG_ERROR
,
1003 "Syntax error on line %d of printers.conf.", linenum
);
1005 else if (!_cups_strcasecmp(line
, "UUID"))
1007 if (value
&& !strncmp(value
, "urn:uuid:", 9))
1008 cupsdSetString(&(p
->uuid
), value
);
1010 cupsdLogMessage(CUPSD_LOG_ERROR
,
1011 "Bad UUID on line %d of printers.conf.", linenum
);
1013 else if (!_cups_strcasecmp(line
, "AuthInfoRequired"))
1015 if (!cupsdSetAuthInfoRequired(p
, value
, NULL
))
1016 cupsdLogMessage(CUPSD_LOG_ERROR
,
1017 "Bad AuthInfoRequired on line %d of printers.conf.",
1020 else if (!_cups_strcasecmp(line
, "Info"))
1023 cupsdSetString(&p
->info
, value
);
1025 else if (!_cups_strcasecmp(line
, "MakeModel"))
1028 cupsdSetString(&p
->make_model
, value
);
1030 else if (!_cups_strcasecmp(line
, "Location"))
1033 cupsdSetString(&p
->location
, value
);
1035 else if (!_cups_strcasecmp(line
, "DeviceURI"))
1038 cupsdSetDeviceURI(p
, value
);
1040 cupsdLogMessage(CUPSD_LOG_ERROR
,
1041 "Syntax error on line %d of printers.conf.", linenum
);
1043 else if (!_cups_strcasecmp(line
, "Option") && value
)
1049 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1052 cupsdLogMessage(CUPSD_LOG_ERROR
,
1053 "Syntax error on line %d of printers.conf.", linenum
);
1056 for (; *valueptr
&& isspace(*valueptr
& 255); *valueptr
++ = '\0');
1058 p
->num_options
= cupsAddOption(value
, valueptr
, p
->num_options
,
1062 else if (!_cups_strcasecmp(line
, "PortMonitor"))
1064 if (value
&& strcmp(value
, "none"))
1065 cupsdSetString(&p
->port_monitor
, value
);
1067 cupsdClearString(&p
->port_monitor
);
1069 cupsdLogMessage(CUPSD_LOG_ERROR
,
1070 "Syntax error on line %d of printers.conf.", linenum
);
1072 else if (!_cups_strcasecmp(line
, "Reason"))
1075 strcmp(value
, "connecting-to-device") &&
1076 strcmp(value
, "cups-insecure-filter-warning") &&
1077 strcmp(value
, "cups-missing-filter-warning"))
1079 for (i
= 0 ; i
< p
->num_reasons
; i
++)
1080 if (!strcmp(value
, p
->reasons
[i
]))
1083 if (i
>= p
->num_reasons
&&
1084 p
->num_reasons
< (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
1086 p
->reasons
[p
->num_reasons
] = _cupsStrAlloc(value
);
1091 cupsdLogMessage(CUPSD_LOG_ERROR
,
1092 "Syntax error on line %d of printers.conf.", linenum
);
1094 else if (!_cups_strcasecmp(line
, "State"))
1097 * Set the initial queue state...
1100 if (value
&& !_cups_strcasecmp(value
, "idle"))
1101 p
->state
= IPP_PRINTER_IDLE
;
1102 else if (value
&& !_cups_strcasecmp(value
, "stopped"))
1104 p
->state
= IPP_PRINTER_STOPPED
;
1106 for (i
= 0 ; i
< p
->num_reasons
; i
++)
1107 if (!strcmp("paused", p
->reasons
[i
]))
1110 if (i
>= p
->num_reasons
&&
1111 p
->num_reasons
< (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
1113 p
->reasons
[p
->num_reasons
] = _cupsStrAlloc("paused");
1118 cupsdLogMessage(CUPSD_LOG_ERROR
,
1119 "Syntax error on line %d of printers.conf.", linenum
);
1121 else if (!_cups_strcasecmp(line
, "StateMessage"))
1124 * Set the initial queue state message...
1128 strlcpy(p
->state_message
, value
, sizeof(p
->state_message
));
1130 else if (!_cups_strcasecmp(line
, "StateTime"))
1133 * Set the state time...
1137 p
->state_time
= atoi(value
);
1139 else if (!_cups_strcasecmp(line
, "Accepting"))
1142 * Set the initial accepting state...
1146 (!_cups_strcasecmp(value
, "yes") ||
1147 !_cups_strcasecmp(value
, "on") ||
1148 !_cups_strcasecmp(value
, "true")))
1151 (!_cups_strcasecmp(value
, "no") ||
1152 !_cups_strcasecmp(value
, "off") ||
1153 !_cups_strcasecmp(value
, "false")))
1156 cupsdLogMessage(CUPSD_LOG_ERROR
,
1157 "Syntax error on line %d of printers.conf.", linenum
);
1159 else if (!_cups_strcasecmp(line
, "Type"))
1162 p
->type
= atoi(value
);
1164 cupsdLogMessage(CUPSD_LOG_ERROR
,
1165 "Syntax error on line %d of printers.conf.", linenum
);
1167 else if (!_cups_strcasecmp(line
, "Shared"))
1170 * Set the initial shared state...
1174 (!_cups_strcasecmp(value
, "yes") ||
1175 !_cups_strcasecmp(value
, "on") ||
1176 !_cups_strcasecmp(value
, "true")))
1179 (!_cups_strcasecmp(value
, "no") ||
1180 !_cups_strcasecmp(value
, "off") ||
1181 !_cups_strcasecmp(value
, "false")))
1184 cupsdLogMessage(CUPSD_LOG_ERROR
,
1185 "Syntax error on line %d of printers.conf.", linenum
);
1187 else if (!_cups_strcasecmp(line
, "JobSheets"))
1190 * Set the initial job sheets...
1195 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1200 cupsdSetString(&p
->job_sheets
[0], value
);
1202 while (isspace(*valueptr
& 255))
1207 for (value
= valueptr
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1212 cupsdSetString(&p
->job_sheets
[1], value
);
1216 cupsdLogMessage(CUPSD_LOG_ERROR
,
1217 "Syntax error on line %d of printers.conf.", linenum
);
1219 else if (!_cups_strcasecmp(line
, "AllowUser"))
1224 cupsdAddString(&(p
->users
), value
);
1227 cupsdLogMessage(CUPSD_LOG_ERROR
,
1228 "Syntax error on line %d of printers.conf.", linenum
);
1230 else if (!_cups_strcasecmp(line
, "DenyUser"))
1235 cupsdAddString(&(p
->users
), value
);
1238 cupsdLogMessage(CUPSD_LOG_ERROR
,
1239 "Syntax error on line %d of printers.conf.", linenum
);
1241 else if (!_cups_strcasecmp(line
, "QuotaPeriod"))
1244 p
->quota_period
= atoi(value
);
1246 cupsdLogMessage(CUPSD_LOG_ERROR
,
1247 "Syntax error on line %d of printers.conf.", linenum
);
1249 else if (!_cups_strcasecmp(line
, "PageLimit"))
1252 p
->page_limit
= atoi(value
);
1254 cupsdLogMessage(CUPSD_LOG_ERROR
,
1255 "Syntax error on line %d of printers.conf.", linenum
);
1257 else if (!_cups_strcasecmp(line
, "KLimit"))
1260 p
->k_limit
= atoi(value
);
1262 cupsdLogMessage(CUPSD_LOG_ERROR
,
1263 "Syntax error on line %d of printers.conf.", linenum
);
1265 else if (!_cups_strcasecmp(line
, "OpPolicy"))
1269 cupsd_policy_t
*pol
; /* Policy */
1272 if ((pol
= cupsdFindPolicy(value
)) != NULL
)
1274 cupsdSetString(&p
->op_policy
, value
);
1275 p
->op_policy_ptr
= pol
;
1278 cupsdLogMessage(CUPSD_LOG_ERROR
,
1279 "Bad policy \"%s\" on line %d of printers.conf",
1283 cupsdLogMessage(CUPSD_LOG_ERROR
,
1284 "Syntax error on line %d of printers.conf.", linenum
);
1286 else if (!_cups_strcasecmp(line
, "ErrorPolicy"))
1289 cupsdSetString(&p
->error_policy
, value
);
1291 cupsdLogMessage(CUPSD_LOG_ERROR
,
1292 "Syntax error on line %d of printers.conf.", linenum
);
1294 else if (!_cups_strcasecmp(line
, "Attribute") && value
)
1296 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1299 cupsdLogMessage(CUPSD_LOG_ERROR
,
1300 "Syntax error on line %d of printers.conf.", linenum
);
1303 for (; *valueptr
&& isspace(*valueptr
& 255); *valueptr
++ = '\0');
1306 cupsdSetPrinterAttrs(p
);
1308 if (!strcmp(value
, "marker-change-time"))
1309 p
->marker_time
= atoi(valueptr
);
1311 cupsdSetPrinterAttr(p
, value
, valueptr
);
1314 else if (_cups_strcasecmp(line
, "Filter") &&
1315 _cups_strcasecmp(line
, "Prefilter") &&
1316 _cups_strcasecmp(line
, "Product"))
1319 * Something else we don't understand (and that wasn't used in a prior
1320 * release of CUPS...
1323 cupsdLogMessage(CUPSD_LOG_ERROR
,
1324 "Unknown configuration directive %s on line %d of "
1325 "printers.conf.", line
, linenum
);
1334 * 'cupsdRenamePrinter()' - Rename a printer.
1339 cupsd_printer_t
*p
, /* I - Printer */
1340 const char *name
) /* I - New name */
1343 * Remove the printer from the array(s) first...
1346 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1347 "cupsdRenamePrinter: Removing %s from Printers", p
->name
);
1348 cupsArrayRemove(Printers
, p
);
1351 * Rename the printer type...
1354 mimeDeleteType(MimeDatabase
, p
->filetype
);
1355 p
->filetype
= mimeAddType(MimeDatabase
, "printer", name
);
1357 if (p
->prefiltertype
)
1359 mimeDeleteType(MimeDatabase
, p
->prefiltertype
);
1360 p
->prefiltertype
= mimeAddType(MimeDatabase
, "prefilter", name
);
1364 * Rename the printer...
1367 cupsdSetString(&p
->name
, name
);
1370 * Reset printer attributes...
1373 cupsdSetPrinterAttrs(p
);
1376 * Add the printer back to the printer array(s)...
1379 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1380 "cupsdRenamePrinter: Adding %s to Printers", p
->name
);
1381 cupsArrayAdd(Printers
, p
);
1386 * 'cupsdSaveAllPrinters()' - Save all printer definitions to the printers.conf
1391 cupsdSaveAllPrinters(void)
1393 int i
; /* Looping var */
1394 cups_file_t
*fp
; /* printers.conf file */
1395 char filename
[1024], /* printers.conf filename */
1396 temp
[1024], /* Temporary string */
1397 value
[2048], /* Value string */
1398 *ptr
, /* Pointer into value */
1399 *name
; /* Current user/group name */
1400 cupsd_printer_t
*printer
; /* Current printer class */
1401 time_t curtime
; /* Current time */
1402 struct tm
*curdate
; /* Current date */
1403 cups_option_t
*option
; /* Current option */
1404 ipp_attribute_t
*marker
; /* Current marker attribute */
1408 * Create the printers.conf file...
1411 snprintf(filename
, sizeof(filename
), "%s/printers.conf", ServerRoot
);
1413 if ((fp
= cupsdCreateConfFile(filename
, ConfigFilePerm
& 0600)) == NULL
)
1416 cupsdLogMessage(CUPSD_LOG_INFO
, "Saving printers.conf...");
1419 * Write a small header to the file...
1422 curtime
= time(NULL
);
1423 curdate
= localtime(&curtime
);
1424 strftime(temp
, sizeof(temp
) - 1, "%Y-%m-%d %H:%M", curdate
);
1426 cupsFilePuts(fp
, "# Printer configuration file for " CUPS_SVERSION
"\n");
1427 cupsFilePrintf(fp
, "# Written by cupsd on %s\n", temp
);
1428 cupsFilePuts(fp
, "# DO NOT EDIT THIS FILE WHEN CUPSD IS RUNNING\n");
1431 * Write each local printer known to the system...
1434 for (printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
1436 printer
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
1439 * Skip printer classes...
1442 if (printer
->type
& CUPS_PRINTER_CLASS
)
1446 * Write printers as needed...
1449 if (printer
== DefaultPrinter
)
1450 cupsFilePrintf(fp
, "<DefaultPrinter %s>\n", printer
->name
);
1452 cupsFilePrintf(fp
, "<Printer %s>\n", printer
->name
);
1454 cupsFilePrintf(fp
, "UUID %s\n", printer
->uuid
);
1456 if (printer
->num_auth_info_required
> 0)
1458 switch (printer
->num_auth_info_required
)
1461 strlcpy(value
, printer
->auth_info_required
[0], sizeof(value
));
1465 snprintf(value
, sizeof(value
), "%s,%s",
1466 printer
->auth_info_required
[0],
1467 printer
->auth_info_required
[1]);
1472 snprintf(value
, sizeof(value
), "%s,%s,%s",
1473 printer
->auth_info_required
[0],
1474 printer
->auth_info_required
[1],
1475 printer
->auth_info_required
[2]);
1479 cupsFilePutConf(fp
, "AuthInfoRequired", value
);
1483 cupsFilePutConf(fp
, "Info", printer
->info
);
1485 if (printer
->location
)
1486 cupsFilePutConf(fp
, "Location", printer
->location
);
1488 if (printer
->make_model
)
1489 cupsFilePutConf(fp
, "MakeModel", printer
->make_model
);
1491 cupsFilePutConf(fp
, "DeviceURI", printer
->device_uri
);
1493 if (printer
->port_monitor
)
1494 cupsFilePutConf(fp
, "PortMonitor", printer
->port_monitor
);
1496 if (printer
->state
== IPP_PRINTER_STOPPED
)
1498 cupsFilePuts(fp
, "State Stopped\n");
1500 if (printer
->state_message
)
1501 cupsFilePutConf(fp
, "StateMessage", printer
->state_message
);
1504 cupsFilePuts(fp
, "State Idle\n");
1506 cupsFilePrintf(fp
, "StateTime %d\n", (int)printer
->state_time
);
1508 for (i
= 0; i
< printer
->num_reasons
; i
++)
1509 if (strcmp(printer
->reasons
[i
], "connecting-to-device") &&
1510 strcmp(printer
->reasons
[i
], "cups-insecure-filter-warning") &&
1511 strcmp(printer
->reasons
[i
], "cups-missing-filter-warning"))
1512 cupsFilePutConf(fp
, "Reason", printer
->reasons
[i
]);
1514 cupsFilePrintf(fp
, "Type %d\n", printer
->type
);
1516 if (printer
->accepting
)
1517 cupsFilePuts(fp
, "Accepting Yes\n");
1519 cupsFilePuts(fp
, "Accepting No\n");
1521 if (printer
->shared
)
1522 cupsFilePuts(fp
, "Shared Yes\n");
1524 cupsFilePuts(fp
, "Shared No\n");
1526 snprintf(value
, sizeof(value
), "%s %s", printer
->job_sheets
[0],
1527 printer
->job_sheets
[1]);
1528 cupsFilePutConf(fp
, "JobSheets", value
);
1530 cupsFilePrintf(fp
, "QuotaPeriod %d\n", printer
->quota_period
);
1531 cupsFilePrintf(fp
, "PageLimit %d\n", printer
->page_limit
);
1532 cupsFilePrintf(fp
, "KLimit %d\n", printer
->k_limit
);
1534 for (name
= (char *)cupsArrayFirst(printer
->users
);
1536 name
= (char *)cupsArrayNext(printer
->users
))
1537 cupsFilePutConf(fp
, printer
->deny_users
? "DenyUser" : "AllowUser", name
);
1539 if (printer
->op_policy
)
1540 cupsFilePutConf(fp
, "OpPolicy", printer
->op_policy
);
1541 if (printer
->error_policy
)
1542 cupsFilePutConf(fp
, "ErrorPolicy", printer
->error_policy
);
1544 for (i
= printer
->num_options
, option
= printer
->options
;
1548 snprintf(value
, sizeof(value
), "%s %s", option
->name
, option
->value
);
1549 cupsFilePutConf(fp
, "Option", value
);
1552 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-colors",
1553 IPP_TAG_NAME
)) != NULL
)
1555 snprintf(value
, sizeof(value
), "%s ", marker
->name
);
1557 for (i
= 0, ptr
= value
+ strlen(value
);
1558 i
< marker
->num_values
&& ptr
< (value
+ sizeof(value
) - 1);
1564 strlcpy(ptr
, marker
->values
[i
].string
.text
,
1565 value
+ sizeof(value
) - ptr
);
1570 cupsFilePutConf(fp
, "Attribute", value
);
1573 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-levels",
1574 IPP_TAG_INTEGER
)) != NULL
)
1576 cupsFilePrintf(fp
, "Attribute %s %d", marker
->name
,
1577 marker
->values
[0].integer
);
1578 for (i
= 1; i
< marker
->num_values
; i
++)
1579 cupsFilePrintf(fp
, ",%d", marker
->values
[i
].integer
);
1580 cupsFilePuts(fp
, "\n");
1583 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-low-levels",
1584 IPP_TAG_INTEGER
)) != NULL
)
1586 cupsFilePrintf(fp
, "Attribute %s %d", marker
->name
,
1587 marker
->values
[0].integer
);
1588 for (i
= 1; i
< marker
->num_values
; i
++)
1589 cupsFilePrintf(fp
, ",%d", marker
->values
[i
].integer
);
1590 cupsFilePuts(fp
, "\n");
1593 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-high-levels",
1594 IPP_TAG_INTEGER
)) != NULL
)
1596 cupsFilePrintf(fp
, "Attribute %s %d", marker
->name
,
1597 marker
->values
[0].integer
);
1598 for (i
= 1; i
< marker
->num_values
; i
++)
1599 cupsFilePrintf(fp
, ",%d", marker
->values
[i
].integer
);
1600 cupsFilePuts(fp
, "\n");
1603 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-message",
1604 IPP_TAG_TEXT
)) != NULL
)
1606 snprintf(value
, sizeof(value
), "%s %s", marker
->name
,
1607 marker
->values
[0].string
.text
);
1609 cupsFilePutConf(fp
, "Attribute", value
);
1612 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-names",
1613 IPP_TAG_NAME
)) != NULL
)
1615 snprintf(value
, sizeof(value
), "%s ", marker
->name
);
1617 for (i
= 0, ptr
= value
+ strlen(value
);
1618 i
< marker
->num_values
&& ptr
< (value
+ sizeof(value
) - 1);
1624 strlcpy(ptr
, marker
->values
[i
].string
.text
,
1625 value
+ sizeof(value
) - ptr
);
1630 cupsFilePutConf(fp
, "Attribute", value
);
1633 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-types",
1634 IPP_TAG_KEYWORD
)) != NULL
)
1636 snprintf(value
, sizeof(value
), "%s ", marker
->name
);
1638 for (i
= 0, ptr
= value
+ strlen(value
);
1639 i
< marker
->num_values
&& ptr
< (value
+ sizeof(value
) - 1);
1645 strlcpy(ptr
, marker
->values
[i
].string
.text
,
1646 value
+ sizeof(value
) - ptr
);
1651 cupsFilePutConf(fp
, "Attribute", value
);
1654 if (printer
->marker_time
)
1655 cupsFilePrintf(fp
, "Attribute marker-change-time %ld\n",
1656 (long)printer
->marker_time
);
1658 cupsFilePuts(fp
, "</Printer>\n");
1662 * Make IRIX desktop & printer status happy
1665 write_irix_state(printer
);
1669 cupsdCloseCreatedConfFile(fp
, filename
);
1674 * 'cupsdSetAuthInfoRequired()' - Set the required authentication info.
1677 int /* O - 1 if value OK, 0 otherwise */
1678 cupsdSetAuthInfoRequired(
1679 cupsd_printer_t
*p
, /* I - Printer */
1680 const char *values
, /* I - Plain text value (or NULL) */
1681 ipp_attribute_t
*attr
) /* I - IPP attribute value (or NULL) */
1683 int i
; /* Looping var */
1686 p
->num_auth_info_required
= 0;
1689 * Do we have a plain text value?
1695 * Yes, grab the keywords...
1698 const char *end
; /* End of current value */
1701 while (*values
&& p
->num_auth_info_required
< 4)
1703 if ((end
= strchr(values
, ',')) == NULL
)
1704 end
= values
+ strlen(values
);
1706 if ((end
- values
) == 4 && !strncmp(values
, "none", 4))
1708 if (p
->num_auth_info_required
!= 0 || *end
)
1711 p
->auth_info_required
[p
->num_auth_info_required
] = "none";
1712 p
->num_auth_info_required
++;
1716 else if ((end
- values
) == 9 && !strncmp(values
, "negotiate", 9))
1718 if (p
->num_auth_info_required
!= 0 || *end
)
1721 p
->auth_info_required
[p
->num_auth_info_required
] = "negotiate";
1722 p
->num_auth_info_required
++;
1725 * Don't allow sharing of queues that require Kerberos authentication.
1730 cupsdDeregisterPrinter(p
, 1);
1734 else if ((end
- values
) == 6 && !strncmp(values
, "domain", 6))
1736 p
->auth_info_required
[p
->num_auth_info_required
] = "domain";
1737 p
->num_auth_info_required
++;
1739 else if ((end
- values
) == 8 && !strncmp(values
, "password", 8))
1741 p
->auth_info_required
[p
->num_auth_info_required
] = "password";
1742 p
->num_auth_info_required
++;
1744 else if ((end
- values
) == 8 && !strncmp(values
, "username", 8))
1746 p
->auth_info_required
[p
->num_auth_info_required
] = "username";
1747 p
->num_auth_info_required
++;
1752 values
= (*end
) ? end
+ 1 : end
;
1755 if (p
->num_auth_info_required
== 0)
1757 p
->auth_info_required
[0] = "none";
1758 p
->num_auth_info_required
= 1;
1762 * Update the printer-type value as needed...
1765 if (p
->num_auth_info_required
> 1 ||
1766 strcmp(p
->auth_info_required
[0], "none"))
1767 p
->type
|= CUPS_PRINTER_AUTHENTICATED
;
1769 p
->type
&= ~CUPS_PRINTER_AUTHENTICATED
;
1775 * Grab values from an attribute instead...
1778 if (!attr
|| attr
->num_values
> 4)
1781 for (i
= 0; i
< attr
->num_values
; i
++)
1783 if (!strcmp(attr
->values
[i
].string
.text
, "none"))
1785 if (p
->num_auth_info_required
!= 0 || attr
->num_values
!= 1)
1788 p
->auth_info_required
[p
->num_auth_info_required
] = "none";
1789 p
->num_auth_info_required
++;
1793 else if (!strcmp(attr
->values
[i
].string
.text
, "negotiate"))
1795 if (p
->num_auth_info_required
!= 0 || attr
->num_values
!= 1)
1798 p
->auth_info_required
[p
->num_auth_info_required
] = "negotiate";
1799 p
->num_auth_info_required
++;
1802 * Don't allow sharing of queues that require Kerberos authentication.
1807 cupsdDeregisterPrinter(p
, 1);
1813 else if (!strcmp(attr
->values
[i
].string
.text
, "domain"))
1815 p
->auth_info_required
[p
->num_auth_info_required
] = "domain";
1816 p
->num_auth_info_required
++;
1818 else if (!strcmp(attr
->values
[i
].string
.text
, "password"))
1820 p
->auth_info_required
[p
->num_auth_info_required
] = "password";
1821 p
->num_auth_info_required
++;
1823 else if (!strcmp(attr
->values
[i
].string
.text
, "username"))
1825 p
->auth_info_required
[p
->num_auth_info_required
] = "username";
1826 p
->num_auth_info_required
++;
1837 * 'cupsdSetDeviceURI()' - Set the device URI for a printer.
1841 cupsdSetDeviceURI(cupsd_printer_t
*p
, /* I - Printer */
1842 const char *uri
) /* I - Device URI */
1844 char buffer
[1024], /* URI buffer */
1845 *start
, /* Start of data after scheme */
1846 *slash
, /* First slash after scheme:// */
1847 *ptr
; /* Pointer into user@host:port part */
1851 * Set the full device URI..
1854 cupsdSetString(&(p
->device_uri
), uri
);
1857 * Copy the device URI to a temporary buffer so we can sanitize any auth
1861 strlcpy(buffer
, uri
, sizeof(buffer
));
1864 * Find the end of the scheme:// part...
1867 if ((ptr
= strchr(buffer
, ':')) != NULL
)
1869 for (start
= ptr
+ 1; *start
; start
++)
1874 * Find the next slash (/) in the URI...
1877 if ((slash
= strchr(start
, '/')) == NULL
)
1878 slash
= start
+ strlen(start
); /* No slash, point to the end */
1881 * Check for an @ sign before the slash...
1884 if ((ptr
= strchr(start
, '@')) != NULL
&& ptr
< slash
)
1887 * Found an @ sign and it is before the resource part, so we have
1888 * an authentication string. Copy the remaining URI over the
1889 * authentication string...
1892 _cups_strcpy(start
, ptr
+ 1);
1897 * Save the sanitized URI...
1900 cupsdSetString(&(p
->sanitized_device_uri
), buffer
);
1905 * 'cupsdSetPrinterAttr()' - Set a printer attribute.
1909 cupsdSetPrinterAttr(
1910 cupsd_printer_t
*p
, /* I - Printer */
1911 const char *name
, /* I - Attribute name */
1912 char *value
) /* I - Attribute value string */
1914 ipp_attribute_t
*attr
; /* Attribute */
1915 int i
, /* Looping var */
1916 count
; /* Number of values */
1917 char *ptr
, /* Pointer into value */
1918 *start
, /* Start of value */
1919 quote
; /* Quote character */
1920 ipp_tag_t value_tag
; /* Value tag for this attribute */
1924 * Don't allow empty values...
1927 if (!*value
&& strcmp(name
, "marker-message"))
1929 cupsdLogMessage(CUPSD_LOG_ERROR
, "Ignoring empty \"%s\" attribute", name
);
1934 * Count the number of values...
1937 for (count
= 1, quote
= '\0', ptr
= value
;
1945 else if (*ptr
== '\\' && ptr
[1])
1947 else if (*ptr
== '\'' || *ptr
== '\"')
1949 else if (*ptr
== ',')
1954 * Then add or update the attribute as needed...
1957 if (!strcmp(name
, "marker-levels") || !strcmp(name
, "marker-low-levels") ||
1958 !strcmp(name
, "marker-high-levels"))
1964 if ((attr
= ippFindAttribute(p
->attrs
, name
, IPP_TAG_INTEGER
)) != NULL
&&
1965 attr
->num_values
< count
)
1967 ippDeleteAttribute(p
->attrs
, attr
);
1972 attr
->num_values
= count
;
1974 attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
, name
,
1979 cupsdLogMessage(CUPSD_LOG_ERROR
,
1980 "Unable to allocate memory for printer attribute "
1981 "(%d values)", count
);
1985 for (i
= 0; i
< count
; i
++)
1987 if ((ptr
= strchr(value
, ',')) != NULL
)
1990 attr
->values
[i
].integer
= strtol(value
, NULL
, 10);
1999 * Name or keyword values...
2002 if (!strcmp(name
, "marker-types"))
2003 value_tag
= IPP_TAG_KEYWORD
;
2004 else if (!strcmp(name
, "marker-message"))
2005 value_tag
= IPP_TAG_TEXT
;
2007 value_tag
= IPP_TAG_NAME
;
2009 if ((attr
= ippFindAttribute(p
->attrs
, name
, value_tag
)) != NULL
&&
2010 attr
->num_values
< count
)
2012 ippDeleteAttribute(p
->attrs
, attr
);
2018 for (i
= 0; i
< attr
->num_values
; i
++)
2019 _cupsStrFree(attr
->values
[i
].string
.text
);
2021 attr
->num_values
= count
;
2024 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, value_tag
, name
,
2029 cupsdLogMessage(CUPSD_LOG_ERROR
,
2030 "Unable to allocate memory for printer attribute "
2031 "(%d values)", count
);
2035 for (i
= 0, quote
= '\0', ptr
= value
; i
< count
; i
++)
2037 for (start
= ptr
; *ptr
; ptr
++)
2040 *ptr
= quote
= '\0';
2043 else if (*ptr
== '\\' && ptr
[1])
2044 _cups_strcpy(ptr
, ptr
+ 1);
2045 else if (*ptr
== '\'' || *ptr
== '\"')
2052 _cups_strcpy(ptr
, ptr
+ 1);
2054 else if (*ptr
== ',')
2061 attr
->values
[i
].string
.text
= _cupsStrAlloc(start
);
2068 * 'cupsdSetPrinterAttrs()' - Set printer attributes based upon the PPD file.
2072 cupsdSetPrinterAttrs(cupsd_printer_t
*p
)/* I - Printer to setup */
2074 int i
; /* Looping var */
2075 char resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
2076 int num_air
; /* Number of auth-info-required values */
2077 const char * const *air
; /* auth-info-required values */
2078 cupsd_location_t
*auth
; /* Pointer to authentication element */
2079 const char *auth_supported
; /* Authentication supported */
2080 ipp_t
*oldattrs
; /* Old printer attributes */
2081 ipp_attribute_t
*attr
; /* Attribute data */
2082 char *name
, /* Current user/group name */
2083 *filter
; /* Current filter */
2084 static const char * const air_none
[] =
2085 { /* No authentication */
2088 static const char * const air_userpass
[] =
2089 { /* Basic/Digest authentication */
2095 DEBUG_printf(("cupsdSetPrinterAttrs: entering name = %s, type = %x\n", p
->name
,
2099 * Make sure that we have the common attributes defined...
2103 cupsdCreateCommonData();
2106 * Clear out old filters, if any...
2109 delete_printer_filters(p
);
2112 * Figure out the authentication that is required for the printer.
2115 auth_supported
= "requesting-user-name";
2119 if (p
->num_auth_info_required
> 0 && strcmp(p
->auth_info_required
[0], "none"))
2121 num_air
= p
->num_auth_info_required
;
2122 air
= p
->auth_info_required
;
2124 else if (p
->type
& CUPS_PRINTER_AUTHENTICATED
)
2130 if (p
->type
& CUPS_PRINTER_CLASS
)
2131 snprintf(resource
, sizeof(resource
), "/classes/%s", p
->name
);
2133 snprintf(resource
, sizeof(resource
), "/printers/%s", p
->name
);
2135 if ((auth
= cupsdFindBest(resource
, HTTP_POST
)) == NULL
||
2136 auth
->type
== CUPSD_AUTH_NONE
)
2137 auth
= cupsdFindPolicyOp(p
->op_policy_ptr
, IPP_PRINT_JOB
);
2141 int auth_type
; /* Authentication type */
2144 if ((auth_type
= auth
->type
) == CUPSD_AUTH_DEFAULT
)
2145 auth_type
= cupsdDefaultAuthType();
2147 if (auth_type
== CUPSD_AUTH_BASIC
|| auth_type
== CUPSD_AUTH_BASICDIGEST
)
2148 auth_supported
= "basic";
2149 else if (auth_type
== CUPSD_AUTH_DIGEST
)
2150 auth_supported
= "digest";
2152 else if (auth_type
== CUPSD_AUTH_NEGOTIATE
)
2153 auth_supported
= "negotiate";
2154 #endif /* HAVE_GSSAPI */
2156 if (auth_type
!= CUPSD_AUTH_NONE
)
2157 p
->type
|= CUPS_PRINTER_AUTHENTICATED
;
2159 p
->type
&= ~CUPS_PRINTER_AUTHENTICATED
;
2162 p
->type
&= ~CUPS_PRINTER_AUTHENTICATED
;
2165 * Create the required IPP attributes for a printer...
2168 oldattrs
= p
->attrs
;
2169 p
->attrs
= ippNew();
2171 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2172 "uri-authentication-supported", NULL
, auth_supported
);
2173 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2174 "uri-security-supported", NULL
, "none");
2175 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
, "printer-name", NULL
,
2177 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-location",
2178 NULL
, p
->location
? p
->location
: "");
2179 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-info",
2180 NULL
, p
->info
? p
->info
: "");
2181 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "printer-uuid", NULL
,
2184 if (cupsArrayCount(p
->users
) > 0)
2187 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2188 "requesting-user-name-denied",
2189 cupsArrayCount(p
->users
), NULL
, NULL
);
2191 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2192 "requesting-user-name-allowed",
2193 cupsArrayCount(p
->users
), NULL
, NULL
);
2195 for (i
= 0, name
= (char *)cupsArrayFirst(p
->users
);
2197 i
++, name
= (char *)cupsArrayNext(p
->users
))
2198 attr
->values
[i
].string
.text
= _cupsStrRetain(name
);
2201 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2202 "job-quota-period", p
->quota_period
);
2203 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2204 "job-k-limit", p
->k_limit
);
2205 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2206 "job-page-limit", p
->page_limit
);
2207 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2208 "auth-info-required", num_air
, NULL
, air
);
2210 if (cupsArrayCount(Banners
) > 0)
2213 * Setup the job-sheets-default attribute...
2216 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2217 "job-sheets-default", 2, NULL
, NULL
);
2221 attr
->values
[0].string
.text
= _cupsStrAlloc(Classification
?
2222 Classification
: p
->job_sheets
[0]);
2223 attr
->values
[1].string
.text
= _cupsStrAlloc(Classification
?
2224 Classification
: p
->job_sheets
[1]);
2232 * Assign additional attributes depending on whether this is a printer
2236 if (p
->type
& CUPS_PRINTER_CLASS
)
2239 p
->type
&= ~CUPS_PRINTER_OPTIONS
;
2242 * Add class-specific attributes...
2245 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
2246 "printer-make-and-model", NULL
, "Local Printer Class");
2247 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "device-uri", NULL
,
2248 "file:///dev/null");
2250 if (p
->num_printers
> 0)
2253 * Add a list of member names; URIs are added in copy_printer_attrs...
2256 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2257 "member-names", p
->num_printers
, NULL
, NULL
);
2258 p
->type
|= CUPS_PRINTER_OPTIONS
;
2260 for (i
= 0; i
< p
->num_printers
; i
++)
2263 attr
->values
[i
].string
.text
= _cupsStrRetain(p
->printers
[i
]->name
);
2265 p
->type
&= ~CUPS_PRINTER_OPTIONS
| p
->printers
[i
]->type
;
2272 * Add printer-specific attributes...
2275 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "device-uri", NULL
,
2276 p
->sanitized_device_uri
);
2279 * Assign additional attributes from the PPD file (if any)...
2285 * Add filters for printer...
2288 cupsdSetPrinterReasons(p
, "-cups-missing-filter-warning,"
2289 "cups-insecure-filter-warning");
2291 if (p
->pc
&& p
->pc
->filters
)
2293 for (filter
= (char *)cupsArrayFirst(p
->pc
->filters
);
2295 filter
= (char *)cupsArrayNext(p
->pc
->filters
))
2296 add_printer_filter(p
, p
->filetype
, filter
);
2298 else if (!(p
->type
& CUPS_PRINTER_REMOTE
))
2300 char interface
[1024]; /* Interface script */
2303 snprintf(interface
, sizeof(interface
), "%s/interfaces/%s", ServerRoot
,
2305 if (!access(interface
, X_OK
))
2308 * Yes, we have a System V style interface script; use it!
2311 snprintf(interface
, sizeof(interface
), "*/* 0 %s/interfaces/%s",
2312 ServerRoot
, p
->name
);
2313 add_printer_filter(p
, p
->filetype
, interface
);
2318 * Add a filter from application/vnd.cups-raw to printer/name to
2319 * handle "raw" printing by users.
2322 add_printer_filter(p
, p
->filetype
, "application/vnd.cups-raw 0 -");
2325 * Add a PostScript filter, since this is still possibly PS printer.
2328 add_printer_filter(p
, p
->filetype
,
2329 "application/vnd.cups-postscript 0 -");
2333 if (p
->pc
&& p
->pc
->prefilters
)
2335 if (!p
->prefiltertype
)
2336 p
->prefiltertype
= mimeAddType(MimeDatabase
, "prefilter", p
->name
);
2338 for (filter
= (char *)cupsArrayFirst(p
->pc
->prefilters
);
2340 filter
= (char *)cupsArrayNext(p
->pc
->prefilters
))
2341 add_printer_filter(p
, p
->prefiltertype
, filter
);
2346 * Copy marker attributes as needed...
2351 ipp_attribute_t
*oldattr
; /* Old attribute */
2354 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-colors",
2355 IPP_TAG_NAME
)) != NULL
)
2357 if ((attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2358 "marker-colors", oldattr
->num_values
, NULL
,
2361 for (i
= 0; i
< oldattr
->num_values
; i
++)
2362 attr
->values
[i
].string
.text
=
2363 _cupsStrRetain(oldattr
->values
[i
].string
.text
);
2367 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-levels",
2368 IPP_TAG_INTEGER
)) != NULL
)
2370 if ((attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2371 "marker-levels", oldattr
->num_values
,
2374 for (i
= 0; i
< oldattr
->num_values
; i
++)
2375 attr
->values
[i
].integer
= oldattr
->values
[i
].integer
;
2379 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-message",
2380 IPP_TAG_TEXT
)) != NULL
)
2381 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "marker-message",
2382 NULL
, oldattr
->values
[0].string
.text
);
2384 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-low-levels",
2385 IPP_TAG_INTEGER
)) != NULL
)
2387 if ((attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2388 "marker-low-levels", oldattr
->num_values
,
2391 for (i
= 0; i
< oldattr
->num_values
; i
++)
2392 attr
->values
[i
].integer
= oldattr
->values
[i
].integer
;
2396 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-high-levels",
2397 IPP_TAG_INTEGER
)) != NULL
)
2399 if ((attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2400 "marker-high-levels", oldattr
->num_values
,
2403 for (i
= 0; i
< oldattr
->num_values
; i
++)
2404 attr
->values
[i
].integer
= oldattr
->values
[i
].integer
;
2408 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-names",
2409 IPP_TAG_NAME
)) != NULL
)
2411 if ((attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2412 "marker-names", oldattr
->num_values
, NULL
,
2415 for (i
= 0; i
< oldattr
->num_values
; i
++)
2416 attr
->values
[i
].string
.text
=
2417 _cupsStrRetain(oldattr
->values
[i
].string
.text
);
2421 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-types",
2422 IPP_TAG_KEYWORD
)) != NULL
)
2424 if ((attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2425 "marker-types", oldattr
->num_values
, NULL
,
2428 for (i
= 0; i
< oldattr
->num_values
; i
++)
2429 attr
->values
[i
].string
.text
=
2430 _cupsStrRetain(oldattr
->values
[i
].string
.text
);
2434 ippDelete(oldattrs
);
2438 * Force sharing off for remote queues...
2441 if (p
->type
& CUPS_PRINTER_REMOTE
)
2445 * Populate the document-format-supported attribute...
2448 add_printer_formats(p
);
2450 DEBUG_printf(("cupsdSetPrinterAttrs: leaving name = %s, type = %x\n", p
->name
,
2454 * Add name-default attributes...
2457 add_printer_defaults(p
);
2461 * Write the IRIX printer config and status files...
2464 write_irix_config(p
);
2465 write_irix_state(p
);
2469 * Let the browse protocols reflect the change
2472 cupsdRegisterPrinter(p
);
2477 * 'cupsdSetPrinterReasons()' - Set/update the reasons strings.
2480 int /* O - 1 if something changed, 0 otherwise */
2481 cupsdSetPrinterReasons(
2482 cupsd_printer_t
*p
, /* I - Printer */
2483 const char *s
) /* I - Reasons strings */
2485 int i
, /* Looping var */
2486 changed
= 0; /* Did something change? */
2487 const char *sptr
; /* Pointer into reasons */
2488 char reason
[255], /* Reason string */
2489 *rptr
; /* Pointer into reason */
2492 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
2493 "cupsdSetPrinterReasons(p=%p(%s),s=\"%s\"", p
, p
->name
, s
);
2495 if (s
[0] == '-' || s
[0] == '+')
2498 * Add/remove reasons...
2506 * Replace reasons...
2511 for (i
= 0; i
< p
->num_reasons
; i
++)
2512 _cupsStrFree(p
->reasons
[i
]);
2520 if (!strcmp(s
, "none"))
2524 * Loop through all of the reasons...
2530 * Skip leading whitespace and commas...
2533 while (isspace(*sptr
& 255) || *sptr
== ',')
2536 for (rptr
= reason
; *sptr
&& !isspace(*sptr
& 255) && *sptr
!= ','; sptr
++)
2537 if (rptr
< (reason
+ sizeof(reason
) - 1))
2551 for (i
= 0; i
< p
->num_reasons
; i
++)
2552 if (!strcmp(reason
, p
->reasons
[i
]))
2555 * Found a match, so remove it...
2560 _cupsStrFree(p
->reasons
[i
]);
2562 if (i
< p
->num_reasons
)
2563 memmove(p
->reasons
+ i
, p
->reasons
+ i
+ 1,
2564 (p
->num_reasons
- i
) * sizeof(char *));
2566 if (!strcmp(reason
, "paused") && p
->state
== IPP_PRINTER_STOPPED
)
2567 cupsdSetPrinterState(p
, IPP_PRINTER_IDLE
, 1);
2569 if (strcmp(reason
, "connecting-to-device"))
2574 else if (p
->num_reasons
< (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
2580 for (i
= 0; i
< p
->num_reasons
; i
++)
2581 if (!strcmp(reason
, p
->reasons
[i
]))
2584 if (i
>= p
->num_reasons
)
2586 if (!strncmp(reason
, "cups-ipp-missing-", 17) ||
2587 !strncmp(reason
, "cups-ipp-wrong-", 15))
2588 log_ipp_conformance(p
, reason
);
2590 if (i
>= (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
2592 cupsdLogMessage(CUPSD_LOG_ALERT
,
2593 "Too many printer-state-reasons values for %s (%d)",
2598 p
->reasons
[i
] = _cupsStrAlloc(reason
);
2602 if (!strcmp(reason
, "paused") && p
->state
!= IPP_PRINTER_STOPPED
)
2603 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, 1);
2605 if (strcmp(reason
, "connecting-to-device"))
2616 * 'cupsdSetPrinterState()' - Update the current state of a printer.
2620 cupsdSetPrinterState(
2621 cupsd_printer_t
*p
, /* I - Printer to change */
2622 ipp_pstate_t s
, /* I - New state */
2623 int update
) /* I - Update printers.conf? */
2625 cupsd_job_t
*job
; /* Current job */
2626 ipp_pstate_t old_state
; /* Old printer state */
2627 static const char * const printer_states
[] =
2628 { /* State strings */
2636 * Set the new state...
2639 old_state
= p
->state
;
2644 cupsdAddEvent(s
== IPP_PRINTER_STOPPED
? CUPSD_EVENT_PRINTER_STOPPED
:
2645 CUPSD_EVENT_PRINTER_STATE
, p
, NULL
,
2646 "%s \"%s\" state changed to %s.",
2647 (p
->type
& CUPS_PRINTER_CLASS
) ? "Class" : "Printer",
2648 p
->name
, printer_states
[p
->state
- IPP_PRINTER_IDLE
]);
2651 * Let the browse code know this needs to be updated...
2654 p
->state_time
= time(NULL
);
2657 write_irix_state(p
);
2662 * Set/clear the paused reason as needed...
2665 if (s
== IPP_PRINTER_STOPPED
)
2666 cupsdSetPrinterReasons(p
, "+paused");
2668 cupsdSetPrinterReasons(p
, "-paused");
2672 for (job
= (cupsd_job_t
*)cupsArrayFirst(ActiveJobs
);
2674 job
= (cupsd_job_t
*)cupsArrayNext(ActiveJobs
))
2675 if (job
->reasons
&& job
->state_value
== IPP_JOB_PENDING
&&
2676 !_cups_strcasecmp(job
->dest
, p
->name
))
2677 ippSetString(job
->attrs
, &job
->reasons
, 0,
2678 s
== IPP_PRINTER_STOPPED
? "printer-stopped" : "none");
2682 * Clear the message for the queue when going to processing...
2685 if (s
== IPP_PRINTER_PROCESSING
)
2686 p
->state_message
[0] = '\0';
2689 * Let the browse protocols reflect the change...
2693 cupsdRegisterPrinter(p
);
2696 * Save the printer configuration if a printer goes from idle or processing
2697 * to stopped (or visa-versa)...
2701 (old_state
== IPP_PRINTER_STOPPED
) != (s
== IPP_PRINTER_STOPPED
))
2707 * 'cupsdStopPrinter()' - Stop a printer from printing any jobs...
2711 cupsdStopPrinter(cupsd_printer_t
*p
, /* I - Printer to stop */
2712 int update
)/* I - Update printers.conf? */
2715 * Set the printer state...
2718 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, update
);
2721 * See if we have a job printing on this printer...
2724 if (p
->job
&& p
->job
->state_value
== IPP_JOB_PROCESSING
)
2725 cupsdSetJobState(p
->job
, IPP_JOB_PENDING
, CUPSD_JOB_DEFAULT
,
2726 "Job stopped due to printer being paused.");
2731 * 'cupsdUpdatePrinterPPD()' - Update keywords in a printer's PPD file.
2734 int /* O - 1 if successful, 0 otherwise */
2735 cupsdUpdatePrinterPPD(
2736 cupsd_printer_t
*p
, /* I - Printer */
2737 int num_keywords
, /* I - Number of keywords */
2738 cups_option_t
*keywords
) /* I - Keywords */
2740 int i
; /* Looping var */
2741 cups_file_t
*src
, /* Original file */
2742 *dst
; /* New file */
2743 char srcfile
[1024], /* Original filename */
2744 dstfile
[1024], /* New filename */
2745 line
[1024], /* Line from file */
2746 keystring
[41]; /* Keyword from line */
2747 cups_option_t
*keyword
; /* Current keyword */
2750 cupsdLogMessage(CUPSD_LOG_INFO
, "Updating keywords in PPD file for %s...",
2754 * Get the old and new PPD filenames...
2757 snprintf(srcfile
, sizeof(srcfile
), "%s/ppd/%s.ppd.O", ServerRoot
, p
->name
);
2758 snprintf(dstfile
, sizeof(srcfile
), "%s/ppd/%s.ppd", ServerRoot
, p
->name
);
2761 * Rename the old file and open the old and new...
2764 if (rename(dstfile
, srcfile
))
2766 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to backup PPD file for %s: %s",
2767 p
->name
, strerror(errno
));
2771 if ((src
= cupsFileOpen(srcfile
, "r")) == NULL
)
2773 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to open PPD file \"%s\": %s",
2774 srcfile
, strerror(errno
));
2775 rename(srcfile
, dstfile
);
2779 if ((dst
= cupsFileOpen(dstfile
, "w")) == NULL
)
2781 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to create PPD file \"%s\": %s",
2782 dstfile
, strerror(errno
));
2784 rename(srcfile
, dstfile
);
2789 * Copy the first line and then write out all of the keywords...
2792 if (!cupsFileGets(src
, line
, sizeof(line
)))
2794 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to read PPD file \"%s\": %s",
2795 srcfile
, strerror(errno
));
2798 rename(srcfile
, dstfile
);
2802 cupsFilePrintf(dst
, "%s\n", line
);
2804 for (i
= num_keywords
, keyword
= keywords
; i
> 0; i
--, keyword
++)
2806 cupsdLogMessage(CUPSD_LOG_DEBUG
, "*%s: %s", keyword
->name
, keyword
->value
);
2807 cupsFilePrintf(dst
, "*%s: %s\n", keyword
->name
, keyword
->value
);
2811 * Then copy the rest of the PPD file, dropping any keywords we changed.
2814 while (cupsFileGets(src
, line
, sizeof(line
)))
2817 * Skip keywords we've already set...
2820 if (sscanf(line
, "*%40[^:]:", keystring
) == 1 &&
2821 cupsGetOption(keystring
, num_keywords
, keywords
))
2825 * Otherwise write the line...
2828 cupsFilePrintf(dst
, "%s\n", line
);
2832 * Close files and return...
2843 * 'cupsdUpdatePrinters()' - Update printers after a partial reload.
2847 cupsdUpdatePrinters(void)
2849 cupsd_printer_t
*p
; /* Current printer */
2853 * Loop through the printers and recreate the printer attributes
2854 * for any local printers since the policy and/or access control
2855 * stuff may have changed. Also, if browsing is disabled, remove
2856 * any remote printers...
2859 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
2861 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
2864 * Update the operation policy pointer...
2867 if ((p
->op_policy_ptr
= cupsdFindPolicy(p
->op_policy
)) == NULL
)
2868 p
->op_policy_ptr
= DefaultPolicyPtr
;
2871 * Update printer attributes...
2874 cupsdSetPrinterAttrs(p
);
2880 * 'cupsdValidateDest()' - Validate a printer/class destination.
2883 const char * /* O - Printer or class name */
2885 const char *uri
, /* I - Printer URI */
2886 cups_ptype_t
*dtype
, /* O - Type (printer or class) */
2887 cupsd_printer_t
**printer
) /* O - Printer pointer */
2889 cupsd_printer_t
*p
; /* Current printer */
2890 char localname
[1024],/* Localized hostname */
2891 *lptr
, /* Pointer into localized hostname */
2892 *sptr
, /* Pointer into server name */
2893 *rptr
, /* Pointer into resource */
2894 scheme
[32], /* Scheme portion of URI */
2895 username
[64], /* Username portion of URI */
2896 hostname
[HTTP_MAX_HOST
],
2897 /* Host portion of URI */
2898 resource
[HTTP_MAX_URI
];
2899 /* Resource portion of URI */
2900 int port
; /* Port portion of URI */
2903 DEBUG_printf(("cupsdValidateDest(uri=\"%s\", dtype=%p, printer=%p)\n", uri
,
2907 * Initialize return values...
2914 *dtype
= (cups_ptype_t
)0;
2917 * Pull the hostname and resource from the URI...
2920 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
, scheme
, sizeof(scheme
),
2921 username
, sizeof(username
), hostname
, sizeof(hostname
),
2922 &port
, resource
, sizeof(resource
));
2925 * See if the resource is a class or printer...
2928 if (!strncmp(resource
, "/classes/", 9))
2934 rptr
= resource
+ 9;
2936 else if (!strncmp(resource
, "/printers/", 10))
2942 rptr
= resource
+ 10;
2947 * Bad resource name...
2954 * See if the printer or class name exists...
2957 p
= cupsdFindDest(rptr
);
2959 if (p
== NULL
&& strchr(rptr
, '@') == NULL
)
2967 *dtype
= p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_REMOTE
);
2973 * Change localhost to the server name...
2976 if (!_cups_strcasecmp(hostname
, "localhost"))
2977 strlcpy(hostname
, ServerName
, sizeof(hostname
));
2979 strlcpy(localname
, hostname
, sizeof(localname
));
2981 if (!_cups_strcasecmp(hostname
, ServerName
))
2984 * Localize the hostname...
2987 lptr
= strchr(localname
, '.');
2988 sptr
= strchr(ServerName
, '.');
2990 if (sptr
!= NULL
&& lptr
!= NULL
)
2993 * Strip the common domain name components...
2996 while (lptr
!= NULL
)
2998 if (!_cups_strcasecmp(lptr
, sptr
))
3004 lptr
= strchr(lptr
+ 1, '.');
3009 DEBUG_printf(("localized hostname is \"%s\"...\n", localname
));
3012 * Find a matching printer or class...
3015 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3017 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3018 if (!_cups_strcasecmp(p
->hostname
, localname
) &&
3019 !_cups_strcasecmp(p
->name
, rptr
))
3025 *dtype
= p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_REMOTE
);
3035 * 'cupsdWritePrintcap()' - Write a pseudo-printcap file for older applications
3040 cupsdWritePrintcap(void)
3042 int i
; /* Looping var */
3043 cups_file_t
*fp
; /* Printcap file */
3044 cupsd_printer_t
*p
; /* Current printer */
3049 * Update the IRIX printer state for the default printer; if
3050 * no printers remain, then the default printer file will be
3054 write_irix_state(DefaultPrinter
);
3058 * See if we have a printcap file; if not, don't bother writing it.
3061 if (!Printcap
|| !*Printcap
)
3064 cupsdLogMessage(CUPSD_LOG_INFO
, "Generating printcap %s...", Printcap
);
3067 * Open the printcap file...
3070 if ((fp
= cupsFileOpen(Printcap
, "w")) == NULL
)
3074 * Put a comment header at the top so that users will know where the
3075 * data has come from...
3078 if (PrintcapFormat
!= PRINTCAP_PLIST
)
3079 cupsFilePrintf(fp
, "# This file was automatically generated by cupsd(8) "
3081 "# %s/printers.conf file. All changes to this file\n"
3082 "# will be lost.\n", ServerRoot
);
3085 * Write a new printcap with the current list of printers.
3088 switch (PrintcapFormat
)
3092 * Each printer is put in the file as:
3102 cupsFilePrintf(fp
, "%s|%s:rm=%s:rp=%s:\n", DefaultPrinter
->name
,
3103 DefaultPrinter
->info
, ServerName
,
3104 DefaultPrinter
->name
);
3106 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3108 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3109 if (p
!= DefaultPrinter
)
3110 cupsFilePrintf(fp
, "%s|%s:rm=%s:rp=%s:\n", p
->name
, p
->info
,
3111 ServerName
, p
->name
);
3114 case PRINTCAP_PLIST
:
3116 * Each printer is written as a dictionary in a plist file.
3117 * Currently the printer-name, printer-info, printer-is-accepting-jobs,
3118 * printer-location, printer-make-and-model, printer-state,
3119 * printer-state-reasons, printer-type, and (sanitized) device-uri.
3122 cupsFilePuts(fp
, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
3123 "<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD "
3124 "PLIST 1.0//EN\" \"http://www.apple.com/DTDs/"
3125 "PropertyList-1.0.dtd\">\n"
3126 "<plist version=\"1.0\">\n"
3129 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3131 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3133 cupsFilePuts(fp
, "\t<dict>\n"
3134 "\t\t<key>printer-name</key>\n"
3136 write_xml_string(fp
, p
->name
);
3137 cupsFilePuts(fp
, "</string>\n"
3138 "\t\t<key>printer-info</key>\n"
3140 write_xml_string(fp
, p
->info
);
3141 cupsFilePrintf(fp
, "</string>\n"
3142 "\t\t<key>printer-is-accepting-jobs</key>\n"
3144 "\t\t<key>printer-location</key>\n"
3145 "\t\t<string>", p
->accepting
? "true" : "false");
3146 write_xml_string(fp
, p
->location
);
3147 cupsFilePuts(fp
, "</string>\n"
3148 "\t\t<key>printer-make-and-model</key>\n"
3150 write_xml_string(fp
, p
->make_model
);
3151 cupsFilePrintf(fp
, "</string>\n"
3152 "\t\t<key>printer-state</key>\n"
3153 "\t\t<integer>%d</integer>\n"
3154 "\t\t<key>printer-state-reasons</key>\n"
3155 "\t\t<array>\n", p
->state
);
3156 for (i
= 0; i
< p
->num_reasons
; i
++)
3158 cupsFilePuts(fp
, "\t\t\t<string>");
3159 write_xml_string(fp
, p
->reasons
[i
]);
3160 cupsFilePuts(fp
, "</string>\n");
3162 cupsFilePrintf(fp
, "\t\t</array>\n"
3163 "\t\t<key>printer-type</key>\n"
3164 "\t\t<integer>%d</integer>\n"
3165 "\t\t<key>device-uri</key>\n"
3166 "\t\t<string>", p
->type
);
3167 write_xml_string(fp
, p
->sanitized_device_uri
);
3168 cupsFilePuts(fp
, "</string>\n"
3171 cupsFilePuts(fp
, "</array>\n"
3175 case PRINTCAP_SOLARIS
:
3177 * Each printer is put in the file as:
3179 * _all:all=Printer1,Printer2,Printer3,...,PrinterN
3180 * _default:use=DefaultPrinter
3182 * :bsdaddr=ServerName,Printer1:\
3183 * :description=Description:
3185 * :bsdaddr=ServerName,Printer2:\
3186 * :description=Description:
3188 * :bsdaddr=ServerName,Printer3:\
3189 * :description=Description:
3192 * :bsdaddr=ServerName,PrinterN:\
3193 * :description=Description:
3196 cupsFilePuts(fp
, "_all:all=");
3197 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3199 p
= (cupsd_printer_t
*)cupsArrayCurrent(Printers
))
3200 cupsFilePrintf(fp
, "%s%c", p
->name
,
3201 cupsArrayNext(Printers
) ? ',' : '\n');
3204 cupsFilePrintf(fp
, "_default:use=%s\n", DefaultPrinter
->name
);
3206 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3208 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3209 cupsFilePrintf(fp
, "%s:\\\n"
3210 "\t:bsdaddr=%s,%s:\\\n"
3211 "\t:description=%s:\n",
3212 p
->name
, ServerName
, p
->name
,
3213 p
->info
? p
->info
: "");
3226 * 'add_printer_defaults()' - Add name-default attributes to the printer attributes.
3230 add_printer_defaults(cupsd_printer_t
*p
)/* I - Printer */
3232 int i
; /* Looping var */
3233 int num_options
; /* Number of default options */
3234 cups_option_t
*options
, /* Default options */
3235 *option
; /* Current option */
3236 char name
[256]; /* name-default */
3240 * Maintain a common array of default attribute names...
3243 if (!CommonDefaults
)
3245 CommonDefaults
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
3247 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("copies-default"));
3248 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("document-format-default"));
3249 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("finishings-default"));
3250 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-hold-until-default"));
3251 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-priority-default"));
3252 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-sheets-default"));
3253 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("media-col-default"));
3254 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("number-up-default"));
3255 cupsArrayAdd(CommonDefaults
,
3256 _cupsStrAlloc("orientation-requested-default"));
3260 * Add all of the default options from the .conf files...
3263 for (num_options
= 0, options
= NULL
, i
= p
->num_options
, option
= p
->options
;
3267 if (strcmp(option
->name
, "ipp-options") &&
3268 strcmp(option
->name
, "job-sheets") &&
3269 strcmp(option
->name
, "lease-duration"))
3271 snprintf(name
, sizeof(name
), "%s-default", option
->name
);
3272 num_options
= cupsAddOption(name
, option
->value
, num_options
, &options
);
3274 if (!cupsArrayFind(CommonDefaults
, name
))
3275 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc(name
));
3280 * Convert options to IPP attributes...
3283 cupsEncodeOptions2(p
->attrs
, num_options
, options
, IPP_TAG_PRINTER
);
3284 cupsFreeOptions(num_options
, options
);
3287 * Add standard -default attributes as needed...
3290 if (!cupsGetOption("copies", p
->num_options
, p
->options
))
3291 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
, "copies-default",
3294 if (!cupsGetOption("document-format", p
->num_options
, p
->options
))
3295 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_MIMETYPE
,
3296 "document-format-default", NULL
, "application/octet-stream");
3298 if (!cupsGetOption("job-hold-until", p
->num_options
, p
->options
))
3299 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3300 "job-hold-until-default", NULL
, "no-hold");
3302 if (!cupsGetOption("job-priority", p
->num_options
, p
->options
))
3303 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3304 "job-priority-default", 50);
3306 if (!cupsGetOption("number-up", p
->num_options
, p
->options
))
3307 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3308 "number-up-default", 1);
3310 if (!cupsGetOption("notify-lease-duration", p
->num_options
, p
->options
))
3311 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3312 "notify-lease-duration-default", DefaultLeaseDuration
);
3314 if (!cupsGetOption("notify-events", p
->num_options
, p
->options
))
3315 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3316 "notify-events-default", NULL
, "job-completed");
3318 if (!cupsGetOption("orientation-requested", p
->num_options
, p
->options
))
3319 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NOVALUE
,
3320 "orientation-requested-default", NULL
, NULL
);
3322 if (!cupsGetOption("print-quality", p
->num_options
, p
->options
))
3323 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
3324 "print-quality-default", IPP_QUALITY_NORMAL
);
3329 * 'add_printer_filter()' - Add a MIME filter for a printer.
3334 cupsd_printer_t
*p
, /* I - Printer to add to */
3335 mime_type_t
*filtertype
, /* I - Filter or prefilter MIME type */
3336 const char *filter
) /* I - Filter to add */
3338 char super
[MIME_MAX_SUPER
], /* Super-type for filter */
3339 type
[MIME_MAX_TYPE
], /* Type for filter */
3340 dsuper
[MIME_MAX_SUPER
], /* Destination super-type for filter */
3341 dtype
[MIME_MAX_TYPE
], /* Destination type for filter */
3342 dest
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2],
3343 /* Destination super/type */
3344 program
[1024]; /* Program/filter name */
3345 int cost
; /* Cost of filter */
3346 size_t maxsize
= 0; /* Maximum supported file size */
3347 mime_type_t
*temptype
, /* MIME type looping var */
3348 *desttype
; /* Destination MIME type */
3349 mime_filter_t
*filterptr
; /* MIME filter */
3350 char filename
[1024]; /* Full filter filename */
3353 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3354 "add_printer_filter(p=%p(%s), filtertype=%p(%s/%s), "
3355 "filter=\"%s\")", p
, p
->name
, filtertype
, filtertype
->super
,
3356 filtertype
->type
, filter
);
3359 * Parse the filter string; it should be in one of the following formats:
3361 * source/type cost program
3362 * source/type cost maxsize(nnnn) program
3363 * source/type dest/type cost program
3364 * source/type dest/type cost maxsize(nnnn) program
3367 if (sscanf(filter
, "%15[^/]/%255s%*[ \t]%15[^/]/%255s%d%*[ \t]%1023[^\n]",
3368 super
, type
, dsuper
, dtype
, &cost
, program
) == 6)
3370 snprintf(dest
, sizeof(dest
), "%s/%s/%s", p
->name
, dsuper
, dtype
);
3372 if ((desttype
= mimeType(MimeDatabase
, "printer", dest
)) == NULL
)
3374 desttype
= mimeAddType(MimeDatabase
, "printer", dest
);
3376 p
->dest_types
= cupsArrayNew(NULL
, NULL
);
3378 cupsArrayAdd(p
->dest_types
, desttype
);
3384 if (sscanf(filter
, "%15[^/]/%255s%d%*[ \t]%1023[^\n]", super
, type
, &cost
,
3387 desttype
= filtertype
;
3391 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: invalid filter string \"%s\"!",
3397 if (!strncmp(program
, "maxsize(", 8))
3399 char *ptr
; /* Pointer into maxsize(nnnn) program */
3401 maxsize
= strtoll(program
+ 8, &ptr
, 10);
3405 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: invalid filter string \"%s\"!",
3411 while (_cups_isspace(*ptr
))
3414 _cups_strcpy(program
, ptr
);
3418 * Check permissions on the filter and its containing directory...
3421 if (strcmp(program
, "-"))
3423 if (program
[0] == '/')
3424 strlcpy(filename
, program
, sizeof(filename
));
3426 snprintf(filename
, sizeof(filename
), "%s/filter/%s", ServerBin
, program
);
3428 _cupsFileCheck(filename
, _CUPS_FILE_CHECK_PROGRAM
, !RunUser
,
3429 cupsdLogFCMessage
, p
);
3433 * Add the filter to the MIME database, supporting wildcards as needed...
3436 for (temptype
= mimeFirstType(MimeDatabase
);
3438 temptype
= mimeNextType(MimeDatabase
))
3439 if (((super
[0] == '*' && _cups_strcasecmp(temptype
->super
, "printer")) ||
3440 !_cups_strcasecmp(temptype
->super
, super
)) &&
3441 (type
[0] == '*' || !_cups_strcasecmp(temptype
->type
, type
)))
3443 if (desttype
!= filtertype
)
3445 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3446 "add_printer_filter: %s: adding filter %s/%s %s/%s %d "
3447 "%s", p
->name
, temptype
->super
, temptype
->type
,
3448 desttype
->super
, desttype
->type
,
3450 filterptr
= mimeAddFilter(MimeDatabase
, temptype
, desttype
, cost
,
3453 if (!mimeFilterLookup(MimeDatabase
, desttype
, filtertype
))
3455 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3456 "add_printer_filter: %s: adding filter %s/%s %s/%s "
3457 "0 -", p
->name
, desttype
->super
, desttype
->type
,
3458 filtertype
->super
, filtertype
->type
);
3459 mimeAddFilter(MimeDatabase
, desttype
, filtertype
, 0, "-");
3464 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3465 "add_printer_filter: %s: adding filter %s/%s %s/%s %d "
3466 "%s", p
->name
, temptype
->super
, temptype
->type
,
3467 filtertype
->super
, filtertype
->type
,
3469 filterptr
= mimeAddFilter(MimeDatabase
, temptype
, filtertype
, cost
,
3474 filterptr
->maxsize
= maxsize
;
3480 * 'add_printer_formats()' - Add document-format-supported values for a printer.
3484 add_printer_formats(cupsd_printer_t
*p
) /* I - Printer */
3486 int i
; /* Looping var */
3487 mime_type_t
*type
; /* Current MIME type */
3488 cups_array_t
*filters
; /* Filters */
3489 ipp_attribute_t
*attr
; /* document-format-supported attribute */
3490 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
3491 /* MIME type name */
3495 * Raw (and remote) queues advertise all of the supported MIME
3499 cupsArrayDelete(p
->filetypes
);
3500 p
->filetypes
= NULL
;
3504 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
,
3505 (ipp_tag_t
)(IPP_TAG_MIMETYPE
| IPP_TAG_COPY
),
3506 "document-format-supported", NumMimeTypes
, NULL
, MimeTypes
);
3511 * Otherwise, loop through the supported MIME types and see if there
3512 * are filters for them...
3515 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_printer_formats: %d types, %d filters",
3516 mimeNumTypes(MimeDatabase
), mimeNumFilters(MimeDatabase
));
3518 p
->filetypes
= cupsArrayNew(NULL
, NULL
);
3520 for (type
= mimeFirstType(MimeDatabase
);
3522 type
= mimeNextType(MimeDatabase
))
3524 if (!_cups_strcasecmp(type
->super
, "printer"))
3527 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
3529 if ((filters
= mimeFilter(MimeDatabase
, type
, p
->filetype
, NULL
)) != NULL
)
3531 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3532 "add_printer_formats: %s: %s needs %d filters",
3533 p
->name
, mimetype
, cupsArrayCount(filters
));
3535 cupsArrayDelete(filters
);
3536 cupsArrayAdd(p
->filetypes
, type
);
3539 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3540 "add_printer_formats: %s: %s not supported",
3545 * Add the file formats that can be filtered...
3548 if ((type
= mimeType(MimeDatabase
, "application", "octet-stream")) == NULL
||
3549 !cupsArrayFind(p
->filetypes
, type
))
3554 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3555 "add_printer_formats: %s: %d supported types",
3556 p
->name
, cupsArrayCount(p
->filetypes
) + i
);
3558 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_MIMETYPE
,
3559 "document-format-supported",
3560 cupsArrayCount(p
->filetypes
) + i
, NULL
, NULL
);
3563 attr
->values
[0].string
.text
= _cupsStrAlloc("application/octet-stream");
3565 for (type
= (mime_type_t
*)cupsArrayFirst(p
->filetypes
);
3567 i
++, type
= (mime_type_t
*)cupsArrayNext(p
->filetypes
))
3569 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
3571 attr
->values
[i
].string
.text
= _cupsStrAlloc(mimetype
);
3576 char pdl
[1024]; /* Buffer to build pdl list */
3577 mime_filter_t
*filter
; /* MIME filter looping var */
3581 * We only support raw printing if this is not a Tioga PrintJobMgr based
3582 * queue and if application/octet-stream is a known type...
3585 for (filter
= (mime_filter_t
*)cupsArrayFirst(MimeDatabase
->filters
);
3587 filter
= (mime_filter_t
*)cupsArrayNext(MimeDatabase
->filters
))
3589 if (filter
->dst
== p
->filetype
&& filter
->filter
&&
3590 strstr(filter
->filter
, "PrintJobMgr"))
3596 if (!filter
&& mimeType(MimeDatabase
, "application", "octet-stream"))
3597 strlcat(pdl
, "application/octet-stream,", sizeof(pdl
));
3600 * Then list a bunch of formats that are supported by the printer...
3603 for (type
= (mime_type_t
*)cupsArrayFirst(p
->filetypes
);
3605 type
= (mime_type_t
*)cupsArrayNext(p
->filetypes
))
3607 if (!_cups_strcasecmp(type
->super
, "application"))
3609 if (!_cups_strcasecmp(type
->type
, "pdf"))
3610 strlcat(pdl
, "application/pdf,", sizeof(pdl
));
3611 else if (!_cups_strcasecmp(type
->type
, "postscript"))
3612 strlcat(pdl
, "application/postscript,", sizeof(pdl
));
3614 else if (!_cups_strcasecmp(type
->super
, "image"))
3616 if (!_cups_strcasecmp(type
->type
, "jpeg"))
3617 strlcat(pdl
, "image/jpeg,", sizeof(pdl
));
3618 else if (!_cups_strcasecmp(type
->type
, "png"))
3619 strlcat(pdl
, "image/png,", sizeof(pdl
));
3620 else if (!_cups_strcasecmp(type
->type
, "pwg-raster"))
3621 strlcat(pdl
, "image/pwg-raster,", sizeof(pdl
));
3626 pdl
[strlen(pdl
) - 1] = '\0'; /* Remove trailing comma */
3628 cupsdSetString(&p
->pdl
, pdl
);
3630 #endif /* HAVE_DNSSD */
3635 * 'compare_printers()' - Compare two printers.
3638 static int /* O - Result of comparison */
3639 compare_printers(void *first
, /* I - First printer */
3640 void *second
, /* I - Second printer */
3641 void *data
) /* I - App data (not used) */
3645 return (_cups_strcasecmp(((cupsd_printer_t
*)first
)->name
,
3646 ((cupsd_printer_t
*)second
)->name
));
3651 * 'delete_printer_filters()' - Delete all MIME filters for a printer.
3655 delete_printer_filters(
3656 cupsd_printer_t
*p
) /* I - Printer to remove from */
3658 mime_filter_t
*filter
; /* MIME filter looping var */
3659 mime_type_t
*type
; /* Destination types for filters */
3663 * Range check input...
3670 * Remove all filters from the MIME database that have a destination
3671 * type == printer...
3674 for (filter
= mimeFirstFilter(MimeDatabase
);
3676 filter
= mimeNextFilter(MimeDatabase
))
3677 if (filter
->dst
== p
->filetype
|| filter
->dst
== p
->prefiltertype
||
3678 cupsArrayFind(p
->dest_types
, filter
->dst
))
3681 * Delete the current filter...
3684 mimeDeleteFilter(MimeDatabase
, filter
);
3687 for (type
= (mime_type_t
*)cupsArrayFirst(p
->dest_types
);
3689 type
= (mime_type_t
*)cupsArrayNext(p
->dest_types
))
3690 mimeDeleteType(MimeDatabase
, type
);
3692 cupsArrayDelete(p
->dest_types
);
3693 p
->dest_types
= NULL
;
3695 cupsdSetPrinterReasons(p
, "-cups-insecure-filter-warning"
3696 ",cups-missing-filter-warning");
3701 * 'dirty_printer()' - Mark config and state files dirty for the specified
3706 dirty_printer(cupsd_printer_t
*p
) /* I - Printer */
3708 if (p
->type
& CUPS_PRINTER_CLASS
)
3709 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
3711 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
3713 if (PrintcapFormat
== PRINTCAP_PLIST
)
3714 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
3719 * 'load_ppd()' - Load a cached PPD file, updating the cache as needed.
3723 load_ppd(cupsd_printer_t
*p
) /* I - Printer */
3725 int i
, j
, k
; /* Looping vars */
3726 char cache_name
[1024]; /* Cache filename */
3727 struct stat cache_info
; /* Cache file info */
3728 ppd_file_t
*ppd
; /* PPD file */
3729 char ppd_name
[1024]; /* PPD filename */
3730 struct stat ppd_info
; /* PPD file info */
3731 int num_media
; /* Number of media options */
3732 ppd_size_t
*size
; /* Current PPD size */
3733 ppd_option_t
*duplex
, /* Duplex option */
3734 *output_bin
, /* OutputBin option */
3735 *output_mode
, /* OutputMode option */
3736 *resolution
; /* (Set|JCL|)Resolution option */
3737 ppd_choice_t
*choice
, /* Current PPD choice */
3738 *input_slot
, /* Current input slot */
3739 *media_type
; /* Current media type */
3740 ppd_attr_t
*ppd_attr
; /* PPD attribute */
3741 int xdpi
, /* Horizontal resolution */
3742 ydpi
; /* Vertical resolution */
3743 const char *resptr
; /* Pointer into resolution keyword */
3744 _pwg_size_t
*pwgsize
; /* Current PWG size */
3745 _pwg_map_t
*pwgsource
, /* Current PWG source */
3746 *pwgtype
; /* Current PWG type */
3747 ipp_attribute_t
*attr
; /* Attribute data */
3748 _ipp_value_t
*val
; /* Attribute value */
3749 int num_finishings
, /* Number of finishings */
3750 finishings
[5]; /* finishings-supported values */
3751 int num_qualities
, /* Number of print-quality values */
3752 qualities
[3]; /* print-quality values */
3753 int num_margins
, /* Number of media-*-margin-supported values */
3754 margins
[16]; /* media-*-margin-supported values */
3755 const char *filter
; /* Current filter */
3756 static const char * const sides
[3] = /* sides-supported values */
3759 "two-sided-long-edge",
3760 "two-sided-short-edge"
3762 static const char * const standard_commands
[] =
3763 { /* Standard CUPS commands */
3771 * Check to see if the cache is up-to-date...
3774 snprintf(cache_name
, sizeof(cache_name
), "%s/%s.data", CacheDir
, p
->name
);
3775 if (stat(cache_name
, &cache_info
))
3776 cache_info
.st_mtime
= 0;
3778 snprintf(ppd_name
, sizeof(ppd_name
), "%s/ppd/%s.ppd", ServerRoot
, p
->name
);
3779 if (stat(ppd_name
, &ppd_info
))
3780 ppd_info
.st_mtime
= 1;
3782 ippDelete(p
->ppd_attrs
);
3783 p
->ppd_attrs
= NULL
;
3785 _ppdCacheDestroy(p
->pc
);
3788 if (cache_info
.st_mtime
>= ppd_info
.st_mtime
)
3790 cupsdLogMessage(CUPSD_LOG_DEBUG
, "load_ppd: Loading %s...", cache_name
);
3792 if ((p
->pc
= _ppdCacheCreateWithFile(cache_name
, &p
->ppd_attrs
)) != NULL
&&
3796 * Loaded successfully!
3804 * Reload PPD attributes from disk...
3807 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
3809 cupsdLogMessage(CUPSD_LOG_DEBUG
, "load_ppd: Loading %s...", ppd_name
);
3811 p
->type
&= ~CUPS_PRINTER_OPTIONS
;
3812 p
->type
|= CUPS_PRINTER_BW
;
3814 finishings
[0] = IPP_FINISHINGS_NONE
;
3817 p
->ppd_attrs
= ippNew();
3819 if ((ppd
= _ppdOpenFile(ppd_name
, _PPD_LOCALIZATION_NONE
)) != NULL
)
3822 * Add make/model and other various attributes...
3825 p
->pc
= _ppdCacheCreateWithPPD(ppd
);
3827 ppdMarkDefaults(ppd
);
3829 if (ppd
->color_device
)
3830 p
->type
|= CUPS_PRINTER_COLOR
;
3831 if (ppd
->variable_sizes
)
3832 p
->type
|= CUPS_PRINTER_VARIABLE
;
3833 if (!ppd
->manual_copies
)
3834 p
->type
|= CUPS_PRINTER_COPIES
;
3835 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsFax", NULL
)) != NULL
)
3836 if (ppd_attr
->value
&& !_cups_strcasecmp(ppd_attr
->value
, "true"))
3837 p
->type
|= CUPS_PRINTER_FAX
;
3839 ippAddBoolean(p
->ppd_attrs
, IPP_TAG_PRINTER
, "color-supported",
3841 if (ppd
->throughput
)
3843 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3844 "pages-per-minute", ppd
->throughput
);
3845 if (ppd
->color_device
)
3846 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3847 "pages-per-minute-color", ppd
->throughput
);
3852 * When there is no speed information, just say "1 page per minute".
3855 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3856 "pages-per-minute", 1);
3857 if (ppd
->color_device
)
3858 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3859 "pages-per-minute-color", 1);
3864 if ((output_mode
= ppdFindOption(ppd
, "OutputMode")) != NULL
)
3866 if (ppdFindChoice(output_mode
, "draft") ||
3867 ppdFindChoice(output_mode
, "fast"))
3868 qualities
[num_qualities
++] = IPP_QUALITY_DRAFT
;
3870 qualities
[num_qualities
++] = IPP_QUALITY_NORMAL
;
3872 if (ppdFindChoice(output_mode
, "best") ||
3873 ppdFindChoice(output_mode
, "high"))
3874 qualities
[num_qualities
++] = IPP_QUALITY_HIGH
;
3876 else if ((ppd_attr
= ppdFindAttr(ppd
, "APPrinterPreset", NULL
)) != NULL
)
3880 if (strstr(ppd_attr
->spec
, "draft") ||
3881 strstr(ppd_attr
->spec
, "Draft"))
3883 qualities
[num_qualities
++] = IPP_QUALITY_DRAFT
;
3887 while ((ppd_attr
= ppdFindNextAttr(ppd
, "APPrinterPreset",
3890 qualities
[num_qualities
++] = IPP_QUALITY_NORMAL
;
3891 qualities
[num_qualities
++] = IPP_QUALITY_HIGH
;
3894 qualities
[num_qualities
++] = IPP_QUALITY_NORMAL
;
3896 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
3897 "print-quality-supported", num_qualities
, qualities
);
3902 * The NickName can be localized in the character set specified
3903 * by the LanugageEncoding attribute. However, ppdOpen2() has
3904 * already converted the ppd->nickname member to UTF-8 for us
3905 * (the original attribute value is available separately)
3908 cupsdSetString(&p
->make_model
, ppd
->nickname
);
3910 else if (ppd
->modelname
)
3913 * Model name can only contain specific characters...
3916 cupsdSetString(&p
->make_model
, ppd
->modelname
);
3919 cupsdSetString(&p
->make_model
, "Bad PPD File");
3921 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
3922 "printer-make-and-model", NULL
, p
->make_model
);
3925 * Add media options from the PPD file...
3928 if (ppd
->num_sizes
== 0 || !p
->pc
)
3930 if (!ppdFindAttr(ppd
, "APScannerOnly", NULL
))
3931 cupsdLogMessage(CUPSD_LOG_CRIT
,
3932 "The PPD file for printer %s contains no media "
3933 "options and is therefore invalid!", p
->name
);
3935 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3936 "media-default", NULL
, "unknown");
3937 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3938 "media-supported", NULL
, "unknown");
3946 if ((size
= ppdPageSize(ppd
, NULL
)) != NULL
)
3947 pwgsize
= _ppdCacheGetSize(p
->pc
, size
->name
);
3951 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3952 "media-default", NULL
,
3953 pwgsize
? pwgsize
->map
.pwg
: "unknown");
3961 ipp_t
*col
; /* Collection value */
3963 input_slot
= ppdFindMarkedChoice(ppd
, "InputSlot");
3964 media_type
= ppdFindMarkedChoice(ppd
, "MediaType");
3965 col
= new_media_col(pwgsize
,
3967 _ppdCacheGetSource(p
->pc
,
3968 input_slot
->choice
) :
3971 _ppdCacheGetType(p
->pc
,
3972 media_type
->choice
) :
3975 ippAddCollection(p
->ppd_attrs
, IPP_TAG_PRINTER
, "media-col-default",
3984 num_media
= p
->pc
->num_sizes
;
3985 if (p
->pc
->custom_min_keyword
)
3988 if ((attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3989 "media-supported", num_media
, NULL
,
3994 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
;
3996 i
--, pwgsize
++, val
++)
3997 val
->string
.text
= _cupsStrRetain(pwgsize
->map
.pwg
);
3999 if (p
->pc
->custom_min_keyword
)
4001 val
->string
.text
= _cupsStrRetain(p
->pc
->custom_min_keyword
);
4003 val
->string
.text
= _cupsStrRetain(p
->pc
->custom_max_keyword
);
4008 * media-source-supported
4011 if (p
->pc
->num_sources
> 0 &&
4012 (attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4013 "media-source-supported", p
->pc
->num_sources
,
4014 NULL
, NULL
)) != NULL
)
4016 for (i
= p
->pc
->num_sources
, pwgsource
= p
->pc
->sources
,
4019 i
--, pwgsource
++, val
++)
4020 val
->string
.text
= _cupsStrRetain(pwgsource
->pwg
);
4024 * media-type-supported
4027 if (p
->pc
->num_types
> 0 &&
4028 (attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4029 "media-type-supported", p
->pc
->num_types
,
4030 NULL
, NULL
)) != NULL
)
4032 for (i
= p
->pc
->num_types
, pwgtype
= p
->pc
->types
,
4035 i
--, pwgtype
++, val
++)
4036 val
->string
.text
= _cupsStrRetain(pwgtype
->pwg
);
4040 * media-*-margin-supported
4043 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, num_margins
= 0;
4044 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4047 for (j
= 0; j
< num_margins
; j
++)
4048 if (pwgsize
->bottom
== margins
[j
])
4051 if (j
>= num_margins
)
4053 margins
[num_margins
] = pwgsize
->bottom
;
4058 if (num_margins
> 0)
4059 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4060 "media-bottom-margin-supported", num_margins
, margins
);
4062 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4063 "media-bottom-margin-supported", 0);
4065 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, num_margins
= 0;
4066 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4069 for (j
= 0; j
< num_margins
; j
++)
4070 if (pwgsize
->left
== margins
[j
])
4073 if (j
>= num_margins
)
4075 margins
[num_margins
] = pwgsize
->left
;
4080 if (num_margins
> 0)
4081 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4082 "media-left-margin-supported", num_margins
, margins
);
4084 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4085 "media-left-margin-supported", 0);
4087 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, num_margins
= 0;
4088 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4091 for (j
= 0; j
< num_margins
; j
++)
4092 if (pwgsize
->right
== margins
[j
])
4095 if (j
>= num_margins
)
4097 margins
[num_margins
] = pwgsize
->right
;
4102 if (num_margins
> 0)
4103 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4104 "media-right-margin-supported", num_margins
, margins
);
4106 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4107 "media-right-margin-supported", 0);
4109 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, num_margins
= 0;
4110 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4113 for (j
= 0; j
< num_margins
; j
++)
4114 if (pwgsize
->top
== margins
[j
])
4117 if (j
>= num_margins
)
4119 margins
[num_margins
] = pwgsize
->top
;
4124 if (num_margins
> 0)
4125 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4126 "media-top-margin-supported", num_margins
, margins
);
4128 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4129 "media-top-margin-supported", 0);
4132 * media-col-database
4135 num_media
= p
->pc
->num_sizes
;
4136 if (p
->pc
->num_sources
)
4138 if (p
->pc
->num_types
> 0)
4139 num_media
+= p
->pc
->num_sizes
* p
->pc
->num_sources
*
4142 num_media
+= p
->pc
->num_sizes
* p
->pc
->num_sources
;
4144 else if (p
->pc
->num_types
)
4145 num_media
+= p
->pc
->num_sizes
* p
->pc
->num_types
;
4147 if ((attr
= ippAddCollections(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4148 "media-col-database", num_media
,
4151 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, val
= attr
->values
;
4156 * Start by adding the page size without source or type...
4159 ppdMarkOption(ppd
, "PageSize", pwgsize
->map
.ppd
);
4161 val
->collection
= new_media_col(pwgsize
, NULL
, NULL
);
4165 * Then add the specific, supported combinations of size, source, and
4169 if (p
->pc
->num_sources
> 0)
4171 for (j
= p
->pc
->num_sources
, pwgsource
= p
->pc
->sources
;
4175 ppdMarkOption(ppd
, "InputSlot", pwgsource
->ppd
);
4177 if (p
->pc
->num_types
> 0)
4179 for (k
= p
->pc
->num_types
, pwgtype
= p
->pc
->types
;
4183 if (!ppdMarkOption(ppd
, "MediaType", pwgtype
->ppd
))
4185 val
->collection
= new_media_col(pwgsize
, pwgsource
->pwg
,
4191 else if (!ppdConflicts(ppd
))
4193 val
->collection
= new_media_col(pwgsize
, pwgsource
->pwg
, NULL
);
4198 else if (p
->pc
->num_types
> 0)
4200 for (j
= p
->pc
->num_types
, pwgtype
= p
->pc
->types
;
4204 if (!ppdMarkOption(ppd
, "MediaType", pwgtype
->ppd
))
4206 val
->collection
= new_media_col(pwgsize
, NULL
, pwgtype
->pwg
);
4214 * Update the number of media-col-database values...
4217 attr
->num_values
= val
- attr
->values
;
4225 if (p
->pc
&& p
->pc
->num_bins
> 0)
4227 attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4228 "output-bin-supported", p
->pc
->num_bins
,
4233 for (i
= 0, val
= attr
->values
;
4234 i
< p
->pc
->num_bins
;
4236 val
->string
.text
= _cupsStrAlloc(p
->pc
->bins
[i
].pwg
);
4239 if ((output_bin
= ppdFindOption(ppd
, "OutputBin")) != NULL
)
4241 for (i
= 0; i
< p
->pc
->num_bins
; i
++)
4242 if (!strcmp(p
->pc
->bins
[i
].ppd
, output_bin
->defchoice
))
4245 if (i
>= p
->pc
->num_bins
)
4248 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4249 "output-bin-default", NULL
, p
->pc
->bins
[i
].pwg
);
4252 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4253 "output-bin-default", NULL
, p
->pc
->bins
[0].pwg
);
4255 else if (((ppd_attr
= ppdFindAttr(ppd
, "DefaultOutputOrder",
4257 !_cups_strcasecmp(ppd_attr
->value
, "Reverse")) ||
4258 (!ppd_attr
&& ppd
->manufacturer
&& /* "Compatibility heuristic" */
4259 (!_cups_strcasecmp(ppd
->manufacturer
, "epson") ||
4260 !_cups_strcasecmp(ppd
->manufacturer
, "lexmark"))))
4263 * Report that this printer has a single output bin that leaves pages face
4267 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4268 "output-bin-supported", NULL
, "face-up");
4269 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4270 "output-bin-default", NULL
, "face-up");
4274 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4275 "output-bin-supported", NULL
, "face-down");
4276 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4277 "output-bin-default", NULL
, "face-down");
4281 * output-mode and print-color-mode...
4284 if (ppd
->color_device
)
4286 static const char * const output_modes
[] =
4292 ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4293 "output-mode-supported", 2, NULL
, output_modes
);
4294 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4295 "output-mode-default", NULL
, "color");
4297 ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4298 "print-color-mode-supported", 2, NULL
, output_modes
);
4299 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4300 "print-color-mode-default", NULL
, "color");
4304 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4305 "output-mode-supported", NULL
, "monochrome");
4306 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4307 "output-mode-default", NULL
, "monochrome");
4309 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4310 "print-color-mode-supported", NULL
, "monochrome");
4311 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4312 "print-color-mode-default", NULL
, "monochrome");
4316 * Printer resolutions...
4319 if ((resolution
= ppdFindOption(ppd
, "Resolution")) == NULL
)
4320 if ((resolution
= ppdFindOption(ppd
, "JCLResolution")) == NULL
)
4321 if ((resolution
= ppdFindOption(ppd
, "SetResolution")) == NULL
)
4322 resolution
= ppdFindOption(ppd
, "CNRes_PGP");
4327 * Report all supported resolutions...
4330 attr
= ippAddResolutions(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4331 "printer-resolution-supported",
4332 resolution
->num_choices
, IPP_RES_PER_INCH
,
4335 for (i
= 0, choice
= resolution
->choices
;
4336 i
< resolution
->num_choices
;
4339 xdpi
= ydpi
= (int)strtol(choice
->choice
, (char **)&resptr
, 10);
4340 if (resptr
> choice
->choice
&& xdpi
> 0 && *resptr
== 'x')
4341 ydpi
= (int)strtol(resptr
+ 1, (char **)&resptr
, 10);
4343 if (xdpi
<= 0 || ydpi
<= 0)
4345 cupsdLogMessage(CUPSD_LOG_WARN
,
4346 "Bad resolution \"%s\" for printer %s.",
4347 choice
->choice
, p
->name
);
4351 attr
->values
[i
].resolution
.xres
= xdpi
;
4352 attr
->values
[i
].resolution
.yres
= ydpi
;
4353 attr
->values
[i
].resolution
.units
= IPP_RES_PER_INCH
;
4356 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4357 "printer-resolution-default", IPP_RES_PER_INCH
,
4361 else if ((ppd_attr
= ppdFindAttr(ppd
, "DefaultResolution", NULL
)) != NULL
&&
4365 * Just the DefaultResolution to report...
4368 xdpi
= ydpi
= (int)strtol(ppd_attr
->value
, (char **)&resptr
, 10);
4369 if (resptr
> ppd_attr
->value
&& xdpi
> 0)
4372 ydpi
= (int)strtol(resptr
+ 1, (char **)&resptr
, 10);
4377 if (xdpi
<= 0 || ydpi
<= 0)
4379 cupsdLogMessage(CUPSD_LOG_WARN
,
4380 "Bad default resolution \"%s\" for printer %s.",
4381 ppd_attr
->value
, p
->name
);
4385 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4386 "printer-resolution-default", IPP_RES_PER_INCH
,
4388 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4389 "printer-resolution-supported", IPP_RES_PER_INCH
,
4395 * No resolutions in PPD - make one up...
4398 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4399 "printer-resolution-default", IPP_RES_PER_INCH
,
4401 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4402 "printer-resolution-supported", IPP_RES_PER_INCH
,
4410 ppdMarkDefaults(ppd
);
4412 if ((duplex
= ppdFindOption(ppd
, "Duplex")) == NULL
)
4413 if ((duplex
= ppdFindOption(ppd
, "EFDuplex")) == NULL
)
4414 if ((duplex
= ppdFindOption(ppd
, "EFDuplexing")) == NULL
)
4415 if ((duplex
= ppdFindOption(ppd
, "KD03Duplex")) == NULL
)
4416 duplex
= ppdFindOption(ppd
, "JCLDuplex");
4418 if (duplex
&& duplex
->num_choices
> 1 &&
4419 !ppdInstallableConflict(ppd
, duplex
->keyword
, "DuplexTumble"))
4421 p
->type
|= CUPS_PRINTER_DUPLEX
;
4423 ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4424 "sides-supported", 3, NULL
, sides
);
4426 if (!_cups_strcasecmp(duplex
->defchoice
, "DuplexTumble"))
4427 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4428 "sides-default", NULL
, "two-sided-short-edge");
4429 else if (!_cups_strcasecmp(duplex
->defchoice
, "DuplexNoTumble"))
4430 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4431 "sides-default", NULL
, "two-sided-long-edge");
4433 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4434 "sides-default", NULL
, "one-sided");
4438 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4439 "sides-supported", NULL
, "one-sided");
4440 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4441 "sides-default", NULL
, "one-sided");
4444 if (ppdFindOption(ppd
, "Collate") != NULL
)
4445 p
->type
|= CUPS_PRINTER_COLLATE
;
4447 if (ppdFindOption(ppd
, "StapleLocation") != NULL
)
4449 p
->type
|= CUPS_PRINTER_STAPLE
;
4450 finishings
[num_finishings
++] = IPP_FINISHINGS_STAPLE
;
4453 if (ppdFindOption(ppd
, "BindEdge") != NULL
)
4455 p
->type
|= CUPS_PRINTER_BIND
;
4456 finishings
[num_finishings
++] = IPP_FINISHINGS_BIND
;
4459 for (i
= 0; i
< ppd
->num_sizes
; i
++)
4460 if (ppd
->sizes
[i
].length
> 1728)
4461 p
->type
|= CUPS_PRINTER_LARGE
;
4462 else if (ppd
->sizes
[i
].length
> 1008)
4463 p
->type
|= CUPS_PRINTER_MEDIUM
;
4465 p
->type
|= CUPS_PRINTER_SMALL
;
4467 if ((ppd_attr
= ppdFindAttr(ppd
, "APICADriver", NULL
)) != NULL
&&
4468 ppd_attr
->value
&& !_cups_strcasecmp(ppd_attr
->value
, "true"))
4470 if ((ppd_attr
= ppdFindAttr(ppd
, "APScannerOnly", NULL
)) != NULL
&&
4471 ppd_attr
->value
&& !_cups_strcasecmp(ppd_attr
->value
, "true"))
4472 p
->type
|= CUPS_PRINTER_SCANNER
;
4474 p
->type
|= CUPS_PRINTER_MFP
;
4478 * Scan the filters in the PPD file...
4483 for (filter
= (const char *)cupsArrayFirst(p
->pc
->filters
);
4485 filter
= (const char *)cupsArrayNext(p
->pc
->filters
))
4487 if (!_cups_strncasecmp(filter
, "application/vnd.cups-command", 28) &&
4488 _cups_isspace(filter
[28]))
4490 p
->type
|= CUPS_PRINTER_COMMANDS
;
4496 if (p
->type
& CUPS_PRINTER_COMMANDS
)
4498 char *commands
, /* Copy of commands */
4499 *start
, /* Start of name */
4500 *end
; /* End of name */
4501 int count
; /* Number of commands */
4503 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsCommands", NULL
)) != NULL
)
4505 for (count
= 0, start
= ppd_attr
->value
; *start
; count
++)
4507 while (_cups_isspace(*start
))
4513 while (*start
&& !isspace(*start
& 255))
4523 * Make a copy of the commands string and count how many commands there
4527 attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4528 "printer-commands", count
, NULL
, NULL
);
4530 commands
= strdup(ppd_attr
->value
);
4532 for (count
= 0, start
= commands
; *start
; count
++)
4534 while (isspace(*start
& 255))
4541 while (*end
&& !isspace(*end
& 255))
4547 attr
->values
[count
].string
.text
= _cupsStrAlloc(start
);
4557 * Add the standard list of commands...
4560 ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4562 (int)(sizeof(standard_commands
) /
4563 sizeof(standard_commands
[0])), NULL
,
4570 * No commands supported...
4573 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4574 "printer-commands", NULL
, "none");
4578 * Show current and available port monitors for this printer...
4581 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
, "port-monitor",
4582 NULL
, p
->port_monitor
? p
->port_monitor
: "none");
4584 for (i
= 1, ppd_attr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
4586 i
++, ppd_attr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
));
4590 if (strstr(ppd
->protocols
, "TBCP"))
4592 else if (strstr(ppd
->protocols
, "BCP"))
4596 attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
4597 "port-monitor-supported", i
, NULL
, NULL
);
4599 attr
->values
[0].string
.text
= _cupsStrAlloc("none");
4601 for (i
= 1, ppd_attr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
4603 i
++, ppd_attr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
))
4604 attr
->values
[i
].string
.text
= _cupsStrAlloc(ppd_attr
->value
);
4608 if (strstr(ppd
->protocols
, "TBCP"))
4609 attr
->values
[i
].string
.text
= _cupsStrAlloc("tbcp");
4610 else if (strstr(ppd
->protocols
, "BCP"))
4611 attr
->values
[i
].string
.text
= _cupsStrAlloc("bcp");
4614 if (ppdFindAttr(ppd
, "APRemoteQueueID", NULL
))
4615 p
->type
|= CUPS_PRINTER_REMOTE
;
4617 #ifdef HAVE_APPLICATIONSERVICES_H
4619 * Convert the file referenced in APPrinterIconPath to a 128x128 PNG
4620 * and save it as cacheDir/printername.png
4623 if ((ppd_attr
= ppdFindAttr(ppd
, "APPrinterIconPath", NULL
)) != NULL
&&
4625 !_cupsFileCheck(ppd_attr
->value
, _CUPS_FILE_CHECK_FILE
, !RunUser
,
4626 cupsdLogFCMessage
, p
))
4628 CGImageRef imageRef
= NULL
;/* Current icon image */
4629 CGImageRef biggestIconRef
= NULL
;
4630 /* Biggest icon image */
4631 CGImageRef closestTo128IconRef
= NULL
;
4632 /* Icon image closest to and >= 128 */
4633 CGImageSourceRef sourceRef
; /* The file's image source */
4634 char outPath
[HTTP_MAX_URI
];
4635 /* The path to the PNG file */
4636 CFURLRef outUrl
; /* The URL made from the outPath */
4637 CFURLRef icnsFileUrl
; /* The URL of the original ICNS icon file */
4638 CGImageDestinationRef destRef
; /* The image destination to write */
4639 size_t bytesPerRow
; /* The bytes per row used for resizing */
4640 CGContextRef context
; /* The CG context used for resizing */
4642 snprintf(outPath
, sizeof(outPath
), "%s/%s.png", CacheDir
, p
->name
);
4643 outUrl
= CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault
,
4647 icnsFileUrl
= CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault
,
4648 (UInt8
*)ppd_attr
->value
,
4649 strlen(ppd_attr
->value
),
4651 if (outUrl
&& icnsFileUrl
)
4653 sourceRef
= CGImageSourceCreateWithURL(icnsFileUrl
, NULL
);
4656 for (i
= 0; i
< CGImageSourceGetCount(sourceRef
); i
++)
4658 imageRef
= CGImageSourceCreateImageAtIndex(sourceRef
, i
, NULL
);
4662 if (CGImageGetWidth(imageRef
) == CGImageGetHeight(imageRef
))
4665 * Loop through remembering the icon closest to 128 but >= 128
4666 * and then remember the largest icon.
4669 if (CGImageGetWidth(imageRef
) >= 128 &&
4670 (!closestTo128IconRef
||
4671 CGImageGetWidth(imageRef
) <
4672 CGImageGetWidth(closestTo128IconRef
)))
4674 CGImageRelease(closestTo128IconRef
);
4675 CGImageRetain(imageRef
);
4676 closestTo128IconRef
= imageRef
;
4679 if (!biggestIconRef
||
4680 CGImageGetWidth(imageRef
) > CGImageGetWidth(biggestIconRef
))
4682 CGImageRelease(biggestIconRef
);
4683 CGImageRetain(imageRef
);
4684 biggestIconRef
= imageRef
;
4688 CGImageRelease(imageRef
);
4694 * If biggestIconRef is NULL, we found no icons. Otherwise we first
4695 * want the closest to 128, but if none are larger than 128, we want
4696 * the largest icon available.
4699 imageRef
= closestTo128IconRef
? closestTo128IconRef
:
4701 CGImageRetain(imageRef
);
4702 CGImageRelease(biggestIconRef
);
4703 if (closestTo128IconRef
)
4704 CGImageRelease(closestTo128IconRef
);
4705 destRef
= CGImageDestinationCreateWithURL(outUrl
, kUTTypePNG
, 1,
4709 if (CGImageGetWidth(imageRef
) != 128)
4711 bytesPerRow
= CGImageGetBytesPerRow(imageRef
) /
4712 CGImageGetWidth(imageRef
) * 128;
4713 context
= CGBitmapContextCreate(NULL
, 128, 128,
4714 CGImageGetBitsPerComponent(imageRef
),
4716 CGImageGetColorSpace(imageRef
),
4717 kCGImageAlphaPremultipliedFirst
);
4720 CGContextDrawImage(context
, CGRectMake(0, 0, 128, 128),
4722 CGImageRelease(imageRef
);
4723 imageRef
= CGBitmapContextCreateImage(context
);
4724 CGContextRelease(context
);
4728 CGImageDestinationAddImage(destRef
, imageRef
, NULL
);
4729 CGImageDestinationFinalize(destRef
);
4733 CGImageRelease(imageRef
);
4736 CFRelease(sourceRef
);
4744 CFRelease(icnsFileUrl
);
4746 #endif /* HAVE_APPLICATIONSERVICES_H */
4749 * Close the PPD and set the type...
4754 else if (!access(ppd_name
, 0))
4756 int pline
; /* PPD line number */
4757 ppd_status_t pstatus
; /* PPD load status */
4760 pstatus
= ppdLastError(&pline
);
4762 cupsdLogMessage(CUPSD_LOG_ERROR
, "PPD file for %s cannot be loaded!",
4765 if (pstatus
<= PPD_ALLOC_ERROR
)
4766 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s", strerror(errno
));
4768 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s on line %d.",
4769 ppdErrorString(pstatus
), pline
);
4771 cupsdLogMessage(CUPSD_LOG_INFO
,
4772 "Hint: Run \"cupstestppd %s\" and fix any errors.",
4778 * If we have an interface script, add a filter entry for it...
4781 char interface
[1024]; /* Interface script */
4784 snprintf(interface
, sizeof(interface
), "%s/interfaces/%s", ServerRoot
,
4786 if (!access(interface
, X_OK
))
4789 * Yes, we have a System V style interface script; use it!
4792 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
4793 "printer-make-and-model", NULL
,
4794 "Local System V Printer");
4796 else if (!strncmp(p
->device_uri
, "ipp://", 6) &&
4797 (strstr(p
->device_uri
, "/printers/") != NULL
||
4798 strstr(p
->device_uri
, "/classes/") != NULL
||
4799 (strstr(p
->device_uri
, "._ipp.") != NULL
&&
4800 !strcmp(p
->device_uri
+ strlen(p
->device_uri
) - 5,
4804 * Tell the client this is really a hard-wired remote printer.
4807 p
->type
|= CUPS_PRINTER_REMOTE
;
4810 * Point the printer-uri-supported attribute to the
4814 if (strchr(p
->device_uri
, '?'))
4817 * Strip trailing "?options" from URI...
4820 char resource
[HTTP_MAX_URI
], /* New URI */
4821 *ptr
; /* Pointer into URI */
4823 strlcpy(resource
, p
->device_uri
, sizeof(resource
));
4824 if ((ptr
= strchr(resource
, '?')) != NULL
)
4827 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
4828 "printer-uri-supported", NULL
, resource
);
4831 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
4832 "printer-uri-supported", NULL
, p
->device_uri
);
4835 * Then set the make-and-model accordingly...
4838 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
4839 "printer-make-and-model", NULL
, "Remote Printer");
4842 * Print all files directly...
4851 * Otherwise we have neither - treat this as a "dumb" printer
4852 * with no PPD file...
4855 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
4856 "printer-make-and-model", NULL
, "Local Raw Printer");
4862 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
4863 "finishings-supported", num_finishings
, finishings
);
4864 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
4865 "finishings-default", IPP_FINISHINGS_NONE
);
4870 * Save cached PPD attributes to disk...
4873 cupsdLogMessage(CUPSD_LOG_DEBUG
, "load_ppd: Saving %s...", cache_name
);
4875 _ppdCacheWriteFile(p
->pc
, cache_name
, p
->ppd_attrs
);
4880 * Remove cache files...
4883 if (cache_info
.st_mtime
)
4890 * 'log_ipp_conformance()' - Log an IPP conformance issue with a printer.
4894 log_ipp_conformance(
4895 cupsd_printer_t
*p
, /* I - Printer */
4896 const char *reason
) /* I - Printer state reason */
4898 const char *message
; /* Message to log */
4900 aslmsg aslm
; /* Apple System Log message */
4901 #endif /* __APPLE__ */
4905 * Strip the leading "cups-ipp-" from the reason and create a log message for
4910 if (!strcmp(reason
, "missing-cancel-job"))
4911 message
= "Printer does not support REQUIRED Cancel-Job operation.";
4912 else if (!strcmp(reason
, "missing-get-job-attributes"))
4913 message
= "Printer does not support REQUIRED Get-Job-Attributes operation.";
4914 else if (!strcmp(reason
, "missing-print-job"))
4915 message
= "Printer does not support REQUIRED Print-Job operation.";
4916 else if (!strcmp(reason
, "missing-validate-job"))
4917 message
= "Printer does not support REQUIRED Validate-Job operation.";
4918 else if (!strcmp(reason
, "missing-get-printer-attributes"))
4919 message
= "Printer does not support REQUIRED Get-Printer-Attributes operation.";
4920 else if (!strcmp(reason
, "missing-job-history"))
4921 message
= "Printer does not provide REQUIRED job history.";
4922 else if (!strcmp(reason
, "missing-job-id"))
4923 message
= "Printer does not provide REQUIRED job-id attribute.";
4924 else if (!strcmp(reason
, "missing-job-state"))
4925 message
= "Printer does not provide REQUIRED job-state attribute.";
4926 else if (!strcmp(reason
, "missing-operations-supported"))
4927 message
= "Printer does not provide REQUIRED operations-supported "
4929 else if (!strcmp(reason
, "missing-printer-is-accepting-jobs"))
4930 message
= "Printer does not provide REQUIRED printer-is-accepting-jobs "
4932 else if (!strcmp(reason
, "missing-printer-state-reasons"))
4933 message
= "Printer does not provide REQUIRED printer-state-reasons "
4935 else if (!strcmp(reason
, "wrong-http-version"))
4936 message
= "Printer does not use REQUIRED HTTP/1.1 transport.";
4938 message
= "Unknown IPP conformance failure.";
4940 cupsdLogMessage(CUPSD_LOG_WARN
, "%s: %s", p
->name
, message
);
4944 * Report the failure information to Apple if the user opts into providing
4945 * feedback to Apple...
4948 aslm
= asl_new(ASL_TYPE_MSG
);
4951 asl_set(aslm
, "com.apple.message.domain", "com.apple.printing.ipp.conformance");
4952 asl_set(aslm
, "com.apple.message.domain_scope", "com.apple.printing.ipp.conformance");
4953 asl_set(aslm
, "com.apple.message.signature", reason
);
4954 asl_set(aslm
, "com.apple.message.signature2",
4955 p
->make_model
? p
->make_model
: "Unknown");
4956 asl_log(NULL
, aslm
, ASL_LEVEL_NOTICE
, "%s: %s",
4957 p
->make_model
? p
->make_model
: "Unknown", message
);
4960 #endif /* __APPLE__ */
4965 * 'new_media_col()' - Create a media-col collection value.
4968 static ipp_t
* /* O - Collection value */
4969 new_media_col(_pwg_size_t
*size
, /* I - media-size/margin values */
4970 const char *source
, /* I - media-source value */
4971 const char *type
) /* I - media-type value */
4973 ipp_t
*media_col
, /* Collection value */
4974 *media_size
; /* media-size value */
4977 media_col
= ippNew();
4979 media_size
= ippNew();
4980 ippAddInteger(media_size
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4981 "x-dimension", size
->width
);
4982 ippAddInteger(media_size
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4983 "y-dimension", size
->length
);
4984 ippAddCollection(media_col
, IPP_TAG_PRINTER
, "media-size", media_size
);
4985 ippDelete(media_size
);
4987 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4988 "media-bottom-margin", size
->bottom
);
4989 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4990 "media-left-margin", size
->left
);
4991 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4992 "media-right-margin", size
->right
);
4993 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4994 "media-top-margin", size
->top
);
4997 ippAddString(media_col
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
, "media-source",
5001 ippAddString(media_col
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
, "media-type",
5010 * 'write_irix_config()' - Update the config files used by the IRIX
5015 write_irix_config(cupsd_printer_t
*p
) /* I - Printer to update */
5017 char filename
[1024]; /* Interface script filename */
5018 cups_file_t
*fp
; /* Interface script file */
5019 ipp_attribute_t
*attr
; /* Attribute data */
5023 * Add dummy interface and GUI scripts to fool SGI's "challenged" printing
5024 * tools. First the interface script that tells the tools what kind of
5025 * printer we have...
5028 snprintf(filename
, sizeof(filename
), "/var/spool/lp/interface/%s", p
->name
);
5030 if (p
->type
& CUPS_PRINTER_CLASS
)
5032 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
5034 cupsFilePuts(fp
, "#!/bin/sh\n");
5036 if ((attr
= ippFindAttribute(p
->attrs
, "printer-make-and-model",
5037 IPP_TAG_TEXT
)) != NULL
)
5038 cupsFilePrintf(fp
, "NAME=\"%s\"\n", attr
->values
[0].string
.text
);
5039 else if (p
->type
& CUPS_PRINTER_CLASS
)
5040 cupsFilePuts(fp
, "NAME=\"Printer Class\"\n");
5042 cupsFilePuts(fp
, "NAME=\"Remote Destination\"\n");
5044 if (p
->type
& CUPS_PRINTER_COLOR
)
5045 cupsFilePuts(fp
, "TYPE=ColorPostScript\n");
5047 cupsFilePuts(fp
, "TYPE=MonoPostScript\n");
5049 cupsFilePrintf(fp
, "HOSTNAME=%s\n", ServerName
);
5050 cupsFilePrintf(fp
, "HOSTPRINTER=%s\n", p
->name
);
5054 chmod(filename
, 0755);
5055 chown(filename
, User
, Group
);
5059 * Then the member file that tells which device file the queue is connected
5060 * to... Networked printers use "/dev/null" in this file, so that's what
5061 * we use (the actual device URI can confuse some apps...)
5064 snprintf(filename
, sizeof(filename
), "/var/spool/lp/member/%s", p
->name
);
5066 if (p
->type
& CUPS_PRINTER_CLASS
)
5068 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
5070 cupsFilePuts(fp
, "/dev/null\n");
5074 chmod(filename
, 0644);
5075 chown(filename
, User
, Group
);
5079 * The gui_interface file is a script or program that launches a GUI
5080 * option panel for the printer, using options specified on the
5081 * command-line in the third argument. The option panel must send
5082 * any printing options to stdout on a single line when the user
5083 * accepts them, or nothing if the user cancels the dialog.
5085 * The default options panel program is /usr/bin/glpoptions, from
5086 * the ESP Print Pro software. You can select another using the
5087 * PrintcapGUI option.
5090 snprintf(filename
, sizeof(filename
), "/var/spool/lp/gui_interface/ELF/%s.gui", p
->name
);
5092 if (p
->type
& CUPS_PRINTER_CLASS
)
5094 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
5096 cupsFilePuts(fp
, "#!/bin/sh\n");
5097 cupsFilePrintf(fp
, "%s -d %s -o \"$3\"\n", PrintcapGUI
, p
->name
);
5101 chmod(filename
, 0755);
5102 chown(filename
, User
, Group
);
5106 * The POD config file is needed by the printstatus command to show
5107 * the printer location and device.
5110 snprintf(filename
, sizeof(filename
), "/var/spool/lp/pod/%s.config", p
->name
);
5112 if (p
->type
& CUPS_PRINTER_CLASS
)
5114 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
5116 cupsFilePrintf(fp
, "Printer Class | %s\n",
5117 (p
->type
& CUPS_PRINTER_COLOR
) ? "ColorPostScript" : "MonoPostScript");
5118 cupsFilePrintf(fp
, "Printer Model | %s\n", p
->make_model
? p
->make_model
: "");
5119 cupsFilePrintf(fp
, "Location Code | %s\n", p
->location
? p
->location
: "");
5120 cupsFilePrintf(fp
, "Physical Location | %s\n", p
->info
? p
->info
: "");
5121 cupsFilePrintf(fp
, "Port Path | %s\n", p
->device_uri
);
5122 cupsFilePrintf(fp
, "Config Path | /var/spool/lp/pod/%s.config\n", p
->name
);
5123 cupsFilePrintf(fp
, "Active Status Path | /var/spool/lp/pod/%s.status\n", p
->name
);
5124 cupsFilePuts(fp
, "Status Update Wait | 10 seconds\n");
5128 chmod(filename
, 0664);
5129 chown(filename
, User
, Group
);
5135 * 'write_irix_state()' - Update the status files used by IRIX printing
5140 write_irix_state(cupsd_printer_t
*p
) /* I - Printer to update */
5142 char filename
[1024]; /* Interface script filename */
5143 cups_file_t
*fp
; /* Interface script file */
5144 int tag
; /* Status tag value */
5150 * The POD status file is needed for the printstatus window to
5151 * provide the current status of the printer.
5154 snprintf(filename
, sizeof(filename
), "/var/spool/lp/pod/%s.status", p
->name
);
5156 if (p
->type
& CUPS_PRINTER_CLASS
)
5158 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
5160 cupsFilePrintf(fp
, "Operational Status | %s\n",
5161 (p
->state
== IPP_PRINTER_IDLE
) ? "Idle" :
5162 (p
->state
== IPP_PRINTER_PROCESSING
) ? "Busy" :
5164 cupsFilePrintf(fp
, "Information | 01 00 00 | %s\n", CUPS_SVERSION
);
5165 cupsFilePrintf(fp
, "Information | 02 00 00 | Device URI: %s\n",
5167 cupsFilePrintf(fp
, "Information | 03 00 00 | %s jobs\n",
5168 p
->accepting
? "Accepting" : "Not accepting");
5169 cupsFilePrintf(fp
, "Information | 04 00 00 | %s\n", p
->state_message
);
5173 chmod(filename
, 0664);
5174 chown(filename
, User
, Group
);
5178 * The activeicons file is needed to provide desktop icons for printers:
5180 * [ quoted from /usr/lib/print/tagit ]
5182 * --- Type of printer tags (base values)
5184 * Dumb=66048 # 0x10200
5185 * DumbColor=66080 # 0x10220
5186 * Raster=66112 # 0x10240
5187 * ColorRaster=66144 # 0x10260
5188 * Plotter=66176 # 0x10280
5189 * PostScript=66208 # 0x102A0
5190 * ColorPostScript=66240 # 0x102C0
5191 * MonoPostScript=66272 # 0x102E0
5193 * --- Printer state modifiers for local printers
5198 * Unknown=3 # 0x3 (Faulted due to unknown reason)
5200 * --- Printer state modifiers for network printers
5204 * NetFaulted=10 # 0xA
5205 * NetUnknown=11 # 0xB (Faulted due to unknown reason)
5208 snprintf(filename
, sizeof(filename
), "/var/spool/lp/activeicons/%s", p
->name
);
5210 if (p
->type
& CUPS_PRINTER_CLASS
)
5212 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
5214 if (p
->type
& CUPS_PRINTER_COLOR
)
5219 if (p
->type
& CUPS_PRINTER_REMOTE
)
5222 if (p
->state
== IPP_PRINTER_PROCESSING
)
5225 else if (p
->state
== IPP_PRINTER_STOPPED
)
5228 cupsFilePuts(fp
, "#!/bin/sh\n");
5229 cupsFilePrintf(fp
, "#Tag %d\n", tag
);
5233 chmod(filename
, 0755);
5234 chown(filename
, User
, Group
);
5239 * The default file is needed by the printers window to show
5240 * the default printer.
5243 snprintf(filename
, sizeof(filename
), "/var/spool/lp/default");
5245 if (DefaultPrinter
!= NULL
)
5247 if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
5249 cupsFilePrintf(fp
, "%s\n", DefaultPrinter
->name
);
5253 chmod(filename
, 0644);
5254 chown(filename
, User
, Group
);
5264 * 'write_xml_string()' - Write a string with XML escaping.
5268 write_xml_string(cups_file_t
*fp
, /* I - File to write to */
5269 const char *s
) /* I - String to write */
5271 const char *start
; /* Start of current sequence */
5277 for (start
= s
; *s
; s
++)
5282 cupsFileWrite(fp
, start
, s
- start
);
5284 cupsFilePuts(fp
, "&");
5290 cupsFileWrite(fp
, start
, s
- start
);
5292 cupsFilePuts(fp
, "<");
5298 cupsFilePuts(fp
, start
);
5303 * End of "$Id: printers.c 7968 2008-09-19 23:03:01Z mike $".