2 * "$Id: printers.c 11418 2013-11-08 15:18:01Z msweet $"
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
,
1910 cupsdLogMessage(CUPSD_LOG_ERROR
,
1911 "Unable to allocate memory for printer attribute "
1912 "(%d values)", count
);
1916 for (i
= 0, start
= temp
; i
< count
; i
++)
1918 if ((ptr
= strchr(start
, ',')) != NULL
)
1921 attr
->values
[i
].integer
= strtol(start
, NULL
, 10);
1930 * Name or keyword values...
1933 if (!strcmp(name
, "marker-types"))
1934 value_tag
= IPP_TAG_KEYWORD
;
1935 else if (!strcmp(name
, "marker-message"))
1936 value_tag
= IPP_TAG_TEXT
;
1938 value_tag
= IPP_TAG_NAME
;
1940 if ((attr
= ippFindAttribute(p
->attrs
, name
, value_tag
)) != NULL
&&
1941 attr
->num_values
< count
)
1943 ippDeleteAttribute(p
->attrs
, attr
);
1949 for (i
= 0; i
< attr
->num_values
; i
++)
1950 _cupsStrFree(attr
->values
[i
].string
.text
);
1952 attr
->num_values
= count
;
1955 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, value_tag
, name
,
1961 cupsdLogMessage(CUPSD_LOG_ERROR
,
1962 "Unable to allocate memory for printer attribute "
1963 "(%d values)", count
);
1967 for (i
= 0, quote
= '\0', ptr
= temp
; i
< count
; i
++)
1969 for (start
= ptr
; *ptr
; ptr
++)
1972 *ptr
= quote
= '\0';
1975 else if (*ptr
== '\\' && ptr
[1])
1976 _cups_strcpy(ptr
, ptr
+ 1);
1977 else if (*ptr
== '\'' || *ptr
== '\"')
1984 _cups_strcpy(ptr
, ptr
+ 1);
1986 else if (*ptr
== ',')
1993 attr
->values
[i
].string
.text
= _cupsStrAlloc(start
);
2002 * 'cupsdSetPrinterAttrs()' - Set printer attributes based upon the PPD file.
2006 cupsdSetPrinterAttrs(cupsd_printer_t
*p
)/* I - Printer to setup */
2008 int i
; /* Looping var */
2009 char resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
2010 cupsd_location_t
*auth
; /* Pointer to authentication element */
2011 const char *auth_supported
; /* Authentication supported */
2012 ipp_t
*oldattrs
; /* Old printer attributes */
2013 ipp_attribute_t
*attr
; /* Attribute data */
2014 char *name
, /* Current user/group name */
2015 *filter
; /* Current filter */
2018 DEBUG_printf(("cupsdSetPrinterAttrs: entering name = %s, type = %x\n", p
->name
,
2022 * Make sure that we have the common attributes defined...
2026 cupsdCreateCommonData();
2029 * Clear out old filters, if any...
2032 delete_printer_filters(p
);
2035 * Figure out the authentication that is required for the printer.
2038 auth_supported
= "requesting-user-name";
2040 if (p
->type
& CUPS_PRINTER_CLASS
)
2041 snprintf(resource
, sizeof(resource
), "/classes/%s", p
->name
);
2043 snprintf(resource
, sizeof(resource
), "/printers/%s", p
->name
);
2045 if ((auth
= cupsdFindBest(resource
, HTTP_POST
)) == NULL
||
2046 auth
->type
== CUPSD_AUTH_NONE
)
2047 auth
= cupsdFindPolicyOp(p
->op_policy_ptr
, IPP_PRINT_JOB
);
2051 int auth_type
; /* Authentication type */
2054 if ((auth_type
= auth
->type
) == CUPSD_AUTH_DEFAULT
)
2055 auth_type
= cupsdDefaultAuthType();
2057 if (auth_type
== CUPSD_AUTH_BASIC
|| auth_type
== CUPSD_AUTH_BASICDIGEST
)
2058 auth_supported
= "basic";
2059 else if (auth_type
== CUPSD_AUTH_DIGEST
)
2060 auth_supported
= "digest";
2062 else if (auth_type
== CUPSD_AUTH_NEGOTIATE
)
2063 auth_supported
= "negotiate";
2064 #endif /* HAVE_GSSAPI */
2066 if (auth_type
!= CUPSD_AUTH_NONE
)
2067 p
->type
|= CUPS_PRINTER_AUTHENTICATED
;
2069 p
->type
&= ~CUPS_PRINTER_AUTHENTICATED
;
2072 p
->type
&= ~CUPS_PRINTER_AUTHENTICATED
;
2075 * Create the required IPP attributes for a printer...
2078 oldattrs
= p
->attrs
;
2079 p
->attrs
= ippNew();
2081 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2082 "uri-authentication-supported", NULL
, auth_supported
);
2083 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2084 "uri-security-supported", NULL
, "none");
2085 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
, "printer-name", NULL
,
2087 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-location",
2088 NULL
, p
->location
? p
->location
: "");
2089 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-info",
2090 NULL
, p
->info
? p
->info
: "");
2091 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "printer-uuid", NULL
,
2094 if (cupsArrayCount(p
->users
) > 0)
2097 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2098 "requesting-user-name-denied",
2099 cupsArrayCount(p
->users
), NULL
, NULL
);
2101 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2102 "requesting-user-name-allowed",
2103 cupsArrayCount(p
->users
), NULL
, NULL
);
2105 for (i
= 0, name
= (char *)cupsArrayFirst(p
->users
);
2107 i
++, name
= (char *)cupsArrayNext(p
->users
))
2108 attr
->values
[i
].string
.text
= _cupsStrAlloc(name
);
2111 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2112 "job-quota-period", p
->quota_period
);
2113 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2114 "job-k-limit", p
->k_limit
);
2115 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2116 "job-page-limit", p
->page_limit
);
2117 if (p
->num_auth_info_required
> 0 && strcmp(p
->auth_info_required
[0], "none"))
2118 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2119 "auth-info-required", p
->num_auth_info_required
, NULL
,
2120 p
->auth_info_required
);
2122 if (cupsArrayCount(Banners
) > 0)
2125 * Setup the job-sheets-default attribute...
2128 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2129 "job-sheets-default", 2, NULL
, NULL
);
2133 attr
->values
[0].string
.text
= _cupsStrAlloc(Classification
?
2134 Classification
: p
->job_sheets
[0]);
2135 attr
->values
[1].string
.text
= _cupsStrAlloc(Classification
?
2136 Classification
: p
->job_sheets
[1]);
2144 * Assign additional attributes depending on whether this is a printer
2148 if (p
->type
& CUPS_PRINTER_CLASS
)
2151 p
->type
&= ~CUPS_PRINTER_OPTIONS
;
2154 * Add class-specific attributes...
2157 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
2158 "printer-make-and-model", NULL
, "Local Printer Class");
2159 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "device-uri", NULL
,
2160 "file:///dev/null");
2162 if (p
->num_printers
> 0)
2165 * Add a list of member names; URIs are added in copy_printer_attrs...
2168 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2169 "member-names", p
->num_printers
, NULL
, NULL
);
2170 p
->type
|= CUPS_PRINTER_OPTIONS
;
2172 for (i
= 0; i
< p
->num_printers
; i
++)
2175 attr
->values
[i
].string
.text
= _cupsStrAlloc(p
->printers
[i
]->name
);
2177 p
->type
&= ~CUPS_PRINTER_OPTIONS
| p
->printers
[i
]->type
;
2184 * Add printer-specific attributes...
2187 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "device-uri", NULL
,
2188 p
->sanitized_device_uri
);
2191 * Assign additional attributes from the PPD file (if any)...
2197 * Add filters for printer...
2200 cupsdSetPrinterReasons(p
, "-cups-missing-filter-warning,"
2201 "cups-insecure-filter-warning");
2203 if (p
->pc
&& p
->pc
->filters
)
2205 for (filter
= (char *)cupsArrayFirst(p
->pc
->filters
);
2207 filter
= (char *)cupsArrayNext(p
->pc
->filters
))
2208 add_printer_filter(p
, p
->filetype
, filter
);
2210 else if (!(p
->type
& CUPS_PRINTER_REMOTE
))
2212 char interface
[1024]; /* Interface script */
2215 snprintf(interface
, sizeof(interface
), "%s/interfaces/%s", ServerRoot
,
2217 if (!access(interface
, X_OK
))
2220 * Yes, we have a System V style interface script; use it!
2223 snprintf(interface
, sizeof(interface
), "*/* 0 %s/interfaces/%s",
2224 ServerRoot
, p
->name
);
2225 add_printer_filter(p
, p
->filetype
, interface
);
2230 * Add a filter from application/vnd.cups-raw to printer/name to
2231 * handle "raw" printing by users.
2234 add_printer_filter(p
, p
->filetype
, "application/vnd.cups-raw 0 -");
2237 * Add a PostScript filter, since this is still possibly PS printer.
2240 add_printer_filter(p
, p
->filetype
,
2241 "application/vnd.cups-postscript 0 -");
2245 if (p
->pc
&& p
->pc
->prefilters
)
2247 if (!p
->prefiltertype
)
2248 p
->prefiltertype
= mimeAddType(MimeDatabase
, "prefilter", p
->name
);
2250 for (filter
= (char *)cupsArrayFirst(p
->pc
->prefilters
);
2252 filter
= (char *)cupsArrayNext(p
->pc
->prefilters
))
2253 add_printer_filter(p
, p
->prefiltertype
, filter
);
2258 * Copy marker attributes as needed...
2263 ipp_attribute_t
*oldattr
; /* Old attribute */
2266 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-colors",
2267 IPP_TAG_NAME
)) != NULL
)
2269 if ((attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2270 "marker-colors", oldattr
->num_values
, NULL
,
2273 for (i
= 0; i
< oldattr
->num_values
; i
++)
2274 attr
->values
[i
].string
.text
=
2275 _cupsStrAlloc(oldattr
->values
[i
].string
.text
);
2279 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-levels",
2280 IPP_TAG_INTEGER
)) != NULL
)
2282 if ((attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2283 "marker-levels", oldattr
->num_values
,
2286 for (i
= 0; i
< oldattr
->num_values
; i
++)
2287 attr
->values
[i
].integer
= oldattr
->values
[i
].integer
;
2291 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-message",
2292 IPP_TAG_TEXT
)) != NULL
)
2293 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "marker-message",
2294 NULL
, oldattr
->values
[0].string
.text
);
2296 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-low-levels",
2297 IPP_TAG_INTEGER
)) != NULL
)
2299 if ((attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2300 "marker-low-levels", oldattr
->num_values
,
2303 for (i
= 0; i
< oldattr
->num_values
; i
++)
2304 attr
->values
[i
].integer
= oldattr
->values
[i
].integer
;
2308 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-high-levels",
2309 IPP_TAG_INTEGER
)) != NULL
)
2311 if ((attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2312 "marker-high-levels", oldattr
->num_values
,
2315 for (i
= 0; i
< oldattr
->num_values
; i
++)
2316 attr
->values
[i
].integer
= oldattr
->values
[i
].integer
;
2320 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-names",
2321 IPP_TAG_NAME
)) != NULL
)
2323 if ((attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2324 "marker-names", oldattr
->num_values
, NULL
,
2327 for (i
= 0; i
< oldattr
->num_values
; i
++)
2328 attr
->values
[i
].string
.text
=
2329 _cupsStrAlloc(oldattr
->values
[i
].string
.text
);
2333 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-types",
2334 IPP_TAG_KEYWORD
)) != NULL
)
2336 if ((attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2337 "marker-types", oldattr
->num_values
, NULL
,
2340 for (i
= 0; i
< oldattr
->num_values
; i
++)
2341 attr
->values
[i
].string
.text
=
2342 _cupsStrAlloc(oldattr
->values
[i
].string
.text
);
2346 ippDelete(oldattrs
);
2350 * Force sharing off for remote queues...
2353 if (p
->type
& CUPS_PRINTER_REMOTE
)
2357 * Populate the document-format-supported attribute...
2360 add_printer_formats(p
);
2362 DEBUG_printf(("cupsdSetPrinterAttrs: leaving name = %s, type = %x\n", p
->name
,
2366 * Add name-default attributes...
2369 add_printer_defaults(p
);
2372 * Let the browse protocols reflect the change
2375 cupsdRegisterPrinter(p
);
2380 * 'cupsdSetPrinterReasons()' - Set/update the reasons strings.
2383 int /* O - 1 if something changed, 0 otherwise */
2384 cupsdSetPrinterReasons(
2385 cupsd_printer_t
*p
, /* I - Printer */
2386 const char *s
) /* I - Reasons strings */
2388 int i
, /* Looping var */
2389 changed
= 0; /* Did something change? */
2390 const char *sptr
; /* Pointer into reasons */
2391 char reason
[255], /* Reason string */
2392 *rptr
; /* Pointer into reason */
2395 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
2396 "cupsdSetPrinterReasons(p=%p(%s),s=\"%s\"", p
, p
->name
, s
);
2398 if (s
[0] == '-' || s
[0] == '+')
2401 * Add/remove reasons...
2409 * Replace reasons...
2414 for (i
= 0; i
< p
->num_reasons
; i
++)
2415 _cupsStrFree(p
->reasons
[i
]);
2423 if (!strcmp(s
, "none"))
2427 * Loop through all of the reasons...
2433 * Skip leading whitespace and commas...
2436 while (isspace(*sptr
& 255) || *sptr
== ',')
2439 for (rptr
= reason
; *sptr
&& !isspace(*sptr
& 255) && *sptr
!= ','; sptr
++)
2440 if (rptr
< (reason
+ sizeof(reason
) - 1))
2454 for (i
= 0; i
< p
->num_reasons
; i
++)
2455 if (!strcmp(reason
, p
->reasons
[i
]))
2458 * Found a match, so remove it...
2463 _cupsStrFree(p
->reasons
[i
]);
2465 if (i
< p
->num_reasons
)
2466 memmove(p
->reasons
+ i
, p
->reasons
+ i
+ 1,
2467 (p
->num_reasons
- i
) * sizeof(char *));
2469 if (!strcmp(reason
, "paused") && p
->state
== IPP_PRINTER_STOPPED
)
2470 cupsdSetPrinterState(p
, IPP_PRINTER_IDLE
, 1);
2472 if (strcmp(reason
, "connecting-to-device"))
2477 else if (p
->num_reasons
< (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
2483 for (i
= 0; i
< p
->num_reasons
; i
++)
2484 if (!strcmp(reason
, p
->reasons
[i
]))
2487 if (i
>= p
->num_reasons
)
2489 if (!strncmp(reason
, "cups-ipp-missing-", 17) ||
2490 !strncmp(reason
, "cups-ipp-wrong-", 15))
2491 log_ipp_conformance(p
, reason
);
2493 if (i
>= (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
2495 cupsdLogMessage(CUPSD_LOG_ALERT
,
2496 "Too many printer-state-reasons values for %s (%d)",
2501 p
->reasons
[i
] = _cupsStrAlloc(reason
);
2505 if (!strcmp(reason
, "paused") && p
->state
!= IPP_PRINTER_STOPPED
)
2506 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, 1);
2508 if (strcmp(reason
, "connecting-to-device"))
2519 * 'cupsdSetPrinterState()' - Update the current state of a printer.
2523 cupsdSetPrinterState(
2524 cupsd_printer_t
*p
, /* I - Printer to change */
2525 ipp_pstate_t s
, /* I - New state */
2526 int update
) /* I - Update printers.conf? */
2528 cupsd_job_t
*job
; /* Current job */
2529 ipp_pstate_t old_state
; /* Old printer state */
2530 static const char * const printer_states
[] =
2531 { /* State strings */
2539 * Set the new state...
2542 old_state
= p
->state
;
2547 cupsdAddEvent(s
== IPP_PRINTER_STOPPED
? CUPSD_EVENT_PRINTER_STOPPED
:
2548 CUPSD_EVENT_PRINTER_STATE
, p
, NULL
,
2549 "%s \"%s\" state changed to %s.",
2550 (p
->type
& CUPS_PRINTER_CLASS
) ? "Class" : "Printer",
2551 p
->name
, printer_states
[p
->state
- IPP_PRINTER_IDLE
]);
2554 * Let the browse code know this needs to be updated...
2557 p
->state_time
= time(NULL
);
2561 * Set/clear the paused reason as needed...
2564 if (s
== IPP_PRINTER_STOPPED
)
2565 cupsdSetPrinterReasons(p
, "+paused");
2567 cupsdSetPrinterReasons(p
, "-paused");
2571 for (job
= (cupsd_job_t
*)cupsArrayFirst(ActiveJobs
);
2573 job
= (cupsd_job_t
*)cupsArrayNext(ActiveJobs
))
2574 if (job
->reasons
&& job
->state_value
== IPP_JOB_PENDING
&&
2575 !_cups_strcasecmp(job
->dest
, p
->name
))
2576 ippSetString(job
->attrs
, &job
->reasons
, 0,
2577 s
== IPP_PRINTER_STOPPED
? "printer-stopped" : "none");
2581 * Clear the message for the queue when going to processing...
2584 if (s
== IPP_PRINTER_PROCESSING
)
2585 p
->state_message
[0] = '\0';
2588 * Let the browse protocols reflect the change...
2592 cupsdRegisterPrinter(p
);
2595 * Save the printer configuration if a printer goes from idle or processing
2596 * to stopped (or visa-versa)...
2600 (old_state
== IPP_PRINTER_STOPPED
) != (s
== IPP_PRINTER_STOPPED
))
2606 * 'cupsdStopPrinter()' - Stop a printer from printing any jobs...
2610 cupsdStopPrinter(cupsd_printer_t
*p
, /* I - Printer to stop */
2611 int update
)/* I - Update printers.conf? */
2614 * Set the printer state...
2617 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, update
);
2620 * See if we have a job printing on this printer...
2623 if (p
->job
&& p
->job
->state_value
== IPP_JOB_PROCESSING
)
2624 cupsdSetJobState(p
->job
, IPP_JOB_PENDING
, CUPSD_JOB_DEFAULT
,
2625 "Job stopped due to printer being paused.");
2630 * 'cupsdUpdatePrinterPPD()' - Update keywords in a printer's PPD file.
2633 int /* O - 1 if successful, 0 otherwise */
2634 cupsdUpdatePrinterPPD(
2635 cupsd_printer_t
*p
, /* I - Printer */
2636 int num_keywords
, /* I - Number of keywords */
2637 cups_option_t
*keywords
) /* I - Keywords */
2639 int i
; /* Looping var */
2640 cups_file_t
*src
, /* Original file */
2641 *dst
; /* New file */
2642 char srcfile
[1024], /* Original filename */
2643 dstfile
[1024], /* New filename */
2644 line
[1024], /* Line from file */
2645 keystring
[41]; /* Keyword from line */
2646 cups_option_t
*keyword
; /* Current keyword */
2649 cupsdLogMessage(CUPSD_LOG_INFO
, "Updating keywords in PPD file for %s...",
2653 * Get the old and new PPD filenames...
2656 snprintf(srcfile
, sizeof(srcfile
), "%s/ppd/%s.ppd.O", ServerRoot
, p
->name
);
2657 snprintf(dstfile
, sizeof(srcfile
), "%s/ppd/%s.ppd", ServerRoot
, p
->name
);
2660 * Rename the old file and open the old and new...
2663 if (rename(dstfile
, srcfile
))
2665 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to backup PPD file for %s: %s",
2666 p
->name
, strerror(errno
));
2670 if ((src
= cupsFileOpen(srcfile
, "r")) == NULL
)
2672 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to open PPD file \"%s\": %s",
2673 srcfile
, strerror(errno
));
2674 rename(srcfile
, dstfile
);
2678 if ((dst
= cupsFileOpen(dstfile
, "w")) == NULL
)
2680 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to create PPD file \"%s\": %s",
2681 dstfile
, strerror(errno
));
2683 rename(srcfile
, dstfile
);
2688 * Copy the first line and then write out all of the keywords...
2691 if (!cupsFileGets(src
, line
, sizeof(line
)))
2693 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to read PPD file \"%s\": %s",
2694 srcfile
, strerror(errno
));
2697 rename(srcfile
, dstfile
);
2701 cupsFilePrintf(dst
, "%s\n", line
);
2703 for (i
= num_keywords
, keyword
= keywords
; i
> 0; i
--, keyword
++)
2705 cupsdLogMessage(CUPSD_LOG_DEBUG
, "*%s: %s", keyword
->name
, keyword
->value
);
2706 cupsFilePrintf(dst
, "*%s: %s\n", keyword
->name
, keyword
->value
);
2710 * Then copy the rest of the PPD file, dropping any keywords we changed.
2713 while (cupsFileGets(src
, line
, sizeof(line
)))
2716 * Skip keywords we've already set...
2719 if (sscanf(line
, "*%40[^:]:", keystring
) == 1 &&
2720 cupsGetOption(keystring
, num_keywords
, keywords
))
2724 * Otherwise write the line...
2727 cupsFilePrintf(dst
, "%s\n", line
);
2731 * Close files and return...
2742 * 'cupsdUpdatePrinters()' - Update printers after a partial reload.
2746 cupsdUpdatePrinters(void)
2748 cupsd_printer_t
*p
; /* Current printer */
2752 * Loop through the printers and recreate the printer attributes
2753 * for any local printers since the policy and/or access control
2754 * stuff may have changed. Also, if browsing is disabled, remove
2755 * any remote printers...
2758 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
2760 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
2763 * Update the operation policy pointer...
2766 if ((p
->op_policy_ptr
= cupsdFindPolicy(p
->op_policy
)) == NULL
)
2767 p
->op_policy_ptr
= DefaultPolicyPtr
;
2770 * Update printer attributes...
2773 cupsdSetPrinterAttrs(p
);
2779 * 'cupsdValidateDest()' - Validate a printer/class destination.
2782 const char * /* O - Printer or class name */
2784 const char *uri
, /* I - Printer URI */
2785 cups_ptype_t
*dtype
, /* O - Type (printer or class) */
2786 cupsd_printer_t
**printer
) /* O - Printer pointer */
2788 cupsd_printer_t
*p
; /* Current printer */
2789 char localname
[1024],/* Localized hostname */
2790 *lptr
, /* Pointer into localized hostname */
2791 *sptr
, /* Pointer into server name */
2792 *rptr
, /* Pointer into resource */
2793 scheme
[32], /* Scheme portion of URI */
2794 username
[64], /* Username portion of URI */
2795 hostname
[HTTP_MAX_HOST
],
2796 /* Host portion of URI */
2797 resource
[HTTP_MAX_URI
];
2798 /* Resource portion of URI */
2799 int port
; /* Port portion of URI */
2802 DEBUG_printf(("cupsdValidateDest(uri=\"%s\", dtype=%p, printer=%p)\n", uri
,
2806 * Initialize return values...
2813 *dtype
= (cups_ptype_t
)0;
2816 * Pull the hostname and resource from the URI...
2819 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
, scheme
, sizeof(scheme
),
2820 username
, sizeof(username
), hostname
, sizeof(hostname
),
2821 &port
, resource
, sizeof(resource
));
2824 * See if the resource is a class or printer...
2827 if (!strncmp(resource
, "/classes/", 9))
2833 rptr
= resource
+ 9;
2835 else if (!strncmp(resource
, "/printers/", 10))
2841 rptr
= resource
+ 10;
2846 * Bad resource name...
2853 * See if the printer or class name exists...
2856 p
= cupsdFindDest(rptr
);
2858 if (p
== NULL
&& strchr(rptr
, '@') == NULL
)
2866 *dtype
= p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_REMOTE
);
2872 * Change localhost to the server name...
2875 if (!_cups_strcasecmp(hostname
, "localhost"))
2876 strlcpy(hostname
, ServerName
, sizeof(hostname
));
2878 strlcpy(localname
, hostname
, sizeof(localname
));
2880 if (!_cups_strcasecmp(hostname
, ServerName
))
2883 * Localize the hostname...
2886 lptr
= strchr(localname
, '.');
2887 sptr
= strchr(ServerName
, '.');
2889 if (sptr
!= NULL
&& lptr
!= NULL
)
2892 * Strip the common domain name components...
2895 while (lptr
!= NULL
)
2897 if (!_cups_strcasecmp(lptr
, sptr
))
2903 lptr
= strchr(lptr
+ 1, '.');
2908 DEBUG_printf(("localized hostname is \"%s\"...\n", localname
));
2911 * Find a matching printer or class...
2914 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
2916 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
2917 if (!_cups_strcasecmp(p
->hostname
, localname
) &&
2918 !_cups_strcasecmp(p
->name
, rptr
))
2924 *dtype
= p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_REMOTE
);
2934 * 'cupsdWritePrintcap()' - Write a pseudo-printcap file for older applications
2939 cupsdWritePrintcap(void)
2941 int i
; /* Looping var */
2942 cups_file_t
*fp
; /* Printcap file */
2943 cupsd_printer_t
*p
; /* Current printer */
2947 * See if we have a printcap file; if not, don't bother writing it.
2950 if (!Printcap
|| !*Printcap
)
2953 cupsdLogMessage(CUPSD_LOG_INFO
, "Generating printcap %s...", Printcap
);
2956 * Open the printcap file...
2959 if ((fp
= cupsFileOpen(Printcap
, "w")) == NULL
)
2963 * Put a comment header at the top so that users will know where the
2964 * data has come from...
2967 if (PrintcapFormat
!= PRINTCAP_PLIST
)
2968 cupsFilePrintf(fp
, "# This file was automatically generated by cupsd(8) "
2970 "# %s/printers.conf file. All changes to this file\n"
2971 "# will be lost.\n", ServerRoot
);
2974 * Write a new printcap with the current list of printers.
2977 switch (PrintcapFormat
)
2981 * Each printer is put in the file as:
2991 cupsFilePrintf(fp
, "%s|%s:rm=%s:rp=%s:\n", DefaultPrinter
->name
,
2992 DefaultPrinter
->info
, ServerName
,
2993 DefaultPrinter
->name
);
2995 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
2997 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
2998 if (p
!= DefaultPrinter
)
2999 cupsFilePrintf(fp
, "%s|%s:rm=%s:rp=%s:\n", p
->name
, p
->info
,
3000 ServerName
, p
->name
);
3003 case PRINTCAP_PLIST
:
3005 * Each printer is written as a dictionary in a plist file.
3006 * Currently the printer-name, printer-info, printer-is-accepting-jobs,
3007 * printer-location, printer-make-and-model, printer-state,
3008 * printer-state-reasons, printer-type, and (sanitized) device-uri.
3011 cupsFilePuts(fp
, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
3012 "<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD "
3013 "PLIST 1.0//EN\" \"http://www.apple.com/DTDs/"
3014 "PropertyList-1.0.dtd\">\n"
3015 "<plist version=\"1.0\">\n"
3018 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3020 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3022 cupsFilePuts(fp
, "\t<dict>\n"
3023 "\t\t<key>printer-name</key>\n"
3025 write_xml_string(fp
, p
->name
);
3026 cupsFilePuts(fp
, "</string>\n"
3027 "\t\t<key>printer-info</key>\n"
3029 write_xml_string(fp
, p
->info
);
3030 cupsFilePrintf(fp
, "</string>\n"
3031 "\t\t<key>printer-is-accepting-jobs</key>\n"
3033 "\t\t<key>printer-location</key>\n"
3034 "\t\t<string>", p
->accepting
? "true" : "false");
3035 write_xml_string(fp
, p
->location
);
3036 cupsFilePuts(fp
, "</string>\n"
3037 "\t\t<key>printer-make-and-model</key>\n"
3039 write_xml_string(fp
, p
->make_model
);
3040 cupsFilePrintf(fp
, "</string>\n"
3041 "\t\t<key>printer-state</key>\n"
3042 "\t\t<integer>%d</integer>\n"
3043 "\t\t<key>printer-state-reasons</key>\n"
3044 "\t\t<array>\n", p
->state
);
3045 for (i
= 0; i
< p
->num_reasons
; i
++)
3047 cupsFilePuts(fp
, "\t\t\t<string>");
3048 write_xml_string(fp
, p
->reasons
[i
]);
3049 cupsFilePuts(fp
, "</string>\n");
3051 cupsFilePrintf(fp
, "\t\t</array>\n"
3052 "\t\t<key>printer-type</key>\n"
3053 "\t\t<integer>%d</integer>\n"
3054 "\t\t<key>device-uri</key>\n"
3055 "\t\t<string>", p
->type
);
3056 write_xml_string(fp
, p
->sanitized_device_uri
);
3057 cupsFilePuts(fp
, "</string>\n"
3060 cupsFilePuts(fp
, "</array>\n"
3064 case PRINTCAP_SOLARIS
:
3066 * Each printer is put in the file as:
3068 * _all:all=Printer1,Printer2,Printer3,...,PrinterN
3069 * _default:use=DefaultPrinter
3071 * :bsdaddr=ServerName,Printer1:\
3072 * :description=Description:
3074 * :bsdaddr=ServerName,Printer2:\
3075 * :description=Description:
3077 * :bsdaddr=ServerName,Printer3:\
3078 * :description=Description:
3081 * :bsdaddr=ServerName,PrinterN:\
3082 * :description=Description:
3085 cupsFilePuts(fp
, "_all:all=");
3086 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3088 p
= (cupsd_printer_t
*)cupsArrayCurrent(Printers
))
3089 cupsFilePrintf(fp
, "%s%c", p
->name
,
3090 cupsArrayNext(Printers
) ? ',' : '\n');
3093 cupsFilePrintf(fp
, "_default:use=%s\n", DefaultPrinter
->name
);
3095 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3097 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3098 cupsFilePrintf(fp
, "%s:\\\n"
3099 "\t:bsdaddr=%s,%s:\\\n"
3100 "\t:description=%s:\n",
3101 p
->name
, ServerName
, p
->name
,
3102 p
->info
? p
->info
: "");
3115 * 'add_printer_defaults()' - Add name-default attributes to the printer attributes.
3119 add_printer_defaults(cupsd_printer_t
*p
)/* I - Printer */
3121 int i
; /* Looping var */
3122 int num_options
; /* Number of default options */
3123 cups_option_t
*options
, /* Default options */
3124 *option
; /* Current option */
3125 char name
[256]; /* name-default */
3129 * Maintain a common array of default attribute names...
3132 if (!CommonDefaults
)
3134 CommonDefaults
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
3136 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("copies-default"));
3137 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("document-format-default"));
3138 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("finishings-default"));
3139 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-account-id-default"));
3140 cupsArrayAdd(CommonDefaults
,
3141 _cupsStrAlloc("job-accounting-user-id-default"));
3142 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-hold-until-default"));
3143 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-priority-default"));
3144 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-sheets-default"));
3145 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("media-col-default"));
3146 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("number-up-default"));
3147 cupsArrayAdd(CommonDefaults
,
3148 _cupsStrAlloc("orientation-requested-default"));
3152 * Add all of the default options from the .conf files...
3155 for (num_options
= 0, options
= NULL
, i
= p
->num_options
, option
= p
->options
;
3159 if (strcmp(option
->name
, "ipp-options") &&
3160 strcmp(option
->name
, "job-sheets") &&
3161 strcmp(option
->name
, "lease-duration"))
3163 snprintf(name
, sizeof(name
), "%s-default", option
->name
);
3164 num_options
= cupsAddOption(name
, option
->value
, num_options
, &options
);
3166 if (!cupsArrayFind(CommonDefaults
, name
))
3167 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc(name
));
3172 * Convert options to IPP attributes...
3175 cupsEncodeOptions2(p
->attrs
, num_options
, options
, IPP_TAG_PRINTER
);
3176 cupsFreeOptions(num_options
, options
);
3179 * Add standard -default attributes as needed...
3182 if (!cupsGetOption("copies", p
->num_options
, p
->options
))
3183 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
, "copies-default",
3186 if (!cupsGetOption("document-format", p
->num_options
, p
->options
))
3187 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_MIMETYPE
,
3188 "document-format-default", NULL
, "application/octet-stream");
3190 if (!cupsGetOption("job-hold-until", p
->num_options
, p
->options
))
3191 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3192 "job-hold-until-default", NULL
, "no-hold");
3194 if (!cupsGetOption("job-priority", p
->num_options
, p
->options
))
3195 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3196 "job-priority-default", 50);
3198 if (!cupsGetOption("number-up", p
->num_options
, p
->options
))
3199 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3200 "number-up-default", 1);
3202 if (!cupsGetOption("notify-lease-duration", p
->num_options
, p
->options
))
3203 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3204 "notify-lease-duration-default", DefaultLeaseDuration
);
3206 if (!cupsGetOption("notify-events", p
->num_options
, p
->options
))
3207 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3208 "notify-events-default", NULL
, "job-completed");
3210 if (!cupsGetOption("orientation-requested", p
->num_options
, p
->options
))
3211 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NOVALUE
,
3212 "orientation-requested-default", NULL
, NULL
);
3214 if (!cupsGetOption("print-quality", p
->num_options
, p
->options
))
3215 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
3216 "print-quality-default", IPP_QUALITY_NORMAL
);
3221 * 'add_printer_filter()' - Add a MIME filter for a printer.
3226 cupsd_printer_t
*p
, /* I - Printer to add to */
3227 mime_type_t
*filtertype
, /* I - Filter or prefilter MIME type */
3228 const char *filter
) /* I - Filter to add */
3230 char super
[MIME_MAX_SUPER
], /* Super-type for filter */
3231 type
[MIME_MAX_TYPE
], /* Type for filter */
3232 dsuper
[MIME_MAX_SUPER
], /* Destination super-type for filter */
3233 dtype
[MIME_MAX_TYPE
], /* Destination type for filter */
3234 dest
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2],
3235 /* Destination super/type */
3236 program
[1024]; /* Program/filter name */
3237 int cost
; /* Cost of filter */
3238 size_t maxsize
= 0; /* Maximum supported file size */
3239 mime_type_t
*temptype
, /* MIME type looping var */
3240 *desttype
; /* Destination MIME type */
3241 mime_filter_t
*filterptr
; /* MIME filter */
3242 char filename
[1024]; /* Full filter filename */
3245 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3246 "add_printer_filter(p=%p(%s), filtertype=%p(%s/%s), "
3247 "filter=\"%s\")", p
, p
->name
, filtertype
, filtertype
->super
,
3248 filtertype
->type
, filter
);
3251 * Parse the filter string; it should be in one of the following formats:
3253 * source/type cost program
3254 * source/type cost maxsize(nnnn) program
3255 * source/type dest/type cost program
3256 * source/type dest/type cost maxsize(nnnn) program
3259 if (sscanf(filter
, "%15[^/]/%255s%*[ \t]%15[^/]/%255s%d%*[ \t]%1023[^\n]",
3260 super
, type
, dsuper
, dtype
, &cost
, program
) == 6)
3262 snprintf(dest
, sizeof(dest
), "%s/%s/%s", p
->name
, dsuper
, dtype
);
3264 if ((desttype
= mimeType(MimeDatabase
, "printer", dest
)) == NULL
)
3266 desttype
= mimeAddType(MimeDatabase
, "printer", dest
);
3268 p
->dest_types
= cupsArrayNew(NULL
, NULL
);
3270 cupsArrayAdd(p
->dest_types
, desttype
);
3276 if (sscanf(filter
, "%15[^/]/%255s%d%*[ \t]%1023[^\n]", super
, type
, &cost
,
3279 desttype
= filtertype
;
3283 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: invalid filter string \"%s\"!",
3289 if (!strncmp(program
, "maxsize(", 8))
3291 char *ptr
; /* Pointer into maxsize(nnnn) program */
3293 maxsize
= strtoll(program
+ 8, &ptr
, 10);
3297 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: invalid filter string \"%s\"!",
3303 while (_cups_isspace(*ptr
))
3306 _cups_strcpy(program
, ptr
);
3310 * Check permissions on the filter and its containing directory...
3313 if (strcmp(program
, "-"))
3315 if (program
[0] == '/')
3316 strlcpy(filename
, program
, sizeof(filename
));
3318 snprintf(filename
, sizeof(filename
), "%s/filter/%s", ServerBin
, program
);
3320 _cupsFileCheck(filename
, _CUPS_FILE_CHECK_PROGRAM
, !RunUser
,
3321 cupsdLogFCMessage
, p
);
3325 * Add the filter to the MIME database, supporting wildcards as needed...
3328 for (temptype
= mimeFirstType(MimeDatabase
);
3330 temptype
= mimeNextType(MimeDatabase
))
3331 if (((super
[0] == '*' && _cups_strcasecmp(temptype
->super
, "printer")) ||
3332 !_cups_strcasecmp(temptype
->super
, super
)) &&
3333 (type
[0] == '*' || !_cups_strcasecmp(temptype
->type
, type
)))
3335 if (desttype
!= filtertype
)
3337 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3338 "add_printer_filter: %s: adding filter %s/%s %s/%s %d "
3339 "%s", p
->name
, temptype
->super
, temptype
->type
,
3340 desttype
->super
, desttype
->type
,
3342 filterptr
= mimeAddFilter(MimeDatabase
, temptype
, desttype
, cost
,
3345 if (!mimeFilterLookup(MimeDatabase
, desttype
, filtertype
))
3347 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3348 "add_printer_filter: %s: adding filter %s/%s %s/%s "
3349 "0 -", p
->name
, desttype
->super
, desttype
->type
,
3350 filtertype
->super
, filtertype
->type
);
3351 mimeAddFilter(MimeDatabase
, desttype
, filtertype
, 0, "-");
3356 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3357 "add_printer_filter: %s: adding filter %s/%s %s/%s %d "
3358 "%s", p
->name
, temptype
->super
, temptype
->type
,
3359 filtertype
->super
, filtertype
->type
,
3361 filterptr
= mimeAddFilter(MimeDatabase
, temptype
, filtertype
, cost
,
3366 filterptr
->maxsize
= maxsize
;
3372 * 'add_printer_formats()' - Add document-format-supported values for a printer.
3376 add_printer_formats(cupsd_printer_t
*p
) /* I - Printer */
3378 int i
; /* Looping var */
3379 mime_type_t
*type
; /* Current MIME type */
3380 cups_array_t
*filters
; /* Filters */
3381 ipp_attribute_t
*attr
; /* document-format-supported attribute */
3382 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
3383 /* MIME type name */
3387 * Raw (and remote) queues advertise all of the supported MIME
3391 cupsArrayDelete(p
->filetypes
);
3392 p
->filetypes
= NULL
;
3396 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
,
3397 (ipp_tag_t
)(IPP_TAG_MIMETYPE
| IPP_TAG_COPY
),
3398 "document-format-supported", NumMimeTypes
, NULL
, MimeTypes
);
3403 * Otherwise, loop through the supported MIME types and see if there
3404 * are filters for them...
3407 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_printer_formats: %d types, %d filters",
3408 mimeNumTypes(MimeDatabase
), mimeNumFilters(MimeDatabase
));
3410 p
->filetypes
= cupsArrayNew(NULL
, NULL
);
3412 for (type
= mimeFirstType(MimeDatabase
);
3414 type
= mimeNextType(MimeDatabase
))
3416 if (!_cups_strcasecmp(type
->super
, "printer"))
3419 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
3421 if ((filters
= mimeFilter(MimeDatabase
, type
, p
->filetype
, NULL
)) != NULL
)
3423 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3424 "add_printer_formats: %s: %s needs %d filters",
3425 p
->name
, mimetype
, cupsArrayCount(filters
));
3427 cupsArrayDelete(filters
);
3428 cupsArrayAdd(p
->filetypes
, type
);
3431 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3432 "add_printer_formats: %s: %s not supported",
3437 * Add the file formats that can be filtered...
3440 if ((type
= mimeType(MimeDatabase
, "application", "octet-stream")) == NULL
||
3441 !cupsArrayFind(p
->filetypes
, type
))
3446 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3447 "add_printer_formats: %s: %d supported types",
3448 p
->name
, cupsArrayCount(p
->filetypes
) + i
);
3450 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_MIMETYPE
,
3451 "document-format-supported",
3452 cupsArrayCount(p
->filetypes
) + i
, NULL
, NULL
);
3455 attr
->values
[0].string
.text
= _cupsStrAlloc("application/octet-stream");
3457 for (type
= (mime_type_t
*)cupsArrayFirst(p
->filetypes
);
3459 i
++, type
= (mime_type_t
*)cupsArrayNext(p
->filetypes
))
3461 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
3463 attr
->values
[i
].string
.text
= _cupsStrAlloc(mimetype
);
3466 #if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
3468 char pdl
[1024]; /* Buffer to build pdl list */
3469 mime_filter_t
*filter
; /* MIME filter looping var */
3473 * We only support raw printing if this is not a Tioga PrintJobMgr based
3474 * queue and if application/octet-stream is a known type...
3477 for (filter
= (mime_filter_t
*)cupsArrayFirst(MimeDatabase
->filters
);
3479 filter
= (mime_filter_t
*)cupsArrayNext(MimeDatabase
->filters
))
3481 if (filter
->dst
== p
->filetype
&& filter
->filter
&&
3482 strstr(filter
->filter
, "PrintJobMgr"))
3488 if (!filter
&& mimeType(MimeDatabase
, "application", "octet-stream"))
3489 strlcat(pdl
, "application/octet-stream,", sizeof(pdl
));
3492 * Then list a bunch of formats that are supported by the printer...
3495 for (type
= (mime_type_t
*)cupsArrayFirst(p
->filetypes
);
3497 type
= (mime_type_t
*)cupsArrayNext(p
->filetypes
))
3499 if (!_cups_strcasecmp(type
->super
, "application"))
3501 if (!_cups_strcasecmp(type
->type
, "pdf"))
3502 strlcat(pdl
, "application/pdf,", sizeof(pdl
));
3503 else if (!_cups_strcasecmp(type
->type
, "postscript"))
3504 strlcat(pdl
, "application/postscript,", sizeof(pdl
));
3506 else if (!_cups_strcasecmp(type
->super
, "image"))
3508 if (!_cups_strcasecmp(type
->type
, "jpeg"))
3509 strlcat(pdl
, "image/jpeg,", sizeof(pdl
));
3510 else if (!_cups_strcasecmp(type
->type
, "png"))
3511 strlcat(pdl
, "image/png,", sizeof(pdl
));
3512 else if (!_cups_strcasecmp(type
->type
, "pwg-raster"))
3513 strlcat(pdl
, "image/pwg-raster,", sizeof(pdl
));
3518 pdl
[strlen(pdl
) - 1] = '\0'; /* Remove trailing comma */
3520 cupsdSetString(&p
->pdl
, pdl
);
3522 #endif /* HAVE_DNSSD || HAVE_AVAHI */
3527 * 'compare_printers()' - Compare two printers.
3530 static int /* O - Result of comparison */
3531 compare_printers(void *first
, /* I - First printer */
3532 void *second
, /* I - Second printer */
3533 void *data
) /* I - App data (not used) */
3537 return (_cups_strcasecmp(((cupsd_printer_t
*)first
)->name
,
3538 ((cupsd_printer_t
*)second
)->name
));
3543 * 'delete_printer_filters()' - Delete all MIME filters for a printer.
3547 delete_printer_filters(
3548 cupsd_printer_t
*p
) /* I - Printer to remove from */
3550 mime_filter_t
*filter
; /* MIME filter looping var */
3551 mime_type_t
*type
; /* Destination types for filters */
3555 * Range check input...
3562 * Remove all filters from the MIME database that have a destination
3563 * type == printer...
3566 for (filter
= mimeFirstFilter(MimeDatabase
);
3568 filter
= mimeNextFilter(MimeDatabase
))
3569 if (filter
->dst
== p
->filetype
|| filter
->dst
== p
->prefiltertype
||
3570 cupsArrayFind(p
->dest_types
, filter
->dst
))
3573 * Delete the current filter...
3576 mimeDeleteFilter(MimeDatabase
, filter
);
3579 for (type
= (mime_type_t
*)cupsArrayFirst(p
->dest_types
);
3581 type
= (mime_type_t
*)cupsArrayNext(p
->dest_types
))
3582 mimeDeleteType(MimeDatabase
, type
);
3584 cupsArrayDelete(p
->dest_types
);
3585 p
->dest_types
= NULL
;
3587 cupsdSetPrinterReasons(p
, "-cups-insecure-filter-warning"
3588 ",cups-missing-filter-warning");
3593 * 'dirty_printer()' - Mark config and state files dirty for the specified
3598 dirty_printer(cupsd_printer_t
*p
) /* I - Printer */
3600 if (p
->type
& CUPS_PRINTER_CLASS
)
3601 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
3603 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
3605 if (PrintcapFormat
== PRINTCAP_PLIST
)
3606 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
3611 * 'load_ppd()' - Load a cached PPD file, updating the cache as needed.
3615 load_ppd(cupsd_printer_t
*p
) /* I - Printer */
3617 int i
, j
, k
; /* Looping vars */
3618 char cache_name
[1024]; /* Cache filename */
3619 struct stat cache_info
; /* Cache file info */
3620 ppd_file_t
*ppd
; /* PPD file */
3621 char ppd_name
[1024]; /* PPD filename */
3622 struct stat ppd_info
; /* PPD file info */
3623 int num_media
; /* Number of media options */
3624 ppd_size_t
*size
; /* Current PPD size */
3625 ppd_option_t
*duplex
, /* Duplex option */
3626 *output_bin
, /* OutputBin option */
3627 *output_mode
, /* OutputMode option */
3628 *resolution
; /* (Set|JCL|)Resolution option */
3629 ppd_choice_t
*choice
, /* Current PPD choice */
3630 *input_slot
, /* Current input slot */
3631 *media_type
; /* Current media type */
3632 ppd_attr_t
*ppd_attr
; /* PPD attribute */
3633 int xdpi
, /* Horizontal resolution */
3634 ydpi
; /* Vertical resolution */
3635 const char *resptr
; /* Pointer into resolution keyword */
3636 _pwg_size_t
*pwgsize
; /* Current PWG size */
3637 _pwg_map_t
*pwgsource
, /* Current PWG source */
3638 *pwgtype
; /* Current PWG type */
3639 ipp_attribute_t
*attr
; /* Attribute data */
3640 _ipp_value_t
*val
; /* Attribute value */
3641 int num_finishings
, /* Number of finishings */
3642 finishings
[5]; /* finishings-supported values */
3643 int num_qualities
, /* Number of print-quality values */
3644 qualities
[3]; /* print-quality values */
3645 int num_margins
, /* Number of media-*-margin-supported values */
3646 margins
[16]; /* media-*-margin-supported values */
3647 const char *filter
, /* Current filter */
3648 *mandatory
; /* Current mandatory attribute */
3649 static const char * const sides
[3] = /* sides-supported values */
3652 "two-sided-long-edge",
3653 "two-sided-short-edge"
3655 static const char * const standard_commands
[] =
3656 { /* Standard CUPS commands */
3664 * Check to see if the cache is up-to-date...
3667 snprintf(cache_name
, sizeof(cache_name
), "%s/%s.data", CacheDir
, p
->name
);
3668 if (stat(cache_name
, &cache_info
))
3669 cache_info
.st_mtime
= 0;
3671 snprintf(ppd_name
, sizeof(ppd_name
), "%s/ppd/%s.ppd", ServerRoot
, p
->name
);
3672 if (stat(ppd_name
, &ppd_info
))
3673 ppd_info
.st_mtime
= 1;
3675 ippDelete(p
->ppd_attrs
);
3676 p
->ppd_attrs
= NULL
;
3678 _ppdCacheDestroy(p
->pc
);
3681 if (cache_info
.st_mtime
>= ppd_info
.st_mtime
)
3683 cupsdLogMessage(CUPSD_LOG_DEBUG
, "load_ppd: Loading %s...", cache_name
);
3685 if ((p
->pc
= _ppdCacheCreateWithFile(cache_name
, &p
->ppd_attrs
)) != NULL
&&
3689 * Loaded successfully!
3697 * Reload PPD attributes from disk...
3700 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
3702 cupsdLogMessage(CUPSD_LOG_DEBUG
, "load_ppd: Loading %s...", ppd_name
);
3704 p
->type
&= ~CUPS_PRINTER_OPTIONS
;
3705 p
->type
|= CUPS_PRINTER_BW
;
3707 finishings
[0] = IPP_FINISHINGS_NONE
;
3710 p
->ppd_attrs
= ippNew();
3712 if ((ppd
= _ppdOpenFile(ppd_name
, _PPD_LOCALIZATION_NONE
)) != NULL
)
3715 * Add make/model and other various attributes...
3718 p
->pc
= _ppdCacheCreateWithPPD(ppd
);
3721 cupsdLogMessage(CUPSD_LOG_WARN
, "Unable to create cache of \"%s\": %s",
3722 ppd_name
, cupsLastErrorString());
3724 ppdMarkDefaults(ppd
);
3726 if (ppd
->color_device
)
3727 p
->type
|= CUPS_PRINTER_COLOR
;
3728 if (ppd
->variable_sizes
)
3729 p
->type
|= CUPS_PRINTER_VARIABLE
;
3730 if (!ppd
->manual_copies
)
3731 p
->type
|= CUPS_PRINTER_COPIES
;
3732 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsFax", NULL
)) != NULL
)
3733 if (ppd_attr
->value
&& !_cups_strcasecmp(ppd_attr
->value
, "true"))
3734 p
->type
|= CUPS_PRINTER_FAX
;
3736 ippAddBoolean(p
->ppd_attrs
, IPP_TAG_PRINTER
, "color-supported",
3739 if (p
->pc
&& p
->pc
->charge_info_uri
)
3740 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
3741 "printer-charge-info-uri", NULL
, p
->pc
->charge_info_uri
);
3743 if (p
->pc
&& p
->pc
->account_id
)
3744 ippAddBoolean(p
->ppd_attrs
, IPP_TAG_PRINTER
, "job-account-id-supported",
3747 if (p
->pc
&& p
->pc
->accounting_user_id
)
3748 ippAddBoolean(p
->ppd_attrs
, IPP_TAG_PRINTER
,
3749 "job-accounting-user-id-supported", 1);
3751 if (p
->pc
&& p
->pc
->password
)
3753 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3754 "job-password-encryption-supported", NULL
, "none");
3755 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3756 "job-password-supported", strlen(p
->pc
->password
));
3759 if (ppd
->throughput
)
3761 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3762 "pages-per-minute", ppd
->throughput
);
3763 if (ppd
->color_device
)
3764 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3765 "pages-per-minute-color", ppd
->throughput
);
3770 * When there is no speed information, just say "1 page per minute".
3773 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3774 "pages-per-minute", 1);
3775 if (ppd
->color_device
)
3776 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3777 "pages-per-minute-color", 1);
3782 if ((output_mode
= ppdFindOption(ppd
, "OutputMode")) != NULL
)
3784 if (ppdFindChoice(output_mode
, "draft") ||
3785 ppdFindChoice(output_mode
, "fast"))
3786 qualities
[num_qualities
++] = IPP_QUALITY_DRAFT
;
3788 qualities
[num_qualities
++] = IPP_QUALITY_NORMAL
;
3790 if (ppdFindChoice(output_mode
, "best") ||
3791 ppdFindChoice(output_mode
, "high"))
3792 qualities
[num_qualities
++] = IPP_QUALITY_HIGH
;
3794 else if ((ppd_attr
= ppdFindAttr(ppd
, "APPrinterPreset", NULL
)) != NULL
)
3798 if (strstr(ppd_attr
->spec
, "draft") ||
3799 strstr(ppd_attr
->spec
, "Draft"))
3801 qualities
[num_qualities
++] = IPP_QUALITY_DRAFT
;
3805 while ((ppd_attr
= ppdFindNextAttr(ppd
, "APPrinterPreset",
3808 qualities
[num_qualities
++] = IPP_QUALITY_NORMAL
;
3809 qualities
[num_qualities
++] = IPP_QUALITY_HIGH
;
3812 qualities
[num_qualities
++] = IPP_QUALITY_NORMAL
;
3814 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
3815 "print-quality-supported", num_qualities
, qualities
);
3820 * The NickName can be localized in the character set specified
3821 * by the LanugageEncoding attribute. However, ppdOpen2() has
3822 * already converted the ppd->nickname member to UTF-8 for us
3823 * (the original attribute value is available separately)
3826 cupsdSetString(&p
->make_model
, ppd
->nickname
);
3828 else if (ppd
->modelname
)
3831 * Model name can only contain specific characters...
3834 cupsdSetString(&p
->make_model
, ppd
->modelname
);
3837 cupsdSetString(&p
->make_model
, "Bad PPD File");
3839 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
3840 "printer-make-and-model", NULL
, p
->make_model
);
3843 * Add media options from the PPD file...
3846 if (ppd
->num_sizes
== 0 || !p
->pc
)
3848 if (!ppdFindAttr(ppd
, "APScannerOnly", NULL
))
3849 cupsdLogMessage(CUPSD_LOG_CRIT
,
3850 "The PPD file for printer %s contains no media "
3851 "options and is therefore invalid!", p
->name
);
3853 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3854 "media-default", NULL
, "unknown");
3855 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3856 "media-supported", NULL
, "unknown");
3864 if ((size
= ppdPageSize(ppd
, NULL
)) != NULL
)
3865 pwgsize
= _ppdCacheGetSize(p
->pc
, size
->name
);
3869 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3870 "media-default", NULL
,
3871 pwgsize
? pwgsize
->map
.pwg
: "unknown");
3879 ipp_t
*col
; /* Collection value */
3881 input_slot
= ppdFindMarkedChoice(ppd
, "InputSlot");
3882 media_type
= ppdFindMarkedChoice(ppd
, "MediaType");
3883 col
= new_media_col(pwgsize
,
3885 _ppdCacheGetSource(p
->pc
,
3886 input_slot
->choice
) :
3889 _ppdCacheGetType(p
->pc
,
3890 media_type
->choice
) :
3893 ippAddCollection(p
->ppd_attrs
, IPP_TAG_PRINTER
, "media-col-default",
3902 num_media
= p
->pc
->num_sizes
;
3903 if (p
->pc
->custom_min_keyword
)
3906 if ((attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3907 "media-supported", num_media
, NULL
,
3912 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
;
3914 i
--, pwgsize
++, val
++)
3915 val
->string
.text
= _cupsStrAlloc(pwgsize
->map
.pwg
);
3917 if (p
->pc
->custom_min_keyword
)
3919 val
->string
.text
= _cupsStrAlloc(p
->pc
->custom_min_keyword
);
3921 val
->string
.text
= _cupsStrAlloc(p
->pc
->custom_max_keyword
);
3926 * media-size-supported
3929 num_media
= p
->pc
->num_sizes
;
3930 if (p
->pc
->custom_min_keyword
)
3933 if ((attr
= ippAddCollections(p
->ppd_attrs
, IPP_TAG_PRINTER
,
3934 "media-size-supported", num_media
,
3939 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
;
3941 i
--, pwgsize
++, val
++)
3943 val
->collection
= ippNew();
3944 ippAddInteger(val
->collection
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3945 "x-dimension", pwgsize
->width
);
3946 ippAddInteger(val
->collection
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3947 "y-dimension", pwgsize
->length
);
3950 if (p
->pc
->custom_min_keyword
)
3952 val
->collection
= ippNew();
3953 ippAddRange(val
->collection
, IPP_TAG_PRINTER
, "x-dimension",
3954 p
->pc
->custom_min_width
, p
->pc
->custom_max_width
);
3955 ippAddRange(val
->collection
, IPP_TAG_PRINTER
, "y-dimension",
3956 p
->pc
->custom_min_length
, p
->pc
->custom_max_length
);
3961 * media-source-supported
3964 if (p
->pc
->num_sources
> 0 &&
3965 (attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3966 "media-source-supported", p
->pc
->num_sources
,
3967 NULL
, NULL
)) != NULL
)
3969 for (i
= p
->pc
->num_sources
, pwgsource
= p
->pc
->sources
,
3972 i
--, pwgsource
++, val
++)
3973 val
->string
.text
= _cupsStrAlloc(pwgsource
->pwg
);
3977 * media-type-supported
3980 if (p
->pc
->num_types
> 0 &&
3981 (attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3982 "media-type-supported", p
->pc
->num_types
,
3983 NULL
, NULL
)) != NULL
)
3985 for (i
= p
->pc
->num_types
, pwgtype
= p
->pc
->types
,
3988 i
--, pwgtype
++, val
++)
3989 val
->string
.text
= _cupsStrAlloc(pwgtype
->pwg
);
3993 * media-*-margin-supported
3996 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, num_margins
= 0;
3997 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4000 for (j
= 0; j
< num_margins
; j
++)
4001 if (pwgsize
->bottom
== margins
[j
])
4004 if (j
>= num_margins
)
4006 margins
[num_margins
] = pwgsize
->bottom
;
4011 if (num_margins
> 0)
4012 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4013 "media-bottom-margin-supported", num_margins
, margins
);
4015 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4016 "media-bottom-margin-supported", 0);
4018 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, num_margins
= 0;
4019 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4022 for (j
= 0; j
< num_margins
; j
++)
4023 if (pwgsize
->left
== margins
[j
])
4026 if (j
>= num_margins
)
4028 margins
[num_margins
] = pwgsize
->left
;
4033 if (num_margins
> 0)
4034 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4035 "media-left-margin-supported", num_margins
, margins
);
4037 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4038 "media-left-margin-supported", 0);
4040 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, num_margins
= 0;
4041 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4044 for (j
= 0; j
< num_margins
; j
++)
4045 if (pwgsize
->right
== margins
[j
])
4048 if (j
>= num_margins
)
4050 margins
[num_margins
] = pwgsize
->right
;
4055 if (num_margins
> 0)
4056 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4057 "media-right-margin-supported", num_margins
, margins
);
4059 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4060 "media-right-margin-supported", 0);
4062 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, num_margins
= 0;
4063 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4066 for (j
= 0; j
< num_margins
; j
++)
4067 if (pwgsize
->top
== margins
[j
])
4070 if (j
>= num_margins
)
4072 margins
[num_margins
] = pwgsize
->top
;
4077 if (num_margins
> 0)
4078 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4079 "media-top-margin-supported", num_margins
, margins
);
4081 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4082 "media-top-margin-supported", 0);
4085 * media-col-database
4088 num_media
= p
->pc
->num_sizes
;
4089 if (p
->pc
->num_sources
)
4091 if (p
->pc
->num_types
> 0)
4092 num_media
+= p
->pc
->num_sizes
* p
->pc
->num_sources
*
4095 num_media
+= p
->pc
->num_sizes
* p
->pc
->num_sources
;
4097 else if (p
->pc
->num_types
)
4098 num_media
+= p
->pc
->num_sizes
* p
->pc
->num_types
;
4100 if ((attr
= ippAddCollections(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4101 "media-col-database", num_media
,
4104 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, val
= attr
->values
;
4109 * Start by adding the page size without source or type...
4112 ppdMarkOption(ppd
, "PageSize", pwgsize
->map
.ppd
);
4114 val
->collection
= new_media_col(pwgsize
, NULL
, NULL
);
4118 * Then add the specific, supported combinations of size, source, and
4122 if (p
->pc
->num_sources
> 0)
4124 for (j
= p
->pc
->num_sources
, pwgsource
= p
->pc
->sources
;
4128 ppdMarkOption(ppd
, "InputSlot", pwgsource
->ppd
);
4130 if (p
->pc
->num_types
> 0)
4132 for (k
= p
->pc
->num_types
, pwgtype
= p
->pc
->types
;
4136 if (!ppdMarkOption(ppd
, "MediaType", pwgtype
->ppd
))
4138 val
->collection
= new_media_col(pwgsize
, pwgsource
->pwg
,
4144 else if (!ppdConflicts(ppd
))
4146 val
->collection
= new_media_col(pwgsize
, pwgsource
->pwg
, NULL
);
4151 else if (p
->pc
->num_types
> 0)
4153 for (j
= p
->pc
->num_types
, pwgtype
= p
->pc
->types
;
4157 if (!ppdMarkOption(ppd
, "MediaType", pwgtype
->ppd
))
4159 val
->collection
= new_media_col(pwgsize
, NULL
, pwgtype
->pwg
);
4167 * Update the number of media-col-database values...
4170 attr
->num_values
= val
- attr
->values
;
4178 if (p
->pc
&& p
->pc
->num_bins
> 0)
4180 attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4181 "output-bin-supported", p
->pc
->num_bins
,
4186 for (i
= 0, val
= attr
->values
;
4187 i
< p
->pc
->num_bins
;
4189 val
->string
.text
= _cupsStrAlloc(p
->pc
->bins
[i
].pwg
);
4192 if ((output_bin
= ppdFindOption(ppd
, "OutputBin")) != NULL
)
4194 for (i
= 0; i
< p
->pc
->num_bins
; i
++)
4195 if (!strcmp(p
->pc
->bins
[i
].ppd
, output_bin
->defchoice
))
4198 if (i
>= p
->pc
->num_bins
)
4201 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4202 "output-bin-default", NULL
, p
->pc
->bins
[i
].pwg
);
4205 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4206 "output-bin-default", NULL
, p
->pc
->bins
[0].pwg
);
4208 else if (((ppd_attr
= ppdFindAttr(ppd
, "DefaultOutputOrder",
4210 !_cups_strcasecmp(ppd_attr
->value
, "Reverse")) ||
4211 (!ppd_attr
&& ppd
->manufacturer
&& /* "Compatibility heuristic" */
4212 (!_cups_strcasecmp(ppd
->manufacturer
, "epson") ||
4213 !_cups_strcasecmp(ppd
->manufacturer
, "lexmark"))))
4216 * Report that this printer has a single output bin that leaves pages face
4220 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4221 "output-bin-supported", NULL
, "face-up");
4222 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4223 "output-bin-default", NULL
, "face-up");
4227 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4228 "output-bin-supported", NULL
, "face-down");
4229 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4230 "output-bin-default", NULL
, "face-down");
4234 * print-color-mode...
4237 if (ppd
->color_device
)
4239 static const char * const color_modes
[] =
4245 ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4246 "print-color-mode-supported", 2, NULL
, color_modes
);
4247 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4248 "print-color-mode-default", NULL
, "color");
4252 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4253 "print-color-mode-supported", NULL
, "monochrome");
4254 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4255 "print-color-mode-default", NULL
, "monochrome");
4259 * Mandatory job attributes, if any...
4262 if (p
->pc
&& cupsArrayCount(p
->pc
->mandatory
) > 0)
4264 int count
= cupsArrayCount(p
->pc
->mandatory
);
4265 /* Number of mandatory attributes */
4267 attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4268 "printer-mandatory-job-attributes", count
, NULL
,
4271 for (val
= attr
->values
,
4272 mandatory
= (char *)cupsArrayFirst(p
->pc
->mandatory
);
4274 val
++, mandatory
= (char *)cupsArrayNext(p
->pc
->mandatory
))
4275 val
->string
.text
= _cupsStrAlloc(mandatory
);
4279 * Printer resolutions...
4282 if ((resolution
= ppdFindOption(ppd
, "Resolution")) == NULL
)
4283 if ((resolution
= ppdFindOption(ppd
, "JCLResolution")) == NULL
)
4284 if ((resolution
= ppdFindOption(ppd
, "SetResolution")) == NULL
)
4285 resolution
= ppdFindOption(ppd
, "CNRes_PGP");
4290 * Report all supported resolutions...
4293 attr
= ippAddResolutions(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4294 "printer-resolution-supported",
4295 resolution
->num_choices
, IPP_RES_PER_INCH
,
4298 for (i
= 0, choice
= resolution
->choices
;
4299 i
< resolution
->num_choices
;
4302 xdpi
= ydpi
= (int)strtol(choice
->choice
, (char **)&resptr
, 10);
4303 if (resptr
> choice
->choice
&& xdpi
> 0 && *resptr
== 'x')
4304 ydpi
= (int)strtol(resptr
+ 1, (char **)&resptr
, 10);
4306 if (xdpi
<= 0 || ydpi
<= 0)
4308 cupsdLogMessage(CUPSD_LOG_WARN
,
4309 "Bad resolution \"%s\" for printer %s.",
4310 choice
->choice
, p
->name
);
4314 attr
->values
[i
].resolution
.xres
= xdpi
;
4315 attr
->values
[i
].resolution
.yres
= ydpi
;
4316 attr
->values
[i
].resolution
.units
= IPP_RES_PER_INCH
;
4319 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4320 "printer-resolution-default", IPP_RES_PER_INCH
,
4324 else if ((ppd_attr
= ppdFindAttr(ppd
, "DefaultResolution", NULL
)) != NULL
&&
4328 * Just the DefaultResolution to report...
4331 xdpi
= ydpi
= (int)strtol(ppd_attr
->value
, (char **)&resptr
, 10);
4332 if (resptr
> ppd_attr
->value
&& xdpi
> 0)
4335 ydpi
= (int)strtol(resptr
+ 1, (char **)&resptr
, 10);
4340 if (xdpi
<= 0 || ydpi
<= 0)
4342 cupsdLogMessage(CUPSD_LOG_WARN
,
4343 "Bad default resolution \"%s\" for printer %s.",
4344 ppd_attr
->value
, p
->name
);
4348 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4349 "printer-resolution-default", IPP_RES_PER_INCH
,
4351 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4352 "printer-resolution-supported", IPP_RES_PER_INCH
,
4358 * No resolutions in PPD - make one up...
4361 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4362 "printer-resolution-default", IPP_RES_PER_INCH
,
4364 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4365 "printer-resolution-supported", IPP_RES_PER_INCH
,
4373 ppdMarkDefaults(ppd
);
4375 if ((duplex
= ppdFindOption(ppd
, "Duplex")) == NULL
)
4376 if ((duplex
= ppdFindOption(ppd
, "EFDuplex")) == NULL
)
4377 if ((duplex
= ppdFindOption(ppd
, "EFDuplexing")) == NULL
)
4378 if ((duplex
= ppdFindOption(ppd
, "KD03Duplex")) == NULL
)
4379 duplex
= ppdFindOption(ppd
, "JCLDuplex");
4381 if (duplex
&& duplex
->num_choices
> 1 &&
4382 !ppdInstallableConflict(ppd
, duplex
->keyword
, "DuplexTumble"))
4384 p
->type
|= CUPS_PRINTER_DUPLEX
;
4386 ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4387 "sides-supported", 3, NULL
, sides
);
4389 if (!_cups_strcasecmp(duplex
->defchoice
, "DuplexTumble"))
4390 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4391 "sides-default", NULL
, "two-sided-short-edge");
4392 else if (!_cups_strcasecmp(duplex
->defchoice
, "DuplexNoTumble"))
4393 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4394 "sides-default", NULL
, "two-sided-long-edge");
4396 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4397 "sides-default", NULL
, "one-sided");
4401 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4402 "sides-supported", NULL
, "one-sided");
4403 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4404 "sides-default", NULL
, "one-sided");
4407 if (ppdFindOption(ppd
, "Collate") != NULL
)
4408 p
->type
|= CUPS_PRINTER_COLLATE
;
4410 if (ppdFindOption(ppd
, "StapleLocation") != NULL
)
4412 p
->type
|= CUPS_PRINTER_STAPLE
;
4413 finishings
[num_finishings
++] = IPP_FINISHINGS_STAPLE
;
4416 if (ppdFindOption(ppd
, "BindEdge") != NULL
)
4418 p
->type
|= CUPS_PRINTER_BIND
;
4419 finishings
[num_finishings
++] = IPP_FINISHINGS_BIND
;
4422 for (i
= 0; i
< ppd
->num_sizes
; i
++)
4423 if (ppd
->sizes
[i
].length
> 1728)
4424 p
->type
|= CUPS_PRINTER_LARGE
;
4425 else if (ppd
->sizes
[i
].length
> 1008)
4426 p
->type
|= CUPS_PRINTER_MEDIUM
;
4428 p
->type
|= CUPS_PRINTER_SMALL
;
4430 if ((ppd_attr
= ppdFindAttr(ppd
, "APICADriver", NULL
)) != NULL
&&
4431 ppd_attr
->value
&& !_cups_strcasecmp(ppd_attr
->value
, "true"))
4433 if ((ppd_attr
= ppdFindAttr(ppd
, "APScannerOnly", NULL
)) != NULL
&&
4434 ppd_attr
->value
&& !_cups_strcasecmp(ppd_attr
->value
, "true"))
4435 p
->type
|= CUPS_PRINTER_SCANNER
;
4437 p
->type
|= CUPS_PRINTER_MFP
;
4441 * Scan the filters in the PPD file...
4446 for (filter
= (const char *)cupsArrayFirst(p
->pc
->filters
);
4448 filter
= (const char *)cupsArrayNext(p
->pc
->filters
))
4450 if (!_cups_strncasecmp(filter
, "application/vnd.cups-command", 28) &&
4451 _cups_isspace(filter
[28]))
4453 p
->type
|= CUPS_PRINTER_COMMANDS
;
4459 if (p
->type
& CUPS_PRINTER_COMMANDS
)
4461 char *commands
, /* Copy of commands */
4462 *start
, /* Start of name */
4463 *end
; /* End of name */
4464 int count
; /* Number of commands */
4466 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsCommands", NULL
)) != NULL
)
4468 for (count
= 0, start
= ppd_attr
->value
; *start
; count
++)
4470 while (_cups_isspace(*start
))
4476 while (*start
&& !isspace(*start
& 255))
4486 * Make a copy of the commands string and count how many commands there
4490 attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4491 "printer-commands", count
, NULL
, NULL
);
4493 commands
= strdup(ppd_attr
->value
);
4495 for (count
= 0, start
= commands
; *start
; count
++)
4497 while (isspace(*start
& 255))
4504 while (*end
&& !isspace(*end
& 255))
4510 attr
->values
[count
].string
.text
= _cupsStrAlloc(start
);
4520 * Add the standard list of commands...
4523 ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4525 (int)(sizeof(standard_commands
) /
4526 sizeof(standard_commands
[0])), NULL
,
4533 * No commands supported...
4536 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4537 "printer-commands", NULL
, "none");
4541 * Show current and available port monitors for this printer...
4544 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
, "port-monitor",
4545 NULL
, p
->port_monitor
? p
->port_monitor
: "none");
4547 for (i
= 1, ppd_attr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
4549 i
++, ppd_attr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
));
4553 if (strstr(ppd
->protocols
, "TBCP"))
4555 else if (strstr(ppd
->protocols
, "BCP"))
4559 attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
4560 "port-monitor-supported", i
, NULL
, NULL
);
4562 attr
->values
[0].string
.text
= _cupsStrAlloc("none");
4564 for (i
= 1, ppd_attr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
4566 i
++, ppd_attr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
))
4567 attr
->values
[i
].string
.text
= _cupsStrAlloc(ppd_attr
->value
);
4571 if (strstr(ppd
->protocols
, "TBCP"))
4572 attr
->values
[i
].string
.text
= _cupsStrAlloc("tbcp");
4573 else if (strstr(ppd
->protocols
, "BCP"))
4574 attr
->values
[i
].string
.text
= _cupsStrAlloc("bcp");
4577 if (ppdFindAttr(ppd
, "APRemoteQueueID", NULL
))
4578 p
->type
|= CUPS_PRINTER_REMOTE
;
4580 #ifdef HAVE_APPLICATIONSERVICES_H
4582 * Convert the file referenced in APPrinterIconPath to a 128x128 PNG
4583 * and save it as cacheDir/printername.png
4586 if ((ppd_attr
= ppdFindAttr(ppd
, "APPrinterIconPath", NULL
)) != NULL
&&
4588 !_cupsFileCheck(ppd_attr
->value
, _CUPS_FILE_CHECK_FILE
, !RunUser
,
4589 cupsdLogFCMessage
, p
))
4591 CGImageRef imageRef
= NULL
;/* Current icon image */
4592 CGImageRef biggestIconRef
= NULL
;
4593 /* Biggest icon image */
4594 CGImageRef closestTo128IconRef
= NULL
;
4595 /* Icon image closest to and >= 128 */
4596 CGImageSourceRef sourceRef
; /* The file's image source */
4597 char outPath
[HTTP_MAX_URI
];
4598 /* The path to the PNG file */
4599 CFURLRef outUrl
; /* The URL made from the outPath */
4600 CFURLRef icnsFileUrl
; /* The URL of the original ICNS icon file */
4601 CGImageDestinationRef destRef
; /* The image destination to write */
4602 size_t bytesPerRow
; /* The bytes per row used for resizing */
4603 CGContextRef context
; /* The CG context used for resizing */
4605 snprintf(outPath
, sizeof(outPath
), "%s/%s.png", CacheDir
, p
->name
);
4606 outUrl
= CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault
,
4610 icnsFileUrl
= CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault
,
4611 (UInt8
*)ppd_attr
->value
,
4612 strlen(ppd_attr
->value
),
4614 if (outUrl
&& icnsFileUrl
)
4616 sourceRef
= CGImageSourceCreateWithURL(icnsFileUrl
, NULL
);
4619 for (i
= 0; i
< CGImageSourceGetCount(sourceRef
); i
++)
4621 imageRef
= CGImageSourceCreateImageAtIndex(sourceRef
, i
, NULL
);
4625 if (CGImageGetWidth(imageRef
) == CGImageGetHeight(imageRef
))
4628 * Loop through remembering the icon closest to 128 but >= 128
4629 * and then remember the largest icon.
4632 if (CGImageGetWidth(imageRef
) >= 128 &&
4633 (!closestTo128IconRef
||
4634 CGImageGetWidth(imageRef
) <
4635 CGImageGetWidth(closestTo128IconRef
)))
4637 CGImageRelease(closestTo128IconRef
);
4638 CGImageRetain(imageRef
);
4639 closestTo128IconRef
= imageRef
;
4642 if (!biggestIconRef
||
4643 CGImageGetWidth(imageRef
) > CGImageGetWidth(biggestIconRef
))
4645 CGImageRelease(biggestIconRef
);
4646 CGImageRetain(imageRef
);
4647 biggestIconRef
= imageRef
;
4651 CGImageRelease(imageRef
);
4657 * If biggestIconRef is NULL, we found no icons. Otherwise we first
4658 * want the closest to 128, but if none are larger than 128, we want
4659 * the largest icon available.
4662 imageRef
= closestTo128IconRef
? closestTo128IconRef
:
4664 CGImageRetain(imageRef
);
4665 CGImageRelease(biggestIconRef
);
4666 if (closestTo128IconRef
)
4667 CGImageRelease(closestTo128IconRef
);
4668 destRef
= CGImageDestinationCreateWithURL(outUrl
, kUTTypePNG
, 1,
4672 if (CGImageGetWidth(imageRef
) != 128)
4674 bytesPerRow
= CGImageGetBytesPerRow(imageRef
) /
4675 CGImageGetWidth(imageRef
) * 128;
4676 context
= CGBitmapContextCreate(NULL
, 128, 128,
4677 CGImageGetBitsPerComponent(imageRef
),
4679 CGImageGetColorSpace(imageRef
),
4680 kCGImageAlphaPremultipliedFirst
);
4683 CGContextDrawImage(context
, CGRectMake(0, 0, 128, 128),
4685 CGImageRelease(imageRef
);
4686 imageRef
= CGBitmapContextCreateImage(context
);
4687 CGContextRelease(context
);
4691 CGImageDestinationAddImage(destRef
, imageRef
, NULL
);
4692 CGImageDestinationFinalize(destRef
);
4696 CGImageRelease(imageRef
);
4699 CFRelease(sourceRef
);
4707 CFRelease(icnsFileUrl
);
4709 #endif /* HAVE_APPLICATIONSERVICES_H */
4712 * Close the PPD and set the type...
4717 else if (!access(ppd_name
, 0))
4719 int pline
; /* PPD line number */
4720 ppd_status_t pstatus
; /* PPD load status */
4723 pstatus
= ppdLastError(&pline
);
4725 cupsdLogMessage(CUPSD_LOG_ERROR
, "PPD file for %s cannot be loaded!",
4728 if (pstatus
<= PPD_ALLOC_ERROR
)
4729 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s", strerror(errno
));
4731 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s on line %d.",
4732 ppdErrorString(pstatus
), pline
);
4734 cupsdLogMessage(CUPSD_LOG_INFO
,
4735 "Hint: Run \"cupstestppd %s\" and fix any errors.",
4741 * If we have an interface script, add a filter entry for it...
4744 char interface
[1024]; /* Interface script */
4747 snprintf(interface
, sizeof(interface
), "%s/interfaces/%s", ServerRoot
,
4749 if (!access(interface
, X_OK
))
4752 * Yes, we have a System V style interface script; use it!
4755 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
4756 "printer-make-and-model", NULL
,
4757 "Local System V Printer");
4759 else if (((!strncmp(p
->device_uri
, "ipp://", 6) ||
4760 !strncmp(p
->device_uri
, "ipps://", 7)) &&
4761 (strstr(p
->device_uri
, "/printers/") != NULL
||
4762 strstr(p
->device_uri
, "/classes/") != NULL
)) ||
4763 ((strstr(p
->device_uri
, "._ipp.") != NULL
||
4764 strstr(p
->device_uri
, "._ipps.") != NULL
) &&
4765 !strcmp(p
->device_uri
+ strlen(p
->device_uri
) - 5, "/cups")))
4768 * Tell the client this is really a hard-wired remote printer.
4771 p
->type
|= CUPS_PRINTER_REMOTE
;
4774 * Point the printer-uri-supported attribute to the
4778 if (strchr(p
->device_uri
, '?'))
4781 * Strip trailing "?options" from URI...
4784 char resource
[HTTP_MAX_URI
], /* New URI */
4785 *ptr
; /* Pointer into URI */
4787 strlcpy(resource
, p
->device_uri
, sizeof(resource
));
4788 if ((ptr
= strchr(resource
, '?')) != NULL
)
4791 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
4792 "printer-uri-supported", NULL
, resource
);
4795 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
4796 "printer-uri-supported", NULL
, p
->device_uri
);
4799 * Then set the make-and-model accordingly...
4802 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
4803 "printer-make-and-model", NULL
, "Remote Printer");
4806 * Print all files directly...
4815 * Otherwise we have neither - treat this as a "dumb" printer
4816 * with no PPD file...
4819 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
4820 "printer-make-and-model", NULL
, "Local Raw Printer");
4826 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
4827 "finishings-supported", num_finishings
, finishings
);
4828 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
4829 "finishings-default", IPP_FINISHINGS_NONE
);
4834 * Save cached PPD attributes to disk...
4837 cupsdLogMessage(CUPSD_LOG_DEBUG
, "load_ppd: Saving %s...", cache_name
);
4839 _ppdCacheWriteFile(p
->pc
, cache_name
, p
->ppd_attrs
);
4844 * Remove cache files...
4847 if (cache_info
.st_mtime
)
4854 * 'log_ipp_conformance()' - Log an IPP conformance issue with a printer.
4858 log_ipp_conformance(
4859 cupsd_printer_t
*p
, /* I - Printer */
4860 const char *reason
) /* I - Printer state reason */
4862 const char *message
; /* Message to log */
4864 aslmsg aslm
; /* Apple System Log message */
4865 #endif /* __APPLE__ */
4869 * Strip the leading "cups-ipp-" from the reason and create a log message for
4874 if (!strcmp(reason
, "missing-cancel-job"))
4875 message
= "Printer does not support REQUIRED Cancel-Job operation.";
4876 else if (!strcmp(reason
, "missing-get-job-attributes"))
4877 message
= "Printer does not support REQUIRED Get-Job-Attributes operation.";
4878 else if (!strcmp(reason
, "missing-print-job"))
4879 message
= "Printer does not support REQUIRED Print-Job operation.";
4880 else if (!strcmp(reason
, "missing-validate-job"))
4881 message
= "Printer does not support REQUIRED Validate-Job operation.";
4882 else if (!strcmp(reason
, "missing-get-printer-attributes"))
4883 message
= "Printer does not support REQUIRED Get-Printer-Attributes operation.";
4884 else if (!strcmp(reason
, "missing-send-document"))
4885 message
= "Printer supports Create-Job but not Send-Document operation.";
4886 else if (!strcmp(reason
, "missing-job-history"))
4887 message
= "Printer does not provide REQUIRED job history.";
4888 else if (!strcmp(reason
, "missing-job-id"))
4889 message
= "Printer does not provide REQUIRED job-id attribute.";
4890 else if (!strcmp(reason
, "missing-job-state"))
4891 message
= "Printer does not provide REQUIRED job-state attribute.";
4892 else if (!strcmp(reason
, "missing-operations-supported"))
4893 message
= "Printer does not provide REQUIRED operations-supported "
4895 else if (!strcmp(reason
, "missing-printer-is-accepting-jobs"))
4896 message
= "Printer does not provide REQUIRED printer-is-accepting-jobs "
4898 else if (!strcmp(reason
, "missing-printer-state-reasons"))
4899 message
= "Printer does not provide REQUIRED printer-state-reasons "
4901 else if (!strcmp(reason
, "wrong-http-version"))
4902 message
= "Printer does not use REQUIRED HTTP/1.1 transport.";
4904 message
= "Unknown IPP conformance failure.";
4906 cupsdLogMessage(CUPSD_LOG_WARN
, "%s: %s", p
->name
, message
);
4910 * Report the failure information to Apple if the user opts into providing
4911 * feedback to Apple...
4914 aslm
= asl_new(ASL_TYPE_MSG
);
4917 asl_set(aslm
, "com.apple.message.domain", "com.apple.printing.ipp.conformance");
4918 asl_set(aslm
, "com.apple.message.domain_scope", "com.apple.printing.ipp.conformance");
4919 asl_set(aslm
, "com.apple.message.signature", reason
);
4920 asl_set(aslm
, "com.apple.message.signature2",
4921 p
->make_model
? p
->make_model
: "Unknown");
4922 asl_log(NULL
, aslm
, ASL_LEVEL_NOTICE
, "%s: %s",
4923 p
->make_model
? p
->make_model
: "Unknown", message
);
4926 #endif /* __APPLE__ */
4931 * 'new_media_col()' - Create a media-col collection value.
4934 static ipp_t
* /* O - Collection value */
4935 new_media_col(_pwg_size_t
*size
, /* I - media-size/margin values */
4936 const char *source
, /* I - media-source value */
4937 const char *type
) /* I - media-type value */
4939 ipp_t
*media_col
, /* Collection value */
4940 *media_size
; /* media-size value */
4943 media_col
= ippNew();
4945 media_size
= ippNew();
4946 ippAddInteger(media_size
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4947 "x-dimension", size
->width
);
4948 ippAddInteger(media_size
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4949 "y-dimension", size
->length
);
4950 ippAddCollection(media_col
, IPP_TAG_PRINTER
, "media-size", media_size
);
4951 ippDelete(media_size
);
4953 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4954 "media-bottom-margin", size
->bottom
);
4955 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4956 "media-left-margin", size
->left
);
4957 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4958 "media-right-margin", size
->right
);
4959 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4960 "media-top-margin", size
->top
);
4963 ippAddString(media_col
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
, "media-source",
4967 ippAddString(media_col
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
, "media-type",
4975 * 'write_xml_string()' - Write a string with XML escaping.
4979 write_xml_string(cups_file_t
*fp
, /* I - File to write to */
4980 const char *s
) /* I - String to write */
4982 const char *start
; /* Start of current sequence */
4988 for (start
= s
; *s
; s
++)
4993 cupsFileWrite(fp
, start
, s
- start
);
4995 cupsFilePuts(fp
, "&");
5001 cupsFileWrite(fp
, start
, s
- start
);
5003 cupsFilePuts(fp
, "<");
5009 cupsFilePuts(fp
, start
);
5014 * End of "$Id: printers.c 11418 2013-11-08 15:18:01Z msweet $".