2 * "$Id: printers.c 11623 2014-02-19 20:18:10Z msweet $"
4 * Printer routines for the CUPS scheduler.
6 * Copyright 2007-2013 by Apple Inc.
7 * Copyright 1997-2007 by Easy Software Products, all rights reserved.
9 * These coded instructions, statements, and computer programs are the
10 * property of Apple Inc. and are protected by Federal copyright
11 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
12 * which should have been included with this file. If this file is
13 * file is missing or damaged, see the license at "http://www.cups.org/".
17 * Include necessary headers...
22 #ifdef HAVE_APPLICATIONSERVICES_H
23 # include <ApplicationServices/ApplicationServices.h>
24 #endif /* HAVE_APPLICATIONSERVICES_H */
25 #ifdef HAVE_SYS_MOUNT_H
26 # include <sys/mount.h>
27 #endif /* HAVE_SYS_MOUNT_H */
28 #ifdef HAVE_SYS_STATVFS_H
29 # include <sys/statvfs.h>
30 #elif defined(HAVE_SYS_STATFS_H)
31 # include <sys/statfs.h>
32 #endif /* HAVE_SYS_STATVFS_H */
35 #endif /* HAVE_SYS_VFS_H */
38 #endif /* __APPLE__ */
45 static void add_printer_defaults(cupsd_printer_t
*p
);
46 static void add_printer_filter(cupsd_printer_t
*p
, mime_type_t
*type
,
48 static void add_printer_formats(cupsd_printer_t
*p
);
49 static int compare_printers(void *first
, void *second
, void *data
);
50 static void delete_printer_filters(cupsd_printer_t
*p
);
51 static void dirty_printer(cupsd_printer_t
*p
);
52 static void load_ppd(cupsd_printer_t
*p
);
53 static 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-creation-attributes-supported */
434 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
435 "job-creation-attributes-supported",
436 sizeof(job_creation
) / sizeof(job_creation
[0]),
439 /* job-hold-until-supported */
440 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
441 "job-hold-until-supported", sizeof(holds
) / sizeof(holds
[0]),
444 /* job-ids-supported */
445 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
, "job-ids-supported", 1);
447 /* job-k-octets-supported */
448 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "job-k-octets-supported", 0,
451 /* job-priority-supported */
452 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
453 "job-priority-supported", 100);
455 /* job-settable-attributes-supported */
456 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
457 "job-settable-attributes-supported",
458 sizeof(job_settable
) / sizeof(job_settable
[0]),
461 /* job-sheets-supported */
462 if (cupsArrayCount(Banners
) > 0)
465 * Setup the job-sheets-supported attribute...
468 if (Classification
&& !ClassifyOverride
)
469 attr
= ippAddString(CommonData
, IPP_TAG_PRINTER
,
470 IPP_TAG_NAME
| IPP_TAG_COPY
,
471 "job-sheets-supported", NULL
, Classification
);
473 attr
= ippAddStrings(CommonData
, IPP_TAG_PRINTER
,
474 IPP_TAG_NAME
| IPP_TAG_COPY
,
475 "job-sheets-supported", cupsArrayCount(Banners
) + 1,
479 cupsdLogMessage(CUPSD_LOG_EMERG
,
480 "Unable to allocate memory for "
481 "job-sheets-supported attribute: %s!", strerror(errno
));
482 else if (!Classification
|| ClassifyOverride
)
484 cupsd_banner_t
*banner
; /* Current banner */
487 attr
->values
[0].string
.text
= _cupsStrAlloc("none");
489 for (i
= 1, banner
= (cupsd_banner_t
*)cupsArrayFirst(Banners
);
491 i
++, banner
= (cupsd_banner_t
*)cupsArrayNext(Banners
))
492 attr
->values
[i
].string
.text
= banner
->name
;
496 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
497 "job-sheets-supported", NULL
, "none");
499 /* jpeg-k-octets-supported */
500 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "jpeg-k-octets-supported", 0,
503 /* jpeg-x-dimension-supported */
504 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "jpeg-x-dimension-supported", 0,
507 /* jpeg-y-dimension-supported */
508 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "jpeg-y-dimension-supported", 1,
511 /* media-col-supported */
512 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
513 "media-col-supported",
514 sizeof(media_col_supported
) /
515 sizeof(media_col_supported
[0]), NULL
,
516 media_col_supported
);
518 /* multiple-document-handling-supported */
519 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
520 "multiple-document-handling-supported",
521 sizeof(multiple_document_handling
) /
522 sizeof(multiple_document_handling
[0]), NULL
,
523 multiple_document_handling
);
525 /* multiple-document-jobs-supported */
526 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
,
527 "multiple-document-jobs-supported", 1);
529 /* multiple-operation-time-out */
530 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
531 "multiple-operation-time-out", MultipleOperationTimeout
);
533 /* natural-language-configured (no IPP_TAG_COPY) */
534 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_LANGUAGE
,
535 "natural-language-configured", NULL
, DefaultLanguage
);
537 /* notify-attributes-supported */
538 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
539 "notify-attributes-supported",
540 (int)(sizeof(notify_attrs
) / sizeof(notify_attrs
[0])),
543 /* notify-lease-duration-supported */
544 ippAddRange(CommonData
, IPP_TAG_PRINTER
,
545 "notify-lease-duration-supported", 0,
546 MaxLeaseDuration
? MaxLeaseDuration
: 2147483647);
548 /* notify-max-events-supported */
549 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
550 "notify-max-events-supported", MaxEvents
);
552 /* notify-events-supported */
553 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
554 "notify-events-supported",
555 (int)(sizeof(notify_events
) / sizeof(notify_events
[0])),
556 NULL
, notify_events
);
558 /* notify-pull-method-supported */
559 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
560 "notify-pull-method-supported", NULL
, "ippget");
562 /* notify-schemes-supported */
563 snprintf(filename
, sizeof(filename
), "%s/notifier", ServerBin
);
564 if ((dir
= cupsDirOpen(filename
)) != NULL
)
566 notifiers
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
568 while ((dent
= cupsDirRead(dir
)) != NULL
)
569 if (S_ISREG(dent
->fileinfo
.st_mode
) &&
570 (dent
->fileinfo
.st_mode
& S_IXOTH
) != 0)
571 cupsArrayAdd(notifiers
, _cupsStrAlloc(dent
->filename
));
573 if (cupsArrayCount(notifiers
) > 0)
575 attr
= ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
576 "notify-schemes-supported",
577 cupsArrayCount(notifiers
), NULL
, NULL
);
579 for (i
= 0, notifier
= (char *)cupsArrayFirst(notifiers
);
581 i
++, notifier
= (char *)cupsArrayNext(notifiers
))
582 attr
->values
[i
].string
.text
= notifier
;
585 cupsArrayDelete(notifiers
);
589 /* number-up-supported */
590 ippAddIntegers(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
591 "number-up-supported", sizeof(nups
) / sizeof(nups
[0]), nups
);
593 /* operations-supported */
594 ippAddIntegers(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
595 "operations-supported", sizeof(ops
) / sizeof(ops
[0]), ops
);
597 /* orientation-requested-supported */
598 ippAddIntegers(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
599 "orientation-requested-supported", 4, orients
);
601 /* page-ranges-supported */
602 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
, "page-ranges-supported", 1);
604 /* pdf-k-octets-supported */
605 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "pdf-k-octets-supported", 0,
608 /* pdf-versions-supported */
609 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
610 "pdf-versions-supported",
611 sizeof(pdf_versions
) / sizeof(pdf_versions
[0]), NULL
,
614 /* pdl-override-supported */
615 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
616 "pdl-override-supported", NULL
, "attempted");
618 /* printer-op-policy-supported */
619 attr
= ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
620 "printer-op-policy-supported", cupsArrayCount(Policies
),
622 for (i
= 0, p
= (cupsd_policy_t
*)cupsArrayFirst(Policies
);
624 i
++, p
= (cupsd_policy_t
*)cupsArrayNext(Policies
))
625 attr
->values
[i
].string
.text
= p
->name
;
627 /* printer-settable-attributes-supported */
628 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
629 "printer-settable-attributes-supported",
630 sizeof(printer_settable
) / sizeof(printer_settable
[0]),
631 NULL
, printer_settable
);
633 /* server-is-sharing-printers */
634 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
, "server-is-sharing-printers",
635 BrowseLocalProtocols
!= 0 && Browsing
);
637 /* which-jobs-supported */
638 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
639 "which-jobs-supported",
640 sizeof(which_jobs
) / sizeof(which_jobs
[0]), NULL
, which_jobs
);
645 * 'cupsdDeleteAllPrinters()' - Delete all printers from the system.
649 cupsdDeleteAllPrinters(void)
651 cupsd_printer_t
*p
; /* Pointer to current printer/class */
654 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
656 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
658 p
->op_policy_ptr
= DefaultPolicyPtr
;
659 cupsdDeletePrinter(p
, 0);
665 * 'cupsdDeletePrinter()' - Delete a printer from the system.
668 int /* O - 1 if classes affected, 0 otherwise */
670 cupsd_printer_t
*p
, /* I - Printer to delete */
671 int update
) /* I - Update printers.conf? */
673 int i
, /* Looping var */
674 changed
= 0; /* Class changed? */
677 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdDeletePrinter(p=%p(%s), update=%d)",
681 * Save the current position in the Printers array...
684 cupsArraySave(Printers
);
687 * Stop printing on this printer...
690 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, update
);
692 p
->state
= IPP_PRINTER_STOPPED
; /* Force for browsed printers */
695 cupsdSetJobState(p
->job
, IPP_JOB_PENDING
, CUPSD_JOB_FORCE
,
696 update
? "Job stopped due to printer being deleted." :
700 * Remove the printer from the list...
703 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
704 "cupsdDeletePrinter: Removing %s from Printers", p
->name
);
705 cupsArrayRemove(Printers
, p
);
708 * If p is the default printer, assign a different one...
711 if (p
== DefaultPrinter
)
712 DefaultPrinter
= NULL
;
715 * Remove this printer from any classes...
718 changed
= cupsdDeletePrinterFromClasses(p
);
721 * Deregister from any browse protocols...
724 cupsdDeregisterPrinter(p
, 1);
727 * Free all memory used by the printer...
730 if (p
->printers
!= NULL
)
733 delete_printer_filters(p
);
735 for (i
= 0; i
< p
->num_reasons
; i
++)
736 _cupsStrFree(p
->reasons
[i
]);
739 ippDelete(p
->ppd_attrs
);
741 mimeDeleteType(MimeDatabase
, p
->filetype
);
742 mimeDeleteType(MimeDatabase
, p
->prefiltertype
);
744 cupsdFreeStrings(&(p
->users
));
747 cupsdClearString(&p
->uri
);
748 cupsdClearString(&p
->hostname
);
749 cupsdClearString(&p
->name
);
750 cupsdClearString(&p
->location
);
751 cupsdClearString(&p
->make_model
);
752 cupsdClearString(&p
->info
);
753 cupsdClearString(&p
->job_sheets
[0]);
754 cupsdClearString(&p
->job_sheets
[1]);
755 cupsdClearString(&p
->device_uri
);
756 cupsdClearString(&p
->sanitized_device_uri
);
757 cupsdClearString(&p
->port_monitor
);
758 cupsdClearString(&p
->op_policy
);
759 cupsdClearString(&p
->error_policy
);
761 cupsdClearString(&p
->alert
);
762 cupsdClearString(&p
->alert_description
);
764 #if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
765 cupsdClearString(&p
->pdl
);
766 cupsdClearString(&p
->reg_name
);
767 #endif /* HAVE_DNSSD || HAVE_AVAHI */
769 cupsArrayDelete(p
->filetypes
);
771 cupsFreeOptions(p
->num_options
, p
->options
);
776 * Restore the previous position in the Printers array...
779 cupsArrayRestore(Printers
);
786 * 'cupsdFindDest()' - Find a destination in the list.
789 cupsd_printer_t
* /* O - Destination in list */
790 cupsdFindDest(const char *name
) /* I - Name of printer or class to find */
792 cupsd_printer_t key
; /* Search key */
795 key
.name
= (char *)name
;
796 return ((cupsd_printer_t
*)cupsArrayFind(Printers
, &key
));
801 * 'cupsdFindPrinter()' - Find a printer in the list.
804 cupsd_printer_t
* /* O - Printer in list */
805 cupsdFindPrinter(const char *name
) /* I - Name of printer to find */
807 cupsd_printer_t
*p
; /* Printer in list */
810 if ((p
= cupsdFindDest(name
)) != NULL
&& (p
->type
& CUPS_PRINTER_CLASS
))
818 * 'cupsdLoadAllPrinters()' - Load printers from the printers.conf file.
822 cupsdLoadAllPrinters(void)
824 int i
; /* Looping var */
825 cups_file_t
*fp
; /* printers.conf file */
826 int linenum
; /* Current line number */
827 char line
[4096], /* Line from file */
828 *value
, /* Pointer to value */
829 *valueptr
; /* Pointer into value */
830 cupsd_printer_t
*p
; /* Current printer */
834 * Open the printers.conf file...
837 snprintf(line
, sizeof(line
), "%s/printers.conf", ServerRoot
);
838 if ((fp
= cupsdOpenConfFile(line
)) == NULL
)
842 * Read printer configurations until we hit EOF...
848 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
851 * Decode the directive...
854 if (!_cups_strcasecmp(line
, "<Printer") ||
855 !_cups_strcasecmp(line
, "<DefaultPrinter"))
858 * <Printer name> or <DefaultPrinter name>
861 if (p
== NULL
&& value
)
864 * Add the printer and a base file type...
867 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Loading printer %s...", value
);
869 p
= cupsdAddPrinter(value
);
871 p
->state
= IPP_PRINTER_IDLE
;
874 * Set the default printer as needed...
877 if (!_cups_strcasecmp(line
, "<DefaultPrinter"))
881 cupsdLogMessage(CUPSD_LOG_ERROR
,
882 "Syntax error on line %d of printers.conf.", linenum
);
884 else if (!_cups_strcasecmp(line
, "</Printer>"))
889 * Close out the current printer...
892 cupsdSetPrinterAttrs(p
);
894 if (strncmp(p
->device_uri
, "file:", 5) &&
895 p
->state
!= IPP_PRINTER_STOPPED
)
898 * See if the backend exists...
901 snprintf(line
, sizeof(line
), "%s/backend/%s", ServerBin
,
904 if ((valueptr
= strchr(line
+ strlen(ServerBin
), ':')) != NULL
)
905 *valueptr
= '\0'; /* Chop everything but URI scheme */
910 * Backend does not exist, stop printer...
913 p
->state
= IPP_PRINTER_STOPPED
;
914 snprintf(p
->state_message
, sizeof(p
->state_message
),
915 "Backend %s does not exist!", line
);
922 cupsdLogMessage(CUPSD_LOG_ERROR
,
923 "Syntax error on line %d of printers.conf.", linenum
);
927 cupsdLogMessage(CUPSD_LOG_ERROR
,
928 "Syntax error on line %d of printers.conf.", linenum
);
930 else if (!_cups_strcasecmp(line
, "UUID"))
932 if (value
&& !strncmp(value
, "urn:uuid:", 9))
933 cupsdSetString(&(p
->uuid
), value
);
935 cupsdLogMessage(CUPSD_LOG_ERROR
,
936 "Bad UUID on line %d of printers.conf.", linenum
);
938 else if (!_cups_strcasecmp(line
, "AuthInfoRequired"))
940 if (!cupsdSetAuthInfoRequired(p
, value
, NULL
))
941 cupsdLogMessage(CUPSD_LOG_ERROR
,
942 "Bad AuthInfoRequired on line %d of printers.conf.",
945 else if (!_cups_strcasecmp(line
, "Info"))
948 cupsdSetString(&p
->info
, value
);
950 else if (!_cups_strcasecmp(line
, "MakeModel"))
953 cupsdSetString(&p
->make_model
, value
);
955 else if (!_cups_strcasecmp(line
, "Location"))
958 cupsdSetString(&p
->location
, value
);
960 else if (!_cups_strcasecmp(line
, "DeviceURI"))
963 cupsdSetDeviceURI(p
, value
);
965 cupsdLogMessage(CUPSD_LOG_ERROR
,
966 "Syntax error on line %d of printers.conf.", linenum
);
968 else if (!_cups_strcasecmp(line
, "Option") && value
)
974 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
977 cupsdLogMessage(CUPSD_LOG_ERROR
,
978 "Syntax error on line %d of printers.conf.", linenum
);
981 for (; *valueptr
&& isspace(*valueptr
& 255); *valueptr
++ = '\0');
983 p
->num_options
= cupsAddOption(value
, valueptr
, p
->num_options
,
987 else if (!_cups_strcasecmp(line
, "PortMonitor"))
989 if (value
&& strcmp(value
, "none"))
990 cupsdSetString(&p
->port_monitor
, value
);
992 cupsdClearString(&p
->port_monitor
);
994 cupsdLogMessage(CUPSD_LOG_ERROR
,
995 "Syntax error on line %d of printers.conf.", linenum
);
997 else if (!_cups_strcasecmp(line
, "Reason"))
1000 strcmp(value
, "connecting-to-device") &&
1001 strcmp(value
, "cups-insecure-filter-warning") &&
1002 strcmp(value
, "cups-missing-filter-warning"))
1004 for (i
= 0 ; i
< p
->num_reasons
; i
++)
1005 if (!strcmp(value
, p
->reasons
[i
]))
1008 if (i
>= p
->num_reasons
&&
1009 p
->num_reasons
< (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
1011 p
->reasons
[p
->num_reasons
] = _cupsStrAlloc(value
);
1016 cupsdLogMessage(CUPSD_LOG_ERROR
,
1017 "Syntax error on line %d of printers.conf.", linenum
);
1019 else if (!_cups_strcasecmp(line
, "State"))
1022 * Set the initial queue state...
1025 if (value
&& !_cups_strcasecmp(value
, "idle"))
1026 p
->state
= IPP_PRINTER_IDLE
;
1027 else if (value
&& !_cups_strcasecmp(value
, "stopped"))
1029 p
->state
= IPP_PRINTER_STOPPED
;
1031 for (i
= 0 ; i
< p
->num_reasons
; i
++)
1032 if (!strcmp("paused", p
->reasons
[i
]))
1035 if (i
>= p
->num_reasons
&&
1036 p
->num_reasons
< (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
1038 p
->reasons
[p
->num_reasons
] = _cupsStrAlloc("paused");
1043 cupsdLogMessage(CUPSD_LOG_ERROR
,
1044 "Syntax error on line %d of printers.conf.", linenum
);
1046 else if (!_cups_strcasecmp(line
, "StateMessage"))
1049 * Set the initial queue state message...
1053 strlcpy(p
->state_message
, value
, sizeof(p
->state_message
));
1055 else if (!_cups_strcasecmp(line
, "StateTime"))
1058 * Set the state time...
1062 p
->state_time
= atoi(value
);
1064 else if (!_cups_strcasecmp(line
, "Accepting"))
1067 * Set the initial accepting state...
1071 (!_cups_strcasecmp(value
, "yes") ||
1072 !_cups_strcasecmp(value
, "on") ||
1073 !_cups_strcasecmp(value
, "true")))
1076 (!_cups_strcasecmp(value
, "no") ||
1077 !_cups_strcasecmp(value
, "off") ||
1078 !_cups_strcasecmp(value
, "false")))
1081 cupsdLogMessage(CUPSD_LOG_ERROR
,
1082 "Syntax error on line %d of printers.conf.", linenum
);
1084 else if (!_cups_strcasecmp(line
, "Type"))
1087 p
->type
= atoi(value
);
1089 cupsdLogMessage(CUPSD_LOG_ERROR
,
1090 "Syntax error on line %d of printers.conf.", linenum
);
1092 else if (!_cups_strcasecmp(line
, "Shared"))
1095 * Set the initial shared state...
1099 (!_cups_strcasecmp(value
, "yes") ||
1100 !_cups_strcasecmp(value
, "on") ||
1101 !_cups_strcasecmp(value
, "true")))
1104 (!_cups_strcasecmp(value
, "no") ||
1105 !_cups_strcasecmp(value
, "off") ||
1106 !_cups_strcasecmp(value
, "false")))
1109 cupsdLogMessage(CUPSD_LOG_ERROR
,
1110 "Syntax error on line %d of printers.conf.", linenum
);
1112 else if (!_cups_strcasecmp(line
, "JobSheets"))
1115 * Set the initial job sheets...
1120 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1125 cupsdSetString(&p
->job_sheets
[0], value
);
1127 while (isspace(*valueptr
& 255))
1132 for (value
= valueptr
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1137 cupsdSetString(&p
->job_sheets
[1], value
);
1141 cupsdLogMessage(CUPSD_LOG_ERROR
,
1142 "Syntax error on line %d of printers.conf.", linenum
);
1144 else if (!_cups_strcasecmp(line
, "AllowUser"))
1149 cupsdAddString(&(p
->users
), value
);
1152 cupsdLogMessage(CUPSD_LOG_ERROR
,
1153 "Syntax error on line %d of printers.conf.", linenum
);
1155 else if (!_cups_strcasecmp(line
, "DenyUser"))
1160 cupsdAddString(&(p
->users
), value
);
1163 cupsdLogMessage(CUPSD_LOG_ERROR
,
1164 "Syntax error on line %d of printers.conf.", linenum
);
1166 else if (!_cups_strcasecmp(line
, "QuotaPeriod"))
1169 p
->quota_period
= atoi(value
);
1171 cupsdLogMessage(CUPSD_LOG_ERROR
,
1172 "Syntax error on line %d of printers.conf.", linenum
);
1174 else if (!_cups_strcasecmp(line
, "PageLimit"))
1177 p
->page_limit
= atoi(value
);
1179 cupsdLogMessage(CUPSD_LOG_ERROR
,
1180 "Syntax error on line %d of printers.conf.", linenum
);
1182 else if (!_cups_strcasecmp(line
, "KLimit"))
1185 p
->k_limit
= atoi(value
);
1187 cupsdLogMessage(CUPSD_LOG_ERROR
,
1188 "Syntax error on line %d of printers.conf.", linenum
);
1190 else if (!_cups_strcasecmp(line
, "OpPolicy"))
1194 cupsd_policy_t
*pol
; /* Policy */
1197 if ((pol
= cupsdFindPolicy(value
)) != NULL
)
1199 cupsdSetString(&p
->op_policy
, value
);
1200 p
->op_policy_ptr
= pol
;
1203 cupsdLogMessage(CUPSD_LOG_ERROR
,
1204 "Bad policy \"%s\" on line %d of printers.conf",
1208 cupsdLogMessage(CUPSD_LOG_ERROR
,
1209 "Syntax error on line %d of printers.conf.", linenum
);
1211 else if (!_cups_strcasecmp(line
, "ErrorPolicy"))
1214 cupsdSetString(&p
->error_policy
, value
);
1216 cupsdLogMessage(CUPSD_LOG_ERROR
,
1217 "Syntax error on line %d of printers.conf.", linenum
);
1219 else if (!_cups_strcasecmp(line
, "Attribute") && value
)
1221 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1224 cupsdLogMessage(CUPSD_LOG_ERROR
,
1225 "Syntax error on line %d of printers.conf.", linenum
);
1228 for (; *valueptr
&& isspace(*valueptr
& 255); *valueptr
++ = '\0');
1231 cupsdSetPrinterAttrs(p
);
1233 if (!strcmp(value
, "marker-change-time"))
1234 p
->marker_time
= atoi(valueptr
);
1236 cupsdSetPrinterAttr(p
, value
, valueptr
);
1239 else if (_cups_strcasecmp(line
, "Filter") &&
1240 _cups_strcasecmp(line
, "Prefilter") &&
1241 _cups_strcasecmp(line
, "Product"))
1244 * Something else we don't understand (and that wasn't used in a prior
1245 * release of CUPS...
1248 cupsdLogMessage(CUPSD_LOG_ERROR
,
1249 "Unknown configuration directive %s on line %d of "
1250 "printers.conf.", line
, linenum
);
1259 * 'cupsdRenamePrinter()' - Rename a printer.
1264 cupsd_printer_t
*p
, /* I - Printer */
1265 const char *name
) /* I - New name */
1268 * Remove the printer from the array(s) first...
1271 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1272 "cupsdRenamePrinter: Removing %s from Printers", p
->name
);
1273 cupsArrayRemove(Printers
, p
);
1276 * Rename the printer type...
1279 mimeDeleteType(MimeDatabase
, p
->filetype
);
1280 p
->filetype
= mimeAddType(MimeDatabase
, "printer", name
);
1282 if (p
->prefiltertype
)
1284 mimeDeleteType(MimeDatabase
, p
->prefiltertype
);
1285 p
->prefiltertype
= mimeAddType(MimeDatabase
, "prefilter", name
);
1289 * Rename the printer...
1292 cupsdSetString(&p
->name
, name
);
1295 * Reset printer attributes...
1298 cupsdSetPrinterAttrs(p
);
1301 * Add the printer back to the printer array(s)...
1304 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1305 "cupsdRenamePrinter: Adding %s to Printers", p
->name
);
1306 cupsArrayAdd(Printers
, p
);
1311 * 'cupsdSaveAllPrinters()' - Save all printer definitions to the printers.conf
1316 cupsdSaveAllPrinters(void)
1318 int i
; /* Looping var */
1319 cups_file_t
*fp
; /* printers.conf file */
1320 char filename
[1024], /* printers.conf filename */
1321 temp
[1024], /* Temporary string */
1322 value
[2048], /* Value string */
1323 *ptr
, /* Pointer into value */
1324 *name
; /* Current user/group name */
1325 cupsd_printer_t
*printer
; /* Current printer class */
1326 time_t curtime
; /* Current time */
1327 struct tm
*curdate
; /* Current date */
1328 cups_option_t
*option
; /* Current option */
1329 ipp_attribute_t
*marker
; /* Current marker attribute */
1333 * Create the printers.conf file...
1336 snprintf(filename
, sizeof(filename
), "%s/printers.conf", ServerRoot
);
1338 if ((fp
= cupsdCreateConfFile(filename
, ConfigFilePerm
& 0600)) == NULL
)
1341 cupsdLogMessage(CUPSD_LOG_INFO
, "Saving printers.conf...");
1344 * Write a small header to the file...
1347 curtime
= time(NULL
);
1348 curdate
= localtime(&curtime
);
1349 strftime(temp
, sizeof(temp
) - 1, "%Y-%m-%d %H:%M", curdate
);
1351 cupsFilePuts(fp
, "# Printer configuration file for " CUPS_SVERSION
"\n");
1352 cupsFilePrintf(fp
, "# Written by cupsd on %s\n", temp
);
1353 cupsFilePuts(fp
, "# DO NOT EDIT THIS FILE WHEN CUPSD IS RUNNING\n");
1356 * Write each local printer known to the system...
1359 for (printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
1361 printer
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
1364 * Skip printer classes...
1367 if (printer
->type
& CUPS_PRINTER_CLASS
)
1371 * Write printers as needed...
1374 if (printer
== DefaultPrinter
)
1375 cupsFilePrintf(fp
, "<DefaultPrinter %s>\n", printer
->name
);
1377 cupsFilePrintf(fp
, "<Printer %s>\n", printer
->name
);
1379 cupsFilePrintf(fp
, "UUID %s\n", printer
->uuid
);
1381 if (printer
->num_auth_info_required
> 0)
1383 switch (printer
->num_auth_info_required
)
1386 strlcpy(value
, printer
->auth_info_required
[0], sizeof(value
));
1390 snprintf(value
, sizeof(value
), "%s,%s",
1391 printer
->auth_info_required
[0],
1392 printer
->auth_info_required
[1]);
1397 snprintf(value
, sizeof(value
), "%s,%s,%s",
1398 printer
->auth_info_required
[0],
1399 printer
->auth_info_required
[1],
1400 printer
->auth_info_required
[2]);
1404 cupsFilePutConf(fp
, "AuthInfoRequired", value
);
1408 cupsFilePutConf(fp
, "Info", printer
->info
);
1410 if (printer
->location
)
1411 cupsFilePutConf(fp
, "Location", printer
->location
);
1413 if (printer
->make_model
)
1414 cupsFilePutConf(fp
, "MakeModel", printer
->make_model
);
1416 cupsFilePutConf(fp
, "DeviceURI", printer
->device_uri
);
1418 if (printer
->port_monitor
)
1419 cupsFilePutConf(fp
, "PortMonitor", printer
->port_monitor
);
1421 if (printer
->state
== IPP_PRINTER_STOPPED
)
1423 cupsFilePuts(fp
, "State Stopped\n");
1425 if (printer
->state_message
)
1426 cupsFilePutConf(fp
, "StateMessage", printer
->state_message
);
1429 cupsFilePuts(fp
, "State Idle\n");
1431 cupsFilePrintf(fp
, "StateTime %d\n", (int)printer
->state_time
);
1433 for (i
= 0; i
< printer
->num_reasons
; i
++)
1434 if (strcmp(printer
->reasons
[i
], "connecting-to-device") &&
1435 strcmp(printer
->reasons
[i
], "cups-insecure-filter-warning") &&
1436 strcmp(printer
->reasons
[i
], "cups-missing-filter-warning"))
1437 cupsFilePutConf(fp
, "Reason", printer
->reasons
[i
]);
1439 cupsFilePrintf(fp
, "Type %d\n", printer
->type
);
1441 if (printer
->accepting
)
1442 cupsFilePuts(fp
, "Accepting Yes\n");
1444 cupsFilePuts(fp
, "Accepting No\n");
1446 if (printer
->shared
)
1447 cupsFilePuts(fp
, "Shared Yes\n");
1449 cupsFilePuts(fp
, "Shared No\n");
1451 snprintf(value
, sizeof(value
), "%s %s", printer
->job_sheets
[0],
1452 printer
->job_sheets
[1]);
1453 cupsFilePutConf(fp
, "JobSheets", value
);
1455 cupsFilePrintf(fp
, "QuotaPeriod %d\n", printer
->quota_period
);
1456 cupsFilePrintf(fp
, "PageLimit %d\n", printer
->page_limit
);
1457 cupsFilePrintf(fp
, "KLimit %d\n", printer
->k_limit
);
1459 for (name
= (char *)cupsArrayFirst(printer
->users
);
1461 name
= (char *)cupsArrayNext(printer
->users
))
1462 cupsFilePutConf(fp
, printer
->deny_users
? "DenyUser" : "AllowUser", name
);
1464 if (printer
->op_policy
)
1465 cupsFilePutConf(fp
, "OpPolicy", printer
->op_policy
);
1466 if (printer
->error_policy
)
1467 cupsFilePutConf(fp
, "ErrorPolicy", printer
->error_policy
);
1469 for (i
= printer
->num_options
, option
= printer
->options
;
1473 snprintf(value
, sizeof(value
), "%s %s", option
->name
, option
->value
);
1474 cupsFilePutConf(fp
, "Option", value
);
1477 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-colors",
1478 IPP_TAG_NAME
)) != NULL
)
1480 snprintf(value
, sizeof(value
), "%s ", marker
->name
);
1482 for (i
= 0, ptr
= value
+ strlen(value
);
1483 i
< marker
->num_values
&& ptr
< (value
+ sizeof(value
) - 1);
1489 strlcpy(ptr
, marker
->values
[i
].string
.text
,
1490 value
+ sizeof(value
) - ptr
);
1495 cupsFilePutConf(fp
, "Attribute", value
);
1498 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-levels",
1499 IPP_TAG_INTEGER
)) != NULL
)
1501 cupsFilePrintf(fp
, "Attribute %s %d", marker
->name
,
1502 marker
->values
[0].integer
);
1503 for (i
= 1; i
< marker
->num_values
; i
++)
1504 cupsFilePrintf(fp
, ",%d", marker
->values
[i
].integer
);
1505 cupsFilePuts(fp
, "\n");
1508 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-low-levels",
1509 IPP_TAG_INTEGER
)) != NULL
)
1511 cupsFilePrintf(fp
, "Attribute %s %d", marker
->name
,
1512 marker
->values
[0].integer
);
1513 for (i
= 1; i
< marker
->num_values
; i
++)
1514 cupsFilePrintf(fp
, ",%d", marker
->values
[i
].integer
);
1515 cupsFilePuts(fp
, "\n");
1518 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-high-levels",
1519 IPP_TAG_INTEGER
)) != NULL
)
1521 cupsFilePrintf(fp
, "Attribute %s %d", marker
->name
,
1522 marker
->values
[0].integer
);
1523 for (i
= 1; i
< marker
->num_values
; i
++)
1524 cupsFilePrintf(fp
, ",%d", marker
->values
[i
].integer
);
1525 cupsFilePuts(fp
, "\n");
1528 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-message",
1529 IPP_TAG_TEXT
)) != NULL
)
1531 snprintf(value
, sizeof(value
), "%s %s", marker
->name
,
1532 marker
->values
[0].string
.text
);
1534 cupsFilePutConf(fp
, "Attribute", value
);
1537 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-names",
1538 IPP_TAG_NAME
)) != NULL
)
1540 snprintf(value
, sizeof(value
), "%s ", marker
->name
);
1542 for (i
= 0, ptr
= value
+ strlen(value
);
1543 i
< marker
->num_values
&& ptr
< (value
+ sizeof(value
) - 1);
1549 strlcpy(ptr
, marker
->values
[i
].string
.text
,
1550 value
+ sizeof(value
) - ptr
);
1555 cupsFilePutConf(fp
, "Attribute", value
);
1558 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-types",
1559 IPP_TAG_KEYWORD
)) != NULL
)
1561 snprintf(value
, sizeof(value
), "%s ", marker
->name
);
1563 for (i
= 0, ptr
= value
+ strlen(value
);
1564 i
< marker
->num_values
&& ptr
< (value
+ sizeof(value
) - 1);
1570 strlcpy(ptr
, marker
->values
[i
].string
.text
,
1571 value
+ sizeof(value
) - ptr
);
1576 cupsFilePutConf(fp
, "Attribute", value
);
1579 if (printer
->marker_time
)
1580 cupsFilePrintf(fp
, "Attribute marker-change-time %ld\n",
1581 (long)printer
->marker_time
);
1583 cupsFilePuts(fp
, "</Printer>\n");
1586 cupsdCloseCreatedConfFile(fp
, filename
);
1591 * 'cupsdSetAuthInfoRequired()' - Set the required authentication info.
1594 int /* O - 1 if value OK, 0 otherwise */
1595 cupsdSetAuthInfoRequired(
1596 cupsd_printer_t
*p
, /* I - Printer */
1597 const char *values
, /* I - Plain text value (or NULL) */
1598 ipp_attribute_t
*attr
) /* I - IPP attribute value (or NULL) */
1600 int i
; /* Looping var */
1603 p
->num_auth_info_required
= 0;
1606 * Do we have a plain text value?
1612 * Yes, grab the keywords...
1615 const char *end
; /* End of current value */
1618 while (*values
&& p
->num_auth_info_required
< 4)
1620 if ((end
= strchr(values
, ',')) == NULL
)
1621 end
= values
+ strlen(values
);
1623 if ((end
- values
) == 4 && !strncmp(values
, "none", 4))
1625 if (p
->num_auth_info_required
!= 0 || *end
)
1628 p
->auth_info_required
[p
->num_auth_info_required
] = "none";
1629 p
->num_auth_info_required
++;
1633 else if ((end
- values
) == 9 && !strncmp(values
, "negotiate", 9))
1635 if (p
->num_auth_info_required
!= 0 || *end
)
1638 p
->auth_info_required
[p
->num_auth_info_required
] = "negotiate";
1639 p
->num_auth_info_required
++;
1642 * Don't allow sharing of queues that require Kerberos authentication.
1647 cupsdDeregisterPrinter(p
, 1);
1651 else if ((end
- values
) == 6 && !strncmp(values
, "domain", 6))
1653 p
->auth_info_required
[p
->num_auth_info_required
] = "domain";
1654 p
->num_auth_info_required
++;
1656 else if ((end
- values
) == 8 && !strncmp(values
, "password", 8))
1658 p
->auth_info_required
[p
->num_auth_info_required
] = "password";
1659 p
->num_auth_info_required
++;
1661 else if ((end
- values
) == 8 && !strncmp(values
, "username", 8))
1663 p
->auth_info_required
[p
->num_auth_info_required
] = "username";
1664 p
->num_auth_info_required
++;
1669 values
= (*end
) ? end
+ 1 : end
;
1672 if (p
->num_auth_info_required
== 0)
1674 p
->auth_info_required
[0] = "none";
1675 p
->num_auth_info_required
= 1;
1679 * Update the printer-type value as needed...
1682 if (p
->num_auth_info_required
> 1 ||
1683 strcmp(p
->auth_info_required
[0], "none"))
1684 p
->type
|= CUPS_PRINTER_AUTHENTICATED
;
1686 p
->type
&= ~CUPS_PRINTER_AUTHENTICATED
;
1692 * Grab values from an attribute instead...
1695 if (!attr
|| attr
->num_values
> 4)
1698 for (i
= 0; i
< attr
->num_values
; i
++)
1700 if (!strcmp(attr
->values
[i
].string
.text
, "none"))
1702 if (p
->num_auth_info_required
!= 0 || attr
->num_values
!= 1)
1705 p
->auth_info_required
[p
->num_auth_info_required
] = "none";
1706 p
->num_auth_info_required
++;
1710 else if (!strcmp(attr
->values
[i
].string
.text
, "negotiate"))
1712 if (p
->num_auth_info_required
!= 0 || attr
->num_values
!= 1)
1715 p
->auth_info_required
[p
->num_auth_info_required
] = "negotiate";
1716 p
->num_auth_info_required
++;
1719 * Don't allow sharing of queues that require Kerberos authentication.
1724 cupsdDeregisterPrinter(p
, 1);
1730 else if (!strcmp(attr
->values
[i
].string
.text
, "domain"))
1732 p
->auth_info_required
[p
->num_auth_info_required
] = "domain";
1733 p
->num_auth_info_required
++;
1735 else if (!strcmp(attr
->values
[i
].string
.text
, "password"))
1737 p
->auth_info_required
[p
->num_auth_info_required
] = "password";
1738 p
->num_auth_info_required
++;
1740 else if (!strcmp(attr
->values
[i
].string
.text
, "username"))
1742 p
->auth_info_required
[p
->num_auth_info_required
] = "username";
1743 p
->num_auth_info_required
++;
1754 * 'cupsdSetDeviceURI()' - Set the device URI for a printer.
1758 cupsdSetDeviceURI(cupsd_printer_t
*p
, /* I - Printer */
1759 const char *uri
) /* I - Device URI */
1761 char buffer
[1024], /* URI buffer */
1762 *start
, /* Start of data after scheme */
1763 *slash
, /* First slash after scheme:// */
1764 *ptr
; /* Pointer into user@host:port part */
1768 * Set the full device URI..
1771 cupsdSetString(&(p
->device_uri
), uri
);
1774 * Copy the device URI to a temporary buffer so we can sanitize any auth
1778 strlcpy(buffer
, uri
, sizeof(buffer
));
1781 * Find the end of the scheme:// part...
1784 if ((ptr
= strchr(buffer
, ':')) != NULL
)
1786 for (start
= ptr
+ 1; *start
; start
++)
1791 * Find the next slash (/) in the URI...
1794 if ((slash
= strchr(start
, '/')) == NULL
)
1795 slash
= start
+ strlen(start
); /* No slash, point to the end */
1798 * Check for an @ sign before the slash...
1801 if ((ptr
= strchr(start
, '@')) != NULL
&& ptr
< slash
)
1804 * Found an @ sign and it is before the resource part, so we have
1805 * an authentication string. Copy the remaining URI over the
1806 * authentication string...
1809 _cups_strcpy(start
, ptr
+ 1);
1814 * Save the sanitized URI...
1817 cupsdSetString(&(p
->sanitized_device_uri
), buffer
);
1822 * 'cupsdSetPrinterAttr()' - Set a printer attribute.
1826 cupsdSetPrinterAttr(
1827 cupsd_printer_t
*p
, /* I - Printer */
1828 const char *name
, /* I - Attribute name */
1829 const char *value
) /* I - Attribute value string */
1831 ipp_attribute_t
*attr
; /* Attribute */
1832 int i
, /* Looping var */
1833 count
; /* Number of values */
1834 char *temp
, /* Temporary copy of value string */
1835 *ptr
, /* Pointer into value */
1836 *start
, /* Start of value */
1837 quote
; /* Quote character */
1838 ipp_tag_t value_tag
; /* Value tag for this attribute */
1842 * Don't allow empty values...
1845 if (!*value
&& strcmp(name
, "marker-message"))
1847 cupsdLogMessage(CUPSD_LOG_ERROR
, "Ignoring empty \"%s\" attribute", name
);
1852 * Copy the value string so we can do what we want with it...
1855 if ((temp
= strdup(value
)) == NULL
)
1857 cupsdLogMessage(CUPSD_LOG_ERROR
,
1858 "Unable to duplicate value for \"%s\" attribute.", name
);
1863 * Count the number of values...
1866 for (count
= 1, quote
= '\0', ptr
= temp
;
1874 else if (*ptr
== '\\' && ptr
[1])
1876 else if (*ptr
== '\'' || *ptr
== '\"')
1878 else if (*ptr
== ',')
1883 * Then add or update the attribute as needed...
1886 if (!strcmp(name
, "marker-levels") || !strcmp(name
, "marker-low-levels") ||
1887 !strcmp(name
, "marker-high-levels"))
1893 if ((attr
= ippFindAttribute(p
->attrs
, name
, IPP_TAG_INTEGER
)) != NULL
&&
1894 attr
->num_values
< count
)
1896 ippDeleteAttribute(p
->attrs
, attr
);
1901 attr
->num_values
= count
;
1903 attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
, name
,
1909 cupsdLogMessage(CUPSD_LOG_ERROR
,
1910 "Unable to allocate memory for printer attribute "
1911 "(%d values)", count
);
1915 for (i
= 0, start
= temp
; i
< count
; i
++)
1917 if ((ptr
= strchr(start
, ',')) != NULL
)
1920 attr
->values
[i
].integer
= strtol(start
, NULL
, 10);
1929 * Name or keyword values...
1932 if (!strcmp(name
, "marker-types"))
1933 value_tag
= IPP_TAG_KEYWORD
;
1934 else if (!strcmp(name
, "marker-message"))
1935 value_tag
= IPP_TAG_TEXT
;
1937 value_tag
= IPP_TAG_NAME
;
1939 if ((attr
= ippFindAttribute(p
->attrs
, name
, value_tag
)) != NULL
&&
1940 attr
->num_values
< count
)
1942 ippDeleteAttribute(p
->attrs
, attr
);
1948 for (i
= 0; i
< attr
->num_values
; i
++)
1949 _cupsStrFree(attr
->values
[i
].string
.text
);
1951 attr
->num_values
= count
;
1954 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, value_tag
, name
,
1960 cupsdLogMessage(CUPSD_LOG_ERROR
,
1961 "Unable to allocate memory for printer attribute "
1962 "(%d values)", count
);
1966 for (i
= 0, quote
= '\0', ptr
= temp
; i
< count
; i
++)
1968 for (start
= ptr
; *ptr
; ptr
++)
1971 *ptr
= quote
= '\0';
1974 else if (*ptr
== '\\' && ptr
[1])
1975 _cups_strcpy(ptr
, ptr
+ 1);
1976 else if (*ptr
== '\'' || *ptr
== '\"')
1983 _cups_strcpy(ptr
, ptr
+ 1);
1985 else if (*ptr
== ',')
1992 attr
->values
[i
].string
.text
= _cupsStrAlloc(start
);
2001 * 'cupsdSetPrinterAttrs()' - Set printer attributes based upon the PPD file.
2005 cupsdSetPrinterAttrs(cupsd_printer_t
*p
)/* I - Printer to setup */
2007 int i
; /* Looping var */
2008 char resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
2009 cupsd_location_t
*auth
; /* Pointer to authentication element */
2010 const char *auth_supported
; /* Authentication supported */
2011 ipp_t
*oldattrs
; /* Old printer attributes */
2012 ipp_attribute_t
*attr
; /* Attribute data */
2013 char *name
, /* Current user/group name */
2014 *filter
; /* Current filter */
2017 DEBUG_printf(("cupsdSetPrinterAttrs: entering name = %s, type = %x\n", p
->name
,
2021 * Make sure that we have the common attributes defined...
2025 cupsdCreateCommonData();
2028 * Clear out old filters, if any...
2031 delete_printer_filters(p
);
2034 * Figure out the authentication that is required for the printer.
2037 auth_supported
= "requesting-user-name";
2039 if (p
->type
& CUPS_PRINTER_CLASS
)
2040 snprintf(resource
, sizeof(resource
), "/classes/%s", p
->name
);
2042 snprintf(resource
, sizeof(resource
), "/printers/%s", p
->name
);
2044 if ((auth
= cupsdFindBest(resource
, HTTP_POST
)) == NULL
||
2045 auth
->type
== CUPSD_AUTH_NONE
)
2046 auth
= cupsdFindPolicyOp(p
->op_policy_ptr
, IPP_PRINT_JOB
);
2050 int auth_type
; /* Authentication type */
2053 if ((auth_type
= auth
->type
) == CUPSD_AUTH_DEFAULT
)
2054 auth_type
= cupsdDefaultAuthType();
2056 if (auth_type
== CUPSD_AUTH_BASIC
|| auth_type
== CUPSD_AUTH_BASICDIGEST
)
2057 auth_supported
= "basic";
2058 else if (auth_type
== CUPSD_AUTH_DIGEST
)
2059 auth_supported
= "digest";
2061 else if (auth_type
== CUPSD_AUTH_NEGOTIATE
)
2062 auth_supported
= "negotiate";
2063 #endif /* HAVE_GSSAPI */
2065 if (auth_type
!= CUPSD_AUTH_NONE
)
2066 p
->type
|= CUPS_PRINTER_AUTHENTICATED
;
2068 p
->type
&= ~CUPS_PRINTER_AUTHENTICATED
;
2071 p
->type
&= ~CUPS_PRINTER_AUTHENTICATED
;
2074 * Create the required IPP attributes for a printer...
2077 oldattrs
= p
->attrs
;
2078 p
->attrs
= ippNew();
2080 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2081 "uri-authentication-supported", NULL
, auth_supported
);
2082 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2083 "uri-security-supported", NULL
, "none");
2084 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
, "printer-name", NULL
,
2086 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-location",
2087 NULL
, p
->location
? p
->location
: "");
2088 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-info",
2089 NULL
, p
->info
? p
->info
: "");
2090 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "printer-uuid", NULL
,
2093 if (cupsArrayCount(p
->users
) > 0)
2096 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2097 "requesting-user-name-denied",
2098 cupsArrayCount(p
->users
), NULL
, NULL
);
2100 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2101 "requesting-user-name-allowed",
2102 cupsArrayCount(p
->users
), NULL
, NULL
);
2104 for (i
= 0, name
= (char *)cupsArrayFirst(p
->users
);
2106 i
++, name
= (char *)cupsArrayNext(p
->users
))
2107 attr
->values
[i
].string
.text
= _cupsStrAlloc(name
);
2110 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2111 "job-quota-period", p
->quota_period
);
2112 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2113 "job-k-limit", p
->k_limit
);
2114 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2115 "job-page-limit", p
->page_limit
);
2116 if (p
->num_auth_info_required
> 0 && strcmp(p
->auth_info_required
[0], "none"))
2117 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2118 "auth-info-required", p
->num_auth_info_required
, NULL
,
2119 p
->auth_info_required
);
2121 if (cupsArrayCount(Banners
) > 0)
2124 * Setup the job-sheets-default attribute...
2127 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2128 "job-sheets-default", 2, NULL
, NULL
);
2132 attr
->values
[0].string
.text
= _cupsStrAlloc(Classification
?
2133 Classification
: p
->job_sheets
[0]);
2134 attr
->values
[1].string
.text
= _cupsStrAlloc(Classification
?
2135 Classification
: p
->job_sheets
[1]);
2143 * Assign additional attributes depending on whether this is a printer
2147 if (p
->type
& CUPS_PRINTER_CLASS
)
2150 p
->type
&= ~CUPS_PRINTER_OPTIONS
;
2153 * Add class-specific attributes...
2156 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
2157 "printer-make-and-model", NULL
, "Local Printer Class");
2158 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "device-uri", NULL
,
2159 "file:///dev/null");
2161 if (p
->num_printers
> 0)
2164 * Add a list of member names; URIs are added in copy_printer_attrs...
2167 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2168 "member-names", p
->num_printers
, NULL
, NULL
);
2169 p
->type
|= CUPS_PRINTER_OPTIONS
;
2171 for (i
= 0; i
< p
->num_printers
; i
++)
2174 attr
->values
[i
].string
.text
= _cupsStrAlloc(p
->printers
[i
]->name
);
2176 p
->type
&= ~CUPS_PRINTER_OPTIONS
| p
->printers
[i
]->type
;
2183 * Add printer-specific attributes...
2186 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "device-uri", NULL
,
2187 p
->sanitized_device_uri
);
2190 * Assign additional attributes from the PPD file (if any)...
2196 * Add filters for printer...
2199 cupsdSetPrinterReasons(p
, "-cups-missing-filter-warning,"
2200 "cups-insecure-filter-warning");
2202 if (p
->pc
&& p
->pc
->filters
)
2204 for (filter
= (char *)cupsArrayFirst(p
->pc
->filters
);
2206 filter
= (char *)cupsArrayNext(p
->pc
->filters
))
2207 add_printer_filter(p
, p
->filetype
, filter
);
2209 else if (!(p
->type
& CUPS_PRINTER_REMOTE
))
2211 char interface
[1024]; /* Interface script */
2214 snprintf(interface
, sizeof(interface
), "%s/interfaces/%s", ServerRoot
,
2216 if (!access(interface
, X_OK
))
2219 * Yes, we have a System V style interface script; use it!
2222 snprintf(interface
, sizeof(interface
), "*/* 0 %s/interfaces/%s",
2223 ServerRoot
, p
->name
);
2224 add_printer_filter(p
, p
->filetype
, interface
);
2229 * Add a filter from application/vnd.cups-raw to printer/name to
2230 * handle "raw" printing by users.
2233 add_printer_filter(p
, p
->filetype
, "application/vnd.cups-raw 0 -");
2236 * Add a PostScript filter, since this is still possibly PS printer.
2239 add_printer_filter(p
, p
->filetype
,
2240 "application/vnd.cups-postscript 0 -");
2244 if (p
->pc
&& p
->pc
->prefilters
)
2246 if (!p
->prefiltertype
)
2247 p
->prefiltertype
= mimeAddType(MimeDatabase
, "prefilter", p
->name
);
2249 for (filter
= (char *)cupsArrayFirst(p
->pc
->prefilters
);
2251 filter
= (char *)cupsArrayNext(p
->pc
->prefilters
))
2252 add_printer_filter(p
, p
->prefiltertype
, filter
);
2257 * Copy marker attributes as needed...
2262 ipp_attribute_t
*oldattr
; /* Old attribute */
2265 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-colors",
2266 IPP_TAG_NAME
)) != NULL
)
2268 if ((attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2269 "marker-colors", oldattr
->num_values
, NULL
,
2272 for (i
= 0; i
< oldattr
->num_values
; i
++)
2273 attr
->values
[i
].string
.text
=
2274 _cupsStrAlloc(oldattr
->values
[i
].string
.text
);
2278 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-levels",
2279 IPP_TAG_INTEGER
)) != NULL
)
2281 if ((attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2282 "marker-levels", oldattr
->num_values
,
2285 for (i
= 0; i
< oldattr
->num_values
; i
++)
2286 attr
->values
[i
].integer
= oldattr
->values
[i
].integer
;
2290 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-message",
2291 IPP_TAG_TEXT
)) != NULL
)
2292 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "marker-message",
2293 NULL
, oldattr
->values
[0].string
.text
);
2295 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-low-levels",
2296 IPP_TAG_INTEGER
)) != NULL
)
2298 if ((attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2299 "marker-low-levels", oldattr
->num_values
,
2302 for (i
= 0; i
< oldattr
->num_values
; i
++)
2303 attr
->values
[i
].integer
= oldattr
->values
[i
].integer
;
2307 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-high-levels",
2308 IPP_TAG_INTEGER
)) != NULL
)
2310 if ((attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2311 "marker-high-levels", oldattr
->num_values
,
2314 for (i
= 0; i
< oldattr
->num_values
; i
++)
2315 attr
->values
[i
].integer
= oldattr
->values
[i
].integer
;
2319 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-names",
2320 IPP_TAG_NAME
)) != NULL
)
2322 if ((attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2323 "marker-names", oldattr
->num_values
, NULL
,
2326 for (i
= 0; i
< oldattr
->num_values
; i
++)
2327 attr
->values
[i
].string
.text
=
2328 _cupsStrAlloc(oldattr
->values
[i
].string
.text
);
2332 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-types",
2333 IPP_TAG_KEYWORD
)) != NULL
)
2335 if ((attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2336 "marker-types", oldattr
->num_values
, NULL
,
2339 for (i
= 0; i
< oldattr
->num_values
; i
++)
2340 attr
->values
[i
].string
.text
=
2341 _cupsStrAlloc(oldattr
->values
[i
].string
.text
);
2345 ippDelete(oldattrs
);
2349 * Force sharing off for remote queues...
2352 if (p
->type
& CUPS_PRINTER_REMOTE
)
2356 * Populate the document-format-supported attribute...
2359 add_printer_formats(p
);
2361 DEBUG_printf(("cupsdSetPrinterAttrs: leaving name = %s, type = %x\n", p
->name
,
2365 * Add name-default attributes...
2368 add_printer_defaults(p
);
2371 * Let the browse protocols reflect the change
2374 cupsdRegisterPrinter(p
);
2379 * 'cupsdSetPrinterReasons()' - Set/update the reasons strings.
2382 int /* O - 1 if something changed, 0 otherwise */
2383 cupsdSetPrinterReasons(
2384 cupsd_printer_t
*p
, /* I - Printer */
2385 const char *s
) /* I - Reasons strings */
2387 int i
, /* Looping var */
2388 changed
= 0; /* Did something change? */
2389 const char *sptr
; /* Pointer into reasons */
2390 char reason
[255], /* Reason string */
2391 *rptr
; /* Pointer into reason */
2394 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
2395 "cupsdSetPrinterReasons(p=%p(%s),s=\"%s\"", p
, p
->name
, s
);
2397 if (s
[0] == '-' || s
[0] == '+')
2400 * Add/remove reasons...
2408 * Replace reasons...
2413 for (i
= 0; i
< p
->num_reasons
; i
++)
2414 _cupsStrFree(p
->reasons
[i
]);
2422 if (!strcmp(s
, "none"))
2426 * Loop through all of the reasons...
2432 * Skip leading whitespace and commas...
2435 while (isspace(*sptr
& 255) || *sptr
== ',')
2438 for (rptr
= reason
; *sptr
&& !isspace(*sptr
& 255) && *sptr
!= ','; sptr
++)
2439 if (rptr
< (reason
+ sizeof(reason
) - 1))
2453 for (i
= 0; i
< p
->num_reasons
; i
++)
2454 if (!strcmp(reason
, p
->reasons
[i
]))
2457 * Found a match, so remove it...
2462 _cupsStrFree(p
->reasons
[i
]);
2464 if (i
< p
->num_reasons
)
2465 memmove(p
->reasons
+ i
, p
->reasons
+ i
+ 1,
2466 (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
, "connecting-to-device"))
2476 else if (p
->num_reasons
< (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
2482 for (i
= 0; i
< p
->num_reasons
; i
++)
2483 if (!strcmp(reason
, p
->reasons
[i
]))
2486 if (i
>= p
->num_reasons
)
2488 if (i
>= (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
2490 cupsdLogMessage(CUPSD_LOG_ALERT
,
2491 "Too many printer-state-reasons values for %s (%d)",
2496 p
->reasons
[i
] = _cupsStrAlloc(reason
);
2500 if (!strcmp(reason
, "paused") && p
->state
!= IPP_PRINTER_STOPPED
)
2501 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, 1);
2503 if (strcmp(reason
, "connecting-to-device"))
2514 * 'cupsdSetPrinterState()' - Update the current state of a printer.
2518 cupsdSetPrinterState(
2519 cupsd_printer_t
*p
, /* I - Printer to change */
2520 ipp_pstate_t s
, /* I - New state */
2521 int update
) /* I - Update printers.conf? */
2523 cupsd_job_t
*job
; /* Current job */
2524 ipp_pstate_t old_state
; /* Old printer state */
2525 static const char * const printer_states
[] =
2526 { /* State strings */
2534 * Set the new state...
2537 old_state
= p
->state
;
2542 cupsdAddEvent(s
== IPP_PRINTER_STOPPED
? CUPSD_EVENT_PRINTER_STOPPED
:
2543 CUPSD_EVENT_PRINTER_STATE
, p
, NULL
,
2544 "%s \"%s\" state changed to %s.",
2545 (p
->type
& CUPS_PRINTER_CLASS
) ? "Class" : "Printer",
2546 p
->name
, printer_states
[p
->state
- IPP_PRINTER_IDLE
]);
2549 * Let the browse code know this needs to be updated...
2552 p
->state_time
= time(NULL
);
2556 * Set/clear the paused reason as needed...
2559 if (s
== IPP_PRINTER_STOPPED
)
2560 cupsdSetPrinterReasons(p
, "+paused");
2562 cupsdSetPrinterReasons(p
, "-paused");
2566 for (job
= (cupsd_job_t
*)cupsArrayFirst(ActiveJobs
);
2568 job
= (cupsd_job_t
*)cupsArrayNext(ActiveJobs
))
2569 if (job
->reasons
&& job
->state_value
== IPP_JOB_PENDING
&&
2570 !_cups_strcasecmp(job
->dest
, p
->name
))
2571 ippSetString(job
->attrs
, &job
->reasons
, 0,
2572 s
== IPP_PRINTER_STOPPED
? "printer-stopped" : "none");
2576 * Clear the message for the queue when going to processing...
2579 if (s
== IPP_PRINTER_PROCESSING
)
2580 p
->state_message
[0] = '\0';
2583 * Let the browse protocols reflect the change...
2587 cupsdRegisterPrinter(p
);
2590 * Save the printer configuration if a printer goes from idle or processing
2591 * to stopped (or visa-versa)...
2595 (old_state
== IPP_PRINTER_STOPPED
) != (s
== IPP_PRINTER_STOPPED
))
2601 * 'cupsdStopPrinter()' - Stop a printer from printing any jobs...
2605 cupsdStopPrinter(cupsd_printer_t
*p
, /* I - Printer to stop */
2606 int update
)/* I - Update printers.conf? */
2609 * Set the printer state...
2612 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, update
);
2615 * See if we have a job printing on this printer...
2618 if (p
->job
&& p
->job
->state_value
== IPP_JOB_PROCESSING
)
2619 cupsdSetJobState(p
->job
, IPP_JOB_PENDING
, CUPSD_JOB_DEFAULT
,
2620 "Job stopped due to printer being paused.");
2625 * 'cupsdUpdatePrinterPPD()' - Update keywords in a printer's PPD file.
2628 int /* O - 1 if successful, 0 otherwise */
2629 cupsdUpdatePrinterPPD(
2630 cupsd_printer_t
*p
, /* I - Printer */
2631 int num_keywords
, /* I - Number of keywords */
2632 cups_option_t
*keywords
) /* I - Keywords */
2634 int i
; /* Looping var */
2635 cups_file_t
*src
, /* Original file */
2636 *dst
; /* New file */
2637 char srcfile
[1024], /* Original filename */
2638 dstfile
[1024], /* New filename */
2639 line
[1024], /* Line from file */
2640 keystring
[41]; /* Keyword from line */
2641 cups_option_t
*keyword
; /* Current keyword */
2644 cupsdLogMessage(CUPSD_LOG_INFO
, "Updating keywords in PPD file for %s...",
2648 * Get the old and new PPD filenames...
2651 snprintf(srcfile
, sizeof(srcfile
), "%s/ppd/%s.ppd.O", ServerRoot
, p
->name
);
2652 snprintf(dstfile
, sizeof(srcfile
), "%s/ppd/%s.ppd", ServerRoot
, p
->name
);
2655 * Rename the old file and open the old and new...
2658 if (rename(dstfile
, srcfile
))
2660 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to backup PPD file for %s: %s",
2661 p
->name
, strerror(errno
));
2665 if ((src
= cupsFileOpen(srcfile
, "r")) == NULL
)
2667 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to open PPD file \"%s\": %s",
2668 srcfile
, strerror(errno
));
2669 rename(srcfile
, dstfile
);
2673 if ((dst
= cupsFileOpen(dstfile
, "w")) == NULL
)
2675 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to create PPD file \"%s\": %s",
2676 dstfile
, strerror(errno
));
2678 rename(srcfile
, dstfile
);
2683 * Copy the first line and then write out all of the keywords...
2686 if (!cupsFileGets(src
, line
, sizeof(line
)))
2688 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to read PPD file \"%s\": %s",
2689 srcfile
, strerror(errno
));
2692 rename(srcfile
, dstfile
);
2696 cupsFilePrintf(dst
, "%s\n", line
);
2698 for (i
= num_keywords
, keyword
= keywords
; i
> 0; i
--, keyword
++)
2700 cupsdLogMessage(CUPSD_LOG_DEBUG
, "*%s: %s", keyword
->name
, keyword
->value
);
2701 cupsFilePrintf(dst
, "*%s: %s\n", keyword
->name
, keyword
->value
);
2705 * Then copy the rest of the PPD file, dropping any keywords we changed.
2708 while (cupsFileGets(src
, line
, sizeof(line
)))
2711 * Skip keywords we've already set...
2714 if (sscanf(line
, "*%40[^:]:", keystring
) == 1 &&
2715 cupsGetOption(keystring
, num_keywords
, keywords
))
2719 * Otherwise write the line...
2722 cupsFilePrintf(dst
, "%s\n", line
);
2726 * Close files and return...
2737 * 'cupsdUpdatePrinters()' - Update printers after a partial reload.
2741 cupsdUpdatePrinters(void)
2743 cupsd_printer_t
*p
; /* Current printer */
2747 * Loop through the printers and recreate the printer attributes
2748 * for any local printers since the policy and/or access control
2749 * stuff may have changed. Also, if browsing is disabled, remove
2750 * any remote printers...
2753 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
2755 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
2758 * Update the operation policy pointer...
2761 if ((p
->op_policy_ptr
= cupsdFindPolicy(p
->op_policy
)) == NULL
)
2762 p
->op_policy_ptr
= DefaultPolicyPtr
;
2765 * Update printer attributes...
2768 cupsdSetPrinterAttrs(p
);
2774 * 'cupsdValidateDest()' - Validate a printer/class destination.
2777 const char * /* O - Printer or class name */
2779 const char *uri
, /* I - Printer URI */
2780 cups_ptype_t
*dtype
, /* O - Type (printer or class) */
2781 cupsd_printer_t
**printer
) /* O - Printer pointer */
2783 cupsd_printer_t
*p
; /* Current printer */
2784 char localname
[1024],/* Localized hostname */
2785 *lptr
, /* Pointer into localized hostname */
2786 *sptr
, /* Pointer into server name */
2787 *rptr
, /* Pointer into resource */
2788 scheme
[32], /* Scheme portion of URI */
2789 username
[64], /* Username portion of URI */
2790 hostname
[HTTP_MAX_HOST
],
2791 /* Host portion of URI */
2792 resource
[HTTP_MAX_URI
];
2793 /* Resource portion of URI */
2794 int port
; /* Port portion of URI */
2797 DEBUG_printf(("cupsdValidateDest(uri=\"%s\", dtype=%p, printer=%p)\n", uri
,
2801 * Initialize return values...
2808 *dtype
= (cups_ptype_t
)0;
2811 * Pull the hostname and resource from the URI...
2814 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
, scheme
, sizeof(scheme
),
2815 username
, sizeof(username
), hostname
, sizeof(hostname
),
2816 &port
, resource
, sizeof(resource
));
2819 * See if the resource is a class or printer...
2822 if (!strncmp(resource
, "/classes/", 9))
2828 rptr
= resource
+ 9;
2830 else if (!strncmp(resource
, "/printers/", 10))
2836 rptr
= resource
+ 10;
2841 * Bad resource name...
2848 * See if the printer or class name exists...
2851 p
= cupsdFindDest(rptr
);
2853 if (p
== NULL
&& strchr(rptr
, '@') == NULL
)
2861 *dtype
= p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_REMOTE
);
2867 * Change localhost to the server name...
2870 if (!_cups_strcasecmp(hostname
, "localhost"))
2871 strlcpy(hostname
, ServerName
, sizeof(hostname
));
2873 strlcpy(localname
, hostname
, sizeof(localname
));
2875 if (!_cups_strcasecmp(hostname
, ServerName
))
2878 * Localize the hostname...
2881 lptr
= strchr(localname
, '.');
2882 sptr
= strchr(ServerName
, '.');
2884 if (sptr
!= NULL
&& lptr
!= NULL
)
2887 * Strip the common domain name components...
2890 while (lptr
!= NULL
)
2892 if (!_cups_strcasecmp(lptr
, sptr
))
2898 lptr
= strchr(lptr
+ 1, '.');
2903 DEBUG_printf(("localized hostname is \"%s\"...\n", localname
));
2906 * Find a matching printer or class...
2909 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
2911 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
2912 if (!_cups_strcasecmp(p
->hostname
, localname
) &&
2913 !_cups_strcasecmp(p
->name
, rptr
))
2919 *dtype
= p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_REMOTE
);
2929 * 'cupsdWritePrintcap()' - Write a pseudo-printcap file for older applications
2934 cupsdWritePrintcap(void)
2936 int i
; /* Looping var */
2937 cups_file_t
*fp
; /* Printcap file */
2938 cupsd_printer_t
*p
; /* Current printer */
2942 * See if we have a printcap file; if not, don't bother writing it.
2945 if (!Printcap
|| !*Printcap
)
2948 cupsdLogMessage(CUPSD_LOG_INFO
, "Generating printcap %s...", Printcap
);
2951 * Open the printcap file...
2954 if ((fp
= cupsFileOpen(Printcap
, "w")) == NULL
)
2958 * Put a comment header at the top so that users will know where the
2959 * data has come from...
2962 if (PrintcapFormat
!= PRINTCAP_PLIST
)
2963 cupsFilePrintf(fp
, "# This file was automatically generated by cupsd(8) "
2965 "# %s/printers.conf file. All changes to this file\n"
2966 "# will be lost.\n", ServerRoot
);
2969 * Write a new printcap with the current list of printers.
2972 switch (PrintcapFormat
)
2976 * Each printer is put in the file as:
2986 cupsFilePrintf(fp
, "%s|%s:rm=%s:rp=%s:\n", DefaultPrinter
->name
,
2987 DefaultPrinter
->info
, ServerName
,
2988 DefaultPrinter
->name
);
2990 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
2992 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
2993 if (p
!= DefaultPrinter
)
2994 cupsFilePrintf(fp
, "%s|%s:rm=%s:rp=%s:\n", p
->name
, p
->info
,
2995 ServerName
, p
->name
);
2998 case PRINTCAP_PLIST
:
3000 * Each printer is written as a dictionary in a plist file.
3001 * Currently the printer-name, printer-info, printer-is-accepting-jobs,
3002 * printer-location, printer-make-and-model, printer-state,
3003 * printer-state-reasons, printer-type, and (sanitized) device-uri.
3006 cupsFilePuts(fp
, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
3007 "<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD "
3008 "PLIST 1.0//EN\" \"http://www.apple.com/DTDs/"
3009 "PropertyList-1.0.dtd\">\n"
3010 "<plist version=\"1.0\">\n"
3013 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3015 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3017 cupsFilePuts(fp
, "\t<dict>\n"
3018 "\t\t<key>printer-name</key>\n"
3020 write_xml_string(fp
, p
->name
);
3021 cupsFilePuts(fp
, "</string>\n"
3022 "\t\t<key>printer-info</key>\n"
3024 write_xml_string(fp
, p
->info
);
3025 cupsFilePrintf(fp
, "</string>\n"
3026 "\t\t<key>printer-is-accepting-jobs</key>\n"
3028 "\t\t<key>printer-location</key>\n"
3029 "\t\t<string>", p
->accepting
? "true" : "false");
3030 write_xml_string(fp
, p
->location
);
3031 cupsFilePuts(fp
, "</string>\n"
3032 "\t\t<key>printer-make-and-model</key>\n"
3034 write_xml_string(fp
, p
->make_model
);
3035 cupsFilePrintf(fp
, "</string>\n"
3036 "\t\t<key>printer-state</key>\n"
3037 "\t\t<integer>%d</integer>\n"
3038 "\t\t<key>printer-state-reasons</key>\n"
3039 "\t\t<array>\n", p
->state
);
3040 for (i
= 0; i
< p
->num_reasons
; i
++)
3042 cupsFilePuts(fp
, "\t\t\t<string>");
3043 write_xml_string(fp
, p
->reasons
[i
]);
3044 cupsFilePuts(fp
, "</string>\n");
3046 cupsFilePrintf(fp
, "\t\t</array>\n"
3047 "\t\t<key>printer-type</key>\n"
3048 "\t\t<integer>%d</integer>\n"
3049 "\t\t<key>device-uri</key>\n"
3050 "\t\t<string>", p
->type
);
3051 write_xml_string(fp
, p
->sanitized_device_uri
);
3052 cupsFilePuts(fp
, "</string>\n"
3055 cupsFilePuts(fp
, "</array>\n"
3059 case PRINTCAP_SOLARIS
:
3061 * Each printer is put in the file as:
3063 * _all:all=Printer1,Printer2,Printer3,...,PrinterN
3064 * _default:use=DefaultPrinter
3066 * :bsdaddr=ServerName,Printer1:\
3067 * :description=Description:
3069 * :bsdaddr=ServerName,Printer2:\
3070 * :description=Description:
3072 * :bsdaddr=ServerName,Printer3:\
3073 * :description=Description:
3076 * :bsdaddr=ServerName,PrinterN:\
3077 * :description=Description:
3080 cupsFilePuts(fp
, "_all:all=");
3081 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3083 p
= (cupsd_printer_t
*)cupsArrayCurrent(Printers
))
3084 cupsFilePrintf(fp
, "%s%c", p
->name
,
3085 cupsArrayNext(Printers
) ? ',' : '\n');
3088 cupsFilePrintf(fp
, "_default:use=%s\n", DefaultPrinter
->name
);
3090 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3092 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3093 cupsFilePrintf(fp
, "%s:\\\n"
3094 "\t:bsdaddr=%s,%s:\\\n"
3095 "\t:description=%s:\n",
3096 p
->name
, ServerName
, p
->name
,
3097 p
->info
? p
->info
: "");
3110 * 'add_printer_defaults()' - Add name-default attributes to the printer attributes.
3114 add_printer_defaults(cupsd_printer_t
*p
)/* I - Printer */
3116 int i
; /* Looping var */
3117 int num_options
; /* Number of default options */
3118 cups_option_t
*options
, /* Default options */
3119 *option
; /* Current option */
3120 char name
[256]; /* name-default */
3124 * Maintain a common array of default attribute names...
3127 if (!CommonDefaults
)
3129 CommonDefaults
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
3131 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("copies-default"));
3132 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("document-format-default"));
3133 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("finishings-default"));
3134 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-account-id-default"));
3135 cupsArrayAdd(CommonDefaults
,
3136 _cupsStrAlloc("job-accounting-user-id-default"));
3137 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-hold-until-default"));
3138 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-priority-default"));
3139 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-sheets-default"));
3140 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("media-col-default"));
3141 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("number-up-default"));
3142 cupsArrayAdd(CommonDefaults
,
3143 _cupsStrAlloc("orientation-requested-default"));
3147 * Add all of the default options from the .conf files...
3150 for (num_options
= 0, options
= NULL
, i
= p
->num_options
, option
= p
->options
;
3154 if (strcmp(option
->name
, "ipp-options") &&
3155 strcmp(option
->name
, "job-sheets") &&
3156 strcmp(option
->name
, "lease-duration"))
3158 snprintf(name
, sizeof(name
), "%s-default", option
->name
);
3159 num_options
= cupsAddOption(name
, option
->value
, num_options
, &options
);
3161 if (!cupsArrayFind(CommonDefaults
, name
))
3162 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc(name
));
3167 * Convert options to IPP attributes...
3170 cupsEncodeOptions2(p
->attrs
, num_options
, options
, IPP_TAG_PRINTER
);
3171 cupsFreeOptions(num_options
, options
);
3174 * Add standard -default attributes as needed...
3177 if (!cupsGetOption("copies", p
->num_options
, p
->options
))
3178 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
, "copies-default",
3181 if (!cupsGetOption("document-format", p
->num_options
, p
->options
))
3182 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_MIMETYPE
,
3183 "document-format-default", NULL
, "application/octet-stream");
3185 if (!cupsGetOption("job-hold-until", p
->num_options
, p
->options
))
3186 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3187 "job-hold-until-default", NULL
, "no-hold");
3189 if (!cupsGetOption("job-priority", p
->num_options
, p
->options
))
3190 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3191 "job-priority-default", 50);
3193 if (!cupsGetOption("number-up", p
->num_options
, p
->options
))
3194 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3195 "number-up-default", 1);
3197 if (!cupsGetOption("notify-lease-duration", p
->num_options
, p
->options
))
3198 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3199 "notify-lease-duration-default", DefaultLeaseDuration
);
3201 if (!cupsGetOption("notify-events", p
->num_options
, p
->options
))
3202 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3203 "notify-events-default", NULL
, "job-completed");
3205 if (!cupsGetOption("orientation-requested", p
->num_options
, p
->options
))
3206 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NOVALUE
,
3207 "orientation-requested-default", NULL
, NULL
);
3209 if (!cupsGetOption("print-quality", p
->num_options
, p
->options
))
3210 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
3211 "print-quality-default", IPP_QUALITY_NORMAL
);
3216 * 'add_printer_filter()' - Add a MIME filter for a printer.
3221 cupsd_printer_t
*p
, /* I - Printer to add to */
3222 mime_type_t
*filtertype
, /* I - Filter or prefilter MIME type */
3223 const char *filter
) /* I - Filter to add */
3225 char super
[MIME_MAX_SUPER
], /* Super-type for filter */
3226 type
[MIME_MAX_TYPE
], /* Type for filter */
3227 dsuper
[MIME_MAX_SUPER
], /* Destination super-type for filter */
3228 dtype
[MIME_MAX_TYPE
], /* Destination type for filter */
3229 dest
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2],
3230 /* Destination super/type */
3231 program
[1024]; /* Program/filter name */
3232 int cost
; /* Cost of filter */
3233 size_t maxsize
= 0; /* Maximum supported file size */
3234 mime_type_t
*temptype
, /* MIME type looping var */
3235 *desttype
; /* Destination MIME type */
3236 mime_filter_t
*filterptr
; /* MIME filter */
3237 char filename
[1024]; /* Full filter filename */
3240 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3241 "add_printer_filter(p=%p(%s), filtertype=%p(%s/%s), "
3242 "filter=\"%s\")", p
, p
->name
, filtertype
, filtertype
->super
,
3243 filtertype
->type
, filter
);
3246 * Parse the filter string; it should be in one of the following formats:
3248 * source/type cost program
3249 * source/type cost maxsize(nnnn) program
3250 * source/type dest/type cost program
3251 * source/type dest/type cost maxsize(nnnn) program
3254 if (sscanf(filter
, "%15[^/]/%255s%*[ \t]%15[^/]/%255s%d%*[ \t]%1023[^\n]",
3255 super
, type
, dsuper
, dtype
, &cost
, program
) == 6)
3257 snprintf(dest
, sizeof(dest
), "%s/%s/%s", p
->name
, dsuper
, dtype
);
3259 if ((desttype
= mimeType(MimeDatabase
, "printer", dest
)) == NULL
)
3261 desttype
= mimeAddType(MimeDatabase
, "printer", dest
);
3263 p
->dest_types
= cupsArrayNew(NULL
, NULL
);
3265 cupsArrayAdd(p
->dest_types
, desttype
);
3271 if (sscanf(filter
, "%15[^/]/%255s%d%*[ \t]%1023[^\n]", super
, type
, &cost
,
3274 desttype
= filtertype
;
3278 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: invalid filter string \"%s\"!",
3284 if (!strncmp(program
, "maxsize(", 8))
3286 char *ptr
; /* Pointer into maxsize(nnnn) program */
3288 maxsize
= strtoll(program
+ 8, &ptr
, 10);
3292 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: invalid filter string \"%s\"!",
3298 while (_cups_isspace(*ptr
))
3301 _cups_strcpy(program
, ptr
);
3305 * Check permissions on the filter and its containing directory...
3308 if (strcmp(program
, "-"))
3310 if (program
[0] == '/')
3311 strlcpy(filename
, program
, sizeof(filename
));
3313 snprintf(filename
, sizeof(filename
), "%s/filter/%s", ServerBin
, program
);
3315 _cupsFileCheck(filename
, _CUPS_FILE_CHECK_PROGRAM
, !RunUser
,
3316 cupsdLogFCMessage
, p
);
3320 * Add the filter to the MIME database, supporting wildcards as needed...
3323 for (temptype
= mimeFirstType(MimeDatabase
);
3325 temptype
= mimeNextType(MimeDatabase
))
3326 if (((super
[0] == '*' && _cups_strcasecmp(temptype
->super
, "printer")) ||
3327 !_cups_strcasecmp(temptype
->super
, super
)) &&
3328 (type
[0] == '*' || !_cups_strcasecmp(temptype
->type
, type
)))
3330 if (desttype
!= filtertype
)
3332 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3333 "add_printer_filter: %s: adding filter %s/%s %s/%s %d "
3334 "%s", p
->name
, temptype
->super
, temptype
->type
,
3335 desttype
->super
, desttype
->type
,
3337 filterptr
= mimeAddFilter(MimeDatabase
, temptype
, desttype
, cost
,
3340 if (!mimeFilterLookup(MimeDatabase
, desttype
, filtertype
))
3342 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3343 "add_printer_filter: %s: adding filter %s/%s %s/%s "
3344 "0 -", p
->name
, desttype
->super
, desttype
->type
,
3345 filtertype
->super
, filtertype
->type
);
3346 mimeAddFilter(MimeDatabase
, desttype
, filtertype
, 0, "-");
3351 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3352 "add_printer_filter: %s: adding filter %s/%s %s/%s %d "
3353 "%s", p
->name
, temptype
->super
, temptype
->type
,
3354 filtertype
->super
, filtertype
->type
,
3356 filterptr
= mimeAddFilter(MimeDatabase
, temptype
, filtertype
, cost
,
3361 filterptr
->maxsize
= maxsize
;
3367 * 'add_printer_formats()' - Add document-format-supported values for a printer.
3371 add_printer_formats(cupsd_printer_t
*p
) /* I - Printer */
3373 int i
; /* Looping var */
3374 mime_type_t
*type
; /* Current MIME type */
3375 cups_array_t
*filters
; /* Filters */
3376 ipp_attribute_t
*attr
; /* document-format-supported attribute */
3377 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
3378 /* MIME type name */
3382 * Raw (and remote) queues advertise all of the supported MIME
3386 cupsArrayDelete(p
->filetypes
);
3387 p
->filetypes
= NULL
;
3391 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
,
3392 (ipp_tag_t
)(IPP_TAG_MIMETYPE
| IPP_TAG_COPY
),
3393 "document-format-supported", NumMimeTypes
, NULL
, MimeTypes
);
3398 * Otherwise, loop through the supported MIME types and see if there
3399 * are filters for them...
3402 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_printer_formats: %d types, %d filters",
3403 mimeNumTypes(MimeDatabase
), mimeNumFilters(MimeDatabase
));
3405 p
->filetypes
= cupsArrayNew(NULL
, NULL
);
3407 for (type
= mimeFirstType(MimeDatabase
);
3409 type
= mimeNextType(MimeDatabase
))
3411 if (!_cups_strcasecmp(type
->super
, "printer"))
3414 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
3416 if ((filters
= mimeFilter(MimeDatabase
, type
, p
->filetype
, NULL
)) != NULL
)
3418 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3419 "add_printer_formats: %s: %s needs %d filters",
3420 p
->name
, mimetype
, cupsArrayCount(filters
));
3422 cupsArrayDelete(filters
);
3423 cupsArrayAdd(p
->filetypes
, type
);
3426 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3427 "add_printer_formats: %s: %s not supported",
3432 * Add the file formats that can be filtered...
3435 if ((type
= mimeType(MimeDatabase
, "application", "octet-stream")) == NULL
||
3436 !cupsArrayFind(p
->filetypes
, type
))
3441 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3442 "add_printer_formats: %s: %d supported types",
3443 p
->name
, cupsArrayCount(p
->filetypes
) + i
);
3445 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_MIMETYPE
,
3446 "document-format-supported",
3447 cupsArrayCount(p
->filetypes
) + i
, NULL
, NULL
);
3450 attr
->values
[0].string
.text
= _cupsStrAlloc("application/octet-stream");
3452 for (type
= (mime_type_t
*)cupsArrayFirst(p
->filetypes
);
3454 i
++, type
= (mime_type_t
*)cupsArrayNext(p
->filetypes
))
3456 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
3458 attr
->values
[i
].string
.text
= _cupsStrAlloc(mimetype
);
3461 #if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
3463 char pdl
[1024]; /* Buffer to build pdl list */
3464 mime_filter_t
*filter
; /* MIME filter looping var */
3468 * We only support raw printing if this is not a Tioga PrintJobMgr based
3469 * queue and if application/octet-stream is a known type...
3472 for (filter
= (mime_filter_t
*)cupsArrayFirst(MimeDatabase
->filters
);
3474 filter
= (mime_filter_t
*)cupsArrayNext(MimeDatabase
->filters
))
3476 if (filter
->dst
== p
->filetype
&& filter
->filter
&&
3477 strstr(filter
->filter
, "PrintJobMgr"))
3483 if (!filter
&& mimeType(MimeDatabase
, "application", "octet-stream"))
3484 strlcat(pdl
, "application/octet-stream,", sizeof(pdl
));
3487 * Then list a bunch of formats that are supported by the printer...
3490 for (type
= (mime_type_t
*)cupsArrayFirst(p
->filetypes
);
3492 type
= (mime_type_t
*)cupsArrayNext(p
->filetypes
))
3494 if (!_cups_strcasecmp(type
->super
, "application"))
3496 if (!_cups_strcasecmp(type
->type
, "pdf"))
3497 strlcat(pdl
, "application/pdf,", sizeof(pdl
));
3498 else if (!_cups_strcasecmp(type
->type
, "postscript"))
3499 strlcat(pdl
, "application/postscript,", sizeof(pdl
));
3501 else if (!_cups_strcasecmp(type
->super
, "image"))
3503 if (!_cups_strcasecmp(type
->type
, "jpeg"))
3504 strlcat(pdl
, "image/jpeg,", sizeof(pdl
));
3505 else if (!_cups_strcasecmp(type
->type
, "png"))
3506 strlcat(pdl
, "image/png,", sizeof(pdl
));
3507 else if (!_cups_strcasecmp(type
->type
, "pwg-raster"))
3508 strlcat(pdl
, "image/pwg-raster,", sizeof(pdl
));
3513 pdl
[strlen(pdl
) - 1] = '\0'; /* Remove trailing comma */
3515 cupsdSetString(&p
->pdl
, pdl
);
3517 #endif /* HAVE_DNSSD || HAVE_AVAHI */
3522 * 'compare_printers()' - Compare two printers.
3525 static int /* O - Result of comparison */
3526 compare_printers(void *first
, /* I - First printer */
3527 void *second
, /* I - Second printer */
3528 void *data
) /* I - App data (not used) */
3532 return (_cups_strcasecmp(((cupsd_printer_t
*)first
)->name
,
3533 ((cupsd_printer_t
*)second
)->name
));
3538 * 'delete_printer_filters()' - Delete all MIME filters for a printer.
3542 delete_printer_filters(
3543 cupsd_printer_t
*p
) /* I - Printer to remove from */
3545 mime_filter_t
*filter
; /* MIME filter looping var */
3546 mime_type_t
*type
; /* Destination types for filters */
3550 * Range check input...
3557 * Remove all filters from the MIME database that have a destination
3558 * type == printer...
3561 for (filter
= mimeFirstFilter(MimeDatabase
);
3563 filter
= mimeNextFilter(MimeDatabase
))
3564 if (filter
->dst
== p
->filetype
|| filter
->dst
== p
->prefiltertype
||
3565 cupsArrayFind(p
->dest_types
, filter
->dst
))
3568 * Delete the current filter...
3571 mimeDeleteFilter(MimeDatabase
, filter
);
3574 for (type
= (mime_type_t
*)cupsArrayFirst(p
->dest_types
);
3576 type
= (mime_type_t
*)cupsArrayNext(p
->dest_types
))
3577 mimeDeleteType(MimeDatabase
, type
);
3579 cupsArrayDelete(p
->dest_types
);
3580 p
->dest_types
= NULL
;
3582 cupsdSetPrinterReasons(p
, "-cups-insecure-filter-warning"
3583 ",cups-missing-filter-warning");
3588 * 'dirty_printer()' - Mark config and state files dirty for the specified
3593 dirty_printer(cupsd_printer_t
*p
) /* I - Printer */
3595 if (p
->type
& CUPS_PRINTER_CLASS
)
3596 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
3598 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
3600 if (PrintcapFormat
== PRINTCAP_PLIST
)
3601 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
3606 * 'load_ppd()' - Load a cached PPD file, updating the cache as needed.
3610 load_ppd(cupsd_printer_t
*p
) /* I - Printer */
3612 int i
, j
, k
; /* Looping vars */
3613 char cache_name
[1024]; /* Cache filename */
3614 struct stat cache_info
; /* Cache file info */
3615 ppd_file_t
*ppd
; /* PPD file */
3616 char ppd_name
[1024]; /* PPD filename */
3617 struct stat ppd_info
; /* PPD file info */
3618 int num_media
; /* Number of media options */
3619 ppd_size_t
*size
; /* Current PPD size */
3620 ppd_option_t
*duplex
, /* Duplex option */
3621 *output_bin
, /* OutputBin option */
3622 *output_mode
, /* OutputMode option */
3623 *resolution
; /* (Set|JCL|)Resolution option */
3624 ppd_choice_t
*choice
, /* Current PPD choice */
3625 *input_slot
, /* Current input slot */
3626 *media_type
; /* Current media type */
3627 ppd_attr_t
*ppd_attr
; /* PPD attribute */
3628 int xdpi
, /* Horizontal resolution */
3629 ydpi
; /* Vertical resolution */
3630 const char *resptr
; /* Pointer into resolution keyword */
3631 _pwg_size_t
*pwgsize
; /* Current PWG size */
3632 _pwg_map_t
*pwgsource
, /* Current PWG source */
3633 *pwgtype
; /* Current PWG type */
3634 ipp_attribute_t
*attr
; /* Attribute data */
3635 _ipp_value_t
*val
; /* Attribute value */
3636 int num_finishings
, /* Number of finishings */
3637 finishings
[5]; /* finishings-supported values */
3638 int num_qualities
, /* Number of print-quality values */
3639 qualities
[3]; /* print-quality values */
3640 int num_margins
, /* Number of media-*-margin-supported values */
3641 margins
[16]; /* media-*-margin-supported values */
3642 const char *filter
, /* Current filter */
3643 *mandatory
; /* Current mandatory attribute */
3644 static const char * const sides
[3] = /* sides-supported values */
3647 "two-sided-long-edge",
3648 "two-sided-short-edge"
3650 static const char * const standard_commands
[] =
3651 { /* Standard CUPS commands */
3659 * Check to see if the cache is up-to-date...
3662 snprintf(cache_name
, sizeof(cache_name
), "%s/%s.data", CacheDir
, p
->name
);
3663 if (stat(cache_name
, &cache_info
))
3664 cache_info
.st_mtime
= 0;
3666 snprintf(ppd_name
, sizeof(ppd_name
), "%s/ppd/%s.ppd", ServerRoot
, p
->name
);
3667 if (stat(ppd_name
, &ppd_info
))
3668 ppd_info
.st_mtime
= 1;
3670 ippDelete(p
->ppd_attrs
);
3671 p
->ppd_attrs
= NULL
;
3673 _ppdCacheDestroy(p
->pc
);
3676 cupsdClearString(&(p
->make_model
));
3678 if (cache_info
.st_mtime
>= ppd_info
.st_mtime
)
3680 cupsdLogMessage(CUPSD_LOG_DEBUG
, "load_ppd: Loading %s...", cache_name
);
3682 if ((p
->pc
= _ppdCacheCreateWithFile(cache_name
, &p
->ppd_attrs
)) != NULL
&&
3686 * Loaded successfully!
3694 * Reload PPD attributes from disk...
3697 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
3699 cupsdLogMessage(CUPSD_LOG_DEBUG
, "load_ppd: Loading %s...", ppd_name
);
3701 p
->type
&= ~CUPS_PRINTER_OPTIONS
;
3702 p
->type
|= CUPS_PRINTER_BW
;
3704 finishings
[0] = IPP_FINISHINGS_NONE
;
3707 p
->ppd_attrs
= ippNew();
3709 if ((ppd
= _ppdOpenFile(ppd_name
, _PPD_LOCALIZATION_NONE
)) != NULL
)
3712 * Add make/model and other various attributes...
3715 p
->pc
= _ppdCacheCreateWithPPD(ppd
);
3718 cupsdLogMessage(CUPSD_LOG_WARN
, "Unable to create cache of \"%s\": %s",
3719 ppd_name
, cupsLastErrorString());
3721 ppdMarkDefaults(ppd
);
3723 if (ppd
->color_device
)
3724 p
->type
|= CUPS_PRINTER_COLOR
;
3725 if (ppd
->variable_sizes
)
3726 p
->type
|= CUPS_PRINTER_VARIABLE
;
3727 if (!ppd
->manual_copies
)
3728 p
->type
|= CUPS_PRINTER_COPIES
;
3729 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsFax", NULL
)) != NULL
)
3730 if (ppd_attr
->value
&& !_cups_strcasecmp(ppd_attr
->value
, "true"))
3731 p
->type
|= CUPS_PRINTER_FAX
;
3733 ippAddBoolean(p
->ppd_attrs
, IPP_TAG_PRINTER
, "color-supported",
3736 if (p
->pc
&& p
->pc
->charge_info_uri
)
3737 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
3738 "printer-charge-info-uri", NULL
, p
->pc
->charge_info_uri
);
3740 if (p
->pc
&& p
->pc
->account_id
)
3741 ippAddBoolean(p
->ppd_attrs
, IPP_TAG_PRINTER
, "job-account-id-supported",
3744 if (p
->pc
&& p
->pc
->accounting_user_id
)
3745 ippAddBoolean(p
->ppd_attrs
, IPP_TAG_PRINTER
,
3746 "job-accounting-user-id-supported", 1);
3748 if (p
->pc
&& p
->pc
->password
)
3750 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3751 "job-password-encryption-supported", NULL
, "none");
3752 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3753 "job-password-supported", strlen(p
->pc
->password
));
3756 if (ppd
->throughput
)
3758 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3759 "pages-per-minute", ppd
->throughput
);
3760 if (ppd
->color_device
)
3761 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3762 "pages-per-minute-color", ppd
->throughput
);
3767 * When there is no speed information, just say "1 page per minute".
3770 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3771 "pages-per-minute", 1);
3772 if (ppd
->color_device
)
3773 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3774 "pages-per-minute-color", 1);
3779 if ((output_mode
= ppdFindOption(ppd
, "OutputMode")) != NULL
)
3781 if (ppdFindChoice(output_mode
, "draft") ||
3782 ppdFindChoice(output_mode
, "fast"))
3783 qualities
[num_qualities
++] = IPP_QUALITY_DRAFT
;
3785 qualities
[num_qualities
++] = IPP_QUALITY_NORMAL
;
3787 if (ppdFindChoice(output_mode
, "best") ||
3788 ppdFindChoice(output_mode
, "high"))
3789 qualities
[num_qualities
++] = IPP_QUALITY_HIGH
;
3791 else if ((ppd_attr
= ppdFindAttr(ppd
, "APPrinterPreset", NULL
)) != NULL
)
3795 if (strstr(ppd_attr
->spec
, "draft") ||
3796 strstr(ppd_attr
->spec
, "Draft"))
3798 qualities
[num_qualities
++] = IPP_QUALITY_DRAFT
;
3802 while ((ppd_attr
= ppdFindNextAttr(ppd
, "APPrinterPreset",
3805 qualities
[num_qualities
++] = IPP_QUALITY_NORMAL
;
3806 qualities
[num_qualities
++] = IPP_QUALITY_HIGH
;
3809 qualities
[num_qualities
++] = IPP_QUALITY_NORMAL
;
3811 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
3812 "print-quality-supported", num_qualities
, qualities
);
3817 * The NickName can be localized in the character set specified
3818 * by the LanugageEncoding attribute. However, ppdOpen2() has
3819 * already converted the ppd->nickname member to UTF-8 for us
3820 * (the original attribute value is available separately)
3823 cupsdSetString(&p
->make_model
, ppd
->nickname
);
3825 else if (ppd
->modelname
)
3828 * Model name can only contain specific characters...
3831 cupsdSetString(&p
->make_model
, ppd
->modelname
);
3834 cupsdSetString(&p
->make_model
, "Bad PPD File");
3836 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
3837 "printer-make-and-model", NULL
, p
->make_model
);
3840 * Add media options from the PPD file...
3843 if (ppd
->num_sizes
== 0 || !p
->pc
)
3845 if (!ppdFindAttr(ppd
, "APScannerOnly", NULL
))
3846 cupsdLogMessage(CUPSD_LOG_CRIT
,
3847 "The PPD file for printer %s contains no media "
3848 "options and is therefore invalid!", p
->name
);
3850 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3851 "media-default", NULL
, "unknown");
3852 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3853 "media-supported", NULL
, "unknown");
3861 if ((size
= ppdPageSize(ppd
, NULL
)) != NULL
)
3862 pwgsize
= _ppdCacheGetSize(p
->pc
, size
->name
);
3866 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3867 "media-default", NULL
,
3868 pwgsize
? pwgsize
->map
.pwg
: "unknown");
3876 ipp_t
*col
; /* Collection value */
3878 input_slot
= ppdFindMarkedChoice(ppd
, "InputSlot");
3879 media_type
= ppdFindMarkedChoice(ppd
, "MediaType");
3880 col
= new_media_col(pwgsize
,
3882 _ppdCacheGetSource(p
->pc
,
3883 input_slot
->choice
) :
3886 _ppdCacheGetType(p
->pc
,
3887 media_type
->choice
) :
3890 ippAddCollection(p
->ppd_attrs
, IPP_TAG_PRINTER
, "media-col-default",
3899 num_media
= p
->pc
->num_sizes
;
3900 if (p
->pc
->custom_min_keyword
)
3903 if ((attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3904 "media-supported", num_media
, NULL
,
3909 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
;
3911 i
--, pwgsize
++, val
++)
3912 val
->string
.text
= _cupsStrAlloc(pwgsize
->map
.pwg
);
3914 if (p
->pc
->custom_min_keyword
)
3916 val
->string
.text
= _cupsStrAlloc(p
->pc
->custom_min_keyword
);
3918 val
->string
.text
= _cupsStrAlloc(p
->pc
->custom_max_keyword
);
3923 * media-size-supported
3926 num_media
= p
->pc
->num_sizes
;
3927 if (p
->pc
->custom_min_keyword
)
3930 if ((attr
= ippAddCollections(p
->ppd_attrs
, IPP_TAG_PRINTER
,
3931 "media-size-supported", num_media
,
3936 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
;
3938 i
--, pwgsize
++, val
++)
3940 val
->collection
= ippNew();
3941 ippAddInteger(val
->collection
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3942 "x-dimension", pwgsize
->width
);
3943 ippAddInteger(val
->collection
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3944 "y-dimension", pwgsize
->length
);
3947 if (p
->pc
->custom_min_keyword
)
3949 val
->collection
= ippNew();
3950 ippAddRange(val
->collection
, IPP_TAG_PRINTER
, "x-dimension",
3951 p
->pc
->custom_min_width
, p
->pc
->custom_max_width
);
3952 ippAddRange(val
->collection
, IPP_TAG_PRINTER
, "y-dimension",
3953 p
->pc
->custom_min_length
, p
->pc
->custom_max_length
);
3958 * media-source-supported
3961 if (p
->pc
->num_sources
> 0 &&
3962 (attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3963 "media-source-supported", p
->pc
->num_sources
,
3964 NULL
, NULL
)) != NULL
)
3966 for (i
= p
->pc
->num_sources
, pwgsource
= p
->pc
->sources
,
3969 i
--, pwgsource
++, val
++)
3970 val
->string
.text
= _cupsStrAlloc(pwgsource
->pwg
);
3974 * media-type-supported
3977 if (p
->pc
->num_types
> 0 &&
3978 (attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3979 "media-type-supported", p
->pc
->num_types
,
3980 NULL
, NULL
)) != NULL
)
3982 for (i
= p
->pc
->num_types
, pwgtype
= p
->pc
->types
,
3985 i
--, pwgtype
++, val
++)
3986 val
->string
.text
= _cupsStrAlloc(pwgtype
->pwg
);
3990 * media-*-margin-supported
3993 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, num_margins
= 0;
3994 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
3997 for (j
= 0; j
< num_margins
; j
++)
3998 if (pwgsize
->bottom
== margins
[j
])
4001 if (j
>= num_margins
)
4003 margins
[num_margins
] = pwgsize
->bottom
;
4008 if (num_margins
> 0)
4009 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4010 "media-bottom-margin-supported", num_margins
, margins
);
4012 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4013 "media-bottom-margin-supported", 0);
4015 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, num_margins
= 0;
4016 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4019 for (j
= 0; j
< num_margins
; j
++)
4020 if (pwgsize
->left
== margins
[j
])
4023 if (j
>= num_margins
)
4025 margins
[num_margins
] = pwgsize
->left
;
4030 if (num_margins
> 0)
4031 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4032 "media-left-margin-supported", num_margins
, margins
);
4034 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4035 "media-left-margin-supported", 0);
4037 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, num_margins
= 0;
4038 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4041 for (j
= 0; j
< num_margins
; j
++)
4042 if (pwgsize
->right
== margins
[j
])
4045 if (j
>= num_margins
)
4047 margins
[num_margins
] = pwgsize
->right
;
4052 if (num_margins
> 0)
4053 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4054 "media-right-margin-supported", num_margins
, margins
);
4056 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4057 "media-right-margin-supported", 0);
4059 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, num_margins
= 0;
4060 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4063 for (j
= 0; j
< num_margins
; j
++)
4064 if (pwgsize
->top
== margins
[j
])
4067 if (j
>= num_margins
)
4069 margins
[num_margins
] = pwgsize
->top
;
4074 if (num_margins
> 0)
4075 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4076 "media-top-margin-supported", num_margins
, margins
);
4078 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4079 "media-top-margin-supported", 0);
4082 * media-col-database
4085 num_media
= p
->pc
->num_sizes
;
4086 if (p
->pc
->num_sources
)
4088 if (p
->pc
->num_types
> 0)
4089 num_media
+= p
->pc
->num_sizes
* p
->pc
->num_sources
*
4092 num_media
+= p
->pc
->num_sizes
* p
->pc
->num_sources
;
4094 else if (p
->pc
->num_types
)
4095 num_media
+= p
->pc
->num_sizes
* p
->pc
->num_types
;
4097 if ((attr
= ippAddCollections(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4098 "media-col-database", num_media
,
4101 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, val
= attr
->values
;
4106 * Start by adding the page size without source or type...
4109 ppdMarkOption(ppd
, "PageSize", pwgsize
->map
.ppd
);
4111 val
->collection
= new_media_col(pwgsize
, NULL
, NULL
);
4115 * Then add the specific, supported combinations of size, source, and
4119 if (p
->pc
->num_sources
> 0)
4121 for (j
= p
->pc
->num_sources
, pwgsource
= p
->pc
->sources
;
4125 ppdMarkOption(ppd
, "InputSlot", pwgsource
->ppd
);
4127 if (p
->pc
->num_types
> 0)
4129 for (k
= p
->pc
->num_types
, pwgtype
= p
->pc
->types
;
4133 if (!ppdMarkOption(ppd
, "MediaType", pwgtype
->ppd
))
4135 val
->collection
= new_media_col(pwgsize
, pwgsource
->pwg
,
4141 else if (!ppdConflicts(ppd
))
4143 val
->collection
= new_media_col(pwgsize
, pwgsource
->pwg
, NULL
);
4148 else if (p
->pc
->num_types
> 0)
4150 for (j
= p
->pc
->num_types
, pwgtype
= p
->pc
->types
;
4154 if (!ppdMarkOption(ppd
, "MediaType", pwgtype
->ppd
))
4156 val
->collection
= new_media_col(pwgsize
, NULL
, pwgtype
->pwg
);
4164 * Update the number of media-col-database values...
4167 attr
->num_values
= val
- attr
->values
;
4175 if (p
->pc
&& p
->pc
->num_bins
> 0)
4177 attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4178 "output-bin-supported", p
->pc
->num_bins
,
4183 for (i
= 0, val
= attr
->values
;
4184 i
< p
->pc
->num_bins
;
4186 val
->string
.text
= _cupsStrAlloc(p
->pc
->bins
[i
].pwg
);
4189 if ((output_bin
= ppdFindOption(ppd
, "OutputBin")) != NULL
)
4191 for (i
= 0; i
< p
->pc
->num_bins
; i
++)
4192 if (!strcmp(p
->pc
->bins
[i
].ppd
, output_bin
->defchoice
))
4195 if (i
>= p
->pc
->num_bins
)
4198 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4199 "output-bin-default", NULL
, p
->pc
->bins
[i
].pwg
);
4202 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4203 "output-bin-default", NULL
, p
->pc
->bins
[0].pwg
);
4205 else if (((ppd_attr
= ppdFindAttr(ppd
, "DefaultOutputOrder",
4207 !_cups_strcasecmp(ppd_attr
->value
, "Reverse")) ||
4208 (!ppd_attr
&& ppd
->manufacturer
&& /* "Compatibility heuristic" */
4209 (!_cups_strcasecmp(ppd
->manufacturer
, "epson") ||
4210 !_cups_strcasecmp(ppd
->manufacturer
, "lexmark"))))
4213 * Report that this printer has a single output bin that leaves pages face
4217 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4218 "output-bin-supported", NULL
, "face-up");
4219 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4220 "output-bin-default", NULL
, "face-up");
4224 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4225 "output-bin-supported", NULL
, "face-down");
4226 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4227 "output-bin-default", NULL
, "face-down");
4231 * print-color-mode...
4234 if (ppd
->color_device
)
4236 static const char * const color_modes
[] =
4242 ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4243 "print-color-mode-supported", 2, NULL
, color_modes
);
4244 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4245 "print-color-mode-default", NULL
, "color");
4249 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4250 "print-color-mode-supported", NULL
, "monochrome");
4251 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4252 "print-color-mode-default", NULL
, "monochrome");
4256 * Mandatory job attributes, if any...
4259 if (p
->pc
&& cupsArrayCount(p
->pc
->mandatory
) > 0)
4261 int count
= cupsArrayCount(p
->pc
->mandatory
);
4262 /* Number of mandatory attributes */
4264 attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4265 "printer-mandatory-job-attributes", count
, NULL
,
4268 for (val
= attr
->values
,
4269 mandatory
= (char *)cupsArrayFirst(p
->pc
->mandatory
);
4271 val
++, mandatory
= (char *)cupsArrayNext(p
->pc
->mandatory
))
4272 val
->string
.text
= _cupsStrAlloc(mandatory
);
4276 * Printer resolutions...
4279 if ((resolution
= ppdFindOption(ppd
, "Resolution")) == NULL
)
4280 if ((resolution
= ppdFindOption(ppd
, "JCLResolution")) == NULL
)
4281 if ((resolution
= ppdFindOption(ppd
, "SetResolution")) == NULL
)
4282 resolution
= ppdFindOption(ppd
, "CNRes_PGP");
4287 * Report all supported resolutions...
4290 attr
= ippAddResolutions(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4291 "printer-resolution-supported",
4292 resolution
->num_choices
, IPP_RES_PER_INCH
,
4295 for (i
= 0, choice
= resolution
->choices
;
4296 i
< resolution
->num_choices
;
4299 xdpi
= ydpi
= (int)strtol(choice
->choice
, (char **)&resptr
, 10);
4300 if (resptr
> choice
->choice
&& xdpi
> 0 && *resptr
== 'x')
4301 ydpi
= (int)strtol(resptr
+ 1, (char **)&resptr
, 10);
4303 if (xdpi
<= 0 || ydpi
<= 0)
4305 cupsdLogMessage(CUPSD_LOG_WARN
,
4306 "Bad resolution \"%s\" for printer %s.",
4307 choice
->choice
, p
->name
);
4311 attr
->values
[i
].resolution
.xres
= xdpi
;
4312 attr
->values
[i
].resolution
.yres
= ydpi
;
4313 attr
->values
[i
].resolution
.units
= IPP_RES_PER_INCH
;
4316 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4317 "printer-resolution-default", IPP_RES_PER_INCH
,
4321 else if ((ppd_attr
= ppdFindAttr(ppd
, "DefaultResolution", NULL
)) != NULL
&&
4325 * Just the DefaultResolution to report...
4328 xdpi
= ydpi
= (int)strtol(ppd_attr
->value
, (char **)&resptr
, 10);
4329 if (resptr
> ppd_attr
->value
&& xdpi
> 0)
4332 ydpi
= (int)strtol(resptr
+ 1, (char **)&resptr
, 10);
4337 if (xdpi
<= 0 || ydpi
<= 0)
4339 cupsdLogMessage(CUPSD_LOG_WARN
,
4340 "Bad default resolution \"%s\" for printer %s.",
4341 ppd_attr
->value
, p
->name
);
4345 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4346 "printer-resolution-default", IPP_RES_PER_INCH
,
4348 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4349 "printer-resolution-supported", IPP_RES_PER_INCH
,
4355 * No resolutions in PPD - make one up...
4358 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4359 "printer-resolution-default", IPP_RES_PER_INCH
,
4361 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4362 "printer-resolution-supported", IPP_RES_PER_INCH
,
4370 ppdMarkDefaults(ppd
);
4372 if ((duplex
= ppdFindOption(ppd
, "Duplex")) == NULL
)
4373 if ((duplex
= ppdFindOption(ppd
, "EFDuplex")) == NULL
)
4374 if ((duplex
= ppdFindOption(ppd
, "EFDuplexing")) == NULL
)
4375 if ((duplex
= ppdFindOption(ppd
, "KD03Duplex")) == NULL
)
4376 duplex
= ppdFindOption(ppd
, "JCLDuplex");
4378 if (duplex
&& duplex
->num_choices
> 1 &&
4379 !ppdInstallableConflict(ppd
, duplex
->keyword
, "DuplexTumble"))
4381 p
->type
|= CUPS_PRINTER_DUPLEX
;
4383 ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4384 "sides-supported", 3, NULL
, sides
);
4386 if (!_cups_strcasecmp(duplex
->defchoice
, "DuplexTumble"))
4387 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4388 "sides-default", NULL
, "two-sided-short-edge");
4389 else if (!_cups_strcasecmp(duplex
->defchoice
, "DuplexNoTumble"))
4390 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4391 "sides-default", NULL
, "two-sided-long-edge");
4393 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4394 "sides-default", NULL
, "one-sided");
4398 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4399 "sides-supported", NULL
, "one-sided");
4400 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4401 "sides-default", NULL
, "one-sided");
4404 if (ppdFindOption(ppd
, "Collate") != NULL
)
4405 p
->type
|= CUPS_PRINTER_COLLATE
;
4407 if (ppdFindOption(ppd
, "StapleLocation") != NULL
)
4409 p
->type
|= CUPS_PRINTER_STAPLE
;
4410 finishings
[num_finishings
++] = IPP_FINISHINGS_STAPLE
;
4413 if (ppdFindOption(ppd
, "BindEdge") != NULL
)
4415 p
->type
|= CUPS_PRINTER_BIND
;
4416 finishings
[num_finishings
++] = IPP_FINISHINGS_BIND
;
4419 for (i
= 0; i
< ppd
->num_sizes
; i
++)
4420 if (ppd
->sizes
[i
].length
> 1728)
4421 p
->type
|= CUPS_PRINTER_LARGE
;
4422 else if (ppd
->sizes
[i
].length
> 1008)
4423 p
->type
|= CUPS_PRINTER_MEDIUM
;
4425 p
->type
|= CUPS_PRINTER_SMALL
;
4427 if ((ppd_attr
= ppdFindAttr(ppd
, "APICADriver", NULL
)) != NULL
&&
4428 ppd_attr
->value
&& !_cups_strcasecmp(ppd_attr
->value
, "true"))
4430 if ((ppd_attr
= ppdFindAttr(ppd
, "APScannerOnly", NULL
)) != NULL
&&
4431 ppd_attr
->value
&& !_cups_strcasecmp(ppd_attr
->value
, "true"))
4432 p
->type
|= CUPS_PRINTER_SCANNER
;
4434 p
->type
|= CUPS_PRINTER_MFP
;
4438 * Scan the filters in the PPD file...
4443 for (filter
= (const char *)cupsArrayFirst(p
->pc
->filters
);
4445 filter
= (const char *)cupsArrayNext(p
->pc
->filters
))
4447 if (!_cups_strncasecmp(filter
, "application/vnd.cups-command", 28) &&
4448 _cups_isspace(filter
[28]))
4450 p
->type
|= CUPS_PRINTER_COMMANDS
;
4456 if (p
->type
& CUPS_PRINTER_COMMANDS
)
4458 char *commands
, /* Copy of commands */
4459 *start
, /* Start of name */
4460 *end
; /* End of name */
4461 int count
; /* Number of commands */
4463 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsCommands", NULL
)) != NULL
)
4465 for (count
= 0, start
= ppd_attr
->value
; *start
; count
++)
4467 while (_cups_isspace(*start
))
4473 while (*start
&& !isspace(*start
& 255))
4483 * Make a copy of the commands string and count how many commands there
4487 attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4488 "printer-commands", count
, NULL
, NULL
);
4490 commands
= strdup(ppd_attr
->value
);
4492 for (count
= 0, start
= commands
; *start
; count
++)
4494 while (isspace(*start
& 255))
4501 while (*end
&& !isspace(*end
& 255))
4507 attr
->values
[count
].string
.text
= _cupsStrAlloc(start
);
4517 * Add the standard list of commands...
4520 ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4522 (int)(sizeof(standard_commands
) /
4523 sizeof(standard_commands
[0])), NULL
,
4530 * No commands supported...
4533 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4534 "printer-commands", NULL
, "none");
4538 * Show current and available port monitors for this printer...
4541 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
, "port-monitor",
4542 NULL
, p
->port_monitor
? p
->port_monitor
: "none");
4544 for (i
= 1, ppd_attr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
4546 i
++, ppd_attr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
));
4550 if (strstr(ppd
->protocols
, "TBCP"))
4552 else if (strstr(ppd
->protocols
, "BCP"))
4556 attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
4557 "port-monitor-supported", i
, NULL
, NULL
);
4559 attr
->values
[0].string
.text
= _cupsStrAlloc("none");
4561 for (i
= 1, ppd_attr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
4563 i
++, ppd_attr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
))
4564 attr
->values
[i
].string
.text
= _cupsStrAlloc(ppd_attr
->value
);
4568 if (strstr(ppd
->protocols
, "TBCP"))
4569 attr
->values
[i
].string
.text
= _cupsStrAlloc("tbcp");
4570 else if (strstr(ppd
->protocols
, "BCP"))
4571 attr
->values
[i
].string
.text
= _cupsStrAlloc("bcp");
4574 if (ppdFindAttr(ppd
, "APRemoteQueueID", NULL
))
4575 p
->type
|= CUPS_PRINTER_REMOTE
;
4577 #ifdef HAVE_APPLICATIONSERVICES_H
4579 * Convert the file referenced in APPrinterIconPath to a 128x128 PNG
4580 * and save it as cacheDir/printername.png
4583 if ((ppd_attr
= ppdFindAttr(ppd
, "APPrinterIconPath", NULL
)) != NULL
&&
4585 !_cupsFileCheck(ppd_attr
->value
, _CUPS_FILE_CHECK_FILE
, !RunUser
,
4586 cupsdLogFCMessage
, p
))
4588 CGImageRef imageRef
= NULL
;/* Current icon image */
4589 CGImageRef biggestIconRef
= NULL
;
4590 /* Biggest icon image */
4591 CGImageRef closestTo128IconRef
= NULL
;
4592 /* Icon image closest to and >= 128 */
4593 CGImageSourceRef sourceRef
; /* The file's image source */
4594 char outPath
[HTTP_MAX_URI
];
4595 /* The path to the PNG file */
4596 CFURLRef outUrl
; /* The URL made from the outPath */
4597 CFURLRef icnsFileUrl
; /* The URL of the original ICNS icon file */
4598 CGImageDestinationRef destRef
; /* The image destination to write */
4599 size_t bytesPerRow
; /* The bytes per row used for resizing */
4600 CGContextRef context
; /* The CG context used for resizing */
4602 snprintf(outPath
, sizeof(outPath
), "%s/%s.png", CacheDir
, p
->name
);
4603 outUrl
= CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault
,
4607 icnsFileUrl
= CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault
,
4608 (UInt8
*)ppd_attr
->value
,
4609 strlen(ppd_attr
->value
),
4611 if (outUrl
&& icnsFileUrl
)
4613 sourceRef
= CGImageSourceCreateWithURL(icnsFileUrl
, NULL
);
4616 for (i
= 0; i
< CGImageSourceGetCount(sourceRef
); i
++)
4618 imageRef
= CGImageSourceCreateImageAtIndex(sourceRef
, i
, NULL
);
4622 if (CGImageGetWidth(imageRef
) == CGImageGetHeight(imageRef
))
4625 * Loop through remembering the icon closest to 128 but >= 128
4626 * and then remember the largest icon.
4629 if (CGImageGetWidth(imageRef
) >= 128 &&
4630 (!closestTo128IconRef
||
4631 CGImageGetWidth(imageRef
) <
4632 CGImageGetWidth(closestTo128IconRef
)))
4634 CGImageRelease(closestTo128IconRef
);
4635 CGImageRetain(imageRef
);
4636 closestTo128IconRef
= imageRef
;
4639 if (!biggestIconRef
||
4640 CGImageGetWidth(imageRef
) > CGImageGetWidth(biggestIconRef
))
4642 CGImageRelease(biggestIconRef
);
4643 CGImageRetain(imageRef
);
4644 biggestIconRef
= imageRef
;
4648 CGImageRelease(imageRef
);
4654 * If biggestIconRef is NULL, we found no icons. Otherwise we first
4655 * want the closest to 128, but if none are larger than 128, we want
4656 * the largest icon available.
4659 imageRef
= closestTo128IconRef
? closestTo128IconRef
:
4661 CGImageRetain(imageRef
);
4662 CGImageRelease(biggestIconRef
);
4663 if (closestTo128IconRef
)
4664 CGImageRelease(closestTo128IconRef
);
4665 destRef
= CGImageDestinationCreateWithURL(outUrl
, kUTTypePNG
, 1,
4669 if (CGImageGetWidth(imageRef
) != 128)
4671 bytesPerRow
= CGImageGetBytesPerRow(imageRef
) /
4672 CGImageGetWidth(imageRef
) * 128;
4673 context
= CGBitmapContextCreate(NULL
, 128, 128,
4674 CGImageGetBitsPerComponent(imageRef
),
4676 CGImageGetColorSpace(imageRef
),
4677 kCGImageAlphaPremultipliedFirst
);
4680 CGContextDrawImage(context
, CGRectMake(0, 0, 128, 128),
4682 CGImageRelease(imageRef
);
4683 imageRef
= CGBitmapContextCreateImage(context
);
4684 CGContextRelease(context
);
4688 CGImageDestinationAddImage(destRef
, imageRef
, NULL
);
4689 CGImageDestinationFinalize(destRef
);
4693 CGImageRelease(imageRef
);
4696 CFRelease(sourceRef
);
4704 CFRelease(icnsFileUrl
);
4706 #endif /* HAVE_APPLICATIONSERVICES_H */
4709 * Close the PPD and set the type...
4714 else if (!access(ppd_name
, 0))
4716 int pline
; /* PPD line number */
4717 ppd_status_t pstatus
; /* PPD load status */
4720 pstatus
= ppdLastError(&pline
);
4722 cupsdLogMessage(CUPSD_LOG_ERROR
, "PPD file for %s cannot be loaded!",
4725 if (pstatus
<= PPD_ALLOC_ERROR
)
4726 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s", strerror(errno
));
4728 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s on line %d.",
4729 ppdErrorString(pstatus
), pline
);
4731 cupsdLogMessage(CUPSD_LOG_INFO
,
4732 "Hint: Run \"cupstestppd %s\" and fix any errors.",
4738 * If we have an interface script, add a filter entry for it...
4741 char interface
[1024]; /* Interface script */
4744 snprintf(interface
, sizeof(interface
), "%s/interfaces/%s", ServerRoot
,
4746 if (!access(interface
, X_OK
))
4749 * Yes, we have a System V style interface script; use it!
4752 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
4753 "printer-make-and-model", NULL
,
4754 "Local System V Printer");
4756 else if (((!strncmp(p
->device_uri
, "ipp://", 6) ||
4757 !strncmp(p
->device_uri
, "ipps://", 7)) &&
4758 (strstr(p
->device_uri
, "/printers/") != NULL
||
4759 strstr(p
->device_uri
, "/classes/") != NULL
)) ||
4760 ((strstr(p
->device_uri
, "._ipp.") != NULL
||
4761 strstr(p
->device_uri
, "._ipps.") != NULL
) &&
4762 !strcmp(p
->device_uri
+ strlen(p
->device_uri
) - 5, "/cups")))
4765 * Tell the client this is really a hard-wired remote printer.
4768 p
->type
|= CUPS_PRINTER_REMOTE
;
4771 * Point the printer-uri-supported attribute to the
4775 if (strchr(p
->device_uri
, '?'))
4778 * Strip trailing "?options" from URI...
4781 char resource
[HTTP_MAX_URI
], /* New URI */
4782 *ptr
; /* Pointer into URI */
4784 strlcpy(resource
, p
->device_uri
, sizeof(resource
));
4785 if ((ptr
= strchr(resource
, '?')) != NULL
)
4788 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
4789 "printer-uri-supported", NULL
, resource
);
4792 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
4793 "printer-uri-supported", NULL
, p
->device_uri
);
4796 * Then set the make-and-model accordingly...
4799 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
4800 "printer-make-and-model", NULL
, "Remote Printer");
4803 * Print all files directly...
4812 * Otherwise we have neither - treat this as a "dumb" printer
4813 * with no PPD file...
4816 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
4817 "printer-make-and-model", NULL
, "Local Raw Printer");
4823 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
4824 "finishings-supported", num_finishings
, finishings
);
4825 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
4826 "finishings-default", IPP_FINISHINGS_NONE
);
4831 * Save cached PPD attributes to disk...
4834 cupsdLogMessage(CUPSD_LOG_DEBUG
, "load_ppd: Saving %s...", cache_name
);
4836 _ppdCacheWriteFile(p
->pc
, cache_name
, p
->ppd_attrs
);
4841 * Remove cache files...
4844 if (cache_info
.st_mtime
)
4851 * 'new_media_col()' - Create a media-col collection value.
4854 static ipp_t
* /* O - Collection value */
4855 new_media_col(_pwg_size_t
*size
, /* I - media-size/margin values */
4856 const char *source
, /* I - media-source value */
4857 const char *type
) /* I - media-type value */
4859 ipp_t
*media_col
, /* Collection value */
4860 *media_size
; /* media-size value */
4863 media_col
= ippNew();
4865 media_size
= ippNew();
4866 ippAddInteger(media_size
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4867 "x-dimension", size
->width
);
4868 ippAddInteger(media_size
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4869 "y-dimension", size
->length
);
4870 ippAddCollection(media_col
, IPP_TAG_PRINTER
, "media-size", media_size
);
4871 ippDelete(media_size
);
4873 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4874 "media-bottom-margin", size
->bottom
);
4875 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4876 "media-left-margin", size
->left
);
4877 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4878 "media-right-margin", size
->right
);
4879 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4880 "media-top-margin", size
->top
);
4883 ippAddString(media_col
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
, "media-source",
4887 ippAddString(media_col
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
, "media-type",
4895 * 'write_xml_string()' - Write a string with XML escaping.
4899 write_xml_string(cups_file_t
*fp
, /* I - File to write to */
4900 const char *s
) /* I - String to write */
4902 const char *start
; /* Start of current sequence */
4908 for (start
= s
; *s
; s
++)
4913 cupsFileWrite(fp
, start
, s
- start
);
4915 cupsFilePuts(fp
, "&");
4921 cupsFileWrite(fp
, start
, s
- start
);
4923 cupsFilePuts(fp
, "<");
4929 cupsFilePuts(fp
, start
);
4934 * End of "$Id: printers.c 11623 2014-02-19 20:18:10Z msweet $".