4 * Printer routines for the CUPS scheduler.
6 * Copyright 2007-2014 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 ipp_t
*new_media_col(_pwg_size_t
*size
, const char *source
,
55 static void write_xml_string(cups_file_t
*fp
, const char *s
);
59 * 'cupsdAddPrinter()' - Add a printer to the system.
62 cupsd_printer_t
* /* O - New printer */
63 cupsdAddPrinter(const char *name
) /* I - Name of printer */
65 cupsd_printer_t
*p
; /* New printer */
66 char uri
[1024], /* Printer URI */
67 uuid
[64]; /* Printer UUID */
71 * Range check input...
74 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdAddPrinter(\"%s\")", name
);
77 * Create a new printer entity...
80 if ((p
= calloc(1, sizeof(cupsd_printer_t
))) == NULL
)
82 cupsdLogMessage(CUPSD_LOG_CRIT
, "Unable to allocate memory for printer - %s",
87 cupsdSetString(&p
->name
, name
);
88 cupsdSetString(&p
->info
, name
);
89 cupsdSetString(&p
->hostname
, ServerName
);
91 httpAssembleURIf(HTTP_URI_CODING_ALL
, uri
, sizeof(uri
), "ipp", NULL
,
92 ServerName
, RemotePort
, "/printers/%s", name
);
93 cupsdSetString(&p
->uri
, uri
);
94 cupsdSetString(&p
->uuid
, httpAssembleUUID(ServerName
, RemotePort
, name
, 0,
96 cupsdSetDeviceURI(p
, "file:///dev/null");
98 p
->state
= IPP_PRINTER_STOPPED
;
99 p
->state_time
= time(NULL
);
101 p
->shared
= DefaultShared
;
102 p
->filetype
= mimeAddType(MimeDatabase
, "printer", name
);
104 cupsdSetString(&p
->job_sheets
[0], "none");
105 cupsdSetString(&p
->job_sheets
[1], "none");
107 cupsdSetString(&p
->error_policy
, ErrorPolicy
);
108 cupsdSetString(&p
->op_policy
, DefaultPolicy
);
110 p
->op_policy_ptr
= DefaultPolicyPtr
;
113 * Insert the printer in the printer list alphabetically...
117 Printers
= cupsArrayNew(compare_printers
, NULL
);
119 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
120 "cupsdAddPrinter: Adding %s to Printers", p
->name
);
121 cupsArrayAdd(Printers
, p
);
124 * Return the new printer...
132 * 'cupsdCreateCommonData()' - Create the common printer data.
136 cupsdCreateCommonData(void)
138 int i
; /* Looping var */
139 ipp_attribute_t
*attr
; /* Attribute data */
140 cups_dir_t
*dir
; /* Notifier directory */
141 cups_dentry_t
*dent
; /* Notifier directory entry */
142 cups_array_t
*notifiers
; /* Notifier array */
143 char filename
[1024], /* Filename */
144 *notifier
; /* Current notifier */
145 cupsd_policy_t
*p
; /* Current policy */
146 int k_supported
; /* Maximum file size supported */
148 struct statvfs spoolinfo
; /* FS info for spool directory */
149 double spoolsize
; /* FS size */
150 #elif defined(HAVE_STATFS)
151 struct statfs spoolinfo
; /* FS info for spool directory */
152 double spoolsize
; /* FS size */
153 #endif /* HAVE_STATVFS */
154 static const int nups
[] = /* number-up-supported values */
155 { 1, 2, 4, 6, 9, 16 };
156 static const int orients
[4] =/* orientation-requested-supported values */
160 IPP_REVERSE_LANDSCAPE
,
163 static const char * const holds
[] = /* job-hold-until-supported values */
174 static const char * const versions
[] =/* ipp-versions-supported values */
181 static const int ops
[] = /* operations-supported values */
188 IPP_GET_JOB_ATTRIBUTES
,
190 IPP_GET_PRINTER_ATTRIBUTES
,
197 IPP_SET_PRINTER_ATTRIBUTES
,
198 IPP_SET_JOB_ATTRIBUTES
,
199 IPP_GET_PRINTER_SUPPORTED_VALUES
,
200 IPP_CREATE_PRINTER_SUBSCRIPTION
,
201 IPP_CREATE_JOB_SUBSCRIPTION
,
202 IPP_GET_SUBSCRIPTION_ATTRIBUTES
,
203 IPP_GET_SUBSCRIPTIONS
,
204 IPP_RENEW_SUBSCRIPTION
,
205 IPP_CANCEL_SUBSCRIPTION
,
206 IPP_GET_NOTIFICATIONS
,
210 IPP_RELEASE_HELD_NEW_JOBS
,
227 CUPS_AUTHENTICATE_JOB
,
232 static const char * const charsets
[] =/* charset-supported values */
237 static const char * const compressions
[] =
238 { /* document-compression-supported values */
242 #endif /* HAVE_LIBZ */
244 static const char * const media_col_supported
[] =
245 { /* media-col-supported values */
246 "media-bottom-margin",
248 "media-right-margin",
254 static const char * const multiple_document_handling
[] =
255 { /* multiple-document-handling-supported values */
256 "separate-documents-uncollated-copies",
257 "separate-documents-collated-copies"
259 static const char * const notify_attrs
[] =
260 { /* notify-attributes-supported values */
261 "printer-state-change-time",
262 "notify-lease-expiration-time",
263 "notify-subscriber-user-name"
265 static const char * const notify_events
[] =
266 { /* notify-events-supported values */
268 "job-config-changed",
275 "printer-config-changed",
277 "printer-finishings-changed",
278 "printer-media-changed",
282 "printer-state-changed",
289 static const char * const job_creation
[] =
290 { /* job-creation-attributes-supported */
293 "ipp-attribute-fidelity",
300 "multiple-document-handling",
303 "orientation-requested",
307 "printer-resolution",
310 static const char * const job_settable
[] =
311 { /* job-settable-attributes-supported */
319 "multiple-document-handling",
322 "orientation-requested",
326 "printer-resolution",
329 static const char * const pdf_versions
[] =
330 { /* pdf-versions-supported */
341 static const char * const printer_settable
[] =
342 { /* printer-settable-attributes-supported */
346 static const char * const which_jobs
[] =
347 { /* which-jobs-supported values */
361 ippDelete(CommonData
);
363 CommonData
= ippNew();
366 * Get the maximum spool size based on the size of the filesystem used for
367 * the RequestRoot directory. If the host OS doesn't support the statfs call
368 * or the filesystem is larger than 2TiB, always report INT_MAX.
372 if (statvfs(RequestRoot
, &spoolinfo
))
373 k_supported
= INT_MAX
;
374 else if ((spoolsize
= (double)spoolinfo
.f_frsize
* spoolinfo
.f_blocks
/ 1024) >
376 k_supported
= INT_MAX
;
378 k_supported
= (int)spoolsize
;
380 #elif defined(HAVE_STATFS)
381 if (statfs(RequestRoot
, &spoolinfo
))
382 k_supported
= INT_MAX
;
383 else if ((spoolsize
= (double)spoolinfo
.f_bsize
* spoolinfo
.f_blocks
/ 1024) >
385 k_supported
= INT_MAX
;
387 k_supported
= (int)spoolsize
;
390 k_supported
= INT_MAX
;
391 #endif /* HAVE_STATVFS */
394 * This list of attributes is sorted to improve performance when the
395 * client provides a requested-attributes attribute...
398 /* charset-configured */
399 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_CHARSET
| IPP_TAG_COPY
,
400 "charset-configured", NULL
, "utf-8");
402 /* charset-supported */
403 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_CHARSET
| IPP_TAG_COPY
,
404 "charset-supported", sizeof(charsets
) / sizeof(charsets
[0]),
407 /* compression-supported */
408 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
409 "compression-supported",
410 sizeof(compressions
) / sizeof(compressions
[0]),
413 /* copies-supported */
414 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "copies-supported", 1, MaxCopies
);
417 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
| IPP_TAG_COPY
,
418 "cups-version", NULL
, CUPS_SVERSION
+ 6);
420 /* generated-natural-language-supported (no IPP_TAG_COPY) */
421 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_LANGUAGE
,
422 "generated-natural-language-supported", NULL
, DefaultLanguage
);
424 /* ipp-versions-supported */
425 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
426 "ipp-versions-supported", sizeof(versions
) / sizeof(versions
[0]),
429 /* ippget-event-life */
430 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
431 "ippget-event-life", 15);
433 /* job-cancel-after-supported */
434 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "job-cancel-after-supported",
437 /* job-creation-attributes-supported */
438 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
439 "job-creation-attributes-supported",
440 sizeof(job_creation
) / sizeof(job_creation
[0]),
443 /* job-hold-until-supported */
444 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
445 "job-hold-until-supported", sizeof(holds
) / sizeof(holds
[0]),
448 /* job-ids-supported */
449 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
, "job-ids-supported", 1);
451 /* job-k-octets-supported */
452 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "job-k-octets-supported", 0,
455 /* job-priority-supported */
456 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
457 "job-priority-supported", 100);
459 /* job-settable-attributes-supported */
460 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
461 "job-settable-attributes-supported",
462 sizeof(job_settable
) / sizeof(job_settable
[0]),
465 /* job-sheets-supported */
466 if (cupsArrayCount(Banners
) > 0)
469 * Setup the job-sheets-supported attribute...
472 if (Classification
&& !ClassifyOverride
)
473 attr
= ippAddString(CommonData
, IPP_TAG_PRINTER
,
474 IPP_TAG_NAME
| IPP_TAG_COPY
,
475 "job-sheets-supported", NULL
, Classification
);
477 attr
= ippAddStrings(CommonData
, IPP_TAG_PRINTER
,
478 IPP_TAG_NAME
| IPP_TAG_COPY
,
479 "job-sheets-supported", cupsArrayCount(Banners
) + 1,
483 cupsdLogMessage(CUPSD_LOG_EMERG
,
484 "Unable to allocate memory for "
485 "job-sheets-supported attribute: %s!", strerror(errno
));
486 else if (!Classification
|| ClassifyOverride
)
488 cupsd_banner_t
*banner
; /* Current banner */
491 attr
->values
[0].string
.text
= _cupsStrAlloc("none");
493 for (i
= 1, banner
= (cupsd_banner_t
*)cupsArrayFirst(Banners
);
495 i
++, banner
= (cupsd_banner_t
*)cupsArrayNext(Banners
))
496 attr
->values
[i
].string
.text
= banner
->name
;
500 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
501 "job-sheets-supported", NULL
, "none");
503 /* jpeg-k-octets-supported */
504 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "jpeg-k-octets-supported", 0,
507 /* jpeg-x-dimension-supported */
508 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "jpeg-x-dimension-supported", 0,
511 /* jpeg-y-dimension-supported */
512 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "jpeg-y-dimension-supported", 1,
515 /* media-col-supported */
516 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
517 "media-col-supported",
518 sizeof(media_col_supported
) /
519 sizeof(media_col_supported
[0]), NULL
,
520 media_col_supported
);
522 /* multiple-document-handling-supported */
523 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
524 "multiple-document-handling-supported",
525 sizeof(multiple_document_handling
) /
526 sizeof(multiple_document_handling
[0]), NULL
,
527 multiple_document_handling
);
529 /* multiple-document-jobs-supported */
530 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
,
531 "multiple-document-jobs-supported", 1);
533 /* multiple-operation-time-out */
534 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
535 "multiple-operation-time-out", MultipleOperationTimeout
);
537 /* natural-language-configured (no IPP_TAG_COPY) */
538 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_LANGUAGE
,
539 "natural-language-configured", NULL
, DefaultLanguage
);
541 /* notify-attributes-supported */
542 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
543 "notify-attributes-supported",
544 (int)(sizeof(notify_attrs
) / sizeof(notify_attrs
[0])),
547 /* notify-lease-duration-supported */
548 ippAddRange(CommonData
, IPP_TAG_PRINTER
,
549 "notify-lease-duration-supported", 0,
550 MaxLeaseDuration
? MaxLeaseDuration
: 2147483647);
552 /* notify-max-events-supported */
553 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
554 "notify-max-events-supported", MaxEvents
);
556 /* notify-events-supported */
557 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
558 "notify-events-supported",
559 (int)(sizeof(notify_events
) / sizeof(notify_events
[0])),
560 NULL
, notify_events
);
562 /* notify-pull-method-supported */
563 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
564 "notify-pull-method-supported", NULL
, "ippget");
566 /* notify-schemes-supported */
567 snprintf(filename
, sizeof(filename
), "%s/notifier", ServerBin
);
568 if ((dir
= cupsDirOpen(filename
)) != NULL
)
570 notifiers
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
572 while ((dent
= cupsDirRead(dir
)) != NULL
)
573 if (S_ISREG(dent
->fileinfo
.st_mode
) &&
574 (dent
->fileinfo
.st_mode
& S_IXOTH
) != 0)
575 cupsArrayAdd(notifiers
, _cupsStrAlloc(dent
->filename
));
577 if (cupsArrayCount(notifiers
) > 0)
579 attr
= ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
580 "notify-schemes-supported",
581 cupsArrayCount(notifiers
), NULL
, NULL
);
583 for (i
= 0, notifier
= (char *)cupsArrayFirst(notifiers
);
585 i
++, notifier
= (char *)cupsArrayNext(notifiers
))
586 attr
->values
[i
].string
.text
= notifier
;
589 cupsArrayDelete(notifiers
);
593 /* number-up-supported */
594 ippAddIntegers(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
595 "number-up-supported", sizeof(nups
) / sizeof(nups
[0]), nups
);
597 /* operations-supported */
598 ippAddIntegers(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
599 "operations-supported", sizeof(ops
) / sizeof(ops
[0]), ops
);
601 /* orientation-requested-supported */
602 ippAddIntegers(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
603 "orientation-requested-supported", 4, orients
);
605 /* page-ranges-supported */
606 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
, "page-ranges-supported", 1);
608 /* pdf-k-octets-supported */
609 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "pdf-k-octets-supported", 0,
612 /* pdf-versions-supported */
613 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
614 "pdf-versions-supported",
615 sizeof(pdf_versions
) / sizeof(pdf_versions
[0]), NULL
,
618 /* pdl-override-supported */
619 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
620 "pdl-override-supported", NULL
, "attempted");
622 /* printer-op-policy-supported */
623 attr
= ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
624 "printer-op-policy-supported", cupsArrayCount(Policies
),
626 for (i
= 0, p
= (cupsd_policy_t
*)cupsArrayFirst(Policies
);
628 i
++, p
= (cupsd_policy_t
*)cupsArrayNext(Policies
))
629 attr
->values
[i
].string
.text
= p
->name
;
631 /* printer-settable-attributes-supported */
632 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
633 "printer-settable-attributes-supported",
634 sizeof(printer_settable
) / sizeof(printer_settable
[0]),
635 NULL
, printer_settable
);
637 /* server-is-sharing-printers */
638 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
, "server-is-sharing-printers",
639 BrowseLocalProtocols
!= 0 && Browsing
);
641 /* which-jobs-supported */
642 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
643 "which-jobs-supported",
644 sizeof(which_jobs
) / sizeof(which_jobs
[0]), NULL
, which_jobs
);
649 * 'cupsdDeleteAllPrinters()' - Delete all printers from the system.
653 cupsdDeleteAllPrinters(void)
655 cupsd_printer_t
*p
; /* Pointer to current printer/class */
658 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
660 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
662 p
->op_policy_ptr
= DefaultPolicyPtr
;
663 cupsdDeletePrinter(p
, 0);
669 * 'cupsdDeletePrinter()' - Delete a printer from the system.
672 int /* O - 1 if classes affected, 0 otherwise */
674 cupsd_printer_t
*p
, /* I - Printer to delete */
675 int update
) /* I - Update printers.conf? */
677 int i
, /* Looping var */
678 changed
= 0; /* Class changed? */
681 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdDeletePrinter(p=%p(%s), update=%d)",
685 * Save the current position in the Printers array...
688 cupsArraySave(Printers
);
691 * Stop printing on this printer...
694 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, update
);
696 p
->state
= IPP_PRINTER_STOPPED
; /* Force for browsed printers */
699 cupsdSetJobState(p
->job
, IPP_JOB_PENDING
, CUPSD_JOB_FORCE
,
700 update
? "Job stopped due to printer being deleted." :
704 * Remove the printer from the list...
707 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
708 "cupsdDeletePrinter: Removing %s from Printers", p
->name
);
709 cupsArrayRemove(Printers
, p
);
712 * If p is the default printer, assign a different one...
715 if (p
== DefaultPrinter
)
716 DefaultPrinter
= NULL
;
719 * Remove this printer from any classes...
722 changed
= cupsdDeletePrinterFromClasses(p
);
725 * Deregister from any browse protocols...
728 cupsdDeregisterPrinter(p
, 1);
731 * Free all memory used by the printer...
734 if (p
->printers
!= NULL
)
737 delete_printer_filters(p
);
739 for (i
= 0; i
< p
->num_reasons
; i
++)
740 _cupsStrFree(p
->reasons
[i
]);
743 ippDelete(p
->ppd_attrs
);
745 mimeDeleteType(MimeDatabase
, p
->filetype
);
746 mimeDeleteType(MimeDatabase
, p
->prefiltertype
);
748 cupsdFreeStrings(&(p
->users
));
751 cupsdClearString(&p
->uri
);
752 cupsdClearString(&p
->hostname
);
753 cupsdClearString(&p
->name
);
754 cupsdClearString(&p
->location
);
755 cupsdClearString(&p
->make_model
);
756 cupsdClearString(&p
->info
);
757 cupsdClearString(&p
->job_sheets
[0]);
758 cupsdClearString(&p
->job_sheets
[1]);
759 cupsdClearString(&p
->device_uri
);
760 cupsdClearString(&p
->sanitized_device_uri
);
761 cupsdClearString(&p
->port_monitor
);
762 cupsdClearString(&p
->op_policy
);
763 cupsdClearString(&p
->error_policy
);
765 cupsdClearString(&p
->alert
);
766 cupsdClearString(&p
->alert_description
);
768 #if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
769 cupsdClearString(&p
->pdl
);
770 cupsdClearString(&p
->reg_name
);
771 #endif /* HAVE_DNSSD || HAVE_AVAHI */
773 cupsArrayDelete(p
->filetypes
);
775 cupsFreeOptions(p
->num_options
, p
->options
);
780 * Restore the previous position in the Printers array...
783 cupsArrayRestore(Printers
);
790 * 'cupsdFindDest()' - Find a destination in the list.
793 cupsd_printer_t
* /* O - Destination in list */
794 cupsdFindDest(const char *name
) /* I - Name of printer or class to find */
796 cupsd_printer_t key
; /* Search key */
799 key
.name
= (char *)name
;
800 return ((cupsd_printer_t
*)cupsArrayFind(Printers
, &key
));
805 * 'cupsdFindPrinter()' - Find a printer in the list.
808 cupsd_printer_t
* /* O - Printer in list */
809 cupsdFindPrinter(const char *name
) /* I - Name of printer to find */
811 cupsd_printer_t
*p
; /* Printer in list */
814 if ((p
= cupsdFindDest(name
)) != NULL
&& (p
->type
& CUPS_PRINTER_CLASS
))
822 * 'cupsdLoadAllPrinters()' - Load printers from the printers.conf file.
826 cupsdLoadAllPrinters(void)
828 int i
; /* Looping var */
829 cups_file_t
*fp
; /* printers.conf file */
830 int linenum
; /* Current line number */
831 char line
[4096], /* Line from file */
832 *value
, /* Pointer to value */
833 *valueptr
; /* Pointer into value */
834 cupsd_printer_t
*p
; /* Current printer */
838 * Open the printers.conf file...
841 snprintf(line
, sizeof(line
), "%s/printers.conf", ServerRoot
);
842 if ((fp
= cupsdOpenConfFile(line
)) == NULL
)
846 * Read printer configurations until we hit EOF...
852 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
855 * Decode the directive...
858 if (!_cups_strcasecmp(line
, "<Printer") ||
859 !_cups_strcasecmp(line
, "<DefaultPrinter"))
862 * <Printer name> or <DefaultPrinter name>
865 if (p
== NULL
&& value
)
868 * Add the printer and a base file type...
871 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Loading printer %s...", value
);
873 p
= cupsdAddPrinter(value
);
875 p
->state
= IPP_PRINTER_IDLE
;
878 * Set the default printer as needed...
881 if (!_cups_strcasecmp(line
, "<DefaultPrinter"))
885 cupsdLogMessage(CUPSD_LOG_ERROR
,
886 "Syntax error on line %d of printers.conf.", linenum
);
888 else if (!_cups_strcasecmp(line
, "</Printer>"))
893 * Close out the current printer...
896 cupsdSetPrinterAttrs(p
);
898 if (strncmp(p
->device_uri
, "file:", 5) &&
899 p
->state
!= IPP_PRINTER_STOPPED
)
902 * See if the backend exists...
905 snprintf(line
, sizeof(line
), "%s/backend/%s", ServerBin
,
908 if ((valueptr
= strchr(line
+ strlen(ServerBin
), ':')) != NULL
)
909 *valueptr
= '\0'; /* Chop everything but URI scheme */
914 * Backend does not exist, stop printer...
917 p
->state
= IPP_PRINTER_STOPPED
;
918 snprintf(p
->state_message
, sizeof(p
->state_message
),
919 "Backend %s does not exist!", line
);
926 cupsdLogMessage(CUPSD_LOG_ERROR
,
927 "Syntax error on line %d of printers.conf.", linenum
);
931 cupsdLogMessage(CUPSD_LOG_ERROR
,
932 "Syntax error on line %d of printers.conf.", linenum
);
934 else if (!_cups_strcasecmp(line
, "UUID"))
936 if (value
&& !strncmp(value
, "urn:uuid:", 9))
937 cupsdSetString(&(p
->uuid
), value
);
939 cupsdLogMessage(CUPSD_LOG_ERROR
,
940 "Bad UUID on line %d of printers.conf.", linenum
);
942 else if (!_cups_strcasecmp(line
, "AuthInfoRequired"))
944 if (!cupsdSetAuthInfoRequired(p
, value
, NULL
))
945 cupsdLogMessage(CUPSD_LOG_ERROR
,
946 "Bad AuthInfoRequired on line %d of printers.conf.",
949 else if (!_cups_strcasecmp(line
, "Info"))
952 cupsdSetString(&p
->info
, value
);
954 else if (!_cups_strcasecmp(line
, "MakeModel"))
957 cupsdSetString(&p
->make_model
, value
);
959 else if (!_cups_strcasecmp(line
, "Location"))
962 cupsdSetString(&p
->location
, value
);
964 else if (!_cups_strcasecmp(line
, "DeviceURI"))
967 cupsdSetDeviceURI(p
, value
);
969 cupsdLogMessage(CUPSD_LOG_ERROR
,
970 "Syntax error on line %d of printers.conf.", linenum
);
972 else if (!_cups_strcasecmp(line
, "Option") && value
)
978 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
981 cupsdLogMessage(CUPSD_LOG_ERROR
,
982 "Syntax error on line %d of printers.conf.", linenum
);
985 for (; *valueptr
&& isspace(*valueptr
& 255); *valueptr
++ = '\0');
987 p
->num_options
= cupsAddOption(value
, valueptr
, p
->num_options
,
991 else if (!_cups_strcasecmp(line
, "PortMonitor"))
993 if (value
&& strcmp(value
, "none"))
994 cupsdSetString(&p
->port_monitor
, value
);
996 cupsdClearString(&p
->port_monitor
);
998 cupsdLogMessage(CUPSD_LOG_ERROR
,
999 "Syntax error on line %d of printers.conf.", linenum
);
1001 else if (!_cups_strcasecmp(line
, "Reason"))
1004 strcmp(value
, "connecting-to-device") &&
1005 strcmp(value
, "cups-insecure-filter-warning") &&
1006 strcmp(value
, "cups-missing-filter-warning"))
1008 for (i
= 0 ; i
< p
->num_reasons
; i
++)
1009 if (!strcmp(value
, p
->reasons
[i
]))
1012 if (i
>= p
->num_reasons
&&
1013 p
->num_reasons
< (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
1015 p
->reasons
[p
->num_reasons
] = _cupsStrAlloc(value
);
1020 cupsdLogMessage(CUPSD_LOG_ERROR
,
1021 "Syntax error on line %d of printers.conf.", linenum
);
1023 else if (!_cups_strcasecmp(line
, "State"))
1026 * Set the initial queue state...
1029 if (value
&& !_cups_strcasecmp(value
, "idle"))
1030 p
->state
= IPP_PRINTER_IDLE
;
1031 else if (value
&& !_cups_strcasecmp(value
, "stopped"))
1033 p
->state
= IPP_PRINTER_STOPPED
;
1035 for (i
= 0 ; i
< p
->num_reasons
; i
++)
1036 if (!strcmp("paused", p
->reasons
[i
]))
1039 if (i
>= p
->num_reasons
&&
1040 p
->num_reasons
< (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
1042 p
->reasons
[p
->num_reasons
] = _cupsStrAlloc("paused");
1047 cupsdLogMessage(CUPSD_LOG_ERROR
,
1048 "Syntax error on line %d of printers.conf.", linenum
);
1050 else if (!_cups_strcasecmp(line
, "StateMessage"))
1053 * Set the initial queue state message...
1057 strlcpy(p
->state_message
, value
, sizeof(p
->state_message
));
1059 else if (!_cups_strcasecmp(line
, "StateTime"))
1062 * Set the state time...
1066 p
->state_time
= atoi(value
);
1068 else if (!_cups_strcasecmp(line
, "Accepting"))
1071 * Set the initial accepting state...
1075 (!_cups_strcasecmp(value
, "yes") ||
1076 !_cups_strcasecmp(value
, "on") ||
1077 !_cups_strcasecmp(value
, "true")))
1080 (!_cups_strcasecmp(value
, "no") ||
1081 !_cups_strcasecmp(value
, "off") ||
1082 !_cups_strcasecmp(value
, "false")))
1085 cupsdLogMessage(CUPSD_LOG_ERROR
,
1086 "Syntax error on line %d of printers.conf.", linenum
);
1088 else if (!_cups_strcasecmp(line
, "Type"))
1091 p
->type
= (cups_ptype_t
)atoi(value
);
1093 cupsdLogMessage(CUPSD_LOG_ERROR
,
1094 "Syntax error on line %d of printers.conf.", linenum
);
1096 else if (!_cups_strcasecmp(line
, "Shared"))
1099 * Set the initial shared state...
1103 (!_cups_strcasecmp(value
, "yes") ||
1104 !_cups_strcasecmp(value
, "on") ||
1105 !_cups_strcasecmp(value
, "true")))
1108 (!_cups_strcasecmp(value
, "no") ||
1109 !_cups_strcasecmp(value
, "off") ||
1110 !_cups_strcasecmp(value
, "false")))
1113 cupsdLogMessage(CUPSD_LOG_ERROR
,
1114 "Syntax error on line %d of printers.conf.", linenum
);
1116 else if (!_cups_strcasecmp(line
, "JobSheets"))
1119 * Set the initial job sheets...
1124 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1129 cupsdSetString(&p
->job_sheets
[0], value
);
1131 while (isspace(*valueptr
& 255))
1136 for (value
= valueptr
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1141 cupsdSetString(&p
->job_sheets
[1], value
);
1145 cupsdLogMessage(CUPSD_LOG_ERROR
,
1146 "Syntax error on line %d of printers.conf.", linenum
);
1148 else if (!_cups_strcasecmp(line
, "AllowUser"))
1153 cupsdAddString(&(p
->users
), value
);
1156 cupsdLogMessage(CUPSD_LOG_ERROR
,
1157 "Syntax error on line %d of printers.conf.", linenum
);
1159 else if (!_cups_strcasecmp(line
, "DenyUser"))
1164 cupsdAddString(&(p
->users
), value
);
1167 cupsdLogMessage(CUPSD_LOG_ERROR
,
1168 "Syntax error on line %d of printers.conf.", linenum
);
1170 else if (!_cups_strcasecmp(line
, "QuotaPeriod"))
1173 p
->quota_period
= atoi(value
);
1175 cupsdLogMessage(CUPSD_LOG_ERROR
,
1176 "Syntax error on line %d of printers.conf.", linenum
);
1178 else if (!_cups_strcasecmp(line
, "PageLimit"))
1181 p
->page_limit
= atoi(value
);
1183 cupsdLogMessage(CUPSD_LOG_ERROR
,
1184 "Syntax error on line %d of printers.conf.", linenum
);
1186 else if (!_cups_strcasecmp(line
, "KLimit"))
1189 p
->k_limit
= atoi(value
);
1191 cupsdLogMessage(CUPSD_LOG_ERROR
,
1192 "Syntax error on line %d of printers.conf.", linenum
);
1194 else if (!_cups_strcasecmp(line
, "OpPolicy"))
1198 cupsd_policy_t
*pol
; /* Policy */
1201 if ((pol
= cupsdFindPolicy(value
)) != NULL
)
1203 cupsdSetString(&p
->op_policy
, value
);
1204 p
->op_policy_ptr
= pol
;
1207 cupsdLogMessage(CUPSD_LOG_ERROR
,
1208 "Bad policy \"%s\" on line %d of printers.conf",
1212 cupsdLogMessage(CUPSD_LOG_ERROR
,
1213 "Syntax error on line %d of printers.conf.", linenum
);
1215 else if (!_cups_strcasecmp(line
, "ErrorPolicy"))
1218 cupsdSetString(&p
->error_policy
, value
);
1220 cupsdLogMessage(CUPSD_LOG_ERROR
,
1221 "Syntax error on line %d of printers.conf.", linenum
);
1223 else if (!_cups_strcasecmp(line
, "Attribute") && value
)
1225 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1228 cupsdLogMessage(CUPSD_LOG_ERROR
,
1229 "Syntax error on line %d of printers.conf.", linenum
);
1232 for (; *valueptr
&& isspace(*valueptr
& 255); *valueptr
++ = '\0');
1235 cupsdSetPrinterAttrs(p
);
1237 if (!strcmp(value
, "marker-change-time"))
1238 p
->marker_time
= atoi(valueptr
);
1240 cupsdSetPrinterAttr(p
, value
, valueptr
);
1243 else if (_cups_strcasecmp(line
, "Filter") &&
1244 _cups_strcasecmp(line
, "Prefilter") &&
1245 _cups_strcasecmp(line
, "Product"))
1248 * Something else we don't understand (and that wasn't used in a prior
1249 * release of CUPS...
1252 cupsdLogMessage(CUPSD_LOG_ERROR
,
1253 "Unknown configuration directive %s on line %d of "
1254 "printers.conf.", line
, linenum
);
1263 * 'cupsdRenamePrinter()' - Rename a printer.
1268 cupsd_printer_t
*p
, /* I - Printer */
1269 const char *name
) /* I - New name */
1272 * Remove the printer from the array(s) first...
1275 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1276 "cupsdRenamePrinter: Removing %s from Printers", p
->name
);
1277 cupsArrayRemove(Printers
, p
);
1280 * Rename the printer type...
1283 mimeDeleteType(MimeDatabase
, p
->filetype
);
1284 p
->filetype
= mimeAddType(MimeDatabase
, "printer", name
);
1286 if (p
->prefiltertype
)
1288 mimeDeleteType(MimeDatabase
, p
->prefiltertype
);
1289 p
->prefiltertype
= mimeAddType(MimeDatabase
, "prefilter", name
);
1293 * Rename the printer...
1296 cupsdSetString(&p
->name
, name
);
1299 * Reset printer attributes...
1302 cupsdSetPrinterAttrs(p
);
1305 * Add the printer back to the printer array(s)...
1308 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1309 "cupsdRenamePrinter: Adding %s to Printers", p
->name
);
1310 cupsArrayAdd(Printers
, p
);
1315 * 'cupsdSaveAllPrinters()' - Save all printer definitions to the printers.conf
1320 cupsdSaveAllPrinters(void)
1322 int i
; /* Looping var */
1323 cups_file_t
*fp
; /* printers.conf file */
1324 char filename
[1024], /* printers.conf filename */
1325 temp
[1024], /* Temporary string */
1326 value
[2048], /* Value string */
1327 *ptr
, /* Pointer into value */
1328 *name
; /* Current user/group name */
1329 cupsd_printer_t
*printer
; /* Current printer class */
1330 time_t curtime
; /* Current time */
1331 struct tm
*curdate
; /* Current date */
1332 cups_option_t
*option
; /* Current option */
1333 ipp_attribute_t
*marker
; /* Current marker attribute */
1337 * Create the printers.conf file...
1340 snprintf(filename
, sizeof(filename
), "%s/printers.conf", ServerRoot
);
1342 if ((fp
= cupsdCreateConfFile(filename
, ConfigFilePerm
& 0600)) == NULL
)
1345 cupsdLogMessage(CUPSD_LOG_INFO
, "Saving printers.conf...");
1348 * Write a small header to the file...
1351 curtime
= time(NULL
);
1352 curdate
= localtime(&curtime
);
1353 strftime(temp
, sizeof(temp
) - 1, "%Y-%m-%d %H:%M", curdate
);
1355 cupsFilePuts(fp
, "# Printer configuration file for " CUPS_SVERSION
"\n");
1356 cupsFilePrintf(fp
, "# Written by cupsd on %s\n", temp
);
1357 cupsFilePuts(fp
, "# DO NOT EDIT THIS FILE WHEN CUPSD IS RUNNING\n");
1360 * Write each local printer known to the system...
1363 for (printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
1365 printer
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
1368 * Skip printer classes...
1371 if (printer
->type
& CUPS_PRINTER_CLASS
)
1375 * Write printers as needed...
1378 if (printer
== DefaultPrinter
)
1379 cupsFilePrintf(fp
, "<DefaultPrinter %s>\n", printer
->name
);
1381 cupsFilePrintf(fp
, "<Printer %s>\n", printer
->name
);
1383 cupsFilePrintf(fp
, "UUID %s\n", printer
->uuid
);
1385 if (printer
->num_auth_info_required
> 0)
1387 switch (printer
->num_auth_info_required
)
1390 strlcpy(value
, printer
->auth_info_required
[0], sizeof(value
));
1394 snprintf(value
, sizeof(value
), "%s,%s",
1395 printer
->auth_info_required
[0],
1396 printer
->auth_info_required
[1]);
1401 snprintf(value
, sizeof(value
), "%s,%s,%s",
1402 printer
->auth_info_required
[0],
1403 printer
->auth_info_required
[1],
1404 printer
->auth_info_required
[2]);
1408 cupsFilePutConf(fp
, "AuthInfoRequired", value
);
1412 cupsFilePutConf(fp
, "Info", printer
->info
);
1414 if (printer
->location
)
1415 cupsFilePutConf(fp
, "Location", printer
->location
);
1417 if (printer
->make_model
)
1418 cupsFilePutConf(fp
, "MakeModel", printer
->make_model
);
1420 cupsFilePutConf(fp
, "DeviceURI", printer
->device_uri
);
1422 if (printer
->port_monitor
)
1423 cupsFilePutConf(fp
, "PortMonitor", printer
->port_monitor
);
1425 if (printer
->state
== IPP_PRINTER_STOPPED
)
1427 cupsFilePuts(fp
, "State Stopped\n");
1429 if (printer
->state_message
)
1430 cupsFilePutConf(fp
, "StateMessage", printer
->state_message
);
1433 cupsFilePuts(fp
, "State Idle\n");
1435 cupsFilePrintf(fp
, "StateTime %d\n", (int)printer
->state_time
);
1437 for (i
= 0; i
< printer
->num_reasons
; i
++)
1438 if (strcmp(printer
->reasons
[i
], "connecting-to-device") &&
1439 strcmp(printer
->reasons
[i
], "cups-insecure-filter-warning") &&
1440 strcmp(printer
->reasons
[i
], "cups-missing-filter-warning"))
1441 cupsFilePutConf(fp
, "Reason", printer
->reasons
[i
]);
1443 cupsFilePrintf(fp
, "Type %d\n", printer
->type
);
1445 if (printer
->accepting
)
1446 cupsFilePuts(fp
, "Accepting Yes\n");
1448 cupsFilePuts(fp
, "Accepting No\n");
1450 if (printer
->shared
)
1451 cupsFilePuts(fp
, "Shared Yes\n");
1453 cupsFilePuts(fp
, "Shared No\n");
1455 snprintf(value
, sizeof(value
), "%s %s", printer
->job_sheets
[0],
1456 printer
->job_sheets
[1]);
1457 cupsFilePutConf(fp
, "JobSheets", value
);
1459 cupsFilePrintf(fp
, "QuotaPeriod %d\n", printer
->quota_period
);
1460 cupsFilePrintf(fp
, "PageLimit %d\n", printer
->page_limit
);
1461 cupsFilePrintf(fp
, "KLimit %d\n", printer
->k_limit
);
1463 for (name
= (char *)cupsArrayFirst(printer
->users
);
1465 name
= (char *)cupsArrayNext(printer
->users
))
1466 cupsFilePutConf(fp
, printer
->deny_users
? "DenyUser" : "AllowUser", name
);
1468 if (printer
->op_policy
)
1469 cupsFilePutConf(fp
, "OpPolicy", printer
->op_policy
);
1470 if (printer
->error_policy
)
1471 cupsFilePutConf(fp
, "ErrorPolicy", printer
->error_policy
);
1473 for (i
= printer
->num_options
, option
= printer
->options
;
1477 snprintf(value
, sizeof(value
), "%s %s", option
->name
, option
->value
);
1478 cupsFilePutConf(fp
, "Option", value
);
1481 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-colors",
1482 IPP_TAG_NAME
)) != NULL
)
1484 snprintf(value
, sizeof(value
), "%s ", marker
->name
);
1486 for (i
= 0, ptr
= value
+ strlen(value
);
1487 i
< marker
->num_values
&& ptr
< (value
+ sizeof(value
) - 1);
1493 strlcpy(ptr
, marker
->values
[i
].string
.text
, (size_t)(value
+ sizeof(value
) - ptr
));
1498 cupsFilePutConf(fp
, "Attribute", value
);
1501 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-levels",
1502 IPP_TAG_INTEGER
)) != NULL
)
1504 cupsFilePrintf(fp
, "Attribute %s %d", marker
->name
,
1505 marker
->values
[0].integer
);
1506 for (i
= 1; i
< marker
->num_values
; i
++)
1507 cupsFilePrintf(fp
, ",%d", marker
->values
[i
].integer
);
1508 cupsFilePuts(fp
, "\n");
1511 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-low-levels",
1512 IPP_TAG_INTEGER
)) != NULL
)
1514 cupsFilePrintf(fp
, "Attribute %s %d", marker
->name
,
1515 marker
->values
[0].integer
);
1516 for (i
= 1; i
< marker
->num_values
; i
++)
1517 cupsFilePrintf(fp
, ",%d", marker
->values
[i
].integer
);
1518 cupsFilePuts(fp
, "\n");
1521 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-high-levels",
1522 IPP_TAG_INTEGER
)) != NULL
)
1524 cupsFilePrintf(fp
, "Attribute %s %d", marker
->name
,
1525 marker
->values
[0].integer
);
1526 for (i
= 1; i
< marker
->num_values
; i
++)
1527 cupsFilePrintf(fp
, ",%d", marker
->values
[i
].integer
);
1528 cupsFilePuts(fp
, "\n");
1531 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-message",
1532 IPP_TAG_TEXT
)) != NULL
)
1534 snprintf(value
, sizeof(value
), "%s %s", marker
->name
,
1535 marker
->values
[0].string
.text
);
1537 cupsFilePutConf(fp
, "Attribute", value
);
1540 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-names",
1541 IPP_TAG_NAME
)) != NULL
)
1543 snprintf(value
, sizeof(value
), "%s ", marker
->name
);
1545 for (i
= 0, ptr
= value
+ strlen(value
);
1546 i
< marker
->num_values
&& ptr
< (value
+ sizeof(value
) - 1);
1552 strlcpy(ptr
, marker
->values
[i
].string
.text
, (size_t)(value
+ sizeof(value
) - ptr
));
1557 cupsFilePutConf(fp
, "Attribute", value
);
1560 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-types",
1561 IPP_TAG_KEYWORD
)) != NULL
)
1563 snprintf(value
, sizeof(value
), "%s ", marker
->name
);
1565 for (i
= 0, ptr
= value
+ strlen(value
);
1566 i
< marker
->num_values
&& ptr
< (value
+ sizeof(value
) - 1);
1572 strlcpy(ptr
, marker
->values
[i
].string
.text
, (size_t)(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_ptype_t
)~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_ptype_t
)~CUPS_PRINTER_AUTHENTICATED
;
2072 p
->type
&= (cups_ptype_t
)~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_ptype_t
)~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_ptype_t
)~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, (size_t)(p
->num_reasons
- i
) * sizeof(char *));
2468 if (!strcmp(reason
, "paused") && p
->state
== IPP_PRINTER_STOPPED
)
2469 cupsdSetPrinterState(p
, IPP_PRINTER_IDLE
, 1);
2471 if (!strcmp(reason
, "cups-waiting-for-job-completed") && p
->job
)
2472 p
->job
->completed
= 0;
2474 if (strcmp(reason
, "connecting-to-device"))
2480 else if (p
->num_reasons
< (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
2486 for (i
= 0; i
< p
->num_reasons
; i
++)
2487 if (!strcmp(reason
, p
->reasons
[i
]))
2490 if (i
>= p
->num_reasons
)
2492 if (i
>= (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
2494 cupsdLogMessage(CUPSD_LOG_ALERT
,
2495 "Too many printer-state-reasons values for %s (%d)",
2500 p
->reasons
[i
] = _cupsStrAlloc(reason
);
2504 if (!strcmp(reason
, "paused") && p
->state
!= IPP_PRINTER_STOPPED
)
2505 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, 1);
2507 if (!strcmp(reason
, "cups-waiting-for-job-completed") && p
->job
)
2508 p
->job
->completed
= 1;
2510 if (strcmp(reason
, "connecting-to-device"))
2521 * 'cupsdSetPrinterState()' - Update the current state of a printer.
2525 cupsdSetPrinterState(
2526 cupsd_printer_t
*p
, /* I - Printer to change */
2527 ipp_pstate_t s
, /* I - New state */
2528 int update
) /* I - Update printers.conf? */
2530 cupsd_job_t
*job
; /* Current job */
2531 ipp_pstate_t old_state
; /* Old printer state */
2532 static const char * const printer_states
[] =
2533 { /* State strings */
2541 * Set the new state...
2544 old_state
= p
->state
;
2549 cupsdAddEvent(s
== IPP_PRINTER_STOPPED
? CUPSD_EVENT_PRINTER_STOPPED
:
2550 CUPSD_EVENT_PRINTER_STATE
, p
, NULL
,
2551 "%s \"%s\" state changed to %s.",
2552 (p
->type
& CUPS_PRINTER_CLASS
) ? "Class" : "Printer",
2553 p
->name
, printer_states
[p
->state
- IPP_PRINTER_IDLE
]);
2556 * Let the browse code know this needs to be updated...
2559 p
->state_time
= time(NULL
);
2563 * Set/clear the paused reason as needed...
2566 if (s
== IPP_PRINTER_STOPPED
)
2567 cupsdSetPrinterReasons(p
, "+paused");
2569 cupsdSetPrinterReasons(p
, "-paused");
2573 for (job
= (cupsd_job_t
*)cupsArrayFirst(ActiveJobs
);
2575 job
= (cupsd_job_t
*)cupsArrayNext(ActiveJobs
))
2576 if (job
->reasons
&& job
->state_value
== IPP_JOB_PENDING
&&
2577 !_cups_strcasecmp(job
->dest
, p
->name
))
2578 ippSetString(job
->attrs
, &job
->reasons
, 0,
2579 s
== IPP_PRINTER_STOPPED
? "printer-stopped" : "none");
2583 * Clear the message for the queue when going to processing...
2586 if (s
== IPP_PRINTER_PROCESSING
)
2587 p
->state_message
[0] = '\0';
2590 * Let the browse protocols reflect the change...
2594 cupsdRegisterPrinter(p
);
2597 * Save the printer configuration if a printer goes from idle or processing
2598 * to stopped (or visa-versa)...
2602 (old_state
== IPP_PRINTER_STOPPED
) != (s
== IPP_PRINTER_STOPPED
))
2608 * 'cupsdStopPrinter()' - Stop a printer from printing any jobs...
2612 cupsdStopPrinter(cupsd_printer_t
*p
, /* I - Printer to stop */
2613 int update
)/* I - Update printers.conf? */
2616 * Set the printer state...
2619 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, update
);
2622 * See if we have a job printing on this printer...
2625 if (p
->job
&& p
->job
->state_value
== IPP_JOB_PROCESSING
)
2626 cupsdSetJobState(p
->job
, IPP_JOB_PENDING
, CUPSD_JOB_DEFAULT
,
2627 "Job stopped due to printer being paused.");
2632 * 'cupsdUpdatePrinterPPD()' - Update keywords in a printer's PPD file.
2635 int /* O - 1 if successful, 0 otherwise */
2636 cupsdUpdatePrinterPPD(
2637 cupsd_printer_t
*p
, /* I - Printer */
2638 int num_keywords
, /* I - Number of keywords */
2639 cups_option_t
*keywords
) /* I - Keywords */
2641 int i
; /* Looping var */
2642 cups_file_t
*src
, /* Original file */
2643 *dst
; /* New file */
2644 char srcfile
[1024], /* Original filename */
2645 dstfile
[1024], /* New filename */
2646 line
[1024], /* Line from file */
2647 keystring
[41]; /* Keyword from line */
2648 cups_option_t
*keyword
; /* Current keyword */
2651 cupsdLogMessage(CUPSD_LOG_INFO
, "Updating keywords in PPD file for %s...",
2655 * Get the old and new PPD filenames...
2658 snprintf(srcfile
, sizeof(srcfile
), "%s/ppd/%s.ppd.O", ServerRoot
, p
->name
);
2659 snprintf(dstfile
, sizeof(srcfile
), "%s/ppd/%s.ppd", ServerRoot
, p
->name
);
2662 * Rename the old file and open the old and new...
2665 if (rename(dstfile
, srcfile
))
2667 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to backup PPD file for %s: %s",
2668 p
->name
, strerror(errno
));
2672 if ((src
= cupsFileOpen(srcfile
, "r")) == NULL
)
2674 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to open PPD file \"%s\": %s",
2675 srcfile
, strerror(errno
));
2676 rename(srcfile
, dstfile
);
2680 if ((dst
= cupsFileOpen(dstfile
, "w")) == NULL
)
2682 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to create PPD file \"%s\": %s",
2683 dstfile
, strerror(errno
));
2685 rename(srcfile
, dstfile
);
2690 * Copy the first line and then write out all of the keywords...
2693 if (!cupsFileGets(src
, line
, sizeof(line
)))
2695 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to read PPD file \"%s\": %s",
2696 srcfile
, strerror(errno
));
2699 rename(srcfile
, dstfile
);
2703 cupsFilePrintf(dst
, "%s\n", line
);
2705 for (i
= num_keywords
, keyword
= keywords
; i
> 0; i
--, keyword
++)
2707 cupsdLogMessage(CUPSD_LOG_DEBUG
, "*%s: %s", keyword
->name
, keyword
->value
);
2708 cupsFilePrintf(dst
, "*%s: %s\n", keyword
->name
, keyword
->value
);
2712 * Then copy the rest of the PPD file, dropping any keywords we changed.
2715 while (cupsFileGets(src
, line
, sizeof(line
)))
2718 * Skip keywords we've already set...
2721 if (sscanf(line
, "*%40[^:]:", keystring
) == 1 &&
2722 cupsGetOption(keystring
, num_keywords
, keywords
))
2726 * Otherwise write the line...
2729 cupsFilePrintf(dst
, "%s\n", line
);
2733 * Close files and return...
2744 * 'cupsdUpdatePrinters()' - Update printers after a partial reload.
2748 cupsdUpdatePrinters(void)
2750 cupsd_printer_t
*p
; /* Current printer */
2754 * Loop through the printers and recreate the printer attributes
2755 * for any local printers since the policy and/or access control
2756 * stuff may have changed. Also, if browsing is disabled, remove
2757 * any remote printers...
2760 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
2762 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
2765 * Update the operation policy pointer...
2768 if ((p
->op_policy_ptr
= cupsdFindPolicy(p
->op_policy
)) == NULL
)
2769 p
->op_policy_ptr
= DefaultPolicyPtr
;
2772 * Update printer attributes...
2775 cupsdSetPrinterAttrs(p
);
2781 * 'cupsdValidateDest()' - Validate a printer/class destination.
2784 const char * /* O - Printer or class name */
2786 const char *uri
, /* I - Printer URI */
2787 cups_ptype_t
*dtype
, /* O - Type (printer or class) */
2788 cupsd_printer_t
**printer
) /* O - Printer pointer */
2790 cupsd_printer_t
*p
; /* Current printer */
2791 char localname
[1024],/* Localized hostname */
2792 *lptr
, /* Pointer into localized hostname */
2793 *sptr
, /* Pointer into server name */
2794 *rptr
, /* Pointer into resource */
2795 scheme
[32], /* Scheme portion of URI */
2796 username
[64], /* Username portion of URI */
2797 hostname
[HTTP_MAX_HOST
],
2798 /* Host portion of URI */
2799 resource
[HTTP_MAX_URI
];
2800 /* Resource portion of URI */
2801 int port
; /* Port portion of URI */
2804 DEBUG_printf(("cupsdValidateDest(uri=\"%s\", dtype=%p, printer=%p)\n", uri
,
2808 * Initialize return values...
2815 *dtype
= (cups_ptype_t
)0;
2818 * Pull the hostname and resource from the URI...
2821 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
, scheme
, sizeof(scheme
),
2822 username
, sizeof(username
), hostname
, sizeof(hostname
),
2823 &port
, resource
, sizeof(resource
));
2826 * See if the resource is a class or printer...
2829 if (!strncmp(resource
, "/classes/", 9))
2835 rptr
= resource
+ 9;
2837 else if (!strncmp(resource
, "/printers/", 10))
2843 rptr
= resource
+ 10;
2848 * Bad resource name...
2855 * See if the printer or class name exists...
2858 p
= cupsdFindDest(rptr
);
2860 if (p
== NULL
&& strchr(rptr
, '@') == NULL
)
2868 *dtype
= p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_REMOTE
);
2874 * Change localhost to the server name...
2877 if (!_cups_strcasecmp(hostname
, "localhost"))
2878 strlcpy(hostname
, ServerName
, sizeof(hostname
));
2880 strlcpy(localname
, hostname
, sizeof(localname
));
2882 if (!_cups_strcasecmp(hostname
, ServerName
))
2885 * Localize the hostname...
2888 lptr
= strchr(localname
, '.');
2889 sptr
= strchr(ServerName
, '.');
2891 if (sptr
!= NULL
&& lptr
!= NULL
)
2894 * Strip the common domain name components...
2897 while (lptr
!= NULL
)
2899 if (!_cups_strcasecmp(lptr
, sptr
))
2905 lptr
= strchr(lptr
+ 1, '.');
2910 DEBUG_printf(("localized hostname is \"%s\"...\n", localname
));
2913 * Find a matching printer or class...
2916 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
2918 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
2919 if (!_cups_strcasecmp(p
->hostname
, localname
) &&
2920 !_cups_strcasecmp(p
->name
, rptr
))
2926 *dtype
= p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_REMOTE
);
2936 * 'cupsdWritePrintcap()' - Write a pseudo-printcap file for older applications
2941 cupsdWritePrintcap(void)
2943 int i
; /* Looping var */
2944 cups_file_t
*fp
; /* Printcap file */
2945 cupsd_printer_t
*p
; /* Current printer */
2949 * See if we have a printcap file; if not, don't bother writing it.
2952 if (!Printcap
|| !*Printcap
)
2955 cupsdLogMessage(CUPSD_LOG_INFO
, "Generating printcap %s...", Printcap
);
2958 * Open the printcap file...
2961 if ((fp
= cupsFileOpen(Printcap
, "w")) == NULL
)
2965 * Put a comment header at the top so that users will know where the
2966 * data has come from...
2969 if (PrintcapFormat
!= PRINTCAP_PLIST
)
2970 cupsFilePrintf(fp
, "# This file was automatically generated by cupsd(8) "
2972 "# %s/printers.conf file. All changes to this file\n"
2973 "# will be lost.\n", ServerRoot
);
2976 * Write a new printcap with the current list of printers.
2979 switch (PrintcapFormat
)
2983 * Each printer is put in the file as:
2993 cupsFilePrintf(fp
, "%s|%s:rm=%s:rp=%s:\n", DefaultPrinter
->name
,
2994 DefaultPrinter
->info
, ServerName
,
2995 DefaultPrinter
->name
);
2997 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
2999 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3000 if (p
!= DefaultPrinter
)
3001 cupsFilePrintf(fp
, "%s|%s:rm=%s:rp=%s:\n", p
->name
, p
->info
,
3002 ServerName
, p
->name
);
3005 case PRINTCAP_PLIST
:
3007 * Each printer is written as a dictionary in a plist file.
3008 * Currently the printer-name, printer-info, printer-is-accepting-jobs,
3009 * printer-location, printer-make-and-model, printer-state,
3010 * printer-state-reasons, printer-type, and (sanitized) device-uri.
3013 cupsFilePuts(fp
, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
3014 "<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD "
3015 "PLIST 1.0//EN\" \"http://www.apple.com/DTDs/"
3016 "PropertyList-1.0.dtd\">\n"
3017 "<plist version=\"1.0\">\n"
3020 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3022 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3024 cupsFilePuts(fp
, "\t<dict>\n"
3025 "\t\t<key>printer-name</key>\n"
3027 write_xml_string(fp
, p
->name
);
3028 cupsFilePuts(fp
, "</string>\n"
3029 "\t\t<key>printer-info</key>\n"
3031 write_xml_string(fp
, p
->info
);
3032 cupsFilePrintf(fp
, "</string>\n"
3033 "\t\t<key>printer-is-accepting-jobs</key>\n"
3035 "\t\t<key>printer-location</key>\n"
3036 "\t\t<string>", p
->accepting
? "true" : "false");
3037 write_xml_string(fp
, p
->location
);
3038 cupsFilePuts(fp
, "</string>\n"
3039 "\t\t<key>printer-make-and-model</key>\n"
3041 write_xml_string(fp
, p
->make_model
);
3042 cupsFilePrintf(fp
, "</string>\n"
3043 "\t\t<key>printer-state</key>\n"
3044 "\t\t<integer>%d</integer>\n"
3045 "\t\t<key>printer-state-reasons</key>\n"
3046 "\t\t<array>\n", p
->state
);
3047 for (i
= 0; i
< p
->num_reasons
; i
++)
3049 cupsFilePuts(fp
, "\t\t\t<string>");
3050 write_xml_string(fp
, p
->reasons
[i
]);
3051 cupsFilePuts(fp
, "</string>\n");
3053 cupsFilePrintf(fp
, "\t\t</array>\n"
3054 "\t\t<key>printer-type</key>\n"
3055 "\t\t<integer>%d</integer>\n"
3056 "\t\t<key>device-uri</key>\n"
3057 "\t\t<string>", p
->type
);
3058 write_xml_string(fp
, p
->sanitized_device_uri
);
3059 cupsFilePuts(fp
, "</string>\n"
3062 cupsFilePuts(fp
, "</array>\n"
3066 case PRINTCAP_SOLARIS
:
3068 * Each printer is put in the file as:
3070 * _all:all=Printer1,Printer2,Printer3,...,PrinterN
3071 * _default:use=DefaultPrinter
3073 * :bsdaddr=ServerName,Printer1:\
3074 * :description=Description:
3076 * :bsdaddr=ServerName,Printer2:\
3077 * :description=Description:
3079 * :bsdaddr=ServerName,Printer3:\
3080 * :description=Description:
3083 * :bsdaddr=ServerName,PrinterN:\
3084 * :description=Description:
3087 cupsFilePuts(fp
, "_all:all=");
3088 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3090 p
= (cupsd_printer_t
*)cupsArrayCurrent(Printers
))
3091 cupsFilePrintf(fp
, "%s%c", p
->name
,
3092 cupsArrayNext(Printers
) ? ',' : '\n');
3095 cupsFilePrintf(fp
, "_default:use=%s\n", DefaultPrinter
->name
);
3097 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3099 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3100 cupsFilePrintf(fp
, "%s:\\\n"
3101 "\t:bsdaddr=%s,%s:\\\n"
3102 "\t:description=%s:\n",
3103 p
->name
, ServerName
, p
->name
,
3104 p
->info
? p
->info
: "");
3117 * 'add_printer_defaults()' - Add name-default attributes to the printer attributes.
3121 add_printer_defaults(cupsd_printer_t
*p
)/* I - Printer */
3123 int i
; /* Looping var */
3124 int num_options
; /* Number of default options */
3125 cups_option_t
*options
, /* Default options */
3126 *option
; /* Current option */
3127 char name
[256]; /* name-default */
3131 * Maintain a common array of default attribute names...
3134 if (!CommonDefaults
)
3136 CommonDefaults
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
3138 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("copies-default"));
3139 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("document-format-default"));
3140 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("finishings-default"));
3141 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-account-id-default"));
3142 cupsArrayAdd(CommonDefaults
,
3143 _cupsStrAlloc("job-accounting-user-id-default"));
3144 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-cancel-after-default"));
3145 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-hold-until-default"));
3146 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-priority-default"));
3147 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-sheets-default"));
3148 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("media-col-default"));
3149 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("number-up-default"));
3150 cupsArrayAdd(CommonDefaults
,
3151 _cupsStrAlloc("orientation-requested-default"));
3155 * Add all of the default options from the .conf files...
3158 for (num_options
= 0, options
= NULL
, i
= p
->num_options
, option
= p
->options
;
3162 if (strcmp(option
->name
, "ipp-options") &&
3163 strcmp(option
->name
, "job-sheets") &&
3164 strcmp(option
->name
, "lease-duration"))
3166 snprintf(name
, sizeof(name
), "%s-default", option
->name
);
3167 num_options
= cupsAddOption(name
, option
->value
, num_options
, &options
);
3169 if (!cupsArrayFind(CommonDefaults
, name
))
3170 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc(name
));
3175 * Convert options to IPP attributes...
3178 cupsEncodeOptions2(p
->attrs
, num_options
, options
, IPP_TAG_PRINTER
);
3179 cupsFreeOptions(num_options
, options
);
3182 * Add standard -default attributes as needed...
3185 if (!cupsGetOption("copies", p
->num_options
, p
->options
))
3186 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
, "copies-default",
3189 if (!cupsGetOption("document-format", p
->num_options
, p
->options
))
3190 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_MIMETYPE
,
3191 "document-format-default", NULL
, "application/octet-stream");
3193 if (!cupsGetOption("job-cancel-after", p
->num_options
, p
->options
))
3194 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3195 "job-cancel-after-default", MaxJobTime
);
3197 if (!cupsGetOption("job-hold-until", p
->num_options
, p
->options
))
3198 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3199 "job-hold-until-default", NULL
, "no-hold");
3201 if (!cupsGetOption("job-priority", p
->num_options
, p
->options
))
3202 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3203 "job-priority-default", 50);
3205 if (!cupsGetOption("number-up", p
->num_options
, p
->options
))
3206 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3207 "number-up-default", 1);
3209 if (!cupsGetOption("notify-lease-duration", p
->num_options
, p
->options
))
3210 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3211 "notify-lease-duration-default", DefaultLeaseDuration
);
3213 if (!cupsGetOption("notify-events", p
->num_options
, p
->options
))
3214 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3215 "notify-events-default", NULL
, "job-completed");
3217 if (!cupsGetOption("orientation-requested", p
->num_options
, p
->options
))
3218 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NOVALUE
,
3219 "orientation-requested-default", NULL
, NULL
);
3221 if (!cupsGetOption("print-quality", p
->num_options
, p
->options
))
3222 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
3223 "print-quality-default", IPP_QUALITY_NORMAL
);
3228 * 'add_printer_filter()' - Add a MIME filter for a printer.
3233 cupsd_printer_t
*p
, /* I - Printer to add to */
3234 mime_type_t
*filtertype
, /* I - Filter or prefilter MIME type */
3235 const char *filter
) /* I - Filter to add */
3237 char super
[MIME_MAX_SUPER
], /* Super-type for filter */
3238 type
[MIME_MAX_TYPE
], /* Type for filter */
3239 dsuper
[MIME_MAX_SUPER
], /* Destination super-type for filter */
3240 dtype
[MIME_MAX_TYPE
], /* Destination type for filter */
3241 dest
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2],
3242 /* Destination super/type */
3243 program
[1024]; /* Program/filter name */
3244 int cost
; /* Cost of filter */
3245 size_t maxsize
= 0; /* Maximum supported file size */
3246 mime_type_t
*temptype
, /* MIME type looping var */
3247 *desttype
; /* Destination MIME type */
3248 mime_filter_t
*filterptr
; /* MIME filter */
3249 char filename
[1024]; /* Full filter filename */
3252 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3253 "add_printer_filter(p=%p(%s), filtertype=%p(%s/%s), "
3254 "filter=\"%s\")", p
, p
->name
, filtertype
, filtertype
->super
,
3255 filtertype
->type
, filter
);
3258 * Parse the filter string; it should be in one of the following formats:
3260 * source/type cost program
3261 * source/type cost maxsize(nnnn) program
3262 * source/type dest/type cost program
3263 * source/type dest/type cost maxsize(nnnn) program
3266 if (sscanf(filter
, "%15[^/]/%255s%*[ \t]%15[^/]/%255s%d%*[ \t]%1023[^\n]",
3267 super
, type
, dsuper
, dtype
, &cost
, program
) == 6)
3269 snprintf(dest
, sizeof(dest
), "%s/%s/%s", p
->name
, dsuper
, dtype
);
3271 if ((desttype
= mimeType(MimeDatabase
, "printer", dest
)) == NULL
)
3273 desttype
= mimeAddType(MimeDatabase
, "printer", dest
);
3275 p
->dest_types
= cupsArrayNew(NULL
, NULL
);
3277 cupsArrayAdd(p
->dest_types
, desttype
);
3283 if (sscanf(filter
, "%15[^/]/%255s%d%*[ \t]%1023[^\n]", super
, type
, &cost
,
3286 desttype
= filtertype
;
3290 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: invalid filter string \"%s\"!",
3296 if (!strncmp(program
, "maxsize(", 8))
3298 char *ptr
; /* Pointer into maxsize(nnnn) program */
3300 maxsize
= (size_t)strtoll(program
+ 8, &ptr
, 10);
3304 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: invalid filter string \"%s\"!",
3310 while (_cups_isspace(*ptr
))
3313 _cups_strcpy(program
, ptr
);
3317 * Check permissions on the filter and its containing directory...
3320 if (strcmp(program
, "-"))
3322 if (program
[0] == '/')
3323 strlcpy(filename
, program
, sizeof(filename
));
3325 snprintf(filename
, sizeof(filename
), "%s/filter/%s", ServerBin
, program
);
3327 _cupsFileCheck(filename
, _CUPS_FILE_CHECK_PROGRAM
, !RunUser
,
3328 cupsdLogFCMessage
, p
);
3332 * Add the filter to the MIME database, supporting wildcards as needed...
3335 for (temptype
= mimeFirstType(MimeDatabase
);
3337 temptype
= mimeNextType(MimeDatabase
))
3338 if (((super
[0] == '*' && _cups_strcasecmp(temptype
->super
, "printer")) ||
3339 !_cups_strcasecmp(temptype
->super
, super
)) &&
3340 (type
[0] == '*' || !_cups_strcasecmp(temptype
->type
, type
)))
3342 if (desttype
!= filtertype
)
3344 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3345 "add_printer_filter: %s: adding filter %s/%s %s/%s %d "
3346 "%s", p
->name
, temptype
->super
, temptype
->type
,
3347 desttype
->super
, desttype
->type
,
3349 filterptr
= mimeAddFilter(MimeDatabase
, temptype
, desttype
, cost
,
3352 if (!mimeFilterLookup(MimeDatabase
, desttype
, filtertype
))
3354 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3355 "add_printer_filter: %s: adding filter %s/%s %s/%s "
3356 "0 -", p
->name
, desttype
->super
, desttype
->type
,
3357 filtertype
->super
, filtertype
->type
);
3358 mimeAddFilter(MimeDatabase
, desttype
, filtertype
, 0, "-");
3363 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3364 "add_printer_filter: %s: adding filter %s/%s %s/%s %d "
3365 "%s", p
->name
, temptype
->super
, temptype
->type
,
3366 filtertype
->super
, filtertype
->type
,
3368 filterptr
= mimeAddFilter(MimeDatabase
, temptype
, filtertype
, cost
,
3373 filterptr
->maxsize
= maxsize
;
3379 * 'add_printer_formats()' - Add document-format-supported values for a printer.
3383 add_printer_formats(cupsd_printer_t
*p
) /* I - Printer */
3385 int i
; /* Looping var */
3386 mime_type_t
*type
; /* Current MIME type */
3387 cups_array_t
*filters
; /* Filters */
3388 ipp_attribute_t
*attr
; /* document-format-supported attribute */
3389 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
3390 /* MIME type name */
3394 * Raw (and remote) queues advertise all of the supported MIME
3398 cupsArrayDelete(p
->filetypes
);
3399 p
->filetypes
= NULL
;
3403 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
,
3404 (ipp_tag_t
)(IPP_TAG_MIMETYPE
| IPP_TAG_COPY
),
3405 "document-format-supported", NumMimeTypes
, NULL
, MimeTypes
);
3410 * Otherwise, loop through the supported MIME types and see if there
3411 * are filters for them...
3414 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_printer_formats: %d types, %d filters",
3415 mimeNumTypes(MimeDatabase
), mimeNumFilters(MimeDatabase
));
3417 p
->filetypes
= cupsArrayNew(NULL
, NULL
);
3419 for (type
= mimeFirstType(MimeDatabase
);
3421 type
= mimeNextType(MimeDatabase
))
3423 if (!_cups_strcasecmp(type
->super
, "printer"))
3426 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
3428 if ((filters
= mimeFilter(MimeDatabase
, type
, p
->filetype
, NULL
)) != NULL
)
3430 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3431 "add_printer_formats: %s: %s needs %d filters",
3432 p
->name
, mimetype
, cupsArrayCount(filters
));
3434 cupsArrayDelete(filters
);
3435 cupsArrayAdd(p
->filetypes
, type
);
3438 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3439 "add_printer_formats: %s: %s not supported",
3444 * Add the file formats that can be filtered...
3447 if ((type
= mimeType(MimeDatabase
, "application", "octet-stream")) == NULL
||
3448 !cupsArrayFind(p
->filetypes
, type
))
3453 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3454 "add_printer_formats: %s: %d supported types",
3455 p
->name
, cupsArrayCount(p
->filetypes
) + i
);
3457 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_MIMETYPE
,
3458 "document-format-supported",
3459 cupsArrayCount(p
->filetypes
) + i
, NULL
, NULL
);
3462 attr
->values
[0].string
.text
= _cupsStrAlloc("application/octet-stream");
3464 for (type
= (mime_type_t
*)cupsArrayFirst(p
->filetypes
);
3466 i
++, type
= (mime_type_t
*)cupsArrayNext(p
->filetypes
))
3468 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
3470 attr
->values
[i
].string
.text
= _cupsStrAlloc(mimetype
);
3473 #if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
3475 char pdl
[1024]; /* Buffer to build pdl list */
3476 mime_filter_t
*filter
; /* MIME filter looping var */
3480 * We only support raw printing if this is not a Tioga PrintJobMgr based
3481 * queue and if application/octet-stream is a known type...
3484 for (filter
= (mime_filter_t
*)cupsArrayFirst(MimeDatabase
->filters
);
3486 filter
= (mime_filter_t
*)cupsArrayNext(MimeDatabase
->filters
))
3488 if (filter
->dst
== p
->filetype
&& filter
->filter
&&
3489 strstr(filter
->filter
, "PrintJobMgr"))
3495 if (!filter
&& mimeType(MimeDatabase
, "application", "octet-stream"))
3496 strlcat(pdl
, "application/octet-stream,", sizeof(pdl
));
3499 * Then list a bunch of formats that are supported by the printer...
3502 for (type
= (mime_type_t
*)cupsArrayFirst(p
->filetypes
);
3504 type
= (mime_type_t
*)cupsArrayNext(p
->filetypes
))
3506 if (!_cups_strcasecmp(type
->super
, "application"))
3508 if (!_cups_strcasecmp(type
->type
, "pdf"))
3509 strlcat(pdl
, "application/pdf,", sizeof(pdl
));
3510 else if (!_cups_strcasecmp(type
->type
, "postscript"))
3511 strlcat(pdl
, "application/postscript,", sizeof(pdl
));
3513 else if (!_cups_strcasecmp(type
->super
, "image"))
3515 if (!_cups_strcasecmp(type
->type
, "jpeg"))
3516 strlcat(pdl
, "image/jpeg,", sizeof(pdl
));
3517 else if (!_cups_strcasecmp(type
->type
, "png"))
3518 strlcat(pdl
, "image/png,", sizeof(pdl
));
3519 else if (!_cups_strcasecmp(type
->type
, "pwg-raster"))
3520 strlcat(pdl
, "image/pwg-raster,", sizeof(pdl
));
3525 pdl
[strlen(pdl
) - 1] = '\0'; /* Remove trailing comma */
3527 cupsdSetString(&p
->pdl
, pdl
);
3529 #endif /* HAVE_DNSSD || HAVE_AVAHI */
3534 * 'compare_printers()' - Compare two printers.
3537 static int /* O - Result of comparison */
3538 compare_printers(void *first
, /* I - First printer */
3539 void *second
, /* I - Second printer */
3540 void *data
) /* I - App data (not used) */
3544 return (_cups_strcasecmp(((cupsd_printer_t
*)first
)->name
,
3545 ((cupsd_printer_t
*)second
)->name
));
3550 * 'delete_printer_filters()' - Delete all MIME filters for a printer.
3554 delete_printer_filters(
3555 cupsd_printer_t
*p
) /* I - Printer to remove from */
3557 mime_filter_t
*filter
; /* MIME filter looping var */
3558 mime_type_t
*type
; /* Destination types for filters */
3562 * Range check input...
3569 * Remove all filters from the MIME database that have a destination
3570 * type == printer...
3573 for (filter
= mimeFirstFilter(MimeDatabase
);
3575 filter
= mimeNextFilter(MimeDatabase
))
3576 if (filter
->dst
== p
->filetype
|| filter
->dst
== p
->prefiltertype
||
3577 cupsArrayFind(p
->dest_types
, filter
->dst
))
3580 * Delete the current filter...
3583 mimeDeleteFilter(MimeDatabase
, filter
);
3586 for (type
= (mime_type_t
*)cupsArrayFirst(p
->dest_types
);
3588 type
= (mime_type_t
*)cupsArrayNext(p
->dest_types
))
3589 mimeDeleteType(MimeDatabase
, type
);
3591 cupsArrayDelete(p
->dest_types
);
3592 p
->dest_types
= NULL
;
3594 cupsdSetPrinterReasons(p
, "-cups-insecure-filter-warning"
3595 ",cups-missing-filter-warning");
3600 * 'dirty_printer()' - Mark config and state files dirty for the specified
3605 dirty_printer(cupsd_printer_t
*p
) /* I - Printer */
3607 if (p
->type
& CUPS_PRINTER_CLASS
)
3608 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
3610 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
3612 if (PrintcapFormat
== PRINTCAP_PLIST
)
3613 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
3618 * 'load_ppd()' - Load a cached PPD file, updating the cache as needed.
3622 load_ppd(cupsd_printer_t
*p
) /* I - Printer */
3624 int i
, j
, k
; /* Looping vars */
3625 char cache_name
[1024]; /* Cache filename */
3626 struct stat cache_info
; /* Cache file info */
3627 ppd_file_t
*ppd
; /* PPD file */
3628 char ppd_name
[1024]; /* PPD filename */
3629 struct stat ppd_info
; /* PPD file info */
3630 int num_media
; /* Number of media options */
3631 ppd_size_t
*size
; /* Current PPD size */
3632 ppd_option_t
*duplex
, /* Duplex option */
3633 *output_bin
, /* OutputBin option */
3634 *output_mode
, /* OutputMode option */
3635 *resolution
; /* (Set|JCL|)Resolution option */
3636 ppd_choice_t
*choice
, /* Current PPD choice */
3637 *input_slot
, /* Current input slot */
3638 *media_type
; /* Current media type */
3639 ppd_attr_t
*ppd_attr
; /* PPD attribute */
3640 int xdpi
, /* Horizontal resolution */
3641 ydpi
; /* Vertical resolution */
3642 const char *resptr
; /* Pointer into resolution keyword */
3643 _pwg_size_t
*pwgsize
; /* Current PWG size */
3644 _pwg_map_t
*pwgsource
, /* Current PWG source */
3645 *pwgtype
; /* Current PWG type */
3646 ipp_attribute_t
*attr
; /* Attribute data */
3647 _ipp_value_t
*val
; /* Attribute value */
3648 int num_finishings
, /* Number of finishings */
3649 finishings
[5]; /* finishings-supported values */
3650 int num_qualities
, /* Number of print-quality values */
3651 qualities
[3]; /* print-quality values */
3652 int num_margins
, /* Number of media-*-margin-supported values */
3653 margins
[16]; /* media-*-margin-supported values */
3654 const char *filter
, /* Current filter */
3655 *mandatory
; /* Current mandatory attribute */
3656 static const char * const sides
[3] = /* sides-supported values */
3659 "two-sided-long-edge",
3660 "two-sided-short-edge"
3662 static const char * const standard_commands
[] =
3663 { /* Standard CUPS commands */
3671 * Check to see if the cache is up-to-date...
3674 snprintf(cache_name
, sizeof(cache_name
), "%s/%s.data", CacheDir
, p
->name
);
3675 if (stat(cache_name
, &cache_info
))
3676 cache_info
.st_mtime
= 0;
3678 snprintf(ppd_name
, sizeof(ppd_name
), "%s/ppd/%s.ppd", ServerRoot
, p
->name
);
3679 if (stat(ppd_name
, &ppd_info
))
3680 ppd_info
.st_mtime
= 1;
3682 ippDelete(p
->ppd_attrs
);
3683 p
->ppd_attrs
= NULL
;
3685 _ppdCacheDestroy(p
->pc
);
3688 if (cache_info
.st_mtime
>= ppd_info
.st_mtime
)
3690 cupsdLogMessage(CUPSD_LOG_DEBUG
, "load_ppd: Loading %s...", cache_name
);
3692 if ((p
->pc
= _ppdCacheCreateWithFile(cache_name
, &p
->ppd_attrs
)) != NULL
&&
3696 * Loaded successfully!
3704 * Reload PPD attributes from disk...
3707 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
3709 cupsdLogMessage(CUPSD_LOG_DEBUG
, "load_ppd: Loading %s...", ppd_name
);
3711 p
->type
&= (cups_ptype_t
)~CUPS_PRINTER_OPTIONS
;
3712 p
->type
|= CUPS_PRINTER_BW
;
3714 finishings
[0] = IPP_FINISHINGS_NONE
;
3717 p
->ppd_attrs
= ippNew();
3719 if ((ppd
= _ppdOpenFile(ppd_name
, _PPD_LOCALIZATION_NONE
)) != NULL
)
3722 * Add make/model and other various attributes...
3725 p
->pc
= _ppdCacheCreateWithPPD(ppd
);
3728 cupsdLogMessage(CUPSD_LOG_WARN
, "Unable to create cache of \"%s\": %s",
3729 ppd_name
, cupsLastErrorString());
3731 ppdMarkDefaults(ppd
);
3733 if (ppd
->color_device
)
3734 p
->type
|= CUPS_PRINTER_COLOR
;
3735 if (ppd
->variable_sizes
)
3736 p
->type
|= CUPS_PRINTER_VARIABLE
;
3737 if (!ppd
->manual_copies
)
3738 p
->type
|= CUPS_PRINTER_COPIES
;
3739 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsFax", NULL
)) != NULL
)
3740 if (ppd_attr
->value
&& !_cups_strcasecmp(ppd_attr
->value
, "true"))
3741 p
->type
|= CUPS_PRINTER_FAX
;
3743 ippAddBoolean(p
->ppd_attrs
, IPP_TAG_PRINTER
, "color-supported", (char)ppd
->color_device
);
3745 if (p
->pc
&& p
->pc
->charge_info_uri
)
3746 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
3747 "printer-charge-info-uri", NULL
, p
->pc
->charge_info_uri
);
3749 if (p
->pc
&& p
->pc
->account_id
)
3750 ippAddBoolean(p
->ppd_attrs
, IPP_TAG_PRINTER
, "job-account-id-supported",
3753 if (p
->pc
&& p
->pc
->accounting_user_id
)
3754 ippAddBoolean(p
->ppd_attrs
, IPP_TAG_PRINTER
,
3755 "job-accounting-user-id-supported", 1);
3757 if (p
->pc
&& p
->pc
->password
)
3759 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3760 "job-password-encryption-supported", NULL
, "none");
3761 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3762 "job-password-supported", (int)strlen(p
->pc
->password
));
3765 if (ppd
->throughput
)
3767 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3768 "pages-per-minute", ppd
->throughput
);
3769 if (ppd
->color_device
)
3770 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3771 "pages-per-minute-color", ppd
->throughput
);
3776 * When there is no speed information, just say "1 page per minute".
3779 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3780 "pages-per-minute", 1);
3781 if (ppd
->color_device
)
3782 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3783 "pages-per-minute-color", 1);
3788 if ((output_mode
= ppdFindOption(ppd
, "OutputMode")) != NULL
)
3790 if (ppdFindChoice(output_mode
, "draft") ||
3791 ppdFindChoice(output_mode
, "fast"))
3792 qualities
[num_qualities
++] = IPP_QUALITY_DRAFT
;
3794 qualities
[num_qualities
++] = IPP_QUALITY_NORMAL
;
3796 if (ppdFindChoice(output_mode
, "best") ||
3797 ppdFindChoice(output_mode
, "high"))
3798 qualities
[num_qualities
++] = IPP_QUALITY_HIGH
;
3800 else if ((ppd_attr
= ppdFindAttr(ppd
, "APPrinterPreset", NULL
)) != NULL
)
3804 if (strstr(ppd_attr
->spec
, "draft") ||
3805 strstr(ppd_attr
->spec
, "Draft"))
3807 qualities
[num_qualities
++] = IPP_QUALITY_DRAFT
;
3811 while ((ppd_attr
= ppdFindNextAttr(ppd
, "APPrinterPreset",
3814 qualities
[num_qualities
++] = IPP_QUALITY_NORMAL
;
3815 qualities
[num_qualities
++] = IPP_QUALITY_HIGH
;
3818 qualities
[num_qualities
++] = IPP_QUALITY_NORMAL
;
3820 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
3821 "print-quality-supported", num_qualities
, qualities
);
3826 * The NickName can be localized in the character set specified
3827 * by the LanugageEncoding attribute. However, ppdOpen2() has
3828 * already converted the ppd->nickname member to UTF-8 for us
3829 * (the original attribute value is available separately)
3832 cupsdSetString(&p
->make_model
, ppd
->nickname
);
3834 else if (ppd
->modelname
)
3837 * Model name can only contain specific characters...
3840 cupsdSetString(&p
->make_model
, ppd
->modelname
);
3843 cupsdSetString(&p
->make_model
, "Bad PPD File");
3845 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
3846 "printer-make-and-model", NULL
, p
->make_model
);
3849 * Add media options from the PPD file...
3852 if (ppd
->num_sizes
== 0 || !p
->pc
)
3854 if (!ppdFindAttr(ppd
, "APScannerOnly", NULL
))
3855 cupsdLogMessage(CUPSD_LOG_CRIT
,
3856 "The PPD file for printer %s contains no media "
3857 "options and is therefore invalid!", p
->name
);
3859 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3860 "media-default", NULL
, "unknown");
3861 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3862 "media-supported", NULL
, "unknown");
3870 if ((size
= ppdPageSize(ppd
, NULL
)) != NULL
)
3871 pwgsize
= _ppdCacheGetSize(p
->pc
, size
->name
);
3875 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3876 "media-default", NULL
,
3877 pwgsize
? pwgsize
->map
.pwg
: "unknown");
3885 ipp_t
*col
; /* Collection value */
3887 input_slot
= ppdFindMarkedChoice(ppd
, "InputSlot");
3888 media_type
= ppdFindMarkedChoice(ppd
, "MediaType");
3889 col
= new_media_col(pwgsize
,
3891 _ppdCacheGetSource(p
->pc
,
3892 input_slot
->choice
) :
3895 _ppdCacheGetType(p
->pc
,
3896 media_type
->choice
) :
3899 ippAddCollection(p
->ppd_attrs
, IPP_TAG_PRINTER
, "media-col-default",
3908 num_media
= p
->pc
->num_sizes
;
3909 if (p
->pc
->custom_min_keyword
)
3912 if ((attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3913 "media-supported", num_media
, NULL
,
3918 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
;
3920 i
--, pwgsize
++, val
++)
3921 val
->string
.text
= _cupsStrAlloc(pwgsize
->map
.pwg
);
3923 if (p
->pc
->custom_min_keyword
)
3925 val
->string
.text
= _cupsStrAlloc(p
->pc
->custom_min_keyword
);
3927 val
->string
.text
= _cupsStrAlloc(p
->pc
->custom_max_keyword
);
3932 * media-size-supported
3935 num_media
= p
->pc
->num_sizes
;
3936 if (p
->pc
->custom_min_keyword
)
3939 if ((attr
= ippAddCollections(p
->ppd_attrs
, IPP_TAG_PRINTER
,
3940 "media-size-supported", num_media
,
3945 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
;
3947 i
--, pwgsize
++, val
++)
3949 val
->collection
= ippNew();
3950 ippAddInteger(val
->collection
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3951 "x-dimension", pwgsize
->width
);
3952 ippAddInteger(val
->collection
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3953 "y-dimension", pwgsize
->length
);
3956 if (p
->pc
->custom_min_keyword
)
3958 val
->collection
= ippNew();
3959 ippAddRange(val
->collection
, IPP_TAG_PRINTER
, "x-dimension",
3960 p
->pc
->custom_min_width
, p
->pc
->custom_max_width
);
3961 ippAddRange(val
->collection
, IPP_TAG_PRINTER
, "y-dimension",
3962 p
->pc
->custom_min_length
, p
->pc
->custom_max_length
);
3967 * media-source-supported
3970 if (p
->pc
->num_sources
> 0 &&
3971 (attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3972 "media-source-supported", p
->pc
->num_sources
,
3973 NULL
, NULL
)) != NULL
)
3975 for (i
= p
->pc
->num_sources
, pwgsource
= p
->pc
->sources
,
3978 i
--, pwgsource
++, val
++)
3979 val
->string
.text
= _cupsStrAlloc(pwgsource
->pwg
);
3983 * media-type-supported
3986 if (p
->pc
->num_types
> 0 &&
3987 (attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3988 "media-type-supported", p
->pc
->num_types
,
3989 NULL
, NULL
)) != NULL
)
3991 for (i
= p
->pc
->num_types
, pwgtype
= p
->pc
->types
,
3994 i
--, pwgtype
++, val
++)
3995 val
->string
.text
= _cupsStrAlloc(pwgtype
->pwg
);
3999 * media-*-margin-supported
4002 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, num_margins
= 0;
4003 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4006 for (j
= 0; j
< num_margins
; j
++)
4007 if (pwgsize
->bottom
== margins
[j
])
4010 if (j
>= num_margins
)
4012 margins
[num_margins
] = pwgsize
->bottom
;
4017 if (num_margins
> 0)
4018 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4019 "media-bottom-margin-supported", num_margins
, margins
);
4021 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4022 "media-bottom-margin-supported", 0);
4024 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, num_margins
= 0;
4025 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4028 for (j
= 0; j
< num_margins
; j
++)
4029 if (pwgsize
->left
== margins
[j
])
4032 if (j
>= num_margins
)
4034 margins
[num_margins
] = pwgsize
->left
;
4039 if (num_margins
> 0)
4040 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4041 "media-left-margin-supported", num_margins
, margins
);
4043 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4044 "media-left-margin-supported", 0);
4046 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, num_margins
= 0;
4047 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4050 for (j
= 0; j
< num_margins
; j
++)
4051 if (pwgsize
->right
== margins
[j
])
4054 if (j
>= num_margins
)
4056 margins
[num_margins
] = pwgsize
->right
;
4061 if (num_margins
> 0)
4062 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4063 "media-right-margin-supported", num_margins
, margins
);
4065 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4066 "media-right-margin-supported", 0);
4068 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, num_margins
= 0;
4069 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4072 for (j
= 0; j
< num_margins
; j
++)
4073 if (pwgsize
->top
== margins
[j
])
4076 if (j
>= num_margins
)
4078 margins
[num_margins
] = pwgsize
->top
;
4083 if (num_margins
> 0)
4084 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4085 "media-top-margin-supported", num_margins
, margins
);
4087 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4088 "media-top-margin-supported", 0);
4091 * media-col-database
4094 num_media
= p
->pc
->num_sizes
;
4095 if (p
->pc
->num_sources
)
4097 if (p
->pc
->num_types
> 0)
4098 num_media
+= p
->pc
->num_sizes
* p
->pc
->num_sources
*
4101 num_media
+= p
->pc
->num_sizes
* p
->pc
->num_sources
;
4103 else if (p
->pc
->num_types
)
4104 num_media
+= p
->pc
->num_sizes
* p
->pc
->num_types
;
4106 if ((attr
= ippAddCollections(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4107 "media-col-database", num_media
,
4110 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, val
= attr
->values
;
4115 * Start by adding the page size without source or type...
4118 ppdMarkOption(ppd
, "PageSize", pwgsize
->map
.ppd
);
4120 val
->collection
= new_media_col(pwgsize
, NULL
, NULL
);
4124 * Then add the specific, supported combinations of size, source, and
4128 if (p
->pc
->num_sources
> 0)
4130 for (j
= p
->pc
->num_sources
, pwgsource
= p
->pc
->sources
;
4134 ppdMarkOption(ppd
, "InputSlot", pwgsource
->ppd
);
4136 if (p
->pc
->num_types
> 0)
4138 for (k
= p
->pc
->num_types
, pwgtype
= p
->pc
->types
;
4142 if (!ppdMarkOption(ppd
, "MediaType", pwgtype
->ppd
))
4144 val
->collection
= new_media_col(pwgsize
, pwgsource
->pwg
,
4150 else if (!ppdConflicts(ppd
))
4152 val
->collection
= new_media_col(pwgsize
, pwgsource
->pwg
, NULL
);
4157 else if (p
->pc
->num_types
> 0)
4159 for (j
= p
->pc
->num_types
, pwgtype
= p
->pc
->types
;
4163 if (!ppdMarkOption(ppd
, "MediaType", pwgtype
->ppd
))
4165 val
->collection
= new_media_col(pwgsize
, NULL
, pwgtype
->pwg
);
4173 * Update the number of media-col-database values...
4176 attr
->num_values
= val
- attr
->values
;
4184 if (p
->pc
&& p
->pc
->num_bins
> 0)
4186 attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4187 "output-bin-supported", p
->pc
->num_bins
,
4192 for (i
= 0, val
= attr
->values
;
4193 i
< p
->pc
->num_bins
;
4195 val
->string
.text
= _cupsStrAlloc(p
->pc
->bins
[i
].pwg
);
4198 if ((output_bin
= ppdFindOption(ppd
, "OutputBin")) != NULL
)
4200 for (i
= 0; i
< p
->pc
->num_bins
; i
++)
4201 if (!strcmp(p
->pc
->bins
[i
].ppd
, output_bin
->defchoice
))
4204 if (i
>= p
->pc
->num_bins
)
4207 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4208 "output-bin-default", NULL
, p
->pc
->bins
[i
].pwg
);
4211 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4212 "output-bin-default", NULL
, p
->pc
->bins
[0].pwg
);
4214 else if (((ppd_attr
= ppdFindAttr(ppd
, "DefaultOutputOrder",
4216 !_cups_strcasecmp(ppd_attr
->value
, "Reverse")) ||
4217 (!ppd_attr
&& ppd
->manufacturer
&& /* "Compatibility heuristic" */
4218 (!_cups_strcasecmp(ppd
->manufacturer
, "epson") ||
4219 !_cups_strcasecmp(ppd
->manufacturer
, "lexmark"))))
4222 * Report that this printer has a single output bin that leaves pages face
4226 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4227 "output-bin-supported", NULL
, "face-up");
4228 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4229 "output-bin-default", NULL
, "face-up");
4233 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4234 "output-bin-supported", NULL
, "face-down");
4235 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4236 "output-bin-default", NULL
, "face-down");
4240 * print-color-mode...
4243 if (ppd
->color_device
)
4245 static const char * const color_modes
[] =
4251 ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4252 "print-color-mode-supported", 2, NULL
, color_modes
);
4253 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4254 "print-color-mode-default", NULL
, "color");
4258 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4259 "print-color-mode-supported", NULL
, "monochrome");
4260 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4261 "print-color-mode-default", NULL
, "monochrome");
4265 * Mandatory job attributes, if any...
4268 if (p
->pc
&& cupsArrayCount(p
->pc
->mandatory
) > 0)
4270 int count
= cupsArrayCount(p
->pc
->mandatory
);
4271 /* Number of mandatory attributes */
4273 attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4274 "printer-mandatory-job-attributes", count
, NULL
,
4277 for (val
= attr
->values
,
4278 mandatory
= (char *)cupsArrayFirst(p
->pc
->mandatory
);
4280 val
++, mandatory
= (char *)cupsArrayNext(p
->pc
->mandatory
))
4281 val
->string
.text
= _cupsStrAlloc(mandatory
);
4285 * Printer resolutions...
4288 if ((resolution
= ppdFindOption(ppd
, "Resolution")) == NULL
)
4289 if ((resolution
= ppdFindOption(ppd
, "JCLResolution")) == NULL
)
4290 if ((resolution
= ppdFindOption(ppd
, "SetResolution")) == NULL
)
4291 resolution
= ppdFindOption(ppd
, "CNRes_PGP");
4296 * Report all supported resolutions...
4299 attr
= ippAddResolutions(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4300 "printer-resolution-supported",
4301 resolution
->num_choices
, IPP_RES_PER_INCH
,
4304 for (i
= 0, choice
= resolution
->choices
;
4305 i
< resolution
->num_choices
;
4308 xdpi
= ydpi
= (int)strtol(choice
->choice
, (char **)&resptr
, 10);
4309 if (resptr
> choice
->choice
&& xdpi
> 0 && *resptr
== 'x')
4310 ydpi
= (int)strtol(resptr
+ 1, (char **)&resptr
, 10);
4312 if (xdpi
<= 0 || ydpi
<= 0)
4314 cupsdLogMessage(CUPSD_LOG_WARN
,
4315 "Bad resolution \"%s\" for printer %s.",
4316 choice
->choice
, p
->name
);
4320 attr
->values
[i
].resolution
.xres
= xdpi
;
4321 attr
->values
[i
].resolution
.yres
= ydpi
;
4322 attr
->values
[i
].resolution
.units
= IPP_RES_PER_INCH
;
4325 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4326 "printer-resolution-default", IPP_RES_PER_INCH
,
4330 else if ((ppd_attr
= ppdFindAttr(ppd
, "DefaultResolution", NULL
)) != NULL
&&
4334 * Just the DefaultResolution to report...
4337 xdpi
= ydpi
= (int)strtol(ppd_attr
->value
, (char **)&resptr
, 10);
4338 if (resptr
> ppd_attr
->value
&& xdpi
> 0)
4341 ydpi
= (int)strtol(resptr
+ 1, (char **)&resptr
, 10);
4346 if (xdpi
<= 0 || ydpi
<= 0)
4348 cupsdLogMessage(CUPSD_LOG_WARN
,
4349 "Bad default resolution \"%s\" for printer %s.",
4350 ppd_attr
->value
, p
->name
);
4354 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4355 "printer-resolution-default", IPP_RES_PER_INCH
,
4357 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4358 "printer-resolution-supported", IPP_RES_PER_INCH
,
4364 * No resolutions in PPD - make one up...
4367 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4368 "printer-resolution-default", IPP_RES_PER_INCH
,
4370 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4371 "printer-resolution-supported", IPP_RES_PER_INCH
,
4379 ppdMarkDefaults(ppd
);
4381 if ((duplex
= ppdFindOption(ppd
, "Duplex")) == NULL
)
4382 if ((duplex
= ppdFindOption(ppd
, "EFDuplex")) == NULL
)
4383 if ((duplex
= ppdFindOption(ppd
, "EFDuplexing")) == NULL
)
4384 if ((duplex
= ppdFindOption(ppd
, "KD03Duplex")) == NULL
)
4385 duplex
= ppdFindOption(ppd
, "JCLDuplex");
4387 if (duplex
&& duplex
->num_choices
> 1 &&
4388 !ppdInstallableConflict(ppd
, duplex
->keyword
, "DuplexTumble"))
4390 p
->type
|= CUPS_PRINTER_DUPLEX
;
4392 ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4393 "sides-supported", 3, NULL
, sides
);
4395 if (!_cups_strcasecmp(duplex
->defchoice
, "DuplexTumble"))
4396 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4397 "sides-default", NULL
, "two-sided-short-edge");
4398 else if (!_cups_strcasecmp(duplex
->defchoice
, "DuplexNoTumble"))
4399 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4400 "sides-default", NULL
, "two-sided-long-edge");
4402 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4403 "sides-default", NULL
, "one-sided");
4407 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4408 "sides-supported", NULL
, "one-sided");
4409 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4410 "sides-default", NULL
, "one-sided");
4413 if (ppdFindOption(ppd
, "Collate") != NULL
)
4414 p
->type
|= CUPS_PRINTER_COLLATE
;
4416 if (ppdFindOption(ppd
, "StapleLocation") != NULL
)
4418 p
->type
|= CUPS_PRINTER_STAPLE
;
4419 finishings
[num_finishings
++] = IPP_FINISHINGS_STAPLE
;
4422 if (ppdFindOption(ppd
, "BindEdge") != NULL
)
4424 p
->type
|= CUPS_PRINTER_BIND
;
4425 finishings
[num_finishings
++] = IPP_FINISHINGS_BIND
;
4428 for (i
= 0; i
< ppd
->num_sizes
; i
++)
4429 if (ppd
->sizes
[i
].length
> 1728)
4430 p
->type
|= CUPS_PRINTER_LARGE
;
4431 else if (ppd
->sizes
[i
].length
> 1008)
4432 p
->type
|= CUPS_PRINTER_MEDIUM
;
4434 p
->type
|= CUPS_PRINTER_SMALL
;
4436 if ((ppd_attr
= ppdFindAttr(ppd
, "APICADriver", NULL
)) != NULL
&&
4437 ppd_attr
->value
&& !_cups_strcasecmp(ppd_attr
->value
, "true"))
4439 if ((ppd_attr
= ppdFindAttr(ppd
, "APScannerOnly", NULL
)) != NULL
&&
4440 ppd_attr
->value
&& !_cups_strcasecmp(ppd_attr
->value
, "true"))
4441 p
->type
|= CUPS_PRINTER_SCANNER
;
4443 p
->type
|= CUPS_PRINTER_MFP
;
4447 * Scan the filters in the PPD file...
4452 for (filter
= (const char *)cupsArrayFirst(p
->pc
->filters
);
4454 filter
= (const char *)cupsArrayNext(p
->pc
->filters
))
4456 if (!_cups_strncasecmp(filter
, "application/vnd.cups-command", 28) &&
4457 _cups_isspace(filter
[28]))
4459 p
->type
|= CUPS_PRINTER_COMMANDS
;
4465 if (p
->type
& CUPS_PRINTER_COMMANDS
)
4467 char *commands
, /* Copy of commands */
4468 *start
, /* Start of name */
4469 *end
; /* End of name */
4470 int count
; /* Number of commands */
4472 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsCommands", NULL
)) != NULL
)
4474 for (count
= 0, start
= ppd_attr
->value
; *start
; count
++)
4476 while (_cups_isspace(*start
))
4482 while (*start
&& !isspace(*start
& 255))
4492 * Make a copy of the commands string and count how many commands there
4496 attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4497 "printer-commands", count
, NULL
, NULL
);
4499 commands
= strdup(ppd_attr
->value
);
4501 for (count
= 0, start
= commands
; *start
; count
++)
4503 while (isspace(*start
& 255))
4510 while (*end
&& !isspace(*end
& 255))
4516 attr
->values
[count
].string
.text
= _cupsStrAlloc(start
);
4526 * Add the standard list of commands...
4529 ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4531 (int)(sizeof(standard_commands
) /
4532 sizeof(standard_commands
[0])), NULL
,
4539 * No commands supported...
4542 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4543 "printer-commands", NULL
, "none");
4547 * Show current and available port monitors for this printer...
4550 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
, "port-monitor",
4551 NULL
, p
->port_monitor
? p
->port_monitor
: "none");
4553 for (i
= 1, ppd_attr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
4555 i
++, ppd_attr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
));
4559 if (strstr(ppd
->protocols
, "TBCP"))
4561 else if (strstr(ppd
->protocols
, "BCP"))
4565 attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
4566 "port-monitor-supported", i
, NULL
, NULL
);
4568 attr
->values
[0].string
.text
= _cupsStrAlloc("none");
4570 for (i
= 1, ppd_attr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
4572 i
++, ppd_attr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
))
4573 attr
->values
[i
].string
.text
= _cupsStrAlloc(ppd_attr
->value
);
4577 if (strstr(ppd
->protocols
, "TBCP"))
4578 attr
->values
[i
].string
.text
= _cupsStrAlloc("tbcp");
4579 else if (strstr(ppd
->protocols
, "BCP"))
4580 attr
->values
[i
].string
.text
= _cupsStrAlloc("bcp");
4583 if (ppdFindAttr(ppd
, "APRemoteQueueID", NULL
))
4584 p
->type
|= CUPS_PRINTER_REMOTE
;
4586 #ifdef HAVE_APPLICATIONSERVICES_H
4588 * Convert the file referenced in APPrinterIconPath to a 128x128 PNG
4589 * and save it as cacheDir/printername.png
4592 if ((ppd_attr
= ppdFindAttr(ppd
, "APPrinterIconPath", NULL
)) != NULL
&&
4594 !_cupsFileCheck(ppd_attr
->value
, _CUPS_FILE_CHECK_FILE
, !RunUser
,
4595 cupsdLogFCMessage
, p
))
4597 CGImageRef imageRef
= NULL
;/* Current icon image */
4598 CGImageRef biggestIconRef
= NULL
;
4599 /* Biggest icon image */
4600 CGImageRef closestTo128IconRef
= NULL
;
4601 /* Icon image closest to and >= 128 */
4602 CGImageSourceRef sourceRef
; /* The file's image source */
4603 char outPath
[HTTP_MAX_URI
];
4604 /* The path to the PNG file */
4605 CFURLRef outUrl
; /* The URL made from the outPath */
4606 CFURLRef icnsFileUrl
; /* The URL of the original ICNS icon file */
4607 CGImageDestinationRef destRef
; /* The image destination to write */
4608 size_t bytesPerRow
; /* The bytes per row used for resizing */
4609 CGContextRef context
; /* The CG context used for resizing */
4611 snprintf(outPath
, sizeof(outPath
), "%s/%s.png", CacheDir
, p
->name
);
4612 outUrl
= CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault
, (UInt8
*)outPath
, (CFIndex
)strlen(outPath
), FALSE
);
4613 icnsFileUrl
= CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault
, (UInt8
*)ppd_attr
->value
, (CFIndex
)strlen(ppd_attr
->value
), FALSE
);
4614 if (outUrl
&& icnsFileUrl
)
4616 sourceRef
= CGImageSourceCreateWithURL(icnsFileUrl
, NULL
);
4619 for (i
= 0; i
< (int)CGImageSourceGetCount(sourceRef
); i
++)
4621 imageRef
= CGImageSourceCreateImageAtIndex(sourceRef
, (size_t)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 * 'new_media_col()' - Create a media-col collection value.
4857 static ipp_t
* /* O - Collection value */
4858 new_media_col(_pwg_size_t
*size
, /* I - media-size/margin values */
4859 const char *source
, /* I - media-source value */
4860 const char *type
) /* I - media-type value */
4862 ipp_t
*media_col
, /* Collection value */
4863 *media_size
; /* media-size value */
4866 media_col
= ippNew();
4868 media_size
= ippNew();
4869 ippAddInteger(media_size
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4870 "x-dimension", size
->width
);
4871 ippAddInteger(media_size
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4872 "y-dimension", size
->length
);
4873 ippAddCollection(media_col
, IPP_TAG_PRINTER
, "media-size", media_size
);
4874 ippDelete(media_size
);
4876 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4877 "media-bottom-margin", size
->bottom
);
4878 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4879 "media-left-margin", size
->left
);
4880 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4881 "media-right-margin", size
->right
);
4882 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4883 "media-top-margin", size
->top
);
4886 ippAddString(media_col
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
, "media-source",
4890 ippAddString(media_col
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
, "media-type",
4898 * 'write_xml_string()' - Write a string with XML escaping.
4902 write_xml_string(cups_file_t
*fp
, /* I - File to write to */
4903 const char *s
) /* I - String to write */
4905 const char *start
; /* Start of current sequence */
4911 for (start
= s
; *s
; s
++)
4916 cupsFileWrite(fp
, start
, (size_t)(s
- start
));
4918 cupsFilePuts(fp
, "&");
4924 cupsFileWrite(fp
, start
, (size_t)(s
- start
));
4926 cupsFilePuts(fp
, "<");
4932 cupsFilePuts(fp
, start
);