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 * Include necessary headers...
22 #ifdef HAVE_APPLICATIONSERVICES_H
23 # include <ApplicationServices/ApplicationServices.h>
24 #endif /* HAVE_APPLICATIONSERVICES_H */
25 #ifdef HAVE_SYS_MOUNT_H
26 # include <sys/mount.h>
27 #endif /* HAVE_SYS_MOUNT_H */
28 #ifdef HAVE_SYS_STATVFS_H
29 # include <sys/statvfs.h>
30 #elif defined(HAVE_SYS_STATFS_H)
31 # include <sys/statfs.h>
32 #endif /* HAVE_SYS_STATVFS_H */
35 #endif /* HAVE_SYS_VFS_H */
38 #endif /* __APPLE__ */
45 static void add_printer_defaults(cupsd_printer_t
*p
);
46 static void add_printer_filter(cupsd_printer_t
*p
, mime_type_t
*type
,
48 static void add_printer_formats(cupsd_printer_t
*p
);
49 static int compare_printers(void *first
, void *second
, void *data
);
50 static void delete_printer_filters(cupsd_printer_t
*p
);
51 static void dirty_printer(cupsd_printer_t
*p
);
52 static void load_ppd(cupsd_printer_t
*p
);
53 static void log_ipp_conformance(cupsd_printer_t
*p
, const char *reason
);
54 static ipp_t
*new_media_col(_pwg_size_t
*size
, const char *source
,
56 static void write_xml_string(cups_file_t
*fp
, const char *s
);
60 * 'cupsdAddPrinter()' - Add a printer to the system.
63 cupsd_printer_t
* /* O - New printer */
64 cupsdAddPrinter(const char *name
) /* I - Name of printer */
66 cupsd_printer_t
*p
; /* New printer */
67 char uri
[1024], /* Printer URI */
68 uuid
[64]; /* Printer UUID */
72 * Range check input...
75 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdAddPrinter(\"%s\")", name
);
78 * Create a new printer entity...
81 if ((p
= calloc(1, sizeof(cupsd_printer_t
))) == NULL
)
83 cupsdLogMessage(CUPSD_LOG_CRIT
, "Unable to allocate memory for printer - %s",
88 cupsdSetString(&p
->name
, name
);
89 cupsdSetString(&p
->info
, name
);
90 cupsdSetString(&p
->hostname
, ServerName
);
92 httpAssembleURIf(HTTP_URI_CODING_ALL
, uri
, sizeof(uri
), "ipp", NULL
,
93 ServerName
, RemotePort
, "/printers/%s", name
);
94 cupsdSetString(&p
->uri
, uri
);
95 cupsdSetString(&p
->uuid
, _httpAssembleUUID(ServerName
, RemotePort
, name
, 0,
97 cupsdSetDeviceURI(p
, "file:///dev/null");
99 p
->state
= IPP_PRINTER_STOPPED
;
100 p
->state_time
= time(NULL
);
102 p
->shared
= DefaultShared
;
103 p
->filetype
= mimeAddType(MimeDatabase
, "printer", name
);
105 cupsdSetString(&p
->job_sheets
[0], "none");
106 cupsdSetString(&p
->job_sheets
[1], "none");
108 cupsdSetString(&p
->error_policy
, ErrorPolicy
);
109 cupsdSetString(&p
->op_policy
, DefaultPolicy
);
111 p
->op_policy_ptr
= DefaultPolicyPtr
;
114 * Insert the printer in the printer list alphabetically...
118 Printers
= cupsArrayNew(compare_printers
, NULL
);
120 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
121 "cupsdAddPrinter: Adding %s to Printers", p
->name
);
122 cupsArrayAdd(Printers
, p
);
125 * Return the new printer...
133 * 'cupsdCreateCommonData()' - Create the common printer data.
137 cupsdCreateCommonData(void)
139 int i
; /* Looping var */
140 ipp_attribute_t
*attr
; /* Attribute data */
141 cups_dir_t
*dir
; /* Notifier directory */
142 cups_dentry_t
*dent
; /* Notifier directory entry */
143 cups_array_t
*notifiers
; /* Notifier array */
144 char filename
[1024], /* Filename */
145 *notifier
; /* Current notifier */
146 cupsd_policy_t
*p
; /* Current policy */
147 int k_supported
; /* Maximum file size supported */
149 struct statvfs spoolinfo
; /* FS info for spool directory */
150 double spoolsize
; /* FS size */
151 #elif defined(HAVE_STATFS)
152 struct statfs spoolinfo
; /* FS info for spool directory */
153 double spoolsize
; /* FS size */
154 #endif /* HAVE_STATVFS */
155 static const int nups
[] = /* number-up-supported values */
156 { 1, 2, 4, 6, 9, 16 };
157 static const int orients
[4] =/* orientation-requested-supported values */
161 IPP_REVERSE_LANDSCAPE
,
164 static const char * const holds
[] = /* job-hold-until-supported values */
175 static const char * const versions
[] =/* ipp-versions-supported values */
182 static const int ops
[] = /* operations-supported values */
189 IPP_GET_JOB_ATTRIBUTES
,
191 IPP_GET_PRINTER_ATTRIBUTES
,
198 IPP_SET_PRINTER_ATTRIBUTES
,
199 IPP_SET_JOB_ATTRIBUTES
,
200 IPP_GET_PRINTER_SUPPORTED_VALUES
,
201 IPP_CREATE_PRINTER_SUBSCRIPTION
,
202 IPP_CREATE_JOB_SUBSCRIPTION
,
203 IPP_GET_SUBSCRIPTION_ATTRIBUTES
,
204 IPP_GET_SUBSCRIPTIONS
,
205 IPP_RENEW_SUBSCRIPTION
,
206 IPP_CANCEL_SUBSCRIPTION
,
207 IPP_GET_NOTIFICATIONS
,
211 IPP_RELEASE_HELD_NEW_JOBS
,
228 CUPS_AUTHENTICATE_JOB
,
233 static const char * const charsets
[] =/* charset-supported values */
238 static const char * const compressions
[] =
239 { /* document-compression-supported values */
243 #endif /* HAVE_LIBZ */
245 static const char * const media_col_supported
[] =
246 { /* media-col-supported values */
247 "media-bottom-margin",
249 "media-right-margin",
255 static const char * const multiple_document_handling
[] =
256 { /* multiple-document-handling-supported values */
257 "separate-documents-uncollated-copies",
258 "separate-documents-collated-copies"
260 static const char * const notify_attrs
[] =
261 { /* notify-attributes-supported values */
262 "printer-state-change-time",
263 "notify-lease-expiration-time",
264 "notify-subscriber-user-name"
266 static const char * const notify_events
[] =
267 { /* notify-events-supported values */
269 "job-config-changed",
276 "printer-config-changed",
278 "printer-finishings-changed",
279 "printer-media-changed",
283 "printer-state-changed",
290 static const char * const job_creation
[] =
291 { /* job-creation-attributes-supported */
294 "ipp-attribute-fidelity",
301 "multiple-document-handling",
304 "orientation-requested",
308 "printer-resolution",
311 static const char * const job_settable
[] =
312 { /* job-settable-attributes-supported */
320 "multiple-document-handling",
323 "orientation-requested",
327 "printer-resolution",
330 static const char * const pdf_versions
[] =
331 { /* pdf-versions-supported */
342 static const char * const printer_settable
[] =
343 { /* printer-settable-attributes-supported */
347 static const char * const which_jobs
[] =
348 { /* which-jobs-supported values */
362 ippDelete(CommonData
);
364 CommonData
= ippNew();
367 * Get the maximum spool size based on the size of the filesystem used for
368 * the RequestRoot directory. If the host OS doesn't support the statfs call
369 * or the filesystem is larger than 2TiB, always report INT_MAX.
373 if (statvfs(RequestRoot
, &spoolinfo
))
374 k_supported
= INT_MAX
;
375 else if ((spoolsize
= (double)spoolinfo
.f_frsize
* spoolinfo
.f_blocks
/ 1024) >
377 k_supported
= INT_MAX
;
379 k_supported
= (int)spoolsize
;
381 #elif defined(HAVE_STATFS)
382 if (statfs(RequestRoot
, &spoolinfo
))
383 k_supported
= INT_MAX
;
384 else if ((spoolsize
= (double)spoolinfo
.f_bsize
* spoolinfo
.f_blocks
/ 1024) >
386 k_supported
= INT_MAX
;
388 k_supported
= (int)spoolsize
;
391 k_supported
= INT_MAX
;
392 #endif /* HAVE_STATVFS */
395 * This list of attributes is sorted to improve performance when the
396 * client provides a requested-attributes attribute...
399 /* charset-configured */
400 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_CHARSET
| IPP_TAG_COPY
,
401 "charset-configured", NULL
, "utf-8");
403 /* charset-supported */
404 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_CHARSET
| IPP_TAG_COPY
,
405 "charset-supported", sizeof(charsets
) / sizeof(charsets
[0]),
408 /* compression-supported */
409 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
410 "compression-supported",
411 sizeof(compressions
) / sizeof(compressions
[0]),
414 /* copies-supported */
415 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "copies-supported", 1, MaxCopies
);
418 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
| IPP_TAG_COPY
,
419 "cups-version", NULL
, CUPS_SVERSION
+ 6);
421 /* generated-natural-language-supported (no IPP_TAG_COPY) */
422 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_LANGUAGE
,
423 "generated-natural-language-supported", NULL
, DefaultLanguage
);
425 /* ipp-versions-supported */
426 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
427 "ipp-versions-supported", sizeof(versions
) / sizeof(versions
[0]),
430 /* ippget-event-life */
431 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
432 "ippget-event-life", 15);
434 /* job-creation-attributes-supported */
435 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
436 "job-creation-attributes-supported",
437 sizeof(job_creation
) / sizeof(job_creation
[0]),
440 /* job-hold-until-supported */
441 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
442 "job-hold-until-supported", sizeof(holds
) / sizeof(holds
[0]),
445 /* job-ids-supported */
446 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
, "job-ids-supported", 1);
448 /* job-k-octets-supported */
449 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "job-k-octets-supported", 0,
452 /* job-priority-supported */
453 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
454 "job-priority-supported", 100);
456 /* job-settable-attributes-supported */
457 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
458 "job-settable-attributes-supported",
459 sizeof(job_settable
) / sizeof(job_settable
[0]),
462 /* job-sheets-supported */
463 if (cupsArrayCount(Banners
) > 0)
466 * Setup the job-sheets-supported attribute...
469 if (Classification
&& !ClassifyOverride
)
470 attr
= ippAddString(CommonData
, IPP_TAG_PRINTER
,
471 IPP_TAG_NAME
| IPP_TAG_COPY
,
472 "job-sheets-supported", NULL
, Classification
);
474 attr
= ippAddStrings(CommonData
, IPP_TAG_PRINTER
,
475 IPP_TAG_NAME
| IPP_TAG_COPY
,
476 "job-sheets-supported", cupsArrayCount(Banners
) + 1,
480 cupsdLogMessage(CUPSD_LOG_EMERG
,
481 "Unable to allocate memory for "
482 "job-sheets-supported attribute: %s!", strerror(errno
));
483 else if (!Classification
|| ClassifyOverride
)
485 cupsd_banner_t
*banner
; /* Current banner */
488 attr
->values
[0].string
.text
= _cupsStrAlloc("none");
490 for (i
= 1, banner
= (cupsd_banner_t
*)cupsArrayFirst(Banners
);
492 i
++, banner
= (cupsd_banner_t
*)cupsArrayNext(Banners
))
493 attr
->values
[i
].string
.text
= banner
->name
;
497 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
498 "job-sheets-supported", NULL
, "none");
500 /* jpeg-k-octets-supported */
501 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "jpeg-k-octets-supported", 0,
504 /* jpeg-x-dimension-supported */
505 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "jpeg-x-dimension-supported", 0,
508 /* jpeg-y-dimension-supported */
509 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "jpeg-y-dimension-supported", 1,
512 /* media-col-supported */
513 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
514 "media-col-supported",
515 sizeof(media_col_supported
) /
516 sizeof(media_col_supported
[0]), NULL
,
517 media_col_supported
);
519 /* multiple-document-handling-supported */
520 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
521 "multiple-document-handling-supported",
522 sizeof(multiple_document_handling
) /
523 sizeof(multiple_document_handling
[0]), NULL
,
524 multiple_document_handling
);
526 /* multiple-document-jobs-supported */
527 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
,
528 "multiple-document-jobs-supported", 1);
530 /* multiple-operation-time-out */
531 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
532 "multiple-operation-time-out", MultipleOperationTimeout
);
534 /* natural-language-configured (no IPP_TAG_COPY) */
535 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_LANGUAGE
,
536 "natural-language-configured", NULL
, DefaultLanguage
);
538 /* notify-attributes-supported */
539 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
540 "notify-attributes-supported",
541 (int)(sizeof(notify_attrs
) / sizeof(notify_attrs
[0])),
544 /* notify-lease-duration-supported */
545 ippAddRange(CommonData
, IPP_TAG_PRINTER
,
546 "notify-lease-duration-supported", 0,
547 MaxLeaseDuration
? MaxLeaseDuration
: 2147483647);
549 /* notify-max-events-supported */
550 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
551 "notify-max-events-supported", MaxEvents
);
553 /* notify-events-supported */
554 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
555 "notify-events-supported",
556 (int)(sizeof(notify_events
) / sizeof(notify_events
[0])),
557 NULL
, notify_events
);
559 /* notify-pull-method-supported */
560 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
561 "notify-pull-method-supported", NULL
, "ippget");
563 /* notify-schemes-supported */
564 snprintf(filename
, sizeof(filename
), "%s/notifier", ServerBin
);
565 if ((dir
= cupsDirOpen(filename
)) != NULL
)
567 notifiers
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
569 while ((dent
= cupsDirRead(dir
)) != NULL
)
570 if (S_ISREG(dent
->fileinfo
.st_mode
) &&
571 (dent
->fileinfo
.st_mode
& S_IXOTH
) != 0)
572 cupsArrayAdd(notifiers
, _cupsStrAlloc(dent
->filename
));
574 if (cupsArrayCount(notifiers
) > 0)
576 attr
= ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
577 "notify-schemes-supported",
578 cupsArrayCount(notifiers
), NULL
, NULL
);
580 for (i
= 0, notifier
= (char *)cupsArrayFirst(notifiers
);
582 i
++, notifier
= (char *)cupsArrayNext(notifiers
))
583 attr
->values
[i
].string
.text
= notifier
;
586 cupsArrayDelete(notifiers
);
590 /* number-up-supported */
591 ippAddIntegers(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
592 "number-up-supported", sizeof(nups
) / sizeof(nups
[0]), nups
);
594 /* operations-supported */
595 ippAddIntegers(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
596 "operations-supported", sizeof(ops
) / sizeof(ops
[0]), ops
);
598 /* orientation-requested-supported */
599 ippAddIntegers(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
600 "orientation-requested-supported", 4, orients
);
602 /* page-ranges-supported */
603 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
, "page-ranges-supported", 1);
605 /* pdf-k-octets-supported */
606 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "pdf-k-octets-supported", 0,
609 /* pdf-versions-supported */
610 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
611 "pdf-versions-supported",
612 sizeof(pdf_versions
) / sizeof(pdf_versions
[0]), NULL
,
615 /* pdl-override-supported */
616 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
617 "pdl-override-supported", NULL
, "attempted");
619 /* printer-op-policy-supported */
620 attr
= ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
621 "printer-op-policy-supported", cupsArrayCount(Policies
),
623 for (i
= 0, p
= (cupsd_policy_t
*)cupsArrayFirst(Policies
);
625 i
++, p
= (cupsd_policy_t
*)cupsArrayNext(Policies
))
626 attr
->values
[i
].string
.text
= p
->name
;
628 /* printer-settable-attributes-supported */
629 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
630 "printer-settable-attributes-supported",
631 sizeof(printer_settable
) / sizeof(printer_settable
[0]),
632 NULL
, printer_settable
);
634 /* server-is-sharing-printers */
635 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
, "server-is-sharing-printers",
636 BrowseLocalProtocols
!= 0 && Browsing
);
638 /* which-jobs-supported */
639 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
640 "which-jobs-supported",
641 sizeof(which_jobs
) / sizeof(which_jobs
[0]), NULL
, which_jobs
);
646 * 'cupsdDeleteAllPrinters()' - Delete all printers from the system.
650 cupsdDeleteAllPrinters(void)
652 cupsd_printer_t
*p
; /* Pointer to current printer/class */
655 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
657 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
659 p
->op_policy_ptr
= DefaultPolicyPtr
;
660 cupsdDeletePrinter(p
, 0);
666 * 'cupsdDeletePrinter()' - Delete a printer from the system.
669 int /* O - 1 if classes affected, 0 otherwise */
671 cupsd_printer_t
*p
, /* I - Printer to delete */
672 int update
) /* I - Update printers.conf? */
674 int i
, /* Looping var */
675 changed
= 0; /* Class changed? */
678 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdDeletePrinter(p=%p(%s), update=%d)",
682 * Save the current position in the Printers array...
685 cupsArraySave(Printers
);
688 * Stop printing on this printer...
691 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, update
);
693 p
->state
= IPP_PRINTER_STOPPED
; /* Force for browsed printers */
696 cupsdSetJobState(p
->job
, IPP_JOB_PENDING
, CUPSD_JOB_FORCE
,
697 update
? "Job stopped due to printer being deleted." :
701 * Remove the printer from the list...
704 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
705 "cupsdDeletePrinter: Removing %s from Printers", p
->name
);
706 cupsArrayRemove(Printers
, p
);
709 * If p is the default printer, assign a different one...
712 if (p
== DefaultPrinter
)
713 DefaultPrinter
= NULL
;
716 * Remove this printer from any classes...
719 changed
= cupsdDeletePrinterFromClasses(p
);
722 * Deregister from any browse protocols...
725 cupsdDeregisterPrinter(p
, 1);
728 * Free all memory used by the printer...
731 if (p
->printers
!= NULL
)
734 delete_printer_filters(p
);
736 for (i
= 0; i
< p
->num_reasons
; i
++)
737 _cupsStrFree(p
->reasons
[i
]);
740 ippDelete(p
->ppd_attrs
);
742 mimeDeleteType(MimeDatabase
, p
->filetype
);
743 mimeDeleteType(MimeDatabase
, p
->prefiltertype
);
745 cupsdFreeStrings(&(p
->users
));
748 cupsdClearString(&p
->uri
);
749 cupsdClearString(&p
->hostname
);
750 cupsdClearString(&p
->name
);
751 cupsdClearString(&p
->location
);
752 cupsdClearString(&p
->make_model
);
753 cupsdClearString(&p
->info
);
754 cupsdClearString(&p
->job_sheets
[0]);
755 cupsdClearString(&p
->job_sheets
[1]);
756 cupsdClearString(&p
->device_uri
);
757 cupsdClearString(&p
->sanitized_device_uri
);
758 cupsdClearString(&p
->port_monitor
);
759 cupsdClearString(&p
->op_policy
);
760 cupsdClearString(&p
->error_policy
);
762 cupsdClearString(&p
->alert
);
763 cupsdClearString(&p
->alert_description
);
765 #if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
766 cupsdClearString(&p
->pdl
);
767 cupsdClearString(&p
->reg_name
);
768 #endif /* HAVE_DNSSD || HAVE_AVAHI */
770 cupsArrayDelete(p
->filetypes
);
772 cupsFreeOptions(p
->num_options
, p
->options
);
777 * Restore the previous position in the Printers array...
780 cupsArrayRestore(Printers
);
787 * 'cupsdFindDest()' - Find a destination in the list.
790 cupsd_printer_t
* /* O - Destination in list */
791 cupsdFindDest(const char *name
) /* I - Name of printer or class to find */
793 cupsd_printer_t key
; /* Search key */
796 key
.name
= (char *)name
;
797 return ((cupsd_printer_t
*)cupsArrayFind(Printers
, &key
));
802 * 'cupsdFindPrinter()' - Find a printer in the list.
805 cupsd_printer_t
* /* O - Printer in list */
806 cupsdFindPrinter(const char *name
) /* I - Name of printer to find */
808 cupsd_printer_t
*p
; /* Printer in list */
811 if ((p
= cupsdFindDest(name
)) != NULL
&& (p
->type
& CUPS_PRINTER_CLASS
))
819 * 'cupsdLoadAllPrinters()' - Load printers from the printers.conf file.
823 cupsdLoadAllPrinters(void)
825 int i
; /* Looping var */
826 cups_file_t
*fp
; /* printers.conf file */
827 int linenum
; /* Current line number */
828 char line
[4096], /* Line from file */
829 *value
, /* Pointer to value */
830 *valueptr
; /* Pointer into value */
831 cupsd_printer_t
*p
; /* Current printer */
835 * Open the printers.conf file...
838 snprintf(line
, sizeof(line
), "%s/printers.conf", ServerRoot
);
839 if ((fp
= cupsdOpenConfFile(line
)) == NULL
)
843 * Read printer configurations until we hit EOF...
849 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
852 * Decode the directive...
855 if (!_cups_strcasecmp(line
, "<Printer") ||
856 !_cups_strcasecmp(line
, "<DefaultPrinter"))
859 * <Printer name> or <DefaultPrinter name>
862 if (p
== NULL
&& value
)
865 * Add the printer and a base file type...
868 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Loading printer %s...", value
);
870 p
= cupsdAddPrinter(value
);
872 p
->state
= IPP_PRINTER_IDLE
;
875 * Set the default printer as needed...
878 if (!_cups_strcasecmp(line
, "<DefaultPrinter"))
882 cupsdLogMessage(CUPSD_LOG_ERROR
,
883 "Syntax error on line %d of printers.conf.", linenum
);
885 else if (!_cups_strcasecmp(line
, "</Printer>"))
890 * Close out the current printer...
893 cupsdSetPrinterAttrs(p
);
895 if (strncmp(p
->device_uri
, "file:", 5) &&
896 p
->state
!= IPP_PRINTER_STOPPED
)
899 * See if the backend exists...
902 snprintf(line
, sizeof(line
), "%s/backend/%s", ServerBin
,
905 if ((valueptr
= strchr(line
+ strlen(ServerBin
), ':')) != NULL
)
906 *valueptr
= '\0'; /* Chop everything but URI scheme */
911 * Backend does not exist, stop printer...
914 p
->state
= IPP_PRINTER_STOPPED
;
915 snprintf(p
->state_message
, sizeof(p
->state_message
),
916 "Backend %s does not exist!", line
);
923 cupsdLogMessage(CUPSD_LOG_ERROR
,
924 "Syntax error on line %d of printers.conf.", linenum
);
928 cupsdLogMessage(CUPSD_LOG_ERROR
,
929 "Syntax error on line %d of printers.conf.", linenum
);
931 else if (!_cups_strcasecmp(line
, "UUID"))
933 if (value
&& !strncmp(value
, "urn:uuid:", 9))
934 cupsdSetString(&(p
->uuid
), value
);
936 cupsdLogMessage(CUPSD_LOG_ERROR
,
937 "Bad UUID on line %d of printers.conf.", linenum
);
939 else if (!_cups_strcasecmp(line
, "AuthInfoRequired"))
941 if (!cupsdSetAuthInfoRequired(p
, value
, NULL
))
942 cupsdLogMessage(CUPSD_LOG_ERROR
,
943 "Bad AuthInfoRequired on line %d of printers.conf.",
946 else if (!_cups_strcasecmp(line
, "Info"))
949 cupsdSetString(&p
->info
, value
);
951 else if (!_cups_strcasecmp(line
, "MakeModel"))
954 cupsdSetString(&p
->make_model
, value
);
956 else if (!_cups_strcasecmp(line
, "Location"))
959 cupsdSetString(&p
->location
, value
);
961 else if (!_cups_strcasecmp(line
, "DeviceURI"))
964 cupsdSetDeviceURI(p
, value
);
966 cupsdLogMessage(CUPSD_LOG_ERROR
,
967 "Syntax error on line %d of printers.conf.", linenum
);
969 else if (!_cups_strcasecmp(line
, "Option") && value
)
975 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
978 cupsdLogMessage(CUPSD_LOG_ERROR
,
979 "Syntax error on line %d of printers.conf.", linenum
);
982 for (; *valueptr
&& isspace(*valueptr
& 255); *valueptr
++ = '\0');
984 p
->num_options
= cupsAddOption(value
, valueptr
, p
->num_options
,
988 else if (!_cups_strcasecmp(line
, "PortMonitor"))
990 if (value
&& strcmp(value
, "none"))
991 cupsdSetString(&p
->port_monitor
, value
);
993 cupsdClearString(&p
->port_monitor
);
995 cupsdLogMessage(CUPSD_LOG_ERROR
,
996 "Syntax error on line %d of printers.conf.", linenum
);
998 else if (!_cups_strcasecmp(line
, "Reason"))
1001 strcmp(value
, "connecting-to-device") &&
1002 strcmp(value
, "cups-insecure-filter-warning") &&
1003 strcmp(value
, "cups-missing-filter-warning"))
1005 for (i
= 0 ; i
< p
->num_reasons
; i
++)
1006 if (!strcmp(value
, p
->reasons
[i
]))
1009 if (i
>= p
->num_reasons
&&
1010 p
->num_reasons
< (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
1012 p
->reasons
[p
->num_reasons
] = _cupsStrAlloc(value
);
1017 cupsdLogMessage(CUPSD_LOG_ERROR
,
1018 "Syntax error on line %d of printers.conf.", linenum
);
1020 else if (!_cups_strcasecmp(line
, "State"))
1023 * Set the initial queue state...
1026 if (value
&& !_cups_strcasecmp(value
, "idle"))
1027 p
->state
= IPP_PRINTER_IDLE
;
1028 else if (value
&& !_cups_strcasecmp(value
, "stopped"))
1030 p
->state
= IPP_PRINTER_STOPPED
;
1032 for (i
= 0 ; i
< p
->num_reasons
; i
++)
1033 if (!strcmp("paused", p
->reasons
[i
]))
1036 if (i
>= p
->num_reasons
&&
1037 p
->num_reasons
< (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
1039 p
->reasons
[p
->num_reasons
] = _cupsStrAlloc("paused");
1044 cupsdLogMessage(CUPSD_LOG_ERROR
,
1045 "Syntax error on line %d of printers.conf.", linenum
);
1047 else if (!_cups_strcasecmp(line
, "StateMessage"))
1050 * Set the initial queue state message...
1054 strlcpy(p
->state_message
, value
, sizeof(p
->state_message
));
1056 else if (!_cups_strcasecmp(line
, "StateTime"))
1059 * Set the state time...
1063 p
->state_time
= atoi(value
);
1065 else if (!_cups_strcasecmp(line
, "Accepting"))
1068 * Set the initial accepting state...
1072 (!_cups_strcasecmp(value
, "yes") ||
1073 !_cups_strcasecmp(value
, "on") ||
1074 !_cups_strcasecmp(value
, "true")))
1077 (!_cups_strcasecmp(value
, "no") ||
1078 !_cups_strcasecmp(value
, "off") ||
1079 !_cups_strcasecmp(value
, "false")))
1082 cupsdLogMessage(CUPSD_LOG_ERROR
,
1083 "Syntax error on line %d of printers.conf.", linenum
);
1085 else if (!_cups_strcasecmp(line
, "Type"))
1088 p
->type
= atoi(value
);
1090 cupsdLogMessage(CUPSD_LOG_ERROR
,
1091 "Syntax error on line %d of printers.conf.", linenum
);
1093 else if (!_cups_strcasecmp(line
, "Shared"))
1096 * Set the initial shared state...
1100 (!_cups_strcasecmp(value
, "yes") ||
1101 !_cups_strcasecmp(value
, "on") ||
1102 !_cups_strcasecmp(value
, "true")))
1105 (!_cups_strcasecmp(value
, "no") ||
1106 !_cups_strcasecmp(value
, "off") ||
1107 !_cups_strcasecmp(value
, "false")))
1110 cupsdLogMessage(CUPSD_LOG_ERROR
,
1111 "Syntax error on line %d of printers.conf.", linenum
);
1113 else if (!_cups_strcasecmp(line
, "JobSheets"))
1116 * Set the initial job sheets...
1121 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1126 cupsdSetString(&p
->job_sheets
[0], value
);
1128 while (isspace(*valueptr
& 255))
1133 for (value
= valueptr
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1138 cupsdSetString(&p
->job_sheets
[1], value
);
1142 cupsdLogMessage(CUPSD_LOG_ERROR
,
1143 "Syntax error on line %d of printers.conf.", linenum
);
1145 else if (!_cups_strcasecmp(line
, "AllowUser"))
1150 cupsdAddString(&(p
->users
), value
);
1153 cupsdLogMessage(CUPSD_LOG_ERROR
,
1154 "Syntax error on line %d of printers.conf.", linenum
);
1156 else if (!_cups_strcasecmp(line
, "DenyUser"))
1161 cupsdAddString(&(p
->users
), value
);
1164 cupsdLogMessage(CUPSD_LOG_ERROR
,
1165 "Syntax error on line %d of printers.conf.", linenum
);
1167 else if (!_cups_strcasecmp(line
, "QuotaPeriod"))
1170 p
->quota_period
= atoi(value
);
1172 cupsdLogMessage(CUPSD_LOG_ERROR
,
1173 "Syntax error on line %d of printers.conf.", linenum
);
1175 else if (!_cups_strcasecmp(line
, "PageLimit"))
1178 p
->page_limit
= atoi(value
);
1180 cupsdLogMessage(CUPSD_LOG_ERROR
,
1181 "Syntax error on line %d of printers.conf.", linenum
);
1183 else if (!_cups_strcasecmp(line
, "KLimit"))
1186 p
->k_limit
= atoi(value
);
1188 cupsdLogMessage(CUPSD_LOG_ERROR
,
1189 "Syntax error on line %d of printers.conf.", linenum
);
1191 else if (!_cups_strcasecmp(line
, "OpPolicy"))
1195 cupsd_policy_t
*pol
; /* Policy */
1198 if ((pol
= cupsdFindPolicy(value
)) != NULL
)
1200 cupsdSetString(&p
->op_policy
, value
);
1201 p
->op_policy_ptr
= pol
;
1204 cupsdLogMessage(CUPSD_LOG_ERROR
,
1205 "Bad policy \"%s\" on line %d of printers.conf",
1209 cupsdLogMessage(CUPSD_LOG_ERROR
,
1210 "Syntax error on line %d of printers.conf.", linenum
);
1212 else if (!_cups_strcasecmp(line
, "ErrorPolicy"))
1215 cupsdSetString(&p
->error_policy
, value
);
1217 cupsdLogMessage(CUPSD_LOG_ERROR
,
1218 "Syntax error on line %d of printers.conf.", linenum
);
1220 else if (!_cups_strcasecmp(line
, "Attribute") && value
)
1222 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1225 cupsdLogMessage(CUPSD_LOG_ERROR
,
1226 "Syntax error on line %d of printers.conf.", linenum
);
1229 for (; *valueptr
&& isspace(*valueptr
& 255); *valueptr
++ = '\0');
1232 cupsdSetPrinterAttrs(p
);
1234 if (!strcmp(value
, "marker-change-time"))
1235 p
->marker_time
= atoi(valueptr
);
1237 cupsdSetPrinterAttr(p
, value
, valueptr
);
1240 else if (_cups_strcasecmp(line
, "Filter") &&
1241 _cups_strcasecmp(line
, "Prefilter") &&
1242 _cups_strcasecmp(line
, "Product"))
1245 * Something else we don't understand (and that wasn't used in a prior
1246 * release of CUPS...
1249 cupsdLogMessage(CUPSD_LOG_ERROR
,
1250 "Unknown configuration directive %s on line %d of "
1251 "printers.conf.", line
, linenum
);
1260 * 'cupsdRenamePrinter()' - Rename a printer.
1265 cupsd_printer_t
*p
, /* I - Printer */
1266 const char *name
) /* I - New name */
1269 * Remove the printer from the array(s) first...
1272 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1273 "cupsdRenamePrinter: Removing %s from Printers", p
->name
);
1274 cupsArrayRemove(Printers
, p
);
1277 * Rename the printer type...
1280 mimeDeleteType(MimeDatabase
, p
->filetype
);
1281 p
->filetype
= mimeAddType(MimeDatabase
, "printer", name
);
1283 if (p
->prefiltertype
)
1285 mimeDeleteType(MimeDatabase
, p
->prefiltertype
);
1286 p
->prefiltertype
= mimeAddType(MimeDatabase
, "prefilter", name
);
1290 * Rename the printer...
1293 cupsdSetString(&p
->name
, name
);
1296 * Reset printer attributes...
1299 cupsdSetPrinterAttrs(p
);
1302 * Add the printer back to the printer array(s)...
1305 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1306 "cupsdRenamePrinter: Adding %s to Printers", p
->name
);
1307 cupsArrayAdd(Printers
, p
);
1312 * 'cupsdSaveAllPrinters()' - Save all printer definitions to the printers.conf
1317 cupsdSaveAllPrinters(void)
1319 int i
; /* Looping var */
1320 cups_file_t
*fp
; /* printers.conf file */
1321 char filename
[1024], /* printers.conf filename */
1322 temp
[1024], /* Temporary string */
1323 value
[2048], /* Value string */
1324 *ptr
, /* Pointer into value */
1325 *name
; /* Current user/group name */
1326 cupsd_printer_t
*printer
; /* Current printer class */
1327 time_t curtime
; /* Current time */
1328 struct tm
*curdate
; /* Current date */
1329 cups_option_t
*option
; /* Current option */
1330 ipp_attribute_t
*marker
; /* Current marker attribute */
1334 * Create the printers.conf file...
1337 snprintf(filename
, sizeof(filename
), "%s/printers.conf", ServerRoot
);
1339 if ((fp
= cupsdCreateConfFile(filename
, ConfigFilePerm
& 0600)) == NULL
)
1342 cupsdLogMessage(CUPSD_LOG_INFO
, "Saving printers.conf...");
1345 * Write a small header to the file...
1348 curtime
= time(NULL
);
1349 curdate
= localtime(&curtime
);
1350 strftime(temp
, sizeof(temp
) - 1, "%Y-%m-%d %H:%M", curdate
);
1352 cupsFilePuts(fp
, "# Printer configuration file for " CUPS_SVERSION
"\n");
1353 cupsFilePrintf(fp
, "# Written by cupsd on %s\n", temp
);
1354 cupsFilePuts(fp
, "# DO NOT EDIT THIS FILE WHEN CUPSD IS RUNNING\n");
1357 * Write each local printer known to the system...
1360 for (printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
1362 printer
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
1365 * Skip printer classes...
1368 if (printer
->type
& CUPS_PRINTER_CLASS
)
1372 * Write printers as needed...
1375 if (printer
== DefaultPrinter
)
1376 cupsFilePrintf(fp
, "<DefaultPrinter %s>\n", printer
->name
);
1378 cupsFilePrintf(fp
, "<Printer %s>\n", printer
->name
);
1380 cupsFilePrintf(fp
, "UUID %s\n", printer
->uuid
);
1382 if (printer
->num_auth_info_required
> 0)
1384 switch (printer
->num_auth_info_required
)
1387 strlcpy(value
, printer
->auth_info_required
[0], sizeof(value
));
1391 snprintf(value
, sizeof(value
), "%s,%s",
1392 printer
->auth_info_required
[0],
1393 printer
->auth_info_required
[1]);
1398 snprintf(value
, sizeof(value
), "%s,%s,%s",
1399 printer
->auth_info_required
[0],
1400 printer
->auth_info_required
[1],
1401 printer
->auth_info_required
[2]);
1405 cupsFilePutConf(fp
, "AuthInfoRequired", value
);
1409 cupsFilePutConf(fp
, "Info", printer
->info
);
1411 if (printer
->location
)
1412 cupsFilePutConf(fp
, "Location", printer
->location
);
1414 if (printer
->make_model
)
1415 cupsFilePutConf(fp
, "MakeModel", printer
->make_model
);
1417 cupsFilePutConf(fp
, "DeviceURI", printer
->device_uri
);
1419 if (printer
->port_monitor
)
1420 cupsFilePutConf(fp
, "PortMonitor", printer
->port_monitor
);
1422 if (printer
->state
== IPP_PRINTER_STOPPED
)
1424 cupsFilePuts(fp
, "State Stopped\n");
1426 if (printer
->state_message
)
1427 cupsFilePutConf(fp
, "StateMessage", printer
->state_message
);
1430 cupsFilePuts(fp
, "State Idle\n");
1432 cupsFilePrintf(fp
, "StateTime %d\n", (int)printer
->state_time
);
1434 for (i
= 0; i
< printer
->num_reasons
; i
++)
1435 if (strcmp(printer
->reasons
[i
], "connecting-to-device") &&
1436 strcmp(printer
->reasons
[i
], "cups-insecure-filter-warning") &&
1437 strcmp(printer
->reasons
[i
], "cups-missing-filter-warning"))
1438 cupsFilePutConf(fp
, "Reason", printer
->reasons
[i
]);
1440 cupsFilePrintf(fp
, "Type %d\n", printer
->type
);
1442 if (printer
->accepting
)
1443 cupsFilePuts(fp
, "Accepting Yes\n");
1445 cupsFilePuts(fp
, "Accepting No\n");
1447 if (printer
->shared
)
1448 cupsFilePuts(fp
, "Shared Yes\n");
1450 cupsFilePuts(fp
, "Shared No\n");
1452 snprintf(value
, sizeof(value
), "%s %s", printer
->job_sheets
[0],
1453 printer
->job_sheets
[1]);
1454 cupsFilePutConf(fp
, "JobSheets", value
);
1456 cupsFilePrintf(fp
, "QuotaPeriod %d\n", printer
->quota_period
);
1457 cupsFilePrintf(fp
, "PageLimit %d\n", printer
->page_limit
);
1458 cupsFilePrintf(fp
, "KLimit %d\n", printer
->k_limit
);
1460 for (name
= (char *)cupsArrayFirst(printer
->users
);
1462 name
= (char *)cupsArrayNext(printer
->users
))
1463 cupsFilePutConf(fp
, printer
->deny_users
? "DenyUser" : "AllowUser", name
);
1465 if (printer
->op_policy
)
1466 cupsFilePutConf(fp
, "OpPolicy", printer
->op_policy
);
1467 if (printer
->error_policy
)
1468 cupsFilePutConf(fp
, "ErrorPolicy", printer
->error_policy
);
1470 for (i
= printer
->num_options
, option
= printer
->options
;
1474 snprintf(value
, sizeof(value
), "%s %s", option
->name
, option
->value
);
1475 cupsFilePutConf(fp
, "Option", value
);
1478 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-colors",
1479 IPP_TAG_NAME
)) != NULL
)
1481 snprintf(value
, sizeof(value
), "%s ", marker
->name
);
1483 for (i
= 0, ptr
= value
+ strlen(value
);
1484 i
< marker
->num_values
&& ptr
< (value
+ sizeof(value
) - 1);
1490 strlcpy(ptr
, marker
->values
[i
].string
.text
,
1491 value
+ sizeof(value
) - ptr
);
1496 cupsFilePutConf(fp
, "Attribute", value
);
1499 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-levels",
1500 IPP_TAG_INTEGER
)) != NULL
)
1502 cupsFilePrintf(fp
, "Attribute %s %d", marker
->name
,
1503 marker
->values
[0].integer
);
1504 for (i
= 1; i
< marker
->num_values
; i
++)
1505 cupsFilePrintf(fp
, ",%d", marker
->values
[i
].integer
);
1506 cupsFilePuts(fp
, "\n");
1509 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-low-levels",
1510 IPP_TAG_INTEGER
)) != NULL
)
1512 cupsFilePrintf(fp
, "Attribute %s %d", marker
->name
,
1513 marker
->values
[0].integer
);
1514 for (i
= 1; i
< marker
->num_values
; i
++)
1515 cupsFilePrintf(fp
, ",%d", marker
->values
[i
].integer
);
1516 cupsFilePuts(fp
, "\n");
1519 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-high-levels",
1520 IPP_TAG_INTEGER
)) != NULL
)
1522 cupsFilePrintf(fp
, "Attribute %s %d", marker
->name
,
1523 marker
->values
[0].integer
);
1524 for (i
= 1; i
< marker
->num_values
; i
++)
1525 cupsFilePrintf(fp
, ",%d", marker
->values
[i
].integer
);
1526 cupsFilePuts(fp
, "\n");
1529 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-message",
1530 IPP_TAG_TEXT
)) != NULL
)
1532 snprintf(value
, sizeof(value
), "%s %s", marker
->name
,
1533 marker
->values
[0].string
.text
);
1535 cupsFilePutConf(fp
, "Attribute", value
);
1538 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-names",
1539 IPP_TAG_NAME
)) != NULL
)
1541 snprintf(value
, sizeof(value
), "%s ", marker
->name
);
1543 for (i
= 0, ptr
= value
+ strlen(value
);
1544 i
< marker
->num_values
&& ptr
< (value
+ sizeof(value
) - 1);
1550 strlcpy(ptr
, marker
->values
[i
].string
.text
,
1551 value
+ sizeof(value
) - ptr
);
1556 cupsFilePutConf(fp
, "Attribute", value
);
1559 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-types",
1560 IPP_TAG_KEYWORD
)) != NULL
)
1562 snprintf(value
, sizeof(value
), "%s ", marker
->name
);
1564 for (i
= 0, ptr
= value
+ strlen(value
);
1565 i
< marker
->num_values
&& ptr
< (value
+ sizeof(value
) - 1);
1571 strlcpy(ptr
, marker
->values
[i
].string
.text
,
1572 value
+ sizeof(value
) - ptr
);
1577 cupsFilePutConf(fp
, "Attribute", value
);
1580 if (printer
->marker_time
)
1581 cupsFilePrintf(fp
, "Attribute marker-change-time %ld\n",
1582 (long)printer
->marker_time
);
1584 cupsFilePuts(fp
, "</Printer>\n");
1587 cupsdCloseCreatedConfFile(fp
, filename
);
1592 * 'cupsdSetAuthInfoRequired()' - Set the required authentication info.
1595 int /* O - 1 if value OK, 0 otherwise */
1596 cupsdSetAuthInfoRequired(
1597 cupsd_printer_t
*p
, /* I - Printer */
1598 const char *values
, /* I - Plain text value (or NULL) */
1599 ipp_attribute_t
*attr
) /* I - IPP attribute value (or NULL) */
1601 int i
; /* Looping var */
1604 p
->num_auth_info_required
= 0;
1607 * Do we have a plain text value?
1613 * Yes, grab the keywords...
1616 const char *end
; /* End of current value */
1619 while (*values
&& p
->num_auth_info_required
< 4)
1621 if ((end
= strchr(values
, ',')) == NULL
)
1622 end
= values
+ strlen(values
);
1624 if ((end
- values
) == 4 && !strncmp(values
, "none", 4))
1626 if (p
->num_auth_info_required
!= 0 || *end
)
1629 p
->auth_info_required
[p
->num_auth_info_required
] = "none";
1630 p
->num_auth_info_required
++;
1634 else if ((end
- values
) == 9 && !strncmp(values
, "negotiate", 9))
1636 if (p
->num_auth_info_required
!= 0 || *end
)
1639 p
->auth_info_required
[p
->num_auth_info_required
] = "negotiate";
1640 p
->num_auth_info_required
++;
1643 * Don't allow sharing of queues that require Kerberos authentication.
1648 cupsdDeregisterPrinter(p
, 1);
1652 else if ((end
- values
) == 6 && !strncmp(values
, "domain", 6))
1654 p
->auth_info_required
[p
->num_auth_info_required
] = "domain";
1655 p
->num_auth_info_required
++;
1657 else if ((end
- values
) == 8 && !strncmp(values
, "password", 8))
1659 p
->auth_info_required
[p
->num_auth_info_required
] = "password";
1660 p
->num_auth_info_required
++;
1662 else if ((end
- values
) == 8 && !strncmp(values
, "username", 8))
1664 p
->auth_info_required
[p
->num_auth_info_required
] = "username";
1665 p
->num_auth_info_required
++;
1670 values
= (*end
) ? end
+ 1 : end
;
1673 if (p
->num_auth_info_required
== 0)
1675 p
->auth_info_required
[0] = "none";
1676 p
->num_auth_info_required
= 1;
1680 * Update the printer-type value as needed...
1683 if (p
->num_auth_info_required
> 1 ||
1684 strcmp(p
->auth_info_required
[0], "none"))
1685 p
->type
|= CUPS_PRINTER_AUTHENTICATED
;
1687 p
->type
&= ~CUPS_PRINTER_AUTHENTICATED
;
1693 * Grab values from an attribute instead...
1696 if (!attr
|| attr
->num_values
> 4)
1699 for (i
= 0; i
< attr
->num_values
; i
++)
1701 if (!strcmp(attr
->values
[i
].string
.text
, "none"))
1703 if (p
->num_auth_info_required
!= 0 || attr
->num_values
!= 1)
1706 p
->auth_info_required
[p
->num_auth_info_required
] = "none";
1707 p
->num_auth_info_required
++;
1711 else if (!strcmp(attr
->values
[i
].string
.text
, "negotiate"))
1713 if (p
->num_auth_info_required
!= 0 || attr
->num_values
!= 1)
1716 p
->auth_info_required
[p
->num_auth_info_required
] = "negotiate";
1717 p
->num_auth_info_required
++;
1720 * Don't allow sharing of queues that require Kerberos authentication.
1725 cupsdDeregisterPrinter(p
, 1);
1731 else if (!strcmp(attr
->values
[i
].string
.text
, "domain"))
1733 p
->auth_info_required
[p
->num_auth_info_required
] = "domain";
1734 p
->num_auth_info_required
++;
1736 else if (!strcmp(attr
->values
[i
].string
.text
, "password"))
1738 p
->auth_info_required
[p
->num_auth_info_required
] = "password";
1739 p
->num_auth_info_required
++;
1741 else if (!strcmp(attr
->values
[i
].string
.text
, "username"))
1743 p
->auth_info_required
[p
->num_auth_info_required
] = "username";
1744 p
->num_auth_info_required
++;
1755 * 'cupsdSetDeviceURI()' - Set the device URI for a printer.
1759 cupsdSetDeviceURI(cupsd_printer_t
*p
, /* I - Printer */
1760 const char *uri
) /* I - Device URI */
1762 char buffer
[1024], /* URI buffer */
1763 *start
, /* Start of data after scheme */
1764 *slash
, /* First slash after scheme:// */
1765 *ptr
; /* Pointer into user@host:port part */
1769 * Set the full device URI..
1772 cupsdSetString(&(p
->device_uri
), uri
);
1775 * Copy the device URI to a temporary buffer so we can sanitize any auth
1779 strlcpy(buffer
, uri
, sizeof(buffer
));
1782 * Find the end of the scheme:// part...
1785 if ((ptr
= strchr(buffer
, ':')) != NULL
)
1787 for (start
= ptr
+ 1; *start
; start
++)
1792 * Find the next slash (/) in the URI...
1795 if ((slash
= strchr(start
, '/')) == NULL
)
1796 slash
= start
+ strlen(start
); /* No slash, point to the end */
1799 * Check for an @ sign before the slash...
1802 if ((ptr
= strchr(start
, '@')) != NULL
&& ptr
< slash
)
1805 * Found an @ sign and it is before the resource part, so we have
1806 * an authentication string. Copy the remaining URI over the
1807 * authentication string...
1810 _cups_strcpy(start
, ptr
+ 1);
1815 * Save the sanitized URI...
1818 cupsdSetString(&(p
->sanitized_device_uri
), buffer
);
1823 * 'cupsdSetPrinterAttr()' - Set a printer attribute.
1827 cupsdSetPrinterAttr(
1828 cupsd_printer_t
*p
, /* I - Printer */
1829 const char *name
, /* I - Attribute name */
1830 const char *value
) /* I - Attribute value string */
1832 ipp_attribute_t
*attr
; /* Attribute */
1833 int i
, /* Looping var */
1834 count
; /* Number of values */
1835 char *temp
, /* Temporary copy of value string */
1836 *ptr
, /* Pointer into value */
1837 *start
, /* Start of value */
1838 quote
; /* Quote character */
1839 ipp_tag_t value_tag
; /* Value tag for this attribute */
1843 * Don't allow empty values...
1846 if (!*value
&& strcmp(name
, "marker-message"))
1848 cupsdLogMessage(CUPSD_LOG_ERROR
, "Ignoring empty \"%s\" attribute", name
);
1853 * Copy the value string so we can do what we want with it...
1856 if ((temp
= strdup(value
)) == NULL
)
1858 cupsdLogMessage(CUPSD_LOG_ERROR
,
1859 "Unable to duplicate value for \"%s\" attribute.", name
);
1864 * Count the number of values...
1867 for (count
= 1, quote
= '\0', ptr
= temp
;
1875 else if (*ptr
== '\\' && ptr
[1])
1877 else if (*ptr
== '\'' || *ptr
== '\"')
1879 else if (*ptr
== ',')
1884 * Then add or update the attribute as needed...
1887 if (!strcmp(name
, "marker-levels") || !strcmp(name
, "marker-low-levels") ||
1888 !strcmp(name
, "marker-high-levels"))
1894 if ((attr
= ippFindAttribute(p
->attrs
, name
, IPP_TAG_INTEGER
)) != NULL
&&
1895 attr
->num_values
< count
)
1897 ippDeleteAttribute(p
->attrs
, attr
);
1902 attr
->num_values
= count
;
1904 attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
, name
,
1909 cupsdLogMessage(CUPSD_LOG_ERROR
,
1910 "Unable to allocate memory for printer attribute "
1911 "(%d values)", count
);
1915 for (i
= 0, start
= temp
; i
< count
; i
++)
1917 if ((ptr
= strchr(start
, ',')) != NULL
)
1920 attr
->values
[i
].integer
= strtol(start
, NULL
, 10);
1929 * Name or keyword values...
1932 if (!strcmp(name
, "marker-types"))
1933 value_tag
= IPP_TAG_KEYWORD
;
1934 else if (!strcmp(name
, "marker-message"))
1935 value_tag
= IPP_TAG_TEXT
;
1937 value_tag
= IPP_TAG_NAME
;
1939 if ((attr
= ippFindAttribute(p
->attrs
, name
, value_tag
)) != NULL
&&
1940 attr
->num_values
< count
)
1942 ippDeleteAttribute(p
->attrs
, attr
);
1948 for (i
= 0; i
< attr
->num_values
; i
++)
1949 _cupsStrFree(attr
->values
[i
].string
.text
);
1951 attr
->num_values
= count
;
1954 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, value_tag
, name
,
1959 cupsdLogMessage(CUPSD_LOG_ERROR
,
1960 "Unable to allocate memory for printer attribute "
1961 "(%d values)", count
);
1965 for (i
= 0, quote
= '\0', ptr
= temp
; i
< count
; i
++)
1967 for (start
= ptr
; *ptr
; ptr
++)
1970 *ptr
= quote
= '\0';
1973 else if (*ptr
== '\\' && ptr
[1])
1974 _cups_strcpy(ptr
, ptr
+ 1);
1975 else if (*ptr
== '\'' || *ptr
== '\"')
1982 _cups_strcpy(ptr
, ptr
+ 1);
1984 else if (*ptr
== ',')
1991 attr
->values
[i
].string
.text
= _cupsStrAlloc(start
);
2000 * 'cupsdSetPrinterAttrs()' - Set printer attributes based upon the PPD file.
2004 cupsdSetPrinterAttrs(cupsd_printer_t
*p
)/* I - Printer to setup */
2006 int i
; /* Looping var */
2007 char resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
2008 cupsd_location_t
*auth
; /* Pointer to authentication element */
2009 const char *auth_supported
; /* Authentication supported */
2010 ipp_t
*oldattrs
; /* Old printer attributes */
2011 ipp_attribute_t
*attr
; /* Attribute data */
2012 char *name
, /* Current user/group name */
2013 *filter
; /* Current filter */
2016 DEBUG_printf(("cupsdSetPrinterAttrs: entering name = %s, type = %x\n", p
->name
,
2020 * Make sure that we have the common attributes defined...
2024 cupsdCreateCommonData();
2027 * Clear out old filters, if any...
2030 delete_printer_filters(p
);
2033 * Figure out the authentication that is required for the printer.
2036 auth_supported
= "requesting-user-name";
2038 if (p
->type
& CUPS_PRINTER_CLASS
)
2039 snprintf(resource
, sizeof(resource
), "/classes/%s", p
->name
);
2041 snprintf(resource
, sizeof(resource
), "/printers/%s", p
->name
);
2043 if ((auth
= cupsdFindBest(resource
, HTTP_POST
)) == NULL
||
2044 auth
->type
== CUPSD_AUTH_NONE
)
2045 auth
= cupsdFindPolicyOp(p
->op_policy_ptr
, IPP_PRINT_JOB
);
2049 int auth_type
; /* Authentication type */
2052 if ((auth_type
= auth
->type
) == CUPSD_AUTH_DEFAULT
)
2053 auth_type
= cupsdDefaultAuthType();
2055 if (auth_type
== CUPSD_AUTH_BASIC
|| auth_type
== CUPSD_AUTH_BASICDIGEST
)
2056 auth_supported
= "basic";
2057 else if (auth_type
== CUPSD_AUTH_DIGEST
)
2058 auth_supported
= "digest";
2060 else if (auth_type
== CUPSD_AUTH_NEGOTIATE
)
2061 auth_supported
= "negotiate";
2062 #endif /* HAVE_GSSAPI */
2064 if (auth_type
!= CUPSD_AUTH_NONE
)
2065 p
->type
|= CUPS_PRINTER_AUTHENTICATED
;
2067 p
->type
&= ~CUPS_PRINTER_AUTHENTICATED
;
2070 p
->type
&= ~CUPS_PRINTER_AUTHENTICATED
;
2073 * Create the required IPP attributes for a printer...
2076 oldattrs
= p
->attrs
;
2077 p
->attrs
= ippNew();
2079 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2080 "uri-authentication-supported", NULL
, auth_supported
);
2081 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2082 "uri-security-supported", NULL
, "none");
2083 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
, "printer-name", NULL
,
2085 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-location",
2086 NULL
, p
->location
? p
->location
: "");
2087 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-info",
2088 NULL
, p
->info
? p
->info
: "");
2089 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "printer-uuid", NULL
,
2092 if (cupsArrayCount(p
->users
) > 0)
2095 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2096 "requesting-user-name-denied",
2097 cupsArrayCount(p
->users
), NULL
, NULL
);
2099 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2100 "requesting-user-name-allowed",
2101 cupsArrayCount(p
->users
), NULL
, NULL
);
2103 for (i
= 0, name
= (char *)cupsArrayFirst(p
->users
);
2105 i
++, name
= (char *)cupsArrayNext(p
->users
))
2106 attr
->values
[i
].string
.text
= _cupsStrAlloc(name
);
2109 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2110 "job-quota-period", p
->quota_period
);
2111 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2112 "job-k-limit", p
->k_limit
);
2113 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2114 "job-page-limit", p
->page_limit
);
2115 if (p
->num_auth_info_required
> 0 && strcmp(p
->auth_info_required
[0], "none"))
2116 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2117 "auth-info-required", p
->num_auth_info_required
, NULL
,
2118 p
->auth_info_required
);
2120 if (cupsArrayCount(Banners
) > 0)
2123 * Setup the job-sheets-default attribute...
2126 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2127 "job-sheets-default", 2, NULL
, NULL
);
2131 attr
->values
[0].string
.text
= _cupsStrAlloc(Classification
?
2132 Classification
: p
->job_sheets
[0]);
2133 attr
->values
[1].string
.text
= _cupsStrAlloc(Classification
?
2134 Classification
: p
->job_sheets
[1]);
2142 * Assign additional attributes depending on whether this is a printer
2146 if (p
->type
& CUPS_PRINTER_CLASS
)
2149 p
->type
&= ~CUPS_PRINTER_OPTIONS
;
2152 * Add class-specific attributes...
2155 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
2156 "printer-make-and-model", NULL
, "Local Printer Class");
2157 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "device-uri", NULL
,
2158 "file:///dev/null");
2160 if (p
->num_printers
> 0)
2163 * Add a list of member names; URIs are added in copy_printer_attrs...
2166 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2167 "member-names", p
->num_printers
, NULL
, NULL
);
2168 p
->type
|= CUPS_PRINTER_OPTIONS
;
2170 for (i
= 0; i
< p
->num_printers
; i
++)
2173 attr
->values
[i
].string
.text
= _cupsStrAlloc(p
->printers
[i
]->name
);
2175 p
->type
&= ~CUPS_PRINTER_OPTIONS
| p
->printers
[i
]->type
;
2182 * Add printer-specific attributes...
2185 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "device-uri", NULL
,
2186 p
->sanitized_device_uri
);
2189 * Assign additional attributes from the PPD file (if any)...
2195 * Add filters for printer...
2198 cupsdSetPrinterReasons(p
, "-cups-missing-filter-warning,"
2199 "cups-insecure-filter-warning");
2201 if (p
->pc
&& p
->pc
->filters
)
2203 for (filter
= (char *)cupsArrayFirst(p
->pc
->filters
);
2205 filter
= (char *)cupsArrayNext(p
->pc
->filters
))
2206 add_printer_filter(p
, p
->filetype
, filter
);
2208 else if (!(p
->type
& CUPS_PRINTER_REMOTE
))
2210 char interface
[1024]; /* Interface script */
2213 snprintf(interface
, sizeof(interface
), "%s/interfaces/%s", ServerRoot
,
2215 if (!access(interface
, X_OK
))
2218 * Yes, we have a System V style interface script; use it!
2221 snprintf(interface
, sizeof(interface
), "*/* 0 %s/interfaces/%s",
2222 ServerRoot
, p
->name
);
2223 add_printer_filter(p
, p
->filetype
, interface
);
2228 * Add a filter from application/vnd.cups-raw to printer/name to
2229 * handle "raw" printing by users.
2232 add_printer_filter(p
, p
->filetype
, "application/vnd.cups-raw 0 -");
2235 * Add a PostScript filter, since this is still possibly PS printer.
2238 add_printer_filter(p
, p
->filetype
,
2239 "application/vnd.cups-postscript 0 -");
2243 if (p
->pc
&& p
->pc
->prefilters
)
2245 if (!p
->prefiltertype
)
2246 p
->prefiltertype
= mimeAddType(MimeDatabase
, "prefilter", p
->name
);
2248 for (filter
= (char *)cupsArrayFirst(p
->pc
->prefilters
);
2250 filter
= (char *)cupsArrayNext(p
->pc
->prefilters
))
2251 add_printer_filter(p
, p
->prefiltertype
, filter
);
2256 * Copy marker attributes as needed...
2261 ipp_attribute_t
*oldattr
; /* Old attribute */
2264 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-colors",
2265 IPP_TAG_NAME
)) != NULL
)
2267 if ((attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2268 "marker-colors", oldattr
->num_values
, NULL
,
2271 for (i
= 0; i
< oldattr
->num_values
; i
++)
2272 attr
->values
[i
].string
.text
=
2273 _cupsStrAlloc(oldattr
->values
[i
].string
.text
);
2277 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-levels",
2278 IPP_TAG_INTEGER
)) != NULL
)
2280 if ((attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2281 "marker-levels", oldattr
->num_values
,
2284 for (i
= 0; i
< oldattr
->num_values
; i
++)
2285 attr
->values
[i
].integer
= oldattr
->values
[i
].integer
;
2289 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-message",
2290 IPP_TAG_TEXT
)) != NULL
)
2291 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "marker-message",
2292 NULL
, oldattr
->values
[0].string
.text
);
2294 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-low-levels",
2295 IPP_TAG_INTEGER
)) != NULL
)
2297 if ((attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2298 "marker-low-levels", oldattr
->num_values
,
2301 for (i
= 0; i
< oldattr
->num_values
; i
++)
2302 attr
->values
[i
].integer
= oldattr
->values
[i
].integer
;
2306 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-high-levels",
2307 IPP_TAG_INTEGER
)) != NULL
)
2309 if ((attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2310 "marker-high-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-names",
2319 IPP_TAG_NAME
)) != NULL
)
2321 if ((attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2322 "marker-names", oldattr
->num_values
, NULL
,
2325 for (i
= 0; i
< oldattr
->num_values
; i
++)
2326 attr
->values
[i
].string
.text
=
2327 _cupsStrAlloc(oldattr
->values
[i
].string
.text
);
2331 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-types",
2332 IPP_TAG_KEYWORD
)) != NULL
)
2334 if ((attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2335 "marker-types", oldattr
->num_values
, NULL
,
2338 for (i
= 0; i
< oldattr
->num_values
; i
++)
2339 attr
->values
[i
].string
.text
=
2340 _cupsStrAlloc(oldattr
->values
[i
].string
.text
);
2344 ippDelete(oldattrs
);
2348 * Force sharing off for remote queues...
2351 if (p
->type
& CUPS_PRINTER_REMOTE
)
2355 * Populate the document-format-supported attribute...
2358 add_printer_formats(p
);
2360 DEBUG_printf(("cupsdSetPrinterAttrs: leaving name = %s, type = %x\n", p
->name
,
2364 * Add name-default attributes...
2367 add_printer_defaults(p
);
2370 * Let the browse protocols reflect the change
2373 cupsdRegisterPrinter(p
);
2378 * 'cupsdSetPrinterReasons()' - Set/update the reasons strings.
2381 int /* O - 1 if something changed, 0 otherwise */
2382 cupsdSetPrinterReasons(
2383 cupsd_printer_t
*p
, /* I - Printer */
2384 const char *s
) /* I - Reasons strings */
2386 int i
, /* Looping var */
2387 changed
= 0; /* Did something change? */
2388 const char *sptr
; /* Pointer into reasons */
2389 char reason
[255], /* Reason string */
2390 *rptr
; /* Pointer into reason */
2393 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
2394 "cupsdSetPrinterReasons(p=%p(%s),s=\"%s\"", p
, p
->name
, s
);
2396 if (s
[0] == '-' || s
[0] == '+')
2399 * Add/remove reasons...
2407 * Replace reasons...
2412 for (i
= 0; i
< p
->num_reasons
; i
++)
2413 _cupsStrFree(p
->reasons
[i
]);
2421 if (!strcmp(s
, "none"))
2425 * Loop through all of the reasons...
2431 * Skip leading whitespace and commas...
2434 while (isspace(*sptr
& 255) || *sptr
== ',')
2437 for (rptr
= reason
; *sptr
&& !isspace(*sptr
& 255) && *sptr
!= ','; sptr
++)
2438 if (rptr
< (reason
+ sizeof(reason
) - 1))
2452 for (i
= 0; i
< p
->num_reasons
; i
++)
2453 if (!strcmp(reason
, p
->reasons
[i
]))
2456 * Found a match, so remove it...
2461 _cupsStrFree(p
->reasons
[i
]);
2463 if (i
< p
->num_reasons
)
2464 memmove(p
->reasons
+ i
, p
->reasons
+ i
+ 1,
2465 (p
->num_reasons
- i
) * sizeof(char *));
2467 if (!strcmp(reason
, "paused") && p
->state
== IPP_PRINTER_STOPPED
)
2468 cupsdSetPrinterState(p
, IPP_PRINTER_IDLE
, 1);
2470 if (strcmp(reason
, "connecting-to-device"))
2475 else if (p
->num_reasons
< (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
2481 for (i
= 0; i
< p
->num_reasons
; i
++)
2482 if (!strcmp(reason
, p
->reasons
[i
]))
2485 if (i
>= p
->num_reasons
)
2487 if (!strncmp(reason
, "cups-ipp-missing-", 17) ||
2488 !strncmp(reason
, "cups-ipp-wrong-", 15))
2489 log_ipp_conformance(p
, reason
);
2491 if (i
>= (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
2493 cupsdLogMessage(CUPSD_LOG_ALERT
,
2494 "Too many printer-state-reasons values for %s (%d)",
2499 p
->reasons
[i
] = _cupsStrAlloc(reason
);
2503 if (!strcmp(reason
, "paused") && p
->state
!= IPP_PRINTER_STOPPED
)
2504 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, 1);
2506 if (strcmp(reason
, "connecting-to-device"))
2517 * 'cupsdSetPrinterState()' - Update the current state of a printer.
2521 cupsdSetPrinterState(
2522 cupsd_printer_t
*p
, /* I - Printer to change */
2523 ipp_pstate_t s
, /* I - New state */
2524 int update
) /* I - Update printers.conf? */
2526 cupsd_job_t
*job
; /* Current job */
2527 ipp_pstate_t old_state
; /* Old printer state */
2528 static const char * const printer_states
[] =
2529 { /* State strings */
2537 * Set the new state...
2540 old_state
= p
->state
;
2545 cupsdAddEvent(s
== IPP_PRINTER_STOPPED
? CUPSD_EVENT_PRINTER_STOPPED
:
2546 CUPSD_EVENT_PRINTER_STATE
, p
, NULL
,
2547 "%s \"%s\" state changed to %s.",
2548 (p
->type
& CUPS_PRINTER_CLASS
) ? "Class" : "Printer",
2549 p
->name
, printer_states
[p
->state
- IPP_PRINTER_IDLE
]);
2552 * Let the browse code know this needs to be updated...
2555 p
->state_time
= time(NULL
);
2559 * Set/clear the paused reason as needed...
2562 if (s
== IPP_PRINTER_STOPPED
)
2563 cupsdSetPrinterReasons(p
, "+paused");
2565 cupsdSetPrinterReasons(p
, "-paused");
2569 for (job
= (cupsd_job_t
*)cupsArrayFirst(ActiveJobs
);
2571 job
= (cupsd_job_t
*)cupsArrayNext(ActiveJobs
))
2572 if (job
->reasons
&& job
->state_value
== IPP_JOB_PENDING
&&
2573 !_cups_strcasecmp(job
->dest
, p
->name
))
2574 ippSetString(job
->attrs
, &job
->reasons
, 0,
2575 s
== IPP_PRINTER_STOPPED
? "printer-stopped" : "none");
2579 * Clear the message for the queue when going to processing...
2582 if (s
== IPP_PRINTER_PROCESSING
)
2583 p
->state_message
[0] = '\0';
2586 * Let the browse protocols reflect the change...
2590 cupsdRegisterPrinter(p
);
2593 * Save the printer configuration if a printer goes from idle or processing
2594 * to stopped (or visa-versa)...
2598 (old_state
== IPP_PRINTER_STOPPED
) != (s
== IPP_PRINTER_STOPPED
))
2604 * 'cupsdStopPrinter()' - Stop a printer from printing any jobs...
2608 cupsdStopPrinter(cupsd_printer_t
*p
, /* I - Printer to stop */
2609 int update
)/* I - Update printers.conf? */
2612 * Set the printer state...
2615 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, update
);
2618 * See if we have a job printing on this printer...
2621 if (p
->job
&& p
->job
->state_value
== IPP_JOB_PROCESSING
)
2622 cupsdSetJobState(p
->job
, IPP_JOB_PENDING
, CUPSD_JOB_DEFAULT
,
2623 "Job stopped due to printer being paused.");
2628 * 'cupsdUpdatePrinterPPD()' - Update keywords in a printer's PPD file.
2631 int /* O - 1 if successful, 0 otherwise */
2632 cupsdUpdatePrinterPPD(
2633 cupsd_printer_t
*p
, /* I - Printer */
2634 int num_keywords
, /* I - Number of keywords */
2635 cups_option_t
*keywords
) /* I - Keywords */
2637 int i
; /* Looping var */
2638 cups_file_t
*src
, /* Original file */
2639 *dst
; /* New file */
2640 char srcfile
[1024], /* Original filename */
2641 dstfile
[1024], /* New filename */
2642 line
[1024], /* Line from file */
2643 keystring
[41]; /* Keyword from line */
2644 cups_option_t
*keyword
; /* Current keyword */
2647 cupsdLogMessage(CUPSD_LOG_INFO
, "Updating keywords in PPD file for %s...",
2651 * Get the old and new PPD filenames...
2654 snprintf(srcfile
, sizeof(srcfile
), "%s/ppd/%s.ppd.O", ServerRoot
, p
->name
);
2655 snprintf(dstfile
, sizeof(srcfile
), "%s/ppd/%s.ppd", ServerRoot
, p
->name
);
2658 * Rename the old file and open the old and new...
2661 if (rename(dstfile
, srcfile
))
2663 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to backup PPD file for %s: %s",
2664 p
->name
, strerror(errno
));
2668 if ((src
= cupsFileOpen(srcfile
, "r")) == NULL
)
2670 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to open PPD file \"%s\": %s",
2671 srcfile
, strerror(errno
));
2672 rename(srcfile
, dstfile
);
2676 if ((dst
= cupsFileOpen(dstfile
, "w")) == NULL
)
2678 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to create PPD file \"%s\": %s",
2679 dstfile
, strerror(errno
));
2681 rename(srcfile
, dstfile
);
2686 * Copy the first line and then write out all of the keywords...
2689 if (!cupsFileGets(src
, line
, sizeof(line
)))
2691 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to read PPD file \"%s\": %s",
2692 srcfile
, strerror(errno
));
2695 rename(srcfile
, dstfile
);
2699 cupsFilePrintf(dst
, "%s\n", line
);
2701 for (i
= num_keywords
, keyword
= keywords
; i
> 0; i
--, keyword
++)
2703 cupsdLogMessage(CUPSD_LOG_DEBUG
, "*%s: %s", keyword
->name
, keyword
->value
);
2704 cupsFilePrintf(dst
, "*%s: %s\n", keyword
->name
, keyword
->value
);
2708 * Then copy the rest of the PPD file, dropping any keywords we changed.
2711 while (cupsFileGets(src
, line
, sizeof(line
)))
2714 * Skip keywords we've already set...
2717 if (sscanf(line
, "*%40[^:]:", keystring
) == 1 &&
2718 cupsGetOption(keystring
, num_keywords
, keywords
))
2722 * Otherwise write the line...
2725 cupsFilePrintf(dst
, "%s\n", line
);
2729 * Close files and return...
2740 * 'cupsdUpdatePrinters()' - Update printers after a partial reload.
2744 cupsdUpdatePrinters(void)
2746 cupsd_printer_t
*p
; /* Current printer */
2750 * Loop through the printers and recreate the printer attributes
2751 * for any local printers since the policy and/or access control
2752 * stuff may have changed. Also, if browsing is disabled, remove
2753 * any remote printers...
2756 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
2758 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
2761 * Update the operation policy pointer...
2764 if ((p
->op_policy_ptr
= cupsdFindPolicy(p
->op_policy
)) == NULL
)
2765 p
->op_policy_ptr
= DefaultPolicyPtr
;
2768 * Update printer attributes...
2771 cupsdSetPrinterAttrs(p
);
2777 * 'cupsdValidateDest()' - Validate a printer/class destination.
2780 const char * /* O - Printer or class name */
2782 const char *uri
, /* I - Printer URI */
2783 cups_ptype_t
*dtype
, /* O - Type (printer or class) */
2784 cupsd_printer_t
**printer
) /* O - Printer pointer */
2786 cupsd_printer_t
*p
; /* Current printer */
2787 char localname
[1024],/* Localized hostname */
2788 *lptr
, /* Pointer into localized hostname */
2789 *sptr
, /* Pointer into server name */
2790 *rptr
, /* Pointer into resource */
2791 scheme
[32], /* Scheme portion of URI */
2792 username
[64], /* Username portion of URI */
2793 hostname
[HTTP_MAX_HOST
],
2794 /* Host portion of URI */
2795 resource
[HTTP_MAX_URI
];
2796 /* Resource portion of URI */
2797 int port
; /* Port portion of URI */
2800 DEBUG_printf(("cupsdValidateDest(uri=\"%s\", dtype=%p, printer=%p)\n", uri
,
2804 * Initialize return values...
2811 *dtype
= (cups_ptype_t
)0;
2814 * Pull the hostname and resource from the URI...
2817 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
, scheme
, sizeof(scheme
),
2818 username
, sizeof(username
), hostname
, sizeof(hostname
),
2819 &port
, resource
, sizeof(resource
));
2822 * See if the resource is a class or printer...
2825 if (!strncmp(resource
, "/classes/", 9))
2831 rptr
= resource
+ 9;
2833 else if (!strncmp(resource
, "/printers/", 10))
2839 rptr
= resource
+ 10;
2844 * Bad resource name...
2851 * See if the printer or class name exists...
2854 p
= cupsdFindDest(rptr
);
2856 if (p
== NULL
&& strchr(rptr
, '@') == NULL
)
2864 *dtype
= p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_REMOTE
);
2870 * Change localhost to the server name...
2873 if (!_cups_strcasecmp(hostname
, "localhost"))
2874 strlcpy(hostname
, ServerName
, sizeof(hostname
));
2876 strlcpy(localname
, hostname
, sizeof(localname
));
2878 if (!_cups_strcasecmp(hostname
, ServerName
))
2881 * Localize the hostname...
2884 lptr
= strchr(localname
, '.');
2885 sptr
= strchr(ServerName
, '.');
2887 if (sptr
!= NULL
&& lptr
!= NULL
)
2890 * Strip the common domain name components...
2893 while (lptr
!= NULL
)
2895 if (!_cups_strcasecmp(lptr
, sptr
))
2901 lptr
= strchr(lptr
+ 1, '.');
2906 DEBUG_printf(("localized hostname is \"%s\"...\n", localname
));
2909 * Find a matching printer or class...
2912 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
2914 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
2915 if (!_cups_strcasecmp(p
->hostname
, localname
) &&
2916 !_cups_strcasecmp(p
->name
, rptr
))
2922 *dtype
= p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_REMOTE
);
2932 * 'cupsdWritePrintcap()' - Write a pseudo-printcap file for older applications
2937 cupsdWritePrintcap(void)
2939 int i
; /* Looping var */
2940 cups_file_t
*fp
; /* Printcap file */
2941 cupsd_printer_t
*p
; /* Current printer */
2945 * See if we have a printcap file; if not, don't bother writing it.
2948 if (!Printcap
|| !*Printcap
)
2951 cupsdLogMessage(CUPSD_LOG_INFO
, "Generating printcap %s...", Printcap
);
2954 * Open the printcap file...
2957 if ((fp
= cupsFileOpen(Printcap
, "w")) == NULL
)
2961 * Put a comment header at the top so that users will know where the
2962 * data has come from...
2965 if (PrintcapFormat
!= PRINTCAP_PLIST
)
2966 cupsFilePrintf(fp
, "# This file was automatically generated by cupsd(8) "
2968 "# %s/printers.conf file. All changes to this file\n"
2969 "# will be lost.\n", ServerRoot
);
2972 * Write a new printcap with the current list of printers.
2975 switch (PrintcapFormat
)
2979 * Each printer is put in the file as:
2989 cupsFilePrintf(fp
, "%s|%s:rm=%s:rp=%s:\n", DefaultPrinter
->name
,
2990 DefaultPrinter
->info
, ServerName
,
2991 DefaultPrinter
->name
);
2993 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
2995 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
2996 if (p
!= DefaultPrinter
)
2997 cupsFilePrintf(fp
, "%s|%s:rm=%s:rp=%s:\n", p
->name
, p
->info
,
2998 ServerName
, p
->name
);
3001 case PRINTCAP_PLIST
:
3003 * Each printer is written as a dictionary in a plist file.
3004 * Currently the printer-name, printer-info, printer-is-accepting-jobs,
3005 * printer-location, printer-make-and-model, printer-state,
3006 * printer-state-reasons, printer-type, and (sanitized) device-uri.
3009 cupsFilePuts(fp
, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
3010 "<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD "
3011 "PLIST 1.0//EN\" \"http://www.apple.com/DTDs/"
3012 "PropertyList-1.0.dtd\">\n"
3013 "<plist version=\"1.0\">\n"
3016 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3018 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3020 cupsFilePuts(fp
, "\t<dict>\n"
3021 "\t\t<key>printer-name</key>\n"
3023 write_xml_string(fp
, p
->name
);
3024 cupsFilePuts(fp
, "</string>\n"
3025 "\t\t<key>printer-info</key>\n"
3027 write_xml_string(fp
, p
->info
);
3028 cupsFilePrintf(fp
, "</string>\n"
3029 "\t\t<key>printer-is-accepting-jobs</key>\n"
3031 "\t\t<key>printer-location</key>\n"
3032 "\t\t<string>", p
->accepting
? "true" : "false");
3033 write_xml_string(fp
, p
->location
);
3034 cupsFilePuts(fp
, "</string>\n"
3035 "\t\t<key>printer-make-and-model</key>\n"
3037 write_xml_string(fp
, p
->make_model
);
3038 cupsFilePrintf(fp
, "</string>\n"
3039 "\t\t<key>printer-state</key>\n"
3040 "\t\t<integer>%d</integer>\n"
3041 "\t\t<key>printer-state-reasons</key>\n"
3042 "\t\t<array>\n", p
->state
);
3043 for (i
= 0; i
< p
->num_reasons
; i
++)
3045 cupsFilePuts(fp
, "\t\t\t<string>");
3046 write_xml_string(fp
, p
->reasons
[i
]);
3047 cupsFilePuts(fp
, "</string>\n");
3049 cupsFilePrintf(fp
, "\t\t</array>\n"
3050 "\t\t<key>printer-type</key>\n"
3051 "\t\t<integer>%d</integer>\n"
3052 "\t\t<key>device-uri</key>\n"
3053 "\t\t<string>", p
->type
);
3054 write_xml_string(fp
, p
->sanitized_device_uri
);
3055 cupsFilePuts(fp
, "</string>\n"
3058 cupsFilePuts(fp
, "</array>\n"
3062 case PRINTCAP_SOLARIS
:
3064 * Each printer is put in the file as:
3066 * _all:all=Printer1,Printer2,Printer3,...,PrinterN
3067 * _default:use=DefaultPrinter
3069 * :bsdaddr=ServerName,Printer1:\
3070 * :description=Description:
3072 * :bsdaddr=ServerName,Printer2:\
3073 * :description=Description:
3075 * :bsdaddr=ServerName,Printer3:\
3076 * :description=Description:
3079 * :bsdaddr=ServerName,PrinterN:\
3080 * :description=Description:
3083 cupsFilePuts(fp
, "_all:all=");
3084 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3086 p
= (cupsd_printer_t
*)cupsArrayCurrent(Printers
))
3087 cupsFilePrintf(fp
, "%s%c", p
->name
,
3088 cupsArrayNext(Printers
) ? ',' : '\n');
3091 cupsFilePrintf(fp
, "_default:use=%s\n", DefaultPrinter
->name
);
3093 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3095 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3096 cupsFilePrintf(fp
, "%s:\\\n"
3097 "\t:bsdaddr=%s,%s:\\\n"
3098 "\t:description=%s:\n",
3099 p
->name
, ServerName
, p
->name
,
3100 p
->info
? p
->info
: "");
3113 * 'add_printer_defaults()' - Add name-default attributes to the printer attributes.
3117 add_printer_defaults(cupsd_printer_t
*p
)/* I - Printer */
3119 int i
; /* Looping var */
3120 int num_options
; /* Number of default options */
3121 cups_option_t
*options
, /* Default options */
3122 *option
; /* Current option */
3123 char name
[256]; /* name-default */
3127 * Maintain a common array of default attribute names...
3130 if (!CommonDefaults
)
3132 CommonDefaults
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
3134 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("copies-default"));
3135 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("document-format-default"));
3136 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("finishings-default"));
3137 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-account-id-default"));
3138 cupsArrayAdd(CommonDefaults
,
3139 _cupsStrAlloc("job-accounting-user-id-default"));
3140 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-hold-until-default"));
3141 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-priority-default"));
3142 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-sheets-default"));
3143 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("media-col-default"));
3144 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("number-up-default"));
3145 cupsArrayAdd(CommonDefaults
,
3146 _cupsStrAlloc("orientation-requested-default"));
3150 * Add all of the default options from the .conf files...
3153 for (num_options
= 0, options
= NULL
, i
= p
->num_options
, option
= p
->options
;
3157 if (strcmp(option
->name
, "ipp-options") &&
3158 strcmp(option
->name
, "job-sheets") &&
3159 strcmp(option
->name
, "lease-duration"))
3161 snprintf(name
, sizeof(name
), "%s-default", option
->name
);
3162 num_options
= cupsAddOption(name
, option
->value
, num_options
, &options
);
3164 if (!cupsArrayFind(CommonDefaults
, name
))
3165 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc(name
));
3170 * Convert options to IPP attributes...
3173 cupsEncodeOptions2(p
->attrs
, num_options
, options
, IPP_TAG_PRINTER
);
3174 cupsFreeOptions(num_options
, options
);
3177 * Add standard -default attributes as needed...
3180 if (!cupsGetOption("copies", p
->num_options
, p
->options
))
3181 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
, "copies-default",
3184 if (!cupsGetOption("document-format", p
->num_options
, p
->options
))
3185 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_MIMETYPE
,
3186 "document-format-default", NULL
, "application/octet-stream");
3188 if (!cupsGetOption("job-hold-until", p
->num_options
, p
->options
))
3189 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3190 "job-hold-until-default", NULL
, "no-hold");
3192 if (!cupsGetOption("job-priority", p
->num_options
, p
->options
))
3193 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3194 "job-priority-default", 50);
3196 if (!cupsGetOption("number-up", p
->num_options
, p
->options
))
3197 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3198 "number-up-default", 1);
3200 if (!cupsGetOption("notify-lease-duration", p
->num_options
, p
->options
))
3201 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3202 "notify-lease-duration-default", DefaultLeaseDuration
);
3204 if (!cupsGetOption("notify-events", p
->num_options
, p
->options
))
3205 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3206 "notify-events-default", NULL
, "job-completed");
3208 if (!cupsGetOption("orientation-requested", p
->num_options
, p
->options
))
3209 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NOVALUE
,
3210 "orientation-requested-default", NULL
, NULL
);
3212 if (!cupsGetOption("print-quality", p
->num_options
, p
->options
))
3213 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
3214 "print-quality-default", IPP_QUALITY_NORMAL
);
3219 * 'add_printer_filter()' - Add a MIME filter for a printer.
3224 cupsd_printer_t
*p
, /* I - Printer to add to */
3225 mime_type_t
*filtertype
, /* I - Filter or prefilter MIME type */
3226 const char *filter
) /* I - Filter to add */
3228 char super
[MIME_MAX_SUPER
], /* Super-type for filter */
3229 type
[MIME_MAX_TYPE
], /* Type for filter */
3230 dsuper
[MIME_MAX_SUPER
], /* Destination super-type for filter */
3231 dtype
[MIME_MAX_TYPE
], /* Destination type for filter */
3232 dest
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2],
3233 /* Destination super/type */
3234 program
[1024]; /* Program/filter name */
3235 int cost
; /* Cost of filter */
3236 size_t maxsize
= 0; /* Maximum supported file size */
3237 mime_type_t
*temptype
, /* MIME type looping var */
3238 *desttype
; /* Destination MIME type */
3239 mime_filter_t
*filterptr
; /* MIME filter */
3240 char filename
[1024]; /* Full filter filename */
3243 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3244 "add_printer_filter(p=%p(%s), filtertype=%p(%s/%s), "
3245 "filter=\"%s\")", p
, p
->name
, filtertype
, filtertype
->super
,
3246 filtertype
->type
, filter
);
3249 * Parse the filter string; it should be in one of the following formats:
3251 * source/type cost program
3252 * source/type cost maxsize(nnnn) program
3253 * source/type dest/type cost program
3254 * source/type dest/type cost maxsize(nnnn) program
3257 if (sscanf(filter
, "%15[^/]/%255s%*[ \t]%15[^/]/%255s%d%*[ \t]%1023[^\n]",
3258 super
, type
, dsuper
, dtype
, &cost
, program
) == 6)
3260 snprintf(dest
, sizeof(dest
), "%s/%s/%s", p
->name
, dsuper
, dtype
);
3262 if ((desttype
= mimeType(MimeDatabase
, "printer", dest
)) == NULL
)
3264 desttype
= mimeAddType(MimeDatabase
, "printer", dest
);
3266 p
->dest_types
= cupsArrayNew(NULL
, NULL
);
3268 cupsArrayAdd(p
->dest_types
, desttype
);
3274 if (sscanf(filter
, "%15[^/]/%255s%d%*[ \t]%1023[^\n]", super
, type
, &cost
,
3277 desttype
= filtertype
;
3281 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: invalid filter string \"%s\"!",
3287 if (!strncmp(program
, "maxsize(", 8))
3289 char *ptr
; /* Pointer into maxsize(nnnn) program */
3291 maxsize
= strtoll(program
+ 8, &ptr
, 10);
3295 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: invalid filter string \"%s\"!",
3301 while (_cups_isspace(*ptr
))
3304 _cups_strcpy(program
, ptr
);
3308 * Check permissions on the filter and its containing directory...
3311 if (strcmp(program
, "-"))
3313 if (program
[0] == '/')
3314 strlcpy(filename
, program
, sizeof(filename
));
3316 snprintf(filename
, sizeof(filename
), "%s/filter/%s", ServerBin
, program
);
3318 _cupsFileCheck(filename
, _CUPS_FILE_CHECK_PROGRAM
, !RunUser
,
3319 cupsdLogFCMessage
, p
);
3323 * Add the filter to the MIME database, supporting wildcards as needed...
3326 for (temptype
= mimeFirstType(MimeDatabase
);
3328 temptype
= mimeNextType(MimeDatabase
))
3329 if (((super
[0] == '*' && _cups_strcasecmp(temptype
->super
, "printer")) ||
3330 !_cups_strcasecmp(temptype
->super
, super
)) &&
3331 (type
[0] == '*' || !_cups_strcasecmp(temptype
->type
, type
)))
3333 if (desttype
!= filtertype
)
3335 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3336 "add_printer_filter: %s: adding filter %s/%s %s/%s %d "
3337 "%s", p
->name
, temptype
->super
, temptype
->type
,
3338 desttype
->super
, desttype
->type
,
3340 filterptr
= mimeAddFilter(MimeDatabase
, temptype
, desttype
, cost
,
3343 if (!mimeFilterLookup(MimeDatabase
, desttype
, filtertype
))
3345 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3346 "add_printer_filter: %s: adding filter %s/%s %s/%s "
3347 "0 -", p
->name
, desttype
->super
, desttype
->type
,
3348 filtertype
->super
, filtertype
->type
);
3349 mimeAddFilter(MimeDatabase
, desttype
, filtertype
, 0, "-");
3354 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3355 "add_printer_filter: %s: adding filter %s/%s %s/%s %d "
3356 "%s", p
->name
, temptype
->super
, temptype
->type
,
3357 filtertype
->super
, filtertype
->type
,
3359 filterptr
= mimeAddFilter(MimeDatabase
, temptype
, filtertype
, cost
,
3364 filterptr
->maxsize
= maxsize
;
3370 * 'add_printer_formats()' - Add document-format-supported values for a printer.
3374 add_printer_formats(cupsd_printer_t
*p
) /* I - Printer */
3376 int i
; /* Looping var */
3377 mime_type_t
*type
; /* Current MIME type */
3378 cups_array_t
*filters
; /* Filters */
3379 ipp_attribute_t
*attr
; /* document-format-supported attribute */
3380 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
3381 /* MIME type name */
3385 * Raw (and remote) queues advertise all of the supported MIME
3389 cupsArrayDelete(p
->filetypes
);
3390 p
->filetypes
= NULL
;
3394 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
,
3395 (ipp_tag_t
)(IPP_TAG_MIMETYPE
| IPP_TAG_COPY
),
3396 "document-format-supported", NumMimeTypes
, NULL
, MimeTypes
);
3401 * Otherwise, loop through the supported MIME types and see if there
3402 * are filters for them...
3405 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_printer_formats: %d types, %d filters",
3406 mimeNumTypes(MimeDatabase
), mimeNumFilters(MimeDatabase
));
3408 p
->filetypes
= cupsArrayNew(NULL
, NULL
);
3410 for (type
= mimeFirstType(MimeDatabase
);
3412 type
= mimeNextType(MimeDatabase
))
3414 if (!_cups_strcasecmp(type
->super
, "printer"))
3417 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
3419 if ((filters
= mimeFilter(MimeDatabase
, type
, p
->filetype
, NULL
)) != NULL
)
3421 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3422 "add_printer_formats: %s: %s needs %d filters",
3423 p
->name
, mimetype
, cupsArrayCount(filters
));
3425 cupsArrayDelete(filters
);
3426 cupsArrayAdd(p
->filetypes
, type
);
3429 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3430 "add_printer_formats: %s: %s not supported",
3435 * Add the file formats that can be filtered...
3438 if ((type
= mimeType(MimeDatabase
, "application", "octet-stream")) == NULL
||
3439 !cupsArrayFind(p
->filetypes
, type
))
3444 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3445 "add_printer_formats: %s: %d supported types",
3446 p
->name
, cupsArrayCount(p
->filetypes
) + i
);
3448 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_MIMETYPE
,
3449 "document-format-supported",
3450 cupsArrayCount(p
->filetypes
) + i
, NULL
, NULL
);
3453 attr
->values
[0].string
.text
= _cupsStrAlloc("application/octet-stream");
3455 for (type
= (mime_type_t
*)cupsArrayFirst(p
->filetypes
);
3457 i
++, type
= (mime_type_t
*)cupsArrayNext(p
->filetypes
))
3459 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
3461 attr
->values
[i
].string
.text
= _cupsStrAlloc(mimetype
);
3464 #if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
3466 char pdl
[1024]; /* Buffer to build pdl list */
3467 mime_filter_t
*filter
; /* MIME filter looping var */
3471 * We only support raw printing if this is not a Tioga PrintJobMgr based
3472 * queue and if application/octet-stream is a known type...
3475 for (filter
= (mime_filter_t
*)cupsArrayFirst(MimeDatabase
->filters
);
3477 filter
= (mime_filter_t
*)cupsArrayNext(MimeDatabase
->filters
))
3479 if (filter
->dst
== p
->filetype
&& filter
->filter
&&
3480 strstr(filter
->filter
, "PrintJobMgr"))
3486 if (!filter
&& mimeType(MimeDatabase
, "application", "octet-stream"))
3487 strlcat(pdl
, "application/octet-stream,", sizeof(pdl
));
3490 * Then list a bunch of formats that are supported by the printer...
3493 for (type
= (mime_type_t
*)cupsArrayFirst(p
->filetypes
);
3495 type
= (mime_type_t
*)cupsArrayNext(p
->filetypes
))
3497 if (!_cups_strcasecmp(type
->super
, "application"))
3499 if (!_cups_strcasecmp(type
->type
, "pdf"))
3500 strlcat(pdl
, "application/pdf,", sizeof(pdl
));
3501 else if (!_cups_strcasecmp(type
->type
, "postscript"))
3502 strlcat(pdl
, "application/postscript,", sizeof(pdl
));
3504 else if (!_cups_strcasecmp(type
->super
, "image"))
3506 if (!_cups_strcasecmp(type
->type
, "jpeg"))
3507 strlcat(pdl
, "image/jpeg,", sizeof(pdl
));
3508 else if (!_cups_strcasecmp(type
->type
, "png"))
3509 strlcat(pdl
, "image/png,", sizeof(pdl
));
3510 else if (!_cups_strcasecmp(type
->type
, "pwg-raster"))
3511 strlcat(pdl
, "image/pwg-raster,", sizeof(pdl
));
3516 pdl
[strlen(pdl
) - 1] = '\0'; /* Remove trailing comma */
3518 cupsdSetString(&p
->pdl
, pdl
);
3520 #endif /* HAVE_DNSSD || HAVE_AVAHI */
3525 * 'compare_printers()' - Compare two printers.
3528 static int /* O - Result of comparison */
3529 compare_printers(void *first
, /* I - First printer */
3530 void *second
, /* I - Second printer */
3531 void *data
) /* I - App data (not used) */
3535 return (_cups_strcasecmp(((cupsd_printer_t
*)first
)->name
,
3536 ((cupsd_printer_t
*)second
)->name
));
3541 * 'delete_printer_filters()' - Delete all MIME filters for a printer.
3545 delete_printer_filters(
3546 cupsd_printer_t
*p
) /* I - Printer to remove from */
3548 mime_filter_t
*filter
; /* MIME filter looping var */
3549 mime_type_t
*type
; /* Destination types for filters */
3553 * Range check input...
3560 * Remove all filters from the MIME database that have a destination
3561 * type == printer...
3564 for (filter
= mimeFirstFilter(MimeDatabase
);
3566 filter
= mimeNextFilter(MimeDatabase
))
3567 if (filter
->dst
== p
->filetype
|| filter
->dst
== p
->prefiltertype
||
3568 cupsArrayFind(p
->dest_types
, filter
->dst
))
3571 * Delete the current filter...
3574 mimeDeleteFilter(MimeDatabase
, filter
);
3577 for (type
= (mime_type_t
*)cupsArrayFirst(p
->dest_types
);
3579 type
= (mime_type_t
*)cupsArrayNext(p
->dest_types
))
3580 mimeDeleteType(MimeDatabase
, type
);
3582 cupsArrayDelete(p
->dest_types
);
3583 p
->dest_types
= NULL
;
3585 cupsdSetPrinterReasons(p
, "-cups-insecure-filter-warning"
3586 ",cups-missing-filter-warning");
3591 * 'dirty_printer()' - Mark config and state files dirty for the specified
3596 dirty_printer(cupsd_printer_t
*p
) /* I - Printer */
3598 if (p
->type
& CUPS_PRINTER_CLASS
)
3599 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
3601 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
3603 if (PrintcapFormat
== PRINTCAP_PLIST
)
3604 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
3609 * 'load_ppd()' - Load a cached PPD file, updating the cache as needed.
3613 load_ppd(cupsd_printer_t
*p
) /* I - Printer */
3615 int i
, j
, k
; /* Looping vars */
3616 char cache_name
[1024]; /* Cache filename */
3617 struct stat cache_info
; /* Cache file info */
3618 ppd_file_t
*ppd
; /* PPD file */
3619 char ppd_name
[1024]; /* PPD filename */
3620 struct stat ppd_info
; /* PPD file info */
3621 int num_media
; /* Number of media options */
3622 ppd_size_t
*size
; /* Current PPD size */
3623 ppd_option_t
*duplex
, /* Duplex option */
3624 *output_bin
, /* OutputBin option */
3625 *output_mode
, /* OutputMode option */
3626 *resolution
; /* (Set|JCL|)Resolution option */
3627 ppd_choice_t
*choice
, /* Current PPD choice */
3628 *input_slot
, /* Current input slot */
3629 *media_type
; /* Current media type */
3630 ppd_attr_t
*ppd_attr
; /* PPD attribute */
3631 int xdpi
, /* Horizontal resolution */
3632 ydpi
; /* Vertical resolution */
3633 const char *resptr
; /* Pointer into resolution keyword */
3634 _pwg_size_t
*pwgsize
; /* Current PWG size */
3635 _pwg_map_t
*pwgsource
, /* Current PWG source */
3636 *pwgtype
; /* Current PWG type */
3637 ipp_attribute_t
*attr
; /* Attribute data */
3638 _ipp_value_t
*val
; /* Attribute value */
3639 int num_finishings
, /* Number of finishings */
3640 finishings
[5]; /* finishings-supported values */
3641 int num_qualities
, /* Number of print-quality values */
3642 qualities
[3]; /* print-quality values */
3643 int num_margins
, /* Number of media-*-margin-supported values */
3644 margins
[16]; /* media-*-margin-supported values */
3645 const char *filter
, /* Current filter */
3646 *mandatory
; /* Current mandatory attribute */
3647 static const char * const sides
[3] = /* sides-supported values */
3650 "two-sided-long-edge",
3651 "two-sided-short-edge"
3653 static const char * const standard_commands
[] =
3654 { /* Standard CUPS commands */
3662 * Check to see if the cache is up-to-date...
3665 snprintf(cache_name
, sizeof(cache_name
), "%s/%s.data", CacheDir
, p
->name
);
3666 if (stat(cache_name
, &cache_info
))
3667 cache_info
.st_mtime
= 0;
3669 snprintf(ppd_name
, sizeof(ppd_name
), "%s/ppd/%s.ppd", ServerRoot
, p
->name
);
3670 if (stat(ppd_name
, &ppd_info
))
3671 ppd_info
.st_mtime
= 1;
3673 ippDelete(p
->ppd_attrs
);
3674 p
->ppd_attrs
= NULL
;
3676 _ppdCacheDestroy(p
->pc
);
3679 if (cache_info
.st_mtime
>= ppd_info
.st_mtime
)
3681 cupsdLogMessage(CUPSD_LOG_DEBUG
, "load_ppd: Loading %s...", cache_name
);
3683 if ((p
->pc
= _ppdCacheCreateWithFile(cache_name
, &p
->ppd_attrs
)) != NULL
&&
3687 * Loaded successfully!
3695 * Reload PPD attributes from disk...
3698 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
3700 cupsdLogMessage(CUPSD_LOG_DEBUG
, "load_ppd: Loading %s...", ppd_name
);
3702 p
->type
&= ~CUPS_PRINTER_OPTIONS
;
3703 p
->type
|= CUPS_PRINTER_BW
;
3705 finishings
[0] = IPP_FINISHINGS_NONE
;
3708 p
->ppd_attrs
= ippNew();
3710 if ((ppd
= _ppdOpenFile(ppd_name
, _PPD_LOCALIZATION_NONE
)) != NULL
)
3713 * Add make/model and other various attributes...
3716 p
->pc
= _ppdCacheCreateWithPPD(ppd
);
3719 cupsdLogMessage(CUPSD_LOG_WARN
, "Unable to create cache of \"%s\": %s",
3720 ppd_name
, cupsLastErrorString());
3722 ppdMarkDefaults(ppd
);
3724 if (ppd
->color_device
)
3725 p
->type
|= CUPS_PRINTER_COLOR
;
3726 if (ppd
->variable_sizes
)
3727 p
->type
|= CUPS_PRINTER_VARIABLE
;
3728 if (!ppd
->manual_copies
)
3729 p
->type
|= CUPS_PRINTER_COPIES
;
3730 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsFax", NULL
)) != NULL
)
3731 if (ppd_attr
->value
&& !_cups_strcasecmp(ppd_attr
->value
, "true"))
3732 p
->type
|= CUPS_PRINTER_FAX
;
3734 ippAddBoolean(p
->ppd_attrs
, IPP_TAG_PRINTER
, "color-supported",
3737 if (p
->pc
&& p
->pc
->charge_info_uri
)
3738 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
3739 "printer-charge-info-uri", NULL
, p
->pc
->charge_info_uri
);
3741 if (p
->pc
&& p
->pc
->account_id
)
3742 ippAddBoolean(p
->ppd_attrs
, IPP_TAG_PRINTER
, "job-account-id-supported",
3745 if (p
->pc
&& p
->pc
->accounting_user_id
)
3746 ippAddBoolean(p
->ppd_attrs
, IPP_TAG_PRINTER
,
3747 "job-accounting-user-id-supported", 1);
3749 if (p
->pc
&& p
->pc
->password
)
3751 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3752 "job-password-encryption-supported", NULL
, "none");
3753 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3754 "job-password-supported", strlen(p
->pc
->password
));
3757 if (ppd
->throughput
)
3759 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3760 "pages-per-minute", ppd
->throughput
);
3761 if (ppd
->color_device
)
3762 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3763 "pages-per-minute-color", ppd
->throughput
);
3768 * When there is no speed information, just say "1 page per minute".
3771 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3772 "pages-per-minute", 1);
3773 if (ppd
->color_device
)
3774 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3775 "pages-per-minute-color", 1);
3780 if ((output_mode
= ppdFindOption(ppd
, "OutputMode")) != NULL
)
3782 if (ppdFindChoice(output_mode
, "draft") ||
3783 ppdFindChoice(output_mode
, "fast"))
3784 qualities
[num_qualities
++] = IPP_QUALITY_DRAFT
;
3786 qualities
[num_qualities
++] = IPP_QUALITY_NORMAL
;
3788 if (ppdFindChoice(output_mode
, "best") ||
3789 ppdFindChoice(output_mode
, "high"))
3790 qualities
[num_qualities
++] = IPP_QUALITY_HIGH
;
3792 else if ((ppd_attr
= ppdFindAttr(ppd
, "APPrinterPreset", NULL
)) != NULL
)
3796 if (strstr(ppd_attr
->spec
, "draft") ||
3797 strstr(ppd_attr
->spec
, "Draft"))
3799 qualities
[num_qualities
++] = IPP_QUALITY_DRAFT
;
3803 while ((ppd_attr
= ppdFindNextAttr(ppd
, "APPrinterPreset",
3806 qualities
[num_qualities
++] = IPP_QUALITY_NORMAL
;
3807 qualities
[num_qualities
++] = IPP_QUALITY_HIGH
;
3810 qualities
[num_qualities
++] = IPP_QUALITY_NORMAL
;
3812 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
3813 "print-quality-supported", num_qualities
, qualities
);
3818 * The NickName can be localized in the character set specified
3819 * by the LanugageEncoding attribute. However, ppdOpen2() has
3820 * already converted the ppd->nickname member to UTF-8 for us
3821 * (the original attribute value is available separately)
3824 cupsdSetString(&p
->make_model
, ppd
->nickname
);
3826 else if (ppd
->modelname
)
3829 * Model name can only contain specific characters...
3832 cupsdSetString(&p
->make_model
, ppd
->modelname
);
3835 cupsdSetString(&p
->make_model
, "Bad PPD File");
3837 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
3838 "printer-make-and-model", NULL
, p
->make_model
);
3841 * Add media options from the PPD file...
3844 if (ppd
->num_sizes
== 0 || !p
->pc
)
3846 if (!ppdFindAttr(ppd
, "APScannerOnly", NULL
))
3847 cupsdLogMessage(CUPSD_LOG_CRIT
,
3848 "The PPD file for printer %s contains no media "
3849 "options and is therefore invalid!", p
->name
);
3851 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3852 "media-default", NULL
, "unknown");
3853 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3854 "media-supported", NULL
, "unknown");
3862 if ((size
= ppdPageSize(ppd
, NULL
)) != NULL
)
3863 pwgsize
= _ppdCacheGetSize(p
->pc
, size
->name
);
3867 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3868 "media-default", NULL
,
3869 pwgsize
? pwgsize
->map
.pwg
: "unknown");
3877 ipp_t
*col
; /* Collection value */
3879 input_slot
= ppdFindMarkedChoice(ppd
, "InputSlot");
3880 media_type
= ppdFindMarkedChoice(ppd
, "MediaType");
3881 col
= new_media_col(pwgsize
,
3883 _ppdCacheGetSource(p
->pc
,
3884 input_slot
->choice
) :
3887 _ppdCacheGetType(p
->pc
,
3888 media_type
->choice
) :
3891 ippAddCollection(p
->ppd_attrs
, IPP_TAG_PRINTER
, "media-col-default",
3900 num_media
= p
->pc
->num_sizes
;
3901 if (p
->pc
->custom_min_keyword
)
3904 if ((attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3905 "media-supported", num_media
, NULL
,
3910 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
;
3912 i
--, pwgsize
++, val
++)
3913 val
->string
.text
= _cupsStrAlloc(pwgsize
->map
.pwg
);
3915 if (p
->pc
->custom_min_keyword
)
3917 val
->string
.text
= _cupsStrAlloc(p
->pc
->custom_min_keyword
);
3919 val
->string
.text
= _cupsStrAlloc(p
->pc
->custom_max_keyword
);
3924 * media-size-supported
3927 num_media
= p
->pc
->num_sizes
;
3928 if (p
->pc
->custom_min_keyword
)
3931 if ((attr
= ippAddCollections(p
->ppd_attrs
, IPP_TAG_PRINTER
,
3932 "media-size-supported", num_media
,
3937 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
;
3939 i
--, pwgsize
++, val
++)
3941 val
->collection
= ippNew();
3942 ippAddInteger(val
->collection
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3943 "x-dimension", pwgsize
->width
);
3944 ippAddInteger(val
->collection
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3945 "y-dimension", pwgsize
->length
);
3948 if (p
->pc
->custom_min_keyword
)
3950 val
->collection
= ippNew();
3951 ippAddRange(val
->collection
, IPP_TAG_PRINTER
, "x-dimension",
3952 p
->pc
->custom_min_width
, p
->pc
->custom_max_width
);
3953 ippAddRange(val
->collection
, IPP_TAG_PRINTER
, "y-dimension",
3954 p
->pc
->custom_min_length
, p
->pc
->custom_max_length
);
3959 * media-source-supported
3962 if (p
->pc
->num_sources
> 0 &&
3963 (attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3964 "media-source-supported", p
->pc
->num_sources
,
3965 NULL
, NULL
)) != NULL
)
3967 for (i
= p
->pc
->num_sources
, pwgsource
= p
->pc
->sources
,
3970 i
--, pwgsource
++, val
++)
3971 val
->string
.text
= _cupsStrAlloc(pwgsource
->pwg
);
3975 * media-type-supported
3978 if (p
->pc
->num_types
> 0 &&
3979 (attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3980 "media-type-supported", p
->pc
->num_types
,
3981 NULL
, NULL
)) != NULL
)
3983 for (i
= p
->pc
->num_types
, pwgtype
= p
->pc
->types
,
3986 i
--, pwgtype
++, val
++)
3987 val
->string
.text
= _cupsStrAlloc(pwgtype
->pwg
);
3991 * media-*-margin-supported
3994 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, num_margins
= 0;
3995 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
3998 for (j
= 0; j
< num_margins
; j
++)
3999 if (pwgsize
->bottom
== margins
[j
])
4002 if (j
>= num_margins
)
4004 margins
[num_margins
] = pwgsize
->bottom
;
4009 if (num_margins
> 0)
4010 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4011 "media-bottom-margin-supported", num_margins
, margins
);
4013 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4014 "media-bottom-margin-supported", 0);
4016 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, num_margins
= 0;
4017 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4020 for (j
= 0; j
< num_margins
; j
++)
4021 if (pwgsize
->left
== margins
[j
])
4024 if (j
>= num_margins
)
4026 margins
[num_margins
] = pwgsize
->left
;
4031 if (num_margins
> 0)
4032 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4033 "media-left-margin-supported", num_margins
, margins
);
4035 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4036 "media-left-margin-supported", 0);
4038 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, num_margins
= 0;
4039 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4042 for (j
= 0; j
< num_margins
; j
++)
4043 if (pwgsize
->right
== margins
[j
])
4046 if (j
>= num_margins
)
4048 margins
[num_margins
] = pwgsize
->right
;
4053 if (num_margins
> 0)
4054 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4055 "media-right-margin-supported", num_margins
, margins
);
4057 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4058 "media-right-margin-supported", 0);
4060 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, num_margins
= 0;
4061 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4064 for (j
= 0; j
< num_margins
; j
++)
4065 if (pwgsize
->top
== margins
[j
])
4068 if (j
>= num_margins
)
4070 margins
[num_margins
] = pwgsize
->top
;
4075 if (num_margins
> 0)
4076 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4077 "media-top-margin-supported", num_margins
, margins
);
4079 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4080 "media-top-margin-supported", 0);
4083 * media-col-database
4086 num_media
= p
->pc
->num_sizes
;
4087 if (p
->pc
->num_sources
)
4089 if (p
->pc
->num_types
> 0)
4090 num_media
+= p
->pc
->num_sizes
* p
->pc
->num_sources
*
4093 num_media
+= p
->pc
->num_sizes
* p
->pc
->num_sources
;
4095 else if (p
->pc
->num_types
)
4096 num_media
+= p
->pc
->num_sizes
* p
->pc
->num_types
;
4098 if ((attr
= ippAddCollections(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4099 "media-col-database", num_media
,
4102 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, val
= attr
->values
;
4107 * Start by adding the page size without source or type...
4110 ppdMarkOption(ppd
, "PageSize", pwgsize
->map
.ppd
);
4112 val
->collection
= new_media_col(pwgsize
, NULL
, NULL
);
4116 * Then add the specific, supported combinations of size, source, and
4120 if (p
->pc
->num_sources
> 0)
4122 for (j
= p
->pc
->num_sources
, pwgsource
= p
->pc
->sources
;
4126 ppdMarkOption(ppd
, "InputSlot", pwgsource
->ppd
);
4128 if (p
->pc
->num_types
> 0)
4130 for (k
= p
->pc
->num_types
, pwgtype
= p
->pc
->types
;
4134 if (!ppdMarkOption(ppd
, "MediaType", pwgtype
->ppd
))
4136 val
->collection
= new_media_col(pwgsize
, pwgsource
->pwg
,
4142 else if (!ppdConflicts(ppd
))
4144 val
->collection
= new_media_col(pwgsize
, pwgsource
->pwg
, NULL
);
4149 else if (p
->pc
->num_types
> 0)
4151 for (j
= p
->pc
->num_types
, pwgtype
= p
->pc
->types
;
4155 if (!ppdMarkOption(ppd
, "MediaType", pwgtype
->ppd
))
4157 val
->collection
= new_media_col(pwgsize
, NULL
, pwgtype
->pwg
);
4165 * Update the number of media-col-database values...
4168 attr
->num_values
= val
- attr
->values
;
4176 if (p
->pc
&& p
->pc
->num_bins
> 0)
4178 attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4179 "output-bin-supported", p
->pc
->num_bins
,
4184 for (i
= 0, val
= attr
->values
;
4185 i
< p
->pc
->num_bins
;
4187 val
->string
.text
= _cupsStrAlloc(p
->pc
->bins
[i
].pwg
);
4190 if ((output_bin
= ppdFindOption(ppd
, "OutputBin")) != NULL
)
4192 for (i
= 0; i
< p
->pc
->num_bins
; i
++)
4193 if (!strcmp(p
->pc
->bins
[i
].ppd
, output_bin
->defchoice
))
4196 if (i
>= p
->pc
->num_bins
)
4199 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4200 "output-bin-default", NULL
, p
->pc
->bins
[i
].pwg
);
4203 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4204 "output-bin-default", NULL
, p
->pc
->bins
[0].pwg
);
4206 else if (((ppd_attr
= ppdFindAttr(ppd
, "DefaultOutputOrder",
4208 !_cups_strcasecmp(ppd_attr
->value
, "Reverse")) ||
4209 (!ppd_attr
&& ppd
->manufacturer
&& /* "Compatibility heuristic" */
4210 (!_cups_strcasecmp(ppd
->manufacturer
, "epson") ||
4211 !_cups_strcasecmp(ppd
->manufacturer
, "lexmark"))))
4214 * Report that this printer has a single output bin that leaves pages face
4218 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4219 "output-bin-supported", NULL
, "face-up");
4220 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4221 "output-bin-default", NULL
, "face-up");
4225 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4226 "output-bin-supported", NULL
, "face-down");
4227 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4228 "output-bin-default", NULL
, "face-down");
4232 * print-color-mode...
4235 if (ppd
->color_device
)
4237 static const char * const color_modes
[] =
4243 ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4244 "print-color-mode-supported", 2, NULL
, color_modes
);
4245 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4246 "print-color-mode-default", NULL
, "color");
4250 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4251 "print-color-mode-supported", NULL
, "monochrome");
4252 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4253 "print-color-mode-default", NULL
, "monochrome");
4257 * Mandatory job attributes, if any...
4260 if (p
->pc
&& cupsArrayCount(p
->pc
->mandatory
) > 0)
4262 int count
= cupsArrayCount(p
->pc
->mandatory
);
4263 /* Number of mandatory attributes */
4265 attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4266 "printer-mandatory-job-attributes", count
, NULL
,
4269 for (val
= attr
->values
,
4270 mandatory
= (char *)cupsArrayFirst(p
->pc
->mandatory
);
4272 val
++, mandatory
= (char *)cupsArrayNext(p
->pc
->mandatory
))
4273 val
->string
.text
= _cupsStrAlloc(mandatory
);
4277 * Printer resolutions...
4280 if ((resolution
= ppdFindOption(ppd
, "Resolution")) == NULL
)
4281 if ((resolution
= ppdFindOption(ppd
, "JCLResolution")) == NULL
)
4282 if ((resolution
= ppdFindOption(ppd
, "SetResolution")) == NULL
)
4283 resolution
= ppdFindOption(ppd
, "CNRes_PGP");
4288 * Report all supported resolutions...
4291 attr
= ippAddResolutions(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4292 "printer-resolution-supported",
4293 resolution
->num_choices
, IPP_RES_PER_INCH
,
4296 for (i
= 0, choice
= resolution
->choices
;
4297 i
< resolution
->num_choices
;
4300 xdpi
= ydpi
= (int)strtol(choice
->choice
, (char **)&resptr
, 10);
4301 if (resptr
> choice
->choice
&& xdpi
> 0 && *resptr
== 'x')
4302 ydpi
= (int)strtol(resptr
+ 1, (char **)&resptr
, 10);
4304 if (xdpi
<= 0 || ydpi
<= 0)
4306 cupsdLogMessage(CUPSD_LOG_WARN
,
4307 "Bad resolution \"%s\" for printer %s.",
4308 choice
->choice
, p
->name
);
4312 attr
->values
[i
].resolution
.xres
= xdpi
;
4313 attr
->values
[i
].resolution
.yres
= ydpi
;
4314 attr
->values
[i
].resolution
.units
= IPP_RES_PER_INCH
;
4317 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4318 "printer-resolution-default", IPP_RES_PER_INCH
,
4322 else if ((ppd_attr
= ppdFindAttr(ppd
, "DefaultResolution", NULL
)) != NULL
&&
4326 * Just the DefaultResolution to report...
4329 xdpi
= ydpi
= (int)strtol(ppd_attr
->value
, (char **)&resptr
, 10);
4330 if (resptr
> ppd_attr
->value
&& xdpi
> 0)
4333 ydpi
= (int)strtol(resptr
+ 1, (char **)&resptr
, 10);
4338 if (xdpi
<= 0 || ydpi
<= 0)
4340 cupsdLogMessage(CUPSD_LOG_WARN
,
4341 "Bad default resolution \"%s\" for printer %s.",
4342 ppd_attr
->value
, p
->name
);
4346 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4347 "printer-resolution-default", IPP_RES_PER_INCH
,
4349 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4350 "printer-resolution-supported", IPP_RES_PER_INCH
,
4356 * No resolutions in PPD - make one up...
4359 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4360 "printer-resolution-default", IPP_RES_PER_INCH
,
4362 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4363 "printer-resolution-supported", IPP_RES_PER_INCH
,
4371 ppdMarkDefaults(ppd
);
4373 if ((duplex
= ppdFindOption(ppd
, "Duplex")) == NULL
)
4374 if ((duplex
= ppdFindOption(ppd
, "EFDuplex")) == NULL
)
4375 if ((duplex
= ppdFindOption(ppd
, "EFDuplexing")) == NULL
)
4376 if ((duplex
= ppdFindOption(ppd
, "KD03Duplex")) == NULL
)
4377 duplex
= ppdFindOption(ppd
, "JCLDuplex");
4379 if (duplex
&& duplex
->num_choices
> 1 &&
4380 !ppdInstallableConflict(ppd
, duplex
->keyword
, "DuplexTumble"))
4382 p
->type
|= CUPS_PRINTER_DUPLEX
;
4384 ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4385 "sides-supported", 3, NULL
, sides
);
4387 if (!_cups_strcasecmp(duplex
->defchoice
, "DuplexTumble"))
4388 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4389 "sides-default", NULL
, "two-sided-short-edge");
4390 else if (!_cups_strcasecmp(duplex
->defchoice
, "DuplexNoTumble"))
4391 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4392 "sides-default", NULL
, "two-sided-long-edge");
4394 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4395 "sides-default", NULL
, "one-sided");
4399 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4400 "sides-supported", NULL
, "one-sided");
4401 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4402 "sides-default", NULL
, "one-sided");
4405 if (ppdFindOption(ppd
, "Collate") != NULL
)
4406 p
->type
|= CUPS_PRINTER_COLLATE
;
4408 if (ppdFindOption(ppd
, "StapleLocation") != NULL
)
4410 p
->type
|= CUPS_PRINTER_STAPLE
;
4411 finishings
[num_finishings
++] = IPP_FINISHINGS_STAPLE
;
4414 if (ppdFindOption(ppd
, "BindEdge") != NULL
)
4416 p
->type
|= CUPS_PRINTER_BIND
;
4417 finishings
[num_finishings
++] = IPP_FINISHINGS_BIND
;
4420 for (i
= 0; i
< ppd
->num_sizes
; i
++)
4421 if (ppd
->sizes
[i
].length
> 1728)
4422 p
->type
|= CUPS_PRINTER_LARGE
;
4423 else if (ppd
->sizes
[i
].length
> 1008)
4424 p
->type
|= CUPS_PRINTER_MEDIUM
;
4426 p
->type
|= CUPS_PRINTER_SMALL
;
4428 if ((ppd_attr
= ppdFindAttr(ppd
, "APICADriver", NULL
)) != NULL
&&
4429 ppd_attr
->value
&& !_cups_strcasecmp(ppd_attr
->value
, "true"))
4431 if ((ppd_attr
= ppdFindAttr(ppd
, "APScannerOnly", NULL
)) != NULL
&&
4432 ppd_attr
->value
&& !_cups_strcasecmp(ppd_attr
->value
, "true"))
4433 p
->type
|= CUPS_PRINTER_SCANNER
;
4435 p
->type
|= CUPS_PRINTER_MFP
;
4439 * Scan the filters in the PPD file...
4444 for (filter
= (const char *)cupsArrayFirst(p
->pc
->filters
);
4446 filter
= (const char *)cupsArrayNext(p
->pc
->filters
))
4448 if (!_cups_strncasecmp(filter
, "application/vnd.cups-command", 28) &&
4449 _cups_isspace(filter
[28]))
4451 p
->type
|= CUPS_PRINTER_COMMANDS
;
4457 if (p
->type
& CUPS_PRINTER_COMMANDS
)
4459 char *commands
, /* Copy of commands */
4460 *start
, /* Start of name */
4461 *end
; /* End of name */
4462 int count
; /* Number of commands */
4464 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsCommands", NULL
)) != NULL
)
4466 for (count
= 0, start
= ppd_attr
->value
; *start
; count
++)
4468 while (_cups_isspace(*start
))
4474 while (*start
&& !isspace(*start
& 255))
4484 * Make a copy of the commands string and count how many commands there
4488 attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4489 "printer-commands", count
, NULL
, NULL
);
4491 commands
= strdup(ppd_attr
->value
);
4493 for (count
= 0, start
= commands
; *start
; count
++)
4495 while (isspace(*start
& 255))
4502 while (*end
&& !isspace(*end
& 255))
4508 attr
->values
[count
].string
.text
= _cupsStrAlloc(start
);
4518 * Add the standard list of commands...
4521 ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4523 (int)(sizeof(standard_commands
) /
4524 sizeof(standard_commands
[0])), NULL
,
4531 * No commands supported...
4534 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4535 "printer-commands", NULL
, "none");
4539 * Show current and available port monitors for this printer...
4542 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
, "port-monitor",
4543 NULL
, p
->port_monitor
? p
->port_monitor
: "none");
4545 for (i
= 1, ppd_attr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
4547 i
++, ppd_attr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
));
4551 if (strstr(ppd
->protocols
, "TBCP"))
4553 else if (strstr(ppd
->protocols
, "BCP"))
4557 attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
4558 "port-monitor-supported", i
, NULL
, NULL
);
4560 attr
->values
[0].string
.text
= _cupsStrAlloc("none");
4562 for (i
= 1, ppd_attr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
4564 i
++, ppd_attr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
))
4565 attr
->values
[i
].string
.text
= _cupsStrAlloc(ppd_attr
->value
);
4569 if (strstr(ppd
->protocols
, "TBCP"))
4570 attr
->values
[i
].string
.text
= _cupsStrAlloc("tbcp");
4571 else if (strstr(ppd
->protocols
, "BCP"))
4572 attr
->values
[i
].string
.text
= _cupsStrAlloc("bcp");
4575 if (ppdFindAttr(ppd
, "APRemoteQueueID", NULL
))
4576 p
->type
|= CUPS_PRINTER_REMOTE
;
4578 #ifdef HAVE_APPLICATIONSERVICES_H
4580 * Convert the file referenced in APPrinterIconPath to a 128x128 PNG
4581 * and save it as cacheDir/printername.png
4584 if ((ppd_attr
= ppdFindAttr(ppd
, "APPrinterIconPath", NULL
)) != NULL
&&
4586 !_cupsFileCheck(ppd_attr
->value
, _CUPS_FILE_CHECK_FILE
, !RunUser
,
4587 cupsdLogFCMessage
, p
))
4589 CGImageRef imageRef
= NULL
;/* Current icon image */
4590 CGImageRef biggestIconRef
= NULL
;
4591 /* Biggest icon image */
4592 CGImageRef closestTo128IconRef
= NULL
;
4593 /* Icon image closest to and >= 128 */
4594 CGImageSourceRef sourceRef
; /* The file's image source */
4595 char outPath
[HTTP_MAX_URI
];
4596 /* The path to the PNG file */
4597 CFURLRef outUrl
; /* The URL made from the outPath */
4598 CFURLRef icnsFileUrl
; /* The URL of the original ICNS icon file */
4599 CGImageDestinationRef destRef
; /* The image destination to write */
4600 size_t bytesPerRow
; /* The bytes per row used for resizing */
4601 CGContextRef context
; /* The CG context used for resizing */
4603 snprintf(outPath
, sizeof(outPath
), "%s/%s.png", CacheDir
, p
->name
);
4604 outUrl
= CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault
,
4608 icnsFileUrl
= CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault
,
4609 (UInt8
*)ppd_attr
->value
,
4610 strlen(ppd_attr
->value
),
4612 if (outUrl
&& icnsFileUrl
)
4614 sourceRef
= CGImageSourceCreateWithURL(icnsFileUrl
, NULL
);
4617 for (i
= 0; i
< CGImageSourceGetCount(sourceRef
); i
++)
4619 imageRef
= CGImageSourceCreateImageAtIndex(sourceRef
, i
, NULL
);
4623 if (CGImageGetWidth(imageRef
) == CGImageGetHeight(imageRef
))
4626 * Loop through remembering the icon closest to 128 but >= 128
4627 * and then remember the largest icon.
4630 if (CGImageGetWidth(imageRef
) >= 128 &&
4631 (!closestTo128IconRef
||
4632 CGImageGetWidth(imageRef
) <
4633 CGImageGetWidth(closestTo128IconRef
)))
4635 CGImageRelease(closestTo128IconRef
);
4636 CGImageRetain(imageRef
);
4637 closestTo128IconRef
= imageRef
;
4640 if (!biggestIconRef
||
4641 CGImageGetWidth(imageRef
) > CGImageGetWidth(biggestIconRef
))
4643 CGImageRelease(biggestIconRef
);
4644 CGImageRetain(imageRef
);
4645 biggestIconRef
= imageRef
;
4649 CGImageRelease(imageRef
);
4655 * If biggestIconRef is NULL, we found no icons. Otherwise we first
4656 * want the closest to 128, but if none are larger than 128, we want
4657 * the largest icon available.
4660 imageRef
= closestTo128IconRef
? closestTo128IconRef
:
4662 CGImageRetain(imageRef
);
4663 CGImageRelease(biggestIconRef
);
4664 if (closestTo128IconRef
)
4665 CGImageRelease(closestTo128IconRef
);
4666 destRef
= CGImageDestinationCreateWithURL(outUrl
, kUTTypePNG
, 1,
4670 if (CGImageGetWidth(imageRef
) != 128)
4672 bytesPerRow
= CGImageGetBytesPerRow(imageRef
) /
4673 CGImageGetWidth(imageRef
) * 128;
4674 context
= CGBitmapContextCreate(NULL
, 128, 128,
4675 CGImageGetBitsPerComponent(imageRef
),
4677 CGImageGetColorSpace(imageRef
),
4678 kCGImageAlphaPremultipliedFirst
);
4681 CGContextDrawImage(context
, CGRectMake(0, 0, 128, 128),
4683 CGImageRelease(imageRef
);
4684 imageRef
= CGBitmapContextCreateImage(context
);
4685 CGContextRelease(context
);
4689 CGImageDestinationAddImage(destRef
, imageRef
, NULL
);
4690 CGImageDestinationFinalize(destRef
);
4694 CGImageRelease(imageRef
);
4697 CFRelease(sourceRef
);
4705 CFRelease(icnsFileUrl
);
4707 #endif /* HAVE_APPLICATIONSERVICES_H */
4710 * Close the PPD and set the type...
4715 else if (!access(ppd_name
, 0))
4717 int pline
; /* PPD line number */
4718 ppd_status_t pstatus
; /* PPD load status */
4721 pstatus
= ppdLastError(&pline
);
4723 cupsdLogMessage(CUPSD_LOG_ERROR
, "PPD file for %s cannot be loaded!",
4726 if (pstatus
<= PPD_ALLOC_ERROR
)
4727 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s", strerror(errno
));
4729 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s on line %d.",
4730 ppdErrorString(pstatus
), pline
);
4732 cupsdLogMessage(CUPSD_LOG_INFO
,
4733 "Hint: Run \"cupstestppd %s\" and fix any errors.",
4739 * If we have an interface script, add a filter entry for it...
4742 char interface
[1024]; /* Interface script */
4745 snprintf(interface
, sizeof(interface
), "%s/interfaces/%s", ServerRoot
,
4747 if (!access(interface
, X_OK
))
4750 * Yes, we have a System V style interface script; use it!
4753 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
4754 "printer-make-and-model", NULL
,
4755 "Local System V Printer");
4757 else if (((!strncmp(p
->device_uri
, "ipp://", 6) ||
4758 !strncmp(p
->device_uri
, "ipps://", 7)) &&
4759 (strstr(p
->device_uri
, "/printers/") != NULL
||
4760 strstr(p
->device_uri
, "/classes/") != NULL
)) ||
4761 ((strstr(p
->device_uri
, "._ipp.") != NULL
||
4762 strstr(p
->device_uri
, "._ipps.") != NULL
) &&
4763 !strcmp(p
->device_uri
+ strlen(p
->device_uri
) - 5, "/cups")))
4766 * Tell the client this is really a hard-wired remote printer.
4769 p
->type
|= CUPS_PRINTER_REMOTE
;
4772 * Point the printer-uri-supported attribute to the
4776 if (strchr(p
->device_uri
, '?'))
4779 * Strip trailing "?options" from URI...
4782 char resource
[HTTP_MAX_URI
], /* New URI */
4783 *ptr
; /* Pointer into URI */
4785 strlcpy(resource
, p
->device_uri
, sizeof(resource
));
4786 if ((ptr
= strchr(resource
, '?')) != NULL
)
4789 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
4790 "printer-uri-supported", NULL
, resource
);
4793 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
4794 "printer-uri-supported", NULL
, p
->device_uri
);
4797 * Then set the make-and-model accordingly...
4800 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
4801 "printer-make-and-model", NULL
, "Remote Printer");
4804 * Print all files directly...
4813 * Otherwise we have neither - treat this as a "dumb" printer
4814 * with no PPD file...
4817 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
4818 "printer-make-and-model", NULL
, "Local Raw Printer");
4824 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
4825 "finishings-supported", num_finishings
, finishings
);
4826 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
4827 "finishings-default", IPP_FINISHINGS_NONE
);
4832 * Save cached PPD attributes to disk...
4835 cupsdLogMessage(CUPSD_LOG_DEBUG
, "load_ppd: Saving %s...", cache_name
);
4837 _ppdCacheWriteFile(p
->pc
, cache_name
, p
->ppd_attrs
);
4842 * Remove cache files...
4845 if (cache_info
.st_mtime
)
4852 * 'log_ipp_conformance()' - Log an IPP conformance issue with a printer.
4856 log_ipp_conformance(
4857 cupsd_printer_t
*p
, /* I - Printer */
4858 const char *reason
) /* I - Printer state reason */
4860 const char *message
; /* Message to log */
4862 aslmsg aslm
; /* Apple System Log message */
4863 #endif /* __APPLE__ */
4867 * Strip the leading "cups-ipp-" from the reason and create a log message for
4872 if (!strcmp(reason
, "missing-cancel-job"))
4873 message
= "Printer does not support REQUIRED Cancel-Job operation.";
4874 else if (!strcmp(reason
, "missing-get-job-attributes"))
4875 message
= "Printer does not support REQUIRED Get-Job-Attributes operation.";
4876 else if (!strcmp(reason
, "missing-print-job"))
4877 message
= "Printer does not support REQUIRED Print-Job operation.";
4878 else if (!strcmp(reason
, "missing-validate-job"))
4879 message
= "Printer does not support REQUIRED Validate-Job operation.";
4880 else if (!strcmp(reason
, "missing-get-printer-attributes"))
4881 message
= "Printer does not support REQUIRED Get-Printer-Attributes operation.";
4882 else if (!strcmp(reason
, "missing-send-document"))
4883 message
= "Printer supports Create-Job but not Send-Document operation.";
4884 else if (!strcmp(reason
, "missing-job-history"))
4885 message
= "Printer does not provide REQUIRED job history.";
4886 else if (!strcmp(reason
, "missing-job-id"))
4887 message
= "Printer does not provide REQUIRED job-id attribute.";
4888 else if (!strcmp(reason
, "missing-job-state"))
4889 message
= "Printer does not provide REQUIRED job-state attribute.";
4890 else if (!strcmp(reason
, "missing-operations-supported"))
4891 message
= "Printer does not provide REQUIRED operations-supported "
4893 else if (!strcmp(reason
, "missing-printer-is-accepting-jobs"))
4894 message
= "Printer does not provide REQUIRED printer-is-accepting-jobs "
4896 else if (!strcmp(reason
, "missing-printer-state-reasons"))
4897 message
= "Printer does not provide REQUIRED printer-state-reasons "
4899 else if (!strcmp(reason
, "wrong-http-version"))
4900 message
= "Printer does not use REQUIRED HTTP/1.1 transport.";
4902 message
= "Unknown IPP conformance failure.";
4904 cupsdLogMessage(CUPSD_LOG_WARN
, "%s: %s", p
->name
, message
);
4908 * Report the failure information to Apple if the user opts into providing
4909 * feedback to Apple...
4912 aslm
= asl_new(ASL_TYPE_MSG
);
4915 asl_set(aslm
, "com.apple.message.domain", "com.apple.printing.ipp.conformance");
4916 asl_set(aslm
, "com.apple.message.domain_scope", "com.apple.printing.ipp.conformance");
4917 asl_set(aslm
, "com.apple.message.signature", reason
);
4918 asl_set(aslm
, "com.apple.message.signature2",
4919 p
->make_model
? p
->make_model
: "Unknown");
4920 asl_log(NULL
, aslm
, ASL_LEVEL_NOTICE
, "%s: %s",
4921 p
->make_model
? p
->make_model
: "Unknown", message
);
4924 #endif /* __APPLE__ */
4929 * 'new_media_col()' - Create a media-col collection value.
4932 static ipp_t
* /* O - Collection value */
4933 new_media_col(_pwg_size_t
*size
, /* I - media-size/margin values */
4934 const char *source
, /* I - media-source value */
4935 const char *type
) /* I - media-type value */
4937 ipp_t
*media_col
, /* Collection value */
4938 *media_size
; /* media-size value */
4941 media_col
= ippNew();
4943 media_size
= ippNew();
4944 ippAddInteger(media_size
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4945 "x-dimension", size
->width
);
4946 ippAddInteger(media_size
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4947 "y-dimension", size
->length
);
4948 ippAddCollection(media_col
, IPP_TAG_PRINTER
, "media-size", media_size
);
4949 ippDelete(media_size
);
4951 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4952 "media-bottom-margin", size
->bottom
);
4953 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4954 "media-left-margin", size
->left
);
4955 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4956 "media-right-margin", size
->right
);
4957 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4958 "media-top-margin", size
->top
);
4961 ippAddString(media_col
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
, "media-source",
4965 ippAddString(media_col
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
, "media-type",
4973 * 'write_xml_string()' - Write a string with XML escaping.
4977 write_xml_string(cups_file_t
*fp
, /* I - File to write to */
4978 const char *s
) /* I - String to write */
4980 const char *start
; /* Start of current sequence */
4986 for (start
= s
; *s
; s
++)
4991 cupsFileWrite(fp
, start
, s
- start
);
4993 cupsFilePuts(fp
, "&");
4999 cupsFileWrite(fp
, start
, s
- start
);
5001 cupsFilePuts(fp
, "<");
5007 cupsFilePuts(fp
, start
);