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
,
315 IPP_SET_PRINTER_ATTRIBUTES
,
316 IPP_SET_JOB_ATTRIBUTES
,
317 IPP_GET_PRINTER_SUPPORTED_VALUES
,
318 IPP_CREATE_PRINTER_SUBSCRIPTION
,
319 IPP_CREATE_JOB_SUBSCRIPTION
,
320 IPP_GET_SUBSCRIPTION_ATTRIBUTES
,
321 IPP_GET_SUBSCRIPTIONS
,
322 IPP_RENEW_SUBSCRIPTION
,
323 IPP_CANCEL_SUBSCRIPTION
,
324 IPP_GET_NOTIFICATIONS
,
328 IPP_RELEASE_HELD_NEW_JOBS
,
345 CUPS_AUTHENTICATE_JOB
,
350 static const char * const charsets
[] =/* charset-supported values */
355 static const char * const compressions
[] =
356 { /* document-compression-supported values */
360 #endif /* HAVE_LIBZ */
362 static const char * const media_col_supported
[] =
363 { /* media-col-supported values */
364 "media-bottom-margin",
366 "media-right-margin",
372 static const char * const multiple_document_handling
[] =
373 { /* multiple-document-handling-supported values */
374 "separate-documents-uncollated-copies",
375 "separate-documents-collated-copies"
377 static const char * const notify_attrs
[] =
378 { /* notify-attributes-supported values */
379 "printer-state-change-time",
380 "notify-lease-expiration-time",
381 "notify-subscriber-user-name"
383 static const char * const notify_events
[] =
384 { /* notify-events-supported values */
386 "job-config-changed",
393 "printer-config-changed",
395 "printer-finishings-changed",
396 "printer-media-changed",
400 "printer-state-changed",
407 static const char * const job_creation
[] =
408 { /* job-creation-attributes-supported */
417 "multiple-document-handling",
420 "orientation-requested",
423 "printer-resolution",
426 static const char * const job_settable
[] =
427 { /* job-settable-attributes-supported */
435 "multiple-document-handling",
438 "orientation-requested",
441 "printer-resolution",
444 static const char * const printer_settable
[] =
445 { /* printer-settable-attributes-supported */
449 static const char * const which_jobs
[] =
450 { /* which-jobs-supported values */
464 ippDelete(CommonData
);
466 CommonData
= ippNew();
469 * This list of attributes is sorted to improve performance when the
470 * client provides a requested-attributes attribute...
473 /* charset-configured */
474 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_CHARSET
| IPP_TAG_COPY
,
475 "charset-configured", NULL
, "utf-8");
477 /* charset-supported */
478 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_CHARSET
| IPP_TAG_COPY
,
479 "charset-supported", sizeof(charsets
) / sizeof(charsets
[0]),
482 /* compression-supported */
483 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
484 "compression-supported",
485 sizeof(compressions
) / sizeof(compressions
[0]),
488 /* copies-supported */
489 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "copies-supported", 1, MaxCopies
);
492 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
| IPP_TAG_COPY
,
493 "cups-version", NULL
, CUPS_SVERSION
+ 6);
495 /* generated-natural-language-supported (no IPP_TAG_COPY) */
496 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_LANGUAGE
,
497 "generated-natural-language-supported", NULL
, DefaultLanguage
);
499 /* ipp-versions-supported */
500 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
501 "ipp-versions-supported", sizeof(versions
) / sizeof(versions
[0]),
504 /* job-creation-attributes-supported */
505 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
506 "job-creation-attributes-supported",
507 sizeof(job_creation
) / sizeof(job_creation
[0]),
510 /* job-hold-until-supported */
511 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
512 "job-hold-until-supported", sizeof(holds
) / sizeof(holds
[0]),
515 /* job-ids-supported */
516 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
, "job-ids-supported", 1);
518 /* job-priority-supported */
519 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
520 "job-priority-supported", 100);
522 /* job-settable-attributes-supported */
523 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
524 "job-settable-attributes-supported",
525 sizeof(job_settable
) / sizeof(job_settable
[0]),
528 /* job-sheets-supported */
529 if (cupsArrayCount(Banners
) > 0)
532 * Setup the job-sheets-supported attribute...
535 if (Classification
&& !ClassifyOverride
)
536 attr
= ippAddString(CommonData
, IPP_TAG_PRINTER
,
537 IPP_TAG_NAME
| IPP_TAG_COPY
,
538 "job-sheets-supported", NULL
, Classification
);
540 attr
= ippAddStrings(CommonData
, IPP_TAG_PRINTER
,
541 IPP_TAG_NAME
| IPP_TAG_COPY
,
542 "job-sheets-supported", cupsArrayCount(Banners
) + 1,
546 cupsdLogMessage(CUPSD_LOG_EMERG
,
547 "Unable to allocate memory for "
548 "job-sheets-supported attribute: %s!", strerror(errno
));
549 else if (!Classification
|| ClassifyOverride
)
551 cupsd_banner_t
*banner
; /* Current banner */
554 attr
->values
[0].string
.text
= _cupsStrAlloc("none");
556 for (i
= 1, banner
= (cupsd_banner_t
*)cupsArrayFirst(Banners
);
558 i
++, banner
= (cupsd_banner_t
*)cupsArrayNext(Banners
))
559 attr
->values
[i
].string
.text
= banner
->name
;
563 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
564 "job-sheets-supported", NULL
, "none");
566 /* media-col-supported */
567 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
568 "media-col-supported",
569 sizeof(media_col_supported
) /
570 sizeof(media_col_supported
[0]), NULL
,
571 media_col_supported
);
573 /* multiple-document-handling-supported */
574 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
575 "multiple-document-handling-supported",
576 sizeof(multiple_document_handling
) /
577 sizeof(multiple_document_handling
[0]), NULL
,
578 multiple_document_handling
);
580 /* multiple-document-jobs-supported */
581 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
,
582 "multiple-document-jobs-supported", 1);
584 /* multiple-operation-time-out */
585 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
586 "multiple-operation-time-out", MultipleOperationTimeout
);
588 /* natural-language-configured (no IPP_TAG_COPY) */
589 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_LANGUAGE
,
590 "natural-language-configured", NULL
, DefaultLanguage
);
592 /* notify-attributes-supported */
593 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
594 "notify-attributes-supported",
595 (int)(sizeof(notify_attrs
) / sizeof(notify_attrs
[0])),
598 /* notify-lease-duration-supported */
599 ippAddRange(CommonData
, IPP_TAG_PRINTER
,
600 "notify-lease-duration-supported", 0,
601 MaxLeaseDuration
? MaxLeaseDuration
: 2147483647);
603 /* notify-max-events-supported */
604 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
605 "notify-max-events-supported", MaxEvents
);
607 /* notify-events-supported */
608 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
609 "notify-events-supported",
610 (int)(sizeof(notify_events
) / sizeof(notify_events
[0])),
611 NULL
, notify_events
);
613 /* notify-pull-method-supported */
614 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
615 "notify-pull-method-supported", NULL
, "ippget");
617 /* notify-schemes-supported */
618 snprintf(filename
, sizeof(filename
), "%s/notifier", ServerBin
);
619 if ((dir
= cupsDirOpen(filename
)) != NULL
)
621 notifiers
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
623 while ((dent
= cupsDirRead(dir
)) != NULL
)
624 if (S_ISREG(dent
->fileinfo
.st_mode
) &&
625 (dent
->fileinfo
.st_mode
& S_IXOTH
) != 0)
626 cupsArrayAdd(notifiers
, _cupsStrAlloc(dent
->filename
));
628 if (cupsArrayCount(notifiers
) > 0)
630 attr
= ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
631 "notify-schemes-supported",
632 cupsArrayCount(notifiers
), NULL
, NULL
);
634 for (i
= 0, notifier
= (char *)cupsArrayFirst(notifiers
);
636 i
++, notifier
= (char *)cupsArrayNext(notifiers
))
637 attr
->values
[i
].string
.text
= notifier
;
640 cupsArrayDelete(notifiers
);
644 /* number-up-supported */
645 ippAddIntegers(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
646 "number-up-supported", sizeof(nups
) / sizeof(nups
[0]), nups
);
648 /* operations-supported */
649 ippAddIntegers(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
650 "operations-supported",
651 sizeof(ops
) / sizeof(ops
[0]) + JobFiles
- 1, ops
);
653 /* orientation-requested-supported */
654 ippAddIntegers(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
655 "orientation-requested-supported", 4, orients
);
657 /* page-ranges-supported */
658 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
, "page-ranges-supported", 1);
660 /* pdf-override-supported */
661 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
662 "pdl-override-supported", NULL
, "not-attempted");
664 /* printer-op-policy-supported */
665 attr
= ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
666 "printer-op-policy-supported", cupsArrayCount(Policies
),
668 for (i
= 0, p
= (cupsd_policy_t
*)cupsArrayFirst(Policies
);
670 i
++, p
= (cupsd_policy_t
*)cupsArrayNext(Policies
))
671 attr
->values
[i
].string
.text
= p
->name
;
673 /* printer-settable-attributes-supported */
674 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
675 "printer-settable-attributes-supported",
676 sizeof(printer_settable
) / sizeof(printer_settable
[0]),
677 NULL
, printer_settable
);
679 /* server-is-sharing-printers */
680 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
, "server-is-sharing-printers",
681 BrowseLocalProtocols
!= 0 && Browsing
);
683 /* which-jobs-supported */
684 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
685 "which-jobs-supported",
686 sizeof(which_jobs
) / sizeof(which_jobs
[0]), NULL
, which_jobs
);
691 * 'cupsdDeleteAllPrinters()' - Delete all printers from the system.
695 cupsdDeleteAllPrinters(void)
697 cupsd_printer_t
*p
; /* Pointer to current printer/class */
700 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
702 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
704 p
->op_policy_ptr
= DefaultPolicyPtr
;
705 cupsdDeletePrinter(p
, 0);
711 * 'cupsdDeletePrinter()' - Delete a printer from the system.
714 int /* O - 1 if classes affected, 0 otherwise */
716 cupsd_printer_t
*p
, /* I - Printer to delete */
717 int update
) /* I - Update printers.conf? */
719 int i
, /* Looping var */
720 changed
= 0; /* Class changed? */
722 char filename
[1024]; /* Interface script filename */
726 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdDeletePrinter(p=%p(%s), update=%d)",
730 * Save the current position in the Printers array...
733 cupsArraySave(Printers
);
736 * Stop printing on this printer...
739 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, update
);
742 cupsdSetJobState(p
->job
, IPP_JOB_PENDING
, CUPSD_JOB_FORCE
,
743 update
? "Job stopped due to printer being deleted." :
747 * If this printer is the next for browsing, point to the next one...
752 cupsArrayFind(Printers
, p
);
753 BrowseNext
= (cupsd_printer_t
*)cupsArrayNext(Printers
);
757 * Remove the printer from the list...
760 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
761 "cupsdDeletePrinter: Removing %s from Printers", p
->name
);
762 cupsArrayRemove(Printers
, p
);
764 if (p
->type
& CUPS_PRINTER_IMPLICIT
)
766 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
767 "cupsdDeletePrinter: Removing %s from ImplicitPrinters",
769 cupsArrayRemove(ImplicitPrinters
, p
);
773 * Remove the dummy interface/icon/option files under IRIX...
777 snprintf(filename
, sizeof(filename
), "/var/spool/lp/interface/%s", p
->name
);
780 snprintf(filename
, sizeof(filename
), "/var/spool/lp/gui_interface/ELF/%s.gui",
784 snprintf(filename
, sizeof(filename
), "/var/spool/lp/activeicons/%s", p
->name
);
787 snprintf(filename
, sizeof(filename
), "/var/spool/lp/pod/%s.config", p
->name
);
790 snprintf(filename
, sizeof(filename
), "/var/spool/lp/pod/%s.status", p
->name
);
793 snprintf(filename
, sizeof(filename
), "/var/spool/lp/member/%s", p
->name
);
798 * If p is the default printer, assign a different one...
801 if (p
== DefaultPrinter
)
803 DefaultPrinter
= NULL
;
805 if (UseNetworkDefault
)
808 * Find the first network default printer and use it...
811 cupsd_printer_t
*dp
; /* New default printer */
814 for (dp
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
816 dp
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
817 if (dp
!= p
&& (dp
->type
& CUPS_PRINTER_DEFAULT
))
826 * Remove this printer from any classes...
829 if (!(p
->type
& CUPS_PRINTER_IMPLICIT
))
831 changed
= cupsdDeletePrinterFromClasses(p
);
834 * Deregister from any browse protocols...
837 cupsdDeregisterPrinter(p
, 1);
841 * Free all memory used by the printer...
844 if (p
->printers
!= NULL
)
847 if (MaxPrinterHistory
)
849 for (i
= 0; i
< p
->num_history
; i
++)
850 ippDelete(p
->history
[i
]);
855 delete_printer_filters(p
);
857 for (i
= 0; i
< p
->num_reasons
; i
++)
858 _cupsStrFree(p
->reasons
[i
]);
861 ippDelete(p
->ppd_attrs
);
863 mimeDeleteType(MimeDatabase
, p
->filetype
);
864 mimeDeleteType(MimeDatabase
, p
->prefiltertype
);
866 delete_string_array(&(p
->filters
));
867 delete_string_array(&(p
->pre_filters
));
869 cupsdFreePrinterUsers(p
);
872 cupsdClearString(&p
->uri
);
873 cupsdClearString(&p
->hostname
);
874 cupsdClearString(&p
->name
);
875 cupsdClearString(&p
->location
);
876 cupsdClearString(&p
->make_model
);
877 cupsdClearString(&p
->info
);
878 cupsdClearString(&p
->job_sheets
[0]);
879 cupsdClearString(&p
->job_sheets
[1]);
880 cupsdClearString(&p
->device_uri
);
881 cupsdClearString(&p
->sanitized_device_uri
);
882 cupsdClearString(&p
->port_monitor
);
883 cupsdClearString(&p
->op_policy
);
884 cupsdClearString(&p
->error_policy
);
886 cupsdClearString(&p
->alert
);
887 cupsdClearString(&p
->alert_description
);
890 cupsdClearString(&p
->product
);
891 cupsdClearString(&p
->pdl
);
892 #endif /* HAVE_DNSSD */
894 cupsArrayDelete(p
->filetypes
);
897 free(p
->browse_attrs
);
899 cupsFreeOptions(p
->num_options
, p
->options
);
904 * Restore the previous position in the Printers array...
907 cupsArrayRestore(Printers
);
914 * 'cupsdFindDest()' - Find a destination in the list.
917 cupsd_printer_t
* /* O - Destination in list */
918 cupsdFindDest(const char *name
) /* I - Name of printer or class to find */
920 cupsd_printer_t key
; /* Search key */
923 key
.name
= (char *)name
;
924 return ((cupsd_printer_t
*)cupsArrayFind(Printers
, &key
));
929 * 'cupsdFindPrinter()' - Find a printer in the list.
932 cupsd_printer_t
* /* O - Printer in list */
933 cupsdFindPrinter(const char *name
) /* I - Name of printer to find */
935 cupsd_printer_t
*p
; /* Printer in list */
938 if ((p
= cupsdFindDest(name
)) != NULL
&& (p
->type
& CUPS_PRINTER_CLASS
))
946 * 'cupsdFreePrinterUsers()' - Free allow/deny users.
950 cupsdFreePrinterUsers(
951 cupsd_printer_t
*p
) /* I - Printer */
953 int i
; /* Looping var */
956 if (!p
|| !p
->num_users
)
959 for (i
= 0; i
< p
->num_users
; i
++)
960 free((void *)p
->users
[i
]);
970 * 'cupsdLoadAllPrinters()' - Load printers from the printers.conf file.
974 cupsdLoadAllPrinters(void)
976 int i
; /* Looping var */
977 cups_file_t
*fp
; /* printers.conf file */
978 int linenum
; /* Current line number */
979 char line
[4096], /* Line from file */
980 *value
, /* Pointer to value */
981 *valueptr
; /* Pointer into value */
982 cupsd_printer_t
*p
; /* Current printer */
986 * Open the printers.conf file...
989 snprintf(line
, sizeof(line
), "%s/printers.conf", ServerRoot
);
990 if ((fp
= cupsFileOpen(line
, "r")) == NULL
)
993 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to open %s - %s", line
,
999 * Read printer configurations until we hit EOF...
1005 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
1008 * Decode the directive...
1011 if (!strcasecmp(line
, "<Printer") ||
1012 !strcasecmp(line
, "<DefaultPrinter"))
1015 * <Printer name> or <DefaultPrinter name>
1018 if (p
== NULL
&& value
)
1021 * Add the printer and a base file type...
1024 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Loading printer %s...", value
);
1026 p
= cupsdAddPrinter(value
);
1028 p
->state
= IPP_PRINTER_IDLE
;
1031 * Set the default printer as needed...
1034 if (!strcasecmp(line
, "<DefaultPrinter"))
1038 cupsdLogMessage(CUPSD_LOG_ERROR
,
1039 "Syntax error on line %d of printers.conf.", linenum
);
1041 else if (!strcasecmp(line
, "</Printer>"))
1046 * Close out the current printer...
1049 cupsdSetPrinterAttrs(p
);
1050 cupsdAddPrinterHistory(p
);
1052 if (strncmp(p
->device_uri
, "file:", 5) &&
1053 p
->state
!= IPP_PRINTER_STOPPED
)
1056 * See if the backend exists...
1059 snprintf(line
, sizeof(line
), "%s/backend/%s", ServerBin
,
1062 if ((valueptr
= strchr(line
+ strlen(ServerBin
), ':')) != NULL
)
1063 *valueptr
= '\0'; /* Chop everything but URI scheme */
1065 if (access(line
, 0))
1068 * Backend does not exist, stop printer...
1071 p
->state
= IPP_PRINTER_STOPPED
;
1072 snprintf(p
->state_message
, sizeof(p
->state_message
),
1073 "Backend %s does not exist!", line
);
1080 cupsdLogMessage(CUPSD_LOG_ERROR
,
1081 "Syntax error on line %d of printers.conf.", linenum
);
1085 cupsdLogMessage(CUPSD_LOG_ERROR
,
1086 "Syntax error on line %d of printers.conf.", linenum
);
1088 else if (!strcasecmp(line
, "AuthInfoRequired"))
1090 if (!cupsdSetAuthInfoRequired(p
, value
, NULL
))
1091 cupsdLogMessage(CUPSD_LOG_ERROR
,
1092 "Bad AuthInfoRequired on line %d of printers.conf.",
1095 else if (!strcasecmp(line
, "Info"))
1098 cupsdSetString(&p
->info
, value
);
1100 else if (!strcasecmp(line
, "MakeModel"))
1103 cupsdSetString(&p
->make_model
, value
);
1105 else if (!strcasecmp(line
, "Location"))
1108 cupsdSetString(&p
->location
, value
);
1110 else if (!strcasecmp(line
, "DeviceURI"))
1113 cupsdSetDeviceURI(p
, value
);
1115 cupsdLogMessage(CUPSD_LOG_ERROR
,
1116 "Syntax error on line %d of printers.conf.", linenum
);
1118 else if (!strcasecmp(line
, "Option") && value
)
1124 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1127 cupsdLogMessage(CUPSD_LOG_ERROR
,
1128 "Syntax error on line %d of printers.conf.", linenum
);
1131 for (; *valueptr
&& isspace(*valueptr
& 255); *valueptr
++ = '\0');
1133 p
->num_options
= cupsAddOption(value
, valueptr
, p
->num_options
,
1137 else if (!strcasecmp(line
, "PortMonitor"))
1139 if (value
&& strcmp(value
, "none"))
1140 cupsdSetString(&p
->port_monitor
, value
);
1142 cupsdClearString(&p
->port_monitor
);
1144 cupsdLogMessage(CUPSD_LOG_ERROR
,
1145 "Syntax error on line %d of printers.conf.", linenum
);
1147 else if (!strcasecmp(line
, "Reason"))
1150 strcmp(value
, "connecting-to-device") &&
1151 strcmp(value
, "cups-insecure-filter-warning") &&
1152 strcmp(value
, "cups-missing-filter-warning"))
1154 for (i
= 0 ; i
< p
->num_reasons
; i
++)
1155 if (!strcmp(value
, p
->reasons
[i
]))
1158 if (i
>= p
->num_reasons
&&
1159 p
->num_reasons
< (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
1161 p
->reasons
[p
->num_reasons
] = _cupsStrAlloc(value
);
1166 cupsdLogMessage(CUPSD_LOG_ERROR
,
1167 "Syntax error on line %d of printers.conf.", linenum
);
1169 else if (!strcasecmp(line
, "State"))
1172 * Set the initial queue state...
1175 if (value
&& !strcasecmp(value
, "idle"))
1176 p
->state
= IPP_PRINTER_IDLE
;
1177 else if (value
&& !strcasecmp(value
, "stopped"))
1179 p
->state
= IPP_PRINTER_STOPPED
;
1181 for (i
= 0 ; i
< p
->num_reasons
; i
++)
1182 if (!strcmp("paused", p
->reasons
[i
]))
1185 if (i
>= p
->num_reasons
&&
1186 p
->num_reasons
< (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
1188 p
->reasons
[p
->num_reasons
] = _cupsStrAlloc("paused");
1193 cupsdLogMessage(CUPSD_LOG_ERROR
,
1194 "Syntax error on line %d of printers.conf.", linenum
);
1196 else if (!strcasecmp(line
, "StateMessage"))
1199 * Set the initial queue state message...
1203 strlcpy(p
->state_message
, value
, sizeof(p
->state_message
));
1205 else if (!strcasecmp(line
, "StateTime"))
1208 * Set the state time...
1212 p
->state_time
= atoi(value
);
1214 else if (!strcasecmp(line
, "Accepting"))
1217 * Set the initial accepting state...
1221 (!strcasecmp(value
, "yes") ||
1222 !strcasecmp(value
, "on") ||
1223 !strcasecmp(value
, "true")))
1226 (!strcasecmp(value
, "no") ||
1227 !strcasecmp(value
, "off") ||
1228 !strcasecmp(value
, "false")))
1231 cupsdLogMessage(CUPSD_LOG_ERROR
,
1232 "Syntax error on line %d of printers.conf.", linenum
);
1234 else if (!strcasecmp(line
, "Type"))
1237 p
->type
= atoi(value
);
1239 cupsdLogMessage(CUPSD_LOG_ERROR
,
1240 "Syntax error on line %d of printers.conf.", linenum
);
1242 else if (!strcasecmp(line
, "Product"))
1247 p
->product
= _cupsStrAlloc(value
);
1248 #endif /* HAVE_DNSSD */
1251 cupsdLogMessage(CUPSD_LOG_ERROR
,
1252 "Syntax error on line %d of printers.conf.", linenum
);
1254 else if (!strcasecmp(line
, "Filter"))
1259 p
->filters
= cupsArrayNew(NULL
, NULL
);
1261 cupsArrayAdd(p
->filters
, _cupsStrAlloc(value
));
1264 cupsdLogMessage(CUPSD_LOG_ERROR
,
1265 "Syntax error on line %d of printers.conf.", linenum
);
1267 else if (!strcasecmp(line
, "PreFilter"))
1271 if (!p
->pre_filters
)
1272 p
->pre_filters
= cupsArrayNew(NULL
, NULL
);
1274 cupsArrayAdd(p
->pre_filters
, _cupsStrAlloc(value
));
1277 cupsdLogMessage(CUPSD_LOG_ERROR
,
1278 "Syntax error on line %d of printers.conf.", linenum
);
1280 else if (!strcasecmp(line
, "Shared"))
1283 * Set the initial shared state...
1287 (!strcasecmp(value
, "yes") ||
1288 !strcasecmp(value
, "on") ||
1289 !strcasecmp(value
, "true")))
1292 (!strcasecmp(value
, "no") ||
1293 !strcasecmp(value
, "off") ||
1294 !strcasecmp(value
, "false")))
1297 cupsdLogMessage(CUPSD_LOG_ERROR
,
1298 "Syntax error on line %d of printers.conf.", linenum
);
1300 else if (!strcasecmp(line
, "JobSheets"))
1303 * Set the initial job sheets...
1308 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1313 cupsdSetString(&p
->job_sheets
[0], value
);
1315 while (isspace(*valueptr
& 255))
1320 for (value
= valueptr
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1325 cupsdSetString(&p
->job_sheets
[1], value
);
1329 cupsdLogMessage(CUPSD_LOG_ERROR
,
1330 "Syntax error on line %d of printers.conf.", linenum
);
1332 else if (!strcasecmp(line
, "AllowUser"))
1337 cupsdAddPrinterUser(p
, value
);
1340 cupsdLogMessage(CUPSD_LOG_ERROR
,
1341 "Syntax error on line %d of printers.conf.", linenum
);
1343 else if (!strcasecmp(line
, "DenyUser"))
1348 cupsdAddPrinterUser(p
, value
);
1351 cupsdLogMessage(CUPSD_LOG_ERROR
,
1352 "Syntax error on line %d of printers.conf.", linenum
);
1354 else if (!strcasecmp(line
, "QuotaPeriod"))
1357 p
->quota_period
= atoi(value
);
1359 cupsdLogMessage(CUPSD_LOG_ERROR
,
1360 "Syntax error on line %d of printers.conf.", linenum
);
1362 else if (!strcasecmp(line
, "PageLimit"))
1365 p
->page_limit
= atoi(value
);
1367 cupsdLogMessage(CUPSD_LOG_ERROR
,
1368 "Syntax error on line %d of printers.conf.", linenum
);
1370 else if (!strcasecmp(line
, "KLimit"))
1373 p
->k_limit
= atoi(value
);
1375 cupsdLogMessage(CUPSD_LOG_ERROR
,
1376 "Syntax error on line %d of printers.conf.", linenum
);
1378 else if (!strcasecmp(line
, "OpPolicy"))
1382 cupsd_policy_t
*pol
; /* Policy */
1385 if ((pol
= cupsdFindPolicy(value
)) != NULL
)
1387 cupsdSetString(&p
->op_policy
, value
);
1388 p
->op_policy_ptr
= pol
;
1391 cupsdLogMessage(CUPSD_LOG_ERROR
,
1392 "Bad policy \"%s\" on line %d of printers.conf",
1396 cupsdLogMessage(CUPSD_LOG_ERROR
,
1397 "Syntax error on line %d of printers.conf.", linenum
);
1399 else if (!strcasecmp(line
, "ErrorPolicy"))
1402 cupsdSetString(&p
->error_policy
, value
);
1404 cupsdLogMessage(CUPSD_LOG_ERROR
,
1405 "Syntax error on line %d of printers.conf.", linenum
);
1407 else if (!strcasecmp(line
, "Attribute") && value
)
1409 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1412 cupsdLogMessage(CUPSD_LOG_ERROR
,
1413 "Syntax error on line %d of printers.conf.", linenum
);
1416 for (; *valueptr
&& isspace(*valueptr
& 255); *valueptr
++ = '\0');
1419 cupsdSetPrinterAttrs(p
);
1421 if (!strcmp(value
, "marker-change-time"))
1422 p
->marker_time
= atoi(valueptr
);
1424 cupsdSetPrinterAttr(p
, value
, valueptr
);
1430 * Something else we don't understand...
1433 cupsdLogMessage(CUPSD_LOG_ERROR
,
1434 "Unknown configuration directive %s on line %d of printers.conf.",
1444 * 'cupsdRenamePrinter()' - Rename a printer.
1449 cupsd_printer_t
*p
, /* I - Printer */
1450 const char *name
) /* I - New name */
1453 * Remove the printer from the array(s) first...
1456 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1457 "cupsdRenamePrinter: Removing %s from Printers", p
->name
);
1458 cupsArrayRemove(Printers
, p
);
1460 if (p
->type
& CUPS_PRINTER_IMPLICIT
)
1462 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1463 "cupsdRenamePrinter: Removing %s from ImplicitPrinters",
1465 cupsArrayRemove(ImplicitPrinters
, p
);
1469 * Rename the printer type...
1472 mimeDeleteType(MimeDatabase
, p
->filetype
);
1473 p
->filetype
= mimeAddType(MimeDatabase
, "printer", name
);
1475 mimeDeleteType(MimeDatabase
, p
->prefiltertype
);
1476 p
->prefiltertype
= mimeAddType(MimeDatabase
, "prefilter", name
);
1479 * Rename the printer...
1482 cupsdSetString(&p
->name
, name
);
1485 * Reset printer attributes...
1488 cupsdSetPrinterAttrs(p
);
1491 * Add the printer back to the printer array(s)...
1494 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1495 "cupsdRenamePrinter: Adding %s to Printers", p
->name
);
1496 cupsArrayAdd(Printers
, p
);
1498 if (p
->type
& CUPS_PRINTER_IMPLICIT
)
1500 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1501 "cupsdRenamePrinter: Adding %s to ImplicitPrinters",
1503 cupsArrayAdd(ImplicitPrinters
, p
);
1509 * 'cupsdSaveAllPrinters()' - Save all printer definitions to the printers.conf
1514 cupsdSaveAllPrinters(void)
1516 int i
; /* Looping var */
1517 cups_file_t
*fp
; /* printers.conf file */
1518 char temp
[1024], /* Temporary string */
1519 backup
[1024], /* printers.conf.O file */
1520 value
[2048], /* Value string */
1521 *ptr
; /* Pointer into value */
1522 cupsd_printer_t
*printer
; /* Current printer class */
1523 time_t curtime
; /* Current time */
1524 struct tm
*curdate
; /* Current date */
1525 cups_option_t
*option
; /* Current option */
1526 ipp_attribute_t
*marker
; /* Current marker attribute */
1530 * Create the printers.conf file...
1533 snprintf(temp
, sizeof(temp
), "%s/printers.conf", ServerRoot
);
1534 snprintf(backup
, sizeof(backup
), "%s/printers.conf.O", ServerRoot
);
1536 if (rename(temp
, backup
))
1538 if (errno
!= ENOENT
)
1539 cupsdLogMessage(CUPSD_LOG_ERROR
,
1540 "Unable to backup printers.conf - %s", strerror(errno
));
1543 if ((fp
= cupsFileOpen(temp
, "w")) == NULL
)
1545 cupsdLogMessage(CUPSD_LOG_ERROR
,
1546 "Unable to save printers.conf - %s", strerror(errno
));
1548 if (rename(backup
, temp
))
1549 cupsdLogMessage(CUPSD_LOG_ERROR
,
1550 "Unable to restore printers.conf - %s", strerror(errno
));
1554 cupsdLogMessage(CUPSD_LOG_INFO
, "Saving printers.conf...");
1557 * Restrict access to the file...
1560 fchown(cupsFileNumber(fp
), getuid(), Group
);
1561 fchmod(cupsFileNumber(fp
), 0600);
1564 * Write a small header to the file...
1567 curtime
= time(NULL
);
1568 curdate
= localtime(&curtime
);
1569 strftime(temp
, sizeof(temp
) - 1, "%Y-%m-%d %H:%M", curdate
);
1571 cupsFilePuts(fp
, "# Printer configuration file for " CUPS_SVERSION
"\n");
1572 cupsFilePrintf(fp
, "# Written by cupsd on %s\n", temp
);
1573 cupsFilePuts(fp
, "# DO NOT EDIT THIS FILE WHEN CUPSD IS RUNNING\n");
1576 * Write each local printer known to the system...
1579 for (printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
1581 printer
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
1584 * Skip remote destinations and printer classes...
1587 if ((printer
->type
& CUPS_PRINTER_DISCOVERED
) ||
1588 (printer
->type
& CUPS_PRINTER_CLASS
) ||
1589 (printer
->type
& CUPS_PRINTER_IMPLICIT
))
1593 * Write printers as needed...
1596 if (printer
== DefaultPrinter
)
1597 cupsFilePrintf(fp
, "<DefaultPrinter %s>\n", printer
->name
);
1599 cupsFilePrintf(fp
, "<Printer %s>\n", printer
->name
);
1601 if (printer
->num_auth_info_required
> 0)
1603 switch (printer
->num_auth_info_required
)
1606 strlcpy(value
, printer
->auth_info_required
[0], sizeof(value
));
1610 snprintf(value
, sizeof(value
), "%s,%s",
1611 printer
->auth_info_required
[0],
1612 printer
->auth_info_required
[1]);
1617 snprintf(value
, sizeof(value
), "%s,%s,%s",
1618 printer
->auth_info_required
[0],
1619 printer
->auth_info_required
[1],
1620 printer
->auth_info_required
[2]);
1624 cupsFilePutConf(fp
, "AuthInfoRequired", value
);
1628 cupsFilePutConf(fp
, "Info", printer
->info
);
1630 if (printer
->location
)
1631 cupsFilePutConf(fp
, "Location", printer
->location
);
1633 if (printer
->make_model
)
1634 cupsFilePutConf(fp
, "MakeModel", printer
->make_model
);
1636 cupsFilePutConf(fp
, "DeviceURI", printer
->device_uri
);
1638 if (printer
->port_monitor
)
1639 cupsFilePutConf(fp
, "PortMonitor", printer
->port_monitor
);
1641 if (printer
->state
== IPP_PRINTER_STOPPED
)
1643 cupsFilePuts(fp
, "State Stopped\n");
1645 if (printer
->state_message
)
1646 cupsFilePutConf(fp
, "StateMessage", printer
->state_message
);
1649 cupsFilePuts(fp
, "State Idle\n");
1651 cupsFilePrintf(fp
, "StateTime %d\n", (int)printer
->state_time
);
1653 for (i
= 0; i
< printer
->num_reasons
; i
++)
1654 if (strcmp(printer
->reasons
[i
], "connecting-to-device") &&
1655 strcmp(printer
->reasons
[i
], "cups-insecure-filter-warning") &&
1656 strcmp(printer
->reasons
[i
], "cups-missing-filter-warning"))
1657 cupsFilePutConf(fp
, "Reason", printer
->reasons
[i
]);
1659 cupsFilePrintf(fp
, "Type %d\n", printer
->type
);
1662 if (printer
->product
)
1663 cupsFilePutConf(fp
, "Product", printer
->product
);
1664 #endif /* HAVE_DNSSD */
1666 for (ptr
= (char *)cupsArrayFirst(printer
->filters
);
1668 ptr
= (char *)cupsArrayNext(printer
->filters
))
1669 cupsFilePutConf(fp
, "Filter", ptr
);
1671 for (ptr
= (char *)cupsArrayFirst(printer
->pre_filters
);
1673 ptr
= (char *)cupsArrayNext(printer
->pre_filters
))
1674 cupsFilePutConf(fp
, "PreFilter", ptr
);
1676 if (printer
->accepting
)
1677 cupsFilePuts(fp
, "Accepting Yes\n");
1679 cupsFilePuts(fp
, "Accepting No\n");
1681 if (printer
->shared
)
1682 cupsFilePuts(fp
, "Shared Yes\n");
1684 cupsFilePuts(fp
, "Shared No\n");
1686 snprintf(value
, sizeof(value
), "%s %s", printer
->job_sheets
[0],
1687 printer
->job_sheets
[1]);
1688 cupsFilePutConf(fp
, "JobSheets", value
);
1690 cupsFilePrintf(fp
, "QuotaPeriod %d\n", printer
->quota_period
);
1691 cupsFilePrintf(fp
, "PageLimit %d\n", printer
->page_limit
);
1692 cupsFilePrintf(fp
, "KLimit %d\n", printer
->k_limit
);
1694 for (i
= 0; i
< printer
->num_users
; i
++)
1695 cupsFilePutConf(fp
, printer
->deny_users
? "DenyUser" : "AllowUser",
1698 if (printer
->op_policy
)
1699 cupsFilePutConf(fp
, "OpPolicy", printer
->op_policy
);
1700 if (printer
->error_policy
)
1701 cupsFilePutConf(fp
, "ErrorPolicy", printer
->error_policy
);
1703 for (i
= printer
->num_options
, option
= printer
->options
;
1707 snprintf(value
, sizeof(value
), "%s %s", option
->name
, option
->value
);
1708 cupsFilePutConf(fp
, "Option", value
);
1711 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-colors",
1712 IPP_TAG_NAME
)) != NULL
)
1714 snprintf(value
, sizeof(value
), "%s ", marker
->name
);
1716 for (i
= 0, ptr
= value
+ strlen(value
);
1717 i
< marker
->num_values
&& ptr
< (value
+ sizeof(value
) - 1);
1723 strlcpy(ptr
, marker
->values
[i
].string
.text
,
1724 value
+ sizeof(value
) - ptr
);
1729 cupsFilePutConf(fp
, "Attribute", value
);
1732 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-levels",
1733 IPP_TAG_INTEGER
)) != NULL
)
1735 cupsFilePrintf(fp
, "Attribute %s %d", marker
->name
,
1736 marker
->values
[0].integer
);
1737 for (i
= 1; i
< marker
->num_values
; i
++)
1738 cupsFilePrintf(fp
, ",%d", marker
->values
[i
].integer
);
1739 cupsFilePuts(fp
, "\n");
1742 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-low-levels",
1743 IPP_TAG_INTEGER
)) != NULL
)
1745 cupsFilePrintf(fp
, "Attribute %s %d", marker
->name
,
1746 marker
->values
[0].integer
);
1747 for (i
= 1; i
< marker
->num_values
; i
++)
1748 cupsFilePrintf(fp
, ",%d", marker
->values
[i
].integer
);
1749 cupsFilePuts(fp
, "\n");
1752 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-high-levels",
1753 IPP_TAG_INTEGER
)) != NULL
)
1755 cupsFilePrintf(fp
, "Attribute %s %d", marker
->name
,
1756 marker
->values
[0].integer
);
1757 for (i
= 1; i
< marker
->num_values
; i
++)
1758 cupsFilePrintf(fp
, ",%d", marker
->values
[i
].integer
);
1759 cupsFilePuts(fp
, "\n");
1762 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-message",
1763 IPP_TAG_TEXT
)) != NULL
)
1765 snprintf(value
, sizeof(value
), "%s %s", marker
->name
,
1766 marker
->values
[0].string
.text
);
1768 cupsFilePutConf(fp
, "Attribute", value
);
1771 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-names",
1772 IPP_TAG_NAME
)) != NULL
)
1774 snprintf(value
, sizeof(value
), "%s ", marker
->name
);
1776 for (i
= 0, ptr
= value
+ strlen(value
);
1777 i
< marker
->num_values
&& ptr
< (value
+ sizeof(value
) - 1);
1783 strlcpy(ptr
, marker
->values
[i
].string
.text
,
1784 value
+ sizeof(value
) - ptr
);
1789 cupsFilePutConf(fp
, "Attribute", value
);
1792 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-types",
1793 IPP_TAG_KEYWORD
)) != NULL
)
1795 snprintf(value
, sizeof(value
), "%s ", marker
->name
);
1797 for (i
= 0, ptr
= value
+ strlen(value
);
1798 i
< marker
->num_values
&& ptr
< (value
+ sizeof(value
) - 1);
1804 strlcpy(ptr
, marker
->values
[i
].string
.text
,
1805 value
+ sizeof(value
) - ptr
);
1810 cupsFilePutConf(fp
, "Attribute", value
);
1813 if (printer
->marker_time
)
1814 cupsFilePrintf(fp
, "Attribute marker-change-time %ld\n",
1815 (long)printer
->marker_time
);
1817 cupsFilePuts(fp
, "</Printer>\n");
1821 * Make IRIX desktop & printer status happy
1824 write_irix_state(printer
);
1833 * 'cupsdSetAuthInfoRequired()' - Set the required authentication info.
1836 int /* O - 1 if value OK, 0 otherwise */
1837 cupsdSetAuthInfoRequired(
1838 cupsd_printer_t
*p
, /* I - Printer */
1839 const char *values
, /* I - Plain text value (or NULL) */
1840 ipp_attribute_t
*attr
) /* I - IPP attribute value (or NULL) */
1842 int i
; /* Looping var */
1845 p
->num_auth_info_required
= 0;
1848 * Do we have a plain text value?
1854 * Yes, grab the keywords...
1857 const char *end
; /* End of current value */
1860 while (*values
&& p
->num_auth_info_required
< 4)
1862 if ((end
= strchr(values
, ',')) == NULL
)
1863 end
= values
+ strlen(values
);
1865 if ((end
- values
) == 4 && !strncmp(values
, "none", 4))
1867 if (p
->num_auth_info_required
!= 0 || *end
)
1870 p
->auth_info_required
[p
->num_auth_info_required
] = "none";
1871 p
->num_auth_info_required
++;
1875 else if ((end
- values
) == 9 && !strncmp(values
, "negotiate", 9))
1877 if (p
->num_auth_info_required
!= 0 || *end
)
1880 p
->auth_info_required
[p
->num_auth_info_required
] = "negotiate";
1881 p
->num_auth_info_required
++;
1883 else if ((end
- values
) == 6 && !strncmp(values
, "domain", 6))
1885 p
->auth_info_required
[p
->num_auth_info_required
] = "domain";
1886 p
->num_auth_info_required
++;
1888 else if ((end
- values
) == 8 && !strncmp(values
, "password", 8))
1890 p
->auth_info_required
[p
->num_auth_info_required
] = "password";
1891 p
->num_auth_info_required
++;
1893 else if ((end
- values
) == 8 && !strncmp(values
, "username", 8))
1895 p
->auth_info_required
[p
->num_auth_info_required
] = "username";
1896 p
->num_auth_info_required
++;
1901 values
= (*end
) ? end
+ 1 : end
;
1904 if (p
->num_auth_info_required
== 0)
1906 p
->auth_info_required
[0] = "none";
1907 p
->num_auth_info_required
= 1;
1911 * Update the printer-type value as needed...
1914 if (p
->num_auth_info_required
> 1 ||
1915 strcmp(p
->auth_info_required
[0], "none"))
1916 p
->type
|= CUPS_PRINTER_AUTHENTICATED
;
1918 p
->type
&= ~CUPS_PRINTER_AUTHENTICATED
;
1924 * Grab values from an attribute instead...
1927 if (!attr
|| attr
->num_values
> 4)
1931 * Update the printer-type value as needed...
1934 if (attr
->num_values
> 1 ||
1935 strcmp(attr
->values
[0].string
.text
, "none"))
1936 p
->type
|= CUPS_PRINTER_AUTHENTICATED
;
1938 p
->type
&= ~CUPS_PRINTER_AUTHENTICATED
;
1940 for (i
= 0; i
< attr
->num_values
; i
++)
1942 if (!strcmp(attr
->values
[i
].string
.text
, "none"))
1944 if (p
->num_auth_info_required
!= 0 || attr
->num_values
!= 1)
1947 p
->auth_info_required
[p
->num_auth_info_required
] = "none";
1948 p
->num_auth_info_required
++;
1952 else if (!strcmp(attr
->values
[i
].string
.text
, "negotiate"))
1954 if (p
->num_auth_info_required
!= 0 || attr
->num_values
!= 1)
1957 p
->auth_info_required
[p
->num_auth_info_required
] = "negotiate";
1958 p
->num_auth_info_required
++;
1962 else if (!strcmp(attr
->values
[i
].string
.text
, "domain"))
1964 p
->auth_info_required
[p
->num_auth_info_required
] = "domain";
1965 p
->num_auth_info_required
++;
1967 else if (!strcmp(attr
->values
[i
].string
.text
, "password"))
1969 p
->auth_info_required
[p
->num_auth_info_required
] = "password";
1970 p
->num_auth_info_required
++;
1972 else if (!strcmp(attr
->values
[i
].string
.text
, "username"))
1974 p
->auth_info_required
[p
->num_auth_info_required
] = "username";
1975 p
->num_auth_info_required
++;
1986 * 'cupsdSetDeviceURI()' - Set the device URI for a printer.
1990 cupsdSetDeviceURI(cupsd_printer_t
*p
, /* I - Printer */
1991 const char *uri
) /* I - Device URI */
1993 char buffer
[1024], /* URI buffer */
1994 *start
, /* Start of data after scheme */
1995 *slash
, /* First slash after scheme:// */
1996 *ptr
; /* Pointer into user@host:port part */
2000 * Set the full device URI..
2003 cupsdSetString(&(p
->device_uri
), uri
);
2006 * Copy the device URI to a temporary buffer so we can sanitize any auth
2010 strlcpy(buffer
, uri
, sizeof(buffer
));
2013 * Find the end of the scheme:// part...
2016 if ((ptr
= strchr(buffer
, ':')) != NULL
)
2018 for (start
= ptr
+ 1; *start
; start
++)
2023 * Find the next slash (/) in the URI...
2026 if ((slash
= strchr(start
, '/')) == NULL
)
2027 slash
= start
+ strlen(start
); /* No slash, point to the end */
2030 * Check for an @ sign before the slash...
2033 if ((ptr
= strchr(start
, '@')) != NULL
&& ptr
< slash
)
2036 * Found an @ sign and it is before the resource part, so we have
2037 * an authentication string. Copy the remaining URI over the
2038 * authentication string...
2041 _cups_strcpy(start
, ptr
+ 1);
2046 * Save the sanitized URI...
2049 cupsdSetString(&(p
->sanitized_device_uri
), buffer
);
2054 * 'cupsdSetPrinterAttr()' - Set a printer attribute.
2058 cupsdSetPrinterAttr(
2059 cupsd_printer_t
*p
, /* I - Printer */
2060 const char *name
, /* I - Attribute name */
2061 char *value
) /* I - Attribute value string */
2063 ipp_attribute_t
*attr
; /* Attribute */
2064 int i
, /* Looping var */
2065 count
; /* Number of values */
2066 char *ptr
; /* Pointer into value */
2067 ipp_tag_t value_tag
; /* Value tag for this attribute */
2071 * Don't allow empty values...
2074 if (!*value
&& strcmp(name
, "marker-message"))
2076 cupsdLogMessage(CUPSD_LOG_ERROR
, "Ignoring empty \"%s\" attribute", name
);
2081 * Count the number of values...
2084 for (count
= 1, ptr
= value
;
2085 (ptr
= strchr(ptr
, ',')) != NULL
;
2089 * Then add or update the attribute as needed...
2092 if (!strcmp(name
, "marker-levels") || !strcmp(name
, "marker-low-levels") ||
2093 !strcmp(name
, "marker-high-levels"))
2099 if ((attr
= ippFindAttribute(p
->attrs
, name
, IPP_TAG_INTEGER
)) != NULL
&&
2100 attr
->num_values
< count
)
2102 ippDeleteAttribute(p
->attrs
, attr
);
2107 attr
->num_values
= count
;
2109 attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
, name
,
2114 cupsdLogMessage(CUPSD_LOG_ERROR
,
2115 "Unable to allocate memory for printer attribute "
2116 "(%d values)", count
);
2120 for (i
= 0; i
< count
; i
++)
2122 if ((ptr
= strchr(value
, ',')) != NULL
)
2125 attr
->values
[i
].integer
= strtol(value
, NULL
, 10);
2134 * Name or keyword values...
2137 if (!strcmp(name
, "marker-types"))
2138 value_tag
= IPP_TAG_KEYWORD
;
2139 else if (!strcmp(name
, "marker-message"))
2140 value_tag
= IPP_TAG_TEXT
;
2142 value_tag
= IPP_TAG_NAME
;
2144 if ((attr
= ippFindAttribute(p
->attrs
, name
, value_tag
)) != NULL
&&
2145 attr
->num_values
< count
)
2147 ippDeleteAttribute(p
->attrs
, attr
);
2153 for (i
= 0; i
< attr
->num_values
; i
++)
2154 _cupsStrFree(attr
->values
[i
].string
.text
);
2156 attr
->num_values
= count
;
2159 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, value_tag
, name
,
2164 cupsdLogMessage(CUPSD_LOG_ERROR
,
2165 "Unable to allocate memory for printer attribute "
2166 "(%d values)", count
);
2170 for (i
= 0; i
< count
; i
++)
2172 if ((ptr
= strchr(value
, ',')) != NULL
)
2175 attr
->values
[i
].string
.text
= _cupsStrAlloc(value
);
2185 * 'cupsdSetPrinterAttrs()' - Set printer attributes based upon the PPD file.
2189 cupsdSetPrinterAttrs(cupsd_printer_t
*p
)/* I - Printer to setup */
2191 int i
, /* Looping var */
2192 length
; /* Length of browse attributes */
2193 char resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
2194 int num_air
; /* Number of auth-info-required values */
2195 const char * const *air
; /* auth-info-required values */
2196 cupsd_location_t
*auth
; /* Pointer to authentication element */
2197 const char *auth_supported
; /* Authentication supported */
2198 ipp_t
*oldattrs
; /* Old printer attributes */
2199 ipp_attribute_t
*attr
; /* Attribute data */
2200 cups_option_t
*option
; /* Current printer option */
2201 char *filter
; /* Current filter */
2202 static const char * const air_none
[] =
2203 { /* No authentication */
2206 static const char * const air_userpass
[] =
2207 { /* Basic/Digest authentication */
2213 DEBUG_printf(("cupsdSetPrinterAttrs: entering name = %s, type = %x\n", p
->name
,
2217 * Make sure that we have the common attributes defined...
2221 cupsdCreateCommonData();
2224 * Clear out old filters, if any...
2227 delete_printer_filters(p
);
2230 * Figure out the authentication that is required for the printer.
2233 auth_supported
= "requesting-user-name";
2237 if (p
->num_auth_info_required
> 0 && strcmp(p
->auth_info_required
[0], "none"))
2239 num_air
= p
->num_auth_info_required
;
2240 air
= p
->auth_info_required
;
2242 else if ((p
->type
& CUPS_PRINTER_AUTHENTICATED
) &&
2243 (p
->type
& CUPS_PRINTER_DISCOVERED
))
2249 if (p
->type
& CUPS_PRINTER_CLASS
)
2250 snprintf(resource
, sizeof(resource
), "/classes/%s", p
->name
);
2252 snprintf(resource
, sizeof(resource
), "/printers/%s", p
->name
);
2254 if ((auth
= cupsdFindBest(resource
, HTTP_POST
)) == NULL
||
2255 auth
->type
== CUPSD_AUTH_NONE
)
2256 auth
= cupsdFindPolicyOp(p
->op_policy_ptr
, IPP_PRINT_JOB
);
2260 int auth_type
; /* Authentication type */
2263 if ((auth_type
= auth
->type
) == CUPSD_AUTH_DEFAULT
)
2264 auth_type
= DefaultAuthType
;
2266 if (auth_type
== CUPSD_AUTH_BASIC
|| auth_type
== CUPSD_AUTH_BASICDIGEST
)
2267 auth_supported
= "basic";
2268 else if (auth_type
== CUPSD_AUTH_DIGEST
)
2269 auth_supported
= "digest";
2271 else if (auth_type
== CUPSD_AUTH_NEGOTIATE
)
2272 auth_supported
= "negotiate";
2273 #endif /* HAVE_GSSAPI */
2275 if (!(p
->type
& CUPS_PRINTER_DISCOVERED
))
2277 if (auth_type
!= CUPSD_AUTH_NONE
)
2278 p
->type
|= CUPS_PRINTER_AUTHENTICATED
;
2280 p
->type
&= ~CUPS_PRINTER_AUTHENTICATED
;
2283 else if (!(p
->type
& CUPS_PRINTER_DISCOVERED
))
2284 p
->type
&= ~CUPS_PRINTER_AUTHENTICATED
;
2287 * Create the required IPP attributes for a printer...
2290 oldattrs
= p
->attrs
;
2291 p
->attrs
= ippNew();
2293 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2294 "uri-authentication-supported", NULL
, auth_supported
);
2295 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2296 "uri-security-supported", NULL
, "none");
2297 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
, "printer-name", NULL
,
2299 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-location",
2300 NULL
, p
->location
? p
->location
: "");
2301 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-info",
2302 NULL
, p
->info
? p
->info
: "");
2307 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2308 "requesting-user-name-denied", p
->num_users
, NULL
,
2311 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2312 "requesting-user-name-allowed", p
->num_users
, NULL
,
2316 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2317 "job-quota-period", p
->quota_period
);
2318 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2319 "job-k-limit", p
->k_limit
);
2320 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2321 "job-page-limit", p
->page_limit
);
2322 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2323 "auth-info-required", num_air
, NULL
, air
);
2325 if (cupsArrayCount(Banners
) > 0 && !(p
->type
& CUPS_PRINTER_DISCOVERED
))
2328 * Setup the job-sheets-default attribute...
2331 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2332 "job-sheets-default", 2, NULL
, NULL
);
2336 attr
->values
[0].string
.text
= _cupsStrAlloc(Classification
?
2337 Classification
: p
->job_sheets
[0]);
2338 attr
->values
[1].string
.text
= _cupsStrAlloc(Classification
?
2339 Classification
: p
->job_sheets
[1]);
2346 if (p
->type
& CUPS_PRINTER_DISCOVERED
)
2349 * Tell the client this is a remote printer of some type...
2352 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
2353 "printer-uri-supported", NULL
, p
->uri
);
2355 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "printer-more-info",
2359 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
2360 "printer-make-and-model", NULL
, p
->make_model
);
2362 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "device-uri", NULL
,
2371 * Assign additional attributes depending on whether this is a printer
2375 if (p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
))
2378 p
->type
&= ~CUPS_PRINTER_OPTIONS
;
2381 * Add class-specific attributes...
2384 if ((p
->type
& CUPS_PRINTER_IMPLICIT
) && p
->num_printers
> 0 &&
2385 p
->printers
[0]->make_model
)
2386 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
2387 "printer-make-and-model", NULL
, p
->printers
[0]->make_model
);
2389 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
2390 "printer-make-and-model", NULL
, "Local Printer Class");
2392 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "device-uri", NULL
,
2393 "file:///dev/null");
2395 if (p
->num_printers
> 0)
2398 * Add a list of member names; URIs are added in copy_printer_attrs...
2401 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2402 "member-names", p
->num_printers
, NULL
, NULL
);
2403 p
->type
|= CUPS_PRINTER_OPTIONS
;
2405 for (i
= 0; i
< p
->num_printers
; i
++)
2408 attr
->values
[i
].string
.text
= _cupsStrRetain(p
->printers
[i
]->name
);
2410 p
->type
&= ~CUPS_PRINTER_OPTIONS
| p
->printers
[i
]->type
;
2417 * Add printer-specific attributes...
2420 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "device-uri", NULL
,
2421 p
->sanitized_device_uri
);
2424 * Assign additional attributes from the PPD file (if any)...
2430 * Add filters for printer...
2433 cupsdSetPrinterReasons(p
, "-cups-missing-filter-warning,"
2434 "cups-insecure-filter-warning");
2436 for (filter
= (char *)cupsArrayFirst(p
->filters
);
2438 filter
= (char *)cupsArrayNext(p
->filters
))
2439 add_printer_filter(p
, p
->filetype
, filter
);
2443 p
->prefiltertype
= mimeAddType(MimeDatabase
, "prefilter", p
->name
);
2445 for (filter
= (char *)cupsArrayFirst(p
->pre_filters
);
2447 filter
= (char *)cupsArrayNext(p
->pre_filters
))
2448 add_printer_filter(p
, p
->prefiltertype
, filter
);
2454 * Copy marker attributes as needed...
2459 ipp_attribute_t
*oldattr
; /* Old attribute */
2462 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-colors",
2463 IPP_TAG_NAME
)) != NULL
)
2465 if ((attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2466 "marker-colors", oldattr
->num_values
, NULL
,
2469 for (i
= 0; i
< oldattr
->num_values
; i
++)
2470 attr
->values
[i
].string
.text
=
2471 _cupsStrRetain(oldattr
->values
[i
].string
.text
);
2475 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-levels",
2476 IPP_TAG_INTEGER
)) != NULL
)
2478 if ((attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2479 "marker-levels", oldattr
->num_values
,
2482 for (i
= 0; i
< oldattr
->num_values
; i
++)
2483 attr
->values
[i
].integer
= oldattr
->values
[i
].integer
;
2487 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-message",
2488 IPP_TAG_TEXT
)) != NULL
)
2489 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "marker-message",
2490 NULL
, oldattr
->values
[0].string
.text
);
2492 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-low-levels",
2493 IPP_TAG_INTEGER
)) != NULL
)
2495 if ((attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2496 "marker-low-levels", oldattr
->num_values
,
2499 for (i
= 0; i
< oldattr
->num_values
; i
++)
2500 attr
->values
[i
].integer
= oldattr
->values
[i
].integer
;
2504 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-high-levels",
2505 IPP_TAG_INTEGER
)) != NULL
)
2507 if ((attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2508 "marker-high-levels", oldattr
->num_values
,
2511 for (i
= 0; i
< oldattr
->num_values
; i
++)
2512 attr
->values
[i
].integer
= oldattr
->values
[i
].integer
;
2516 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-names",
2517 IPP_TAG_NAME
)) != NULL
)
2519 if ((attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2520 "marker-names", oldattr
->num_values
, NULL
,
2523 for (i
= 0; i
< oldattr
->num_values
; i
++)
2524 attr
->values
[i
].string
.text
=
2525 _cupsStrRetain(oldattr
->values
[i
].string
.text
);
2529 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-types",
2530 IPP_TAG_KEYWORD
)) != NULL
)
2532 if ((attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2533 "marker-types", oldattr
->num_values
, NULL
,
2536 for (i
= 0; i
< oldattr
->num_values
; i
++)
2537 attr
->values
[i
].string
.text
=
2538 _cupsStrRetain(oldattr
->values
[i
].string
.text
);
2542 ippDelete(oldattrs
);
2546 * Force sharing off for remote queues...
2549 if (p
->type
& (CUPS_PRINTER_REMOTE
| CUPS_PRINTER_IMPLICIT
))
2554 * Copy the printer options into a browse attributes string we can re-use.
2557 const char *valptr
; /* Pointer into value */
2558 char *attrptr
; /* Pointer into attribute string */
2562 * Free the old browse attributes as needed...
2565 if (p
->browse_attrs
)
2566 free(p
->browse_attrs
);
2569 * Compute the length of all attributes + job-sheets, lease-duration,
2570 * and BrowseLocalOptions.
2573 for (length
= 1, i
= p
->num_options
, option
= p
->options
;
2577 length
+= strlen(option
->name
) + 2;
2581 for (valptr
= option
->value
; *valptr
; valptr
++)
2582 if (strchr(" \"\'\\", *valptr
))
2589 length
+= 13 + strlen(p
->job_sheets
[0]) + strlen(p
->job_sheets
[1]);
2591 if (BrowseLocalOptions
)
2592 length
+= 12 + strlen(BrowseLocalOptions
);
2595 * Allocate the new string...
2598 if ((p
->browse_attrs
= calloc(1, length
)) == NULL
)
2599 cupsdLogMessage(CUPSD_LOG_ERROR
,
2600 "Unable to allocate %d bytes for browse data!",
2605 * Got the allocated string, now copy the options and attributes over...
2608 sprintf(p
->browse_attrs
, "job-sheets=%s,%s lease-duration=%d",
2609 p
->job_sheets
[0], p
->job_sheets
[1], BrowseTimeout
);
2610 attrptr
= p
->browse_attrs
+ strlen(p
->browse_attrs
);
2612 if (BrowseLocalOptions
)
2614 sprintf(attrptr
, " ipp-options=%s", BrowseLocalOptions
);
2615 attrptr
+= strlen(attrptr
);
2618 for (i
= p
->num_options
, option
= p
->options
;
2623 strcpy(attrptr
, option
->name
);
2624 attrptr
+= strlen(attrptr
);
2630 for (valptr
= option
->value
; *valptr
; valptr
++)
2632 if (strchr(" \"\'\\", *valptr
))
2635 *attrptr
++ = *valptr
;
2643 * Populate the document-format-supported attribute...
2646 add_printer_formats(p
);
2648 DEBUG_printf(("cupsdSetPrinterAttrs: leaving name = %s, type = %x\n", p
->name
,
2652 * Add name-default attributes...
2655 add_printer_defaults(p
);
2659 * Write the IRIX printer config and status files...
2662 write_irix_config(p
);
2663 write_irix_state(p
);
2667 * Let the browse protocols reflect the change
2670 cupsdRegisterPrinter(p
);
2675 * 'cupsdSetPrinterReasons()' - Set/update the reasons strings.
2678 int /* O - 1 if something changed, 0 otherwise */
2679 cupsdSetPrinterReasons(
2680 cupsd_printer_t
*p
, /* I - Printer */
2681 const char *s
) /* I - Reasons strings */
2683 int i
, /* Looping var */
2684 changed
= 0; /* Did something change? */
2685 const char *sptr
; /* Pointer into reasons */
2686 char reason
[255], /* Reason string */
2687 *rptr
; /* Pointer into reason */
2690 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
2691 "cupsdSetPrinterReasons(p=%p(%s),s=\"%s\"", p
, p
->name
, s
);
2693 if (s
[0] == '-' || s
[0] == '+')
2696 * Add/remove reasons...
2704 * Replace reasons...
2709 for (i
= 0; i
< p
->num_reasons
; i
++)
2710 _cupsStrFree(p
->reasons
[i
]);
2715 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
2717 if (PrintcapFormat
== PRINTCAP_PLIST
)
2718 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
2721 if (!strcmp(s
, "none"))
2725 * Loop through all of the reasons...
2731 * Skip leading whitespace and commas...
2734 while (isspace(*sptr
& 255) || *sptr
== ',')
2737 for (rptr
= reason
; *sptr
&& !isspace(*sptr
& 255) && *sptr
!= ','; sptr
++)
2738 if (rptr
< (reason
+ sizeof(reason
) - 1))
2752 for (i
= 0; i
< p
->num_reasons
; i
++)
2753 if (!strcmp(reason
, p
->reasons
[i
]))
2756 * Found a match, so remove it...
2761 _cupsStrFree(p
->reasons
[i
]);
2763 if (i
< p
->num_reasons
)
2764 memmove(p
->reasons
+ i
, p
->reasons
+ i
+ 1,
2765 (p
->num_reasons
- i
) * sizeof(char *));
2767 if (!strcmp(reason
, "paused") && p
->state
== IPP_PRINTER_STOPPED
)
2768 cupsdSetPrinterState(p
, IPP_PRINTER_IDLE
, 1);
2770 if (strcmp(reason
, "connecting-to-device"))
2772 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
2774 if (PrintcapFormat
== PRINTCAP_PLIST
)
2775 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
2780 else if (p
->num_reasons
< (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
2786 for (i
= 0; i
< p
->num_reasons
; i
++)
2787 if (!strcmp(reason
, p
->reasons
[i
]))
2790 if (i
>= p
->num_reasons
)
2792 if (i
>= (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
2794 cupsdLogMessage(CUPSD_LOG_ALERT
,
2795 "Too many printer-state-reasons values for %s (%d)",
2800 p
->reasons
[i
] = _cupsStrAlloc(reason
);
2804 if (!strcmp(reason
, "paused") && p
->state
!= IPP_PRINTER_STOPPED
)
2805 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, 1);
2807 if (strcmp(reason
, "connecting-to-device"))
2809 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
2811 if (PrintcapFormat
== PRINTCAP_PLIST
)
2812 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
2823 * 'cupsdSetPrinterState()' - Update the current state of a printer.
2827 cupsdSetPrinterState(
2828 cupsd_printer_t
*p
, /* I - Printer to change */
2829 ipp_pstate_t s
, /* I - New state */
2830 int update
) /* I - Update printers.conf? */
2832 ipp_pstate_t old_state
; /* Old printer state */
2833 static const char * const printer_states
[] =
2834 { /* State strings */
2842 * Can't set status of remote printers...
2845 if (p
->type
& CUPS_PRINTER_DISCOVERED
)
2849 * Set the new state...
2852 if (PrintcapFormat
== PRINTCAP_PLIST
)
2853 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
2855 old_state
= p
->state
;
2860 cupsdAddEvent(s
== IPP_PRINTER_STOPPED
? CUPSD_EVENT_PRINTER_STOPPED
:
2861 CUPSD_EVENT_PRINTER_STATE
, p
, NULL
,
2862 "%s \"%s\" state changed to %s.",
2863 (p
->type
& CUPS_PRINTER_CLASS
) ? "Class" : "Printer",
2864 p
->name
, printer_states
[p
->state
]);
2867 * Let the browse code know this needs to be updated...
2871 p
->state_time
= time(NULL
);
2875 write_irix_state(p
);
2880 * Set/clear the paused reason as needed...
2883 if (s
== IPP_PRINTER_STOPPED
)
2884 cupsdSetPrinterReasons(p
, "+paused");
2886 cupsdSetPrinterReasons(p
, "-paused");
2889 * Clear the message for the queue when going to processing...
2892 if (s
== IPP_PRINTER_PROCESSING
)
2893 p
->state_message
[0] = '\0';
2896 * Update the printer history...
2899 cupsdAddPrinterHistory(p
);
2902 * Let the browse protocols reflect the change...
2906 cupsdRegisterPrinter(p
);
2909 * Save the printer configuration if a printer goes from idle or processing
2910 * to stopped (or visa-versa)...
2914 (old_state
== IPP_PRINTER_STOPPED
) != (s
== IPP_PRINTER_STOPPED
))
2916 if (p
->type
& CUPS_PRINTER_CLASS
)
2917 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
2919 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
2925 * 'cupsdStopPrinter()' - Stop a printer from printing any jobs...
2929 cupsdStopPrinter(cupsd_printer_t
*p
, /* I - Printer to stop */
2930 int update
)/* I - Update printers.conf? */
2933 * Set the printer state...
2936 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, update
);
2939 * See if we have a job printing on this printer...
2942 if (p
->job
&& p
->job
->state_value
== IPP_JOB_PROCESSING
)
2943 cupsdSetJobState(p
->job
, IPP_JOB_PENDING
, CUPSD_JOB_DEFAULT
,
2944 "Job stopped due to printer being paused.");
2949 * 'cupsdUpdatePrinterPPD()' - Update keywords in a printer's PPD file.
2952 int /* O - 1 if successful, 0 otherwise */
2953 cupsdUpdatePrinterPPD(
2954 cupsd_printer_t
*p
, /* I - Printer */
2955 int num_keywords
, /* I - Number of keywords */
2956 cups_option_t
*keywords
) /* I - Keywords */
2958 int i
; /* Looping var */
2959 cups_file_t
*src
, /* Original file */
2960 *dst
; /* New file */
2961 char srcfile
[1024], /* Original filename */
2962 dstfile
[1024], /* New filename */
2963 line
[1024], /* Line from file */
2964 keystring
[41]; /* Keyword from line */
2965 cups_option_t
*keyword
; /* Current keyword */
2968 cupsdLogMessage(CUPSD_LOG_INFO
, "Updating keywords in PPD file for %s...",
2972 * Get the old and new PPD filenames...
2975 snprintf(srcfile
, sizeof(srcfile
), "%s/ppd/%s.ppd.O", ServerRoot
, p
->name
);
2976 snprintf(dstfile
, sizeof(srcfile
), "%s/ppd/%s.ppd", ServerRoot
, p
->name
);
2979 * Rename the old file and open the old and new...
2982 if (rename(dstfile
, srcfile
))
2984 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to backup PPD file for %s: %s",
2985 p
->name
, strerror(errno
));
2989 if ((src
= cupsFileOpen(srcfile
, "r")) == NULL
)
2991 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to open PPD file \"%s\": %s",
2992 srcfile
, strerror(errno
));
2993 rename(srcfile
, dstfile
);
2997 if ((dst
= cupsFileOpen(dstfile
, "w")) == NULL
)
2999 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to create PPD file \"%s\": %s",
3000 dstfile
, strerror(errno
));
3002 rename(srcfile
, dstfile
);
3007 * Copy the first line and then write out all of the keywords...
3010 if (!cupsFileGets(src
, line
, sizeof(line
)))
3012 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to read PPD file \"%s\": %s",
3013 srcfile
, strerror(errno
));
3016 rename(srcfile
, dstfile
);
3020 cupsFilePrintf(dst
, "%s\n", line
);
3022 for (i
= num_keywords
, keyword
= keywords
; i
> 0; i
--, keyword
++)
3024 cupsdLogMessage(CUPSD_LOG_DEBUG
, "*%s: %s", keyword
->name
, keyword
->value
);
3025 cupsFilePrintf(dst
, "*%s: %s\n", keyword
->name
, keyword
->value
);
3029 * Then copy the rest of the PPD file, dropping any keywords we changed.
3032 while (cupsFileGets(src
, line
, sizeof(line
)))
3035 * Skip keywords we've already set...
3038 if (sscanf(line
, "*%40[^:]:", keystring
) == 1 &&
3039 cupsGetOption(keystring
, num_keywords
, keywords
))
3043 * Otherwise write the line...
3046 cupsFilePrintf(dst
, "%s\n", line
);
3050 * Close files and return...
3061 * 'cupsdUpdatePrinters()' - Update printers after a partial reload.
3065 cupsdUpdatePrinters(void)
3067 cupsd_printer_t
*p
; /* Current printer */
3071 * Loop through the printers and recreate the printer attributes
3072 * for any local printers since the policy and/or access control
3073 * stuff may have changed. Also, if browsing is disabled, remove
3074 * any remote printers...
3077 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3079 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3082 * Remove remote printers if we are no longer browsing...
3086 (p
->type
& (CUPS_PRINTER_IMPLICIT
| CUPS_PRINTER_DISCOVERED
)))
3088 if (p
->type
& CUPS_PRINTER_IMPLICIT
)
3089 cupsArrayRemove(ImplicitPrinters
, p
);
3091 cupsArraySave(Printers
);
3092 cupsdDeletePrinter(p
, 0);
3093 cupsArrayRestore(Printers
);
3098 * Update the operation policy pointer...
3101 if ((p
->op_policy_ptr
= cupsdFindPolicy(p
->op_policy
)) == NULL
)
3102 p
->op_policy_ptr
= DefaultPolicyPtr
;
3105 * Update printer attributes as needed...
3108 if (!(p
->type
& CUPS_PRINTER_DISCOVERED
))
3109 cupsdSetPrinterAttrs(p
);
3115 * 'cupsdValidateDest()' - Validate a printer/class destination.
3118 const char * /* O - Printer or class name */
3120 const char *uri
, /* I - Printer URI */
3121 cups_ptype_t
*dtype
, /* O - Type (printer or class) */
3122 cupsd_printer_t
**printer
) /* O - Printer pointer */
3124 cupsd_printer_t
*p
; /* Current printer */
3125 char localname
[1024],/* Localized hostname */
3126 *lptr
, /* Pointer into localized hostname */
3127 *sptr
, /* Pointer into server name */
3128 *rptr
, /* Pointer into resource */
3129 scheme
[32], /* Scheme portion of URI */
3130 username
[64], /* Username portion of URI */
3131 hostname
[HTTP_MAX_HOST
],
3132 /* Host portion of URI */
3133 resource
[HTTP_MAX_URI
];
3134 /* Resource portion of URI */
3135 int port
; /* Port portion of URI */
3138 DEBUG_printf(("cupsdValidateDest(uri=\"%s\", dtype=%p, printer=%p)\n", uri
,
3142 * Initialize return values...
3149 *dtype
= (cups_ptype_t
)0;
3152 * Pull the hostname and resource from the URI...
3155 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
, scheme
, sizeof(scheme
),
3156 username
, sizeof(username
), hostname
, sizeof(hostname
),
3157 &port
, resource
, sizeof(resource
));
3160 * See if the resource is a class or printer...
3163 if (!strncmp(resource
, "/classes/", 9))
3169 rptr
= resource
+ 9;
3171 else if (!strncmp(resource
, "/printers/", 10))
3177 rptr
= resource
+ 10;
3182 * Bad resource name...
3189 * See if the printer or class name exists...
3192 p
= cupsdFindDest(rptr
);
3194 if (p
== NULL
&& strchr(rptr
, '@') == NULL
)
3202 *dtype
= p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
|
3203 CUPS_PRINTER_REMOTE
| CUPS_PRINTER_DISCOVERED
);
3209 * Change localhost to the server name...
3212 if (!strcasecmp(hostname
, "localhost"))
3213 strlcpy(hostname
, ServerName
, sizeof(hostname
));
3215 strlcpy(localname
, hostname
, sizeof(localname
));
3217 if (!strcasecmp(hostname
, ServerName
))
3220 * Localize the hostname...
3223 lptr
= strchr(localname
, '.');
3224 sptr
= strchr(ServerName
, '.');
3226 if (sptr
!= NULL
&& lptr
!= NULL
)
3229 * Strip the common domain name components...
3232 while (lptr
!= NULL
)
3234 if (!strcasecmp(lptr
, sptr
))
3240 lptr
= strchr(lptr
+ 1, '.');
3245 DEBUG_printf(("localized hostname is \"%s\"...\n", localname
));
3248 * Find a matching printer or class...
3251 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3253 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3254 if (!strcasecmp(p
->hostname
, localname
) &&
3255 !strcasecmp(p
->name
, rptr
))
3261 *dtype
= p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
|
3262 CUPS_PRINTER_REMOTE
| CUPS_PRINTER_DISCOVERED
);
3272 * 'cupsdWritePrintcap()' - Write a pseudo-printcap file for older applications
3277 cupsdWritePrintcap(void)
3279 int i
; /* Looping var */
3280 cups_file_t
*fp
; /* Printcap file */
3281 cupsd_printer_t
*p
; /* Current printer */
3286 * Update the IRIX printer state for the default printer; if
3287 * no printers remain, then the default printer file will be
3291 write_irix_state(DefaultPrinter
);
3295 * See if we have a printcap file; if not, don't bother writing it.
3298 if (!Printcap
|| !*Printcap
)
3301 cupsdLogMessage(CUPSD_LOG_INFO
, "Generating printcap %s...", Printcap
);
3304 * Open the printcap file...
3307 if ((fp
= cupsFileOpen(Printcap
, "w")) == NULL
)
3311 * Put a comment header at the top so that users will know where the
3312 * data has come from...
3315 if (PrintcapFormat
!= PRINTCAP_PLIST
)
3316 cupsFilePrintf(fp
, "# This file was automatically generated by cupsd(8) "
3318 "# %s/printers.conf file. All changes to this file\n"
3319 "# will be lost.\n", ServerRoot
);
3322 * Write a new printcap with the current list of printers.
3325 switch (PrintcapFormat
)
3329 * Each printer is put in the file as:
3339 cupsFilePrintf(fp
, "%s|%s:rm=%s:rp=%s:\n", DefaultPrinter
->name
,
3340 DefaultPrinter
->info
, ServerName
,
3341 DefaultPrinter
->name
);
3343 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3345 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3346 if (p
!= DefaultPrinter
)
3347 cupsFilePrintf(fp
, "%s|%s:rm=%s:rp=%s:\n", p
->name
, p
->info
,
3348 ServerName
, p
->name
);
3351 case PRINTCAP_PLIST
:
3353 * Each printer is written as a dictionary in a plist file.
3354 * Currently the printer-name, printer-info, printer-is-accepting-jobs,
3355 * printer-location, printer-make-and-model, printer-state,
3356 * printer-state-reasons, printer-type, and (sanitized) device-uri.
3359 cupsFilePuts(fp
, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
3360 "<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD "
3361 "PLIST 1.0//EN\" \"http://www.apple.com/DTDs/"
3362 "PropertyList-1.0.dtd\">\n"
3363 "<plist version=\"1.0\">\n"
3366 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3368 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3370 cupsFilePuts(fp
, "\t<dict>\n"
3371 "\t\t<key>printer-name</key>\n"
3373 write_xml_string(fp
, p
->name
);
3374 cupsFilePuts(fp
, "</string>\n"
3375 "\t\t<key>printer-info</key>\n"
3377 write_xml_string(fp
, p
->info
);
3378 cupsFilePrintf(fp
, "</string>\n"
3379 "\t\t<key>printer-is-accepting-jobs</key>\n"
3381 "\t\t<key>printer-location</key>\n"
3382 "\t\t<string>", p
->accepting
? "true" : "false");
3383 write_xml_string(fp
, p
->location
);
3384 cupsFilePuts(fp
, "</string>\n"
3385 "\t\t<key>printer-make-and-model</key>\n"
3387 write_xml_string(fp
, p
->make_model
);
3388 cupsFilePrintf(fp
, "</string>\n"
3389 "\t\t<key>printer-state</key>\n"
3390 "\t\t<integer>%d</integer>\n"
3391 "\t\t<key>printer-state-reasons</key>\n"
3392 "\t\t<array>\n", p
->state
);
3393 for (i
= 0; i
< p
->num_reasons
; i
++)
3395 cupsFilePuts(fp
, "\t\t\t<string>");
3396 write_xml_string(fp
, p
->reasons
[i
]);
3397 cupsFilePuts(fp
, "</string>\n");
3399 cupsFilePrintf(fp
, "\t\t</array>\n"
3400 "\t\t<key>printer-type</key>\n"
3401 "\t\t<integer>%d</integer>\n"
3402 "\t\t<key>device-uri</key>\n"
3403 "\t\t<string>", p
->type
);
3404 write_xml_string(fp
, p
->sanitized_device_uri
);
3405 cupsFilePuts(fp
, "</string>\n"
3408 cupsFilePuts(fp
, "</array>\n"
3412 case PRINTCAP_SOLARIS
:
3414 * Each printer is put in the file as:
3416 * _all:all=Printer1,Printer2,Printer3,...,PrinterN
3417 * _default:use=DefaultPrinter
3419 * :bsdaddr=ServerName,Printer1:\
3420 * :description=Description:
3422 * :bsdaddr=ServerName,Printer2:\
3423 * :description=Description:
3425 * :bsdaddr=ServerName,Printer3:\
3426 * :description=Description:
3429 * :bsdaddr=ServerName,PrinterN:\
3430 * :description=Description:
3433 cupsFilePuts(fp
, "_all:all=");
3434 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3436 p
= (cupsd_printer_t
*)cupsArrayCurrent(Printers
))
3437 cupsFilePrintf(fp
, "%s%c", p
->name
,
3438 cupsArrayNext(Printers
) ? ',' : '\n');
3441 cupsFilePrintf(fp
, "_default:use=%s\n", DefaultPrinter
->name
);
3443 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3445 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3446 cupsFilePrintf(fp
, "%s:\\\n"
3447 "\t:bsdaddr=%s,%s:\\\n"
3448 "\t:description=%s:\n",
3449 p
->name
, ServerName
, p
->name
,
3450 p
->info
? p
->info
: "");
3463 * 'add_printer_defaults()' - Add name-default attributes to the printer attributes.
3467 add_printer_defaults(cupsd_printer_t
*p
)/* I - Printer */
3469 int i
; /* Looping var */
3470 int num_options
; /* Number of default options */
3471 cups_option_t
*options
, /* Default options */
3472 *option
; /* Current option */
3473 char name
[256]; /* name-default */
3477 * Maintain a common array of default attribute names...
3480 if (!CommonDefaults
)
3482 CommonDefaults
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
3484 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("copies-default"));
3485 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("document-format-default"));
3486 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("finishings-default"));
3487 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-hold-until-default"));
3488 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-priority-default"));
3489 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-sheets-default"));
3490 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("media-default"));
3491 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("media-col-default"));
3492 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("number-up-default"));
3493 cupsArrayAdd(CommonDefaults
,
3494 _cupsStrAlloc("orientation-requested-default"));
3495 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("sides-default"));
3499 * Add all of the default options from the .conf files...
3502 for (num_options
= 0, options
= NULL
, i
= p
->num_options
, option
= p
->options
;
3506 if (strcmp(option
->name
, "ipp-options") &&
3507 strcmp(option
->name
, "job-sheets") &&
3508 strcmp(option
->name
, "lease-duration"))
3510 snprintf(name
, sizeof(name
), "%s-default", option
->name
);
3511 num_options
= cupsAddOption(name
, option
->value
, num_options
, &options
);
3513 if (!cupsArrayFind(CommonDefaults
, name
))
3514 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc(name
));
3519 * Convert options to IPP attributes...
3522 cupsEncodeOptions2(p
->attrs
, num_options
, options
, IPP_TAG_PRINTER
);
3523 cupsFreeOptions(num_options
, options
);
3526 * Add standard -default attributes as needed...
3529 if (!cupsGetOption("copies", p
->num_options
, p
->options
))
3530 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
, "copies-default",
3533 if (!cupsGetOption("document-format", p
->num_options
, p
->options
))
3534 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_MIMETYPE
,
3535 "document-format-default", NULL
, "application/octet-stream");
3537 if (!cupsGetOption("job-hold-until", p
->num_options
, p
->options
))
3538 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3539 "job-hold-until-default", NULL
, "no-hold");
3541 if (!cupsGetOption("job-priority", p
->num_options
, p
->options
))
3542 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3543 "job-priority-default", 50);
3545 if (!cupsGetOption("number-up", p
->num_options
, p
->options
))
3546 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3547 "number-up-default", 1);
3549 if (!cupsGetOption("notify-lease-duration", p
->num_options
, p
->options
))
3550 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3551 "notify-lease-duration-default", DefaultLeaseDuration
);
3553 if (!cupsGetOption("notify-events", p
->num_options
, p
->options
))
3554 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3555 "notify-events-default", NULL
, "job-completed");
3557 if (!cupsGetOption("orientation-requested", p
->num_options
, p
->options
))
3558 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NOVALUE
,
3559 "orientation-requested-default", NULL
, NULL
);
3561 if (!cupsGetOption("print-quality", p
->num_options
, p
->options
))
3562 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
3563 "print-quality-default", IPP_QUALITY_NORMAL
);
3568 * 'add_printer_filter()' - Add a MIME filter for a printer.
3573 cupsd_printer_t
*p
, /* I - Printer to add to */
3574 mime_type_t
*filtertype
, /* I - Filter or prefilter MIME type */
3575 const char *filter
) /* I - Filter to add */
3577 char super
[MIME_MAX_SUPER
], /* Super-type for filter */
3578 type
[MIME_MAX_TYPE
], /* Type for filter */
3579 program
[1024]; /* Program/filter name */
3580 int cost
; /* Cost of filter */
3581 mime_type_t
*temptype
; /* MIME type looping var */
3582 char filename
[1024], /* Full filter filename */
3583 *dirsep
; /* Pointer to directory separator */
3584 struct stat fileinfo
; /* File information */
3588 * Parse the filter string; it should be in the following format:
3590 * super/type cost program
3593 if (sscanf(filter
, "%15[^/]/%31s%d%*[ \t]%1023[^\n]", super
, type
, &cost
,
3596 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: invalid filter string \"%s\"!",
3602 * See if the filter program exists; if not, stop the printer and flag
3606 if (strcmp(program
, "-"))
3608 if (program
[0] == '/')
3609 strlcpy(filename
, program
, sizeof(filename
));
3611 snprintf(filename
, sizeof(filename
), "%s/filter/%s", ServerBin
, program
);
3613 if (stat(filename
, &fileinfo
))
3615 memset(&fileinfo
, 0, sizeof(fileinfo
));
3617 snprintf(p
->state_message
, sizeof(p
->state_message
),
3618 "Filter \"%s\" for printer \"%s\" not available: %s",
3619 filename
, p
->name
, strerror(errno
));
3620 cupsdSetPrinterReasons(p
, "+cups-missing-filter-warning");
3622 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s", p
->state_message
);
3626 * When running as root, do additional security checks...
3632 * Only use filters that are owned by root and do not have group or world
3633 * write permissions.
3636 if (fileinfo
.st_uid
||
3637 (fileinfo
.st_mode
& (S_ISUID
| S_IWGRP
| S_IWOTH
)) != 0)
3639 if (fileinfo
.st_uid
)
3640 snprintf(p
->state_message
, sizeof(p
->state_message
),
3641 "Filter \"%s\" for printer \"%s\" not owned by root",
3644 snprintf(p
->state_message
, sizeof(p
->state_message
),
3645 "Filter \"%s\" for printer \"%s\" has insecure permissions "
3646 "(0%o)", filename
, p
->name
, fileinfo
.st_mode
);
3648 cupsdSetPrinterReasons(p
, "+cups-insecure-filter-warning");
3650 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s", p
->state_message
);
3652 else if (fileinfo
.st_mode
)
3655 * Similarly, check that the parent directory is also owned by root and
3656 * does not have world write permissions.
3659 if ((dirsep
= strrchr(filename
, '/')) != NULL
)
3662 if (!stat(filename
, &fileinfo
) &&
3664 (fileinfo
.st_mode
& (S_ISUID
| S_IWGRP
| S_IWOTH
)) != 0))
3666 if (fileinfo
.st_uid
)
3667 snprintf(p
->state_message
, sizeof(p
->state_message
),
3668 "Filter directory \"%s\" for printer \"%s\" not owned by "
3669 "root", filename
, p
->name
);
3671 snprintf(p
->state_message
, sizeof(p
->state_message
),
3672 "Filter directory \"%s\" for printer \"%s\" has insecure "
3673 "permissions (0%o)", filename
, p
->name
, fileinfo
.st_mode
);
3675 cupsdSetPrinterReasons(p
, "+cups-insecure-filter-warning");
3677 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s", p
->state_message
);
3684 * Add the filter to the MIME database, supporting wildcards as needed...
3687 for (temptype
= mimeFirstType(MimeDatabase
);
3689 temptype
= mimeNextType(MimeDatabase
))
3690 if (((super
[0] == '*' && strcasecmp(temptype
->super
, "printer")) ||
3691 !strcasecmp(temptype
->super
, super
)) &&
3692 (type
[0] == '*' || !strcasecmp(temptype
->type
, type
)))
3694 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3695 "add_printer_filter: %s: adding filter %s/%s %s/%s %d %s",
3696 p
->name
, temptype
->super
, temptype
->type
,
3697 filtertype
->super
, filtertype
->type
,
3699 mimeAddFilter(MimeDatabase
, temptype
, filtertype
, cost
, program
);
3705 * 'add_printer_formats()' - Add document-format-supported values for a printer.
3709 add_printer_formats(cupsd_printer_t
*p
) /* I - Printer */
3711 int i
; /* Looping var */
3712 mime_type_t
*type
; /* Current MIME type */
3713 cups_array_t
*filters
; /* Filters */
3714 ipp_attribute_t
*attr
; /* document-format-supported attribute */
3715 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
3716 /* MIME type name */
3720 * Raw (and remote) queues advertise all of the supported MIME
3724 cupsArrayDelete(p
->filetypes
);
3725 p
->filetypes
= NULL
;
3729 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
,
3730 (ipp_tag_t
)(IPP_TAG_MIMETYPE
| IPP_TAG_COPY
),
3731 "document-format-supported", NumMimeTypes
, NULL
, MimeTypes
);
3736 * Otherwise, loop through the supported MIME types and see if there
3737 * are filters for them...
3740 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_printer_formats: %d types, %d filters",
3741 mimeNumTypes(MimeDatabase
), mimeNumFilters(MimeDatabase
));
3743 p
->filetypes
= cupsArrayNew(NULL
, NULL
);
3745 for (type
= mimeFirstType(MimeDatabase
);
3747 type
= mimeNextType(MimeDatabase
))
3749 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
3751 if ((filters
= mimeFilter(MimeDatabase
, type
, p
->filetype
, NULL
)) != NULL
)
3753 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3754 "add_printer_formats: %s: %s needs %d filters",
3755 p
->name
, mimetype
, cupsArrayCount(filters
));
3757 cupsArrayDelete(filters
);
3758 cupsArrayAdd(p
->filetypes
, type
);
3761 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3762 "add_printer_formats: %s: %s not supported",
3767 * Add the file formats that can be filtered...
3770 if ((type
= mimeType(MimeDatabase
, "application", "octet-stream")) == NULL
||
3771 !cupsArrayFind(p
->filetypes
, type
))
3776 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3777 "add_printer_formats: %s: %d supported types",
3778 p
->name
, cupsArrayCount(p
->filetypes
) + i
);
3780 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_MIMETYPE
,
3781 "document-format-supported",
3782 cupsArrayCount(p
->filetypes
) + i
, NULL
, NULL
);
3785 attr
->values
[0].string
.text
= _cupsStrAlloc("application/octet-stream");
3787 for (type
= (mime_type_t
*)cupsArrayFirst(p
->filetypes
);
3789 i
++, type
= (mime_type_t
*)cupsArrayNext(p
->filetypes
))
3791 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
3793 attr
->values
[i
].string
.text
= _cupsStrAlloc(mimetype
);
3798 char pdl
[1024]; /* Buffer to build pdl list */
3799 mime_filter_t
*filter
; /* MIME filter looping var */
3803 * We only support raw printing if this is not a Tioga PrintJobMgr based
3804 * queue and if application/octet-stream is a known type...
3807 for (filter
= (mime_filter_t
*)cupsArrayFirst(MimeDatabase
->filters
);
3809 filter
= (mime_filter_t
*)cupsArrayNext(MimeDatabase
->filters
))
3811 if (filter
->dst
== p
->filetype
&& filter
->filter
&&
3812 strstr(filter
->filter
, "PrintJobMgr"))
3818 if (!filter
&& mimeType(MimeDatabase
, "application", "octet-stream"))
3819 strlcat(pdl
, "application/octet-stream,", sizeof(pdl
));
3822 * Then list a bunch of formats that are supported by the printer...
3825 for (type
= (mime_type_t
*)cupsArrayFirst(p
->filetypes
);
3827 type
= (mime_type_t
*)cupsArrayNext(p
->filetypes
))
3829 if (!strcasecmp(type
->super
, "application"))
3831 if (!strcasecmp(type
->type
, "pdf"))
3832 strlcat(pdl
, "application/pdf,", sizeof(pdl
));
3833 else if (!strcasecmp(type
->type
, "postscript"))
3834 strlcat(pdl
, "application/postscript,", sizeof(pdl
));
3836 else if (!strcasecmp(type
->super
, "image"))
3838 if (!strcasecmp(type
->type
, "jpeg"))
3839 strlcat(pdl
, "image/jpeg,", sizeof(pdl
));
3840 else if (!strcasecmp(type
->type
, "png"))
3841 strlcat(pdl
, "image/png,", sizeof(pdl
));
3846 pdl
[strlen(pdl
) - 1] = '\0'; /* Remove trailing comma */
3848 cupsdSetString(&p
->pdl
, pdl
);
3850 #endif /* HAVE_DNSSD */
3855 * 'add_string_array()' - Add a string to an array of CUPS strings.
3859 add_string_array(cups_array_t
**a
, /* I - Array */
3860 const char *s
) /* I - String */
3863 *a
= cupsArrayNew(NULL
, NULL
);
3865 cupsArrayAdd(*a
, _cupsStrAlloc(s
));
3870 * 'compare_printers()' - Compare two printers.
3873 static int /* O - Result of comparison */
3874 compare_printers(void *first
, /* I - First printer */
3875 void *second
, /* I - Second printer */
3876 void *data
) /* I - App data (not used) */
3878 return (strcasecmp(((cupsd_printer_t
*)first
)->name
,
3879 ((cupsd_printer_t
*)second
)->name
));
3884 * 'delete_printer_filters()' - Delete all MIME filters for a printer.
3888 delete_printer_filters(
3889 cupsd_printer_t
*p
) /* I - Printer to remove from */
3891 mime_filter_t
*filter
; /* MIME filter looping var */
3895 * Range check input...
3902 * Remove all filters from the MIME database that have a destination
3903 * type == printer...
3906 for (filter
= mimeFirstFilter(MimeDatabase
);
3908 filter
= mimeNextFilter(MimeDatabase
))
3909 if (filter
->dst
== p
->filetype
|| filter
->dst
== p
->prefiltertype
)
3912 * Delete the current filter...
3915 mimeDeleteFilter(MimeDatabase
, filter
);
3918 cupsdSetPrinterReasons(p
, "-cups-insecure-filter-warning"
3919 ",cups-missing-filter-warning");
3924 * 'delete_string_array()' - Delete an array of CUPS strings.
3928 delete_string_array(cups_array_t
**a
) /* I - Array */
3930 char *ptr
; /* Current string */
3933 for (ptr
= (char *)cupsArrayFirst(*a
);
3935 ptr
= (char *)cupsArrayNext(*a
))
3938 cupsArrayDelete(*a
);
3944 * 'load_ppd()' - Load a cached PPD file, updating the cache as needed.
3948 load_ppd(cupsd_printer_t
*p
) /* I - Printer */
3950 int i
, j
, k
; /* Looping vars */
3951 cups_file_t
*cache
; /* IPP cache file */
3952 char cache_name
[1024]; /* IPP cache filename */
3953 struct stat cache_info
; /* IPP cache file info */
3954 char pwg_name
[1024]; /* PWG cache filename */
3955 struct stat pwg_info
; /* PWG cache file info */
3956 ppd_file_t
*ppd
; /* PPD file */
3957 char ppd_name
[1024]; /* PPD filename */
3958 struct stat ppd_info
; /* PPD file info */
3959 int num_media
; /* Number of media options */
3960 ppd_size_t
*size
; /* Current PPD size */
3961 ppd_option_t
*duplex
, /* Duplex option */
3962 *output_bin
, /* OutputBin option */
3963 *output_mode
, /* OutputMode option */
3964 *resolution
; /* (Set|JCL|)Resolution option */
3965 ppd_choice_t
*choice
, /* Current PPD choice */
3966 *input_slot
, /* Current input slot */
3967 *media_type
; /* Current media type */
3968 ppd_attr_t
*ppd_attr
; /* PPD attribute */
3969 int xdpi
, /* Horizontal resolution */
3970 ydpi
; /* Vertical resolution */
3971 const char *resptr
; /* Pointer into resolution keyword */
3972 _pwg_size_t
*pwgsize
; /* Current PWG size */
3973 _pwg_map_t
*pwgsource
, /* Current PWG source */
3974 *pwgtype
; /* Current PWG type */
3975 ipp_attribute_t
*attr
; /* Attribute data */
3976 ipp_value_t
*val
; /* Attribute value */
3977 int num_finishings
, /* Number of finishings */
3978 finishings
[5]; /* finishings-supported values */
3979 int num_qualities
, /* Number of print-quality values */
3980 qualities
[3]; /* print-quality values */
3981 int num_margins
, /* Number of media-*-margin-supported values */
3982 margins
[16]; /* media-*-margin-supported values */
3983 static const char * const sides
[3] = /* sides-supported values */
3986 "two-sided-long-edge",
3987 "two-sided-short-edge"
3989 static const char * const standard_commands
[] =
3990 { /* Standard CUPS commands */
3998 * Check to see if the cache is up-to-date...
4001 snprintf(cache_name
, sizeof(cache_name
), "%s/%s.ipp2", CacheDir
, p
->name
);
4002 if (stat(cache_name
, &cache_info
))
4003 cache_info
.st_mtime
= 0;
4005 snprintf(pwg_name
, sizeof(pwg_name
), "%s/%s.pwg", CacheDir
, p
->name
);
4006 if (stat(pwg_name
, &pwg_info
))
4007 pwg_info
.st_mtime
= 0;
4009 snprintf(ppd_name
, sizeof(ppd_name
), "%s/ppd/%s.ppd", ServerRoot
, p
->name
);
4010 if (stat(ppd_name
, &ppd_info
))
4011 ppd_info
.st_mtime
= 1;
4013 ippDelete(p
->ppd_attrs
);
4014 p
->ppd_attrs
= ippNew();
4016 _pwgDestroy(p
->pwg
);
4019 if (pwg_info
.st_mtime
>= ppd_info
.st_mtime
)
4020 p
->pwg
= _pwgCreateWithFile(pwg_name
);
4022 if (cache_info
.st_mtime
>= ppd_info
.st_mtime
&& p
->pwg
&&
4023 (cache
= cupsFileOpen(cache_name
, "r")) != NULL
)
4026 * Load cached information and return...
4029 cupsdLogMessage(CUPSD_LOG_DEBUG
, "load_ppd: Loading %s...", cache_name
);
4031 if (ippReadIO(cache
, (ipp_iocb_t
)cupsFileRead
, 1, NULL
,
4032 p
->ppd_attrs
) == IPP_DATA
)
4034 cupsFileClose(cache
);
4038 cupsFileClose(cache
);
4042 * Reload PPD attributes from disk...
4045 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
4047 _pwgDestroy(p
->pwg
);
4050 cupsdLogMessage(CUPSD_LOG_DEBUG
, "load_ppd: Loading %s...", ppd_name
);
4052 delete_string_array(&(p
->filters
));
4053 delete_string_array(&(p
->pre_filters
));
4055 p
->type
&= ~CUPS_PRINTER_OPTIONS
;
4056 p
->type
|= CUPS_PRINTER_BW
;
4058 finishings
[0] = IPP_FINISHINGS_NONE
;
4061 if ((ppd
= ppdOpenFile(ppd_name
)) != NULL
)
4064 * Add make/model and other various attributes...
4067 p
->pwg
= _pwgCreateWithPPD(ppd
);
4069 ppdMarkDefaults(ppd
);
4071 if (ppd
->color_device
)
4072 p
->type
|= CUPS_PRINTER_COLOR
;
4073 if (ppd
->variable_sizes
)
4074 p
->type
|= CUPS_PRINTER_VARIABLE
;
4075 if (!ppd
->manual_copies
)
4076 p
->type
|= CUPS_PRINTER_COPIES
;
4077 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsFax", NULL
)) != NULL
)
4078 if (ppd_attr
->value
&& !strcasecmp(ppd_attr
->value
, "true"))
4079 p
->type
|= CUPS_PRINTER_FAX
;
4081 ippAddBoolean(p
->ppd_attrs
, IPP_TAG_PRINTER
, "color-supported",
4083 if (ppd
->throughput
)
4085 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4086 "pages-per-minute", ppd
->throughput
);
4087 if (ppd
->color_device
)
4088 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4089 "pages-per-minute-color", ppd
->throughput
);
4094 if ((output_mode
= ppdFindOption(ppd
, "OutputMode")) != NULL
)
4096 if (ppdFindChoice(output_mode
, "draft") ||
4097 ppdFindChoice(output_mode
, "fast"))
4098 qualities
[num_qualities
++] = IPP_QUALITY_DRAFT
;
4099 if (ppdFindChoice(output_mode
, "normal") ||
4100 ppdFindChoice(output_mode
, "good"))
4101 qualities
[num_qualities
++] = IPP_QUALITY_NORMAL
;
4102 if (ppdFindChoice(output_mode
, "best") ||
4103 ppdFindChoice(output_mode
, "high"))
4104 qualities
[num_qualities
++] = IPP_QUALITY_HIGH
;
4106 else if ((ppd_attr
= ppdFindAttr(ppd
, "APPrinterPreset", NULL
)) != NULL
)
4110 if (strstr(ppd_attr
->spec
, "draft") ||
4111 strstr(ppd_attr
->spec
, "Draft"))
4113 qualities
[num_qualities
++] = IPP_QUALITY_DRAFT
;
4117 while ((ppd_attr
= ppdFindNextAttr(ppd
, "APPrinterPreset",
4120 qualities
[num_qualities
++] = IPP_QUALITY_NORMAL
;
4121 qualities
[num_qualities
++] = IPP_QUALITY_HIGH
;
4124 if (num_qualities
== 0)
4125 qualities
[num_qualities
++] = IPP_QUALITY_NORMAL
;
4127 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
4128 "print-quality-supported", num_qualities
, qualities
);
4133 * The NickName can be localized in the character set specified
4134 * by the LanugageEncoding attribute. However, ppdOpen2() has
4135 * already converted the ppd->nickname member to UTF-8 for us
4136 * (the original attribute value is available separately)
4139 cupsdSetString(&p
->make_model
, ppd
->nickname
);
4141 else if (ppd
->modelname
)
4144 * Model name can only contain specific characters...
4147 cupsdSetString(&p
->make_model
, ppd
->modelname
);
4150 cupsdSetString(&p
->make_model
, "Bad PPD File");
4152 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
4153 "printer-make-and-model", NULL
, p
->make_model
);
4156 * Add media options from the PPD file...
4159 if (ppd
->num_sizes
== 0 || !p
->pwg
)
4161 if (!ppdFindAttr(ppd
, "APScannerOnly", NULL
))
4162 cupsdLogMessage(CUPSD_LOG_CRIT
,
4163 "The PPD file for printer %s contains no media "
4164 "options and is therefore invalid!", p
->name
);
4166 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4167 "media-default", NULL
, "unknown");
4168 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4169 "media-supported", NULL
, "unknown");
4177 if ((size
= ppdPageSize(ppd
, NULL
)) != NULL
)
4178 pwgsize
= _pwgGetSize(p
->pwg
, size
->name
);
4182 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4183 "media-default", NULL
,
4184 pwgsize
? pwgsize
->map
.pwg
: "unknown");
4192 ipp_t
*col
; /* Collection value */
4194 input_slot
= ppdFindMarkedChoice(ppd
, "InputSlot");
4195 media_type
= ppdFindMarkedChoice(ppd
, "MediaType");
4196 col
= new_media_col(pwgsize
,
4198 _pwgGetSource(p
->pwg
,
4199 input_slot
->choice
) :
4203 media_type
->choice
) :
4206 ippAddCollection(p
->ppd_attrs
, IPP_TAG_PRINTER
, "media-col-default",
4215 num_media
= p
->pwg
->num_sizes
;
4216 if (p
->pwg
->custom_min_keyword
)
4219 if ((attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4220 "media-supported", num_media
, NULL
,
4225 for (i
= p
->pwg
->num_sizes
, pwgsize
= p
->pwg
->sizes
;
4227 i
--, pwgsize
++, val
++)
4228 val
->string
.text
= _cupsStrRetain(pwgsize
->map
.pwg
);
4230 if (p
->pwg
->custom_min_keyword
)
4232 val
->string
.text
= _cupsStrRetain(p
->pwg
->custom_min_keyword
);
4234 val
->string
.text
= _cupsStrRetain(p
->pwg
->custom_max_keyword
);
4239 * media-source-supported
4242 if (p
->pwg
->num_sources
> 0 &&
4243 (attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4244 "media-source-supported", p
->pwg
->num_sources
,
4245 NULL
, NULL
)) != NULL
)
4247 for (i
= p
->pwg
->num_sources
, pwgsource
= p
->pwg
->sources
,
4250 i
--, pwgsource
++, val
++)
4251 val
->string
.text
= _cupsStrRetain(pwgsource
->pwg
);
4255 * media-type-supported
4258 if (p
->pwg
->num_types
> 0 &&
4259 (attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4260 "media-type-supported", p
->pwg
->num_types
,
4261 NULL
, NULL
)) != NULL
)
4263 for (i
= p
->pwg
->num_types
, pwgtype
= p
->pwg
->types
,
4266 i
--, pwgtype
++, val
++)
4267 val
->string
.text
= _cupsStrRetain(pwgtype
->pwg
);
4271 * media-*-margin-supported
4274 for (i
= p
->pwg
->num_sizes
, pwgsize
= p
->pwg
->sizes
, num_margins
= 0;
4275 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4278 for (j
= 0; j
< num_margins
; j
++)
4279 if (pwgsize
->bottom
== margins
[j
])
4282 if (j
>= num_margins
)
4284 margins
[num_margins
] = pwgsize
->bottom
;
4289 if (num_margins
> 0)
4290 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4291 "media-bottom-margin-supported", num_margins
, margins
);
4293 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4294 "media-bottom-margin-supported", 0);
4296 for (i
= p
->pwg
->num_sizes
, pwgsize
= p
->pwg
->sizes
, num_margins
= 0;
4297 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4300 for (j
= 0; j
< num_margins
; j
++)
4301 if (pwgsize
->left
== margins
[j
])
4304 if (j
>= num_margins
)
4306 margins
[num_margins
] = pwgsize
->left
;
4311 if (num_margins
> 0)
4312 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4313 "media-left-margin-supported", num_margins
, margins
);
4315 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4316 "media-left-margin-supported", 0);
4318 for (i
= p
->pwg
->num_sizes
, pwgsize
= p
->pwg
->sizes
, num_margins
= 0;
4319 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4322 for (j
= 0; j
< num_margins
; j
++)
4323 if (pwgsize
->right
== margins
[j
])
4326 if (j
>= num_margins
)
4328 margins
[num_margins
] = pwgsize
->right
;
4333 if (num_margins
> 0)
4334 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4335 "media-right-margin-supported", num_margins
, margins
);
4337 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4338 "media-right-margin-supported", 0);
4340 for (i
= p
->pwg
->num_sizes
, pwgsize
= p
->pwg
->sizes
, num_margins
= 0;
4341 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4344 for (j
= 0; j
< num_margins
; j
++)
4345 if (pwgsize
->top
== margins
[j
])
4348 if (j
>= num_margins
)
4350 margins
[num_margins
] = pwgsize
->top
;
4355 if (num_margins
> 0)
4356 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4357 "media-top-margin-supported", num_margins
, margins
);
4359 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4360 "media-top-margin-supported", 0);
4363 * media-col-database
4366 num_media
= p
->pwg
->num_sizes
;
4367 if (p
->pwg
->num_sources
)
4369 if (p
->pwg
->num_types
> 0)
4370 num_media
+= p
->pwg
->num_sizes
* p
->pwg
->num_sources
*
4373 num_media
+= p
->pwg
->num_sizes
* p
->pwg
->num_sources
;
4375 else if (p
->pwg
->num_types
)
4376 num_media
+= p
->pwg
->num_sizes
* p
->pwg
->num_types
;
4378 if ((attr
= ippAddCollections(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4379 "media-col-database", num_media
,
4382 for (i
= p
->pwg
->num_sizes
, pwgsize
= p
->pwg
->sizes
, val
= attr
->values
;
4387 * Start by adding the page size without source or type...
4390 ppdMarkOption(ppd
, "PageSize", pwgsize
->map
.ppd
);
4392 val
->collection
= new_media_col(pwgsize
, NULL
, NULL
);
4396 * Then add the specific, supported combinations of size, source, and
4400 if (p
->pwg
->num_sources
> 0)
4402 for (j
= p
->pwg
->num_sources
, pwgsource
= p
->pwg
->sources
;
4406 ppdMarkOption(ppd
, "InputSlot", pwgsource
->ppd
);
4408 if (p
->pwg
->num_types
> 0)
4410 for (k
= p
->pwg
->num_types
, pwgtype
= p
->pwg
->types
;
4414 if (!ppdMarkOption(ppd
, "MediaType", pwgtype
->ppd
))
4416 val
->collection
= new_media_col(pwgsize
, pwgsource
->pwg
,
4422 else if (!ppdConflicts(ppd
))
4424 val
->collection
= new_media_col(pwgsize
, pwgsource
->pwg
, NULL
);
4429 else if (p
->pwg
->num_types
> 0)
4431 for (j
= p
->pwg
->num_types
, pwgtype
= p
->pwg
->types
;
4435 if (!ppdMarkOption(ppd
, "MediaType", pwgtype
->ppd
))
4437 val
->collection
= new_media_col(pwgsize
, NULL
, pwgtype
->pwg
);
4445 * Update the number of media-col-database values...
4448 attr
->num_values
= val
- attr
->values
;
4456 if ((output_bin
= ppdFindOption(ppd
, "OutputBin")) != NULL
)
4458 attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4459 "output-bin-supported", output_bin
->num_choices
,
4464 for (i
= 0, val
= attr
->values
;
4465 i
< output_bin
->num_choices
;
4467 val
->string
.text
= _cupsStrAlloc(output_bin
->choices
[i
].choice
);
4470 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4471 "output-bin-default", NULL
, output_bin
->defchoice
);
4475 * Printer resolutions...
4478 if ((resolution
= ppdFindOption(ppd
, "Resolution")) == NULL
)
4479 if ((resolution
= ppdFindOption(ppd
, "JCLResolution")) == NULL
)
4480 if ((resolution
= ppdFindOption(ppd
, "SetResolution")) == NULL
)
4481 resolution
= ppdFindOption(ppd
, "CNRes_PGP");
4486 * Report all supported resolutions...
4489 attr
= ippAddResolutions(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4490 "printer-resolution-supported",
4491 resolution
->num_choices
, IPP_RES_PER_INCH
,
4494 for (i
= 0, choice
= resolution
->choices
;
4495 i
< resolution
->num_choices
;
4498 xdpi
= ydpi
= (int)strtol(choice
->choice
, (char **)&resptr
, 10);
4499 if (resptr
> choice
->choice
&& xdpi
> 0 && *resptr
== 'x')
4500 ydpi
= (int)strtol(resptr
+ 1, (char **)&resptr
, 10);
4502 if (xdpi
<= 0 || ydpi
<= 0)
4504 cupsdLogMessage(CUPSD_LOG_WARN
,
4505 "Bad resolution \"%s\" for printer %s.",
4506 choice
->choice
, p
->name
);
4510 attr
->values
[i
].resolution
.xres
= xdpi
;
4511 attr
->values
[i
].resolution
.yres
= ydpi
;
4512 attr
->values
[i
].resolution
.units
= IPP_RES_PER_INCH
;
4515 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4516 "printer-resolution-default", IPP_RES_PER_INCH
,
4520 else if ((ppd_attr
= ppdFindAttr(ppd
, "DefaultResolution", NULL
)) != NULL
&&
4524 * Just the DefaultResolution to report...
4527 xdpi
= ydpi
= (int)strtol(ppd_attr
->value
, (char **)&resptr
, 10);
4528 if (resptr
> ppd_attr
->value
&& xdpi
> 0)
4531 ydpi
= (int)strtol(resptr
+ 1, (char **)&resptr
, 10);
4536 if (xdpi
<= 0 || ydpi
<= 0)
4538 cupsdLogMessage(CUPSD_LOG_WARN
,
4539 "Bad default resolution \"%s\" for printer %s.",
4540 ppd_attr
->value
, p
->name
);
4544 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4545 "printer-resolution-default", IPP_RES_PER_INCH
,
4547 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4548 "printer-resolution-supported", IPP_RES_PER_INCH
,
4554 * No resolutions in PPD - make one up...
4557 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4558 "printer-resolution-default", IPP_RES_PER_INCH
,
4560 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4561 "printer-resolution-supported", IPP_RES_PER_INCH
,
4569 if ((duplex
= ppdFindOption(ppd
, "Duplex")) == NULL
)
4570 if ((duplex
= ppdFindOption(ppd
, "EFDuplex")) == NULL
)
4571 if ((duplex
= ppdFindOption(ppd
, "EFDuplexing")) == NULL
)
4572 if ((duplex
= ppdFindOption(ppd
, "KD03Duplex")) == NULL
)
4573 duplex
= ppdFindOption(ppd
, "JCLDuplex");
4575 if (duplex
&& duplex
->num_choices
> 1 &&
4576 !ppdInstallableConflict(ppd
, duplex
->keyword
, "DuplexTumble"))
4578 p
->type
|= CUPS_PRINTER_DUPLEX
;
4580 ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4581 "sides-supported", 3, NULL
, sides
);
4583 if (!strcasecmp(duplex
->defchoice
, "DuplexTumble"))
4584 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4585 "sides-default", NULL
, "two-sided-short-edge");
4586 else if (!strcasecmp(duplex
->defchoice
, "DuplexNoTumble"))
4587 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4588 "sides-default", NULL
, "two-sided-long-edge");
4590 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4591 "sides-default", NULL
, "one-sided");
4594 if (ppdFindOption(ppd
, "Collate") != NULL
)
4595 p
->type
|= CUPS_PRINTER_COLLATE
;
4597 if (ppdFindOption(ppd
, "StapleLocation") != NULL
)
4599 p
->type
|= CUPS_PRINTER_STAPLE
;
4600 finishings
[num_finishings
++] = IPP_FINISHINGS_STAPLE
;
4603 if (ppdFindOption(ppd
, "BindEdge") != NULL
)
4605 p
->type
|= CUPS_PRINTER_BIND
;
4606 finishings
[num_finishings
++] = IPP_FINISHINGS_BIND
;
4609 for (i
= 0; i
< ppd
->num_sizes
; i
++)
4610 if (ppd
->sizes
[i
].length
> 1728)
4611 p
->type
|= CUPS_PRINTER_LARGE
;
4612 else if (ppd
->sizes
[i
].length
> 1008)
4613 p
->type
|= CUPS_PRINTER_MEDIUM
;
4615 p
->type
|= CUPS_PRINTER_SMALL
;
4617 if ((ppd_attr
= ppdFindAttr(ppd
, "APICADriver", NULL
)) != NULL
&&
4618 ppd_attr
->value
&& !strcasecmp(ppd_attr
->value
, "true"))
4620 if ((ppd_attr
= ppdFindAttr(ppd
, "APScannerOnly", NULL
)) != NULL
&&
4621 ppd_attr
->value
&& !strcasecmp(ppd_attr
->value
, "true"))
4622 p
->type
|= CUPS_PRINTER_SCANNER
;
4624 p
->type
|= CUPS_PRINTER_MFP
;
4628 * Add a filter from application/vnd.cups-raw to printer/name to
4629 * handle "raw" printing by users.
4632 add_string_array(&(p
->filters
), "application/vnd.cups-raw 0 -");
4635 * Add any pre-filters in the PPD file...
4638 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsPreFilter", NULL
)) != NULL
)
4640 for (; ppd_attr
; ppd_attr
= ppdFindNextAttr(ppd
, "cupsPreFilter", NULL
))
4641 if (ppd_attr
->value
)
4642 add_string_array(&(p
->pre_filters
), ppd_attr
->value
);
4646 * Add any filters in the PPD file...
4649 DEBUG_printf(("ppd->num_filters = %d\n", ppd
->num_filters
));
4650 for (i
= 0; i
< ppd
->num_filters
; i
++)
4652 DEBUG_printf(("ppd->filters[%d] = \"%s\"\n", i
, ppd
->filters
[i
]));
4653 add_string_array(&(p
->filters
), ppd
->filters
[i
]);
4655 if (!strncasecmp(ppd
->filters
[i
], "application/vnd.cups-command", 28) &&
4656 isspace(ppd
->filters
[i
][28] & 255))
4657 p
->type
|= CUPS_PRINTER_COMMANDS
;
4660 if (ppd
->num_filters
== 0)
4663 * If there are no filters, add PostScript printing filters.
4666 add_string_array(&(p
->filters
),
4667 "application/vnd.cups-command 0 commandtops");
4668 add_string_array(&(p
->filters
),
4669 "application/vnd.cups-postscript 0 -");
4671 p
->type
|= CUPS_PRINTER_COMMANDS
;
4673 else if (!(p
->type
& CUPS_PRINTER_COMMANDS
))
4676 * See if this is a PostScript device without a command filter...
4679 for (i
= 0; i
< ppd
->num_filters
; i
++)
4680 if (!strncasecmp(ppd
->filters
[i
],
4681 "application/vnd.cups-postscript", 31) &&
4682 isspace(ppd
->filters
[i
][31] & 255))
4685 if (i
< ppd
->num_filters
)
4688 * Add the generic PostScript command filter...
4691 add_string_array(&(p
->filters
),
4692 "application/vnd.cups-command 0 commandtops");
4693 p
->type
|= CUPS_PRINTER_COMMANDS
;
4697 if (p
->type
& CUPS_PRINTER_COMMANDS
)
4699 char *commands
, /* Copy of commands */
4700 *start
, /* Start of name */
4701 *end
; /* End of name */
4702 int count
; /* Number of commands */
4705 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsCommands", NULL
)) != NULL
&&
4706 ppd_attr
->value
&& ppd_attr
->value
[0])
4708 for (count
= 0, start
= ppd_attr
->value
; *start
; count
++)
4710 while (isspace(*start
& 255))
4716 while (*start
&& !isspace(*start
& 255))
4726 * Make a copy of the commands string and count how many ...
4729 attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4730 "printer-commands", count
, NULL
, NULL
);
4732 commands
= strdup(ppd_attr
->value
);
4734 for (count
= 0, start
= commands
; *start
; count
++)
4736 while (isspace(*start
& 255))
4743 while (*end
&& !isspace(*end
& 255))
4749 attr
->values
[count
].string
.text
= _cupsStrAlloc(start
);
4759 * Add the standard list of commands...
4762 ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4764 (int)(sizeof(standard_commands
) /
4765 sizeof(standard_commands
[0])), NULL
,
4772 * No commands supported...
4775 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4776 "printer-commands", NULL
, "none");
4780 * Show current and available port monitors for this printer...
4783 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
, "port-monitor",
4784 NULL
, p
->port_monitor
? p
->port_monitor
: "none");
4786 for (i
= 1, ppd_attr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
4788 i
++, ppd_attr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
));
4792 if (strstr(ppd
->protocols
, "TBCP"))
4794 else if (strstr(ppd
->protocols
, "BCP"))
4798 attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
4799 "port-monitor-supported", i
, NULL
, NULL
);
4801 attr
->values
[0].string
.text
= _cupsStrAlloc("none");
4803 for (i
= 1, ppd_attr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
4805 i
++, ppd_attr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
))
4806 attr
->values
[i
].string
.text
= _cupsStrAlloc(ppd_attr
->value
);
4810 if (strstr(ppd
->protocols
, "TBCP"))
4811 attr
->values
[i
].string
.text
= _cupsStrAlloc("tbcp");
4812 else if (strstr(ppd
->protocols
, "BCP"))
4813 attr
->values
[i
].string
.text
= _cupsStrAlloc("bcp");
4817 cupsdSetString(&p
->product
, ppd
->product
);
4818 #endif /* HAVE_DNSSD */
4820 if (ppdFindAttr(ppd
, "APRemoteQueueID", NULL
))
4821 p
->type
|= CUPS_PRINTER_REMOTE
;
4824 * Close the PPD and set the type...
4829 else if (!access(ppd_name
, 0))
4831 int pline
; /* PPD line number */
4832 ppd_status_t pstatus
; /* PPD load status */
4835 pstatus
= ppdLastError(&pline
);
4837 cupsdLogMessage(CUPSD_LOG_ERROR
, "PPD file for %s cannot be loaded!",
4840 if (pstatus
<= PPD_ALLOC_ERROR
)
4841 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s", strerror(errno
));
4843 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s on line %d.",
4844 ppdErrorString(pstatus
), pline
);
4846 cupsdLogMessage(CUPSD_LOG_INFO
,
4847 "Hint: Run \"cupstestppd %s\" and fix any errors.",
4851 * Add a filter from application/vnd.cups-raw to printer/name to
4852 * handle "raw" printing by users.
4855 add_string_array(&(p
->filters
), "application/vnd.cups-raw 0 -");
4858 * Add a PostScript filter, since this is still possibly PS printer.
4861 add_string_array(&(p
->filters
), "application/vnd.cups-postscript 0 -");
4866 * If we have an interface script, add a filter entry for it...
4869 char interface
[1024]; /* Interface script */
4872 snprintf(interface
, sizeof(interface
), "%s/interfaces/%s", ServerRoot
,
4874 if (!access(interface
, X_OK
))
4877 * Yes, we have a System V style interface script; use it!
4880 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
4881 "printer-make-and-model", NULL
,
4882 "Local System V Printer");
4884 snprintf(interface
, sizeof(interface
), "*/* 0 %s/interfaces/%s",
4885 ServerRoot
, p
->name
);
4886 add_string_array(&(p
->filters
), interface
);
4888 else if (!strncmp(p
->device_uri
, "ipp://", 6) &&
4889 (strstr(p
->device_uri
, "/printers/") != NULL
||
4890 strstr(p
->device_uri
, "/classes/") != NULL
||
4891 (strstr(p
->device_uri
, "._ipp.") != NULL
&&
4892 !strcmp(p
->device_uri
+ strlen(p
->device_uri
) - 5,
4896 * Tell the client this is really a hard-wired remote printer.
4899 p
->type
|= CUPS_PRINTER_REMOTE
;
4902 * Point the printer-uri-supported attribute to the
4906 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
4907 "printer-uri-supported", NULL
, p
->device_uri
);
4910 * Then set the make-and-model accordingly...
4913 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
4914 "printer-make-and-model", NULL
, "Remote Printer");
4917 * Print all files directly...
4926 * Otherwise we have neither - treat this as a "dumb" printer
4927 * with no PPD file...
4930 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
4931 "printer-make-and-model", NULL
, "Local Raw Printer");
4937 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
4938 "finishings-supported", num_finishings
, finishings
);
4939 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
4940 "finishings-default", IPP_FINISHINGS_NONE
);
4942 if (ppd
&& (cache
= cupsFileOpen(cache_name
, "w9")) != NULL
)
4945 * Save cached PPD attributes to disk...
4948 cupsdLogMessage(CUPSD_LOG_DEBUG
, "load_ppd: Saving %s...", cache_name
);
4950 p
->ppd_attrs
->state
= IPP_IDLE
;
4952 if (ippWriteIO(cache
, (ipp_iocb_t
)cupsFileWrite
, 1, NULL
,
4953 p
->ppd_attrs
) != IPP_DATA
)
4955 cupsdLogMessage(CUPSD_LOG_ERROR
,
4956 "Unable to save PPD cache file \"%s\" - %s", cache_name
,
4961 cupsFileClose(cache
);
4963 _pwgWriteFile(p
->pwg
, pwg_name
);
4968 * Remove cache files...
4971 if (cache_info
.st_mtime
)
4974 if (pwg_info
.st_mtime
)
4981 * 'new_media_col()' - Create a media-col collection value.
4984 static ipp_t
* /* O - Collection value */
4985 new_media_col(_pwg_size_t
*size
, /* I - media-size/margin values */
4986 const char *source
, /* I - media-source value */
4987 const char *type
) /* I - media-type value */
4989 ipp_t
*media_col
, /* Collection value */
4990 *media_size
; /* media-size value */
4993 media_col
= ippNew();
4995 media_size
= ippNew();
4996 ippAddInteger(media_size
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4997 "x-dimension", size
->width
);
4998 ippAddInteger(media_size
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4999 "y-dimension", size
->length
);
5000 ippAddCollection(media_col
, IPP_TAG_PRINTER
, "media-size", media_size
);
5001 ippDelete(media_size
);
5003 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5004 "media-bottom-margin", size
->bottom
);
5005 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5006 "media-left-margin", size
->left
);
5007 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5008 "media-right-margin", size
->right
);
5009 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5010 "media-top-margin", size
->top
);
5013 ippAddString(media_col
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
, "media-source",
5017 ippAddString(media_col
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
, "media-type",
5026 * 'write_irix_config()' - Update the config files used by the IRIX
5031 write_irix_config(cupsd_printer_t
*p
) /* I - Printer to update */
5033 char filename
[1024]; /* Interface script filename */
5034 cups_file_t
*fp
; /* Interface script file */
5035 ipp_attribute_t
*attr
; /* Attribute data */
5039 * Add dummy interface and GUI scripts to fool SGI's "challenged" printing
5040 * tools. First the interface script that tells the tools what kind of
5041 * printer we have...
5044 snprintf(filename
, sizeof(filename
), "/var/spool/lp/interface/%s", p
->name
);
5046 if (p
->type
& CUPS_PRINTER_CLASS
)
5048 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
5050 cupsFilePuts(fp
, "#!/bin/sh\n");
5052 if ((attr
= ippFindAttribute(p
->attrs
, "printer-make-and-model",
5053 IPP_TAG_TEXT
)) != NULL
)
5054 cupsFilePrintf(fp
, "NAME=\"%s\"\n", attr
->values
[0].string
.text
);
5055 else if (p
->type
& CUPS_PRINTER_CLASS
)
5056 cupsFilePuts(fp
, "NAME=\"Printer Class\"\n");
5058 cupsFilePuts(fp
, "NAME=\"Remote Destination\"\n");
5060 if (p
->type
& CUPS_PRINTER_COLOR
)
5061 cupsFilePuts(fp
, "TYPE=ColorPostScript\n");
5063 cupsFilePuts(fp
, "TYPE=MonoPostScript\n");
5065 cupsFilePrintf(fp
, "HOSTNAME=%s\n", ServerName
);
5066 cupsFilePrintf(fp
, "HOSTPRINTER=%s\n", p
->name
);
5070 chmod(filename
, 0755);
5071 chown(filename
, User
, Group
);
5075 * Then the member file that tells which device file the queue is connected
5076 * to... Networked printers use "/dev/null" in this file, so that's what
5077 * we use (the actual device URI can confuse some apps...)
5080 snprintf(filename
, sizeof(filename
), "/var/spool/lp/member/%s", p
->name
);
5082 if (p
->type
& CUPS_PRINTER_CLASS
)
5084 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
5086 cupsFilePuts(fp
, "/dev/null\n");
5090 chmod(filename
, 0644);
5091 chown(filename
, User
, Group
);
5095 * The gui_interface file is a script or program that launches a GUI
5096 * option panel for the printer, using options specified on the
5097 * command-line in the third argument. The option panel must send
5098 * any printing options to stdout on a single line when the user
5099 * accepts them, or nothing if the user cancels the dialog.
5101 * The default options panel program is /usr/bin/glpoptions, from
5102 * the ESP Print Pro software. You can select another using the
5103 * PrintcapGUI option.
5106 snprintf(filename
, sizeof(filename
), "/var/spool/lp/gui_interface/ELF/%s.gui", p
->name
);
5108 if (p
->type
& CUPS_PRINTER_CLASS
)
5110 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
5112 cupsFilePuts(fp
, "#!/bin/sh\n");
5113 cupsFilePrintf(fp
, "%s -d %s -o \"$3\"\n", PrintcapGUI
, p
->name
);
5117 chmod(filename
, 0755);
5118 chown(filename
, User
, Group
);
5122 * The POD config file is needed by the printstatus command to show
5123 * the printer location and device.
5126 snprintf(filename
, sizeof(filename
), "/var/spool/lp/pod/%s.config", p
->name
);
5128 if (p
->type
& CUPS_PRINTER_CLASS
)
5130 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
5132 cupsFilePrintf(fp
, "Printer Class | %s\n",
5133 (p
->type
& CUPS_PRINTER_COLOR
) ? "ColorPostScript" : "MonoPostScript");
5134 cupsFilePrintf(fp
, "Printer Model | %s\n", p
->make_model
? p
->make_model
: "");
5135 cupsFilePrintf(fp
, "Location Code | %s\n", p
->location
? p
->location
: "");
5136 cupsFilePrintf(fp
, "Physical Location | %s\n", p
->info
? p
->info
: "");
5137 cupsFilePrintf(fp
, "Port Path | %s\n", p
->device_uri
);
5138 cupsFilePrintf(fp
, "Config Path | /var/spool/lp/pod/%s.config\n", p
->name
);
5139 cupsFilePrintf(fp
, "Active Status Path | /var/spool/lp/pod/%s.status\n", p
->name
);
5140 cupsFilePuts(fp
, "Status Update Wait | 10 seconds\n");
5144 chmod(filename
, 0664);
5145 chown(filename
, User
, Group
);
5151 * 'write_irix_state()' - Update the status files used by IRIX printing
5156 write_irix_state(cupsd_printer_t
*p
) /* I - Printer to update */
5158 char filename
[1024]; /* Interface script filename */
5159 cups_file_t
*fp
; /* Interface script file */
5160 int tag
; /* Status tag value */
5166 * The POD status file is needed for the printstatus window to
5167 * provide the current status of the printer.
5170 snprintf(filename
, sizeof(filename
), "/var/spool/lp/pod/%s.status", p
->name
);
5172 if (p
->type
& CUPS_PRINTER_CLASS
)
5174 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
5176 cupsFilePrintf(fp
, "Operational Status | %s\n",
5177 (p
->state
== IPP_PRINTER_IDLE
) ? "Idle" :
5178 (p
->state
== IPP_PRINTER_PROCESSING
) ? "Busy" :
5180 cupsFilePrintf(fp
, "Information | 01 00 00 | %s\n", CUPS_SVERSION
);
5181 cupsFilePrintf(fp
, "Information | 02 00 00 | Device URI: %s\n",
5183 cupsFilePrintf(fp
, "Information | 03 00 00 | %s jobs\n",
5184 p
->accepting
? "Accepting" : "Not accepting");
5185 cupsFilePrintf(fp
, "Information | 04 00 00 | %s\n", p
->state_message
);
5189 chmod(filename
, 0664);
5190 chown(filename
, User
, Group
);
5194 * The activeicons file is needed to provide desktop icons for printers:
5196 * [ quoted from /usr/lib/print/tagit ]
5198 * --- Type of printer tags (base values)
5200 * Dumb=66048 # 0x10200
5201 * DumbColor=66080 # 0x10220
5202 * Raster=66112 # 0x10240
5203 * ColorRaster=66144 # 0x10260
5204 * Plotter=66176 # 0x10280
5205 * PostScript=66208 # 0x102A0
5206 * ColorPostScript=66240 # 0x102C0
5207 * MonoPostScript=66272 # 0x102E0
5209 * --- Printer state modifiers for local printers
5214 * Unknown=3 # 0x3 (Faulted due to unknown reason)
5216 * --- Printer state modifiers for network printers
5220 * NetFaulted=10 # 0xA
5221 * NetUnknown=11 # 0xB (Faulted due to unknown reason)
5224 snprintf(filename
, sizeof(filename
), "/var/spool/lp/activeicons/%s", p
->name
);
5226 if (p
->type
& CUPS_PRINTER_CLASS
)
5228 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
5230 if (p
->type
& CUPS_PRINTER_COLOR
)
5235 if (p
->type
& CUPS_PRINTER_REMOTE
)
5238 if (p
->state
== IPP_PRINTER_PROCESSING
)
5241 else if (p
->state
== IPP_PRINTER_STOPPED
)
5244 cupsFilePuts(fp
, "#!/bin/sh\n");
5245 cupsFilePrintf(fp
, "#Tag %d\n", tag
);
5249 chmod(filename
, 0755);
5250 chown(filename
, User
, Group
);
5255 * The default file is needed by the printers window to show
5256 * the default printer.
5259 snprintf(filename
, sizeof(filename
), "/var/spool/lp/default");
5261 if (DefaultPrinter
!= NULL
)
5263 if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
5265 cupsFilePrintf(fp
, "%s\n", DefaultPrinter
->name
);
5269 chmod(filename
, 0644);
5270 chown(filename
, User
, Group
);
5280 * 'write_xml_string()' - Write a string with XML escaping.
5284 write_xml_string(cups_file_t
*fp
, /* I - File to write to */
5285 const char *s
) /* I - String to write */
5287 const char *start
; /* Start of current sequence */
5293 for (start
= s
; *s
; s
++)
5298 cupsFileWrite(fp
, start
, s
- start
);
5300 cupsFilePuts(fp
, "&");
5306 cupsFileWrite(fp
, start
, s
- start
);
5308 cupsFilePuts(fp
, "<");
5314 cupsFilePuts(fp
, start
);
5319 * End of "$Id: printers.c 7968 2008-09-19 23:03:01Z mike $".