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
= cupsdOpenConfFile(line
)) == NULL
)
962 * Read printer configurations until we hit EOF...
968 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
971 * Decode the directive...
974 if (!_cups_strcasecmp(line
, "<Printer") ||
975 !_cups_strcasecmp(line
, "<DefaultPrinter"))
978 * <Printer name> or <DefaultPrinter name>
981 if (p
== NULL
&& value
)
984 * Add the printer and a base file type...
987 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Loading printer %s...", value
);
989 p
= cupsdAddPrinter(value
);
991 p
->state
= IPP_PRINTER_IDLE
;
994 * Set the default printer as needed...
997 if (!_cups_strcasecmp(line
, "<DefaultPrinter"))
1001 cupsdLogMessage(CUPSD_LOG_ERROR
,
1002 "Syntax error on line %d of printers.conf.", linenum
);
1004 else if (!_cups_strcasecmp(line
, "</Printer>"))
1009 * Close out the current printer...
1012 cupsdSetPrinterAttrs(p
);
1014 if (strncmp(p
->device_uri
, "file:", 5) &&
1015 p
->state
!= IPP_PRINTER_STOPPED
)
1018 * See if the backend exists...
1021 snprintf(line
, sizeof(line
), "%s/backend/%s", ServerBin
,
1024 if ((valueptr
= strchr(line
+ strlen(ServerBin
), ':')) != NULL
)
1025 *valueptr
= '\0'; /* Chop everything but URI scheme */
1027 if (access(line
, 0))
1030 * Backend does not exist, stop printer...
1033 p
->state
= IPP_PRINTER_STOPPED
;
1034 snprintf(p
->state_message
, sizeof(p
->state_message
),
1035 "Backend %s does not exist!", line
);
1042 cupsdLogMessage(CUPSD_LOG_ERROR
,
1043 "Syntax error on line %d of printers.conf.", linenum
);
1047 cupsdLogMessage(CUPSD_LOG_ERROR
,
1048 "Syntax error on line %d of printers.conf.", linenum
);
1050 else if (!_cups_strcasecmp(line
, "UUID"))
1052 if (value
&& !strncmp(value
, "urn:uuid:", 9))
1053 cupsdSetString(&(p
->uuid
), value
);
1055 cupsdLogMessage(CUPSD_LOG_ERROR
,
1056 "Bad UUID on line %d of printers.conf.", linenum
);
1058 else if (!_cups_strcasecmp(line
, "AuthInfoRequired"))
1060 if (!cupsdSetAuthInfoRequired(p
, value
, NULL
))
1061 cupsdLogMessage(CUPSD_LOG_ERROR
,
1062 "Bad AuthInfoRequired on line %d of printers.conf.",
1065 else if (!_cups_strcasecmp(line
, "Info"))
1068 cupsdSetString(&p
->info
, value
);
1070 else if (!_cups_strcasecmp(line
, "MakeModel"))
1073 cupsdSetString(&p
->make_model
, value
);
1075 else if (!_cups_strcasecmp(line
, "Location"))
1078 cupsdSetString(&p
->location
, value
);
1080 else if (!_cups_strcasecmp(line
, "DeviceURI"))
1083 cupsdSetDeviceURI(p
, value
);
1085 cupsdLogMessage(CUPSD_LOG_ERROR
,
1086 "Syntax error on line %d of printers.conf.", linenum
);
1088 else if (!_cups_strcasecmp(line
, "Option") && value
)
1094 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1097 cupsdLogMessage(CUPSD_LOG_ERROR
,
1098 "Syntax error on line %d of printers.conf.", linenum
);
1101 for (; *valueptr
&& isspace(*valueptr
& 255); *valueptr
++ = '\0');
1103 p
->num_options
= cupsAddOption(value
, valueptr
, p
->num_options
,
1107 else if (!_cups_strcasecmp(line
, "PortMonitor"))
1109 if (value
&& strcmp(value
, "none"))
1110 cupsdSetString(&p
->port_monitor
, value
);
1112 cupsdClearString(&p
->port_monitor
);
1114 cupsdLogMessage(CUPSD_LOG_ERROR
,
1115 "Syntax error on line %d of printers.conf.", linenum
);
1117 else if (!_cups_strcasecmp(line
, "Reason"))
1120 strcmp(value
, "connecting-to-device") &&
1121 strcmp(value
, "cups-insecure-filter-warning") &&
1122 strcmp(value
, "cups-missing-filter-warning"))
1124 for (i
= 0 ; i
< p
->num_reasons
; i
++)
1125 if (!strcmp(value
, p
->reasons
[i
]))
1128 if (i
>= p
->num_reasons
&&
1129 p
->num_reasons
< (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
1131 p
->reasons
[p
->num_reasons
] = _cupsStrAlloc(value
);
1136 cupsdLogMessage(CUPSD_LOG_ERROR
,
1137 "Syntax error on line %d of printers.conf.", linenum
);
1139 else if (!_cups_strcasecmp(line
, "State"))
1142 * Set the initial queue state...
1145 if (value
&& !_cups_strcasecmp(value
, "idle"))
1146 p
->state
= IPP_PRINTER_IDLE
;
1147 else if (value
&& !_cups_strcasecmp(value
, "stopped"))
1149 p
->state
= IPP_PRINTER_STOPPED
;
1151 for (i
= 0 ; i
< p
->num_reasons
; i
++)
1152 if (!strcmp("paused", p
->reasons
[i
]))
1155 if (i
>= p
->num_reasons
&&
1156 p
->num_reasons
< (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
1158 p
->reasons
[p
->num_reasons
] = _cupsStrAlloc("paused");
1163 cupsdLogMessage(CUPSD_LOG_ERROR
,
1164 "Syntax error on line %d of printers.conf.", linenum
);
1166 else if (!_cups_strcasecmp(line
, "StateMessage"))
1169 * Set the initial queue state message...
1173 strlcpy(p
->state_message
, value
, sizeof(p
->state_message
));
1175 else if (!_cups_strcasecmp(line
, "StateTime"))
1178 * Set the state time...
1182 p
->state_time
= atoi(value
);
1184 else if (!_cups_strcasecmp(line
, "Accepting"))
1187 * Set the initial accepting state...
1191 (!_cups_strcasecmp(value
, "yes") ||
1192 !_cups_strcasecmp(value
, "on") ||
1193 !_cups_strcasecmp(value
, "true")))
1196 (!_cups_strcasecmp(value
, "no") ||
1197 !_cups_strcasecmp(value
, "off") ||
1198 !_cups_strcasecmp(value
, "false")))
1201 cupsdLogMessage(CUPSD_LOG_ERROR
,
1202 "Syntax error on line %d of printers.conf.", linenum
);
1204 else if (!_cups_strcasecmp(line
, "Type"))
1207 p
->type
= atoi(value
);
1209 cupsdLogMessage(CUPSD_LOG_ERROR
,
1210 "Syntax error on line %d of printers.conf.", linenum
);
1212 else if (!_cups_strcasecmp(line
, "Shared"))
1215 * Set the initial shared state...
1219 (!_cups_strcasecmp(value
, "yes") ||
1220 !_cups_strcasecmp(value
, "on") ||
1221 !_cups_strcasecmp(value
, "true")))
1224 (!_cups_strcasecmp(value
, "no") ||
1225 !_cups_strcasecmp(value
, "off") ||
1226 !_cups_strcasecmp(value
, "false")))
1229 cupsdLogMessage(CUPSD_LOG_ERROR
,
1230 "Syntax error on line %d of printers.conf.", linenum
);
1232 else if (!_cups_strcasecmp(line
, "JobSheets"))
1235 * Set the initial job sheets...
1240 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1245 cupsdSetString(&p
->job_sheets
[0], value
);
1247 while (isspace(*valueptr
& 255))
1252 for (value
= valueptr
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1257 cupsdSetString(&p
->job_sheets
[1], value
);
1261 cupsdLogMessage(CUPSD_LOG_ERROR
,
1262 "Syntax error on line %d of printers.conf.", linenum
);
1264 else if (!_cups_strcasecmp(line
, "AllowUser"))
1269 cupsdAddString(&(p
->users
), value
);
1272 cupsdLogMessage(CUPSD_LOG_ERROR
,
1273 "Syntax error on line %d of printers.conf.", linenum
);
1275 else if (!_cups_strcasecmp(line
, "DenyUser"))
1280 cupsdAddString(&(p
->users
), value
);
1283 cupsdLogMessage(CUPSD_LOG_ERROR
,
1284 "Syntax error on line %d of printers.conf.", linenum
);
1286 else if (!_cups_strcasecmp(line
, "QuotaPeriod"))
1289 p
->quota_period
= atoi(value
);
1291 cupsdLogMessage(CUPSD_LOG_ERROR
,
1292 "Syntax error on line %d of printers.conf.", linenum
);
1294 else if (!_cups_strcasecmp(line
, "PageLimit"))
1297 p
->page_limit
= atoi(value
);
1299 cupsdLogMessage(CUPSD_LOG_ERROR
,
1300 "Syntax error on line %d of printers.conf.", linenum
);
1302 else if (!_cups_strcasecmp(line
, "KLimit"))
1305 p
->k_limit
= atoi(value
);
1307 cupsdLogMessage(CUPSD_LOG_ERROR
,
1308 "Syntax error on line %d of printers.conf.", linenum
);
1310 else if (!_cups_strcasecmp(line
, "OpPolicy"))
1314 cupsd_policy_t
*pol
; /* Policy */
1317 if ((pol
= cupsdFindPolicy(value
)) != NULL
)
1319 cupsdSetString(&p
->op_policy
, value
);
1320 p
->op_policy_ptr
= pol
;
1323 cupsdLogMessage(CUPSD_LOG_ERROR
,
1324 "Bad policy \"%s\" on line %d of printers.conf",
1328 cupsdLogMessage(CUPSD_LOG_ERROR
,
1329 "Syntax error on line %d of printers.conf.", linenum
);
1331 else if (!_cups_strcasecmp(line
, "ErrorPolicy"))
1334 cupsdSetString(&p
->error_policy
, value
);
1336 cupsdLogMessage(CUPSD_LOG_ERROR
,
1337 "Syntax error on line %d of printers.conf.", linenum
);
1339 else if (!_cups_strcasecmp(line
, "Attribute") && value
)
1341 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1344 cupsdLogMessage(CUPSD_LOG_ERROR
,
1345 "Syntax error on line %d of printers.conf.", linenum
);
1348 for (; *valueptr
&& isspace(*valueptr
& 255); *valueptr
++ = '\0');
1351 cupsdSetPrinterAttrs(p
);
1353 if (!strcmp(value
, "marker-change-time"))
1354 p
->marker_time
= atoi(valueptr
);
1356 cupsdSetPrinterAttr(p
, value
, valueptr
);
1359 else if (_cups_strcasecmp(line
, "Filter") &&
1360 _cups_strcasecmp(line
, "Prefilter") &&
1361 _cups_strcasecmp(line
, "Product"))
1364 * Something else we don't understand (and that wasn't used in a prior
1365 * release of CUPS...
1368 cupsdLogMessage(CUPSD_LOG_ERROR
,
1369 "Unknown configuration directive %s on line %d of "
1370 "printers.conf.", line
, linenum
);
1379 * 'cupsdRenamePrinter()' - Rename a printer.
1384 cupsd_printer_t
*p
, /* I - Printer */
1385 const char *name
) /* I - New name */
1388 * Remove the printer from the array(s) first...
1391 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1392 "cupsdRenamePrinter: Removing %s from Printers", p
->name
);
1393 cupsArrayRemove(Printers
, p
);
1395 if (p
->type
& CUPS_PRINTER_IMPLICIT
)
1397 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1398 "cupsdRenamePrinter: Removing %s from ImplicitPrinters",
1400 cupsArrayRemove(ImplicitPrinters
, p
);
1404 * Rename the printer type...
1407 mimeDeleteType(MimeDatabase
, p
->filetype
);
1408 p
->filetype
= mimeAddType(MimeDatabase
, "printer", name
);
1410 if (p
->prefiltertype
)
1412 mimeDeleteType(MimeDatabase
, p
->prefiltertype
);
1413 p
->prefiltertype
= mimeAddType(MimeDatabase
, "prefilter", name
);
1417 * Rename the printer...
1420 cupsdSetString(&p
->name
, name
);
1423 * Reset printer attributes...
1426 cupsdSetPrinterAttrs(p
);
1429 * Add the printer back to the printer array(s)...
1432 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1433 "cupsdRenamePrinter: Adding %s to Printers", p
->name
);
1434 cupsArrayAdd(Printers
, p
);
1436 if (p
->type
& CUPS_PRINTER_IMPLICIT
)
1438 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1439 "cupsdRenamePrinter: Adding %s to ImplicitPrinters",
1441 cupsArrayAdd(ImplicitPrinters
, p
);
1447 * 'cupsdSaveAllPrinters()' - Save all printer definitions to the printers.conf
1452 cupsdSaveAllPrinters(void)
1454 int i
; /* Looping var */
1455 cups_file_t
*fp
; /* printers.conf file */
1456 char filename
[1024], /* printers.conf filename */
1457 temp
[1024], /* Temporary string */
1458 value
[2048], /* Value string */
1459 *ptr
, /* Pointer into value */
1460 *name
; /* Current user/group name */
1461 cupsd_printer_t
*printer
; /* Current printer class */
1462 time_t curtime
; /* Current time */
1463 struct tm
*curdate
; /* Current date */
1464 cups_option_t
*option
; /* Current option */
1465 ipp_attribute_t
*marker
; /* Current marker attribute */
1469 * Create the printers.conf file...
1472 snprintf(filename
, sizeof(filename
), "%s/printers.conf", ServerRoot
);
1474 if ((fp
= cupsdCreateConfFile(filename
, ConfigFilePerm
& 0600)) == NULL
)
1477 cupsdLogMessage(CUPSD_LOG_INFO
, "Saving printers.conf...");
1480 * Write a small header to the file...
1483 curtime
= time(NULL
);
1484 curdate
= localtime(&curtime
);
1485 strftime(temp
, sizeof(temp
) - 1, "%Y-%m-%d %H:%M", curdate
);
1487 cupsFilePuts(fp
, "# Printer configuration file for " CUPS_SVERSION
"\n");
1488 cupsFilePrintf(fp
, "# Written by cupsd on %s\n", temp
);
1489 cupsFilePuts(fp
, "# DO NOT EDIT THIS FILE WHEN CUPSD IS RUNNING\n");
1492 * Write each local printer known to the system...
1495 for (printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
1497 printer
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
1500 * Skip remote destinations and printer classes...
1503 if ((printer
->type
& CUPS_PRINTER_DISCOVERED
) ||
1504 (printer
->type
& CUPS_PRINTER_CLASS
) ||
1505 (printer
->type
& CUPS_PRINTER_IMPLICIT
))
1509 * Write printers as needed...
1512 if (printer
== DefaultPrinter
)
1513 cupsFilePrintf(fp
, "<DefaultPrinter %s>\n", printer
->name
);
1515 cupsFilePrintf(fp
, "<Printer %s>\n", printer
->name
);
1517 cupsFilePrintf(fp
, "UUID %s\n", printer
->uuid
);
1519 if (printer
->num_auth_info_required
> 0)
1521 switch (printer
->num_auth_info_required
)
1524 strlcpy(value
, printer
->auth_info_required
[0], sizeof(value
));
1528 snprintf(value
, sizeof(value
), "%s,%s",
1529 printer
->auth_info_required
[0],
1530 printer
->auth_info_required
[1]);
1535 snprintf(value
, sizeof(value
), "%s,%s,%s",
1536 printer
->auth_info_required
[0],
1537 printer
->auth_info_required
[1],
1538 printer
->auth_info_required
[2]);
1542 cupsFilePutConf(fp
, "AuthInfoRequired", value
);
1546 cupsFilePutConf(fp
, "Info", printer
->info
);
1548 if (printer
->location
)
1549 cupsFilePutConf(fp
, "Location", printer
->location
);
1551 if (printer
->make_model
)
1552 cupsFilePutConf(fp
, "MakeModel", printer
->make_model
);
1554 cupsFilePutConf(fp
, "DeviceURI", printer
->device_uri
);
1556 if (printer
->port_monitor
)
1557 cupsFilePutConf(fp
, "PortMonitor", printer
->port_monitor
);
1559 if (printer
->state
== IPP_PRINTER_STOPPED
)
1561 cupsFilePuts(fp
, "State Stopped\n");
1563 if (printer
->state_message
)
1564 cupsFilePutConf(fp
, "StateMessage", printer
->state_message
);
1567 cupsFilePuts(fp
, "State Idle\n");
1569 cupsFilePrintf(fp
, "StateTime %d\n", (int)printer
->state_time
);
1571 for (i
= 0; i
< printer
->num_reasons
; i
++)
1572 if (strcmp(printer
->reasons
[i
], "connecting-to-device") &&
1573 strcmp(printer
->reasons
[i
], "cups-insecure-filter-warning") &&
1574 strcmp(printer
->reasons
[i
], "cups-missing-filter-warning"))
1575 cupsFilePutConf(fp
, "Reason", printer
->reasons
[i
]);
1577 cupsFilePrintf(fp
, "Type %d\n", printer
->type
);
1579 if (printer
->accepting
)
1580 cupsFilePuts(fp
, "Accepting Yes\n");
1582 cupsFilePuts(fp
, "Accepting No\n");
1584 if (printer
->shared
)
1585 cupsFilePuts(fp
, "Shared Yes\n");
1587 cupsFilePuts(fp
, "Shared No\n");
1589 snprintf(value
, sizeof(value
), "%s %s", printer
->job_sheets
[0],
1590 printer
->job_sheets
[1]);
1591 cupsFilePutConf(fp
, "JobSheets", value
);
1593 cupsFilePrintf(fp
, "QuotaPeriod %d\n", printer
->quota_period
);
1594 cupsFilePrintf(fp
, "PageLimit %d\n", printer
->page_limit
);
1595 cupsFilePrintf(fp
, "KLimit %d\n", printer
->k_limit
);
1597 for (name
= (char *)cupsArrayFirst(printer
->users
);
1599 name
= (char *)cupsArrayNext(printer
->users
))
1600 cupsFilePutConf(fp
, printer
->deny_users
? "DenyUser" : "AllowUser", name
);
1602 if (printer
->op_policy
)
1603 cupsFilePutConf(fp
, "OpPolicy", printer
->op_policy
);
1604 if (printer
->error_policy
)
1605 cupsFilePutConf(fp
, "ErrorPolicy", printer
->error_policy
);
1607 for (i
= printer
->num_options
, option
= printer
->options
;
1611 snprintf(value
, sizeof(value
), "%s %s", option
->name
, option
->value
);
1612 cupsFilePutConf(fp
, "Option", value
);
1615 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-colors",
1616 IPP_TAG_NAME
)) != NULL
)
1618 snprintf(value
, sizeof(value
), "%s ", marker
->name
);
1620 for (i
= 0, ptr
= value
+ strlen(value
);
1621 i
< marker
->num_values
&& ptr
< (value
+ sizeof(value
) - 1);
1627 strlcpy(ptr
, marker
->values
[i
].string
.text
,
1628 value
+ sizeof(value
) - ptr
);
1633 cupsFilePutConf(fp
, "Attribute", value
);
1636 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-levels",
1637 IPP_TAG_INTEGER
)) != NULL
)
1639 cupsFilePrintf(fp
, "Attribute %s %d", marker
->name
,
1640 marker
->values
[0].integer
);
1641 for (i
= 1; i
< marker
->num_values
; i
++)
1642 cupsFilePrintf(fp
, ",%d", marker
->values
[i
].integer
);
1643 cupsFilePuts(fp
, "\n");
1646 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-low-levels",
1647 IPP_TAG_INTEGER
)) != NULL
)
1649 cupsFilePrintf(fp
, "Attribute %s %d", marker
->name
,
1650 marker
->values
[0].integer
);
1651 for (i
= 1; i
< marker
->num_values
; i
++)
1652 cupsFilePrintf(fp
, ",%d", marker
->values
[i
].integer
);
1653 cupsFilePuts(fp
, "\n");
1656 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-high-levels",
1657 IPP_TAG_INTEGER
)) != NULL
)
1659 cupsFilePrintf(fp
, "Attribute %s %d", marker
->name
,
1660 marker
->values
[0].integer
);
1661 for (i
= 1; i
< marker
->num_values
; i
++)
1662 cupsFilePrintf(fp
, ",%d", marker
->values
[i
].integer
);
1663 cupsFilePuts(fp
, "\n");
1666 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-message",
1667 IPP_TAG_TEXT
)) != NULL
)
1669 snprintf(value
, sizeof(value
), "%s %s", marker
->name
,
1670 marker
->values
[0].string
.text
);
1672 cupsFilePutConf(fp
, "Attribute", value
);
1675 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-names",
1676 IPP_TAG_NAME
)) != NULL
)
1678 snprintf(value
, sizeof(value
), "%s ", marker
->name
);
1680 for (i
= 0, ptr
= value
+ strlen(value
);
1681 i
< marker
->num_values
&& ptr
< (value
+ sizeof(value
) - 1);
1687 strlcpy(ptr
, marker
->values
[i
].string
.text
,
1688 value
+ sizeof(value
) - ptr
);
1693 cupsFilePutConf(fp
, "Attribute", value
);
1696 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-types",
1697 IPP_TAG_KEYWORD
)) != NULL
)
1699 snprintf(value
, sizeof(value
), "%s ", marker
->name
);
1701 for (i
= 0, ptr
= value
+ strlen(value
);
1702 i
< marker
->num_values
&& ptr
< (value
+ sizeof(value
) - 1);
1708 strlcpy(ptr
, marker
->values
[i
].string
.text
,
1709 value
+ sizeof(value
) - ptr
);
1714 cupsFilePutConf(fp
, "Attribute", value
);
1717 if (printer
->marker_time
)
1718 cupsFilePrintf(fp
, "Attribute marker-change-time %ld\n",
1719 (long)printer
->marker_time
);
1721 cupsFilePuts(fp
, "</Printer>\n");
1725 * Make IRIX desktop & printer status happy
1728 write_irix_state(printer
);
1732 cupsdCloseCreatedConfFile(fp
, filename
);
1737 * 'cupsdSetAuthInfoRequired()' - Set the required authentication info.
1740 int /* O - 1 if value OK, 0 otherwise */
1741 cupsdSetAuthInfoRequired(
1742 cupsd_printer_t
*p
, /* I - Printer */
1743 const char *values
, /* I - Plain text value (or NULL) */
1744 ipp_attribute_t
*attr
) /* I - IPP attribute value (or NULL) */
1746 int i
; /* Looping var */
1749 p
->num_auth_info_required
= 0;
1752 * Do we have a plain text value?
1758 * Yes, grab the keywords...
1761 const char *end
; /* End of current value */
1764 while (*values
&& p
->num_auth_info_required
< 4)
1766 if ((end
= strchr(values
, ',')) == NULL
)
1767 end
= values
+ strlen(values
);
1769 if ((end
- values
) == 4 && !strncmp(values
, "none", 4))
1771 if (p
->num_auth_info_required
!= 0 || *end
)
1774 p
->auth_info_required
[p
->num_auth_info_required
] = "none";
1775 p
->num_auth_info_required
++;
1779 else if ((end
- values
) == 9 && !strncmp(values
, "negotiate", 9))
1781 if (p
->num_auth_info_required
!= 0 || *end
)
1784 p
->auth_info_required
[p
->num_auth_info_required
] = "negotiate";
1785 p
->num_auth_info_required
++;
1788 * Don't allow sharing of queues that require Kerberos authentication.
1793 cupsdDeregisterPrinter(p
, 1);
1797 else if ((end
- values
) == 6 && !strncmp(values
, "domain", 6))
1799 p
->auth_info_required
[p
->num_auth_info_required
] = "domain";
1800 p
->num_auth_info_required
++;
1802 else if ((end
- values
) == 8 && !strncmp(values
, "password", 8))
1804 p
->auth_info_required
[p
->num_auth_info_required
] = "password";
1805 p
->num_auth_info_required
++;
1807 else if ((end
- values
) == 8 && !strncmp(values
, "username", 8))
1809 p
->auth_info_required
[p
->num_auth_info_required
] = "username";
1810 p
->num_auth_info_required
++;
1815 values
= (*end
) ? end
+ 1 : end
;
1818 if (p
->num_auth_info_required
== 0)
1820 p
->auth_info_required
[0] = "none";
1821 p
->num_auth_info_required
= 1;
1825 * Update the printer-type value as needed...
1828 if (p
->num_auth_info_required
> 1 ||
1829 strcmp(p
->auth_info_required
[0], "none"))
1830 p
->type
|= CUPS_PRINTER_AUTHENTICATED
;
1832 p
->type
&= ~CUPS_PRINTER_AUTHENTICATED
;
1838 * Grab values from an attribute instead...
1841 if (!attr
|| attr
->num_values
> 4)
1845 * Update the printer-type value as needed...
1848 if (attr
->num_values
> 1 ||
1849 strcmp(attr
->values
[0].string
.text
, "none"))
1850 p
->type
|= CUPS_PRINTER_AUTHENTICATED
;
1852 p
->type
&= ~CUPS_PRINTER_AUTHENTICATED
;
1854 for (i
= 0; i
< attr
->num_values
; i
++)
1856 if (!strcmp(attr
->values
[i
].string
.text
, "none"))
1858 if (p
->num_auth_info_required
!= 0 || attr
->num_values
!= 1)
1861 p
->auth_info_required
[p
->num_auth_info_required
] = "none";
1862 p
->num_auth_info_required
++;
1866 else if (!strcmp(attr
->values
[i
].string
.text
, "negotiate"))
1868 if (p
->num_auth_info_required
!= 0 || attr
->num_values
!= 1)
1871 p
->auth_info_required
[p
->num_auth_info_required
] = "negotiate";
1872 p
->num_auth_info_required
++;
1875 * Don't allow sharing of queues that require Kerberos authentication.
1880 cupsdDeregisterPrinter(p
, 1);
1886 else if (!strcmp(attr
->values
[i
].string
.text
, "domain"))
1888 p
->auth_info_required
[p
->num_auth_info_required
] = "domain";
1889 p
->num_auth_info_required
++;
1891 else if (!strcmp(attr
->values
[i
].string
.text
, "password"))
1893 p
->auth_info_required
[p
->num_auth_info_required
] = "password";
1894 p
->num_auth_info_required
++;
1896 else if (!strcmp(attr
->values
[i
].string
.text
, "username"))
1898 p
->auth_info_required
[p
->num_auth_info_required
] = "username";
1899 p
->num_auth_info_required
++;
1910 * 'cupsdSetDeviceURI()' - Set the device URI for a printer.
1914 cupsdSetDeviceURI(cupsd_printer_t
*p
, /* I - Printer */
1915 const char *uri
) /* I - Device URI */
1917 char buffer
[1024], /* URI buffer */
1918 *start
, /* Start of data after scheme */
1919 *slash
, /* First slash after scheme:// */
1920 *ptr
; /* Pointer into user@host:port part */
1924 * Set the full device URI..
1927 cupsdSetString(&(p
->device_uri
), uri
);
1930 * Copy the device URI to a temporary buffer so we can sanitize any auth
1934 strlcpy(buffer
, uri
, sizeof(buffer
));
1937 * Find the end of the scheme:// part...
1940 if ((ptr
= strchr(buffer
, ':')) != NULL
)
1942 for (start
= ptr
+ 1; *start
; start
++)
1947 * Find the next slash (/) in the URI...
1950 if ((slash
= strchr(start
, '/')) == NULL
)
1951 slash
= start
+ strlen(start
); /* No slash, point to the end */
1954 * Check for an @ sign before the slash...
1957 if ((ptr
= strchr(start
, '@')) != NULL
&& ptr
< slash
)
1960 * Found an @ sign and it is before the resource part, so we have
1961 * an authentication string. Copy the remaining URI over the
1962 * authentication string...
1965 _cups_strcpy(start
, ptr
+ 1);
1970 * Save the sanitized URI...
1973 cupsdSetString(&(p
->sanitized_device_uri
), buffer
);
1978 * 'cupsdSetPrinterAttr()' - Set a printer attribute.
1982 cupsdSetPrinterAttr(
1983 cupsd_printer_t
*p
, /* I - Printer */
1984 const char *name
, /* I - Attribute name */
1985 char *value
) /* I - Attribute value string */
1987 ipp_attribute_t
*attr
; /* Attribute */
1988 int i
, /* Looping var */
1989 count
; /* Number of values */
1990 char *ptr
; /* Pointer into value */
1991 ipp_tag_t value_tag
; /* Value tag for this attribute */
1995 * Don't allow empty values...
1998 if (!*value
&& strcmp(name
, "marker-message"))
2000 cupsdLogMessage(CUPSD_LOG_ERROR
, "Ignoring empty \"%s\" attribute", name
);
2005 * Count the number of values...
2008 for (count
= 1, ptr
= value
;
2009 (ptr
= strchr(ptr
, ',')) != NULL
;
2013 * Then add or update the attribute as needed...
2016 if (!strcmp(name
, "marker-levels") || !strcmp(name
, "marker-low-levels") ||
2017 !strcmp(name
, "marker-high-levels"))
2023 if ((attr
= ippFindAttribute(p
->attrs
, name
, IPP_TAG_INTEGER
)) != NULL
&&
2024 attr
->num_values
< count
)
2026 ippDeleteAttribute(p
->attrs
, attr
);
2031 attr
->num_values
= count
;
2033 attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
, name
,
2038 cupsdLogMessage(CUPSD_LOG_ERROR
,
2039 "Unable to allocate memory for printer attribute "
2040 "(%d values)", count
);
2044 for (i
= 0; i
< count
; i
++)
2046 if ((ptr
= strchr(value
, ',')) != NULL
)
2049 attr
->values
[i
].integer
= strtol(value
, NULL
, 10);
2058 * Name or keyword values...
2061 if (!strcmp(name
, "marker-types"))
2062 value_tag
= IPP_TAG_KEYWORD
;
2063 else if (!strcmp(name
, "marker-message"))
2064 value_tag
= IPP_TAG_TEXT
;
2066 value_tag
= IPP_TAG_NAME
;
2068 if ((attr
= ippFindAttribute(p
->attrs
, name
, value_tag
)) != NULL
&&
2069 attr
->num_values
< count
)
2071 ippDeleteAttribute(p
->attrs
, attr
);
2077 for (i
= 0; i
< attr
->num_values
; i
++)
2078 _cupsStrFree(attr
->values
[i
].string
.text
);
2080 attr
->num_values
= count
;
2083 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, value_tag
, name
,
2088 cupsdLogMessage(CUPSD_LOG_ERROR
,
2089 "Unable to allocate memory for printer attribute "
2090 "(%d values)", count
);
2094 for (i
= 0; i
< count
; i
++)
2096 if ((ptr
= strchr(value
, ',')) != NULL
)
2099 attr
->values
[i
].string
.text
= _cupsStrAlloc(value
);
2109 * 'cupsdSetPrinterAttrs()' - Set printer attributes based upon the PPD file.
2113 cupsdSetPrinterAttrs(cupsd_printer_t
*p
)/* I - Printer to setup */
2115 int i
, /* Looping var */
2116 length
; /* Length of browse attributes */
2117 char resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
2118 int num_air
; /* Number of auth-info-required values */
2119 const char * const *air
; /* auth-info-required values */
2120 cupsd_location_t
*auth
; /* Pointer to authentication element */
2121 const char *auth_supported
; /* Authentication supported */
2122 ipp_t
*oldattrs
; /* Old printer attributes */
2123 ipp_attribute_t
*attr
; /* Attribute data */
2124 cups_option_t
*option
; /* Current printer option */
2125 char *name
, /* Current user/group name */
2126 *filter
; /* Current filter */
2127 static const char * const air_none
[] =
2128 { /* No authentication */
2131 static const char * const air_userpass
[] =
2132 { /* Basic/Digest authentication */
2138 DEBUG_printf(("cupsdSetPrinterAttrs: entering name = %s, type = %x\n", p
->name
,
2142 * Make sure that we have the common attributes defined...
2146 cupsdCreateCommonData();
2149 * Clear out old filters, if any...
2152 delete_printer_filters(p
);
2155 * Figure out the authentication that is required for the printer.
2158 auth_supported
= "requesting-user-name";
2162 if (p
->num_auth_info_required
> 0 && strcmp(p
->auth_info_required
[0], "none"))
2164 num_air
= p
->num_auth_info_required
;
2165 air
= p
->auth_info_required
;
2167 else if ((p
->type
& CUPS_PRINTER_AUTHENTICATED
) &&
2168 (p
->type
& CUPS_PRINTER_DISCOVERED
))
2174 if (p
->type
& CUPS_PRINTER_CLASS
)
2175 snprintf(resource
, sizeof(resource
), "/classes/%s", p
->name
);
2177 snprintf(resource
, sizeof(resource
), "/printers/%s", p
->name
);
2179 if ((auth
= cupsdFindBest(resource
, HTTP_POST
)) == NULL
||
2180 auth
->type
== CUPSD_AUTH_NONE
)
2181 auth
= cupsdFindPolicyOp(p
->op_policy_ptr
, IPP_PRINT_JOB
);
2185 int auth_type
; /* Authentication type */
2188 if ((auth_type
= auth
->type
) == CUPSD_AUTH_DEFAULT
)
2189 auth_type
= DefaultAuthType
;
2191 if (auth_type
== CUPSD_AUTH_BASIC
|| auth_type
== CUPSD_AUTH_BASICDIGEST
)
2192 auth_supported
= "basic";
2193 else if (auth_type
== CUPSD_AUTH_DIGEST
)
2194 auth_supported
= "digest";
2196 else if (auth_type
== CUPSD_AUTH_NEGOTIATE
)
2197 auth_supported
= "negotiate";
2198 #endif /* HAVE_GSSAPI */
2200 if (!(p
->type
& CUPS_PRINTER_DISCOVERED
))
2202 if (auth_type
!= CUPSD_AUTH_NONE
)
2203 p
->type
|= CUPS_PRINTER_AUTHENTICATED
;
2205 p
->type
&= ~CUPS_PRINTER_AUTHENTICATED
;
2208 else if (!(p
->type
& CUPS_PRINTER_DISCOVERED
))
2209 p
->type
&= ~CUPS_PRINTER_AUTHENTICATED
;
2212 * Create the required IPP attributes for a printer...
2215 oldattrs
= p
->attrs
;
2216 p
->attrs
= ippNew();
2218 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2219 "uri-authentication-supported", NULL
, auth_supported
);
2220 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2221 "uri-security-supported", NULL
, "none");
2222 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
, "printer-name", NULL
,
2224 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-location",
2225 NULL
, p
->location
? p
->location
: "");
2226 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-info",
2227 NULL
, p
->info
? p
->info
: "");
2228 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "printer-uuid", NULL
,
2231 if (cupsArrayCount(p
->users
) > 0)
2234 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2235 "requesting-user-name-denied",
2236 cupsArrayCount(p
->users
), NULL
, NULL
);
2238 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2239 "requesting-user-name-allowed",
2240 cupsArrayCount(p
->users
), NULL
, NULL
);
2242 for (i
= 0, name
= (char *)cupsArrayFirst(p
->users
);
2244 i
++, name
= (char *)cupsArrayNext(p
->users
))
2245 attr
->values
[i
].string
.text
= _cupsStrRetain(name
);
2248 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2249 "job-quota-period", p
->quota_period
);
2250 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2251 "job-k-limit", p
->k_limit
);
2252 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2253 "job-page-limit", p
->page_limit
);
2254 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2255 "auth-info-required", num_air
, NULL
, air
);
2257 if (cupsArrayCount(Banners
) > 0 && !(p
->type
& CUPS_PRINTER_DISCOVERED
))
2260 * Setup the job-sheets-default attribute...
2263 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2264 "job-sheets-default", 2, NULL
, NULL
);
2268 attr
->values
[0].string
.text
= _cupsStrAlloc(Classification
?
2269 Classification
: p
->job_sheets
[0]);
2270 attr
->values
[1].string
.text
= _cupsStrAlloc(Classification
?
2271 Classification
: p
->job_sheets
[1]);
2278 if (p
->type
& CUPS_PRINTER_DISCOVERED
)
2281 * Tell the client this is a remote printer of some type...
2284 if (strchr(p
->uri
, '?'))
2287 * Strip trailing "?options" from URI...
2290 char *ptr
; /* Pointer into URI */
2292 strlcpy(resource
, p
->uri
, sizeof(resource
));
2293 if ((ptr
= strchr(resource
, '?')) != NULL
)
2296 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
2297 "printer-uri-supported", NULL
, resource
);
2300 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
2301 "printer-uri-supported", NULL
, p
->uri
);
2303 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "printer-more-info",
2307 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
2308 "printer-make-and-model", NULL
, p
->make_model
);
2310 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "device-uri", NULL
,
2319 * Assign additional attributes depending on whether this is a printer
2323 if (p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
))
2326 p
->type
&= ~CUPS_PRINTER_OPTIONS
;
2329 * Add class-specific attributes...
2332 if ((p
->type
& CUPS_PRINTER_IMPLICIT
) && p
->num_printers
> 0 &&
2333 p
->printers
[0]->make_model
)
2334 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
2335 "printer-make-and-model", NULL
, p
->printers
[0]->make_model
);
2337 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
2338 "printer-make-and-model", NULL
, "Local Printer Class");
2340 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "device-uri", NULL
,
2341 "file:///dev/null");
2343 if (p
->num_printers
> 0)
2346 * Add a list of member names; URIs are added in copy_printer_attrs...
2349 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2350 "member-names", p
->num_printers
, NULL
, NULL
);
2351 p
->type
|= CUPS_PRINTER_OPTIONS
;
2353 for (i
= 0; i
< p
->num_printers
; i
++)
2356 attr
->values
[i
].string
.text
= _cupsStrRetain(p
->printers
[i
]->name
);
2358 p
->type
&= ~CUPS_PRINTER_OPTIONS
| p
->printers
[i
]->type
;
2365 * Add printer-specific attributes...
2368 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "device-uri", NULL
,
2369 p
->sanitized_device_uri
);
2372 * Assign additional attributes from the PPD file (if any)...
2378 * Add filters for printer...
2381 cupsdSetPrinterReasons(p
, "-cups-missing-filter-warning,"
2382 "cups-insecure-filter-warning");
2384 if (p
->pc
&& p
->pc
->filters
)
2386 for (filter
= (char *)cupsArrayFirst(p
->pc
->filters
);
2388 filter
= (char *)cupsArrayNext(p
->pc
->filters
))
2389 add_printer_filter(p
, p
->filetype
, filter
);
2391 else if (!(p
->type
& CUPS_PRINTER_REMOTE
))
2393 char interface
[1024]; /* Interface script */
2396 snprintf(interface
, sizeof(interface
), "%s/interfaces/%s", ServerRoot
,
2398 if (!access(interface
, X_OK
))
2401 * Yes, we have a System V style interface script; use it!
2404 snprintf(interface
, sizeof(interface
), "*/* 0 %s/interfaces/%s",
2405 ServerRoot
, p
->name
);
2406 add_printer_filter(p
, p
->filetype
, interface
);
2411 * Add a filter from application/vnd.cups-raw to printer/name to
2412 * handle "raw" printing by users.
2415 add_printer_filter(p
, p
->filetype
, "application/vnd.cups-raw 0 -");
2418 * Add a PostScript filter, since this is still possibly PS printer.
2421 add_printer_filter(p
, p
->filetype
,
2422 "application/vnd.cups-postscript 0 -");
2426 if (p
->pc
&& p
->pc
->prefilters
)
2428 if (!p
->prefiltertype
)
2429 p
->prefiltertype
= mimeAddType(MimeDatabase
, "prefilter", p
->name
);
2431 for (filter
= (char *)cupsArrayFirst(p
->pc
->prefilters
);
2433 filter
= (char *)cupsArrayNext(p
->pc
->prefilters
))
2434 add_printer_filter(p
, p
->prefiltertype
, filter
);
2440 * Copy marker attributes as needed...
2445 ipp_attribute_t
*oldattr
; /* Old attribute */
2448 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-colors",
2449 IPP_TAG_NAME
)) != NULL
)
2451 if ((attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2452 "marker-colors", oldattr
->num_values
, NULL
,
2455 for (i
= 0; i
< oldattr
->num_values
; i
++)
2456 attr
->values
[i
].string
.text
=
2457 _cupsStrRetain(oldattr
->values
[i
].string
.text
);
2461 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-levels",
2462 IPP_TAG_INTEGER
)) != NULL
)
2464 if ((attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2465 "marker-levels", oldattr
->num_values
,
2468 for (i
= 0; i
< oldattr
->num_values
; i
++)
2469 attr
->values
[i
].integer
= oldattr
->values
[i
].integer
;
2473 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-message",
2474 IPP_TAG_TEXT
)) != NULL
)
2475 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "marker-message",
2476 NULL
, oldattr
->values
[0].string
.text
);
2478 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-low-levels",
2479 IPP_TAG_INTEGER
)) != NULL
)
2481 if ((attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2482 "marker-low-levels", oldattr
->num_values
,
2485 for (i
= 0; i
< oldattr
->num_values
; i
++)
2486 attr
->values
[i
].integer
= oldattr
->values
[i
].integer
;
2490 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-high-levels",
2491 IPP_TAG_INTEGER
)) != NULL
)
2493 if ((attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2494 "marker-high-levels", oldattr
->num_values
,
2497 for (i
= 0; i
< oldattr
->num_values
; i
++)
2498 attr
->values
[i
].integer
= oldattr
->values
[i
].integer
;
2502 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-names",
2503 IPP_TAG_NAME
)) != NULL
)
2505 if ((attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2506 "marker-names", oldattr
->num_values
, NULL
,
2509 for (i
= 0; i
< oldattr
->num_values
; i
++)
2510 attr
->values
[i
].string
.text
=
2511 _cupsStrRetain(oldattr
->values
[i
].string
.text
);
2515 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-types",
2516 IPP_TAG_KEYWORD
)) != NULL
)
2518 if ((attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2519 "marker-types", oldattr
->num_values
, NULL
,
2522 for (i
= 0; i
< oldattr
->num_values
; i
++)
2523 attr
->values
[i
].string
.text
=
2524 _cupsStrRetain(oldattr
->values
[i
].string
.text
);
2528 ippDelete(oldattrs
);
2532 * Force sharing off for remote queues...
2535 if (p
->type
& (CUPS_PRINTER_REMOTE
| CUPS_PRINTER_IMPLICIT
))
2540 * Copy the printer options into a browse attributes string we can re-use.
2543 const char *valptr
; /* Pointer into value */
2544 char *attrptr
; /* Pointer into attribute string */
2548 * Free the old browse attributes as needed...
2551 if (p
->browse_attrs
)
2552 free(p
->browse_attrs
);
2555 * Compute the length of all attributes + job-sheets, lease-duration,
2556 * and BrowseLocalOptions.
2559 for (length
= 1, i
= p
->num_options
, option
= p
->options
;
2563 length
+= strlen(option
->name
) + 2;
2567 for (valptr
= option
->value
; *valptr
; valptr
++)
2568 if (strchr(" \"\'\\", *valptr
))
2575 length
+= 13 + strlen(p
->job_sheets
[0]) + strlen(p
->job_sheets
[1]);
2577 if (BrowseLocalOptions
)
2578 length
+= 12 + strlen(BrowseLocalOptions
);
2581 * Allocate the new string...
2584 if ((p
->browse_attrs
= calloc(1, length
)) == NULL
)
2585 cupsdLogMessage(CUPSD_LOG_ERROR
,
2586 "Unable to allocate %d bytes for browse data!",
2591 * Got the allocated string, now copy the options and attributes over...
2594 sprintf(p
->browse_attrs
, "job-sheets=%s,%s lease-duration=%d",
2595 p
->job_sheets
[0], p
->job_sheets
[1], BrowseTimeout
);
2596 attrptr
= p
->browse_attrs
+ strlen(p
->browse_attrs
);
2598 if (BrowseLocalOptions
)
2600 sprintf(attrptr
, " ipp-options=%s", BrowseLocalOptions
);
2601 attrptr
+= strlen(attrptr
);
2604 for (i
= p
->num_options
, option
= p
->options
;
2609 strcpy(attrptr
, option
->name
);
2610 attrptr
+= strlen(attrptr
);
2616 for (valptr
= option
->value
; *valptr
; valptr
++)
2618 if (strchr(" \"\'\\", *valptr
))
2621 *attrptr
++ = *valptr
;
2629 * Populate the document-format-supported attribute...
2632 add_printer_formats(p
);
2634 DEBUG_printf(("cupsdSetPrinterAttrs: leaving name = %s, type = %x\n", p
->name
,
2638 * Add name-default attributes...
2641 add_printer_defaults(p
);
2645 * Write the IRIX printer config and status files...
2648 write_irix_config(p
);
2649 write_irix_state(p
);
2653 * Let the browse protocols reflect the change
2656 cupsdRegisterPrinter(p
);
2661 * 'cupsdSetPrinterReasons()' - Set/update the reasons strings.
2664 int /* O - 1 if something changed, 0 otherwise */
2665 cupsdSetPrinterReasons(
2666 cupsd_printer_t
*p
, /* I - Printer */
2667 const char *s
) /* I - Reasons strings */
2669 int i
, /* Looping var */
2670 changed
= 0; /* Did something change? */
2671 const char *sptr
; /* Pointer into reasons */
2672 char reason
[255], /* Reason string */
2673 *rptr
; /* Pointer into reason */
2676 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
2677 "cupsdSetPrinterReasons(p=%p(%s),s=\"%s\"", p
, p
->name
, s
);
2679 if (s
[0] == '-' || s
[0] == '+')
2682 * Add/remove reasons...
2690 * Replace reasons...
2695 for (i
= 0; i
< p
->num_reasons
; i
++)
2696 _cupsStrFree(p
->reasons
[i
]);
2704 if (!strcmp(s
, "none"))
2708 * Loop through all of the reasons...
2714 * Skip leading whitespace and commas...
2717 while (isspace(*sptr
& 255) || *sptr
== ',')
2720 for (rptr
= reason
; *sptr
&& !isspace(*sptr
& 255) && *sptr
!= ','; sptr
++)
2721 if (rptr
< (reason
+ sizeof(reason
) - 1))
2735 for (i
= 0; i
< p
->num_reasons
; i
++)
2736 if (!strcmp(reason
, p
->reasons
[i
]))
2739 * Found a match, so remove it...
2744 _cupsStrFree(p
->reasons
[i
]);
2746 if (i
< p
->num_reasons
)
2747 memmove(p
->reasons
+ i
, p
->reasons
+ i
+ 1,
2748 (p
->num_reasons
- i
) * sizeof(char *));
2750 if (!strcmp(reason
, "paused") && p
->state
== IPP_PRINTER_STOPPED
)
2751 cupsdSetPrinterState(p
, IPP_PRINTER_IDLE
, 1);
2753 if (strcmp(reason
, "connecting-to-device"))
2758 else if (p
->num_reasons
< (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
2764 for (i
= 0; i
< p
->num_reasons
; i
++)
2765 if (!strcmp(reason
, p
->reasons
[i
]))
2768 if (i
>= p
->num_reasons
)
2770 if (i
>= (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
2772 cupsdLogMessage(CUPSD_LOG_ALERT
,
2773 "Too many printer-state-reasons values for %s (%d)",
2778 p
->reasons
[i
] = _cupsStrAlloc(reason
);
2782 if (!strcmp(reason
, "paused") && p
->state
!= IPP_PRINTER_STOPPED
)
2783 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, 1);
2785 if (strcmp(reason
, "connecting-to-device"))
2796 * 'cupsdSetPrinterState()' - Update the current state of a printer.
2800 cupsdSetPrinterState(
2801 cupsd_printer_t
*p
, /* I - Printer to change */
2802 ipp_pstate_t s
, /* I - New state */
2803 int update
) /* I - Update printers.conf? */
2805 ipp_pstate_t old_state
; /* Old printer state */
2806 static const char * const printer_states
[] =
2807 { /* State strings */
2815 * Can't set status of remote printers...
2818 if (p
->type
& CUPS_PRINTER_DISCOVERED
)
2822 * Set the new state...
2825 old_state
= p
->state
;
2830 cupsdAddEvent(s
== IPP_PRINTER_STOPPED
? CUPSD_EVENT_PRINTER_STOPPED
:
2831 CUPSD_EVENT_PRINTER_STATE
, p
, NULL
,
2832 "%s \"%s\" state changed to %s.",
2833 (p
->type
& CUPS_PRINTER_CLASS
) ? "Class" : "Printer",
2834 p
->name
, printer_states
[p
->state
- IPP_PRINTER_IDLE
]);
2837 * Let the browse code know this needs to be updated...
2841 p
->state_time
= time(NULL
);
2845 write_irix_state(p
);
2850 * Set/clear the paused reason as needed...
2853 if (s
== IPP_PRINTER_STOPPED
)
2854 cupsdSetPrinterReasons(p
, "+paused");
2856 cupsdSetPrinterReasons(p
, "-paused");
2859 * Clear the message for the queue when going to processing...
2862 if (s
== IPP_PRINTER_PROCESSING
)
2863 p
->state_message
[0] = '\0';
2866 * Let the browse protocols reflect the change...
2870 cupsdRegisterPrinter(p
);
2873 * Save the printer configuration if a printer goes from idle or processing
2874 * to stopped (or visa-versa)...
2878 (old_state
== IPP_PRINTER_STOPPED
) != (s
== IPP_PRINTER_STOPPED
))
2884 * 'cupsdStopPrinter()' - Stop a printer from printing any jobs...
2888 cupsdStopPrinter(cupsd_printer_t
*p
, /* I - Printer to stop */
2889 int update
)/* I - Update printers.conf? */
2892 * Set the printer state...
2895 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, update
);
2898 * See if we have a job printing on this printer...
2901 if (p
->job
&& p
->job
->state_value
== IPP_JOB_PROCESSING
)
2902 cupsdSetJobState(p
->job
, IPP_JOB_PENDING
, CUPSD_JOB_DEFAULT
,
2903 "Job stopped due to printer being paused.");
2908 * 'cupsdUpdatePrinterPPD()' - Update keywords in a printer's PPD file.
2911 int /* O - 1 if successful, 0 otherwise */
2912 cupsdUpdatePrinterPPD(
2913 cupsd_printer_t
*p
, /* I - Printer */
2914 int num_keywords
, /* I - Number of keywords */
2915 cups_option_t
*keywords
) /* I - Keywords */
2917 int i
; /* Looping var */
2918 cups_file_t
*src
, /* Original file */
2919 *dst
; /* New file */
2920 char srcfile
[1024], /* Original filename */
2921 dstfile
[1024], /* New filename */
2922 line
[1024], /* Line from file */
2923 keystring
[41]; /* Keyword from line */
2924 cups_option_t
*keyword
; /* Current keyword */
2927 cupsdLogMessage(CUPSD_LOG_INFO
, "Updating keywords in PPD file for %s...",
2931 * Get the old and new PPD filenames...
2934 snprintf(srcfile
, sizeof(srcfile
), "%s/ppd/%s.ppd.O", ServerRoot
, p
->name
);
2935 snprintf(dstfile
, sizeof(srcfile
), "%s/ppd/%s.ppd", ServerRoot
, p
->name
);
2938 * Rename the old file and open the old and new...
2941 if (rename(dstfile
, srcfile
))
2943 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to backup PPD file for %s: %s",
2944 p
->name
, strerror(errno
));
2948 if ((src
= cupsFileOpen(srcfile
, "r")) == NULL
)
2950 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to open PPD file \"%s\": %s",
2951 srcfile
, strerror(errno
));
2952 rename(srcfile
, dstfile
);
2956 if ((dst
= cupsFileOpen(dstfile
, "w")) == NULL
)
2958 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to create PPD file \"%s\": %s",
2959 dstfile
, strerror(errno
));
2961 rename(srcfile
, dstfile
);
2966 * Copy the first line and then write out all of the keywords...
2969 if (!cupsFileGets(src
, line
, sizeof(line
)))
2971 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to read PPD file \"%s\": %s",
2972 srcfile
, strerror(errno
));
2975 rename(srcfile
, dstfile
);
2979 cupsFilePrintf(dst
, "%s\n", line
);
2981 for (i
= num_keywords
, keyword
= keywords
; i
> 0; i
--, keyword
++)
2983 cupsdLogMessage(CUPSD_LOG_DEBUG
, "*%s: %s", keyword
->name
, keyword
->value
);
2984 cupsFilePrintf(dst
, "*%s: %s\n", keyword
->name
, keyword
->value
);
2988 * Then copy the rest of the PPD file, dropping any keywords we changed.
2991 while (cupsFileGets(src
, line
, sizeof(line
)))
2994 * Skip keywords we've already set...
2997 if (sscanf(line
, "*%40[^:]:", keystring
) == 1 &&
2998 cupsGetOption(keystring
, num_keywords
, keywords
))
3002 * Otherwise write the line...
3005 cupsFilePrintf(dst
, "%s\n", line
);
3009 * Close files and return...
3020 * 'cupsdUpdatePrinters()' - Update printers after a partial reload.
3024 cupsdUpdatePrinters(void)
3026 cupsd_printer_t
*p
; /* Current printer */
3030 * Loop through the printers and recreate the printer attributes
3031 * for any local printers since the policy and/or access control
3032 * stuff may have changed. Also, if browsing is disabled, remove
3033 * any remote printers...
3036 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3038 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3041 * Remove remote printers if we are no longer browsing...
3045 (p
->type
& (CUPS_PRINTER_IMPLICIT
| CUPS_PRINTER_DISCOVERED
)))
3047 if (p
->type
& CUPS_PRINTER_IMPLICIT
)
3048 cupsArrayRemove(ImplicitPrinters
, p
);
3050 cupsArraySave(Printers
);
3051 cupsdDeletePrinter(p
, 0);
3052 cupsArrayRestore(Printers
);
3057 * Update the operation policy pointer...
3060 if ((p
->op_policy_ptr
= cupsdFindPolicy(p
->op_policy
)) == NULL
)
3061 p
->op_policy_ptr
= DefaultPolicyPtr
;
3064 * Update printer attributes as needed...
3067 if (!(p
->type
& CUPS_PRINTER_DISCOVERED
))
3068 cupsdSetPrinterAttrs(p
);
3074 * 'cupsdValidateDest()' - Validate a printer/class destination.
3077 const char * /* O - Printer or class name */
3079 const char *uri
, /* I - Printer URI */
3080 cups_ptype_t
*dtype
, /* O - Type (printer or class) */
3081 cupsd_printer_t
**printer
) /* O - Printer pointer */
3083 cupsd_printer_t
*p
; /* Current printer */
3084 char localname
[1024],/* Localized hostname */
3085 *lptr
, /* Pointer into localized hostname */
3086 *sptr
, /* Pointer into server name */
3087 *rptr
, /* Pointer into resource */
3088 scheme
[32], /* Scheme portion of URI */
3089 username
[64], /* Username portion of URI */
3090 hostname
[HTTP_MAX_HOST
],
3091 /* Host portion of URI */
3092 resource
[HTTP_MAX_URI
];
3093 /* Resource portion of URI */
3094 int port
; /* Port portion of URI */
3097 DEBUG_printf(("cupsdValidateDest(uri=\"%s\", dtype=%p, printer=%p)\n", uri
,
3101 * Initialize return values...
3108 *dtype
= (cups_ptype_t
)0;
3111 * Pull the hostname and resource from the URI...
3114 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
, scheme
, sizeof(scheme
),
3115 username
, sizeof(username
), hostname
, sizeof(hostname
),
3116 &port
, resource
, sizeof(resource
));
3119 * See if the resource is a class or printer...
3122 if (!strncmp(resource
, "/classes/", 9))
3128 rptr
= resource
+ 9;
3130 else if (!strncmp(resource
, "/printers/", 10))
3136 rptr
= resource
+ 10;
3141 * Bad resource name...
3148 * See if the printer or class name exists...
3151 p
= cupsdFindDest(rptr
);
3153 if (p
== NULL
&& strchr(rptr
, '@') == NULL
)
3161 *dtype
= p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
|
3162 CUPS_PRINTER_REMOTE
| CUPS_PRINTER_DISCOVERED
);
3168 * Change localhost to the server name...
3171 if (!_cups_strcasecmp(hostname
, "localhost"))
3172 strlcpy(hostname
, ServerName
, sizeof(hostname
));
3174 strlcpy(localname
, hostname
, sizeof(localname
));
3176 if (!_cups_strcasecmp(hostname
, ServerName
))
3179 * Localize the hostname...
3182 lptr
= strchr(localname
, '.');
3183 sptr
= strchr(ServerName
, '.');
3185 if (sptr
!= NULL
&& lptr
!= NULL
)
3188 * Strip the common domain name components...
3191 while (lptr
!= NULL
)
3193 if (!_cups_strcasecmp(lptr
, sptr
))
3199 lptr
= strchr(lptr
+ 1, '.');
3204 DEBUG_printf(("localized hostname is \"%s\"...\n", localname
));
3207 * Find a matching printer or class...
3210 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3212 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3213 if (!_cups_strcasecmp(p
->hostname
, localname
) &&
3214 !_cups_strcasecmp(p
->name
, rptr
))
3220 *dtype
= p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
|
3221 CUPS_PRINTER_REMOTE
| CUPS_PRINTER_DISCOVERED
);
3231 * 'cupsdWritePrintcap()' - Write a pseudo-printcap file for older applications
3236 cupsdWritePrintcap(void)
3238 int i
; /* Looping var */
3239 cups_file_t
*fp
; /* Printcap file */
3240 cupsd_printer_t
*p
; /* Current printer */
3245 * Update the IRIX printer state for the default printer; if
3246 * no printers remain, then the default printer file will be
3250 write_irix_state(DefaultPrinter
);
3254 * See if we have a printcap file; if not, don't bother writing it.
3257 if (!Printcap
|| !*Printcap
)
3260 cupsdLogMessage(CUPSD_LOG_INFO
, "Generating printcap %s...", Printcap
);
3263 * Open the printcap file...
3266 if ((fp
= cupsFileOpen(Printcap
, "w")) == NULL
)
3270 * Put a comment header at the top so that users will know where the
3271 * data has come from...
3274 if (PrintcapFormat
!= PRINTCAP_PLIST
)
3275 cupsFilePrintf(fp
, "# This file was automatically generated by cupsd(8) "
3277 "# %s/printers.conf file. All changes to this file\n"
3278 "# will be lost.\n", ServerRoot
);
3281 * Write a new printcap with the current list of printers.
3284 switch (PrintcapFormat
)
3288 * Each printer is put in the file as:
3298 cupsFilePrintf(fp
, "%s|%s:rm=%s:rp=%s:\n", DefaultPrinter
->name
,
3299 DefaultPrinter
->info
, ServerName
,
3300 DefaultPrinter
->name
);
3302 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3304 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3305 if (p
!= DefaultPrinter
)
3306 cupsFilePrintf(fp
, "%s|%s:rm=%s:rp=%s:\n", p
->name
, p
->info
,
3307 ServerName
, p
->name
);
3310 case PRINTCAP_PLIST
:
3312 * Each printer is written as a dictionary in a plist file.
3313 * Currently the printer-name, printer-info, printer-is-accepting-jobs,
3314 * printer-location, printer-make-and-model, printer-state,
3315 * printer-state-reasons, printer-type, and (sanitized) device-uri.
3318 cupsFilePuts(fp
, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
3319 "<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD "
3320 "PLIST 1.0//EN\" \"http://www.apple.com/DTDs/"
3321 "PropertyList-1.0.dtd\">\n"
3322 "<plist version=\"1.0\">\n"
3325 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3327 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3329 cupsFilePuts(fp
, "\t<dict>\n"
3330 "\t\t<key>printer-name</key>\n"
3332 write_xml_string(fp
, p
->name
);
3333 cupsFilePuts(fp
, "</string>\n"
3334 "\t\t<key>printer-info</key>\n"
3336 write_xml_string(fp
, p
->info
);
3337 cupsFilePrintf(fp
, "</string>\n"
3338 "\t\t<key>printer-is-accepting-jobs</key>\n"
3340 "\t\t<key>printer-location</key>\n"
3341 "\t\t<string>", p
->accepting
? "true" : "false");
3342 write_xml_string(fp
, p
->location
);
3343 cupsFilePuts(fp
, "</string>\n"
3344 "\t\t<key>printer-make-and-model</key>\n"
3346 write_xml_string(fp
, p
->make_model
);
3347 cupsFilePrintf(fp
, "</string>\n"
3348 "\t\t<key>printer-state</key>\n"
3349 "\t\t<integer>%d</integer>\n"
3350 "\t\t<key>printer-state-reasons</key>\n"
3351 "\t\t<array>\n", p
->state
);
3352 for (i
= 0; i
< p
->num_reasons
; i
++)
3354 cupsFilePuts(fp
, "\t\t\t<string>");
3355 write_xml_string(fp
, p
->reasons
[i
]);
3356 cupsFilePuts(fp
, "</string>\n");
3358 cupsFilePrintf(fp
, "\t\t</array>\n"
3359 "\t\t<key>printer-type</key>\n"
3360 "\t\t<integer>%d</integer>\n"
3361 "\t\t<key>device-uri</key>\n"
3362 "\t\t<string>", p
->type
);
3363 write_xml_string(fp
, p
->sanitized_device_uri
);
3364 cupsFilePuts(fp
, "</string>\n"
3367 cupsFilePuts(fp
, "</array>\n"
3371 case PRINTCAP_SOLARIS
:
3373 * Each printer is put in the file as:
3375 * _all:all=Printer1,Printer2,Printer3,...,PrinterN
3376 * _default:use=DefaultPrinter
3378 * :bsdaddr=ServerName,Printer1:\
3379 * :description=Description:
3381 * :bsdaddr=ServerName,Printer2:\
3382 * :description=Description:
3384 * :bsdaddr=ServerName,Printer3:\
3385 * :description=Description:
3388 * :bsdaddr=ServerName,PrinterN:\
3389 * :description=Description:
3392 cupsFilePuts(fp
, "_all:all=");
3393 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3395 p
= (cupsd_printer_t
*)cupsArrayCurrent(Printers
))
3396 cupsFilePrintf(fp
, "%s%c", p
->name
,
3397 cupsArrayNext(Printers
) ? ',' : '\n');
3400 cupsFilePrintf(fp
, "_default:use=%s\n", DefaultPrinter
->name
);
3402 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3404 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3405 cupsFilePrintf(fp
, "%s:\\\n"
3406 "\t:bsdaddr=%s,%s:\\\n"
3407 "\t:description=%s:\n",
3408 p
->name
, ServerName
, p
->name
,
3409 p
->info
? p
->info
: "");
3422 * 'add_printer_defaults()' - Add name-default attributes to the printer attributes.
3426 add_printer_defaults(cupsd_printer_t
*p
)/* I - Printer */
3428 int i
; /* Looping var */
3429 int num_options
; /* Number of default options */
3430 cups_option_t
*options
, /* Default options */
3431 *option
; /* Current option */
3432 char name
[256]; /* name-default */
3436 * Maintain a common array of default attribute names...
3439 if (!CommonDefaults
)
3441 CommonDefaults
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
3443 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("copies-default"));
3444 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("document-format-default"));
3445 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("finishings-default"));
3446 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-hold-until-default"));
3447 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-priority-default"));
3448 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-sheets-default"));
3449 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("media-col-default"));
3450 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("number-up-default"));
3451 cupsArrayAdd(CommonDefaults
,
3452 _cupsStrAlloc("orientation-requested-default"));
3456 * Add all of the default options from the .conf files...
3459 for (num_options
= 0, options
= NULL
, i
= p
->num_options
, option
= p
->options
;
3463 if (strcmp(option
->name
, "ipp-options") &&
3464 strcmp(option
->name
, "job-sheets") &&
3465 strcmp(option
->name
, "lease-duration"))
3467 snprintf(name
, sizeof(name
), "%s-default", option
->name
);
3468 num_options
= cupsAddOption(name
, option
->value
, num_options
, &options
);
3470 if (!cupsArrayFind(CommonDefaults
, name
))
3471 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc(name
));
3476 * Convert options to IPP attributes...
3479 cupsEncodeOptions2(p
->attrs
, num_options
, options
, IPP_TAG_PRINTER
);
3480 cupsFreeOptions(num_options
, options
);
3483 * Add standard -default attributes as needed...
3486 if (!cupsGetOption("copies", p
->num_options
, p
->options
))
3487 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
, "copies-default",
3490 if (!cupsGetOption("document-format", p
->num_options
, p
->options
))
3491 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_MIMETYPE
,
3492 "document-format-default", NULL
, "application/octet-stream");
3494 if (!cupsGetOption("job-hold-until", p
->num_options
, p
->options
))
3495 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3496 "job-hold-until-default", NULL
, "no-hold");
3498 if (!cupsGetOption("job-priority", p
->num_options
, p
->options
))
3499 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3500 "job-priority-default", 50);
3502 if (!cupsGetOption("number-up", p
->num_options
, p
->options
))
3503 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3504 "number-up-default", 1);
3506 if (!cupsGetOption("notify-lease-duration", p
->num_options
, p
->options
))
3507 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3508 "notify-lease-duration-default", DefaultLeaseDuration
);
3510 if (!cupsGetOption("notify-events", p
->num_options
, p
->options
))
3511 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3512 "notify-events-default", NULL
, "job-completed");
3514 if (!cupsGetOption("orientation-requested", p
->num_options
, p
->options
))
3515 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NOVALUE
,
3516 "orientation-requested-default", NULL
, NULL
);
3518 if (!cupsGetOption("print-quality", p
->num_options
, p
->options
))
3519 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
3520 "print-quality-default", IPP_QUALITY_NORMAL
);
3525 * 'add_printer_filter()' - Add a MIME filter for a printer.
3530 cupsd_printer_t
*p
, /* I - Printer to add to */
3531 mime_type_t
*filtertype
, /* I - Filter or prefilter MIME type */
3532 const char *filter
) /* I - Filter to add */
3534 char super
[MIME_MAX_SUPER
], /* Super-type for filter */
3535 type
[MIME_MAX_TYPE
], /* Type for filter */
3536 dsuper
[MIME_MAX_SUPER
], /* Destination super-type for filter */
3537 dtype
[MIME_MAX_TYPE
], /* Destination type for filter */
3538 dest
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2],
3539 /* Destination super/type */
3540 program
[1024]; /* Program/filter name */
3541 int cost
; /* Cost of filter */
3542 size_t maxsize
= 0; /* Maximum supported file size */
3543 mime_type_t
*temptype
, /* MIME type looping var */
3544 *desttype
; /* Destination MIME type */
3545 mime_filter_t
*filterptr
; /* MIME filter */
3546 char filename
[1024]; /* Full filter filename */
3549 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3550 "add_printer_filter(p=%p(%s), filtertype=%p(%s/%s), "
3551 "filter=\"%s\")", p
, p
->name
, filtertype
, filtertype
->super
,
3552 filtertype
->type
, filter
);
3555 * Parse the filter string; it should be in one of the following formats:
3557 * source/type cost program
3558 * source/type cost maxsize(nnnn) program
3559 * source/type dest/type cost program
3560 * source/type dest/type cost maxsize(nnnn) program
3563 if (sscanf(filter
, "%15[^/]/%255s%*[ \t]%15[^/]/%255s%d%*[ \t]%1023[^\n]",
3564 super
, type
, dsuper
, dtype
, &cost
, program
) == 6)
3566 snprintf(dest
, sizeof(dest
), "%s/%s/%s", p
->name
, dsuper
, dtype
);
3568 if ((desttype
= mimeType(MimeDatabase
, "printer", dest
)) == NULL
)
3570 desttype
= mimeAddType(MimeDatabase
, "printer", dest
);
3572 p
->dest_types
= cupsArrayNew(NULL
, NULL
);
3574 cupsArrayAdd(p
->dest_types
, desttype
);
3580 if (sscanf(filter
, "%15[^/]/%255s%d%*[ \t]%1023[^\n]", super
, type
, &cost
,
3583 desttype
= filtertype
;
3587 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: invalid filter string \"%s\"!",
3593 if (!strncmp(program
, "maxsize(", 8))
3595 char *ptr
; /* Pointer into maxsize(nnnn) program */
3597 maxsize
= strtoll(program
+ 8, &ptr
, 10);
3601 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: invalid filter string \"%s\"!",
3607 while (_cups_isspace(*ptr
))
3610 _cups_strcpy(program
, ptr
);
3614 * Check permissions on the filter and its containing directory...
3617 if (strcmp(program
, "-"))
3619 if (program
[0] == '/')
3620 strlcpy(filename
, program
, sizeof(filename
));
3622 snprintf(filename
, sizeof(filename
), "%s/filter/%s", ServerBin
, program
);
3624 _cupsFileCheck(filename
, _CUPS_FILE_CHECK_PROGRAM
, !RunUser
,
3625 cupsdLogFCMessage
, p
);
3629 * Add the filter to the MIME database, supporting wildcards as needed...
3632 for (temptype
= mimeFirstType(MimeDatabase
);
3634 temptype
= mimeNextType(MimeDatabase
))
3635 if (((super
[0] == '*' && _cups_strcasecmp(temptype
->super
, "printer")) ||
3636 !_cups_strcasecmp(temptype
->super
, super
)) &&
3637 (type
[0] == '*' || !_cups_strcasecmp(temptype
->type
, type
)))
3639 if (desttype
!= filtertype
)
3641 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3642 "add_printer_filter: %s: adding filter %s/%s %s/%s %d "
3643 "%s", p
->name
, temptype
->super
, temptype
->type
,
3644 desttype
->super
, desttype
->type
,
3646 filterptr
= mimeAddFilter(MimeDatabase
, temptype
, desttype
, cost
,
3649 if (!mimeFilterLookup(MimeDatabase
, desttype
, filtertype
))
3651 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3652 "add_printer_filter: %s: adding filter %s/%s %s/%s "
3653 "0 -", p
->name
, desttype
->super
, desttype
->type
,
3654 filtertype
->super
, filtertype
->type
);
3655 mimeAddFilter(MimeDatabase
, desttype
, filtertype
, cost
, "-");
3660 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3661 "add_printer_filter: %s: adding filter %s/%s %s/%s %d "
3662 "%s", p
->name
, temptype
->super
, temptype
->type
,
3663 filtertype
->super
, filtertype
->type
,
3665 filterptr
= mimeAddFilter(MimeDatabase
, temptype
, filtertype
, cost
,
3670 filterptr
->maxsize
= maxsize
;
3676 * 'add_printer_formats()' - Add document-format-supported values for a printer.
3680 add_printer_formats(cupsd_printer_t
*p
) /* I - Printer */
3682 int i
; /* Looping var */
3683 mime_type_t
*type
; /* Current MIME type */
3684 cups_array_t
*filters
; /* Filters */
3685 ipp_attribute_t
*attr
; /* document-format-supported attribute */
3686 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
3687 /* MIME type name */
3691 * Raw (and remote) queues advertise all of the supported MIME
3695 cupsArrayDelete(p
->filetypes
);
3696 p
->filetypes
= NULL
;
3700 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
,
3701 (ipp_tag_t
)(IPP_TAG_MIMETYPE
| IPP_TAG_COPY
),
3702 "document-format-supported", NumMimeTypes
, NULL
, MimeTypes
);
3707 * Otherwise, loop through the supported MIME types and see if there
3708 * are filters for them...
3711 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_printer_formats: %d types, %d filters",
3712 mimeNumTypes(MimeDatabase
), mimeNumFilters(MimeDatabase
));
3714 p
->filetypes
= cupsArrayNew(NULL
, NULL
);
3716 for (type
= mimeFirstType(MimeDatabase
);
3718 type
= mimeNextType(MimeDatabase
))
3720 if (!_cups_strcasecmp(type
->super
, "printer"))
3723 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
3725 if ((filters
= mimeFilter(MimeDatabase
, type
, p
->filetype
, NULL
)) != NULL
)
3727 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3728 "add_printer_formats: %s: %s needs %d filters",
3729 p
->name
, mimetype
, cupsArrayCount(filters
));
3731 cupsArrayDelete(filters
);
3732 cupsArrayAdd(p
->filetypes
, type
);
3735 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3736 "add_printer_formats: %s: %s not supported",
3741 * Add the file formats that can be filtered...
3744 if ((type
= mimeType(MimeDatabase
, "application", "octet-stream")) == NULL
||
3745 !cupsArrayFind(p
->filetypes
, type
))
3750 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3751 "add_printer_formats: %s: %d supported types",
3752 p
->name
, cupsArrayCount(p
->filetypes
) + i
);
3754 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_MIMETYPE
,
3755 "document-format-supported",
3756 cupsArrayCount(p
->filetypes
) + i
, NULL
, NULL
);
3759 attr
->values
[0].string
.text
= _cupsStrAlloc("application/octet-stream");
3761 for (type
= (mime_type_t
*)cupsArrayFirst(p
->filetypes
);
3763 i
++, type
= (mime_type_t
*)cupsArrayNext(p
->filetypes
))
3765 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
3767 attr
->values
[i
].string
.text
= _cupsStrAlloc(mimetype
);
3772 char pdl
[1024]; /* Buffer to build pdl list */
3773 mime_filter_t
*filter
; /* MIME filter looping var */
3777 * We only support raw printing if this is not a Tioga PrintJobMgr based
3778 * queue and if application/octet-stream is a known type...
3781 for (filter
= (mime_filter_t
*)cupsArrayFirst(MimeDatabase
->filters
);
3783 filter
= (mime_filter_t
*)cupsArrayNext(MimeDatabase
->filters
))
3785 if (filter
->dst
== p
->filetype
&& filter
->filter
&&
3786 strstr(filter
->filter
, "PrintJobMgr"))
3792 if (!filter
&& mimeType(MimeDatabase
, "application", "octet-stream"))
3793 strlcat(pdl
, "application/octet-stream,", sizeof(pdl
));
3796 * Then list a bunch of formats that are supported by the printer...
3799 for (type
= (mime_type_t
*)cupsArrayFirst(p
->filetypes
);
3801 type
= (mime_type_t
*)cupsArrayNext(p
->filetypes
))
3803 if (!_cups_strcasecmp(type
->super
, "application"))
3805 if (!_cups_strcasecmp(type
->type
, "pdf"))
3806 strlcat(pdl
, "application/pdf,", sizeof(pdl
));
3807 else if (!_cups_strcasecmp(type
->type
, "postscript"))
3808 strlcat(pdl
, "application/postscript,", sizeof(pdl
));
3810 else if (!_cups_strcasecmp(type
->super
, "image"))
3812 if (!_cups_strcasecmp(type
->type
, "jpeg"))
3813 strlcat(pdl
, "image/jpeg,", sizeof(pdl
));
3814 else if (!_cups_strcasecmp(type
->type
, "png"))
3815 strlcat(pdl
, "image/png,", sizeof(pdl
));
3816 else if (!_cups_strcasecmp(type
->type
, "pwg-raster"))
3817 strlcat(pdl
, "image/pwg-raster,", sizeof(pdl
));
3822 pdl
[strlen(pdl
) - 1] = '\0'; /* Remove trailing comma */
3824 cupsdSetString(&p
->pdl
, pdl
);
3826 #endif /* HAVE_DNSSD */
3831 * 'compare_printers()' - Compare two printers.
3834 static int /* O - Result of comparison */
3835 compare_printers(void *first
, /* I - First printer */
3836 void *second
, /* I - Second printer */
3837 void *data
) /* I - App data (not used) */
3841 return (_cups_strcasecmp(((cupsd_printer_t
*)first
)->name
,
3842 ((cupsd_printer_t
*)second
)->name
));
3847 * 'delete_printer_filters()' - Delete all MIME filters for a printer.
3851 delete_printer_filters(
3852 cupsd_printer_t
*p
) /* I - Printer to remove from */
3854 mime_filter_t
*filter
; /* MIME filter looping var */
3855 mime_type_t
*type
; /* Destination types for filters */
3859 * Range check input...
3866 * Remove all filters from the MIME database that have a destination
3867 * type == printer...
3870 for (filter
= mimeFirstFilter(MimeDatabase
);
3872 filter
= mimeNextFilter(MimeDatabase
))
3873 if (filter
->dst
== p
->filetype
|| filter
->dst
== p
->prefiltertype
||
3874 cupsArrayFind(p
->dest_types
, filter
->dst
))
3877 * Delete the current filter...
3880 mimeDeleteFilter(MimeDatabase
, filter
);
3883 for (type
= (mime_type_t
*)cupsArrayFirst(p
->dest_types
);
3885 type
= (mime_type_t
*)cupsArrayNext(p
->dest_types
))
3886 mimeDeleteType(MimeDatabase
, type
);
3888 cupsArrayDelete(p
->dest_types
);
3889 p
->dest_types
= NULL
;
3891 cupsdSetPrinterReasons(p
, "-cups-insecure-filter-warning"
3892 ",cups-missing-filter-warning");
3897 * 'dirty_printer()' - Mark config and state files dirty for the specified
3902 dirty_printer(cupsd_printer_t
*p
) /* I - Printer */
3904 if (p
->type
& CUPS_PRINTER_DISCOVERED
)
3905 cupsdMarkDirty(CUPSD_DIRTY_REMOTE
);
3906 else if (p
->type
& CUPS_PRINTER_CLASS
)
3907 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
3909 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
3911 if (PrintcapFormat
== PRINTCAP_PLIST
)
3912 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
3917 * 'load_ppd()' - Load a cached PPD file, updating the cache as needed.
3921 load_ppd(cupsd_printer_t
*p
) /* I - Printer */
3923 int i
, j
, k
; /* Looping vars */
3924 char cache_name
[1024]; /* Cache filename */
3925 struct stat cache_info
; /* Cache file info */
3926 ppd_file_t
*ppd
; /* PPD file */
3927 char ppd_name
[1024]; /* PPD filename */
3928 struct stat ppd_info
; /* PPD file info */
3929 int num_media
; /* Number of media options */
3930 ppd_size_t
*size
; /* Current PPD size */
3931 ppd_option_t
*duplex
, /* Duplex option */
3932 *output_bin
, /* OutputBin option */
3933 *output_mode
, /* OutputMode option */
3934 *resolution
; /* (Set|JCL|)Resolution option */
3935 ppd_choice_t
*choice
, /* Current PPD choice */
3936 *input_slot
, /* Current input slot */
3937 *media_type
; /* Current media type */
3938 ppd_attr_t
*ppd_attr
; /* PPD attribute */
3939 int xdpi
, /* Horizontal resolution */
3940 ydpi
; /* Vertical resolution */
3941 const char *resptr
; /* Pointer into resolution keyword */
3942 _pwg_size_t
*pwgsize
; /* Current PWG size */
3943 _pwg_map_t
*pwgsource
, /* Current PWG source */
3944 *pwgtype
; /* Current PWG type */
3945 ipp_attribute_t
*attr
; /* Attribute data */
3946 ipp_value_t
*val
; /* Attribute value */
3947 int num_finishings
, /* Number of finishings */
3948 finishings
[5]; /* finishings-supported values */
3949 int num_qualities
, /* Number of print-quality values */
3950 qualities
[3]; /* print-quality values */
3951 int num_margins
, /* Number of media-*-margin-supported values */
3952 margins
[16]; /* media-*-margin-supported values */
3953 const char *filter
; /* Current filter */
3954 static const char * const sides
[3] = /* sides-supported values */
3957 "two-sided-long-edge",
3958 "two-sided-short-edge"
3960 static const char * const standard_commands
[] =
3961 { /* Standard CUPS commands */
3969 * Check to see if the cache is up-to-date...
3972 snprintf(cache_name
, sizeof(cache_name
), "%s/%s.data", CacheDir
, p
->name
);
3973 if (stat(cache_name
, &cache_info
))
3974 cache_info
.st_mtime
= 0;
3976 snprintf(ppd_name
, sizeof(ppd_name
), "%s/ppd/%s.ppd", ServerRoot
, p
->name
);
3977 if (stat(ppd_name
, &ppd_info
))
3978 ppd_info
.st_mtime
= 1;
3980 ippDelete(p
->ppd_attrs
);
3981 p
->ppd_attrs
= NULL
;
3983 _ppdCacheDestroy(p
->pc
);
3986 if (cache_info
.st_mtime
>= ppd_info
.st_mtime
)
3988 cupsdLogMessage(CUPSD_LOG_DEBUG
, "load_ppd: Loading %s...", cache_name
);
3990 if ((p
->pc
= _ppdCacheCreateWithFile(cache_name
, &p
->ppd_attrs
)) != NULL
&&
3994 * Loaded successfully!
4002 * Reload PPD attributes from disk...
4005 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
4007 cupsdLogMessage(CUPSD_LOG_DEBUG
, "load_ppd: Loading %s...", ppd_name
);
4009 p
->type
&= ~CUPS_PRINTER_OPTIONS
;
4010 p
->type
|= CUPS_PRINTER_BW
;
4012 finishings
[0] = IPP_FINISHINGS_NONE
;
4015 p
->ppd_attrs
= ippNew();
4017 if ((ppd
= ppdOpenFile(ppd_name
)) != NULL
)
4020 * Add make/model and other various attributes...
4023 p
->pc
= _ppdCacheCreateWithPPD(ppd
);
4025 ppdMarkDefaults(ppd
);
4027 if (ppd
->color_device
)
4028 p
->type
|= CUPS_PRINTER_COLOR
;
4029 if (ppd
->variable_sizes
)
4030 p
->type
|= CUPS_PRINTER_VARIABLE
;
4031 if (!ppd
->manual_copies
)
4032 p
->type
|= CUPS_PRINTER_COPIES
;
4033 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsFax", NULL
)) != NULL
)
4034 if (ppd_attr
->value
&& !_cups_strcasecmp(ppd_attr
->value
, "true"))
4035 p
->type
|= CUPS_PRINTER_FAX
;
4037 ippAddBoolean(p
->ppd_attrs
, IPP_TAG_PRINTER
, "color-supported",
4039 if (ppd
->throughput
)
4041 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4042 "pages-per-minute", ppd
->throughput
);
4043 if (ppd
->color_device
)
4044 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4045 "pages-per-minute-color", ppd
->throughput
);
4050 * When there is no speed information, just say "1 page per minute".
4053 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4054 "pages-per-minute", 1);
4055 if (ppd
->color_device
)
4056 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4057 "pages-per-minute-color", 1);
4062 if ((output_mode
= ppdFindOption(ppd
, "OutputMode")) != NULL
)
4064 if (ppdFindChoice(output_mode
, "draft") ||
4065 ppdFindChoice(output_mode
, "fast"))
4066 qualities
[num_qualities
++] = IPP_QUALITY_DRAFT
;
4068 qualities
[num_qualities
++] = IPP_QUALITY_NORMAL
;
4070 if (ppdFindChoice(output_mode
, "best") ||
4071 ppdFindChoice(output_mode
, "high"))
4072 qualities
[num_qualities
++] = IPP_QUALITY_HIGH
;
4074 else if ((ppd_attr
= ppdFindAttr(ppd
, "APPrinterPreset", NULL
)) != NULL
)
4078 if (strstr(ppd_attr
->spec
, "draft") ||
4079 strstr(ppd_attr
->spec
, "Draft"))
4081 qualities
[num_qualities
++] = IPP_QUALITY_DRAFT
;
4085 while ((ppd_attr
= ppdFindNextAttr(ppd
, "APPrinterPreset",
4088 qualities
[num_qualities
++] = IPP_QUALITY_NORMAL
;
4089 qualities
[num_qualities
++] = IPP_QUALITY_HIGH
;
4092 qualities
[num_qualities
++] = IPP_QUALITY_NORMAL
;
4094 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
4095 "print-quality-supported", num_qualities
, qualities
);
4100 * The NickName can be localized in the character set specified
4101 * by the LanugageEncoding attribute. However, ppdOpen2() has
4102 * already converted the ppd->nickname member to UTF-8 for us
4103 * (the original attribute value is available separately)
4106 cupsdSetString(&p
->make_model
, ppd
->nickname
);
4108 else if (ppd
->modelname
)
4111 * Model name can only contain specific characters...
4114 cupsdSetString(&p
->make_model
, ppd
->modelname
);
4117 cupsdSetString(&p
->make_model
, "Bad PPD File");
4119 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
4120 "printer-make-and-model", NULL
, p
->make_model
);
4123 * Add media options from the PPD file...
4126 if (ppd
->num_sizes
== 0 || !p
->pc
)
4128 if (!ppdFindAttr(ppd
, "APScannerOnly", NULL
))
4129 cupsdLogMessage(CUPSD_LOG_CRIT
,
4130 "The PPD file for printer %s contains no media "
4131 "options and is therefore invalid!", p
->name
);
4133 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4134 "media-default", NULL
, "unknown");
4135 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4136 "media-supported", NULL
, "unknown");
4144 if ((size
= ppdPageSize(ppd
, NULL
)) != NULL
)
4145 pwgsize
= _ppdCacheGetSize(p
->pc
, size
->name
);
4149 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4150 "media-default", NULL
,
4151 pwgsize
? pwgsize
->map
.pwg
: "unknown");
4159 ipp_t
*col
; /* Collection value */
4161 input_slot
= ppdFindMarkedChoice(ppd
, "InputSlot");
4162 media_type
= ppdFindMarkedChoice(ppd
, "MediaType");
4163 col
= new_media_col(pwgsize
,
4165 _ppdCacheGetSource(p
->pc
,
4166 input_slot
->choice
) :
4169 _ppdCacheGetType(p
->pc
,
4170 media_type
->choice
) :
4173 ippAddCollection(p
->ppd_attrs
, IPP_TAG_PRINTER
, "media-col-default",
4182 num_media
= p
->pc
->num_sizes
;
4183 if (p
->pc
->custom_min_keyword
)
4186 if ((attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4187 "media-supported", num_media
, NULL
,
4192 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
;
4194 i
--, pwgsize
++, val
++)
4195 val
->string
.text
= _cupsStrRetain(pwgsize
->map
.pwg
);
4197 if (p
->pc
->custom_min_keyword
)
4199 val
->string
.text
= _cupsStrRetain(p
->pc
->custom_min_keyword
);
4201 val
->string
.text
= _cupsStrRetain(p
->pc
->custom_max_keyword
);
4206 * media-source-supported
4209 if (p
->pc
->num_sources
> 0 &&
4210 (attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4211 "media-source-supported", p
->pc
->num_sources
,
4212 NULL
, NULL
)) != NULL
)
4214 for (i
= p
->pc
->num_sources
, pwgsource
= p
->pc
->sources
,
4217 i
--, pwgsource
++, val
++)
4218 val
->string
.text
= _cupsStrRetain(pwgsource
->pwg
);
4222 * media-type-supported
4225 if (p
->pc
->num_types
> 0 &&
4226 (attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4227 "media-type-supported", p
->pc
->num_types
,
4228 NULL
, NULL
)) != NULL
)
4230 for (i
= p
->pc
->num_types
, pwgtype
= p
->pc
->types
,
4233 i
--, pwgtype
++, val
++)
4234 val
->string
.text
= _cupsStrRetain(pwgtype
->pwg
);
4238 * media-*-margin-supported
4241 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, num_margins
= 0;
4242 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4245 for (j
= 0; j
< num_margins
; j
++)
4246 if (pwgsize
->bottom
== margins
[j
])
4249 if (j
>= num_margins
)
4251 margins
[num_margins
] = pwgsize
->bottom
;
4256 if (num_margins
> 0)
4257 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4258 "media-bottom-margin-supported", num_margins
, margins
);
4260 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4261 "media-bottom-margin-supported", 0);
4263 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, num_margins
= 0;
4264 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4267 for (j
= 0; j
< num_margins
; j
++)
4268 if (pwgsize
->left
== margins
[j
])
4271 if (j
>= num_margins
)
4273 margins
[num_margins
] = pwgsize
->left
;
4278 if (num_margins
> 0)
4279 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4280 "media-left-margin-supported", num_margins
, margins
);
4282 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4283 "media-left-margin-supported", 0);
4285 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, num_margins
= 0;
4286 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4289 for (j
= 0; j
< num_margins
; j
++)
4290 if (pwgsize
->right
== margins
[j
])
4293 if (j
>= num_margins
)
4295 margins
[num_margins
] = pwgsize
->right
;
4300 if (num_margins
> 0)
4301 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4302 "media-right-margin-supported", num_margins
, margins
);
4304 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4305 "media-right-margin-supported", 0);
4307 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, num_margins
= 0;
4308 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4311 for (j
= 0; j
< num_margins
; j
++)
4312 if (pwgsize
->top
== margins
[j
])
4315 if (j
>= num_margins
)
4317 margins
[num_margins
] = pwgsize
->top
;
4322 if (num_margins
> 0)
4323 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4324 "media-top-margin-supported", num_margins
, margins
);
4326 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4327 "media-top-margin-supported", 0);
4330 * media-col-database
4333 num_media
= p
->pc
->num_sizes
;
4334 if (p
->pc
->num_sources
)
4336 if (p
->pc
->num_types
> 0)
4337 num_media
+= p
->pc
->num_sizes
* p
->pc
->num_sources
*
4340 num_media
+= p
->pc
->num_sizes
* p
->pc
->num_sources
;
4342 else if (p
->pc
->num_types
)
4343 num_media
+= p
->pc
->num_sizes
* p
->pc
->num_types
;
4345 if ((attr
= ippAddCollections(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4346 "media-col-database", num_media
,
4349 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, val
= attr
->values
;
4354 * Start by adding the page size without source or type...
4357 ppdMarkOption(ppd
, "PageSize", pwgsize
->map
.ppd
);
4359 val
->collection
= new_media_col(pwgsize
, NULL
, NULL
);
4363 * Then add the specific, supported combinations of size, source, and
4367 if (p
->pc
->num_sources
> 0)
4369 for (j
= p
->pc
->num_sources
, pwgsource
= p
->pc
->sources
;
4373 ppdMarkOption(ppd
, "InputSlot", pwgsource
->ppd
);
4375 if (p
->pc
->num_types
> 0)
4377 for (k
= p
->pc
->num_types
, pwgtype
= p
->pc
->types
;
4381 if (!ppdMarkOption(ppd
, "MediaType", pwgtype
->ppd
))
4383 val
->collection
= new_media_col(pwgsize
, pwgsource
->pwg
,
4389 else if (!ppdConflicts(ppd
))
4391 val
->collection
= new_media_col(pwgsize
, pwgsource
->pwg
, NULL
);
4396 else if (p
->pc
->num_types
> 0)
4398 for (j
= p
->pc
->num_types
, pwgtype
= p
->pc
->types
;
4402 if (!ppdMarkOption(ppd
, "MediaType", pwgtype
->ppd
))
4404 val
->collection
= new_media_col(pwgsize
, NULL
, pwgtype
->pwg
);
4412 * Update the number of media-col-database values...
4415 attr
->num_values
= val
- attr
->values
;
4423 if (p
->pc
&& p
->pc
->num_bins
> 0)
4425 attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4426 "output-bin-supported", p
->pc
->num_bins
,
4431 for (i
= 0, val
= attr
->values
;
4432 i
< p
->pc
->num_bins
;
4434 val
->string
.text
= _cupsStrAlloc(p
->pc
->bins
[i
].pwg
);
4437 if ((output_bin
= ppdFindOption(ppd
, "OutputBin")) != NULL
)
4439 for (i
= 0; i
< p
->pc
->num_bins
; i
++)
4440 if (!strcmp(p
->pc
->bins
[i
].ppd
, output_bin
->defchoice
))
4443 if (i
>= p
->pc
->num_bins
)
4446 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4447 "output-bin-default", NULL
, p
->pc
->bins
[i
].pwg
);
4450 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4451 "output-bin-default", NULL
, p
->pc
->bins
[0].pwg
);
4453 else if (((ppd_attr
= ppdFindAttr(ppd
, "DefaultOutputOrder",
4455 !_cups_strcasecmp(ppd_attr
->value
, "Reverse")) ||
4456 (!ppd_attr
&& ppd
->manufacturer
&& /* "Compatibility heuristic" */
4457 (!_cups_strcasecmp(ppd
->manufacturer
, "epson") ||
4458 !_cups_strcasecmp(ppd
->manufacturer
, "lexmark"))))
4461 * Report that this printer has a single output bin that leaves pages face
4465 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4466 "output-bin-supported", NULL
, "face-up");
4467 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4468 "output-bin-default", NULL
, "face-up");
4472 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4473 "output-bin-supported", NULL
, "face-down");
4474 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4475 "output-bin-default", NULL
, "face-down");
4479 * output-mode and print-color-mode...
4482 if (ppd
->color_device
)
4484 static const char * const output_modes
[] =
4490 ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4491 "output-mode-supported", 2, NULL
, output_modes
);
4492 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4493 "output-mode-default", NULL
, "color");
4495 ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4496 "print-color-mode-supported", 2, NULL
, output_modes
);
4497 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4498 "print-color-mode-default", NULL
, "color");
4502 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4503 "output-mode-supported", NULL
, "monochrome");
4504 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4505 "output-mode-default", NULL
, "monochrome");
4507 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4508 "print-color-mode-supported", NULL
, "monochrome");
4509 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4510 "print-color-mode-default", NULL
, "monochrome");
4514 * Printer resolutions...
4517 if ((resolution
= ppdFindOption(ppd
, "Resolution")) == NULL
)
4518 if ((resolution
= ppdFindOption(ppd
, "JCLResolution")) == NULL
)
4519 if ((resolution
= ppdFindOption(ppd
, "SetResolution")) == NULL
)
4520 resolution
= ppdFindOption(ppd
, "CNRes_PGP");
4525 * Report all supported resolutions...
4528 attr
= ippAddResolutions(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4529 "printer-resolution-supported",
4530 resolution
->num_choices
, IPP_RES_PER_INCH
,
4533 for (i
= 0, choice
= resolution
->choices
;
4534 i
< resolution
->num_choices
;
4537 xdpi
= ydpi
= (int)strtol(choice
->choice
, (char **)&resptr
, 10);
4538 if (resptr
> choice
->choice
&& xdpi
> 0 && *resptr
== 'x')
4539 ydpi
= (int)strtol(resptr
+ 1, (char **)&resptr
, 10);
4541 if (xdpi
<= 0 || ydpi
<= 0)
4543 cupsdLogMessage(CUPSD_LOG_WARN
,
4544 "Bad resolution \"%s\" for printer %s.",
4545 choice
->choice
, p
->name
);
4549 attr
->values
[i
].resolution
.xres
= xdpi
;
4550 attr
->values
[i
].resolution
.yres
= ydpi
;
4551 attr
->values
[i
].resolution
.units
= IPP_RES_PER_INCH
;
4554 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4555 "printer-resolution-default", IPP_RES_PER_INCH
,
4559 else if ((ppd_attr
= ppdFindAttr(ppd
, "DefaultResolution", NULL
)) != NULL
&&
4563 * Just the DefaultResolution to report...
4566 xdpi
= ydpi
= (int)strtol(ppd_attr
->value
, (char **)&resptr
, 10);
4567 if (resptr
> ppd_attr
->value
&& xdpi
> 0)
4570 ydpi
= (int)strtol(resptr
+ 1, (char **)&resptr
, 10);
4575 if (xdpi
<= 0 || ydpi
<= 0)
4577 cupsdLogMessage(CUPSD_LOG_WARN
,
4578 "Bad default resolution \"%s\" for printer %s.",
4579 ppd_attr
->value
, p
->name
);
4583 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4584 "printer-resolution-default", IPP_RES_PER_INCH
,
4586 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4587 "printer-resolution-supported", IPP_RES_PER_INCH
,
4593 * No resolutions in PPD - make one up...
4596 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4597 "printer-resolution-default", IPP_RES_PER_INCH
,
4599 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4600 "printer-resolution-supported", IPP_RES_PER_INCH
,
4608 ppdMarkDefaults(ppd
);
4610 if ((duplex
= ppdFindOption(ppd
, "Duplex")) == NULL
)
4611 if ((duplex
= ppdFindOption(ppd
, "EFDuplex")) == NULL
)
4612 if ((duplex
= ppdFindOption(ppd
, "EFDuplexing")) == NULL
)
4613 if ((duplex
= ppdFindOption(ppd
, "KD03Duplex")) == NULL
)
4614 duplex
= ppdFindOption(ppd
, "JCLDuplex");
4616 if (duplex
&& duplex
->num_choices
> 1 &&
4617 !ppdInstallableConflict(ppd
, duplex
->keyword
, "DuplexTumble"))
4619 p
->type
|= CUPS_PRINTER_DUPLEX
;
4621 ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4622 "sides-supported", 3, NULL
, sides
);
4624 if (!_cups_strcasecmp(duplex
->defchoice
, "DuplexTumble"))
4625 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4626 "sides-default", NULL
, "two-sided-short-edge");
4627 else if (!_cups_strcasecmp(duplex
->defchoice
, "DuplexNoTumble"))
4628 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4629 "sides-default", NULL
, "two-sided-long-edge");
4631 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4632 "sides-default", NULL
, "one-sided");
4636 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4637 "sides-supported", NULL
, "one-sided");
4638 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4639 "sides-default", NULL
, "one-sided");
4642 if (ppdFindOption(ppd
, "Collate") != NULL
)
4643 p
->type
|= CUPS_PRINTER_COLLATE
;
4645 if (ppdFindOption(ppd
, "StapleLocation") != NULL
)
4647 p
->type
|= CUPS_PRINTER_STAPLE
;
4648 finishings
[num_finishings
++] = IPP_FINISHINGS_STAPLE
;
4651 if (ppdFindOption(ppd
, "BindEdge") != NULL
)
4653 p
->type
|= CUPS_PRINTER_BIND
;
4654 finishings
[num_finishings
++] = IPP_FINISHINGS_BIND
;
4657 for (i
= 0; i
< ppd
->num_sizes
; i
++)
4658 if (ppd
->sizes
[i
].length
> 1728)
4659 p
->type
|= CUPS_PRINTER_LARGE
;
4660 else if (ppd
->sizes
[i
].length
> 1008)
4661 p
->type
|= CUPS_PRINTER_MEDIUM
;
4663 p
->type
|= CUPS_PRINTER_SMALL
;
4665 if ((ppd_attr
= ppdFindAttr(ppd
, "APICADriver", NULL
)) != NULL
&&
4666 ppd_attr
->value
&& !_cups_strcasecmp(ppd_attr
->value
, "true"))
4668 if ((ppd_attr
= ppdFindAttr(ppd
, "APScannerOnly", NULL
)) != NULL
&&
4669 ppd_attr
->value
&& !_cups_strcasecmp(ppd_attr
->value
, "true"))
4670 p
->type
|= CUPS_PRINTER_SCANNER
;
4672 p
->type
|= CUPS_PRINTER_MFP
;
4676 * Scan the filters in the PPD file...
4681 for (filter
= (const char *)cupsArrayFirst(p
->pc
->filters
);
4683 filter
= (const char *)cupsArrayNext(p
->pc
->filters
))
4685 if (!_cups_strncasecmp(filter
, "application/vnd.cups-command", 28) &&
4686 _cups_isspace(filter
[28]))
4688 p
->type
|= CUPS_PRINTER_COMMANDS
;
4694 if (p
->type
& CUPS_PRINTER_COMMANDS
)
4696 char *commands
, /* Copy of commands */
4697 *start
, /* Start of name */
4698 *end
; /* End of name */
4699 int count
; /* Number of commands */
4701 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsCommands", NULL
)) != NULL
)
4703 for (count
= 0, start
= ppd_attr
->value
; *start
; count
++)
4705 while (_cups_isspace(*start
))
4711 while (*start
&& !isspace(*start
& 255))
4721 * Make a copy of the commands string and count how many commands there
4725 attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4726 "printer-commands", count
, NULL
, NULL
);
4728 commands
= strdup(ppd_attr
->value
);
4730 for (count
= 0, start
= commands
; *start
; count
++)
4732 while (isspace(*start
& 255))
4739 while (*end
&& !isspace(*end
& 255))
4745 attr
->values
[count
].string
.text
= _cupsStrAlloc(start
);
4755 * Add the standard list of commands...
4758 ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4760 (int)(sizeof(standard_commands
) /
4761 sizeof(standard_commands
[0])), NULL
,
4768 * No commands supported...
4771 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4772 "printer-commands", NULL
, "none");
4776 * Show current and available port monitors for this printer...
4779 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
, "port-monitor",
4780 NULL
, p
->port_monitor
? p
->port_monitor
: "none");
4782 for (i
= 1, ppd_attr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
4784 i
++, ppd_attr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
));
4788 if (strstr(ppd
->protocols
, "TBCP"))
4790 else if (strstr(ppd
->protocols
, "BCP"))
4794 attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
4795 "port-monitor-supported", i
, NULL
, NULL
);
4797 attr
->values
[0].string
.text
= _cupsStrAlloc("none");
4799 for (i
= 1, ppd_attr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
4801 i
++, ppd_attr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
))
4802 attr
->values
[i
].string
.text
= _cupsStrAlloc(ppd_attr
->value
);
4806 if (strstr(ppd
->protocols
, "TBCP"))
4807 attr
->values
[i
].string
.text
= _cupsStrAlloc("tbcp");
4808 else if (strstr(ppd
->protocols
, "BCP"))
4809 attr
->values
[i
].string
.text
= _cupsStrAlloc("bcp");
4812 if (ppdFindAttr(ppd
, "APRemoteQueueID", NULL
))
4813 p
->type
|= CUPS_PRINTER_REMOTE
;
4815 #ifdef HAVE_APPLICATIONSERVICES_H
4817 * Convert the file referenced in APPrinterIconPath to a 128x128 PNG
4818 * and save it as cacheDir/printername.png
4821 if ((ppd_attr
= ppdFindAttr(ppd
, "APPrinterIconPath", NULL
)) != NULL
&&
4823 !_cupsFileCheck(ppd_attr
->value
, _CUPS_FILE_CHECK_FILE
, !RunUser
,
4824 cupsdLogFCMessage
, p
))
4826 CGImageRef imageRef
= NULL
;/* Current icon image */
4827 CGImageRef biggestIconRef
= NULL
;
4828 /* Biggest icon image */
4829 CGImageRef closestTo128IconRef
= NULL
;
4830 /* Icon image closest to and >= 128 */
4831 CGImageSourceRef sourceRef
; /* The file's image source */
4832 char outPath
[HTTP_MAX_URI
];
4833 /* The path to the PNG file */
4834 CFURLRef outUrl
; /* The URL made from the outPath */
4835 CFURLRef icnsFileUrl
; /* The URL of the original ICNS icon file */
4836 CGImageDestinationRef destRef
; /* The image destination to write */
4837 size_t bytesPerRow
; /* The bytes per row used for resizing */
4838 CGContextRef context
; /* The CG context used for resizing */
4840 snprintf(outPath
, sizeof(outPath
), "%s/%s.png", CacheDir
, p
->name
);
4841 outUrl
= CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault
,
4845 icnsFileUrl
= CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault
,
4846 (UInt8
*)ppd_attr
->value
,
4847 strlen(ppd_attr
->value
),
4849 if (outUrl
&& icnsFileUrl
)
4851 sourceRef
= CGImageSourceCreateWithURL(icnsFileUrl
, NULL
);
4854 for (i
= 0; i
< CGImageSourceGetCount(sourceRef
); i
++)
4856 imageRef
= CGImageSourceCreateImageAtIndex(sourceRef
, i
, NULL
);
4860 if (CGImageGetWidth(imageRef
) == CGImageGetHeight(imageRef
))
4863 * Loop through remembering the icon closest to 128 but >= 128
4864 * and then remember the largest icon.
4867 if (CGImageGetWidth(imageRef
) >= 128 &&
4868 (!closestTo128IconRef
||
4869 CGImageGetWidth(imageRef
) <
4870 CGImageGetWidth(closestTo128IconRef
)))
4872 CGImageRelease(closestTo128IconRef
);
4873 CGImageRetain(imageRef
);
4874 closestTo128IconRef
= imageRef
;
4877 if (!biggestIconRef
||
4878 CGImageGetWidth(imageRef
) > CGImageGetWidth(biggestIconRef
))
4880 CGImageRelease(biggestIconRef
);
4881 CGImageRetain(imageRef
);
4882 biggestIconRef
= imageRef
;
4886 CGImageRelease(imageRef
);
4892 * If biggestIconRef is NULL, we found no icons. Otherwise we first
4893 * want the closest to 128, but if none are larger than 128, we want
4894 * the largest icon available.
4897 imageRef
= closestTo128IconRef
? closestTo128IconRef
:
4899 CGImageRetain(imageRef
);
4900 CGImageRelease(biggestIconRef
);
4901 if (closestTo128IconRef
)
4902 CGImageRelease(closestTo128IconRef
);
4903 destRef
= CGImageDestinationCreateWithURL(outUrl
, kUTTypePNG
, 1,
4907 if (CGImageGetWidth(imageRef
) != 128)
4909 bytesPerRow
= CGImageGetBytesPerRow(imageRef
) /
4910 CGImageGetWidth(imageRef
) * 128;
4911 context
= CGBitmapContextCreate(NULL
, 128, 128,
4912 CGImageGetBitsPerComponent(imageRef
),
4914 CGImageGetColorSpace(imageRef
),
4915 kCGImageAlphaPremultipliedFirst
);
4918 CGContextDrawImage(context
, CGRectMake(0, 0, 128, 128),
4920 CGImageRelease(imageRef
);
4921 imageRef
= CGBitmapContextCreateImage(context
);
4922 CGContextRelease(context
);
4926 CGImageDestinationAddImage(destRef
, imageRef
, NULL
);
4927 CGImageDestinationFinalize(destRef
);
4931 CGImageRelease(imageRef
);
4934 CFRelease(sourceRef
);
4942 CFRelease(icnsFileUrl
);
4944 #endif /* HAVE_APPLICATIONSERVICES_H */
4947 * Close the PPD and set the type...
4952 else if (!access(ppd_name
, 0))
4954 int pline
; /* PPD line number */
4955 ppd_status_t pstatus
; /* PPD load status */
4958 pstatus
= ppdLastError(&pline
);
4960 cupsdLogMessage(CUPSD_LOG_ERROR
, "PPD file for %s cannot be loaded!",
4963 if (pstatus
<= PPD_ALLOC_ERROR
)
4964 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s", strerror(errno
));
4966 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s on line %d.",
4967 ppdErrorString(pstatus
), pline
);
4969 cupsdLogMessage(CUPSD_LOG_INFO
,
4970 "Hint: Run \"cupstestppd %s\" and fix any errors.",
4976 * If we have an interface script, add a filter entry for it...
4979 char interface
[1024]; /* Interface script */
4982 snprintf(interface
, sizeof(interface
), "%s/interfaces/%s", ServerRoot
,
4984 if (!access(interface
, X_OK
))
4987 * Yes, we have a System V style interface script; use it!
4990 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
4991 "printer-make-and-model", NULL
,
4992 "Local System V Printer");
4994 else if (!strncmp(p
->device_uri
, "ipp://", 6) &&
4995 (strstr(p
->device_uri
, "/printers/") != NULL
||
4996 strstr(p
->device_uri
, "/classes/") != NULL
||
4997 (strstr(p
->device_uri
, "._ipp.") != NULL
&&
4998 !strcmp(p
->device_uri
+ strlen(p
->device_uri
) - 5,
5002 * Tell the client this is really a hard-wired remote printer.
5005 p
->type
|= CUPS_PRINTER_REMOTE
;
5008 * Point the printer-uri-supported attribute to the
5012 if (strchr(p
->device_uri
, '?'))
5015 * Strip trailing "?options" from URI...
5018 char resource
[HTTP_MAX_URI
], /* New URI */
5019 *ptr
; /* Pointer into URI */
5021 strlcpy(resource
, p
->device_uri
, sizeof(resource
));
5022 if ((ptr
= strchr(resource
, '?')) != NULL
)
5025 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
5026 "printer-uri-supported", NULL
, resource
);
5029 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
5030 "printer-uri-supported", NULL
, p
->device_uri
);
5033 * Then set the make-and-model accordingly...
5036 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
5037 "printer-make-and-model", NULL
, "Remote Printer");
5040 * Print all files directly...
5049 * Otherwise we have neither - treat this as a "dumb" printer
5050 * with no PPD file...
5053 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
5054 "printer-make-and-model", NULL
, "Local Raw Printer");
5060 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
5061 "finishings-supported", num_finishings
, finishings
);
5062 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
5063 "finishings-default", IPP_FINISHINGS_NONE
);
5068 * Save cached PPD attributes to disk...
5071 cupsdLogMessage(CUPSD_LOG_DEBUG
, "load_ppd: Saving %s...", cache_name
);
5073 _ppdCacheWriteFile(p
->pc
, cache_name
, p
->ppd_attrs
);
5078 * Remove cache files...
5081 if (cache_info
.st_mtime
)
5088 * 'new_media_col()' - Create a media-col collection value.
5091 static ipp_t
* /* O - Collection value */
5092 new_media_col(_pwg_size_t
*size
, /* I - media-size/margin values */
5093 const char *source
, /* I - media-source value */
5094 const char *type
) /* I - media-type value */
5096 ipp_t
*media_col
, /* Collection value */
5097 *media_size
; /* media-size value */
5100 media_col
= ippNew();
5102 media_size
= ippNew();
5103 ippAddInteger(media_size
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5104 "x-dimension", size
->width
);
5105 ippAddInteger(media_size
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5106 "y-dimension", size
->length
);
5107 ippAddCollection(media_col
, IPP_TAG_PRINTER
, "media-size", media_size
);
5108 ippDelete(media_size
);
5110 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5111 "media-bottom-margin", size
->bottom
);
5112 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5113 "media-left-margin", size
->left
);
5114 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5115 "media-right-margin", size
->right
);
5116 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5117 "media-top-margin", size
->top
);
5120 ippAddString(media_col
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
, "media-source",
5124 ippAddString(media_col
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
, "media-type",
5133 * 'write_irix_config()' - Update the config files used by the IRIX
5138 write_irix_config(cupsd_printer_t
*p
) /* I - Printer to update */
5140 char filename
[1024]; /* Interface script filename */
5141 cups_file_t
*fp
; /* Interface script file */
5142 ipp_attribute_t
*attr
; /* Attribute data */
5146 * Add dummy interface and GUI scripts to fool SGI's "challenged" printing
5147 * tools. First the interface script that tells the tools what kind of
5148 * printer we have...
5151 snprintf(filename
, sizeof(filename
), "/var/spool/lp/interface/%s", p
->name
);
5153 if (p
->type
& CUPS_PRINTER_CLASS
)
5155 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
5157 cupsFilePuts(fp
, "#!/bin/sh\n");
5159 if ((attr
= ippFindAttribute(p
->attrs
, "printer-make-and-model",
5160 IPP_TAG_TEXT
)) != NULL
)
5161 cupsFilePrintf(fp
, "NAME=\"%s\"\n", attr
->values
[0].string
.text
);
5162 else if (p
->type
& CUPS_PRINTER_CLASS
)
5163 cupsFilePuts(fp
, "NAME=\"Printer Class\"\n");
5165 cupsFilePuts(fp
, "NAME=\"Remote Destination\"\n");
5167 if (p
->type
& CUPS_PRINTER_COLOR
)
5168 cupsFilePuts(fp
, "TYPE=ColorPostScript\n");
5170 cupsFilePuts(fp
, "TYPE=MonoPostScript\n");
5172 cupsFilePrintf(fp
, "HOSTNAME=%s\n", ServerName
);
5173 cupsFilePrintf(fp
, "HOSTPRINTER=%s\n", p
->name
);
5177 chmod(filename
, 0755);
5178 chown(filename
, User
, Group
);
5182 * Then the member file that tells which device file the queue is connected
5183 * to... Networked printers use "/dev/null" in this file, so that's what
5184 * we use (the actual device URI can confuse some apps...)
5187 snprintf(filename
, sizeof(filename
), "/var/spool/lp/member/%s", p
->name
);
5189 if (p
->type
& CUPS_PRINTER_CLASS
)
5191 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
5193 cupsFilePuts(fp
, "/dev/null\n");
5197 chmod(filename
, 0644);
5198 chown(filename
, User
, Group
);
5202 * The gui_interface file is a script or program that launches a GUI
5203 * option panel for the printer, using options specified on the
5204 * command-line in the third argument. The option panel must send
5205 * any printing options to stdout on a single line when the user
5206 * accepts them, or nothing if the user cancels the dialog.
5208 * The default options panel program is /usr/bin/glpoptions, from
5209 * the ESP Print Pro software. You can select another using the
5210 * PrintcapGUI option.
5213 snprintf(filename
, sizeof(filename
), "/var/spool/lp/gui_interface/ELF/%s.gui", p
->name
);
5215 if (p
->type
& CUPS_PRINTER_CLASS
)
5217 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
5219 cupsFilePuts(fp
, "#!/bin/sh\n");
5220 cupsFilePrintf(fp
, "%s -d %s -o \"$3\"\n", PrintcapGUI
, p
->name
);
5224 chmod(filename
, 0755);
5225 chown(filename
, User
, Group
);
5229 * The POD config file is needed by the printstatus command to show
5230 * the printer location and device.
5233 snprintf(filename
, sizeof(filename
), "/var/spool/lp/pod/%s.config", p
->name
);
5235 if (p
->type
& CUPS_PRINTER_CLASS
)
5237 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
5239 cupsFilePrintf(fp
, "Printer Class | %s\n",
5240 (p
->type
& CUPS_PRINTER_COLOR
) ? "ColorPostScript" : "MonoPostScript");
5241 cupsFilePrintf(fp
, "Printer Model | %s\n", p
->make_model
? p
->make_model
: "");
5242 cupsFilePrintf(fp
, "Location Code | %s\n", p
->location
? p
->location
: "");
5243 cupsFilePrintf(fp
, "Physical Location | %s\n", p
->info
? p
->info
: "");
5244 cupsFilePrintf(fp
, "Port Path | %s\n", p
->device_uri
);
5245 cupsFilePrintf(fp
, "Config Path | /var/spool/lp/pod/%s.config\n", p
->name
);
5246 cupsFilePrintf(fp
, "Active Status Path | /var/spool/lp/pod/%s.status\n", p
->name
);
5247 cupsFilePuts(fp
, "Status Update Wait | 10 seconds\n");
5251 chmod(filename
, 0664);
5252 chown(filename
, User
, Group
);
5258 * 'write_irix_state()' - Update the status files used by IRIX printing
5263 write_irix_state(cupsd_printer_t
*p
) /* I - Printer to update */
5265 char filename
[1024]; /* Interface script filename */
5266 cups_file_t
*fp
; /* Interface script file */
5267 int tag
; /* Status tag value */
5273 * The POD status file is needed for the printstatus window to
5274 * provide the current status of the printer.
5277 snprintf(filename
, sizeof(filename
), "/var/spool/lp/pod/%s.status", p
->name
);
5279 if (p
->type
& CUPS_PRINTER_CLASS
)
5281 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
5283 cupsFilePrintf(fp
, "Operational Status | %s\n",
5284 (p
->state
== IPP_PRINTER_IDLE
) ? "Idle" :
5285 (p
->state
== IPP_PRINTER_PROCESSING
) ? "Busy" :
5287 cupsFilePrintf(fp
, "Information | 01 00 00 | %s\n", CUPS_SVERSION
);
5288 cupsFilePrintf(fp
, "Information | 02 00 00 | Device URI: %s\n",
5290 cupsFilePrintf(fp
, "Information | 03 00 00 | %s jobs\n",
5291 p
->accepting
? "Accepting" : "Not accepting");
5292 cupsFilePrintf(fp
, "Information | 04 00 00 | %s\n", p
->state_message
);
5296 chmod(filename
, 0664);
5297 chown(filename
, User
, Group
);
5301 * The activeicons file is needed to provide desktop icons for printers:
5303 * [ quoted from /usr/lib/print/tagit ]
5305 * --- Type of printer tags (base values)
5307 * Dumb=66048 # 0x10200
5308 * DumbColor=66080 # 0x10220
5309 * Raster=66112 # 0x10240
5310 * ColorRaster=66144 # 0x10260
5311 * Plotter=66176 # 0x10280
5312 * PostScript=66208 # 0x102A0
5313 * ColorPostScript=66240 # 0x102C0
5314 * MonoPostScript=66272 # 0x102E0
5316 * --- Printer state modifiers for local printers
5321 * Unknown=3 # 0x3 (Faulted due to unknown reason)
5323 * --- Printer state modifiers for network printers
5327 * NetFaulted=10 # 0xA
5328 * NetUnknown=11 # 0xB (Faulted due to unknown reason)
5331 snprintf(filename
, sizeof(filename
), "/var/spool/lp/activeicons/%s", p
->name
);
5333 if (p
->type
& CUPS_PRINTER_CLASS
)
5335 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
5337 if (p
->type
& CUPS_PRINTER_COLOR
)
5342 if (p
->type
& CUPS_PRINTER_REMOTE
)
5345 if (p
->state
== IPP_PRINTER_PROCESSING
)
5348 else if (p
->state
== IPP_PRINTER_STOPPED
)
5351 cupsFilePuts(fp
, "#!/bin/sh\n");
5352 cupsFilePrintf(fp
, "#Tag %d\n", tag
);
5356 chmod(filename
, 0755);
5357 chown(filename
, User
, Group
);
5362 * The default file is needed by the printers window to show
5363 * the default printer.
5366 snprintf(filename
, sizeof(filename
), "/var/spool/lp/default");
5368 if (DefaultPrinter
!= NULL
)
5370 if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
5372 cupsFilePrintf(fp
, "%s\n", DefaultPrinter
->name
);
5376 chmod(filename
, 0644);
5377 chown(filename
, User
, Group
);
5387 * 'write_xml_string()' - Write a string with XML escaping.
5391 write_xml_string(cups_file_t
*fp
, /* I - File to write to */
5392 const char *s
) /* I - String to write */
5394 const char *start
; /* Start of current sequence */
5400 for (start
= s
; *s
; s
++)
5405 cupsFileWrite(fp
, start
, s
- start
);
5407 cupsFilePuts(fp
, "&");
5413 cupsFileWrite(fp
, start
, s
- start
);
5415 cupsFilePuts(fp
, "<");
5421 cupsFilePuts(fp
, start
);
5426 * End of "$Id: printers.c 7968 2008-09-19 23:03:01Z mike $".