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
);
840 #if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
841 cupsdClearString(&p
->pdl
);
842 cupsdClearString(&p
->reg_name
);
843 #endif /* HAVE_DNSSD || HAVE_AVAHI */
845 cupsArrayDelete(p
->filetypes
);
847 cupsFreeOptions(p
->num_options
, p
->options
);
852 * Restore the previous position in the Printers array...
855 cupsArrayRestore(Printers
);
862 * 'cupsdFindDest()' - Find a destination in the list.
865 cupsd_printer_t
* /* O - Destination in list */
866 cupsdFindDest(const char *name
) /* I - Name of printer or class to find */
868 cupsd_printer_t key
; /* Search key */
871 key
.name
= (char *)name
;
872 return ((cupsd_printer_t
*)cupsArrayFind(Printers
, &key
));
877 * 'cupsdFindPrinter()' - Find a printer in the list.
880 cupsd_printer_t
* /* O - Printer in list */
881 cupsdFindPrinter(const char *name
) /* I - Name of printer to find */
883 cupsd_printer_t
*p
; /* Printer in list */
886 if ((p
= cupsdFindDest(name
)) != NULL
&& (p
->type
& CUPS_PRINTER_CLASS
))
894 * 'cupsdLoadAllPrinters()' - Load printers from the printers.conf file.
898 cupsdLoadAllPrinters(void)
900 int i
; /* Looping var */
901 cups_file_t
*fp
; /* printers.conf file */
902 int linenum
; /* Current line number */
903 char line
[4096], /* Line from file */
904 *value
, /* Pointer to value */
905 *valueptr
; /* Pointer into value */
906 cupsd_printer_t
*p
; /* Current printer */
910 * Open the printers.conf file...
913 snprintf(line
, sizeof(line
), "%s/printers.conf", ServerRoot
);
914 if ((fp
= cupsdOpenConfFile(line
)) == NULL
)
918 * Read printer configurations until we hit EOF...
924 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
927 * Decode the directive...
930 if (!_cups_strcasecmp(line
, "<Printer") ||
931 !_cups_strcasecmp(line
, "<DefaultPrinter"))
934 * <Printer name> or <DefaultPrinter name>
937 if (p
== NULL
&& value
)
940 * Add the printer and a base file type...
943 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Loading printer %s...", value
);
945 p
= cupsdAddPrinter(value
);
947 p
->state
= IPP_PRINTER_IDLE
;
950 * Set the default printer as needed...
953 if (!_cups_strcasecmp(line
, "<DefaultPrinter"))
957 cupsdLogMessage(CUPSD_LOG_ERROR
,
958 "Syntax error on line %d of printers.conf.", linenum
);
960 else if (!_cups_strcasecmp(line
, "</Printer>"))
965 * Close out the current printer...
968 cupsdSetPrinterAttrs(p
);
970 if (strncmp(p
->device_uri
, "file:", 5) &&
971 p
->state
!= IPP_PRINTER_STOPPED
)
974 * See if the backend exists...
977 snprintf(line
, sizeof(line
), "%s/backend/%s", ServerBin
,
980 if ((valueptr
= strchr(line
+ strlen(ServerBin
), ':')) != NULL
)
981 *valueptr
= '\0'; /* Chop everything but URI scheme */
986 * Backend does not exist, stop printer...
989 p
->state
= IPP_PRINTER_STOPPED
;
990 snprintf(p
->state_message
, sizeof(p
->state_message
),
991 "Backend %s does not exist!", line
);
998 cupsdLogMessage(CUPSD_LOG_ERROR
,
999 "Syntax error on line %d of printers.conf.", linenum
);
1003 cupsdLogMessage(CUPSD_LOG_ERROR
,
1004 "Syntax error on line %d of printers.conf.", linenum
);
1006 else if (!_cups_strcasecmp(line
, "UUID"))
1008 if (value
&& !strncmp(value
, "urn:uuid:", 9))
1009 cupsdSetString(&(p
->uuid
), value
);
1011 cupsdLogMessage(CUPSD_LOG_ERROR
,
1012 "Bad UUID on line %d of printers.conf.", linenum
);
1014 else if (!_cups_strcasecmp(line
, "AuthInfoRequired"))
1016 if (!cupsdSetAuthInfoRequired(p
, value
, NULL
))
1017 cupsdLogMessage(CUPSD_LOG_ERROR
,
1018 "Bad AuthInfoRequired on line %d of printers.conf.",
1021 else if (!_cups_strcasecmp(line
, "Info"))
1024 cupsdSetString(&p
->info
, value
);
1026 else if (!_cups_strcasecmp(line
, "MakeModel"))
1029 cupsdSetString(&p
->make_model
, value
);
1031 else if (!_cups_strcasecmp(line
, "Location"))
1034 cupsdSetString(&p
->location
, value
);
1036 else if (!_cups_strcasecmp(line
, "DeviceURI"))
1039 cupsdSetDeviceURI(p
, value
);
1041 cupsdLogMessage(CUPSD_LOG_ERROR
,
1042 "Syntax error on line %d of printers.conf.", linenum
);
1044 else if (!_cups_strcasecmp(line
, "Option") && value
)
1050 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1053 cupsdLogMessage(CUPSD_LOG_ERROR
,
1054 "Syntax error on line %d of printers.conf.", linenum
);
1057 for (; *valueptr
&& isspace(*valueptr
& 255); *valueptr
++ = '\0');
1059 p
->num_options
= cupsAddOption(value
, valueptr
, p
->num_options
,
1063 else if (!_cups_strcasecmp(line
, "PortMonitor"))
1065 if (value
&& strcmp(value
, "none"))
1066 cupsdSetString(&p
->port_monitor
, value
);
1068 cupsdClearString(&p
->port_monitor
);
1070 cupsdLogMessage(CUPSD_LOG_ERROR
,
1071 "Syntax error on line %d of printers.conf.", linenum
);
1073 else if (!_cups_strcasecmp(line
, "Reason"))
1076 strcmp(value
, "connecting-to-device") &&
1077 strcmp(value
, "cups-insecure-filter-warning") &&
1078 strcmp(value
, "cups-missing-filter-warning"))
1080 for (i
= 0 ; i
< p
->num_reasons
; i
++)
1081 if (!strcmp(value
, p
->reasons
[i
]))
1084 if (i
>= p
->num_reasons
&&
1085 p
->num_reasons
< (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
1087 p
->reasons
[p
->num_reasons
] = _cupsStrAlloc(value
);
1092 cupsdLogMessage(CUPSD_LOG_ERROR
,
1093 "Syntax error on line %d of printers.conf.", linenum
);
1095 else if (!_cups_strcasecmp(line
, "State"))
1098 * Set the initial queue state...
1101 if (value
&& !_cups_strcasecmp(value
, "idle"))
1102 p
->state
= IPP_PRINTER_IDLE
;
1103 else if (value
&& !_cups_strcasecmp(value
, "stopped"))
1105 p
->state
= IPP_PRINTER_STOPPED
;
1107 for (i
= 0 ; i
< p
->num_reasons
; i
++)
1108 if (!strcmp("paused", p
->reasons
[i
]))
1111 if (i
>= p
->num_reasons
&&
1112 p
->num_reasons
< (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
1114 p
->reasons
[p
->num_reasons
] = _cupsStrAlloc("paused");
1119 cupsdLogMessage(CUPSD_LOG_ERROR
,
1120 "Syntax error on line %d of printers.conf.", linenum
);
1122 else if (!_cups_strcasecmp(line
, "StateMessage"))
1125 * Set the initial queue state message...
1129 strlcpy(p
->state_message
, value
, sizeof(p
->state_message
));
1131 else if (!_cups_strcasecmp(line
, "StateTime"))
1134 * Set the state time...
1138 p
->state_time
= atoi(value
);
1140 else if (!_cups_strcasecmp(line
, "Accepting"))
1143 * Set the initial accepting state...
1147 (!_cups_strcasecmp(value
, "yes") ||
1148 !_cups_strcasecmp(value
, "on") ||
1149 !_cups_strcasecmp(value
, "true")))
1152 (!_cups_strcasecmp(value
, "no") ||
1153 !_cups_strcasecmp(value
, "off") ||
1154 !_cups_strcasecmp(value
, "false")))
1157 cupsdLogMessage(CUPSD_LOG_ERROR
,
1158 "Syntax error on line %d of printers.conf.", linenum
);
1160 else if (!_cups_strcasecmp(line
, "Type"))
1163 p
->type
= atoi(value
);
1165 cupsdLogMessage(CUPSD_LOG_ERROR
,
1166 "Syntax error on line %d of printers.conf.", linenum
);
1168 else if (!_cups_strcasecmp(line
, "Shared"))
1171 * Set the initial shared state...
1175 (!_cups_strcasecmp(value
, "yes") ||
1176 !_cups_strcasecmp(value
, "on") ||
1177 !_cups_strcasecmp(value
, "true")))
1180 (!_cups_strcasecmp(value
, "no") ||
1181 !_cups_strcasecmp(value
, "off") ||
1182 !_cups_strcasecmp(value
, "false")))
1185 cupsdLogMessage(CUPSD_LOG_ERROR
,
1186 "Syntax error on line %d of printers.conf.", linenum
);
1188 else if (!_cups_strcasecmp(line
, "JobSheets"))
1191 * Set the initial job sheets...
1196 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1201 cupsdSetString(&p
->job_sheets
[0], value
);
1203 while (isspace(*valueptr
& 255))
1208 for (value
= valueptr
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1213 cupsdSetString(&p
->job_sheets
[1], value
);
1217 cupsdLogMessage(CUPSD_LOG_ERROR
,
1218 "Syntax error on line %d of printers.conf.", linenum
);
1220 else if (!_cups_strcasecmp(line
, "AllowUser"))
1225 cupsdAddString(&(p
->users
), value
);
1228 cupsdLogMessage(CUPSD_LOG_ERROR
,
1229 "Syntax error on line %d of printers.conf.", linenum
);
1231 else if (!_cups_strcasecmp(line
, "DenyUser"))
1236 cupsdAddString(&(p
->users
), value
);
1239 cupsdLogMessage(CUPSD_LOG_ERROR
,
1240 "Syntax error on line %d of printers.conf.", linenum
);
1242 else if (!_cups_strcasecmp(line
, "QuotaPeriod"))
1245 p
->quota_period
= atoi(value
);
1247 cupsdLogMessage(CUPSD_LOG_ERROR
,
1248 "Syntax error on line %d of printers.conf.", linenum
);
1250 else if (!_cups_strcasecmp(line
, "PageLimit"))
1253 p
->page_limit
= atoi(value
);
1255 cupsdLogMessage(CUPSD_LOG_ERROR
,
1256 "Syntax error on line %d of printers.conf.", linenum
);
1258 else if (!_cups_strcasecmp(line
, "KLimit"))
1261 p
->k_limit
= atoi(value
);
1263 cupsdLogMessage(CUPSD_LOG_ERROR
,
1264 "Syntax error on line %d of printers.conf.", linenum
);
1266 else if (!_cups_strcasecmp(line
, "OpPolicy"))
1270 cupsd_policy_t
*pol
; /* Policy */
1273 if ((pol
= cupsdFindPolicy(value
)) != NULL
)
1275 cupsdSetString(&p
->op_policy
, value
);
1276 p
->op_policy_ptr
= pol
;
1279 cupsdLogMessage(CUPSD_LOG_ERROR
,
1280 "Bad policy \"%s\" on line %d of printers.conf",
1284 cupsdLogMessage(CUPSD_LOG_ERROR
,
1285 "Syntax error on line %d of printers.conf.", linenum
);
1287 else if (!_cups_strcasecmp(line
, "ErrorPolicy"))
1290 cupsdSetString(&p
->error_policy
, value
);
1292 cupsdLogMessage(CUPSD_LOG_ERROR
,
1293 "Syntax error on line %d of printers.conf.", linenum
);
1295 else if (!_cups_strcasecmp(line
, "Attribute") && value
)
1297 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1300 cupsdLogMessage(CUPSD_LOG_ERROR
,
1301 "Syntax error on line %d of printers.conf.", linenum
);
1304 for (; *valueptr
&& isspace(*valueptr
& 255); *valueptr
++ = '\0');
1307 cupsdSetPrinterAttrs(p
);
1309 if (!strcmp(value
, "marker-change-time"))
1310 p
->marker_time
= atoi(valueptr
);
1312 cupsdSetPrinterAttr(p
, value
, valueptr
);
1315 else if (_cups_strcasecmp(line
, "Filter") &&
1316 _cups_strcasecmp(line
, "Prefilter") &&
1317 _cups_strcasecmp(line
, "Product"))
1320 * Something else we don't understand (and that wasn't used in a prior
1321 * release of CUPS...
1324 cupsdLogMessage(CUPSD_LOG_ERROR
,
1325 "Unknown configuration directive %s on line %d of "
1326 "printers.conf.", line
, linenum
);
1335 * 'cupsdRenamePrinter()' - Rename a printer.
1340 cupsd_printer_t
*p
, /* I - Printer */
1341 const char *name
) /* I - New name */
1344 * Remove the printer from the array(s) first...
1347 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1348 "cupsdRenamePrinter: Removing %s from Printers", p
->name
);
1349 cupsArrayRemove(Printers
, p
);
1352 * Rename the printer type...
1355 mimeDeleteType(MimeDatabase
, p
->filetype
);
1356 p
->filetype
= mimeAddType(MimeDatabase
, "printer", name
);
1358 if (p
->prefiltertype
)
1360 mimeDeleteType(MimeDatabase
, p
->prefiltertype
);
1361 p
->prefiltertype
= mimeAddType(MimeDatabase
, "prefilter", name
);
1365 * Rename the printer...
1368 cupsdSetString(&p
->name
, name
);
1371 * Reset printer attributes...
1374 cupsdSetPrinterAttrs(p
);
1377 * Add the printer back to the printer array(s)...
1380 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1381 "cupsdRenamePrinter: Adding %s to Printers", p
->name
);
1382 cupsArrayAdd(Printers
, p
);
1387 * 'cupsdSaveAllPrinters()' - Save all printer definitions to the printers.conf
1392 cupsdSaveAllPrinters(void)
1394 int i
; /* Looping var */
1395 cups_file_t
*fp
; /* printers.conf file */
1396 char filename
[1024], /* printers.conf filename */
1397 temp
[1024], /* Temporary string */
1398 value
[2048], /* Value string */
1399 *ptr
, /* Pointer into value */
1400 *name
; /* Current user/group name */
1401 cupsd_printer_t
*printer
; /* Current printer class */
1402 time_t curtime
; /* Current time */
1403 struct tm
*curdate
; /* Current date */
1404 cups_option_t
*option
; /* Current option */
1405 ipp_attribute_t
*marker
; /* Current marker attribute */
1409 * Create the printers.conf file...
1412 snprintf(filename
, sizeof(filename
), "%s/printers.conf", ServerRoot
);
1414 if ((fp
= cupsdCreateConfFile(filename
, ConfigFilePerm
& 0600)) == NULL
)
1417 cupsdLogMessage(CUPSD_LOG_INFO
, "Saving printers.conf...");
1420 * Write a small header to the file...
1423 curtime
= time(NULL
);
1424 curdate
= localtime(&curtime
);
1425 strftime(temp
, sizeof(temp
) - 1, "%Y-%m-%d %H:%M", curdate
);
1427 cupsFilePuts(fp
, "# Printer configuration file for " CUPS_SVERSION
"\n");
1428 cupsFilePrintf(fp
, "# Written by cupsd on %s\n", temp
);
1429 cupsFilePuts(fp
, "# DO NOT EDIT THIS FILE WHEN CUPSD IS RUNNING\n");
1432 * Write each local printer known to the system...
1435 for (printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
1437 printer
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
1440 * Skip printer classes...
1443 if (printer
->type
& CUPS_PRINTER_CLASS
)
1447 * Write printers as needed...
1450 if (printer
== DefaultPrinter
)
1451 cupsFilePrintf(fp
, "<DefaultPrinter %s>\n", printer
->name
);
1453 cupsFilePrintf(fp
, "<Printer %s>\n", printer
->name
);
1455 cupsFilePrintf(fp
, "UUID %s\n", printer
->uuid
);
1457 if (printer
->num_auth_info_required
> 0)
1459 switch (printer
->num_auth_info_required
)
1462 strlcpy(value
, printer
->auth_info_required
[0], sizeof(value
));
1466 snprintf(value
, sizeof(value
), "%s,%s",
1467 printer
->auth_info_required
[0],
1468 printer
->auth_info_required
[1]);
1473 snprintf(value
, sizeof(value
), "%s,%s,%s",
1474 printer
->auth_info_required
[0],
1475 printer
->auth_info_required
[1],
1476 printer
->auth_info_required
[2]);
1480 cupsFilePutConf(fp
, "AuthInfoRequired", value
);
1484 cupsFilePutConf(fp
, "Info", printer
->info
);
1486 if (printer
->location
)
1487 cupsFilePutConf(fp
, "Location", printer
->location
);
1489 if (printer
->make_model
)
1490 cupsFilePutConf(fp
, "MakeModel", printer
->make_model
);
1492 cupsFilePutConf(fp
, "DeviceURI", printer
->device_uri
);
1494 if (printer
->port_monitor
)
1495 cupsFilePutConf(fp
, "PortMonitor", printer
->port_monitor
);
1497 if (printer
->state
== IPP_PRINTER_STOPPED
)
1499 cupsFilePuts(fp
, "State Stopped\n");
1501 if (printer
->state_message
)
1502 cupsFilePutConf(fp
, "StateMessage", printer
->state_message
);
1505 cupsFilePuts(fp
, "State Idle\n");
1507 cupsFilePrintf(fp
, "StateTime %d\n", (int)printer
->state_time
);
1509 for (i
= 0; i
< printer
->num_reasons
; i
++)
1510 if (strcmp(printer
->reasons
[i
], "connecting-to-device") &&
1511 strcmp(printer
->reasons
[i
], "cups-insecure-filter-warning") &&
1512 strcmp(printer
->reasons
[i
], "cups-missing-filter-warning"))
1513 cupsFilePutConf(fp
, "Reason", printer
->reasons
[i
]);
1515 cupsFilePrintf(fp
, "Type %d\n", printer
->type
);
1517 if (printer
->accepting
)
1518 cupsFilePuts(fp
, "Accepting Yes\n");
1520 cupsFilePuts(fp
, "Accepting No\n");
1522 if (printer
->shared
)
1523 cupsFilePuts(fp
, "Shared Yes\n");
1525 cupsFilePuts(fp
, "Shared No\n");
1527 snprintf(value
, sizeof(value
), "%s %s", printer
->job_sheets
[0],
1528 printer
->job_sheets
[1]);
1529 cupsFilePutConf(fp
, "JobSheets", value
);
1531 cupsFilePrintf(fp
, "QuotaPeriod %d\n", printer
->quota_period
);
1532 cupsFilePrintf(fp
, "PageLimit %d\n", printer
->page_limit
);
1533 cupsFilePrintf(fp
, "KLimit %d\n", printer
->k_limit
);
1535 for (name
= (char *)cupsArrayFirst(printer
->users
);
1537 name
= (char *)cupsArrayNext(printer
->users
))
1538 cupsFilePutConf(fp
, printer
->deny_users
? "DenyUser" : "AllowUser", name
);
1540 if (printer
->op_policy
)
1541 cupsFilePutConf(fp
, "OpPolicy", printer
->op_policy
);
1542 if (printer
->error_policy
)
1543 cupsFilePutConf(fp
, "ErrorPolicy", printer
->error_policy
);
1545 for (i
= printer
->num_options
, option
= printer
->options
;
1549 snprintf(value
, sizeof(value
), "%s %s", option
->name
, option
->value
);
1550 cupsFilePutConf(fp
, "Option", value
);
1553 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-colors",
1554 IPP_TAG_NAME
)) != NULL
)
1556 snprintf(value
, sizeof(value
), "%s ", marker
->name
);
1558 for (i
= 0, ptr
= value
+ strlen(value
);
1559 i
< marker
->num_values
&& ptr
< (value
+ sizeof(value
) - 1);
1565 strlcpy(ptr
, marker
->values
[i
].string
.text
,
1566 value
+ sizeof(value
) - ptr
);
1571 cupsFilePutConf(fp
, "Attribute", value
);
1574 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-levels",
1575 IPP_TAG_INTEGER
)) != NULL
)
1577 cupsFilePrintf(fp
, "Attribute %s %d", marker
->name
,
1578 marker
->values
[0].integer
);
1579 for (i
= 1; i
< marker
->num_values
; i
++)
1580 cupsFilePrintf(fp
, ",%d", marker
->values
[i
].integer
);
1581 cupsFilePuts(fp
, "\n");
1584 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-low-levels",
1585 IPP_TAG_INTEGER
)) != NULL
)
1587 cupsFilePrintf(fp
, "Attribute %s %d", marker
->name
,
1588 marker
->values
[0].integer
);
1589 for (i
= 1; i
< marker
->num_values
; i
++)
1590 cupsFilePrintf(fp
, ",%d", marker
->values
[i
].integer
);
1591 cupsFilePuts(fp
, "\n");
1594 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-high-levels",
1595 IPP_TAG_INTEGER
)) != NULL
)
1597 cupsFilePrintf(fp
, "Attribute %s %d", marker
->name
,
1598 marker
->values
[0].integer
);
1599 for (i
= 1; i
< marker
->num_values
; i
++)
1600 cupsFilePrintf(fp
, ",%d", marker
->values
[i
].integer
);
1601 cupsFilePuts(fp
, "\n");
1604 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-message",
1605 IPP_TAG_TEXT
)) != NULL
)
1607 snprintf(value
, sizeof(value
), "%s %s", marker
->name
,
1608 marker
->values
[0].string
.text
);
1610 cupsFilePutConf(fp
, "Attribute", value
);
1613 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-names",
1614 IPP_TAG_NAME
)) != NULL
)
1616 snprintf(value
, sizeof(value
), "%s ", marker
->name
);
1618 for (i
= 0, ptr
= value
+ strlen(value
);
1619 i
< marker
->num_values
&& ptr
< (value
+ sizeof(value
) - 1);
1625 strlcpy(ptr
, marker
->values
[i
].string
.text
,
1626 value
+ sizeof(value
) - ptr
);
1631 cupsFilePutConf(fp
, "Attribute", value
);
1634 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-types",
1635 IPP_TAG_KEYWORD
)) != NULL
)
1637 snprintf(value
, sizeof(value
), "%s ", marker
->name
);
1639 for (i
= 0, ptr
= value
+ strlen(value
);
1640 i
< marker
->num_values
&& ptr
< (value
+ sizeof(value
) - 1);
1646 strlcpy(ptr
, marker
->values
[i
].string
.text
,
1647 value
+ sizeof(value
) - ptr
);
1652 cupsFilePutConf(fp
, "Attribute", value
);
1655 if (printer
->marker_time
)
1656 cupsFilePrintf(fp
, "Attribute marker-change-time %ld\n",
1657 (long)printer
->marker_time
);
1659 cupsFilePuts(fp
, "</Printer>\n");
1663 * Make IRIX desktop & printer status happy
1666 write_irix_state(printer
);
1670 cupsdCloseCreatedConfFile(fp
, filename
);
1675 * 'cupsdSetAuthInfoRequired()' - Set the required authentication info.
1678 int /* O - 1 if value OK, 0 otherwise */
1679 cupsdSetAuthInfoRequired(
1680 cupsd_printer_t
*p
, /* I - Printer */
1681 const char *values
, /* I - Plain text value (or NULL) */
1682 ipp_attribute_t
*attr
) /* I - IPP attribute value (or NULL) */
1684 int i
; /* Looping var */
1687 p
->num_auth_info_required
= 0;
1690 * Do we have a plain text value?
1696 * Yes, grab the keywords...
1699 const char *end
; /* End of current value */
1702 while (*values
&& p
->num_auth_info_required
< 4)
1704 if ((end
= strchr(values
, ',')) == NULL
)
1705 end
= values
+ strlen(values
);
1707 if ((end
- values
) == 4 && !strncmp(values
, "none", 4))
1709 if (p
->num_auth_info_required
!= 0 || *end
)
1712 p
->auth_info_required
[p
->num_auth_info_required
] = "none";
1713 p
->num_auth_info_required
++;
1717 else if ((end
- values
) == 9 && !strncmp(values
, "negotiate", 9))
1719 if (p
->num_auth_info_required
!= 0 || *end
)
1722 p
->auth_info_required
[p
->num_auth_info_required
] = "negotiate";
1723 p
->num_auth_info_required
++;
1726 * Don't allow sharing of queues that require Kerberos authentication.
1731 cupsdDeregisterPrinter(p
, 1);
1735 else if ((end
- values
) == 6 && !strncmp(values
, "domain", 6))
1737 p
->auth_info_required
[p
->num_auth_info_required
] = "domain";
1738 p
->num_auth_info_required
++;
1740 else if ((end
- values
) == 8 && !strncmp(values
, "password", 8))
1742 p
->auth_info_required
[p
->num_auth_info_required
] = "password";
1743 p
->num_auth_info_required
++;
1745 else if ((end
- values
) == 8 && !strncmp(values
, "username", 8))
1747 p
->auth_info_required
[p
->num_auth_info_required
] = "username";
1748 p
->num_auth_info_required
++;
1753 values
= (*end
) ? end
+ 1 : end
;
1756 if (p
->num_auth_info_required
== 0)
1758 p
->auth_info_required
[0] = "none";
1759 p
->num_auth_info_required
= 1;
1763 * Update the printer-type value as needed...
1766 if (p
->num_auth_info_required
> 1 ||
1767 strcmp(p
->auth_info_required
[0], "none"))
1768 p
->type
|= CUPS_PRINTER_AUTHENTICATED
;
1770 p
->type
&= ~CUPS_PRINTER_AUTHENTICATED
;
1776 * Grab values from an attribute instead...
1779 if (!attr
|| attr
->num_values
> 4)
1782 for (i
= 0; i
< attr
->num_values
; i
++)
1784 if (!strcmp(attr
->values
[i
].string
.text
, "none"))
1786 if (p
->num_auth_info_required
!= 0 || attr
->num_values
!= 1)
1789 p
->auth_info_required
[p
->num_auth_info_required
] = "none";
1790 p
->num_auth_info_required
++;
1794 else if (!strcmp(attr
->values
[i
].string
.text
, "negotiate"))
1796 if (p
->num_auth_info_required
!= 0 || attr
->num_values
!= 1)
1799 p
->auth_info_required
[p
->num_auth_info_required
] = "negotiate";
1800 p
->num_auth_info_required
++;
1803 * Don't allow sharing of queues that require Kerberos authentication.
1808 cupsdDeregisterPrinter(p
, 1);
1814 else if (!strcmp(attr
->values
[i
].string
.text
, "domain"))
1816 p
->auth_info_required
[p
->num_auth_info_required
] = "domain";
1817 p
->num_auth_info_required
++;
1819 else if (!strcmp(attr
->values
[i
].string
.text
, "password"))
1821 p
->auth_info_required
[p
->num_auth_info_required
] = "password";
1822 p
->num_auth_info_required
++;
1824 else if (!strcmp(attr
->values
[i
].string
.text
, "username"))
1826 p
->auth_info_required
[p
->num_auth_info_required
] = "username";
1827 p
->num_auth_info_required
++;
1838 * 'cupsdSetDeviceURI()' - Set the device URI for a printer.
1842 cupsdSetDeviceURI(cupsd_printer_t
*p
, /* I - Printer */
1843 const char *uri
) /* I - Device URI */
1845 char buffer
[1024], /* URI buffer */
1846 *start
, /* Start of data after scheme */
1847 *slash
, /* First slash after scheme:// */
1848 *ptr
; /* Pointer into user@host:port part */
1852 * Set the full device URI..
1855 cupsdSetString(&(p
->device_uri
), uri
);
1858 * Copy the device URI to a temporary buffer so we can sanitize any auth
1862 strlcpy(buffer
, uri
, sizeof(buffer
));
1865 * Find the end of the scheme:// part...
1868 if ((ptr
= strchr(buffer
, ':')) != NULL
)
1870 for (start
= ptr
+ 1; *start
; start
++)
1875 * Find the next slash (/) in the URI...
1878 if ((slash
= strchr(start
, '/')) == NULL
)
1879 slash
= start
+ strlen(start
); /* No slash, point to the end */
1882 * Check for an @ sign before the slash...
1885 if ((ptr
= strchr(start
, '@')) != NULL
&& ptr
< slash
)
1888 * Found an @ sign and it is before the resource part, so we have
1889 * an authentication string. Copy the remaining URI over the
1890 * authentication string...
1893 _cups_strcpy(start
, ptr
+ 1);
1898 * Save the sanitized URI...
1901 cupsdSetString(&(p
->sanitized_device_uri
), buffer
);
1906 * 'cupsdSetPrinterAttr()' - Set a printer attribute.
1910 cupsdSetPrinterAttr(
1911 cupsd_printer_t
*p
, /* I - Printer */
1912 const char *name
, /* I - Attribute name */
1913 char *value
) /* I - Attribute value string */
1915 ipp_attribute_t
*attr
; /* Attribute */
1916 int i
, /* Looping var */
1917 count
; /* Number of values */
1918 char *ptr
, /* Pointer into value */
1919 *start
, /* Start of value */
1920 quote
; /* Quote character */
1921 ipp_tag_t value_tag
; /* Value tag for this attribute */
1925 * Don't allow empty values...
1928 if (!*value
&& strcmp(name
, "marker-message"))
1930 cupsdLogMessage(CUPSD_LOG_ERROR
, "Ignoring empty \"%s\" attribute", name
);
1935 * Count the number of values...
1938 for (count
= 1, quote
= '\0', ptr
= value
;
1946 else if (*ptr
== '\\' && ptr
[1])
1948 else if (*ptr
== '\'' || *ptr
== '\"')
1950 else if (*ptr
== ',')
1955 * Then add or update the attribute as needed...
1958 if (!strcmp(name
, "marker-levels") || !strcmp(name
, "marker-low-levels") ||
1959 !strcmp(name
, "marker-high-levels"))
1965 if ((attr
= ippFindAttribute(p
->attrs
, name
, IPP_TAG_INTEGER
)) != NULL
&&
1966 attr
->num_values
< count
)
1968 ippDeleteAttribute(p
->attrs
, attr
);
1973 attr
->num_values
= count
;
1975 attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
, name
,
1980 cupsdLogMessage(CUPSD_LOG_ERROR
,
1981 "Unable to allocate memory for printer attribute "
1982 "(%d values)", count
);
1986 for (i
= 0; i
< count
; i
++)
1988 if ((ptr
= strchr(value
, ',')) != NULL
)
1991 attr
->values
[i
].integer
= strtol(value
, NULL
, 10);
2000 * Name or keyword values...
2003 if (!strcmp(name
, "marker-types"))
2004 value_tag
= IPP_TAG_KEYWORD
;
2005 else if (!strcmp(name
, "marker-message"))
2006 value_tag
= IPP_TAG_TEXT
;
2008 value_tag
= IPP_TAG_NAME
;
2010 if ((attr
= ippFindAttribute(p
->attrs
, name
, value_tag
)) != NULL
&&
2011 attr
->num_values
< count
)
2013 ippDeleteAttribute(p
->attrs
, attr
);
2019 for (i
= 0; i
< attr
->num_values
; i
++)
2020 _cupsStrFree(attr
->values
[i
].string
.text
);
2022 attr
->num_values
= count
;
2025 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, value_tag
, name
,
2030 cupsdLogMessage(CUPSD_LOG_ERROR
,
2031 "Unable to allocate memory for printer attribute "
2032 "(%d values)", count
);
2036 for (i
= 0, quote
= '\0', ptr
= value
; i
< count
; i
++)
2038 for (start
= ptr
; *ptr
; ptr
++)
2041 *ptr
= quote
= '\0';
2044 else if (*ptr
== '\\' && ptr
[1])
2045 _cups_strcpy(ptr
, ptr
+ 1);
2046 else if (*ptr
== '\'' || *ptr
== '\"')
2053 _cups_strcpy(ptr
, ptr
+ 1);
2055 else if (*ptr
== ',')
2062 attr
->values
[i
].string
.text
= _cupsStrAlloc(start
);
2069 * 'cupsdSetPrinterAttrs()' - Set printer attributes based upon the PPD file.
2073 cupsdSetPrinterAttrs(cupsd_printer_t
*p
)/* I - Printer to setup */
2075 int i
; /* Looping var */
2076 char resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
2077 int num_air
; /* Number of auth-info-required values */
2078 const char * const *air
; /* auth-info-required values */
2079 cupsd_location_t
*auth
; /* Pointer to authentication element */
2080 const char *auth_supported
; /* Authentication supported */
2081 ipp_t
*oldattrs
; /* Old printer attributes */
2082 ipp_attribute_t
*attr
; /* Attribute data */
2083 char *name
, /* Current user/group name */
2084 *filter
; /* Current filter */
2085 static const char * const air_none
[] =
2086 { /* No authentication */
2089 static const char * const air_userpass
[] =
2090 { /* Basic/Digest authentication */
2096 DEBUG_printf(("cupsdSetPrinterAttrs: entering name = %s, type = %x\n", p
->name
,
2100 * Make sure that we have the common attributes defined...
2104 cupsdCreateCommonData();
2107 * Clear out old filters, if any...
2110 delete_printer_filters(p
);
2113 * Figure out the authentication that is required for the printer.
2116 auth_supported
= "requesting-user-name";
2120 if (p
->num_auth_info_required
> 0 && strcmp(p
->auth_info_required
[0], "none"))
2122 num_air
= p
->num_auth_info_required
;
2123 air
= p
->auth_info_required
;
2125 else if (p
->type
& CUPS_PRINTER_AUTHENTICATED
)
2131 if (p
->type
& CUPS_PRINTER_CLASS
)
2132 snprintf(resource
, sizeof(resource
), "/classes/%s", p
->name
);
2134 snprintf(resource
, sizeof(resource
), "/printers/%s", p
->name
);
2136 if ((auth
= cupsdFindBest(resource
, HTTP_POST
)) == NULL
||
2137 auth
->type
== CUPSD_AUTH_NONE
)
2138 auth
= cupsdFindPolicyOp(p
->op_policy_ptr
, IPP_PRINT_JOB
);
2142 int auth_type
; /* Authentication type */
2145 if ((auth_type
= auth
->type
) == CUPSD_AUTH_DEFAULT
)
2146 auth_type
= cupsdDefaultAuthType();
2148 if (auth_type
== CUPSD_AUTH_BASIC
|| auth_type
== CUPSD_AUTH_BASICDIGEST
)
2149 auth_supported
= "basic";
2150 else if (auth_type
== CUPSD_AUTH_DIGEST
)
2151 auth_supported
= "digest";
2153 else if (auth_type
== CUPSD_AUTH_NEGOTIATE
)
2154 auth_supported
= "negotiate";
2155 #endif /* HAVE_GSSAPI */
2157 if (auth_type
!= CUPSD_AUTH_NONE
)
2158 p
->type
|= CUPS_PRINTER_AUTHENTICATED
;
2160 p
->type
&= ~CUPS_PRINTER_AUTHENTICATED
;
2163 p
->type
&= ~CUPS_PRINTER_AUTHENTICATED
;
2166 * Create the required IPP attributes for a printer...
2169 oldattrs
= p
->attrs
;
2170 p
->attrs
= ippNew();
2172 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2173 "uri-authentication-supported", NULL
, auth_supported
);
2174 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2175 "uri-security-supported", NULL
, "none");
2176 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
, "printer-name", NULL
,
2178 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-location",
2179 NULL
, p
->location
? p
->location
: "");
2180 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-info",
2181 NULL
, p
->info
? p
->info
: "");
2182 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "printer-uuid", NULL
,
2185 if (cupsArrayCount(p
->users
) > 0)
2188 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2189 "requesting-user-name-denied",
2190 cupsArrayCount(p
->users
), NULL
, NULL
);
2192 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2193 "requesting-user-name-allowed",
2194 cupsArrayCount(p
->users
), NULL
, NULL
);
2196 for (i
= 0, name
= (char *)cupsArrayFirst(p
->users
);
2198 i
++, name
= (char *)cupsArrayNext(p
->users
))
2199 attr
->values
[i
].string
.text
= _cupsStrRetain(name
);
2202 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2203 "job-quota-period", p
->quota_period
);
2204 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2205 "job-k-limit", p
->k_limit
);
2206 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2207 "job-page-limit", p
->page_limit
);
2208 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2209 "auth-info-required", num_air
, NULL
, air
);
2211 if (cupsArrayCount(Banners
) > 0)
2214 * Setup the job-sheets-default attribute...
2217 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2218 "job-sheets-default", 2, NULL
, NULL
);
2222 attr
->values
[0].string
.text
= _cupsStrAlloc(Classification
?
2223 Classification
: p
->job_sheets
[0]);
2224 attr
->values
[1].string
.text
= _cupsStrAlloc(Classification
?
2225 Classification
: p
->job_sheets
[1]);
2233 * Assign additional attributes depending on whether this is a printer
2237 if (p
->type
& CUPS_PRINTER_CLASS
)
2240 p
->type
&= ~CUPS_PRINTER_OPTIONS
;
2243 * Add class-specific attributes...
2246 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
2247 "printer-make-and-model", NULL
, "Local Printer Class");
2248 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "device-uri", NULL
,
2249 "file:///dev/null");
2251 if (p
->num_printers
> 0)
2254 * Add a list of member names; URIs are added in copy_printer_attrs...
2257 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2258 "member-names", p
->num_printers
, NULL
, NULL
);
2259 p
->type
|= CUPS_PRINTER_OPTIONS
;
2261 for (i
= 0; i
< p
->num_printers
; i
++)
2264 attr
->values
[i
].string
.text
= _cupsStrRetain(p
->printers
[i
]->name
);
2266 p
->type
&= ~CUPS_PRINTER_OPTIONS
| p
->printers
[i
]->type
;
2273 * Add printer-specific attributes...
2276 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "device-uri", NULL
,
2277 p
->sanitized_device_uri
);
2280 * Assign additional attributes from the PPD file (if any)...
2286 * Add filters for printer...
2289 cupsdSetPrinterReasons(p
, "-cups-missing-filter-warning,"
2290 "cups-insecure-filter-warning");
2292 if (p
->pc
&& p
->pc
->filters
)
2294 for (filter
= (char *)cupsArrayFirst(p
->pc
->filters
);
2296 filter
= (char *)cupsArrayNext(p
->pc
->filters
))
2297 add_printer_filter(p
, p
->filetype
, filter
);
2299 else if (!(p
->type
& CUPS_PRINTER_REMOTE
))
2301 char interface
[1024]; /* Interface script */
2304 snprintf(interface
, sizeof(interface
), "%s/interfaces/%s", ServerRoot
,
2306 if (!access(interface
, X_OK
))
2309 * Yes, we have a System V style interface script; use it!
2312 snprintf(interface
, sizeof(interface
), "*/* 0 %s/interfaces/%s",
2313 ServerRoot
, p
->name
);
2314 add_printer_filter(p
, p
->filetype
, interface
);
2319 * Add a filter from application/vnd.cups-raw to printer/name to
2320 * handle "raw" printing by users.
2323 add_printer_filter(p
, p
->filetype
, "application/vnd.cups-raw 0 -");
2326 * Add a PostScript filter, since this is still possibly PS printer.
2329 add_printer_filter(p
, p
->filetype
,
2330 "application/vnd.cups-postscript 0 -");
2334 if (p
->pc
&& p
->pc
->prefilters
)
2336 if (!p
->prefiltertype
)
2337 p
->prefiltertype
= mimeAddType(MimeDatabase
, "prefilter", p
->name
);
2339 for (filter
= (char *)cupsArrayFirst(p
->pc
->prefilters
);
2341 filter
= (char *)cupsArrayNext(p
->pc
->prefilters
))
2342 add_printer_filter(p
, p
->prefiltertype
, filter
);
2347 * Copy marker attributes as needed...
2352 ipp_attribute_t
*oldattr
; /* Old attribute */
2355 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-colors",
2356 IPP_TAG_NAME
)) != NULL
)
2358 if ((attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2359 "marker-colors", oldattr
->num_values
, NULL
,
2362 for (i
= 0; i
< oldattr
->num_values
; i
++)
2363 attr
->values
[i
].string
.text
=
2364 _cupsStrRetain(oldattr
->values
[i
].string
.text
);
2368 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-levels",
2369 IPP_TAG_INTEGER
)) != NULL
)
2371 if ((attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2372 "marker-levels", oldattr
->num_values
,
2375 for (i
= 0; i
< oldattr
->num_values
; i
++)
2376 attr
->values
[i
].integer
= oldattr
->values
[i
].integer
;
2380 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-message",
2381 IPP_TAG_TEXT
)) != NULL
)
2382 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "marker-message",
2383 NULL
, oldattr
->values
[0].string
.text
);
2385 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-low-levels",
2386 IPP_TAG_INTEGER
)) != NULL
)
2388 if ((attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2389 "marker-low-levels", oldattr
->num_values
,
2392 for (i
= 0; i
< oldattr
->num_values
; i
++)
2393 attr
->values
[i
].integer
= oldattr
->values
[i
].integer
;
2397 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-high-levels",
2398 IPP_TAG_INTEGER
)) != NULL
)
2400 if ((attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2401 "marker-high-levels", oldattr
->num_values
,
2404 for (i
= 0; i
< oldattr
->num_values
; i
++)
2405 attr
->values
[i
].integer
= oldattr
->values
[i
].integer
;
2409 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-names",
2410 IPP_TAG_NAME
)) != NULL
)
2412 if ((attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2413 "marker-names", oldattr
->num_values
, NULL
,
2416 for (i
= 0; i
< oldattr
->num_values
; i
++)
2417 attr
->values
[i
].string
.text
=
2418 _cupsStrRetain(oldattr
->values
[i
].string
.text
);
2422 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-types",
2423 IPP_TAG_KEYWORD
)) != NULL
)
2425 if ((attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2426 "marker-types", oldattr
->num_values
, NULL
,
2429 for (i
= 0; i
< oldattr
->num_values
; i
++)
2430 attr
->values
[i
].string
.text
=
2431 _cupsStrRetain(oldattr
->values
[i
].string
.text
);
2435 ippDelete(oldattrs
);
2439 * Force sharing off for remote queues...
2442 if (p
->type
& CUPS_PRINTER_REMOTE
)
2446 * Populate the document-format-supported attribute...
2449 add_printer_formats(p
);
2451 DEBUG_printf(("cupsdSetPrinterAttrs: leaving name = %s, type = %x\n", p
->name
,
2455 * Add name-default attributes...
2458 add_printer_defaults(p
);
2462 * Write the IRIX printer config and status files...
2465 write_irix_config(p
);
2466 write_irix_state(p
);
2470 * Let the browse protocols reflect the change
2473 cupsdRegisterPrinter(p
);
2478 * 'cupsdSetPrinterReasons()' - Set/update the reasons strings.
2481 int /* O - 1 if something changed, 0 otherwise */
2482 cupsdSetPrinterReasons(
2483 cupsd_printer_t
*p
, /* I - Printer */
2484 const char *s
) /* I - Reasons strings */
2486 int i
, /* Looping var */
2487 changed
= 0; /* Did something change? */
2488 const char *sptr
; /* Pointer into reasons */
2489 char reason
[255], /* Reason string */
2490 *rptr
; /* Pointer into reason */
2493 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
2494 "cupsdSetPrinterReasons(p=%p(%s),s=\"%s\"", p
, p
->name
, s
);
2496 if (s
[0] == '-' || s
[0] == '+')
2499 * Add/remove reasons...
2507 * Replace reasons...
2512 for (i
= 0; i
< p
->num_reasons
; i
++)
2513 _cupsStrFree(p
->reasons
[i
]);
2521 if (!strcmp(s
, "none"))
2525 * Loop through all of the reasons...
2531 * Skip leading whitespace and commas...
2534 while (isspace(*sptr
& 255) || *sptr
== ',')
2537 for (rptr
= reason
; *sptr
&& !isspace(*sptr
& 255) && *sptr
!= ','; sptr
++)
2538 if (rptr
< (reason
+ sizeof(reason
) - 1))
2552 for (i
= 0; i
< p
->num_reasons
; i
++)
2553 if (!strcmp(reason
, p
->reasons
[i
]))
2556 * Found a match, so remove it...
2561 _cupsStrFree(p
->reasons
[i
]);
2563 if (i
< p
->num_reasons
)
2564 memmove(p
->reasons
+ i
, p
->reasons
+ i
+ 1,
2565 (p
->num_reasons
- i
) * sizeof(char *));
2567 if (!strcmp(reason
, "paused") && p
->state
== IPP_PRINTER_STOPPED
)
2568 cupsdSetPrinterState(p
, IPP_PRINTER_IDLE
, 1);
2570 if (strcmp(reason
, "connecting-to-device"))
2575 else if (p
->num_reasons
< (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
2581 for (i
= 0; i
< p
->num_reasons
; i
++)
2582 if (!strcmp(reason
, p
->reasons
[i
]))
2585 if (i
>= p
->num_reasons
)
2587 if (!strncmp(reason
, "cups-ipp-missing-", 17) ||
2588 !strncmp(reason
, "cups-ipp-wrong-", 15))
2589 log_ipp_conformance(p
, reason
);
2591 if (i
>= (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
2593 cupsdLogMessage(CUPSD_LOG_ALERT
,
2594 "Too many printer-state-reasons values for %s (%d)",
2599 p
->reasons
[i
] = _cupsStrAlloc(reason
);
2603 if (!strcmp(reason
, "paused") && p
->state
!= IPP_PRINTER_STOPPED
)
2604 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, 1);
2606 if (strcmp(reason
, "connecting-to-device"))
2617 * 'cupsdSetPrinterState()' - Update the current state of a printer.
2621 cupsdSetPrinterState(
2622 cupsd_printer_t
*p
, /* I - Printer to change */
2623 ipp_pstate_t s
, /* I - New state */
2624 int update
) /* I - Update printers.conf? */
2626 cupsd_job_t
*job
; /* Current job */
2627 ipp_pstate_t old_state
; /* Old printer state */
2628 static const char * const printer_states
[] =
2629 { /* State strings */
2637 * Set the new state...
2640 old_state
= p
->state
;
2645 cupsdAddEvent(s
== IPP_PRINTER_STOPPED
? CUPSD_EVENT_PRINTER_STOPPED
:
2646 CUPSD_EVENT_PRINTER_STATE
, p
, NULL
,
2647 "%s \"%s\" state changed to %s.",
2648 (p
->type
& CUPS_PRINTER_CLASS
) ? "Class" : "Printer",
2649 p
->name
, printer_states
[p
->state
- IPP_PRINTER_IDLE
]);
2652 * Let the browse code know this needs to be updated...
2655 p
->state_time
= time(NULL
);
2658 write_irix_state(p
);
2663 * Set/clear the paused reason as needed...
2666 if (s
== IPP_PRINTER_STOPPED
)
2667 cupsdSetPrinterReasons(p
, "+paused");
2669 cupsdSetPrinterReasons(p
, "-paused");
2673 for (job
= (cupsd_job_t
*)cupsArrayFirst(ActiveJobs
);
2675 job
= (cupsd_job_t
*)cupsArrayNext(ActiveJobs
))
2676 if (job
->reasons
&& job
->state_value
== IPP_JOB_PENDING
&&
2677 !_cups_strcasecmp(job
->dest
, p
->name
))
2678 ippSetString(job
->attrs
, &job
->reasons
, 0,
2679 s
== IPP_PRINTER_STOPPED
? "printer-stopped" : "none");
2683 * Clear the message for the queue when going to processing...
2686 if (s
== IPP_PRINTER_PROCESSING
)
2687 p
->state_message
[0] = '\0';
2690 * Let the browse protocols reflect the change...
2694 cupsdRegisterPrinter(p
);
2697 * Save the printer configuration if a printer goes from idle or processing
2698 * to stopped (or visa-versa)...
2702 (old_state
== IPP_PRINTER_STOPPED
) != (s
== IPP_PRINTER_STOPPED
))
2708 * 'cupsdStopPrinter()' - Stop a printer from printing any jobs...
2712 cupsdStopPrinter(cupsd_printer_t
*p
, /* I - Printer to stop */
2713 int update
)/* I - Update printers.conf? */
2716 * Set the printer state...
2719 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, update
);
2722 * See if we have a job printing on this printer...
2725 if (p
->job
&& p
->job
->state_value
== IPP_JOB_PROCESSING
)
2726 cupsdSetJobState(p
->job
, IPP_JOB_PENDING
, CUPSD_JOB_DEFAULT
,
2727 "Job stopped due to printer being paused.");
2732 * 'cupsdUpdatePrinterPPD()' - Update keywords in a printer's PPD file.
2735 int /* O - 1 if successful, 0 otherwise */
2736 cupsdUpdatePrinterPPD(
2737 cupsd_printer_t
*p
, /* I - Printer */
2738 int num_keywords
, /* I - Number of keywords */
2739 cups_option_t
*keywords
) /* I - Keywords */
2741 int i
; /* Looping var */
2742 cups_file_t
*src
, /* Original file */
2743 *dst
; /* New file */
2744 char srcfile
[1024], /* Original filename */
2745 dstfile
[1024], /* New filename */
2746 line
[1024], /* Line from file */
2747 keystring
[41]; /* Keyword from line */
2748 cups_option_t
*keyword
; /* Current keyword */
2751 cupsdLogMessage(CUPSD_LOG_INFO
, "Updating keywords in PPD file for %s...",
2755 * Get the old and new PPD filenames...
2758 snprintf(srcfile
, sizeof(srcfile
), "%s/ppd/%s.ppd.O", ServerRoot
, p
->name
);
2759 snprintf(dstfile
, sizeof(srcfile
), "%s/ppd/%s.ppd", ServerRoot
, p
->name
);
2762 * Rename the old file and open the old and new...
2765 if (rename(dstfile
, srcfile
))
2767 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to backup PPD file for %s: %s",
2768 p
->name
, strerror(errno
));
2772 if ((src
= cupsFileOpen(srcfile
, "r")) == NULL
)
2774 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to open PPD file \"%s\": %s",
2775 srcfile
, strerror(errno
));
2776 rename(srcfile
, dstfile
);
2780 if ((dst
= cupsFileOpen(dstfile
, "w")) == NULL
)
2782 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to create PPD file \"%s\": %s",
2783 dstfile
, strerror(errno
));
2785 rename(srcfile
, dstfile
);
2790 * Copy the first line and then write out all of the keywords...
2793 if (!cupsFileGets(src
, line
, sizeof(line
)))
2795 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to read PPD file \"%s\": %s",
2796 srcfile
, strerror(errno
));
2799 rename(srcfile
, dstfile
);
2803 cupsFilePrintf(dst
, "%s\n", line
);
2805 for (i
= num_keywords
, keyword
= keywords
; i
> 0; i
--, keyword
++)
2807 cupsdLogMessage(CUPSD_LOG_DEBUG
, "*%s: %s", keyword
->name
, keyword
->value
);
2808 cupsFilePrintf(dst
, "*%s: %s\n", keyword
->name
, keyword
->value
);
2812 * Then copy the rest of the PPD file, dropping any keywords we changed.
2815 while (cupsFileGets(src
, line
, sizeof(line
)))
2818 * Skip keywords we've already set...
2821 if (sscanf(line
, "*%40[^:]:", keystring
) == 1 &&
2822 cupsGetOption(keystring
, num_keywords
, keywords
))
2826 * Otherwise write the line...
2829 cupsFilePrintf(dst
, "%s\n", line
);
2833 * Close files and return...
2844 * 'cupsdUpdatePrinters()' - Update printers after a partial reload.
2848 cupsdUpdatePrinters(void)
2850 cupsd_printer_t
*p
; /* Current printer */
2854 * Loop through the printers and recreate the printer attributes
2855 * for any local printers since the policy and/or access control
2856 * stuff may have changed. Also, if browsing is disabled, remove
2857 * any remote printers...
2860 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
2862 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
2865 * Update the operation policy pointer...
2868 if ((p
->op_policy_ptr
= cupsdFindPolicy(p
->op_policy
)) == NULL
)
2869 p
->op_policy_ptr
= DefaultPolicyPtr
;
2872 * Update printer attributes...
2875 cupsdSetPrinterAttrs(p
);
2881 * 'cupsdValidateDest()' - Validate a printer/class destination.
2884 const char * /* O - Printer or class name */
2886 const char *uri
, /* I - Printer URI */
2887 cups_ptype_t
*dtype
, /* O - Type (printer or class) */
2888 cupsd_printer_t
**printer
) /* O - Printer pointer */
2890 cupsd_printer_t
*p
; /* Current printer */
2891 char localname
[1024],/* Localized hostname */
2892 *lptr
, /* Pointer into localized hostname */
2893 *sptr
, /* Pointer into server name */
2894 *rptr
, /* Pointer into resource */
2895 scheme
[32], /* Scheme portion of URI */
2896 username
[64], /* Username portion of URI */
2897 hostname
[HTTP_MAX_HOST
],
2898 /* Host portion of URI */
2899 resource
[HTTP_MAX_URI
];
2900 /* Resource portion of URI */
2901 int port
; /* Port portion of URI */
2904 DEBUG_printf(("cupsdValidateDest(uri=\"%s\", dtype=%p, printer=%p)\n", uri
,
2908 * Initialize return values...
2915 *dtype
= (cups_ptype_t
)0;
2918 * Pull the hostname and resource from the URI...
2921 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
, scheme
, sizeof(scheme
),
2922 username
, sizeof(username
), hostname
, sizeof(hostname
),
2923 &port
, resource
, sizeof(resource
));
2926 * See if the resource is a class or printer...
2929 if (!strncmp(resource
, "/classes/", 9))
2935 rptr
= resource
+ 9;
2937 else if (!strncmp(resource
, "/printers/", 10))
2943 rptr
= resource
+ 10;
2948 * Bad resource name...
2955 * See if the printer or class name exists...
2958 p
= cupsdFindDest(rptr
);
2960 if (p
== NULL
&& strchr(rptr
, '@') == NULL
)
2968 *dtype
= p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_REMOTE
);
2974 * Change localhost to the server name...
2977 if (!_cups_strcasecmp(hostname
, "localhost"))
2978 strlcpy(hostname
, ServerName
, sizeof(hostname
));
2980 strlcpy(localname
, hostname
, sizeof(localname
));
2982 if (!_cups_strcasecmp(hostname
, ServerName
))
2985 * Localize the hostname...
2988 lptr
= strchr(localname
, '.');
2989 sptr
= strchr(ServerName
, '.');
2991 if (sptr
!= NULL
&& lptr
!= NULL
)
2994 * Strip the common domain name components...
2997 while (lptr
!= NULL
)
2999 if (!_cups_strcasecmp(lptr
, sptr
))
3005 lptr
= strchr(lptr
+ 1, '.');
3010 DEBUG_printf(("localized hostname is \"%s\"...\n", localname
));
3013 * Find a matching printer or class...
3016 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3018 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3019 if (!_cups_strcasecmp(p
->hostname
, localname
) &&
3020 !_cups_strcasecmp(p
->name
, rptr
))
3026 *dtype
= p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_REMOTE
);
3036 * 'cupsdWritePrintcap()' - Write a pseudo-printcap file for older applications
3041 cupsdWritePrintcap(void)
3043 int i
; /* Looping var */
3044 cups_file_t
*fp
; /* Printcap file */
3045 cupsd_printer_t
*p
; /* Current printer */
3050 * Update the IRIX printer state for the default printer; if
3051 * no printers remain, then the default printer file will be
3055 write_irix_state(DefaultPrinter
);
3059 * See if we have a printcap file; if not, don't bother writing it.
3062 if (!Printcap
|| !*Printcap
)
3065 cupsdLogMessage(CUPSD_LOG_INFO
, "Generating printcap %s...", Printcap
);
3068 * Open the printcap file...
3071 if ((fp
= cupsFileOpen(Printcap
, "w")) == NULL
)
3075 * Put a comment header at the top so that users will know where the
3076 * data has come from...
3079 if (PrintcapFormat
!= PRINTCAP_PLIST
)
3080 cupsFilePrintf(fp
, "# This file was automatically generated by cupsd(8) "
3082 "# %s/printers.conf file. All changes to this file\n"
3083 "# will be lost.\n", ServerRoot
);
3086 * Write a new printcap with the current list of printers.
3089 switch (PrintcapFormat
)
3093 * Each printer is put in the file as:
3103 cupsFilePrintf(fp
, "%s|%s:rm=%s:rp=%s:\n", DefaultPrinter
->name
,
3104 DefaultPrinter
->info
, ServerName
,
3105 DefaultPrinter
->name
);
3107 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3109 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3110 if (p
!= DefaultPrinter
)
3111 cupsFilePrintf(fp
, "%s|%s:rm=%s:rp=%s:\n", p
->name
, p
->info
,
3112 ServerName
, p
->name
);
3115 case PRINTCAP_PLIST
:
3117 * Each printer is written as a dictionary in a plist file.
3118 * Currently the printer-name, printer-info, printer-is-accepting-jobs,
3119 * printer-location, printer-make-and-model, printer-state,
3120 * printer-state-reasons, printer-type, and (sanitized) device-uri.
3123 cupsFilePuts(fp
, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
3124 "<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD "
3125 "PLIST 1.0//EN\" \"http://www.apple.com/DTDs/"
3126 "PropertyList-1.0.dtd\">\n"
3127 "<plist version=\"1.0\">\n"
3130 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3132 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3134 cupsFilePuts(fp
, "\t<dict>\n"
3135 "\t\t<key>printer-name</key>\n"
3137 write_xml_string(fp
, p
->name
);
3138 cupsFilePuts(fp
, "</string>\n"
3139 "\t\t<key>printer-info</key>\n"
3141 write_xml_string(fp
, p
->info
);
3142 cupsFilePrintf(fp
, "</string>\n"
3143 "\t\t<key>printer-is-accepting-jobs</key>\n"
3145 "\t\t<key>printer-location</key>\n"
3146 "\t\t<string>", p
->accepting
? "true" : "false");
3147 write_xml_string(fp
, p
->location
);
3148 cupsFilePuts(fp
, "</string>\n"
3149 "\t\t<key>printer-make-and-model</key>\n"
3151 write_xml_string(fp
, p
->make_model
);
3152 cupsFilePrintf(fp
, "</string>\n"
3153 "\t\t<key>printer-state</key>\n"
3154 "\t\t<integer>%d</integer>\n"
3155 "\t\t<key>printer-state-reasons</key>\n"
3156 "\t\t<array>\n", p
->state
);
3157 for (i
= 0; i
< p
->num_reasons
; i
++)
3159 cupsFilePuts(fp
, "\t\t\t<string>");
3160 write_xml_string(fp
, p
->reasons
[i
]);
3161 cupsFilePuts(fp
, "</string>\n");
3163 cupsFilePrintf(fp
, "\t\t</array>\n"
3164 "\t\t<key>printer-type</key>\n"
3165 "\t\t<integer>%d</integer>\n"
3166 "\t\t<key>device-uri</key>\n"
3167 "\t\t<string>", p
->type
);
3168 write_xml_string(fp
, p
->sanitized_device_uri
);
3169 cupsFilePuts(fp
, "</string>\n"
3172 cupsFilePuts(fp
, "</array>\n"
3176 case PRINTCAP_SOLARIS
:
3178 * Each printer is put in the file as:
3180 * _all:all=Printer1,Printer2,Printer3,...,PrinterN
3181 * _default:use=DefaultPrinter
3183 * :bsdaddr=ServerName,Printer1:\
3184 * :description=Description:
3186 * :bsdaddr=ServerName,Printer2:\
3187 * :description=Description:
3189 * :bsdaddr=ServerName,Printer3:\
3190 * :description=Description:
3193 * :bsdaddr=ServerName,PrinterN:\
3194 * :description=Description:
3197 cupsFilePuts(fp
, "_all:all=");
3198 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3200 p
= (cupsd_printer_t
*)cupsArrayCurrent(Printers
))
3201 cupsFilePrintf(fp
, "%s%c", p
->name
,
3202 cupsArrayNext(Printers
) ? ',' : '\n');
3205 cupsFilePrintf(fp
, "_default:use=%s\n", DefaultPrinter
->name
);
3207 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3209 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3210 cupsFilePrintf(fp
, "%s:\\\n"
3211 "\t:bsdaddr=%s,%s:\\\n"
3212 "\t:description=%s:\n",
3213 p
->name
, ServerName
, p
->name
,
3214 p
->info
? p
->info
: "");
3227 * 'add_printer_defaults()' - Add name-default attributes to the printer attributes.
3231 add_printer_defaults(cupsd_printer_t
*p
)/* I - Printer */
3233 int i
; /* Looping var */
3234 int num_options
; /* Number of default options */
3235 cups_option_t
*options
, /* Default options */
3236 *option
; /* Current option */
3237 char name
[256]; /* name-default */
3241 * Maintain a common array of default attribute names...
3244 if (!CommonDefaults
)
3246 CommonDefaults
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
3248 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("copies-default"));
3249 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("document-format-default"));
3250 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("finishings-default"));
3251 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-hold-until-default"));
3252 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-priority-default"));
3253 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-sheets-default"));
3254 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("media-col-default"));
3255 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("number-up-default"));
3256 cupsArrayAdd(CommonDefaults
,
3257 _cupsStrAlloc("orientation-requested-default"));
3261 * Add all of the default options from the .conf files...
3264 for (num_options
= 0, options
= NULL
, i
= p
->num_options
, option
= p
->options
;
3268 if (strcmp(option
->name
, "ipp-options") &&
3269 strcmp(option
->name
, "job-sheets") &&
3270 strcmp(option
->name
, "lease-duration"))
3272 snprintf(name
, sizeof(name
), "%s-default", option
->name
);
3273 num_options
= cupsAddOption(name
, option
->value
, num_options
, &options
);
3275 if (!cupsArrayFind(CommonDefaults
, name
))
3276 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc(name
));
3281 * Convert options to IPP attributes...
3284 cupsEncodeOptions2(p
->attrs
, num_options
, options
, IPP_TAG_PRINTER
);
3285 cupsFreeOptions(num_options
, options
);
3288 * Add standard -default attributes as needed...
3291 if (!cupsGetOption("copies", p
->num_options
, p
->options
))
3292 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
, "copies-default",
3295 if (!cupsGetOption("document-format", p
->num_options
, p
->options
))
3296 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_MIMETYPE
,
3297 "document-format-default", NULL
, "application/octet-stream");
3299 if (!cupsGetOption("job-hold-until", p
->num_options
, p
->options
))
3300 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3301 "job-hold-until-default", NULL
, "no-hold");
3303 if (!cupsGetOption("job-priority", p
->num_options
, p
->options
))
3304 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3305 "job-priority-default", 50);
3307 if (!cupsGetOption("number-up", p
->num_options
, p
->options
))
3308 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3309 "number-up-default", 1);
3311 if (!cupsGetOption("notify-lease-duration", p
->num_options
, p
->options
))
3312 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3313 "notify-lease-duration-default", DefaultLeaseDuration
);
3315 if (!cupsGetOption("notify-events", p
->num_options
, p
->options
))
3316 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3317 "notify-events-default", NULL
, "job-completed");
3319 if (!cupsGetOption("orientation-requested", p
->num_options
, p
->options
))
3320 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NOVALUE
,
3321 "orientation-requested-default", NULL
, NULL
);
3323 if (!cupsGetOption("print-quality", p
->num_options
, p
->options
))
3324 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
3325 "print-quality-default", IPP_QUALITY_NORMAL
);
3330 * 'add_printer_filter()' - Add a MIME filter for a printer.
3335 cupsd_printer_t
*p
, /* I - Printer to add to */
3336 mime_type_t
*filtertype
, /* I - Filter or prefilter MIME type */
3337 const char *filter
) /* I - Filter to add */
3339 char super
[MIME_MAX_SUPER
], /* Super-type for filter */
3340 type
[MIME_MAX_TYPE
], /* Type for filter */
3341 dsuper
[MIME_MAX_SUPER
], /* Destination super-type for filter */
3342 dtype
[MIME_MAX_TYPE
], /* Destination type for filter */
3343 dest
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2],
3344 /* Destination super/type */
3345 program
[1024]; /* Program/filter name */
3346 int cost
; /* Cost of filter */
3347 size_t maxsize
= 0; /* Maximum supported file size */
3348 mime_type_t
*temptype
, /* MIME type looping var */
3349 *desttype
; /* Destination MIME type */
3350 mime_filter_t
*filterptr
; /* MIME filter */
3351 char filename
[1024]; /* Full filter filename */
3354 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3355 "add_printer_filter(p=%p(%s), filtertype=%p(%s/%s), "
3356 "filter=\"%s\")", p
, p
->name
, filtertype
, filtertype
->super
,
3357 filtertype
->type
, filter
);
3360 * Parse the filter string; it should be in one of the following formats:
3362 * source/type cost program
3363 * source/type cost maxsize(nnnn) program
3364 * source/type dest/type cost program
3365 * source/type dest/type cost maxsize(nnnn) program
3368 if (sscanf(filter
, "%15[^/]/%255s%*[ \t]%15[^/]/%255s%d%*[ \t]%1023[^\n]",
3369 super
, type
, dsuper
, dtype
, &cost
, program
) == 6)
3371 snprintf(dest
, sizeof(dest
), "%s/%s/%s", p
->name
, dsuper
, dtype
);
3373 if ((desttype
= mimeType(MimeDatabase
, "printer", dest
)) == NULL
)
3375 desttype
= mimeAddType(MimeDatabase
, "printer", dest
);
3377 p
->dest_types
= cupsArrayNew(NULL
, NULL
);
3379 cupsArrayAdd(p
->dest_types
, desttype
);
3385 if (sscanf(filter
, "%15[^/]/%255s%d%*[ \t]%1023[^\n]", super
, type
, &cost
,
3388 desttype
= filtertype
;
3392 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: invalid filter string \"%s\"!",
3398 if (!strncmp(program
, "maxsize(", 8))
3400 char *ptr
; /* Pointer into maxsize(nnnn) program */
3402 maxsize
= strtoll(program
+ 8, &ptr
, 10);
3406 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: invalid filter string \"%s\"!",
3412 while (_cups_isspace(*ptr
))
3415 _cups_strcpy(program
, ptr
);
3419 * Check permissions on the filter and its containing directory...
3422 if (strcmp(program
, "-"))
3424 if (program
[0] == '/')
3425 strlcpy(filename
, program
, sizeof(filename
));
3427 snprintf(filename
, sizeof(filename
), "%s/filter/%s", ServerBin
, program
);
3429 _cupsFileCheck(filename
, _CUPS_FILE_CHECK_PROGRAM
, !RunUser
,
3430 cupsdLogFCMessage
, p
);
3434 * Add the filter to the MIME database, supporting wildcards as needed...
3437 for (temptype
= mimeFirstType(MimeDatabase
);
3439 temptype
= mimeNextType(MimeDatabase
))
3440 if (((super
[0] == '*' && _cups_strcasecmp(temptype
->super
, "printer")) ||
3441 !_cups_strcasecmp(temptype
->super
, super
)) &&
3442 (type
[0] == '*' || !_cups_strcasecmp(temptype
->type
, type
)))
3444 if (desttype
!= filtertype
)
3446 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3447 "add_printer_filter: %s: adding filter %s/%s %s/%s %d "
3448 "%s", p
->name
, temptype
->super
, temptype
->type
,
3449 desttype
->super
, desttype
->type
,
3451 filterptr
= mimeAddFilter(MimeDatabase
, temptype
, desttype
, cost
,
3454 if (!mimeFilterLookup(MimeDatabase
, desttype
, filtertype
))
3456 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3457 "add_printer_filter: %s: adding filter %s/%s %s/%s "
3458 "0 -", p
->name
, desttype
->super
, desttype
->type
,
3459 filtertype
->super
, filtertype
->type
);
3460 mimeAddFilter(MimeDatabase
, desttype
, filtertype
, 0, "-");
3465 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3466 "add_printer_filter: %s: adding filter %s/%s %s/%s %d "
3467 "%s", p
->name
, temptype
->super
, temptype
->type
,
3468 filtertype
->super
, filtertype
->type
,
3470 filterptr
= mimeAddFilter(MimeDatabase
, temptype
, filtertype
, cost
,
3475 filterptr
->maxsize
= maxsize
;
3481 * 'add_printer_formats()' - Add document-format-supported values for a printer.
3485 add_printer_formats(cupsd_printer_t
*p
) /* I - Printer */
3487 int i
; /* Looping var */
3488 mime_type_t
*type
; /* Current MIME type */
3489 cups_array_t
*filters
; /* Filters */
3490 ipp_attribute_t
*attr
; /* document-format-supported attribute */
3491 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
3492 /* MIME type name */
3496 * Raw (and remote) queues advertise all of the supported MIME
3500 cupsArrayDelete(p
->filetypes
);
3501 p
->filetypes
= NULL
;
3505 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
,
3506 (ipp_tag_t
)(IPP_TAG_MIMETYPE
| IPP_TAG_COPY
),
3507 "document-format-supported", NumMimeTypes
, NULL
, MimeTypes
);
3512 * Otherwise, loop through the supported MIME types and see if there
3513 * are filters for them...
3516 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_printer_formats: %d types, %d filters",
3517 mimeNumTypes(MimeDatabase
), mimeNumFilters(MimeDatabase
));
3519 p
->filetypes
= cupsArrayNew(NULL
, NULL
);
3521 for (type
= mimeFirstType(MimeDatabase
);
3523 type
= mimeNextType(MimeDatabase
))
3525 if (!_cups_strcasecmp(type
->super
, "printer"))
3528 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
3530 if ((filters
= mimeFilter(MimeDatabase
, type
, p
->filetype
, NULL
)) != NULL
)
3532 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3533 "add_printer_formats: %s: %s needs %d filters",
3534 p
->name
, mimetype
, cupsArrayCount(filters
));
3536 cupsArrayDelete(filters
);
3537 cupsArrayAdd(p
->filetypes
, type
);
3540 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3541 "add_printer_formats: %s: %s not supported",
3546 * Add the file formats that can be filtered...
3549 if ((type
= mimeType(MimeDatabase
, "application", "octet-stream")) == NULL
||
3550 !cupsArrayFind(p
->filetypes
, type
))
3555 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3556 "add_printer_formats: %s: %d supported types",
3557 p
->name
, cupsArrayCount(p
->filetypes
) + i
);
3559 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_MIMETYPE
,
3560 "document-format-supported",
3561 cupsArrayCount(p
->filetypes
) + i
, NULL
, NULL
);
3564 attr
->values
[0].string
.text
= _cupsStrAlloc("application/octet-stream");
3566 for (type
= (mime_type_t
*)cupsArrayFirst(p
->filetypes
);
3568 i
++, type
= (mime_type_t
*)cupsArrayNext(p
->filetypes
))
3570 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
3572 attr
->values
[i
].string
.text
= _cupsStrAlloc(mimetype
);
3575 #if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
3577 char pdl
[1024]; /* Buffer to build pdl list */
3578 mime_filter_t
*filter
; /* MIME filter looping var */
3582 * We only support raw printing if this is not a Tioga PrintJobMgr based
3583 * queue and if application/octet-stream is a known type...
3586 for (filter
= (mime_filter_t
*)cupsArrayFirst(MimeDatabase
->filters
);
3588 filter
= (mime_filter_t
*)cupsArrayNext(MimeDatabase
->filters
))
3590 if (filter
->dst
== p
->filetype
&& filter
->filter
&&
3591 strstr(filter
->filter
, "PrintJobMgr"))
3597 if (!filter
&& mimeType(MimeDatabase
, "application", "octet-stream"))
3598 strlcat(pdl
, "application/octet-stream,", sizeof(pdl
));
3601 * Then list a bunch of formats that are supported by the printer...
3604 for (type
= (mime_type_t
*)cupsArrayFirst(p
->filetypes
);
3606 type
= (mime_type_t
*)cupsArrayNext(p
->filetypes
))
3608 if (!_cups_strcasecmp(type
->super
, "application"))
3610 if (!_cups_strcasecmp(type
->type
, "pdf"))
3611 strlcat(pdl
, "application/pdf,", sizeof(pdl
));
3612 else if (!_cups_strcasecmp(type
->type
, "postscript"))
3613 strlcat(pdl
, "application/postscript,", sizeof(pdl
));
3615 else if (!_cups_strcasecmp(type
->super
, "image"))
3617 if (!_cups_strcasecmp(type
->type
, "jpeg"))
3618 strlcat(pdl
, "image/jpeg,", sizeof(pdl
));
3619 else if (!_cups_strcasecmp(type
->type
, "png"))
3620 strlcat(pdl
, "image/png,", sizeof(pdl
));
3621 else if (!_cups_strcasecmp(type
->type
, "pwg-raster"))
3622 strlcat(pdl
, "image/pwg-raster,", sizeof(pdl
));
3627 pdl
[strlen(pdl
) - 1] = '\0'; /* Remove trailing comma */
3629 cupsdSetString(&p
->pdl
, pdl
);
3631 #endif /* HAVE_DNSSD || HAVE_AVAHI */
3636 * 'compare_printers()' - Compare two printers.
3639 static int /* O - Result of comparison */
3640 compare_printers(void *first
, /* I - First printer */
3641 void *second
, /* I - Second printer */
3642 void *data
) /* I - App data (not used) */
3646 return (_cups_strcasecmp(((cupsd_printer_t
*)first
)->name
,
3647 ((cupsd_printer_t
*)second
)->name
));
3652 * 'delete_printer_filters()' - Delete all MIME filters for a printer.
3656 delete_printer_filters(
3657 cupsd_printer_t
*p
) /* I - Printer to remove from */
3659 mime_filter_t
*filter
; /* MIME filter looping var */
3660 mime_type_t
*type
; /* Destination types for filters */
3664 * Range check input...
3671 * Remove all filters from the MIME database that have a destination
3672 * type == printer...
3675 for (filter
= mimeFirstFilter(MimeDatabase
);
3677 filter
= mimeNextFilter(MimeDatabase
))
3678 if (filter
->dst
== p
->filetype
|| filter
->dst
== p
->prefiltertype
||
3679 cupsArrayFind(p
->dest_types
, filter
->dst
))
3682 * Delete the current filter...
3685 mimeDeleteFilter(MimeDatabase
, filter
);
3688 for (type
= (mime_type_t
*)cupsArrayFirst(p
->dest_types
);
3690 type
= (mime_type_t
*)cupsArrayNext(p
->dest_types
))
3691 mimeDeleteType(MimeDatabase
, type
);
3693 cupsArrayDelete(p
->dest_types
);
3694 p
->dest_types
= NULL
;
3696 cupsdSetPrinterReasons(p
, "-cups-insecure-filter-warning"
3697 ",cups-missing-filter-warning");
3702 * 'dirty_printer()' - Mark config and state files dirty for the specified
3707 dirty_printer(cupsd_printer_t
*p
) /* I - Printer */
3709 if (p
->type
& CUPS_PRINTER_CLASS
)
3710 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
3712 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
3714 if (PrintcapFormat
== PRINTCAP_PLIST
)
3715 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
3720 * 'load_ppd()' - Load a cached PPD file, updating the cache as needed.
3724 load_ppd(cupsd_printer_t
*p
) /* I - Printer */
3726 int i
, j
, k
; /* Looping vars */
3727 char cache_name
[1024]; /* Cache filename */
3728 struct stat cache_info
; /* Cache file info */
3729 ppd_file_t
*ppd
; /* PPD file */
3730 char ppd_name
[1024]; /* PPD filename */
3731 struct stat ppd_info
; /* PPD file info */
3732 int num_media
; /* Number of media options */
3733 ppd_size_t
*size
; /* Current PPD size */
3734 ppd_option_t
*duplex
, /* Duplex option */
3735 *output_bin
, /* OutputBin option */
3736 *output_mode
, /* OutputMode option */
3737 *resolution
; /* (Set|JCL|)Resolution option */
3738 ppd_choice_t
*choice
, /* Current PPD choice */
3739 *input_slot
, /* Current input slot */
3740 *media_type
; /* Current media type */
3741 ppd_attr_t
*ppd_attr
; /* PPD attribute */
3742 int xdpi
, /* Horizontal resolution */
3743 ydpi
; /* Vertical resolution */
3744 const char *resptr
; /* Pointer into resolution keyword */
3745 _pwg_size_t
*pwgsize
; /* Current PWG size */
3746 _pwg_map_t
*pwgsource
, /* Current PWG source */
3747 *pwgtype
; /* Current PWG type */
3748 ipp_attribute_t
*attr
; /* Attribute data */
3749 _ipp_value_t
*val
; /* Attribute value */
3750 int num_finishings
, /* Number of finishings */
3751 finishings
[5]; /* finishings-supported values */
3752 int num_qualities
, /* Number of print-quality values */
3753 qualities
[3]; /* print-quality values */
3754 int num_margins
, /* Number of media-*-margin-supported values */
3755 margins
[16]; /* media-*-margin-supported values */
3756 const char *filter
; /* Current filter */
3757 static const char * const sides
[3] = /* sides-supported values */
3760 "two-sided-long-edge",
3761 "two-sided-short-edge"
3763 static const char * const standard_commands
[] =
3764 { /* Standard CUPS commands */
3772 * Check to see if the cache is up-to-date...
3775 snprintf(cache_name
, sizeof(cache_name
), "%s/%s.data", CacheDir
, p
->name
);
3776 if (stat(cache_name
, &cache_info
))
3777 cache_info
.st_mtime
= 0;
3779 snprintf(ppd_name
, sizeof(ppd_name
), "%s/ppd/%s.ppd", ServerRoot
, p
->name
);
3780 if (stat(ppd_name
, &ppd_info
))
3781 ppd_info
.st_mtime
= 1;
3783 ippDelete(p
->ppd_attrs
);
3784 p
->ppd_attrs
= NULL
;
3786 _ppdCacheDestroy(p
->pc
);
3789 if (cache_info
.st_mtime
>= ppd_info
.st_mtime
)
3791 cupsdLogMessage(CUPSD_LOG_DEBUG
, "load_ppd: Loading %s...", cache_name
);
3793 if ((p
->pc
= _ppdCacheCreateWithFile(cache_name
, &p
->ppd_attrs
)) != NULL
&&
3797 * Loaded successfully!
3805 * Reload PPD attributes from disk...
3808 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
3810 cupsdLogMessage(CUPSD_LOG_DEBUG
, "load_ppd: Loading %s...", ppd_name
);
3812 p
->type
&= ~CUPS_PRINTER_OPTIONS
;
3813 p
->type
|= CUPS_PRINTER_BW
;
3815 finishings
[0] = IPP_FINISHINGS_NONE
;
3818 p
->ppd_attrs
= ippNew();
3820 if ((ppd
= _ppdOpenFile(ppd_name
, _PPD_LOCALIZATION_NONE
)) != NULL
)
3823 * Add make/model and other various attributes...
3826 p
->pc
= _ppdCacheCreateWithPPD(ppd
);
3828 ppdMarkDefaults(ppd
);
3830 if (ppd
->color_device
)
3831 p
->type
|= CUPS_PRINTER_COLOR
;
3832 if (ppd
->variable_sizes
)
3833 p
->type
|= CUPS_PRINTER_VARIABLE
;
3834 if (!ppd
->manual_copies
)
3835 p
->type
|= CUPS_PRINTER_COPIES
;
3836 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsFax", NULL
)) != NULL
)
3837 if (ppd_attr
->value
&& !_cups_strcasecmp(ppd_attr
->value
, "true"))
3838 p
->type
|= CUPS_PRINTER_FAX
;
3840 ippAddBoolean(p
->ppd_attrs
, IPP_TAG_PRINTER
, "color-supported",
3842 if (ppd
->throughput
)
3844 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3845 "pages-per-minute", ppd
->throughput
);
3846 if (ppd
->color_device
)
3847 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3848 "pages-per-minute-color", ppd
->throughput
);
3853 * When there is no speed information, just say "1 page per minute".
3856 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3857 "pages-per-minute", 1);
3858 if (ppd
->color_device
)
3859 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3860 "pages-per-minute-color", 1);
3865 if ((output_mode
= ppdFindOption(ppd
, "OutputMode")) != NULL
)
3867 if (ppdFindChoice(output_mode
, "draft") ||
3868 ppdFindChoice(output_mode
, "fast"))
3869 qualities
[num_qualities
++] = IPP_QUALITY_DRAFT
;
3871 qualities
[num_qualities
++] = IPP_QUALITY_NORMAL
;
3873 if (ppdFindChoice(output_mode
, "best") ||
3874 ppdFindChoice(output_mode
, "high"))
3875 qualities
[num_qualities
++] = IPP_QUALITY_HIGH
;
3877 else if ((ppd_attr
= ppdFindAttr(ppd
, "APPrinterPreset", NULL
)) != NULL
)
3881 if (strstr(ppd_attr
->spec
, "draft") ||
3882 strstr(ppd_attr
->spec
, "Draft"))
3884 qualities
[num_qualities
++] = IPP_QUALITY_DRAFT
;
3888 while ((ppd_attr
= ppdFindNextAttr(ppd
, "APPrinterPreset",
3891 qualities
[num_qualities
++] = IPP_QUALITY_NORMAL
;
3892 qualities
[num_qualities
++] = IPP_QUALITY_HIGH
;
3895 qualities
[num_qualities
++] = IPP_QUALITY_NORMAL
;
3897 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
3898 "print-quality-supported", num_qualities
, qualities
);
3903 * The NickName can be localized in the character set specified
3904 * by the LanugageEncoding attribute. However, ppdOpen2() has
3905 * already converted the ppd->nickname member to UTF-8 for us
3906 * (the original attribute value is available separately)
3909 cupsdSetString(&p
->make_model
, ppd
->nickname
);
3911 else if (ppd
->modelname
)
3914 * Model name can only contain specific characters...
3917 cupsdSetString(&p
->make_model
, ppd
->modelname
);
3920 cupsdSetString(&p
->make_model
, "Bad PPD File");
3922 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
3923 "printer-make-and-model", NULL
, p
->make_model
);
3926 * Add media options from the PPD file...
3929 if (ppd
->num_sizes
== 0 || !p
->pc
)
3931 if (!ppdFindAttr(ppd
, "APScannerOnly", NULL
))
3932 cupsdLogMessage(CUPSD_LOG_CRIT
,
3933 "The PPD file for printer %s contains no media "
3934 "options and is therefore invalid!", p
->name
);
3936 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3937 "media-default", NULL
, "unknown");
3938 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3939 "media-supported", NULL
, "unknown");
3947 if ((size
= ppdPageSize(ppd
, NULL
)) != NULL
)
3948 pwgsize
= _ppdCacheGetSize(p
->pc
, size
->name
);
3952 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3953 "media-default", NULL
,
3954 pwgsize
? pwgsize
->map
.pwg
: "unknown");
3962 ipp_t
*col
; /* Collection value */
3964 input_slot
= ppdFindMarkedChoice(ppd
, "InputSlot");
3965 media_type
= ppdFindMarkedChoice(ppd
, "MediaType");
3966 col
= new_media_col(pwgsize
,
3968 _ppdCacheGetSource(p
->pc
,
3969 input_slot
->choice
) :
3972 _ppdCacheGetType(p
->pc
,
3973 media_type
->choice
) :
3976 ippAddCollection(p
->ppd_attrs
, IPP_TAG_PRINTER
, "media-col-default",
3985 num_media
= p
->pc
->num_sizes
;
3986 if (p
->pc
->custom_min_keyword
)
3989 if ((attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3990 "media-supported", num_media
, NULL
,
3995 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
;
3997 i
--, pwgsize
++, val
++)
3998 val
->string
.text
= _cupsStrRetain(pwgsize
->map
.pwg
);
4000 if (p
->pc
->custom_min_keyword
)
4002 val
->string
.text
= _cupsStrRetain(p
->pc
->custom_min_keyword
);
4004 val
->string
.text
= _cupsStrRetain(p
->pc
->custom_max_keyword
);
4009 * media-size-supported
4012 num_media
= p
->pc
->num_sizes
;
4013 if (p
->pc
->custom_min_keyword
)
4016 if ((attr
= ippAddCollections(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4017 "media-size-supported", num_media
,
4022 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
;
4024 i
--, pwgsize
++, val
++)
4026 val
->collection
= ippNew();
4027 ippAddInteger(val
->collection
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4028 "x-dimension", pwgsize
->width
);
4029 ippAddInteger(val
->collection
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4030 "y-dimension", pwgsize
->length
);
4033 if (p
->pc
->custom_min_keyword
)
4035 val
->collection
= ippNew();
4036 ippAddRange(val
->collection
, IPP_TAG_PRINTER
, "x-dimension",
4037 p
->pc
->custom_min_width
, p
->pc
->custom_max_width
);
4038 ippAddRange(val
->collection
, IPP_TAG_PRINTER
, "y-dimension",
4039 p
->pc
->custom_min_length
, p
->pc
->custom_max_length
);
4044 * media-source-supported
4047 if (p
->pc
->num_sources
> 0 &&
4048 (attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4049 "media-source-supported", p
->pc
->num_sources
,
4050 NULL
, NULL
)) != NULL
)
4052 for (i
= p
->pc
->num_sources
, pwgsource
= p
->pc
->sources
,
4055 i
--, pwgsource
++, val
++)
4056 val
->string
.text
= _cupsStrRetain(pwgsource
->pwg
);
4060 * media-type-supported
4063 if (p
->pc
->num_types
> 0 &&
4064 (attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4065 "media-type-supported", p
->pc
->num_types
,
4066 NULL
, NULL
)) != NULL
)
4068 for (i
= p
->pc
->num_types
, pwgtype
= p
->pc
->types
,
4071 i
--, pwgtype
++, val
++)
4072 val
->string
.text
= _cupsStrRetain(pwgtype
->pwg
);
4076 * media-*-margin-supported
4079 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, num_margins
= 0;
4080 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4083 for (j
= 0; j
< num_margins
; j
++)
4084 if (pwgsize
->bottom
== margins
[j
])
4087 if (j
>= num_margins
)
4089 margins
[num_margins
] = pwgsize
->bottom
;
4094 if (num_margins
> 0)
4095 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4096 "media-bottom-margin-supported", num_margins
, margins
);
4098 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4099 "media-bottom-margin-supported", 0);
4101 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, num_margins
= 0;
4102 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4105 for (j
= 0; j
< num_margins
; j
++)
4106 if (pwgsize
->left
== margins
[j
])
4109 if (j
>= num_margins
)
4111 margins
[num_margins
] = pwgsize
->left
;
4116 if (num_margins
> 0)
4117 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4118 "media-left-margin-supported", num_margins
, margins
);
4120 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4121 "media-left-margin-supported", 0);
4123 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, num_margins
= 0;
4124 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4127 for (j
= 0; j
< num_margins
; j
++)
4128 if (pwgsize
->right
== margins
[j
])
4131 if (j
>= num_margins
)
4133 margins
[num_margins
] = pwgsize
->right
;
4138 if (num_margins
> 0)
4139 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4140 "media-right-margin-supported", num_margins
, margins
);
4142 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4143 "media-right-margin-supported", 0);
4145 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, num_margins
= 0;
4146 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4149 for (j
= 0; j
< num_margins
; j
++)
4150 if (pwgsize
->top
== margins
[j
])
4153 if (j
>= num_margins
)
4155 margins
[num_margins
] = pwgsize
->top
;
4160 if (num_margins
> 0)
4161 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4162 "media-top-margin-supported", num_margins
, margins
);
4164 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4165 "media-top-margin-supported", 0);
4168 * media-col-database
4171 num_media
= p
->pc
->num_sizes
;
4172 if (p
->pc
->num_sources
)
4174 if (p
->pc
->num_types
> 0)
4175 num_media
+= p
->pc
->num_sizes
* p
->pc
->num_sources
*
4178 num_media
+= p
->pc
->num_sizes
* p
->pc
->num_sources
;
4180 else if (p
->pc
->num_types
)
4181 num_media
+= p
->pc
->num_sizes
* p
->pc
->num_types
;
4183 if ((attr
= ippAddCollections(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4184 "media-col-database", num_media
,
4187 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, val
= attr
->values
;
4192 * Start by adding the page size without source or type...
4195 ppdMarkOption(ppd
, "PageSize", pwgsize
->map
.ppd
);
4197 val
->collection
= new_media_col(pwgsize
, NULL
, NULL
);
4201 * Then add the specific, supported combinations of size, source, and
4205 if (p
->pc
->num_sources
> 0)
4207 for (j
= p
->pc
->num_sources
, pwgsource
= p
->pc
->sources
;
4211 ppdMarkOption(ppd
, "InputSlot", pwgsource
->ppd
);
4213 if (p
->pc
->num_types
> 0)
4215 for (k
= p
->pc
->num_types
, pwgtype
= p
->pc
->types
;
4219 if (!ppdMarkOption(ppd
, "MediaType", pwgtype
->ppd
))
4221 val
->collection
= new_media_col(pwgsize
, pwgsource
->pwg
,
4227 else if (!ppdConflicts(ppd
))
4229 val
->collection
= new_media_col(pwgsize
, pwgsource
->pwg
, NULL
);
4234 else if (p
->pc
->num_types
> 0)
4236 for (j
= p
->pc
->num_types
, pwgtype
= p
->pc
->types
;
4240 if (!ppdMarkOption(ppd
, "MediaType", pwgtype
->ppd
))
4242 val
->collection
= new_media_col(pwgsize
, NULL
, pwgtype
->pwg
);
4250 * Update the number of media-col-database values...
4253 attr
->num_values
= val
- attr
->values
;
4261 if (p
->pc
&& p
->pc
->num_bins
> 0)
4263 attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4264 "output-bin-supported", p
->pc
->num_bins
,
4269 for (i
= 0, val
= attr
->values
;
4270 i
< p
->pc
->num_bins
;
4272 val
->string
.text
= _cupsStrAlloc(p
->pc
->bins
[i
].pwg
);
4275 if ((output_bin
= ppdFindOption(ppd
, "OutputBin")) != NULL
)
4277 for (i
= 0; i
< p
->pc
->num_bins
; i
++)
4278 if (!strcmp(p
->pc
->bins
[i
].ppd
, output_bin
->defchoice
))
4281 if (i
>= p
->pc
->num_bins
)
4284 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4285 "output-bin-default", NULL
, p
->pc
->bins
[i
].pwg
);
4288 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4289 "output-bin-default", NULL
, p
->pc
->bins
[0].pwg
);
4291 else if (((ppd_attr
= ppdFindAttr(ppd
, "DefaultOutputOrder",
4293 !_cups_strcasecmp(ppd_attr
->value
, "Reverse")) ||
4294 (!ppd_attr
&& ppd
->manufacturer
&& /* "Compatibility heuristic" */
4295 (!_cups_strcasecmp(ppd
->manufacturer
, "epson") ||
4296 !_cups_strcasecmp(ppd
->manufacturer
, "lexmark"))))
4299 * Report that this printer has a single output bin that leaves pages face
4303 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4304 "output-bin-supported", NULL
, "face-up");
4305 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4306 "output-bin-default", NULL
, "face-up");
4310 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4311 "output-bin-supported", NULL
, "face-down");
4312 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4313 "output-bin-default", NULL
, "face-down");
4317 * output-mode and print-color-mode...
4320 if (ppd
->color_device
)
4322 static const char * const output_modes
[] =
4328 ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4329 "output-mode-supported", 2, NULL
, output_modes
);
4330 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4331 "output-mode-default", NULL
, "color");
4333 ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4334 "print-color-mode-supported", 2, NULL
, output_modes
);
4335 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4336 "print-color-mode-default", NULL
, "color");
4340 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4341 "output-mode-supported", NULL
, "monochrome");
4342 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4343 "output-mode-default", NULL
, "monochrome");
4345 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4346 "print-color-mode-supported", NULL
, "monochrome");
4347 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4348 "print-color-mode-default", NULL
, "monochrome");
4352 * Printer resolutions...
4355 if ((resolution
= ppdFindOption(ppd
, "Resolution")) == NULL
)
4356 if ((resolution
= ppdFindOption(ppd
, "JCLResolution")) == NULL
)
4357 if ((resolution
= ppdFindOption(ppd
, "SetResolution")) == NULL
)
4358 resolution
= ppdFindOption(ppd
, "CNRes_PGP");
4363 * Report all supported resolutions...
4366 attr
= ippAddResolutions(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4367 "printer-resolution-supported",
4368 resolution
->num_choices
, IPP_RES_PER_INCH
,
4371 for (i
= 0, choice
= resolution
->choices
;
4372 i
< resolution
->num_choices
;
4375 xdpi
= ydpi
= (int)strtol(choice
->choice
, (char **)&resptr
, 10);
4376 if (resptr
> choice
->choice
&& xdpi
> 0 && *resptr
== 'x')
4377 ydpi
= (int)strtol(resptr
+ 1, (char **)&resptr
, 10);
4379 if (xdpi
<= 0 || ydpi
<= 0)
4381 cupsdLogMessage(CUPSD_LOG_WARN
,
4382 "Bad resolution \"%s\" for printer %s.",
4383 choice
->choice
, p
->name
);
4387 attr
->values
[i
].resolution
.xres
= xdpi
;
4388 attr
->values
[i
].resolution
.yres
= ydpi
;
4389 attr
->values
[i
].resolution
.units
= IPP_RES_PER_INCH
;
4392 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4393 "printer-resolution-default", IPP_RES_PER_INCH
,
4397 else if ((ppd_attr
= ppdFindAttr(ppd
, "DefaultResolution", NULL
)) != NULL
&&
4401 * Just the DefaultResolution to report...
4404 xdpi
= ydpi
= (int)strtol(ppd_attr
->value
, (char **)&resptr
, 10);
4405 if (resptr
> ppd_attr
->value
&& xdpi
> 0)
4408 ydpi
= (int)strtol(resptr
+ 1, (char **)&resptr
, 10);
4413 if (xdpi
<= 0 || ydpi
<= 0)
4415 cupsdLogMessage(CUPSD_LOG_WARN
,
4416 "Bad default resolution \"%s\" for printer %s.",
4417 ppd_attr
->value
, p
->name
);
4421 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4422 "printer-resolution-default", IPP_RES_PER_INCH
,
4424 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4425 "printer-resolution-supported", IPP_RES_PER_INCH
,
4431 * No resolutions in PPD - make one up...
4434 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4435 "printer-resolution-default", IPP_RES_PER_INCH
,
4437 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4438 "printer-resolution-supported", IPP_RES_PER_INCH
,
4446 ppdMarkDefaults(ppd
);
4448 if ((duplex
= ppdFindOption(ppd
, "Duplex")) == NULL
)
4449 if ((duplex
= ppdFindOption(ppd
, "EFDuplex")) == NULL
)
4450 if ((duplex
= ppdFindOption(ppd
, "EFDuplexing")) == NULL
)
4451 if ((duplex
= ppdFindOption(ppd
, "KD03Duplex")) == NULL
)
4452 duplex
= ppdFindOption(ppd
, "JCLDuplex");
4454 if (duplex
&& duplex
->num_choices
> 1 &&
4455 !ppdInstallableConflict(ppd
, duplex
->keyword
, "DuplexTumble"))
4457 p
->type
|= CUPS_PRINTER_DUPLEX
;
4459 ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4460 "sides-supported", 3, NULL
, sides
);
4462 if (!_cups_strcasecmp(duplex
->defchoice
, "DuplexTumble"))
4463 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4464 "sides-default", NULL
, "two-sided-short-edge");
4465 else if (!_cups_strcasecmp(duplex
->defchoice
, "DuplexNoTumble"))
4466 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4467 "sides-default", NULL
, "two-sided-long-edge");
4469 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4470 "sides-default", NULL
, "one-sided");
4474 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4475 "sides-supported", NULL
, "one-sided");
4476 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4477 "sides-default", NULL
, "one-sided");
4480 if (ppdFindOption(ppd
, "Collate") != NULL
)
4481 p
->type
|= CUPS_PRINTER_COLLATE
;
4483 if (ppdFindOption(ppd
, "StapleLocation") != NULL
)
4485 p
->type
|= CUPS_PRINTER_STAPLE
;
4486 finishings
[num_finishings
++] = IPP_FINISHINGS_STAPLE
;
4489 if (ppdFindOption(ppd
, "BindEdge") != NULL
)
4491 p
->type
|= CUPS_PRINTER_BIND
;
4492 finishings
[num_finishings
++] = IPP_FINISHINGS_BIND
;
4495 for (i
= 0; i
< ppd
->num_sizes
; i
++)
4496 if (ppd
->sizes
[i
].length
> 1728)
4497 p
->type
|= CUPS_PRINTER_LARGE
;
4498 else if (ppd
->sizes
[i
].length
> 1008)
4499 p
->type
|= CUPS_PRINTER_MEDIUM
;
4501 p
->type
|= CUPS_PRINTER_SMALL
;
4503 if ((ppd_attr
= ppdFindAttr(ppd
, "APICADriver", NULL
)) != NULL
&&
4504 ppd_attr
->value
&& !_cups_strcasecmp(ppd_attr
->value
, "true"))
4506 if ((ppd_attr
= ppdFindAttr(ppd
, "APScannerOnly", NULL
)) != NULL
&&
4507 ppd_attr
->value
&& !_cups_strcasecmp(ppd_attr
->value
, "true"))
4508 p
->type
|= CUPS_PRINTER_SCANNER
;
4510 p
->type
|= CUPS_PRINTER_MFP
;
4514 * Scan the filters in the PPD file...
4519 for (filter
= (const char *)cupsArrayFirst(p
->pc
->filters
);
4521 filter
= (const char *)cupsArrayNext(p
->pc
->filters
))
4523 if (!_cups_strncasecmp(filter
, "application/vnd.cups-command", 28) &&
4524 _cups_isspace(filter
[28]))
4526 p
->type
|= CUPS_PRINTER_COMMANDS
;
4532 if (p
->type
& CUPS_PRINTER_COMMANDS
)
4534 char *commands
, /* Copy of commands */
4535 *start
, /* Start of name */
4536 *end
; /* End of name */
4537 int count
; /* Number of commands */
4539 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsCommands", NULL
)) != NULL
)
4541 for (count
= 0, start
= ppd_attr
->value
; *start
; count
++)
4543 while (_cups_isspace(*start
))
4549 while (*start
&& !isspace(*start
& 255))
4559 * Make a copy of the commands string and count how many commands there
4563 attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4564 "printer-commands", count
, NULL
, NULL
);
4566 commands
= strdup(ppd_attr
->value
);
4568 for (count
= 0, start
= commands
; *start
; count
++)
4570 while (isspace(*start
& 255))
4577 while (*end
&& !isspace(*end
& 255))
4583 attr
->values
[count
].string
.text
= _cupsStrAlloc(start
);
4593 * Add the standard list of commands...
4596 ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4598 (int)(sizeof(standard_commands
) /
4599 sizeof(standard_commands
[0])), NULL
,
4606 * No commands supported...
4609 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4610 "printer-commands", NULL
, "none");
4614 * Show current and available port monitors for this printer...
4617 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
, "port-monitor",
4618 NULL
, p
->port_monitor
? p
->port_monitor
: "none");
4620 for (i
= 1, ppd_attr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
4622 i
++, ppd_attr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
));
4626 if (strstr(ppd
->protocols
, "TBCP"))
4628 else if (strstr(ppd
->protocols
, "BCP"))
4632 attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
4633 "port-monitor-supported", i
, NULL
, NULL
);
4635 attr
->values
[0].string
.text
= _cupsStrAlloc("none");
4637 for (i
= 1, ppd_attr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
4639 i
++, ppd_attr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
))
4640 attr
->values
[i
].string
.text
= _cupsStrAlloc(ppd_attr
->value
);
4644 if (strstr(ppd
->protocols
, "TBCP"))
4645 attr
->values
[i
].string
.text
= _cupsStrAlloc("tbcp");
4646 else if (strstr(ppd
->protocols
, "BCP"))
4647 attr
->values
[i
].string
.text
= _cupsStrAlloc("bcp");
4650 if (ppdFindAttr(ppd
, "APRemoteQueueID", NULL
))
4651 p
->type
|= CUPS_PRINTER_REMOTE
;
4653 #ifdef HAVE_APPLICATIONSERVICES_H
4655 * Convert the file referenced in APPrinterIconPath to a 128x128 PNG
4656 * and save it as cacheDir/printername.png
4659 if ((ppd_attr
= ppdFindAttr(ppd
, "APPrinterIconPath", NULL
)) != NULL
&&
4661 !_cupsFileCheck(ppd_attr
->value
, _CUPS_FILE_CHECK_FILE
, !RunUser
,
4662 cupsdLogFCMessage
, p
))
4664 CGImageRef imageRef
= NULL
;/* Current icon image */
4665 CGImageRef biggestIconRef
= NULL
;
4666 /* Biggest icon image */
4667 CGImageRef closestTo128IconRef
= NULL
;
4668 /* Icon image closest to and >= 128 */
4669 CGImageSourceRef sourceRef
; /* The file's image source */
4670 char outPath
[HTTP_MAX_URI
];
4671 /* The path to the PNG file */
4672 CFURLRef outUrl
; /* The URL made from the outPath */
4673 CFURLRef icnsFileUrl
; /* The URL of the original ICNS icon file */
4674 CGImageDestinationRef destRef
; /* The image destination to write */
4675 size_t bytesPerRow
; /* The bytes per row used for resizing */
4676 CGContextRef context
; /* The CG context used for resizing */
4678 snprintf(outPath
, sizeof(outPath
), "%s/%s.png", CacheDir
, p
->name
);
4679 outUrl
= CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault
,
4683 icnsFileUrl
= CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault
,
4684 (UInt8
*)ppd_attr
->value
,
4685 strlen(ppd_attr
->value
),
4687 if (outUrl
&& icnsFileUrl
)
4689 sourceRef
= CGImageSourceCreateWithURL(icnsFileUrl
, NULL
);
4692 for (i
= 0; i
< CGImageSourceGetCount(sourceRef
); i
++)
4694 imageRef
= CGImageSourceCreateImageAtIndex(sourceRef
, i
, NULL
);
4698 if (CGImageGetWidth(imageRef
) == CGImageGetHeight(imageRef
))
4701 * Loop through remembering the icon closest to 128 but >= 128
4702 * and then remember the largest icon.
4705 if (CGImageGetWidth(imageRef
) >= 128 &&
4706 (!closestTo128IconRef
||
4707 CGImageGetWidth(imageRef
) <
4708 CGImageGetWidth(closestTo128IconRef
)))
4710 CGImageRelease(closestTo128IconRef
);
4711 CGImageRetain(imageRef
);
4712 closestTo128IconRef
= imageRef
;
4715 if (!biggestIconRef
||
4716 CGImageGetWidth(imageRef
) > CGImageGetWidth(biggestIconRef
))
4718 CGImageRelease(biggestIconRef
);
4719 CGImageRetain(imageRef
);
4720 biggestIconRef
= imageRef
;
4724 CGImageRelease(imageRef
);
4730 * If biggestIconRef is NULL, we found no icons. Otherwise we first
4731 * want the closest to 128, but if none are larger than 128, we want
4732 * the largest icon available.
4735 imageRef
= closestTo128IconRef
? closestTo128IconRef
:
4737 CGImageRetain(imageRef
);
4738 CGImageRelease(biggestIconRef
);
4739 if (closestTo128IconRef
)
4740 CGImageRelease(closestTo128IconRef
);
4741 destRef
= CGImageDestinationCreateWithURL(outUrl
, kUTTypePNG
, 1,
4745 if (CGImageGetWidth(imageRef
) != 128)
4747 bytesPerRow
= CGImageGetBytesPerRow(imageRef
) /
4748 CGImageGetWidth(imageRef
) * 128;
4749 context
= CGBitmapContextCreate(NULL
, 128, 128,
4750 CGImageGetBitsPerComponent(imageRef
),
4752 CGImageGetColorSpace(imageRef
),
4753 kCGImageAlphaPremultipliedFirst
);
4756 CGContextDrawImage(context
, CGRectMake(0, 0, 128, 128),
4758 CGImageRelease(imageRef
);
4759 imageRef
= CGBitmapContextCreateImage(context
);
4760 CGContextRelease(context
);
4764 CGImageDestinationAddImage(destRef
, imageRef
, NULL
);
4765 CGImageDestinationFinalize(destRef
);
4769 CGImageRelease(imageRef
);
4772 CFRelease(sourceRef
);
4780 CFRelease(icnsFileUrl
);
4782 #endif /* HAVE_APPLICATIONSERVICES_H */
4785 * Close the PPD and set the type...
4790 else if (!access(ppd_name
, 0))
4792 int pline
; /* PPD line number */
4793 ppd_status_t pstatus
; /* PPD load status */
4796 pstatus
= ppdLastError(&pline
);
4798 cupsdLogMessage(CUPSD_LOG_ERROR
, "PPD file for %s cannot be loaded!",
4801 if (pstatus
<= PPD_ALLOC_ERROR
)
4802 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s", strerror(errno
));
4804 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s on line %d.",
4805 ppdErrorString(pstatus
), pline
);
4807 cupsdLogMessage(CUPSD_LOG_INFO
,
4808 "Hint: Run \"cupstestppd %s\" and fix any errors.",
4814 * If we have an interface script, add a filter entry for it...
4817 char interface
[1024]; /* Interface script */
4820 snprintf(interface
, sizeof(interface
), "%s/interfaces/%s", ServerRoot
,
4822 if (!access(interface
, X_OK
))
4825 * Yes, we have a System V style interface script; use it!
4828 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
4829 "printer-make-and-model", NULL
,
4830 "Local System V Printer");
4832 else if (((!strncmp(p
->device_uri
, "ipp://", 6) ||
4833 !strncmp(p
->device_uri
, "ipps://", 7)) &&
4834 (strstr(p
->device_uri
, "/printers/") != NULL
||
4835 strstr(p
->device_uri
, "/classes/") != NULL
)) ||
4836 ((strstr(p
->device_uri
, "._ipp.") != NULL
||
4837 strstr(p
->device_uri
, "._ipps.") != NULL
) &&
4838 !strcmp(p
->device_uri
+ strlen(p
->device_uri
) - 5, "/cups")))
4841 * Tell the client this is really a hard-wired remote printer.
4844 p
->type
|= CUPS_PRINTER_REMOTE
;
4847 * Point the printer-uri-supported attribute to the
4851 if (strchr(p
->device_uri
, '?'))
4854 * Strip trailing "?options" from URI...
4857 char resource
[HTTP_MAX_URI
], /* New URI */
4858 *ptr
; /* Pointer into URI */
4860 strlcpy(resource
, p
->device_uri
, sizeof(resource
));
4861 if ((ptr
= strchr(resource
, '?')) != NULL
)
4864 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
4865 "printer-uri-supported", NULL
, resource
);
4868 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
4869 "printer-uri-supported", NULL
, p
->device_uri
);
4872 * Then set the make-and-model accordingly...
4875 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
4876 "printer-make-and-model", NULL
, "Remote Printer");
4879 * Print all files directly...
4888 * Otherwise we have neither - treat this as a "dumb" printer
4889 * with no PPD file...
4892 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
4893 "printer-make-and-model", NULL
, "Local Raw Printer");
4899 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
4900 "finishings-supported", num_finishings
, finishings
);
4901 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
4902 "finishings-default", IPP_FINISHINGS_NONE
);
4907 * Save cached PPD attributes to disk...
4910 cupsdLogMessage(CUPSD_LOG_DEBUG
, "load_ppd: Saving %s...", cache_name
);
4912 _ppdCacheWriteFile(p
->pc
, cache_name
, p
->ppd_attrs
);
4917 * Remove cache files...
4920 if (cache_info
.st_mtime
)
4927 * 'log_ipp_conformance()' - Log an IPP conformance issue with a printer.
4931 log_ipp_conformance(
4932 cupsd_printer_t
*p
, /* I - Printer */
4933 const char *reason
) /* I - Printer state reason */
4935 const char *message
; /* Message to log */
4937 aslmsg aslm
; /* Apple System Log message */
4938 #endif /* __APPLE__ */
4942 * Strip the leading "cups-ipp-" from the reason and create a log message for
4947 if (!strcmp(reason
, "missing-cancel-job"))
4948 message
= "Printer does not support REQUIRED Cancel-Job operation.";
4949 else if (!strcmp(reason
, "missing-get-job-attributes"))
4950 message
= "Printer does not support REQUIRED Get-Job-Attributes operation.";
4951 else if (!strcmp(reason
, "missing-print-job"))
4952 message
= "Printer does not support REQUIRED Print-Job operation.";
4953 else if (!strcmp(reason
, "missing-validate-job"))
4954 message
= "Printer does not support REQUIRED Validate-Job operation.";
4955 else if (!strcmp(reason
, "missing-get-printer-attributes"))
4956 message
= "Printer does not support REQUIRED Get-Printer-Attributes operation.";
4957 else if (!strcmp(reason
, "missing-send-document"))
4958 message
= "Printer supports Create-Job but not Send-Document operation.";
4959 else if (!strcmp(reason
, "missing-job-history"))
4960 message
= "Printer does not provide REQUIRED job history.";
4961 else if (!strcmp(reason
, "missing-job-id"))
4962 message
= "Printer does not provide REQUIRED job-id attribute.";
4963 else if (!strcmp(reason
, "missing-job-state"))
4964 message
= "Printer does not provide REQUIRED job-state attribute.";
4965 else if (!strcmp(reason
, "missing-operations-supported"))
4966 message
= "Printer does not provide REQUIRED operations-supported "
4968 else if (!strcmp(reason
, "missing-printer-is-accepting-jobs"))
4969 message
= "Printer does not provide REQUIRED printer-is-accepting-jobs "
4971 else if (!strcmp(reason
, "missing-printer-state-reasons"))
4972 message
= "Printer does not provide REQUIRED printer-state-reasons "
4974 else if (!strcmp(reason
, "wrong-http-version"))
4975 message
= "Printer does not use REQUIRED HTTP/1.1 transport.";
4977 message
= "Unknown IPP conformance failure.";
4979 cupsdLogMessage(CUPSD_LOG_WARN
, "%s: %s", p
->name
, message
);
4983 * Report the failure information to Apple if the user opts into providing
4984 * feedback to Apple...
4987 aslm
= asl_new(ASL_TYPE_MSG
);
4990 asl_set(aslm
, "com.apple.message.domain", "com.apple.printing.ipp.conformance");
4991 asl_set(aslm
, "com.apple.message.domain_scope", "com.apple.printing.ipp.conformance");
4992 asl_set(aslm
, "com.apple.message.signature", reason
);
4993 asl_set(aslm
, "com.apple.message.signature2",
4994 p
->make_model
? p
->make_model
: "Unknown");
4995 asl_log(NULL
, aslm
, ASL_LEVEL_NOTICE
, "%s: %s",
4996 p
->make_model
? p
->make_model
: "Unknown", message
);
4999 #endif /* __APPLE__ */
5004 * 'new_media_col()' - Create a media-col collection value.
5007 static ipp_t
* /* O - Collection value */
5008 new_media_col(_pwg_size_t
*size
, /* I - media-size/margin values */
5009 const char *source
, /* I - media-source value */
5010 const char *type
) /* I - media-type value */
5012 ipp_t
*media_col
, /* Collection value */
5013 *media_size
; /* media-size value */
5016 media_col
= ippNew();
5018 media_size
= ippNew();
5019 ippAddInteger(media_size
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5020 "x-dimension", size
->width
);
5021 ippAddInteger(media_size
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5022 "y-dimension", size
->length
);
5023 ippAddCollection(media_col
, IPP_TAG_PRINTER
, "media-size", media_size
);
5024 ippDelete(media_size
);
5026 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5027 "media-bottom-margin", size
->bottom
);
5028 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5029 "media-left-margin", size
->left
);
5030 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5031 "media-right-margin", size
->right
);
5032 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5033 "media-top-margin", size
->top
);
5036 ippAddString(media_col
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
, "media-source",
5040 ippAddString(media_col
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
, "media-type",
5049 * 'write_irix_config()' - Update the config files used by the IRIX
5054 write_irix_config(cupsd_printer_t
*p
) /* I - Printer to update */
5056 char filename
[1024]; /* Interface script filename */
5057 cups_file_t
*fp
; /* Interface script file */
5058 ipp_attribute_t
*attr
; /* Attribute data */
5062 * Add dummy interface and GUI scripts to fool SGI's "challenged" printing
5063 * tools. First the interface script that tells the tools what kind of
5064 * printer we have...
5067 snprintf(filename
, sizeof(filename
), "/var/spool/lp/interface/%s", p
->name
);
5069 if (p
->type
& CUPS_PRINTER_CLASS
)
5071 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
5073 cupsFilePuts(fp
, "#!/bin/sh\n");
5075 if ((attr
= ippFindAttribute(p
->attrs
, "printer-make-and-model",
5076 IPP_TAG_TEXT
)) != NULL
)
5077 cupsFilePrintf(fp
, "NAME=\"%s\"\n", attr
->values
[0].string
.text
);
5078 else if (p
->type
& CUPS_PRINTER_CLASS
)
5079 cupsFilePuts(fp
, "NAME=\"Printer Class\"\n");
5081 cupsFilePuts(fp
, "NAME=\"Remote Destination\"\n");
5083 if (p
->type
& CUPS_PRINTER_COLOR
)
5084 cupsFilePuts(fp
, "TYPE=ColorPostScript\n");
5086 cupsFilePuts(fp
, "TYPE=MonoPostScript\n");
5088 cupsFilePrintf(fp
, "HOSTNAME=%s\n", ServerName
);
5089 cupsFilePrintf(fp
, "HOSTPRINTER=%s\n", p
->name
);
5093 chmod(filename
, 0755);
5094 chown(filename
, User
, Group
);
5098 * Then the member file that tells which device file the queue is connected
5099 * to... Networked printers use "/dev/null" in this file, so that's what
5100 * we use (the actual device URI can confuse some apps...)
5103 snprintf(filename
, sizeof(filename
), "/var/spool/lp/member/%s", p
->name
);
5105 if (p
->type
& CUPS_PRINTER_CLASS
)
5107 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
5109 cupsFilePuts(fp
, "/dev/null\n");
5113 chmod(filename
, 0644);
5114 chown(filename
, User
, Group
);
5118 * The gui_interface file is a script or program that launches a GUI
5119 * option panel for the printer, using options specified on the
5120 * command-line in the third argument. The option panel must send
5121 * any printing options to stdout on a single line when the user
5122 * accepts them, or nothing if the user cancels the dialog.
5124 * The default options panel program is /usr/bin/glpoptions, from
5125 * the ESP Print Pro software. You can select another using the
5126 * PrintcapGUI option.
5129 snprintf(filename
, sizeof(filename
), "/var/spool/lp/gui_interface/ELF/%s.gui", p
->name
);
5131 if (p
->type
& CUPS_PRINTER_CLASS
)
5133 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
5135 cupsFilePuts(fp
, "#!/bin/sh\n");
5136 cupsFilePrintf(fp
, "%s -d %s -o \"$3\"\n", PrintcapGUI
, p
->name
);
5140 chmod(filename
, 0755);
5141 chown(filename
, User
, Group
);
5145 * The POD config file is needed by the printstatus command to show
5146 * the printer location and device.
5149 snprintf(filename
, sizeof(filename
), "/var/spool/lp/pod/%s.config", p
->name
);
5151 if (p
->type
& CUPS_PRINTER_CLASS
)
5153 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
5155 cupsFilePrintf(fp
, "Printer Class | %s\n",
5156 (p
->type
& CUPS_PRINTER_COLOR
) ? "ColorPostScript" : "MonoPostScript");
5157 cupsFilePrintf(fp
, "Printer Model | %s\n", p
->make_model
? p
->make_model
: "");
5158 cupsFilePrintf(fp
, "Location Code | %s\n", p
->location
? p
->location
: "");
5159 cupsFilePrintf(fp
, "Physical Location | %s\n", p
->info
? p
->info
: "");
5160 cupsFilePrintf(fp
, "Port Path | %s\n", p
->device_uri
);
5161 cupsFilePrintf(fp
, "Config Path | /var/spool/lp/pod/%s.config\n", p
->name
);
5162 cupsFilePrintf(fp
, "Active Status Path | /var/spool/lp/pod/%s.status\n", p
->name
);
5163 cupsFilePuts(fp
, "Status Update Wait | 10 seconds\n");
5167 chmod(filename
, 0664);
5168 chown(filename
, User
, Group
);
5174 * 'write_irix_state()' - Update the status files used by IRIX printing
5179 write_irix_state(cupsd_printer_t
*p
) /* I - Printer to update */
5181 char filename
[1024]; /* Interface script filename */
5182 cups_file_t
*fp
; /* Interface script file */
5183 int tag
; /* Status tag value */
5189 * The POD status file is needed for the printstatus window to
5190 * provide the current status of the printer.
5193 snprintf(filename
, sizeof(filename
), "/var/spool/lp/pod/%s.status", p
->name
);
5195 if (p
->type
& CUPS_PRINTER_CLASS
)
5197 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
5199 cupsFilePrintf(fp
, "Operational Status | %s\n",
5200 (p
->state
== IPP_PRINTER_IDLE
) ? "Idle" :
5201 (p
->state
== IPP_PRINTER_PROCESSING
) ? "Busy" :
5203 cupsFilePrintf(fp
, "Information | 01 00 00 | %s\n", CUPS_SVERSION
);
5204 cupsFilePrintf(fp
, "Information | 02 00 00 | Device URI: %s\n",
5206 cupsFilePrintf(fp
, "Information | 03 00 00 | %s jobs\n",
5207 p
->accepting
? "Accepting" : "Not accepting");
5208 cupsFilePrintf(fp
, "Information | 04 00 00 | %s\n", p
->state_message
);
5212 chmod(filename
, 0664);
5213 chown(filename
, User
, Group
);
5217 * The activeicons file is needed to provide desktop icons for printers:
5219 * [ quoted from /usr/lib/print/tagit ]
5221 * --- Type of printer tags (base values)
5223 * Dumb=66048 # 0x10200
5224 * DumbColor=66080 # 0x10220
5225 * Raster=66112 # 0x10240
5226 * ColorRaster=66144 # 0x10260
5227 * Plotter=66176 # 0x10280
5228 * PostScript=66208 # 0x102A0
5229 * ColorPostScript=66240 # 0x102C0
5230 * MonoPostScript=66272 # 0x102E0
5232 * --- Printer state modifiers for local printers
5237 * Unknown=3 # 0x3 (Faulted due to unknown reason)
5239 * --- Printer state modifiers for network printers
5243 * NetFaulted=10 # 0xA
5244 * NetUnknown=11 # 0xB (Faulted due to unknown reason)
5247 snprintf(filename
, sizeof(filename
), "/var/spool/lp/activeicons/%s", p
->name
);
5249 if (p
->type
& CUPS_PRINTER_CLASS
)
5251 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
5253 if (p
->type
& CUPS_PRINTER_COLOR
)
5258 if (p
->type
& CUPS_PRINTER_REMOTE
)
5261 if (p
->state
== IPP_PRINTER_PROCESSING
)
5264 else if (p
->state
== IPP_PRINTER_STOPPED
)
5267 cupsFilePuts(fp
, "#!/bin/sh\n");
5268 cupsFilePrintf(fp
, "#Tag %d\n", tag
);
5272 chmod(filename
, 0755);
5273 chown(filename
, User
, Group
);
5278 * The default file is needed by the printers window to show
5279 * the default printer.
5282 snprintf(filename
, sizeof(filename
), "/var/spool/lp/default");
5284 if (DefaultPrinter
!= NULL
)
5286 if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
5288 cupsFilePrintf(fp
, "%s\n", DefaultPrinter
->name
);
5292 chmod(filename
, 0644);
5293 chown(filename
, User
, Group
);
5303 * 'write_xml_string()' - Write a string with XML escaping.
5307 write_xml_string(cups_file_t
*fp
, /* I - File to write to */
5308 const char *s
) /* I - String to write */
5310 const char *start
; /* Start of current sequence */
5316 for (start
= s
; *s
; s
++)
5321 cupsFileWrite(fp
, start
, s
- start
);
5323 cupsFilePuts(fp
, "&");
5329 cupsFileWrite(fp
, start
, s
- start
);
5331 cupsFilePuts(fp
, "<");
5337 cupsFilePuts(fp
, start
);
5342 * End of "$Id: printers.c 7968 2008-09-19 23:03:01Z mike $".