2 * "$Id: printers.c 7968 2008-09-19 23:03:01Z mike $"
4 * Printer routines for the Common UNIX Printing System (CUPS).
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...
74 static void add_printer_defaults(cupsd_printer_t
*p
);
75 static void add_printer_filter(cupsd_printer_t
*p
, mime_type_t
*type
,
77 static void add_printer_formats(cupsd_printer_t
*p
);
78 static void add_string_array(cups_array_t
**a
, const char *s
);
79 static int compare_printers(void *first
, void *second
, void *data
);
80 static void delete_printer_filters(cupsd_printer_t
*p
);
81 static void delete_string_array(cups_array_t
**a
);
82 static void load_ppd(cupsd_printer_t
*p
);
83 static ipp_t
*new_media_col(_pwg_size_t
*size
, const char *source
,
86 static void write_irix_config(cupsd_printer_t
*p
);
87 static void write_irix_state(cupsd_printer_t
*p
);
89 static void write_xml_string(cups_file_t
*fp
, const char *s
);
93 * 'cupsdAddPrinter()' - Add a printer to the system.
96 cupsd_printer_t
* /* O - New printer */
97 cupsdAddPrinter(const char *name
) /* I - Name of printer */
99 cupsd_printer_t
*p
; /* New printer */
103 * Range check input...
106 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdAddPrinter(\"%s\")", name
);
109 * Create a new printer entity...
112 if ((p
= calloc(1, sizeof(cupsd_printer_t
))) == NULL
)
114 cupsdLogMessage(CUPSD_LOG_CRIT
, "Unable to allocate memory for printer - %s",
119 cupsdSetString(&p
->name
, name
);
120 cupsdSetString(&p
->info
, name
);
121 cupsdSetString(&p
->hostname
, ServerName
);
123 cupsdSetStringf(&p
->uri
, "ipp://%s:%d/printers/%s", ServerName
, RemotePort
,
125 cupsdSetDeviceURI(p
, "file:///dev/null");
127 p
->state
= IPP_PRINTER_STOPPED
;
128 p
->state_time
= time(NULL
);
130 p
->shared
= DefaultShared
;
131 p
->filetype
= mimeAddType(MimeDatabase
, "printer", name
);
133 cupsdSetString(&p
->job_sheets
[0], "none");
134 cupsdSetString(&p
->job_sheets
[1], "none");
136 cupsdSetString(&p
->error_policy
, ErrorPolicy
);
137 cupsdSetString(&p
->op_policy
, DefaultPolicy
);
139 p
->op_policy_ptr
= DefaultPolicyPtr
;
141 if (MaxPrinterHistory
)
142 p
->history
= calloc(MaxPrinterHistory
, sizeof(ipp_t
*));
145 * Insert the printer in the printer list alphabetically...
149 Printers
= cupsArrayNew(compare_printers
, NULL
);
151 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
152 "cupsdAddPrinter: Adding %s to Printers", p
->name
);
153 cupsArrayAdd(Printers
, p
);
155 if (!ImplicitPrinters
)
156 ImplicitPrinters
= cupsArrayNew(compare_printers
, NULL
);
159 * Return the new printer...
167 * 'cupsdAddPrinterHistory()' - Add the current printer state to the history.
171 cupsdAddPrinterHistory(
172 cupsd_printer_t
*p
) /* I - Printer */
174 ipp_t
*history
; /* History collection */
178 * Stop early if we aren't keeping history data...
181 if (MaxPrinterHistory
<= 0)
185 * Retire old history data as needed...
188 p
->sequence_number
++;
190 if (p
->num_history
>= MaxPrinterHistory
)
193 ippDelete(p
->history
[0]);
194 memmove(p
->history
, p
->history
+ 1, p
->num_history
* sizeof(ipp_t
*));
198 * Create a collection containing the current printer-state, printer-up-time,
199 * printer-state-message, and printer-state-reasons attributes.
203 ippAddInteger(history
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-state",
205 ippAddBoolean(history
, IPP_TAG_PRINTER
, "printer-is-accepting-jobs",
207 ippAddBoolean(history
, IPP_TAG_PRINTER
, "printer-is-shared", p
->shared
);
208 ippAddString(history
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-state-message",
209 NULL
, p
->state_message
);
210 if (p
->num_reasons
== 0)
211 ippAddString(history
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
212 "printer-state-reasons", NULL
, "none");
214 ippAddStrings(history
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
215 "printer-state-reasons", p
->num_reasons
, NULL
,
216 (const char * const *)p
->reasons
);
217 ippAddInteger(history
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
218 "printer-state-change-time", p
->state_time
);
219 ippAddInteger(history
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
220 "printer-state-sequence-number", p
->sequence_number
);
222 p
->history
[p
->num_history
] = history
;
228 * 'cupsdAddPrinterUser()' - Add a user to the ACL.
233 cupsd_printer_t
*p
, /* I - Printer */
234 const char *username
) /* I - User */
236 const char **temp
; /* Temporary array pointer */
242 if (p
->num_users
== 0)
243 temp
= malloc(sizeof(char **));
245 temp
= realloc(p
->users
, sizeof(char **) * (p
->num_users
+ 1));
251 temp
+= p
->num_users
;
253 if ((*temp
= strdup(username
)) != NULL
)
259 * 'cupsdCreateCommonData()' - Create the common printer data.
263 cupsdCreateCommonData(void)
265 int i
; /* Looping var */
266 ipp_attribute_t
*attr
; /* Attribute data */
267 cups_dir_t
*dir
; /* Notifier directory */
268 cups_dentry_t
*dent
; /* Notifier directory entry */
269 cups_array_t
*notifiers
; /* Notifier array */
270 char filename
[1024], /* Filename */
271 *notifier
; /* Current notifier */
272 cupsd_policy_t
*p
; /* Current policy */
273 static const int nups
[] = /* number-up-supported values */
274 { 1, 2, 4, 6, 9, 16 };
275 static const int orients
[4] =/* orientation-requested-supported values */
279 IPP_REVERSE_LANDSCAPE
,
282 static const char * const holds
[] = /* job-hold-until-supported values */
293 static const char * const versions
[] =/* ipp-versions-supported values */
300 static const int ops
[] = /* operations-supported values */
307 IPP_GET_JOB_ATTRIBUTES
,
309 IPP_GET_PRINTER_ATTRIBUTES
,
316 IPP_SET_PRINTER_ATTRIBUTES
,
317 IPP_SET_JOB_ATTRIBUTES
,
318 IPP_GET_PRINTER_SUPPORTED_VALUES
,
319 IPP_CREATE_PRINTER_SUBSCRIPTION
,
320 IPP_CREATE_JOB_SUBSCRIPTION
,
321 IPP_GET_SUBSCRIPTION_ATTRIBUTES
,
322 IPP_GET_SUBSCRIPTIONS
,
323 IPP_RENEW_SUBSCRIPTION
,
324 IPP_CANCEL_SUBSCRIPTION
,
325 IPP_GET_NOTIFICATIONS
,
329 IPP_RELEASE_HELD_NEW_JOBS
,
346 CUPS_AUTHENTICATE_JOB
,
351 static const char * const charsets
[] =/* charset-supported values */
356 static const char * const compressions
[] =
357 { /* document-compression-supported values */
361 #endif /* HAVE_LIBZ */
363 static const char * const media_col_supported
[] =
364 { /* media-col-supported values */
365 "media-bottom-margin",
367 "media-right-margin",
373 static const char * const multiple_document_handling
[] =
374 { /* multiple-document-handling-supported values */
375 "separate-documents-uncollated-copies",
376 "separate-documents-collated-copies"
378 static const char * const notify_attrs
[] =
379 { /* notify-attributes-supported values */
380 "printer-state-change-time",
381 "notify-lease-expiration-time",
382 "notify-subscriber-user-name"
384 static const char * const notify_events
[] =
385 { /* notify-events-supported values */
387 "job-config-changed",
394 "printer-config-changed",
396 "printer-finishings-changed",
397 "printer-media-changed",
401 "printer-state-changed",
408 static const char * const job_creation
[] =
409 { /* job-creation-attributes-supported */
412 "ipp-attribute-fidelity",
419 "multiple-document-handling",
422 "orientation-requested",
425 "printer-resolution",
428 static const char * const job_settable
[] =
429 { /* job-settable-attributes-supported */
437 "multiple-document-handling",
440 "orientation-requested",
443 "printer-resolution",
446 static const char * const printer_settable
[] =
447 { /* printer-settable-attributes-supported */
451 static const char * const which_jobs
[] =
452 { /* which-jobs-supported values */
466 ippDelete(CommonData
);
468 CommonData
= ippNew();
471 * This list of attributes is sorted to improve performance when the
472 * client provides a requested-attributes attribute...
475 /* charset-configured */
476 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_CHARSET
| IPP_TAG_COPY
,
477 "charset-configured", NULL
, "utf-8");
479 /* charset-supported */
480 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_CHARSET
| IPP_TAG_COPY
,
481 "charset-supported", sizeof(charsets
) / sizeof(charsets
[0]),
484 /* compression-supported */
485 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
486 "compression-supported",
487 sizeof(compressions
) / sizeof(compressions
[0]),
490 /* copies-supported */
491 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "copies-supported", 1, MaxCopies
);
494 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
| IPP_TAG_COPY
,
495 "cups-version", NULL
, CUPS_SVERSION
+ 6);
497 /* generated-natural-language-supported (no IPP_TAG_COPY) */
498 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_LANGUAGE
,
499 "generated-natural-language-supported", NULL
, DefaultLanguage
);
501 /* ipp-versions-supported */
502 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
503 "ipp-versions-supported", sizeof(versions
) / sizeof(versions
[0]),
506 /* ippget-event-life */
507 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
508 "ippget-event-life", 15);
510 /* job-creation-attributes-supported */
511 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
512 "job-creation-attributes-supported",
513 sizeof(job_creation
) / sizeof(job_creation
[0]),
516 /* job-hold-until-supported */
517 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
518 "job-hold-until-supported", sizeof(holds
) / sizeof(holds
[0]),
521 /* job-ids-supported */
522 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
, "job-ids-supported", 1);
524 /* job-priority-supported */
525 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
526 "job-priority-supported", 100);
528 /* job-settable-attributes-supported */
529 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
530 "job-settable-attributes-supported",
531 sizeof(job_settable
) / sizeof(job_settable
[0]),
534 /* job-sheets-supported */
535 if (cupsArrayCount(Banners
) > 0)
538 * Setup the job-sheets-supported attribute...
541 if (Classification
&& !ClassifyOverride
)
542 attr
= ippAddString(CommonData
, IPP_TAG_PRINTER
,
543 IPP_TAG_NAME
| IPP_TAG_COPY
,
544 "job-sheets-supported", NULL
, Classification
);
546 attr
= ippAddStrings(CommonData
, IPP_TAG_PRINTER
,
547 IPP_TAG_NAME
| IPP_TAG_COPY
,
548 "job-sheets-supported", cupsArrayCount(Banners
) + 1,
552 cupsdLogMessage(CUPSD_LOG_EMERG
,
553 "Unable to allocate memory for "
554 "job-sheets-supported attribute: %s!", strerror(errno
));
555 else if (!Classification
|| ClassifyOverride
)
557 cupsd_banner_t
*banner
; /* Current banner */
560 attr
->values
[0].string
.text
= _cupsStrAlloc("none");
562 for (i
= 1, banner
= (cupsd_banner_t
*)cupsArrayFirst(Banners
);
564 i
++, banner
= (cupsd_banner_t
*)cupsArrayNext(Banners
))
565 attr
->values
[i
].string
.text
= banner
->name
;
569 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
570 "job-sheets-supported", NULL
, "none");
572 /* media-col-supported */
573 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
574 "media-col-supported",
575 sizeof(media_col_supported
) /
576 sizeof(media_col_supported
[0]), NULL
,
577 media_col_supported
);
579 /* multiple-document-handling-supported */
580 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
581 "multiple-document-handling-supported",
582 sizeof(multiple_document_handling
) /
583 sizeof(multiple_document_handling
[0]), NULL
,
584 multiple_document_handling
);
586 /* multiple-document-jobs-supported */
587 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
,
588 "multiple-document-jobs-supported", 1);
590 /* multiple-operation-time-out */
591 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
592 "multiple-operation-time-out", MultipleOperationTimeout
);
594 /* natural-language-configured (no IPP_TAG_COPY) */
595 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_LANGUAGE
,
596 "natural-language-configured", NULL
, DefaultLanguage
);
598 /* notify-attributes-supported */
599 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
600 "notify-attributes-supported",
601 (int)(sizeof(notify_attrs
) / sizeof(notify_attrs
[0])),
604 /* notify-lease-duration-supported */
605 ippAddRange(CommonData
, IPP_TAG_PRINTER
,
606 "notify-lease-duration-supported", 0,
607 MaxLeaseDuration
? MaxLeaseDuration
: 2147483647);
609 /* notify-max-events-supported */
610 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
611 "notify-max-events-supported", MaxEvents
);
613 /* notify-events-supported */
614 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
615 "notify-events-supported",
616 (int)(sizeof(notify_events
) / sizeof(notify_events
[0])),
617 NULL
, notify_events
);
619 /* notify-pull-method-supported */
620 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
621 "notify-pull-method-supported", NULL
, "ippget");
623 /* notify-schemes-supported */
624 snprintf(filename
, sizeof(filename
), "%s/notifier", ServerBin
);
625 if ((dir
= cupsDirOpen(filename
)) != NULL
)
627 notifiers
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
629 while ((dent
= cupsDirRead(dir
)) != NULL
)
630 if (S_ISREG(dent
->fileinfo
.st_mode
) &&
631 (dent
->fileinfo
.st_mode
& S_IXOTH
) != 0)
632 cupsArrayAdd(notifiers
, _cupsStrAlloc(dent
->filename
));
634 if (cupsArrayCount(notifiers
) > 0)
636 attr
= ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
637 "notify-schemes-supported",
638 cupsArrayCount(notifiers
), NULL
, NULL
);
640 for (i
= 0, notifier
= (char *)cupsArrayFirst(notifiers
);
642 i
++, notifier
= (char *)cupsArrayNext(notifiers
))
643 attr
->values
[i
].string
.text
= notifier
;
646 cupsArrayDelete(notifiers
);
650 /* number-up-supported */
651 ippAddIntegers(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
652 "number-up-supported", sizeof(nups
) / sizeof(nups
[0]), nups
);
654 /* operations-supported */
655 ippAddIntegers(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
656 "operations-supported",
657 sizeof(ops
) / sizeof(ops
[0]) + JobFiles
- 1, ops
);
659 /* orientation-requested-supported */
660 ippAddIntegers(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
661 "orientation-requested-supported", 4, orients
);
663 /* page-ranges-supported */
664 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
, "page-ranges-supported", 1);
666 /* pdf-override-supported */
667 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
668 "pdl-override-supported", NULL
, "not-attempted");
670 /* printer-op-policy-supported */
671 attr
= ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
672 "printer-op-policy-supported", cupsArrayCount(Policies
),
674 for (i
= 0, p
= (cupsd_policy_t
*)cupsArrayFirst(Policies
);
676 i
++, p
= (cupsd_policy_t
*)cupsArrayNext(Policies
))
677 attr
->values
[i
].string
.text
= p
->name
;
679 /* printer-settable-attributes-supported */
680 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
681 "printer-settable-attributes-supported",
682 sizeof(printer_settable
) / sizeof(printer_settable
[0]),
683 NULL
, printer_settable
);
685 /* server-is-sharing-printers */
686 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
, "server-is-sharing-printers",
687 BrowseLocalProtocols
!= 0 && Browsing
);
689 /* which-jobs-supported */
690 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
691 "which-jobs-supported",
692 sizeof(which_jobs
) / sizeof(which_jobs
[0]), NULL
, which_jobs
);
697 * 'cupsdDeleteAllPrinters()' - Delete all printers from the system.
701 cupsdDeleteAllPrinters(void)
703 cupsd_printer_t
*p
; /* Pointer to current printer/class */
706 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
708 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
710 p
->op_policy_ptr
= DefaultPolicyPtr
;
711 cupsdDeletePrinter(p
, 0);
717 * 'cupsdDeletePrinter()' - Delete a printer from the system.
720 int /* O - 1 if classes affected, 0 otherwise */
722 cupsd_printer_t
*p
, /* I - Printer to delete */
723 int update
) /* I - Update printers.conf? */
725 int i
, /* Looping var */
726 changed
= 0; /* Class changed? */
728 char filename
[1024]; /* Interface script filename */
732 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdDeletePrinter(p=%p(%s), update=%d)",
736 * Save the current position in the Printers array...
739 cupsArraySave(Printers
);
742 * Stop printing on this printer...
745 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, update
);
748 cupsdSetJobState(p
->job
, IPP_JOB_PENDING
, CUPSD_JOB_FORCE
,
749 update
? "Job stopped due to printer being deleted." :
753 * If this printer is the next for browsing, point to the next one...
758 cupsArrayFind(Printers
, p
);
759 BrowseNext
= (cupsd_printer_t
*)cupsArrayNext(Printers
);
763 * Remove the printer from the list...
766 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
767 "cupsdDeletePrinter: Removing %s from Printers", p
->name
);
768 cupsArrayRemove(Printers
, p
);
770 if (p
->type
& CUPS_PRINTER_IMPLICIT
)
772 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
773 "cupsdDeletePrinter: Removing %s from ImplicitPrinters",
775 cupsArrayRemove(ImplicitPrinters
, p
);
779 * Remove the dummy interface/icon/option files under IRIX...
783 snprintf(filename
, sizeof(filename
), "/var/spool/lp/interface/%s", p
->name
);
786 snprintf(filename
, sizeof(filename
), "/var/spool/lp/gui_interface/ELF/%s.gui",
790 snprintf(filename
, sizeof(filename
), "/var/spool/lp/activeicons/%s", p
->name
);
793 snprintf(filename
, sizeof(filename
), "/var/spool/lp/pod/%s.config", p
->name
);
796 snprintf(filename
, sizeof(filename
), "/var/spool/lp/pod/%s.status", p
->name
);
799 snprintf(filename
, sizeof(filename
), "/var/spool/lp/member/%s", p
->name
);
804 * If p is the default printer, assign a different one...
807 if (p
== DefaultPrinter
)
809 DefaultPrinter
= NULL
;
811 if (UseNetworkDefault
)
814 * Find the first network default printer and use it...
817 cupsd_printer_t
*dp
; /* New default printer */
820 for (dp
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
822 dp
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
823 if (dp
!= p
&& (dp
->type
& CUPS_PRINTER_DEFAULT
))
832 * Remove this printer from any classes...
835 if (!(p
->type
& CUPS_PRINTER_IMPLICIT
))
837 changed
= cupsdDeletePrinterFromClasses(p
);
840 * Deregister from any browse protocols...
843 cupsdDeregisterPrinter(p
, 1);
847 * Free all memory used by the printer...
850 if (p
->printers
!= NULL
)
853 if (MaxPrinterHistory
)
855 for (i
= 0; i
< p
->num_history
; i
++)
856 ippDelete(p
->history
[i
]);
861 delete_printer_filters(p
);
863 for (i
= 0; i
< p
->num_reasons
; i
++)
864 _cupsStrFree(p
->reasons
[i
]);
867 ippDelete(p
->ppd_attrs
);
869 mimeDeleteType(MimeDatabase
, p
->filetype
);
870 mimeDeleteType(MimeDatabase
, p
->prefiltertype
);
872 delete_string_array(&(p
->filters
));
873 delete_string_array(&(p
->pre_filters
));
875 cupsdFreePrinterUsers(p
);
878 cupsdClearString(&p
->uri
);
879 cupsdClearString(&p
->hostname
);
880 cupsdClearString(&p
->name
);
881 cupsdClearString(&p
->location
);
882 cupsdClearString(&p
->make_model
);
883 cupsdClearString(&p
->info
);
884 cupsdClearString(&p
->job_sheets
[0]);
885 cupsdClearString(&p
->job_sheets
[1]);
886 cupsdClearString(&p
->device_uri
);
887 cupsdClearString(&p
->sanitized_device_uri
);
888 cupsdClearString(&p
->port_monitor
);
889 cupsdClearString(&p
->op_policy
);
890 cupsdClearString(&p
->error_policy
);
892 cupsdClearString(&p
->alert
);
893 cupsdClearString(&p
->alert_description
);
896 cupsdClearString(&p
->product
);
897 cupsdClearString(&p
->pdl
);
898 #endif /* HAVE_DNSSD */
900 cupsArrayDelete(p
->filetypes
);
903 free(p
->browse_attrs
);
905 cupsFreeOptions(p
->num_options
, p
->options
);
910 * Restore the previous position in the Printers array...
913 cupsArrayRestore(Printers
);
920 * 'cupsdFindDest()' - Find a destination in the list.
923 cupsd_printer_t
* /* O - Destination in list */
924 cupsdFindDest(const char *name
) /* I - Name of printer or class to find */
926 cupsd_printer_t key
; /* Search key */
929 key
.name
= (char *)name
;
930 return ((cupsd_printer_t
*)cupsArrayFind(Printers
, &key
));
935 * 'cupsdFindPrinter()' - Find a printer in the list.
938 cupsd_printer_t
* /* O - Printer in list */
939 cupsdFindPrinter(const char *name
) /* I - Name of printer to find */
941 cupsd_printer_t
*p
; /* Printer in list */
944 if ((p
= cupsdFindDest(name
)) != NULL
&& (p
->type
& CUPS_PRINTER_CLASS
))
952 * 'cupsdFreePrinterUsers()' - Free allow/deny users.
956 cupsdFreePrinterUsers(
957 cupsd_printer_t
*p
) /* I - Printer */
959 int i
; /* Looping var */
962 if (!p
|| !p
->num_users
)
965 for (i
= 0; i
< p
->num_users
; i
++)
966 free((void *)p
->users
[i
]);
976 * 'cupsdLoadAllPrinters()' - Load printers from the printers.conf file.
980 cupsdLoadAllPrinters(void)
982 int i
; /* Looping var */
983 cups_file_t
*fp
; /* printers.conf file */
984 int linenum
; /* Current line number */
985 char line
[4096], /* Line from file */
986 *value
, /* Pointer to value */
987 *valueptr
; /* Pointer into value */
988 cupsd_printer_t
*p
; /* Current printer */
992 * Open the printers.conf file...
995 snprintf(line
, sizeof(line
), "%s/printers.conf", ServerRoot
);
996 if ((fp
= cupsFileOpen(line
, "r")) == NULL
)
999 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to open %s - %s", line
,
1005 * Read printer configurations until we hit EOF...
1011 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
1014 * Decode the directive...
1017 if (!strcasecmp(line
, "<Printer") ||
1018 !strcasecmp(line
, "<DefaultPrinter"))
1021 * <Printer name> or <DefaultPrinter name>
1024 if (p
== NULL
&& value
)
1027 * Add the printer and a base file type...
1030 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Loading printer %s...", value
);
1032 p
= cupsdAddPrinter(value
);
1034 p
->state
= IPP_PRINTER_IDLE
;
1037 * Set the default printer as needed...
1040 if (!strcasecmp(line
, "<DefaultPrinter"))
1044 cupsdLogMessage(CUPSD_LOG_ERROR
,
1045 "Syntax error on line %d of printers.conf.", linenum
);
1047 else if (!strcasecmp(line
, "</Printer>"))
1052 * Close out the current printer...
1055 cupsdSetPrinterAttrs(p
);
1056 cupsdAddPrinterHistory(p
);
1058 if (strncmp(p
->device_uri
, "file:", 5) &&
1059 p
->state
!= IPP_PRINTER_STOPPED
)
1062 * See if the backend exists...
1065 snprintf(line
, sizeof(line
), "%s/backend/%s", ServerBin
,
1068 if ((valueptr
= strchr(line
+ strlen(ServerBin
), ':')) != NULL
)
1069 *valueptr
= '\0'; /* Chop everything but URI scheme */
1071 if (access(line
, 0))
1074 * Backend does not exist, stop printer...
1077 p
->state
= IPP_PRINTER_STOPPED
;
1078 snprintf(p
->state_message
, sizeof(p
->state_message
),
1079 "Backend %s does not exist!", line
);
1086 cupsdLogMessage(CUPSD_LOG_ERROR
,
1087 "Syntax error on line %d of printers.conf.", linenum
);
1091 cupsdLogMessage(CUPSD_LOG_ERROR
,
1092 "Syntax error on line %d of printers.conf.", linenum
);
1094 else if (!strcasecmp(line
, "AuthInfoRequired"))
1096 if (!cupsdSetAuthInfoRequired(p
, value
, NULL
))
1097 cupsdLogMessage(CUPSD_LOG_ERROR
,
1098 "Bad AuthInfoRequired on line %d of printers.conf.",
1101 else if (!strcasecmp(line
, "Info"))
1104 cupsdSetString(&p
->info
, value
);
1106 else if (!strcasecmp(line
, "MakeModel"))
1109 cupsdSetString(&p
->make_model
, value
);
1111 else if (!strcasecmp(line
, "Location"))
1114 cupsdSetString(&p
->location
, value
);
1116 else if (!strcasecmp(line
, "DeviceURI"))
1119 cupsdSetDeviceURI(p
, value
);
1121 cupsdLogMessage(CUPSD_LOG_ERROR
,
1122 "Syntax error on line %d of printers.conf.", linenum
);
1124 else if (!strcasecmp(line
, "Option") && value
)
1130 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1133 cupsdLogMessage(CUPSD_LOG_ERROR
,
1134 "Syntax error on line %d of printers.conf.", linenum
);
1137 for (; *valueptr
&& isspace(*valueptr
& 255); *valueptr
++ = '\0');
1139 p
->num_options
= cupsAddOption(value
, valueptr
, p
->num_options
,
1143 else if (!strcasecmp(line
, "PortMonitor"))
1145 if (value
&& strcmp(value
, "none"))
1146 cupsdSetString(&p
->port_monitor
, value
);
1148 cupsdClearString(&p
->port_monitor
);
1150 cupsdLogMessage(CUPSD_LOG_ERROR
,
1151 "Syntax error on line %d of printers.conf.", linenum
);
1153 else if (!strcasecmp(line
, "Reason"))
1156 strcmp(value
, "connecting-to-device") &&
1157 strcmp(value
, "cups-insecure-filter-warning") &&
1158 strcmp(value
, "cups-missing-filter-warning"))
1160 for (i
= 0 ; i
< p
->num_reasons
; i
++)
1161 if (!strcmp(value
, p
->reasons
[i
]))
1164 if (i
>= p
->num_reasons
&&
1165 p
->num_reasons
< (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
1167 p
->reasons
[p
->num_reasons
] = _cupsStrAlloc(value
);
1172 cupsdLogMessage(CUPSD_LOG_ERROR
,
1173 "Syntax error on line %d of printers.conf.", linenum
);
1175 else if (!strcasecmp(line
, "State"))
1178 * Set the initial queue state...
1181 if (value
&& !strcasecmp(value
, "idle"))
1182 p
->state
= IPP_PRINTER_IDLE
;
1183 else if (value
&& !strcasecmp(value
, "stopped"))
1185 p
->state
= IPP_PRINTER_STOPPED
;
1187 for (i
= 0 ; i
< p
->num_reasons
; i
++)
1188 if (!strcmp("paused", p
->reasons
[i
]))
1191 if (i
>= p
->num_reasons
&&
1192 p
->num_reasons
< (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
1194 p
->reasons
[p
->num_reasons
] = _cupsStrAlloc("paused");
1199 cupsdLogMessage(CUPSD_LOG_ERROR
,
1200 "Syntax error on line %d of printers.conf.", linenum
);
1202 else if (!strcasecmp(line
, "StateMessage"))
1205 * Set the initial queue state message...
1209 strlcpy(p
->state_message
, value
, sizeof(p
->state_message
));
1211 else if (!strcasecmp(line
, "StateTime"))
1214 * Set the state time...
1218 p
->state_time
= atoi(value
);
1220 else if (!strcasecmp(line
, "Accepting"))
1223 * Set the initial accepting state...
1227 (!strcasecmp(value
, "yes") ||
1228 !strcasecmp(value
, "on") ||
1229 !strcasecmp(value
, "true")))
1232 (!strcasecmp(value
, "no") ||
1233 !strcasecmp(value
, "off") ||
1234 !strcasecmp(value
, "false")))
1237 cupsdLogMessage(CUPSD_LOG_ERROR
,
1238 "Syntax error on line %d of printers.conf.", linenum
);
1240 else if (!strcasecmp(line
, "Type"))
1243 p
->type
= atoi(value
);
1245 cupsdLogMessage(CUPSD_LOG_ERROR
,
1246 "Syntax error on line %d of printers.conf.", linenum
);
1248 else if (!strcasecmp(line
, "Product"))
1253 p
->product
= _cupsStrAlloc(value
);
1254 #endif /* HAVE_DNSSD */
1257 cupsdLogMessage(CUPSD_LOG_ERROR
,
1258 "Syntax error on line %d of printers.conf.", linenum
);
1260 else if (!strcasecmp(line
, "Filter"))
1265 p
->filters
= cupsArrayNew(NULL
, NULL
);
1267 cupsArrayAdd(p
->filters
, _cupsStrAlloc(value
));
1270 cupsdLogMessage(CUPSD_LOG_ERROR
,
1271 "Syntax error on line %d of printers.conf.", linenum
);
1273 else if (!strcasecmp(line
, "PreFilter"))
1277 if (!p
->pre_filters
)
1278 p
->pre_filters
= cupsArrayNew(NULL
, NULL
);
1280 cupsArrayAdd(p
->pre_filters
, _cupsStrAlloc(value
));
1283 cupsdLogMessage(CUPSD_LOG_ERROR
,
1284 "Syntax error on line %d of printers.conf.", linenum
);
1286 else if (!strcasecmp(line
, "Shared"))
1289 * Set the initial shared state...
1293 (!strcasecmp(value
, "yes") ||
1294 !strcasecmp(value
, "on") ||
1295 !strcasecmp(value
, "true")))
1298 (!strcasecmp(value
, "no") ||
1299 !strcasecmp(value
, "off") ||
1300 !strcasecmp(value
, "false")))
1303 cupsdLogMessage(CUPSD_LOG_ERROR
,
1304 "Syntax error on line %d of printers.conf.", linenum
);
1306 else if (!strcasecmp(line
, "JobSheets"))
1309 * Set the initial job sheets...
1314 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1319 cupsdSetString(&p
->job_sheets
[0], value
);
1321 while (isspace(*valueptr
& 255))
1326 for (value
= valueptr
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1331 cupsdSetString(&p
->job_sheets
[1], value
);
1335 cupsdLogMessage(CUPSD_LOG_ERROR
,
1336 "Syntax error on line %d of printers.conf.", linenum
);
1338 else if (!strcasecmp(line
, "AllowUser"))
1343 cupsdAddPrinterUser(p
, value
);
1346 cupsdLogMessage(CUPSD_LOG_ERROR
,
1347 "Syntax error on line %d of printers.conf.", linenum
);
1349 else if (!strcasecmp(line
, "DenyUser"))
1354 cupsdAddPrinterUser(p
, value
);
1357 cupsdLogMessage(CUPSD_LOG_ERROR
,
1358 "Syntax error on line %d of printers.conf.", linenum
);
1360 else if (!strcasecmp(line
, "QuotaPeriod"))
1363 p
->quota_period
= atoi(value
);
1365 cupsdLogMessage(CUPSD_LOG_ERROR
,
1366 "Syntax error on line %d of printers.conf.", linenum
);
1368 else if (!strcasecmp(line
, "PageLimit"))
1371 p
->page_limit
= atoi(value
);
1373 cupsdLogMessage(CUPSD_LOG_ERROR
,
1374 "Syntax error on line %d of printers.conf.", linenum
);
1376 else if (!strcasecmp(line
, "KLimit"))
1379 p
->k_limit
= atoi(value
);
1381 cupsdLogMessage(CUPSD_LOG_ERROR
,
1382 "Syntax error on line %d of printers.conf.", linenum
);
1384 else if (!strcasecmp(line
, "OpPolicy"))
1388 cupsd_policy_t
*pol
; /* Policy */
1391 if ((pol
= cupsdFindPolicy(value
)) != NULL
)
1393 cupsdSetString(&p
->op_policy
, value
);
1394 p
->op_policy_ptr
= pol
;
1397 cupsdLogMessage(CUPSD_LOG_ERROR
,
1398 "Bad policy \"%s\" on line %d of printers.conf",
1402 cupsdLogMessage(CUPSD_LOG_ERROR
,
1403 "Syntax error on line %d of printers.conf.", linenum
);
1405 else if (!strcasecmp(line
, "ErrorPolicy"))
1408 cupsdSetString(&p
->error_policy
, value
);
1410 cupsdLogMessage(CUPSD_LOG_ERROR
,
1411 "Syntax error on line %d of printers.conf.", linenum
);
1413 else if (!strcasecmp(line
, "Attribute") && value
)
1415 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1418 cupsdLogMessage(CUPSD_LOG_ERROR
,
1419 "Syntax error on line %d of printers.conf.", linenum
);
1422 for (; *valueptr
&& isspace(*valueptr
& 255); *valueptr
++ = '\0');
1425 cupsdSetPrinterAttrs(p
);
1427 if (!strcmp(value
, "marker-change-time"))
1428 p
->marker_time
= atoi(valueptr
);
1430 cupsdSetPrinterAttr(p
, value
, valueptr
);
1436 * Something else we don't understand...
1439 cupsdLogMessage(CUPSD_LOG_ERROR
,
1440 "Unknown configuration directive %s on line %d of printers.conf.",
1450 * 'cupsdRenamePrinter()' - Rename a printer.
1455 cupsd_printer_t
*p
, /* I - Printer */
1456 const char *name
) /* I - New name */
1459 * Remove the printer from the array(s) first...
1462 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1463 "cupsdRenamePrinter: Removing %s from Printers", p
->name
);
1464 cupsArrayRemove(Printers
, p
);
1466 if (p
->type
& CUPS_PRINTER_IMPLICIT
)
1468 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1469 "cupsdRenamePrinter: Removing %s from ImplicitPrinters",
1471 cupsArrayRemove(ImplicitPrinters
, p
);
1475 * Rename the printer type...
1478 mimeDeleteType(MimeDatabase
, p
->filetype
);
1479 p
->filetype
= mimeAddType(MimeDatabase
, "printer", name
);
1481 mimeDeleteType(MimeDatabase
, p
->prefiltertype
);
1482 p
->prefiltertype
= mimeAddType(MimeDatabase
, "prefilter", name
);
1485 * Rename the printer...
1488 cupsdSetString(&p
->name
, name
);
1491 * Reset printer attributes...
1494 cupsdSetPrinterAttrs(p
);
1497 * Add the printer back to the printer array(s)...
1500 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1501 "cupsdRenamePrinter: Adding %s to Printers", p
->name
);
1502 cupsArrayAdd(Printers
, p
);
1504 if (p
->type
& CUPS_PRINTER_IMPLICIT
)
1506 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1507 "cupsdRenamePrinter: Adding %s to ImplicitPrinters",
1509 cupsArrayAdd(ImplicitPrinters
, p
);
1515 * 'cupsdSaveAllPrinters()' - Save all printer definitions to the printers.conf
1520 cupsdSaveAllPrinters(void)
1522 int i
; /* Looping var */
1523 cups_file_t
*fp
; /* printers.conf file */
1524 char temp
[1024], /* Temporary string */
1525 backup
[1024], /* printers.conf.O file */
1526 value
[2048], /* Value string */
1527 *ptr
; /* Pointer into value */
1528 cupsd_printer_t
*printer
; /* Current printer class */
1529 time_t curtime
; /* Current time */
1530 struct tm
*curdate
; /* Current date */
1531 cups_option_t
*option
; /* Current option */
1532 ipp_attribute_t
*marker
; /* Current marker attribute */
1536 * Create the printers.conf file...
1539 snprintf(temp
, sizeof(temp
), "%s/printers.conf", ServerRoot
);
1540 snprintf(backup
, sizeof(backup
), "%s/printers.conf.O", ServerRoot
);
1542 if (rename(temp
, backup
))
1544 if (errno
!= ENOENT
)
1545 cupsdLogMessage(CUPSD_LOG_ERROR
,
1546 "Unable to backup printers.conf - %s", strerror(errno
));
1549 if ((fp
= cupsFileOpen(temp
, "w")) == NULL
)
1551 cupsdLogMessage(CUPSD_LOG_ERROR
,
1552 "Unable to save printers.conf - %s", strerror(errno
));
1554 if (rename(backup
, temp
))
1555 cupsdLogMessage(CUPSD_LOG_ERROR
,
1556 "Unable to restore printers.conf - %s", strerror(errno
));
1560 cupsdLogMessage(CUPSD_LOG_INFO
, "Saving printers.conf...");
1563 * Restrict access to the file...
1566 fchown(cupsFileNumber(fp
), getuid(), Group
);
1567 fchmod(cupsFileNumber(fp
), 0600);
1570 * Write a small header to the file...
1573 curtime
= time(NULL
);
1574 curdate
= localtime(&curtime
);
1575 strftime(temp
, sizeof(temp
) - 1, "%Y-%m-%d %H:%M", curdate
);
1577 cupsFilePuts(fp
, "# Printer configuration file for " CUPS_SVERSION
"\n");
1578 cupsFilePrintf(fp
, "# Written by cupsd on %s\n", temp
);
1579 cupsFilePuts(fp
, "# DO NOT EDIT THIS FILE WHEN CUPSD IS RUNNING\n");
1582 * Write each local printer known to the system...
1585 for (printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
1587 printer
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
1590 * Skip remote destinations and printer classes...
1593 if ((printer
->type
& CUPS_PRINTER_DISCOVERED
) ||
1594 (printer
->type
& CUPS_PRINTER_CLASS
) ||
1595 (printer
->type
& CUPS_PRINTER_IMPLICIT
))
1599 * Write printers as needed...
1602 if (printer
== DefaultPrinter
)
1603 cupsFilePrintf(fp
, "<DefaultPrinter %s>\n", printer
->name
);
1605 cupsFilePrintf(fp
, "<Printer %s>\n", printer
->name
);
1607 if (printer
->num_auth_info_required
> 0)
1609 switch (printer
->num_auth_info_required
)
1612 strlcpy(value
, printer
->auth_info_required
[0], sizeof(value
));
1616 snprintf(value
, sizeof(value
), "%s,%s",
1617 printer
->auth_info_required
[0],
1618 printer
->auth_info_required
[1]);
1623 snprintf(value
, sizeof(value
), "%s,%s,%s",
1624 printer
->auth_info_required
[0],
1625 printer
->auth_info_required
[1],
1626 printer
->auth_info_required
[2]);
1630 cupsFilePutConf(fp
, "AuthInfoRequired", value
);
1634 cupsFilePutConf(fp
, "Info", printer
->info
);
1636 if (printer
->location
)
1637 cupsFilePutConf(fp
, "Location", printer
->location
);
1639 if (printer
->make_model
)
1640 cupsFilePutConf(fp
, "MakeModel", printer
->make_model
);
1642 cupsFilePutConf(fp
, "DeviceURI", printer
->device_uri
);
1644 if (printer
->port_monitor
)
1645 cupsFilePutConf(fp
, "PortMonitor", printer
->port_monitor
);
1647 if (printer
->state
== IPP_PRINTER_STOPPED
)
1649 cupsFilePuts(fp
, "State Stopped\n");
1651 if (printer
->state_message
)
1652 cupsFilePutConf(fp
, "StateMessage", printer
->state_message
);
1655 cupsFilePuts(fp
, "State Idle\n");
1657 cupsFilePrintf(fp
, "StateTime %d\n", (int)printer
->state_time
);
1659 for (i
= 0; i
< printer
->num_reasons
; i
++)
1660 if (strcmp(printer
->reasons
[i
], "connecting-to-device") &&
1661 strcmp(printer
->reasons
[i
], "cups-insecure-filter-warning") &&
1662 strcmp(printer
->reasons
[i
], "cups-missing-filter-warning"))
1663 cupsFilePutConf(fp
, "Reason", printer
->reasons
[i
]);
1665 cupsFilePrintf(fp
, "Type %d\n", printer
->type
);
1668 if (printer
->product
)
1669 cupsFilePutConf(fp
, "Product", printer
->product
);
1670 #endif /* HAVE_DNSSD */
1672 for (ptr
= (char *)cupsArrayFirst(printer
->filters
);
1674 ptr
= (char *)cupsArrayNext(printer
->filters
))
1675 cupsFilePutConf(fp
, "Filter", ptr
);
1677 for (ptr
= (char *)cupsArrayFirst(printer
->pre_filters
);
1679 ptr
= (char *)cupsArrayNext(printer
->pre_filters
))
1680 cupsFilePutConf(fp
, "PreFilter", ptr
);
1682 if (printer
->accepting
)
1683 cupsFilePuts(fp
, "Accepting Yes\n");
1685 cupsFilePuts(fp
, "Accepting No\n");
1687 if (printer
->shared
)
1688 cupsFilePuts(fp
, "Shared Yes\n");
1690 cupsFilePuts(fp
, "Shared No\n");
1692 snprintf(value
, sizeof(value
), "%s %s", printer
->job_sheets
[0],
1693 printer
->job_sheets
[1]);
1694 cupsFilePutConf(fp
, "JobSheets", value
);
1696 cupsFilePrintf(fp
, "QuotaPeriod %d\n", printer
->quota_period
);
1697 cupsFilePrintf(fp
, "PageLimit %d\n", printer
->page_limit
);
1698 cupsFilePrintf(fp
, "KLimit %d\n", printer
->k_limit
);
1700 for (i
= 0; i
< printer
->num_users
; i
++)
1701 cupsFilePutConf(fp
, printer
->deny_users
? "DenyUser" : "AllowUser",
1704 if (printer
->op_policy
)
1705 cupsFilePutConf(fp
, "OpPolicy", printer
->op_policy
);
1706 if (printer
->error_policy
)
1707 cupsFilePutConf(fp
, "ErrorPolicy", printer
->error_policy
);
1709 for (i
= printer
->num_options
, option
= printer
->options
;
1713 snprintf(value
, sizeof(value
), "%s %s", option
->name
, option
->value
);
1714 cupsFilePutConf(fp
, "Option", value
);
1717 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-colors",
1718 IPP_TAG_NAME
)) != NULL
)
1720 snprintf(value
, sizeof(value
), "%s ", marker
->name
);
1722 for (i
= 0, ptr
= value
+ strlen(value
);
1723 i
< marker
->num_values
&& ptr
< (value
+ sizeof(value
) - 1);
1729 strlcpy(ptr
, marker
->values
[i
].string
.text
,
1730 value
+ sizeof(value
) - ptr
);
1735 cupsFilePutConf(fp
, "Attribute", value
);
1738 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-levels",
1739 IPP_TAG_INTEGER
)) != NULL
)
1741 cupsFilePrintf(fp
, "Attribute %s %d", marker
->name
,
1742 marker
->values
[0].integer
);
1743 for (i
= 1; i
< marker
->num_values
; i
++)
1744 cupsFilePrintf(fp
, ",%d", marker
->values
[i
].integer
);
1745 cupsFilePuts(fp
, "\n");
1748 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-low-levels",
1749 IPP_TAG_INTEGER
)) != NULL
)
1751 cupsFilePrintf(fp
, "Attribute %s %d", marker
->name
,
1752 marker
->values
[0].integer
);
1753 for (i
= 1; i
< marker
->num_values
; i
++)
1754 cupsFilePrintf(fp
, ",%d", marker
->values
[i
].integer
);
1755 cupsFilePuts(fp
, "\n");
1758 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-high-levels",
1759 IPP_TAG_INTEGER
)) != NULL
)
1761 cupsFilePrintf(fp
, "Attribute %s %d", marker
->name
,
1762 marker
->values
[0].integer
);
1763 for (i
= 1; i
< marker
->num_values
; i
++)
1764 cupsFilePrintf(fp
, ",%d", marker
->values
[i
].integer
);
1765 cupsFilePuts(fp
, "\n");
1768 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-message",
1769 IPP_TAG_TEXT
)) != NULL
)
1771 snprintf(value
, sizeof(value
), "%s %s", marker
->name
,
1772 marker
->values
[0].string
.text
);
1774 cupsFilePutConf(fp
, "Attribute", value
);
1777 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-names",
1778 IPP_TAG_NAME
)) != NULL
)
1780 snprintf(value
, sizeof(value
), "%s ", marker
->name
);
1782 for (i
= 0, ptr
= value
+ strlen(value
);
1783 i
< marker
->num_values
&& ptr
< (value
+ sizeof(value
) - 1);
1789 strlcpy(ptr
, marker
->values
[i
].string
.text
,
1790 value
+ sizeof(value
) - ptr
);
1795 cupsFilePutConf(fp
, "Attribute", value
);
1798 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-types",
1799 IPP_TAG_KEYWORD
)) != NULL
)
1801 snprintf(value
, sizeof(value
), "%s ", marker
->name
);
1803 for (i
= 0, ptr
= value
+ strlen(value
);
1804 i
< marker
->num_values
&& ptr
< (value
+ sizeof(value
) - 1);
1810 strlcpy(ptr
, marker
->values
[i
].string
.text
,
1811 value
+ sizeof(value
) - ptr
);
1816 cupsFilePutConf(fp
, "Attribute", value
);
1819 if (printer
->marker_time
)
1820 cupsFilePrintf(fp
, "Attribute marker-change-time %ld\n",
1821 (long)printer
->marker_time
);
1823 cupsFilePuts(fp
, "</Printer>\n");
1827 * Make IRIX desktop & printer status happy
1830 write_irix_state(printer
);
1839 * 'cupsdSetAuthInfoRequired()' - Set the required authentication info.
1842 int /* O - 1 if value OK, 0 otherwise */
1843 cupsdSetAuthInfoRequired(
1844 cupsd_printer_t
*p
, /* I - Printer */
1845 const char *values
, /* I - Plain text value (or NULL) */
1846 ipp_attribute_t
*attr
) /* I - IPP attribute value (or NULL) */
1848 int i
; /* Looping var */
1851 p
->num_auth_info_required
= 0;
1854 * Do we have a plain text value?
1860 * Yes, grab the keywords...
1863 const char *end
; /* End of current value */
1866 while (*values
&& p
->num_auth_info_required
< 4)
1868 if ((end
= strchr(values
, ',')) == NULL
)
1869 end
= values
+ strlen(values
);
1871 if ((end
- values
) == 4 && !strncmp(values
, "none", 4))
1873 if (p
->num_auth_info_required
!= 0 || *end
)
1876 p
->auth_info_required
[p
->num_auth_info_required
] = "none";
1877 p
->num_auth_info_required
++;
1881 else if ((end
- values
) == 9 && !strncmp(values
, "negotiate", 9))
1883 if (p
->num_auth_info_required
!= 0 || *end
)
1886 p
->auth_info_required
[p
->num_auth_info_required
] = "negotiate";
1887 p
->num_auth_info_required
++;
1889 else if ((end
- values
) == 6 && !strncmp(values
, "domain", 6))
1891 p
->auth_info_required
[p
->num_auth_info_required
] = "domain";
1892 p
->num_auth_info_required
++;
1894 else if ((end
- values
) == 8 && !strncmp(values
, "password", 8))
1896 p
->auth_info_required
[p
->num_auth_info_required
] = "password";
1897 p
->num_auth_info_required
++;
1899 else if ((end
- values
) == 8 && !strncmp(values
, "username", 8))
1901 p
->auth_info_required
[p
->num_auth_info_required
] = "username";
1902 p
->num_auth_info_required
++;
1907 values
= (*end
) ? end
+ 1 : end
;
1910 if (p
->num_auth_info_required
== 0)
1912 p
->auth_info_required
[0] = "none";
1913 p
->num_auth_info_required
= 1;
1917 * Update the printer-type value as needed...
1920 if (p
->num_auth_info_required
> 1 ||
1921 strcmp(p
->auth_info_required
[0], "none"))
1922 p
->type
|= CUPS_PRINTER_AUTHENTICATED
;
1924 p
->type
&= ~CUPS_PRINTER_AUTHENTICATED
;
1930 * Grab values from an attribute instead...
1933 if (!attr
|| attr
->num_values
> 4)
1937 * Update the printer-type value as needed...
1940 if (attr
->num_values
> 1 ||
1941 strcmp(attr
->values
[0].string
.text
, "none"))
1942 p
->type
|= CUPS_PRINTER_AUTHENTICATED
;
1944 p
->type
&= ~CUPS_PRINTER_AUTHENTICATED
;
1946 for (i
= 0; i
< attr
->num_values
; i
++)
1948 if (!strcmp(attr
->values
[i
].string
.text
, "none"))
1950 if (p
->num_auth_info_required
!= 0 || attr
->num_values
!= 1)
1953 p
->auth_info_required
[p
->num_auth_info_required
] = "none";
1954 p
->num_auth_info_required
++;
1958 else if (!strcmp(attr
->values
[i
].string
.text
, "negotiate"))
1960 if (p
->num_auth_info_required
!= 0 || attr
->num_values
!= 1)
1963 p
->auth_info_required
[p
->num_auth_info_required
] = "negotiate";
1964 p
->num_auth_info_required
++;
1968 else if (!strcmp(attr
->values
[i
].string
.text
, "domain"))
1970 p
->auth_info_required
[p
->num_auth_info_required
] = "domain";
1971 p
->num_auth_info_required
++;
1973 else if (!strcmp(attr
->values
[i
].string
.text
, "password"))
1975 p
->auth_info_required
[p
->num_auth_info_required
] = "password";
1976 p
->num_auth_info_required
++;
1978 else if (!strcmp(attr
->values
[i
].string
.text
, "username"))
1980 p
->auth_info_required
[p
->num_auth_info_required
] = "username";
1981 p
->num_auth_info_required
++;
1992 * 'cupsdSetDeviceURI()' - Set the device URI for a printer.
1996 cupsdSetDeviceURI(cupsd_printer_t
*p
, /* I - Printer */
1997 const char *uri
) /* I - Device URI */
1999 char buffer
[1024], /* URI buffer */
2000 *start
, /* Start of data after scheme */
2001 *slash
, /* First slash after scheme:// */
2002 *ptr
; /* Pointer into user@host:port part */
2006 * Set the full device URI..
2009 cupsdSetString(&(p
->device_uri
), uri
);
2012 * Copy the device URI to a temporary buffer so we can sanitize any auth
2016 strlcpy(buffer
, uri
, sizeof(buffer
));
2019 * Find the end of the scheme:// part...
2022 if ((ptr
= strchr(buffer
, ':')) != NULL
)
2024 for (start
= ptr
+ 1; *start
; start
++)
2029 * Find the next slash (/) in the URI...
2032 if ((slash
= strchr(start
, '/')) == NULL
)
2033 slash
= start
+ strlen(start
); /* No slash, point to the end */
2036 * Check for an @ sign before the slash...
2039 if ((ptr
= strchr(start
, '@')) != NULL
&& ptr
< slash
)
2042 * Found an @ sign and it is before the resource part, so we have
2043 * an authentication string. Copy the remaining URI over the
2044 * authentication string...
2047 _cups_strcpy(start
, ptr
+ 1);
2052 * Save the sanitized URI...
2055 cupsdSetString(&(p
->sanitized_device_uri
), buffer
);
2060 * 'cupsdSetPrinterAttr()' - Set a printer attribute.
2064 cupsdSetPrinterAttr(
2065 cupsd_printer_t
*p
, /* I - Printer */
2066 const char *name
, /* I - Attribute name */
2067 char *value
) /* I - Attribute value string */
2069 ipp_attribute_t
*attr
; /* Attribute */
2070 int i
, /* Looping var */
2071 count
; /* Number of values */
2072 char *ptr
; /* Pointer into value */
2073 ipp_tag_t value_tag
; /* Value tag for this attribute */
2077 * Don't allow empty values...
2080 if (!*value
&& strcmp(name
, "marker-message"))
2082 cupsdLogMessage(CUPSD_LOG_ERROR
, "Ignoring empty \"%s\" attribute", name
);
2087 * Count the number of values...
2090 for (count
= 1, ptr
= value
;
2091 (ptr
= strchr(ptr
, ',')) != NULL
;
2095 * Then add or update the attribute as needed...
2098 if (!strcmp(name
, "marker-levels") || !strcmp(name
, "marker-low-levels") ||
2099 !strcmp(name
, "marker-high-levels"))
2105 if ((attr
= ippFindAttribute(p
->attrs
, name
, IPP_TAG_INTEGER
)) != NULL
&&
2106 attr
->num_values
< count
)
2108 ippDeleteAttribute(p
->attrs
, attr
);
2113 attr
->num_values
= count
;
2115 attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
, name
,
2120 cupsdLogMessage(CUPSD_LOG_ERROR
,
2121 "Unable to allocate memory for printer attribute "
2122 "(%d values)", count
);
2126 for (i
= 0; i
< count
; i
++)
2128 if ((ptr
= strchr(value
, ',')) != NULL
)
2131 attr
->values
[i
].integer
= strtol(value
, NULL
, 10);
2140 * Name or keyword values...
2143 if (!strcmp(name
, "marker-types"))
2144 value_tag
= IPP_TAG_KEYWORD
;
2145 else if (!strcmp(name
, "marker-message"))
2146 value_tag
= IPP_TAG_TEXT
;
2148 value_tag
= IPP_TAG_NAME
;
2150 if ((attr
= ippFindAttribute(p
->attrs
, name
, value_tag
)) != NULL
&&
2151 attr
->num_values
< count
)
2153 ippDeleteAttribute(p
->attrs
, attr
);
2159 for (i
= 0; i
< attr
->num_values
; i
++)
2160 _cupsStrFree(attr
->values
[i
].string
.text
);
2162 attr
->num_values
= count
;
2165 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, value_tag
, name
,
2170 cupsdLogMessage(CUPSD_LOG_ERROR
,
2171 "Unable to allocate memory for printer attribute "
2172 "(%d values)", count
);
2176 for (i
= 0; i
< count
; i
++)
2178 if ((ptr
= strchr(value
, ',')) != NULL
)
2181 attr
->values
[i
].string
.text
= _cupsStrAlloc(value
);
2191 * 'cupsdSetPrinterAttrs()' - Set printer attributes based upon the PPD file.
2195 cupsdSetPrinterAttrs(cupsd_printer_t
*p
)/* I - Printer to setup */
2197 int i
, /* Looping var */
2198 length
; /* Length of browse attributes */
2199 char resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
2200 int num_air
; /* Number of auth-info-required values */
2201 const char * const *air
; /* auth-info-required values */
2202 cupsd_location_t
*auth
; /* Pointer to authentication element */
2203 const char *auth_supported
; /* Authentication supported */
2204 ipp_t
*oldattrs
; /* Old printer attributes */
2205 ipp_attribute_t
*attr
; /* Attribute data */
2206 cups_option_t
*option
; /* Current printer option */
2207 char *filter
; /* Current filter */
2208 static const char * const air_none
[] =
2209 { /* No authentication */
2212 static const char * const air_userpass
[] =
2213 { /* Basic/Digest authentication */
2219 DEBUG_printf(("cupsdSetPrinterAttrs: entering name = %s, type = %x\n", p
->name
,
2223 * Make sure that we have the common attributes defined...
2227 cupsdCreateCommonData();
2230 * Clear out old filters, if any...
2233 delete_printer_filters(p
);
2236 * Figure out the authentication that is required for the printer.
2239 auth_supported
= "requesting-user-name";
2243 if (p
->num_auth_info_required
> 0 && strcmp(p
->auth_info_required
[0], "none"))
2245 num_air
= p
->num_auth_info_required
;
2246 air
= p
->auth_info_required
;
2248 else if ((p
->type
& CUPS_PRINTER_AUTHENTICATED
) &&
2249 (p
->type
& CUPS_PRINTER_DISCOVERED
))
2255 if (p
->type
& CUPS_PRINTER_CLASS
)
2256 snprintf(resource
, sizeof(resource
), "/classes/%s", p
->name
);
2258 snprintf(resource
, sizeof(resource
), "/printers/%s", p
->name
);
2260 if ((auth
= cupsdFindBest(resource
, HTTP_POST
)) == NULL
||
2261 auth
->type
== CUPSD_AUTH_NONE
)
2262 auth
= cupsdFindPolicyOp(p
->op_policy_ptr
, IPP_PRINT_JOB
);
2266 int auth_type
; /* Authentication type */
2269 if ((auth_type
= auth
->type
) == CUPSD_AUTH_DEFAULT
)
2270 auth_type
= DefaultAuthType
;
2272 if (auth_type
== CUPSD_AUTH_BASIC
|| auth_type
== CUPSD_AUTH_BASICDIGEST
)
2273 auth_supported
= "basic";
2274 else if (auth_type
== CUPSD_AUTH_DIGEST
)
2275 auth_supported
= "digest";
2277 else if (auth_type
== CUPSD_AUTH_NEGOTIATE
)
2278 auth_supported
= "negotiate";
2279 #endif /* HAVE_GSSAPI */
2281 if (!(p
->type
& CUPS_PRINTER_DISCOVERED
))
2283 if (auth_type
!= CUPSD_AUTH_NONE
)
2284 p
->type
|= CUPS_PRINTER_AUTHENTICATED
;
2286 p
->type
&= ~CUPS_PRINTER_AUTHENTICATED
;
2289 else if (!(p
->type
& CUPS_PRINTER_DISCOVERED
))
2290 p
->type
&= ~CUPS_PRINTER_AUTHENTICATED
;
2293 * Create the required IPP attributes for a printer...
2296 oldattrs
= p
->attrs
;
2297 p
->attrs
= ippNew();
2299 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2300 "uri-authentication-supported", NULL
, auth_supported
);
2301 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2302 "uri-security-supported", NULL
, "none");
2303 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
, "printer-name", NULL
,
2305 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-location",
2306 NULL
, p
->location
? p
->location
: "");
2307 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-info",
2308 NULL
, p
->info
? p
->info
: "");
2313 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2314 "requesting-user-name-denied", p
->num_users
, NULL
,
2317 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2318 "requesting-user-name-allowed", p
->num_users
, NULL
,
2322 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2323 "job-quota-period", p
->quota_period
);
2324 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2325 "job-k-limit", p
->k_limit
);
2326 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2327 "job-page-limit", p
->page_limit
);
2328 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2329 "auth-info-required", num_air
, NULL
, air
);
2331 if (cupsArrayCount(Banners
) > 0 && !(p
->type
& CUPS_PRINTER_DISCOVERED
))
2334 * Setup the job-sheets-default attribute...
2337 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2338 "job-sheets-default", 2, NULL
, NULL
);
2342 attr
->values
[0].string
.text
= _cupsStrAlloc(Classification
?
2343 Classification
: p
->job_sheets
[0]);
2344 attr
->values
[1].string
.text
= _cupsStrAlloc(Classification
?
2345 Classification
: p
->job_sheets
[1]);
2352 if (p
->type
& CUPS_PRINTER_DISCOVERED
)
2355 * Tell the client this is a remote printer of some type...
2358 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
2359 "printer-uri-supported", NULL
, p
->uri
);
2361 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "printer-more-info",
2365 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
2366 "printer-make-and-model", NULL
, p
->make_model
);
2368 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "device-uri", NULL
,
2377 * Assign additional attributes depending on whether this is a printer
2381 if (p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
))
2384 p
->type
&= ~CUPS_PRINTER_OPTIONS
;
2387 * Add class-specific attributes...
2390 if ((p
->type
& CUPS_PRINTER_IMPLICIT
) && p
->num_printers
> 0 &&
2391 p
->printers
[0]->make_model
)
2392 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
2393 "printer-make-and-model", NULL
, p
->printers
[0]->make_model
);
2395 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
2396 "printer-make-and-model", NULL
, "Local Printer Class");
2398 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "device-uri", NULL
,
2399 "file:///dev/null");
2401 if (p
->num_printers
> 0)
2404 * Add a list of member names; URIs are added in copy_printer_attrs...
2407 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2408 "member-names", p
->num_printers
, NULL
, NULL
);
2409 p
->type
|= CUPS_PRINTER_OPTIONS
;
2411 for (i
= 0; i
< p
->num_printers
; i
++)
2414 attr
->values
[i
].string
.text
= _cupsStrRetain(p
->printers
[i
]->name
);
2416 p
->type
&= ~CUPS_PRINTER_OPTIONS
| p
->printers
[i
]->type
;
2423 * Add printer-specific attributes...
2426 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "device-uri", NULL
,
2427 p
->sanitized_device_uri
);
2430 * Assign additional attributes from the PPD file (if any)...
2436 * Add filters for printer...
2439 cupsdSetPrinterReasons(p
, "-cups-missing-filter-warning,"
2440 "cups-insecure-filter-warning");
2442 for (filter
= (char *)cupsArrayFirst(p
->filters
);
2444 filter
= (char *)cupsArrayNext(p
->filters
))
2445 add_printer_filter(p
, p
->filetype
, filter
);
2449 p
->prefiltertype
= mimeAddType(MimeDatabase
, "prefilter", p
->name
);
2451 for (filter
= (char *)cupsArrayFirst(p
->pre_filters
);
2453 filter
= (char *)cupsArrayNext(p
->pre_filters
))
2454 add_printer_filter(p
, p
->prefiltertype
, filter
);
2460 * Copy marker attributes as needed...
2465 ipp_attribute_t
*oldattr
; /* Old attribute */
2468 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-colors",
2469 IPP_TAG_NAME
)) != NULL
)
2471 if ((attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2472 "marker-colors", oldattr
->num_values
, NULL
,
2475 for (i
= 0; i
< oldattr
->num_values
; i
++)
2476 attr
->values
[i
].string
.text
=
2477 _cupsStrRetain(oldattr
->values
[i
].string
.text
);
2481 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-levels",
2482 IPP_TAG_INTEGER
)) != NULL
)
2484 if ((attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2485 "marker-levels", oldattr
->num_values
,
2488 for (i
= 0; i
< oldattr
->num_values
; i
++)
2489 attr
->values
[i
].integer
= oldattr
->values
[i
].integer
;
2493 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-message",
2494 IPP_TAG_TEXT
)) != NULL
)
2495 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "marker-message",
2496 NULL
, oldattr
->values
[0].string
.text
);
2498 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-low-levels",
2499 IPP_TAG_INTEGER
)) != NULL
)
2501 if ((attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2502 "marker-low-levels", oldattr
->num_values
,
2505 for (i
= 0; i
< oldattr
->num_values
; i
++)
2506 attr
->values
[i
].integer
= oldattr
->values
[i
].integer
;
2510 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-high-levels",
2511 IPP_TAG_INTEGER
)) != NULL
)
2513 if ((attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2514 "marker-high-levels", oldattr
->num_values
,
2517 for (i
= 0; i
< oldattr
->num_values
; i
++)
2518 attr
->values
[i
].integer
= oldattr
->values
[i
].integer
;
2522 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-names",
2523 IPP_TAG_NAME
)) != NULL
)
2525 if ((attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2526 "marker-names", oldattr
->num_values
, NULL
,
2529 for (i
= 0; i
< oldattr
->num_values
; i
++)
2530 attr
->values
[i
].string
.text
=
2531 _cupsStrRetain(oldattr
->values
[i
].string
.text
);
2535 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-types",
2536 IPP_TAG_KEYWORD
)) != NULL
)
2538 if ((attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2539 "marker-types", oldattr
->num_values
, NULL
,
2542 for (i
= 0; i
< oldattr
->num_values
; i
++)
2543 attr
->values
[i
].string
.text
=
2544 _cupsStrRetain(oldattr
->values
[i
].string
.text
);
2548 ippDelete(oldattrs
);
2552 * Force sharing off for remote queues...
2555 if (p
->type
& (CUPS_PRINTER_REMOTE
| CUPS_PRINTER_IMPLICIT
))
2560 * Copy the printer options into a browse attributes string we can re-use.
2563 const char *valptr
; /* Pointer into value */
2564 char *attrptr
; /* Pointer into attribute string */
2568 * Free the old browse attributes as needed...
2571 if (p
->browse_attrs
)
2572 free(p
->browse_attrs
);
2575 * Compute the length of all attributes + job-sheets, lease-duration,
2576 * and BrowseLocalOptions.
2579 for (length
= 1, i
= p
->num_options
, option
= p
->options
;
2583 length
+= strlen(option
->name
) + 2;
2587 for (valptr
= option
->value
; *valptr
; valptr
++)
2588 if (strchr(" \"\'\\", *valptr
))
2595 length
+= 13 + strlen(p
->job_sheets
[0]) + strlen(p
->job_sheets
[1]);
2597 if (BrowseLocalOptions
)
2598 length
+= 12 + strlen(BrowseLocalOptions
);
2601 * Allocate the new string...
2604 if ((p
->browse_attrs
= calloc(1, length
)) == NULL
)
2605 cupsdLogMessage(CUPSD_LOG_ERROR
,
2606 "Unable to allocate %d bytes for browse data!",
2611 * Got the allocated string, now copy the options and attributes over...
2614 sprintf(p
->browse_attrs
, "job-sheets=%s,%s lease-duration=%d",
2615 p
->job_sheets
[0], p
->job_sheets
[1], BrowseTimeout
);
2616 attrptr
= p
->browse_attrs
+ strlen(p
->browse_attrs
);
2618 if (BrowseLocalOptions
)
2620 sprintf(attrptr
, " ipp-options=%s", BrowseLocalOptions
);
2621 attrptr
+= strlen(attrptr
);
2624 for (i
= p
->num_options
, option
= p
->options
;
2629 strcpy(attrptr
, option
->name
);
2630 attrptr
+= strlen(attrptr
);
2636 for (valptr
= option
->value
; *valptr
; valptr
++)
2638 if (strchr(" \"\'\\", *valptr
))
2641 *attrptr
++ = *valptr
;
2649 * Populate the document-format-supported attribute...
2652 add_printer_formats(p
);
2654 DEBUG_printf(("cupsdSetPrinterAttrs: leaving name = %s, type = %x\n", p
->name
,
2658 * Add name-default attributes...
2661 add_printer_defaults(p
);
2665 * Write the IRIX printer config and status files...
2668 write_irix_config(p
);
2669 write_irix_state(p
);
2673 * Let the browse protocols reflect the change
2676 cupsdRegisterPrinter(p
);
2681 * 'cupsdSetPrinterReasons()' - Set/update the reasons strings.
2684 int /* O - 1 if something changed, 0 otherwise */
2685 cupsdSetPrinterReasons(
2686 cupsd_printer_t
*p
, /* I - Printer */
2687 const char *s
) /* I - Reasons strings */
2689 int i
, /* Looping var */
2690 changed
= 0; /* Did something change? */
2691 const char *sptr
; /* Pointer into reasons */
2692 char reason
[255], /* Reason string */
2693 *rptr
; /* Pointer into reason */
2696 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
2697 "cupsdSetPrinterReasons(p=%p(%s),s=\"%s\"", p
, p
->name
, s
);
2699 if (s
[0] == '-' || s
[0] == '+')
2702 * Add/remove reasons...
2710 * Replace reasons...
2715 for (i
= 0; i
< p
->num_reasons
; i
++)
2716 _cupsStrFree(p
->reasons
[i
]);
2721 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
2723 if (PrintcapFormat
== PRINTCAP_PLIST
)
2724 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
2727 if (!strcmp(s
, "none"))
2731 * Loop through all of the reasons...
2737 * Skip leading whitespace and commas...
2740 while (isspace(*sptr
& 255) || *sptr
== ',')
2743 for (rptr
= reason
; *sptr
&& !isspace(*sptr
& 255) && *sptr
!= ','; sptr
++)
2744 if (rptr
< (reason
+ sizeof(reason
) - 1))
2758 for (i
= 0; i
< p
->num_reasons
; i
++)
2759 if (!strcmp(reason
, p
->reasons
[i
]))
2762 * Found a match, so remove it...
2767 _cupsStrFree(p
->reasons
[i
]);
2769 if (i
< p
->num_reasons
)
2770 memmove(p
->reasons
+ i
, p
->reasons
+ i
+ 1,
2771 (p
->num_reasons
- i
) * sizeof(char *));
2773 if (!strcmp(reason
, "paused") && p
->state
== IPP_PRINTER_STOPPED
)
2774 cupsdSetPrinterState(p
, IPP_PRINTER_IDLE
, 1);
2776 if (strcmp(reason
, "connecting-to-device"))
2778 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
2780 if (PrintcapFormat
== PRINTCAP_PLIST
)
2781 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
2786 else if (p
->num_reasons
< (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
2792 for (i
= 0; i
< p
->num_reasons
; i
++)
2793 if (!strcmp(reason
, p
->reasons
[i
]))
2796 if (i
>= p
->num_reasons
)
2798 if (i
>= (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
2800 cupsdLogMessage(CUPSD_LOG_ALERT
,
2801 "Too many printer-state-reasons values for %s (%d)",
2806 p
->reasons
[i
] = _cupsStrAlloc(reason
);
2810 if (!strcmp(reason
, "paused") && p
->state
!= IPP_PRINTER_STOPPED
)
2811 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, 1);
2813 if (strcmp(reason
, "connecting-to-device"))
2815 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
2817 if (PrintcapFormat
== PRINTCAP_PLIST
)
2818 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
2829 * 'cupsdSetPrinterState()' - Update the current state of a printer.
2833 cupsdSetPrinterState(
2834 cupsd_printer_t
*p
, /* I - Printer to change */
2835 ipp_pstate_t s
, /* I - New state */
2836 int update
) /* I - Update printers.conf? */
2838 ipp_pstate_t old_state
; /* Old printer state */
2839 static const char * const printer_states
[] =
2840 { /* State strings */
2848 * Can't set status of remote printers...
2851 if (p
->type
& CUPS_PRINTER_DISCOVERED
)
2855 * Set the new state...
2858 if (PrintcapFormat
== PRINTCAP_PLIST
)
2859 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
2861 old_state
= p
->state
;
2866 cupsdAddEvent(s
== IPP_PRINTER_STOPPED
? CUPSD_EVENT_PRINTER_STOPPED
:
2867 CUPSD_EVENT_PRINTER_STATE
, p
, NULL
,
2868 "%s \"%s\" state changed to %s.",
2869 (p
->type
& CUPS_PRINTER_CLASS
) ? "Class" : "Printer",
2870 p
->name
, printer_states
[p
->state
]);
2873 * Let the browse code know this needs to be updated...
2877 p
->state_time
= time(NULL
);
2881 write_irix_state(p
);
2886 * Set/clear the paused reason as needed...
2889 if (s
== IPP_PRINTER_STOPPED
)
2890 cupsdSetPrinterReasons(p
, "+paused");
2892 cupsdSetPrinterReasons(p
, "-paused");
2895 * Clear the message for the queue when going to processing...
2898 if (s
== IPP_PRINTER_PROCESSING
)
2899 p
->state_message
[0] = '\0';
2902 * Update the printer history...
2905 cupsdAddPrinterHistory(p
);
2908 * Let the browse protocols reflect the change...
2912 cupsdRegisterPrinter(p
);
2915 * Save the printer configuration if a printer goes from idle or processing
2916 * to stopped (or visa-versa)...
2920 (old_state
== IPP_PRINTER_STOPPED
) != (s
== IPP_PRINTER_STOPPED
))
2922 if (p
->type
& CUPS_PRINTER_CLASS
)
2923 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
2925 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
2931 * 'cupsdStopPrinter()' - Stop a printer from printing any jobs...
2935 cupsdStopPrinter(cupsd_printer_t
*p
, /* I - Printer to stop */
2936 int update
)/* I - Update printers.conf? */
2939 * Set the printer state...
2942 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, update
);
2945 * See if we have a job printing on this printer...
2948 if (p
->job
&& p
->job
->state_value
== IPP_JOB_PROCESSING
)
2949 cupsdSetJobState(p
->job
, IPP_JOB_PENDING
, CUPSD_JOB_DEFAULT
,
2950 "Job stopped due to printer being paused.");
2955 * 'cupsdUpdatePrinterPPD()' - Update keywords in a printer's PPD file.
2958 int /* O - 1 if successful, 0 otherwise */
2959 cupsdUpdatePrinterPPD(
2960 cupsd_printer_t
*p
, /* I - Printer */
2961 int num_keywords
, /* I - Number of keywords */
2962 cups_option_t
*keywords
) /* I - Keywords */
2964 int i
; /* Looping var */
2965 cups_file_t
*src
, /* Original file */
2966 *dst
; /* New file */
2967 char srcfile
[1024], /* Original filename */
2968 dstfile
[1024], /* New filename */
2969 line
[1024], /* Line from file */
2970 keystring
[41]; /* Keyword from line */
2971 cups_option_t
*keyword
; /* Current keyword */
2974 cupsdLogMessage(CUPSD_LOG_INFO
, "Updating keywords in PPD file for %s...",
2978 * Get the old and new PPD filenames...
2981 snprintf(srcfile
, sizeof(srcfile
), "%s/ppd/%s.ppd.O", ServerRoot
, p
->name
);
2982 snprintf(dstfile
, sizeof(srcfile
), "%s/ppd/%s.ppd", ServerRoot
, p
->name
);
2985 * Rename the old file and open the old and new...
2988 if (rename(dstfile
, srcfile
))
2990 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to backup PPD file for %s: %s",
2991 p
->name
, strerror(errno
));
2995 if ((src
= cupsFileOpen(srcfile
, "r")) == NULL
)
2997 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to open PPD file \"%s\": %s",
2998 srcfile
, strerror(errno
));
2999 rename(srcfile
, dstfile
);
3003 if ((dst
= cupsFileOpen(dstfile
, "w")) == NULL
)
3005 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to create PPD file \"%s\": %s",
3006 dstfile
, strerror(errno
));
3008 rename(srcfile
, dstfile
);
3013 * Copy the first line and then write out all of the keywords...
3016 if (!cupsFileGets(src
, line
, sizeof(line
)))
3018 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to read PPD file \"%s\": %s",
3019 srcfile
, strerror(errno
));
3022 rename(srcfile
, dstfile
);
3026 cupsFilePrintf(dst
, "%s\n", line
);
3028 for (i
= num_keywords
, keyword
= keywords
; i
> 0; i
--, keyword
++)
3030 cupsdLogMessage(CUPSD_LOG_DEBUG
, "*%s: %s", keyword
->name
, keyword
->value
);
3031 cupsFilePrintf(dst
, "*%s: %s\n", keyword
->name
, keyword
->value
);
3035 * Then copy the rest of the PPD file, dropping any keywords we changed.
3038 while (cupsFileGets(src
, line
, sizeof(line
)))
3041 * Skip keywords we've already set...
3044 if (sscanf(line
, "*%40[^:]:", keystring
) == 1 &&
3045 cupsGetOption(keystring
, num_keywords
, keywords
))
3049 * Otherwise write the line...
3052 cupsFilePrintf(dst
, "%s\n", line
);
3056 * Close files and return...
3067 * 'cupsdUpdatePrinters()' - Update printers after a partial reload.
3071 cupsdUpdatePrinters(void)
3073 cupsd_printer_t
*p
; /* Current printer */
3077 * Loop through the printers and recreate the printer attributes
3078 * for any local printers since the policy and/or access control
3079 * stuff may have changed. Also, if browsing is disabled, remove
3080 * any remote printers...
3083 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3085 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3088 * Remove remote printers if we are no longer browsing...
3092 (p
->type
& (CUPS_PRINTER_IMPLICIT
| CUPS_PRINTER_DISCOVERED
)))
3094 if (p
->type
& CUPS_PRINTER_IMPLICIT
)
3095 cupsArrayRemove(ImplicitPrinters
, p
);
3097 cupsArraySave(Printers
);
3098 cupsdDeletePrinter(p
, 0);
3099 cupsArrayRestore(Printers
);
3104 * Update the operation policy pointer...
3107 if ((p
->op_policy_ptr
= cupsdFindPolicy(p
->op_policy
)) == NULL
)
3108 p
->op_policy_ptr
= DefaultPolicyPtr
;
3111 * Update printer attributes as needed...
3114 if (!(p
->type
& CUPS_PRINTER_DISCOVERED
))
3115 cupsdSetPrinterAttrs(p
);
3121 * 'cupsdValidateDest()' - Validate a printer/class destination.
3124 const char * /* O - Printer or class name */
3126 const char *uri
, /* I - Printer URI */
3127 cups_ptype_t
*dtype
, /* O - Type (printer or class) */
3128 cupsd_printer_t
**printer
) /* O - Printer pointer */
3130 cupsd_printer_t
*p
; /* Current printer */
3131 char localname
[1024],/* Localized hostname */
3132 *lptr
, /* Pointer into localized hostname */
3133 *sptr
, /* Pointer into server name */
3134 *rptr
, /* Pointer into resource */
3135 scheme
[32], /* Scheme portion of URI */
3136 username
[64], /* Username portion of URI */
3137 hostname
[HTTP_MAX_HOST
],
3138 /* Host portion of URI */
3139 resource
[HTTP_MAX_URI
];
3140 /* Resource portion of URI */
3141 int port
; /* Port portion of URI */
3144 DEBUG_printf(("cupsdValidateDest(uri=\"%s\", dtype=%p, printer=%p)\n", uri
,
3148 * Initialize return values...
3155 *dtype
= (cups_ptype_t
)0;
3158 * Pull the hostname and resource from the URI...
3161 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
, scheme
, sizeof(scheme
),
3162 username
, sizeof(username
), hostname
, sizeof(hostname
),
3163 &port
, resource
, sizeof(resource
));
3166 * See if the resource is a class or printer...
3169 if (!strncmp(resource
, "/classes/", 9))
3175 rptr
= resource
+ 9;
3177 else if (!strncmp(resource
, "/printers/", 10))
3183 rptr
= resource
+ 10;
3188 * Bad resource name...
3195 * See if the printer or class name exists...
3198 p
= cupsdFindDest(rptr
);
3200 if (p
== NULL
&& strchr(rptr
, '@') == NULL
)
3208 *dtype
= p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
|
3209 CUPS_PRINTER_REMOTE
| CUPS_PRINTER_DISCOVERED
);
3215 * Change localhost to the server name...
3218 if (!strcasecmp(hostname
, "localhost"))
3219 strlcpy(hostname
, ServerName
, sizeof(hostname
));
3221 strlcpy(localname
, hostname
, sizeof(localname
));
3223 if (!strcasecmp(hostname
, ServerName
))
3226 * Localize the hostname...
3229 lptr
= strchr(localname
, '.');
3230 sptr
= strchr(ServerName
, '.');
3232 if (sptr
!= NULL
&& lptr
!= NULL
)
3235 * Strip the common domain name components...
3238 while (lptr
!= NULL
)
3240 if (!strcasecmp(lptr
, sptr
))
3246 lptr
= strchr(lptr
+ 1, '.');
3251 DEBUG_printf(("localized hostname is \"%s\"...\n", localname
));
3254 * Find a matching printer or class...
3257 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3259 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3260 if (!strcasecmp(p
->hostname
, localname
) &&
3261 !strcasecmp(p
->name
, rptr
))
3267 *dtype
= p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
|
3268 CUPS_PRINTER_REMOTE
| CUPS_PRINTER_DISCOVERED
);
3278 * 'cupsdWritePrintcap()' - Write a pseudo-printcap file for older applications
3283 cupsdWritePrintcap(void)
3285 int i
; /* Looping var */
3286 cups_file_t
*fp
; /* Printcap file */
3287 cupsd_printer_t
*p
; /* Current printer */
3292 * Update the IRIX printer state for the default printer; if
3293 * no printers remain, then the default printer file will be
3297 write_irix_state(DefaultPrinter
);
3301 * See if we have a printcap file; if not, don't bother writing it.
3304 if (!Printcap
|| !*Printcap
)
3307 cupsdLogMessage(CUPSD_LOG_INFO
, "Generating printcap %s...", Printcap
);
3310 * Open the printcap file...
3313 if ((fp
= cupsFileOpen(Printcap
, "w")) == NULL
)
3317 * Put a comment header at the top so that users will know where the
3318 * data has come from...
3321 if (PrintcapFormat
!= PRINTCAP_PLIST
)
3322 cupsFilePrintf(fp
, "# This file was automatically generated by cupsd(8) "
3324 "# %s/printers.conf file. All changes to this file\n"
3325 "# will be lost.\n", ServerRoot
);
3328 * Write a new printcap with the current list of printers.
3331 switch (PrintcapFormat
)
3335 * Each printer is put in the file as:
3345 cupsFilePrintf(fp
, "%s|%s:rm=%s:rp=%s:\n", DefaultPrinter
->name
,
3346 DefaultPrinter
->info
, ServerName
,
3347 DefaultPrinter
->name
);
3349 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3351 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3352 if (p
!= DefaultPrinter
)
3353 cupsFilePrintf(fp
, "%s|%s:rm=%s:rp=%s:\n", p
->name
, p
->info
,
3354 ServerName
, p
->name
);
3357 case PRINTCAP_PLIST
:
3359 * Each printer is written as a dictionary in a plist file.
3360 * Currently the printer-name, printer-info, printer-is-accepting-jobs,
3361 * printer-location, printer-make-and-model, printer-state,
3362 * printer-state-reasons, printer-type, and (sanitized) device-uri.
3365 cupsFilePuts(fp
, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
3366 "<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD "
3367 "PLIST 1.0//EN\" \"http://www.apple.com/DTDs/"
3368 "PropertyList-1.0.dtd\">\n"
3369 "<plist version=\"1.0\">\n"
3372 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3374 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3376 cupsFilePuts(fp
, "\t<dict>\n"
3377 "\t\t<key>printer-name</key>\n"
3379 write_xml_string(fp
, p
->name
);
3380 cupsFilePuts(fp
, "</string>\n"
3381 "\t\t<key>printer-info</key>\n"
3383 write_xml_string(fp
, p
->info
);
3384 cupsFilePrintf(fp
, "</string>\n"
3385 "\t\t<key>printer-is-accepting-jobs</key>\n"
3387 "\t\t<key>printer-location</key>\n"
3388 "\t\t<string>", p
->accepting
? "true" : "false");
3389 write_xml_string(fp
, p
->location
);
3390 cupsFilePuts(fp
, "</string>\n"
3391 "\t\t<key>printer-make-and-model</key>\n"
3393 write_xml_string(fp
, p
->make_model
);
3394 cupsFilePrintf(fp
, "</string>\n"
3395 "\t\t<key>printer-state</key>\n"
3396 "\t\t<integer>%d</integer>\n"
3397 "\t\t<key>printer-state-reasons</key>\n"
3398 "\t\t<array>\n", p
->state
);
3399 for (i
= 0; i
< p
->num_reasons
; i
++)
3401 cupsFilePuts(fp
, "\t\t\t<string>");
3402 write_xml_string(fp
, p
->reasons
[i
]);
3403 cupsFilePuts(fp
, "</string>\n");
3405 cupsFilePrintf(fp
, "\t\t</array>\n"
3406 "\t\t<key>printer-type</key>\n"
3407 "\t\t<integer>%d</integer>\n"
3408 "\t\t<key>device-uri</key>\n"
3409 "\t\t<string>", p
->type
);
3410 write_xml_string(fp
, p
->sanitized_device_uri
);
3411 cupsFilePuts(fp
, "</string>\n"
3414 cupsFilePuts(fp
, "</array>\n"
3418 case PRINTCAP_SOLARIS
:
3420 * Each printer is put in the file as:
3422 * _all:all=Printer1,Printer2,Printer3,...,PrinterN
3423 * _default:use=DefaultPrinter
3425 * :bsdaddr=ServerName,Printer1:\
3426 * :description=Description:
3428 * :bsdaddr=ServerName,Printer2:\
3429 * :description=Description:
3431 * :bsdaddr=ServerName,Printer3:\
3432 * :description=Description:
3435 * :bsdaddr=ServerName,PrinterN:\
3436 * :description=Description:
3439 cupsFilePuts(fp
, "_all:all=");
3440 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3442 p
= (cupsd_printer_t
*)cupsArrayCurrent(Printers
))
3443 cupsFilePrintf(fp
, "%s%c", p
->name
,
3444 cupsArrayNext(Printers
) ? ',' : '\n');
3447 cupsFilePrintf(fp
, "_default:use=%s\n", DefaultPrinter
->name
);
3449 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3451 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3452 cupsFilePrintf(fp
, "%s:\\\n"
3453 "\t:bsdaddr=%s,%s:\\\n"
3454 "\t:description=%s:\n",
3455 p
->name
, ServerName
, p
->name
,
3456 p
->info
? p
->info
: "");
3469 * 'add_printer_defaults()' - Add name-default attributes to the printer attributes.
3473 add_printer_defaults(cupsd_printer_t
*p
)/* I - Printer */
3475 int i
; /* Looping var */
3476 int num_options
; /* Number of default options */
3477 cups_option_t
*options
, /* Default options */
3478 *option
; /* Current option */
3479 char name
[256]; /* name-default */
3483 * Maintain a common array of default attribute names...
3486 if (!CommonDefaults
)
3488 CommonDefaults
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
3490 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("copies-default"));
3491 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("document-format-default"));
3492 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("finishings-default"));
3493 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-hold-until-default"));
3494 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-priority-default"));
3495 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-sheets-default"));
3496 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("media-col-default"));
3497 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("number-up-default"));
3498 cupsArrayAdd(CommonDefaults
,
3499 _cupsStrAlloc("orientation-requested-default"));
3503 * Add all of the default options from the .conf files...
3506 for (num_options
= 0, options
= NULL
, i
= p
->num_options
, option
= p
->options
;
3510 if (strcmp(option
->name
, "ipp-options") &&
3511 strcmp(option
->name
, "job-sheets") &&
3512 strcmp(option
->name
, "lease-duration"))
3514 snprintf(name
, sizeof(name
), "%s-default", option
->name
);
3515 num_options
= cupsAddOption(name
, option
->value
, num_options
, &options
);
3517 if (!cupsArrayFind(CommonDefaults
, name
))
3518 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc(name
));
3523 * Convert options to IPP attributes...
3526 cupsEncodeOptions2(p
->attrs
, num_options
, options
, IPP_TAG_PRINTER
);
3527 cupsFreeOptions(num_options
, options
);
3530 * Add standard -default attributes as needed...
3533 if (!cupsGetOption("copies", p
->num_options
, p
->options
))
3534 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
, "copies-default",
3537 if (!cupsGetOption("document-format", p
->num_options
, p
->options
))
3538 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_MIMETYPE
,
3539 "document-format-default", NULL
, "application/octet-stream");
3541 if (!cupsGetOption("job-hold-until", p
->num_options
, p
->options
))
3542 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3543 "job-hold-until-default", NULL
, "no-hold");
3545 if (!cupsGetOption("job-priority", p
->num_options
, p
->options
))
3546 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3547 "job-priority-default", 50);
3549 if (!cupsGetOption("number-up", p
->num_options
, p
->options
))
3550 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3551 "number-up-default", 1);
3553 if (!cupsGetOption("notify-lease-duration", p
->num_options
, p
->options
))
3554 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3555 "notify-lease-duration-default", DefaultLeaseDuration
);
3557 if (!cupsGetOption("notify-events", p
->num_options
, p
->options
))
3558 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3559 "notify-events-default", NULL
, "job-completed");
3561 if (!cupsGetOption("orientation-requested", p
->num_options
, p
->options
))
3562 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NOVALUE
,
3563 "orientation-requested-default", NULL
, NULL
);
3565 if (!cupsGetOption("print-quality", p
->num_options
, p
->options
))
3566 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
3567 "print-quality-default", IPP_QUALITY_NORMAL
);
3572 * 'add_printer_filter()' - Add a MIME filter for a printer.
3577 cupsd_printer_t
*p
, /* I - Printer to add to */
3578 mime_type_t
*filtertype
, /* I - Filter or prefilter MIME type */
3579 const char *filter
) /* I - Filter to add */
3581 char super
[MIME_MAX_SUPER
], /* Super-type for filter */
3582 type
[MIME_MAX_TYPE
], /* Type for filter */
3583 program
[1024]; /* Program/filter name */
3584 int cost
; /* Cost of filter */
3585 mime_type_t
*temptype
; /* MIME type looping var */
3586 char filename
[1024], /* Full filter filename */
3587 *dirsep
; /* Pointer to directory separator */
3588 struct stat fileinfo
; /* File information */
3592 * Parse the filter string; it should be in the following format:
3594 * super/type cost program
3597 if (sscanf(filter
, "%15[^/]/%31s%d%*[ \t]%1023[^\n]", super
, type
, &cost
,
3600 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: invalid filter string \"%s\"!",
3606 * See if the filter program exists; if not, stop the printer and flag
3610 if (strcmp(program
, "-"))
3612 if (program
[0] == '/')
3613 strlcpy(filename
, program
, sizeof(filename
));
3615 snprintf(filename
, sizeof(filename
), "%s/filter/%s", ServerBin
, program
);
3617 if (stat(filename
, &fileinfo
))
3619 memset(&fileinfo
, 0, sizeof(fileinfo
));
3621 snprintf(p
->state_message
, sizeof(p
->state_message
),
3622 "Filter \"%s\" for printer \"%s\" not available: %s",
3623 filename
, p
->name
, strerror(errno
));
3624 cupsdSetPrinterReasons(p
, "+cups-missing-filter-warning");
3626 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s", p
->state_message
);
3630 * When running as root, do additional security checks...
3636 * Only use filters that are owned by root and do not have group or world
3637 * write permissions.
3640 if (fileinfo
.st_uid
||
3641 (fileinfo
.st_mode
& (S_ISUID
| S_IWGRP
| S_IWOTH
)) != 0)
3643 if (fileinfo
.st_uid
)
3644 snprintf(p
->state_message
, sizeof(p
->state_message
),
3645 "Filter \"%s\" for printer \"%s\" not owned by root",
3648 snprintf(p
->state_message
, sizeof(p
->state_message
),
3649 "Filter \"%s\" for printer \"%s\" has insecure permissions "
3650 "(0%o)", filename
, p
->name
, fileinfo
.st_mode
);
3652 cupsdSetPrinterReasons(p
, "+cups-insecure-filter-warning");
3654 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s", p
->state_message
);
3656 else if (fileinfo
.st_mode
)
3659 * Similarly, check that the parent directory is also owned by root and
3660 * does not have world write permissions.
3663 if ((dirsep
= strrchr(filename
, '/')) != NULL
)
3666 if (!stat(filename
, &fileinfo
) &&
3668 (fileinfo
.st_mode
& (S_ISUID
| S_IWGRP
| S_IWOTH
)) != 0))
3670 if (fileinfo
.st_uid
)
3671 snprintf(p
->state_message
, sizeof(p
->state_message
),
3672 "Filter directory \"%s\" for printer \"%s\" not owned by "
3673 "root", filename
, p
->name
);
3675 snprintf(p
->state_message
, sizeof(p
->state_message
),
3676 "Filter directory \"%s\" for printer \"%s\" has insecure "
3677 "permissions (0%o)", filename
, p
->name
, fileinfo
.st_mode
);
3679 cupsdSetPrinterReasons(p
, "+cups-insecure-filter-warning");
3681 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s", p
->state_message
);
3688 * Add the filter to the MIME database, supporting wildcards as needed...
3691 for (temptype
= mimeFirstType(MimeDatabase
);
3693 temptype
= mimeNextType(MimeDatabase
))
3694 if (((super
[0] == '*' && strcasecmp(temptype
->super
, "printer")) ||
3695 !strcasecmp(temptype
->super
, super
)) &&
3696 (type
[0] == '*' || !strcasecmp(temptype
->type
, type
)))
3698 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3699 "add_printer_filter: %s: adding filter %s/%s %s/%s %d %s",
3700 p
->name
, temptype
->super
, temptype
->type
,
3701 filtertype
->super
, filtertype
->type
,
3703 mimeAddFilter(MimeDatabase
, temptype
, filtertype
, cost
, program
);
3709 * 'add_printer_formats()' - Add document-format-supported values for a printer.
3713 add_printer_formats(cupsd_printer_t
*p
) /* I - Printer */
3715 int i
; /* Looping var */
3716 mime_type_t
*type
; /* Current MIME type */
3717 cups_array_t
*filters
; /* Filters */
3718 ipp_attribute_t
*attr
; /* document-format-supported attribute */
3719 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
3720 /* MIME type name */
3724 * Raw (and remote) queues advertise all of the supported MIME
3728 cupsArrayDelete(p
->filetypes
);
3729 p
->filetypes
= NULL
;
3733 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
,
3734 (ipp_tag_t
)(IPP_TAG_MIMETYPE
| IPP_TAG_COPY
),
3735 "document-format-supported", NumMimeTypes
, NULL
, MimeTypes
);
3740 * Otherwise, loop through the supported MIME types and see if there
3741 * are filters for them...
3744 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_printer_formats: %d types, %d filters",
3745 mimeNumTypes(MimeDatabase
), mimeNumFilters(MimeDatabase
));
3747 p
->filetypes
= cupsArrayNew(NULL
, NULL
);
3749 for (type
= mimeFirstType(MimeDatabase
);
3751 type
= mimeNextType(MimeDatabase
))
3753 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
3755 if ((filters
= mimeFilter(MimeDatabase
, type
, p
->filetype
, NULL
)) != NULL
)
3757 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3758 "add_printer_formats: %s: %s needs %d filters",
3759 p
->name
, mimetype
, cupsArrayCount(filters
));
3761 cupsArrayDelete(filters
);
3762 cupsArrayAdd(p
->filetypes
, type
);
3765 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3766 "add_printer_formats: %s: %s not supported",
3771 * Add the file formats that can be filtered...
3774 if ((type
= mimeType(MimeDatabase
, "application", "octet-stream")) == NULL
||
3775 !cupsArrayFind(p
->filetypes
, type
))
3780 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3781 "add_printer_formats: %s: %d supported types",
3782 p
->name
, cupsArrayCount(p
->filetypes
) + i
);
3784 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_MIMETYPE
,
3785 "document-format-supported",
3786 cupsArrayCount(p
->filetypes
) + i
, NULL
, NULL
);
3789 attr
->values
[0].string
.text
= _cupsStrAlloc("application/octet-stream");
3791 for (type
= (mime_type_t
*)cupsArrayFirst(p
->filetypes
);
3793 i
++, type
= (mime_type_t
*)cupsArrayNext(p
->filetypes
))
3795 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
3797 attr
->values
[i
].string
.text
= _cupsStrAlloc(mimetype
);
3802 char pdl
[1024]; /* Buffer to build pdl list */
3803 mime_filter_t
*filter
; /* MIME filter looping var */
3807 * We only support raw printing if this is not a Tioga PrintJobMgr based
3808 * queue and if application/octet-stream is a known type...
3811 for (filter
= (mime_filter_t
*)cupsArrayFirst(MimeDatabase
->filters
);
3813 filter
= (mime_filter_t
*)cupsArrayNext(MimeDatabase
->filters
))
3815 if (filter
->dst
== p
->filetype
&& filter
->filter
&&
3816 strstr(filter
->filter
, "PrintJobMgr"))
3822 if (!filter
&& mimeType(MimeDatabase
, "application", "octet-stream"))
3823 strlcat(pdl
, "application/octet-stream,", sizeof(pdl
));
3826 * Then list a bunch of formats that are supported by the printer...
3829 for (type
= (mime_type_t
*)cupsArrayFirst(p
->filetypes
);
3831 type
= (mime_type_t
*)cupsArrayNext(p
->filetypes
))
3833 if (!strcasecmp(type
->super
, "application"))
3835 if (!strcasecmp(type
->type
, "pdf"))
3836 strlcat(pdl
, "application/pdf,", sizeof(pdl
));
3837 else if (!strcasecmp(type
->type
, "postscript"))
3838 strlcat(pdl
, "application/postscript,", sizeof(pdl
));
3840 else if (!strcasecmp(type
->super
, "image"))
3842 if (!strcasecmp(type
->type
, "jpeg"))
3843 strlcat(pdl
, "image/jpeg,", sizeof(pdl
));
3844 else if (!strcasecmp(type
->type
, "png"))
3845 strlcat(pdl
, "image/png,", sizeof(pdl
));
3850 pdl
[strlen(pdl
) - 1] = '\0'; /* Remove trailing comma */
3852 cupsdSetString(&p
->pdl
, pdl
);
3854 #endif /* HAVE_DNSSD */
3859 * 'add_string_array()' - Add a string to an array of CUPS strings.
3863 add_string_array(cups_array_t
**a
, /* I - Array */
3864 const char *s
) /* I - String */
3867 *a
= cupsArrayNew(NULL
, NULL
);
3869 cupsArrayAdd(*a
, _cupsStrAlloc(s
));
3874 * 'compare_printers()' - Compare two printers.
3877 static int /* O - Result of comparison */
3878 compare_printers(void *first
, /* I - First printer */
3879 void *second
, /* I - Second printer */
3880 void *data
) /* I - App data (not used) */
3882 return (strcasecmp(((cupsd_printer_t
*)first
)->name
,
3883 ((cupsd_printer_t
*)second
)->name
));
3888 * 'delete_printer_filters()' - Delete all MIME filters for a printer.
3892 delete_printer_filters(
3893 cupsd_printer_t
*p
) /* I - Printer to remove from */
3895 mime_filter_t
*filter
; /* MIME filter looping var */
3899 * Range check input...
3906 * Remove all filters from the MIME database that have a destination
3907 * type == printer...
3910 for (filter
= mimeFirstFilter(MimeDatabase
);
3912 filter
= mimeNextFilter(MimeDatabase
))
3913 if (filter
->dst
== p
->filetype
|| filter
->dst
== p
->prefiltertype
)
3916 * Delete the current filter...
3919 mimeDeleteFilter(MimeDatabase
, filter
);
3922 cupsdSetPrinterReasons(p
, "-cups-insecure-filter-warning"
3923 ",cups-missing-filter-warning");
3928 * 'delete_string_array()' - Delete an array of CUPS strings.
3932 delete_string_array(cups_array_t
**a
) /* I - Array */
3934 char *ptr
; /* Current string */
3937 for (ptr
= (char *)cupsArrayFirst(*a
);
3939 ptr
= (char *)cupsArrayNext(*a
))
3942 cupsArrayDelete(*a
);
3948 * 'load_ppd()' - Load a cached PPD file, updating the cache as needed.
3952 load_ppd(cupsd_printer_t
*p
) /* I - Printer */
3954 int i
, j
, k
; /* Looping vars */
3955 cups_file_t
*cache
; /* IPP cache file */
3956 char cache_name
[1024]; /* IPP cache filename */
3957 struct stat cache_info
; /* IPP cache file info */
3958 char pwg_name
[1024]; /* PWG cache filename */
3959 struct stat pwg_info
; /* PWG cache file info */
3960 ppd_file_t
*ppd
; /* PPD file */
3961 char ppd_name
[1024]; /* PPD filename */
3962 struct stat ppd_info
; /* PPD file info */
3963 int num_media
; /* Number of media options */
3964 ppd_size_t
*size
; /* Current PPD size */
3965 ppd_option_t
*duplex
, /* Duplex option */
3966 *output_bin
, /* OutputBin option */
3967 *output_mode
, /* OutputMode option */
3968 *resolution
; /* (Set|JCL|)Resolution option */
3969 ppd_choice_t
*choice
, /* Current PPD choice */
3970 *input_slot
, /* Current input slot */
3971 *media_type
; /* Current media type */
3972 ppd_attr_t
*ppd_attr
; /* PPD attribute */
3973 int xdpi
, /* Horizontal resolution */
3974 ydpi
; /* Vertical resolution */
3975 const char *resptr
; /* Pointer into resolution keyword */
3976 _pwg_size_t
*pwgsize
; /* Current PWG size */
3977 _pwg_map_t
*pwgsource
, /* Current PWG source */
3978 *pwgtype
; /* Current PWG type */
3979 ipp_attribute_t
*attr
; /* Attribute data */
3980 ipp_value_t
*val
; /* Attribute value */
3981 int num_finishings
, /* Number of finishings */
3982 finishings
[5]; /* finishings-supported values */
3983 int num_qualities
, /* Number of print-quality values */
3984 qualities
[3]; /* print-quality values */
3985 int num_margins
, /* Number of media-*-margin-supported values */
3986 margins
[16]; /* media-*-margin-supported values */
3987 static const char * const sides
[3] = /* sides-supported values */
3990 "two-sided-long-edge",
3991 "two-sided-short-edge"
3993 static const char * const standard_commands
[] =
3994 { /* Standard CUPS commands */
4002 * Check to see if the cache is up-to-date...
4005 snprintf(cache_name
, sizeof(cache_name
), "%s/%s.ipp2", CacheDir
, p
->name
);
4006 if (stat(cache_name
, &cache_info
))
4007 cache_info
.st_mtime
= 0;
4009 snprintf(pwg_name
, sizeof(pwg_name
), "%s/%s.pwg", CacheDir
, p
->name
);
4010 if (stat(pwg_name
, &pwg_info
))
4011 pwg_info
.st_mtime
= 0;
4013 snprintf(ppd_name
, sizeof(ppd_name
), "%s/ppd/%s.ppd", ServerRoot
, p
->name
);
4014 if (stat(ppd_name
, &ppd_info
))
4015 ppd_info
.st_mtime
= 1;
4017 ippDelete(p
->ppd_attrs
);
4018 p
->ppd_attrs
= ippNew();
4020 _pwgDestroy(p
->pwg
);
4023 if (pwg_info
.st_mtime
>= ppd_info
.st_mtime
)
4024 p
->pwg
= _pwgCreateWithFile(pwg_name
);
4026 if (cache_info
.st_mtime
>= ppd_info
.st_mtime
&& p
->pwg
&&
4027 (cache
= cupsFileOpen(cache_name
, "r")) != NULL
)
4030 * Load cached information and return...
4033 cupsdLogMessage(CUPSD_LOG_DEBUG
, "load_ppd: Loading %s...", cache_name
);
4035 if (ippReadIO(cache
, (ipp_iocb_t
)cupsFileRead
, 1, NULL
,
4036 p
->ppd_attrs
) == IPP_DATA
)
4038 cupsFileClose(cache
);
4042 cupsFileClose(cache
);
4046 * Reload PPD attributes from disk...
4049 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
4051 _pwgDestroy(p
->pwg
);
4054 cupsdLogMessage(CUPSD_LOG_DEBUG
, "load_ppd: Loading %s...", ppd_name
);
4056 delete_string_array(&(p
->filters
));
4057 delete_string_array(&(p
->pre_filters
));
4059 p
->type
&= ~CUPS_PRINTER_OPTIONS
;
4060 p
->type
|= CUPS_PRINTER_BW
;
4062 finishings
[0] = IPP_FINISHINGS_NONE
;
4065 if ((ppd
= ppdOpenFile(ppd_name
)) != NULL
)
4068 * Add make/model and other various attributes...
4071 p
->pwg
= _pwgCreateWithPPD(ppd
);
4073 ppdMarkDefaults(ppd
);
4075 if (ppd
->color_device
)
4076 p
->type
|= CUPS_PRINTER_COLOR
;
4077 if (ppd
->variable_sizes
)
4078 p
->type
|= CUPS_PRINTER_VARIABLE
;
4079 if (!ppd
->manual_copies
)
4080 p
->type
|= CUPS_PRINTER_COPIES
;
4081 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsFax", NULL
)) != NULL
)
4082 if (ppd_attr
->value
&& !strcasecmp(ppd_attr
->value
, "true"))
4083 p
->type
|= CUPS_PRINTER_FAX
;
4085 ippAddBoolean(p
->ppd_attrs
, IPP_TAG_PRINTER
, "color-supported",
4087 if (ppd
->throughput
)
4089 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4090 "pages-per-minute", ppd
->throughput
);
4091 if (ppd
->color_device
)
4092 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4093 "pages-per-minute-color", ppd
->throughput
);
4098 if ((output_mode
= ppdFindOption(ppd
, "OutputMode")) != NULL
)
4100 if (ppdFindChoice(output_mode
, "draft") ||
4101 ppdFindChoice(output_mode
, "fast"))
4102 qualities
[num_qualities
++] = IPP_QUALITY_DRAFT
;
4103 if (ppdFindChoice(output_mode
, "normal") ||
4104 ppdFindChoice(output_mode
, "good"))
4105 qualities
[num_qualities
++] = IPP_QUALITY_NORMAL
;
4106 if (ppdFindChoice(output_mode
, "best") ||
4107 ppdFindChoice(output_mode
, "high"))
4108 qualities
[num_qualities
++] = IPP_QUALITY_HIGH
;
4110 else if ((ppd_attr
= ppdFindAttr(ppd
, "APPrinterPreset", NULL
)) != NULL
)
4114 if (strstr(ppd_attr
->spec
, "draft") ||
4115 strstr(ppd_attr
->spec
, "Draft"))
4117 qualities
[num_qualities
++] = IPP_QUALITY_DRAFT
;
4121 while ((ppd_attr
= ppdFindNextAttr(ppd
, "APPrinterPreset",
4124 qualities
[num_qualities
++] = IPP_QUALITY_NORMAL
;
4125 qualities
[num_qualities
++] = IPP_QUALITY_HIGH
;
4128 if (num_qualities
== 0)
4129 qualities
[num_qualities
++] = IPP_QUALITY_NORMAL
;
4131 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
4132 "print-quality-supported", num_qualities
, qualities
);
4137 * The NickName can be localized in the character set specified
4138 * by the LanugageEncoding attribute. However, ppdOpen2() has
4139 * already converted the ppd->nickname member to UTF-8 for us
4140 * (the original attribute value is available separately)
4143 cupsdSetString(&p
->make_model
, ppd
->nickname
);
4145 else if (ppd
->modelname
)
4148 * Model name can only contain specific characters...
4151 cupsdSetString(&p
->make_model
, ppd
->modelname
);
4154 cupsdSetString(&p
->make_model
, "Bad PPD File");
4156 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
4157 "printer-make-and-model", NULL
, p
->make_model
);
4160 * Add media options from the PPD file...
4163 if (ppd
->num_sizes
== 0 || !p
->pwg
)
4165 if (!ppdFindAttr(ppd
, "APScannerOnly", NULL
))
4166 cupsdLogMessage(CUPSD_LOG_CRIT
,
4167 "The PPD file for printer %s contains no media "
4168 "options and is therefore invalid!", p
->name
);
4170 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4171 "media-default", NULL
, "unknown");
4172 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4173 "media-supported", NULL
, "unknown");
4181 if ((size
= ppdPageSize(ppd
, NULL
)) != NULL
)
4182 pwgsize
= _pwgGetSize(p
->pwg
, size
->name
);
4186 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4187 "media-default", NULL
,
4188 pwgsize
? pwgsize
->map
.pwg
: "unknown");
4196 ipp_t
*col
; /* Collection value */
4198 input_slot
= ppdFindMarkedChoice(ppd
, "InputSlot");
4199 media_type
= ppdFindMarkedChoice(ppd
, "MediaType");
4200 col
= new_media_col(pwgsize
,
4202 _pwgGetSource(p
->pwg
,
4203 input_slot
->choice
) :
4207 media_type
->choice
) :
4210 ippAddCollection(p
->ppd_attrs
, IPP_TAG_PRINTER
, "media-col-default",
4219 num_media
= p
->pwg
->num_sizes
;
4220 if (p
->pwg
->custom_min_keyword
)
4223 if ((attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4224 "media-supported", num_media
, NULL
,
4229 for (i
= p
->pwg
->num_sizes
, pwgsize
= p
->pwg
->sizes
;
4231 i
--, pwgsize
++, val
++)
4232 val
->string
.text
= _cupsStrRetain(pwgsize
->map
.pwg
);
4234 if (p
->pwg
->custom_min_keyword
)
4236 val
->string
.text
= _cupsStrRetain(p
->pwg
->custom_min_keyword
);
4238 val
->string
.text
= _cupsStrRetain(p
->pwg
->custom_max_keyword
);
4243 * media-source-supported
4246 if (p
->pwg
->num_sources
> 0 &&
4247 (attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4248 "media-source-supported", p
->pwg
->num_sources
,
4249 NULL
, NULL
)) != NULL
)
4251 for (i
= p
->pwg
->num_sources
, pwgsource
= p
->pwg
->sources
,
4254 i
--, pwgsource
++, val
++)
4255 val
->string
.text
= _cupsStrRetain(pwgsource
->pwg
);
4259 * media-type-supported
4262 if (p
->pwg
->num_types
> 0 &&
4263 (attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4264 "media-type-supported", p
->pwg
->num_types
,
4265 NULL
, NULL
)) != NULL
)
4267 for (i
= p
->pwg
->num_types
, pwgtype
= p
->pwg
->types
,
4270 i
--, pwgtype
++, val
++)
4271 val
->string
.text
= _cupsStrRetain(pwgtype
->pwg
);
4275 * media-*-margin-supported
4278 for (i
= p
->pwg
->num_sizes
, pwgsize
= p
->pwg
->sizes
, num_margins
= 0;
4279 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4282 for (j
= 0; j
< num_margins
; j
++)
4283 if (pwgsize
->bottom
== margins
[j
])
4286 if (j
>= num_margins
)
4288 margins
[num_margins
] = pwgsize
->bottom
;
4293 if (num_margins
> 0)
4294 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4295 "media-bottom-margin-supported", num_margins
, margins
);
4297 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4298 "media-bottom-margin-supported", 0);
4300 for (i
= p
->pwg
->num_sizes
, pwgsize
= p
->pwg
->sizes
, num_margins
= 0;
4301 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4304 for (j
= 0; j
< num_margins
; j
++)
4305 if (pwgsize
->left
== margins
[j
])
4308 if (j
>= num_margins
)
4310 margins
[num_margins
] = pwgsize
->left
;
4315 if (num_margins
> 0)
4316 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4317 "media-left-margin-supported", num_margins
, margins
);
4319 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4320 "media-left-margin-supported", 0);
4322 for (i
= p
->pwg
->num_sizes
, pwgsize
= p
->pwg
->sizes
, num_margins
= 0;
4323 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4326 for (j
= 0; j
< num_margins
; j
++)
4327 if (pwgsize
->right
== margins
[j
])
4330 if (j
>= num_margins
)
4332 margins
[num_margins
] = pwgsize
->right
;
4337 if (num_margins
> 0)
4338 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4339 "media-right-margin-supported", num_margins
, margins
);
4341 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4342 "media-right-margin-supported", 0);
4344 for (i
= p
->pwg
->num_sizes
, pwgsize
= p
->pwg
->sizes
, num_margins
= 0;
4345 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4348 for (j
= 0; j
< num_margins
; j
++)
4349 if (pwgsize
->top
== margins
[j
])
4352 if (j
>= num_margins
)
4354 margins
[num_margins
] = pwgsize
->top
;
4359 if (num_margins
> 0)
4360 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4361 "media-top-margin-supported", num_margins
, margins
);
4363 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4364 "media-top-margin-supported", 0);
4367 * media-col-database
4370 num_media
= p
->pwg
->num_sizes
;
4371 if (p
->pwg
->num_sources
)
4373 if (p
->pwg
->num_types
> 0)
4374 num_media
+= p
->pwg
->num_sizes
* p
->pwg
->num_sources
*
4377 num_media
+= p
->pwg
->num_sizes
* p
->pwg
->num_sources
;
4379 else if (p
->pwg
->num_types
)
4380 num_media
+= p
->pwg
->num_sizes
* p
->pwg
->num_types
;
4382 if ((attr
= ippAddCollections(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4383 "media-col-database", num_media
,
4386 for (i
= p
->pwg
->num_sizes
, pwgsize
= p
->pwg
->sizes
, val
= attr
->values
;
4391 * Start by adding the page size without source or type...
4394 ppdMarkOption(ppd
, "PageSize", pwgsize
->map
.ppd
);
4396 val
->collection
= new_media_col(pwgsize
, NULL
, NULL
);
4400 * Then add the specific, supported combinations of size, source, and
4404 if (p
->pwg
->num_sources
> 0)
4406 for (j
= p
->pwg
->num_sources
, pwgsource
= p
->pwg
->sources
;
4410 ppdMarkOption(ppd
, "InputSlot", pwgsource
->ppd
);
4412 if (p
->pwg
->num_types
> 0)
4414 for (k
= p
->pwg
->num_types
, pwgtype
= p
->pwg
->types
;
4418 if (!ppdMarkOption(ppd
, "MediaType", pwgtype
->ppd
))
4420 val
->collection
= new_media_col(pwgsize
, pwgsource
->pwg
,
4426 else if (!ppdConflicts(ppd
))
4428 val
->collection
= new_media_col(pwgsize
, pwgsource
->pwg
, NULL
);
4433 else if (p
->pwg
->num_types
> 0)
4435 for (j
= p
->pwg
->num_types
, pwgtype
= p
->pwg
->types
;
4439 if (!ppdMarkOption(ppd
, "MediaType", pwgtype
->ppd
))
4441 val
->collection
= new_media_col(pwgsize
, NULL
, pwgtype
->pwg
);
4449 * Update the number of media-col-database values...
4452 attr
->num_values
= val
- attr
->values
;
4460 if (p
->pwg
&& p
->pwg
->num_bins
> 0)
4462 attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4463 "output-bin-supported", p
->pwg
->num_bins
,
4468 for (i
= 0, val
= attr
->values
;
4469 i
< p
->pwg
->num_bins
;
4471 val
->string
.text
= _cupsStrAlloc(p
->pwg
->bins
[i
].pwg
);
4474 if ((output_bin
= ppdFindOption(ppd
, "OutputBin")) != NULL
)
4476 for (i
= 0; i
< p
->pwg
->num_bins
; i
++)
4477 if (!strcmp(p
->pwg
->bins
[i
].ppd
, output_bin
->defchoice
))
4480 if (i
>= p
->pwg
->num_bins
)
4483 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4484 "output-bin-default", NULL
, p
->pwg
->bins
[i
].pwg
);
4487 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4488 "output-bin-default", NULL
, p
->pwg
->bins
[0].pwg
);
4490 else if ((ppd_attr
= ppdFindAttr(ppd
, "DefaultOutputOrder",
4492 !strcasecmp(ppd_attr
->value
, "Reverse"))
4494 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4495 "output-bin-supported", NULL
, "face-up");
4496 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4497 "output-bin-default", NULL
, "face-up");
4501 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4502 "output-bin-supported", NULL
, "face-down");
4503 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4504 "output-bin-default", NULL
, "face-down");
4508 * Printer resolutions...
4511 if ((resolution
= ppdFindOption(ppd
, "Resolution")) == NULL
)
4512 if ((resolution
= ppdFindOption(ppd
, "JCLResolution")) == NULL
)
4513 if ((resolution
= ppdFindOption(ppd
, "SetResolution")) == NULL
)
4514 resolution
= ppdFindOption(ppd
, "CNRes_PGP");
4519 * Report all supported resolutions...
4522 attr
= ippAddResolutions(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4523 "printer-resolution-supported",
4524 resolution
->num_choices
, IPP_RES_PER_INCH
,
4527 for (i
= 0, choice
= resolution
->choices
;
4528 i
< resolution
->num_choices
;
4531 xdpi
= ydpi
= (int)strtol(choice
->choice
, (char **)&resptr
, 10);
4532 if (resptr
> choice
->choice
&& xdpi
> 0 && *resptr
== 'x')
4533 ydpi
= (int)strtol(resptr
+ 1, (char **)&resptr
, 10);
4535 if (xdpi
<= 0 || ydpi
<= 0)
4537 cupsdLogMessage(CUPSD_LOG_WARN
,
4538 "Bad resolution \"%s\" for printer %s.",
4539 choice
->choice
, p
->name
);
4543 attr
->values
[i
].resolution
.xres
= xdpi
;
4544 attr
->values
[i
].resolution
.yres
= ydpi
;
4545 attr
->values
[i
].resolution
.units
= IPP_RES_PER_INCH
;
4548 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4549 "printer-resolution-default", IPP_RES_PER_INCH
,
4553 else if ((ppd_attr
= ppdFindAttr(ppd
, "DefaultResolution", NULL
)) != NULL
&&
4557 * Just the DefaultResolution to report...
4560 xdpi
= ydpi
= (int)strtol(ppd_attr
->value
, (char **)&resptr
, 10);
4561 if (resptr
> ppd_attr
->value
&& xdpi
> 0)
4564 ydpi
= (int)strtol(resptr
+ 1, (char **)&resptr
, 10);
4569 if (xdpi
<= 0 || ydpi
<= 0)
4571 cupsdLogMessage(CUPSD_LOG_WARN
,
4572 "Bad default resolution \"%s\" for printer %s.",
4573 ppd_attr
->value
, p
->name
);
4577 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4578 "printer-resolution-default", IPP_RES_PER_INCH
,
4580 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4581 "printer-resolution-supported", IPP_RES_PER_INCH
,
4587 * No resolutions in PPD - make one up...
4590 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4591 "printer-resolution-default", IPP_RES_PER_INCH
,
4593 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4594 "printer-resolution-supported", IPP_RES_PER_INCH
,
4602 if ((duplex
= ppdFindOption(ppd
, "Duplex")) == NULL
)
4603 if ((duplex
= ppdFindOption(ppd
, "EFDuplex")) == NULL
)
4604 if ((duplex
= ppdFindOption(ppd
, "EFDuplexing")) == NULL
)
4605 if ((duplex
= ppdFindOption(ppd
, "KD03Duplex")) == NULL
)
4606 duplex
= ppdFindOption(ppd
, "JCLDuplex");
4608 if (duplex
&& duplex
->num_choices
> 1 &&
4609 !ppdInstallableConflict(ppd
, duplex
->keyword
, "DuplexTumble"))
4611 p
->type
|= CUPS_PRINTER_DUPLEX
;
4613 ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4614 "sides-supported", 3, NULL
, sides
);
4616 if (!strcasecmp(duplex
->defchoice
, "DuplexTumble"))
4617 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4618 "sides-default", NULL
, "two-sided-short-edge");
4619 else if (!strcasecmp(duplex
->defchoice
, "DuplexNoTumble"))
4620 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4621 "sides-default", NULL
, "two-sided-long-edge");
4623 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4624 "sides-default", NULL
, "one-sided");
4628 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4629 "sides-supported", NULL
, "one-sided");
4630 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4631 "sides-default", NULL
, "one-sided");
4634 if (ppdFindOption(ppd
, "Collate") != NULL
)
4635 p
->type
|= CUPS_PRINTER_COLLATE
;
4637 if (ppdFindOption(ppd
, "StapleLocation") != NULL
)
4639 p
->type
|= CUPS_PRINTER_STAPLE
;
4640 finishings
[num_finishings
++] = IPP_FINISHINGS_STAPLE
;
4643 if (ppdFindOption(ppd
, "BindEdge") != NULL
)
4645 p
->type
|= CUPS_PRINTER_BIND
;
4646 finishings
[num_finishings
++] = IPP_FINISHINGS_BIND
;
4649 for (i
= 0; i
< ppd
->num_sizes
; i
++)
4650 if (ppd
->sizes
[i
].length
> 1728)
4651 p
->type
|= CUPS_PRINTER_LARGE
;
4652 else if (ppd
->sizes
[i
].length
> 1008)
4653 p
->type
|= CUPS_PRINTER_MEDIUM
;
4655 p
->type
|= CUPS_PRINTER_SMALL
;
4657 if ((ppd_attr
= ppdFindAttr(ppd
, "APICADriver", NULL
)) != NULL
&&
4658 ppd_attr
->value
&& !strcasecmp(ppd_attr
->value
, "true"))
4660 if ((ppd_attr
= ppdFindAttr(ppd
, "APScannerOnly", NULL
)) != NULL
&&
4661 ppd_attr
->value
&& !strcasecmp(ppd_attr
->value
, "true"))
4662 p
->type
|= CUPS_PRINTER_SCANNER
;
4664 p
->type
|= CUPS_PRINTER_MFP
;
4668 * Add a filter from application/vnd.cups-raw to printer/name to
4669 * handle "raw" printing by users.
4672 add_string_array(&(p
->filters
), "application/vnd.cups-raw 0 -");
4675 * Add any pre-filters in the PPD file...
4678 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsPreFilter", NULL
)) != NULL
)
4680 for (; ppd_attr
; ppd_attr
= ppdFindNextAttr(ppd
, "cupsPreFilter", NULL
))
4681 if (ppd_attr
->value
)
4682 add_string_array(&(p
->pre_filters
), ppd_attr
->value
);
4686 * Add any filters in the PPD file...
4689 DEBUG_printf(("ppd->num_filters = %d\n", ppd
->num_filters
));
4690 for (i
= 0; i
< ppd
->num_filters
; i
++)
4692 DEBUG_printf(("ppd->filters[%d] = \"%s\"\n", i
, ppd
->filters
[i
]));
4693 add_string_array(&(p
->filters
), ppd
->filters
[i
]);
4695 if (!strncasecmp(ppd
->filters
[i
], "application/vnd.cups-command", 28) &&
4696 isspace(ppd
->filters
[i
][28] & 255))
4697 p
->type
|= CUPS_PRINTER_COMMANDS
;
4700 if (ppd
->num_filters
== 0)
4703 * If there are no filters, add PostScript printing filters.
4706 add_string_array(&(p
->filters
),
4707 "application/vnd.cups-command 0 commandtops");
4708 add_string_array(&(p
->filters
),
4709 "application/vnd.cups-postscript 0 -");
4711 p
->type
|= CUPS_PRINTER_COMMANDS
;
4713 else if (!(p
->type
& CUPS_PRINTER_COMMANDS
))
4716 * See if this is a PostScript device without a command filter...
4719 for (i
= 0; i
< ppd
->num_filters
; i
++)
4720 if (!strncasecmp(ppd
->filters
[i
],
4721 "application/vnd.cups-postscript", 31) &&
4722 isspace(ppd
->filters
[i
][31] & 255))
4725 if (i
< ppd
->num_filters
)
4728 * Add the generic PostScript command filter...
4731 add_string_array(&(p
->filters
),
4732 "application/vnd.cups-command 0 commandtops");
4733 p
->type
|= CUPS_PRINTER_COMMANDS
;
4737 if (p
->type
& CUPS_PRINTER_COMMANDS
)
4739 char *commands
, /* Copy of commands */
4740 *start
, /* Start of name */
4741 *end
; /* End of name */
4742 int count
; /* Number of commands */
4745 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsCommands", NULL
)) != NULL
&&
4746 ppd_attr
->value
&& ppd_attr
->value
[0])
4748 for (count
= 0, start
= ppd_attr
->value
; *start
; count
++)
4750 while (isspace(*start
& 255))
4756 while (*start
&& !isspace(*start
& 255))
4766 * Make a copy of the commands string and count how many ...
4769 attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4770 "printer-commands", count
, NULL
, NULL
);
4772 commands
= strdup(ppd_attr
->value
);
4774 for (count
= 0, start
= commands
; *start
; count
++)
4776 while (isspace(*start
& 255))
4783 while (*end
&& !isspace(*end
& 255))
4789 attr
->values
[count
].string
.text
= _cupsStrAlloc(start
);
4799 * Add the standard list of commands...
4802 ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4804 (int)(sizeof(standard_commands
) /
4805 sizeof(standard_commands
[0])), NULL
,
4812 * No commands supported...
4815 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4816 "printer-commands", NULL
, "none");
4820 * Show current and available port monitors for this printer...
4823 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
, "port-monitor",
4824 NULL
, p
->port_monitor
? p
->port_monitor
: "none");
4826 for (i
= 1, ppd_attr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
4828 i
++, ppd_attr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
));
4832 if (strstr(ppd
->protocols
, "TBCP"))
4834 else if (strstr(ppd
->protocols
, "BCP"))
4838 attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
4839 "port-monitor-supported", i
, NULL
, NULL
);
4841 attr
->values
[0].string
.text
= _cupsStrAlloc("none");
4843 for (i
= 1, ppd_attr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
4845 i
++, ppd_attr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
))
4846 attr
->values
[i
].string
.text
= _cupsStrAlloc(ppd_attr
->value
);
4850 if (strstr(ppd
->protocols
, "TBCP"))
4851 attr
->values
[i
].string
.text
= _cupsStrAlloc("tbcp");
4852 else if (strstr(ppd
->protocols
, "BCP"))
4853 attr
->values
[i
].string
.text
= _cupsStrAlloc("bcp");
4857 cupsdSetString(&p
->product
, ppd
->product
);
4858 #endif /* HAVE_DNSSD */
4860 if (ppdFindAttr(ppd
, "APRemoteQueueID", NULL
))
4861 p
->type
|= CUPS_PRINTER_REMOTE
;
4864 * Close the PPD and set the type...
4869 else if (!access(ppd_name
, 0))
4871 int pline
; /* PPD line number */
4872 ppd_status_t pstatus
; /* PPD load status */
4875 pstatus
= ppdLastError(&pline
);
4877 cupsdLogMessage(CUPSD_LOG_ERROR
, "PPD file for %s cannot be loaded!",
4880 if (pstatus
<= PPD_ALLOC_ERROR
)
4881 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s", strerror(errno
));
4883 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s on line %d.",
4884 ppdErrorString(pstatus
), pline
);
4886 cupsdLogMessage(CUPSD_LOG_INFO
,
4887 "Hint: Run \"cupstestppd %s\" and fix any errors.",
4891 * Add a filter from application/vnd.cups-raw to printer/name to
4892 * handle "raw" printing by users.
4895 add_string_array(&(p
->filters
), "application/vnd.cups-raw 0 -");
4898 * Add a PostScript filter, since this is still possibly PS printer.
4901 add_string_array(&(p
->filters
), "application/vnd.cups-postscript 0 -");
4906 * If we have an interface script, add a filter entry for it...
4909 char interface
[1024]; /* Interface script */
4912 snprintf(interface
, sizeof(interface
), "%s/interfaces/%s", ServerRoot
,
4914 if (!access(interface
, X_OK
))
4917 * Yes, we have a System V style interface script; use it!
4920 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
4921 "printer-make-and-model", NULL
,
4922 "Local System V Printer");
4924 snprintf(interface
, sizeof(interface
), "*/* 0 %s/interfaces/%s",
4925 ServerRoot
, p
->name
);
4926 add_string_array(&(p
->filters
), interface
);
4928 else if (!strncmp(p
->device_uri
, "ipp://", 6) &&
4929 (strstr(p
->device_uri
, "/printers/") != NULL
||
4930 strstr(p
->device_uri
, "/classes/") != NULL
||
4931 (strstr(p
->device_uri
, "._ipp.") != NULL
&&
4932 !strcmp(p
->device_uri
+ strlen(p
->device_uri
) - 5,
4936 * Tell the client this is really a hard-wired remote printer.
4939 p
->type
|= CUPS_PRINTER_REMOTE
;
4942 * Point the printer-uri-supported attribute to the
4946 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
4947 "printer-uri-supported", NULL
, p
->device_uri
);
4950 * Then set the make-and-model accordingly...
4953 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
4954 "printer-make-and-model", NULL
, "Remote Printer");
4957 * Print all files directly...
4966 * Otherwise we have neither - treat this as a "dumb" printer
4967 * with no PPD file...
4970 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
4971 "printer-make-and-model", NULL
, "Local Raw Printer");
4977 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
4978 "finishings-supported", num_finishings
, finishings
);
4979 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
4980 "finishings-default", IPP_FINISHINGS_NONE
);
4982 if (ppd
&& (cache
= cupsFileOpen(cache_name
, "w9")) != NULL
)
4985 * Save cached PPD attributes to disk...
4988 cupsdLogMessage(CUPSD_LOG_DEBUG
, "load_ppd: Saving %s...", cache_name
);
4990 p
->ppd_attrs
->state
= IPP_IDLE
;
4992 if (ippWriteIO(cache
, (ipp_iocb_t
)cupsFileWrite
, 1, NULL
,
4993 p
->ppd_attrs
) != IPP_DATA
)
4995 cupsdLogMessage(CUPSD_LOG_ERROR
,
4996 "Unable to save PPD cache file \"%s\" - %s", cache_name
,
5001 cupsFileClose(cache
);
5003 _pwgWriteFile(p
->pwg
, pwg_name
);
5008 * Remove cache files...
5011 if (cache_info
.st_mtime
)
5014 if (pwg_info
.st_mtime
)
5021 * 'new_media_col()' - Create a media-col collection value.
5024 static ipp_t
* /* O - Collection value */
5025 new_media_col(_pwg_size_t
*size
, /* I - media-size/margin values */
5026 const char *source
, /* I - media-source value */
5027 const char *type
) /* I - media-type value */
5029 ipp_t
*media_col
, /* Collection value */
5030 *media_size
; /* media-size value */
5033 media_col
= ippNew();
5035 media_size
= ippNew();
5036 ippAddInteger(media_size
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5037 "x-dimension", size
->width
);
5038 ippAddInteger(media_size
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5039 "y-dimension", size
->length
);
5040 ippAddCollection(media_col
, IPP_TAG_PRINTER
, "media-size", media_size
);
5041 ippDelete(media_size
);
5043 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5044 "media-bottom-margin", size
->bottom
);
5045 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5046 "media-left-margin", size
->left
);
5047 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5048 "media-right-margin", size
->right
);
5049 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5050 "media-top-margin", size
->top
);
5053 ippAddString(media_col
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
, "media-source",
5057 ippAddString(media_col
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
, "media-type",
5066 * 'write_irix_config()' - Update the config files used by the IRIX
5071 write_irix_config(cupsd_printer_t
*p
) /* I - Printer to update */
5073 char filename
[1024]; /* Interface script filename */
5074 cups_file_t
*fp
; /* Interface script file */
5075 ipp_attribute_t
*attr
; /* Attribute data */
5079 * Add dummy interface and GUI scripts to fool SGI's "challenged" printing
5080 * tools. First the interface script that tells the tools what kind of
5081 * printer we have...
5084 snprintf(filename
, sizeof(filename
), "/var/spool/lp/interface/%s", p
->name
);
5086 if (p
->type
& CUPS_PRINTER_CLASS
)
5088 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
5090 cupsFilePuts(fp
, "#!/bin/sh\n");
5092 if ((attr
= ippFindAttribute(p
->attrs
, "printer-make-and-model",
5093 IPP_TAG_TEXT
)) != NULL
)
5094 cupsFilePrintf(fp
, "NAME=\"%s\"\n", attr
->values
[0].string
.text
);
5095 else if (p
->type
& CUPS_PRINTER_CLASS
)
5096 cupsFilePuts(fp
, "NAME=\"Printer Class\"\n");
5098 cupsFilePuts(fp
, "NAME=\"Remote Destination\"\n");
5100 if (p
->type
& CUPS_PRINTER_COLOR
)
5101 cupsFilePuts(fp
, "TYPE=ColorPostScript\n");
5103 cupsFilePuts(fp
, "TYPE=MonoPostScript\n");
5105 cupsFilePrintf(fp
, "HOSTNAME=%s\n", ServerName
);
5106 cupsFilePrintf(fp
, "HOSTPRINTER=%s\n", p
->name
);
5110 chmod(filename
, 0755);
5111 chown(filename
, User
, Group
);
5115 * Then the member file that tells which device file the queue is connected
5116 * to... Networked printers use "/dev/null" in this file, so that's what
5117 * we use (the actual device URI can confuse some apps...)
5120 snprintf(filename
, sizeof(filename
), "/var/spool/lp/member/%s", p
->name
);
5122 if (p
->type
& CUPS_PRINTER_CLASS
)
5124 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
5126 cupsFilePuts(fp
, "/dev/null\n");
5130 chmod(filename
, 0644);
5131 chown(filename
, User
, Group
);
5135 * The gui_interface file is a script or program that launches a GUI
5136 * option panel for the printer, using options specified on the
5137 * command-line in the third argument. The option panel must send
5138 * any printing options to stdout on a single line when the user
5139 * accepts them, or nothing if the user cancels the dialog.
5141 * The default options panel program is /usr/bin/glpoptions, from
5142 * the ESP Print Pro software. You can select another using the
5143 * PrintcapGUI option.
5146 snprintf(filename
, sizeof(filename
), "/var/spool/lp/gui_interface/ELF/%s.gui", p
->name
);
5148 if (p
->type
& CUPS_PRINTER_CLASS
)
5150 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
5152 cupsFilePuts(fp
, "#!/bin/sh\n");
5153 cupsFilePrintf(fp
, "%s -d %s -o \"$3\"\n", PrintcapGUI
, p
->name
);
5157 chmod(filename
, 0755);
5158 chown(filename
, User
, Group
);
5162 * The POD config file is needed by the printstatus command to show
5163 * the printer location and device.
5166 snprintf(filename
, sizeof(filename
), "/var/spool/lp/pod/%s.config", p
->name
);
5168 if (p
->type
& CUPS_PRINTER_CLASS
)
5170 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
5172 cupsFilePrintf(fp
, "Printer Class | %s\n",
5173 (p
->type
& CUPS_PRINTER_COLOR
) ? "ColorPostScript" : "MonoPostScript");
5174 cupsFilePrintf(fp
, "Printer Model | %s\n", p
->make_model
? p
->make_model
: "");
5175 cupsFilePrintf(fp
, "Location Code | %s\n", p
->location
? p
->location
: "");
5176 cupsFilePrintf(fp
, "Physical Location | %s\n", p
->info
? p
->info
: "");
5177 cupsFilePrintf(fp
, "Port Path | %s\n", p
->device_uri
);
5178 cupsFilePrintf(fp
, "Config Path | /var/spool/lp/pod/%s.config\n", p
->name
);
5179 cupsFilePrintf(fp
, "Active Status Path | /var/spool/lp/pod/%s.status\n", p
->name
);
5180 cupsFilePuts(fp
, "Status Update Wait | 10 seconds\n");
5184 chmod(filename
, 0664);
5185 chown(filename
, User
, Group
);
5191 * 'write_irix_state()' - Update the status files used by IRIX printing
5196 write_irix_state(cupsd_printer_t
*p
) /* I - Printer to update */
5198 char filename
[1024]; /* Interface script filename */
5199 cups_file_t
*fp
; /* Interface script file */
5200 int tag
; /* Status tag value */
5206 * The POD status file is needed for the printstatus window to
5207 * provide the current status of the printer.
5210 snprintf(filename
, sizeof(filename
), "/var/spool/lp/pod/%s.status", p
->name
);
5212 if (p
->type
& CUPS_PRINTER_CLASS
)
5214 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
5216 cupsFilePrintf(fp
, "Operational Status | %s\n",
5217 (p
->state
== IPP_PRINTER_IDLE
) ? "Idle" :
5218 (p
->state
== IPP_PRINTER_PROCESSING
) ? "Busy" :
5220 cupsFilePrintf(fp
, "Information | 01 00 00 | %s\n", CUPS_SVERSION
);
5221 cupsFilePrintf(fp
, "Information | 02 00 00 | Device URI: %s\n",
5223 cupsFilePrintf(fp
, "Information | 03 00 00 | %s jobs\n",
5224 p
->accepting
? "Accepting" : "Not accepting");
5225 cupsFilePrintf(fp
, "Information | 04 00 00 | %s\n", p
->state_message
);
5229 chmod(filename
, 0664);
5230 chown(filename
, User
, Group
);
5234 * The activeicons file is needed to provide desktop icons for printers:
5236 * [ quoted from /usr/lib/print/tagit ]
5238 * --- Type of printer tags (base values)
5240 * Dumb=66048 # 0x10200
5241 * DumbColor=66080 # 0x10220
5242 * Raster=66112 # 0x10240
5243 * ColorRaster=66144 # 0x10260
5244 * Plotter=66176 # 0x10280
5245 * PostScript=66208 # 0x102A0
5246 * ColorPostScript=66240 # 0x102C0
5247 * MonoPostScript=66272 # 0x102E0
5249 * --- Printer state modifiers for local printers
5254 * Unknown=3 # 0x3 (Faulted due to unknown reason)
5256 * --- Printer state modifiers for network printers
5260 * NetFaulted=10 # 0xA
5261 * NetUnknown=11 # 0xB (Faulted due to unknown reason)
5264 snprintf(filename
, sizeof(filename
), "/var/spool/lp/activeicons/%s", p
->name
);
5266 if (p
->type
& CUPS_PRINTER_CLASS
)
5268 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
5270 if (p
->type
& CUPS_PRINTER_COLOR
)
5275 if (p
->type
& CUPS_PRINTER_REMOTE
)
5278 if (p
->state
== IPP_PRINTER_PROCESSING
)
5281 else if (p
->state
== IPP_PRINTER_STOPPED
)
5284 cupsFilePuts(fp
, "#!/bin/sh\n");
5285 cupsFilePrintf(fp
, "#Tag %d\n", tag
);
5289 chmod(filename
, 0755);
5290 chown(filename
, User
, Group
);
5295 * The default file is needed by the printers window to show
5296 * the default printer.
5299 snprintf(filename
, sizeof(filename
), "/var/spool/lp/default");
5301 if (DefaultPrinter
!= NULL
)
5303 if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
5305 cupsFilePrintf(fp
, "%s\n", DefaultPrinter
->name
);
5309 chmod(filename
, 0644);
5310 chown(filename
, User
, Group
);
5320 * 'write_xml_string()' - Write a string with XML escaping.
5324 write_xml_string(cups_file_t
*fp
, /* I - File to write to */
5325 const char *s
) /* I - String to write */
5327 const char *start
; /* Start of current sequence */
5333 for (start
= s
; *s
; s
++)
5338 cupsFileWrite(fp
, start
, s
- start
);
5340 cupsFilePuts(fp
, "&");
5346 cupsFileWrite(fp
, start
, s
- start
);
5348 cupsFilePuts(fp
, "<");
5354 cupsFilePuts(fp
, start
);
5359 * End of "$Id: printers.c 7968 2008-09-19 23:03:01Z mike $".