2 * "$Id: printers.c 7968 2008-09-19 23:03:01Z mike $"
4 * Printer routines for the CUPS scheduler.
6 * Copyright 2007-2011 by Apple Inc.
7 * Copyright 1997-2007 by Easy Software Products, all rights reserved.
9 * These coded instructions, statements, and computer programs are the
10 * property of Apple Inc. and are protected by Federal copyright
11 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
12 * which should have been included with this file. If this file is
13 * file is missing or damaged, see the license at "http://www.cups.org/".
17 * cupsdAddPrinter() - Add a printer to the system.
18 * cupsdCreateCommonData() - Create the common printer data.
19 * cupsdDeleteAllPrinters() - Delete all printers from the system.
20 * cupsdDeletePrinter() - Delete a printer from the system.
21 * cupsdFindDest() - Find a destination in the list.
22 * cupsdFindPrinter() - Find a printer in the list.
23 * cupsdLoadAllPrinters() - Load printers from the printers.conf file.
24 * cupsdRenamePrinter() - Rename a printer.
25 * cupsdSaveAllPrinters() - Save all printer definitions to the
27 * cupsdSetAuthInfoRequired() - Set the required authentication info.
28 * cupsdSetDeviceURI() - Set the device URI for a printer.
29 * cupsdSetPrinterAttr() - Set a printer attribute.
30 * cupsdSetPrinterAttrs() - Set printer attributes based upon the PPD
32 * cupsdSetPrinterReasons() - Set/update the reasons strings.
33 * cupsdSetPrinterState() - Update the current state of a printer.
34 * cupsdStopPrinter() - Stop a printer from printing any jobs...
35 * cupsdUpdatePrinterPPD() - Update keywords in a printer's PPD file.
36 * cupsdUpdatePrinters() - Update printers after a partial reload.
37 * cupsdValidateDest() - Validate a printer/class destination.
38 * cupsdWritePrintcap() - Write a pseudo-printcap file for older
39 * applications that need it...
40 * add_printer_defaults() - Add name-default attributes to the printer
42 * add_printer_filter() - Add a MIME filter for a printer.
43 * add_printer_formats() - Add document-format-supported values for a
45 * compare_printers() - Compare two printers.
46 * delete_printer_filters() - Delete all MIME filters for a printer.
47 * dirty_printer() - Mark config and state files dirty for the
49 * load_ppd() - Load a cached PPD file, updating the cache as
51 * new_media_col() - Create a media-col collection value.
52 * write_irix_config() - Update the config files used by the IRIX
54 * write_irix_state() - Update the status files used by IRIX printing
56 * write_xml_string() - Write a string with XML escaping.
60 * Include necessary headers...
65 #ifdef HAVE_APPLICATIONSERVICES_H
66 # include <ApplicationServices/ApplicationServices.h>
67 #endif /* HAVE_APPLICATIONSERVICES_H */
68 #ifdef HAVE_SYS_MOUNT_H
69 # include <sys/mount.h>
70 #endif /* HAVE_SYS_MOUNT_H */
71 #ifdef HAVE_SYS_STATVFS_H
72 # include <sys/statvfs.h>
73 #elif defined(HAVE_SYS_STATFS_H)
74 # include <sys/statfs.h>
75 #endif /* HAVE_SYS_STATVFS_H */
78 #endif /* HAVE_SYS_VFS_H */
85 static void add_printer_defaults(cupsd_printer_t
*p
);
86 static void add_printer_filter(cupsd_printer_t
*p
, mime_type_t
*type
,
88 static void add_printer_formats(cupsd_printer_t
*p
);
89 static int compare_printers(void *first
, void *second
, void *data
);
90 static void delete_printer_filters(cupsd_printer_t
*p
);
91 static void dirty_printer(cupsd_printer_t
*p
);
92 static void load_ppd(cupsd_printer_t
*p
);
93 static ipp_t
*new_media_col(_pwg_size_t
*size
, const char *source
,
96 static void write_irix_config(cupsd_printer_t
*p
);
97 static void write_irix_state(cupsd_printer_t
*p
);
99 static void write_xml_string(cups_file_t
*fp
, const char *s
);
103 * 'cupsdAddPrinter()' - Add a printer to the system.
106 cupsd_printer_t
* /* O - New printer */
107 cupsdAddPrinter(const char *name
) /* I - Name of printer */
109 cupsd_printer_t
*p
; /* New printer */
110 char uri
[1024], /* Printer URI */
111 uuid
[64]; /* Printer UUID */
115 * Range check input...
118 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdAddPrinter(\"%s\")", name
);
121 * Create a new printer entity...
124 if ((p
= calloc(1, sizeof(cupsd_printer_t
))) == NULL
)
126 cupsdLogMessage(CUPSD_LOG_CRIT
, "Unable to allocate memory for printer - %s",
131 cupsdSetString(&p
->name
, name
);
132 cupsdSetString(&p
->info
, name
);
133 cupsdSetString(&p
->hostname
, ServerName
);
135 httpAssembleURIf(HTTP_URI_CODING_ALL
, uri
, sizeof(uri
), "ipp", NULL
,
136 ServerName
, RemotePort
, "/printers/%s", name
);
137 cupsdSetString(&p
->uri
, uri
);
138 cupsdSetString(&p
->uuid
, _httpAssembleUUID(ServerName
, RemotePort
, name
, 0,
139 uuid
, sizeof(uuid
)));
140 cupsdSetDeviceURI(p
, "file:///dev/null");
142 p
->state
= IPP_PRINTER_STOPPED
;
143 p
->state_time
= time(NULL
);
145 p
->shared
= DefaultShared
;
146 p
->filetype
= mimeAddType(MimeDatabase
, "printer", name
);
148 cupsdSetString(&p
->job_sheets
[0], "none");
149 cupsdSetString(&p
->job_sheets
[1], "none");
151 cupsdSetString(&p
->error_policy
, ErrorPolicy
);
152 cupsdSetString(&p
->op_policy
, DefaultPolicy
);
154 p
->op_policy_ptr
= DefaultPolicyPtr
;
157 * Insert the printer in the printer list alphabetically...
161 Printers
= cupsArrayNew(compare_printers
, NULL
);
163 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
164 "cupsdAddPrinter: Adding %s to Printers", p
->name
);
165 cupsArrayAdd(Printers
, p
);
167 if (!ImplicitPrinters
)
168 ImplicitPrinters
= cupsArrayNew(compare_printers
, NULL
);
171 * Return the new printer...
179 * 'cupsdCreateCommonData()' - Create the common printer data.
183 cupsdCreateCommonData(void)
185 int i
; /* Looping var */
186 ipp_attribute_t
*attr
; /* Attribute data */
187 cups_dir_t
*dir
; /* Notifier directory */
188 cups_dentry_t
*dent
; /* Notifier directory entry */
189 cups_array_t
*notifiers
; /* Notifier array */
190 char filename
[1024], /* Filename */
191 *notifier
; /* Current notifier */
192 cupsd_policy_t
*p
; /* Current policy */
193 int k_supported
; /* Maximum file size supported */
195 struct statvfs spoolinfo
; /* FS info for spool directory */
196 double spoolsize
; /* FS size */
197 #elif defined(HAVE_STATFS)
198 struct statfs spoolinfo
; /* FS info for spool directory */
199 double spoolsize
; /* FS size */
200 #endif /* HAVE_STATVFS */
201 static const int nups
[] = /* number-up-supported values */
202 { 1, 2, 4, 6, 9, 16 };
203 static const int orients
[4] =/* orientation-requested-supported values */
207 IPP_REVERSE_LANDSCAPE
,
210 static const char * const holds
[] = /* job-hold-until-supported values */
221 static const char * const versions
[] =/* ipp-versions-supported values */
228 static const int ops
[] = /* operations-supported values */
235 IPP_GET_JOB_ATTRIBUTES
,
237 IPP_GET_PRINTER_ATTRIBUTES
,
244 IPP_SET_PRINTER_ATTRIBUTES
,
245 IPP_SET_JOB_ATTRIBUTES
,
246 IPP_GET_PRINTER_SUPPORTED_VALUES
,
247 IPP_CREATE_PRINTER_SUBSCRIPTION
,
248 IPP_CREATE_JOB_SUBSCRIPTION
,
249 IPP_GET_SUBSCRIPTION_ATTRIBUTES
,
250 IPP_GET_SUBSCRIPTIONS
,
251 IPP_RENEW_SUBSCRIPTION
,
252 IPP_CANCEL_SUBSCRIPTION
,
253 IPP_GET_NOTIFICATIONS
,
257 IPP_RELEASE_HELD_NEW_JOBS
,
274 CUPS_AUTHENTICATE_JOB
,
279 static const char * const charsets
[] =/* charset-supported values */
284 static const char * const compressions
[] =
285 { /* document-compression-supported values */
289 #endif /* HAVE_LIBZ */
291 static const char * const media_col_supported
[] =
292 { /* media-col-supported values */
293 "media-bottom-margin",
295 "media-right-margin",
301 static const char * const multiple_document_handling
[] =
302 { /* multiple-document-handling-supported values */
303 "separate-documents-uncollated-copies",
304 "separate-documents-collated-copies"
306 static const char * const notify_attrs
[] =
307 { /* notify-attributes-supported values */
308 "printer-state-change-time",
309 "notify-lease-expiration-time",
310 "notify-subscriber-user-name"
312 static const char * const notify_events
[] =
313 { /* notify-events-supported values */
315 "job-config-changed",
322 "printer-config-changed",
324 "printer-finishings-changed",
325 "printer-media-changed",
329 "printer-state-changed",
336 static const char * const job_creation
[] =
337 { /* job-creation-attributes-supported */
340 "ipp-attribute-fidelity",
347 "multiple-document-handling",
351 "orientation-requested",
354 "printer-resolution",
357 static const char * const job_settable
[] =
358 { /* job-settable-attributes-supported */
366 "multiple-document-handling",
370 "orientation-requested",
373 "printer-resolution",
376 static const char * const pdf_versions
[] =
377 { /* pdf-versions-supported */
388 static const char * const printer_settable
[] =
389 { /* printer-settable-attributes-supported */
393 static const char * const which_jobs
[] =
394 { /* which-jobs-supported values */
408 ippDelete(CommonData
);
410 CommonData
= ippNew();
413 * Get the maximum spool size based on the size of the filesystem used for
414 * the RequestRoot directory. If the host OS doesn't support the statfs call
415 * or the filesystem is larger than 2TiB, always report INT_MAX.
419 if (statvfs(RequestRoot
, &spoolinfo
))
420 k_supported
= INT_MAX
;
421 else if ((spoolsize
= (double)spoolinfo
.f_frsize
* spoolinfo
.f_blocks
/ 1024) >
423 k_supported
= INT_MAX
;
425 k_supported
= (int)spoolsize
;
427 #elif defined(HAVE_STATFS)
428 if (statfs(RequestRoot
, &spoolinfo
))
429 k_supported
= INT_MAX
;
430 else if ((spoolsize
= (double)spoolinfo
.f_bsize
* spoolinfo
.f_blocks
/ 1024) >
432 k_supported
= INT_MAX
;
434 k_supported
= (int)spoolsize
;
437 k_supported
= INT_MAX
;
438 #endif /* HAVE_STATVFS */
441 * This list of attributes is sorted to improve performance when the
442 * client provides a requested-attributes attribute...
445 /* charset-configured */
446 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_CHARSET
| IPP_TAG_COPY
,
447 "charset-configured", NULL
, "utf-8");
449 /* charset-supported */
450 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_CHARSET
| IPP_TAG_COPY
,
451 "charset-supported", sizeof(charsets
) / sizeof(charsets
[0]),
454 /* compression-supported */
455 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
456 "compression-supported",
457 sizeof(compressions
) / sizeof(compressions
[0]),
460 /* copies-supported */
461 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "copies-supported", 1, MaxCopies
);
464 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
| IPP_TAG_COPY
,
465 "cups-version", NULL
, CUPS_SVERSION
+ 6);
467 /* generated-natural-language-supported (no IPP_TAG_COPY) */
468 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_LANGUAGE
,
469 "generated-natural-language-supported", NULL
, DefaultLanguage
);
471 /* ipp-versions-supported */
472 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
473 "ipp-versions-supported", sizeof(versions
) / sizeof(versions
[0]),
476 /* ippget-event-life */
477 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
478 "ippget-event-life", 15);
480 /* job-creation-attributes-supported */
481 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
482 "job-creation-attributes-supported",
483 sizeof(job_creation
) / sizeof(job_creation
[0]),
486 /* job-hold-until-supported */
487 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
488 "job-hold-until-supported", sizeof(holds
) / sizeof(holds
[0]),
491 /* job-ids-supported */
492 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
, "job-ids-supported", 1);
494 /* job-k-octets-supported */
495 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
496 "job-k-octets-supported", k_supported
);
498 /* job-priority-supported */
499 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
500 "job-priority-supported", 100);
502 /* job-settable-attributes-supported */
503 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
504 "job-settable-attributes-supported",
505 sizeof(job_settable
) / sizeof(job_settable
[0]),
508 /* job-sheets-supported */
509 if (cupsArrayCount(Banners
) > 0)
512 * Setup the job-sheets-supported attribute...
515 if (Classification
&& !ClassifyOverride
)
516 attr
= ippAddString(CommonData
, IPP_TAG_PRINTER
,
517 IPP_TAG_NAME
| IPP_TAG_COPY
,
518 "job-sheets-supported", NULL
, Classification
);
520 attr
= ippAddStrings(CommonData
, IPP_TAG_PRINTER
,
521 IPP_TAG_NAME
| IPP_TAG_COPY
,
522 "job-sheets-supported", cupsArrayCount(Banners
) + 1,
526 cupsdLogMessage(CUPSD_LOG_EMERG
,
527 "Unable to allocate memory for "
528 "job-sheets-supported attribute: %s!", strerror(errno
));
529 else if (!Classification
|| ClassifyOverride
)
531 cupsd_banner_t
*banner
; /* Current banner */
534 attr
->values
[0].string
.text
= _cupsStrAlloc("none");
536 for (i
= 1, banner
= (cupsd_banner_t
*)cupsArrayFirst(Banners
);
538 i
++, banner
= (cupsd_banner_t
*)cupsArrayNext(Banners
))
539 attr
->values
[i
].string
.text
= banner
->name
;
543 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
544 "job-sheets-supported", NULL
, "none");
546 /* jpeg-k-octets-supported */
547 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "jpeg-k-octets-supported", 0,
550 /* jpeg-x-dimension-supported */
551 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "jpeg-x-dimension-supported", 0,
554 /* jpeg-y-dimension-supported */
555 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "jpeg-y-dimension-supported", 1,
558 /* media-col-supported */
559 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
560 "media-col-supported",
561 sizeof(media_col_supported
) /
562 sizeof(media_col_supported
[0]), NULL
,
563 media_col_supported
);
565 /* multiple-document-handling-supported */
566 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
567 "multiple-document-handling-supported",
568 sizeof(multiple_document_handling
) /
569 sizeof(multiple_document_handling
[0]), NULL
,
570 multiple_document_handling
);
572 /* multiple-document-jobs-supported */
573 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
,
574 "multiple-document-jobs-supported", 1);
576 /* multiple-operation-time-out */
577 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
578 "multiple-operation-time-out", MultipleOperationTimeout
);
580 /* natural-language-configured (no IPP_TAG_COPY) */
581 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_LANGUAGE
,
582 "natural-language-configured", NULL
, DefaultLanguage
);
584 /* notify-attributes-supported */
585 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
586 "notify-attributes-supported",
587 (int)(sizeof(notify_attrs
) / sizeof(notify_attrs
[0])),
590 /* notify-lease-duration-supported */
591 ippAddRange(CommonData
, IPP_TAG_PRINTER
,
592 "notify-lease-duration-supported", 0,
593 MaxLeaseDuration
? MaxLeaseDuration
: 2147483647);
595 /* notify-max-events-supported */
596 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
597 "notify-max-events-supported", MaxEvents
);
599 /* notify-events-supported */
600 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
601 "notify-events-supported",
602 (int)(sizeof(notify_events
) / sizeof(notify_events
[0])),
603 NULL
, notify_events
);
605 /* notify-pull-method-supported */
606 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
607 "notify-pull-method-supported", NULL
, "ippget");
609 /* notify-schemes-supported */
610 snprintf(filename
, sizeof(filename
), "%s/notifier", ServerBin
);
611 if ((dir
= cupsDirOpen(filename
)) != NULL
)
613 notifiers
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
615 while ((dent
= cupsDirRead(dir
)) != NULL
)
616 if (S_ISREG(dent
->fileinfo
.st_mode
) &&
617 (dent
->fileinfo
.st_mode
& S_IXOTH
) != 0)
618 cupsArrayAdd(notifiers
, _cupsStrAlloc(dent
->filename
));
620 if (cupsArrayCount(notifiers
) > 0)
622 attr
= ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
623 "notify-schemes-supported",
624 cupsArrayCount(notifiers
), NULL
, NULL
);
626 for (i
= 0, notifier
= (char *)cupsArrayFirst(notifiers
);
628 i
++, notifier
= (char *)cupsArrayNext(notifiers
))
629 attr
->values
[i
].string
.text
= notifier
;
632 cupsArrayDelete(notifiers
);
636 /* number-up-supported */
637 ippAddIntegers(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
638 "number-up-supported", sizeof(nups
) / sizeof(nups
[0]), nups
);
640 /* operations-supported */
641 ippAddIntegers(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
642 "operations-supported",
643 sizeof(ops
) / sizeof(ops
[0]) + JobFiles
- 1, ops
);
645 /* orientation-requested-supported */
646 ippAddIntegers(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
647 "orientation-requested-supported", 4, orients
);
649 /* page-ranges-supported */
650 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
, "page-ranges-supported", 1);
652 /* pdf-k-octets-supported */
653 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "pdf-k-octets-supported", 0,
656 /* pdf-versions-supported */
657 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
658 "pdf-versions-supported",
659 sizeof(pdf_versions
) / sizeof(pdf_versions
[0]), NULL
,
662 /* pdl-override-supported */
663 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
664 "pdl-override-supported", NULL
, "attempted");
666 /* printer-op-policy-supported */
667 attr
= ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
668 "printer-op-policy-supported", cupsArrayCount(Policies
),
670 for (i
= 0, p
= (cupsd_policy_t
*)cupsArrayFirst(Policies
);
672 i
++, p
= (cupsd_policy_t
*)cupsArrayNext(Policies
))
673 attr
->values
[i
].string
.text
= p
->name
;
675 /* printer-settable-attributes-supported */
676 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
677 "printer-settable-attributes-supported",
678 sizeof(printer_settable
) / sizeof(printer_settable
[0]),
679 NULL
, printer_settable
);
681 /* server-is-sharing-printers */
682 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
, "server-is-sharing-printers",
683 BrowseLocalProtocols
!= 0 && Browsing
);
685 /* which-jobs-supported */
686 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
687 "which-jobs-supported",
688 sizeof(which_jobs
) / sizeof(which_jobs
[0]), NULL
, which_jobs
);
693 * 'cupsdDeleteAllPrinters()' - Delete all printers from the system.
697 cupsdDeleteAllPrinters(void)
699 cupsd_printer_t
*p
; /* Pointer to current printer/class */
702 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
704 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
706 p
->op_policy_ptr
= DefaultPolicyPtr
;
707 cupsdDeletePrinter(p
, 0);
713 * 'cupsdDeletePrinter()' - Delete a printer from the system.
716 int /* O - 1 if classes affected, 0 otherwise */
718 cupsd_printer_t
*p
, /* I - Printer to delete */
719 int update
) /* I - Update printers.conf? */
721 int i
, /* Looping var */
722 changed
= 0; /* Class changed? */
724 char filename
[1024]; /* Interface script filename */
728 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdDeletePrinter(p=%p(%s), update=%d)",
732 * Save the current position in the Printers array...
735 cupsArraySave(Printers
);
738 * Stop printing on this printer...
741 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, update
);
743 p
->state
= IPP_PRINTER_STOPPED
; /* Force for browsed printers */
746 cupsdSetJobState(p
->job
, IPP_JOB_PENDING
, CUPSD_JOB_FORCE
,
747 update
? "Job stopped due to printer being deleted." :
751 * If this printer is the next for browsing, point to the next one...
756 cupsArrayFind(Printers
, p
);
757 BrowseNext
= (cupsd_printer_t
*)cupsArrayNext(Printers
);
761 * Remove the printer from the list...
764 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
765 "cupsdDeletePrinter: Removing %s from Printers", p
->name
);
766 cupsArrayRemove(Printers
, p
);
768 if (p
->type
& CUPS_PRINTER_IMPLICIT
)
770 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
771 "cupsdDeletePrinter: Removing %s from ImplicitPrinters",
773 cupsArrayRemove(ImplicitPrinters
, p
);
777 * Remove the dummy interface/icon/option files under IRIX...
781 snprintf(filename
, sizeof(filename
), "/var/spool/lp/interface/%s", p
->name
);
784 snprintf(filename
, sizeof(filename
), "/var/spool/lp/gui_interface/ELF/%s.gui",
788 snprintf(filename
, sizeof(filename
), "/var/spool/lp/activeicons/%s", p
->name
);
791 snprintf(filename
, sizeof(filename
), "/var/spool/lp/pod/%s.config", p
->name
);
794 snprintf(filename
, sizeof(filename
), "/var/spool/lp/pod/%s.status", p
->name
);
797 snprintf(filename
, sizeof(filename
), "/var/spool/lp/member/%s", p
->name
);
802 * If p is the default printer, assign a different one...
805 if (p
== DefaultPrinter
)
807 DefaultPrinter
= NULL
;
809 if (UseNetworkDefault
)
812 * Find the first network default printer and use it...
815 cupsd_printer_t
*dp
; /* New default printer */
818 for (dp
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
820 dp
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
821 if (dp
!= p
&& (dp
->type
& CUPS_PRINTER_DEFAULT
))
830 * Remove this printer from any classes...
833 if (!(p
->type
& CUPS_PRINTER_IMPLICIT
))
835 changed
= cupsdDeletePrinterFromClasses(p
);
838 * Deregister from any browse protocols...
841 cupsdDeregisterPrinter(p
, 1);
845 * Free all memory used by the printer...
848 if (p
->printers
!= NULL
)
851 delete_printer_filters(p
);
853 for (i
= 0; i
< p
->num_reasons
; i
++)
854 _cupsStrFree(p
->reasons
[i
]);
857 ippDelete(p
->ppd_attrs
);
859 mimeDeleteType(MimeDatabase
, p
->filetype
);
860 mimeDeleteType(MimeDatabase
, p
->prefiltertype
);
862 cupsdFreeStrings(&(p
->users
));
865 cupsdClearString(&p
->uri
);
866 cupsdClearString(&p
->hostname
);
867 cupsdClearString(&p
->name
);
868 cupsdClearString(&p
->location
);
869 cupsdClearString(&p
->make_model
);
870 cupsdClearString(&p
->info
);
871 cupsdClearString(&p
->job_sheets
[0]);
872 cupsdClearString(&p
->job_sheets
[1]);
873 cupsdClearString(&p
->device_uri
);
874 cupsdClearString(&p
->sanitized_device_uri
);
875 cupsdClearString(&p
->port_monitor
);
876 cupsdClearString(&p
->op_policy
);
877 cupsdClearString(&p
->error_policy
);
879 cupsdClearString(&p
->alert
);
880 cupsdClearString(&p
->alert_description
);
883 cupsdClearString(&p
->pdl
);
884 #endif /* HAVE_DNSSD */
886 cupsArrayDelete(p
->filetypes
);
889 free(p
->browse_attrs
);
891 cupsFreeOptions(p
->num_options
, p
->options
);
896 * Restore the previous position in the Printers array...
899 cupsArrayRestore(Printers
);
906 * 'cupsdFindDest()' - Find a destination in the list.
909 cupsd_printer_t
* /* O - Destination in list */
910 cupsdFindDest(const char *name
) /* I - Name of printer or class to find */
912 cupsd_printer_t key
; /* Search key */
915 key
.name
= (char *)name
;
916 return ((cupsd_printer_t
*)cupsArrayFind(Printers
, &key
));
921 * 'cupsdFindPrinter()' - Find a printer in the list.
924 cupsd_printer_t
* /* O - Printer in list */
925 cupsdFindPrinter(const char *name
) /* I - Name of printer to find */
927 cupsd_printer_t
*p
; /* Printer in list */
930 if ((p
= cupsdFindDest(name
)) != NULL
&& (p
->type
& CUPS_PRINTER_CLASS
))
938 * 'cupsdLoadAllPrinters()' - Load printers from the printers.conf file.
942 cupsdLoadAllPrinters(void)
944 int i
; /* Looping var */
945 cups_file_t
*fp
; /* printers.conf file */
946 int linenum
; /* Current line number */
947 char line
[4096], /* Line from file */
948 *value
, /* Pointer to value */
949 *valueptr
; /* Pointer into value */
950 cupsd_printer_t
*p
; /* Current printer */
954 * Open the printers.conf file...
957 snprintf(line
, sizeof(line
), "%s/printers.conf", ServerRoot
);
958 if ((fp
= cupsFileOpen(line
, "r")) == NULL
)
961 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to open %s - %s", line
,
967 * Read printer configurations until we hit EOF...
973 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
976 * Decode the directive...
979 if (!strcasecmp(line
, "<Printer") ||
980 !strcasecmp(line
, "<DefaultPrinter"))
983 * <Printer name> or <DefaultPrinter name>
986 if (p
== NULL
&& value
)
989 * Add the printer and a base file type...
992 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Loading printer %s...", value
);
994 p
= cupsdAddPrinter(value
);
996 p
->state
= IPP_PRINTER_IDLE
;
999 * Set the default printer as needed...
1002 if (!strcasecmp(line
, "<DefaultPrinter"))
1006 cupsdLogMessage(CUPSD_LOG_ERROR
,
1007 "Syntax error on line %d of printers.conf.", linenum
);
1009 else if (!strcasecmp(line
, "</Printer>"))
1014 * Close out the current printer...
1017 cupsdSetPrinterAttrs(p
);
1019 if (strncmp(p
->device_uri
, "file:", 5) &&
1020 p
->state
!= IPP_PRINTER_STOPPED
)
1023 * See if the backend exists...
1026 snprintf(line
, sizeof(line
), "%s/backend/%s", ServerBin
,
1029 if ((valueptr
= strchr(line
+ strlen(ServerBin
), ':')) != NULL
)
1030 *valueptr
= '\0'; /* Chop everything but URI scheme */
1032 if (access(line
, 0))
1035 * Backend does not exist, stop printer...
1038 p
->state
= IPP_PRINTER_STOPPED
;
1039 snprintf(p
->state_message
, sizeof(p
->state_message
),
1040 "Backend %s does not exist!", line
);
1047 cupsdLogMessage(CUPSD_LOG_ERROR
,
1048 "Syntax error on line %d of printers.conf.", linenum
);
1052 cupsdLogMessage(CUPSD_LOG_ERROR
,
1053 "Syntax error on line %d of printers.conf.", linenum
);
1055 else if (!strcasecmp(line
, "UUID"))
1057 if (value
&& !strncmp(value
, "urn:uuid:", 9))
1058 cupsdSetString(&(p
->uuid
), value
);
1060 cupsdLogMessage(CUPSD_LOG_ERROR
,
1061 "Bad UUID on line %d of printers.conf.", linenum
);
1063 else if (!strcasecmp(line
, "AuthInfoRequired"))
1065 if (!cupsdSetAuthInfoRequired(p
, value
, NULL
))
1066 cupsdLogMessage(CUPSD_LOG_ERROR
,
1067 "Bad AuthInfoRequired on line %d of printers.conf.",
1070 else if (!strcasecmp(line
, "Info"))
1073 cupsdSetString(&p
->info
, value
);
1075 else if (!strcasecmp(line
, "MakeModel"))
1078 cupsdSetString(&p
->make_model
, value
);
1080 else if (!strcasecmp(line
, "Location"))
1083 cupsdSetString(&p
->location
, value
);
1085 else if (!strcasecmp(line
, "DeviceURI"))
1088 cupsdSetDeviceURI(p
, value
);
1090 cupsdLogMessage(CUPSD_LOG_ERROR
,
1091 "Syntax error on line %d of printers.conf.", linenum
);
1093 else if (!strcasecmp(line
, "Option") && value
)
1099 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1102 cupsdLogMessage(CUPSD_LOG_ERROR
,
1103 "Syntax error on line %d of printers.conf.", linenum
);
1106 for (; *valueptr
&& isspace(*valueptr
& 255); *valueptr
++ = '\0');
1108 p
->num_options
= cupsAddOption(value
, valueptr
, p
->num_options
,
1112 else if (!strcasecmp(line
, "PortMonitor"))
1114 if (value
&& strcmp(value
, "none"))
1115 cupsdSetString(&p
->port_monitor
, value
);
1117 cupsdClearString(&p
->port_monitor
);
1119 cupsdLogMessage(CUPSD_LOG_ERROR
,
1120 "Syntax error on line %d of printers.conf.", linenum
);
1122 else if (!strcasecmp(line
, "Reason"))
1125 strcmp(value
, "connecting-to-device") &&
1126 strcmp(value
, "cups-insecure-filter-warning") &&
1127 strcmp(value
, "cups-missing-filter-warning"))
1129 for (i
= 0 ; i
< p
->num_reasons
; i
++)
1130 if (!strcmp(value
, p
->reasons
[i
]))
1133 if (i
>= p
->num_reasons
&&
1134 p
->num_reasons
< (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
1136 p
->reasons
[p
->num_reasons
] = _cupsStrAlloc(value
);
1141 cupsdLogMessage(CUPSD_LOG_ERROR
,
1142 "Syntax error on line %d of printers.conf.", linenum
);
1144 else if (!strcasecmp(line
, "State"))
1147 * Set the initial queue state...
1150 if (value
&& !strcasecmp(value
, "idle"))
1151 p
->state
= IPP_PRINTER_IDLE
;
1152 else if (value
&& !strcasecmp(value
, "stopped"))
1154 p
->state
= IPP_PRINTER_STOPPED
;
1156 for (i
= 0 ; i
< p
->num_reasons
; i
++)
1157 if (!strcmp("paused", p
->reasons
[i
]))
1160 if (i
>= p
->num_reasons
&&
1161 p
->num_reasons
< (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
1163 p
->reasons
[p
->num_reasons
] = _cupsStrAlloc("paused");
1168 cupsdLogMessage(CUPSD_LOG_ERROR
,
1169 "Syntax error on line %d of printers.conf.", linenum
);
1171 else if (!strcasecmp(line
, "StateMessage"))
1174 * Set the initial queue state message...
1178 strlcpy(p
->state_message
, value
, sizeof(p
->state_message
));
1180 else if (!strcasecmp(line
, "StateTime"))
1183 * Set the state time...
1187 p
->state_time
= atoi(value
);
1189 else if (!strcasecmp(line
, "Accepting"))
1192 * Set the initial accepting state...
1196 (!strcasecmp(value
, "yes") ||
1197 !strcasecmp(value
, "on") ||
1198 !strcasecmp(value
, "true")))
1201 (!strcasecmp(value
, "no") ||
1202 !strcasecmp(value
, "off") ||
1203 !strcasecmp(value
, "false")))
1206 cupsdLogMessage(CUPSD_LOG_ERROR
,
1207 "Syntax error on line %d of printers.conf.", linenum
);
1209 else if (!strcasecmp(line
, "Type"))
1212 p
->type
= atoi(value
);
1214 cupsdLogMessage(CUPSD_LOG_ERROR
,
1215 "Syntax error on line %d of printers.conf.", linenum
);
1217 else if (!strcasecmp(line
, "Shared"))
1220 * Set the initial shared state...
1224 (!strcasecmp(value
, "yes") ||
1225 !strcasecmp(value
, "on") ||
1226 !strcasecmp(value
, "true")))
1229 (!strcasecmp(value
, "no") ||
1230 !strcasecmp(value
, "off") ||
1231 !strcasecmp(value
, "false")))
1234 cupsdLogMessage(CUPSD_LOG_ERROR
,
1235 "Syntax error on line %d of printers.conf.", linenum
);
1237 else if (!strcasecmp(line
, "JobSheets"))
1240 * Set the initial job sheets...
1245 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1250 cupsdSetString(&p
->job_sheets
[0], value
);
1252 while (isspace(*valueptr
& 255))
1257 for (value
= valueptr
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1262 cupsdSetString(&p
->job_sheets
[1], value
);
1266 cupsdLogMessage(CUPSD_LOG_ERROR
,
1267 "Syntax error on line %d of printers.conf.", linenum
);
1269 else if (!strcasecmp(line
, "AllowUser"))
1274 cupsdAddString(&(p
->users
), value
);
1277 cupsdLogMessage(CUPSD_LOG_ERROR
,
1278 "Syntax error on line %d of printers.conf.", linenum
);
1280 else if (!strcasecmp(line
, "DenyUser"))
1285 cupsdAddString(&(p
->users
), value
);
1288 cupsdLogMessage(CUPSD_LOG_ERROR
,
1289 "Syntax error on line %d of printers.conf.", linenum
);
1291 else if (!strcasecmp(line
, "QuotaPeriod"))
1294 p
->quota_period
= atoi(value
);
1296 cupsdLogMessage(CUPSD_LOG_ERROR
,
1297 "Syntax error on line %d of printers.conf.", linenum
);
1299 else if (!strcasecmp(line
, "PageLimit"))
1302 p
->page_limit
= atoi(value
);
1304 cupsdLogMessage(CUPSD_LOG_ERROR
,
1305 "Syntax error on line %d of printers.conf.", linenum
);
1307 else if (!strcasecmp(line
, "KLimit"))
1310 p
->k_limit
= atoi(value
);
1312 cupsdLogMessage(CUPSD_LOG_ERROR
,
1313 "Syntax error on line %d of printers.conf.", linenum
);
1315 else if (!strcasecmp(line
, "OpPolicy"))
1319 cupsd_policy_t
*pol
; /* Policy */
1322 if ((pol
= cupsdFindPolicy(value
)) != NULL
)
1324 cupsdSetString(&p
->op_policy
, value
);
1325 p
->op_policy_ptr
= pol
;
1328 cupsdLogMessage(CUPSD_LOG_ERROR
,
1329 "Bad policy \"%s\" on line %d of printers.conf",
1333 cupsdLogMessage(CUPSD_LOG_ERROR
,
1334 "Syntax error on line %d of printers.conf.", linenum
);
1336 else if (!strcasecmp(line
, "ErrorPolicy"))
1339 cupsdSetString(&p
->error_policy
, value
);
1341 cupsdLogMessage(CUPSD_LOG_ERROR
,
1342 "Syntax error on line %d of printers.conf.", linenum
);
1344 else if (!strcasecmp(line
, "Attribute") && value
)
1346 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1349 cupsdLogMessage(CUPSD_LOG_ERROR
,
1350 "Syntax error on line %d of printers.conf.", linenum
);
1353 for (; *valueptr
&& isspace(*valueptr
& 255); *valueptr
++ = '\0');
1356 cupsdSetPrinterAttrs(p
);
1358 if (!strcmp(value
, "marker-change-time"))
1359 p
->marker_time
= atoi(valueptr
);
1361 cupsdSetPrinterAttr(p
, value
, valueptr
);
1367 * Something else we don't understand...
1370 cupsdLogMessage(CUPSD_LOG_ERROR
,
1371 "Unknown configuration directive %s on line %d of printers.conf.",
1381 * 'cupsdRenamePrinter()' - Rename a printer.
1386 cupsd_printer_t
*p
, /* I - Printer */
1387 const char *name
) /* I - New name */
1390 * Remove the printer from the array(s) first...
1393 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1394 "cupsdRenamePrinter: Removing %s from Printers", p
->name
);
1395 cupsArrayRemove(Printers
, p
);
1397 if (p
->type
& CUPS_PRINTER_IMPLICIT
)
1399 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1400 "cupsdRenamePrinter: Removing %s from ImplicitPrinters",
1402 cupsArrayRemove(ImplicitPrinters
, p
);
1406 * Rename the printer type...
1409 mimeDeleteType(MimeDatabase
, p
->filetype
);
1410 p
->filetype
= mimeAddType(MimeDatabase
, "printer", name
);
1412 if (p
->prefiltertype
)
1414 mimeDeleteType(MimeDatabase
, p
->prefiltertype
);
1415 p
->prefiltertype
= mimeAddType(MimeDatabase
, "prefilter", name
);
1419 * Rename the printer...
1422 cupsdSetString(&p
->name
, name
);
1425 * Reset printer attributes...
1428 cupsdSetPrinterAttrs(p
);
1431 * Add the printer back to the printer array(s)...
1434 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1435 "cupsdRenamePrinter: Adding %s to Printers", p
->name
);
1436 cupsArrayAdd(Printers
, p
);
1438 if (p
->type
& CUPS_PRINTER_IMPLICIT
)
1440 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1441 "cupsdRenamePrinter: Adding %s to ImplicitPrinters",
1443 cupsArrayAdd(ImplicitPrinters
, p
);
1449 * 'cupsdSaveAllPrinters()' - Save all printer definitions to the printers.conf
1454 cupsdSaveAllPrinters(void)
1456 int i
; /* Looping var */
1457 cups_file_t
*fp
; /* printers.conf file */
1458 char temp
[1024], /* Temporary string */
1459 backup
[1024], /* printers.conf.O file */
1460 value
[2048], /* Value string */
1461 *ptr
, /* Pointer into value */
1462 *name
; /* Current user/group name */
1463 cupsd_printer_t
*printer
; /* Current printer class */
1464 time_t curtime
; /* Current time */
1465 struct tm
*curdate
; /* Current date */
1466 cups_option_t
*option
; /* Current option */
1467 ipp_attribute_t
*marker
; /* Current marker attribute */
1471 * Create the printers.conf file...
1474 snprintf(temp
, sizeof(temp
), "%s/printers.conf", ServerRoot
);
1475 snprintf(backup
, sizeof(backup
), "%s/printers.conf.O", ServerRoot
);
1477 if (rename(temp
, backup
))
1479 if (errno
!= ENOENT
)
1480 cupsdLogMessage(CUPSD_LOG_ERROR
,
1481 "Unable to backup printers.conf - %s", strerror(errno
));
1484 if ((fp
= cupsFileOpen(temp
, "w")) == NULL
)
1486 cupsdLogMessage(CUPSD_LOG_ERROR
,
1487 "Unable to save printers.conf - %s", strerror(errno
));
1489 if (rename(backup
, temp
))
1490 cupsdLogMessage(CUPSD_LOG_ERROR
,
1491 "Unable to restore printers.conf - %s", strerror(errno
));
1495 cupsdLogMessage(CUPSD_LOG_INFO
, "Saving printers.conf...");
1498 * Restrict access to the file...
1501 fchown(cupsFileNumber(fp
), getuid(), Group
);
1502 fchmod(cupsFileNumber(fp
), ConfigFilePerm
& 0600);
1505 * Write a small header to the file...
1508 curtime
= time(NULL
);
1509 curdate
= localtime(&curtime
);
1510 strftime(temp
, sizeof(temp
) - 1, "%Y-%m-%d %H:%M", curdate
);
1512 cupsFilePuts(fp
, "# Printer configuration file for " CUPS_SVERSION
"\n");
1513 cupsFilePrintf(fp
, "# Written by cupsd on %s\n", temp
);
1514 cupsFilePuts(fp
, "# DO NOT EDIT THIS FILE WHEN CUPSD IS RUNNING\n");
1517 * Write each local printer known to the system...
1520 for (printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
1522 printer
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
1525 * Skip remote destinations and printer classes...
1528 if ((printer
->type
& CUPS_PRINTER_DISCOVERED
) ||
1529 (printer
->type
& CUPS_PRINTER_CLASS
) ||
1530 (printer
->type
& CUPS_PRINTER_IMPLICIT
))
1534 * Write printers as needed...
1537 if (printer
== DefaultPrinter
)
1538 cupsFilePrintf(fp
, "<DefaultPrinter %s>\n", printer
->name
);
1540 cupsFilePrintf(fp
, "<Printer %s>\n", printer
->name
);
1542 cupsFilePrintf(fp
, "UUID %s\n", printer
->uuid
);
1544 if (printer
->num_auth_info_required
> 0)
1546 switch (printer
->num_auth_info_required
)
1549 strlcpy(value
, printer
->auth_info_required
[0], sizeof(value
));
1553 snprintf(value
, sizeof(value
), "%s,%s",
1554 printer
->auth_info_required
[0],
1555 printer
->auth_info_required
[1]);
1560 snprintf(value
, sizeof(value
), "%s,%s,%s",
1561 printer
->auth_info_required
[0],
1562 printer
->auth_info_required
[1],
1563 printer
->auth_info_required
[2]);
1567 cupsFilePutConf(fp
, "AuthInfoRequired", value
);
1571 cupsFilePutConf(fp
, "Info", printer
->info
);
1573 if (printer
->location
)
1574 cupsFilePutConf(fp
, "Location", printer
->location
);
1576 if (printer
->make_model
)
1577 cupsFilePutConf(fp
, "MakeModel", printer
->make_model
);
1579 cupsFilePutConf(fp
, "DeviceURI", printer
->device_uri
);
1581 if (printer
->port_monitor
)
1582 cupsFilePutConf(fp
, "PortMonitor", printer
->port_monitor
);
1584 if (printer
->state
== IPP_PRINTER_STOPPED
)
1586 cupsFilePuts(fp
, "State Stopped\n");
1588 if (printer
->state_message
)
1589 cupsFilePutConf(fp
, "StateMessage", printer
->state_message
);
1592 cupsFilePuts(fp
, "State Idle\n");
1594 cupsFilePrintf(fp
, "StateTime %d\n", (int)printer
->state_time
);
1596 for (i
= 0; i
< printer
->num_reasons
; i
++)
1597 if (strcmp(printer
->reasons
[i
], "connecting-to-device") &&
1598 strcmp(printer
->reasons
[i
], "cups-insecure-filter-warning") &&
1599 strcmp(printer
->reasons
[i
], "cups-missing-filter-warning"))
1600 cupsFilePutConf(fp
, "Reason", printer
->reasons
[i
]);
1602 cupsFilePrintf(fp
, "Type %d\n", printer
->type
);
1604 if (printer
->accepting
)
1605 cupsFilePuts(fp
, "Accepting Yes\n");
1607 cupsFilePuts(fp
, "Accepting No\n");
1609 if (printer
->shared
)
1610 cupsFilePuts(fp
, "Shared Yes\n");
1612 cupsFilePuts(fp
, "Shared No\n");
1614 snprintf(value
, sizeof(value
), "%s %s", printer
->job_sheets
[0],
1615 printer
->job_sheets
[1]);
1616 cupsFilePutConf(fp
, "JobSheets", value
);
1618 cupsFilePrintf(fp
, "QuotaPeriod %d\n", printer
->quota_period
);
1619 cupsFilePrintf(fp
, "PageLimit %d\n", printer
->page_limit
);
1620 cupsFilePrintf(fp
, "KLimit %d\n", printer
->k_limit
);
1622 for (name
= (char *)cupsArrayFirst(printer
->users
);
1624 name
= (char *)cupsArrayNext(printer
->users
))
1625 cupsFilePutConf(fp
, printer
->deny_users
? "DenyUser" : "AllowUser", name
);
1627 if (printer
->op_policy
)
1628 cupsFilePutConf(fp
, "OpPolicy", printer
->op_policy
);
1629 if (printer
->error_policy
)
1630 cupsFilePutConf(fp
, "ErrorPolicy", printer
->error_policy
);
1632 for (i
= printer
->num_options
, option
= printer
->options
;
1636 snprintf(value
, sizeof(value
), "%s %s", option
->name
, option
->value
);
1637 cupsFilePutConf(fp
, "Option", value
);
1640 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-colors",
1641 IPP_TAG_NAME
)) != NULL
)
1643 snprintf(value
, sizeof(value
), "%s ", marker
->name
);
1645 for (i
= 0, ptr
= value
+ strlen(value
);
1646 i
< marker
->num_values
&& ptr
< (value
+ sizeof(value
) - 1);
1652 strlcpy(ptr
, marker
->values
[i
].string
.text
,
1653 value
+ sizeof(value
) - ptr
);
1658 cupsFilePutConf(fp
, "Attribute", value
);
1661 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-levels",
1662 IPP_TAG_INTEGER
)) != NULL
)
1664 cupsFilePrintf(fp
, "Attribute %s %d", marker
->name
,
1665 marker
->values
[0].integer
);
1666 for (i
= 1; i
< marker
->num_values
; i
++)
1667 cupsFilePrintf(fp
, ",%d", marker
->values
[i
].integer
);
1668 cupsFilePuts(fp
, "\n");
1671 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-low-levels",
1672 IPP_TAG_INTEGER
)) != NULL
)
1674 cupsFilePrintf(fp
, "Attribute %s %d", marker
->name
,
1675 marker
->values
[0].integer
);
1676 for (i
= 1; i
< marker
->num_values
; i
++)
1677 cupsFilePrintf(fp
, ",%d", marker
->values
[i
].integer
);
1678 cupsFilePuts(fp
, "\n");
1681 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-high-levels",
1682 IPP_TAG_INTEGER
)) != NULL
)
1684 cupsFilePrintf(fp
, "Attribute %s %d", marker
->name
,
1685 marker
->values
[0].integer
);
1686 for (i
= 1; i
< marker
->num_values
; i
++)
1687 cupsFilePrintf(fp
, ",%d", marker
->values
[i
].integer
);
1688 cupsFilePuts(fp
, "\n");
1691 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-message",
1692 IPP_TAG_TEXT
)) != NULL
)
1694 snprintf(value
, sizeof(value
), "%s %s", marker
->name
,
1695 marker
->values
[0].string
.text
);
1697 cupsFilePutConf(fp
, "Attribute", value
);
1700 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-names",
1701 IPP_TAG_NAME
)) != NULL
)
1703 snprintf(value
, sizeof(value
), "%s ", marker
->name
);
1705 for (i
= 0, ptr
= value
+ strlen(value
);
1706 i
< marker
->num_values
&& ptr
< (value
+ sizeof(value
) - 1);
1712 strlcpy(ptr
, marker
->values
[i
].string
.text
,
1713 value
+ sizeof(value
) - ptr
);
1718 cupsFilePutConf(fp
, "Attribute", value
);
1721 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-types",
1722 IPP_TAG_KEYWORD
)) != NULL
)
1724 snprintf(value
, sizeof(value
), "%s ", marker
->name
);
1726 for (i
= 0, ptr
= value
+ strlen(value
);
1727 i
< marker
->num_values
&& ptr
< (value
+ sizeof(value
) - 1);
1733 strlcpy(ptr
, marker
->values
[i
].string
.text
,
1734 value
+ sizeof(value
) - ptr
);
1739 cupsFilePutConf(fp
, "Attribute", value
);
1742 if (printer
->marker_time
)
1743 cupsFilePrintf(fp
, "Attribute marker-change-time %ld\n",
1744 (long)printer
->marker_time
);
1746 cupsFilePuts(fp
, "</Printer>\n");
1750 * Make IRIX desktop & printer status happy
1753 write_irix_state(printer
);
1762 * 'cupsdSetAuthInfoRequired()' - Set the required authentication info.
1765 int /* O - 1 if value OK, 0 otherwise */
1766 cupsdSetAuthInfoRequired(
1767 cupsd_printer_t
*p
, /* I - Printer */
1768 const char *values
, /* I - Plain text value (or NULL) */
1769 ipp_attribute_t
*attr
) /* I - IPP attribute value (or NULL) */
1771 int i
; /* Looping var */
1774 p
->num_auth_info_required
= 0;
1777 * Do we have a plain text value?
1783 * Yes, grab the keywords...
1786 const char *end
; /* End of current value */
1789 while (*values
&& p
->num_auth_info_required
< 4)
1791 if ((end
= strchr(values
, ',')) == NULL
)
1792 end
= values
+ strlen(values
);
1794 if ((end
- values
) == 4 && !strncmp(values
, "none", 4))
1796 if (p
->num_auth_info_required
!= 0 || *end
)
1799 p
->auth_info_required
[p
->num_auth_info_required
] = "none";
1800 p
->num_auth_info_required
++;
1804 else if ((end
- values
) == 9 && !strncmp(values
, "negotiate", 9))
1806 if (p
->num_auth_info_required
!= 0 || *end
)
1809 p
->auth_info_required
[p
->num_auth_info_required
] = "negotiate";
1810 p
->num_auth_info_required
++;
1813 * Don't allow sharing of queues that require Kerberos authentication.
1818 cupsdDeregisterPrinter(p
, 1);
1822 else if ((end
- values
) == 6 && !strncmp(values
, "domain", 6))
1824 p
->auth_info_required
[p
->num_auth_info_required
] = "domain";
1825 p
->num_auth_info_required
++;
1827 else if ((end
- values
) == 8 && !strncmp(values
, "password", 8))
1829 p
->auth_info_required
[p
->num_auth_info_required
] = "password";
1830 p
->num_auth_info_required
++;
1832 else if ((end
- values
) == 8 && !strncmp(values
, "username", 8))
1834 p
->auth_info_required
[p
->num_auth_info_required
] = "username";
1835 p
->num_auth_info_required
++;
1840 values
= (*end
) ? end
+ 1 : end
;
1843 if (p
->num_auth_info_required
== 0)
1845 p
->auth_info_required
[0] = "none";
1846 p
->num_auth_info_required
= 1;
1850 * Update the printer-type value as needed...
1853 if (p
->num_auth_info_required
> 1 ||
1854 strcmp(p
->auth_info_required
[0], "none"))
1855 p
->type
|= CUPS_PRINTER_AUTHENTICATED
;
1857 p
->type
&= ~CUPS_PRINTER_AUTHENTICATED
;
1863 * Grab values from an attribute instead...
1866 if (!attr
|| attr
->num_values
> 4)
1870 * Update the printer-type value as needed...
1873 if (attr
->num_values
> 1 ||
1874 strcmp(attr
->values
[0].string
.text
, "none"))
1875 p
->type
|= CUPS_PRINTER_AUTHENTICATED
;
1877 p
->type
&= ~CUPS_PRINTER_AUTHENTICATED
;
1879 for (i
= 0; i
< attr
->num_values
; i
++)
1881 if (!strcmp(attr
->values
[i
].string
.text
, "none"))
1883 if (p
->num_auth_info_required
!= 0 || attr
->num_values
!= 1)
1886 p
->auth_info_required
[p
->num_auth_info_required
] = "none";
1887 p
->num_auth_info_required
++;
1891 else if (!strcmp(attr
->values
[i
].string
.text
, "negotiate"))
1893 if (p
->num_auth_info_required
!= 0 || attr
->num_values
!= 1)
1896 p
->auth_info_required
[p
->num_auth_info_required
] = "negotiate";
1897 p
->num_auth_info_required
++;
1900 * Don't allow sharing of queues that require Kerberos authentication.
1905 cupsdDeregisterPrinter(p
, 1);
1911 else if (!strcmp(attr
->values
[i
].string
.text
, "domain"))
1913 p
->auth_info_required
[p
->num_auth_info_required
] = "domain";
1914 p
->num_auth_info_required
++;
1916 else if (!strcmp(attr
->values
[i
].string
.text
, "password"))
1918 p
->auth_info_required
[p
->num_auth_info_required
] = "password";
1919 p
->num_auth_info_required
++;
1921 else if (!strcmp(attr
->values
[i
].string
.text
, "username"))
1923 p
->auth_info_required
[p
->num_auth_info_required
] = "username";
1924 p
->num_auth_info_required
++;
1935 * 'cupsdSetDeviceURI()' - Set the device URI for a printer.
1939 cupsdSetDeviceURI(cupsd_printer_t
*p
, /* I - Printer */
1940 const char *uri
) /* I - Device URI */
1942 char buffer
[1024], /* URI buffer */
1943 *start
, /* Start of data after scheme */
1944 *slash
, /* First slash after scheme:// */
1945 *ptr
; /* Pointer into user@host:port part */
1949 * Set the full device URI..
1952 cupsdSetString(&(p
->device_uri
), uri
);
1955 * Copy the device URI to a temporary buffer so we can sanitize any auth
1959 strlcpy(buffer
, uri
, sizeof(buffer
));
1962 * Find the end of the scheme:// part...
1965 if ((ptr
= strchr(buffer
, ':')) != NULL
)
1967 for (start
= ptr
+ 1; *start
; start
++)
1972 * Find the next slash (/) in the URI...
1975 if ((slash
= strchr(start
, '/')) == NULL
)
1976 slash
= start
+ strlen(start
); /* No slash, point to the end */
1979 * Check for an @ sign before the slash...
1982 if ((ptr
= strchr(start
, '@')) != NULL
&& ptr
< slash
)
1985 * Found an @ sign and it is before the resource part, so we have
1986 * an authentication string. Copy the remaining URI over the
1987 * authentication string...
1990 _cups_strcpy(start
, ptr
+ 1);
1995 * Save the sanitized URI...
1998 cupsdSetString(&(p
->sanitized_device_uri
), buffer
);
2003 * 'cupsdSetPrinterAttr()' - Set a printer attribute.
2007 cupsdSetPrinterAttr(
2008 cupsd_printer_t
*p
, /* I - Printer */
2009 const char *name
, /* I - Attribute name */
2010 char *value
) /* I - Attribute value string */
2012 ipp_attribute_t
*attr
; /* Attribute */
2013 int i
, /* Looping var */
2014 count
; /* Number of values */
2015 char *ptr
; /* Pointer into value */
2016 ipp_tag_t value_tag
; /* Value tag for this attribute */
2020 * Don't allow empty values...
2023 if (!*value
&& strcmp(name
, "marker-message"))
2025 cupsdLogMessage(CUPSD_LOG_ERROR
, "Ignoring empty \"%s\" attribute", name
);
2030 * Count the number of values...
2033 for (count
= 1, ptr
= value
;
2034 (ptr
= strchr(ptr
, ',')) != NULL
;
2038 * Then add or update the attribute as needed...
2041 if (!strcmp(name
, "marker-levels") || !strcmp(name
, "marker-low-levels") ||
2042 !strcmp(name
, "marker-high-levels"))
2048 if ((attr
= ippFindAttribute(p
->attrs
, name
, IPP_TAG_INTEGER
)) != NULL
&&
2049 attr
->num_values
< count
)
2051 ippDeleteAttribute(p
->attrs
, attr
);
2056 attr
->num_values
= count
;
2058 attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
, name
,
2063 cupsdLogMessage(CUPSD_LOG_ERROR
,
2064 "Unable to allocate memory for printer attribute "
2065 "(%d values)", count
);
2069 for (i
= 0; i
< count
; i
++)
2071 if ((ptr
= strchr(value
, ',')) != NULL
)
2074 attr
->values
[i
].integer
= strtol(value
, NULL
, 10);
2083 * Name or keyword values...
2086 if (!strcmp(name
, "marker-types"))
2087 value_tag
= IPP_TAG_KEYWORD
;
2088 else if (!strcmp(name
, "marker-message"))
2089 value_tag
= IPP_TAG_TEXT
;
2091 value_tag
= IPP_TAG_NAME
;
2093 if ((attr
= ippFindAttribute(p
->attrs
, name
, value_tag
)) != NULL
&&
2094 attr
->num_values
< count
)
2096 ippDeleteAttribute(p
->attrs
, attr
);
2102 for (i
= 0; i
< attr
->num_values
; i
++)
2103 _cupsStrFree(attr
->values
[i
].string
.text
);
2105 attr
->num_values
= count
;
2108 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, value_tag
, name
,
2113 cupsdLogMessage(CUPSD_LOG_ERROR
,
2114 "Unable to allocate memory for printer attribute "
2115 "(%d values)", count
);
2119 for (i
= 0; i
< count
; i
++)
2121 if ((ptr
= strchr(value
, ',')) != NULL
)
2124 attr
->values
[i
].string
.text
= _cupsStrAlloc(value
);
2134 * 'cupsdSetPrinterAttrs()' - Set printer attributes based upon the PPD file.
2138 cupsdSetPrinterAttrs(cupsd_printer_t
*p
)/* I - Printer to setup */
2140 int i
, /* Looping var */
2141 length
; /* Length of browse attributes */
2142 char resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
2143 int num_air
; /* Number of auth-info-required values */
2144 const char * const *air
; /* auth-info-required values */
2145 cupsd_location_t
*auth
; /* Pointer to authentication element */
2146 const char *auth_supported
; /* Authentication supported */
2147 ipp_t
*oldattrs
; /* Old printer attributes */
2148 ipp_attribute_t
*attr
; /* Attribute data */
2149 cups_option_t
*option
; /* Current printer option */
2150 char *name
, /* Current user/group name */
2151 *filter
; /* Current filter */
2152 static const char * const air_none
[] =
2153 { /* No authentication */
2156 static const char * const air_userpass
[] =
2157 { /* Basic/Digest authentication */
2163 DEBUG_printf(("cupsdSetPrinterAttrs: entering name = %s, type = %x\n", p
->name
,
2167 * Make sure that we have the common attributes defined...
2171 cupsdCreateCommonData();
2174 * Clear out old filters, if any...
2177 delete_printer_filters(p
);
2180 * Figure out the authentication that is required for the printer.
2183 auth_supported
= "requesting-user-name";
2187 if (p
->num_auth_info_required
> 0 && strcmp(p
->auth_info_required
[0], "none"))
2189 num_air
= p
->num_auth_info_required
;
2190 air
= p
->auth_info_required
;
2192 else if ((p
->type
& CUPS_PRINTER_AUTHENTICATED
) &&
2193 (p
->type
& CUPS_PRINTER_DISCOVERED
))
2199 if (p
->type
& CUPS_PRINTER_CLASS
)
2200 snprintf(resource
, sizeof(resource
), "/classes/%s", p
->name
);
2202 snprintf(resource
, sizeof(resource
), "/printers/%s", p
->name
);
2204 if ((auth
= cupsdFindBest(resource
, HTTP_POST
)) == NULL
||
2205 auth
->type
== CUPSD_AUTH_NONE
)
2206 auth
= cupsdFindPolicyOp(p
->op_policy_ptr
, IPP_PRINT_JOB
);
2210 int auth_type
; /* Authentication type */
2213 if ((auth_type
= auth
->type
) == CUPSD_AUTH_DEFAULT
)
2214 auth_type
= DefaultAuthType
;
2216 if (auth_type
== CUPSD_AUTH_BASIC
|| auth_type
== CUPSD_AUTH_BASICDIGEST
)
2217 auth_supported
= "basic";
2218 else if (auth_type
== CUPSD_AUTH_DIGEST
)
2219 auth_supported
= "digest";
2221 else if (auth_type
== CUPSD_AUTH_NEGOTIATE
)
2222 auth_supported
= "negotiate";
2223 #endif /* HAVE_GSSAPI */
2225 if (!(p
->type
& CUPS_PRINTER_DISCOVERED
))
2227 if (auth_type
!= CUPSD_AUTH_NONE
)
2228 p
->type
|= CUPS_PRINTER_AUTHENTICATED
;
2230 p
->type
&= ~CUPS_PRINTER_AUTHENTICATED
;
2233 else if (!(p
->type
& CUPS_PRINTER_DISCOVERED
))
2234 p
->type
&= ~CUPS_PRINTER_AUTHENTICATED
;
2237 * Create the required IPP attributes for a printer...
2240 oldattrs
= p
->attrs
;
2241 p
->attrs
= ippNew();
2243 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2244 "uri-authentication-supported", NULL
, auth_supported
);
2245 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2246 "uri-security-supported", NULL
, "none");
2247 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
, "printer-name", NULL
,
2249 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-location",
2250 NULL
, p
->location
? p
->location
: "");
2251 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-info",
2252 NULL
, p
->info
? p
->info
: "");
2253 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "printer-uuid", NULL
,
2256 if (cupsArrayCount(p
->users
) > 0)
2259 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2260 "requesting-user-name-denied",
2261 cupsArrayCount(p
->users
), NULL
, NULL
);
2263 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2264 "requesting-user-name-allowed",
2265 cupsArrayCount(p
->users
), NULL
, NULL
);
2267 for (i
= 0, name
= (char *)cupsArrayFirst(p
->users
);
2269 i
++, name
= (char *)cupsArrayNext(p
->users
))
2270 attr
->values
[i
].string
.text
= _cupsStrRetain(name
);
2273 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2274 "job-quota-period", p
->quota_period
);
2275 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2276 "job-k-limit", p
->k_limit
);
2277 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2278 "job-page-limit", p
->page_limit
);
2279 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2280 "auth-info-required", num_air
, NULL
, air
);
2282 if (cupsArrayCount(Banners
) > 0 && !(p
->type
& CUPS_PRINTER_DISCOVERED
))
2285 * Setup the job-sheets-default attribute...
2288 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2289 "job-sheets-default", 2, NULL
, NULL
);
2293 attr
->values
[0].string
.text
= _cupsStrAlloc(Classification
?
2294 Classification
: p
->job_sheets
[0]);
2295 attr
->values
[1].string
.text
= _cupsStrAlloc(Classification
?
2296 Classification
: p
->job_sheets
[1]);
2303 if (p
->type
& CUPS_PRINTER_DISCOVERED
)
2306 * Tell the client this is a remote printer of some type...
2309 if (strchr(p
->uri
, '?'))
2312 * Strip trailing "?options" from URI...
2315 char *ptr
; /* Pointer into URI */
2317 strlcpy(resource
, p
->uri
, sizeof(resource
));
2318 if ((ptr
= strchr(resource
, '?')) != NULL
)
2321 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
2322 "printer-uri-supported", NULL
, resource
);
2325 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
2326 "printer-uri-supported", NULL
, p
->uri
);
2328 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "printer-more-info",
2332 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
2333 "printer-make-and-model", NULL
, p
->make_model
);
2335 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "device-uri", NULL
,
2344 * Assign additional attributes depending on whether this is a printer
2348 if (p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
))
2351 p
->type
&= ~CUPS_PRINTER_OPTIONS
;
2354 * Add class-specific attributes...
2357 if ((p
->type
& CUPS_PRINTER_IMPLICIT
) && p
->num_printers
> 0 &&
2358 p
->printers
[0]->make_model
)
2359 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
2360 "printer-make-and-model", NULL
, p
->printers
[0]->make_model
);
2362 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
2363 "printer-make-and-model", NULL
, "Local Printer Class");
2365 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "device-uri", NULL
,
2366 "file:///dev/null");
2368 if (p
->num_printers
> 0)
2371 * Add a list of member names; URIs are added in copy_printer_attrs...
2374 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2375 "member-names", p
->num_printers
, NULL
, NULL
);
2376 p
->type
|= CUPS_PRINTER_OPTIONS
;
2378 for (i
= 0; i
< p
->num_printers
; i
++)
2381 attr
->values
[i
].string
.text
= _cupsStrRetain(p
->printers
[i
]->name
);
2383 p
->type
&= ~CUPS_PRINTER_OPTIONS
| p
->printers
[i
]->type
;
2390 * Add printer-specific attributes...
2393 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "device-uri", NULL
,
2394 p
->sanitized_device_uri
);
2397 * Assign additional attributes from the PPD file (if any)...
2403 * Add filters for printer...
2406 cupsdSetPrinterReasons(p
, "-cups-missing-filter-warning,"
2407 "cups-insecure-filter-warning");
2409 if (p
->pc
&& p
->pc
->filters
)
2411 for (filter
= (char *)cupsArrayFirst(p
->pc
->filters
);
2413 filter
= (char *)cupsArrayNext(p
->pc
->filters
))
2414 add_printer_filter(p
, p
->filetype
, filter
);
2416 else if (!(p
->type
& CUPS_PRINTER_REMOTE
))
2418 char interface
[1024]; /* Interface script */
2421 snprintf(interface
, sizeof(interface
), "%s/interfaces/%s", ServerRoot
,
2423 if (!access(interface
, X_OK
))
2426 * Yes, we have a System V style interface script; use it!
2429 snprintf(interface
, sizeof(interface
), "*/* 0 %s/interfaces/%s",
2430 ServerRoot
, p
->name
);
2431 add_printer_filter(p
, p
->filetype
, interface
);
2436 * Add a filter from application/vnd.cups-raw to printer/name to
2437 * handle "raw" printing by users.
2440 add_printer_filter(p
, p
->filetype
, "application/vnd.cups-raw 0 -");
2443 * Add a PostScript filter, since this is still possibly PS printer.
2446 add_printer_filter(p
, p
->filetype
,
2447 "application/vnd.cups-postscript 0 -");
2451 if (p
->pc
&& p
->pc
->prefilters
)
2453 if (!p
->prefiltertype
)
2454 p
->prefiltertype
= mimeAddType(MimeDatabase
, "prefilter", p
->name
);
2456 for (filter
= (char *)cupsArrayFirst(p
->pc
->prefilters
);
2458 filter
= (char *)cupsArrayNext(p
->pc
->prefilters
))
2459 add_printer_filter(p
, p
->prefiltertype
, filter
);
2465 * Copy marker attributes as needed...
2470 ipp_attribute_t
*oldattr
; /* Old attribute */
2473 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-colors",
2474 IPP_TAG_NAME
)) != NULL
)
2476 if ((attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2477 "marker-colors", oldattr
->num_values
, NULL
,
2480 for (i
= 0; i
< oldattr
->num_values
; i
++)
2481 attr
->values
[i
].string
.text
=
2482 _cupsStrRetain(oldattr
->values
[i
].string
.text
);
2486 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-levels",
2487 IPP_TAG_INTEGER
)) != NULL
)
2489 if ((attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2490 "marker-levels", oldattr
->num_values
,
2493 for (i
= 0; i
< oldattr
->num_values
; i
++)
2494 attr
->values
[i
].integer
= oldattr
->values
[i
].integer
;
2498 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-message",
2499 IPP_TAG_TEXT
)) != NULL
)
2500 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "marker-message",
2501 NULL
, oldattr
->values
[0].string
.text
);
2503 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-low-levels",
2504 IPP_TAG_INTEGER
)) != NULL
)
2506 if ((attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2507 "marker-low-levels", oldattr
->num_values
,
2510 for (i
= 0; i
< oldattr
->num_values
; i
++)
2511 attr
->values
[i
].integer
= oldattr
->values
[i
].integer
;
2515 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-high-levels",
2516 IPP_TAG_INTEGER
)) != NULL
)
2518 if ((attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2519 "marker-high-levels", oldattr
->num_values
,
2522 for (i
= 0; i
< oldattr
->num_values
; i
++)
2523 attr
->values
[i
].integer
= oldattr
->values
[i
].integer
;
2527 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-names",
2528 IPP_TAG_NAME
)) != NULL
)
2530 if ((attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2531 "marker-names", oldattr
->num_values
, NULL
,
2534 for (i
= 0; i
< oldattr
->num_values
; i
++)
2535 attr
->values
[i
].string
.text
=
2536 _cupsStrRetain(oldattr
->values
[i
].string
.text
);
2540 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-types",
2541 IPP_TAG_KEYWORD
)) != NULL
)
2543 if ((attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2544 "marker-types", oldattr
->num_values
, NULL
,
2547 for (i
= 0; i
< oldattr
->num_values
; i
++)
2548 attr
->values
[i
].string
.text
=
2549 _cupsStrRetain(oldattr
->values
[i
].string
.text
);
2553 ippDelete(oldattrs
);
2557 * Force sharing off for remote queues...
2560 if (p
->type
& (CUPS_PRINTER_REMOTE
| CUPS_PRINTER_IMPLICIT
))
2565 * Copy the printer options into a browse attributes string we can re-use.
2568 const char *valptr
; /* Pointer into value */
2569 char *attrptr
; /* Pointer into attribute string */
2573 * Free the old browse attributes as needed...
2576 if (p
->browse_attrs
)
2577 free(p
->browse_attrs
);
2580 * Compute the length of all attributes + job-sheets, lease-duration,
2581 * and BrowseLocalOptions.
2584 for (length
= 1, i
= p
->num_options
, option
= p
->options
;
2588 length
+= strlen(option
->name
) + 2;
2592 for (valptr
= option
->value
; *valptr
; valptr
++)
2593 if (strchr(" \"\'\\", *valptr
))
2600 length
+= 13 + strlen(p
->job_sheets
[0]) + strlen(p
->job_sheets
[1]);
2602 if (BrowseLocalOptions
)
2603 length
+= 12 + strlen(BrowseLocalOptions
);
2606 * Allocate the new string...
2609 if ((p
->browse_attrs
= calloc(1, length
)) == NULL
)
2610 cupsdLogMessage(CUPSD_LOG_ERROR
,
2611 "Unable to allocate %d bytes for browse data!",
2616 * Got the allocated string, now copy the options and attributes over...
2619 sprintf(p
->browse_attrs
, "job-sheets=%s,%s lease-duration=%d",
2620 p
->job_sheets
[0], p
->job_sheets
[1], BrowseTimeout
);
2621 attrptr
= p
->browse_attrs
+ strlen(p
->browse_attrs
);
2623 if (BrowseLocalOptions
)
2625 sprintf(attrptr
, " ipp-options=%s", BrowseLocalOptions
);
2626 attrptr
+= strlen(attrptr
);
2629 for (i
= p
->num_options
, option
= p
->options
;
2634 strcpy(attrptr
, option
->name
);
2635 attrptr
+= strlen(attrptr
);
2641 for (valptr
= option
->value
; *valptr
; valptr
++)
2643 if (strchr(" \"\'\\", *valptr
))
2646 *attrptr
++ = *valptr
;
2654 * Populate the document-format-supported attribute...
2657 add_printer_formats(p
);
2659 DEBUG_printf(("cupsdSetPrinterAttrs: leaving name = %s, type = %x\n", p
->name
,
2663 * Add name-default attributes...
2666 add_printer_defaults(p
);
2670 * Write the IRIX printer config and status files...
2673 write_irix_config(p
);
2674 write_irix_state(p
);
2678 * Let the browse protocols reflect the change
2681 cupsdRegisterPrinter(p
);
2686 * 'cupsdSetPrinterReasons()' - Set/update the reasons strings.
2689 int /* O - 1 if something changed, 0 otherwise */
2690 cupsdSetPrinterReasons(
2691 cupsd_printer_t
*p
, /* I - Printer */
2692 const char *s
) /* I - Reasons strings */
2694 int i
, /* Looping var */
2695 changed
= 0; /* Did something change? */
2696 const char *sptr
; /* Pointer into reasons */
2697 char reason
[255], /* Reason string */
2698 *rptr
; /* Pointer into reason */
2701 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
2702 "cupsdSetPrinterReasons(p=%p(%s),s=\"%s\"", p
, p
->name
, s
);
2704 if (s
[0] == '-' || s
[0] == '+')
2707 * Add/remove reasons...
2715 * Replace reasons...
2720 for (i
= 0; i
< p
->num_reasons
; i
++)
2721 _cupsStrFree(p
->reasons
[i
]);
2729 if (!strcmp(s
, "none"))
2733 * Loop through all of the reasons...
2739 * Skip leading whitespace and commas...
2742 while (isspace(*sptr
& 255) || *sptr
== ',')
2745 for (rptr
= reason
; *sptr
&& !isspace(*sptr
& 255) && *sptr
!= ','; sptr
++)
2746 if (rptr
< (reason
+ sizeof(reason
) - 1))
2760 for (i
= 0; i
< p
->num_reasons
; i
++)
2761 if (!strcmp(reason
, p
->reasons
[i
]))
2764 * Found a match, so remove it...
2769 _cupsStrFree(p
->reasons
[i
]);
2771 if (i
< p
->num_reasons
)
2772 memmove(p
->reasons
+ i
, p
->reasons
+ i
+ 1,
2773 (p
->num_reasons
- i
) * sizeof(char *));
2775 if (!strcmp(reason
, "paused") && p
->state
== IPP_PRINTER_STOPPED
)
2776 cupsdSetPrinterState(p
, IPP_PRINTER_IDLE
, 1);
2778 if (strcmp(reason
, "connecting-to-device"))
2783 else if (p
->num_reasons
< (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
2789 for (i
= 0; i
< p
->num_reasons
; i
++)
2790 if (!strcmp(reason
, p
->reasons
[i
]))
2793 if (i
>= p
->num_reasons
)
2795 if (i
>= (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
2797 cupsdLogMessage(CUPSD_LOG_ALERT
,
2798 "Too many printer-state-reasons values for %s (%d)",
2803 p
->reasons
[i
] = _cupsStrAlloc(reason
);
2807 if (!strcmp(reason
, "paused") && p
->state
!= IPP_PRINTER_STOPPED
)
2808 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, 1);
2810 if (strcmp(reason
, "connecting-to-device"))
2821 * 'cupsdSetPrinterState()' - Update the current state of a printer.
2825 cupsdSetPrinterState(
2826 cupsd_printer_t
*p
, /* I - Printer to change */
2827 ipp_pstate_t s
, /* I - New state */
2828 int update
) /* I - Update printers.conf? */
2830 ipp_pstate_t old_state
; /* Old printer state */
2831 static const char * const printer_states
[] =
2832 { /* State strings */
2840 * Can't set status of remote printers...
2843 if (p
->type
& CUPS_PRINTER_DISCOVERED
)
2847 * Set the new state...
2850 old_state
= p
->state
;
2855 cupsdAddEvent(s
== IPP_PRINTER_STOPPED
? CUPSD_EVENT_PRINTER_STOPPED
:
2856 CUPSD_EVENT_PRINTER_STATE
, p
, NULL
,
2857 "%s \"%s\" state changed to %s.",
2858 (p
->type
& CUPS_PRINTER_CLASS
) ? "Class" : "Printer",
2859 p
->name
, printer_states
[p
->state
- IPP_PRINTER_IDLE
]);
2862 * Let the browse code know this needs to be updated...
2866 p
->state_time
= time(NULL
);
2870 write_irix_state(p
);
2875 * Set/clear the paused reason as needed...
2878 if (s
== IPP_PRINTER_STOPPED
)
2879 cupsdSetPrinterReasons(p
, "+paused");
2881 cupsdSetPrinterReasons(p
, "-paused");
2884 * Clear the message for the queue when going to processing...
2887 if (s
== IPP_PRINTER_PROCESSING
)
2888 p
->state_message
[0] = '\0';
2891 * Let the browse protocols reflect the change...
2895 cupsdRegisterPrinter(p
);
2898 * Save the printer configuration if a printer goes from idle or processing
2899 * to stopped (or visa-versa)...
2903 (old_state
== IPP_PRINTER_STOPPED
) != (s
== IPP_PRINTER_STOPPED
))
2909 * 'cupsdStopPrinter()' - Stop a printer from printing any jobs...
2913 cupsdStopPrinter(cupsd_printer_t
*p
, /* I - Printer to stop */
2914 int update
)/* I - Update printers.conf? */
2917 * Set the printer state...
2920 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, update
);
2923 * See if we have a job printing on this printer...
2926 if (p
->job
&& p
->job
->state_value
== IPP_JOB_PROCESSING
)
2927 cupsdSetJobState(p
->job
, IPP_JOB_PENDING
, CUPSD_JOB_DEFAULT
,
2928 "Job stopped due to printer being paused.");
2933 * 'cupsdUpdatePrinterPPD()' - Update keywords in a printer's PPD file.
2936 int /* O - 1 if successful, 0 otherwise */
2937 cupsdUpdatePrinterPPD(
2938 cupsd_printer_t
*p
, /* I - Printer */
2939 int num_keywords
, /* I - Number of keywords */
2940 cups_option_t
*keywords
) /* I - Keywords */
2942 int i
; /* Looping var */
2943 cups_file_t
*src
, /* Original file */
2944 *dst
; /* New file */
2945 char srcfile
[1024], /* Original filename */
2946 dstfile
[1024], /* New filename */
2947 line
[1024], /* Line from file */
2948 keystring
[41]; /* Keyword from line */
2949 cups_option_t
*keyword
; /* Current keyword */
2952 cupsdLogMessage(CUPSD_LOG_INFO
, "Updating keywords in PPD file for %s...",
2956 * Get the old and new PPD filenames...
2959 snprintf(srcfile
, sizeof(srcfile
), "%s/ppd/%s.ppd.O", ServerRoot
, p
->name
);
2960 snprintf(dstfile
, sizeof(srcfile
), "%s/ppd/%s.ppd", ServerRoot
, p
->name
);
2963 * Rename the old file and open the old and new...
2966 if (rename(dstfile
, srcfile
))
2968 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to backup PPD file for %s: %s",
2969 p
->name
, strerror(errno
));
2973 if ((src
= cupsFileOpen(srcfile
, "r")) == NULL
)
2975 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to open PPD file \"%s\": %s",
2976 srcfile
, strerror(errno
));
2977 rename(srcfile
, dstfile
);
2981 if ((dst
= cupsFileOpen(dstfile
, "w")) == NULL
)
2983 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to create PPD file \"%s\": %s",
2984 dstfile
, strerror(errno
));
2986 rename(srcfile
, dstfile
);
2991 * Copy the first line and then write out all of the keywords...
2994 if (!cupsFileGets(src
, line
, sizeof(line
)))
2996 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to read PPD file \"%s\": %s",
2997 srcfile
, strerror(errno
));
3000 rename(srcfile
, dstfile
);
3004 cupsFilePrintf(dst
, "%s\n", line
);
3006 for (i
= num_keywords
, keyword
= keywords
; i
> 0; i
--, keyword
++)
3008 cupsdLogMessage(CUPSD_LOG_DEBUG
, "*%s: %s", keyword
->name
, keyword
->value
);
3009 cupsFilePrintf(dst
, "*%s: %s\n", keyword
->name
, keyword
->value
);
3013 * Then copy the rest of the PPD file, dropping any keywords we changed.
3016 while (cupsFileGets(src
, line
, sizeof(line
)))
3019 * Skip keywords we've already set...
3022 if (sscanf(line
, "*%40[^:]:", keystring
) == 1 &&
3023 cupsGetOption(keystring
, num_keywords
, keywords
))
3027 * Otherwise write the line...
3030 cupsFilePrintf(dst
, "%s\n", line
);
3034 * Close files and return...
3045 * 'cupsdUpdatePrinters()' - Update printers after a partial reload.
3049 cupsdUpdatePrinters(void)
3051 cupsd_printer_t
*p
; /* Current printer */
3055 * Loop through the printers and recreate the printer attributes
3056 * for any local printers since the policy and/or access control
3057 * stuff may have changed. Also, if browsing is disabled, remove
3058 * any remote printers...
3061 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3063 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3066 * Remove remote printers if we are no longer browsing...
3070 (p
->type
& (CUPS_PRINTER_IMPLICIT
| CUPS_PRINTER_DISCOVERED
)))
3072 if (p
->type
& CUPS_PRINTER_IMPLICIT
)
3073 cupsArrayRemove(ImplicitPrinters
, p
);
3075 cupsArraySave(Printers
);
3076 cupsdDeletePrinter(p
, 0);
3077 cupsArrayRestore(Printers
);
3082 * Update the operation policy pointer...
3085 if ((p
->op_policy_ptr
= cupsdFindPolicy(p
->op_policy
)) == NULL
)
3086 p
->op_policy_ptr
= DefaultPolicyPtr
;
3089 * Update printer attributes as needed...
3092 if (!(p
->type
& CUPS_PRINTER_DISCOVERED
))
3093 cupsdSetPrinterAttrs(p
);
3099 * 'cupsdValidateDest()' - Validate a printer/class destination.
3102 const char * /* O - Printer or class name */
3104 const char *uri
, /* I - Printer URI */
3105 cups_ptype_t
*dtype
, /* O - Type (printer or class) */
3106 cupsd_printer_t
**printer
) /* O - Printer pointer */
3108 cupsd_printer_t
*p
; /* Current printer */
3109 char localname
[1024],/* Localized hostname */
3110 *lptr
, /* Pointer into localized hostname */
3111 *sptr
, /* Pointer into server name */
3112 *rptr
, /* Pointer into resource */
3113 scheme
[32], /* Scheme portion of URI */
3114 username
[64], /* Username portion of URI */
3115 hostname
[HTTP_MAX_HOST
],
3116 /* Host portion of URI */
3117 resource
[HTTP_MAX_URI
];
3118 /* Resource portion of URI */
3119 int port
; /* Port portion of URI */
3122 DEBUG_printf(("cupsdValidateDest(uri=\"%s\", dtype=%p, printer=%p)\n", uri
,
3126 * Initialize return values...
3133 *dtype
= (cups_ptype_t
)0;
3136 * Pull the hostname and resource from the URI...
3139 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
, scheme
, sizeof(scheme
),
3140 username
, sizeof(username
), hostname
, sizeof(hostname
),
3141 &port
, resource
, sizeof(resource
));
3144 * See if the resource is a class or printer...
3147 if (!strncmp(resource
, "/classes/", 9))
3153 rptr
= resource
+ 9;
3155 else if (!strncmp(resource
, "/printers/", 10))
3161 rptr
= resource
+ 10;
3166 * Bad resource name...
3173 * See if the printer or class name exists...
3176 p
= cupsdFindDest(rptr
);
3178 if (p
== NULL
&& strchr(rptr
, '@') == NULL
)
3186 *dtype
= p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
|
3187 CUPS_PRINTER_REMOTE
| CUPS_PRINTER_DISCOVERED
);
3193 * Change localhost to the server name...
3196 if (!strcasecmp(hostname
, "localhost"))
3197 strlcpy(hostname
, ServerName
, sizeof(hostname
));
3199 strlcpy(localname
, hostname
, sizeof(localname
));
3201 if (!strcasecmp(hostname
, ServerName
))
3204 * Localize the hostname...
3207 lptr
= strchr(localname
, '.');
3208 sptr
= strchr(ServerName
, '.');
3210 if (sptr
!= NULL
&& lptr
!= NULL
)
3213 * Strip the common domain name components...
3216 while (lptr
!= NULL
)
3218 if (!strcasecmp(lptr
, sptr
))
3224 lptr
= strchr(lptr
+ 1, '.');
3229 DEBUG_printf(("localized hostname is \"%s\"...\n", localname
));
3232 * Find a matching printer or class...
3235 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3237 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3238 if (!strcasecmp(p
->hostname
, localname
) &&
3239 !strcasecmp(p
->name
, rptr
))
3245 *dtype
= p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
|
3246 CUPS_PRINTER_REMOTE
| CUPS_PRINTER_DISCOVERED
);
3256 * 'cupsdWritePrintcap()' - Write a pseudo-printcap file for older applications
3261 cupsdWritePrintcap(void)
3263 int i
; /* Looping var */
3264 cups_file_t
*fp
; /* Printcap file */
3265 cupsd_printer_t
*p
; /* Current printer */
3270 * Update the IRIX printer state for the default printer; if
3271 * no printers remain, then the default printer file will be
3275 write_irix_state(DefaultPrinter
);
3279 * See if we have a printcap file; if not, don't bother writing it.
3282 if (!Printcap
|| !*Printcap
)
3285 cupsdLogMessage(CUPSD_LOG_INFO
, "Generating printcap %s...", Printcap
);
3288 * Open the printcap file...
3291 if ((fp
= cupsFileOpen(Printcap
, "w")) == NULL
)
3295 * Put a comment header at the top so that users will know where the
3296 * data has come from...
3299 if (PrintcapFormat
!= PRINTCAP_PLIST
)
3300 cupsFilePrintf(fp
, "# This file was automatically generated by cupsd(8) "
3302 "# %s/printers.conf file. All changes to this file\n"
3303 "# will be lost.\n", ServerRoot
);
3306 * Write a new printcap with the current list of printers.
3309 switch (PrintcapFormat
)
3313 * Each printer is put in the file as:
3323 cupsFilePrintf(fp
, "%s|%s:rm=%s:rp=%s:\n", DefaultPrinter
->name
,
3324 DefaultPrinter
->info
, ServerName
,
3325 DefaultPrinter
->name
);
3327 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3329 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3330 if (p
!= DefaultPrinter
)
3331 cupsFilePrintf(fp
, "%s|%s:rm=%s:rp=%s:\n", p
->name
, p
->info
,
3332 ServerName
, p
->name
);
3335 case PRINTCAP_PLIST
:
3337 * Each printer is written as a dictionary in a plist file.
3338 * Currently the printer-name, printer-info, printer-is-accepting-jobs,
3339 * printer-location, printer-make-and-model, printer-state,
3340 * printer-state-reasons, printer-type, and (sanitized) device-uri.
3343 cupsFilePuts(fp
, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
3344 "<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD "
3345 "PLIST 1.0//EN\" \"http://www.apple.com/DTDs/"
3346 "PropertyList-1.0.dtd\">\n"
3347 "<plist version=\"1.0\">\n"
3350 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3352 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3354 cupsFilePuts(fp
, "\t<dict>\n"
3355 "\t\t<key>printer-name</key>\n"
3357 write_xml_string(fp
, p
->name
);
3358 cupsFilePuts(fp
, "</string>\n"
3359 "\t\t<key>printer-info</key>\n"
3361 write_xml_string(fp
, p
->info
);
3362 cupsFilePrintf(fp
, "</string>\n"
3363 "\t\t<key>printer-is-accepting-jobs</key>\n"
3365 "\t\t<key>printer-location</key>\n"
3366 "\t\t<string>", p
->accepting
? "true" : "false");
3367 write_xml_string(fp
, p
->location
);
3368 cupsFilePuts(fp
, "</string>\n"
3369 "\t\t<key>printer-make-and-model</key>\n"
3371 write_xml_string(fp
, p
->make_model
);
3372 cupsFilePrintf(fp
, "</string>\n"
3373 "\t\t<key>printer-state</key>\n"
3374 "\t\t<integer>%d</integer>\n"
3375 "\t\t<key>printer-state-reasons</key>\n"
3376 "\t\t<array>\n", p
->state
);
3377 for (i
= 0; i
< p
->num_reasons
; i
++)
3379 cupsFilePuts(fp
, "\t\t\t<string>");
3380 write_xml_string(fp
, p
->reasons
[i
]);
3381 cupsFilePuts(fp
, "</string>\n");
3383 cupsFilePrintf(fp
, "\t\t</array>\n"
3384 "\t\t<key>printer-type</key>\n"
3385 "\t\t<integer>%d</integer>\n"
3386 "\t\t<key>device-uri</key>\n"
3387 "\t\t<string>", p
->type
);
3388 write_xml_string(fp
, p
->sanitized_device_uri
);
3389 cupsFilePuts(fp
, "</string>\n"
3392 cupsFilePuts(fp
, "</array>\n"
3396 case PRINTCAP_SOLARIS
:
3398 * Each printer is put in the file as:
3400 * _all:all=Printer1,Printer2,Printer3,...,PrinterN
3401 * _default:use=DefaultPrinter
3403 * :bsdaddr=ServerName,Printer1:\
3404 * :description=Description:
3406 * :bsdaddr=ServerName,Printer2:\
3407 * :description=Description:
3409 * :bsdaddr=ServerName,Printer3:\
3410 * :description=Description:
3413 * :bsdaddr=ServerName,PrinterN:\
3414 * :description=Description:
3417 cupsFilePuts(fp
, "_all:all=");
3418 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3420 p
= (cupsd_printer_t
*)cupsArrayCurrent(Printers
))
3421 cupsFilePrintf(fp
, "%s%c", p
->name
,
3422 cupsArrayNext(Printers
) ? ',' : '\n');
3425 cupsFilePrintf(fp
, "_default:use=%s\n", DefaultPrinter
->name
);
3427 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3429 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3430 cupsFilePrintf(fp
, "%s:\\\n"
3431 "\t:bsdaddr=%s,%s:\\\n"
3432 "\t:description=%s:\n",
3433 p
->name
, ServerName
, p
->name
,
3434 p
->info
? p
->info
: "");
3447 * 'add_printer_defaults()' - Add name-default attributes to the printer attributes.
3451 add_printer_defaults(cupsd_printer_t
*p
)/* I - Printer */
3453 int i
; /* Looping var */
3454 int num_options
; /* Number of default options */
3455 cups_option_t
*options
, /* Default options */
3456 *option
; /* Current option */
3457 char name
[256]; /* name-default */
3461 * Maintain a common array of default attribute names...
3464 if (!CommonDefaults
)
3466 CommonDefaults
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
3468 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("copies-default"));
3469 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("document-format-default"));
3470 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("finishings-default"));
3471 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-hold-until-default"));
3472 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-priority-default"));
3473 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-sheets-default"));
3474 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("media-col-default"));
3475 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("number-up-default"));
3476 cupsArrayAdd(CommonDefaults
,
3477 _cupsStrAlloc("orientation-requested-default"));
3481 * Add all of the default options from the .conf files...
3484 for (num_options
= 0, options
= NULL
, i
= p
->num_options
, option
= p
->options
;
3488 if (strcmp(option
->name
, "ipp-options") &&
3489 strcmp(option
->name
, "job-sheets") &&
3490 strcmp(option
->name
, "lease-duration"))
3492 snprintf(name
, sizeof(name
), "%s-default", option
->name
);
3493 num_options
= cupsAddOption(name
, option
->value
, num_options
, &options
);
3495 if (!cupsArrayFind(CommonDefaults
, name
))
3496 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc(name
));
3501 * Convert options to IPP attributes...
3504 cupsEncodeOptions2(p
->attrs
, num_options
, options
, IPP_TAG_PRINTER
);
3505 cupsFreeOptions(num_options
, options
);
3508 * Add standard -default attributes as needed...
3511 if (!cupsGetOption("copies", p
->num_options
, p
->options
))
3512 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
, "copies-default",
3515 if (!cupsGetOption("document-format", p
->num_options
, p
->options
))
3516 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_MIMETYPE
,
3517 "document-format-default", NULL
, "application/octet-stream");
3519 if (!cupsGetOption("job-hold-until", p
->num_options
, p
->options
))
3520 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3521 "job-hold-until-default", NULL
, "no-hold");
3523 if (!cupsGetOption("job-priority", p
->num_options
, p
->options
))
3524 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3525 "job-priority-default", 50);
3527 if (!cupsGetOption("number-up", p
->num_options
, p
->options
))
3528 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3529 "number-up-default", 1);
3531 if (!cupsGetOption("notify-lease-duration", p
->num_options
, p
->options
))
3532 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3533 "notify-lease-duration-default", DefaultLeaseDuration
);
3535 if (!cupsGetOption("notify-events", p
->num_options
, p
->options
))
3536 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3537 "notify-events-default", NULL
, "job-completed");
3539 if (!cupsGetOption("orientation-requested", p
->num_options
, p
->options
))
3540 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NOVALUE
,
3541 "orientation-requested-default", NULL
, NULL
);
3543 if (!cupsGetOption("print-quality", p
->num_options
, p
->options
))
3544 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
3545 "print-quality-default", IPP_QUALITY_NORMAL
);
3550 * 'add_printer_filter()' - Add a MIME filter for a printer.
3555 cupsd_printer_t
*p
, /* I - Printer to add to */
3556 mime_type_t
*filtertype
, /* I - Filter or prefilter MIME type */
3557 const char *filter
) /* I - Filter to add */
3559 char super
[MIME_MAX_SUPER
], /* Super-type for filter */
3560 type
[MIME_MAX_TYPE
], /* Type for filter */
3561 dsuper
[MIME_MAX_SUPER
], /* Destination super-type for filter */
3562 dtype
[MIME_MAX_TYPE
], /* Destination type for filter */
3563 dest
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2],
3564 /* Destination super/type */
3565 program
[1024]; /* Program/filter name */
3566 int cost
; /* Cost of filter */
3567 size_t maxsize
= 0; /* Maximum supported file size */
3568 mime_type_t
*temptype
, /* MIME type looping var */
3569 *desttype
; /* Destination MIME type */
3570 mime_filter_t
*filterptr
; /* MIME filter */
3571 char filename
[1024]; /* Full filter filename */
3574 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3575 "add_printer_filter(p=%p(%s), filtertype=%p(%s/%s), "
3576 "filter=\"%s\")", p
, p
->name
, filtertype
, filtertype
->super
,
3577 filtertype
->type
, filter
);
3580 * Parse the filter string; it should be in one of the following formats:
3582 * source/type cost program
3583 * source/type cost maxsize(nnnn) program
3584 * source/type dest/type cost program
3585 * source/type dest/type cost maxsize(nnnn) program
3588 if (sscanf(filter
, "%15[^/]/%255s%*[ \t]%15[^/]/%255s%d%*[ \t]%1023[^\n]",
3589 super
, type
, dsuper
, dtype
, &cost
, program
) == 6)
3591 snprintf(dest
, sizeof(dest
), "%s/%s/%s", p
->name
, dsuper
, dtype
);
3593 if ((desttype
= mimeType(MimeDatabase
, "printer", dest
)) == NULL
)
3595 desttype
= mimeAddType(MimeDatabase
, "printer", dest
);
3597 p
->dest_types
= cupsArrayNew(NULL
, NULL
);
3599 cupsArrayAdd(p
->dest_types
, desttype
);
3605 if (sscanf(filter
, "%15[^/]/%255s%d%*[ \t]%1023[^\n]", super
, type
, &cost
,
3608 desttype
= filtertype
;
3612 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: invalid filter string \"%s\"!",
3618 if (!strncmp(program
, "maxsize(", 8))
3620 char *ptr
; /* Pointer into maxsize(nnnn) program */
3622 maxsize
= strtoll(program
+ 8, &ptr
, 10);
3626 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: invalid filter string \"%s\"!",
3632 while (_cups_isspace(*ptr
))
3635 _cups_strcpy(program
, ptr
);
3639 * Check permissions on the filter and its containing directory...
3642 if (strcmp(program
, "-"))
3644 _cups_fc_result_t result
; /* Result of file check */
3646 if (program
[0] == '/')
3647 strlcpy(filename
, program
, sizeof(filename
));
3649 snprintf(filename
, sizeof(filename
), "%s/filter/%s", ServerBin
, program
);
3651 result
= _cupsFileCheck(filename
, _CUPS_FILE_CHECK_PROGRAM
, !RunUser
,
3652 cupsdLogFCMessage
, p
);
3654 if (result
== _CUPS_FILE_CHECK_MISSING
||
3655 result
== _CUPS_FILE_CHECK_WRONG_TYPE
)
3660 * Add the filter to the MIME database, supporting wildcards as needed...
3663 for (temptype
= mimeFirstType(MimeDatabase
);
3665 temptype
= mimeNextType(MimeDatabase
))
3666 if (((super
[0] == '*' && strcasecmp(temptype
->super
, "printer")) ||
3667 !strcasecmp(temptype
->super
, super
)) &&
3668 (type
[0] == '*' || !strcasecmp(temptype
->type
, type
)))
3670 if (desttype
!= filtertype
)
3672 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3673 "add_printer_filter: %s: adding filter %s/%s %s/%s %d "
3674 "%s", p
->name
, temptype
->super
, temptype
->type
,
3675 desttype
->super
, desttype
->type
,
3677 filterptr
= mimeAddFilter(MimeDatabase
, temptype
, desttype
, cost
,
3680 if (!mimeFilterLookup(MimeDatabase
, desttype
, filtertype
))
3682 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3683 "add_printer_filter: %s: adding filter %s/%s %s/%s "
3684 "0 -", p
->name
, desttype
->super
, desttype
->type
,
3685 filtertype
->super
, filtertype
->type
);
3686 mimeAddFilter(MimeDatabase
, desttype
, filtertype
, cost
, "-");
3691 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3692 "add_printer_filter: %s: adding filter %s/%s %s/%s %d "
3693 "%s", p
->name
, temptype
->super
, temptype
->type
,
3694 filtertype
->super
, filtertype
->type
,
3696 filterptr
= mimeAddFilter(MimeDatabase
, temptype
, filtertype
, cost
,
3701 filterptr
->maxsize
= maxsize
;
3707 * 'add_printer_formats()' - Add document-format-supported values for a printer.
3711 add_printer_formats(cupsd_printer_t
*p
) /* I - Printer */
3713 int i
; /* Looping var */
3714 mime_type_t
*type
; /* Current MIME type */
3715 cups_array_t
*filters
; /* Filters */
3716 ipp_attribute_t
*attr
; /* document-format-supported attribute */
3717 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
3718 /* MIME type name */
3722 * Raw (and remote) queues advertise all of the supported MIME
3726 cupsArrayDelete(p
->filetypes
);
3727 p
->filetypes
= NULL
;
3731 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
,
3732 (ipp_tag_t
)(IPP_TAG_MIMETYPE
| IPP_TAG_COPY
),
3733 "document-format-supported", NumMimeTypes
, NULL
, MimeTypes
);
3738 * Otherwise, loop through the supported MIME types and see if there
3739 * are filters for them...
3742 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_printer_formats: %d types, %d filters",
3743 mimeNumTypes(MimeDatabase
), mimeNumFilters(MimeDatabase
));
3745 p
->filetypes
= cupsArrayNew(NULL
, NULL
);
3747 for (type
= mimeFirstType(MimeDatabase
);
3749 type
= mimeNextType(MimeDatabase
))
3751 if (!strcasecmp(type
->super
, "printer"))
3754 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
3756 if ((filters
= mimeFilter(MimeDatabase
, type
, p
->filetype
, NULL
)) != NULL
)
3758 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3759 "add_printer_formats: %s: %s needs %d filters",
3760 p
->name
, mimetype
, cupsArrayCount(filters
));
3762 cupsArrayDelete(filters
);
3763 cupsArrayAdd(p
->filetypes
, type
);
3766 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3767 "add_printer_formats: %s: %s not supported",
3772 * Add the file formats that can be filtered...
3775 if ((type
= mimeType(MimeDatabase
, "application", "octet-stream")) == NULL
||
3776 !cupsArrayFind(p
->filetypes
, type
))
3781 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3782 "add_printer_formats: %s: %d supported types",
3783 p
->name
, cupsArrayCount(p
->filetypes
) + i
);
3785 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_MIMETYPE
,
3786 "document-format-supported",
3787 cupsArrayCount(p
->filetypes
) + i
, NULL
, NULL
);
3790 attr
->values
[0].string
.text
= _cupsStrAlloc("application/octet-stream");
3792 for (type
= (mime_type_t
*)cupsArrayFirst(p
->filetypes
);
3794 i
++, type
= (mime_type_t
*)cupsArrayNext(p
->filetypes
))
3796 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
3798 attr
->values
[i
].string
.text
= _cupsStrAlloc(mimetype
);
3803 char pdl
[1024]; /* Buffer to build pdl list */
3804 mime_filter_t
*filter
; /* MIME filter looping var */
3808 * We only support raw printing if this is not a Tioga PrintJobMgr based
3809 * queue and if application/octet-stream is a known type...
3812 for (filter
= (mime_filter_t
*)cupsArrayFirst(MimeDatabase
->filters
);
3814 filter
= (mime_filter_t
*)cupsArrayNext(MimeDatabase
->filters
))
3816 if (filter
->dst
== p
->filetype
&& filter
->filter
&&
3817 strstr(filter
->filter
, "PrintJobMgr"))
3823 if (!filter
&& mimeType(MimeDatabase
, "application", "octet-stream"))
3824 strlcat(pdl
, "application/octet-stream,", sizeof(pdl
));
3827 * Then list a bunch of formats that are supported by the printer...
3830 for (type
= (mime_type_t
*)cupsArrayFirst(p
->filetypes
);
3832 type
= (mime_type_t
*)cupsArrayNext(p
->filetypes
))
3834 if (!strcasecmp(type
->super
, "application"))
3836 if (!strcasecmp(type
->type
, "pdf"))
3837 strlcat(pdl
, "application/pdf,", sizeof(pdl
));
3838 else if (!strcasecmp(type
->type
, "postscript"))
3839 strlcat(pdl
, "application/postscript,", sizeof(pdl
));
3841 else if (!strcasecmp(type
->super
, "image"))
3843 if (!strcasecmp(type
->type
, "jpeg"))
3844 strlcat(pdl
, "image/jpeg,", sizeof(pdl
));
3845 else if (!strcasecmp(type
->type
, "png"))
3846 strlcat(pdl
, "image/png,", sizeof(pdl
));
3847 else if (!strcasecmp(type
->type
, "pwg-raster"))
3848 strlcat(pdl
, "image/pwg-raster,", sizeof(pdl
));
3853 pdl
[strlen(pdl
) - 1] = '\0'; /* Remove trailing comma */
3855 cupsdSetString(&p
->pdl
, pdl
);
3857 #endif /* HAVE_DNSSD */
3862 * 'compare_printers()' - Compare two printers.
3865 static int /* O - Result of comparison */
3866 compare_printers(void *first
, /* I - First printer */
3867 void *second
, /* I - Second printer */
3868 void *data
) /* I - App data (not used) */
3870 return (strcasecmp(((cupsd_printer_t
*)first
)->name
,
3871 ((cupsd_printer_t
*)second
)->name
));
3876 * 'delete_printer_filters()' - Delete all MIME filters for a printer.
3880 delete_printer_filters(
3881 cupsd_printer_t
*p
) /* I - Printer to remove from */
3883 mime_filter_t
*filter
; /* MIME filter looping var */
3884 mime_type_t
*type
; /* Destination types for filters */
3888 * Range check input...
3895 * Remove all filters from the MIME database that have a destination
3896 * type == printer...
3899 for (filter
= mimeFirstFilter(MimeDatabase
);
3901 filter
= mimeNextFilter(MimeDatabase
))
3902 if (filter
->dst
== p
->filetype
|| filter
->dst
== p
->prefiltertype
||
3903 cupsArrayFind(p
->dest_types
, filter
->dst
))
3906 * Delete the current filter...
3909 mimeDeleteFilter(MimeDatabase
, filter
);
3912 for (type
= (mime_type_t
*)cupsArrayFirst(p
->dest_types
);
3914 type
= (mime_type_t
*)cupsArrayNext(p
->dest_types
))
3915 mimeDeleteType(MimeDatabase
, type
);
3917 cupsArrayDelete(p
->dest_types
);
3918 p
->dest_types
= NULL
;
3920 cupsdSetPrinterReasons(p
, "-cups-insecure-filter-warning"
3921 ",cups-missing-filter-warning");
3926 * 'dirty_printer()' - Mark config and state files dirty for the specified
3931 dirty_printer(cupsd_printer_t
*p
) /* I - Printer */
3933 if (p
->type
& CUPS_PRINTER_DISCOVERED
)
3934 cupsdMarkDirty(CUPSD_DIRTY_REMOTE
);
3935 else if (p
->type
& CUPS_PRINTER_CLASS
)
3936 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
3938 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
3940 if (PrintcapFormat
== PRINTCAP_PLIST
)
3941 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
3946 * 'load_ppd()' - Load a cached PPD file, updating the cache as needed.
3950 load_ppd(cupsd_printer_t
*p
) /* I - Printer */
3952 int i
, j
, k
; /* Looping vars */
3953 char cache_name
[1024]; /* Cache filename */
3954 struct stat cache_info
; /* Cache file info */
3955 ppd_file_t
*ppd
; /* PPD file */
3956 char ppd_name
[1024]; /* PPD filename */
3957 struct stat ppd_info
; /* PPD file info */
3958 int num_media
; /* Number of media options */
3959 ppd_size_t
*size
; /* Current PPD size */
3960 ppd_option_t
*duplex
, /* Duplex option */
3961 *output_bin
, /* OutputBin option */
3962 *output_mode
, /* OutputMode option */
3963 *resolution
; /* (Set|JCL|)Resolution option */
3964 ppd_choice_t
*choice
, /* Current PPD choice */
3965 *input_slot
, /* Current input slot */
3966 *media_type
; /* Current media type */
3967 ppd_attr_t
*ppd_attr
; /* PPD attribute */
3968 int xdpi
, /* Horizontal resolution */
3969 ydpi
; /* Vertical resolution */
3970 const char *resptr
; /* Pointer into resolution keyword */
3971 _pwg_size_t
*pwgsize
; /* Current PWG size */
3972 _pwg_map_t
*pwgsource
, /* Current PWG source */
3973 *pwgtype
; /* Current PWG type */
3974 ipp_attribute_t
*attr
; /* Attribute data */
3975 ipp_value_t
*val
; /* Attribute value */
3976 int num_finishings
, /* Number of finishings */
3977 finishings
[5]; /* finishings-supported values */
3978 int num_qualities
, /* Number of print-quality values */
3979 qualities
[3]; /* print-quality values */
3980 int num_margins
, /* Number of media-*-margin-supported values */
3981 margins
[16]; /* media-*-margin-supported values */
3982 const char *filter
; /* Current filter */
3983 static const char * const sides
[3] = /* sides-supported values */
3986 "two-sided-long-edge",
3987 "two-sided-short-edge"
3989 static const char * const standard_commands
[] =
3990 { /* Standard CUPS commands */
3998 * Check to see if the cache is up-to-date...
4001 snprintf(cache_name
, sizeof(cache_name
), "%s/%s.data", CacheDir
, p
->name
);
4002 if (stat(cache_name
, &cache_info
))
4003 cache_info
.st_mtime
= 0;
4005 snprintf(ppd_name
, sizeof(ppd_name
), "%s/ppd/%s.ppd", ServerRoot
, p
->name
);
4006 if (stat(ppd_name
, &ppd_info
))
4007 ppd_info
.st_mtime
= 1;
4009 ippDelete(p
->ppd_attrs
);
4010 p
->ppd_attrs
= NULL
;
4012 _ppdCacheDestroy(p
->pc
);
4015 if (cache_info
.st_mtime
>= ppd_info
.st_mtime
)
4017 cupsdLogMessage(CUPSD_LOG_DEBUG
, "load_ppd: Loading %s...", cache_name
);
4019 if ((p
->pc
= _ppdCacheCreateWithFile(cache_name
, &p
->ppd_attrs
)) != NULL
&&
4023 * Loaded successfully!
4031 * Reload PPD attributes from disk...
4034 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
4036 cupsdLogMessage(CUPSD_LOG_DEBUG
, "load_ppd: Loading %s...", ppd_name
);
4038 p
->type
&= ~CUPS_PRINTER_OPTIONS
;
4039 p
->type
|= CUPS_PRINTER_BW
;
4041 finishings
[0] = IPP_FINISHINGS_NONE
;
4044 p
->ppd_attrs
= ippNew();
4046 if ((ppd
= ppdOpenFile(ppd_name
)) != NULL
)
4049 * Add make/model and other various attributes...
4052 p
->pc
= _ppdCacheCreateWithPPD(ppd
);
4054 ppdMarkDefaults(ppd
);
4056 if (ppd
->color_device
)
4057 p
->type
|= CUPS_PRINTER_COLOR
;
4058 if (ppd
->variable_sizes
)
4059 p
->type
|= CUPS_PRINTER_VARIABLE
;
4060 if (!ppd
->manual_copies
)
4061 p
->type
|= CUPS_PRINTER_COPIES
;
4062 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsFax", NULL
)) != NULL
)
4063 if (ppd_attr
->value
&& !strcasecmp(ppd_attr
->value
, "true"))
4064 p
->type
|= CUPS_PRINTER_FAX
;
4066 ippAddBoolean(p
->ppd_attrs
, IPP_TAG_PRINTER
, "color-supported",
4068 if (ppd
->throughput
)
4070 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4071 "pages-per-minute", ppd
->throughput
);
4072 if (ppd
->color_device
)
4073 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4074 "pages-per-minute-color", ppd
->throughput
);
4079 * When there is no speed information, just say "1 page per minute".
4082 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4083 "pages-per-minute", 1);
4084 if (ppd
->color_device
)
4085 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4086 "pages-per-minute-color", 1);
4091 if ((output_mode
= ppdFindOption(ppd
, "OutputMode")) != NULL
)
4093 if (ppdFindChoice(output_mode
, "draft") ||
4094 ppdFindChoice(output_mode
, "fast"))
4095 qualities
[num_qualities
++] = IPP_QUALITY_DRAFT
;
4097 qualities
[num_qualities
++] = IPP_QUALITY_NORMAL
;
4099 if (ppdFindChoice(output_mode
, "best") ||
4100 ppdFindChoice(output_mode
, "high"))
4101 qualities
[num_qualities
++] = IPP_QUALITY_HIGH
;
4103 else if ((ppd_attr
= ppdFindAttr(ppd
, "APPrinterPreset", NULL
)) != NULL
)
4107 if (strstr(ppd_attr
->spec
, "draft") ||
4108 strstr(ppd_attr
->spec
, "Draft"))
4110 qualities
[num_qualities
++] = IPP_QUALITY_DRAFT
;
4114 while ((ppd_attr
= ppdFindNextAttr(ppd
, "APPrinterPreset",
4117 qualities
[num_qualities
++] = IPP_QUALITY_NORMAL
;
4118 qualities
[num_qualities
++] = IPP_QUALITY_HIGH
;
4121 qualities
[num_qualities
++] = IPP_QUALITY_NORMAL
;
4123 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
4124 "print-quality-supported", num_qualities
, qualities
);
4129 * The NickName can be localized in the character set specified
4130 * by the LanugageEncoding attribute. However, ppdOpen2() has
4131 * already converted the ppd->nickname member to UTF-8 for us
4132 * (the original attribute value is available separately)
4135 cupsdSetString(&p
->make_model
, ppd
->nickname
);
4137 else if (ppd
->modelname
)
4140 * Model name can only contain specific characters...
4143 cupsdSetString(&p
->make_model
, ppd
->modelname
);
4146 cupsdSetString(&p
->make_model
, "Bad PPD File");
4148 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
4149 "printer-make-and-model", NULL
, p
->make_model
);
4152 * Add media options from the PPD file...
4155 if (ppd
->num_sizes
== 0 || !p
->pc
)
4157 if (!ppdFindAttr(ppd
, "APScannerOnly", NULL
))
4158 cupsdLogMessage(CUPSD_LOG_CRIT
,
4159 "The PPD file for printer %s contains no media "
4160 "options and is therefore invalid!", p
->name
);
4162 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4163 "media-default", NULL
, "unknown");
4164 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4165 "media-supported", NULL
, "unknown");
4173 if ((size
= ppdPageSize(ppd
, NULL
)) != NULL
)
4174 pwgsize
= _ppdCacheGetSize(p
->pc
, size
->name
);
4178 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4179 "media-default", NULL
,
4180 pwgsize
? pwgsize
->map
.pwg
: "unknown");
4188 ipp_t
*col
; /* Collection value */
4190 input_slot
= ppdFindMarkedChoice(ppd
, "InputSlot");
4191 media_type
= ppdFindMarkedChoice(ppd
, "MediaType");
4192 col
= new_media_col(pwgsize
,
4194 _ppdCacheGetSource(p
->pc
,
4195 input_slot
->choice
) :
4198 _ppdCacheGetType(p
->pc
,
4199 media_type
->choice
) :
4202 ippAddCollection(p
->ppd_attrs
, IPP_TAG_PRINTER
, "media-col-default",
4211 num_media
= p
->pc
->num_sizes
;
4212 if (p
->pc
->custom_min_keyword
)
4215 if ((attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4216 "media-supported", num_media
, NULL
,
4221 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
;
4223 i
--, pwgsize
++, val
++)
4224 val
->string
.text
= _cupsStrRetain(pwgsize
->map
.pwg
);
4226 if (p
->pc
->custom_min_keyword
)
4228 val
->string
.text
= _cupsStrRetain(p
->pc
->custom_min_keyword
);
4230 val
->string
.text
= _cupsStrRetain(p
->pc
->custom_max_keyword
);
4235 * media-source-supported
4238 if (p
->pc
->num_sources
> 0 &&
4239 (attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4240 "media-source-supported", p
->pc
->num_sources
,
4241 NULL
, NULL
)) != NULL
)
4243 for (i
= p
->pc
->num_sources
, pwgsource
= p
->pc
->sources
,
4246 i
--, pwgsource
++, val
++)
4247 val
->string
.text
= _cupsStrRetain(pwgsource
->pwg
);
4251 * media-type-supported
4254 if (p
->pc
->num_types
> 0 &&
4255 (attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4256 "media-type-supported", p
->pc
->num_types
,
4257 NULL
, NULL
)) != NULL
)
4259 for (i
= p
->pc
->num_types
, pwgtype
= p
->pc
->types
,
4262 i
--, pwgtype
++, val
++)
4263 val
->string
.text
= _cupsStrRetain(pwgtype
->pwg
);
4267 * media-*-margin-supported
4270 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, num_margins
= 0;
4271 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4274 for (j
= 0; j
< num_margins
; j
++)
4275 if (pwgsize
->bottom
== margins
[j
])
4278 if (j
>= num_margins
)
4280 margins
[num_margins
] = pwgsize
->bottom
;
4285 if (num_margins
> 0)
4286 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4287 "media-bottom-margin-supported", num_margins
, margins
);
4289 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4290 "media-bottom-margin-supported", 0);
4292 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, num_margins
= 0;
4293 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4296 for (j
= 0; j
< num_margins
; j
++)
4297 if (pwgsize
->left
== margins
[j
])
4300 if (j
>= num_margins
)
4302 margins
[num_margins
] = pwgsize
->left
;
4307 if (num_margins
> 0)
4308 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4309 "media-left-margin-supported", num_margins
, margins
);
4311 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4312 "media-left-margin-supported", 0);
4314 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, num_margins
= 0;
4315 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4318 for (j
= 0; j
< num_margins
; j
++)
4319 if (pwgsize
->right
== margins
[j
])
4322 if (j
>= num_margins
)
4324 margins
[num_margins
] = pwgsize
->right
;
4329 if (num_margins
> 0)
4330 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4331 "media-right-margin-supported", num_margins
, margins
);
4333 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4334 "media-right-margin-supported", 0);
4336 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, num_margins
= 0;
4337 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4340 for (j
= 0; j
< num_margins
; j
++)
4341 if (pwgsize
->top
== margins
[j
])
4344 if (j
>= num_margins
)
4346 margins
[num_margins
] = pwgsize
->top
;
4351 if (num_margins
> 0)
4352 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4353 "media-top-margin-supported", num_margins
, margins
);
4355 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4356 "media-top-margin-supported", 0);
4359 * media-col-database
4362 num_media
= p
->pc
->num_sizes
;
4363 if (p
->pc
->num_sources
)
4365 if (p
->pc
->num_types
> 0)
4366 num_media
+= p
->pc
->num_sizes
* p
->pc
->num_sources
*
4369 num_media
+= p
->pc
->num_sizes
* p
->pc
->num_sources
;
4371 else if (p
->pc
->num_types
)
4372 num_media
+= p
->pc
->num_sizes
* p
->pc
->num_types
;
4374 if ((attr
= ippAddCollections(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4375 "media-col-database", num_media
,
4378 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, val
= attr
->values
;
4383 * Start by adding the page size without source or type...
4386 ppdMarkOption(ppd
, "PageSize", pwgsize
->map
.ppd
);
4388 val
->collection
= new_media_col(pwgsize
, NULL
, NULL
);
4392 * Then add the specific, supported combinations of size, source, and
4396 if (p
->pc
->num_sources
> 0)
4398 for (j
= p
->pc
->num_sources
, pwgsource
= p
->pc
->sources
;
4402 ppdMarkOption(ppd
, "InputSlot", pwgsource
->ppd
);
4404 if (p
->pc
->num_types
> 0)
4406 for (k
= p
->pc
->num_types
, pwgtype
= p
->pc
->types
;
4410 if (!ppdMarkOption(ppd
, "MediaType", pwgtype
->ppd
))
4412 val
->collection
= new_media_col(pwgsize
, pwgsource
->pwg
,
4418 else if (!ppdConflicts(ppd
))
4420 val
->collection
= new_media_col(pwgsize
, pwgsource
->pwg
, NULL
);
4425 else if (p
->pc
->num_types
> 0)
4427 for (j
= p
->pc
->num_types
, pwgtype
= p
->pc
->types
;
4431 if (!ppdMarkOption(ppd
, "MediaType", pwgtype
->ppd
))
4433 val
->collection
= new_media_col(pwgsize
, NULL
, pwgtype
->pwg
);
4441 * Update the number of media-col-database values...
4444 attr
->num_values
= val
- attr
->values
;
4452 if (p
->pc
&& p
->pc
->num_bins
> 0)
4454 attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4455 "output-bin-supported", p
->pc
->num_bins
,
4460 for (i
= 0, val
= attr
->values
;
4461 i
< p
->pc
->num_bins
;
4463 val
->string
.text
= _cupsStrAlloc(p
->pc
->bins
[i
].pwg
);
4466 if ((output_bin
= ppdFindOption(ppd
, "OutputBin")) != NULL
)
4468 for (i
= 0; i
< p
->pc
->num_bins
; i
++)
4469 if (!strcmp(p
->pc
->bins
[i
].ppd
, output_bin
->defchoice
))
4472 if (i
>= p
->pc
->num_bins
)
4475 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4476 "output-bin-default", NULL
, p
->pc
->bins
[i
].pwg
);
4479 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4480 "output-bin-default", NULL
, p
->pc
->bins
[0].pwg
);
4482 else if (((ppd_attr
= ppdFindAttr(ppd
, "DefaultOutputOrder",
4484 !strcasecmp(ppd_attr
->value
, "Reverse")) ||
4485 (!ppd_attr
&& ppd
->manufacturer
&& /* "Compatibility heuristic" */
4486 (!strcasecmp(ppd
->manufacturer
, "epson") ||
4487 !strcasecmp(ppd
->manufacturer
, "lexmark"))))
4490 * Report that this printer has a single output bin that leaves pages face
4494 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4495 "output-bin-supported", NULL
, "face-up");
4496 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4497 "output-bin-default", NULL
, "face-up");
4501 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4502 "output-bin-supported", NULL
, "face-down");
4503 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4504 "output-bin-default", NULL
, "face-down");
4508 * output-mode and print-color-mode...
4511 if (ppd
->color_device
)
4513 static const char * const output_modes
[] =
4519 ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4520 "output-mode-supported", 2, NULL
, output_modes
);
4521 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4522 "output-mode-default", NULL
, "color");
4524 ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4525 "print-color-mode-supported", 2, NULL
, output_modes
);
4526 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4527 "print-color-mode-default", NULL
, "color");
4531 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4532 "output-mode-supported", NULL
, "monochrome");
4533 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4534 "output-mode-default", NULL
, "monochrome");
4536 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4537 "print-color-mode-supported", NULL
, "monochrome");
4538 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4539 "print-color-mode-default", NULL
, "monochrome");
4543 * Printer resolutions...
4546 if ((resolution
= ppdFindOption(ppd
, "Resolution")) == NULL
)
4547 if ((resolution
= ppdFindOption(ppd
, "JCLResolution")) == NULL
)
4548 if ((resolution
= ppdFindOption(ppd
, "SetResolution")) == NULL
)
4549 resolution
= ppdFindOption(ppd
, "CNRes_PGP");
4554 * Report all supported resolutions...
4557 attr
= ippAddResolutions(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4558 "printer-resolution-supported",
4559 resolution
->num_choices
, IPP_RES_PER_INCH
,
4562 for (i
= 0, choice
= resolution
->choices
;
4563 i
< resolution
->num_choices
;
4566 xdpi
= ydpi
= (int)strtol(choice
->choice
, (char **)&resptr
, 10);
4567 if (resptr
> choice
->choice
&& xdpi
> 0 && *resptr
== 'x')
4568 ydpi
= (int)strtol(resptr
+ 1, (char **)&resptr
, 10);
4570 if (xdpi
<= 0 || ydpi
<= 0)
4572 cupsdLogMessage(CUPSD_LOG_WARN
,
4573 "Bad resolution \"%s\" for printer %s.",
4574 choice
->choice
, p
->name
);
4578 attr
->values
[i
].resolution
.xres
= xdpi
;
4579 attr
->values
[i
].resolution
.yres
= ydpi
;
4580 attr
->values
[i
].resolution
.units
= IPP_RES_PER_INCH
;
4583 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4584 "printer-resolution-default", IPP_RES_PER_INCH
,
4588 else if ((ppd_attr
= ppdFindAttr(ppd
, "DefaultResolution", NULL
)) != NULL
&&
4592 * Just the DefaultResolution to report...
4595 xdpi
= ydpi
= (int)strtol(ppd_attr
->value
, (char **)&resptr
, 10);
4596 if (resptr
> ppd_attr
->value
&& xdpi
> 0)
4599 ydpi
= (int)strtol(resptr
+ 1, (char **)&resptr
, 10);
4604 if (xdpi
<= 0 || ydpi
<= 0)
4606 cupsdLogMessage(CUPSD_LOG_WARN
,
4607 "Bad default resolution \"%s\" for printer %s.",
4608 ppd_attr
->value
, p
->name
);
4612 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4613 "printer-resolution-default", IPP_RES_PER_INCH
,
4615 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4616 "printer-resolution-supported", IPP_RES_PER_INCH
,
4622 * No resolutions in PPD - make one up...
4625 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4626 "printer-resolution-default", IPP_RES_PER_INCH
,
4628 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4629 "printer-resolution-supported", IPP_RES_PER_INCH
,
4637 ppdMarkDefaults(ppd
);
4639 if ((duplex
= ppdFindOption(ppd
, "Duplex")) == NULL
)
4640 if ((duplex
= ppdFindOption(ppd
, "EFDuplex")) == NULL
)
4641 if ((duplex
= ppdFindOption(ppd
, "EFDuplexing")) == NULL
)
4642 if ((duplex
= ppdFindOption(ppd
, "KD03Duplex")) == NULL
)
4643 duplex
= ppdFindOption(ppd
, "JCLDuplex");
4645 if (duplex
&& duplex
->num_choices
> 1 &&
4646 !ppdInstallableConflict(ppd
, duplex
->keyword
, "DuplexTumble"))
4648 p
->type
|= CUPS_PRINTER_DUPLEX
;
4650 ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4651 "sides-supported", 3, NULL
, sides
);
4653 if (!strcasecmp(duplex
->defchoice
, "DuplexTumble"))
4654 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4655 "sides-default", NULL
, "two-sided-short-edge");
4656 else if (!strcasecmp(duplex
->defchoice
, "DuplexNoTumble"))
4657 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4658 "sides-default", NULL
, "two-sided-long-edge");
4660 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4661 "sides-default", NULL
, "one-sided");
4665 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4666 "sides-supported", NULL
, "one-sided");
4667 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4668 "sides-default", NULL
, "one-sided");
4671 if (ppdFindOption(ppd
, "Collate") != NULL
)
4672 p
->type
|= CUPS_PRINTER_COLLATE
;
4674 if (ppdFindOption(ppd
, "StapleLocation") != NULL
)
4676 p
->type
|= CUPS_PRINTER_STAPLE
;
4677 finishings
[num_finishings
++] = IPP_FINISHINGS_STAPLE
;
4680 if (ppdFindOption(ppd
, "BindEdge") != NULL
)
4682 p
->type
|= CUPS_PRINTER_BIND
;
4683 finishings
[num_finishings
++] = IPP_FINISHINGS_BIND
;
4686 for (i
= 0; i
< ppd
->num_sizes
; i
++)
4687 if (ppd
->sizes
[i
].length
> 1728)
4688 p
->type
|= CUPS_PRINTER_LARGE
;
4689 else if (ppd
->sizes
[i
].length
> 1008)
4690 p
->type
|= CUPS_PRINTER_MEDIUM
;
4692 p
->type
|= CUPS_PRINTER_SMALL
;
4694 if ((ppd_attr
= ppdFindAttr(ppd
, "APICADriver", NULL
)) != NULL
&&
4695 ppd_attr
->value
&& !strcasecmp(ppd_attr
->value
, "true"))
4697 if ((ppd_attr
= ppdFindAttr(ppd
, "APScannerOnly", NULL
)) != NULL
&&
4698 ppd_attr
->value
&& !strcasecmp(ppd_attr
->value
, "true"))
4699 p
->type
|= CUPS_PRINTER_SCANNER
;
4701 p
->type
|= CUPS_PRINTER_MFP
;
4705 * Scan the filters in the PPD file...
4710 for (filter
= (const char *)cupsArrayFirst(p
->pc
->filters
);
4712 filter
= (const char *)cupsArrayNext(p
->pc
->filters
))
4714 if (!strncasecmp(filter
, "application/vnd.cups-command", 28) &&
4715 _cups_isspace(filter
[28]))
4717 p
->type
|= CUPS_PRINTER_COMMANDS
;
4723 if (p
->type
& CUPS_PRINTER_COMMANDS
)
4725 char *commands
, /* Copy of commands */
4726 *start
, /* Start of name */
4727 *end
; /* End of name */
4728 int count
; /* Number of commands */
4730 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsCommands", NULL
)) != NULL
)
4732 for (count
= 0, start
= ppd_attr
->value
; *start
; count
++)
4734 while (_cups_isspace(*start
))
4740 while (*start
&& !isspace(*start
& 255))
4750 * Make a copy of the commands string and count how many commands there
4754 attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4755 "printer-commands", count
, NULL
, NULL
);
4757 commands
= strdup(ppd_attr
->value
);
4759 for (count
= 0, start
= commands
; *start
; count
++)
4761 while (isspace(*start
& 255))
4768 while (*end
&& !isspace(*end
& 255))
4774 attr
->values
[count
].string
.text
= _cupsStrAlloc(start
);
4784 * Add the standard list of commands...
4787 ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4789 (int)(sizeof(standard_commands
) /
4790 sizeof(standard_commands
[0])), NULL
,
4797 * No commands supported...
4800 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4801 "printer-commands", NULL
, "none");
4805 * Show current and available port monitors for this printer...
4808 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
, "port-monitor",
4809 NULL
, p
->port_monitor
? p
->port_monitor
: "none");
4811 for (i
= 1, ppd_attr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
4813 i
++, ppd_attr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
));
4817 if (strstr(ppd
->protocols
, "TBCP"))
4819 else if (strstr(ppd
->protocols
, "BCP"))
4823 attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
4824 "port-monitor-supported", i
, NULL
, NULL
);
4826 attr
->values
[0].string
.text
= _cupsStrAlloc("none");
4828 for (i
= 1, ppd_attr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
4830 i
++, ppd_attr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
))
4831 attr
->values
[i
].string
.text
= _cupsStrAlloc(ppd_attr
->value
);
4835 if (strstr(ppd
->protocols
, "TBCP"))
4836 attr
->values
[i
].string
.text
= _cupsStrAlloc("tbcp");
4837 else if (strstr(ppd
->protocols
, "BCP"))
4838 attr
->values
[i
].string
.text
= _cupsStrAlloc("bcp");
4841 if (ppdFindAttr(ppd
, "APRemoteQueueID", NULL
))
4842 p
->type
|= CUPS_PRINTER_REMOTE
;
4844 #ifdef HAVE_APPLICATIONSERVICES_H
4846 * Convert the file referenced in APPrinterIconPath to a 128x128 PNG
4847 * and save it as cacheDir/printername.png
4850 if ((ppd_attr
= ppdFindAttr(ppd
, "APPrinterIconPath", NULL
)) != NULL
&&
4852 !_cupsFileCheck(ppd_attr
->value
, _CUPS_FILE_CHECK_FILE
, !RunUser
,
4853 cupsdLogFCMessage
, p
))
4855 CGImageRef imageRef
= NULL
;/* Current icon image */
4856 CGImageRef biggestIconRef
= NULL
;
4857 /* Biggest icon image */
4858 CGImageRef closestTo128IconRef
= NULL
;
4859 /* Icon image closest to and >= 128 */
4860 CGImageSourceRef sourceRef
; /* The file's image source */
4861 char outPath
[HTTP_MAX_URI
];
4862 /* The path to the PNG file */
4863 CFURLRef outUrl
; /* The URL made from the outPath */
4864 CFURLRef icnsFileUrl
; /* The URL of the original ICNS icon file */
4865 CGImageDestinationRef destRef
; /* The image destination to write */
4866 size_t bytesPerRow
; /* The bytes per row used for resizing */
4867 CGContextRef context
; /* The CG context used for resizing */
4869 snprintf(outPath
, sizeof(outPath
), "%s/%s.png", CacheDir
, p
->name
);
4870 outUrl
= CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault
,
4874 icnsFileUrl
= CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault
,
4875 (UInt8
*)ppd_attr
->value
,
4876 strlen(ppd_attr
->value
),
4878 if (outUrl
&& icnsFileUrl
)
4880 sourceRef
= CGImageSourceCreateWithURL(icnsFileUrl
, NULL
);
4883 for (i
= 0; i
< CGImageSourceGetCount(sourceRef
); i
++)
4885 imageRef
= CGImageSourceCreateImageAtIndex(sourceRef
, i
, NULL
);
4889 if (CGImageGetWidth(imageRef
) == CGImageGetHeight(imageRef
))
4892 * Loop through remembering the icon closest to 128 but >= 128
4893 * and then remember the largest icon.
4896 if (CGImageGetWidth(imageRef
) >= 128 &&
4897 (!closestTo128IconRef
||
4898 CGImageGetWidth(imageRef
) <
4899 CGImageGetWidth(closestTo128IconRef
)))
4901 CGImageRelease(closestTo128IconRef
);
4902 CGImageRetain(imageRef
);
4903 closestTo128IconRef
= imageRef
;
4906 if (!biggestIconRef
||
4907 CGImageGetWidth(imageRef
) > CGImageGetWidth(biggestIconRef
))
4909 CGImageRelease(biggestIconRef
);
4910 CGImageRetain(imageRef
);
4911 biggestIconRef
= imageRef
;
4915 CGImageRelease(imageRef
);
4921 * If biggestIconRef is NULL, we found no icons. Otherwise we first
4922 * want the closest to 128, but if none are larger than 128, we want
4923 * the largest icon available.
4926 imageRef
= closestTo128IconRef
? closestTo128IconRef
:
4928 CGImageRetain(imageRef
);
4929 CGImageRelease(biggestIconRef
);
4930 if (closestTo128IconRef
)
4931 CGImageRelease(closestTo128IconRef
);
4932 destRef
= CGImageDestinationCreateWithURL(outUrl
, kUTTypePNG
, 1,
4936 if (CGImageGetWidth(imageRef
) != 128)
4938 bytesPerRow
= CGImageGetBytesPerRow(imageRef
) /
4939 CGImageGetWidth(imageRef
) * 128;
4940 context
= CGBitmapContextCreate(NULL
, 128, 128,
4941 CGImageGetBitsPerComponent(imageRef
),
4943 CGImageGetColorSpace(imageRef
),
4944 kCGImageAlphaPremultipliedFirst
);
4947 CGContextDrawImage(context
, CGRectMake(0, 0, 128, 128),
4949 CGImageRelease(imageRef
);
4950 imageRef
= CGBitmapContextCreateImage(context
);
4951 CGContextRelease(context
);
4955 CGImageDestinationAddImage(destRef
, imageRef
, NULL
);
4956 CGImageDestinationFinalize(destRef
);
4960 CGImageRelease(imageRef
);
4963 CFRelease(sourceRef
);
4971 CFRelease(icnsFileUrl
);
4973 #endif /* HAVE_APPLICATIONSERVICES_H */
4976 * Close the PPD and set the type...
4981 else if (!access(ppd_name
, 0))
4983 int pline
; /* PPD line number */
4984 ppd_status_t pstatus
; /* PPD load status */
4987 pstatus
= ppdLastError(&pline
);
4989 cupsdLogMessage(CUPSD_LOG_ERROR
, "PPD file for %s cannot be loaded!",
4992 if (pstatus
<= PPD_ALLOC_ERROR
)
4993 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s", strerror(errno
));
4995 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s on line %d.",
4996 ppdErrorString(pstatus
), pline
);
4998 cupsdLogMessage(CUPSD_LOG_INFO
,
4999 "Hint: Run \"cupstestppd %s\" and fix any errors.",
5005 * If we have an interface script, add a filter entry for it...
5008 char interface
[1024]; /* Interface script */
5011 snprintf(interface
, sizeof(interface
), "%s/interfaces/%s", ServerRoot
,
5013 if (!access(interface
, X_OK
))
5016 * Yes, we have a System V style interface script; use it!
5019 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
5020 "printer-make-and-model", NULL
,
5021 "Local System V Printer");
5023 else if (!strncmp(p
->device_uri
, "ipp://", 6) &&
5024 (strstr(p
->device_uri
, "/printers/") != NULL
||
5025 strstr(p
->device_uri
, "/classes/") != NULL
||
5026 (strstr(p
->device_uri
, "._ipp.") != NULL
&&
5027 !strcmp(p
->device_uri
+ strlen(p
->device_uri
) - 5,
5031 * Tell the client this is really a hard-wired remote printer.
5034 p
->type
|= CUPS_PRINTER_REMOTE
;
5037 * Point the printer-uri-supported attribute to the
5041 if (strchr(p
->device_uri
, '?'))
5044 * Strip trailing "?options" from URI...
5047 char resource
[HTTP_MAX_URI
], /* New URI */
5048 *ptr
; /* Pointer into URI */
5050 strlcpy(resource
, p
->device_uri
, sizeof(resource
));
5051 if ((ptr
= strchr(resource
, '?')) != NULL
)
5054 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
5055 "printer-uri-supported", NULL
, resource
);
5058 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
5059 "printer-uri-supported", NULL
, p
->device_uri
);
5062 * Then set the make-and-model accordingly...
5065 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
5066 "printer-make-and-model", NULL
, "Remote Printer");
5069 * Print all files directly...
5078 * Otherwise we have neither - treat this as a "dumb" printer
5079 * with no PPD file...
5082 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
5083 "printer-make-and-model", NULL
, "Local Raw Printer");
5089 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
5090 "finishings-supported", num_finishings
, finishings
);
5091 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
5092 "finishings-default", IPP_FINISHINGS_NONE
);
5097 * Save cached PPD attributes to disk...
5100 cupsdLogMessage(CUPSD_LOG_DEBUG
, "load_ppd: Saving %s...", cache_name
);
5102 _ppdCacheWriteFile(p
->pc
, cache_name
, p
->ppd_attrs
);
5107 * Remove cache files...
5110 if (cache_info
.st_mtime
)
5117 * 'new_media_col()' - Create a media-col collection value.
5120 static ipp_t
* /* O - Collection value */
5121 new_media_col(_pwg_size_t
*size
, /* I - media-size/margin values */
5122 const char *source
, /* I - media-source value */
5123 const char *type
) /* I - media-type value */
5125 ipp_t
*media_col
, /* Collection value */
5126 *media_size
; /* media-size value */
5129 media_col
= ippNew();
5131 media_size
= ippNew();
5132 ippAddInteger(media_size
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5133 "x-dimension", size
->width
);
5134 ippAddInteger(media_size
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5135 "y-dimension", size
->length
);
5136 ippAddCollection(media_col
, IPP_TAG_PRINTER
, "media-size", media_size
);
5137 ippDelete(media_size
);
5139 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5140 "media-bottom-margin", size
->bottom
);
5141 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5142 "media-left-margin", size
->left
);
5143 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5144 "media-right-margin", size
->right
);
5145 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5146 "media-top-margin", size
->top
);
5149 ippAddString(media_col
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
, "media-source",
5153 ippAddString(media_col
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
, "media-type",
5162 * 'write_irix_config()' - Update the config files used by the IRIX
5167 write_irix_config(cupsd_printer_t
*p
) /* I - Printer to update */
5169 char filename
[1024]; /* Interface script filename */
5170 cups_file_t
*fp
; /* Interface script file */
5171 ipp_attribute_t
*attr
; /* Attribute data */
5175 * Add dummy interface and GUI scripts to fool SGI's "challenged" printing
5176 * tools. First the interface script that tells the tools what kind of
5177 * printer we have...
5180 snprintf(filename
, sizeof(filename
), "/var/spool/lp/interface/%s", p
->name
);
5182 if (p
->type
& CUPS_PRINTER_CLASS
)
5184 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
5186 cupsFilePuts(fp
, "#!/bin/sh\n");
5188 if ((attr
= ippFindAttribute(p
->attrs
, "printer-make-and-model",
5189 IPP_TAG_TEXT
)) != NULL
)
5190 cupsFilePrintf(fp
, "NAME=\"%s\"\n", attr
->values
[0].string
.text
);
5191 else if (p
->type
& CUPS_PRINTER_CLASS
)
5192 cupsFilePuts(fp
, "NAME=\"Printer Class\"\n");
5194 cupsFilePuts(fp
, "NAME=\"Remote Destination\"\n");
5196 if (p
->type
& CUPS_PRINTER_COLOR
)
5197 cupsFilePuts(fp
, "TYPE=ColorPostScript\n");
5199 cupsFilePuts(fp
, "TYPE=MonoPostScript\n");
5201 cupsFilePrintf(fp
, "HOSTNAME=%s\n", ServerName
);
5202 cupsFilePrintf(fp
, "HOSTPRINTER=%s\n", p
->name
);
5206 chmod(filename
, 0755);
5207 chown(filename
, User
, Group
);
5211 * Then the member file that tells which device file the queue is connected
5212 * to... Networked printers use "/dev/null" in this file, so that's what
5213 * we use (the actual device URI can confuse some apps...)
5216 snprintf(filename
, sizeof(filename
), "/var/spool/lp/member/%s", p
->name
);
5218 if (p
->type
& CUPS_PRINTER_CLASS
)
5220 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
5222 cupsFilePuts(fp
, "/dev/null\n");
5226 chmod(filename
, 0644);
5227 chown(filename
, User
, Group
);
5231 * The gui_interface file is a script or program that launches a GUI
5232 * option panel for the printer, using options specified on the
5233 * command-line in the third argument. The option panel must send
5234 * any printing options to stdout on a single line when the user
5235 * accepts them, or nothing if the user cancels the dialog.
5237 * The default options panel program is /usr/bin/glpoptions, from
5238 * the ESP Print Pro software. You can select another using the
5239 * PrintcapGUI option.
5242 snprintf(filename
, sizeof(filename
), "/var/spool/lp/gui_interface/ELF/%s.gui", p
->name
);
5244 if (p
->type
& CUPS_PRINTER_CLASS
)
5246 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
5248 cupsFilePuts(fp
, "#!/bin/sh\n");
5249 cupsFilePrintf(fp
, "%s -d %s -o \"$3\"\n", PrintcapGUI
, p
->name
);
5253 chmod(filename
, 0755);
5254 chown(filename
, User
, Group
);
5258 * The POD config file is needed by the printstatus command to show
5259 * the printer location and device.
5262 snprintf(filename
, sizeof(filename
), "/var/spool/lp/pod/%s.config", p
->name
);
5264 if (p
->type
& CUPS_PRINTER_CLASS
)
5266 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
5268 cupsFilePrintf(fp
, "Printer Class | %s\n",
5269 (p
->type
& CUPS_PRINTER_COLOR
) ? "ColorPostScript" : "MonoPostScript");
5270 cupsFilePrintf(fp
, "Printer Model | %s\n", p
->make_model
? p
->make_model
: "");
5271 cupsFilePrintf(fp
, "Location Code | %s\n", p
->location
? p
->location
: "");
5272 cupsFilePrintf(fp
, "Physical Location | %s\n", p
->info
? p
->info
: "");
5273 cupsFilePrintf(fp
, "Port Path | %s\n", p
->device_uri
);
5274 cupsFilePrintf(fp
, "Config Path | /var/spool/lp/pod/%s.config\n", p
->name
);
5275 cupsFilePrintf(fp
, "Active Status Path | /var/spool/lp/pod/%s.status\n", p
->name
);
5276 cupsFilePuts(fp
, "Status Update Wait | 10 seconds\n");
5280 chmod(filename
, 0664);
5281 chown(filename
, User
, Group
);
5287 * 'write_irix_state()' - Update the status files used by IRIX printing
5292 write_irix_state(cupsd_printer_t
*p
) /* I - Printer to update */
5294 char filename
[1024]; /* Interface script filename */
5295 cups_file_t
*fp
; /* Interface script file */
5296 int tag
; /* Status tag value */
5302 * The POD status file is needed for the printstatus window to
5303 * provide the current status of the printer.
5306 snprintf(filename
, sizeof(filename
), "/var/spool/lp/pod/%s.status", p
->name
);
5308 if (p
->type
& CUPS_PRINTER_CLASS
)
5310 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
5312 cupsFilePrintf(fp
, "Operational Status | %s\n",
5313 (p
->state
== IPP_PRINTER_IDLE
) ? "Idle" :
5314 (p
->state
== IPP_PRINTER_PROCESSING
) ? "Busy" :
5316 cupsFilePrintf(fp
, "Information | 01 00 00 | %s\n", CUPS_SVERSION
);
5317 cupsFilePrintf(fp
, "Information | 02 00 00 | Device URI: %s\n",
5319 cupsFilePrintf(fp
, "Information | 03 00 00 | %s jobs\n",
5320 p
->accepting
? "Accepting" : "Not accepting");
5321 cupsFilePrintf(fp
, "Information | 04 00 00 | %s\n", p
->state_message
);
5325 chmod(filename
, 0664);
5326 chown(filename
, User
, Group
);
5330 * The activeicons file is needed to provide desktop icons for printers:
5332 * [ quoted from /usr/lib/print/tagit ]
5334 * --- Type of printer tags (base values)
5336 * Dumb=66048 # 0x10200
5337 * DumbColor=66080 # 0x10220
5338 * Raster=66112 # 0x10240
5339 * ColorRaster=66144 # 0x10260
5340 * Plotter=66176 # 0x10280
5341 * PostScript=66208 # 0x102A0
5342 * ColorPostScript=66240 # 0x102C0
5343 * MonoPostScript=66272 # 0x102E0
5345 * --- Printer state modifiers for local printers
5350 * Unknown=3 # 0x3 (Faulted due to unknown reason)
5352 * --- Printer state modifiers for network printers
5356 * NetFaulted=10 # 0xA
5357 * NetUnknown=11 # 0xB (Faulted due to unknown reason)
5360 snprintf(filename
, sizeof(filename
), "/var/spool/lp/activeicons/%s", p
->name
);
5362 if (p
->type
& CUPS_PRINTER_CLASS
)
5364 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
5366 if (p
->type
& CUPS_PRINTER_COLOR
)
5371 if (p
->type
& CUPS_PRINTER_REMOTE
)
5374 if (p
->state
== IPP_PRINTER_PROCESSING
)
5377 else if (p
->state
== IPP_PRINTER_STOPPED
)
5380 cupsFilePuts(fp
, "#!/bin/sh\n");
5381 cupsFilePrintf(fp
, "#Tag %d\n", tag
);
5385 chmod(filename
, 0755);
5386 chown(filename
, User
, Group
);
5391 * The default file is needed by the printers window to show
5392 * the default printer.
5395 snprintf(filename
, sizeof(filename
), "/var/spool/lp/default");
5397 if (DefaultPrinter
!= NULL
)
5399 if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
5401 cupsFilePrintf(fp
, "%s\n", DefaultPrinter
->name
);
5405 chmod(filename
, 0644);
5406 chown(filename
, User
, Group
);
5416 * 'write_xml_string()' - Write a string with XML escaping.
5420 write_xml_string(cups_file_t
*fp
, /* I - File to write to */
5421 const char *s
) /* I - String to write */
5423 const char *start
; /* Start of current sequence */
5429 for (start
= s
; *s
; s
++)
5434 cupsFileWrite(fp
, start
, s
- start
);
5436 cupsFilePuts(fp
, "&");
5442 cupsFileWrite(fp
, start
, s
- start
);
5444 cupsFilePuts(fp
, "<");
5450 cupsFilePuts(fp
, start
);
5455 * End of "$Id: printers.c 7968 2008-09-19 23:03:01Z mike $".