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-2008 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 * cupsdFindPrinter() - Find a printer in the list.
24 * cupsdFreePrinterUsers() - Free allow/deny users.
25 * cupsdLoadAllPrinters() - Load printers from the printers.conf file.
26 * cupsdRenamePrinter() - Rename a printer.
27 * cupsdSaveAllPrinters() - Save all printer definitions to the
29 * cupsdSetAuthInfoRequired() - Set the required authentication info.
30 * cupsdSetDeviceURI() - Set the device URI for a printer.
31 * cupsdSetPrinterAttr() - Set a printer attribute.
32 * cupsdSetPrinterAttrs() - Set printer attributes based upon the PPD
34 * cupsdSetPrinterReasons() - Set/update the reasons strings.
35 * cupsdSetPrinterState() - Update the current state of a printer.
36 * cupsdStopPrinter() - Stop a printer from printing any jobs...
37 * cupsdUpdatePrinters() - Update printers after a partial reload.
38 * cupsdValidateDest() - Validate a printer/class destination.
39 * cupsdWritePrintcap() - Write a pseudo-printcap file for older
40 * applications that need it...
41 * add_printer_defaults() - Add name-default attributes to the printer
43 * add_printer_filter() - Add a MIME filter for a printer.
44 * add_printer_formats() - Add document-format-supported values for
46 * compare_printers() - Compare two printers.
47 * delete_printer_filters() - Delete all MIME filters for a printer.
48 * write_irix_config() - Update the config files used by the IRIX
50 * write_irix_state() - Update the status files used by IRIX
51 * printing desktop tools.
52 * write_xml_string() - Write a string with XML escaping.
56 * Include necessary headers...
67 static void add_printer_defaults(cupsd_printer_t
*p
);
68 static void add_printer_filter(cupsd_printer_t
*p
, mime_type_t
*type
,
70 static void add_printer_formats(cupsd_printer_t
*p
);
71 static void add_string_array(cups_array_t
**a
, const char *s
);
72 static int compare_printers(void *first
, void *second
, void *data
);
73 static void delete_printer_filters(cupsd_printer_t
*p
);
74 static void delete_string_array(cups_array_t
**a
);
75 static void load_ppd(cupsd_printer_t
*p
);
77 static void write_irix_config(cupsd_printer_t
*p
);
78 static void write_irix_state(cupsd_printer_t
*p
);
80 static void write_xml_string(cups_file_t
*fp
, const char *s
);
84 * 'cupsdAddPrinter()' - Add a printer to the system.
87 cupsd_printer_t
* /* O - New printer */
88 cupsdAddPrinter(const char *name
) /* I - Name of printer */
90 cupsd_printer_t
*p
; /* New printer */
94 * Range check input...
97 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdAddPrinter(\"%s\")", name
);
100 * Create a new printer entity...
103 if ((p
= calloc(1, sizeof(cupsd_printer_t
))) == NULL
)
105 cupsdLogMessage(CUPSD_LOG_CRIT
, "Unable to allocate memory for printer - %s",
110 cupsdSetString(&p
->name
, name
);
111 cupsdSetString(&p
->info
, name
);
112 cupsdSetString(&p
->hostname
, ServerName
);
114 cupsdSetStringf(&p
->uri
, "ipp://%s:%d/printers/%s", ServerName
, LocalPort
, name
);
115 cupsdSetDeviceURI(p
, "file:/dev/null");
117 p
->state
= IPP_PRINTER_STOPPED
;
118 p
->state_time
= time(NULL
);
120 p
->shared
= DefaultShared
;
121 p
->filetype
= mimeAddType(MimeDatabase
, "printer", name
);
123 cupsdSetString(&p
->job_sheets
[0], "none");
124 cupsdSetString(&p
->job_sheets
[1], "none");
126 cupsdSetString(&p
->error_policy
, ErrorPolicy
);
127 cupsdSetString(&p
->op_policy
, DefaultPolicy
);
129 p
->op_policy_ptr
= DefaultPolicyPtr
;
131 if (MaxPrinterHistory
)
132 p
->history
= calloc(MaxPrinterHistory
, sizeof(ipp_t
*));
135 * Insert the printer in the printer list alphabetically...
139 Printers
= cupsArrayNew(compare_printers
, NULL
);
141 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
142 "cupsdAddPrinter: Adding %s to Printers", p
->name
);
143 cupsArrayAdd(Printers
, p
);
145 if (!ImplicitPrinters
)
146 ImplicitPrinters
= cupsArrayNew(compare_printers
, NULL
);
149 * Return the new printer...
157 * 'cupsdAddPrinterHistory()' - Add the current printer state to the history.
161 cupsdAddPrinterHistory(
162 cupsd_printer_t
*p
) /* I - Printer */
164 ipp_t
*history
; /* History collection */
168 * Stop early if we aren't keeping history data...
171 if (MaxPrinterHistory
<= 0)
175 * Retire old history data as needed...
178 p
->sequence_number
++;
180 if (p
->num_history
>= MaxPrinterHistory
)
183 ippDelete(p
->history
[0]);
184 memmove(p
->history
, p
->history
+ 1, p
->num_history
* sizeof(ipp_t
*));
188 * Create a collection containing the current printer-state, printer-up-time,
189 * printer-state-message, and printer-state-reasons attributes.
193 ippAddInteger(history
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-state",
195 ippAddBoolean(history
, IPP_TAG_PRINTER
, "printer-is-accepting-jobs",
197 ippAddBoolean(history
, IPP_TAG_PRINTER
, "printer-is-shared", p
->shared
);
198 ippAddString(history
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-state-message",
199 NULL
, p
->state_message
);
202 ippAddString(history
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
203 "com.apple.print.recoverable-message", NULL
, p
->recoverable
);
204 #endif /* __APPLE__ */
205 if (p
->num_reasons
== 0)
206 ippAddString(history
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
207 "printer-state-reasons", NULL
,
208 p
->state
== IPP_PRINTER_STOPPED
? "paused" : "none");
210 ippAddStrings(history
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
211 "printer-state-reasons", p
->num_reasons
, NULL
,
212 (const char * const *)p
->reasons
);
213 ippAddInteger(history
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
214 "printer-state-change-time", p
->state_time
);
215 ippAddInteger(history
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
216 "printer-state-sequence-number", p
->sequence_number
);
218 p
->history
[p
->num_history
] = history
;
224 * 'cupsdAddPrinterUser()' - Add a user to the ACL.
229 cupsd_printer_t
*p
, /* I - Printer */
230 const char *username
) /* I - User */
232 const char **temp
; /* Temporary array pointer */
238 if (p
->num_users
== 0)
239 temp
= malloc(sizeof(char **));
241 temp
= realloc(p
->users
, sizeof(char **) * (p
->num_users
+ 1));
247 temp
+= p
->num_users
;
249 if ((*temp
= strdup(username
)) != NULL
)
255 * 'cupsdCreateCommonData()' - Create the common printer data.
259 cupsdCreateCommonData(void)
261 int i
; /* Looping var */
262 ipp_attribute_t
*attr
; /* Attribute data */
263 cups_dir_t
*dir
; /* Notifier directory */
264 cups_dentry_t
*dent
; /* Notifier directory entry */
265 cups_array_t
*notifiers
; /* Notifier array */
266 char filename
[1024], /* Filename */
267 *notifier
; /* Current notifier */
268 cupsd_policy_t
*p
; /* Current policy */
269 static const int nups
[] = /* number-up-supported values */
270 { 1, 2, 4, 6, 9, 16 };
271 static const int orients
[4] =/* orientation-requested-supported values */
275 IPP_REVERSE_LANDSCAPE
,
278 static const char * const holds
[] = /* job-hold-until-supported values */
289 static const char * const versions
[] =/* ipp-versions-supported values */
294 static const int ops
[] = /* operations-supported values */
301 IPP_GET_JOB_ATTRIBUTES
,
303 IPP_GET_PRINTER_ATTRIBUTES
,
309 IPP_SET_JOB_ATTRIBUTES
,
310 IPP_CREATE_PRINTER_SUBSCRIPTION
,
311 IPP_CREATE_JOB_SUBSCRIPTION
,
312 IPP_GET_SUBSCRIPTION_ATTRIBUTES
,
313 IPP_GET_SUBSCRIPTIONS
,
314 IPP_RENEW_SUBSCRIPTION
,
315 IPP_CANCEL_SUBSCRIPTION
,
316 IPP_GET_NOTIFICATIONS
,
320 IPP_RELEASE_HELD_NEW_JOBS
,
334 CUPS_AUTHENTICATE_JOB
,
339 static const char * const charsets
[] =/* charset-supported values */
344 static const char * const compressions
[] =
345 { /* document-compression-supported values */
349 #endif /* HAVE_LIBZ */
351 static const char * const multiple_document_handling
[] =
352 { /* multiple-document-handling-supported values */
353 "separate-documents-uncollated-copies",
354 "separate-documents-collated-copies"
356 static const char * const errors
[] = /* printer-error-policy-supported values */
363 static const char * const notify_attrs
[] =
364 { /* notify-attributes-supported values */
365 "printer-state-change-time",
366 "notify-lease-expiration-time",
367 "notify-subscriber-user-name"
369 static const char * const notify_events
[] =
370 { /* notify-events-supported values */
372 "job-config-changed",
379 "printer-config-changed",
381 "printer-finishings-changed",
382 "printer-media-changed",
386 "printer-state-changed",
393 static const char * const job_settable
[] =
394 { /* job-settable-attributes-supported */
400 "multiple-document-handling",
402 "orientation-requested",
405 "printer-resolution",
411 ippDelete(CommonData
);
413 CommonData
= ippNew();
416 * This list of attributes is sorted to improve performance when the
417 * client provides a requested-attributes attribute...
420 /* charset-configured */
421 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_CHARSET
| IPP_TAG_COPY
,
422 "charset-configured", NULL
, DefaultCharset
);
424 /* charset-supported */
425 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_CHARSET
| IPP_TAG_COPY
,
426 "charset-supported", sizeof(charsets
) / sizeof(charsets
[0]),
429 /* compression-supported */
430 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
431 "compression-supported",
432 sizeof(compressions
) / sizeof(compressions
[0]),
435 /* copies-supported */
436 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "copies-supported", 1, MaxCopies
);
439 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
| IPP_TAG_COPY
,
440 "cups-version", NULL
, CUPS_SVERSION
+ 6);
442 /* generated-natural-language-supported */
443 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_LANGUAGE
| IPP_TAG_COPY
,
444 "generated-natural-language-supported", NULL
, DefaultLanguage
);
446 /* ipp-versions-supported */
447 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
448 "ipp-versions-supported", sizeof(versions
) / sizeof(versions
[0]),
451 /* job-hold-until-supported */
452 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
453 "job-hold-until-supported", sizeof(holds
) / sizeof(holds
[0]),
456 /* job-priority-supported */
457 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
458 "job-priority-supported", 100);
460 /* job-settable-attributes-supported */
461 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
462 "job-settable-attributes-supported",
463 sizeof(job_settable
) / sizeof(job_settable
[0]),
466 /* job-sheets-supported */
467 if (cupsArrayCount(Banners
) > 0)
470 * Setup the job-sheets-supported attribute...
473 if (Classification
&& !ClassifyOverride
)
474 attr
= ippAddString(CommonData
, IPP_TAG_PRINTER
,
475 IPP_TAG_NAME
| IPP_TAG_COPY
,
476 "job-sheets-supported", NULL
, Classification
);
478 attr
= ippAddStrings(CommonData
, IPP_TAG_PRINTER
,
479 IPP_TAG_NAME
| IPP_TAG_COPY
,
480 "job-sheets-supported", cupsArrayCount(Banners
) + 1,
484 cupsdLogMessage(CUPSD_LOG_EMERG
,
485 "Unable to allocate memory for "
486 "job-sheets-supported attribute: %s!", strerror(errno
));
487 else if (!Classification
|| ClassifyOverride
)
489 cupsd_banner_t
*banner
; /* Current banner */
492 attr
->values
[0].string
.text
= _cupsStrAlloc("none");
494 for (i
= 1, banner
= (cupsd_banner_t
*)cupsArrayFirst(Banners
);
496 i
++, banner
= (cupsd_banner_t
*)cupsArrayNext(Banners
))
497 attr
->values
[i
].string
.text
= banner
->name
;
501 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
502 "job-sheets-supported", NULL
, "none");
504 /* multiple-document-handling-supported */
505 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
506 "multiple-document-handling-supported",
507 sizeof(multiple_document_handling
) /
508 sizeof(multiple_document_handling
[0]), NULL
,
509 multiple_document_handling
);
511 /* multiple-document-jobs-supported */
512 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
,
513 "multiple-document-jobs-supported", 1);
515 /* multiple-operation-time-out */
516 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
517 "multiple-operation-time-out", 60);
519 /* natural-language-configured */
520 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_LANGUAGE
| IPP_TAG_COPY
,
521 "natural-language-configured", NULL
, DefaultLanguage
);
523 /* notify-attributes-supported */
524 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
525 "notify-attributes-supported",
526 (int)(sizeof(notify_attrs
) / sizeof(notify_attrs
[0])),
529 /* notify-lease-duration-supported */
530 ippAddRange(CommonData
, IPP_TAG_PRINTER
,
531 "notify-lease-duration-supported", 0,
532 MaxLeaseDuration
? MaxLeaseDuration
: 2147483647);
534 /* notify-max-events-supported */
535 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
536 "notify-max-events-supported", MaxEvents
);
538 /* notify-events-supported */
539 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
540 "notify-events-supported",
541 (int)(sizeof(notify_events
) / sizeof(notify_events
[0])),
542 NULL
, notify_events
);
544 /* notify-pull-method-supported */
545 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
546 "notify-pull-method-supported", NULL
, "ippget");
548 /* notify-schemes-supported */
549 snprintf(filename
, sizeof(filename
), "%s/notifier", ServerBin
);
550 if ((dir
= cupsDirOpen(filename
)) != NULL
)
552 notifiers
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
554 while ((dent
= cupsDirRead(dir
)) != NULL
)
555 if (S_ISREG(dent
->fileinfo
.st_mode
) &&
556 (dent
->fileinfo
.st_mode
& S_IXOTH
) != 0)
557 cupsArrayAdd(notifiers
, _cupsStrAlloc(dent
->filename
));
559 if (cupsArrayCount(notifiers
) > 0)
561 attr
= ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
562 "notify-schemes-supported",
563 cupsArrayCount(notifiers
), NULL
, NULL
);
565 for (i
= 0, notifier
= (char *)cupsArrayFirst(notifiers
);
567 i
++, notifier
= (char *)cupsArrayNext(notifiers
))
568 attr
->values
[i
].string
.text
= notifier
;
571 cupsArrayDelete(notifiers
);
575 /* number-up-supported */
576 ippAddIntegers(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
577 "number-up-supported", sizeof(nups
) / sizeof(nups
[0]), nups
);
579 /* operations-supported */
580 ippAddIntegers(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
581 "operations-supported",
582 sizeof(ops
) / sizeof(ops
[0]) + JobFiles
- 1, ops
);
584 /* orientation-requested-supported */
585 ippAddIntegers(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
586 "orientation-requested-supported", 4, orients
);
588 /* page-ranges-supported */
589 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
, "page-ranges-supported", 1);
591 /* pdf-override-supported */
592 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
593 "pdl-override-supported", NULL
, "not-attempted");
595 /* printer-error-policy-supported */
596 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
597 "printer-error-policy-supported",
598 sizeof(errors
) / sizeof(errors
[0]), NULL
, errors
);
600 /* printer-op-policy-supported */
601 attr
= ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
602 "printer-op-policy-supported", cupsArrayCount(Policies
),
604 for (i
= 0, p
= (cupsd_policy_t
*)cupsArrayFirst(Policies
);
606 i
++, p
= (cupsd_policy_t
*)cupsArrayNext(Policies
))
607 attr
->values
[i
].string
.text
= p
->name
;
609 /* server-is-sharing-printers */
610 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
, "server-is-sharing-printers",
611 BrowseLocalProtocols
!= 0 && Browsing
);
616 * 'cupsdDeleteAllPrinters()' - Delete all printers from the system.
620 cupsdDeleteAllPrinters(void)
622 cupsd_printer_t
*p
; /* Pointer to current printer/class */
625 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
627 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
628 cupsdDeletePrinter(p
, 0);
633 * 'cupsdDeletePrinter()' - Delete a printer from the system.
638 cupsd_printer_t
*p
, /* I - Printer to delete */
639 int update
) /* I - Update printers.conf? */
641 int i
; /* Looping var */
643 char filename
[1024]; /* Interface script filename */
647 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdDeletePrinter(p=%p(%s), update=%d)",
651 * Save the current position in the Printers array...
654 cupsArraySave(Printers
);
657 * Stop printing on this printer...
660 cupsdStopPrinter(p
, update
);
663 * If this printer is the next for browsing, point to the next one...
668 cupsArrayFind(Printers
, p
);
669 BrowseNext
= (cupsd_printer_t
*)cupsArrayNext(Printers
);
673 * Remove the printer from the list...
676 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
677 "cupsdDeletePrinter: Removing %s from Printers", p
->name
);
678 cupsArrayRemove(Printers
, p
);
680 if (p
->type
& CUPS_PRINTER_IMPLICIT
)
682 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
683 "cupsdDeletePrinter: Removing %s from ImplicitPrinters",
685 cupsArrayRemove(ImplicitPrinters
, p
);
689 * Remove the dummy interface/icon/option files under IRIX...
693 snprintf(filename
, sizeof(filename
), "/var/spool/lp/interface/%s", p
->name
);
696 snprintf(filename
, sizeof(filename
), "/var/spool/lp/gui_interface/ELF/%s.gui",
700 snprintf(filename
, sizeof(filename
), "/var/spool/lp/activeicons/%s", p
->name
);
703 snprintf(filename
, sizeof(filename
), "/var/spool/lp/pod/%s.config", p
->name
);
706 snprintf(filename
, sizeof(filename
), "/var/spool/lp/pod/%s.status", p
->name
);
709 snprintf(filename
, sizeof(filename
), "/var/spool/lp/member/%s", p
->name
);
714 * If p is the default printer, assign a different one...
717 if (p
== DefaultPrinter
)
719 DefaultPrinter
= NULL
;
721 if (UseNetworkDefault
)
724 * Find the first network default printer and use it...
727 cupsd_printer_t
*dp
; /* New default printer */
730 for (dp
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
732 dp
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
733 if (dp
!= p
&& (dp
->type
& CUPS_PRINTER_DEFAULT
))
742 * Remove this printer from any classes...
745 if (!(p
->type
& CUPS_PRINTER_IMPLICIT
))
747 cupsdDeletePrinterFromClasses(p
);
750 * Deregister from any browse protocols...
753 cupsdDeregisterPrinter(p
, 1);
757 * Free all memory used by the printer...
760 if (p
->printers
!= NULL
)
763 if (MaxPrinterHistory
)
765 for (i
= 0; i
< p
->num_history
; i
++)
766 ippDelete(p
->history
[i
]);
771 for (i
= 0; i
< p
->num_reasons
; i
++)
772 _cupsStrFree(p
->reasons
[i
]);
775 ippDelete(p
->ppd_attrs
);
777 delete_printer_filters(p
);
779 mimeDeleteType(MimeDatabase
, p
->filetype
);
780 mimeDeleteType(MimeDatabase
, p
->prefiltertype
);
782 delete_string_array(&(p
->filters
));
783 delete_string_array(&(p
->pre_filters
));
785 cupsdFreePrinterUsers(p
);
788 cupsdClearString(&p
->uri
);
789 cupsdClearString(&p
->hostname
);
790 cupsdClearString(&p
->name
);
791 cupsdClearString(&p
->location
);
792 cupsdClearString(&p
->make_model
);
793 cupsdClearString(&p
->info
);
794 cupsdClearString(&p
->job_sheets
[0]);
795 cupsdClearString(&p
->job_sheets
[1]);
796 cupsdClearString(&p
->device_uri
);
797 cupsdClearString(&p
->sanitized_device_uri
);
798 cupsdClearString(&p
->port_monitor
);
799 cupsdClearString(&p
->op_policy
);
800 cupsdClearString(&p
->error_policy
);
802 cupsdClearString(&p
->alert
);
803 cupsdClearString(&p
->alert_description
);
806 cupsdClearString(&p
->product
);
807 cupsdClearString(&p
->pdl
);
808 #endif /* HAVE_DNSSD */
810 cupsArrayDelete(p
->filetypes
);
813 free(p
->browse_attrs
);
816 cupsdClearString(&p
->recoverable
);
817 #endif /* __APPLE__ */
819 cupsFreeOptions(p
->num_options
, p
->options
);
824 * Restore the previous position in the Printers array...
827 cupsArrayRestore(Printers
);
832 * 'cupsdFindDest()' - Find a destination in the list.
835 cupsd_printer_t
* /* O - Destination in list */
836 cupsdFindDest(const char *name
) /* I - Name of printer or class to find */
838 cupsd_printer_t key
; /* Search key */
841 key
.name
= (char *)name
;
842 return ((cupsd_printer_t
*)cupsArrayFind(Printers
, &key
));
847 * 'cupsdFindPrinter()' - Find a printer in the list.
850 cupsd_printer_t
* /* O - Printer in list */
851 cupsdFindPrinter(const char *name
) /* I - Name of printer to find */
853 cupsd_printer_t
*p
; /* Printer in list */
856 if ((p
= cupsdFindDest(name
)) != NULL
&& (p
->type
& CUPS_PRINTER_CLASS
))
864 * 'cupsdFreePrinterUsers()' - Free allow/deny users.
868 cupsdFreePrinterUsers(
869 cupsd_printer_t
*p
) /* I - Printer */
871 int i
; /* Looping var */
874 if (!p
|| !p
->num_users
)
877 for (i
= 0; i
< p
->num_users
; i
++)
878 free((void *)p
->users
[i
]);
888 * 'cupsdLoadAllPrinters()' - Load printers from the printers.conf file.
892 cupsdLoadAllPrinters(void)
894 cups_file_t
*fp
; /* printers.conf file */
895 int linenum
; /* Current line number */
896 char line
[1024], /* Line from file */
897 *value
, /* Pointer to value */
898 *valueptr
; /* Pointer into value */
899 cupsd_printer_t
*p
; /* Current printer */
903 * Open the printers.conf file...
906 snprintf(line
, sizeof(line
), "%s/printers.conf", ServerRoot
);
907 if ((fp
= cupsFileOpen(line
, "r")) == NULL
)
910 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to open %s - %s", line
,
916 * Read printer configurations until we hit EOF...
922 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
925 * Decode the directive...
928 if (!strcasecmp(line
, "<Printer") ||
929 !strcasecmp(line
, "<DefaultPrinter"))
932 * <Printer name> or <DefaultPrinter name>
935 if (p
== NULL
&& value
)
938 * Add the printer and a base file type...
941 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Loading printer %s...", value
);
943 p
= cupsdAddPrinter(value
);
945 p
->state
= IPP_PRINTER_IDLE
;
948 * Set the default printer as needed...
951 if (!strcasecmp(line
, "<DefaultPrinter"))
955 cupsdLogMessage(CUPSD_LOG_ERROR
,
956 "Syntax error on line %d of printers.conf.", linenum
);
958 else if (!strcasecmp(line
, "</Printer>"))
963 * Close out the current printer...
966 cupsdSetPrinterAttrs(p
);
967 cupsdAddPrinterHistory(p
);
969 if (strncmp(p
->device_uri
, "file:", 5) &&
970 p
->state
!= IPP_PRINTER_STOPPED
)
973 * See if the backend exists...
976 snprintf(line
, sizeof(line
), "%s/backend/%s", ServerBin
,
979 if ((valueptr
= strchr(line
+ strlen(ServerBin
), ':')) != NULL
)
980 *valueptr
= '\0'; /* Chop everything but URI scheme */
985 * Backend does not exist, stop printer...
988 p
->state
= IPP_PRINTER_STOPPED
;
989 snprintf(p
->state_message
, sizeof(p
->state_message
),
990 "Backend %s does not exist!", line
);
997 cupsdLogMessage(CUPSD_LOG_ERROR
,
998 "Syntax error on line %d of printers.conf.", linenum
);
1002 cupsdLogMessage(CUPSD_LOG_ERROR
,
1003 "Syntax error on line %d of printers.conf.", linenum
);
1005 else if (!strcasecmp(line
, "AuthInfoRequired"))
1007 if (!cupsdSetAuthInfoRequired(p
, value
, NULL
))
1008 cupsdLogMessage(CUPSD_LOG_ERROR
,
1009 "Bad AuthInfoRequired on line %d of printers.conf.",
1012 else if (!strcasecmp(line
, "Info"))
1015 cupsdSetString(&p
->info
, value
);
1017 else if (!strcasecmp(line
, "MakeModel"))
1020 cupsdSetString(&p
->make_model
, value
);
1022 else if (!strcasecmp(line
, "Location"))
1025 cupsdSetString(&p
->location
, value
);
1027 else if (!strcasecmp(line
, "DeviceURI"))
1030 cupsdSetDeviceURI(p
, value
);
1032 cupsdLogMessage(CUPSD_LOG_ERROR
,
1033 "Syntax error on line %d of printers.conf.", linenum
);
1035 else if (!strcasecmp(line
, "Option") && value
)
1041 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1044 cupsdLogMessage(CUPSD_LOG_ERROR
,
1045 "Syntax error on line %d of printers.conf.", linenum
);
1048 for (; *valueptr
&& isspace(*valueptr
& 255); *valueptr
++ = '\0');
1050 p
->num_options
= cupsAddOption(value
, valueptr
, p
->num_options
,
1054 else if (!strcasecmp(line
, "PortMonitor"))
1056 if (value
&& strcmp(value
, "none"))
1057 cupsdSetString(&p
->port_monitor
, value
);
1059 cupsdClearString(&p
->port_monitor
);
1061 cupsdLogMessage(CUPSD_LOG_ERROR
,
1062 "Syntax error on line %d of printers.conf.", linenum
);
1064 else if (!strcasecmp(line
, "Reason"))
1067 p
->num_reasons
< (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
1069 p
->reasons
[p
->num_reasons
] = _cupsStrAlloc(value
);
1073 cupsdLogMessage(CUPSD_LOG_ERROR
,
1074 "Syntax error on line %d of printers.conf.", linenum
);
1076 else if (!strcasecmp(line
, "State"))
1079 * Set the initial queue state...
1082 if (value
&& !strcasecmp(value
, "idle"))
1083 p
->state
= IPP_PRINTER_IDLE
;
1084 else if (value
&& !strcasecmp(value
, "stopped"))
1085 p
->state
= IPP_PRINTER_STOPPED
;
1087 cupsdLogMessage(CUPSD_LOG_ERROR
,
1088 "Syntax error on line %d of printers.conf.", linenum
);
1090 else if (!strcasecmp(line
, "StateMessage"))
1093 * Set the initial queue state message...
1097 strlcpy(p
->state_message
, value
, sizeof(p
->state_message
));
1099 else if (!strcasecmp(line
, "StateTime"))
1102 * Set the state time...
1106 p
->state_time
= atoi(value
);
1108 else if (!strcasecmp(line
, "Accepting"))
1111 * Set the initial accepting state...
1115 (!strcasecmp(value
, "yes") ||
1116 !strcasecmp(value
, "on") ||
1117 !strcasecmp(value
, "true")))
1120 (!strcasecmp(value
, "no") ||
1121 !strcasecmp(value
, "off") ||
1122 !strcasecmp(value
, "false")))
1125 cupsdLogMessage(CUPSD_LOG_ERROR
,
1126 "Syntax error on line %d of printers.conf.", linenum
);
1128 else if (!strcasecmp(line
, "Type"))
1131 p
->type
= atoi(value
);
1133 cupsdLogMessage(CUPSD_LOG_ERROR
,
1134 "Syntax error on line %d of printers.conf.", linenum
);
1136 else if (!strcasecmp(line
, "Product"))
1141 p
->product
= _cupsStrAlloc(value
);
1142 #endif /* HAVE_DNSSD */
1145 cupsdLogMessage(CUPSD_LOG_ERROR
,
1146 "Syntax error on line %d of printers.conf.", linenum
);
1148 else if (!strcasecmp(line
, "Filter"))
1153 p
->filters
= cupsArrayNew(NULL
, NULL
);
1155 cupsArrayAdd(p
->filters
, _cupsStrAlloc(value
));
1158 cupsdLogMessage(CUPSD_LOG_ERROR
,
1159 "Syntax error on line %d of printers.conf.", linenum
);
1161 else if (!strcasecmp(line
, "PreFilter"))
1165 if (!p
->pre_filters
)
1166 p
->pre_filters
= cupsArrayNew(NULL
, NULL
);
1168 cupsArrayAdd(p
->pre_filters
, _cupsStrAlloc(value
));
1171 cupsdLogMessage(CUPSD_LOG_ERROR
,
1172 "Syntax error on line %d of printers.conf.", linenum
);
1174 else if (!strcasecmp(line
, "Shared"))
1177 * Set the initial shared state...
1181 (!strcasecmp(value
, "yes") ||
1182 !strcasecmp(value
, "on") ||
1183 !strcasecmp(value
, "true")))
1186 (!strcasecmp(value
, "no") ||
1187 !strcasecmp(value
, "off") ||
1188 !strcasecmp(value
, "false")))
1191 cupsdLogMessage(CUPSD_LOG_ERROR
,
1192 "Syntax error on line %d of printers.conf.", linenum
);
1194 else if (!strcasecmp(line
, "JobSheets"))
1197 * Set the initial job sheets...
1202 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1207 cupsdSetString(&p
->job_sheets
[0], value
);
1209 while (isspace(*valueptr
& 255))
1214 for (value
= valueptr
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1219 cupsdSetString(&p
->job_sheets
[1], value
);
1223 cupsdLogMessage(CUPSD_LOG_ERROR
,
1224 "Syntax error on line %d of printers.conf.", linenum
);
1226 else if (!strcasecmp(line
, "AllowUser"))
1231 cupsdAddPrinterUser(p
, value
);
1234 cupsdLogMessage(CUPSD_LOG_ERROR
,
1235 "Syntax error on line %d of printers.conf.", linenum
);
1237 else if (!strcasecmp(line
, "DenyUser"))
1242 cupsdAddPrinterUser(p
, value
);
1245 cupsdLogMessage(CUPSD_LOG_ERROR
,
1246 "Syntax error on line %d of printers.conf.", linenum
);
1248 else if (!strcasecmp(line
, "QuotaPeriod"))
1251 p
->quota_period
= atoi(value
);
1253 cupsdLogMessage(CUPSD_LOG_ERROR
,
1254 "Syntax error on line %d of printers.conf.", linenum
);
1256 else if (!strcasecmp(line
, "PageLimit"))
1259 p
->page_limit
= atoi(value
);
1261 cupsdLogMessage(CUPSD_LOG_ERROR
,
1262 "Syntax error on line %d of printers.conf.", linenum
);
1264 else if (!strcasecmp(line
, "KLimit"))
1267 p
->k_limit
= atoi(value
);
1269 cupsdLogMessage(CUPSD_LOG_ERROR
,
1270 "Syntax error on line %d of printers.conf.", linenum
);
1272 else if (!strcasecmp(line
, "OpPolicy"))
1276 cupsd_policy_t
*pol
; /* Policy */
1279 if ((pol
= cupsdFindPolicy(value
)) != NULL
)
1281 cupsdSetString(&p
->op_policy
, value
);
1282 p
->op_policy_ptr
= pol
;
1285 cupsdLogMessage(CUPSD_LOG_ERROR
,
1286 "Bad policy \"%s\" on line %d of printers.conf",
1290 cupsdLogMessage(CUPSD_LOG_ERROR
,
1291 "Syntax error on line %d of printers.conf.", linenum
);
1293 else if (!strcasecmp(line
, "ErrorPolicy"))
1296 cupsdSetString(&p
->error_policy
, value
);
1298 cupsdLogMessage(CUPSD_LOG_ERROR
,
1299 "Syntax error on line %d of printers.conf.", linenum
);
1301 else if (!strcasecmp(line
, "Attribute") && value
)
1303 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1306 cupsdLogMessage(CUPSD_LOG_ERROR
,
1307 "Syntax error on line %d of printers.conf.", linenum
);
1310 for (; *valueptr
&& isspace(*valueptr
& 255); *valueptr
++ = '\0');
1313 cupsdSetPrinterAttrs(p
);
1315 cupsdSetPrinterAttr(p
, value
, valueptr
);
1317 if (!strncmp(value
, "marker-", 7))
1318 p
->marker_time
= time(NULL
);
1324 * Something else we don't understand...
1327 cupsdLogMessage(CUPSD_LOG_ERROR
,
1328 "Unknown configuration directive %s on line %d of printers.conf.",
1338 * 'cupsdRenamePrinter()' - Rename a printer.
1343 cupsd_printer_t
*p
, /* I - Printer */
1344 const char *name
) /* I - New name */
1347 * Remove the printer from the array(s) first...
1350 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1351 "cupsdRenamePrinter: Removing %s from Printers", p
->name
);
1352 cupsArrayRemove(Printers
, p
);
1354 if (p
->type
& CUPS_PRINTER_IMPLICIT
)
1356 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1357 "cupsdRenamePrinter: Removing %s from ImplicitPrinters",
1359 cupsArrayRemove(ImplicitPrinters
, p
);
1363 * Rename the printer type...
1366 mimeDeleteType(MimeDatabase
, p
->filetype
);
1367 p
->filetype
= mimeAddType(MimeDatabase
, "printer", name
);
1369 mimeDeleteType(MimeDatabase
, p
->prefiltertype
);
1370 p
->prefiltertype
= mimeAddType(MimeDatabase
, "prefilter", name
);
1373 * Rename the printer...
1376 cupsdSetString(&p
->name
, name
);
1379 * Reset printer attributes...
1382 cupsdSetPrinterAttrs(p
);
1385 * Add the printer back to the printer array(s)...
1388 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1389 "cupsdRenamePrinter: Adding %s to Printers", p
->name
);
1390 cupsArrayAdd(Printers
, p
);
1392 if (p
->type
& CUPS_PRINTER_IMPLICIT
)
1394 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1395 "cupsdRenamePrinter: Adding %s to ImplicitPrinters",
1397 cupsArrayAdd(ImplicitPrinters
, p
);
1403 * 'cupsdSaveAllPrinters()' - Save all printer definitions to the printers.conf
1408 cupsdSaveAllPrinters(void)
1410 int i
; /* Looping var */
1411 cups_file_t
*fp
; /* printers.conf file */
1412 char temp
[1024], /* Temporary string */
1413 backup
[1024], /* printers.conf.O file */
1414 value
[2048], /* Value string */
1415 *ptr
; /* Pointer into value */
1416 cupsd_printer_t
*printer
; /* Current printer class */
1417 time_t curtime
; /* Current time */
1418 struct tm
*curdate
; /* Current date */
1419 cups_option_t
*option
; /* Current option */
1420 ipp_attribute_t
*marker
; /* Current marker attribute */
1424 * Create the printers.conf file...
1427 snprintf(temp
, sizeof(temp
), "%s/printers.conf", ServerRoot
);
1428 snprintf(backup
, sizeof(backup
), "%s/printers.conf.O", ServerRoot
);
1430 if (rename(temp
, backup
))
1432 if (errno
!= ENOENT
)
1433 cupsdLogMessage(CUPSD_LOG_ERROR
,
1434 "Unable to backup printers.conf - %s", strerror(errno
));
1437 if ((fp
= cupsFileOpen(temp
, "w")) == NULL
)
1439 cupsdLogMessage(CUPSD_LOG_ERROR
,
1440 "Unable to save printers.conf - %s", strerror(errno
));
1442 if (rename(backup
, temp
))
1443 cupsdLogMessage(CUPSD_LOG_ERROR
,
1444 "Unable to restore printers.conf - %s", strerror(errno
));
1448 cupsdLogMessage(CUPSD_LOG_INFO
, "Saving printers.conf...");
1451 * Restrict access to the file...
1454 fchown(cupsFileNumber(fp
), getuid(), Group
);
1455 fchmod(cupsFileNumber(fp
), 0600);
1458 * Write a small header to the file...
1461 curtime
= time(NULL
);
1462 curdate
= localtime(&curtime
);
1463 strftime(temp
, sizeof(temp
) - 1, "%Y-%m-%d %H:%M", curdate
);
1465 cupsFilePuts(fp
, "# Printer configuration file for " CUPS_SVERSION
"\n");
1466 cupsFilePrintf(fp
, "# Written by cupsd on %s\n", temp
);
1469 * Write each local printer known to the system...
1472 for (printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
1474 printer
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
1477 * Skip remote destinations and printer classes...
1480 if ((printer
->type
& CUPS_PRINTER_DISCOVERED
) ||
1481 (printer
->type
& CUPS_PRINTER_CLASS
) ||
1482 (printer
->type
& CUPS_PRINTER_IMPLICIT
))
1486 * Write printers as needed...
1489 if (printer
== DefaultPrinter
)
1490 cupsFilePrintf(fp
, "<DefaultPrinter %s>\n", printer
->name
);
1492 cupsFilePrintf(fp
, "<Printer %s>\n", printer
->name
);
1494 if (printer
->num_auth_info_required
> 0)
1496 switch (printer
->num_auth_info_required
)
1499 strlcpy(value
, printer
->auth_info_required
[0], sizeof(value
));
1503 snprintf(value
, sizeof(value
), "%s,%s",
1504 printer
->auth_info_required
[0],
1505 printer
->auth_info_required
[1]);
1510 snprintf(value
, sizeof(value
), "%s,%s,%s",
1511 printer
->auth_info_required
[0],
1512 printer
->auth_info_required
[1],
1513 printer
->auth_info_required
[2]);
1517 cupsFilePutConf(fp
, "AuthInfoRequired", value
);
1521 cupsFilePutConf(fp
, "Info", printer
->info
);
1523 if (printer
->location
)
1524 cupsFilePutConf(fp
, "Location", printer
->location
);
1526 if (printer
->make_model
)
1527 cupsFilePutConf(fp
, "MakeModel", printer
->make_model
);
1529 cupsFilePutConf(fp
, "DeviceURI", printer
->device_uri
);
1531 if (printer
->port_monitor
)
1532 cupsFilePutConf(fp
, "PortMonitor", printer
->port_monitor
);
1534 if (printer
->state
== IPP_PRINTER_STOPPED
)
1536 cupsFilePuts(fp
, "State Stopped\n");
1538 if (printer
->state_message
)
1539 cupsFilePutConf(fp
, "StateMessage", printer
->state_message
);
1542 cupsFilePuts(fp
, "State Idle\n");
1544 cupsFilePrintf(fp
, "StateTime %d\n", (int)printer
->state_time
);
1546 for (i
= 0; i
< printer
->num_reasons
; i
++)
1547 if (strcmp(printer
->reasons
[i
], "connecting-to-device"))
1548 cupsFilePutConf(fp
, "Reason", printer
->reasons
[i
]);
1550 cupsFilePrintf(fp
, "Type %d\n", printer
->type
);
1553 if (printer
->product
)
1554 cupsFilePutConf(fp
, "Product", printer
->product
);
1555 #endif /* HAVE_DNSSD */
1557 for (ptr
= (char *)cupsArrayFirst(printer
->filters
);
1559 ptr
= (char *)cupsArrayNext(printer
->filters
))
1560 cupsFilePutConf(fp
, "Filter", ptr
);
1562 for (ptr
= (char *)cupsArrayFirst(printer
->pre_filters
);
1564 ptr
= (char *)cupsArrayNext(printer
->pre_filters
))
1565 cupsFilePutConf(fp
, "PreFilter", ptr
);
1567 if (printer
->accepting
)
1568 cupsFilePuts(fp
, "Accepting Yes\n");
1570 cupsFilePuts(fp
, "Accepting No\n");
1572 if (printer
->shared
)
1573 cupsFilePuts(fp
, "Shared Yes\n");
1575 cupsFilePuts(fp
, "Shared No\n");
1577 snprintf(value
, sizeof(value
), "%s %s", printer
->job_sheets
[0],
1578 printer
->job_sheets
[1]);
1579 cupsFilePutConf(fp
, "JobSheets", value
);
1581 cupsFilePrintf(fp
, "QuotaPeriod %d\n", printer
->quota_period
);
1582 cupsFilePrintf(fp
, "PageLimit %d\n", printer
->page_limit
);
1583 cupsFilePrintf(fp
, "KLimit %d\n", printer
->k_limit
);
1585 for (i
= 0; i
< printer
->num_users
; i
++)
1586 cupsFilePutConf(fp
, printer
->deny_users
? "DenyUser" : "AllowUser",
1589 if (printer
->op_policy
)
1590 cupsFilePutConf(fp
, "OpPolicy", printer
->op_policy
);
1591 if (printer
->error_policy
)
1592 cupsFilePutConf(fp
, "ErrorPolicy", printer
->error_policy
);
1594 for (i
= printer
->num_options
, option
= printer
->options
;
1598 snprintf(value
, sizeof(value
), "%s %s", option
->name
, option
->value
);
1599 cupsFilePutConf(fp
, "Option", value
);
1602 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-colors",
1603 IPP_TAG_NAME
)) != NULL
)
1605 snprintf(value
, sizeof(value
), "%s ", marker
->name
);
1607 for (i
= 0, ptr
= value
+ strlen(value
);
1608 i
< marker
->num_values
&& ptr
< (value
+ sizeof(value
) - 1);
1614 strlcpy(ptr
, marker
->values
[i
].string
.text
,
1615 value
+ sizeof(value
) - ptr
);
1620 cupsFilePutConf(fp
, "Attribute", value
);
1623 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-levels",
1624 IPP_TAG_INTEGER
)) != NULL
)
1626 cupsFilePrintf(fp
, "Attribute %s %d", marker
->name
,
1627 marker
->values
[0].integer
);
1628 for (i
= 1; i
< marker
->num_values
; i
++)
1629 cupsFilePrintf(fp
, ",%d", marker
->values
[i
].integer
);
1630 cupsFilePuts(fp
, "\n");
1633 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-message",
1634 IPP_TAG_TEXT
)) != NULL
)
1636 snprintf(value
, sizeof(value
), "%s %s", marker
->name
,
1637 marker
->values
[0].string
.text
);
1639 cupsFilePutConf(fp
, "Attribute", value
);
1642 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-names",
1643 IPP_TAG_NAME
)) != NULL
)
1645 snprintf(value
, sizeof(value
), "%s ", marker
->name
);
1647 for (i
= 0, ptr
= value
+ strlen(value
);
1648 i
< marker
->num_values
&& ptr
< (value
+ sizeof(value
) - 1);
1654 strlcpy(ptr
, marker
->values
[i
].string
.text
,
1655 value
+ sizeof(value
) - ptr
);
1660 cupsFilePutConf(fp
, "Attribute", value
);
1663 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-types",
1664 IPP_TAG_KEYWORD
)) != NULL
)
1666 snprintf(value
, sizeof(value
), "%s ", marker
->name
);
1668 for (i
= 0, ptr
= value
+ strlen(value
);
1669 i
< marker
->num_values
&& ptr
< (value
+ sizeof(value
) - 1);
1675 strlcpy(ptr
, marker
->values
[i
].string
.text
,
1676 value
+ sizeof(value
) - ptr
);
1681 cupsFilePutConf(fp
, "Attribute", value
);
1684 cupsFilePuts(fp
, "</Printer>\n");
1688 * Make IRIX desktop & printer status happy
1691 write_irix_state(printer
);
1700 * 'cupsdSetAuthInfoRequired()' - Set the required authentication info.
1703 int /* O - 1 if value OK, 0 otherwise */
1704 cupsdSetAuthInfoRequired(
1705 cupsd_printer_t
*p
, /* I - Printer */
1706 const char *values
, /* I - Plain text value (or NULL) */
1707 ipp_attribute_t
*attr
) /* I - IPP attribute value (or NULL) */
1709 int i
; /* Looping var */
1712 p
->num_auth_info_required
= 0;
1715 * Do we have a plain text value?
1721 * Yes, grab the keywords...
1724 const char *end
; /* End of current value */
1727 while (*values
&& p
->num_auth_info_required
< 4)
1729 if ((end
= strchr(values
, ',')) == NULL
)
1730 end
= values
+ strlen(values
);
1732 if ((end
- values
) == 4 && !strncmp(values
, "none", 4))
1734 if (p
->num_auth_info_required
!= 0 || *end
)
1737 p
->auth_info_required
[p
->num_auth_info_required
] = "none";
1738 p
->num_auth_info_required
++;
1742 else if ((end
- values
) == 9 && !strncmp(values
, "negotiate", 9))
1744 if (p
->num_auth_info_required
!= 0 || *end
)
1747 p
->auth_info_required
[p
->num_auth_info_required
] = "negotiate";
1748 p
->num_auth_info_required
++;
1750 else if ((end
- values
) == 6 && !strncmp(values
, "domain", 6))
1752 p
->auth_info_required
[p
->num_auth_info_required
] = "domain";
1753 p
->num_auth_info_required
++;
1755 else if ((end
- values
) == 8 && !strncmp(values
, "password", 8))
1757 p
->auth_info_required
[p
->num_auth_info_required
] = "password";
1758 p
->num_auth_info_required
++;
1760 else if ((end
- values
) == 8 && !strncmp(values
, "username", 8))
1762 p
->auth_info_required
[p
->num_auth_info_required
] = "username";
1763 p
->num_auth_info_required
++;
1768 values
= (*end
) ? end
+ 1 : end
;
1771 if (p
->num_auth_info_required
== 0)
1773 p
->auth_info_required
[0] = "none";
1774 p
->num_auth_info_required
= 1;
1778 * Update the printer-type value as needed...
1781 if (p
->num_auth_info_required
> 1 ||
1782 strcmp(p
->auth_info_required
[0], "none"))
1783 p
->type
|= CUPS_PRINTER_AUTHENTICATED
;
1785 p
->type
&= ~CUPS_PRINTER_AUTHENTICATED
;
1791 * Grab values from an attribute instead...
1794 if (!attr
|| attr
->num_values
> 4)
1798 * Update the printer-type value as needed...
1801 if (attr
->num_values
> 1 ||
1802 strcmp(attr
->values
[0].string
.text
, "none"))
1803 p
->type
|= CUPS_PRINTER_AUTHENTICATED
;
1805 p
->type
&= ~CUPS_PRINTER_AUTHENTICATED
;
1807 for (i
= 0; i
< attr
->num_values
; i
++)
1809 if (!strcmp(attr
->values
[i
].string
.text
, "none"))
1811 if (p
->num_auth_info_required
!= 0 || attr
->num_values
!= 1)
1814 p
->auth_info_required
[p
->num_auth_info_required
] = "none";
1815 p
->num_auth_info_required
++;
1819 else if (!strcmp(attr
->values
[i
].string
.text
, "negotiate"))
1821 if (p
->num_auth_info_required
!= 0 || attr
->num_values
!= 1)
1824 p
->auth_info_required
[p
->num_auth_info_required
] = "negotiate";
1825 p
->num_auth_info_required
++;
1829 else if (!strcmp(attr
->values
[i
].string
.text
, "domain"))
1831 p
->auth_info_required
[p
->num_auth_info_required
] = "domain";
1832 p
->num_auth_info_required
++;
1834 else if (!strcmp(attr
->values
[i
].string
.text
, "password"))
1836 p
->auth_info_required
[p
->num_auth_info_required
] = "password";
1837 p
->num_auth_info_required
++;
1839 else if (!strcmp(attr
->values
[i
].string
.text
, "username"))
1841 p
->auth_info_required
[p
->num_auth_info_required
] = "username";
1842 p
->num_auth_info_required
++;
1853 * 'cupsdSetDeviceURI()' - Set the device URI for a printer.
1857 cupsdSetDeviceURI(cupsd_printer_t
*p
, /* I - Printer */
1858 const char *uri
) /* I - Device URI */
1860 char buffer
[1024], /* URI buffer */
1861 *start
, /* Start of data after scheme */
1862 *slash
, /* First slash after scheme:// */
1863 *ptr
; /* Pointer into user@host:port part */
1867 * Set the full device URI..
1870 cupsdSetString(&(p
->device_uri
), uri
);
1873 * Copy the device URI to a temporary buffer so we can sanitize any auth
1877 strlcpy(buffer
, uri
, sizeof(buffer
));
1880 * Find the end of the scheme:// part...
1883 if ((ptr
= strchr(buffer
, ':')) != NULL
)
1885 for (start
= ptr
+ 1; *start
; start
++)
1890 * Find the next slash (/) in the URI...
1893 if ((slash
= strchr(start
, '/')) == NULL
)
1894 slash
= start
+ strlen(start
); /* No slash, point to the end */
1897 * Check for an @ sign before the slash...
1900 if ((ptr
= strchr(start
, '@')) != NULL
&& ptr
< slash
)
1903 * Found an @ sign and it is before the resource part, so we have
1904 * an authentication string. Copy the remaining URI over the
1905 * authentication string...
1908 _cups_strcpy(start
, ptr
+ 1);
1913 * Save the sanitized URI...
1916 cupsdSetString(&(p
->sanitized_device_uri
), buffer
);
1921 * 'cupsdSetPrinterAttr()' - Set a printer attribute.
1925 cupsdSetPrinterAttr(
1926 cupsd_printer_t
*p
, /* I - Printer */
1927 const char *name
, /* I - Attribute name */
1928 char *value
) /* I - Attribute value string */
1930 ipp_attribute_t
*attr
; /* Attribute */
1931 int i
, /* Looping var */
1932 count
; /* Number of values */
1933 char *ptr
; /* Pointer into value */
1934 ipp_tag_t value_tag
; /* Value tag for this attribute */
1938 * Don't allow empty values...
1943 cupsdLogMessage(CUPSD_LOG_ERROR
, "Ignoring empty \"%s\" attribute", name
);
1948 * Count the number of values...
1951 for (count
= 1, ptr
= value
;
1952 (ptr
= strchr(ptr
, ',')) != NULL
;
1956 * Then add or update the attribute as needed...
1959 if (!strcmp(name
, "marker-levels"))
1965 if ((attr
= ippFindAttribute(p
->attrs
, name
, IPP_TAG_INTEGER
)) != NULL
&&
1966 attr
->num_values
< count
)
1968 ippDeleteAttribute(p
->attrs
, attr
);
1973 attr
->num_values
= count
;
1975 attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
, name
,
1980 cupsdLogMessage(CUPSD_LOG_ERROR
,
1981 "Unable to allocate memory for printer attribute "
1982 "(%d values)", count
);
1986 for (i
= 0; i
< count
; i
++)
1988 if ((ptr
= strchr(value
, ',')) != NULL
)
1991 attr
->values
[i
].integer
= strtol(value
, NULL
, 10);
2000 * Name or keyword values...
2003 if (!strcmp(name
, "marker-types"))
2004 value_tag
= IPP_TAG_KEYWORD
;
2005 else if (!strcmp(name
, "marker-message"))
2006 value_tag
= IPP_TAG_TEXT
;
2008 value_tag
= IPP_TAG_NAME
;
2010 if ((attr
= ippFindAttribute(p
->attrs
, name
, value_tag
)) != NULL
&&
2011 attr
->num_values
< count
)
2013 ippDeleteAttribute(p
->attrs
, attr
);
2019 for (i
= 0; i
< attr
->num_values
; i
++)
2020 _cupsStrFree(attr
->values
[i
].string
.text
);
2022 attr
->num_values
= count
;
2025 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, value_tag
, name
,
2030 cupsdLogMessage(CUPSD_LOG_ERROR
,
2031 "Unable to allocate memory for printer attribute "
2032 "(%d values)", count
);
2036 for (i
= 0; i
< count
; i
++)
2038 if ((ptr
= strchr(value
, ',')) != NULL
)
2041 attr
->values
[i
].string
.text
= _cupsStrAlloc(value
);
2048 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
2053 * 'cupsdSetPrinterAttrs()' - Set printer attributes based upon the PPD file.
2057 cupsdSetPrinterAttrs(cupsd_printer_t
*p
)/* I - Printer to setup */
2059 int i
, /* Looping var */
2060 length
; /* Length of browse attributes */
2061 char resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
2062 int num_air
; /* Number of auth-info-required values */
2063 const char * const *air
; /* auth-info-required values */
2064 cupsd_location_t
*auth
; /* Pointer to authentication element */
2065 const char *auth_supported
; /* Authentication supported */
2066 ipp_t
*oldattrs
; /* Old printer attributes */
2067 ipp_attribute_t
*attr
; /* Attribute data */
2068 cups_option_t
*option
; /* Current printer option */
2069 char *filter
; /* Current filter */
2070 static const char * const air_userpass
[] =
2071 { /* Basic/Digest authentication */
2076 static const char * const air_negotiate
[] =
2077 { /* Kerberos authentication */
2080 #endif /* HAVE_GSSAPI */
2081 static const char * const air_none
[] =
2082 { /* No authentication */
2087 DEBUG_printf(("cupsdSetPrinterAttrs: entering name = %s, type = %x\n", p
->name
,
2091 * Make sure that we have the common attributes defined...
2095 cupsdCreateCommonData();
2098 * Clear out old filters, if any...
2101 delete_printer_filters(p
);
2104 * Figure out the authentication that is required for the printer.
2107 auth_supported
= "requesting-user-name";
2111 if (p
->num_auth_info_required
> 0 && strcmp(p
->auth_info_required
[0], "none"))
2113 num_air
= p
->num_auth_info_required
;
2114 air
= p
->auth_info_required
;
2116 if (!strcmp(air
[0], "username"))
2117 auth_supported
= "basic";
2119 auth_supported
= "negotiate";
2121 else if (!(p
->type
& CUPS_PRINTER_DISCOVERED
))
2123 if (p
->type
& CUPS_PRINTER_CLASS
)
2124 snprintf(resource
, sizeof(resource
), "/classes/%s", p
->name
);
2126 snprintf(resource
, sizeof(resource
), "/printers/%s", p
->name
);
2128 if ((auth
= cupsdFindBest(resource
, HTTP_POST
)) == NULL
||
2129 auth
->type
== CUPSD_AUTH_NONE
)
2130 auth
= cupsdFindPolicyOp(p
->op_policy_ptr
, IPP_PRINT_JOB
);
2134 int auth_type
; /* Authentication type */
2137 if ((auth_type
= auth
->type
) == CUPSD_AUTH_DEFAULT
)
2138 auth_type
= DefaultAuthType
;
2140 if (auth_type
== CUPSD_AUTH_BASIC
|| auth_type
== CUPSD_AUTH_BASICDIGEST
)
2142 auth_supported
= "basic";
2146 else if (auth_type
== CUPSD_AUTH_DIGEST
)
2148 auth_supported
= "digest";
2153 else if (auth_type
== CUPSD_AUTH_NEGOTIATE
)
2155 auth_supported
= "negotiate";
2157 air
= air_negotiate
;
2159 #endif /* HAVE_GSSAPI */
2161 if (auth_type
!= CUPSD_AUTH_NONE
)
2162 p
->type
|= CUPS_PRINTER_AUTHENTICATED
;
2164 p
->type
&= ~CUPS_PRINTER_AUTHENTICATED
;
2167 p
->type
&= ~CUPS_PRINTER_AUTHENTICATED
;
2169 else if (p
->type
& CUPS_PRINTER_AUTHENTICATED
)
2176 * Create the required IPP attributes for a printer...
2179 oldattrs
= p
->attrs
;
2180 p
->attrs
= ippNew();
2182 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2183 "uri-authentication-supported", NULL
, auth_supported
);
2184 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2185 "uri-security-supported", NULL
, "none");
2186 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
, "printer-name", NULL
,
2188 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-location",
2189 NULL
, p
->location
? p
->location
: "");
2190 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-info",
2191 NULL
, p
->info
? p
->info
: "");
2196 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2197 "requesting-user-name-denied", p
->num_users
, NULL
,
2200 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2201 "requesting-user-name-allowed", p
->num_users
, NULL
,
2205 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2206 "job-quota-period", p
->quota_period
);
2207 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2208 "job-k-limit", p
->k_limit
);
2209 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2210 "job-page-limit", p
->page_limit
);
2211 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2212 "auth-info-required", num_air
, NULL
, air
);
2214 if (cupsArrayCount(Banners
) > 0 && !(p
->type
& CUPS_PRINTER_DISCOVERED
))
2217 * Setup the job-sheets-default attribute...
2220 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2221 "job-sheets-default", 2, NULL
, NULL
);
2225 attr
->values
[0].string
.text
= _cupsStrAlloc(Classification
?
2226 Classification
: p
->job_sheets
[0]);
2227 attr
->values
[1].string
.text
= _cupsStrAlloc(Classification
?
2228 Classification
: p
->job_sheets
[1]);
2235 if (p
->type
& CUPS_PRINTER_DISCOVERED
)
2238 * Tell the client this is a remote printer of some type...
2241 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
2242 "printer-uri-supported", NULL
, p
->uri
);
2244 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "printer-more-info",
2248 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
2249 "printer-make-and-model", NULL
, p
->make_model
);
2251 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "device-uri", NULL
,
2260 * Assign additional attributes depending on whether this is a printer
2264 if (p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
))
2267 p
->type
&= ~CUPS_PRINTER_OPTIONS
;
2270 * Add class-specific attributes...
2273 if ((p
->type
& CUPS_PRINTER_IMPLICIT
) && p
->num_printers
> 0 &&
2274 p
->printers
[0]->make_model
)
2275 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
2276 "printer-make-and-model", NULL
, p
->printers
[0]->make_model
);
2278 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
2279 "printer-make-and-model", NULL
, "Local Printer Class");
2281 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "device-uri", NULL
,
2282 "file:///dev/null");
2284 if (p
->num_printers
> 0)
2287 * Add a list of member names; URIs are added in copy_printer_attrs...
2290 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2291 "member-names", p
->num_printers
, NULL
, NULL
);
2292 p
->type
|= CUPS_PRINTER_OPTIONS
;
2294 for (i
= 0; i
< p
->num_printers
; i
++)
2297 attr
->values
[i
].string
.text
= _cupsStrAlloc(p
->printers
[i
]->name
);
2299 p
->type
&= ~CUPS_PRINTER_OPTIONS
| p
->printers
[i
]->type
;
2306 * Add printer-specific attributes...
2309 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "device-uri", NULL
,
2310 p
->sanitized_device_uri
);
2313 * Assign additional attributes from the PPD file (if any)...
2319 * Add filters for printer...
2322 for (filter
= (char *)cupsArrayFirst(p
->filters
);
2324 filter
= (char *)cupsArrayNext(p
->filters
))
2325 add_printer_filter(p
, p
->filetype
, filter
);
2329 p
->prefiltertype
= mimeAddType(MimeDatabase
, "prefilter", p
->name
);
2331 for (filter
= (char *)cupsArrayFirst(p
->pre_filters
);
2333 filter
= (char *)cupsArrayNext(p
->pre_filters
))
2334 add_printer_filter(p
, p
->prefiltertype
, filter
);
2340 * Copy marker attributes as needed...
2345 ipp_attribute_t
*oldattr
; /* Old attribute */
2348 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-colors",
2349 IPP_TAG_NAME
)) != NULL
)
2351 if ((attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2352 "marker-colors", oldattr
->num_values
, NULL
,
2355 for (i
= 0; i
< oldattr
->num_values
; i
++)
2356 attr
->values
[i
].string
.text
=
2357 _cupsStrAlloc(oldattr
->values
[i
].string
.text
);
2361 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-levels",
2362 IPP_TAG_INTEGER
)) != NULL
)
2364 if ((attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2365 "marker-levels", oldattr
->num_values
,
2368 for (i
= 0; i
< oldattr
->num_values
; i
++)
2369 attr
->values
[i
].integer
= oldattr
->values
[i
].integer
;
2373 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-names",
2374 IPP_TAG_NAME
)) != NULL
)
2376 if ((attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2377 "marker-names", oldattr
->num_values
, NULL
,
2380 for (i
= 0; i
< oldattr
->num_values
; i
++)
2381 attr
->values
[i
].string
.text
=
2382 _cupsStrAlloc(oldattr
->values
[i
].string
.text
);
2386 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-types",
2387 IPP_TAG_KEYWORD
)) != NULL
)
2389 if ((attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2390 "marker-types", oldattr
->num_values
, NULL
,
2393 for (i
= 0; i
< oldattr
->num_values
; i
++)
2394 attr
->values
[i
].string
.text
=
2395 _cupsStrAlloc(oldattr
->values
[i
].string
.text
);
2399 ippDelete(oldattrs
);
2403 * Force sharing off for remote queues...
2406 if (p
->type
& (CUPS_PRINTER_REMOTE
| CUPS_PRINTER_IMPLICIT
))
2411 * Copy the printer options into a browse attributes string we can re-use.
2414 const char *valptr
; /* Pointer into value */
2415 char *attrptr
; /* Pointer into attribute string */
2419 * Free the old browse attributes as needed...
2422 if (p
->browse_attrs
)
2423 free(p
->browse_attrs
);
2426 * Compute the length of all attributes + job-sheets, lease-duration,
2427 * and BrowseLocalOptions.
2430 for (length
= 1, i
= p
->num_options
, option
= p
->options
;
2434 length
+= strlen(option
->name
) + 2;
2438 for (valptr
= option
->value
; *valptr
; valptr
++)
2439 if (strchr(" \"\'\\", *valptr
))
2446 length
+= 13 + strlen(p
->job_sheets
[0]) + strlen(p
->job_sheets
[1]);
2448 if (BrowseLocalOptions
)
2449 length
+= 12 + strlen(BrowseLocalOptions
);
2451 if (p
->num_auth_info_required
> 0)
2453 length
+= 18; /* auth-info-required */
2455 for (i
= 0; i
< p
->num_auth_info_required
; i
++)
2456 length
+= strlen(p
->auth_info_required
[i
]) + 1;
2460 * Allocate the new string...
2463 if ((p
->browse_attrs
= calloc(1, length
)) == NULL
)
2464 cupsdLogMessage(CUPSD_LOG_ERROR
,
2465 "Unable to allocate %d bytes for browse data!",
2470 * Got the allocated string, now copy the options and attributes over...
2473 sprintf(p
->browse_attrs
, "job-sheets=%s,%s lease-duration=%d",
2474 p
->job_sheets
[0], p
->job_sheets
[1], BrowseTimeout
);
2475 attrptr
= p
->browse_attrs
+ strlen(p
->browse_attrs
);
2477 if (BrowseLocalOptions
)
2479 sprintf(attrptr
, " ipp-options=%s", BrowseLocalOptions
);
2480 attrptr
+= strlen(attrptr
);
2483 for (i
= p
->num_options
, option
= p
->options
;
2488 strcpy(attrptr
, option
->name
);
2489 attrptr
+= strlen(attrptr
);
2495 for (valptr
= option
->value
; *valptr
; valptr
++)
2497 if (strchr(" \"\'\\", *valptr
))
2500 *attrptr
++ = *valptr
;
2505 if (p
->num_auth_info_required
> 0)
2507 strcpy(attrptr
, "auth-info-required");
2510 for (i
= 0; i
< p
->num_auth_info_required
; i
++)
2512 *attrptr
++ = i
? ',' : '=';
2513 strcpy(attrptr
, p
->auth_info_required
[i
]);
2514 attrptr
+= strlen(attrptr
);
2523 * Populate the document-format-supported attribute...
2526 add_printer_formats(p
);
2528 DEBUG_printf(("cupsdSetPrinterAttrs: leaving name = %s, type = %x\n", p
->name
,
2532 * Add name-default attributes...
2535 add_printer_defaults(p
);
2539 * Write the IRIX printer config and status files...
2542 write_irix_config(p
);
2543 write_irix_state(p
);
2547 * Let the browse protocols reflect the change
2550 cupsdRegisterPrinter(p
);
2555 * 'cupsdSetPrinterReasons()' - Set/update the reasons strings.
2559 cupsdSetPrinterReasons(
2560 cupsd_printer_t
*p
, /* I - Printer */
2561 const char *s
) /* I - Reasons strings */
2563 int i
; /* Looping var */
2564 const char *sptr
; /* Pointer into reasons */
2565 char reason
[255], /* Reason string */
2566 *rptr
; /* Pointer into reason */
2569 if (s
[0] == '-' || s
[0] == '+')
2572 * Add/remove reasons...
2580 * Replace reasons...
2585 for (i
= 0; i
< p
->num_reasons
; i
++)
2586 _cupsStrFree(p
->reasons
[i
]);
2590 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
2592 if (PrintcapFormat
== PRINTCAP_PLIST
)
2593 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
2596 if (!strcmp(s
, "none"))
2600 * Loop through all of the reasons...
2606 * Skip leading whitespace and commas...
2609 while (isspace(*sptr
& 255) || *sptr
== ',')
2612 for (rptr
= reason
; *sptr
&& !isspace(*sptr
& 255) && *sptr
!= ','; sptr
++)
2613 if (rptr
< (reason
+ sizeof(reason
) - 1))
2627 for (i
= 0; i
< p
->num_reasons
; i
++)
2628 if (!strcasecmp(reason
, p
->reasons
[i
]))
2631 * Found a match, so remove it...
2635 _cupsStrFree(p
->reasons
[i
]);
2637 if (i
< p
->num_reasons
)
2638 memmove(p
->reasons
+ i
, p
->reasons
+ i
+ 1,
2639 (p
->num_reasons
- i
) * sizeof(char *));
2643 if (!strcmp(reason
, "paused") && p
->state
== IPP_PRINTER_STOPPED
)
2644 cupsdSetPrinterState(p
, IPP_PRINTER_IDLE
, 1);
2646 if (strcmp(reason
, "connecting-to-device"))
2647 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
2649 if (PrintcapFormat
== PRINTCAP_PLIST
)
2650 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
2653 else if (p
->num_reasons
< (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
2659 for (i
= 0; i
< p
->num_reasons
; i
++)
2660 if (!strcasecmp(reason
, p
->reasons
[i
]))
2663 if (i
>= p
->num_reasons
)
2665 p
->reasons
[i
] = _cupsStrAlloc(reason
);
2668 if (!strcmp(reason
, "paused") && p
->state
!= IPP_PRINTER_STOPPED
)
2669 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, 1);
2671 if (strcmp(reason
, "connecting-to-device"))
2672 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
2674 if (PrintcapFormat
== PRINTCAP_PLIST
)
2675 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
2683 * 'cupsdSetPrinterState()' - Update the current state of a printer.
2687 cupsdSetPrinterState(
2688 cupsd_printer_t
*p
, /* I - Printer to change */
2689 ipp_pstate_t s
, /* I - New state */
2690 int update
) /* I - Update printers.conf? */
2692 ipp_pstate_t old_state
; /* Old printer state */
2696 * Can't set status of remote printers...
2699 if (p
->type
& CUPS_PRINTER_DISCOVERED
)
2703 * Set the new state...
2706 if (PrintcapFormat
== PRINTCAP_PLIST
)
2707 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
2709 old_state
= p
->state
;
2714 cupsdAddEvent(s
== IPP_PRINTER_STOPPED
? CUPSD_EVENT_PRINTER_STOPPED
:
2715 CUPSD_EVENT_PRINTER_STATE
, p
, NULL
,
2716 "%s \"%s\" state changed.",
2717 (p
->type
& CUPS_PRINTER_CLASS
) ? "Class" : "Printer",
2721 * Let the browse code know this needs to be updated...
2725 p
->state_time
= time(NULL
);
2729 write_irix_state(p
);
2733 cupsdAddPrinterHistory(p
);
2736 * Let the browse protocols reflect the change...
2740 cupsdRegisterPrinter(p
);
2743 * Save the printer configuration if a printer goes from idle or processing
2744 * to stopped (or visa-versa)...
2747 if ((old_state
== IPP_PRINTER_STOPPED
) != (s
== IPP_PRINTER_STOPPED
) &&
2750 if (p
->type
& CUPS_PRINTER_CLASS
)
2751 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
2753 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
2759 * 'cupsdStopPrinter()' - Stop a printer from printing any jobs...
2763 cupsdStopPrinter(cupsd_printer_t
*p
, /* I - Printer to stop */
2764 int update
)/* I - Update printers.conf? */
2766 cupsd_job_t
*job
; /* Active print job */
2770 * Set the printer state...
2773 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, update
);
2776 * See if we have a job printing on this printer...
2782 * Get pointer to job...
2785 job
= (cupsd_job_t
*)p
->job
;
2791 cupsdStopJob(job
, 0);
2794 * Reset the state to pending...
2797 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
2798 job
->state_value
= IPP_JOB_PENDING
;
2801 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
2803 cupsdAddEvent(CUPSD_EVENT_JOB_STOPPED
, p
, job
,
2804 "Job stopped due to printer being paused");
2810 * 'cupsdUpdatePrinterPPD()' - Update keywords in a printer's PPD file.
2813 int /* O - 1 if successful, 0 otherwise */
2814 cupsdUpdatePrinterPPD(
2815 cupsd_printer_t
*p
, /* I - Printer */
2816 int num_keywords
, /* I - Number of keywords */
2817 cups_option_t
*keywords
) /* I - Keywords */
2819 int i
; /* Looping var */
2820 cups_file_t
*src
, /* Original file */
2821 *dst
; /* New file */
2822 char srcfile
[1024], /* Original filename */
2823 dstfile
[1024], /* New filename */
2824 line
[1024], /* Line from file */
2825 keystring
[41]; /* Keyword from line */
2826 cups_option_t
*keyword
; /* Current keyword */
2829 cupsdLogMessage(CUPSD_LOG_INFO
, "Updating keywords in PPD file for %s...",
2833 * Get the old and new PPD filenames...
2836 snprintf(srcfile
, sizeof(srcfile
), "%s/ppd/%s.ppd.O", ServerRoot
, p
->name
);
2837 snprintf(dstfile
, sizeof(srcfile
), "%s/ppd/%s.ppd", ServerRoot
, p
->name
);
2840 * Rename the old file and open the old and new...
2843 if (rename(dstfile
, srcfile
))
2845 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to backup PPD file for %s: %s",
2846 p
->name
, strerror(errno
));
2850 if ((src
= cupsFileOpen(srcfile
, "r")) == NULL
)
2852 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to open PPD file \"%s\": %s",
2853 srcfile
, strerror(errno
));
2854 rename(srcfile
, dstfile
);
2858 if ((dst
= cupsFileOpen(dstfile
, "w")) == NULL
)
2860 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to create PPD file \"%s\": %s",
2861 dstfile
, strerror(errno
));
2863 rename(srcfile
, dstfile
);
2868 * Copy the first line and then write out all of the keywords...
2871 if (!cupsFileGets(src
, line
, sizeof(line
)))
2873 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to read PPD file \"%s\": %s",
2874 srcfile
, strerror(errno
));
2877 rename(srcfile
, dstfile
);
2881 cupsFilePrintf(dst
, "%s\n", line
);
2883 for (i
= num_keywords
, keyword
= keywords
; i
> 0; i
--, keyword
++)
2885 cupsdLogMessage(CUPSD_LOG_DEBUG
, "*%s: %s", keyword
->name
, keyword
->value
);
2886 cupsFilePrintf(dst
, "*%s: %s\n", keyword
->name
, keyword
->value
);
2890 * Then copy the rest of the PPD file, dropping any keywords we changed.
2893 while (cupsFileGets(src
, line
, sizeof(line
)))
2896 * Skip keywords we've already set...
2899 if (sscanf(line
, "*%40[^:]:", keystring
) == 1 &&
2900 cupsGetOption(keystring
, num_keywords
, keywords
))
2904 * Otherwise write the line...
2907 cupsFilePrintf(dst
, "%s\n", line
);
2911 * Close files and return...
2922 * 'cupsdUpdatePrinters()' - Update printers after a partial reload.
2926 cupsdUpdatePrinters(void)
2928 cupsd_printer_t
*p
; /* Current printer */
2932 * Loop through the printers and recreate the printer attributes
2933 * for any local printers since the policy and/or access control
2934 * stuff may have changed. Also, if browsing is disabled, remove
2935 * any remote printers...
2938 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
2940 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
2943 * Remove remote printers if we are no longer browsing...
2947 (p
->type
& (CUPS_PRINTER_IMPLICIT
| CUPS_PRINTER_DISCOVERED
)))
2949 if (p
->type
& CUPS_PRINTER_IMPLICIT
)
2950 cupsArrayRemove(ImplicitPrinters
, p
);
2952 cupsArraySave(Printers
);
2953 cupsdDeletePrinter(p
, 0);
2954 cupsArrayRestore(Printers
);
2959 * Update the operation policy pointer...
2962 if ((p
->op_policy_ptr
= cupsdFindPolicy(p
->op_policy
)) == NULL
)
2963 p
->op_policy_ptr
= DefaultPolicyPtr
;
2966 * Update printer attributes as needed...
2969 if (!(p
->type
& CUPS_PRINTER_DISCOVERED
))
2970 cupsdSetPrinterAttrs(p
);
2976 * 'cupsdValidateDest()' - Validate a printer/class destination.
2979 const char * /* O - Printer or class name */
2981 const char *uri
, /* I - Printer URI */
2982 cups_ptype_t
*dtype
, /* O - Type (printer or class) */
2983 cupsd_printer_t
**printer
) /* O - Printer pointer */
2985 cupsd_printer_t
*p
; /* Current printer */
2986 char localname
[1024],/* Localized hostname */
2987 *lptr
, /* Pointer into localized hostname */
2988 *sptr
, /* Pointer into server name */
2989 *rptr
, /* Pointer into resource */
2990 scheme
[32], /* Scheme portion of URI */
2991 username
[64], /* Username portion of URI */
2992 hostname
[HTTP_MAX_HOST
],
2993 /* Host portion of URI */
2994 resource
[HTTP_MAX_URI
];
2995 /* Resource portion of URI */
2996 int port
; /* Port portion of URI */
2999 DEBUG_printf(("cupsdValidateDest(uri=\"%s\", dtype=%p, printer=%p)\n", uri
,
3003 * Initialize return values...
3010 *dtype
= (cups_ptype_t
)0;
3013 * Pull the hostname and resource from the URI...
3016 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
, scheme
, sizeof(scheme
),
3017 username
, sizeof(username
), hostname
, sizeof(hostname
),
3018 &port
, resource
, sizeof(resource
));
3021 * See if the resource is a class or printer...
3024 if (!strncmp(resource
, "/classes/", 9))
3030 rptr
= resource
+ 9;
3032 else if (!strncmp(resource
, "/printers/", 10))
3038 rptr
= resource
+ 10;
3043 * Bad resource name...
3050 * See if the printer or class name exists...
3053 p
= cupsdFindDest(rptr
);
3055 if (p
== NULL
&& strchr(rptr
, '@') == NULL
)
3063 *dtype
= p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
|
3064 CUPS_PRINTER_REMOTE
| CUPS_PRINTER_DISCOVERED
);
3070 * Change localhost to the server name...
3073 if (!strcasecmp(hostname
, "localhost"))
3074 strlcpy(hostname
, ServerName
, sizeof(hostname
));
3076 strlcpy(localname
, hostname
, sizeof(localname
));
3078 if (!strcasecmp(hostname
, ServerName
))
3081 * Localize the hostname...
3084 lptr
= strchr(localname
, '.');
3085 sptr
= strchr(ServerName
, '.');
3087 if (sptr
!= NULL
&& lptr
!= NULL
)
3090 * Strip the common domain name components...
3093 while (lptr
!= NULL
)
3095 if (!strcasecmp(lptr
, sptr
))
3101 lptr
= strchr(lptr
+ 1, '.');
3106 DEBUG_printf(("localized hostname is \"%s\"...\n", localname
));
3109 * Find a matching printer or class...
3112 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3114 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3115 if (!strcasecmp(p
->hostname
, localname
) &&
3116 !strcasecmp(p
->name
, rptr
))
3122 *dtype
= p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
|
3123 CUPS_PRINTER_REMOTE
| CUPS_PRINTER_DISCOVERED
);
3133 * 'cupsdWritePrintcap()' - Write a pseudo-printcap file for older applications
3138 cupsdWritePrintcap(void)
3140 int i
; /* Looping var */
3141 cups_file_t
*fp
; /* Printcap file */
3142 cupsd_printer_t
*p
; /* Current printer */
3147 * Update the IRIX printer state for the default printer; if
3148 * no printers remain, then the default printer file will be
3152 write_irix_state(DefaultPrinter
);
3156 * See if we have a printcap file; if not, don't bother writing it.
3159 if (!Printcap
|| !*Printcap
)
3163 * Open the printcap file...
3166 if ((fp
= cupsFileOpen(Printcap
, "w")) == NULL
)
3170 * Put a comment header at the top so that users will know where the
3171 * data has come from...
3174 if (PrintcapFormat
!= PRINTCAP_PLIST
)
3175 cupsFilePrintf(fp
, "# This file was automatically generated by cupsd(8) "
3177 "# %s/printers.conf file. All changes to this file\n"
3178 "# will be lost.\n", ServerRoot
);
3183 * Write a new printcap with the current list of printers.
3186 switch (PrintcapFormat
)
3190 * Each printer is put in the file as:
3200 cupsFilePrintf(fp
, "%s|%s:rm=%s:rp=%s:\n", DefaultPrinter
->name
,
3201 DefaultPrinter
->info
, ServerName
,
3202 DefaultPrinter
->name
);
3204 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3206 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3207 if (p
!= DefaultPrinter
)
3208 cupsFilePrintf(fp
, "%s|%s:rm=%s:rp=%s:\n", p
->name
, p
->info
,
3209 ServerName
, p
->name
);
3212 case PRINTCAP_PLIST
:
3214 * Each printer is written as a dictionary in a plist file.
3215 * Currently the printer-name, printer-info, printer-is-accepting-jobs,
3216 * printer-location, printer-make-and-model, printer-state,
3217 * printer-state-reasons, printer-type, and (sanitized) device-uri.
3220 cupsFilePuts(fp
, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
3221 "<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD "
3222 "PLIST 1.0//EN\" \"http://www.apple.com/DTDs/"
3223 "PropertyList-1.0.dtd\">\n"
3224 "<plist version=\"1.0\">\n"
3227 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3229 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3231 cupsFilePuts(fp
, "\t<dict>\n"
3232 "\t\t<key>printer-name</key>\n"
3234 write_xml_string(fp
, p
->name
);
3235 cupsFilePuts(fp
, "</string>\n"
3236 "\t\t<key>printer-info</key>\n"
3238 write_xml_string(fp
, p
->info
);
3239 cupsFilePrintf(fp
, "</string>\n"
3240 "\t\t<key>printer-is-accepting-jobs</key>\n"
3242 "\t\t<key>printer-location</key>\n"
3243 "\t\t<string>", p
->accepting
? "true" : "false");
3244 write_xml_string(fp
, p
->location
);
3245 cupsFilePuts(fp
, "</string>\n"
3246 "\t\t<key>printer-make-and-model</key>\n"
3248 write_xml_string(fp
, p
->make_model
);
3249 cupsFilePrintf(fp
, "</string>\n"
3250 "\t\t<key>printer-state</key>\n"
3251 "\t\t<integer>%d</integer>\n"
3252 "\t\t<key>printer-state-reasons</key>\n"
3253 "\t\t<array>\n", p
->state
);
3254 for (i
= 0; i
< p
->num_reasons
; i
++)
3256 cupsFilePuts(fp
, "\t\t\t<string>");
3257 write_xml_string(fp
, p
->reasons
[i
]);
3258 cupsFilePuts(fp
, "</string>\n");
3260 cupsFilePrintf(fp
, "\t\t</array>\n"
3261 "\t\t<key>printer-type</key>\n"
3262 "\t\t<integer>%d</integer>\n"
3263 "\t\t<key>device-uri</key>\n"
3264 "\t\t<string>", p
->type
);
3265 write_xml_string(fp
, p
->sanitized_device_uri
);
3266 cupsFilePuts(fp
, "</string>\n"
3269 cupsFilePuts(fp
, "</array>\n"
3273 case PRINTCAP_SOLARIS
:
3275 * Each printer is put in the file as:
3277 * _all:all=Printer1,Printer2,Printer3,...,PrinterN
3278 * _default:use=DefaultPrinter
3280 * :bsdaddr=ServerName,Printer1:\
3281 * :description=Description:
3283 * :bsdaddr=ServerName,Printer2:\
3284 * :description=Description:
3286 * :bsdaddr=ServerName,Printer3:\
3287 * :description=Description:
3290 * :bsdaddr=ServerName,PrinterN:\
3291 * :description=Description:
3294 cupsFilePuts(fp
, "_all:all=");
3295 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3297 p
= (cupsd_printer_t
*)cupsArrayCurrent(Printers
))
3298 cupsFilePrintf(fp
, "%s%c", p
->name
,
3299 cupsArrayNext(Printers
) ? ',' : '\n');
3302 cupsFilePrintf(fp
, "_default:use=%s\n", DefaultPrinter
->name
);
3304 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3306 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3307 cupsFilePrintf(fp
, "%s:\\\n"
3308 "\t:bsdaddr=%s,%s:\\\n"
3309 "\t:description=%s:\n",
3310 p
->name
, ServerName
, p
->name
,
3311 p
->info
? p
->info
: "");
3325 * 'add_printer_defaults()' - Add name-default attributes to the printer attributes.
3329 add_printer_defaults(cupsd_printer_t
*p
)/* I - Printer */
3331 int i
; /* Looping var */
3332 int num_options
; /* Number of default options */
3333 cups_option_t
*options
, /* Default options */
3334 *option
; /* Current option */
3335 char name
[256]; /* name-default */
3339 * Maintain a common array of default attribute names...
3342 if (!CommonDefaults
)
3344 CommonDefaults
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
3346 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("copies-default"));
3347 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("document-format-default"));
3348 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("finishings-default"));
3349 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-hold-until-default"));
3350 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-priority-default"));
3351 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-sheets-default"));
3352 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("media-default"));
3353 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("number-up-default"));
3354 cupsArrayAdd(CommonDefaults
,
3355 _cupsStrAlloc("orientation-requested-default"));
3356 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("sides-default"));
3360 * Add all of the default options from the .conf files...
3363 for (num_options
= 0, options
= NULL
, i
= p
->num_options
, option
= p
->options
;
3367 if (strcmp(option
->name
, "ipp-options") &&
3368 strcmp(option
->name
, "job-sheets") &&
3369 strcmp(option
->name
, "lease-duration"))
3371 snprintf(name
, sizeof(name
), "%s-default", option
->name
);
3372 num_options
= cupsAddOption(name
, option
->value
, num_options
, &options
);
3374 if (!cupsArrayFind(CommonDefaults
, name
))
3375 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc(name
));
3380 * Convert options to IPP attributes...
3383 cupsEncodeOptions2(p
->attrs
, num_options
, options
, IPP_TAG_PRINTER
);
3384 cupsFreeOptions(num_options
, options
);
3387 * Add standard -default attributes as needed...
3390 if (!cupsGetOption("copies", p
->num_options
, p
->options
))
3391 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
, "copies-default",
3394 if (!cupsGetOption("document-format", p
->num_options
, p
->options
))
3395 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_MIMETYPE
,
3396 "document-format-default", NULL
, "application/octet-stream");
3398 if (!cupsGetOption("job-hold-until", p
->num_options
, p
->options
))
3399 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3400 "job-hold-until-default", NULL
, "no-hold");
3402 if (!cupsGetOption("job-priority", p
->num_options
, p
->options
))
3403 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3404 "job-priority-default", 50);
3406 if (!cupsGetOption("number-up", p
->num_options
, p
->options
))
3407 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3408 "number-up-default", 1);
3410 if (!cupsGetOption("orientation-requested", p
->num_options
, p
->options
))
3411 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NOVALUE
,
3412 "orientation-requested-default", NULL
, NULL
);
3414 if (!cupsGetOption("notify-lease-duration", p
->num_options
, p
->options
))
3415 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3416 "notify-lease-duration-default", DefaultLeaseDuration
);
3418 if (!cupsGetOption("notify-events", p
->num_options
, p
->options
))
3419 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3420 "notify-events-default", NULL
, "job-completed");
3425 * 'add_printer_filter()' - Add a MIME filter for a printer.
3430 cupsd_printer_t
*p
, /* I - Printer to add to */
3431 mime_type_t
*filtertype
, /* I - Filter or prefilter MIME type */
3432 const char *filter
) /* I - Filter to add */
3434 char super
[MIME_MAX_SUPER
], /* Super-type for filter */
3435 type
[MIME_MAX_TYPE
], /* Type for filter */
3436 program
[1024]; /* Program/filter name */
3437 int cost
; /* Cost of filter */
3438 mime_type_t
*temptype
; /* MIME type looping var */
3439 char filename
[1024]; /* Full filter filename */
3443 * Parse the filter string; it should be in the following format:
3445 * super/type cost program
3448 if (sscanf(filter
, "%15[^/]/%31s%d%*[ \t]%1023[^\n]", super
, type
, &cost
,
3451 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: invalid filter string \"%s\"!",
3457 * See if the filter program exists; if not, stop the printer and flag
3461 if (strcmp(program
, "-"))
3463 if (program
[0] == '/')
3464 strlcpy(filename
, program
, sizeof(filename
));
3466 snprintf(filename
, sizeof(filename
), "%s/filter/%s", ServerBin
, program
);
3468 if (access(filename
, X_OK
))
3470 snprintf(p
->state_message
, sizeof(p
->state_message
),
3471 "Filter \"%s\" for printer \"%s\" not available: %s",
3472 program
, p
->name
, strerror(errno
));
3473 cupsdSetPrinterReasons(p
, "+cups-missing-filter-error");
3474 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, 0);
3476 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s", p
->state_message
);
3481 * Mark the CUPS_PRINTER_COMMANDS bit if we have a filter for
3482 * application/vnd.cups-command...
3485 if (!strcasecmp(super
, "application") &&
3486 !strcasecmp(type
, "vnd.cups-command"))
3487 p
->type
|= CUPS_PRINTER_COMMANDS
;
3490 * Add the filter to the MIME database, supporting wildcards as needed...
3493 for (temptype
= mimeFirstType(MimeDatabase
);
3495 temptype
= mimeNextType(MimeDatabase
))
3496 if (((super
[0] == '*' && strcasecmp(temptype
->super
, "printer")) ||
3497 !strcasecmp(temptype
->super
, super
)) &&
3498 (type
[0] == '*' || !strcasecmp(temptype
->type
, type
)))
3500 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3501 "add_printer_filter: %s: adding filter %s/%s %s/%s %d %s",
3502 p
->name
, temptype
->super
, temptype
->type
,
3503 filtertype
->super
, filtertype
->type
,
3505 mimeAddFilter(MimeDatabase
, temptype
, filtertype
, cost
, program
);
3511 * 'add_printer_formats()' - Add document-format-supported values for a printer.
3515 add_printer_formats(cupsd_printer_t
*p
) /* I - Printer */
3517 int i
; /* Looping var */
3518 mime_type_t
*type
; /* Current MIME type */
3519 cups_array_t
*filters
; /* Filters */
3520 ipp_attribute_t
*attr
; /* document-format-supported attribute */
3521 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
3522 /* MIME type name */
3526 * Raw (and remote) queues advertise all of the supported MIME
3530 cupsArrayDelete(p
->filetypes
);
3531 p
->filetypes
= NULL
;
3535 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
,
3536 (ipp_tag_t
)(IPP_TAG_MIMETYPE
| IPP_TAG_COPY
),
3537 "document-format-supported", NumMimeTypes
, NULL
, MimeTypes
);
3542 * Otherwise, loop through the supported MIME types and see if there
3543 * are filters for them...
3546 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_printer_formats: %d types, %d filters",
3547 mimeNumTypes(MimeDatabase
), mimeNumFilters(MimeDatabase
));
3549 p
->filetypes
= cupsArrayNew(NULL
, NULL
);
3551 for (type
= mimeFirstType(MimeDatabase
);
3553 type
= mimeNextType(MimeDatabase
))
3555 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
3557 if ((filters
= mimeFilter(MimeDatabase
, type
, p
->filetype
, NULL
)) != NULL
)
3559 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3560 "add_printer_formats: %s: %s needs %d filters",
3561 p
->name
, mimetype
, cupsArrayCount(filters
));
3563 cupsArrayDelete(filters
);
3564 cupsArrayAdd(p
->filetypes
, type
);
3567 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3568 "add_printer_formats: %s: %s not supported",
3572 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3573 "add_printer_formats: %s: %d supported types",
3574 p
->name
, cupsArrayCount(p
->filetypes
) + 1);
3577 * Add the file formats that can be filtered...
3580 if ((type
= mimeType(MimeDatabase
, "application", "octet-stream")) == NULL
||
3581 !cupsArrayFind(p
->filetypes
, type
))
3586 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_MIMETYPE
,
3587 "document-format-supported",
3588 cupsArrayCount(p
->filetypes
) + 1, NULL
, NULL
);
3591 attr
->values
[0].string
.text
= _cupsStrAlloc("application/octet-stream");
3593 for (type
= (mime_type_t
*)cupsArrayFirst(p
->filetypes
);
3595 i
++, type
= (mime_type_t
*)cupsArrayNext(p
->filetypes
))
3597 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
3599 attr
->values
[i
].string
.text
= _cupsStrAlloc(mimetype
);
3604 char pdl
[1024]; /* Buffer to build pdl list */
3605 mime_filter_t
*filter
; /* MIME filter looping var */
3610 if (mimeType(MimeDatabase
, "application", "pdf"))
3611 strlcat(pdl
, "application/pdf,", sizeof(pdl
));
3613 if (mimeType(MimeDatabase
, "application", "postscript"))
3614 strlcat(pdl
, "application/postscript,", sizeof(pdl
));
3616 if (mimeType(MimeDatabase
, "application", "vnd.cups-raster"))
3617 strlcat(pdl
, "application/vnd.cups-raster,", sizeof(pdl
));
3620 * Determine if this is a Tioga PrintJobMgr based queue...
3623 for (filter
= (mime_filter_t
*)cupsArrayFirst(MimeDatabase
->filters
);
3625 filter
= (mime_filter_t
*)cupsArrayNext(MimeDatabase
->filters
))
3627 if (filter
->dst
== p
->filetype
&& filter
->filter
&&
3628 strstr(filter
->filter
, "PrintJobMgr"))
3633 * We only support raw printing if this is not a Tioga PrintJobMgr based
3634 * queue and if application/octet-stream is a known conversion...
3637 if (!filter
&& mimeType(MimeDatabase
, "application", "octet-stream"))
3638 strlcat(pdl
, "application/octet-stream,", sizeof(pdl
));
3640 if (mimeType(MimeDatabase
, "image", "png"))
3641 strlcat(pdl
, "image/png,", sizeof(pdl
));
3644 pdl
[strlen(pdl
) - 1] = '\0'; /* Remove trailing comma */
3646 cupsdSetString(&p
->pdl
, pdl
);
3648 #endif /* HAVE_DNSSD */
3653 * 'add_string_array()' - Add a string to an array of CUPS strings.
3657 add_string_array(cups_array_t
**a
, /* I - Array */
3658 const char *s
) /* I - String */
3661 *a
= cupsArrayNew(NULL
, NULL
);
3663 cupsArrayAdd(*a
, _cupsStrAlloc(s
));
3668 * 'compare_printers()' - Compare two printers.
3671 static int /* O - Result of comparison */
3672 compare_printers(void *first
, /* I - First printer */
3673 void *second
, /* I - Second printer */
3674 void *data
) /* I - App data (not used) */
3676 return (strcasecmp(((cupsd_printer_t
*)first
)->name
,
3677 ((cupsd_printer_t
*)second
)->name
));
3682 * 'delete_printer_filters()' - Delete all MIME filters for a printer.
3686 delete_printer_filters(
3687 cupsd_printer_t
*p
) /* I - Printer to remove from */
3689 mime_filter_t
*filter
; /* MIME filter looping var */
3693 * Range check input...
3700 * Remove all filters from the MIME database that have a destination
3701 * type == printer...
3704 for (filter
= mimeFirstFilter(MimeDatabase
);
3706 filter
= mimeNextFilter(MimeDatabase
))
3707 if (filter
->dst
== p
->filetype
)
3710 * Delete the current filter...
3713 mimeDeleteFilter(MimeDatabase
, filter
);
3719 * 'delete_string_array()' - Delete an array of CUPS strings.
3723 delete_string_array(cups_array_t
**a
) /* I - Array */
3725 char *ptr
; /* Current string */
3728 for (ptr
= (char *)cupsArrayFirst(*a
);
3730 ptr
= (char *)cupsArrayNext(*a
))
3733 cupsArrayDelete(*a
);
3739 * 'load_ppd()' - Load a cached PPD file, updating the cache as needed.
3743 load_ppd(cupsd_printer_t
*p
) /* I - Printer */
3745 int i
; /* Looping var */
3746 cups_file_t
*cache
; /* Cache file */
3747 char cache_name
[1024]; /* Cache filename */
3748 struct stat cache_info
; /* Cache file info */
3749 ppd_file_t
*ppd
; /* PPD file */
3750 char ppd_name
[1024]; /* PPD filename */
3751 struct stat ppd_info
; /* PPD file info */
3752 int num_media
; /* Number of media options */
3753 ppd_option_t
*input_slot
, /* InputSlot options */
3754 *media_type
, /* MediaType options */
3755 *page_size
, /* PageSize options */
3756 *output_bin
, /* OutputBin options */
3757 *media_quality
, /* EFMediaQualityMode options */
3758 *duplex
; /* Duplex options */
3759 ppd_attr_t
*ppd_attr
; /* PPD attribute */
3760 ipp_attribute_t
*attr
; /* Attribute data */
3761 ipp_value_t
*val
; /* Attribute value */
3762 int num_finishings
; /* Number of finishings */
3763 int finishings
[5]; /* finishings-supported values */
3764 static const char * const sides
[3] = /* sides-supported values */
3767 "two-sided-long-edge",
3768 "two-sided-short-edge"
3770 static const char * const standard_commands
[] =
3771 { /* Standard CUPS commands */
3774 "PrintSelfTestPage",
3780 * Check to see if the cache is up-to-date...
3783 snprintf(cache_name
, sizeof(cache_name
), "%s/%s.ipp", CacheDir
, p
->name
);
3784 if (stat(cache_name
, &cache_info
))
3785 cache_info
.st_mtime
= 0;
3787 snprintf(ppd_name
, sizeof(ppd_name
), "%s/ppd/%s.ppd", ServerRoot
, p
->name
);
3788 if (stat(ppd_name
, &ppd_info
))
3789 ppd_info
.st_mtime
= 1;
3791 ippDelete(p
->ppd_attrs
);
3792 p
->ppd_attrs
= ippNew();
3794 if (cache_info
.st_mtime
>= ppd_info
.st_mtime
&&
3795 (cache
= cupsFileOpen(cache_name
, "r")) != NULL
)
3798 * Load cached information and return...
3801 cupsdLogMessage(CUPSD_LOG_DEBUG
, "load_ppd: Loading %s...", cache_name
);
3803 if (ippReadIO(cache
, (ipp_iocb_t
)cupsFileRead
, 1, NULL
,
3804 p
->ppd_attrs
) == IPP_DATA
)
3806 cupsFileClose(cache
);
3810 cupsFileClose(cache
);
3814 * Reload PPD attributes from disk...
3817 cupsdLogMessage(CUPSD_LOG_DEBUG
, "load_ppd: Loading %s...", ppd_name
);
3819 delete_string_array(&(p
->filters
));
3820 delete_string_array(&(p
->pre_filters
));
3822 p
->type
&= ~CUPS_PRINTER_OPTIONS
;
3823 p
->type
|= CUPS_PRINTER_BW
;
3825 finishings
[0] = IPP_FINISHINGS_NONE
;
3828 if ((ppd
= ppdOpenFile(ppd_name
)) != NULL
)
3831 * Add make/model and other various attributes...
3834 if (ppd
->color_device
)
3835 p
->type
|= CUPS_PRINTER_COLOR
;
3836 if (ppd
->variable_sizes
)
3837 p
->type
|= CUPS_PRINTER_VARIABLE
;
3838 if (!ppd
->manual_copies
)
3839 p
->type
|= CUPS_PRINTER_COPIES
;
3840 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsFax", NULL
)) != NULL
)
3841 if (ppd_attr
->value
&& !strcasecmp(ppd_attr
->value
, "true"))
3842 p
->type
|= CUPS_PRINTER_FAX
;
3844 ippAddBoolean(p
->ppd_attrs
, IPP_TAG_PRINTER
, "color-supported",
3846 if (ppd
->throughput
)
3847 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3848 "pages-per-minute", ppd
->throughput
);
3853 * The NickName can be localized in the character set specified
3854 * by the LanugageEncoding attribute. However, ppdOpen2() has
3855 * already converted the ppd->nickname member to UTF-8 for us
3856 * (the original attribute value is available separately)
3859 cupsdSetString(&p
->make_model
, ppd
->nickname
);
3861 else if (ppd
->modelname
)
3864 * Model name can only contain specific characters...
3867 cupsdSetString(&p
->make_model
, ppd
->modelname
);
3870 cupsdSetString(&p
->make_model
, "Bad PPD File");
3872 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
3873 "printer-make-and-model", NULL
, p
->make_model
);
3876 * Add media options from the PPD file...
3879 if ((input_slot
= ppdFindOption(ppd
, "InputSlot")) != NULL
)
3880 num_media
= input_slot
->num_choices
;
3884 if ((media_type
= ppdFindOption(ppd
, "MediaType")) != NULL
)
3885 num_media
+= media_type
->num_choices
;
3887 if ((page_size
= ppdFindOption(ppd
, "PageSize")) != NULL
)
3888 num_media
+= page_size
->num_choices
;
3890 if ((media_quality
= ppdFindOption(ppd
, "EFMediaQualityMode")) != NULL
)
3891 num_media
+= media_quality
->num_choices
;
3895 cupsdLogMessage(CUPSD_LOG_CRIT
,
3896 "The PPD file for printer %s contains no media "
3897 "options and is therefore invalid!", p
->name
);
3901 attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3902 "media-supported", num_media
, NULL
, NULL
);
3907 if (input_slot
!= NULL
)
3908 for (i
= 0; i
< input_slot
->num_choices
; i
++, val
++)
3909 val
->string
.text
= _cupsStrAlloc(input_slot
->choices
[i
].choice
);
3911 if (media_type
!= NULL
)
3912 for (i
= 0; i
< media_type
->num_choices
; i
++, val
++)
3913 val
->string
.text
= _cupsStrAlloc(media_type
->choices
[i
].choice
);
3915 if (media_quality
!= NULL
)
3916 for (i
= 0; i
< media_quality
->num_choices
; i
++, val
++)
3917 val
->string
.text
= _cupsStrAlloc(media_quality
->choices
[i
].choice
);
3919 if (page_size
!= NULL
)
3921 for (i
= 0; i
< page_size
->num_choices
; i
++, val
++)
3922 val
->string
.text
= _cupsStrAlloc(page_size
->choices
[i
].choice
);
3924 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3925 "media-default", NULL
, page_size
->defchoice
);
3927 else if (input_slot
!= NULL
)
3928 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3929 "media-default", NULL
, input_slot
->defchoice
);
3930 else if (media_type
!= NULL
)
3931 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3932 "media-default", NULL
, media_type
->defchoice
);
3933 else if (media_quality
!= NULL
)
3934 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3935 "media-default", NULL
, media_quality
->defchoice
);
3937 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3938 "media-default", NULL
, "none");
3946 if ((output_bin
= ppdFindOption(ppd
, "OutputBin")) != NULL
)
3948 attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3949 "output-bin-supported", output_bin
->num_choices
,
3954 for (i
= 0, val
= attr
->values
;
3955 i
< output_bin
->num_choices
;
3957 val
->string
.text
= _cupsStrAlloc(output_bin
->choices
[i
].choice
);
3965 if ((duplex
= ppdFindOption(ppd
, "Duplex")) == NULL
)
3966 if ((duplex
= ppdFindOption(ppd
, "EFDuplex")) == NULL
)
3967 if ((duplex
= ppdFindOption(ppd
, "EFDuplexing")) == NULL
)
3968 if ((duplex
= ppdFindOption(ppd
, "KD03Duplex")) == NULL
)
3969 duplex
= ppdFindOption(ppd
, "JCLDuplex");
3971 if (duplex
&& duplex
->num_choices
> 1 &&
3972 !ppdInstallableConflict(ppd
, duplex
->keyword
, "DuplexTumble"))
3974 p
->type
|= CUPS_PRINTER_DUPLEX
;
3976 ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3977 "sides-supported", 3, NULL
, sides
);
3979 if (!strcasecmp(duplex
->defchoice
, "DuplexTumble"))
3980 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3981 "sides-default", NULL
, "two-sided-short-edge");
3982 else if (!strcasecmp(duplex
->defchoice
, "DuplexNoTumble"))
3983 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3984 "sides-default", NULL
, "two-sided-long-edge");
3986 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3987 "sides-default", NULL
, "one-sided");
3990 if (ppdFindOption(ppd
, "Collate") != NULL
)
3991 p
->type
|= CUPS_PRINTER_COLLATE
;
3993 if (ppdFindOption(ppd
, "StapleLocation") != NULL
)
3995 p
->type
|= CUPS_PRINTER_STAPLE
;
3996 finishings
[num_finishings
++] = IPP_FINISHINGS_STAPLE
;
3999 if (ppdFindOption(ppd
, "BindEdge") != NULL
)
4001 p
->type
|= CUPS_PRINTER_BIND
;
4002 finishings
[num_finishings
++] = IPP_FINISHINGS_BIND
;
4005 for (i
= 0; i
< ppd
->num_sizes
; i
++)
4006 if (ppd
->sizes
[i
].length
> 1728)
4007 p
->type
|= CUPS_PRINTER_LARGE
;
4008 else if (ppd
->sizes
[i
].length
> 1008)
4009 p
->type
|= CUPS_PRINTER_MEDIUM
;
4011 p
->type
|= CUPS_PRINTER_SMALL
;
4014 * Add a filter from application/vnd.cups-raw to printer/name to
4015 * handle "raw" printing by users.
4018 add_string_array(&(p
->filters
), "application/vnd.cups-raw 0 -");
4021 * Add any pre-filters in the PPD file...
4024 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsPreFilter", NULL
)) != NULL
)
4026 for (; ppd_attr
; ppd_attr
= ppdFindNextAttr(ppd
, "cupsPreFilter", NULL
))
4027 if (ppd_attr
->value
)
4028 add_string_array(&(p
->pre_filters
), ppd_attr
->value
);
4032 * Add any filters in the PPD file...
4035 DEBUG_printf(("ppd->num_filters = %d\n", ppd
->num_filters
));
4036 for (i
= 0; i
< ppd
->num_filters
; i
++)
4038 DEBUG_printf(("ppd->filters[%d] = \"%s\"\n", i
, ppd
->filters
[i
]));
4039 add_string_array(&(p
->filters
), ppd
->filters
[i
]);
4042 if (ppd
->num_filters
== 0)
4045 * If there are no filters, add PostScript printing filters.
4048 add_string_array(&(p
->filters
),
4049 "application/vnd.cups-command 0 commandtops");
4050 add_string_array(&(p
->filters
),
4051 "application/vnd.cups-postscript 0 -");
4053 p
->type
|= CUPS_PRINTER_COMMANDS
;
4055 else if (!(p
->type
& CUPS_PRINTER_COMMANDS
))
4058 * See if this is a PostScript device without a command filter...
4061 for (i
= 0; i
< ppd
->num_filters
; i
++)
4062 if (!strncasecmp(ppd
->filters
[i
],
4063 "application/vnd.cups-postscript", 31))
4066 if (i
< ppd
->num_filters
)
4069 * Add the generic PostScript command filter...
4072 add_string_array(&(p
->filters
),
4073 "application/vnd.cups-command 0 commandtops");
4074 p
->type
|= CUPS_PRINTER_COMMANDS
;
4078 if (p
->type
& CUPS_PRINTER_COMMANDS
)
4080 char *commands
, /* Copy of commands */
4081 *start
, /* Start of name */
4082 *end
; /* End of name */
4083 int count
; /* Number of commands */
4086 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsCommands", NULL
)) != NULL
&&
4087 ppd_attr
->value
&& ppd_attr
->value
[0])
4089 for (count
= 0, start
= ppd_attr
->value
; *start
; count
++)
4091 while (isspace(*start
& 255))
4097 while (*start
&& !isspace(*start
& 255))
4107 * Make a copy of the commands string and count how many ...
4110 attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4111 "printer-commands", count
, NULL
, NULL
);
4113 commands
= strdup(ppd_attr
->value
);
4115 for (count
= 0, start
= commands
; *start
; count
++)
4117 while (isspace(*start
& 255))
4124 while (*end
&& !isspace(*end
& 255))
4130 attr
->values
[count
].string
.text
= _cupsStrAlloc(start
);
4140 * Add the standard list of commands...
4143 ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4145 (int)(sizeof(standard_commands
) /
4146 sizeof(standard_commands
[0])), NULL
,
4153 * No commands supported...
4156 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4157 "printer-commands", NULL
, "none");
4161 * Show current and available port monitors for this printer...
4164 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
, "port-monitor",
4165 NULL
, p
->port_monitor
? p
->port_monitor
: "none");
4167 for (i
= 1, ppd_attr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
4169 i
++, ppd_attr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
));
4173 if (strstr(ppd
->protocols
, "TBCP"))
4175 else if (strstr(ppd
->protocols
, "BCP"))
4179 attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
4180 "port-monitor-supported", i
, NULL
, NULL
);
4182 attr
->values
[0].string
.text
= _cupsStrAlloc("none");
4184 for (i
= 1, ppd_attr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
4186 i
++, ppd_attr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
))
4187 attr
->values
[i
].string
.text
= _cupsStrAlloc(ppd_attr
->value
);
4191 if (strstr(ppd
->protocols
, "TBCP"))
4192 attr
->values
[i
].string
.text
= _cupsStrAlloc("tbcp");
4193 else if (strstr(ppd
->protocols
, "BCP"))
4194 attr
->values
[i
].string
.text
= _cupsStrAlloc("bcp");
4198 cupsdSetString(&p
->product
, ppd
->product
);
4199 #endif /* HAVE_DNSSD */
4201 if (ppdFindAttr(ppd
, "APRemoteQueueID", NULL
))
4202 p
->type
|= CUPS_PRINTER_REMOTE
;
4205 * Close the PPD and set the type...
4210 else if (!access(ppd_name
, 0))
4212 int pline
; /* PPD line number */
4213 ppd_status_t pstatus
; /* PPD load status */
4216 pstatus
= ppdLastError(&pline
);
4218 cupsdLogMessage(CUPSD_LOG_ERROR
, "PPD file for %s cannot be loaded!",
4221 if (pstatus
<= PPD_ALLOC_ERROR
)
4222 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s", strerror(errno
));
4224 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s on line %d.",
4225 ppdErrorString(pstatus
), pline
);
4227 cupsdLogMessage(CUPSD_LOG_INFO
,
4228 "Hint: Run \"cupstestppd %s\" and fix any errors.",
4232 * Add a filter from application/vnd.cups-raw to printer/name to
4233 * handle "raw" printing by users.
4236 add_string_array(&(p
->filters
), "application/vnd.cups-raw 0 -");
4239 * Add a PostScript filter, since this is still possibly PS printer.
4242 add_string_array(&(p
->filters
), "application/vnd.cups-postscript 0 -");
4247 * If we have an interface script, add a filter entry for it...
4250 char interface
[1024]; /* Interface script */
4253 snprintf(interface
, sizeof(interface
), "%s/interfaces/%s", ServerRoot
,
4255 if (!access(interface
, X_OK
))
4258 * Yes, we have a System V style interface script; use it!
4261 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
4262 "printer-make-and-model", NULL
,
4263 "Local System V Printer");
4265 snprintf(interface
, sizeof(interface
), "*/* 0 %s/interfaces/%s",
4266 ServerRoot
, p
->name
);
4267 add_string_array(&(p
->filters
), interface
);
4269 else if (!strncmp(p
->device_uri
, "ipp://", 6) &&
4270 (strstr(p
->device_uri
, "/printers/") != NULL
||
4271 strstr(p
->device_uri
, "/classes/") != NULL
||
4272 (strstr(p
->device_uri
, "._ipp.") != NULL
&&
4273 !strcmp(p
->device_uri
+ strlen(p
->device_uri
) - 5,
4277 * Tell the client this is really a hard-wired remote printer.
4280 p
->type
|= CUPS_PRINTER_REMOTE
;
4283 * Point the printer-uri-supported attribute to the
4287 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
4288 "printer-uri-supported", NULL
, p
->device_uri
);
4291 * Then set the make-and-model accordingly...
4294 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
4295 "printer-make-and-model", NULL
, "Remote Printer");
4298 * Print all files directly...
4307 * Otherwise we have neither - treat this as a "dumb" printer
4308 * with no PPD file...
4311 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
4312 "printer-make-and-model", NULL
, "Local Raw Printer");
4318 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
4319 "finishings-supported", num_finishings
, finishings
);
4320 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
4321 "finishings-default", IPP_FINISHINGS_NONE
);
4323 if (ppd
&& (cache
= cupsFileOpen(cache_name
, "w")) != NULL
)
4326 * Save cached PPD attributes to disk...
4329 cupsdLogMessage(CUPSD_LOG_DEBUG
, "load_ppd: Saving %s...", cache_name
);
4331 p
->ppd_attrs
->state
= IPP_IDLE
;
4333 if (ippWriteIO(cache
, (ipp_iocb_t
)cupsFileWrite
, 1, NULL
,
4334 p
->ppd_attrs
) != IPP_DATA
)
4336 cupsdLogMessage(CUPSD_LOG_ERROR
,
4337 "Unable to save PPD cache file \"%s\" - %s", cache_name
,
4342 cupsFileClose(cache
);
4344 else if (cache_info
.st_mtime
)
4347 * Remove cache file...
4357 * 'write_irix_config()' - Update the config files used by the IRIX
4362 write_irix_config(cupsd_printer_t
*p
) /* I - Printer to update */
4364 char filename
[1024]; /* Interface script filename */
4365 cups_file_t
*fp
; /* Interface script file */
4366 ipp_attribute_t
*attr
; /* Attribute data */
4370 * Add dummy interface and GUI scripts to fool SGI's "challenged" printing
4371 * tools. First the interface script that tells the tools what kind of
4372 * printer we have...
4375 snprintf(filename
, sizeof(filename
), "/var/spool/lp/interface/%s", p
->name
);
4377 if (p
->type
& CUPS_PRINTER_CLASS
)
4379 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
4381 cupsFilePuts(fp
, "#!/bin/sh\n");
4383 if ((attr
= ippFindAttribute(p
->attrs
, "printer-make-and-model",
4384 IPP_TAG_TEXT
)) != NULL
)
4385 cupsFilePrintf(fp
, "NAME=\"%s\"\n", attr
->values
[0].string
.text
);
4386 else if (p
->type
& CUPS_PRINTER_CLASS
)
4387 cupsFilePuts(fp
, "NAME=\"Printer Class\"\n");
4389 cupsFilePuts(fp
, "NAME=\"Remote Destination\"\n");
4391 if (p
->type
& CUPS_PRINTER_COLOR
)
4392 cupsFilePuts(fp
, "TYPE=ColorPostScript\n");
4394 cupsFilePuts(fp
, "TYPE=MonoPostScript\n");
4396 cupsFilePrintf(fp
, "HOSTNAME=%s\n", ServerName
);
4397 cupsFilePrintf(fp
, "HOSTPRINTER=%s\n", p
->name
);
4401 chmod(filename
, 0755);
4402 chown(filename
, User
, Group
);
4406 * Then the member file that tells which device file the queue is connected
4407 * to... Networked printers use "/dev/null" in this file, so that's what
4408 * we use (the actual device URI can confuse some apps...)
4411 snprintf(filename
, sizeof(filename
), "/var/spool/lp/member/%s", p
->name
);
4413 if (p
->type
& CUPS_PRINTER_CLASS
)
4415 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
4417 cupsFilePuts(fp
, "/dev/null\n");
4421 chmod(filename
, 0644);
4422 chown(filename
, User
, Group
);
4426 * The gui_interface file is a script or program that launches a GUI
4427 * option panel for the printer, using options specified on the
4428 * command-line in the third argument. The option panel must send
4429 * any printing options to stdout on a single line when the user
4430 * accepts them, or nothing if the user cancels the dialog.
4432 * The default options panel program is /usr/bin/glpoptions, from
4433 * the ESP Print Pro software. You can select another using the
4434 * PrintcapGUI option.
4437 snprintf(filename
, sizeof(filename
), "/var/spool/lp/gui_interface/ELF/%s.gui", p
->name
);
4439 if (p
->type
& CUPS_PRINTER_CLASS
)
4441 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
4443 cupsFilePuts(fp
, "#!/bin/sh\n");
4444 cupsFilePrintf(fp
, "%s -d %s -o \"$3\"\n", PrintcapGUI
, p
->name
);
4448 chmod(filename
, 0755);
4449 chown(filename
, User
, Group
);
4453 * The POD config file is needed by the printstatus command to show
4454 * the printer location and device.
4457 snprintf(filename
, sizeof(filename
), "/var/spool/lp/pod/%s.config", p
->name
);
4459 if (p
->type
& CUPS_PRINTER_CLASS
)
4461 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
4463 cupsFilePrintf(fp
, "Printer Class | %s\n",
4464 (p
->type
& CUPS_PRINTER_COLOR
) ? "ColorPostScript" : "MonoPostScript");
4465 cupsFilePrintf(fp
, "Printer Model | %s\n", p
->make_model
? p
->make_model
: "");
4466 cupsFilePrintf(fp
, "Location Code | %s\n", p
->location
? p
->location
: "");
4467 cupsFilePrintf(fp
, "Physical Location | %s\n", p
->info
? p
->info
: "");
4468 cupsFilePrintf(fp
, "Port Path | %s\n", p
->device_uri
);
4469 cupsFilePrintf(fp
, "Config Path | /var/spool/lp/pod/%s.config\n", p
->name
);
4470 cupsFilePrintf(fp
, "Active Status Path | /var/spool/lp/pod/%s.status\n", p
->name
);
4471 cupsFilePuts(fp
, "Status Update Wait | 10 seconds\n");
4475 chmod(filename
, 0664);
4476 chown(filename
, User
, Group
);
4482 * 'write_irix_state()' - Update the status files used by IRIX printing
4487 write_irix_state(cupsd_printer_t
*p
) /* I - Printer to update */
4489 char filename
[1024]; /* Interface script filename */
4490 cups_file_t
*fp
; /* Interface script file */
4491 int tag
; /* Status tag value */
4497 * The POD status file is needed for the printstatus window to
4498 * provide the current status of the printer.
4501 snprintf(filename
, sizeof(filename
), "/var/spool/lp/pod/%s.status", p
->name
);
4503 if (p
->type
& CUPS_PRINTER_CLASS
)
4505 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
4507 cupsFilePrintf(fp
, "Operational Status | %s\n",
4508 (p
->state
== IPP_PRINTER_IDLE
) ? "Idle" :
4509 (p
->state
== IPP_PRINTER_PROCESSING
) ? "Busy" :
4511 cupsFilePrintf(fp
, "Information | 01 00 00 | %s\n", CUPS_SVERSION
);
4512 cupsFilePrintf(fp
, "Information | 02 00 00 | Device URI: %s\n",
4514 cupsFilePrintf(fp
, "Information | 03 00 00 | %s jobs\n",
4515 p
->accepting
? "Accepting" : "Not accepting");
4516 cupsFilePrintf(fp
, "Information | 04 00 00 | %s\n", p
->state_message
);
4520 chmod(filename
, 0664);
4521 chown(filename
, User
, Group
);
4525 * The activeicons file is needed to provide desktop icons for printers:
4527 * [ quoted from /usr/lib/print/tagit ]
4529 * --- Type of printer tags (base values)
4531 * Dumb=66048 # 0x10200
4532 * DumbColor=66080 # 0x10220
4533 * Raster=66112 # 0x10240
4534 * ColorRaster=66144 # 0x10260
4535 * Plotter=66176 # 0x10280
4536 * PostScript=66208 # 0x102A0
4537 * ColorPostScript=66240 # 0x102C0
4538 * MonoPostScript=66272 # 0x102E0
4540 * --- Printer state modifiers for local printers
4545 * Unknown=3 # 0x3 (Faulted due to unknown reason)
4547 * --- Printer state modifiers for network printers
4551 * NetFaulted=10 # 0xA
4552 * NetUnknown=11 # 0xB (Faulted due to unknown reason)
4555 snprintf(filename
, sizeof(filename
), "/var/spool/lp/activeicons/%s", p
->name
);
4557 if (p
->type
& CUPS_PRINTER_CLASS
)
4559 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
4561 if (p
->type
& CUPS_PRINTER_COLOR
)
4566 if (p
->type
& CUPS_PRINTER_REMOTE
)
4569 if (p
->state
== IPP_PRINTER_PROCESSING
)
4572 else if (p
->state
== IPP_PRINTER_STOPPED
)
4575 cupsFilePuts(fp
, "#!/bin/sh\n");
4576 cupsFilePrintf(fp
, "#Tag %d\n", tag
);
4580 chmod(filename
, 0755);
4581 chown(filename
, User
, Group
);
4586 * The default file is needed by the printers window to show
4587 * the default printer.
4590 snprintf(filename
, sizeof(filename
), "/var/spool/lp/default");
4592 if (DefaultPrinter
!= NULL
)
4594 if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
4596 cupsFilePrintf(fp
, "%s\n", DefaultPrinter
->name
);
4600 chmod(filename
, 0644);
4601 chown(filename
, User
, Group
);
4611 * 'write_xml_string()' - Write a string with XML escaping.
4615 write_xml_string(cups_file_t
*fp
, /* I - File to write to */
4616 const char *s
) /* I - String to write */
4618 const char *start
; /* Start of current sequence */
4624 for (start
= s
; *s
; s
++)
4629 cupsFileWrite(fp
, start
, s
- start
);
4631 cupsFilePuts(fp
, "&");
4637 cupsFileWrite(fp
, start
, s
- start
);
4639 cupsFilePuts(fp
, "<");
4645 cupsFilePuts(fp
, start
);
4650 * End of "$Id: printers.c 7968 2008-09-19 23:03:01Z mike $".