2 * "$Id: printers.c 7968 2008-09-19 23:03:01Z mike $"
4 * Printer routines for the CUPS scheduler.
6 * Copyright 2007-2010 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 * cupsdAddPrinterHistory() - Add the current printer state to the history.
19 * cupsdAddPrinterUser() - Add a user to the ACL.
20 * cupsdCreateCommonData() - Create the common printer data.
21 * cupsdDeleteAllPrinters() - Delete all printers from the system.
22 * cupsdDeletePrinter() - Delete a printer from the system.
23 * cupsdFindDest() - Find a destination in the list.
24 * cupsdFindPrinter() - Find a printer in the list.
25 * cupsdFreePrinterUsers() - Free allow/deny users.
26 * cupsdLoadAllPrinters() - Load printers from the printers.conf file.
27 * cupsdRenamePrinter() - Rename a printer.
28 * cupsdSaveAllPrinters() - Save all printer definitions to the
30 * cupsdSetAuthInfoRequired() - Set the required authentication info.
31 * cupsdSetDeviceURI() - Set the device URI for a printer.
32 * cupsdSetPrinterAttr() - Set a printer attribute.
33 * cupsdSetPrinterAttrs() - Set printer attributes based upon the PPD
35 * cupsdSetPrinterReasons() - Set/update the reasons strings.
36 * cupsdSetPrinterState() - Update the current state of a printer.
37 * cupsdStopPrinter() - Stop a printer from printing any jobs...
38 * cupsdUpdatePrinterPPD() - Update keywords in a printer's PPD file.
39 * cupsdUpdatePrinters() - Update printers after a partial reload.
40 * cupsdValidateDest() - Validate a printer/class destination.
41 * cupsdWritePrintcap() - Write a pseudo-printcap file for older
42 * applications that need it...
43 * add_printer_defaults() - Add name-default attributes to the printer
45 * add_printer_filter() - Add a MIME filter for a printer.
46 * add_printer_formats() - Add document-format-supported values for a
48 * add_string_array() - Add a string to an array of CUPS strings.
49 * compare_printers() - Compare two printers.
50 * delete_printer_filters() - Delete all MIME filters for a printer.
51 * delete_string_array() - Delete an array of CUPS strings.
52 * load_ppd() - Load a cached PPD file, updating the cache as
54 * new_media_col() - Create a media-col collection value.
55 * write_irix_config() - Update the config files used by the IRIX
57 * write_irix_state() - Update the status files used by IRIX printing
59 * write_xml_string() - Write a string with XML escaping.
63 * Include necessary headers...
68 #ifdef HAVE_APPLICATIONSERVICES_H
69 # include <ApplicationServices/ApplicationServices.h>
70 #endif /* HAVE_APPLICATIONSERVICES_H */
71 #ifdef HAVE_SYS_MOUNT_H
72 # include <sys/mount.h>
73 #endif /* HAVE_SYS_MOUNT_H */
74 #ifdef HAVE_SYS_STATFS_H
75 # include <sys/statfs.h>
76 #endif /* HAVE_SYS_STATFS_H */
77 #ifdef HAVE_SYS_STATVFS_H
78 # include <sys/statvfs.h>
79 #endif /* HAVE_SYS_STATVFS_H */
82 #endif /* HAVE_SYS_VFS_H */
89 static void add_printer_defaults(cupsd_printer_t
*p
);
90 static void add_printer_filter(cupsd_printer_t
*p
, mime_type_t
*type
,
92 static void add_printer_formats(cupsd_printer_t
*p
);
93 static void add_string_array(cups_array_t
**a
, const char *s
);
94 static int compare_printers(void *first
, void *second
, void *data
);
95 static void delete_printer_filters(cupsd_printer_t
*p
);
96 static void delete_string_array(cups_array_t
**a
);
97 static void load_ppd(cupsd_printer_t
*p
);
98 static ipp_t
*new_media_col(_pwg_size_t
*size
, const char *source
,
101 static void write_irix_config(cupsd_printer_t
*p
);
102 static void write_irix_state(cupsd_printer_t
*p
);
104 static void write_xml_string(cups_file_t
*fp
, const char *s
);
108 * 'cupsdAddPrinter()' - Add a printer to the system.
111 cupsd_printer_t
* /* O - New printer */
112 cupsdAddPrinter(const char *name
) /* I - Name of printer */
114 cupsd_printer_t
*p
; /* New printer */
115 char uri
[1024]; /* Printer URI */
119 * Range check input...
122 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdAddPrinter(\"%s\")", name
);
125 * Create a new printer entity...
128 if ((p
= calloc(1, sizeof(cupsd_printer_t
))) == NULL
)
130 cupsdLogMessage(CUPSD_LOG_CRIT
, "Unable to allocate memory for printer - %s",
135 cupsdSetString(&p
->name
, name
);
136 cupsdSetString(&p
->info
, name
);
137 cupsdSetString(&p
->hostname
, ServerName
);
139 httpAssembleURIf(HTTP_URI_CODING_ALL
, uri
, sizeof(uri
), "ipp", NULL
,
140 ServerName
, RemotePort
, "/printers/%s", name
);
141 cupsdSetString(&p
->uri
, uri
);
142 cupsdSetDeviceURI(p
, "file:///dev/null");
144 p
->state
= IPP_PRINTER_STOPPED
;
145 p
->state_time
= time(NULL
);
147 p
->shared
= DefaultShared
;
148 p
->filetype
= mimeAddType(MimeDatabase
, "printer", name
);
150 cupsdSetString(&p
->job_sheets
[0], "none");
151 cupsdSetString(&p
->job_sheets
[1], "none");
153 cupsdSetString(&p
->error_policy
, ErrorPolicy
);
154 cupsdSetString(&p
->op_policy
, DefaultPolicy
);
156 p
->op_policy_ptr
= DefaultPolicyPtr
;
158 if (MaxPrinterHistory
)
159 p
->history
= calloc(MaxPrinterHistory
, sizeof(ipp_t
*));
162 * Insert the printer in the printer list alphabetically...
166 Printers
= cupsArrayNew(compare_printers
, NULL
);
168 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
169 "cupsdAddPrinter: Adding %s to Printers", p
->name
);
170 cupsArrayAdd(Printers
, p
);
172 if (!ImplicitPrinters
)
173 ImplicitPrinters
= cupsArrayNew(compare_printers
, NULL
);
176 * Return the new printer...
184 * 'cupsdAddPrinterHistory()' - Add the current printer state to the history.
188 cupsdAddPrinterHistory(
189 cupsd_printer_t
*p
) /* I - Printer */
191 ipp_t
*history
; /* History collection */
195 * Stop early if we aren't keeping history data...
198 if (MaxPrinterHistory
<= 0)
202 * Retire old history data as needed...
205 p
->sequence_number
++;
207 if (p
->num_history
>= MaxPrinterHistory
)
210 ippDelete(p
->history
[0]);
211 memmove(p
->history
, p
->history
+ 1, p
->num_history
* sizeof(ipp_t
*));
215 * Create a collection containing the current printer-state, printer-up-time,
216 * printer-state-message, and printer-state-reasons attributes.
220 ippAddInteger(history
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-state",
222 ippAddBoolean(history
, IPP_TAG_PRINTER
, "printer-is-accepting-jobs",
224 ippAddBoolean(history
, IPP_TAG_PRINTER
, "printer-is-shared", p
->shared
);
225 ippAddString(history
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-state-message",
226 NULL
, p
->state_message
);
227 if (p
->num_reasons
== 0)
228 ippAddString(history
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
229 "printer-state-reasons", NULL
, "none");
231 ippAddStrings(history
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
232 "printer-state-reasons", p
->num_reasons
, NULL
,
233 (const char * const *)p
->reasons
);
234 ippAddInteger(history
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
235 "printer-state-change-time", p
->state_time
);
236 ippAddInteger(history
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
237 "printer-state-sequence-number", p
->sequence_number
);
239 p
->history
[p
->num_history
] = history
;
245 * 'cupsdAddPrinterUser()' - Add a user to the ACL.
250 cupsd_printer_t
*p
, /* I - Printer */
251 const char *username
) /* I - User */
253 const char **temp
; /* Temporary array pointer */
259 if (p
->num_users
== 0)
260 temp
= malloc(sizeof(char **));
262 temp
= realloc(p
->users
, sizeof(char **) * (p
->num_users
+ 1));
268 temp
+= p
->num_users
;
270 if ((*temp
= strdup(username
)) != NULL
)
276 * 'cupsdCreateCommonData()' - Create the common printer data.
280 cupsdCreateCommonData(void)
282 int i
; /* Looping var */
283 ipp_attribute_t
*attr
; /* Attribute data */
284 cups_dir_t
*dir
; /* Notifier directory */
285 cups_dentry_t
*dent
; /* Notifier directory entry */
286 cups_array_t
*notifiers
; /* Notifier array */
287 char filename
[1024], /* Filename */
288 *notifier
; /* Current notifier */
289 cupsd_policy_t
*p
; /* Current policy */
290 int k_supported
; /* Maximum file size supported */
292 struct statfs spoolinfo
; /* FS info for spool directory */
293 double spoolsize
; /* FS size */
294 #elif defined(HAVE_STATVFS)
295 struct statvfs spoolinfo
; /* FS info for spool directory */
296 double spoolsize
; /* FS size */
297 #endif /* HAVE_STATFS */
298 static const int nups
[] = /* number-up-supported values */
299 { 1, 2, 4, 6, 9, 16 };
300 static const int orients
[4] =/* orientation-requested-supported values */
304 IPP_REVERSE_LANDSCAPE
,
307 static const char * const holds
[] = /* job-hold-until-supported values */
318 static const char * const versions
[] =/* ipp-versions-supported values */
325 static const int ops
[] = /* operations-supported values */
332 IPP_GET_JOB_ATTRIBUTES
,
334 IPP_GET_PRINTER_ATTRIBUTES
,
341 IPP_SET_PRINTER_ATTRIBUTES
,
342 IPP_SET_JOB_ATTRIBUTES
,
343 IPP_GET_PRINTER_SUPPORTED_VALUES
,
344 IPP_CREATE_PRINTER_SUBSCRIPTION
,
345 IPP_CREATE_JOB_SUBSCRIPTION
,
346 IPP_GET_SUBSCRIPTION_ATTRIBUTES
,
347 IPP_GET_SUBSCRIPTIONS
,
348 IPP_RENEW_SUBSCRIPTION
,
349 IPP_CANCEL_SUBSCRIPTION
,
350 IPP_GET_NOTIFICATIONS
,
354 IPP_RELEASE_HELD_NEW_JOBS
,
371 CUPS_AUTHENTICATE_JOB
,
376 static const char * const charsets
[] =/* charset-supported values */
381 static const char * const compressions
[] =
382 { /* document-compression-supported values */
386 #endif /* HAVE_LIBZ */
388 static const char * const media_col_supported
[] =
389 { /* media-col-supported values */
390 "media-bottom-margin",
392 "media-right-margin",
398 static const char * const multiple_document_handling
[] =
399 { /* multiple-document-handling-supported values */
400 "separate-documents-uncollated-copies",
401 "separate-documents-collated-copies"
403 static const char * const notify_attrs
[] =
404 { /* notify-attributes-supported values */
405 "printer-state-change-time",
406 "notify-lease-expiration-time",
407 "notify-subscriber-user-name"
409 static const char * const notify_events
[] =
410 { /* notify-events-supported values */
412 "job-config-changed",
419 "printer-config-changed",
421 "printer-finishings-changed",
422 "printer-media-changed",
426 "printer-state-changed",
433 static const char * const job_creation
[] =
434 { /* job-creation-attributes-supported */
437 "ipp-attribute-fidelity",
444 "multiple-document-handling",
448 "orientation-requested",
451 "printer-resolution",
454 static const char * const job_settable
[] =
455 { /* job-settable-attributes-supported */
463 "multiple-document-handling",
467 "orientation-requested",
470 "printer-resolution",
473 static const char * const printer_settable
[] =
474 { /* printer-settable-attributes-supported */
478 static const char * const which_jobs
[] =
479 { /* which-jobs-supported values */
493 ippDelete(CommonData
);
495 CommonData
= ippNew();
498 * Get the maximum spool size based on the size of the filesystem used for
499 * the RequestRoot directory. If the host OS doesn't support the statfs call
500 * or the filesystem is larger than 2TiB, always report INT_MAX.
504 if (statfs(RequestRoot
, &spoolinfo
))
505 k_supported
= INT_MAX
;
506 else if ((spoolsize
= (double)spoolinfo
.f_bsize
* spoolinfo
.f_blocks
/ 1024) >
508 k_supported
= INT_MAX
;
510 k_supported
= (int)spoolsize
;
512 #elif defined(HAVE_STATVFS)
513 if (statvfs(RequestRoot
, &spoolinfo
))
514 k_supported
= INT_MAX
;
515 else if ((spoolsize
= (double)spoolinfo
.f_frsize
* spoolinfo
.f_blocks
/ 1024) >
517 k_supported
= INT_MAX
;
519 k_supported
= (int)spoolsize
;
522 k_supported
= INT_MAX
;
523 #endif /* HAVE_STATFS */
526 * This list of attributes is sorted to improve performance when the
527 * client provides a requested-attributes attribute...
530 /* charset-configured */
531 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_CHARSET
| IPP_TAG_COPY
,
532 "charset-configured", NULL
, "utf-8");
534 /* charset-supported */
535 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_CHARSET
| IPP_TAG_COPY
,
536 "charset-supported", sizeof(charsets
) / sizeof(charsets
[0]),
539 /* compression-supported */
540 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
541 "compression-supported",
542 sizeof(compressions
) / sizeof(compressions
[0]),
545 /* copies-supported */
546 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "copies-supported", 1, MaxCopies
);
549 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
| IPP_TAG_COPY
,
550 "cups-version", NULL
, CUPS_SVERSION
+ 6);
552 /* generated-natural-language-supported (no IPP_TAG_COPY) */
553 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_LANGUAGE
,
554 "generated-natural-language-supported", NULL
, DefaultLanguage
);
556 /* ipp-versions-supported */
557 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
558 "ipp-versions-supported", sizeof(versions
) / sizeof(versions
[0]),
561 /* ippget-event-life */
562 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
563 "ippget-event-life", 15);
565 /* job-creation-attributes-supported */
566 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
567 "job-creation-attributes-supported",
568 sizeof(job_creation
) / sizeof(job_creation
[0]),
571 /* job-hold-until-supported */
572 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
573 "job-hold-until-supported", sizeof(holds
) / sizeof(holds
[0]),
576 /* job-ids-supported */
577 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
, "job-ids-supported", 1);
579 /* job-k-octets-supported */
580 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
581 "job-k-octets-supported", k_supported
);
583 /* job-priority-supported */
584 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
585 "job-priority-supported", 100);
587 /* job-settable-attributes-supported */
588 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
589 "job-settable-attributes-supported",
590 sizeof(job_settable
) / sizeof(job_settable
[0]),
593 /* job-sheets-supported */
594 if (cupsArrayCount(Banners
) > 0)
597 * Setup the job-sheets-supported attribute...
600 if (Classification
&& !ClassifyOverride
)
601 attr
= ippAddString(CommonData
, IPP_TAG_PRINTER
,
602 IPP_TAG_NAME
| IPP_TAG_COPY
,
603 "job-sheets-supported", NULL
, Classification
);
605 attr
= ippAddStrings(CommonData
, IPP_TAG_PRINTER
,
606 IPP_TAG_NAME
| IPP_TAG_COPY
,
607 "job-sheets-supported", cupsArrayCount(Banners
) + 1,
611 cupsdLogMessage(CUPSD_LOG_EMERG
,
612 "Unable to allocate memory for "
613 "job-sheets-supported attribute: %s!", strerror(errno
));
614 else if (!Classification
|| ClassifyOverride
)
616 cupsd_banner_t
*banner
; /* Current banner */
619 attr
->values
[0].string
.text
= _cupsStrAlloc("none");
621 for (i
= 1, banner
= (cupsd_banner_t
*)cupsArrayFirst(Banners
);
623 i
++, banner
= (cupsd_banner_t
*)cupsArrayNext(Banners
))
624 attr
->values
[i
].string
.text
= banner
->name
;
628 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
629 "job-sheets-supported", NULL
, "none");
631 /* media-col-supported */
632 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
633 "media-col-supported",
634 sizeof(media_col_supported
) /
635 sizeof(media_col_supported
[0]), NULL
,
636 media_col_supported
);
638 /* multiple-document-handling-supported */
639 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
640 "multiple-document-handling-supported",
641 sizeof(multiple_document_handling
) /
642 sizeof(multiple_document_handling
[0]), NULL
,
643 multiple_document_handling
);
645 /* multiple-document-jobs-supported */
646 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
,
647 "multiple-document-jobs-supported", 1);
649 /* multiple-operation-time-out */
650 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
651 "multiple-operation-time-out", MultipleOperationTimeout
);
653 /* natural-language-configured (no IPP_TAG_COPY) */
654 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_LANGUAGE
,
655 "natural-language-configured", NULL
, DefaultLanguage
);
657 /* notify-attributes-supported */
658 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
659 "notify-attributes-supported",
660 (int)(sizeof(notify_attrs
) / sizeof(notify_attrs
[0])),
663 /* notify-lease-duration-supported */
664 ippAddRange(CommonData
, IPP_TAG_PRINTER
,
665 "notify-lease-duration-supported", 0,
666 MaxLeaseDuration
? MaxLeaseDuration
: 2147483647);
668 /* notify-max-events-supported */
669 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
670 "notify-max-events-supported", MaxEvents
);
672 /* notify-events-supported */
673 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
674 "notify-events-supported",
675 (int)(sizeof(notify_events
) / sizeof(notify_events
[0])),
676 NULL
, notify_events
);
678 /* notify-pull-method-supported */
679 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
680 "notify-pull-method-supported", NULL
, "ippget");
682 /* notify-schemes-supported */
683 snprintf(filename
, sizeof(filename
), "%s/notifier", ServerBin
);
684 if ((dir
= cupsDirOpen(filename
)) != NULL
)
686 notifiers
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
688 while ((dent
= cupsDirRead(dir
)) != NULL
)
689 if (S_ISREG(dent
->fileinfo
.st_mode
) &&
690 (dent
->fileinfo
.st_mode
& S_IXOTH
) != 0)
691 cupsArrayAdd(notifiers
, _cupsStrAlloc(dent
->filename
));
693 if (cupsArrayCount(notifiers
) > 0)
695 attr
= ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
696 "notify-schemes-supported",
697 cupsArrayCount(notifiers
), NULL
, NULL
);
699 for (i
= 0, notifier
= (char *)cupsArrayFirst(notifiers
);
701 i
++, notifier
= (char *)cupsArrayNext(notifiers
))
702 attr
->values
[i
].string
.text
= notifier
;
705 cupsArrayDelete(notifiers
);
709 /* number-up-supported */
710 ippAddIntegers(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
711 "number-up-supported", sizeof(nups
) / sizeof(nups
[0]), nups
);
713 /* operations-supported */
714 ippAddIntegers(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
715 "operations-supported",
716 sizeof(ops
) / sizeof(ops
[0]) + JobFiles
- 1, ops
);
718 /* orientation-requested-supported */
719 ippAddIntegers(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
720 "orientation-requested-supported", 4, orients
);
722 /* page-ranges-supported */
723 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
, "page-ranges-supported", 1);
725 /* pdl-override-supported */
726 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
727 "pdl-override-supported", NULL
, "attempted");
729 /* printer-op-policy-supported */
730 attr
= ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
731 "printer-op-policy-supported", cupsArrayCount(Policies
),
733 for (i
= 0, p
= (cupsd_policy_t
*)cupsArrayFirst(Policies
);
735 i
++, p
= (cupsd_policy_t
*)cupsArrayNext(Policies
))
736 attr
->values
[i
].string
.text
= p
->name
;
738 /* printer-settable-attributes-supported */
739 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
740 "printer-settable-attributes-supported",
741 sizeof(printer_settable
) / sizeof(printer_settable
[0]),
742 NULL
, printer_settable
);
744 /* server-is-sharing-printers */
745 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
, "server-is-sharing-printers",
746 BrowseLocalProtocols
!= 0 && Browsing
);
748 /* which-jobs-supported */
749 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
750 "which-jobs-supported",
751 sizeof(which_jobs
) / sizeof(which_jobs
[0]), NULL
, which_jobs
);
756 * 'cupsdDeleteAllPrinters()' - Delete all printers from the system.
760 cupsdDeleteAllPrinters(void)
762 cupsd_printer_t
*p
; /* Pointer to current printer/class */
765 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
767 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
769 p
->op_policy_ptr
= DefaultPolicyPtr
;
770 cupsdDeletePrinter(p
, 0);
776 * 'cupsdDeletePrinter()' - Delete a printer from the system.
779 int /* O - 1 if classes affected, 0 otherwise */
781 cupsd_printer_t
*p
, /* I - Printer to delete */
782 int update
) /* I - Update printers.conf? */
784 int i
, /* Looping var */
785 changed
= 0; /* Class changed? */
787 char filename
[1024]; /* Interface script filename */
791 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdDeletePrinter(p=%p(%s), update=%d)",
795 * Save the current position in the Printers array...
798 cupsArraySave(Printers
);
801 * Stop printing on this printer...
804 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, update
);
807 cupsdSetJobState(p
->job
, IPP_JOB_PENDING
, CUPSD_JOB_FORCE
,
808 update
? "Job stopped due to printer being deleted." :
812 * If this printer is the next for browsing, point to the next one...
817 cupsArrayFind(Printers
, p
);
818 BrowseNext
= (cupsd_printer_t
*)cupsArrayNext(Printers
);
822 * Remove the printer from the list...
825 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
826 "cupsdDeletePrinter: Removing %s from Printers", p
->name
);
827 cupsArrayRemove(Printers
, p
);
829 if (p
->type
& CUPS_PRINTER_IMPLICIT
)
831 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
832 "cupsdDeletePrinter: Removing %s from ImplicitPrinters",
834 cupsArrayRemove(ImplicitPrinters
, p
);
838 * Remove the dummy interface/icon/option files under IRIX...
842 snprintf(filename
, sizeof(filename
), "/var/spool/lp/interface/%s", p
->name
);
845 snprintf(filename
, sizeof(filename
), "/var/spool/lp/gui_interface/ELF/%s.gui",
849 snprintf(filename
, sizeof(filename
), "/var/spool/lp/activeicons/%s", p
->name
);
852 snprintf(filename
, sizeof(filename
), "/var/spool/lp/pod/%s.config", p
->name
);
855 snprintf(filename
, sizeof(filename
), "/var/spool/lp/pod/%s.status", p
->name
);
858 snprintf(filename
, sizeof(filename
), "/var/spool/lp/member/%s", p
->name
);
863 * If p is the default printer, assign a different one...
866 if (p
== DefaultPrinter
)
868 DefaultPrinter
= NULL
;
870 if (UseNetworkDefault
)
873 * Find the first network default printer and use it...
876 cupsd_printer_t
*dp
; /* New default printer */
879 for (dp
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
881 dp
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
882 if (dp
!= p
&& (dp
->type
& CUPS_PRINTER_DEFAULT
))
891 * Remove this printer from any classes...
894 if (!(p
->type
& CUPS_PRINTER_IMPLICIT
))
896 changed
= cupsdDeletePrinterFromClasses(p
);
899 * Deregister from any browse protocols...
902 cupsdDeregisterPrinter(p
, 1);
906 * Free all memory used by the printer...
909 if (p
->printers
!= NULL
)
912 if (MaxPrinterHistory
)
914 for (i
= 0; i
< p
->num_history
; i
++)
915 ippDelete(p
->history
[i
]);
920 delete_printer_filters(p
);
922 for (i
= 0; i
< p
->num_reasons
; i
++)
923 _cupsStrFree(p
->reasons
[i
]);
926 ippDelete(p
->ppd_attrs
);
928 mimeDeleteType(MimeDatabase
, p
->filetype
);
929 mimeDeleteType(MimeDatabase
, p
->prefiltertype
);
931 delete_string_array(&(p
->filters
));
932 delete_string_array(&(p
->pre_filters
));
934 cupsdFreePrinterUsers(p
);
937 cupsdClearString(&p
->uri
);
938 cupsdClearString(&p
->hostname
);
939 cupsdClearString(&p
->name
);
940 cupsdClearString(&p
->location
);
941 cupsdClearString(&p
->make_model
);
942 cupsdClearString(&p
->info
);
943 cupsdClearString(&p
->job_sheets
[0]);
944 cupsdClearString(&p
->job_sheets
[1]);
945 cupsdClearString(&p
->device_uri
);
946 cupsdClearString(&p
->sanitized_device_uri
);
947 cupsdClearString(&p
->port_monitor
);
948 cupsdClearString(&p
->op_policy
);
949 cupsdClearString(&p
->error_policy
);
951 cupsdClearString(&p
->alert
);
952 cupsdClearString(&p
->alert_description
);
955 cupsdClearString(&p
->product
);
956 cupsdClearString(&p
->pdl
);
957 #endif /* HAVE_DNSSD */
959 cupsArrayDelete(p
->filetypes
);
962 free(p
->browse_attrs
);
964 cupsFreeOptions(p
->num_options
, p
->options
);
969 * Restore the previous position in the Printers array...
972 cupsArrayRestore(Printers
);
979 * 'cupsdFindDest()' - Find a destination in the list.
982 cupsd_printer_t
* /* O - Destination in list */
983 cupsdFindDest(const char *name
) /* I - Name of printer or class to find */
985 cupsd_printer_t key
; /* Search key */
988 key
.name
= (char *)name
;
989 return ((cupsd_printer_t
*)cupsArrayFind(Printers
, &key
));
994 * 'cupsdFindPrinter()' - Find a printer in the list.
997 cupsd_printer_t
* /* O - Printer in list */
998 cupsdFindPrinter(const char *name
) /* I - Name of printer to find */
1000 cupsd_printer_t
*p
; /* Printer in list */
1003 if ((p
= cupsdFindDest(name
)) != NULL
&& (p
->type
& CUPS_PRINTER_CLASS
))
1011 * 'cupsdFreePrinterUsers()' - Free allow/deny users.
1015 cupsdFreePrinterUsers(
1016 cupsd_printer_t
*p
) /* I - Printer */
1018 int i
; /* Looping var */
1021 if (!p
|| !p
->num_users
)
1024 for (i
= 0; i
< p
->num_users
; i
++)
1025 free((void *)p
->users
[i
]);
1035 * 'cupsdLoadAllPrinters()' - Load printers from the printers.conf file.
1039 cupsdLoadAllPrinters(void)
1041 int i
; /* Looping var */
1042 cups_file_t
*fp
; /* printers.conf file */
1043 int linenum
; /* Current line number */
1044 char line
[4096], /* Line from file */
1045 *value
, /* Pointer to value */
1046 *valueptr
; /* Pointer into value */
1047 cupsd_printer_t
*p
; /* Current printer */
1051 * Open the printers.conf file...
1054 snprintf(line
, sizeof(line
), "%s/printers.conf", ServerRoot
);
1055 if ((fp
= cupsFileOpen(line
, "r")) == NULL
)
1057 if (errno
!= ENOENT
)
1058 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to open %s - %s", line
,
1064 * Read printer configurations until we hit EOF...
1070 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
1073 * Decode the directive...
1076 if (!strcasecmp(line
, "<Printer") ||
1077 !strcasecmp(line
, "<DefaultPrinter"))
1080 * <Printer name> or <DefaultPrinter name>
1083 if (p
== NULL
&& value
)
1086 * Add the printer and a base file type...
1089 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Loading printer %s...", value
);
1091 p
= cupsdAddPrinter(value
);
1093 p
->state
= IPP_PRINTER_IDLE
;
1096 * Set the default printer as needed...
1099 if (!strcasecmp(line
, "<DefaultPrinter"))
1103 cupsdLogMessage(CUPSD_LOG_ERROR
,
1104 "Syntax error on line %d of printers.conf.", linenum
);
1106 else if (!strcasecmp(line
, "</Printer>"))
1111 * Close out the current printer...
1114 cupsdSetPrinterAttrs(p
);
1115 cupsdAddPrinterHistory(p
);
1117 if (strncmp(p
->device_uri
, "file:", 5) &&
1118 p
->state
!= IPP_PRINTER_STOPPED
)
1121 * See if the backend exists...
1124 snprintf(line
, sizeof(line
), "%s/backend/%s", ServerBin
,
1127 if ((valueptr
= strchr(line
+ strlen(ServerBin
), ':')) != NULL
)
1128 *valueptr
= '\0'; /* Chop everything but URI scheme */
1130 if (access(line
, 0))
1133 * Backend does not exist, stop printer...
1136 p
->state
= IPP_PRINTER_STOPPED
;
1137 snprintf(p
->state_message
, sizeof(p
->state_message
),
1138 "Backend %s does not exist!", line
);
1145 cupsdLogMessage(CUPSD_LOG_ERROR
,
1146 "Syntax error on line %d of printers.conf.", linenum
);
1150 cupsdLogMessage(CUPSD_LOG_ERROR
,
1151 "Syntax error on line %d of printers.conf.", linenum
);
1153 else if (!strcasecmp(line
, "AuthInfoRequired"))
1155 if (!cupsdSetAuthInfoRequired(p
, value
, NULL
))
1156 cupsdLogMessage(CUPSD_LOG_ERROR
,
1157 "Bad AuthInfoRequired on line %d of printers.conf.",
1160 else if (!strcasecmp(line
, "Info"))
1163 cupsdSetString(&p
->info
, value
);
1165 else if (!strcasecmp(line
, "MakeModel"))
1168 cupsdSetString(&p
->make_model
, value
);
1170 else if (!strcasecmp(line
, "Location"))
1173 cupsdSetString(&p
->location
, value
);
1175 else if (!strcasecmp(line
, "DeviceURI"))
1178 cupsdSetDeviceURI(p
, value
);
1180 cupsdLogMessage(CUPSD_LOG_ERROR
,
1181 "Syntax error on line %d of printers.conf.", linenum
);
1183 else if (!strcasecmp(line
, "Option") && value
)
1189 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1192 cupsdLogMessage(CUPSD_LOG_ERROR
,
1193 "Syntax error on line %d of printers.conf.", linenum
);
1196 for (; *valueptr
&& isspace(*valueptr
& 255); *valueptr
++ = '\0');
1198 p
->num_options
= cupsAddOption(value
, valueptr
, p
->num_options
,
1202 else if (!strcasecmp(line
, "PortMonitor"))
1204 if (value
&& strcmp(value
, "none"))
1205 cupsdSetString(&p
->port_monitor
, value
);
1207 cupsdClearString(&p
->port_monitor
);
1209 cupsdLogMessage(CUPSD_LOG_ERROR
,
1210 "Syntax error on line %d of printers.conf.", linenum
);
1212 else if (!strcasecmp(line
, "Reason"))
1215 strcmp(value
, "connecting-to-device") &&
1216 strcmp(value
, "cups-insecure-filter-warning") &&
1217 strcmp(value
, "cups-missing-filter-warning"))
1219 for (i
= 0 ; i
< p
->num_reasons
; i
++)
1220 if (!strcmp(value
, p
->reasons
[i
]))
1223 if (i
>= p
->num_reasons
&&
1224 p
->num_reasons
< (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
1226 p
->reasons
[p
->num_reasons
] = _cupsStrAlloc(value
);
1231 cupsdLogMessage(CUPSD_LOG_ERROR
,
1232 "Syntax error on line %d of printers.conf.", linenum
);
1234 else if (!strcasecmp(line
, "State"))
1237 * Set the initial queue state...
1240 if (value
&& !strcasecmp(value
, "idle"))
1241 p
->state
= IPP_PRINTER_IDLE
;
1242 else if (value
&& !strcasecmp(value
, "stopped"))
1244 p
->state
= IPP_PRINTER_STOPPED
;
1246 for (i
= 0 ; i
< p
->num_reasons
; i
++)
1247 if (!strcmp("paused", p
->reasons
[i
]))
1250 if (i
>= p
->num_reasons
&&
1251 p
->num_reasons
< (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
1253 p
->reasons
[p
->num_reasons
] = _cupsStrAlloc("paused");
1258 cupsdLogMessage(CUPSD_LOG_ERROR
,
1259 "Syntax error on line %d of printers.conf.", linenum
);
1261 else if (!strcasecmp(line
, "StateMessage"))
1264 * Set the initial queue state message...
1268 strlcpy(p
->state_message
, value
, sizeof(p
->state_message
));
1270 else if (!strcasecmp(line
, "StateTime"))
1273 * Set the state time...
1277 p
->state_time
= atoi(value
);
1279 else if (!strcasecmp(line
, "Accepting"))
1282 * Set the initial accepting state...
1286 (!strcasecmp(value
, "yes") ||
1287 !strcasecmp(value
, "on") ||
1288 !strcasecmp(value
, "true")))
1291 (!strcasecmp(value
, "no") ||
1292 !strcasecmp(value
, "off") ||
1293 !strcasecmp(value
, "false")))
1296 cupsdLogMessage(CUPSD_LOG_ERROR
,
1297 "Syntax error on line %d of printers.conf.", linenum
);
1299 else if (!strcasecmp(line
, "Type"))
1302 p
->type
= atoi(value
);
1304 cupsdLogMessage(CUPSD_LOG_ERROR
,
1305 "Syntax error on line %d of printers.conf.", linenum
);
1307 else if (!strcasecmp(line
, "Product"))
1312 p
->product
= _cupsStrAlloc(value
);
1313 #endif /* HAVE_DNSSD */
1316 cupsdLogMessage(CUPSD_LOG_ERROR
,
1317 "Syntax error on line %d of printers.conf.", linenum
);
1319 else if (!strcasecmp(line
, "Filter"))
1324 p
->filters
= cupsArrayNew(NULL
, NULL
);
1326 cupsArrayAdd(p
->filters
, _cupsStrAlloc(value
));
1329 cupsdLogMessage(CUPSD_LOG_ERROR
,
1330 "Syntax error on line %d of printers.conf.", linenum
);
1332 else if (!strcasecmp(line
, "PreFilter"))
1336 if (!p
->pre_filters
)
1337 p
->pre_filters
= cupsArrayNew(NULL
, NULL
);
1339 cupsArrayAdd(p
->pre_filters
, _cupsStrAlloc(value
));
1342 cupsdLogMessage(CUPSD_LOG_ERROR
,
1343 "Syntax error on line %d of printers.conf.", linenum
);
1345 else if (!strcasecmp(line
, "Shared"))
1348 * Set the initial shared state...
1352 (!strcasecmp(value
, "yes") ||
1353 !strcasecmp(value
, "on") ||
1354 !strcasecmp(value
, "true")))
1357 (!strcasecmp(value
, "no") ||
1358 !strcasecmp(value
, "off") ||
1359 !strcasecmp(value
, "false")))
1362 cupsdLogMessage(CUPSD_LOG_ERROR
,
1363 "Syntax error on line %d of printers.conf.", linenum
);
1365 else if (!strcasecmp(line
, "JobSheets"))
1368 * Set the initial job sheets...
1373 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1378 cupsdSetString(&p
->job_sheets
[0], value
);
1380 while (isspace(*valueptr
& 255))
1385 for (value
= valueptr
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1390 cupsdSetString(&p
->job_sheets
[1], value
);
1394 cupsdLogMessage(CUPSD_LOG_ERROR
,
1395 "Syntax error on line %d of printers.conf.", linenum
);
1397 else if (!strcasecmp(line
, "AllowUser"))
1402 cupsdAddPrinterUser(p
, value
);
1405 cupsdLogMessage(CUPSD_LOG_ERROR
,
1406 "Syntax error on line %d of printers.conf.", linenum
);
1408 else if (!strcasecmp(line
, "DenyUser"))
1413 cupsdAddPrinterUser(p
, value
);
1416 cupsdLogMessage(CUPSD_LOG_ERROR
,
1417 "Syntax error on line %d of printers.conf.", linenum
);
1419 else if (!strcasecmp(line
, "QuotaPeriod"))
1422 p
->quota_period
= atoi(value
);
1424 cupsdLogMessage(CUPSD_LOG_ERROR
,
1425 "Syntax error on line %d of printers.conf.", linenum
);
1427 else if (!strcasecmp(line
, "PageLimit"))
1430 p
->page_limit
= atoi(value
);
1432 cupsdLogMessage(CUPSD_LOG_ERROR
,
1433 "Syntax error on line %d of printers.conf.", linenum
);
1435 else if (!strcasecmp(line
, "KLimit"))
1438 p
->k_limit
= atoi(value
);
1440 cupsdLogMessage(CUPSD_LOG_ERROR
,
1441 "Syntax error on line %d of printers.conf.", linenum
);
1443 else if (!strcasecmp(line
, "OpPolicy"))
1447 cupsd_policy_t
*pol
; /* Policy */
1450 if ((pol
= cupsdFindPolicy(value
)) != NULL
)
1452 cupsdSetString(&p
->op_policy
, value
);
1453 p
->op_policy_ptr
= pol
;
1456 cupsdLogMessage(CUPSD_LOG_ERROR
,
1457 "Bad policy \"%s\" on line %d of printers.conf",
1461 cupsdLogMessage(CUPSD_LOG_ERROR
,
1462 "Syntax error on line %d of printers.conf.", linenum
);
1464 else if (!strcasecmp(line
, "ErrorPolicy"))
1467 cupsdSetString(&p
->error_policy
, value
);
1469 cupsdLogMessage(CUPSD_LOG_ERROR
,
1470 "Syntax error on line %d of printers.conf.", linenum
);
1472 else if (!strcasecmp(line
, "Attribute") && value
)
1474 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1477 cupsdLogMessage(CUPSD_LOG_ERROR
,
1478 "Syntax error on line %d of printers.conf.", linenum
);
1481 for (; *valueptr
&& isspace(*valueptr
& 255); *valueptr
++ = '\0');
1484 cupsdSetPrinterAttrs(p
);
1486 if (!strcmp(value
, "marker-change-time"))
1487 p
->marker_time
= atoi(valueptr
);
1489 cupsdSetPrinterAttr(p
, value
, valueptr
);
1495 * Something else we don't understand...
1498 cupsdLogMessage(CUPSD_LOG_ERROR
,
1499 "Unknown configuration directive %s on line %d of printers.conf.",
1509 * 'cupsdRenamePrinter()' - Rename a printer.
1514 cupsd_printer_t
*p
, /* I - Printer */
1515 const char *name
) /* I - New name */
1518 * Remove the printer from the array(s) first...
1521 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1522 "cupsdRenamePrinter: Removing %s from Printers", p
->name
);
1523 cupsArrayRemove(Printers
, p
);
1525 if (p
->type
& CUPS_PRINTER_IMPLICIT
)
1527 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1528 "cupsdRenamePrinter: Removing %s from ImplicitPrinters",
1530 cupsArrayRemove(ImplicitPrinters
, p
);
1534 * Rename the printer type...
1537 mimeDeleteType(MimeDatabase
, p
->filetype
);
1538 p
->filetype
= mimeAddType(MimeDatabase
, "printer", name
);
1540 mimeDeleteType(MimeDatabase
, p
->prefiltertype
);
1541 p
->prefiltertype
= mimeAddType(MimeDatabase
, "prefilter", name
);
1544 * Rename the printer...
1547 cupsdSetString(&p
->name
, name
);
1550 * Reset printer attributes...
1553 cupsdSetPrinterAttrs(p
);
1556 * Add the printer back to the printer array(s)...
1559 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1560 "cupsdRenamePrinter: Adding %s to Printers", p
->name
);
1561 cupsArrayAdd(Printers
, p
);
1563 if (p
->type
& CUPS_PRINTER_IMPLICIT
)
1565 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1566 "cupsdRenamePrinter: Adding %s to ImplicitPrinters",
1568 cupsArrayAdd(ImplicitPrinters
, p
);
1574 * 'cupsdSaveAllPrinters()' - Save all printer definitions to the printers.conf
1579 cupsdSaveAllPrinters(void)
1581 int i
; /* Looping var */
1582 cups_file_t
*fp
; /* printers.conf file */
1583 char temp
[1024], /* Temporary string */
1584 backup
[1024], /* printers.conf.O file */
1585 value
[2048], /* Value string */
1586 *ptr
; /* Pointer into value */
1587 cupsd_printer_t
*printer
; /* Current printer class */
1588 time_t curtime
; /* Current time */
1589 struct tm
*curdate
; /* Current date */
1590 cups_option_t
*option
; /* Current option */
1591 ipp_attribute_t
*marker
; /* Current marker attribute */
1595 * Create the printers.conf file...
1598 snprintf(temp
, sizeof(temp
), "%s/printers.conf", ServerRoot
);
1599 snprintf(backup
, sizeof(backup
), "%s/printers.conf.O", ServerRoot
);
1601 if (rename(temp
, backup
))
1603 if (errno
!= ENOENT
)
1604 cupsdLogMessage(CUPSD_LOG_ERROR
,
1605 "Unable to backup printers.conf - %s", strerror(errno
));
1608 if ((fp
= cupsFileOpen(temp
, "w")) == NULL
)
1610 cupsdLogMessage(CUPSD_LOG_ERROR
,
1611 "Unable to save printers.conf - %s", strerror(errno
));
1613 if (rename(backup
, temp
))
1614 cupsdLogMessage(CUPSD_LOG_ERROR
,
1615 "Unable to restore printers.conf - %s", strerror(errno
));
1619 cupsdLogMessage(CUPSD_LOG_INFO
, "Saving printers.conf...");
1622 * Restrict access to the file...
1625 fchown(cupsFileNumber(fp
), getuid(), Group
);
1626 fchmod(cupsFileNumber(fp
), ConfigFilePerm
& 0600);
1629 * Write a small header to the file...
1632 curtime
= time(NULL
);
1633 curdate
= localtime(&curtime
);
1634 strftime(temp
, sizeof(temp
) - 1, "%Y-%m-%d %H:%M", curdate
);
1636 cupsFilePuts(fp
, "# Printer configuration file for " CUPS_SVERSION
"\n");
1637 cupsFilePrintf(fp
, "# Written by cupsd on %s\n", temp
);
1638 cupsFilePuts(fp
, "# DO NOT EDIT THIS FILE WHEN CUPSD IS RUNNING\n");
1641 * Write each local printer known to the system...
1644 for (printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
1646 printer
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
1649 * Skip remote destinations and printer classes...
1652 if ((printer
->type
& CUPS_PRINTER_DISCOVERED
) ||
1653 (printer
->type
& CUPS_PRINTER_CLASS
) ||
1654 (printer
->type
& CUPS_PRINTER_IMPLICIT
))
1658 * Write printers as needed...
1661 if (printer
== DefaultPrinter
)
1662 cupsFilePrintf(fp
, "<DefaultPrinter %s>\n", printer
->name
);
1664 cupsFilePrintf(fp
, "<Printer %s>\n", printer
->name
);
1666 if (printer
->num_auth_info_required
> 0)
1668 switch (printer
->num_auth_info_required
)
1671 strlcpy(value
, printer
->auth_info_required
[0], sizeof(value
));
1675 snprintf(value
, sizeof(value
), "%s,%s",
1676 printer
->auth_info_required
[0],
1677 printer
->auth_info_required
[1]);
1682 snprintf(value
, sizeof(value
), "%s,%s,%s",
1683 printer
->auth_info_required
[0],
1684 printer
->auth_info_required
[1],
1685 printer
->auth_info_required
[2]);
1689 cupsFilePutConf(fp
, "AuthInfoRequired", value
);
1693 cupsFilePutConf(fp
, "Info", printer
->info
);
1695 if (printer
->location
)
1696 cupsFilePutConf(fp
, "Location", printer
->location
);
1698 if (printer
->make_model
)
1699 cupsFilePutConf(fp
, "MakeModel", printer
->make_model
);
1701 cupsFilePutConf(fp
, "DeviceURI", printer
->device_uri
);
1703 if (printer
->port_monitor
)
1704 cupsFilePutConf(fp
, "PortMonitor", printer
->port_monitor
);
1706 if (printer
->state
== IPP_PRINTER_STOPPED
)
1708 cupsFilePuts(fp
, "State Stopped\n");
1710 if (printer
->state_message
)
1711 cupsFilePutConf(fp
, "StateMessage", printer
->state_message
);
1714 cupsFilePuts(fp
, "State Idle\n");
1716 cupsFilePrintf(fp
, "StateTime %d\n", (int)printer
->state_time
);
1718 for (i
= 0; i
< printer
->num_reasons
; i
++)
1719 if (strcmp(printer
->reasons
[i
], "connecting-to-device") &&
1720 strcmp(printer
->reasons
[i
], "cups-insecure-filter-warning") &&
1721 strcmp(printer
->reasons
[i
], "cups-missing-filter-warning"))
1722 cupsFilePutConf(fp
, "Reason", printer
->reasons
[i
]);
1724 cupsFilePrintf(fp
, "Type %d\n", printer
->type
);
1727 if (printer
->product
)
1728 cupsFilePutConf(fp
, "Product", printer
->product
);
1729 #endif /* HAVE_DNSSD */
1731 for (ptr
= (char *)cupsArrayFirst(printer
->filters
);
1733 ptr
= (char *)cupsArrayNext(printer
->filters
))
1734 cupsFilePutConf(fp
, "Filter", ptr
);
1736 for (ptr
= (char *)cupsArrayFirst(printer
->pre_filters
);
1738 ptr
= (char *)cupsArrayNext(printer
->pre_filters
))
1739 cupsFilePutConf(fp
, "PreFilter", ptr
);
1741 if (printer
->accepting
)
1742 cupsFilePuts(fp
, "Accepting Yes\n");
1744 cupsFilePuts(fp
, "Accepting No\n");
1746 if (printer
->shared
)
1747 cupsFilePuts(fp
, "Shared Yes\n");
1749 cupsFilePuts(fp
, "Shared No\n");
1751 snprintf(value
, sizeof(value
), "%s %s", printer
->job_sheets
[0],
1752 printer
->job_sheets
[1]);
1753 cupsFilePutConf(fp
, "JobSheets", value
);
1755 cupsFilePrintf(fp
, "QuotaPeriod %d\n", printer
->quota_period
);
1756 cupsFilePrintf(fp
, "PageLimit %d\n", printer
->page_limit
);
1757 cupsFilePrintf(fp
, "KLimit %d\n", printer
->k_limit
);
1759 for (i
= 0; i
< printer
->num_users
; i
++)
1760 cupsFilePutConf(fp
, printer
->deny_users
? "DenyUser" : "AllowUser",
1763 if (printer
->op_policy
)
1764 cupsFilePutConf(fp
, "OpPolicy", printer
->op_policy
);
1765 if (printer
->error_policy
)
1766 cupsFilePutConf(fp
, "ErrorPolicy", printer
->error_policy
);
1768 for (i
= printer
->num_options
, option
= printer
->options
;
1772 snprintf(value
, sizeof(value
), "%s %s", option
->name
, option
->value
);
1773 cupsFilePutConf(fp
, "Option", value
);
1776 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-colors",
1777 IPP_TAG_NAME
)) != NULL
)
1779 snprintf(value
, sizeof(value
), "%s ", marker
->name
);
1781 for (i
= 0, ptr
= value
+ strlen(value
);
1782 i
< marker
->num_values
&& ptr
< (value
+ sizeof(value
) - 1);
1788 strlcpy(ptr
, marker
->values
[i
].string
.text
,
1789 value
+ sizeof(value
) - ptr
);
1794 cupsFilePutConf(fp
, "Attribute", value
);
1797 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-levels",
1798 IPP_TAG_INTEGER
)) != NULL
)
1800 cupsFilePrintf(fp
, "Attribute %s %d", marker
->name
,
1801 marker
->values
[0].integer
);
1802 for (i
= 1; i
< marker
->num_values
; i
++)
1803 cupsFilePrintf(fp
, ",%d", marker
->values
[i
].integer
);
1804 cupsFilePuts(fp
, "\n");
1807 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-low-levels",
1808 IPP_TAG_INTEGER
)) != NULL
)
1810 cupsFilePrintf(fp
, "Attribute %s %d", marker
->name
,
1811 marker
->values
[0].integer
);
1812 for (i
= 1; i
< marker
->num_values
; i
++)
1813 cupsFilePrintf(fp
, ",%d", marker
->values
[i
].integer
);
1814 cupsFilePuts(fp
, "\n");
1817 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-high-levels",
1818 IPP_TAG_INTEGER
)) != NULL
)
1820 cupsFilePrintf(fp
, "Attribute %s %d", marker
->name
,
1821 marker
->values
[0].integer
);
1822 for (i
= 1; i
< marker
->num_values
; i
++)
1823 cupsFilePrintf(fp
, ",%d", marker
->values
[i
].integer
);
1824 cupsFilePuts(fp
, "\n");
1827 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-message",
1828 IPP_TAG_TEXT
)) != NULL
)
1830 snprintf(value
, sizeof(value
), "%s %s", marker
->name
,
1831 marker
->values
[0].string
.text
);
1833 cupsFilePutConf(fp
, "Attribute", value
);
1836 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-names",
1837 IPP_TAG_NAME
)) != NULL
)
1839 snprintf(value
, sizeof(value
), "%s ", marker
->name
);
1841 for (i
= 0, ptr
= value
+ strlen(value
);
1842 i
< marker
->num_values
&& ptr
< (value
+ sizeof(value
) - 1);
1848 strlcpy(ptr
, marker
->values
[i
].string
.text
,
1849 value
+ sizeof(value
) - ptr
);
1854 cupsFilePutConf(fp
, "Attribute", value
);
1857 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-types",
1858 IPP_TAG_KEYWORD
)) != NULL
)
1860 snprintf(value
, sizeof(value
), "%s ", marker
->name
);
1862 for (i
= 0, ptr
= value
+ strlen(value
);
1863 i
< marker
->num_values
&& ptr
< (value
+ sizeof(value
) - 1);
1869 strlcpy(ptr
, marker
->values
[i
].string
.text
,
1870 value
+ sizeof(value
) - ptr
);
1875 cupsFilePutConf(fp
, "Attribute", value
);
1878 if (printer
->marker_time
)
1879 cupsFilePrintf(fp
, "Attribute marker-change-time %ld\n",
1880 (long)printer
->marker_time
);
1882 cupsFilePuts(fp
, "</Printer>\n");
1886 * Make IRIX desktop & printer status happy
1889 write_irix_state(printer
);
1898 * 'cupsdSetAuthInfoRequired()' - Set the required authentication info.
1901 int /* O - 1 if value OK, 0 otherwise */
1902 cupsdSetAuthInfoRequired(
1903 cupsd_printer_t
*p
, /* I - Printer */
1904 const char *values
, /* I - Plain text value (or NULL) */
1905 ipp_attribute_t
*attr
) /* I - IPP attribute value (or NULL) */
1907 int i
; /* Looping var */
1910 p
->num_auth_info_required
= 0;
1913 * Do we have a plain text value?
1919 * Yes, grab the keywords...
1922 const char *end
; /* End of current value */
1925 while (*values
&& p
->num_auth_info_required
< 4)
1927 if ((end
= strchr(values
, ',')) == NULL
)
1928 end
= values
+ strlen(values
);
1930 if ((end
- values
) == 4 && !strncmp(values
, "none", 4))
1932 if (p
->num_auth_info_required
!= 0 || *end
)
1935 p
->auth_info_required
[p
->num_auth_info_required
] = "none";
1936 p
->num_auth_info_required
++;
1940 else if ((end
- values
) == 9 && !strncmp(values
, "negotiate", 9))
1942 if (p
->num_auth_info_required
!= 0 || *end
)
1945 p
->auth_info_required
[p
->num_auth_info_required
] = "negotiate";
1946 p
->num_auth_info_required
++;
1948 else if ((end
- values
) == 6 && !strncmp(values
, "domain", 6))
1950 p
->auth_info_required
[p
->num_auth_info_required
] = "domain";
1951 p
->num_auth_info_required
++;
1953 else if ((end
- values
) == 8 && !strncmp(values
, "password", 8))
1955 p
->auth_info_required
[p
->num_auth_info_required
] = "password";
1956 p
->num_auth_info_required
++;
1958 else if ((end
- values
) == 8 && !strncmp(values
, "username", 8))
1960 p
->auth_info_required
[p
->num_auth_info_required
] = "username";
1961 p
->num_auth_info_required
++;
1966 values
= (*end
) ? end
+ 1 : end
;
1969 if (p
->num_auth_info_required
== 0)
1971 p
->auth_info_required
[0] = "none";
1972 p
->num_auth_info_required
= 1;
1976 * Update the printer-type value as needed...
1979 if (p
->num_auth_info_required
> 1 ||
1980 strcmp(p
->auth_info_required
[0], "none"))
1981 p
->type
|= CUPS_PRINTER_AUTHENTICATED
;
1983 p
->type
&= ~CUPS_PRINTER_AUTHENTICATED
;
1989 * Grab values from an attribute instead...
1992 if (!attr
|| attr
->num_values
> 4)
1996 * Update the printer-type value as needed...
1999 if (attr
->num_values
> 1 ||
2000 strcmp(attr
->values
[0].string
.text
, "none"))
2001 p
->type
|= CUPS_PRINTER_AUTHENTICATED
;
2003 p
->type
&= ~CUPS_PRINTER_AUTHENTICATED
;
2005 for (i
= 0; i
< attr
->num_values
; i
++)
2007 if (!strcmp(attr
->values
[i
].string
.text
, "none"))
2009 if (p
->num_auth_info_required
!= 0 || attr
->num_values
!= 1)
2012 p
->auth_info_required
[p
->num_auth_info_required
] = "none";
2013 p
->num_auth_info_required
++;
2017 else if (!strcmp(attr
->values
[i
].string
.text
, "negotiate"))
2019 if (p
->num_auth_info_required
!= 0 || attr
->num_values
!= 1)
2022 p
->auth_info_required
[p
->num_auth_info_required
] = "negotiate";
2023 p
->num_auth_info_required
++;
2027 else if (!strcmp(attr
->values
[i
].string
.text
, "domain"))
2029 p
->auth_info_required
[p
->num_auth_info_required
] = "domain";
2030 p
->num_auth_info_required
++;
2032 else if (!strcmp(attr
->values
[i
].string
.text
, "password"))
2034 p
->auth_info_required
[p
->num_auth_info_required
] = "password";
2035 p
->num_auth_info_required
++;
2037 else if (!strcmp(attr
->values
[i
].string
.text
, "username"))
2039 p
->auth_info_required
[p
->num_auth_info_required
] = "username";
2040 p
->num_auth_info_required
++;
2051 * 'cupsdSetDeviceURI()' - Set the device URI for a printer.
2055 cupsdSetDeviceURI(cupsd_printer_t
*p
, /* I - Printer */
2056 const char *uri
) /* I - Device URI */
2058 char buffer
[1024], /* URI buffer */
2059 *start
, /* Start of data after scheme */
2060 *slash
, /* First slash after scheme:// */
2061 *ptr
; /* Pointer into user@host:port part */
2065 * Set the full device URI..
2068 cupsdSetString(&(p
->device_uri
), uri
);
2071 * Copy the device URI to a temporary buffer so we can sanitize any auth
2075 strlcpy(buffer
, uri
, sizeof(buffer
));
2078 * Find the end of the scheme:// part...
2081 if ((ptr
= strchr(buffer
, ':')) != NULL
)
2083 for (start
= ptr
+ 1; *start
; start
++)
2088 * Find the next slash (/) in the URI...
2091 if ((slash
= strchr(start
, '/')) == NULL
)
2092 slash
= start
+ strlen(start
); /* No slash, point to the end */
2095 * Check for an @ sign before the slash...
2098 if ((ptr
= strchr(start
, '@')) != NULL
&& ptr
< slash
)
2101 * Found an @ sign and it is before the resource part, so we have
2102 * an authentication string. Copy the remaining URI over the
2103 * authentication string...
2106 _cups_strcpy(start
, ptr
+ 1);
2111 * Save the sanitized URI...
2114 cupsdSetString(&(p
->sanitized_device_uri
), buffer
);
2119 * 'cupsdSetPrinterAttr()' - Set a printer attribute.
2123 cupsdSetPrinterAttr(
2124 cupsd_printer_t
*p
, /* I - Printer */
2125 const char *name
, /* I - Attribute name */
2126 char *value
) /* I - Attribute value string */
2128 ipp_attribute_t
*attr
; /* Attribute */
2129 int i
, /* Looping var */
2130 count
; /* Number of values */
2131 char *ptr
; /* Pointer into value */
2132 ipp_tag_t value_tag
; /* Value tag for this attribute */
2136 * Don't allow empty values...
2139 if (!*value
&& strcmp(name
, "marker-message"))
2141 cupsdLogMessage(CUPSD_LOG_ERROR
, "Ignoring empty \"%s\" attribute", name
);
2146 * Count the number of values...
2149 for (count
= 1, ptr
= value
;
2150 (ptr
= strchr(ptr
, ',')) != NULL
;
2154 * Then add or update the attribute as needed...
2157 if (!strcmp(name
, "marker-levels") || !strcmp(name
, "marker-low-levels") ||
2158 !strcmp(name
, "marker-high-levels"))
2164 if ((attr
= ippFindAttribute(p
->attrs
, name
, IPP_TAG_INTEGER
)) != NULL
&&
2165 attr
->num_values
< count
)
2167 ippDeleteAttribute(p
->attrs
, attr
);
2172 attr
->num_values
= count
;
2174 attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
, name
,
2179 cupsdLogMessage(CUPSD_LOG_ERROR
,
2180 "Unable to allocate memory for printer attribute "
2181 "(%d values)", count
);
2185 for (i
= 0; i
< count
; i
++)
2187 if ((ptr
= strchr(value
, ',')) != NULL
)
2190 attr
->values
[i
].integer
= strtol(value
, NULL
, 10);
2199 * Name or keyword values...
2202 if (!strcmp(name
, "marker-types"))
2203 value_tag
= IPP_TAG_KEYWORD
;
2204 else if (!strcmp(name
, "marker-message"))
2205 value_tag
= IPP_TAG_TEXT
;
2207 value_tag
= IPP_TAG_NAME
;
2209 if ((attr
= ippFindAttribute(p
->attrs
, name
, value_tag
)) != NULL
&&
2210 attr
->num_values
< count
)
2212 ippDeleteAttribute(p
->attrs
, attr
);
2218 for (i
= 0; i
< attr
->num_values
; i
++)
2219 _cupsStrFree(attr
->values
[i
].string
.text
);
2221 attr
->num_values
= count
;
2224 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, value_tag
, name
,
2229 cupsdLogMessage(CUPSD_LOG_ERROR
,
2230 "Unable to allocate memory for printer attribute "
2231 "(%d values)", count
);
2235 for (i
= 0; i
< count
; i
++)
2237 if ((ptr
= strchr(value
, ',')) != NULL
)
2240 attr
->values
[i
].string
.text
= _cupsStrAlloc(value
);
2250 * 'cupsdSetPrinterAttrs()' - Set printer attributes based upon the PPD file.
2254 cupsdSetPrinterAttrs(cupsd_printer_t
*p
)/* I - Printer to setup */
2256 int i
, /* Looping var */
2257 length
; /* Length of browse attributes */
2258 char resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
2259 int num_air
; /* Number of auth-info-required values */
2260 const char * const *air
; /* auth-info-required values */
2261 cupsd_location_t
*auth
; /* Pointer to authentication element */
2262 const char *auth_supported
; /* Authentication supported */
2263 ipp_t
*oldattrs
; /* Old printer attributes */
2264 ipp_attribute_t
*attr
; /* Attribute data */
2265 cups_option_t
*option
; /* Current printer option */
2266 char *filter
; /* Current filter */
2267 static const char * const air_none
[] =
2268 { /* No authentication */
2271 static const char * const air_userpass
[] =
2272 { /* Basic/Digest authentication */
2278 DEBUG_printf(("cupsdSetPrinterAttrs: entering name = %s, type = %x\n", p
->name
,
2282 * Make sure that we have the common attributes defined...
2286 cupsdCreateCommonData();
2289 * Clear out old filters, if any...
2292 delete_printer_filters(p
);
2295 * Figure out the authentication that is required for the printer.
2298 auth_supported
= "requesting-user-name";
2302 if (p
->num_auth_info_required
> 0 && strcmp(p
->auth_info_required
[0], "none"))
2304 num_air
= p
->num_auth_info_required
;
2305 air
= p
->auth_info_required
;
2307 else if ((p
->type
& CUPS_PRINTER_AUTHENTICATED
) &&
2308 (p
->type
& CUPS_PRINTER_DISCOVERED
))
2314 if (p
->type
& CUPS_PRINTER_CLASS
)
2315 snprintf(resource
, sizeof(resource
), "/classes/%s", p
->name
);
2317 snprintf(resource
, sizeof(resource
), "/printers/%s", p
->name
);
2319 if ((auth
= cupsdFindBest(resource
, HTTP_POST
)) == NULL
||
2320 auth
->type
== CUPSD_AUTH_NONE
)
2321 auth
= cupsdFindPolicyOp(p
->op_policy_ptr
, IPP_PRINT_JOB
);
2325 int auth_type
; /* Authentication type */
2328 if ((auth_type
= auth
->type
) == CUPSD_AUTH_DEFAULT
)
2329 auth_type
= DefaultAuthType
;
2331 if (auth_type
== CUPSD_AUTH_BASIC
|| auth_type
== CUPSD_AUTH_BASICDIGEST
)
2332 auth_supported
= "basic";
2333 else if (auth_type
== CUPSD_AUTH_DIGEST
)
2334 auth_supported
= "digest";
2336 else if (auth_type
== CUPSD_AUTH_NEGOTIATE
)
2337 auth_supported
= "negotiate";
2338 #endif /* HAVE_GSSAPI */
2340 if (!(p
->type
& CUPS_PRINTER_DISCOVERED
))
2342 if (auth_type
!= CUPSD_AUTH_NONE
)
2343 p
->type
|= CUPS_PRINTER_AUTHENTICATED
;
2345 p
->type
&= ~CUPS_PRINTER_AUTHENTICATED
;
2348 else if (!(p
->type
& CUPS_PRINTER_DISCOVERED
))
2349 p
->type
&= ~CUPS_PRINTER_AUTHENTICATED
;
2352 * Create the required IPP attributes for a printer...
2355 oldattrs
= p
->attrs
;
2356 p
->attrs
= ippNew();
2358 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2359 "uri-authentication-supported", NULL
, auth_supported
);
2360 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2361 "uri-security-supported", NULL
, "none");
2362 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
, "printer-name", NULL
,
2364 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-location",
2365 NULL
, p
->location
? p
->location
: "");
2366 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-info",
2367 NULL
, p
->info
? p
->info
: "");
2372 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2373 "requesting-user-name-denied", p
->num_users
, NULL
,
2376 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2377 "requesting-user-name-allowed", p
->num_users
, NULL
,
2381 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2382 "job-quota-period", p
->quota_period
);
2383 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2384 "job-k-limit", p
->k_limit
);
2385 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2386 "job-page-limit", p
->page_limit
);
2387 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2388 "auth-info-required", num_air
, NULL
, air
);
2390 if (cupsArrayCount(Banners
) > 0 && !(p
->type
& CUPS_PRINTER_DISCOVERED
))
2393 * Setup the job-sheets-default attribute...
2396 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2397 "job-sheets-default", 2, NULL
, NULL
);
2401 attr
->values
[0].string
.text
= _cupsStrAlloc(Classification
?
2402 Classification
: p
->job_sheets
[0]);
2403 attr
->values
[1].string
.text
= _cupsStrAlloc(Classification
?
2404 Classification
: p
->job_sheets
[1]);
2411 if (p
->type
& CUPS_PRINTER_DISCOVERED
)
2414 * Tell the client this is a remote printer of some type...
2417 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
2418 "printer-uri-supported", NULL
, p
->uri
);
2420 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "printer-more-info",
2424 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
2425 "printer-make-and-model", NULL
, p
->make_model
);
2427 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "device-uri", NULL
,
2436 * Assign additional attributes depending on whether this is a printer
2440 if (p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
))
2443 p
->type
&= ~CUPS_PRINTER_OPTIONS
;
2446 * Add class-specific attributes...
2449 if ((p
->type
& CUPS_PRINTER_IMPLICIT
) && p
->num_printers
> 0 &&
2450 p
->printers
[0]->make_model
)
2451 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
2452 "printer-make-and-model", NULL
, p
->printers
[0]->make_model
);
2454 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
2455 "printer-make-and-model", NULL
, "Local Printer Class");
2457 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "device-uri", NULL
,
2458 "file:///dev/null");
2460 if (p
->num_printers
> 0)
2463 * Add a list of member names; URIs are added in copy_printer_attrs...
2466 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2467 "member-names", p
->num_printers
, NULL
, NULL
);
2468 p
->type
|= CUPS_PRINTER_OPTIONS
;
2470 for (i
= 0; i
< p
->num_printers
; i
++)
2473 attr
->values
[i
].string
.text
= _cupsStrRetain(p
->printers
[i
]->name
);
2475 p
->type
&= ~CUPS_PRINTER_OPTIONS
| p
->printers
[i
]->type
;
2482 * Add printer-specific attributes...
2485 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "device-uri", NULL
,
2486 p
->sanitized_device_uri
);
2489 * Assign additional attributes from the PPD file (if any)...
2495 * Add filters for printer...
2498 cupsdSetPrinterReasons(p
, "-cups-missing-filter-warning,"
2499 "cups-insecure-filter-warning");
2501 for (filter
= (char *)cupsArrayFirst(p
->filters
);
2503 filter
= (char *)cupsArrayNext(p
->filters
))
2504 add_printer_filter(p
, p
->filetype
, filter
);
2508 p
->prefiltertype
= mimeAddType(MimeDatabase
, "prefilter", p
->name
);
2510 for (filter
= (char *)cupsArrayFirst(p
->pre_filters
);
2512 filter
= (char *)cupsArrayNext(p
->pre_filters
))
2513 add_printer_filter(p
, p
->prefiltertype
, filter
);
2519 * Copy marker attributes as needed...
2524 ipp_attribute_t
*oldattr
; /* Old attribute */
2527 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-colors",
2528 IPP_TAG_NAME
)) != NULL
)
2530 if ((attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2531 "marker-colors", oldattr
->num_values
, NULL
,
2534 for (i
= 0; i
< oldattr
->num_values
; i
++)
2535 attr
->values
[i
].string
.text
=
2536 _cupsStrRetain(oldattr
->values
[i
].string
.text
);
2540 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-levels",
2541 IPP_TAG_INTEGER
)) != NULL
)
2543 if ((attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2544 "marker-levels", oldattr
->num_values
,
2547 for (i
= 0; i
< oldattr
->num_values
; i
++)
2548 attr
->values
[i
].integer
= oldattr
->values
[i
].integer
;
2552 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-message",
2553 IPP_TAG_TEXT
)) != NULL
)
2554 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "marker-message",
2555 NULL
, oldattr
->values
[0].string
.text
);
2557 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-low-levels",
2558 IPP_TAG_INTEGER
)) != NULL
)
2560 if ((attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2561 "marker-low-levels", oldattr
->num_values
,
2564 for (i
= 0; i
< oldattr
->num_values
; i
++)
2565 attr
->values
[i
].integer
= oldattr
->values
[i
].integer
;
2569 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-high-levels",
2570 IPP_TAG_INTEGER
)) != NULL
)
2572 if ((attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2573 "marker-high-levels", oldattr
->num_values
,
2576 for (i
= 0; i
< oldattr
->num_values
; i
++)
2577 attr
->values
[i
].integer
= oldattr
->values
[i
].integer
;
2581 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-names",
2582 IPP_TAG_NAME
)) != NULL
)
2584 if ((attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2585 "marker-names", oldattr
->num_values
, NULL
,
2588 for (i
= 0; i
< oldattr
->num_values
; i
++)
2589 attr
->values
[i
].string
.text
=
2590 _cupsStrRetain(oldattr
->values
[i
].string
.text
);
2594 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-types",
2595 IPP_TAG_KEYWORD
)) != NULL
)
2597 if ((attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2598 "marker-types", oldattr
->num_values
, NULL
,
2601 for (i
= 0; i
< oldattr
->num_values
; i
++)
2602 attr
->values
[i
].string
.text
=
2603 _cupsStrRetain(oldattr
->values
[i
].string
.text
);
2607 ippDelete(oldattrs
);
2611 * Force sharing off for remote queues...
2614 if (p
->type
& (CUPS_PRINTER_REMOTE
| CUPS_PRINTER_IMPLICIT
))
2619 * Copy the printer options into a browse attributes string we can re-use.
2622 const char *valptr
; /* Pointer into value */
2623 char *attrptr
; /* Pointer into attribute string */
2627 * Free the old browse attributes as needed...
2630 if (p
->browse_attrs
)
2631 free(p
->browse_attrs
);
2634 * Compute the length of all attributes + job-sheets, lease-duration,
2635 * and BrowseLocalOptions.
2638 for (length
= 1, i
= p
->num_options
, option
= p
->options
;
2642 length
+= strlen(option
->name
) + 2;
2646 for (valptr
= option
->value
; *valptr
; valptr
++)
2647 if (strchr(" \"\'\\", *valptr
))
2654 length
+= 13 + strlen(p
->job_sheets
[0]) + strlen(p
->job_sheets
[1]);
2656 if (BrowseLocalOptions
)
2657 length
+= 12 + strlen(BrowseLocalOptions
);
2660 * Allocate the new string...
2663 if ((p
->browse_attrs
= calloc(1, length
)) == NULL
)
2664 cupsdLogMessage(CUPSD_LOG_ERROR
,
2665 "Unable to allocate %d bytes for browse data!",
2670 * Got the allocated string, now copy the options and attributes over...
2673 sprintf(p
->browse_attrs
, "job-sheets=%s,%s lease-duration=%d",
2674 p
->job_sheets
[0], p
->job_sheets
[1], BrowseTimeout
);
2675 attrptr
= p
->browse_attrs
+ strlen(p
->browse_attrs
);
2677 if (BrowseLocalOptions
)
2679 sprintf(attrptr
, " ipp-options=%s", BrowseLocalOptions
);
2680 attrptr
+= strlen(attrptr
);
2683 for (i
= p
->num_options
, option
= p
->options
;
2688 strcpy(attrptr
, option
->name
);
2689 attrptr
+= strlen(attrptr
);
2695 for (valptr
= option
->value
; *valptr
; valptr
++)
2697 if (strchr(" \"\'\\", *valptr
))
2700 *attrptr
++ = *valptr
;
2708 * Populate the document-format-supported attribute...
2711 add_printer_formats(p
);
2713 DEBUG_printf(("cupsdSetPrinterAttrs: leaving name = %s, type = %x\n", p
->name
,
2717 * Add name-default attributes...
2720 add_printer_defaults(p
);
2724 * Write the IRIX printer config and status files...
2727 write_irix_config(p
);
2728 write_irix_state(p
);
2732 * Let the browse protocols reflect the change
2735 cupsdRegisterPrinter(p
);
2740 * 'cupsdSetPrinterReasons()' - Set/update the reasons strings.
2743 int /* O - 1 if something changed, 0 otherwise */
2744 cupsdSetPrinterReasons(
2745 cupsd_printer_t
*p
, /* I - Printer */
2746 const char *s
) /* I - Reasons strings */
2748 int i
, /* Looping var */
2749 changed
= 0; /* Did something change? */
2750 const char *sptr
; /* Pointer into reasons */
2751 char reason
[255], /* Reason string */
2752 *rptr
; /* Pointer into reason */
2755 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
2756 "cupsdSetPrinterReasons(p=%p(%s),s=\"%s\"", p
, p
->name
, s
);
2758 if (s
[0] == '-' || s
[0] == '+')
2761 * Add/remove reasons...
2769 * Replace reasons...
2774 for (i
= 0; i
< p
->num_reasons
; i
++)
2775 _cupsStrFree(p
->reasons
[i
]);
2780 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
2782 if (PrintcapFormat
== PRINTCAP_PLIST
)
2783 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
2786 if (!strcmp(s
, "none"))
2790 * Loop through all of the reasons...
2796 * Skip leading whitespace and commas...
2799 while (isspace(*sptr
& 255) || *sptr
== ',')
2802 for (rptr
= reason
; *sptr
&& !isspace(*sptr
& 255) && *sptr
!= ','; sptr
++)
2803 if (rptr
< (reason
+ sizeof(reason
) - 1))
2817 for (i
= 0; i
< p
->num_reasons
; i
++)
2818 if (!strcmp(reason
, p
->reasons
[i
]))
2821 * Found a match, so remove it...
2826 _cupsStrFree(p
->reasons
[i
]);
2828 if (i
< p
->num_reasons
)
2829 memmove(p
->reasons
+ i
, p
->reasons
+ i
+ 1,
2830 (p
->num_reasons
- i
) * sizeof(char *));
2832 if (!strcmp(reason
, "paused") && p
->state
== IPP_PRINTER_STOPPED
)
2833 cupsdSetPrinterState(p
, IPP_PRINTER_IDLE
, 1);
2835 if (strcmp(reason
, "connecting-to-device"))
2837 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
2839 if (PrintcapFormat
== PRINTCAP_PLIST
)
2840 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
2845 else if (p
->num_reasons
< (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
2851 for (i
= 0; i
< p
->num_reasons
; i
++)
2852 if (!strcmp(reason
, p
->reasons
[i
]))
2855 if (i
>= p
->num_reasons
)
2857 if (i
>= (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
2859 cupsdLogMessage(CUPSD_LOG_ALERT
,
2860 "Too many printer-state-reasons values for %s (%d)",
2865 p
->reasons
[i
] = _cupsStrAlloc(reason
);
2869 if (!strcmp(reason
, "paused") && p
->state
!= IPP_PRINTER_STOPPED
)
2870 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, 1);
2872 if (strcmp(reason
, "connecting-to-device"))
2874 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
2876 if (PrintcapFormat
== PRINTCAP_PLIST
)
2877 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
2888 * 'cupsdSetPrinterState()' - Update the current state of a printer.
2892 cupsdSetPrinterState(
2893 cupsd_printer_t
*p
, /* I - Printer to change */
2894 ipp_pstate_t s
, /* I - New state */
2895 int update
) /* I - Update printers.conf? */
2897 ipp_pstate_t old_state
; /* Old printer state */
2898 static const char * const printer_states
[] =
2899 { /* State strings */
2907 * Can't set status of remote printers...
2910 if (p
->type
& CUPS_PRINTER_DISCOVERED
)
2914 * Set the new state...
2917 if (PrintcapFormat
== PRINTCAP_PLIST
)
2918 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
2920 old_state
= p
->state
;
2925 cupsdAddEvent(s
== IPP_PRINTER_STOPPED
? CUPSD_EVENT_PRINTER_STOPPED
:
2926 CUPSD_EVENT_PRINTER_STATE
, p
, NULL
,
2927 "%s \"%s\" state changed to %s.",
2928 (p
->type
& CUPS_PRINTER_CLASS
) ? "Class" : "Printer",
2929 p
->name
, printer_states
[p
->state
]);
2932 * Let the browse code know this needs to be updated...
2936 p
->state_time
= time(NULL
);
2940 write_irix_state(p
);
2945 * Set/clear the paused reason as needed...
2948 if (s
== IPP_PRINTER_STOPPED
)
2949 cupsdSetPrinterReasons(p
, "+paused");
2951 cupsdSetPrinterReasons(p
, "-paused");
2954 * Clear the message for the queue when going to processing...
2957 if (s
== IPP_PRINTER_PROCESSING
)
2958 p
->state_message
[0] = '\0';
2961 * Update the printer history...
2964 cupsdAddPrinterHistory(p
);
2967 * Let the browse protocols reflect the change...
2971 cupsdRegisterPrinter(p
);
2974 * Save the printer configuration if a printer goes from idle or processing
2975 * to stopped (or visa-versa)...
2979 (old_state
== IPP_PRINTER_STOPPED
) != (s
== IPP_PRINTER_STOPPED
))
2981 if (p
->type
& CUPS_PRINTER_CLASS
)
2982 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
2984 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
2990 * 'cupsdStopPrinter()' - Stop a printer from printing any jobs...
2994 cupsdStopPrinter(cupsd_printer_t
*p
, /* I - Printer to stop */
2995 int update
)/* I - Update printers.conf? */
2998 * Set the printer state...
3001 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, update
);
3004 * See if we have a job printing on this printer...
3007 if (p
->job
&& p
->job
->state_value
== IPP_JOB_PROCESSING
)
3008 cupsdSetJobState(p
->job
, IPP_JOB_PENDING
, CUPSD_JOB_DEFAULT
,
3009 "Job stopped due to printer being paused.");
3014 * 'cupsdUpdatePrinterPPD()' - Update keywords in a printer's PPD file.
3017 int /* O - 1 if successful, 0 otherwise */
3018 cupsdUpdatePrinterPPD(
3019 cupsd_printer_t
*p
, /* I - Printer */
3020 int num_keywords
, /* I - Number of keywords */
3021 cups_option_t
*keywords
) /* I - Keywords */
3023 int i
; /* Looping var */
3024 cups_file_t
*src
, /* Original file */
3025 *dst
; /* New file */
3026 char srcfile
[1024], /* Original filename */
3027 dstfile
[1024], /* New filename */
3028 line
[1024], /* Line from file */
3029 keystring
[41]; /* Keyword from line */
3030 cups_option_t
*keyword
; /* Current keyword */
3033 cupsdLogMessage(CUPSD_LOG_INFO
, "Updating keywords in PPD file for %s...",
3037 * Get the old and new PPD filenames...
3040 snprintf(srcfile
, sizeof(srcfile
), "%s/ppd/%s.ppd.O", ServerRoot
, p
->name
);
3041 snprintf(dstfile
, sizeof(srcfile
), "%s/ppd/%s.ppd", ServerRoot
, p
->name
);
3044 * Rename the old file and open the old and new...
3047 if (rename(dstfile
, srcfile
))
3049 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to backup PPD file for %s: %s",
3050 p
->name
, strerror(errno
));
3054 if ((src
= cupsFileOpen(srcfile
, "r")) == NULL
)
3056 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to open PPD file \"%s\": %s",
3057 srcfile
, strerror(errno
));
3058 rename(srcfile
, dstfile
);
3062 if ((dst
= cupsFileOpen(dstfile
, "w")) == NULL
)
3064 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to create PPD file \"%s\": %s",
3065 dstfile
, strerror(errno
));
3067 rename(srcfile
, dstfile
);
3072 * Copy the first line and then write out all of the keywords...
3075 if (!cupsFileGets(src
, line
, sizeof(line
)))
3077 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to read PPD file \"%s\": %s",
3078 srcfile
, strerror(errno
));
3081 rename(srcfile
, dstfile
);
3085 cupsFilePrintf(dst
, "%s\n", line
);
3087 for (i
= num_keywords
, keyword
= keywords
; i
> 0; i
--, keyword
++)
3089 cupsdLogMessage(CUPSD_LOG_DEBUG
, "*%s: %s", keyword
->name
, keyword
->value
);
3090 cupsFilePrintf(dst
, "*%s: %s\n", keyword
->name
, keyword
->value
);
3094 * Then copy the rest of the PPD file, dropping any keywords we changed.
3097 while (cupsFileGets(src
, line
, sizeof(line
)))
3100 * Skip keywords we've already set...
3103 if (sscanf(line
, "*%40[^:]:", keystring
) == 1 &&
3104 cupsGetOption(keystring
, num_keywords
, keywords
))
3108 * Otherwise write the line...
3111 cupsFilePrintf(dst
, "%s\n", line
);
3115 * Close files and return...
3126 * 'cupsdUpdatePrinters()' - Update printers after a partial reload.
3130 cupsdUpdatePrinters(void)
3132 cupsd_printer_t
*p
; /* Current printer */
3136 * Loop through the printers and recreate the printer attributes
3137 * for any local printers since the policy and/or access control
3138 * stuff may have changed. Also, if browsing is disabled, remove
3139 * any remote printers...
3142 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3144 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3147 * Remove remote printers if we are no longer browsing...
3151 (p
->type
& (CUPS_PRINTER_IMPLICIT
| CUPS_PRINTER_DISCOVERED
)))
3153 if (p
->type
& CUPS_PRINTER_IMPLICIT
)
3154 cupsArrayRemove(ImplicitPrinters
, p
);
3156 cupsArraySave(Printers
);
3157 cupsdDeletePrinter(p
, 0);
3158 cupsArrayRestore(Printers
);
3163 * Update the operation policy pointer...
3166 if ((p
->op_policy_ptr
= cupsdFindPolicy(p
->op_policy
)) == NULL
)
3167 p
->op_policy_ptr
= DefaultPolicyPtr
;
3170 * Update printer attributes as needed...
3173 if (!(p
->type
& CUPS_PRINTER_DISCOVERED
))
3174 cupsdSetPrinterAttrs(p
);
3180 * 'cupsdValidateDest()' - Validate a printer/class destination.
3183 const char * /* O - Printer or class name */
3185 const char *uri
, /* I - Printer URI */
3186 cups_ptype_t
*dtype
, /* O - Type (printer or class) */
3187 cupsd_printer_t
**printer
) /* O - Printer pointer */
3189 cupsd_printer_t
*p
; /* Current printer */
3190 char localname
[1024],/* Localized hostname */
3191 *lptr
, /* Pointer into localized hostname */
3192 *sptr
, /* Pointer into server name */
3193 *rptr
, /* Pointer into resource */
3194 scheme
[32], /* Scheme portion of URI */
3195 username
[64], /* Username portion of URI */
3196 hostname
[HTTP_MAX_HOST
],
3197 /* Host portion of URI */
3198 resource
[HTTP_MAX_URI
];
3199 /* Resource portion of URI */
3200 int port
; /* Port portion of URI */
3203 DEBUG_printf(("cupsdValidateDest(uri=\"%s\", dtype=%p, printer=%p)\n", uri
,
3207 * Initialize return values...
3214 *dtype
= (cups_ptype_t
)0;
3217 * Pull the hostname and resource from the URI...
3220 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
, scheme
, sizeof(scheme
),
3221 username
, sizeof(username
), hostname
, sizeof(hostname
),
3222 &port
, resource
, sizeof(resource
));
3225 * See if the resource is a class or printer...
3228 if (!strncmp(resource
, "/classes/", 9))
3234 rptr
= resource
+ 9;
3236 else if (!strncmp(resource
, "/printers/", 10))
3242 rptr
= resource
+ 10;
3247 * Bad resource name...
3254 * See if the printer or class name exists...
3257 p
= cupsdFindDest(rptr
);
3259 if (p
== NULL
&& strchr(rptr
, '@') == NULL
)
3267 *dtype
= p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
|
3268 CUPS_PRINTER_REMOTE
| CUPS_PRINTER_DISCOVERED
);
3274 * Change localhost to the server name...
3277 if (!strcasecmp(hostname
, "localhost"))
3278 strlcpy(hostname
, ServerName
, sizeof(hostname
));
3280 strlcpy(localname
, hostname
, sizeof(localname
));
3282 if (!strcasecmp(hostname
, ServerName
))
3285 * Localize the hostname...
3288 lptr
= strchr(localname
, '.');
3289 sptr
= strchr(ServerName
, '.');
3291 if (sptr
!= NULL
&& lptr
!= NULL
)
3294 * Strip the common domain name components...
3297 while (lptr
!= NULL
)
3299 if (!strcasecmp(lptr
, sptr
))
3305 lptr
= strchr(lptr
+ 1, '.');
3310 DEBUG_printf(("localized hostname is \"%s\"...\n", localname
));
3313 * Find a matching printer or class...
3316 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3318 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3319 if (!strcasecmp(p
->hostname
, localname
) &&
3320 !strcasecmp(p
->name
, rptr
))
3326 *dtype
= p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
|
3327 CUPS_PRINTER_REMOTE
| CUPS_PRINTER_DISCOVERED
);
3337 * 'cupsdWritePrintcap()' - Write a pseudo-printcap file for older applications
3342 cupsdWritePrintcap(void)
3344 int i
; /* Looping var */
3345 cups_file_t
*fp
; /* Printcap file */
3346 cupsd_printer_t
*p
; /* Current printer */
3351 * Update the IRIX printer state for the default printer; if
3352 * no printers remain, then the default printer file will be
3356 write_irix_state(DefaultPrinter
);
3360 * See if we have a printcap file; if not, don't bother writing it.
3363 if (!Printcap
|| !*Printcap
)
3366 cupsdLogMessage(CUPSD_LOG_INFO
, "Generating printcap %s...", Printcap
);
3369 * Open the printcap file...
3372 if ((fp
= cupsFileOpen(Printcap
, "w")) == NULL
)
3376 * Put a comment header at the top so that users will know where the
3377 * data has come from...
3380 if (PrintcapFormat
!= PRINTCAP_PLIST
)
3381 cupsFilePrintf(fp
, "# This file was automatically generated by cupsd(8) "
3383 "# %s/printers.conf file. All changes to this file\n"
3384 "# will be lost.\n", ServerRoot
);
3387 * Write a new printcap with the current list of printers.
3390 switch (PrintcapFormat
)
3394 * Each printer is put in the file as:
3404 cupsFilePrintf(fp
, "%s|%s:rm=%s:rp=%s:\n", DefaultPrinter
->name
,
3405 DefaultPrinter
->info
, ServerName
,
3406 DefaultPrinter
->name
);
3408 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3410 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3411 if (p
!= DefaultPrinter
)
3412 cupsFilePrintf(fp
, "%s|%s:rm=%s:rp=%s:\n", p
->name
, p
->info
,
3413 ServerName
, p
->name
);
3416 case PRINTCAP_PLIST
:
3418 * Each printer is written as a dictionary in a plist file.
3419 * Currently the printer-name, printer-info, printer-is-accepting-jobs,
3420 * printer-location, printer-make-and-model, printer-state,
3421 * printer-state-reasons, printer-type, and (sanitized) device-uri.
3424 cupsFilePuts(fp
, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
3425 "<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD "
3426 "PLIST 1.0//EN\" \"http://www.apple.com/DTDs/"
3427 "PropertyList-1.0.dtd\">\n"
3428 "<plist version=\"1.0\">\n"
3431 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3433 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3435 cupsFilePuts(fp
, "\t<dict>\n"
3436 "\t\t<key>printer-name</key>\n"
3438 write_xml_string(fp
, p
->name
);
3439 cupsFilePuts(fp
, "</string>\n"
3440 "\t\t<key>printer-info</key>\n"
3442 write_xml_string(fp
, p
->info
);
3443 cupsFilePrintf(fp
, "</string>\n"
3444 "\t\t<key>printer-is-accepting-jobs</key>\n"
3446 "\t\t<key>printer-location</key>\n"
3447 "\t\t<string>", p
->accepting
? "true" : "false");
3448 write_xml_string(fp
, p
->location
);
3449 cupsFilePuts(fp
, "</string>\n"
3450 "\t\t<key>printer-make-and-model</key>\n"
3452 write_xml_string(fp
, p
->make_model
);
3453 cupsFilePrintf(fp
, "</string>\n"
3454 "\t\t<key>printer-state</key>\n"
3455 "\t\t<integer>%d</integer>\n"
3456 "\t\t<key>printer-state-reasons</key>\n"
3457 "\t\t<array>\n", p
->state
);
3458 for (i
= 0; i
< p
->num_reasons
; i
++)
3460 cupsFilePuts(fp
, "\t\t\t<string>");
3461 write_xml_string(fp
, p
->reasons
[i
]);
3462 cupsFilePuts(fp
, "</string>\n");
3464 cupsFilePrintf(fp
, "\t\t</array>\n"
3465 "\t\t<key>printer-type</key>\n"
3466 "\t\t<integer>%d</integer>\n"
3467 "\t\t<key>device-uri</key>\n"
3468 "\t\t<string>", p
->type
);
3469 write_xml_string(fp
, p
->sanitized_device_uri
);
3470 cupsFilePuts(fp
, "</string>\n"
3473 cupsFilePuts(fp
, "</array>\n"
3477 case PRINTCAP_SOLARIS
:
3479 * Each printer is put in the file as:
3481 * _all:all=Printer1,Printer2,Printer3,...,PrinterN
3482 * _default:use=DefaultPrinter
3484 * :bsdaddr=ServerName,Printer1:\
3485 * :description=Description:
3487 * :bsdaddr=ServerName,Printer2:\
3488 * :description=Description:
3490 * :bsdaddr=ServerName,Printer3:\
3491 * :description=Description:
3494 * :bsdaddr=ServerName,PrinterN:\
3495 * :description=Description:
3498 cupsFilePuts(fp
, "_all:all=");
3499 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3501 p
= (cupsd_printer_t
*)cupsArrayCurrent(Printers
))
3502 cupsFilePrintf(fp
, "%s%c", p
->name
,
3503 cupsArrayNext(Printers
) ? ',' : '\n');
3506 cupsFilePrintf(fp
, "_default:use=%s\n", DefaultPrinter
->name
);
3508 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3510 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3511 cupsFilePrintf(fp
, "%s:\\\n"
3512 "\t:bsdaddr=%s,%s:\\\n"
3513 "\t:description=%s:\n",
3514 p
->name
, ServerName
, p
->name
,
3515 p
->info
? p
->info
: "");
3528 * 'add_printer_defaults()' - Add name-default attributes to the printer attributes.
3532 add_printer_defaults(cupsd_printer_t
*p
)/* I - Printer */
3534 int i
; /* Looping var */
3535 int num_options
; /* Number of default options */
3536 cups_option_t
*options
, /* Default options */
3537 *option
; /* Current option */
3538 char name
[256]; /* name-default */
3542 * Maintain a common array of default attribute names...
3545 if (!CommonDefaults
)
3547 CommonDefaults
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
3549 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("copies-default"));
3550 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("document-format-default"));
3551 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("finishings-default"));
3552 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-hold-until-default"));
3553 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-priority-default"));
3554 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-sheets-default"));
3555 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("media-col-default"));
3556 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("number-up-default"));
3557 cupsArrayAdd(CommonDefaults
,
3558 _cupsStrAlloc("orientation-requested-default"));
3562 * Add all of the default options from the .conf files...
3565 for (num_options
= 0, options
= NULL
, i
= p
->num_options
, option
= p
->options
;
3569 if (strcmp(option
->name
, "ipp-options") &&
3570 strcmp(option
->name
, "job-sheets") &&
3571 strcmp(option
->name
, "lease-duration"))
3573 snprintf(name
, sizeof(name
), "%s-default", option
->name
);
3574 num_options
= cupsAddOption(name
, option
->value
, num_options
, &options
);
3576 if (!cupsArrayFind(CommonDefaults
, name
))
3577 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc(name
));
3582 * Convert options to IPP attributes...
3585 cupsEncodeOptions2(p
->attrs
, num_options
, options
, IPP_TAG_PRINTER
);
3586 cupsFreeOptions(num_options
, options
);
3589 * Add standard -default attributes as needed...
3592 if (!cupsGetOption("copies", p
->num_options
, p
->options
))
3593 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
, "copies-default",
3596 if (!cupsGetOption("document-format", p
->num_options
, p
->options
))
3597 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_MIMETYPE
,
3598 "document-format-default", NULL
, "application/octet-stream");
3600 if (!cupsGetOption("job-hold-until", p
->num_options
, p
->options
))
3601 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3602 "job-hold-until-default", NULL
, "no-hold");
3604 if (!cupsGetOption("job-priority", p
->num_options
, p
->options
))
3605 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3606 "job-priority-default", 50);
3608 if (!cupsGetOption("number-up", p
->num_options
, p
->options
))
3609 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3610 "number-up-default", 1);
3612 if (!cupsGetOption("notify-lease-duration", p
->num_options
, p
->options
))
3613 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3614 "notify-lease-duration-default", DefaultLeaseDuration
);
3616 if (!cupsGetOption("notify-events", p
->num_options
, p
->options
))
3617 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3618 "notify-events-default", NULL
, "job-completed");
3620 if (!cupsGetOption("orientation-requested", p
->num_options
, p
->options
))
3621 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NOVALUE
,
3622 "orientation-requested-default", NULL
, NULL
);
3624 if (!cupsGetOption("print-quality", p
->num_options
, p
->options
))
3625 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
3626 "print-quality-default", IPP_QUALITY_NORMAL
);
3631 * 'add_printer_filter()' - Add a MIME filter for a printer.
3636 cupsd_printer_t
*p
, /* I - Printer to add to */
3637 mime_type_t
*filtertype
, /* I - Filter or prefilter MIME type */
3638 const char *filter
) /* I - Filter to add */
3640 char super
[MIME_MAX_SUPER
], /* Super-type for filter */
3641 type
[MIME_MAX_TYPE
], /* Type for filter */
3642 program
[1024]; /* Program/filter name */
3643 int cost
; /* Cost of filter */
3644 mime_type_t
*temptype
; /* MIME type looping var */
3645 char filename
[1024], /* Full filter filename */
3646 *dirsep
; /* Pointer to directory separator */
3647 struct stat fileinfo
; /* File information */
3651 * Parse the filter string; it should be in the following format:
3653 * super/type cost program
3656 if (sscanf(filter
, "%15[^/]/%31s%d%*[ \t]%1023[^\n]", super
, type
, &cost
,
3659 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: invalid filter string \"%s\"!",
3665 * See if the filter program exists; if not, stop the printer and flag
3669 if (strcmp(program
, "-"))
3671 if (program
[0] == '/')
3672 strlcpy(filename
, program
, sizeof(filename
));
3674 snprintf(filename
, sizeof(filename
), "%s/filter/%s", ServerBin
, program
);
3676 if (stat(filename
, &fileinfo
))
3678 memset(&fileinfo
, 0, sizeof(fileinfo
));
3680 snprintf(p
->state_message
, sizeof(p
->state_message
),
3681 "Filter \"%s\" for printer \"%s\" not available: %s",
3682 filename
, p
->name
, strerror(errno
));
3683 cupsdSetPrinterReasons(p
, "+cups-missing-filter-warning");
3685 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s", p
->state_message
);
3689 * When running as root, do additional security checks...
3695 * Only use filters that are owned by root and do not have world write
3699 if (fileinfo
.st_uid
|| (fileinfo
.st_mode
& (S_ISUID
| S_IWOTH
)) != 0)
3701 if (fileinfo
.st_uid
)
3702 snprintf(p
->state_message
, sizeof(p
->state_message
),
3703 "Filter \"%s\" for printer \"%s\" not owned by root",
3706 snprintf(p
->state_message
, sizeof(p
->state_message
),
3707 "Filter \"%s\" for printer \"%s\" has insecure permissions "
3708 "(0%o)", filename
, p
->name
, fileinfo
.st_mode
);
3710 cupsdSetPrinterReasons(p
, "+cups-insecure-filter-warning");
3712 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s", p
->state_message
);
3714 else if (fileinfo
.st_mode
)
3717 * Similarly, check that the parent directory is also owned by root and
3718 * does not have world write permissions.
3721 if ((dirsep
= strrchr(filename
, '/')) != NULL
)
3724 if (!stat(filename
, &fileinfo
) &&
3726 (fileinfo
.st_mode
& (S_ISUID
| S_IWOTH
)) != 0))
3728 if (fileinfo
.st_uid
)
3729 snprintf(p
->state_message
, sizeof(p
->state_message
),
3730 "Filter directory \"%s\" for printer \"%s\" not owned by "
3731 "root", filename
, p
->name
);
3733 snprintf(p
->state_message
, sizeof(p
->state_message
),
3734 "Filter directory \"%s\" for printer \"%s\" has insecure "
3735 "permissions (0%o)", filename
, p
->name
, fileinfo
.st_mode
);
3737 cupsdSetPrinterReasons(p
, "+cups-insecure-filter-warning");
3739 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s", p
->state_message
);
3746 * Add the filter to the MIME database, supporting wildcards as needed...
3749 for (temptype
= mimeFirstType(MimeDatabase
);
3751 temptype
= mimeNextType(MimeDatabase
))
3752 if (((super
[0] == '*' && strcasecmp(temptype
->super
, "printer")) ||
3753 !strcasecmp(temptype
->super
, super
)) &&
3754 (type
[0] == '*' || !strcasecmp(temptype
->type
, type
)))
3756 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3757 "add_printer_filter: %s: adding filter %s/%s %s/%s %d %s",
3758 p
->name
, temptype
->super
, temptype
->type
,
3759 filtertype
->super
, filtertype
->type
,
3761 mimeAddFilter(MimeDatabase
, temptype
, filtertype
, cost
, program
);
3767 * 'add_printer_formats()' - Add document-format-supported values for a printer.
3771 add_printer_formats(cupsd_printer_t
*p
) /* I - Printer */
3773 int i
; /* Looping var */
3774 mime_type_t
*type
; /* Current MIME type */
3775 cups_array_t
*filters
; /* Filters */
3776 ipp_attribute_t
*attr
; /* document-format-supported attribute */
3777 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
3778 /* MIME type name */
3782 * Raw (and remote) queues advertise all of the supported MIME
3786 cupsArrayDelete(p
->filetypes
);
3787 p
->filetypes
= NULL
;
3791 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
,
3792 (ipp_tag_t
)(IPP_TAG_MIMETYPE
| IPP_TAG_COPY
),
3793 "document-format-supported", NumMimeTypes
, NULL
, MimeTypes
);
3798 * Otherwise, loop through the supported MIME types and see if there
3799 * are filters for them...
3802 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_printer_formats: %d types, %d filters",
3803 mimeNumTypes(MimeDatabase
), mimeNumFilters(MimeDatabase
));
3805 p
->filetypes
= cupsArrayNew(NULL
, NULL
);
3807 for (type
= mimeFirstType(MimeDatabase
);
3809 type
= mimeNextType(MimeDatabase
))
3811 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
3813 if ((filters
= mimeFilter(MimeDatabase
, type
, p
->filetype
, NULL
)) != NULL
)
3815 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3816 "add_printer_formats: %s: %s needs %d filters",
3817 p
->name
, mimetype
, cupsArrayCount(filters
));
3819 cupsArrayDelete(filters
);
3820 cupsArrayAdd(p
->filetypes
, type
);
3823 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3824 "add_printer_formats: %s: %s not supported",
3829 * Add the file formats that can be filtered...
3832 if ((type
= mimeType(MimeDatabase
, "application", "octet-stream")) == NULL
||
3833 !cupsArrayFind(p
->filetypes
, type
))
3838 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3839 "add_printer_formats: %s: %d supported types",
3840 p
->name
, cupsArrayCount(p
->filetypes
) + i
);
3842 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_MIMETYPE
,
3843 "document-format-supported",
3844 cupsArrayCount(p
->filetypes
) + i
, NULL
, NULL
);
3847 attr
->values
[0].string
.text
= _cupsStrAlloc("application/octet-stream");
3849 for (type
= (mime_type_t
*)cupsArrayFirst(p
->filetypes
);
3851 i
++, type
= (mime_type_t
*)cupsArrayNext(p
->filetypes
))
3853 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
3855 attr
->values
[i
].string
.text
= _cupsStrAlloc(mimetype
);
3860 char pdl
[1024]; /* Buffer to build pdl list */
3861 mime_filter_t
*filter
; /* MIME filter looping var */
3865 * We only support raw printing if this is not a Tioga PrintJobMgr based
3866 * queue and if application/octet-stream is a known type...
3869 for (filter
= (mime_filter_t
*)cupsArrayFirst(MimeDatabase
->filters
);
3871 filter
= (mime_filter_t
*)cupsArrayNext(MimeDatabase
->filters
))
3873 if (filter
->dst
== p
->filetype
&& filter
->filter
&&
3874 strstr(filter
->filter
, "PrintJobMgr"))
3880 if (!filter
&& mimeType(MimeDatabase
, "application", "octet-stream"))
3881 strlcat(pdl
, "application/octet-stream,", sizeof(pdl
));
3884 * Then list a bunch of formats that are supported by the printer...
3887 for (type
= (mime_type_t
*)cupsArrayFirst(p
->filetypes
);
3889 type
= (mime_type_t
*)cupsArrayNext(p
->filetypes
))
3891 if (!strcasecmp(type
->super
, "application"))
3893 if (!strcasecmp(type
->type
, "pdf"))
3894 strlcat(pdl
, "application/pdf,", sizeof(pdl
));
3895 else if (!strcasecmp(type
->type
, "postscript"))
3896 strlcat(pdl
, "application/postscript,", sizeof(pdl
));
3898 else if (!strcasecmp(type
->super
, "image"))
3900 if (!strcasecmp(type
->type
, "jpeg"))
3901 strlcat(pdl
, "image/jpeg,", sizeof(pdl
));
3902 else if (!strcasecmp(type
->type
, "png"))
3903 strlcat(pdl
, "image/png,", sizeof(pdl
));
3908 pdl
[strlen(pdl
) - 1] = '\0'; /* Remove trailing comma */
3910 cupsdSetString(&p
->pdl
, pdl
);
3912 #endif /* HAVE_DNSSD */
3917 * 'add_string_array()' - Add a string to an array of CUPS strings.
3921 add_string_array(cups_array_t
**a
, /* I - Array */
3922 const char *s
) /* I - String */
3925 *a
= cupsArrayNew(NULL
, NULL
);
3927 cupsArrayAdd(*a
, _cupsStrAlloc(s
));
3932 * 'compare_printers()' - Compare two printers.
3935 static int /* O - Result of comparison */
3936 compare_printers(void *first
, /* I - First printer */
3937 void *second
, /* I - Second printer */
3938 void *data
) /* I - App data (not used) */
3940 return (strcasecmp(((cupsd_printer_t
*)first
)->name
,
3941 ((cupsd_printer_t
*)second
)->name
));
3946 * 'delete_printer_filters()' - Delete all MIME filters for a printer.
3950 delete_printer_filters(
3951 cupsd_printer_t
*p
) /* I - Printer to remove from */
3953 mime_filter_t
*filter
; /* MIME filter looping var */
3957 * Range check input...
3964 * Remove all filters from the MIME database that have a destination
3965 * type == printer...
3968 for (filter
= mimeFirstFilter(MimeDatabase
);
3970 filter
= mimeNextFilter(MimeDatabase
))
3971 if (filter
->dst
== p
->filetype
|| filter
->dst
== p
->prefiltertype
)
3974 * Delete the current filter...
3977 mimeDeleteFilter(MimeDatabase
, filter
);
3980 cupsdSetPrinterReasons(p
, "-cups-insecure-filter-warning"
3981 ",cups-missing-filter-warning");
3986 * 'delete_string_array()' - Delete an array of CUPS strings.
3990 delete_string_array(cups_array_t
**a
) /* I - Array */
3992 char *ptr
; /* Current string */
3995 for (ptr
= (char *)cupsArrayFirst(*a
);
3997 ptr
= (char *)cupsArrayNext(*a
))
4000 cupsArrayDelete(*a
);
4006 * 'load_ppd()' - Load a cached PPD file, updating the cache as needed.
4010 load_ppd(cupsd_printer_t
*p
) /* I - Printer */
4012 int i
, j
, k
; /* Looping vars */
4013 cups_file_t
*cache
; /* IPP cache file */
4014 char cache_name
[1024]; /* IPP cache filename */
4015 struct stat cache_info
; /* IPP cache file info */
4016 char pwg_name
[1024]; /* PWG cache filename */
4017 struct stat pwg_info
; /* PWG cache file info */
4018 ppd_file_t
*ppd
; /* PPD file */
4019 char ppd_name
[1024]; /* PPD filename */
4020 struct stat ppd_info
; /* PPD file info */
4021 int num_media
; /* Number of media options */
4022 ppd_size_t
*size
; /* Current PPD size */
4023 ppd_option_t
*duplex
, /* Duplex option */
4024 *output_bin
, /* OutputBin option */
4025 *output_mode
, /* OutputMode option */
4026 *resolution
; /* (Set|JCL|)Resolution option */
4027 ppd_choice_t
*choice
, /* Current PPD choice */
4028 *input_slot
, /* Current input slot */
4029 *media_type
; /* Current media type */
4030 ppd_attr_t
*ppd_attr
; /* PPD attribute */
4031 int xdpi
, /* Horizontal resolution */
4032 ydpi
; /* Vertical resolution */
4033 const char *resptr
; /* Pointer into resolution keyword */
4034 _pwg_size_t
*pwgsize
; /* Current PWG size */
4035 _pwg_map_t
*pwgsource
, /* Current PWG source */
4036 *pwgtype
; /* Current PWG type */
4037 ipp_attribute_t
*attr
; /* Attribute data */
4038 ipp_value_t
*val
; /* Attribute value */
4039 int num_finishings
, /* Number of finishings */
4040 finishings
[5]; /* finishings-supported values */
4041 int num_qualities
, /* Number of print-quality values */
4042 qualities
[3]; /* print-quality values */
4043 int num_margins
, /* Number of media-*-margin-supported values */
4044 margins
[16]; /* media-*-margin-supported values */
4045 static const char * const sides
[3] = /* sides-supported values */
4048 "two-sided-long-edge",
4049 "two-sided-short-edge"
4051 static const char * const standard_commands
[] =
4052 { /* Standard CUPS commands */
4060 * Check to see if the cache is up-to-date...
4063 snprintf(cache_name
, sizeof(cache_name
), "%s/%s.ipp4", CacheDir
, p
->name
);
4064 if (stat(cache_name
, &cache_info
))
4065 cache_info
.st_mtime
= 0;
4067 snprintf(pwg_name
, sizeof(pwg_name
), "%s/%s.pwg3", CacheDir
, p
->name
);
4068 if (stat(pwg_name
, &pwg_info
))
4069 pwg_info
.st_mtime
= 0;
4071 snprintf(ppd_name
, sizeof(ppd_name
), "%s/ppd/%s.ppd", ServerRoot
, p
->name
);
4072 if (stat(ppd_name
, &ppd_info
))
4073 ppd_info
.st_mtime
= 1;
4075 ippDelete(p
->ppd_attrs
);
4076 p
->ppd_attrs
= ippNew();
4078 _pwgDestroy(p
->pwg
);
4081 if (pwg_info
.st_mtime
>= ppd_info
.st_mtime
)
4082 p
->pwg
= _pwgCreateWithFile(pwg_name
);
4084 if (cache_info
.st_mtime
>= ppd_info
.st_mtime
&& p
->pwg
&&
4085 (cache
= cupsFileOpen(cache_name
, "r")) != NULL
)
4088 * Load cached information and return...
4091 cupsdLogMessage(CUPSD_LOG_DEBUG
, "load_ppd: Loading %s...", cache_name
);
4093 if (ippReadIO(cache
, (ipp_iocb_t
)cupsFileRead
, 1, NULL
,
4094 p
->ppd_attrs
) == IPP_DATA
)
4096 cupsFileClose(cache
);
4100 cupsFileClose(cache
);
4104 * Reload PPD attributes from disk...
4107 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
4109 _pwgDestroy(p
->pwg
);
4112 cupsdLogMessage(CUPSD_LOG_DEBUG
, "load_ppd: Loading %s...", ppd_name
);
4114 delete_string_array(&(p
->filters
));
4115 delete_string_array(&(p
->pre_filters
));
4117 p
->type
&= ~CUPS_PRINTER_OPTIONS
;
4118 p
->type
|= CUPS_PRINTER_BW
;
4120 finishings
[0] = IPP_FINISHINGS_NONE
;
4123 if ((ppd
= ppdOpenFile(ppd_name
)) != NULL
)
4126 * Add make/model and other various attributes...
4129 p
->pwg
= _pwgCreateWithPPD(ppd
);
4131 ppdMarkDefaults(ppd
);
4133 if (ppd
->color_device
)
4134 p
->type
|= CUPS_PRINTER_COLOR
;
4135 if (ppd
->variable_sizes
)
4136 p
->type
|= CUPS_PRINTER_VARIABLE
;
4137 if (!ppd
->manual_copies
)
4138 p
->type
|= CUPS_PRINTER_COPIES
;
4139 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsFax", NULL
)) != NULL
)
4140 if (ppd_attr
->value
&& !strcasecmp(ppd_attr
->value
, "true"))
4141 p
->type
|= CUPS_PRINTER_FAX
;
4143 ippAddBoolean(p
->ppd_attrs
, IPP_TAG_PRINTER
, "color-supported",
4145 if (ppd
->throughput
)
4147 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4148 "pages-per-minute", ppd
->throughput
);
4149 if (ppd
->color_device
)
4150 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4151 "pages-per-minute-color", ppd
->throughput
);
4156 if ((output_mode
= ppdFindOption(ppd
, "OutputMode")) != NULL
)
4158 if (ppdFindChoice(output_mode
, "draft") ||
4159 ppdFindChoice(output_mode
, "fast"))
4160 qualities
[num_qualities
++] = IPP_QUALITY_DRAFT
;
4161 if (ppdFindChoice(output_mode
, "normal") ||
4162 ppdFindChoice(output_mode
, "good"))
4163 qualities
[num_qualities
++] = IPP_QUALITY_NORMAL
;
4164 if (ppdFindChoice(output_mode
, "best") ||
4165 ppdFindChoice(output_mode
, "high"))
4166 qualities
[num_qualities
++] = IPP_QUALITY_HIGH
;
4168 else if ((ppd_attr
= ppdFindAttr(ppd
, "APPrinterPreset", NULL
)) != NULL
)
4172 if (strstr(ppd_attr
->spec
, "draft") ||
4173 strstr(ppd_attr
->spec
, "Draft"))
4175 qualities
[num_qualities
++] = IPP_QUALITY_DRAFT
;
4179 while ((ppd_attr
= ppdFindNextAttr(ppd
, "APPrinterPreset",
4182 qualities
[num_qualities
++] = IPP_QUALITY_NORMAL
;
4183 qualities
[num_qualities
++] = IPP_QUALITY_HIGH
;
4186 if (num_qualities
== 0)
4187 qualities
[num_qualities
++] = IPP_QUALITY_NORMAL
;
4189 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
4190 "print-quality-supported", num_qualities
, qualities
);
4195 * The NickName can be localized in the character set specified
4196 * by the LanugageEncoding attribute. However, ppdOpen2() has
4197 * already converted the ppd->nickname member to UTF-8 for us
4198 * (the original attribute value is available separately)
4201 cupsdSetString(&p
->make_model
, ppd
->nickname
);
4203 else if (ppd
->modelname
)
4206 * Model name can only contain specific characters...
4209 cupsdSetString(&p
->make_model
, ppd
->modelname
);
4212 cupsdSetString(&p
->make_model
, "Bad PPD File");
4214 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
4215 "printer-make-and-model", NULL
, p
->make_model
);
4218 * Add media options from the PPD file...
4221 if (ppd
->num_sizes
== 0 || !p
->pwg
)
4223 if (!ppdFindAttr(ppd
, "APScannerOnly", NULL
))
4224 cupsdLogMessage(CUPSD_LOG_CRIT
,
4225 "The PPD file for printer %s contains no media "
4226 "options and is therefore invalid!", p
->name
);
4228 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4229 "media-default", NULL
, "unknown");
4230 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4231 "media-supported", NULL
, "unknown");
4239 if ((size
= ppdPageSize(ppd
, NULL
)) != NULL
)
4240 pwgsize
= _pwgGetSize(p
->pwg
, size
->name
);
4244 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4245 "media-default", NULL
,
4246 pwgsize
? pwgsize
->map
.pwg
: "unknown");
4254 ipp_t
*col
; /* Collection value */
4256 input_slot
= ppdFindMarkedChoice(ppd
, "InputSlot");
4257 media_type
= ppdFindMarkedChoice(ppd
, "MediaType");
4258 col
= new_media_col(pwgsize
,
4260 _pwgGetSource(p
->pwg
,
4261 input_slot
->choice
) :
4265 media_type
->choice
) :
4268 ippAddCollection(p
->ppd_attrs
, IPP_TAG_PRINTER
, "media-col-default",
4277 num_media
= p
->pwg
->num_sizes
;
4278 if (p
->pwg
->custom_min_keyword
)
4281 if ((attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4282 "media-supported", num_media
, NULL
,
4287 for (i
= p
->pwg
->num_sizes
, pwgsize
= p
->pwg
->sizes
;
4289 i
--, pwgsize
++, val
++)
4290 val
->string
.text
= _cupsStrRetain(pwgsize
->map
.pwg
);
4292 if (p
->pwg
->custom_min_keyword
)
4294 val
->string
.text
= _cupsStrRetain(p
->pwg
->custom_min_keyword
);
4296 val
->string
.text
= _cupsStrRetain(p
->pwg
->custom_max_keyword
);
4301 * media-source-supported
4304 if (p
->pwg
->num_sources
> 0 &&
4305 (attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4306 "media-source-supported", p
->pwg
->num_sources
,
4307 NULL
, NULL
)) != NULL
)
4309 for (i
= p
->pwg
->num_sources
, pwgsource
= p
->pwg
->sources
,
4312 i
--, pwgsource
++, val
++)
4313 val
->string
.text
= _cupsStrRetain(pwgsource
->pwg
);
4317 * media-type-supported
4320 if (p
->pwg
->num_types
> 0 &&
4321 (attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4322 "media-type-supported", p
->pwg
->num_types
,
4323 NULL
, NULL
)) != NULL
)
4325 for (i
= p
->pwg
->num_types
, pwgtype
= p
->pwg
->types
,
4328 i
--, pwgtype
++, val
++)
4329 val
->string
.text
= _cupsStrRetain(pwgtype
->pwg
);
4333 * media-*-margin-supported
4336 for (i
= p
->pwg
->num_sizes
, pwgsize
= p
->pwg
->sizes
, num_margins
= 0;
4337 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4340 for (j
= 0; j
< num_margins
; j
++)
4341 if (pwgsize
->bottom
== margins
[j
])
4344 if (j
>= num_margins
)
4346 margins
[num_margins
] = pwgsize
->bottom
;
4351 if (num_margins
> 0)
4352 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4353 "media-bottom-margin-supported", num_margins
, margins
);
4355 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4356 "media-bottom-margin-supported", 0);
4358 for (i
= p
->pwg
->num_sizes
, pwgsize
= p
->pwg
->sizes
, num_margins
= 0;
4359 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4362 for (j
= 0; j
< num_margins
; j
++)
4363 if (pwgsize
->left
== margins
[j
])
4366 if (j
>= num_margins
)
4368 margins
[num_margins
] = pwgsize
->left
;
4373 if (num_margins
> 0)
4374 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4375 "media-left-margin-supported", num_margins
, margins
);
4377 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4378 "media-left-margin-supported", 0);
4380 for (i
= p
->pwg
->num_sizes
, pwgsize
= p
->pwg
->sizes
, num_margins
= 0;
4381 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4384 for (j
= 0; j
< num_margins
; j
++)
4385 if (pwgsize
->right
== margins
[j
])
4388 if (j
>= num_margins
)
4390 margins
[num_margins
] = pwgsize
->right
;
4395 if (num_margins
> 0)
4396 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4397 "media-right-margin-supported", num_margins
, margins
);
4399 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4400 "media-right-margin-supported", 0);
4402 for (i
= p
->pwg
->num_sizes
, pwgsize
= p
->pwg
->sizes
, num_margins
= 0;
4403 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4406 for (j
= 0; j
< num_margins
; j
++)
4407 if (pwgsize
->top
== margins
[j
])
4410 if (j
>= num_margins
)
4412 margins
[num_margins
] = pwgsize
->top
;
4417 if (num_margins
> 0)
4418 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4419 "media-top-margin-supported", num_margins
, margins
);
4421 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4422 "media-top-margin-supported", 0);
4425 * media-col-database
4428 num_media
= p
->pwg
->num_sizes
;
4429 if (p
->pwg
->num_sources
)
4431 if (p
->pwg
->num_types
> 0)
4432 num_media
+= p
->pwg
->num_sizes
* p
->pwg
->num_sources
*
4435 num_media
+= p
->pwg
->num_sizes
* p
->pwg
->num_sources
;
4437 else if (p
->pwg
->num_types
)
4438 num_media
+= p
->pwg
->num_sizes
* p
->pwg
->num_types
;
4440 if ((attr
= ippAddCollections(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4441 "media-col-database", num_media
,
4444 for (i
= p
->pwg
->num_sizes
, pwgsize
= p
->pwg
->sizes
, val
= attr
->values
;
4449 * Start by adding the page size without source or type...
4452 ppdMarkOption(ppd
, "PageSize", pwgsize
->map
.ppd
);
4454 val
->collection
= new_media_col(pwgsize
, NULL
, NULL
);
4458 * Then add the specific, supported combinations of size, source, and
4462 if (p
->pwg
->num_sources
> 0)
4464 for (j
= p
->pwg
->num_sources
, pwgsource
= p
->pwg
->sources
;
4468 ppdMarkOption(ppd
, "InputSlot", pwgsource
->ppd
);
4470 if (p
->pwg
->num_types
> 0)
4472 for (k
= p
->pwg
->num_types
, pwgtype
= p
->pwg
->types
;
4476 if (!ppdMarkOption(ppd
, "MediaType", pwgtype
->ppd
))
4478 val
->collection
= new_media_col(pwgsize
, pwgsource
->pwg
,
4484 else if (!ppdConflicts(ppd
))
4486 val
->collection
= new_media_col(pwgsize
, pwgsource
->pwg
, NULL
);
4491 else if (p
->pwg
->num_types
> 0)
4493 for (j
= p
->pwg
->num_types
, pwgtype
= p
->pwg
->types
;
4497 if (!ppdMarkOption(ppd
, "MediaType", pwgtype
->ppd
))
4499 val
->collection
= new_media_col(pwgsize
, NULL
, pwgtype
->pwg
);
4507 * Update the number of media-col-database values...
4510 attr
->num_values
= val
- attr
->values
;
4518 if (p
->pwg
&& p
->pwg
->num_bins
> 0)
4520 attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4521 "output-bin-supported", p
->pwg
->num_bins
,
4526 for (i
= 0, val
= attr
->values
;
4527 i
< p
->pwg
->num_bins
;
4529 val
->string
.text
= _cupsStrAlloc(p
->pwg
->bins
[i
].pwg
);
4532 if ((output_bin
= ppdFindOption(ppd
, "OutputBin")) != NULL
)
4534 for (i
= 0; i
< p
->pwg
->num_bins
; i
++)
4535 if (!strcmp(p
->pwg
->bins
[i
].ppd
, output_bin
->defchoice
))
4538 if (i
>= p
->pwg
->num_bins
)
4541 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4542 "output-bin-default", NULL
, p
->pwg
->bins
[i
].pwg
);
4545 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4546 "output-bin-default", NULL
, p
->pwg
->bins
[0].pwg
);
4548 else if (((ppd_attr
= ppdFindAttr(ppd
, "DefaultOutputOrder",
4550 !strcasecmp(ppd_attr
->value
, "Reverse")) ||
4551 (!ppd_attr
&& ppd
->manufacturer
&& /* "Compatibility heuristic" */
4552 (!strcasecmp(ppd
->manufacturer
, "epson") ||
4553 !strcasecmp(ppd
->manufacturer
, "lexmark"))))
4556 * Report that this printer has a single output bin that leaves pages face
4560 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4561 "output-bin-supported", NULL
, "face-up");
4562 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4563 "output-bin-default", NULL
, "face-up");
4567 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4568 "output-bin-supported", NULL
, "face-down");
4569 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4570 "output-bin-default", NULL
, "face-down");
4577 if (ppd
->color_device
)
4579 static const char * const output_modes
[] =
4585 ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4586 "output-mode-supported", 2, NULL
, output_modes
);
4587 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4588 "output-mode-default", NULL
, "color");
4592 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4593 "output-mode-supported", NULL
, "monochrome");
4594 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4595 "output-mode-default", NULL
, "monochrome");
4599 * Printer resolutions...
4602 if ((resolution
= ppdFindOption(ppd
, "Resolution")) == NULL
)
4603 if ((resolution
= ppdFindOption(ppd
, "JCLResolution")) == NULL
)
4604 if ((resolution
= ppdFindOption(ppd
, "SetResolution")) == NULL
)
4605 resolution
= ppdFindOption(ppd
, "CNRes_PGP");
4610 * Report all supported resolutions...
4613 attr
= ippAddResolutions(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4614 "printer-resolution-supported",
4615 resolution
->num_choices
, IPP_RES_PER_INCH
,
4618 for (i
= 0, choice
= resolution
->choices
;
4619 i
< resolution
->num_choices
;
4622 xdpi
= ydpi
= (int)strtol(choice
->choice
, (char **)&resptr
, 10);
4623 if (resptr
> choice
->choice
&& xdpi
> 0 && *resptr
== 'x')
4624 ydpi
= (int)strtol(resptr
+ 1, (char **)&resptr
, 10);
4626 if (xdpi
<= 0 || ydpi
<= 0)
4628 cupsdLogMessage(CUPSD_LOG_WARN
,
4629 "Bad resolution \"%s\" for printer %s.",
4630 choice
->choice
, p
->name
);
4634 attr
->values
[i
].resolution
.xres
= xdpi
;
4635 attr
->values
[i
].resolution
.yres
= ydpi
;
4636 attr
->values
[i
].resolution
.units
= IPP_RES_PER_INCH
;
4639 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4640 "printer-resolution-default", IPP_RES_PER_INCH
,
4644 else if ((ppd_attr
= ppdFindAttr(ppd
, "DefaultResolution", NULL
)) != NULL
&&
4648 * Just the DefaultResolution to report...
4651 xdpi
= ydpi
= (int)strtol(ppd_attr
->value
, (char **)&resptr
, 10);
4652 if (resptr
> ppd_attr
->value
&& xdpi
> 0)
4655 ydpi
= (int)strtol(resptr
+ 1, (char **)&resptr
, 10);
4660 if (xdpi
<= 0 || ydpi
<= 0)
4662 cupsdLogMessage(CUPSD_LOG_WARN
,
4663 "Bad default resolution \"%s\" for printer %s.",
4664 ppd_attr
->value
, p
->name
);
4668 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4669 "printer-resolution-default", IPP_RES_PER_INCH
,
4671 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4672 "printer-resolution-supported", IPP_RES_PER_INCH
,
4678 * No resolutions in PPD - make one up...
4681 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4682 "printer-resolution-default", IPP_RES_PER_INCH
,
4684 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4685 "printer-resolution-supported", IPP_RES_PER_INCH
,
4693 ppdMarkDefaults(ppd
);
4695 if ((duplex
= ppdFindOption(ppd
, "Duplex")) == NULL
)
4696 if ((duplex
= ppdFindOption(ppd
, "EFDuplex")) == NULL
)
4697 if ((duplex
= ppdFindOption(ppd
, "EFDuplexing")) == NULL
)
4698 if ((duplex
= ppdFindOption(ppd
, "KD03Duplex")) == NULL
)
4699 duplex
= ppdFindOption(ppd
, "JCLDuplex");
4701 if (duplex
&& duplex
->num_choices
> 1 &&
4702 !ppdInstallableConflict(ppd
, duplex
->keyword
, "DuplexTumble"))
4704 p
->type
|= CUPS_PRINTER_DUPLEX
;
4706 ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4707 "sides-supported", 3, NULL
, sides
);
4709 if (!strcasecmp(duplex
->defchoice
, "DuplexTumble"))
4710 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4711 "sides-default", NULL
, "two-sided-short-edge");
4712 else if (!strcasecmp(duplex
->defchoice
, "DuplexNoTumble"))
4713 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4714 "sides-default", NULL
, "two-sided-long-edge");
4716 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4717 "sides-default", NULL
, "one-sided");
4721 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4722 "sides-supported", NULL
, "one-sided");
4723 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4724 "sides-default", NULL
, "one-sided");
4727 if (ppdFindOption(ppd
, "Collate") != NULL
)
4728 p
->type
|= CUPS_PRINTER_COLLATE
;
4730 if (ppdFindOption(ppd
, "StapleLocation") != NULL
)
4732 p
->type
|= CUPS_PRINTER_STAPLE
;
4733 finishings
[num_finishings
++] = IPP_FINISHINGS_STAPLE
;
4736 if (ppdFindOption(ppd
, "BindEdge") != NULL
)
4738 p
->type
|= CUPS_PRINTER_BIND
;
4739 finishings
[num_finishings
++] = IPP_FINISHINGS_BIND
;
4742 for (i
= 0; i
< ppd
->num_sizes
; i
++)
4743 if (ppd
->sizes
[i
].length
> 1728)
4744 p
->type
|= CUPS_PRINTER_LARGE
;
4745 else if (ppd
->sizes
[i
].length
> 1008)
4746 p
->type
|= CUPS_PRINTER_MEDIUM
;
4748 p
->type
|= CUPS_PRINTER_SMALL
;
4750 if ((ppd_attr
= ppdFindAttr(ppd
, "APICADriver", NULL
)) != NULL
&&
4751 ppd_attr
->value
&& !strcasecmp(ppd_attr
->value
, "true"))
4753 if ((ppd_attr
= ppdFindAttr(ppd
, "APScannerOnly", NULL
)) != NULL
&&
4754 ppd_attr
->value
&& !strcasecmp(ppd_attr
->value
, "true"))
4755 p
->type
|= CUPS_PRINTER_SCANNER
;
4757 p
->type
|= CUPS_PRINTER_MFP
;
4761 * Add a filter from application/vnd.cups-raw to printer/name to
4762 * handle "raw" printing by users.
4765 add_string_array(&(p
->filters
), "application/vnd.cups-raw 0 -");
4768 * Add any pre-filters in the PPD file...
4771 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsPreFilter", NULL
)) != NULL
)
4773 for (; ppd_attr
; ppd_attr
= ppdFindNextAttr(ppd
, "cupsPreFilter", NULL
))
4774 if (ppd_attr
->value
)
4775 add_string_array(&(p
->pre_filters
), ppd_attr
->value
);
4779 * Add any filters in the PPD file...
4782 DEBUG_printf(("ppd->num_filters = %d\n", ppd
->num_filters
));
4783 for (i
= 0; i
< ppd
->num_filters
; i
++)
4785 DEBUG_printf(("ppd->filters[%d] = \"%s\"\n", i
, ppd
->filters
[i
]));
4786 add_string_array(&(p
->filters
), ppd
->filters
[i
]);
4788 if (!strncasecmp(ppd
->filters
[i
], "application/vnd.cups-command", 28) &&
4789 isspace(ppd
->filters
[i
][28] & 255))
4790 p
->type
|= CUPS_PRINTER_COMMANDS
;
4793 if (ppd
->num_filters
== 0)
4796 * If there are no filters, add PostScript printing filters.
4799 add_string_array(&(p
->filters
),
4800 "application/vnd.cups-command 0 commandtops");
4801 add_string_array(&(p
->filters
),
4802 "application/vnd.cups-postscript 0 -");
4804 p
->type
|= CUPS_PRINTER_COMMANDS
;
4806 else if (!(p
->type
& CUPS_PRINTER_COMMANDS
))
4809 * See if this is a PostScript device without a command filter...
4812 for (i
= 0; i
< ppd
->num_filters
; i
++)
4813 if (!strncasecmp(ppd
->filters
[i
],
4814 "application/vnd.cups-postscript", 31) &&
4815 isspace(ppd
->filters
[i
][31] & 255))
4818 if (i
< ppd
->num_filters
)
4821 * Add the generic PostScript command filter...
4824 add_string_array(&(p
->filters
),
4825 "application/vnd.cups-command 0 commandtops");
4826 p
->type
|= CUPS_PRINTER_COMMANDS
;
4830 if (p
->type
& CUPS_PRINTER_COMMANDS
)
4832 char *commands
, /* Copy of commands */
4833 *start
, /* Start of name */
4834 *end
; /* End of name */
4835 int count
; /* Number of commands */
4838 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsCommands", NULL
)) != NULL
&&
4839 ppd_attr
->value
&& ppd_attr
->value
[0])
4841 for (count
= 0, start
= ppd_attr
->value
; *start
; count
++)
4843 while (isspace(*start
& 255))
4849 while (*start
&& !isspace(*start
& 255))
4859 * Make a copy of the commands string and count how many ...
4862 attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4863 "printer-commands", count
, NULL
, NULL
);
4865 commands
= strdup(ppd_attr
->value
);
4867 for (count
= 0, start
= commands
; *start
; count
++)
4869 while (isspace(*start
& 255))
4876 while (*end
&& !isspace(*end
& 255))
4882 attr
->values
[count
].string
.text
= _cupsStrAlloc(start
);
4892 * Add the standard list of commands...
4895 ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4897 (int)(sizeof(standard_commands
) /
4898 sizeof(standard_commands
[0])), NULL
,
4905 * No commands supported...
4908 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4909 "printer-commands", NULL
, "none");
4913 * Show current and available port monitors for this printer...
4916 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
, "port-monitor",
4917 NULL
, p
->port_monitor
? p
->port_monitor
: "none");
4919 for (i
= 1, ppd_attr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
4921 i
++, ppd_attr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
));
4925 if (strstr(ppd
->protocols
, "TBCP"))
4927 else if (strstr(ppd
->protocols
, "BCP"))
4931 attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
4932 "port-monitor-supported", i
, NULL
, NULL
);
4934 attr
->values
[0].string
.text
= _cupsStrAlloc("none");
4936 for (i
= 1, ppd_attr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
4938 i
++, ppd_attr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
))
4939 attr
->values
[i
].string
.text
= _cupsStrAlloc(ppd_attr
->value
);
4943 if (strstr(ppd
->protocols
, "TBCP"))
4944 attr
->values
[i
].string
.text
= _cupsStrAlloc("tbcp");
4945 else if (strstr(ppd
->protocols
, "BCP"))
4946 attr
->values
[i
].string
.text
= _cupsStrAlloc("bcp");
4950 cupsdSetString(&p
->product
, ppd
->product
);
4951 #endif /* HAVE_DNSSD */
4953 if (ppdFindAttr(ppd
, "APRemoteQueueID", NULL
))
4954 p
->type
|= CUPS_PRINTER_REMOTE
;
4956 #ifdef HAVE_APPLICATIONSERVICES_H
4958 * Convert the file referenced in APPrinterIconPath to a 128x128 PNG
4959 * and save it as cacheDir/printername.png
4962 if ((ppd_attr
= ppdFindAttr(ppd
, "APPrinterIconPath", NULL
)) != NULL
&&
4965 CGImageRef imageRef
= NULL
;/* Current icon image */
4966 CGImageRef biggestIconRef
= NULL
;
4967 /* Biggest icon image */
4968 CGImageRef closestTo128IconRef
= NULL
;
4969 /* Icon image closest to and >= 128 */
4970 CGImageSourceRef sourceRef
; /* The file's image source */
4971 char outPath
[HTTP_MAX_URI
];
4972 /* The path to the PNG file */
4973 CFURLRef outUrl
; /* The URL made from the outPath */
4974 CFURLRef icnsFileUrl
; /* The URL of the original ICNS icon file */
4975 CGImageDestinationRef destRef
; /* The image destination to write */
4976 size_t bytesPerRow
; /* The bytes per row used for resizing */
4977 CGContextRef context
; /* The CG context used for resizing */
4979 snprintf(outPath
, sizeof(outPath
), "%s/%s.png", CacheDir
, p
->name
);
4980 outUrl
= CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault
,
4984 icnsFileUrl
= CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault
,
4985 (UInt8
*)ppd_attr
->value
,
4986 strlen(ppd_attr
->value
),
4988 if (outUrl
&& icnsFileUrl
)
4990 sourceRef
= CGImageSourceCreateWithURL(icnsFileUrl
, NULL
);
4993 for (i
= 0; i
< CGImageSourceGetCount(sourceRef
); i
++)
4995 imageRef
= CGImageSourceCreateImageAtIndex(sourceRef
, i
, NULL
);
4997 CGImageGetWidth(imageRef
) == CGImageGetHeight(imageRef
))
5000 * Loop through remembering the icon closest to 128 but >= 128
5001 * and then remember the largest icon.
5004 if (CGImageGetWidth(imageRef
) >= 128 &&
5005 (!closestTo128IconRef
||
5006 CGImageGetWidth(imageRef
) <
5007 CGImageGetWidth(closestTo128IconRef
)))
5009 CGImageRelease(closestTo128IconRef
);
5010 CGImageRetain(imageRef
);
5011 closestTo128IconRef
= imageRef
;
5014 if (!biggestIconRef
||
5015 CGImageGetWidth(imageRef
) > CGImageGetWidth(biggestIconRef
))
5017 CGImageRelease(biggestIconRef
);
5018 CGImageRetain(imageRef
);
5019 biggestIconRef
= imageRef
;
5022 CGImageRelease(imageRef
);
5029 * If biggestIconRef is NULL, we found no icons. Otherwise we first
5030 * want the closest to 128, but if none are larger than 128, we want
5031 * the largest icon available.
5034 imageRef
= closestTo128IconRef
? closestTo128IconRef
:
5036 CGImageRetain(imageRef
);
5037 CGImageRelease(biggestIconRef
);
5038 CGImageRelease(closestTo128IconRef
);
5039 destRef
= CGImageDestinationCreateWithURL(outUrl
, kUTTypePNG
, 1,
5043 if (CGImageGetWidth(imageRef
) != 128)
5045 bytesPerRow
= CGImageGetBytesPerRow(imageRef
) /
5046 CGImageGetWidth(imageRef
) * 128;
5047 context
= CGBitmapContextCreate(NULL
, 128, 128,
5048 CGImageGetBitsPerComponent(imageRef
),
5050 CGImageGetColorSpace(imageRef
),
5051 kCGImageAlphaPremultipliedFirst
);
5054 CGContextDrawImage(context
, CGRectMake(0, 0, 128, 128),
5056 CGImageRelease(imageRef
);
5057 imageRef
= CGBitmapContextCreateImage(context
);
5058 CGContextRelease(context
);
5062 CGImageDestinationAddImage(destRef
, imageRef
, NULL
);
5063 CGImageDestinationFinalize(destRef
);
5067 CGImageRelease(imageRef
);
5070 CFRelease(sourceRef
);
5071 CFRelease(icnsFileUrl
);
5077 #endif /* HAVE_APPLICATIONSERVICES_H */
5080 * Close the PPD and set the type...
5085 else if (!access(ppd_name
, 0))
5087 int pline
; /* PPD line number */
5088 ppd_status_t pstatus
; /* PPD load status */
5091 pstatus
= ppdLastError(&pline
);
5093 cupsdLogMessage(CUPSD_LOG_ERROR
, "PPD file for %s cannot be loaded!",
5096 if (pstatus
<= PPD_ALLOC_ERROR
)
5097 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s", strerror(errno
));
5099 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s on line %d.",
5100 ppdErrorString(pstatus
), pline
);
5102 cupsdLogMessage(CUPSD_LOG_INFO
,
5103 "Hint: Run \"cupstestppd %s\" and fix any errors.",
5107 * Add a filter from application/vnd.cups-raw to printer/name to
5108 * handle "raw" printing by users.
5111 add_string_array(&(p
->filters
), "application/vnd.cups-raw 0 -");
5114 * Add a PostScript filter, since this is still possibly PS printer.
5117 add_string_array(&(p
->filters
), "application/vnd.cups-postscript 0 -");
5122 * If we have an interface script, add a filter entry for it...
5125 char interface
[1024]; /* Interface script */
5128 snprintf(interface
, sizeof(interface
), "%s/interfaces/%s", ServerRoot
,
5130 if (!access(interface
, X_OK
))
5133 * Yes, we have a System V style interface script; use it!
5136 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
5137 "printer-make-and-model", NULL
,
5138 "Local System V Printer");
5140 snprintf(interface
, sizeof(interface
), "*/* 0 %s/interfaces/%s",
5141 ServerRoot
, p
->name
);
5142 add_string_array(&(p
->filters
), interface
);
5144 else if (!strncmp(p
->device_uri
, "ipp://", 6) &&
5145 (strstr(p
->device_uri
, "/printers/") != NULL
||
5146 strstr(p
->device_uri
, "/classes/") != NULL
||
5147 (strstr(p
->device_uri
, "._ipp.") != NULL
&&
5148 !strcmp(p
->device_uri
+ strlen(p
->device_uri
) - 5,
5152 * Tell the client this is really a hard-wired remote printer.
5155 p
->type
|= CUPS_PRINTER_REMOTE
;
5158 * Point the printer-uri-supported attribute to the
5162 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
5163 "printer-uri-supported", NULL
, p
->device_uri
);
5166 * Then set the make-and-model accordingly...
5169 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
5170 "printer-make-and-model", NULL
, "Remote Printer");
5173 * Print all files directly...
5182 * Otherwise we have neither - treat this as a "dumb" printer
5183 * with no PPD file...
5186 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
5187 "printer-make-and-model", NULL
, "Local Raw Printer");
5193 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
5194 "finishings-supported", num_finishings
, finishings
);
5195 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
5196 "finishings-default", IPP_FINISHINGS_NONE
);
5198 if (ppd
&& (cache
= cupsFileOpen(cache_name
, "w9")) != NULL
)
5201 * Save cached PPD attributes to disk...
5204 cupsdLogMessage(CUPSD_LOG_DEBUG
, "load_ppd: Saving %s...", cache_name
);
5206 p
->ppd_attrs
->state
= IPP_IDLE
;
5208 if (ippWriteIO(cache
, (ipp_iocb_t
)cupsFileWrite
, 1, NULL
,
5209 p
->ppd_attrs
) != IPP_DATA
)
5211 cupsdLogMessage(CUPSD_LOG_ERROR
,
5212 "Unable to save PPD cache file \"%s\" - %s", cache_name
,
5217 cupsFileClose(cache
);
5219 _pwgWriteFile(p
->pwg
, pwg_name
);
5224 * Remove cache files...
5227 if (cache_info
.st_mtime
)
5230 if (pwg_info
.st_mtime
)
5237 * 'new_media_col()' - Create a media-col collection value.
5240 static ipp_t
* /* O - Collection value */
5241 new_media_col(_pwg_size_t
*size
, /* I - media-size/margin values */
5242 const char *source
, /* I - media-source value */
5243 const char *type
) /* I - media-type value */
5245 ipp_t
*media_col
, /* Collection value */
5246 *media_size
; /* media-size value */
5249 media_col
= ippNew();
5251 media_size
= ippNew();
5252 ippAddInteger(media_size
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5253 "x-dimension", size
->width
);
5254 ippAddInteger(media_size
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5255 "y-dimension", size
->length
);
5256 ippAddCollection(media_col
, IPP_TAG_PRINTER
, "media-size", media_size
);
5257 ippDelete(media_size
);
5259 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5260 "media-bottom-margin", size
->bottom
);
5261 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5262 "media-left-margin", size
->left
);
5263 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5264 "media-right-margin", size
->right
);
5265 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5266 "media-top-margin", size
->top
);
5269 ippAddString(media_col
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
, "media-source",
5273 ippAddString(media_col
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
, "media-type",
5282 * 'write_irix_config()' - Update the config files used by the IRIX
5287 write_irix_config(cupsd_printer_t
*p
) /* I - Printer to update */
5289 char filename
[1024]; /* Interface script filename */
5290 cups_file_t
*fp
; /* Interface script file */
5291 ipp_attribute_t
*attr
; /* Attribute data */
5295 * Add dummy interface and GUI scripts to fool SGI's "challenged" printing
5296 * tools. First the interface script that tells the tools what kind of
5297 * printer we have...
5300 snprintf(filename
, sizeof(filename
), "/var/spool/lp/interface/%s", p
->name
);
5302 if (p
->type
& CUPS_PRINTER_CLASS
)
5304 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
5306 cupsFilePuts(fp
, "#!/bin/sh\n");
5308 if ((attr
= ippFindAttribute(p
->attrs
, "printer-make-and-model",
5309 IPP_TAG_TEXT
)) != NULL
)
5310 cupsFilePrintf(fp
, "NAME=\"%s\"\n", attr
->values
[0].string
.text
);
5311 else if (p
->type
& CUPS_PRINTER_CLASS
)
5312 cupsFilePuts(fp
, "NAME=\"Printer Class\"\n");
5314 cupsFilePuts(fp
, "NAME=\"Remote Destination\"\n");
5316 if (p
->type
& CUPS_PRINTER_COLOR
)
5317 cupsFilePuts(fp
, "TYPE=ColorPostScript\n");
5319 cupsFilePuts(fp
, "TYPE=MonoPostScript\n");
5321 cupsFilePrintf(fp
, "HOSTNAME=%s\n", ServerName
);
5322 cupsFilePrintf(fp
, "HOSTPRINTER=%s\n", p
->name
);
5326 chmod(filename
, 0755);
5327 chown(filename
, User
, Group
);
5331 * Then the member file that tells which device file the queue is connected
5332 * to... Networked printers use "/dev/null" in this file, so that's what
5333 * we use (the actual device URI can confuse some apps...)
5336 snprintf(filename
, sizeof(filename
), "/var/spool/lp/member/%s", p
->name
);
5338 if (p
->type
& CUPS_PRINTER_CLASS
)
5340 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
5342 cupsFilePuts(fp
, "/dev/null\n");
5346 chmod(filename
, 0644);
5347 chown(filename
, User
, Group
);
5351 * The gui_interface file is a script or program that launches a GUI
5352 * option panel for the printer, using options specified on the
5353 * command-line in the third argument. The option panel must send
5354 * any printing options to stdout on a single line when the user
5355 * accepts them, or nothing if the user cancels the dialog.
5357 * The default options panel program is /usr/bin/glpoptions, from
5358 * the ESP Print Pro software. You can select another using the
5359 * PrintcapGUI option.
5362 snprintf(filename
, sizeof(filename
), "/var/spool/lp/gui_interface/ELF/%s.gui", p
->name
);
5364 if (p
->type
& CUPS_PRINTER_CLASS
)
5366 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
5368 cupsFilePuts(fp
, "#!/bin/sh\n");
5369 cupsFilePrintf(fp
, "%s -d %s -o \"$3\"\n", PrintcapGUI
, p
->name
);
5373 chmod(filename
, 0755);
5374 chown(filename
, User
, Group
);
5378 * The POD config file is needed by the printstatus command to show
5379 * the printer location and device.
5382 snprintf(filename
, sizeof(filename
), "/var/spool/lp/pod/%s.config", p
->name
);
5384 if (p
->type
& CUPS_PRINTER_CLASS
)
5386 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
5388 cupsFilePrintf(fp
, "Printer Class | %s\n",
5389 (p
->type
& CUPS_PRINTER_COLOR
) ? "ColorPostScript" : "MonoPostScript");
5390 cupsFilePrintf(fp
, "Printer Model | %s\n", p
->make_model
? p
->make_model
: "");
5391 cupsFilePrintf(fp
, "Location Code | %s\n", p
->location
? p
->location
: "");
5392 cupsFilePrintf(fp
, "Physical Location | %s\n", p
->info
? p
->info
: "");
5393 cupsFilePrintf(fp
, "Port Path | %s\n", p
->device_uri
);
5394 cupsFilePrintf(fp
, "Config Path | /var/spool/lp/pod/%s.config\n", p
->name
);
5395 cupsFilePrintf(fp
, "Active Status Path | /var/spool/lp/pod/%s.status\n", p
->name
);
5396 cupsFilePuts(fp
, "Status Update Wait | 10 seconds\n");
5400 chmod(filename
, 0664);
5401 chown(filename
, User
, Group
);
5407 * 'write_irix_state()' - Update the status files used by IRIX printing
5412 write_irix_state(cupsd_printer_t
*p
) /* I - Printer to update */
5414 char filename
[1024]; /* Interface script filename */
5415 cups_file_t
*fp
; /* Interface script file */
5416 int tag
; /* Status tag value */
5422 * The POD status file is needed for the printstatus window to
5423 * provide the current status of the printer.
5426 snprintf(filename
, sizeof(filename
), "/var/spool/lp/pod/%s.status", p
->name
);
5428 if (p
->type
& CUPS_PRINTER_CLASS
)
5430 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
5432 cupsFilePrintf(fp
, "Operational Status | %s\n",
5433 (p
->state
== IPP_PRINTER_IDLE
) ? "Idle" :
5434 (p
->state
== IPP_PRINTER_PROCESSING
) ? "Busy" :
5436 cupsFilePrintf(fp
, "Information | 01 00 00 | %s\n", CUPS_SVERSION
);
5437 cupsFilePrintf(fp
, "Information | 02 00 00 | Device URI: %s\n",
5439 cupsFilePrintf(fp
, "Information | 03 00 00 | %s jobs\n",
5440 p
->accepting
? "Accepting" : "Not accepting");
5441 cupsFilePrintf(fp
, "Information | 04 00 00 | %s\n", p
->state_message
);
5445 chmod(filename
, 0664);
5446 chown(filename
, User
, Group
);
5450 * The activeicons file is needed to provide desktop icons for printers:
5452 * [ quoted from /usr/lib/print/tagit ]
5454 * --- Type of printer tags (base values)
5456 * Dumb=66048 # 0x10200
5457 * DumbColor=66080 # 0x10220
5458 * Raster=66112 # 0x10240
5459 * ColorRaster=66144 # 0x10260
5460 * Plotter=66176 # 0x10280
5461 * PostScript=66208 # 0x102A0
5462 * ColorPostScript=66240 # 0x102C0
5463 * MonoPostScript=66272 # 0x102E0
5465 * --- Printer state modifiers for local printers
5470 * Unknown=3 # 0x3 (Faulted due to unknown reason)
5472 * --- Printer state modifiers for network printers
5476 * NetFaulted=10 # 0xA
5477 * NetUnknown=11 # 0xB (Faulted due to unknown reason)
5480 snprintf(filename
, sizeof(filename
), "/var/spool/lp/activeicons/%s", p
->name
);
5482 if (p
->type
& CUPS_PRINTER_CLASS
)
5484 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
5486 if (p
->type
& CUPS_PRINTER_COLOR
)
5491 if (p
->type
& CUPS_PRINTER_REMOTE
)
5494 if (p
->state
== IPP_PRINTER_PROCESSING
)
5497 else if (p
->state
== IPP_PRINTER_STOPPED
)
5500 cupsFilePuts(fp
, "#!/bin/sh\n");
5501 cupsFilePrintf(fp
, "#Tag %d\n", tag
);
5505 chmod(filename
, 0755);
5506 chown(filename
, User
, Group
);
5511 * The default file is needed by the printers window to show
5512 * the default printer.
5515 snprintf(filename
, sizeof(filename
), "/var/spool/lp/default");
5517 if (DefaultPrinter
!= NULL
)
5519 if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
5521 cupsFilePrintf(fp
, "%s\n", DefaultPrinter
->name
);
5525 chmod(filename
, 0644);
5526 chown(filename
, User
, Group
);
5536 * 'write_xml_string()' - Write a string with XML escaping.
5540 write_xml_string(cups_file_t
*fp
, /* I - File to write to */
5541 const char *s
) /* I - String to write */
5543 const char *start
; /* Start of current sequence */
5549 for (start
= s
; *s
; s
++)
5554 cupsFileWrite(fp
, start
, s
- start
);
5556 cupsFilePuts(fp
, "&");
5562 cupsFileWrite(fp
, start
, s
- start
);
5564 cupsFilePuts(fp
, "<");
5570 cupsFilePuts(fp
, start
);
5575 * End of "$Id: printers.c 7968 2008-09-19 23:03:01Z mike $".