4 * Printer routines for the CUPS scheduler.
6 * Copyright 2007-2013 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_xml_string() - Write a string with XML escaping.
56 * Include necessary headers...
61 #ifdef HAVE_APPLICATIONSERVICES_H
62 # include <ApplicationServices/ApplicationServices.h>
63 #endif /* HAVE_APPLICATIONSERVICES_H */
64 #ifdef HAVE_SYS_MOUNT_H
65 # include <sys/mount.h>
66 #endif /* HAVE_SYS_MOUNT_H */
67 #ifdef HAVE_SYS_STATVFS_H
68 # include <sys/statvfs.h>
69 #elif defined(HAVE_SYS_STATFS_H)
70 # include <sys/statfs.h>
71 #endif /* HAVE_SYS_STATVFS_H */
74 #endif /* HAVE_SYS_VFS_H */
77 #endif /* __APPLE__ */
84 static void add_printer_defaults(cupsd_printer_t
*p
);
85 static void add_printer_filter(cupsd_printer_t
*p
, mime_type_t
*type
,
87 static void add_printer_formats(cupsd_printer_t
*p
);
88 static int compare_printers(void *first
, void *second
, void *data
);
89 static void delete_printer_filters(cupsd_printer_t
*p
);
90 static void dirty_printer(cupsd_printer_t
*p
);
91 static void load_ppd(cupsd_printer_t
*p
);
92 static void log_ipp_conformance(cupsd_printer_t
*p
, const char *reason
);
93 static ipp_t
*new_media_col(_pwg_size_t
*size
, const char *source
,
95 static void write_xml_string(cups_file_t
*fp
, const char *s
);
99 * 'cupsdAddPrinter()' - Add a printer to the system.
102 cupsd_printer_t
* /* O - New printer */
103 cupsdAddPrinter(const char *name
) /* I - Name of printer */
105 cupsd_printer_t
*p
; /* New printer */
106 char uri
[1024], /* Printer URI */
107 uuid
[64]; /* Printer UUID */
111 * Range check input...
114 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdAddPrinter(\"%s\")", name
);
117 * Create a new printer entity...
120 if ((p
= calloc(1, sizeof(cupsd_printer_t
))) == NULL
)
122 cupsdLogMessage(CUPSD_LOG_CRIT
, "Unable to allocate memory for printer - %s",
127 cupsdSetString(&p
->name
, name
);
128 cupsdSetString(&p
->info
, name
);
129 cupsdSetString(&p
->hostname
, ServerName
);
131 httpAssembleURIf(HTTP_URI_CODING_ALL
, uri
, sizeof(uri
), "ipp", NULL
,
132 ServerName
, RemotePort
, "/printers/%s", name
);
133 cupsdSetString(&p
->uri
, uri
);
134 cupsdSetString(&p
->uuid
, httpAssembleUUID(ServerName
, RemotePort
, name
, 0,
135 uuid
, sizeof(uuid
)));
136 cupsdSetDeviceURI(p
, "file:///dev/null");
138 p
->state
= IPP_PRINTER_STOPPED
;
139 p
->state_time
= time(NULL
);
141 p
->shared
= DefaultShared
;
142 p
->filetype
= mimeAddType(MimeDatabase
, "printer", name
);
144 cupsdSetString(&p
->job_sheets
[0], "none");
145 cupsdSetString(&p
->job_sheets
[1], "none");
147 cupsdSetString(&p
->error_policy
, ErrorPolicy
);
148 cupsdSetString(&p
->op_policy
, DefaultPolicy
);
150 p
->op_policy_ptr
= DefaultPolicyPtr
;
153 * Insert the printer in the printer list alphabetically...
157 Printers
= cupsArrayNew(compare_printers
, NULL
);
159 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
160 "cupsdAddPrinter: Adding %s to Printers", p
->name
);
161 cupsArrayAdd(Printers
, p
);
164 * Return the new printer...
172 * 'cupsdCreateCommonData()' - Create the common printer data.
176 cupsdCreateCommonData(void)
178 int i
; /* Looping var */
179 ipp_attribute_t
*attr
; /* Attribute data */
180 cups_dir_t
*dir
; /* Notifier directory */
181 cups_dentry_t
*dent
; /* Notifier directory entry */
182 cups_array_t
*notifiers
; /* Notifier array */
183 char filename
[1024], /* Filename */
184 *notifier
; /* Current notifier */
185 cupsd_policy_t
*p
; /* Current policy */
186 int k_supported
; /* Maximum file size supported */
188 struct statvfs spoolinfo
; /* FS info for spool directory */
189 double spoolsize
; /* FS size */
190 #elif defined(HAVE_STATFS)
191 struct statfs spoolinfo
; /* FS info for spool directory */
192 double spoolsize
; /* FS size */
193 #endif /* HAVE_STATVFS */
194 static const int nups
[] = /* number-up-supported values */
195 { 1, 2, 4, 6, 9, 16 };
196 static const int orients
[4] =/* orientation-requested-supported values */
200 IPP_REVERSE_LANDSCAPE
,
203 static const char * const holds
[] = /* job-hold-until-supported values */
214 static const char * const versions
[] =/* ipp-versions-supported values */
221 static const int ops
[] = /* operations-supported values */
228 IPP_GET_JOB_ATTRIBUTES
,
230 IPP_GET_PRINTER_ATTRIBUTES
,
237 IPP_SET_PRINTER_ATTRIBUTES
,
238 IPP_SET_JOB_ATTRIBUTES
,
239 IPP_GET_PRINTER_SUPPORTED_VALUES
,
240 IPP_CREATE_PRINTER_SUBSCRIPTION
,
241 IPP_CREATE_JOB_SUBSCRIPTION
,
242 IPP_GET_SUBSCRIPTION_ATTRIBUTES
,
243 IPP_GET_SUBSCRIPTIONS
,
244 IPP_RENEW_SUBSCRIPTION
,
245 IPP_CANCEL_SUBSCRIPTION
,
246 IPP_GET_NOTIFICATIONS
,
250 IPP_RELEASE_HELD_NEW_JOBS
,
267 CUPS_AUTHENTICATE_JOB
,
272 static const char * const charsets
[] =/* charset-supported values */
277 static const char * const compressions
[] =
278 { /* document-compression-supported values */
282 #endif /* HAVE_LIBZ */
284 static const char * const media_col_supported
[] =
285 { /* media-col-supported values */
286 "media-bottom-margin",
288 "media-right-margin",
294 static const char * const multiple_document_handling
[] =
295 { /* multiple-document-handling-supported values */
296 "separate-documents-uncollated-copies",
297 "separate-documents-collated-copies"
299 static const char * const notify_attrs
[] =
300 { /* notify-attributes-supported values */
301 "printer-state-change-time",
302 "notify-lease-expiration-time",
303 "notify-subscriber-user-name"
305 static const char * const notify_events
[] =
306 { /* notify-events-supported values */
308 "job-config-changed",
315 "printer-config-changed",
317 "printer-finishings-changed",
318 "printer-media-changed",
322 "printer-state-changed",
329 static const char * const job_creation
[] =
330 { /* job-creation-attributes-supported */
333 "ipp-attribute-fidelity",
340 "multiple-document-handling",
343 "orientation-requested",
347 "printer-resolution",
350 static const char * const job_settable
[] =
351 { /* job-settable-attributes-supported */
359 "multiple-document-handling",
362 "orientation-requested",
366 "printer-resolution",
369 static const char * const pdf_versions
[] =
370 { /* pdf-versions-supported */
381 static const char * const printer_settable
[] =
382 { /* printer-settable-attributes-supported */
386 static const char * const which_jobs
[] =
387 { /* which-jobs-supported values */
401 ippDelete(CommonData
);
403 CommonData
= ippNew();
406 * Get the maximum spool size based on the size of the filesystem used for
407 * the RequestRoot directory. If the host OS doesn't support the statfs call
408 * or the filesystem is larger than 2TiB, always report INT_MAX.
412 if (statvfs(RequestRoot
, &spoolinfo
))
413 k_supported
= INT_MAX
;
414 else if ((spoolsize
= (double)spoolinfo
.f_frsize
* spoolinfo
.f_blocks
/ 1024) >
416 k_supported
= INT_MAX
;
418 k_supported
= (int)spoolsize
;
420 #elif defined(HAVE_STATFS)
421 if (statfs(RequestRoot
, &spoolinfo
))
422 k_supported
= INT_MAX
;
423 else if ((spoolsize
= (double)spoolinfo
.f_bsize
* spoolinfo
.f_blocks
/ 1024) >
425 k_supported
= INT_MAX
;
427 k_supported
= (int)spoolsize
;
430 k_supported
= INT_MAX
;
431 #endif /* HAVE_STATVFS */
434 * This list of attributes is sorted to improve performance when the
435 * client provides a requested-attributes attribute...
438 /* charset-configured */
439 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_CHARSET
| IPP_TAG_COPY
,
440 "charset-configured", NULL
, "utf-8");
442 /* charset-supported */
443 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_CHARSET
| IPP_TAG_COPY
,
444 "charset-supported", sizeof(charsets
) / sizeof(charsets
[0]),
447 /* compression-supported */
448 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
449 "compression-supported",
450 sizeof(compressions
) / sizeof(compressions
[0]),
453 /* copies-supported */
454 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "copies-supported", 1, MaxCopies
);
457 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
| IPP_TAG_COPY
,
458 "cups-version", NULL
, CUPS_SVERSION
+ 6);
460 /* generated-natural-language-supported (no IPP_TAG_COPY) */
461 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_LANGUAGE
,
462 "generated-natural-language-supported", NULL
, DefaultLanguage
);
464 /* ipp-versions-supported */
465 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
466 "ipp-versions-supported", sizeof(versions
) / sizeof(versions
[0]),
469 /* ippget-event-life */
470 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
471 "ippget-event-life", 15);
473 /* job-cancel-after-supported */
474 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "job-cancel-after-supported",
477 /* job-creation-attributes-supported */
478 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
479 "job-creation-attributes-supported",
480 sizeof(job_creation
) / sizeof(job_creation
[0]),
483 /* job-hold-until-supported */
484 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
485 "job-hold-until-supported", sizeof(holds
) / sizeof(holds
[0]),
488 /* job-ids-supported */
489 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
, "job-ids-supported", 1);
491 /* job-k-octets-supported */
492 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "job-k-octets-supported", 0,
495 /* job-priority-supported */
496 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
497 "job-priority-supported", 100);
499 /* job-settable-attributes-supported */
500 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
501 "job-settable-attributes-supported",
502 sizeof(job_settable
) / sizeof(job_settable
[0]),
505 /* job-sheets-supported */
506 if (cupsArrayCount(Banners
) > 0)
509 * Setup the job-sheets-supported attribute...
512 if (Classification
&& !ClassifyOverride
)
513 attr
= ippAddString(CommonData
, IPP_TAG_PRINTER
,
514 IPP_TAG_NAME
| IPP_TAG_COPY
,
515 "job-sheets-supported", NULL
, Classification
);
517 attr
= ippAddStrings(CommonData
, IPP_TAG_PRINTER
,
518 IPP_TAG_NAME
| IPP_TAG_COPY
,
519 "job-sheets-supported", cupsArrayCount(Banners
) + 1,
523 cupsdLogMessage(CUPSD_LOG_EMERG
,
524 "Unable to allocate memory for "
525 "job-sheets-supported attribute: %s!", strerror(errno
));
526 else if (!Classification
|| ClassifyOverride
)
528 cupsd_banner_t
*banner
; /* Current banner */
531 attr
->values
[0].string
.text
= _cupsStrAlloc("none");
533 for (i
= 1, banner
= (cupsd_banner_t
*)cupsArrayFirst(Banners
);
535 i
++, banner
= (cupsd_banner_t
*)cupsArrayNext(Banners
))
536 attr
->values
[i
].string
.text
= banner
->name
;
540 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
541 "job-sheets-supported", NULL
, "none");
543 /* jpeg-k-octets-supported */
544 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "jpeg-k-octets-supported", 0,
547 /* jpeg-x-dimension-supported */
548 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "jpeg-x-dimension-supported", 0,
551 /* jpeg-y-dimension-supported */
552 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "jpeg-y-dimension-supported", 1,
555 /* media-col-supported */
556 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
557 "media-col-supported",
558 sizeof(media_col_supported
) /
559 sizeof(media_col_supported
[0]), NULL
,
560 media_col_supported
);
562 /* multiple-document-handling-supported */
563 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
564 "multiple-document-handling-supported",
565 sizeof(multiple_document_handling
) /
566 sizeof(multiple_document_handling
[0]), NULL
,
567 multiple_document_handling
);
569 /* multiple-document-jobs-supported */
570 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
,
571 "multiple-document-jobs-supported", 1);
573 /* multiple-operation-time-out */
574 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
575 "multiple-operation-time-out", MultipleOperationTimeout
);
577 /* natural-language-configured (no IPP_TAG_COPY) */
578 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_LANGUAGE
,
579 "natural-language-configured", NULL
, DefaultLanguage
);
581 /* notify-attributes-supported */
582 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
583 "notify-attributes-supported",
584 (int)(sizeof(notify_attrs
) / sizeof(notify_attrs
[0])),
587 /* notify-lease-duration-supported */
588 ippAddRange(CommonData
, IPP_TAG_PRINTER
,
589 "notify-lease-duration-supported", 0,
590 MaxLeaseDuration
? MaxLeaseDuration
: 2147483647);
592 /* notify-max-events-supported */
593 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
594 "notify-max-events-supported", MaxEvents
);
596 /* notify-events-supported */
597 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
598 "notify-events-supported",
599 (int)(sizeof(notify_events
) / sizeof(notify_events
[0])),
600 NULL
, notify_events
);
602 /* notify-pull-method-supported */
603 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
604 "notify-pull-method-supported", NULL
, "ippget");
606 /* notify-schemes-supported */
607 snprintf(filename
, sizeof(filename
), "%s/notifier", ServerBin
);
608 if ((dir
= cupsDirOpen(filename
)) != NULL
)
610 notifiers
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
612 while ((dent
= cupsDirRead(dir
)) != NULL
)
613 if (S_ISREG(dent
->fileinfo
.st_mode
) &&
614 (dent
->fileinfo
.st_mode
& S_IXOTH
) != 0)
615 cupsArrayAdd(notifiers
, _cupsStrAlloc(dent
->filename
));
617 if (cupsArrayCount(notifiers
) > 0)
619 attr
= ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
620 "notify-schemes-supported",
621 cupsArrayCount(notifiers
), NULL
, NULL
);
623 for (i
= 0, notifier
= (char *)cupsArrayFirst(notifiers
);
625 i
++, notifier
= (char *)cupsArrayNext(notifiers
))
626 attr
->values
[i
].string
.text
= notifier
;
629 cupsArrayDelete(notifiers
);
633 /* number-up-supported */
634 ippAddIntegers(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
635 "number-up-supported", sizeof(nups
) / sizeof(nups
[0]), nups
);
637 /* operations-supported */
638 ippAddIntegers(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
639 "operations-supported", sizeof(ops
) / sizeof(ops
[0]), ops
);
641 /* orientation-requested-supported */
642 ippAddIntegers(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
643 "orientation-requested-supported", 4, orients
);
645 /* page-ranges-supported */
646 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
, "page-ranges-supported", 1);
648 /* pdf-k-octets-supported */
649 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "pdf-k-octets-supported", 0,
652 /* pdf-versions-supported */
653 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
654 "pdf-versions-supported",
655 sizeof(pdf_versions
) / sizeof(pdf_versions
[0]), NULL
,
658 /* pdl-override-supported */
659 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
660 "pdl-override-supported", NULL
, "attempted");
662 /* printer-op-policy-supported */
663 attr
= ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
664 "printer-op-policy-supported", cupsArrayCount(Policies
),
666 for (i
= 0, p
= (cupsd_policy_t
*)cupsArrayFirst(Policies
);
668 i
++, p
= (cupsd_policy_t
*)cupsArrayNext(Policies
))
669 attr
->values
[i
].string
.text
= p
->name
;
671 /* printer-settable-attributes-supported */
672 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
673 "printer-settable-attributes-supported",
674 sizeof(printer_settable
) / sizeof(printer_settable
[0]),
675 NULL
, printer_settable
);
677 /* server-is-sharing-printers */
678 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
, "server-is-sharing-printers",
679 BrowseLocalProtocols
!= 0 && Browsing
);
681 /* which-jobs-supported */
682 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
683 "which-jobs-supported",
684 sizeof(which_jobs
) / sizeof(which_jobs
[0]), NULL
, which_jobs
);
689 * 'cupsdDeleteAllPrinters()' - Delete all printers from the system.
693 cupsdDeleteAllPrinters(void)
695 cupsd_printer_t
*p
; /* Pointer to current printer/class */
698 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
700 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
702 p
->op_policy_ptr
= DefaultPolicyPtr
;
703 cupsdDeletePrinter(p
, 0);
709 * 'cupsdDeletePrinter()' - Delete a printer from the system.
712 int /* O - 1 if classes affected, 0 otherwise */
714 cupsd_printer_t
*p
, /* I - Printer to delete */
715 int update
) /* I - Update printers.conf? */
717 int i
, /* Looping var */
718 changed
= 0; /* Class changed? */
721 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdDeletePrinter(p=%p(%s), update=%d)",
725 * Save the current position in the Printers array...
728 cupsArraySave(Printers
);
731 * Stop printing on this printer...
734 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, update
);
736 p
->state
= IPP_PRINTER_STOPPED
; /* Force for browsed printers */
739 cupsdSetJobState(p
->job
, IPP_JOB_PENDING
, CUPSD_JOB_FORCE
,
740 update
? "Job stopped due to printer being deleted." :
744 * Remove the printer from the list...
747 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
748 "cupsdDeletePrinter: Removing %s from Printers", p
->name
);
749 cupsArrayRemove(Printers
, p
);
752 * If p is the default printer, assign a different one...
755 if (p
== DefaultPrinter
)
756 DefaultPrinter
= NULL
;
759 * Remove this printer from any classes...
762 changed
= cupsdDeletePrinterFromClasses(p
);
765 * Deregister from any browse protocols...
768 cupsdDeregisterPrinter(p
, 1);
771 * Free all memory used by the printer...
774 if (p
->printers
!= NULL
)
777 delete_printer_filters(p
);
779 for (i
= 0; i
< p
->num_reasons
; i
++)
780 _cupsStrFree(p
->reasons
[i
]);
783 ippDelete(p
->ppd_attrs
);
785 mimeDeleteType(MimeDatabase
, p
->filetype
);
786 mimeDeleteType(MimeDatabase
, p
->prefiltertype
);
788 cupsdFreeStrings(&(p
->users
));
791 cupsdClearString(&p
->uri
);
792 cupsdClearString(&p
->hostname
);
793 cupsdClearString(&p
->name
);
794 cupsdClearString(&p
->location
);
795 cupsdClearString(&p
->make_model
);
796 cupsdClearString(&p
->info
);
797 cupsdClearString(&p
->job_sheets
[0]);
798 cupsdClearString(&p
->job_sheets
[1]);
799 cupsdClearString(&p
->device_uri
);
800 cupsdClearString(&p
->sanitized_device_uri
);
801 cupsdClearString(&p
->port_monitor
);
802 cupsdClearString(&p
->op_policy
);
803 cupsdClearString(&p
->error_policy
);
805 cupsdClearString(&p
->alert
);
806 cupsdClearString(&p
->alert_description
);
808 #if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
809 cupsdClearString(&p
->pdl
);
810 cupsdClearString(&p
->reg_name
);
811 #endif /* HAVE_DNSSD || HAVE_AVAHI */
813 cupsArrayDelete(p
->filetypes
);
815 cupsFreeOptions(p
->num_options
, p
->options
);
820 * Restore the previous position in the Printers array...
823 cupsArrayRestore(Printers
);
830 * 'cupsdFindDest()' - Find a destination in the list.
833 cupsd_printer_t
* /* O - Destination in list */
834 cupsdFindDest(const char *name
) /* I - Name of printer or class to find */
836 cupsd_printer_t key
; /* Search key */
839 key
.name
= (char *)name
;
840 return ((cupsd_printer_t
*)cupsArrayFind(Printers
, &key
));
845 * 'cupsdFindPrinter()' - Find a printer in the list.
848 cupsd_printer_t
* /* O - Printer in list */
849 cupsdFindPrinter(const char *name
) /* I - Name of printer to find */
851 cupsd_printer_t
*p
; /* Printer in list */
854 if ((p
= cupsdFindDest(name
)) != NULL
&& (p
->type
& CUPS_PRINTER_CLASS
))
862 * 'cupsdLoadAllPrinters()' - Load printers from the printers.conf file.
866 cupsdLoadAllPrinters(void)
868 int i
; /* Looping var */
869 cups_file_t
*fp
; /* printers.conf file */
870 int linenum
; /* Current line number */
871 char line
[4096], /* Line from file */
872 *value
, /* Pointer to value */
873 *valueptr
; /* Pointer into value */
874 cupsd_printer_t
*p
; /* Current printer */
878 * Open the printers.conf file...
881 snprintf(line
, sizeof(line
), "%s/printers.conf", ServerRoot
);
882 if ((fp
= cupsdOpenConfFile(line
)) == NULL
)
886 * Read printer configurations until we hit EOF...
892 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
895 * Decode the directive...
898 if (!_cups_strcasecmp(line
, "<Printer") ||
899 !_cups_strcasecmp(line
, "<DefaultPrinter"))
902 * <Printer name> or <DefaultPrinter name>
905 if (p
== NULL
&& value
)
908 * Add the printer and a base file type...
911 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Loading printer %s...", value
);
913 p
= cupsdAddPrinter(value
);
915 p
->state
= IPP_PRINTER_IDLE
;
918 * Set the default printer as needed...
921 if (!_cups_strcasecmp(line
, "<DefaultPrinter"))
925 cupsdLogMessage(CUPSD_LOG_ERROR
,
926 "Syntax error on line %d of printers.conf.", linenum
);
928 else if (!_cups_strcasecmp(line
, "</Printer>"))
933 * Close out the current printer...
936 cupsdSetPrinterAttrs(p
);
938 if (strncmp(p
->device_uri
, "file:", 5) &&
939 p
->state
!= IPP_PRINTER_STOPPED
)
942 * See if the backend exists...
945 snprintf(line
, sizeof(line
), "%s/backend/%s", ServerBin
,
948 if ((valueptr
= strchr(line
+ strlen(ServerBin
), ':')) != NULL
)
949 *valueptr
= '\0'; /* Chop everything but URI scheme */
954 * Backend does not exist, stop printer...
957 p
->state
= IPP_PRINTER_STOPPED
;
958 snprintf(p
->state_message
, sizeof(p
->state_message
),
959 "Backend %s does not exist!", line
);
966 cupsdLogMessage(CUPSD_LOG_ERROR
,
967 "Syntax error on line %d of printers.conf.", linenum
);
971 cupsdLogMessage(CUPSD_LOG_ERROR
,
972 "Syntax error on line %d of printers.conf.", linenum
);
974 else if (!_cups_strcasecmp(line
, "UUID"))
976 if (value
&& !strncmp(value
, "urn:uuid:", 9))
977 cupsdSetString(&(p
->uuid
), value
);
979 cupsdLogMessage(CUPSD_LOG_ERROR
,
980 "Bad UUID on line %d of printers.conf.", linenum
);
982 else if (!_cups_strcasecmp(line
, "AuthInfoRequired"))
984 if (!cupsdSetAuthInfoRequired(p
, value
, NULL
))
985 cupsdLogMessage(CUPSD_LOG_ERROR
,
986 "Bad AuthInfoRequired on line %d of printers.conf.",
989 else if (!_cups_strcasecmp(line
, "Info"))
992 cupsdSetString(&p
->info
, value
);
994 else if (!_cups_strcasecmp(line
, "MakeModel"))
997 cupsdSetString(&p
->make_model
, value
);
999 else if (!_cups_strcasecmp(line
, "Location"))
1002 cupsdSetString(&p
->location
, value
);
1004 else if (!_cups_strcasecmp(line
, "DeviceURI"))
1007 cupsdSetDeviceURI(p
, value
);
1009 cupsdLogMessage(CUPSD_LOG_ERROR
,
1010 "Syntax error on line %d of printers.conf.", linenum
);
1012 else if (!_cups_strcasecmp(line
, "Option") && value
)
1018 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1021 cupsdLogMessage(CUPSD_LOG_ERROR
,
1022 "Syntax error on line %d of printers.conf.", linenum
);
1025 for (; *valueptr
&& isspace(*valueptr
& 255); *valueptr
++ = '\0');
1027 p
->num_options
= cupsAddOption(value
, valueptr
, p
->num_options
,
1031 else if (!_cups_strcasecmp(line
, "PortMonitor"))
1033 if (value
&& strcmp(value
, "none"))
1034 cupsdSetString(&p
->port_monitor
, value
);
1036 cupsdClearString(&p
->port_monitor
);
1038 cupsdLogMessage(CUPSD_LOG_ERROR
,
1039 "Syntax error on line %d of printers.conf.", linenum
);
1041 else if (!_cups_strcasecmp(line
, "Reason"))
1044 strcmp(value
, "connecting-to-device") &&
1045 strcmp(value
, "cups-insecure-filter-warning") &&
1046 strcmp(value
, "cups-missing-filter-warning"))
1048 for (i
= 0 ; i
< p
->num_reasons
; i
++)
1049 if (!strcmp(value
, p
->reasons
[i
]))
1052 if (i
>= p
->num_reasons
&&
1053 p
->num_reasons
< (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
1055 p
->reasons
[p
->num_reasons
] = _cupsStrAlloc(value
);
1060 cupsdLogMessage(CUPSD_LOG_ERROR
,
1061 "Syntax error on line %d of printers.conf.", linenum
);
1063 else if (!_cups_strcasecmp(line
, "State"))
1066 * Set the initial queue state...
1069 if (value
&& !_cups_strcasecmp(value
, "idle"))
1070 p
->state
= IPP_PRINTER_IDLE
;
1071 else if (value
&& !_cups_strcasecmp(value
, "stopped"))
1073 p
->state
= IPP_PRINTER_STOPPED
;
1075 for (i
= 0 ; i
< p
->num_reasons
; i
++)
1076 if (!strcmp("paused", p
->reasons
[i
]))
1079 if (i
>= p
->num_reasons
&&
1080 p
->num_reasons
< (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
1082 p
->reasons
[p
->num_reasons
] = _cupsStrAlloc("paused");
1087 cupsdLogMessage(CUPSD_LOG_ERROR
,
1088 "Syntax error on line %d of printers.conf.", linenum
);
1090 else if (!_cups_strcasecmp(line
, "StateMessage"))
1093 * Set the initial queue state message...
1097 strlcpy(p
->state_message
, value
, sizeof(p
->state_message
));
1099 else if (!_cups_strcasecmp(line
, "StateTime"))
1102 * Set the state time...
1106 p
->state_time
= atoi(value
);
1108 else if (!_cups_strcasecmp(line
, "Accepting"))
1111 * Set the initial accepting state...
1115 (!_cups_strcasecmp(value
, "yes") ||
1116 !_cups_strcasecmp(value
, "on") ||
1117 !_cups_strcasecmp(value
, "true")))
1120 (!_cups_strcasecmp(value
, "no") ||
1121 !_cups_strcasecmp(value
, "off") ||
1122 !_cups_strcasecmp(value
, "false")))
1125 cupsdLogMessage(CUPSD_LOG_ERROR
,
1126 "Syntax error on line %d of printers.conf.", linenum
);
1128 else if (!_cups_strcasecmp(line
, "Type"))
1131 p
->type
= atoi(value
);
1133 cupsdLogMessage(CUPSD_LOG_ERROR
,
1134 "Syntax error on line %d of printers.conf.", linenum
);
1136 else if (!_cups_strcasecmp(line
, "Shared"))
1139 * Set the initial shared state...
1143 (!_cups_strcasecmp(value
, "yes") ||
1144 !_cups_strcasecmp(value
, "on") ||
1145 !_cups_strcasecmp(value
, "true")))
1148 (!_cups_strcasecmp(value
, "no") ||
1149 !_cups_strcasecmp(value
, "off") ||
1150 !_cups_strcasecmp(value
, "false")))
1153 cupsdLogMessage(CUPSD_LOG_ERROR
,
1154 "Syntax error on line %d of printers.conf.", linenum
);
1156 else if (!_cups_strcasecmp(line
, "JobSheets"))
1159 * Set the initial job sheets...
1164 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1169 cupsdSetString(&p
->job_sheets
[0], value
);
1171 while (isspace(*valueptr
& 255))
1176 for (value
= valueptr
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1181 cupsdSetString(&p
->job_sheets
[1], value
);
1185 cupsdLogMessage(CUPSD_LOG_ERROR
,
1186 "Syntax error on line %d of printers.conf.", linenum
);
1188 else if (!_cups_strcasecmp(line
, "AllowUser"))
1193 cupsdAddString(&(p
->users
), value
);
1196 cupsdLogMessage(CUPSD_LOG_ERROR
,
1197 "Syntax error on line %d of printers.conf.", linenum
);
1199 else if (!_cups_strcasecmp(line
, "DenyUser"))
1204 cupsdAddString(&(p
->users
), value
);
1207 cupsdLogMessage(CUPSD_LOG_ERROR
,
1208 "Syntax error on line %d of printers.conf.", linenum
);
1210 else if (!_cups_strcasecmp(line
, "QuotaPeriod"))
1213 p
->quota_period
= atoi(value
);
1215 cupsdLogMessage(CUPSD_LOG_ERROR
,
1216 "Syntax error on line %d of printers.conf.", linenum
);
1218 else if (!_cups_strcasecmp(line
, "PageLimit"))
1221 p
->page_limit
= atoi(value
);
1223 cupsdLogMessage(CUPSD_LOG_ERROR
,
1224 "Syntax error on line %d of printers.conf.", linenum
);
1226 else if (!_cups_strcasecmp(line
, "KLimit"))
1229 p
->k_limit
= atoi(value
);
1231 cupsdLogMessage(CUPSD_LOG_ERROR
,
1232 "Syntax error on line %d of printers.conf.", linenum
);
1234 else if (!_cups_strcasecmp(line
, "OpPolicy"))
1238 cupsd_policy_t
*pol
; /* Policy */
1241 if ((pol
= cupsdFindPolicy(value
)) != NULL
)
1243 cupsdSetString(&p
->op_policy
, value
);
1244 p
->op_policy_ptr
= pol
;
1247 cupsdLogMessage(CUPSD_LOG_ERROR
,
1248 "Bad policy \"%s\" on line %d of printers.conf",
1252 cupsdLogMessage(CUPSD_LOG_ERROR
,
1253 "Syntax error on line %d of printers.conf.", linenum
);
1255 else if (!_cups_strcasecmp(line
, "ErrorPolicy"))
1258 cupsdSetString(&p
->error_policy
, value
);
1260 cupsdLogMessage(CUPSD_LOG_ERROR
,
1261 "Syntax error on line %d of printers.conf.", linenum
);
1263 else if (!_cups_strcasecmp(line
, "Attribute") && value
)
1265 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1268 cupsdLogMessage(CUPSD_LOG_ERROR
,
1269 "Syntax error on line %d of printers.conf.", linenum
);
1272 for (; *valueptr
&& isspace(*valueptr
& 255); *valueptr
++ = '\0');
1275 cupsdSetPrinterAttrs(p
);
1277 if (!strcmp(value
, "marker-change-time"))
1278 p
->marker_time
= atoi(valueptr
);
1280 cupsdSetPrinterAttr(p
, value
, valueptr
);
1283 else if (_cups_strcasecmp(line
, "Filter") &&
1284 _cups_strcasecmp(line
, "Prefilter") &&
1285 _cups_strcasecmp(line
, "Product"))
1288 * Something else we don't understand (and that wasn't used in a prior
1289 * release of CUPS...
1292 cupsdLogMessage(CUPSD_LOG_ERROR
,
1293 "Unknown configuration directive %s on line %d of "
1294 "printers.conf.", line
, linenum
);
1303 * 'cupsdRenamePrinter()' - Rename a printer.
1308 cupsd_printer_t
*p
, /* I - Printer */
1309 const char *name
) /* I - New name */
1312 * Remove the printer from the array(s) first...
1315 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1316 "cupsdRenamePrinter: Removing %s from Printers", p
->name
);
1317 cupsArrayRemove(Printers
, p
);
1320 * Rename the printer type...
1323 mimeDeleteType(MimeDatabase
, p
->filetype
);
1324 p
->filetype
= mimeAddType(MimeDatabase
, "printer", name
);
1326 if (p
->prefiltertype
)
1328 mimeDeleteType(MimeDatabase
, p
->prefiltertype
);
1329 p
->prefiltertype
= mimeAddType(MimeDatabase
, "prefilter", name
);
1333 * Rename the printer...
1336 cupsdSetString(&p
->name
, name
);
1339 * Reset printer attributes...
1342 cupsdSetPrinterAttrs(p
);
1345 * Add the printer back to the printer array(s)...
1348 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1349 "cupsdRenamePrinter: Adding %s to Printers", p
->name
);
1350 cupsArrayAdd(Printers
, p
);
1355 * 'cupsdSaveAllPrinters()' - Save all printer definitions to the printers.conf
1360 cupsdSaveAllPrinters(void)
1362 int i
; /* Looping var */
1363 cups_file_t
*fp
; /* printers.conf file */
1364 char filename
[1024], /* printers.conf filename */
1365 temp
[1024], /* Temporary string */
1366 value
[2048], /* Value string */
1367 *ptr
, /* Pointer into value */
1368 *name
; /* Current user/group name */
1369 cupsd_printer_t
*printer
; /* Current printer class */
1370 time_t curtime
; /* Current time */
1371 struct tm
*curdate
; /* Current date */
1372 cups_option_t
*option
; /* Current option */
1373 ipp_attribute_t
*marker
; /* Current marker attribute */
1377 * Create the printers.conf file...
1380 snprintf(filename
, sizeof(filename
), "%s/printers.conf", ServerRoot
);
1382 if ((fp
= cupsdCreateConfFile(filename
, ConfigFilePerm
& 0600)) == NULL
)
1385 cupsdLogMessage(CUPSD_LOG_INFO
, "Saving printers.conf...");
1388 * Write a small header to the file...
1391 curtime
= time(NULL
);
1392 curdate
= localtime(&curtime
);
1393 strftime(temp
, sizeof(temp
) - 1, "%Y-%m-%d %H:%M", curdate
);
1395 cupsFilePuts(fp
, "# Printer configuration file for " CUPS_SVERSION
"\n");
1396 cupsFilePrintf(fp
, "# Written by cupsd on %s\n", temp
);
1397 cupsFilePuts(fp
, "# DO NOT EDIT THIS FILE WHEN CUPSD IS RUNNING\n");
1400 * Write each local printer known to the system...
1403 for (printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
1405 printer
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
1408 * Skip printer classes...
1411 if (printer
->type
& CUPS_PRINTER_CLASS
)
1415 * Write printers as needed...
1418 if (printer
== DefaultPrinter
)
1419 cupsFilePrintf(fp
, "<DefaultPrinter %s>\n", printer
->name
);
1421 cupsFilePrintf(fp
, "<Printer %s>\n", printer
->name
);
1423 cupsFilePrintf(fp
, "UUID %s\n", printer
->uuid
);
1425 if (printer
->num_auth_info_required
> 0)
1427 switch (printer
->num_auth_info_required
)
1430 strlcpy(value
, printer
->auth_info_required
[0], sizeof(value
));
1434 snprintf(value
, sizeof(value
), "%s,%s",
1435 printer
->auth_info_required
[0],
1436 printer
->auth_info_required
[1]);
1441 snprintf(value
, sizeof(value
), "%s,%s,%s",
1442 printer
->auth_info_required
[0],
1443 printer
->auth_info_required
[1],
1444 printer
->auth_info_required
[2]);
1448 cupsFilePutConf(fp
, "AuthInfoRequired", value
);
1452 cupsFilePutConf(fp
, "Info", printer
->info
);
1454 if (printer
->location
)
1455 cupsFilePutConf(fp
, "Location", printer
->location
);
1457 if (printer
->make_model
)
1458 cupsFilePutConf(fp
, "MakeModel", printer
->make_model
);
1460 cupsFilePutConf(fp
, "DeviceURI", printer
->device_uri
);
1462 if (printer
->port_monitor
)
1463 cupsFilePutConf(fp
, "PortMonitor", printer
->port_monitor
);
1465 if (printer
->state
== IPP_PRINTER_STOPPED
)
1467 cupsFilePuts(fp
, "State Stopped\n");
1469 if (printer
->state_message
)
1470 cupsFilePutConf(fp
, "StateMessage", printer
->state_message
);
1473 cupsFilePuts(fp
, "State Idle\n");
1475 cupsFilePrintf(fp
, "StateTime %d\n", (int)printer
->state_time
);
1477 for (i
= 0; i
< printer
->num_reasons
; i
++)
1478 if (strcmp(printer
->reasons
[i
], "connecting-to-device") &&
1479 strcmp(printer
->reasons
[i
], "cups-insecure-filter-warning") &&
1480 strcmp(printer
->reasons
[i
], "cups-missing-filter-warning"))
1481 cupsFilePutConf(fp
, "Reason", printer
->reasons
[i
]);
1483 cupsFilePrintf(fp
, "Type %d\n", printer
->type
);
1485 if (printer
->accepting
)
1486 cupsFilePuts(fp
, "Accepting Yes\n");
1488 cupsFilePuts(fp
, "Accepting No\n");
1490 if (printer
->shared
)
1491 cupsFilePuts(fp
, "Shared Yes\n");
1493 cupsFilePuts(fp
, "Shared No\n");
1495 snprintf(value
, sizeof(value
), "%s %s", printer
->job_sheets
[0],
1496 printer
->job_sheets
[1]);
1497 cupsFilePutConf(fp
, "JobSheets", value
);
1499 cupsFilePrintf(fp
, "QuotaPeriod %d\n", printer
->quota_period
);
1500 cupsFilePrintf(fp
, "PageLimit %d\n", printer
->page_limit
);
1501 cupsFilePrintf(fp
, "KLimit %d\n", printer
->k_limit
);
1503 for (name
= (char *)cupsArrayFirst(printer
->users
);
1505 name
= (char *)cupsArrayNext(printer
->users
))
1506 cupsFilePutConf(fp
, printer
->deny_users
? "DenyUser" : "AllowUser", name
);
1508 if (printer
->op_policy
)
1509 cupsFilePutConf(fp
, "OpPolicy", printer
->op_policy
);
1510 if (printer
->error_policy
)
1511 cupsFilePutConf(fp
, "ErrorPolicy", printer
->error_policy
);
1513 for (i
= printer
->num_options
, option
= printer
->options
;
1517 snprintf(value
, sizeof(value
), "%s %s", option
->name
, option
->value
);
1518 cupsFilePutConf(fp
, "Option", value
);
1521 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-colors",
1522 IPP_TAG_NAME
)) != NULL
)
1524 snprintf(value
, sizeof(value
), "%s ", marker
->name
);
1526 for (i
= 0, ptr
= value
+ strlen(value
);
1527 i
< marker
->num_values
&& ptr
< (value
+ sizeof(value
) - 1);
1533 strlcpy(ptr
, marker
->values
[i
].string
.text
,
1534 value
+ sizeof(value
) - ptr
);
1539 cupsFilePutConf(fp
, "Attribute", value
);
1542 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-levels",
1543 IPP_TAG_INTEGER
)) != NULL
)
1545 cupsFilePrintf(fp
, "Attribute %s %d", marker
->name
,
1546 marker
->values
[0].integer
);
1547 for (i
= 1; i
< marker
->num_values
; i
++)
1548 cupsFilePrintf(fp
, ",%d", marker
->values
[i
].integer
);
1549 cupsFilePuts(fp
, "\n");
1552 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-low-levels",
1553 IPP_TAG_INTEGER
)) != NULL
)
1555 cupsFilePrintf(fp
, "Attribute %s %d", marker
->name
,
1556 marker
->values
[0].integer
);
1557 for (i
= 1; i
< marker
->num_values
; i
++)
1558 cupsFilePrintf(fp
, ",%d", marker
->values
[i
].integer
);
1559 cupsFilePuts(fp
, "\n");
1562 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-high-levels",
1563 IPP_TAG_INTEGER
)) != NULL
)
1565 cupsFilePrintf(fp
, "Attribute %s %d", marker
->name
,
1566 marker
->values
[0].integer
);
1567 for (i
= 1; i
< marker
->num_values
; i
++)
1568 cupsFilePrintf(fp
, ",%d", marker
->values
[i
].integer
);
1569 cupsFilePuts(fp
, "\n");
1572 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-message",
1573 IPP_TAG_TEXT
)) != NULL
)
1575 snprintf(value
, sizeof(value
), "%s %s", marker
->name
,
1576 marker
->values
[0].string
.text
);
1578 cupsFilePutConf(fp
, "Attribute", value
);
1581 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-names",
1582 IPP_TAG_NAME
)) != NULL
)
1584 snprintf(value
, sizeof(value
), "%s ", marker
->name
);
1586 for (i
= 0, ptr
= value
+ strlen(value
);
1587 i
< marker
->num_values
&& ptr
< (value
+ sizeof(value
) - 1);
1593 strlcpy(ptr
, marker
->values
[i
].string
.text
,
1594 value
+ sizeof(value
) - ptr
);
1599 cupsFilePutConf(fp
, "Attribute", value
);
1602 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-types",
1603 IPP_TAG_KEYWORD
)) != NULL
)
1605 snprintf(value
, sizeof(value
), "%s ", marker
->name
);
1607 for (i
= 0, ptr
= value
+ strlen(value
);
1608 i
< marker
->num_values
&& ptr
< (value
+ sizeof(value
) - 1);
1614 strlcpy(ptr
, marker
->values
[i
].string
.text
,
1615 value
+ sizeof(value
) - ptr
);
1620 cupsFilePutConf(fp
, "Attribute", value
);
1623 if (printer
->marker_time
)
1624 cupsFilePrintf(fp
, "Attribute marker-change-time %ld\n",
1625 (long)printer
->marker_time
);
1627 cupsFilePuts(fp
, "</Printer>\n");
1630 cupsdCloseCreatedConfFile(fp
, filename
);
1635 * 'cupsdSetAuthInfoRequired()' - Set the required authentication info.
1638 int /* O - 1 if value OK, 0 otherwise */
1639 cupsdSetAuthInfoRequired(
1640 cupsd_printer_t
*p
, /* I - Printer */
1641 const char *values
, /* I - Plain text value (or NULL) */
1642 ipp_attribute_t
*attr
) /* I - IPP attribute value (or NULL) */
1644 int i
; /* Looping var */
1647 p
->num_auth_info_required
= 0;
1650 * Do we have a plain text value?
1656 * Yes, grab the keywords...
1659 const char *end
; /* End of current value */
1662 while (*values
&& p
->num_auth_info_required
< 4)
1664 if ((end
= strchr(values
, ',')) == NULL
)
1665 end
= values
+ strlen(values
);
1667 if ((end
- values
) == 4 && !strncmp(values
, "none", 4))
1669 if (p
->num_auth_info_required
!= 0 || *end
)
1672 p
->auth_info_required
[p
->num_auth_info_required
] = "none";
1673 p
->num_auth_info_required
++;
1677 else if ((end
- values
) == 9 && !strncmp(values
, "negotiate", 9))
1679 if (p
->num_auth_info_required
!= 0 || *end
)
1682 p
->auth_info_required
[p
->num_auth_info_required
] = "negotiate";
1683 p
->num_auth_info_required
++;
1686 * Don't allow sharing of queues that require Kerberos authentication.
1691 cupsdDeregisterPrinter(p
, 1);
1695 else if ((end
- values
) == 6 && !strncmp(values
, "domain", 6))
1697 p
->auth_info_required
[p
->num_auth_info_required
] = "domain";
1698 p
->num_auth_info_required
++;
1700 else if ((end
- values
) == 8 && !strncmp(values
, "password", 8))
1702 p
->auth_info_required
[p
->num_auth_info_required
] = "password";
1703 p
->num_auth_info_required
++;
1705 else if ((end
- values
) == 8 && !strncmp(values
, "username", 8))
1707 p
->auth_info_required
[p
->num_auth_info_required
] = "username";
1708 p
->num_auth_info_required
++;
1713 values
= (*end
) ? end
+ 1 : end
;
1716 if (p
->num_auth_info_required
== 0)
1718 p
->auth_info_required
[0] = "none";
1719 p
->num_auth_info_required
= 1;
1723 * Update the printer-type value as needed...
1726 if (p
->num_auth_info_required
> 1 ||
1727 strcmp(p
->auth_info_required
[0], "none"))
1728 p
->type
|= CUPS_PRINTER_AUTHENTICATED
;
1730 p
->type
&= ~CUPS_PRINTER_AUTHENTICATED
;
1736 * Grab values from an attribute instead...
1739 if (!attr
|| attr
->num_values
> 4)
1742 for (i
= 0; i
< attr
->num_values
; i
++)
1744 if (!strcmp(attr
->values
[i
].string
.text
, "none"))
1746 if (p
->num_auth_info_required
!= 0 || attr
->num_values
!= 1)
1749 p
->auth_info_required
[p
->num_auth_info_required
] = "none";
1750 p
->num_auth_info_required
++;
1754 else if (!strcmp(attr
->values
[i
].string
.text
, "negotiate"))
1756 if (p
->num_auth_info_required
!= 0 || attr
->num_values
!= 1)
1759 p
->auth_info_required
[p
->num_auth_info_required
] = "negotiate";
1760 p
->num_auth_info_required
++;
1763 * Don't allow sharing of queues that require Kerberos authentication.
1768 cupsdDeregisterPrinter(p
, 1);
1774 else if (!strcmp(attr
->values
[i
].string
.text
, "domain"))
1776 p
->auth_info_required
[p
->num_auth_info_required
] = "domain";
1777 p
->num_auth_info_required
++;
1779 else if (!strcmp(attr
->values
[i
].string
.text
, "password"))
1781 p
->auth_info_required
[p
->num_auth_info_required
] = "password";
1782 p
->num_auth_info_required
++;
1784 else if (!strcmp(attr
->values
[i
].string
.text
, "username"))
1786 p
->auth_info_required
[p
->num_auth_info_required
] = "username";
1787 p
->num_auth_info_required
++;
1798 * 'cupsdSetDeviceURI()' - Set the device URI for a printer.
1802 cupsdSetDeviceURI(cupsd_printer_t
*p
, /* I - Printer */
1803 const char *uri
) /* I - Device URI */
1805 char buffer
[1024], /* URI buffer */
1806 *start
, /* Start of data after scheme */
1807 *slash
, /* First slash after scheme:// */
1808 *ptr
; /* Pointer into user@host:port part */
1812 * Set the full device URI..
1815 cupsdSetString(&(p
->device_uri
), uri
);
1818 * Copy the device URI to a temporary buffer so we can sanitize any auth
1822 strlcpy(buffer
, uri
, sizeof(buffer
));
1825 * Find the end of the scheme:// part...
1828 if ((ptr
= strchr(buffer
, ':')) != NULL
)
1830 for (start
= ptr
+ 1; *start
; start
++)
1835 * Find the next slash (/) in the URI...
1838 if ((slash
= strchr(start
, '/')) == NULL
)
1839 slash
= start
+ strlen(start
); /* No slash, point to the end */
1842 * Check for an @ sign before the slash...
1845 if ((ptr
= strchr(start
, '@')) != NULL
&& ptr
< slash
)
1848 * Found an @ sign and it is before the resource part, so we have
1849 * an authentication string. Copy the remaining URI over the
1850 * authentication string...
1853 _cups_strcpy(start
, ptr
+ 1);
1858 * Save the sanitized URI...
1861 cupsdSetString(&(p
->sanitized_device_uri
), buffer
);
1866 * 'cupsdSetPrinterAttr()' - Set a printer attribute.
1870 cupsdSetPrinterAttr(
1871 cupsd_printer_t
*p
, /* I - Printer */
1872 const char *name
, /* I - Attribute name */
1873 char *value
) /* I - Attribute value string */
1875 ipp_attribute_t
*attr
; /* Attribute */
1876 int i
, /* Looping var */
1877 count
; /* Number of values */
1878 char *ptr
, /* Pointer into value */
1879 *start
, /* Start of value */
1880 quote
; /* Quote character */
1881 ipp_tag_t value_tag
; /* Value tag for this attribute */
1885 * Don't allow empty values...
1888 if (!*value
&& strcmp(name
, "marker-message"))
1890 cupsdLogMessage(CUPSD_LOG_ERROR
, "Ignoring empty \"%s\" attribute", name
);
1895 * Count the number of values...
1898 for (count
= 1, quote
= '\0', ptr
= value
;
1906 else if (*ptr
== '\\' && ptr
[1])
1908 else if (*ptr
== '\'' || *ptr
== '\"')
1910 else if (*ptr
== ',')
1915 * Then add or update the attribute as needed...
1918 if (!strcmp(name
, "marker-levels") || !strcmp(name
, "marker-low-levels") ||
1919 !strcmp(name
, "marker-high-levels"))
1925 if ((attr
= ippFindAttribute(p
->attrs
, name
, IPP_TAG_INTEGER
)) != NULL
&&
1926 attr
->num_values
< count
)
1928 ippDeleteAttribute(p
->attrs
, attr
);
1933 attr
->num_values
= count
;
1935 attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
, name
,
1940 cupsdLogMessage(CUPSD_LOG_ERROR
,
1941 "Unable to allocate memory for printer attribute "
1942 "(%d values)", count
);
1946 for (i
= 0; i
< count
; i
++)
1948 if ((ptr
= strchr(value
, ',')) != NULL
)
1951 attr
->values
[i
].integer
= strtol(value
, NULL
, 10);
1960 * Name or keyword values...
1963 if (!strcmp(name
, "marker-types"))
1964 value_tag
= IPP_TAG_KEYWORD
;
1965 else if (!strcmp(name
, "marker-message"))
1966 value_tag
= IPP_TAG_TEXT
;
1968 value_tag
= IPP_TAG_NAME
;
1970 if ((attr
= ippFindAttribute(p
->attrs
, name
, value_tag
)) != NULL
&&
1971 attr
->num_values
< count
)
1973 ippDeleteAttribute(p
->attrs
, attr
);
1979 for (i
= 0; i
< attr
->num_values
; i
++)
1980 _cupsStrFree(attr
->values
[i
].string
.text
);
1982 attr
->num_values
= count
;
1985 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, value_tag
, name
,
1990 cupsdLogMessage(CUPSD_LOG_ERROR
,
1991 "Unable to allocate memory for printer attribute "
1992 "(%d values)", count
);
1996 for (i
= 0, quote
= '\0', ptr
= value
; i
< count
; i
++)
1998 for (start
= ptr
; *ptr
; ptr
++)
2001 *ptr
= quote
= '\0';
2004 else if (*ptr
== '\\' && ptr
[1])
2005 _cups_strcpy(ptr
, ptr
+ 1);
2006 else if (*ptr
== '\'' || *ptr
== '\"')
2013 _cups_strcpy(ptr
, ptr
+ 1);
2015 else if (*ptr
== ',')
2022 attr
->values
[i
].string
.text
= _cupsStrAlloc(start
);
2029 * 'cupsdSetPrinterAttrs()' - Set printer attributes based upon the PPD file.
2033 cupsdSetPrinterAttrs(cupsd_printer_t
*p
)/* I - Printer to setup */
2035 int i
; /* Looping var */
2036 char resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
2037 cupsd_location_t
*auth
; /* Pointer to authentication element */
2038 const char *auth_supported
; /* Authentication supported */
2039 ipp_t
*oldattrs
; /* Old printer attributes */
2040 ipp_attribute_t
*attr
; /* Attribute data */
2041 char *name
, /* Current user/group name */
2042 *filter
; /* Current filter */
2045 DEBUG_printf(("cupsdSetPrinterAttrs: entering name = %s, type = %x\n", p
->name
,
2049 * Make sure that we have the common attributes defined...
2053 cupsdCreateCommonData();
2056 * Clear out old filters, if any...
2059 delete_printer_filters(p
);
2062 * Figure out the authentication that is required for the printer.
2065 auth_supported
= "requesting-user-name";
2067 if (p
->type
& CUPS_PRINTER_CLASS
)
2068 snprintf(resource
, sizeof(resource
), "/classes/%s", p
->name
);
2070 snprintf(resource
, sizeof(resource
), "/printers/%s", p
->name
);
2072 if ((auth
= cupsdFindBest(resource
, HTTP_POST
)) == NULL
||
2073 auth
->type
== CUPSD_AUTH_NONE
)
2074 auth
= cupsdFindPolicyOp(p
->op_policy_ptr
, IPP_PRINT_JOB
);
2078 int auth_type
; /* Authentication type */
2081 if ((auth_type
= auth
->type
) == CUPSD_AUTH_DEFAULT
)
2082 auth_type
= cupsdDefaultAuthType();
2084 if (auth_type
== CUPSD_AUTH_BASIC
|| auth_type
== CUPSD_AUTH_BASICDIGEST
)
2085 auth_supported
= "basic";
2086 else if (auth_type
== CUPSD_AUTH_DIGEST
)
2087 auth_supported
= "digest";
2089 else if (auth_type
== CUPSD_AUTH_NEGOTIATE
)
2090 auth_supported
= "negotiate";
2091 #endif /* HAVE_GSSAPI */
2093 if (auth_type
!= CUPSD_AUTH_NONE
)
2094 p
->type
|= CUPS_PRINTER_AUTHENTICATED
;
2096 p
->type
&= ~CUPS_PRINTER_AUTHENTICATED
;
2099 p
->type
&= ~CUPS_PRINTER_AUTHENTICATED
;
2102 * Create the required IPP attributes for a printer...
2105 oldattrs
= p
->attrs
;
2106 p
->attrs
= ippNew();
2108 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2109 "uri-authentication-supported", NULL
, auth_supported
);
2110 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2111 "uri-security-supported", NULL
, "none");
2112 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
, "printer-name", NULL
,
2114 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-location",
2115 NULL
, p
->location
? p
->location
: "");
2116 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-info",
2117 NULL
, p
->info
? p
->info
: "");
2118 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "printer-uuid", NULL
,
2121 if (cupsArrayCount(p
->users
) > 0)
2124 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2125 "requesting-user-name-denied",
2126 cupsArrayCount(p
->users
), NULL
, NULL
);
2128 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2129 "requesting-user-name-allowed",
2130 cupsArrayCount(p
->users
), NULL
, NULL
);
2132 for (i
= 0, name
= (char *)cupsArrayFirst(p
->users
);
2134 i
++, name
= (char *)cupsArrayNext(p
->users
))
2135 attr
->values
[i
].string
.text
= _cupsStrAlloc(name
);
2138 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2139 "job-quota-period", p
->quota_period
);
2140 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2141 "job-k-limit", p
->k_limit
);
2142 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2143 "job-page-limit", p
->page_limit
);
2144 if (p
->num_auth_info_required
> 0 && strcmp(p
->auth_info_required
[0], "none"))
2145 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2146 "auth-info-required", p
->num_auth_info_required
, NULL
,
2147 p
->auth_info_required
);
2149 if (cupsArrayCount(Banners
) > 0)
2152 * Setup the job-sheets-default attribute...
2155 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2156 "job-sheets-default", 2, NULL
, NULL
);
2160 attr
->values
[0].string
.text
= _cupsStrAlloc(Classification
?
2161 Classification
: p
->job_sheets
[0]);
2162 attr
->values
[1].string
.text
= _cupsStrAlloc(Classification
?
2163 Classification
: p
->job_sheets
[1]);
2171 * Assign additional attributes depending on whether this is a printer
2175 if (p
->type
& CUPS_PRINTER_CLASS
)
2178 p
->type
&= ~CUPS_PRINTER_OPTIONS
;
2181 * Add class-specific attributes...
2184 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
2185 "printer-make-and-model", NULL
, "Local Printer Class");
2186 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "device-uri", NULL
,
2187 "file:///dev/null");
2189 if (p
->num_printers
> 0)
2192 * Add a list of member names; URIs are added in copy_printer_attrs...
2195 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2196 "member-names", p
->num_printers
, NULL
, NULL
);
2197 p
->type
|= CUPS_PRINTER_OPTIONS
;
2199 for (i
= 0; i
< p
->num_printers
; i
++)
2202 attr
->values
[i
].string
.text
= _cupsStrAlloc(p
->printers
[i
]->name
);
2204 p
->type
&= ~CUPS_PRINTER_OPTIONS
| p
->printers
[i
]->type
;
2211 * Add printer-specific attributes...
2214 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "device-uri", NULL
,
2215 p
->sanitized_device_uri
);
2218 * Assign additional attributes from the PPD file (if any)...
2224 * Add filters for printer...
2227 cupsdSetPrinterReasons(p
, "-cups-missing-filter-warning,"
2228 "cups-insecure-filter-warning");
2230 if (p
->pc
&& p
->pc
->filters
)
2232 for (filter
= (char *)cupsArrayFirst(p
->pc
->filters
);
2234 filter
= (char *)cupsArrayNext(p
->pc
->filters
))
2235 add_printer_filter(p
, p
->filetype
, filter
);
2237 else if (!(p
->type
& CUPS_PRINTER_REMOTE
))
2239 char interface
[1024]; /* Interface script */
2242 snprintf(interface
, sizeof(interface
), "%s/interfaces/%s", ServerRoot
,
2244 if (!access(interface
, X_OK
))
2247 * Yes, we have a System V style interface script; use it!
2250 snprintf(interface
, sizeof(interface
), "*/* 0 %s/interfaces/%s",
2251 ServerRoot
, p
->name
);
2252 add_printer_filter(p
, p
->filetype
, interface
);
2257 * Add a filter from application/vnd.cups-raw to printer/name to
2258 * handle "raw" printing by users.
2261 add_printer_filter(p
, p
->filetype
, "application/vnd.cups-raw 0 -");
2264 * Add a PostScript filter, since this is still possibly PS printer.
2267 add_printer_filter(p
, p
->filetype
,
2268 "application/vnd.cups-postscript 0 -");
2272 if (p
->pc
&& p
->pc
->prefilters
)
2274 if (!p
->prefiltertype
)
2275 p
->prefiltertype
= mimeAddType(MimeDatabase
, "prefilter", p
->name
);
2277 for (filter
= (char *)cupsArrayFirst(p
->pc
->prefilters
);
2279 filter
= (char *)cupsArrayNext(p
->pc
->prefilters
))
2280 add_printer_filter(p
, p
->prefiltertype
, filter
);
2285 * Copy marker attributes as needed...
2290 ipp_attribute_t
*oldattr
; /* Old attribute */
2293 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-colors",
2294 IPP_TAG_NAME
)) != NULL
)
2296 if ((attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2297 "marker-colors", oldattr
->num_values
, NULL
,
2300 for (i
= 0; i
< oldattr
->num_values
; i
++)
2301 attr
->values
[i
].string
.text
=
2302 _cupsStrAlloc(oldattr
->values
[i
].string
.text
);
2306 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-levels",
2307 IPP_TAG_INTEGER
)) != NULL
)
2309 if ((attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2310 "marker-levels", oldattr
->num_values
,
2313 for (i
= 0; i
< oldattr
->num_values
; i
++)
2314 attr
->values
[i
].integer
= oldattr
->values
[i
].integer
;
2318 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-message",
2319 IPP_TAG_TEXT
)) != NULL
)
2320 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "marker-message",
2321 NULL
, oldattr
->values
[0].string
.text
);
2323 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-low-levels",
2324 IPP_TAG_INTEGER
)) != NULL
)
2326 if ((attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2327 "marker-low-levels", oldattr
->num_values
,
2330 for (i
= 0; i
< oldattr
->num_values
; i
++)
2331 attr
->values
[i
].integer
= oldattr
->values
[i
].integer
;
2335 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-high-levels",
2336 IPP_TAG_INTEGER
)) != NULL
)
2338 if ((attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2339 "marker-high-levels", oldattr
->num_values
,
2342 for (i
= 0; i
< oldattr
->num_values
; i
++)
2343 attr
->values
[i
].integer
= oldattr
->values
[i
].integer
;
2347 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-names",
2348 IPP_TAG_NAME
)) != NULL
)
2350 if ((attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2351 "marker-names", oldattr
->num_values
, NULL
,
2354 for (i
= 0; i
< oldattr
->num_values
; i
++)
2355 attr
->values
[i
].string
.text
=
2356 _cupsStrAlloc(oldattr
->values
[i
].string
.text
);
2360 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-types",
2361 IPP_TAG_KEYWORD
)) != NULL
)
2363 if ((attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2364 "marker-types", oldattr
->num_values
, NULL
,
2367 for (i
= 0; i
< oldattr
->num_values
; i
++)
2368 attr
->values
[i
].string
.text
=
2369 _cupsStrAlloc(oldattr
->values
[i
].string
.text
);
2373 ippDelete(oldattrs
);
2377 * Force sharing off for remote queues...
2380 if (p
->type
& CUPS_PRINTER_REMOTE
)
2384 * Populate the document-format-supported attribute...
2387 add_printer_formats(p
);
2389 DEBUG_printf(("cupsdSetPrinterAttrs: leaving name = %s, type = %x\n", p
->name
,
2393 * Add name-default attributes...
2396 add_printer_defaults(p
);
2399 * Let the browse protocols reflect the change
2402 cupsdRegisterPrinter(p
);
2407 * 'cupsdSetPrinterReasons()' - Set/update the reasons strings.
2410 int /* O - 1 if something changed, 0 otherwise */
2411 cupsdSetPrinterReasons(
2412 cupsd_printer_t
*p
, /* I - Printer */
2413 const char *s
) /* I - Reasons strings */
2415 int i
, /* Looping var */
2416 changed
= 0; /* Did something change? */
2417 const char *sptr
; /* Pointer into reasons */
2418 char reason
[255], /* Reason string */
2419 *rptr
; /* Pointer into reason */
2422 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
2423 "cupsdSetPrinterReasons(p=%p(%s),s=\"%s\"", p
, p
->name
, s
);
2425 if (s
[0] == '-' || s
[0] == '+')
2428 * Add/remove reasons...
2436 * Replace reasons...
2441 for (i
= 0; i
< p
->num_reasons
; i
++)
2442 _cupsStrFree(p
->reasons
[i
]);
2450 if (!strcmp(s
, "none"))
2454 * Loop through all of the reasons...
2460 * Skip leading whitespace and commas...
2463 while (isspace(*sptr
& 255) || *sptr
== ',')
2466 for (rptr
= reason
; *sptr
&& !isspace(*sptr
& 255) && *sptr
!= ','; sptr
++)
2467 if (rptr
< (reason
+ sizeof(reason
) - 1))
2481 for (i
= 0; i
< p
->num_reasons
; i
++)
2482 if (!strcmp(reason
, p
->reasons
[i
]))
2485 * Found a match, so remove it...
2490 _cupsStrFree(p
->reasons
[i
]);
2492 if (i
< p
->num_reasons
)
2493 memmove(p
->reasons
+ i
, p
->reasons
+ i
+ 1,
2494 (p
->num_reasons
- i
) * sizeof(char *));
2496 if (!strcmp(reason
, "paused") && p
->state
== IPP_PRINTER_STOPPED
)
2497 cupsdSetPrinterState(p
, IPP_PRINTER_IDLE
, 1);
2499 if (strcmp(reason
, "connecting-to-device"))
2504 else if (p
->num_reasons
< (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
2510 for (i
= 0; i
< p
->num_reasons
; i
++)
2511 if (!strcmp(reason
, p
->reasons
[i
]))
2514 if (i
>= p
->num_reasons
)
2516 if (!strncmp(reason
, "cups-ipp-missing-", 17) ||
2517 !strncmp(reason
, "cups-ipp-wrong-", 15))
2518 log_ipp_conformance(p
, reason
);
2520 if (i
>= (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
2522 cupsdLogMessage(CUPSD_LOG_ALERT
,
2523 "Too many printer-state-reasons values for %s (%d)",
2528 p
->reasons
[i
] = _cupsStrAlloc(reason
);
2532 if (!strcmp(reason
, "paused") && p
->state
!= IPP_PRINTER_STOPPED
)
2533 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, 1);
2535 if (strcmp(reason
, "connecting-to-device"))
2546 * 'cupsdSetPrinterState()' - Update the current state of a printer.
2550 cupsdSetPrinterState(
2551 cupsd_printer_t
*p
, /* I - Printer to change */
2552 ipp_pstate_t s
, /* I - New state */
2553 int update
) /* I - Update printers.conf? */
2555 cupsd_job_t
*job
; /* Current job */
2556 ipp_pstate_t old_state
; /* Old printer state */
2557 static const char * const printer_states
[] =
2558 { /* State strings */
2566 * Set the new state...
2569 old_state
= p
->state
;
2574 cupsdAddEvent(s
== IPP_PRINTER_STOPPED
? CUPSD_EVENT_PRINTER_STOPPED
:
2575 CUPSD_EVENT_PRINTER_STATE
, p
, NULL
,
2576 "%s \"%s\" state changed to %s.",
2577 (p
->type
& CUPS_PRINTER_CLASS
) ? "Class" : "Printer",
2578 p
->name
, printer_states
[p
->state
- IPP_PRINTER_IDLE
]);
2581 * Let the browse code know this needs to be updated...
2584 p
->state_time
= time(NULL
);
2588 * Set/clear the paused reason as needed...
2591 if (s
== IPP_PRINTER_STOPPED
)
2592 cupsdSetPrinterReasons(p
, "+paused");
2594 cupsdSetPrinterReasons(p
, "-paused");
2598 for (job
= (cupsd_job_t
*)cupsArrayFirst(ActiveJobs
);
2600 job
= (cupsd_job_t
*)cupsArrayNext(ActiveJobs
))
2601 if (job
->reasons
&& job
->state_value
== IPP_JOB_PENDING
&&
2602 !_cups_strcasecmp(job
->dest
, p
->name
))
2603 ippSetString(job
->attrs
, &job
->reasons
, 0,
2604 s
== IPP_PRINTER_STOPPED
? "printer-stopped" : "none");
2608 * Clear the message for the queue when going to processing...
2611 if (s
== IPP_PRINTER_PROCESSING
)
2612 p
->state_message
[0] = '\0';
2615 * Let the browse protocols reflect the change...
2619 cupsdRegisterPrinter(p
);
2622 * Save the printer configuration if a printer goes from idle or processing
2623 * to stopped (or visa-versa)...
2627 (old_state
== IPP_PRINTER_STOPPED
) != (s
== IPP_PRINTER_STOPPED
))
2633 * 'cupsdStopPrinter()' - Stop a printer from printing any jobs...
2637 cupsdStopPrinter(cupsd_printer_t
*p
, /* I - Printer to stop */
2638 int update
)/* I - Update printers.conf? */
2641 * Set the printer state...
2644 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, update
);
2647 * See if we have a job printing on this printer...
2650 if (p
->job
&& p
->job
->state_value
== IPP_JOB_PROCESSING
)
2651 cupsdSetJobState(p
->job
, IPP_JOB_PENDING
, CUPSD_JOB_DEFAULT
,
2652 "Job stopped due to printer being paused.");
2657 * 'cupsdUpdatePrinterPPD()' - Update keywords in a printer's PPD file.
2660 int /* O - 1 if successful, 0 otherwise */
2661 cupsdUpdatePrinterPPD(
2662 cupsd_printer_t
*p
, /* I - Printer */
2663 int num_keywords
, /* I - Number of keywords */
2664 cups_option_t
*keywords
) /* I - Keywords */
2666 int i
; /* Looping var */
2667 cups_file_t
*src
, /* Original file */
2668 *dst
; /* New file */
2669 char srcfile
[1024], /* Original filename */
2670 dstfile
[1024], /* New filename */
2671 line
[1024], /* Line from file */
2672 keystring
[41]; /* Keyword from line */
2673 cups_option_t
*keyword
; /* Current keyword */
2676 cupsdLogMessage(CUPSD_LOG_INFO
, "Updating keywords in PPD file for %s...",
2680 * Get the old and new PPD filenames...
2683 snprintf(srcfile
, sizeof(srcfile
), "%s/ppd/%s.ppd.O", ServerRoot
, p
->name
);
2684 snprintf(dstfile
, sizeof(srcfile
), "%s/ppd/%s.ppd", ServerRoot
, p
->name
);
2687 * Rename the old file and open the old and new...
2690 if (rename(dstfile
, srcfile
))
2692 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to backup PPD file for %s: %s",
2693 p
->name
, strerror(errno
));
2697 if ((src
= cupsFileOpen(srcfile
, "r")) == NULL
)
2699 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to open PPD file \"%s\": %s",
2700 srcfile
, strerror(errno
));
2701 rename(srcfile
, dstfile
);
2705 if ((dst
= cupsFileOpen(dstfile
, "w")) == NULL
)
2707 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to create PPD file \"%s\": %s",
2708 dstfile
, strerror(errno
));
2710 rename(srcfile
, dstfile
);
2715 * Copy the first line and then write out all of the keywords...
2718 if (!cupsFileGets(src
, line
, sizeof(line
)))
2720 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to read PPD file \"%s\": %s",
2721 srcfile
, strerror(errno
));
2724 rename(srcfile
, dstfile
);
2728 cupsFilePrintf(dst
, "%s\n", line
);
2730 for (i
= num_keywords
, keyword
= keywords
; i
> 0; i
--, keyword
++)
2732 cupsdLogMessage(CUPSD_LOG_DEBUG
, "*%s: %s", keyword
->name
, keyword
->value
);
2733 cupsFilePrintf(dst
, "*%s: %s\n", keyword
->name
, keyword
->value
);
2737 * Then copy the rest of the PPD file, dropping any keywords we changed.
2740 while (cupsFileGets(src
, line
, sizeof(line
)))
2743 * Skip keywords we've already set...
2746 if (sscanf(line
, "*%40[^:]:", keystring
) == 1 &&
2747 cupsGetOption(keystring
, num_keywords
, keywords
))
2751 * Otherwise write the line...
2754 cupsFilePrintf(dst
, "%s\n", line
);
2758 * Close files and return...
2769 * 'cupsdUpdatePrinters()' - Update printers after a partial reload.
2773 cupsdUpdatePrinters(void)
2775 cupsd_printer_t
*p
; /* Current printer */
2779 * Loop through the printers and recreate the printer attributes
2780 * for any local printers since the policy and/or access control
2781 * stuff may have changed. Also, if browsing is disabled, remove
2782 * any remote printers...
2785 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
2787 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
2790 * Update the operation policy pointer...
2793 if ((p
->op_policy_ptr
= cupsdFindPolicy(p
->op_policy
)) == NULL
)
2794 p
->op_policy_ptr
= DefaultPolicyPtr
;
2797 * Update printer attributes...
2800 cupsdSetPrinterAttrs(p
);
2806 * 'cupsdValidateDest()' - Validate a printer/class destination.
2809 const char * /* O - Printer or class name */
2811 const char *uri
, /* I - Printer URI */
2812 cups_ptype_t
*dtype
, /* O - Type (printer or class) */
2813 cupsd_printer_t
**printer
) /* O - Printer pointer */
2815 cupsd_printer_t
*p
; /* Current printer */
2816 char localname
[1024],/* Localized hostname */
2817 *lptr
, /* Pointer into localized hostname */
2818 *sptr
, /* Pointer into server name */
2819 *rptr
, /* Pointer into resource */
2820 scheme
[32], /* Scheme portion of URI */
2821 username
[64], /* Username portion of URI */
2822 hostname
[HTTP_MAX_HOST
],
2823 /* Host portion of URI */
2824 resource
[HTTP_MAX_URI
];
2825 /* Resource portion of URI */
2826 int port
; /* Port portion of URI */
2829 DEBUG_printf(("cupsdValidateDest(uri=\"%s\", dtype=%p, printer=%p)\n", uri
,
2833 * Initialize return values...
2840 *dtype
= (cups_ptype_t
)0;
2843 * Pull the hostname and resource from the URI...
2846 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
, scheme
, sizeof(scheme
),
2847 username
, sizeof(username
), hostname
, sizeof(hostname
),
2848 &port
, resource
, sizeof(resource
));
2851 * See if the resource is a class or printer...
2854 if (!strncmp(resource
, "/classes/", 9))
2860 rptr
= resource
+ 9;
2862 else if (!strncmp(resource
, "/printers/", 10))
2868 rptr
= resource
+ 10;
2873 * Bad resource name...
2880 * See if the printer or class name exists...
2883 p
= cupsdFindDest(rptr
);
2885 if (p
== NULL
&& strchr(rptr
, '@') == NULL
)
2893 *dtype
= p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_REMOTE
);
2899 * Change localhost to the server name...
2902 if (!_cups_strcasecmp(hostname
, "localhost"))
2903 strlcpy(hostname
, ServerName
, sizeof(hostname
));
2905 strlcpy(localname
, hostname
, sizeof(localname
));
2907 if (!_cups_strcasecmp(hostname
, ServerName
))
2910 * Localize the hostname...
2913 lptr
= strchr(localname
, '.');
2914 sptr
= strchr(ServerName
, '.');
2916 if (sptr
!= NULL
&& lptr
!= NULL
)
2919 * Strip the common domain name components...
2922 while (lptr
!= NULL
)
2924 if (!_cups_strcasecmp(lptr
, sptr
))
2930 lptr
= strchr(lptr
+ 1, '.');
2935 DEBUG_printf(("localized hostname is \"%s\"...\n", localname
));
2938 * Find a matching printer or class...
2941 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
2943 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
2944 if (!_cups_strcasecmp(p
->hostname
, localname
) &&
2945 !_cups_strcasecmp(p
->name
, rptr
))
2951 *dtype
= p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_REMOTE
);
2961 * 'cupsdWritePrintcap()' - Write a pseudo-printcap file for older applications
2966 cupsdWritePrintcap(void)
2968 int i
; /* Looping var */
2969 cups_file_t
*fp
; /* Printcap file */
2970 cupsd_printer_t
*p
; /* Current printer */
2974 * See if we have a printcap file; if not, don't bother writing it.
2977 if (!Printcap
|| !*Printcap
)
2980 cupsdLogMessage(CUPSD_LOG_INFO
, "Generating printcap %s...", Printcap
);
2983 * Open the printcap file...
2986 if ((fp
= cupsFileOpen(Printcap
, "w")) == NULL
)
2990 * Put a comment header at the top so that users will know where the
2991 * data has come from...
2994 if (PrintcapFormat
!= PRINTCAP_PLIST
)
2995 cupsFilePrintf(fp
, "# This file was automatically generated by cupsd(8) "
2997 "# %s/printers.conf file. All changes to this file\n"
2998 "# will be lost.\n", ServerRoot
);
3001 * Write a new printcap with the current list of printers.
3004 switch (PrintcapFormat
)
3008 * Each printer is put in the file as:
3018 cupsFilePrintf(fp
, "%s|%s:rm=%s:rp=%s:\n", DefaultPrinter
->name
,
3019 DefaultPrinter
->info
, ServerName
,
3020 DefaultPrinter
->name
);
3022 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3024 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3025 if (p
!= DefaultPrinter
)
3026 cupsFilePrintf(fp
, "%s|%s:rm=%s:rp=%s:\n", p
->name
, p
->info
,
3027 ServerName
, p
->name
);
3030 case PRINTCAP_PLIST
:
3032 * Each printer is written as a dictionary in a plist file.
3033 * Currently the printer-name, printer-info, printer-is-accepting-jobs,
3034 * printer-location, printer-make-and-model, printer-state,
3035 * printer-state-reasons, printer-type, and (sanitized) device-uri.
3038 cupsFilePuts(fp
, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
3039 "<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD "
3040 "PLIST 1.0//EN\" \"http://www.apple.com/DTDs/"
3041 "PropertyList-1.0.dtd\">\n"
3042 "<plist version=\"1.0\">\n"
3045 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3047 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3049 cupsFilePuts(fp
, "\t<dict>\n"
3050 "\t\t<key>printer-name</key>\n"
3052 write_xml_string(fp
, p
->name
);
3053 cupsFilePuts(fp
, "</string>\n"
3054 "\t\t<key>printer-info</key>\n"
3056 write_xml_string(fp
, p
->info
);
3057 cupsFilePrintf(fp
, "</string>\n"
3058 "\t\t<key>printer-is-accepting-jobs</key>\n"
3060 "\t\t<key>printer-location</key>\n"
3061 "\t\t<string>", p
->accepting
? "true" : "false");
3062 write_xml_string(fp
, p
->location
);
3063 cupsFilePuts(fp
, "</string>\n"
3064 "\t\t<key>printer-make-and-model</key>\n"
3066 write_xml_string(fp
, p
->make_model
);
3067 cupsFilePrintf(fp
, "</string>\n"
3068 "\t\t<key>printer-state</key>\n"
3069 "\t\t<integer>%d</integer>\n"
3070 "\t\t<key>printer-state-reasons</key>\n"
3071 "\t\t<array>\n", p
->state
);
3072 for (i
= 0; i
< p
->num_reasons
; i
++)
3074 cupsFilePuts(fp
, "\t\t\t<string>");
3075 write_xml_string(fp
, p
->reasons
[i
]);
3076 cupsFilePuts(fp
, "</string>\n");
3078 cupsFilePrintf(fp
, "\t\t</array>\n"
3079 "\t\t<key>printer-type</key>\n"
3080 "\t\t<integer>%d</integer>\n"
3081 "\t\t<key>device-uri</key>\n"
3082 "\t\t<string>", p
->type
);
3083 write_xml_string(fp
, p
->sanitized_device_uri
);
3084 cupsFilePuts(fp
, "</string>\n"
3087 cupsFilePuts(fp
, "</array>\n"
3091 case PRINTCAP_SOLARIS
:
3093 * Each printer is put in the file as:
3095 * _all:all=Printer1,Printer2,Printer3,...,PrinterN
3096 * _default:use=DefaultPrinter
3098 * :bsdaddr=ServerName,Printer1:\
3099 * :description=Description:
3101 * :bsdaddr=ServerName,Printer2:\
3102 * :description=Description:
3104 * :bsdaddr=ServerName,Printer3:\
3105 * :description=Description:
3108 * :bsdaddr=ServerName,PrinterN:\
3109 * :description=Description:
3112 cupsFilePuts(fp
, "_all:all=");
3113 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3115 p
= (cupsd_printer_t
*)cupsArrayCurrent(Printers
))
3116 cupsFilePrintf(fp
, "%s%c", p
->name
,
3117 cupsArrayNext(Printers
) ? ',' : '\n');
3120 cupsFilePrintf(fp
, "_default:use=%s\n", DefaultPrinter
->name
);
3122 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3124 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3125 cupsFilePrintf(fp
, "%s:\\\n"
3126 "\t:bsdaddr=%s,%s:\\\n"
3127 "\t:description=%s:\n",
3128 p
->name
, ServerName
, p
->name
,
3129 p
->info
? p
->info
: "");
3142 * 'add_printer_defaults()' - Add name-default attributes to the printer attributes.
3146 add_printer_defaults(cupsd_printer_t
*p
)/* I - Printer */
3148 int i
; /* Looping var */
3149 int num_options
; /* Number of default options */
3150 cups_option_t
*options
, /* Default options */
3151 *option
; /* Current option */
3152 char name
[256]; /* name-default */
3156 * Maintain a common array of default attribute names...
3159 if (!CommonDefaults
)
3161 CommonDefaults
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
3163 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("copies-default"));
3164 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("document-format-default"));
3165 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("finishings-default"));
3166 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-account-id-default"));
3167 cupsArrayAdd(CommonDefaults
,
3168 _cupsStrAlloc("job-accounting-user-id-default"));
3169 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-cancel-after-default"));
3170 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-hold-until-default"));
3171 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-priority-default"));
3172 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-sheets-default"));
3173 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("media-col-default"));
3174 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("number-up-default"));
3175 cupsArrayAdd(CommonDefaults
,
3176 _cupsStrAlloc("orientation-requested-default"));
3180 * Add all of the default options from the .conf files...
3183 for (num_options
= 0, options
= NULL
, i
= p
->num_options
, option
= p
->options
;
3187 if (strcmp(option
->name
, "ipp-options") &&
3188 strcmp(option
->name
, "job-sheets") &&
3189 strcmp(option
->name
, "lease-duration"))
3191 snprintf(name
, sizeof(name
), "%s-default", option
->name
);
3192 num_options
= cupsAddOption(name
, option
->value
, num_options
, &options
);
3194 if (!cupsArrayFind(CommonDefaults
, name
))
3195 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc(name
));
3200 * Convert options to IPP attributes...
3203 cupsEncodeOptions2(p
->attrs
, num_options
, options
, IPP_TAG_PRINTER
);
3204 cupsFreeOptions(num_options
, options
);
3207 * Add standard -default attributes as needed...
3210 if (!cupsGetOption("copies", p
->num_options
, p
->options
))
3211 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
, "copies-default",
3214 if (!cupsGetOption("document-format", p
->num_options
, p
->options
))
3215 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_MIMETYPE
,
3216 "document-format-default", NULL
, "application/octet-stream");
3218 if (!cupsGetOption("job-cancel-after", p
->num_options
, p
->options
))
3219 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3220 "job-cancel-after-default", MaxJobTime
);
3222 if (!cupsGetOption("job-hold-until", p
->num_options
, p
->options
))
3223 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3224 "job-hold-until-default", NULL
, "no-hold");
3226 if (!cupsGetOption("job-priority", p
->num_options
, p
->options
))
3227 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3228 "job-priority-default", 50);
3230 if (!cupsGetOption("number-up", p
->num_options
, p
->options
))
3231 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3232 "number-up-default", 1);
3234 if (!cupsGetOption("notify-lease-duration", p
->num_options
, p
->options
))
3235 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3236 "notify-lease-duration-default", DefaultLeaseDuration
);
3238 if (!cupsGetOption("notify-events", p
->num_options
, p
->options
))
3239 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3240 "notify-events-default", NULL
, "job-completed");
3242 if (!cupsGetOption("orientation-requested", p
->num_options
, p
->options
))
3243 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NOVALUE
,
3244 "orientation-requested-default", NULL
, NULL
);
3246 if (!cupsGetOption("print-quality", p
->num_options
, p
->options
))
3247 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
3248 "print-quality-default", IPP_QUALITY_NORMAL
);
3253 * 'add_printer_filter()' - Add a MIME filter for a printer.
3258 cupsd_printer_t
*p
, /* I - Printer to add to */
3259 mime_type_t
*filtertype
, /* I - Filter or prefilter MIME type */
3260 const char *filter
) /* I - Filter to add */
3262 char super
[MIME_MAX_SUPER
], /* Super-type for filter */
3263 type
[MIME_MAX_TYPE
], /* Type for filter */
3264 dsuper
[MIME_MAX_SUPER
], /* Destination super-type for filter */
3265 dtype
[MIME_MAX_TYPE
], /* Destination type for filter */
3266 dest
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2],
3267 /* Destination super/type */
3268 program
[1024]; /* Program/filter name */
3269 int cost
; /* Cost of filter */
3270 size_t maxsize
= 0; /* Maximum supported file size */
3271 mime_type_t
*temptype
, /* MIME type looping var */
3272 *desttype
; /* Destination MIME type */
3273 mime_filter_t
*filterptr
; /* MIME filter */
3274 char filename
[1024]; /* Full filter filename */
3277 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3278 "add_printer_filter(p=%p(%s), filtertype=%p(%s/%s), "
3279 "filter=\"%s\")", p
, p
->name
, filtertype
, filtertype
->super
,
3280 filtertype
->type
, filter
);
3283 * Parse the filter string; it should be in one of the following formats:
3285 * source/type cost program
3286 * source/type cost maxsize(nnnn) program
3287 * source/type dest/type cost program
3288 * source/type dest/type cost maxsize(nnnn) program
3291 if (sscanf(filter
, "%15[^/]/%255s%*[ \t]%15[^/]/%255s%d%*[ \t]%1023[^\n]",
3292 super
, type
, dsuper
, dtype
, &cost
, program
) == 6)
3294 snprintf(dest
, sizeof(dest
), "%s/%s/%s", p
->name
, dsuper
, dtype
);
3296 if ((desttype
= mimeType(MimeDatabase
, "printer", dest
)) == NULL
)
3298 desttype
= mimeAddType(MimeDatabase
, "printer", dest
);
3300 p
->dest_types
= cupsArrayNew(NULL
, NULL
);
3302 cupsArrayAdd(p
->dest_types
, desttype
);
3308 if (sscanf(filter
, "%15[^/]/%255s%d%*[ \t]%1023[^\n]", super
, type
, &cost
,
3311 desttype
= filtertype
;
3315 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: invalid filter string \"%s\"!",
3321 if (!strncmp(program
, "maxsize(", 8))
3323 char *ptr
; /* Pointer into maxsize(nnnn) program */
3325 maxsize
= strtoll(program
+ 8, &ptr
, 10);
3329 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: invalid filter string \"%s\"!",
3335 while (_cups_isspace(*ptr
))
3338 _cups_strcpy(program
, ptr
);
3342 * Check permissions on the filter and its containing directory...
3345 if (strcmp(program
, "-"))
3347 if (program
[0] == '/')
3348 strlcpy(filename
, program
, sizeof(filename
));
3350 snprintf(filename
, sizeof(filename
), "%s/filter/%s", ServerBin
, program
);
3352 _cupsFileCheck(filename
, _CUPS_FILE_CHECK_PROGRAM
, !RunUser
,
3353 cupsdLogFCMessage
, p
);
3357 * Add the filter to the MIME database, supporting wildcards as needed...
3360 for (temptype
= mimeFirstType(MimeDatabase
);
3362 temptype
= mimeNextType(MimeDatabase
))
3363 if (((super
[0] == '*' && _cups_strcasecmp(temptype
->super
, "printer")) ||
3364 !_cups_strcasecmp(temptype
->super
, super
)) &&
3365 (type
[0] == '*' || !_cups_strcasecmp(temptype
->type
, type
)))
3367 if (desttype
!= filtertype
)
3369 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3370 "add_printer_filter: %s: adding filter %s/%s %s/%s %d "
3371 "%s", p
->name
, temptype
->super
, temptype
->type
,
3372 desttype
->super
, desttype
->type
,
3374 filterptr
= mimeAddFilter(MimeDatabase
, temptype
, desttype
, cost
,
3377 if (!mimeFilterLookup(MimeDatabase
, desttype
, filtertype
))
3379 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3380 "add_printer_filter: %s: adding filter %s/%s %s/%s "
3381 "0 -", p
->name
, desttype
->super
, desttype
->type
,
3382 filtertype
->super
, filtertype
->type
);
3383 mimeAddFilter(MimeDatabase
, desttype
, filtertype
, 0, "-");
3388 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3389 "add_printer_filter: %s: adding filter %s/%s %s/%s %d "
3390 "%s", p
->name
, temptype
->super
, temptype
->type
,
3391 filtertype
->super
, filtertype
->type
,
3393 filterptr
= mimeAddFilter(MimeDatabase
, temptype
, filtertype
, cost
,
3398 filterptr
->maxsize
= maxsize
;
3404 * 'add_printer_formats()' - Add document-format-supported values for a printer.
3408 add_printer_formats(cupsd_printer_t
*p
) /* I - Printer */
3410 int i
; /* Looping var */
3411 mime_type_t
*type
; /* Current MIME type */
3412 cups_array_t
*filters
; /* Filters */
3413 ipp_attribute_t
*attr
; /* document-format-supported attribute */
3414 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
3415 /* MIME type name */
3419 * Raw (and remote) queues advertise all of the supported MIME
3423 cupsArrayDelete(p
->filetypes
);
3424 p
->filetypes
= NULL
;
3428 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
,
3429 (ipp_tag_t
)(IPP_TAG_MIMETYPE
| IPP_TAG_COPY
),
3430 "document-format-supported", NumMimeTypes
, NULL
, MimeTypes
);
3435 * Otherwise, loop through the supported MIME types and see if there
3436 * are filters for them...
3439 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_printer_formats: %d types, %d filters",
3440 mimeNumTypes(MimeDatabase
), mimeNumFilters(MimeDatabase
));
3442 p
->filetypes
= cupsArrayNew(NULL
, NULL
);
3444 for (type
= mimeFirstType(MimeDatabase
);
3446 type
= mimeNextType(MimeDatabase
))
3448 if (!_cups_strcasecmp(type
->super
, "printer"))
3451 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
3453 if ((filters
= mimeFilter(MimeDatabase
, type
, p
->filetype
, NULL
)) != NULL
)
3455 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3456 "add_printer_formats: %s: %s needs %d filters",
3457 p
->name
, mimetype
, cupsArrayCount(filters
));
3459 cupsArrayDelete(filters
);
3460 cupsArrayAdd(p
->filetypes
, type
);
3463 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3464 "add_printer_formats: %s: %s not supported",
3469 * Add the file formats that can be filtered...
3472 if ((type
= mimeType(MimeDatabase
, "application", "octet-stream")) == NULL
||
3473 !cupsArrayFind(p
->filetypes
, type
))
3478 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3479 "add_printer_formats: %s: %d supported types",
3480 p
->name
, cupsArrayCount(p
->filetypes
) + i
);
3482 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_MIMETYPE
,
3483 "document-format-supported",
3484 cupsArrayCount(p
->filetypes
) + i
, NULL
, NULL
);
3487 attr
->values
[0].string
.text
= _cupsStrAlloc("application/octet-stream");
3489 for (type
= (mime_type_t
*)cupsArrayFirst(p
->filetypes
);
3491 i
++, type
= (mime_type_t
*)cupsArrayNext(p
->filetypes
))
3493 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
3495 attr
->values
[i
].string
.text
= _cupsStrAlloc(mimetype
);
3498 #if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
3500 char pdl
[1024]; /* Buffer to build pdl list */
3501 mime_filter_t
*filter
; /* MIME filter looping var */
3505 * We only support raw printing if this is not a Tioga PrintJobMgr based
3506 * queue and if application/octet-stream is a known type...
3509 for (filter
= (mime_filter_t
*)cupsArrayFirst(MimeDatabase
->filters
);
3511 filter
= (mime_filter_t
*)cupsArrayNext(MimeDatabase
->filters
))
3513 if (filter
->dst
== p
->filetype
&& filter
->filter
&&
3514 strstr(filter
->filter
, "PrintJobMgr"))
3520 if (!filter
&& mimeType(MimeDatabase
, "application", "octet-stream"))
3521 strlcat(pdl
, "application/octet-stream,", sizeof(pdl
));
3524 * Then list a bunch of formats that are supported by the printer...
3527 for (type
= (mime_type_t
*)cupsArrayFirst(p
->filetypes
);
3529 type
= (mime_type_t
*)cupsArrayNext(p
->filetypes
))
3531 if (!_cups_strcasecmp(type
->super
, "application"))
3533 if (!_cups_strcasecmp(type
->type
, "pdf"))
3534 strlcat(pdl
, "application/pdf,", sizeof(pdl
));
3535 else if (!_cups_strcasecmp(type
->type
, "postscript"))
3536 strlcat(pdl
, "application/postscript,", sizeof(pdl
));
3538 else if (!_cups_strcasecmp(type
->super
, "image"))
3540 if (!_cups_strcasecmp(type
->type
, "jpeg"))
3541 strlcat(pdl
, "image/jpeg,", sizeof(pdl
));
3542 else if (!_cups_strcasecmp(type
->type
, "png"))
3543 strlcat(pdl
, "image/png,", sizeof(pdl
));
3544 else if (!_cups_strcasecmp(type
->type
, "pwg-raster"))
3545 strlcat(pdl
, "image/pwg-raster,", sizeof(pdl
));
3550 pdl
[strlen(pdl
) - 1] = '\0'; /* Remove trailing comma */
3552 cupsdSetString(&p
->pdl
, pdl
);
3554 #endif /* HAVE_DNSSD || HAVE_AVAHI */
3559 * 'compare_printers()' - Compare two printers.
3562 static int /* O - Result of comparison */
3563 compare_printers(void *first
, /* I - First printer */
3564 void *second
, /* I - Second printer */
3565 void *data
) /* I - App data (not used) */
3569 return (_cups_strcasecmp(((cupsd_printer_t
*)first
)->name
,
3570 ((cupsd_printer_t
*)second
)->name
));
3575 * 'delete_printer_filters()' - Delete all MIME filters for a printer.
3579 delete_printer_filters(
3580 cupsd_printer_t
*p
) /* I - Printer to remove from */
3582 mime_filter_t
*filter
; /* MIME filter looping var */
3583 mime_type_t
*type
; /* Destination types for filters */
3587 * Range check input...
3594 * Remove all filters from the MIME database that have a destination
3595 * type == printer...
3598 for (filter
= mimeFirstFilter(MimeDatabase
);
3600 filter
= mimeNextFilter(MimeDatabase
))
3601 if (filter
->dst
== p
->filetype
|| filter
->dst
== p
->prefiltertype
||
3602 cupsArrayFind(p
->dest_types
, filter
->dst
))
3605 * Delete the current filter...
3608 mimeDeleteFilter(MimeDatabase
, filter
);
3611 for (type
= (mime_type_t
*)cupsArrayFirst(p
->dest_types
);
3613 type
= (mime_type_t
*)cupsArrayNext(p
->dest_types
))
3614 mimeDeleteType(MimeDatabase
, type
);
3616 cupsArrayDelete(p
->dest_types
);
3617 p
->dest_types
= NULL
;
3619 cupsdSetPrinterReasons(p
, "-cups-insecure-filter-warning"
3620 ",cups-missing-filter-warning");
3625 * 'dirty_printer()' - Mark config and state files dirty for the specified
3630 dirty_printer(cupsd_printer_t
*p
) /* I - Printer */
3632 if (p
->type
& CUPS_PRINTER_CLASS
)
3633 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
3635 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
3637 if (PrintcapFormat
== PRINTCAP_PLIST
)
3638 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
3643 * 'load_ppd()' - Load a cached PPD file, updating the cache as needed.
3647 load_ppd(cupsd_printer_t
*p
) /* I - Printer */
3649 int i
, j
, k
; /* Looping vars */
3650 char cache_name
[1024]; /* Cache filename */
3651 struct stat cache_info
; /* Cache file info */
3652 ppd_file_t
*ppd
; /* PPD file */
3653 char ppd_name
[1024]; /* PPD filename */
3654 struct stat ppd_info
; /* PPD file info */
3655 int num_media
; /* Number of media options */
3656 ppd_size_t
*size
; /* Current PPD size */
3657 ppd_option_t
*duplex
, /* Duplex option */
3658 *output_bin
, /* OutputBin option */
3659 *output_mode
, /* OutputMode option */
3660 *resolution
; /* (Set|JCL|)Resolution option */
3661 ppd_choice_t
*choice
, /* Current PPD choice */
3662 *input_slot
, /* Current input slot */
3663 *media_type
; /* Current media type */
3664 ppd_attr_t
*ppd_attr
; /* PPD attribute */
3665 int xdpi
, /* Horizontal resolution */
3666 ydpi
; /* Vertical resolution */
3667 const char *resptr
; /* Pointer into resolution keyword */
3668 _pwg_size_t
*pwgsize
; /* Current PWG size */
3669 _pwg_map_t
*pwgsource
, /* Current PWG source */
3670 *pwgtype
; /* Current PWG type */
3671 ipp_attribute_t
*attr
; /* Attribute data */
3672 _ipp_value_t
*val
; /* Attribute value */
3673 int num_finishings
, /* Number of finishings */
3674 finishings
[5]; /* finishings-supported values */
3675 int num_qualities
, /* Number of print-quality values */
3676 qualities
[3]; /* print-quality values */
3677 int num_margins
, /* Number of media-*-margin-supported values */
3678 margins
[16]; /* media-*-margin-supported values */
3679 const char *filter
, /* Current filter */
3680 *mandatory
; /* Current mandatory attribute */
3681 static const char * const sides
[3] = /* sides-supported values */
3684 "two-sided-long-edge",
3685 "two-sided-short-edge"
3687 static const char * const standard_commands
[] =
3688 { /* Standard CUPS commands */
3696 * Check to see if the cache is up-to-date...
3699 snprintf(cache_name
, sizeof(cache_name
), "%s/%s.data", CacheDir
, p
->name
);
3700 if (stat(cache_name
, &cache_info
))
3701 cache_info
.st_mtime
= 0;
3703 snprintf(ppd_name
, sizeof(ppd_name
), "%s/ppd/%s.ppd", ServerRoot
, p
->name
);
3704 if (stat(ppd_name
, &ppd_info
))
3705 ppd_info
.st_mtime
= 1;
3707 ippDelete(p
->ppd_attrs
);
3708 p
->ppd_attrs
= NULL
;
3710 _ppdCacheDestroy(p
->pc
);
3713 if (cache_info
.st_mtime
>= ppd_info
.st_mtime
)
3715 cupsdLogMessage(CUPSD_LOG_DEBUG
, "load_ppd: Loading %s...", cache_name
);
3717 if ((p
->pc
= _ppdCacheCreateWithFile(cache_name
, &p
->ppd_attrs
)) != NULL
&&
3721 * Loaded successfully!
3729 * Reload PPD attributes from disk...
3732 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
3734 cupsdLogMessage(CUPSD_LOG_DEBUG
, "load_ppd: Loading %s...", ppd_name
);
3736 p
->type
&= ~CUPS_PRINTER_OPTIONS
;
3737 p
->type
|= CUPS_PRINTER_BW
;
3739 finishings
[0] = IPP_FINISHINGS_NONE
;
3742 p
->ppd_attrs
= ippNew();
3744 if ((ppd
= _ppdOpenFile(ppd_name
, _PPD_LOCALIZATION_NONE
)) != NULL
)
3747 * Add make/model and other various attributes...
3750 p
->pc
= _ppdCacheCreateWithPPD(ppd
);
3753 cupsdLogMessage(CUPSD_LOG_WARN
, "Unable to create cache of \"%s\": %s",
3754 ppd_name
, cupsLastErrorString());
3756 ppdMarkDefaults(ppd
);
3758 if (ppd
->color_device
)
3759 p
->type
|= CUPS_PRINTER_COLOR
;
3760 if (ppd
->variable_sizes
)
3761 p
->type
|= CUPS_PRINTER_VARIABLE
;
3762 if (!ppd
->manual_copies
)
3763 p
->type
|= CUPS_PRINTER_COPIES
;
3764 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsFax", NULL
)) != NULL
)
3765 if (ppd_attr
->value
&& !_cups_strcasecmp(ppd_attr
->value
, "true"))
3766 p
->type
|= CUPS_PRINTER_FAX
;
3768 ippAddBoolean(p
->ppd_attrs
, IPP_TAG_PRINTER
, "color-supported",
3771 if (p
->pc
&& p
->pc
->charge_info_uri
)
3772 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
3773 "printer-charge-info-uri", NULL
, p
->pc
->charge_info_uri
);
3775 if (p
->pc
&& p
->pc
->account_id
)
3776 ippAddBoolean(p
->ppd_attrs
, IPP_TAG_PRINTER
, "job-account-id-supported",
3779 if (p
->pc
&& p
->pc
->accounting_user_id
)
3780 ippAddBoolean(p
->ppd_attrs
, IPP_TAG_PRINTER
,
3781 "job-accounting-user-id-supported", 1);
3783 if (p
->pc
&& p
->pc
->password
)
3785 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3786 "job-password-encryption-supported", NULL
, "none");
3787 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3788 "job-password-supported", strlen(p
->pc
->password
));
3791 if (ppd
->throughput
)
3793 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3794 "pages-per-minute", ppd
->throughput
);
3795 if (ppd
->color_device
)
3796 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3797 "pages-per-minute-color", ppd
->throughput
);
3802 * When there is no speed information, just say "1 page per minute".
3805 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3806 "pages-per-minute", 1);
3807 if (ppd
->color_device
)
3808 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3809 "pages-per-minute-color", 1);
3814 if ((output_mode
= ppdFindOption(ppd
, "OutputMode")) != NULL
)
3816 if (ppdFindChoice(output_mode
, "draft") ||
3817 ppdFindChoice(output_mode
, "fast"))
3818 qualities
[num_qualities
++] = IPP_QUALITY_DRAFT
;
3820 qualities
[num_qualities
++] = IPP_QUALITY_NORMAL
;
3822 if (ppdFindChoice(output_mode
, "best") ||
3823 ppdFindChoice(output_mode
, "high"))
3824 qualities
[num_qualities
++] = IPP_QUALITY_HIGH
;
3826 else if ((ppd_attr
= ppdFindAttr(ppd
, "APPrinterPreset", NULL
)) != NULL
)
3830 if (strstr(ppd_attr
->spec
, "draft") ||
3831 strstr(ppd_attr
->spec
, "Draft"))
3833 qualities
[num_qualities
++] = IPP_QUALITY_DRAFT
;
3837 while ((ppd_attr
= ppdFindNextAttr(ppd
, "APPrinterPreset",
3840 qualities
[num_qualities
++] = IPP_QUALITY_NORMAL
;
3841 qualities
[num_qualities
++] = IPP_QUALITY_HIGH
;
3844 qualities
[num_qualities
++] = IPP_QUALITY_NORMAL
;
3846 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
3847 "print-quality-supported", num_qualities
, qualities
);
3852 * The NickName can be localized in the character set specified
3853 * by the LanugageEncoding attribute. However, ppdOpen2() has
3854 * already converted the ppd->nickname member to UTF-8 for us
3855 * (the original attribute value is available separately)
3858 cupsdSetString(&p
->make_model
, ppd
->nickname
);
3860 else if (ppd
->modelname
)
3863 * Model name can only contain specific characters...
3866 cupsdSetString(&p
->make_model
, ppd
->modelname
);
3869 cupsdSetString(&p
->make_model
, "Bad PPD File");
3871 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
3872 "printer-make-and-model", NULL
, p
->make_model
);
3875 * Add media options from the PPD file...
3878 if (ppd
->num_sizes
== 0 || !p
->pc
)
3880 if (!ppdFindAttr(ppd
, "APScannerOnly", NULL
))
3881 cupsdLogMessage(CUPSD_LOG_CRIT
,
3882 "The PPD file for printer %s contains no media "
3883 "options and is therefore invalid!", p
->name
);
3885 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3886 "media-default", NULL
, "unknown");
3887 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3888 "media-supported", NULL
, "unknown");
3896 if ((size
= ppdPageSize(ppd
, NULL
)) != NULL
)
3897 pwgsize
= _ppdCacheGetSize(p
->pc
, size
->name
);
3901 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3902 "media-default", NULL
,
3903 pwgsize
? pwgsize
->map
.pwg
: "unknown");
3911 ipp_t
*col
; /* Collection value */
3913 input_slot
= ppdFindMarkedChoice(ppd
, "InputSlot");
3914 media_type
= ppdFindMarkedChoice(ppd
, "MediaType");
3915 col
= new_media_col(pwgsize
,
3917 _ppdCacheGetSource(p
->pc
,
3918 input_slot
->choice
) :
3921 _ppdCacheGetType(p
->pc
,
3922 media_type
->choice
) :
3925 ippAddCollection(p
->ppd_attrs
, IPP_TAG_PRINTER
, "media-col-default",
3934 num_media
= p
->pc
->num_sizes
;
3935 if (p
->pc
->custom_min_keyword
)
3938 if ((attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3939 "media-supported", num_media
, NULL
,
3944 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
;
3946 i
--, pwgsize
++, val
++)
3947 val
->string
.text
= _cupsStrAlloc(pwgsize
->map
.pwg
);
3949 if (p
->pc
->custom_min_keyword
)
3951 val
->string
.text
= _cupsStrAlloc(p
->pc
->custom_min_keyword
);
3953 val
->string
.text
= _cupsStrAlloc(p
->pc
->custom_max_keyword
);
3958 * media-size-supported
3961 num_media
= p
->pc
->num_sizes
;
3962 if (p
->pc
->custom_min_keyword
)
3965 if ((attr
= ippAddCollections(p
->ppd_attrs
, IPP_TAG_PRINTER
,
3966 "media-size-supported", num_media
,
3971 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
;
3973 i
--, pwgsize
++, val
++)
3975 val
->collection
= ippNew();
3976 ippAddInteger(val
->collection
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3977 "x-dimension", pwgsize
->width
);
3978 ippAddInteger(val
->collection
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3979 "y-dimension", pwgsize
->length
);
3982 if (p
->pc
->custom_min_keyword
)
3984 val
->collection
= ippNew();
3985 ippAddRange(val
->collection
, IPP_TAG_PRINTER
, "x-dimension",
3986 p
->pc
->custom_min_width
, p
->pc
->custom_max_width
);
3987 ippAddRange(val
->collection
, IPP_TAG_PRINTER
, "y-dimension",
3988 p
->pc
->custom_min_length
, p
->pc
->custom_max_length
);
3993 * media-source-supported
3996 if (p
->pc
->num_sources
> 0 &&
3997 (attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3998 "media-source-supported", p
->pc
->num_sources
,
3999 NULL
, NULL
)) != NULL
)
4001 for (i
= p
->pc
->num_sources
, pwgsource
= p
->pc
->sources
,
4004 i
--, pwgsource
++, val
++)
4005 val
->string
.text
= _cupsStrAlloc(pwgsource
->pwg
);
4009 * media-type-supported
4012 if (p
->pc
->num_types
> 0 &&
4013 (attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4014 "media-type-supported", p
->pc
->num_types
,
4015 NULL
, NULL
)) != NULL
)
4017 for (i
= p
->pc
->num_types
, pwgtype
= p
->pc
->types
,
4020 i
--, pwgtype
++, val
++)
4021 val
->string
.text
= _cupsStrAlloc(pwgtype
->pwg
);
4025 * media-*-margin-supported
4028 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, num_margins
= 0;
4029 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4032 for (j
= 0; j
< num_margins
; j
++)
4033 if (pwgsize
->bottom
== margins
[j
])
4036 if (j
>= num_margins
)
4038 margins
[num_margins
] = pwgsize
->bottom
;
4043 if (num_margins
> 0)
4044 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4045 "media-bottom-margin-supported", num_margins
, margins
);
4047 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4048 "media-bottom-margin-supported", 0);
4050 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, num_margins
= 0;
4051 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4054 for (j
= 0; j
< num_margins
; j
++)
4055 if (pwgsize
->left
== margins
[j
])
4058 if (j
>= num_margins
)
4060 margins
[num_margins
] = pwgsize
->left
;
4065 if (num_margins
> 0)
4066 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4067 "media-left-margin-supported", num_margins
, margins
);
4069 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4070 "media-left-margin-supported", 0);
4072 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, num_margins
= 0;
4073 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4076 for (j
= 0; j
< num_margins
; j
++)
4077 if (pwgsize
->right
== margins
[j
])
4080 if (j
>= num_margins
)
4082 margins
[num_margins
] = pwgsize
->right
;
4087 if (num_margins
> 0)
4088 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4089 "media-right-margin-supported", num_margins
, margins
);
4091 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4092 "media-right-margin-supported", 0);
4094 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, num_margins
= 0;
4095 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4098 for (j
= 0; j
< num_margins
; j
++)
4099 if (pwgsize
->top
== margins
[j
])
4102 if (j
>= num_margins
)
4104 margins
[num_margins
] = pwgsize
->top
;
4109 if (num_margins
> 0)
4110 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4111 "media-top-margin-supported", num_margins
, margins
);
4113 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4114 "media-top-margin-supported", 0);
4117 * media-col-database
4120 num_media
= p
->pc
->num_sizes
;
4121 if (p
->pc
->num_sources
)
4123 if (p
->pc
->num_types
> 0)
4124 num_media
+= p
->pc
->num_sizes
* p
->pc
->num_sources
*
4127 num_media
+= p
->pc
->num_sizes
* p
->pc
->num_sources
;
4129 else if (p
->pc
->num_types
)
4130 num_media
+= p
->pc
->num_sizes
* p
->pc
->num_types
;
4132 if ((attr
= ippAddCollections(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4133 "media-col-database", num_media
,
4136 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, val
= attr
->values
;
4141 * Start by adding the page size without source or type...
4144 ppdMarkOption(ppd
, "PageSize", pwgsize
->map
.ppd
);
4146 val
->collection
= new_media_col(pwgsize
, NULL
, NULL
);
4150 * Then add the specific, supported combinations of size, source, and
4154 if (p
->pc
->num_sources
> 0)
4156 for (j
= p
->pc
->num_sources
, pwgsource
= p
->pc
->sources
;
4160 ppdMarkOption(ppd
, "InputSlot", pwgsource
->ppd
);
4162 if (p
->pc
->num_types
> 0)
4164 for (k
= p
->pc
->num_types
, pwgtype
= p
->pc
->types
;
4168 if (!ppdMarkOption(ppd
, "MediaType", pwgtype
->ppd
))
4170 val
->collection
= new_media_col(pwgsize
, pwgsource
->pwg
,
4176 else if (!ppdConflicts(ppd
))
4178 val
->collection
= new_media_col(pwgsize
, pwgsource
->pwg
, NULL
);
4183 else if (p
->pc
->num_types
> 0)
4185 for (j
= p
->pc
->num_types
, pwgtype
= p
->pc
->types
;
4189 if (!ppdMarkOption(ppd
, "MediaType", pwgtype
->ppd
))
4191 val
->collection
= new_media_col(pwgsize
, NULL
, pwgtype
->pwg
);
4199 * Update the number of media-col-database values...
4202 attr
->num_values
= val
- attr
->values
;
4210 if (p
->pc
&& p
->pc
->num_bins
> 0)
4212 attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4213 "output-bin-supported", p
->pc
->num_bins
,
4218 for (i
= 0, val
= attr
->values
;
4219 i
< p
->pc
->num_bins
;
4221 val
->string
.text
= _cupsStrAlloc(p
->pc
->bins
[i
].pwg
);
4224 if ((output_bin
= ppdFindOption(ppd
, "OutputBin")) != NULL
)
4226 for (i
= 0; i
< p
->pc
->num_bins
; i
++)
4227 if (!strcmp(p
->pc
->bins
[i
].ppd
, output_bin
->defchoice
))
4230 if (i
>= p
->pc
->num_bins
)
4233 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4234 "output-bin-default", NULL
, p
->pc
->bins
[i
].pwg
);
4237 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4238 "output-bin-default", NULL
, p
->pc
->bins
[0].pwg
);
4240 else if (((ppd_attr
= ppdFindAttr(ppd
, "DefaultOutputOrder",
4242 !_cups_strcasecmp(ppd_attr
->value
, "Reverse")) ||
4243 (!ppd_attr
&& ppd
->manufacturer
&& /* "Compatibility heuristic" */
4244 (!_cups_strcasecmp(ppd
->manufacturer
, "epson") ||
4245 !_cups_strcasecmp(ppd
->manufacturer
, "lexmark"))))
4248 * Report that this printer has a single output bin that leaves pages face
4252 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4253 "output-bin-supported", NULL
, "face-up");
4254 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4255 "output-bin-default", NULL
, "face-up");
4259 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4260 "output-bin-supported", NULL
, "face-down");
4261 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4262 "output-bin-default", NULL
, "face-down");
4266 * print-color-mode...
4269 if (ppd
->color_device
)
4271 static const char * const color_modes
[] =
4277 ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4278 "print-color-mode-supported", 2, NULL
, color_modes
);
4279 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4280 "print-color-mode-default", NULL
, "color");
4284 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4285 "print-color-mode-supported", NULL
, "monochrome");
4286 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4287 "print-color-mode-default", NULL
, "monochrome");
4291 * Mandatory job attributes, if any...
4294 if (p
->pc
&& cupsArrayCount(p
->pc
->mandatory
) > 0)
4296 int count
= cupsArrayCount(p
->pc
->mandatory
);
4297 /* Number of mandatory attributes */
4299 attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4300 "printer-mandatory-job-attributes", count
, NULL
,
4303 for (val
= attr
->values
,
4304 mandatory
= (char *)cupsArrayFirst(p
->pc
->mandatory
);
4306 val
++, mandatory
= (char *)cupsArrayNext(p
->pc
->mandatory
))
4307 val
->string
.text
= _cupsStrAlloc(mandatory
);
4311 * Printer resolutions...
4314 if ((resolution
= ppdFindOption(ppd
, "Resolution")) == NULL
)
4315 if ((resolution
= ppdFindOption(ppd
, "JCLResolution")) == NULL
)
4316 if ((resolution
= ppdFindOption(ppd
, "SetResolution")) == NULL
)
4317 resolution
= ppdFindOption(ppd
, "CNRes_PGP");
4322 * Report all supported resolutions...
4325 attr
= ippAddResolutions(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4326 "printer-resolution-supported",
4327 resolution
->num_choices
, IPP_RES_PER_INCH
,
4330 for (i
= 0, choice
= resolution
->choices
;
4331 i
< resolution
->num_choices
;
4334 xdpi
= ydpi
= (int)strtol(choice
->choice
, (char **)&resptr
, 10);
4335 if (resptr
> choice
->choice
&& xdpi
> 0 && *resptr
== 'x')
4336 ydpi
= (int)strtol(resptr
+ 1, (char **)&resptr
, 10);
4338 if (xdpi
<= 0 || ydpi
<= 0)
4340 cupsdLogMessage(CUPSD_LOG_WARN
,
4341 "Bad resolution \"%s\" for printer %s.",
4342 choice
->choice
, p
->name
);
4346 attr
->values
[i
].resolution
.xres
= xdpi
;
4347 attr
->values
[i
].resolution
.yres
= ydpi
;
4348 attr
->values
[i
].resolution
.units
= IPP_RES_PER_INCH
;
4351 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4352 "printer-resolution-default", IPP_RES_PER_INCH
,
4356 else if ((ppd_attr
= ppdFindAttr(ppd
, "DefaultResolution", NULL
)) != NULL
&&
4360 * Just the DefaultResolution to report...
4363 xdpi
= ydpi
= (int)strtol(ppd_attr
->value
, (char **)&resptr
, 10);
4364 if (resptr
> ppd_attr
->value
&& xdpi
> 0)
4367 ydpi
= (int)strtol(resptr
+ 1, (char **)&resptr
, 10);
4372 if (xdpi
<= 0 || ydpi
<= 0)
4374 cupsdLogMessage(CUPSD_LOG_WARN
,
4375 "Bad default resolution \"%s\" for printer %s.",
4376 ppd_attr
->value
, p
->name
);
4380 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4381 "printer-resolution-default", IPP_RES_PER_INCH
,
4383 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4384 "printer-resolution-supported", IPP_RES_PER_INCH
,
4390 * No resolutions in PPD - make one up...
4393 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4394 "printer-resolution-default", IPP_RES_PER_INCH
,
4396 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4397 "printer-resolution-supported", IPP_RES_PER_INCH
,
4405 ppdMarkDefaults(ppd
);
4407 if ((duplex
= ppdFindOption(ppd
, "Duplex")) == NULL
)
4408 if ((duplex
= ppdFindOption(ppd
, "EFDuplex")) == NULL
)
4409 if ((duplex
= ppdFindOption(ppd
, "EFDuplexing")) == NULL
)
4410 if ((duplex
= ppdFindOption(ppd
, "KD03Duplex")) == NULL
)
4411 duplex
= ppdFindOption(ppd
, "JCLDuplex");
4413 if (duplex
&& duplex
->num_choices
> 1 &&
4414 !ppdInstallableConflict(ppd
, duplex
->keyword
, "DuplexTumble"))
4416 p
->type
|= CUPS_PRINTER_DUPLEX
;
4418 ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4419 "sides-supported", 3, NULL
, sides
);
4421 if (!_cups_strcasecmp(duplex
->defchoice
, "DuplexTumble"))
4422 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4423 "sides-default", NULL
, "two-sided-short-edge");
4424 else if (!_cups_strcasecmp(duplex
->defchoice
, "DuplexNoTumble"))
4425 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4426 "sides-default", NULL
, "two-sided-long-edge");
4428 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4429 "sides-default", NULL
, "one-sided");
4433 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4434 "sides-supported", NULL
, "one-sided");
4435 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4436 "sides-default", NULL
, "one-sided");
4439 if (ppdFindOption(ppd
, "Collate") != NULL
)
4440 p
->type
|= CUPS_PRINTER_COLLATE
;
4442 if (ppdFindOption(ppd
, "StapleLocation") != NULL
)
4444 p
->type
|= CUPS_PRINTER_STAPLE
;
4445 finishings
[num_finishings
++] = IPP_FINISHINGS_STAPLE
;
4448 if (ppdFindOption(ppd
, "BindEdge") != NULL
)
4450 p
->type
|= CUPS_PRINTER_BIND
;
4451 finishings
[num_finishings
++] = IPP_FINISHINGS_BIND
;
4454 for (i
= 0; i
< ppd
->num_sizes
; i
++)
4455 if (ppd
->sizes
[i
].length
> 1728)
4456 p
->type
|= CUPS_PRINTER_LARGE
;
4457 else if (ppd
->sizes
[i
].length
> 1008)
4458 p
->type
|= CUPS_PRINTER_MEDIUM
;
4460 p
->type
|= CUPS_PRINTER_SMALL
;
4462 if ((ppd_attr
= ppdFindAttr(ppd
, "APICADriver", NULL
)) != NULL
&&
4463 ppd_attr
->value
&& !_cups_strcasecmp(ppd_attr
->value
, "true"))
4465 if ((ppd_attr
= ppdFindAttr(ppd
, "APScannerOnly", NULL
)) != NULL
&&
4466 ppd_attr
->value
&& !_cups_strcasecmp(ppd_attr
->value
, "true"))
4467 p
->type
|= CUPS_PRINTER_SCANNER
;
4469 p
->type
|= CUPS_PRINTER_MFP
;
4473 * Scan the filters in the PPD file...
4478 for (filter
= (const char *)cupsArrayFirst(p
->pc
->filters
);
4480 filter
= (const char *)cupsArrayNext(p
->pc
->filters
))
4482 if (!_cups_strncasecmp(filter
, "application/vnd.cups-command", 28) &&
4483 _cups_isspace(filter
[28]))
4485 p
->type
|= CUPS_PRINTER_COMMANDS
;
4491 if (p
->type
& CUPS_PRINTER_COMMANDS
)
4493 char *commands
, /* Copy of commands */
4494 *start
, /* Start of name */
4495 *end
; /* End of name */
4496 int count
; /* Number of commands */
4498 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsCommands", NULL
)) != NULL
)
4500 for (count
= 0, start
= ppd_attr
->value
; *start
; count
++)
4502 while (_cups_isspace(*start
))
4508 while (*start
&& !isspace(*start
& 255))
4518 * Make a copy of the commands string and count how many commands there
4522 attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4523 "printer-commands", count
, NULL
, NULL
);
4525 commands
= strdup(ppd_attr
->value
);
4527 for (count
= 0, start
= commands
; *start
; count
++)
4529 while (isspace(*start
& 255))
4536 while (*end
&& !isspace(*end
& 255))
4542 attr
->values
[count
].string
.text
= _cupsStrAlloc(start
);
4552 * Add the standard list of commands...
4555 ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4557 (int)(sizeof(standard_commands
) /
4558 sizeof(standard_commands
[0])), NULL
,
4565 * No commands supported...
4568 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4569 "printer-commands", NULL
, "none");
4573 * Show current and available port monitors for this printer...
4576 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
, "port-monitor",
4577 NULL
, p
->port_monitor
? p
->port_monitor
: "none");
4579 for (i
= 1, ppd_attr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
4581 i
++, ppd_attr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
));
4585 if (strstr(ppd
->protocols
, "TBCP"))
4587 else if (strstr(ppd
->protocols
, "BCP"))
4591 attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
4592 "port-monitor-supported", i
, NULL
, NULL
);
4594 attr
->values
[0].string
.text
= _cupsStrAlloc("none");
4596 for (i
= 1, ppd_attr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
4598 i
++, ppd_attr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
))
4599 attr
->values
[i
].string
.text
= _cupsStrAlloc(ppd_attr
->value
);
4603 if (strstr(ppd
->protocols
, "TBCP"))
4604 attr
->values
[i
].string
.text
= _cupsStrAlloc("tbcp");
4605 else if (strstr(ppd
->protocols
, "BCP"))
4606 attr
->values
[i
].string
.text
= _cupsStrAlloc("bcp");
4609 if (ppdFindAttr(ppd
, "APRemoteQueueID", NULL
))
4610 p
->type
|= CUPS_PRINTER_REMOTE
;
4612 #ifdef HAVE_APPLICATIONSERVICES_H
4614 * Convert the file referenced in APPrinterIconPath to a 128x128 PNG
4615 * and save it as cacheDir/printername.png
4618 if ((ppd_attr
= ppdFindAttr(ppd
, "APPrinterIconPath", NULL
)) != NULL
&&
4620 !_cupsFileCheck(ppd_attr
->value
, _CUPS_FILE_CHECK_FILE
, !RunUser
,
4621 cupsdLogFCMessage
, p
))
4623 CGImageRef imageRef
= NULL
;/* Current icon image */
4624 CGImageRef biggestIconRef
= NULL
;
4625 /* Biggest icon image */
4626 CGImageRef closestTo128IconRef
= NULL
;
4627 /* Icon image closest to and >= 128 */
4628 CGImageSourceRef sourceRef
; /* The file's image source */
4629 char outPath
[HTTP_MAX_URI
];
4630 /* The path to the PNG file */
4631 CFURLRef outUrl
; /* The URL made from the outPath */
4632 CFURLRef icnsFileUrl
; /* The URL of the original ICNS icon file */
4633 CGImageDestinationRef destRef
; /* The image destination to write */
4634 size_t bytesPerRow
; /* The bytes per row used for resizing */
4635 CGContextRef context
; /* The CG context used for resizing */
4637 snprintf(outPath
, sizeof(outPath
), "%s/%s.png", CacheDir
, p
->name
);
4638 outUrl
= CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault
,
4642 icnsFileUrl
= CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault
,
4643 (UInt8
*)ppd_attr
->value
,
4644 strlen(ppd_attr
->value
),
4646 if (outUrl
&& icnsFileUrl
)
4648 sourceRef
= CGImageSourceCreateWithURL(icnsFileUrl
, NULL
);
4651 for (i
= 0; i
< CGImageSourceGetCount(sourceRef
); i
++)
4653 imageRef
= CGImageSourceCreateImageAtIndex(sourceRef
, i
, NULL
);
4657 if (CGImageGetWidth(imageRef
) == CGImageGetHeight(imageRef
))
4660 * Loop through remembering the icon closest to 128 but >= 128
4661 * and then remember the largest icon.
4664 if (CGImageGetWidth(imageRef
) >= 128 &&
4665 (!closestTo128IconRef
||
4666 CGImageGetWidth(imageRef
) <
4667 CGImageGetWidth(closestTo128IconRef
)))
4669 CGImageRelease(closestTo128IconRef
);
4670 CGImageRetain(imageRef
);
4671 closestTo128IconRef
= imageRef
;
4674 if (!biggestIconRef
||
4675 CGImageGetWidth(imageRef
) > CGImageGetWidth(biggestIconRef
))
4677 CGImageRelease(biggestIconRef
);
4678 CGImageRetain(imageRef
);
4679 biggestIconRef
= imageRef
;
4683 CGImageRelease(imageRef
);
4689 * If biggestIconRef is NULL, we found no icons. Otherwise we first
4690 * want the closest to 128, but if none are larger than 128, we want
4691 * the largest icon available.
4694 imageRef
= closestTo128IconRef
? closestTo128IconRef
:
4696 CGImageRetain(imageRef
);
4697 CGImageRelease(biggestIconRef
);
4698 if (closestTo128IconRef
)
4699 CGImageRelease(closestTo128IconRef
);
4700 destRef
= CGImageDestinationCreateWithURL(outUrl
, kUTTypePNG
, 1,
4704 if (CGImageGetWidth(imageRef
) != 128)
4706 bytesPerRow
= CGImageGetBytesPerRow(imageRef
) /
4707 CGImageGetWidth(imageRef
) * 128;
4708 context
= CGBitmapContextCreate(NULL
, 128, 128,
4709 CGImageGetBitsPerComponent(imageRef
),
4711 CGImageGetColorSpace(imageRef
),
4712 kCGImageAlphaPremultipliedFirst
);
4715 CGContextDrawImage(context
, CGRectMake(0, 0, 128, 128),
4717 CGImageRelease(imageRef
);
4718 imageRef
= CGBitmapContextCreateImage(context
);
4719 CGContextRelease(context
);
4723 CGImageDestinationAddImage(destRef
, imageRef
, NULL
);
4724 CGImageDestinationFinalize(destRef
);
4728 CGImageRelease(imageRef
);
4731 CFRelease(sourceRef
);
4739 CFRelease(icnsFileUrl
);
4741 #endif /* HAVE_APPLICATIONSERVICES_H */
4744 * Close the PPD and set the type...
4749 else if (!access(ppd_name
, 0))
4751 int pline
; /* PPD line number */
4752 ppd_status_t pstatus
; /* PPD load status */
4755 pstatus
= ppdLastError(&pline
);
4757 cupsdLogMessage(CUPSD_LOG_ERROR
, "PPD file for %s cannot be loaded!",
4760 if (pstatus
<= PPD_ALLOC_ERROR
)
4761 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s", strerror(errno
));
4763 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s on line %d.",
4764 ppdErrorString(pstatus
), pline
);
4766 cupsdLogMessage(CUPSD_LOG_INFO
,
4767 "Hint: Run \"cupstestppd %s\" and fix any errors.",
4773 * If we have an interface script, add a filter entry for it...
4776 char interface
[1024]; /* Interface script */
4779 snprintf(interface
, sizeof(interface
), "%s/interfaces/%s", ServerRoot
,
4781 if (!access(interface
, X_OK
))
4784 * Yes, we have a System V style interface script; use it!
4787 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
4788 "printer-make-and-model", NULL
,
4789 "Local System V Printer");
4791 else if (((!strncmp(p
->device_uri
, "ipp://", 6) ||
4792 !strncmp(p
->device_uri
, "ipps://", 7)) &&
4793 (strstr(p
->device_uri
, "/printers/") != NULL
||
4794 strstr(p
->device_uri
, "/classes/") != NULL
)) ||
4795 ((strstr(p
->device_uri
, "._ipp.") != NULL
||
4796 strstr(p
->device_uri
, "._ipps.") != NULL
) &&
4797 !strcmp(p
->device_uri
+ strlen(p
->device_uri
) - 5, "/cups")))
4800 * Tell the client this is really a hard-wired remote printer.
4803 p
->type
|= CUPS_PRINTER_REMOTE
;
4806 * Point the printer-uri-supported attribute to the
4810 if (strchr(p
->device_uri
, '?'))
4813 * Strip trailing "?options" from URI...
4816 char resource
[HTTP_MAX_URI
], /* New URI */
4817 *ptr
; /* Pointer into URI */
4819 strlcpy(resource
, p
->device_uri
, sizeof(resource
));
4820 if ((ptr
= strchr(resource
, '?')) != NULL
)
4823 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
4824 "printer-uri-supported", NULL
, resource
);
4827 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
4828 "printer-uri-supported", NULL
, p
->device_uri
);
4831 * Then set the make-and-model accordingly...
4834 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
4835 "printer-make-and-model", NULL
, "Remote Printer");
4838 * Print all files directly...
4847 * Otherwise we have neither - treat this as a "dumb" printer
4848 * with no PPD file...
4851 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
4852 "printer-make-and-model", NULL
, "Local Raw Printer");
4858 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
4859 "finishings-supported", num_finishings
, finishings
);
4860 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
4861 "finishings-default", IPP_FINISHINGS_NONE
);
4866 * Save cached PPD attributes to disk...
4869 cupsdLogMessage(CUPSD_LOG_DEBUG
, "load_ppd: Saving %s...", cache_name
);
4871 _ppdCacheWriteFile(p
->pc
, cache_name
, p
->ppd_attrs
);
4876 * Remove cache files...
4879 if (cache_info
.st_mtime
)
4886 * 'log_ipp_conformance()' - Log an IPP conformance issue with a printer.
4890 log_ipp_conformance(
4891 cupsd_printer_t
*p
, /* I - Printer */
4892 const char *reason
) /* I - Printer state reason */
4894 const char *message
; /* Message to log */
4896 aslmsg aslm
; /* Apple System Log message */
4897 #endif /* __APPLE__ */
4901 * Strip the leading "cups-ipp-" from the reason and create a log message for
4906 if (!strcmp(reason
, "missing-cancel-job"))
4907 message
= "Printer does not support REQUIRED Cancel-Job operation.";
4908 else if (!strcmp(reason
, "missing-get-job-attributes"))
4909 message
= "Printer does not support REQUIRED Get-Job-Attributes operation.";
4910 else if (!strcmp(reason
, "missing-print-job"))
4911 message
= "Printer does not support REQUIRED Print-Job operation.";
4912 else if (!strcmp(reason
, "missing-validate-job"))
4913 message
= "Printer does not support REQUIRED Validate-Job operation.";
4914 else if (!strcmp(reason
, "missing-get-printer-attributes"))
4915 message
= "Printer does not support REQUIRED Get-Printer-Attributes operation.";
4916 else if (!strcmp(reason
, "missing-send-document"))
4917 message
= "Printer supports Create-Job but not Send-Document operation.";
4918 else if (!strcmp(reason
, "missing-job-history"))
4919 message
= "Printer does not provide REQUIRED job history.";
4920 else if (!strcmp(reason
, "missing-job-id"))
4921 message
= "Printer does not provide REQUIRED job-id attribute.";
4922 else if (!strcmp(reason
, "missing-job-state"))
4923 message
= "Printer does not provide REQUIRED job-state attribute.";
4924 else if (!strcmp(reason
, "missing-operations-supported"))
4925 message
= "Printer does not provide REQUIRED operations-supported "
4927 else if (!strcmp(reason
, "missing-printer-is-accepting-jobs"))
4928 message
= "Printer does not provide REQUIRED printer-is-accepting-jobs "
4930 else if (!strcmp(reason
, "missing-printer-state-reasons"))
4931 message
= "Printer does not provide REQUIRED printer-state-reasons "
4933 else if (!strcmp(reason
, "wrong-http-version"))
4934 message
= "Printer does not use REQUIRED HTTP/1.1 transport.";
4936 message
= "Unknown IPP conformance failure.";
4938 cupsdLogMessage(CUPSD_LOG_WARN
, "%s: %s", p
->name
, message
);
4942 * Report the failure information to Apple if the user opts into providing
4943 * feedback to Apple...
4946 aslm
= asl_new(ASL_TYPE_MSG
);
4949 asl_set(aslm
, "com.apple.message.domain", "com.apple.printing.ipp.conformance");
4950 asl_set(aslm
, "com.apple.message.domain_scope", "com.apple.printing.ipp.conformance");
4951 asl_set(aslm
, "com.apple.message.signature", reason
);
4952 asl_set(aslm
, "com.apple.message.signature2",
4953 p
->make_model
? p
->make_model
: "Unknown");
4954 asl_log(NULL
, aslm
, ASL_LEVEL_NOTICE
, "%s: %s",
4955 p
->make_model
? p
->make_model
: "Unknown", message
);
4958 #endif /* __APPLE__ */
4963 * 'new_media_col()' - Create a media-col collection value.
4966 static ipp_t
* /* O - Collection value */
4967 new_media_col(_pwg_size_t
*size
, /* I - media-size/margin values */
4968 const char *source
, /* I - media-source value */
4969 const char *type
) /* I - media-type value */
4971 ipp_t
*media_col
, /* Collection value */
4972 *media_size
; /* media-size value */
4975 media_col
= ippNew();
4977 media_size
= ippNew();
4978 ippAddInteger(media_size
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4979 "x-dimension", size
->width
);
4980 ippAddInteger(media_size
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4981 "y-dimension", size
->length
);
4982 ippAddCollection(media_col
, IPP_TAG_PRINTER
, "media-size", media_size
);
4983 ippDelete(media_size
);
4985 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4986 "media-bottom-margin", size
->bottom
);
4987 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4988 "media-left-margin", size
->left
);
4989 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4990 "media-right-margin", size
->right
);
4991 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4992 "media-top-margin", size
->top
);
4995 ippAddString(media_col
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
, "media-source",
4999 ippAddString(media_col
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
, "media-type",
5007 * 'write_xml_string()' - Write a string with XML escaping.
5011 write_xml_string(cups_file_t
*fp
, /* I - File to write to */
5012 const char *s
) /* I - String to write */
5014 const char *start
; /* Start of current sequence */
5020 for (start
= s
; *s
; s
++)
5025 cupsFileWrite(fp
, start
, s
- start
);
5027 cupsFilePuts(fp
, "&");
5033 cupsFileWrite(fp
, start
, s
- start
);
5035 cupsFilePuts(fp
, "<");
5041 cupsFilePuts(fp
, start
);