2 * "$Id: printers.c 7879 2008-08-28 00:08:56Z 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 * cupsdSetPrinterAttr() - Set a printer attribute.
31 * cupsdSetPrinterAttrs() - Set printer attributes based upon the PPD
33 * cupsdSetPrinterReasons() - Set/update the reasons strings.
34 * cupsdSetPrinterState() - Update the current state of a printer.
35 * cupsdStopPrinter() - Stop a printer from printing any jobs...
36 * cupsdUpdatePrinters() - Update printers after a partial reload.
37 * cupsdValidateDest() - Validate a printer/class destination.
38 * cupsdWritePrintcap() - Write a pseudo-printcap file for older
39 * applications that need it...
40 * cupsdSanitizeURI() - Sanitize a device URI...
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.
55 * Include necessary headers...
66 static void add_printer_defaults(cupsd_printer_t
*p
);
67 static void add_printer_filter(cupsd_printer_t
*p
, mime_type_t
*type
,
69 static void add_printer_formats(cupsd_printer_t
*p
);
70 static int compare_printers(void *first
, void *second
, void *data
);
71 static void delete_printer_filters(cupsd_printer_t
*p
);
73 static void write_irix_config(cupsd_printer_t
*p
);
74 static void write_irix_state(cupsd_printer_t
*p
);
79 * 'cupsdAddPrinter()' - Add a printer to the system.
82 cupsd_printer_t
* /* O - New printer */
83 cupsdAddPrinter(const char *name
) /* I - Name of printer */
85 cupsd_printer_t
*p
; /* New printer */
89 * Range check input...
92 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdAddPrinter(\"%s\")", name
);
95 * Create a new printer entity...
98 if ((p
= calloc(1, sizeof(cupsd_printer_t
))) == NULL
)
100 cupsdLogMessage(CUPSD_LOG_CRIT
, "Unable to allocate memory for printer - %s",
105 cupsdSetString(&p
->name
, name
);
106 cupsdSetString(&p
->info
, name
);
107 cupsdSetString(&p
->hostname
, ServerName
);
109 cupsdSetStringf(&p
->uri
, "ipp://%s:%d/printers/%s", ServerName
, LocalPort
, name
);
110 cupsdSetStringf(&p
->device_uri
, "file:/dev/null");
112 p
->state
= IPP_PRINTER_STOPPED
;
113 p
->state_time
= time(NULL
);
115 p
->shared
= DefaultShared
;
116 p
->filetype
= mimeAddType(MimeDatabase
, "printer", name
);
118 cupsdSetString(&p
->job_sheets
[0], "none");
119 cupsdSetString(&p
->job_sheets
[1], "none");
121 cupsdSetString(&p
->error_policy
, ErrorPolicy
);
122 cupsdSetString(&p
->op_policy
, DefaultPolicy
);
124 p
->op_policy_ptr
= DefaultPolicyPtr
;
126 if (MaxPrinterHistory
)
127 p
->history
= calloc(MaxPrinterHistory
, sizeof(ipp_t
*));
130 * Insert the printer in the printer list alphabetically...
134 Printers
= cupsArrayNew(compare_printers
, NULL
);
136 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
137 "cupsdAddPrinter: Adding %s to Printers", p
->name
);
138 cupsArrayAdd(Printers
, p
);
140 if (!ImplicitPrinters
)
141 ImplicitPrinters
= cupsArrayNew(compare_printers
, NULL
);
144 * Return the new printer...
152 * 'cupsdAddPrinterHistory()' - Add the current printer state to the history.
156 cupsdAddPrinterHistory(
157 cupsd_printer_t
*p
) /* I - Printer */
159 ipp_t
*history
; /* History collection */
163 * Stop early if we aren't keeping history data...
166 if (MaxPrinterHistory
<= 0)
170 * Retire old history data as needed...
173 p
->sequence_number
++;
175 if (p
->num_history
>= MaxPrinterHistory
)
178 ippDelete(p
->history
[0]);
179 memmove(p
->history
, p
->history
+ 1, p
->num_history
* sizeof(ipp_t
*));
183 * Create a collection containing the current printer-state, printer-up-time,
184 * printer-state-message, and printer-state-reasons attributes.
188 ippAddInteger(history
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-state",
190 ippAddBoolean(history
, IPP_TAG_PRINTER
, "printer-is-accepting-jobs",
192 ippAddBoolean(history
, IPP_TAG_PRINTER
, "printer-is-shared", p
->shared
);
193 ippAddString(history
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-state-message",
194 NULL
, p
->state_message
);
197 ippAddString(history
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
198 "com.apple.print.recoverable-message", NULL
, p
->recoverable
);
199 #endif /* __APPLE__ */
200 if (p
->num_reasons
== 0)
201 ippAddString(history
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
202 "printer-state-reasons", NULL
,
203 p
->state
== IPP_PRINTER_STOPPED
? "paused" : "none");
205 ippAddStrings(history
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
206 "printer-state-reasons", p
->num_reasons
, NULL
,
207 (const char * const *)p
->reasons
);
208 ippAddInteger(history
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
209 "printer-state-change-time", p
->state_time
);
210 ippAddInteger(history
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
211 "printer-state-sequence-number", p
->sequence_number
);
213 p
->history
[p
->num_history
] = history
;
219 * 'cupsdAddPrinterUser()' - Add a user to the ACL.
224 cupsd_printer_t
*p
, /* I - Printer */
225 const char *username
) /* I - User */
227 const char **temp
; /* Temporary array pointer */
233 if (p
->num_users
== 0)
234 temp
= malloc(sizeof(char **));
236 temp
= realloc(p
->users
, sizeof(char **) * (p
->num_users
+ 1));
242 temp
+= p
->num_users
;
244 if ((*temp
= strdup(username
)) != NULL
)
250 * 'cupsdCreateCommonData()' - Create the common printer data.
254 cupsdCreateCommonData(void)
256 int i
; /* Looping var */
257 ipp_attribute_t
*attr
; /* Attribute data */
258 cups_dir_t
*dir
; /* Notifier directory */
259 cups_dentry_t
*dent
; /* Notifier directory entry */
260 cups_array_t
*notifiers
; /* Notifier array */
261 char filename
[1024], /* Filename */
262 *notifier
; /* Current notifier */
263 cupsd_policy_t
*p
; /* Current policy */
264 static const int nups
[] = /* number-up-supported values */
265 { 1, 2, 4, 6, 9, 16 };
266 static const int orients
[4] =/* orientation-requested-supported values */
270 IPP_REVERSE_LANDSCAPE
,
273 static const char * const holds
[] = /* job-hold-until-supported values */
284 static const char * const versions
[] =/* ipp-versions-supported values */
289 static const int ops
[] = /* operations-supported values */
296 IPP_GET_JOB_ATTRIBUTES
,
298 IPP_GET_PRINTER_ATTRIBUTES
,
304 IPP_SET_JOB_ATTRIBUTES
,
305 IPP_CREATE_PRINTER_SUBSCRIPTION
,
306 IPP_CREATE_JOB_SUBSCRIPTION
,
307 IPP_GET_SUBSCRIPTION_ATTRIBUTES
,
308 IPP_GET_SUBSCRIPTIONS
,
309 IPP_RENEW_SUBSCRIPTION
,
310 IPP_CANCEL_SUBSCRIPTION
,
311 IPP_GET_NOTIFICATIONS
,
327 CUPS_AUTHENTICATE_JOB
,
332 static const char * const charsets
[] =/* charset-supported values */
337 static const char * const compressions
[] =
338 { /* document-compression-supported values */
342 #endif /* HAVE_LIBZ */
344 static const char * const multiple_document_handling
[] =
345 { /* multiple-document-handling-supported values */
346 "separate-documents-uncollated-copies",
347 "separate-documents-collated-copies"
349 static const char * const errors
[] = /* printer-error-policy-supported values */
356 static const char * const notify_attrs
[] =
357 { /* notify-attributes-supported values */
358 "printer-state-change-time",
359 "notify-lease-expiration-time",
360 "notify-subscriber-user-name"
362 static const char * const notify_events
[] =
363 { /* notify-events-supported values */
365 "job-config-changed",
372 "printer-config-changed",
374 "printer-finishings-changed",
375 "printer-media-changed",
379 "printer-state-changed",
389 ippDelete(CommonData
);
391 CommonData
= ippNew();
394 * This list of attributes is sorted to improve performance when the
395 * client provides a requested-attributes attribute...
398 /* charset-configured */
399 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_CHARSET
,
400 "charset-configured", NULL
, DefaultCharset
);
402 /* charset-supported */
403 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_CHARSET
,
404 "charset-supported", sizeof(charsets
) / sizeof(charsets
[0]),
407 /* compression-supported */
408 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
409 "compression-supported",
410 sizeof(compressions
) / sizeof(compressions
[0]),
413 /* copies-supported */
414 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "copies-supported", 1, MaxCopies
);
417 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "cups-version",
418 NULL
, CUPS_SVERSION
+ 6);
420 /* generated-natural-language-supported */
421 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_LANGUAGE
,
422 "generated-natural-language-supported", NULL
, DefaultLanguage
);
424 /* ipp-versions-supported */
425 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
426 "ipp-versions-supported", sizeof(versions
) / sizeof(versions
[0]),
429 /* job-hold-until-supported */
430 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
431 "job-hold-until-supported", sizeof(holds
) / sizeof(holds
[0]),
434 /* job-priority-supported */
435 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
436 "job-priority-supported", 100);
438 /* job-sheets-supported */
439 if (cupsArrayCount(Banners
) > 0)
442 * Setup the job-sheets-supported attribute...
445 if (Classification
&& !ClassifyOverride
)
446 attr
= ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
447 "job-sheets-supported", NULL
, Classification
);
449 attr
= ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
450 "job-sheets-supported", cupsArrayCount(Banners
) + 1,
454 cupsdLogMessage(CUPSD_LOG_EMERG
,
455 "Unable to allocate memory for "
456 "job-sheets-supported attribute: %s!", strerror(errno
));
457 else if (!Classification
|| ClassifyOverride
)
459 cupsd_banner_t
*banner
; /* Current banner */
462 attr
->values
[0].string
.text
= _cupsStrAlloc("none");
464 for (i
= 1, banner
= (cupsd_banner_t
*)cupsArrayFirst(Banners
);
466 i
++, banner
= (cupsd_banner_t
*)cupsArrayNext(Banners
))
467 attr
->values
[i
].string
.text
= _cupsStrAlloc(banner
->name
);
471 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
472 "job-sheets-supported", NULL
, "none");
474 /* multiple-document-handling-supported */
475 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
476 "multiple-document-handling-supported",
477 sizeof(multiple_document_handling
) /
478 sizeof(multiple_document_handling
[0]), NULL
,
479 multiple_document_handling
);
481 /* multiple-document-jobs-supported */
482 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
,
483 "multiple-document-jobs-supported", 1);
485 /* multiple-operation-time-out */
486 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
487 "multiple-operation-time-out", 60);
489 /* natural-language-configured */
490 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_LANGUAGE
,
491 "natural-language-configured", NULL
, DefaultLanguage
);
493 /* notify-attributes-supported */
494 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
495 "notify-attributes-supported",
496 (int)(sizeof(notify_attrs
) / sizeof(notify_attrs
[0])),
499 /* notify-lease-duration-supported */
500 ippAddRange(CommonData
, IPP_TAG_PRINTER
,
501 "notify-lease-duration-supported", 0,
502 MaxLeaseDuration
? MaxLeaseDuration
: 2147483647);
504 /* notify-max-events-supported */
505 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
506 "notify-max-events-supported", MaxEvents
);
508 /* notify-events-supported */
509 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
510 "notify-events-supported",
511 (int)(sizeof(notify_events
) / sizeof(notify_events
[0])),
512 NULL
, notify_events
);
514 /* notify-pull-method-supported */
515 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
516 "notify-pull-method-supported", NULL
, "ippget");
518 /* notify-schemes-supported */
519 snprintf(filename
, sizeof(filename
), "%s/notifier", ServerBin
);
520 if ((dir
= cupsDirOpen(filename
)) != NULL
)
522 notifiers
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
524 while ((dent
= cupsDirRead(dir
)) != NULL
)
525 if (S_ISREG(dent
->fileinfo
.st_mode
) &&
526 (dent
->fileinfo
.st_mode
& S_IXOTH
) != 0)
527 cupsArrayAdd(notifiers
, _cupsStrAlloc(dent
->filename
));
529 if (cupsArrayCount(notifiers
) > 0)
531 attr
= ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
532 "notify-schemes-supported",
533 cupsArrayCount(notifiers
), NULL
, NULL
);
535 for (i
= 0, notifier
= (char *)cupsArrayFirst(notifiers
);
537 i
++, notifier
= (char *)cupsArrayNext(notifiers
))
538 attr
->values
[i
].string
.text
= notifier
;
541 cupsArrayDelete(notifiers
);
545 /* number-up-supported */
546 ippAddIntegers(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
547 "number-up-supported", sizeof(nups
) / sizeof(nups
[0]), nups
);
549 /* operations-supported */
550 ippAddIntegers(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
551 "operations-supported",
552 sizeof(ops
) / sizeof(ops
[0]) + JobFiles
- 1, ops
);
554 /* orientation-requested-supported */
555 ippAddIntegers(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
556 "orientation-requested-supported", 4, orients
);
558 /* page-ranges-supported */
559 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
, "page-ranges-supported", 1);
561 /* pdf-override-supported */
562 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
563 "pdl-override-supported", NULL
, "not-attempted");
565 /* printer-error-policy-supported */
566 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
567 "printer-error-policy-supported",
568 sizeof(errors
) / sizeof(errors
[0]), NULL
, errors
);
570 /* printer-op-policy-supported */
571 attr
= ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
572 "printer-op-policy-supported", cupsArrayCount(Policies
),
574 for (i
= 0, p
= (cupsd_policy_t
*)cupsArrayFirst(Policies
);
576 i
++, p
= (cupsd_policy_t
*)cupsArrayNext(Policies
))
577 attr
->values
[i
].string
.text
= _cupsStrAlloc(p
->name
);
579 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
, "server-is-sharing-printers",
580 BrowseLocalProtocols
!= 0 && Browsing
);
585 * 'cupsdDeleteAllPrinters()' - Delete all printers from the system.
589 cupsdDeleteAllPrinters(void)
591 cupsd_printer_t
*p
; /* Pointer to current printer/class */
594 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
596 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
597 if (!(p
->type
& CUPS_PRINTER_CLASS
))
598 cupsdDeletePrinter(p
, 0);
603 * 'cupsdDeletePrinter()' - Delete a printer from the system.
608 cupsd_printer_t
*p
, /* I - Printer to delete */
609 int update
) /* I - Update printers.conf? */
611 int i
; /* Looping var */
613 char filename
[1024]; /* Interface script filename */
617 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdDeletePrinter(p=%p(%s), update=%d)",
621 * Save the current position in the Printers array...
624 cupsArraySave(Printers
);
627 * Stop printing on this printer...
630 cupsdStopPrinter(p
, update
);
633 * If this printer is the next for browsing, point to the next one...
638 cupsArrayFind(Printers
, p
);
639 BrowseNext
= (cupsd_printer_t
*)cupsArrayNext(Printers
);
643 * Remove the printer from the list...
646 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
647 "cupsdDeletePrinter: Removing %s from Printers", p
->name
);
648 cupsArrayRemove(Printers
, p
);
650 if (p
->type
& CUPS_PRINTER_IMPLICIT
)
652 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
653 "cupsdDeletePrinter: Removing %s from ImplicitPrinters",
655 cupsArrayRemove(ImplicitPrinters
, p
);
659 * Remove the dummy interface/icon/option files under IRIX...
663 snprintf(filename
, sizeof(filename
), "/var/spool/lp/interface/%s", p
->name
);
666 snprintf(filename
, sizeof(filename
), "/var/spool/lp/gui_interface/ELF/%s.gui",
670 snprintf(filename
, sizeof(filename
), "/var/spool/lp/activeicons/%s", p
->name
);
673 snprintf(filename
, sizeof(filename
), "/var/spool/lp/pod/%s.config", p
->name
);
676 snprintf(filename
, sizeof(filename
), "/var/spool/lp/pod/%s.status", p
->name
);
679 snprintf(filename
, sizeof(filename
), "/var/spool/lp/member/%s", p
->name
);
684 * If p is the default printer, assign a different one...
687 if (p
== DefaultPrinter
)
689 DefaultPrinter
= NULL
;
691 if (UseNetworkDefault
)
694 * Find the first network default printer and use it...
697 cupsd_printer_t
*dp
; /* New default printer */
700 for (dp
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
702 dp
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
703 if (dp
!= p
&& (dp
->type
& CUPS_PRINTER_DEFAULT
))
712 * Remove this printer from any classes...
715 if (!(p
->type
& CUPS_PRINTER_IMPLICIT
))
717 cupsdDeletePrinterFromClasses(p
);
720 * Deregister from any browse protocols...
723 cupsdDeregisterPrinter(p
, 1);
727 * Free all memory used by the printer...
730 if (p
->printers
!= NULL
)
733 if (MaxPrinterHistory
)
735 for (i
= 0; i
< p
->num_history
; i
++)
736 ippDelete(p
->history
[i
]);
741 for (i
= 0; i
< p
->num_reasons
; i
++)
746 delete_printer_filters(p
);
748 mimeDeleteType(MimeDatabase
, p
->filetype
);
749 mimeDeleteType(MimeDatabase
, p
->prefiltertype
);
751 cupsdFreePrinterUsers(p
);
754 cupsdClearString(&p
->uri
);
755 cupsdClearString(&p
->hostname
);
756 cupsdClearString(&p
->name
);
757 cupsdClearString(&p
->location
);
758 cupsdClearString(&p
->make_model
);
759 cupsdClearString(&p
->info
);
760 cupsdClearString(&p
->job_sheets
[0]);
761 cupsdClearString(&p
->job_sheets
[1]);
762 cupsdClearString(&p
->device_uri
);
763 cupsdClearString(&p
->port_monitor
);
764 cupsdClearString(&p
->op_policy
);
765 cupsdClearString(&p
->error_policy
);
767 cupsdClearString(&p
->alert
);
768 cupsdClearString(&p
->alert_description
);
771 cupsdClearString(&p
->product
);
772 cupsdClearString(&p
->pdl
);
773 #endif /* HAVE_DNSSD */
775 cupsArrayDelete(p
->filetypes
);
778 free(p
->browse_attrs
);
781 cupsdClearString(&p
->recoverable
);
782 #endif /* __APPLE__ */
784 cupsFreeOptions(p
->num_options
, p
->options
);
789 * Restore the previous position in the Printers array...
792 cupsArrayRestore(Printers
);
797 * 'cupsdFindDest()' - Find a destination in the list.
800 cupsd_printer_t
* /* O - Destination in list */
801 cupsdFindDest(const char *name
) /* I - Name of printer or class to find */
803 cupsd_printer_t key
; /* Search key */
806 key
.name
= (char *)name
;
807 return ((cupsd_printer_t
*)cupsArrayFind(Printers
, &key
));
812 * 'cupsdFindPrinter()' - Find a printer in the list.
815 cupsd_printer_t
* /* O - Printer in list */
816 cupsdFindPrinter(const char *name
) /* I - Name of printer to find */
818 cupsd_printer_t
*p
; /* Printer in list */
821 if ((p
= cupsdFindDest(name
)) != NULL
&& (p
->type
& CUPS_PRINTER_CLASS
))
829 * 'cupsdFreePrinterUsers()' - Free allow/deny users.
833 cupsdFreePrinterUsers(
834 cupsd_printer_t
*p
) /* I - Printer */
836 int i
; /* Looping var */
839 if (!p
|| !p
->num_users
)
842 for (i
= 0; i
< p
->num_users
; i
++)
843 free((void *)p
->users
[i
]);
853 * 'cupsdLoadAllPrinters()' - Load printers from the printers.conf file.
857 cupsdLoadAllPrinters(void)
859 cups_file_t
*fp
; /* printers.conf file */
860 int linenum
; /* Current line number */
861 char line
[1024], /* Line from file */
862 *value
, /* Pointer to value */
863 *valueptr
; /* Pointer into value */
864 cupsd_printer_t
*p
; /* Current printer */
868 * Open the printers.conf file...
871 snprintf(line
, sizeof(line
), "%s/printers.conf", ServerRoot
);
872 if ((fp
= cupsFileOpen(line
, "r")) == NULL
)
875 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to open %s - %s", line
,
881 * Read printer configurations until we hit EOF...
887 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
890 * Decode the directive...
893 if (!strcasecmp(line
, "<Printer") ||
894 !strcasecmp(line
, "<DefaultPrinter"))
897 * <Printer name> or <DefaultPrinter name>
900 if (p
== NULL
&& value
)
903 * Add the printer and a base file type...
906 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Loading printer %s...", value
);
908 p
= cupsdAddPrinter(value
);
910 p
->state
= IPP_PRINTER_IDLE
;
913 * Set the default printer as needed...
916 if (!strcasecmp(line
, "<DefaultPrinter"))
921 cupsdLogMessage(CUPSD_LOG_ERROR
,
922 "Syntax error on line %d of printers.conf.", linenum
);
926 else if (!strcasecmp(line
, "</Printer>"))
931 * Close out the current printer...
934 cupsdSetPrinterAttrs(p
);
935 cupsdAddPrinterHistory(p
);
937 if (p
->device_uri
&& strncmp(p
->device_uri
, "file:", 5) &&
938 p
->state
!= IPP_PRINTER_STOPPED
)
941 * See if the backend exists...
944 snprintf(line
, sizeof(line
), "%s/backend/%s", ServerBin
,
947 if ((valueptr
= strchr(line
+ strlen(ServerBin
), ':')) != NULL
)
948 *valueptr
= '\0'; /* Chop everything but URI scheme */
953 * Backend does not exist, stop printer...
956 p
->state
= IPP_PRINTER_STOPPED
;
957 snprintf(p
->state_message
, sizeof(p
->state_message
),
958 "Backend %s does not exist!", line
);
966 cupsdLogMessage(CUPSD_LOG_ERROR
,
967 "Syntax error on line %d of printers.conf.", linenum
);
973 cupsdLogMessage(CUPSD_LOG_ERROR
,
974 "Syntax error on line %d of printers.conf.", linenum
);
977 else if (!strcasecmp(line
, "AuthInfoRequired"))
979 if (!cupsdSetAuthInfoRequired(p
, value
, NULL
))
980 cupsdLogMessage(CUPSD_LOG_ERROR
,
981 "Bad AuthInfoRequired on line %d of printers.conf.",
984 else if (!strcasecmp(line
, "Info"))
987 cupsdSetString(&p
->info
, value
);
989 else if (!strcasecmp(line
, "Location"))
992 cupsdSetString(&p
->location
, value
);
994 else if (!strcasecmp(line
, "DeviceURI"))
997 cupsdSetString(&p
->device_uri
, value
);
1000 cupsdLogMessage(CUPSD_LOG_ERROR
,
1001 "Syntax error on line %d of printers.conf.", linenum
);
1005 else if (!strcasecmp(line
, "Option") && value
)
1011 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1014 cupsdLogMessage(CUPSD_LOG_ERROR
,
1015 "Syntax error on line %d of printers.conf.", linenum
);
1018 for (; *valueptr
&& isspace(*valueptr
& 255); *valueptr
++ = '\0');
1020 p
->num_options
= cupsAddOption(value
, valueptr
, p
->num_options
,
1024 else if (!strcasecmp(line
, "PortMonitor"))
1026 if (value
&& strcmp(value
, "none"))
1027 cupsdSetString(&p
->port_monitor
, value
);
1029 cupsdClearString(&p
->port_monitor
);
1032 cupsdLogMessage(CUPSD_LOG_ERROR
,
1033 "Syntax error on line %d of printers.conf.", linenum
);
1037 else if (!strcasecmp(line
, "State"))
1040 * Set the initial queue state...
1043 if (value
&& !strcasecmp(value
, "idle"))
1044 p
->state
= IPP_PRINTER_IDLE
;
1045 else if (value
&& !strcasecmp(value
, "stopped"))
1046 p
->state
= IPP_PRINTER_STOPPED
;
1049 cupsdLogMessage(CUPSD_LOG_ERROR
,
1050 "Syntax error on line %d of printers.conf.", linenum
);
1054 else if (!strcasecmp(line
, "StateMessage"))
1057 * Set the initial queue state message...
1061 strlcpy(p
->state_message
, value
, sizeof(p
->state_message
));
1063 else if (!strcasecmp(line
, "StateTime"))
1066 * Set the state time...
1070 p
->state_time
= atoi(value
);
1072 else if (!strcasecmp(line
, "Accepting"))
1075 * Set the initial accepting state...
1079 (!strcasecmp(value
, "yes") ||
1080 !strcasecmp(value
, "on") ||
1081 !strcasecmp(value
, "true")))
1084 (!strcasecmp(value
, "no") ||
1085 !strcasecmp(value
, "off") ||
1086 !strcasecmp(value
, "false")))
1090 cupsdLogMessage(CUPSD_LOG_ERROR
,
1091 "Syntax error on line %d of printers.conf.", linenum
);
1095 else if (!strcasecmp(line
, "Shared"))
1098 * Set the initial shared state...
1102 (!strcasecmp(value
, "yes") ||
1103 !strcasecmp(value
, "on") ||
1104 !strcasecmp(value
, "true")))
1107 (!strcasecmp(value
, "no") ||
1108 !strcasecmp(value
, "off") ||
1109 !strcasecmp(value
, "false")))
1113 cupsdLogMessage(CUPSD_LOG_ERROR
,
1114 "Syntax error on line %d of printers.conf.", linenum
);
1118 else if (!strcasecmp(line
, "JobSheets"))
1121 * Set the initial job sheets...
1126 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1131 cupsdSetString(&p
->job_sheets
[0], value
);
1133 while (isspace(*valueptr
& 255))
1138 for (value
= valueptr
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1143 cupsdSetString(&p
->job_sheets
[1], value
);
1148 cupsdLogMessage(CUPSD_LOG_ERROR
,
1149 "Syntax error on line %d of printers.conf.", linenum
);
1153 else if (!strcasecmp(line
, "AllowUser"))
1158 cupsdAddPrinterUser(p
, value
);
1162 cupsdLogMessage(CUPSD_LOG_ERROR
,
1163 "Syntax error on line %d of printers.conf.", linenum
);
1167 else if (!strcasecmp(line
, "DenyUser"))
1172 cupsdAddPrinterUser(p
, value
);
1176 cupsdLogMessage(CUPSD_LOG_ERROR
,
1177 "Syntax error on line %d of printers.conf.", linenum
);
1181 else if (!strcasecmp(line
, "QuotaPeriod"))
1184 p
->quota_period
= atoi(value
);
1187 cupsdLogMessage(CUPSD_LOG_ERROR
,
1188 "Syntax error on line %d of printers.conf.", linenum
);
1192 else if (!strcasecmp(line
, "PageLimit"))
1195 p
->page_limit
= atoi(value
);
1198 cupsdLogMessage(CUPSD_LOG_ERROR
,
1199 "Syntax error on line %d of printers.conf.", linenum
);
1203 else if (!strcasecmp(line
, "KLimit"))
1206 p
->k_limit
= atoi(value
);
1209 cupsdLogMessage(CUPSD_LOG_ERROR
,
1210 "Syntax error on line %d of printers.conf.", linenum
);
1214 else if (!strcasecmp(line
, "OpPolicy"))
1218 cupsd_policy_t
*pol
; /* Policy */
1221 if ((pol
= cupsdFindPolicy(value
)) != NULL
)
1223 cupsdSetString(&p
->op_policy
, value
);
1224 p
->op_policy_ptr
= pol
;
1227 cupsdLogMessage(CUPSD_LOG_ERROR
,
1228 "Bad policy \"%s\" on line %d of printers.conf",
1233 cupsdLogMessage(CUPSD_LOG_ERROR
,
1234 "Syntax error on line %d of printers.conf.", linenum
);
1238 else if (!strcasecmp(line
, "ErrorPolicy"))
1241 cupsdSetString(&p
->error_policy
, value
);
1244 cupsdLogMessage(CUPSD_LOG_ERROR
,
1245 "Syntax error on line %d of printers.conf.", linenum
);
1249 else if (!strcasecmp(line
, "Attribute") && value
)
1251 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1254 cupsdLogMessage(CUPSD_LOG_ERROR
,
1255 "Syntax error on line %d of printers.conf.", linenum
);
1258 for (; *valueptr
&& isspace(*valueptr
& 255); *valueptr
++ = '\0');
1261 cupsdSetPrinterAttrs(p
);
1263 cupsdSetPrinterAttr(p
, value
, valueptr
);
1265 if (!strncmp(value
, "marker-", 7))
1266 p
->marker_time
= time(NULL
);
1272 * Something else we don't understand...
1275 cupsdLogMessage(CUPSD_LOG_ERROR
,
1276 "Unknown configuration directive %s on line %d of printers.conf.",
1286 * 'cupsdRenamePrinter()' - Rename a printer.
1291 cupsd_printer_t
*p
, /* I - Printer */
1292 const char *name
) /* I - New name */
1295 * Remove the printer from the array(s) first...
1298 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1299 "cupsdRenamePrinter: Removing %s from Printers", p
->name
);
1300 cupsArrayRemove(Printers
, p
);
1302 if (p
->type
& CUPS_PRINTER_IMPLICIT
)
1304 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1305 "cupsdRenamePrinter: Removing %s from ImplicitPrinters",
1307 cupsArrayRemove(ImplicitPrinters
, p
);
1311 * Rename the printer type...
1314 mimeDeleteType(MimeDatabase
, p
->filetype
);
1315 p
->filetype
= mimeAddType(MimeDatabase
, "printer", name
);
1317 mimeDeleteType(MimeDatabase
, p
->prefiltertype
);
1318 p
->prefiltertype
= mimeAddType(MimeDatabase
, "prefilter", name
);
1321 * Rename the printer...
1324 cupsdSetString(&p
->name
, name
);
1327 * Reset printer attributes...
1330 cupsdSetPrinterAttrs(p
);
1333 * Add the printer back to the printer array(s)...
1336 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1337 "cupsdRenamePrinter: Adding %s to Printers", p
->name
);
1338 cupsArrayAdd(Printers
, p
);
1340 if (p
->type
& CUPS_PRINTER_IMPLICIT
)
1342 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1343 "cupsdRenamePrinter: Adding %s to ImplicitPrinters",
1345 cupsArrayAdd(ImplicitPrinters
, p
);
1351 * 'cupsdSaveAllPrinters()' - Save all printer definitions to the printers.conf
1356 cupsdSaveAllPrinters(void)
1358 int i
; /* Looping var */
1359 cups_file_t
*fp
; /* printers.conf file */
1360 char temp
[1024]; /* Temporary string */
1361 char backup
[1024]; /* printers.conf.O file */
1362 cupsd_printer_t
*printer
; /* Current printer class */
1363 time_t curtime
; /* Current time */
1364 struct tm
*curdate
; /* Current date */
1365 cups_option_t
*option
; /* Current option */
1366 const char *ptr
; /* Pointer into info/location */
1367 ipp_attribute_t
*marker
; /* Current marker attribute */
1371 * Create the printers.conf file...
1374 snprintf(temp
, sizeof(temp
), "%s/printers.conf", ServerRoot
);
1375 snprintf(backup
, sizeof(backup
), "%s/printers.conf.O", ServerRoot
);
1377 if (rename(temp
, backup
))
1379 if (errno
!= ENOENT
)
1380 cupsdLogMessage(CUPSD_LOG_ERROR
,
1381 "Unable to backup printers.conf - %s", strerror(errno
));
1384 if ((fp
= cupsFileOpen(temp
, "w")) == NULL
)
1386 cupsdLogMessage(CUPSD_LOG_ERROR
,
1387 "Unable to save printers.conf - %s", strerror(errno
));
1389 if (rename(backup
, temp
))
1390 cupsdLogMessage(CUPSD_LOG_ERROR
,
1391 "Unable to restore printers.conf - %s", strerror(errno
));
1395 cupsdLogMessage(CUPSD_LOG_INFO
, "Saving printers.conf...");
1398 * Restrict access to the file...
1401 fchown(cupsFileNumber(fp
), getuid(), Group
);
1402 fchmod(cupsFileNumber(fp
), 0600);
1405 * Write a small header to the file...
1408 curtime
= time(NULL
);
1409 curdate
= localtime(&curtime
);
1410 strftime(temp
, sizeof(temp
) - 1, "%Y-%m-%d %H:%M", curdate
);
1412 cupsFilePuts(fp
, "# Printer configuration file for " CUPS_SVERSION
"\n");
1413 cupsFilePrintf(fp
, "# Written by cupsd on %s\n", temp
);
1416 * Write each local printer known to the system...
1419 for (printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
1421 printer
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
1424 * Skip remote destinations and printer classes...
1427 if ((printer
->type
& CUPS_PRINTER_DISCOVERED
) ||
1428 (printer
->type
& CUPS_PRINTER_CLASS
) ||
1429 (printer
->type
& CUPS_PRINTER_IMPLICIT
))
1433 * Write printers as needed...
1436 if (printer
== DefaultPrinter
)
1437 cupsFilePrintf(fp
, "<DefaultPrinter %s>\n", printer
->name
);
1439 cupsFilePrintf(fp
, "<Printer %s>\n", printer
->name
);
1441 if (printer
->num_auth_info_required
> 0)
1443 cupsFilePrintf(fp
, "AuthInfoRequired %s", printer
->auth_info_required
[0]);
1444 for (i
= 1; i
< printer
->num_auth_info_required
; i
++)
1445 cupsFilePrintf(fp
, ",%s", printer
->auth_info_required
[i
]);
1446 cupsFilePutChar(fp
, '\n');
1451 if ((ptr
= strchr(printer
->info
, '#')) != NULL
)
1454 * Need to quote the first # in the info string...
1457 cupsFilePuts(fp
, "Info ");
1458 cupsFileWrite(fp
, printer
->info
, ptr
- printer
->info
);
1459 cupsFilePutChar(fp
, '\\');
1460 cupsFilePuts(fp
, ptr
);
1461 cupsFilePutChar(fp
, '\n');
1464 cupsFilePrintf(fp
, "Info %s\n", printer
->info
);
1467 if (printer
->location
)
1469 if ((ptr
= strchr(printer
->info
, '#')) != NULL
)
1472 * Need to quote the first # in the location string...
1475 cupsFilePuts(fp
, "Location ");
1476 cupsFileWrite(fp
, printer
->location
, ptr
- printer
->location
);
1477 cupsFilePutChar(fp
, '\\');
1478 cupsFilePuts(fp
, ptr
);
1479 cupsFilePutChar(fp
, '\n');
1482 cupsFilePrintf(fp
, "Location %s\n", printer
->location
);
1484 if (printer
->device_uri
)
1485 cupsFilePrintf(fp
, "DeviceURI %s\n", printer
->device_uri
);
1487 if (printer
->port_monitor
)
1488 cupsFilePrintf(fp
, "PortMonitor %s\n", printer
->port_monitor
);
1490 if (printer
->state
== IPP_PRINTER_STOPPED
)
1492 cupsFilePuts(fp
, "State Stopped\n");
1493 cupsFilePrintf(fp
, "StateMessage %s\n", printer
->state_message
);
1496 cupsFilePuts(fp
, "State Idle\n");
1498 cupsFilePrintf(fp
, "StateTime %d\n", (int)printer
->state_time
);
1500 if (printer
->accepting
)
1501 cupsFilePuts(fp
, "Accepting Yes\n");
1503 cupsFilePuts(fp
, "Accepting No\n");
1505 if (printer
->shared
)
1506 cupsFilePuts(fp
, "Shared Yes\n");
1508 cupsFilePuts(fp
, "Shared No\n");
1510 cupsFilePrintf(fp
, "JobSheets %s %s\n", printer
->job_sheets
[0],
1511 printer
->job_sheets
[1]);
1513 cupsFilePrintf(fp
, "QuotaPeriod %d\n", printer
->quota_period
);
1514 cupsFilePrintf(fp
, "PageLimit %d\n", printer
->page_limit
);
1515 cupsFilePrintf(fp
, "KLimit %d\n", printer
->k_limit
);
1517 for (i
= 0; i
< printer
->num_users
; i
++)
1519 if ((ptr
= strchr(printer
->users
[i
], '#')) != NULL
)
1522 * Need to quote the first # in the user string...
1525 cupsFilePrintf(fp
, "%sUser ", printer
->deny_users
? "Deny" : "Allow");
1526 cupsFileWrite(fp
, printer
->users
[i
], ptr
- printer
->users
[i
]);
1527 cupsFilePutChar(fp
, '\\');
1528 cupsFilePuts(fp
, ptr
);
1529 cupsFilePutChar(fp
, '\n');
1532 cupsFilePrintf(fp
, "%sUser %s\n",
1533 printer
->deny_users
? "Deny" : "Allow",
1537 if (printer
->op_policy
)
1538 cupsFilePrintf(fp
, "OpPolicy %s\n", printer
->op_policy
);
1539 if (printer
->error_policy
)
1540 cupsFilePrintf(fp
, "ErrorPolicy %s\n", printer
->error_policy
);
1542 for (i
= printer
->num_options
, option
= printer
->options
;
1546 if ((ptr
= strchr(option
->value
, '#')) != NULL
)
1549 * Need to quote the first # in the option string...
1552 cupsFilePrintf(fp
, "Option %s ", option
->name
);
1553 cupsFileWrite(fp
, option
->value
, ptr
- option
->value
);
1554 cupsFilePutChar(fp
, '\\');
1555 cupsFilePuts(fp
, ptr
);
1556 cupsFilePutChar(fp
, '\n');
1559 cupsFilePrintf(fp
, "Option %s %s\n", option
->name
, option
->value
);
1562 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-colors",
1563 IPP_TAG_NAME
)) != NULL
)
1565 cupsFilePrintf(fp
, "Attribute %s ", marker
->name
);
1567 for (i
= 0, ptr
= NULL
; i
< marker
->num_values
; i
++)
1570 cupsFilePutChar(fp
, ',');
1572 if (!ptr
&& (ptr
= strchr(marker
->values
[i
].string
.text
, '#')) != NULL
)
1574 cupsFileWrite(fp
, marker
->values
[i
].string
.text
,
1575 ptr
- marker
->values
[i
].string
.text
);
1576 cupsFilePutChar(fp
, '\\');
1577 cupsFilePuts(fp
, ptr
);
1580 cupsFilePuts(fp
, marker
->values
[i
].string
.text
);
1583 cupsFilePuts(fp
, "\n");
1586 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-levels",
1587 IPP_TAG_INTEGER
)) != NULL
)
1589 cupsFilePrintf(fp
, "Attribute %s %d", marker
->name
,
1590 marker
->values
[0].integer
);
1591 for (i
= 1; i
< marker
->num_values
; i
++)
1592 cupsFilePrintf(fp
, ",%d", marker
->values
[i
].integer
);
1593 cupsFilePuts(fp
, "\n");
1596 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-message",
1597 IPP_TAG_TEXT
)) != NULL
)
1599 cupsFilePrintf(fp
, "Attribute %s ", marker
->name
);
1601 if ((ptr
= strchr(marker
->values
[0].string
.text
, '#')) != NULL
)
1603 cupsFileWrite(fp
, marker
->values
[0].string
.text
,
1604 ptr
- marker
->values
[0].string
.text
);
1605 cupsFilePutChar(fp
, '\\');
1606 cupsFilePuts(fp
, ptr
);
1609 cupsFilePuts(fp
, marker
->values
[0].string
.text
);
1611 cupsFilePuts(fp
, "\n");
1614 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-names",
1615 IPP_TAG_NAME
)) != NULL
)
1617 cupsFilePrintf(fp
, "Attribute %s ", marker
->name
);
1619 for (i
= 0, ptr
= NULL
; i
< marker
->num_values
; i
++)
1622 cupsFilePutChar(fp
, ',');
1624 if (!ptr
&& (ptr
= strchr(marker
->values
[i
].string
.text
, '#')) != NULL
)
1626 cupsFileWrite(fp
, marker
->values
[i
].string
.text
,
1627 ptr
- marker
->values
[i
].string
.text
);
1628 cupsFilePutChar(fp
, '\\');
1629 cupsFilePuts(fp
, ptr
);
1632 cupsFilePuts(fp
, marker
->values
[i
].string
.text
);
1635 cupsFilePuts(fp
, "\n");
1638 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-types",
1639 IPP_TAG_KEYWORD
)) != NULL
)
1641 cupsFilePrintf(fp
, "Attribute %s ", marker
->name
);
1643 for (i
= 0, ptr
= NULL
; i
< marker
->num_values
; i
++)
1646 cupsFilePutChar(fp
, ',');
1648 if (!ptr
&& (ptr
= strchr(marker
->values
[i
].string
.text
, '#')) != NULL
)
1650 cupsFileWrite(fp
, marker
->values
[i
].string
.text
,
1651 ptr
- marker
->values
[i
].string
.text
);
1652 cupsFilePutChar(fp
, '\\');
1653 cupsFilePuts(fp
, ptr
);
1656 cupsFilePuts(fp
, marker
->values
[i
].string
.text
);
1659 cupsFilePuts(fp
, "\n");
1662 cupsFilePuts(fp
, "</Printer>\n");
1666 * Make IRIX desktop & printer status happy
1669 write_irix_state(printer
);
1678 * 'cupsdSetAuthInfoRequired()' - Set the required authentication info.
1681 int /* O - 1 if value OK, 0 otherwise */
1682 cupsdSetAuthInfoRequired(
1683 cupsd_printer_t
*p
, /* I - Printer */
1684 const char *values
, /* I - Plain text value (or NULL) */
1685 ipp_attribute_t
*attr
) /* I - IPP attribute value (or NULL) */
1687 int i
; /* Looping var */
1690 p
->num_auth_info_required
= 0;
1693 * Do we have a plain text value?
1699 * Yes, grab the keywords...
1702 const char *end
; /* End of current value */
1705 while (*values
&& p
->num_auth_info_required
< 4)
1707 if ((end
= strchr(values
, ',')) == NULL
)
1708 end
= values
+ strlen(values
);
1710 if ((end
- values
) == 4 && !strncmp(values
, "none", 4))
1712 if (p
->num_auth_info_required
!= 0 || *end
)
1715 p
->auth_info_required
[p
->num_auth_info_required
] = "none";
1716 p
->num_auth_info_required
++;
1720 else if ((end
- values
) == 9 && !strncmp(values
, "negotiate", 9))
1722 if (p
->num_auth_info_required
!= 0 || *end
)
1725 p
->auth_info_required
[p
->num_auth_info_required
] = "negotiate";
1726 p
->num_auth_info_required
++;
1728 else if ((end
- values
) == 6 && !strncmp(values
, "domain", 6))
1730 p
->auth_info_required
[p
->num_auth_info_required
] = "domain";
1731 p
->num_auth_info_required
++;
1733 else if ((end
- values
) == 8 && !strncmp(values
, "password", 8))
1735 p
->auth_info_required
[p
->num_auth_info_required
] = "password";
1736 p
->num_auth_info_required
++;
1738 else if ((end
- values
) == 8 && !strncmp(values
, "username", 8))
1740 p
->auth_info_required
[p
->num_auth_info_required
] = "username";
1741 p
->num_auth_info_required
++;
1746 values
= (*end
) ? end
+ 1 : end
;
1749 if (p
->num_auth_info_required
== 0)
1751 p
->auth_info_required
[0] = "none";
1752 p
->num_auth_info_required
= 1;
1756 * Update the printer-type value as needed...
1759 if (p
->num_auth_info_required
> 1 ||
1760 strcmp(p
->auth_info_required
[0], "none"))
1761 p
->type
|= CUPS_PRINTER_AUTHENTICATED
;
1763 p
->type
&= ~CUPS_PRINTER_AUTHENTICATED
;
1769 * Grab values from an attribute instead...
1772 if (!attr
|| attr
->num_values
> 4)
1776 * Update the printer-type value as needed...
1779 if (attr
->num_values
> 1 ||
1780 strcmp(attr
->values
[0].string
.text
, "none"))
1781 p
->type
|= CUPS_PRINTER_AUTHENTICATED
;
1783 p
->type
&= ~CUPS_PRINTER_AUTHENTICATED
;
1785 for (i
= 0; i
< attr
->num_values
; i
++)
1787 if (!strcmp(attr
->values
[i
].string
.text
, "none"))
1789 if (p
->num_auth_info_required
!= 0 || attr
->num_values
!= 1)
1792 p
->auth_info_required
[p
->num_auth_info_required
] = "none";
1793 p
->num_auth_info_required
++;
1797 else if (!strcmp(attr
->values
[i
].string
.text
, "negotiate"))
1799 if (p
->num_auth_info_required
!= 0 || attr
->num_values
!= 1)
1802 p
->auth_info_required
[p
->num_auth_info_required
] = "negotiate";
1803 p
->num_auth_info_required
++;
1807 else if (!strcmp(attr
->values
[i
].string
.text
, "domain"))
1809 p
->auth_info_required
[p
->num_auth_info_required
] = "domain";
1810 p
->num_auth_info_required
++;
1812 else if (!strcmp(attr
->values
[i
].string
.text
, "password"))
1814 p
->auth_info_required
[p
->num_auth_info_required
] = "password";
1815 p
->num_auth_info_required
++;
1817 else if (!strcmp(attr
->values
[i
].string
.text
, "username"))
1819 p
->auth_info_required
[p
->num_auth_info_required
] = "username";
1820 p
->num_auth_info_required
++;
1831 * 'cupsdSetPrinterAttr()' - Set a printer attribute.
1835 cupsdSetPrinterAttr(
1836 cupsd_printer_t
*p
, /* I - Printer */
1837 const char *name
, /* I - Attribute name */
1838 char *value
) /* I - Attribute value string */
1840 ipp_attribute_t
*attr
; /* Attribute */
1841 int i
, /* Looping var */
1842 count
; /* Number of values */
1843 char *ptr
; /* Pointer into value */
1844 ipp_tag_t value_tag
; /* Value tag for this attribute */
1848 * Count the number of values...
1851 for (count
= 1, ptr
= value
;
1852 (ptr
= strchr(ptr
, ',')) != NULL
;
1856 * Then add or update the attribute as needed...
1859 if (!strcmp(name
, "marker-levels"))
1865 if ((attr
= ippFindAttribute(p
->attrs
, name
, IPP_TAG_INTEGER
)) != NULL
&&
1866 attr
->num_values
< count
)
1868 ippDeleteAttribute(p
->attrs
, attr
);
1873 attr
->num_values
= count
;
1875 attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
, name
,
1880 cupsdLogMessage(CUPSD_LOG_ERROR
,
1881 "Unable to allocate memory for printer attribute "
1882 "(%d values)", count
);
1886 for (i
= 0; i
< count
; i
++)
1888 if ((ptr
= strchr(value
, ',')) != NULL
)
1891 attr
->values
[i
].integer
= strtol(value
, NULL
, 10);
1900 * Name or keyword values...
1903 if (!strcmp(name
, "marker-types"))
1904 value_tag
= IPP_TAG_KEYWORD
;
1905 else if (!strcmp(name
, "marker-message"))
1906 value_tag
= IPP_TAG_TEXT
;
1908 value_tag
= IPP_TAG_NAME
;
1910 if ((attr
= ippFindAttribute(p
->attrs
, name
, value_tag
)) != NULL
&&
1911 attr
->num_values
< count
)
1913 ippDeleteAttribute(p
->attrs
, attr
);
1919 for (i
= 0; i
< attr
->num_values
; i
++)
1920 _cupsStrFree(attr
->values
[i
].string
.text
);
1922 attr
->num_values
= count
;
1925 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, value_tag
, name
,
1930 cupsdLogMessage(CUPSD_LOG_ERROR
,
1931 "Unable to allocate memory for printer attribute "
1932 "(%d values)", count
);
1936 for (i
= 0; i
< count
; i
++)
1938 if ((ptr
= strchr(value
, ',')) != NULL
)
1941 attr
->values
[i
].string
.text
= _cupsStrAlloc(value
);
1948 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
1953 * 'cupsdSetPrinterAttrs()' - Set printer attributes based upon the PPD file.
1957 cupsdSetPrinterAttrs(cupsd_printer_t
*p
)/* I - Printer to setup */
1959 int i
, /* Looping var */
1960 length
; /* Length of browse attributes */
1961 char uri
[HTTP_MAX_URI
]; /* URI for printer */
1962 char resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
1963 char filename
[1024]; /* Name of PPD file */
1964 int num_air
; /* Number of auth-info-required values */
1965 const char * const *air
; /* auth-info-required values */
1966 int num_media
; /* Number of media options */
1967 cupsd_location_t
*auth
; /* Pointer to authentication element */
1968 const char *auth_supported
; /* Authentication supported */
1969 ppd_file_t
*ppd
; /* PPD file data */
1970 ppd_option_t
*input_slot
, /* InputSlot options */
1971 *media_type
, /* MediaType options */
1972 *page_size
, /* PageSize options */
1973 *output_bin
, /* OutputBin options */
1974 *media_quality
, /* EFMediaQualityMode options */
1975 *duplex
; /* Duplex options */
1976 ppd_attr_t
*ppdattr
; /* PPD attribute */
1977 ipp_t
*oldattrs
; /* Old printer attributes */
1978 ipp_attribute_t
*attr
; /* Attribute data */
1979 ipp_value_t
*val
; /* Attribute value */
1980 int num_finishings
; /* Number of finishings */
1981 int finishings
[5]; /* finishings-supported values */
1982 cups_option_t
*option
; /* Current printer option */
1983 static const char * const sides
[3] = /* sides-supported values */
1986 "two-sided-long-edge",
1987 "two-sided-short-edge"
1989 static const char * const air_userpass
[] =
1990 { /* Basic/Digest authentication */
1995 static const char * const air_negotiate
[] =
1996 { /* Kerberos authentication */
1999 #endif /* HAVE_GSSAPI */
2000 static const char * const air_none
[] =
2001 { /* No authentication */
2004 static const char * const standard_commands
[] =
2005 { /* Standard CUPS commands */
2008 "PrintSelfTestPage",
2013 DEBUG_printf(("cupsdSetPrinterAttrs: entering name = %s, type = %x\n", p
->name
,
2017 * Make sure that we have the common attributes defined...
2021 cupsdCreateCommonData();
2024 * Clear out old filters, if any...
2027 delete_printer_filters(p
);
2030 * Figure out the authentication that is required for the printer.
2033 auth_supported
= "requesting-user-name";
2037 if (p
->num_auth_info_required
> 0 && strcmp(p
->auth_info_required
[0], "none"))
2039 num_air
= p
->num_auth_info_required
;
2040 air
= p
->auth_info_required
;
2042 if (!strcmp(air
[0], "username"))
2043 auth_supported
= "basic";
2045 auth_supported
= "negotiate";
2047 else if (!(p
->type
& CUPS_PRINTER_DISCOVERED
))
2049 if (p
->type
& CUPS_PRINTER_CLASS
)
2050 snprintf(resource
, sizeof(resource
), "/classes/%s", p
->name
);
2052 snprintf(resource
, sizeof(resource
), "/printers/%s", p
->name
);
2054 if ((auth
= cupsdFindBest(resource
, HTTP_POST
)) == NULL
||
2055 auth
->type
== CUPSD_AUTH_NONE
)
2056 auth
= cupsdFindPolicyOp(p
->op_policy_ptr
, IPP_PRINT_JOB
);
2060 int auth_type
; /* Authentication type */
2063 if ((auth_type
= auth
->type
) == CUPSD_AUTH_DEFAULT
)
2064 auth_type
= DefaultAuthType
;
2066 if (auth_type
== CUPSD_AUTH_BASIC
|| auth_type
== CUPSD_AUTH_BASICDIGEST
)
2068 auth_supported
= "basic";
2072 else if (auth_type
== CUPSD_AUTH_DIGEST
)
2074 auth_supported
= "digest";
2079 else if (auth_type
== CUPSD_AUTH_NEGOTIATE
)
2081 auth_supported
= "negotiate";
2083 air
= air_negotiate
;
2085 #endif /* HAVE_GSSAPI */
2087 if (auth_type
!= CUPSD_AUTH_NONE
)
2088 p
->type
|= CUPS_PRINTER_AUTHENTICATED
;
2090 p
->type
&= ~CUPS_PRINTER_AUTHENTICATED
;
2093 p
->type
&= ~CUPS_PRINTER_AUTHENTICATED
;
2095 else if (p
->type
& CUPS_PRINTER_AUTHENTICATED
)
2102 * Create the required IPP attributes for a printer...
2105 oldattrs
= p
->attrs
;
2106 p
->attrs
= ippNew();
2108 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2109 "uri-authentication-supported", NULL
, auth_supported
);
2110 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2111 "uri-security-supported", NULL
, "none");
2112 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
, "printer-name", NULL
,
2114 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-location",
2115 NULL
, p
->location
? p
->location
: "");
2116 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-info",
2117 NULL
, p
->info
? p
->info
: "");
2118 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "printer-more-info",
2124 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2125 "requesting-user-name-denied", p
->num_users
, NULL
,
2128 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2129 "requesting-user-name-allowed", p
->num_users
, NULL
,
2133 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2134 "job-quota-period", p
->quota_period
);
2135 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2136 "job-k-limit", p
->k_limit
);
2137 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2138 "job-page-limit", p
->page_limit
);
2139 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2140 "auth-info-required", num_air
, NULL
, air
);
2142 if (cupsArrayCount(Banners
) > 0 && !(p
->type
& CUPS_PRINTER_DISCOVERED
))
2145 * Setup the job-sheets-default attribute...
2148 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2149 "job-sheets-default", 2, NULL
, NULL
);
2153 attr
->values
[0].string
.text
= _cupsStrAlloc(Classification
?
2154 Classification
: p
->job_sheets
[0]);
2155 attr
->values
[1].string
.text
= _cupsStrAlloc(Classification
?
2156 Classification
: p
->job_sheets
[1]);
2163 if (p
->type
& CUPS_PRINTER_DISCOVERED
)
2166 * Tell the client this is a remote printer of some type...
2169 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
2170 "printer-uri-supported", NULL
, p
->uri
);
2173 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
2174 "printer-make-and-model", NULL
, p
->make_model
);
2176 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "device-uri", NULL
,
2185 * Assign additional attributes depending on whether this is a printer
2189 p
->type
&= ~CUPS_PRINTER_OPTIONS
;
2191 if (p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
))
2196 * Add class-specific attributes...
2199 if ((p
->type
& CUPS_PRINTER_IMPLICIT
) && p
->num_printers
> 0 &&
2200 p
->printers
[0]->make_model
)
2201 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
2202 "printer-make-and-model", NULL
, p
->printers
[0]->make_model
);
2204 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
2205 "printer-make-and-model", NULL
, "Local Printer Class");
2207 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "device-uri", NULL
,
2208 "file:///dev/null");
2210 if (p
->num_printers
> 0)
2213 * Add a list of member names; URIs are added in copy_printer_attrs...
2216 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2217 "member-names", p
->num_printers
, NULL
, NULL
);
2218 p
->type
|= CUPS_PRINTER_OPTIONS
;
2220 for (i
= 0; i
< p
->num_printers
; i
++)
2223 attr
->values
[i
].string
.text
= _cupsStrAlloc(p
->printers
[i
]->name
);
2225 p
->type
&= ~CUPS_PRINTER_OPTIONS
| p
->printers
[i
]->type
;
2232 * Add printer-specific attributes... Start by sanitizing the device
2233 * URI so it doesn't have a username or password in it...
2237 strcpy(uri
, "file:/dev/null");
2238 else if (strstr(p
->device_uri
, "://") != NULL
)
2241 * http://..., ipp://..., etc.
2244 cupsdSanitizeURI(p
->device_uri
, uri
, sizeof(uri
));
2249 * file:..., serial:..., etc.
2252 strlcpy(uri
, p
->device_uri
, sizeof(uri
));
2255 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "device-uri", NULL
,
2259 * Assign additional attributes from the PPD file (if any)...
2262 p
->type
|= CUPS_PRINTER_BW
;
2263 finishings
[0] = IPP_FINISHINGS_NONE
;
2266 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
2269 if ((ppd
= ppdOpenFile(filename
)) != NULL
)
2272 * Add make/model and other various attributes...
2275 if (ppd
->color_device
)
2276 p
->type
|= CUPS_PRINTER_COLOR
;
2277 if (ppd
->variable_sizes
)
2278 p
->type
|= CUPS_PRINTER_VARIABLE
;
2279 if (!ppd
->manual_copies
)
2280 p
->type
|= CUPS_PRINTER_COPIES
;
2281 if ((ppdattr
= ppdFindAttr(ppd
, "cupsFax", NULL
)) != NULL
)
2282 if (ppdattr
->value
&& !strcasecmp(ppdattr
->value
, "true"))
2283 p
->type
|= CUPS_PRINTER_FAX
;
2285 ippAddBoolean(p
->attrs
, IPP_TAG_PRINTER
, "color-supported",
2287 if (ppd
->throughput
)
2288 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2289 "pages-per-minute", ppd
->throughput
);
2294 * The NickName can be localized in the character set specified
2295 * by the LanugageEncoding attribute. However, ppdOpen2() has
2296 * already converted the ppd->nickname member to UTF-8 for us
2297 * (the original attribute value is available separately)
2300 cupsdSetString(&p
->make_model
, ppd
->nickname
);
2302 else if (ppd
->modelname
)
2305 * Model name can only contain specific characters...
2308 cupsdSetString(&p
->make_model
, ppd
->modelname
);
2311 cupsdSetString(&p
->make_model
, "Bad PPD File");
2313 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
2314 "printer-make-and-model", NULL
, p
->make_model
);
2317 * Add media options from the PPD file...
2320 if ((input_slot
= ppdFindOption(ppd
, "InputSlot")) != NULL
)
2321 num_media
= input_slot
->num_choices
;
2325 if ((media_type
= ppdFindOption(ppd
, "MediaType")) != NULL
)
2326 num_media
+= media_type
->num_choices
;
2328 if ((page_size
= ppdFindOption(ppd
, "PageSize")) != NULL
)
2329 num_media
+= page_size
->num_choices
;
2331 if ((media_quality
= ppdFindOption(ppd
, "EFMediaQualityMode")) != NULL
)
2332 num_media
+= media_quality
->num_choices
;
2336 cupsdLogMessage(CUPSD_LOG_CRIT
,
2337 "The PPD file for printer %s contains no media "
2338 "options and is therefore invalid!", p
->name
);
2342 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2343 "media-supported", num_media
, NULL
, NULL
);
2348 if (input_slot
!= NULL
)
2349 for (i
= 0; i
< input_slot
->num_choices
; i
++, val
++)
2350 val
->string
.text
= _cupsStrAlloc(input_slot
->choices
[i
].choice
);
2352 if (media_type
!= NULL
)
2353 for (i
= 0; i
< media_type
->num_choices
; i
++, val
++)
2354 val
->string
.text
= _cupsStrAlloc(media_type
->choices
[i
].choice
);
2356 if (media_quality
!= NULL
)
2357 for (i
= 0; i
< media_quality
->num_choices
; i
++, val
++)
2358 val
->string
.text
= _cupsStrAlloc(media_quality
->choices
[i
].choice
);
2360 if (page_size
!= NULL
)
2362 for (i
= 0; i
< page_size
->num_choices
; i
++, val
++)
2363 val
->string
.text
= _cupsStrAlloc(page_size
->choices
[i
].choice
);
2365 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2366 "media-default", NULL
, page_size
->defchoice
);
2368 else if (input_slot
!= NULL
)
2369 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2370 "media-default", NULL
, input_slot
->defchoice
);
2371 else if (media_type
!= NULL
)
2372 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2373 "media-default", NULL
, media_type
->defchoice
);
2374 else if (media_quality
!= NULL
)
2375 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2376 "media-default", NULL
, media_quality
->defchoice
);
2378 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2379 "media-default", NULL
, "none");
2387 if ((output_bin
= ppdFindOption(ppd
, "OutputBin")) != NULL
)
2389 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2390 "output-bin-supported", output_bin
->num_choices
,
2395 for (i
= 0, val
= attr
->values
;
2396 i
< output_bin
->num_choices
;
2398 val
->string
.text
= _cupsStrAlloc(output_bin
->choices
[i
].choice
);
2406 if ((duplex
= ppdFindOption(ppd
, "Duplex")) == NULL
)
2407 if ((duplex
= ppdFindOption(ppd
, "EFDuplex")) == NULL
)
2408 if ((duplex
= ppdFindOption(ppd
, "EFDuplexing")) == NULL
)
2409 if ((duplex
= ppdFindOption(ppd
, "KD03Duplex")) == NULL
)
2410 duplex
= ppdFindOption(ppd
, "JCLDuplex");
2412 if (duplex
&& duplex
->num_choices
> 1 &&
2413 !ppdInstallableConflict(ppd
, duplex
->keyword
, "DuplexTumble"))
2415 p
->type
|= CUPS_PRINTER_DUPLEX
;
2417 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2418 "sides-supported", 3, NULL
, sides
);
2420 if (!strcasecmp(duplex
->defchoice
, "DuplexTumble"))
2421 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2422 "sides-default", NULL
, "two-sided-short-edge");
2423 else if (!strcasecmp(duplex
->defchoice
, "DuplexNoTumble"))
2424 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2425 "sides-default", NULL
, "two-sided-long-edge");
2427 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2428 "sides-default", NULL
, "one-sided");
2431 if (ppdFindOption(ppd
, "Collate") != NULL
)
2432 p
->type
|= CUPS_PRINTER_COLLATE
;
2434 if (ppdFindOption(ppd
, "StapleLocation") != NULL
)
2436 p
->type
|= CUPS_PRINTER_STAPLE
;
2437 finishings
[num_finishings
++] = IPP_FINISHINGS_STAPLE
;
2440 if (ppdFindOption(ppd
, "BindEdge") != NULL
)
2442 p
->type
|= CUPS_PRINTER_BIND
;
2443 finishings
[num_finishings
++] = IPP_FINISHINGS_BIND
;
2446 for (i
= 0; i
< ppd
->num_sizes
; i
++)
2447 if (ppd
->sizes
[i
].length
> 1728)
2448 p
->type
|= CUPS_PRINTER_LARGE
;
2449 else if (ppd
->sizes
[i
].length
> 1008)
2450 p
->type
|= CUPS_PRINTER_MEDIUM
;
2452 p
->type
|= CUPS_PRINTER_SMALL
;
2455 * Add a filter from application/vnd.cups-raw to printer/name to
2456 * handle "raw" printing by users.
2459 add_printer_filter(p
, p
->filetype
, "application/vnd.cups-raw 0 -");
2462 * Add any pre-filters in the PPD file...
2465 if ((ppdattr
= ppdFindAttr(ppd
, "cupsPreFilter", NULL
)) != NULL
)
2467 p
->prefiltertype
= mimeAddType(MimeDatabase
, "prefilter", p
->name
);
2469 for (; ppdattr
; ppdattr
= ppdFindNextAttr(ppd
, "cupsPreFilter", NULL
))
2471 add_printer_filter(p
, p
->prefiltertype
, ppdattr
->value
);
2475 * Add any filters in the PPD file...
2478 DEBUG_printf(("ppd->num_filters = %d\n", ppd
->num_filters
));
2479 for (i
= 0; i
< ppd
->num_filters
; i
++)
2481 DEBUG_printf(("ppd->filters[%d] = \"%s\"\n", i
, ppd
->filters
[i
]));
2482 add_printer_filter(p
, p
->filetype
, ppd
->filters
[i
]);
2485 if (ppd
->num_filters
== 0)
2488 * If there are no filters, add PostScript printing filters.
2491 add_printer_filter(p
, p
->filetype
,
2492 "application/vnd.cups-command 0 commandtops");
2493 add_printer_filter(p
, p
->filetype
,
2494 "application/vnd.cups-postscript 0 -");
2496 p
->type
|= CUPS_PRINTER_COMMANDS
;
2498 else if (!(p
->type
& CUPS_PRINTER_COMMANDS
))
2501 * See if this is a PostScript device without a command filter...
2504 for (i
= 0; i
< ppd
->num_filters
; i
++)
2505 if (!strncasecmp(ppd
->filters
[i
],
2506 "application/vnd.cups-postscript", 31))
2509 if (i
< ppd
->num_filters
)
2512 * Add the generic PostScript command filter...
2515 add_printer_filter(p
, p
->filetype
,
2516 "application/vnd.cups-command 0 commandtops");
2517 p
->type
|= CUPS_PRINTER_COMMANDS
;
2521 if (p
->type
& CUPS_PRINTER_COMMANDS
)
2523 char *commands
, /* Copy of commands */
2524 *start
, /* Start of name */
2525 *end
; /* End of name */
2526 int count
; /* Number of commands */
2529 if ((ppdattr
= ppdFindAttr(ppd
, "cupsCommands", NULL
)) != NULL
&&
2530 ppdattr
->value
&& ppdattr
->value
[0])
2532 for (count
= 0, start
= ppdattr
->value
; *start
; count
++)
2534 while (isspace(*start
& 255))
2540 while (*start
&& !isspace(*start
& 255))
2550 * Make a copy of the commands string and count how many ...
2553 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2554 "printer-commands", count
, NULL
, NULL
);
2556 commands
= strdup(ppdattr
->value
);
2558 for (count
= 0, start
= commands
; *start
; count
++)
2560 while (isspace(*start
& 255))
2567 while (*end
&& !isspace(*end
& 255))
2573 attr
->values
[count
].string
.text
= _cupsStrAlloc(start
);
2583 * Add the standard list of commands...
2586 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2588 (int)(sizeof(standard_commands
) /
2589 sizeof(standard_commands
[0])), NULL
,
2596 * No commands supported...
2599 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2600 "printer-commands", NULL
, "none");
2604 * Show current and available port monitors for this printer...
2607 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
, "port-monitor",
2608 NULL
, p
->port_monitor
? p
->port_monitor
: "none");
2610 for (i
= 1, ppdattr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
2612 i
++, ppdattr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
));
2616 if (strstr(ppd
->protocols
, "TBCP"))
2618 else if (strstr(ppd
->protocols
, "BCP"))
2622 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2623 "port-monitor-supported", i
, NULL
, NULL
);
2625 attr
->values
[0].string
.text
= _cupsStrAlloc("none");
2627 for (i
= 1, ppdattr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
2629 i
++, ppdattr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
))
2630 attr
->values
[i
].string
.text
= _cupsStrAlloc(ppdattr
->value
);
2634 if (strstr(ppd
->protocols
, "TBCP"))
2635 attr
->values
[i
].string
.text
= _cupsStrAlloc("tbcp");
2636 else if (strstr(ppd
->protocols
, "BCP"))
2637 attr
->values
[i
].string
.text
= _cupsStrAlloc("bcp");
2641 cupsdSetString(&p
->product
, ppd
->product
);
2642 #endif /* HAVE_DNSSD */
2644 if (ppdFindAttr(ppd
, "APRemoteQueueID", NULL
))
2645 p
->type
|= CUPS_PRINTER_REMOTE
;
2648 * Close the PPD and set the type...
2653 else if (!access(filename
, 0))
2655 int pline
; /* PPD line number */
2656 ppd_status_t pstatus
; /* PPD load status */
2659 pstatus
= ppdLastError(&pline
);
2661 cupsdLogMessage(CUPSD_LOG_ERROR
, "PPD file for %s cannot be loaded!",
2664 if (pstatus
<= PPD_ALLOC_ERROR
)
2665 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s", strerror(errno
));
2667 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s on line %d.",
2668 ppdErrorString(pstatus
), pline
);
2670 cupsdLogMessage(CUPSD_LOG_INFO
,
2671 "Hint: Run \"cupstestppd %s\" and fix any errors.",
2675 * Add a filter from application/vnd.cups-raw to printer/name to
2676 * handle "raw" printing by users.
2679 add_printer_filter(p
, p
->filetype
, "application/vnd.cups-raw 0 -");
2682 * Add a PostScript filter, since this is still possibly PS printer.
2685 add_printer_filter(p
, p
->filetype
,
2686 "application/vnd.cups-postscript 0 -");
2691 * If we have an interface script, add a filter entry for it...
2694 snprintf(filename
, sizeof(filename
), "%s/interfaces/%s", ServerRoot
,
2696 if (!access(filename
, X_OK
))
2699 * Yes, we have a System V style interface script; use it!
2702 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
2703 "printer-make-and-model", NULL
,
2704 "Local System V Printer");
2706 snprintf(filename
, sizeof(filename
), "*/* 0 %s/interfaces/%s",
2707 ServerRoot
, p
->name
);
2708 add_printer_filter(p
, p
->filetype
, filename
);
2710 else if (p
->device_uri
&&
2711 !strncmp(p
->device_uri
, "ipp://", 6) &&
2712 (strstr(p
->device_uri
, "/printers/") != NULL
||
2713 strstr(p
->device_uri
, "/classes/") != NULL
))
2716 * Tell the client this is really a hard-wired remote printer.
2719 p
->type
|= CUPS_PRINTER_REMOTE
;
2722 * Point the printer-uri-supported attribute to the
2726 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
2727 "printer-uri-supported", NULL
, p
->device_uri
);
2730 * Then set the make-and-model accordingly...
2733 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
2734 "printer-make-and-model", NULL
, "Remote Printer");
2737 * Print all files directly...
2746 * Otherwise we have neither - treat this as a "dumb" printer
2747 * with no PPD file...
2750 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
2751 "printer-make-and-model", NULL
, "Local Raw Printer");
2757 ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
2758 "finishings-supported", num_finishings
, finishings
);
2759 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
2760 "finishings-default", IPP_FINISHINGS_NONE
);
2765 * Copy marker attributes as needed...
2770 ipp_attribute_t
*oldattr
; /* Old attribute */
2773 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-colors",
2774 IPP_TAG_NAME
)) != NULL
)
2776 if ((attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2777 "marker-colors", oldattr
->num_values
, NULL
,
2780 for (i
= 0; i
< oldattr
->num_values
; i
++)
2781 attr
->values
[i
].string
.text
=
2782 _cupsStrAlloc(oldattr
->values
[i
].string
.text
);
2786 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-levels",
2787 IPP_TAG_INTEGER
)) != NULL
)
2789 if ((attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2790 "marker-levels", oldattr
->num_values
,
2793 for (i
= 0; i
< oldattr
->num_values
; i
++)
2794 attr
->values
[i
].integer
= oldattr
->values
[i
].integer
;
2798 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-names",
2799 IPP_TAG_NAME
)) != NULL
)
2801 if ((attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2802 "marker-names", oldattr
->num_values
, NULL
,
2805 for (i
= 0; i
< oldattr
->num_values
; i
++)
2806 attr
->values
[i
].string
.text
=
2807 _cupsStrAlloc(oldattr
->values
[i
].string
.text
);
2811 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-types",
2812 IPP_TAG_KEYWORD
)) != NULL
)
2814 if ((attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2815 "marker-types", oldattr
->num_values
, NULL
,
2818 for (i
= 0; i
< oldattr
->num_values
; i
++)
2819 attr
->values
[i
].string
.text
=
2820 _cupsStrAlloc(oldattr
->values
[i
].string
.text
);
2824 ippDelete(oldattrs
);
2828 * Force sharing off for remote queues...
2831 if (p
->type
& (CUPS_PRINTER_REMOTE
| CUPS_PRINTER_IMPLICIT
))
2836 * Copy the printer options into a browse attributes string we can re-use.
2839 const char *valptr
; /* Pointer into value */
2840 char *attrptr
; /* Pointer into attribute string */
2844 * Free the old browse attributes as needed...
2847 if (p
->browse_attrs
)
2848 free(p
->browse_attrs
);
2851 * Compute the length of all attributes + job-sheets, lease-duration,
2852 * and BrowseLocalOptions.
2855 for (length
= 1, i
= p
->num_options
, option
= p
->options
;
2859 length
+= strlen(option
->name
) + 2;
2863 for (valptr
= option
->value
; *valptr
; valptr
++)
2864 if (strchr(" \"\'\\", *valptr
))
2871 length
+= 13 + strlen(p
->job_sheets
[0]) + strlen(p
->job_sheets
[1]);
2873 if (BrowseLocalOptions
)
2874 length
+= 12 + strlen(BrowseLocalOptions
);
2876 if (p
->num_auth_info_required
> 0)
2878 length
+= 18; /* auth-info-required */
2880 for (i
= 0; i
< p
->num_auth_info_required
; i
++)
2881 length
+= strlen(p
->auth_info_required
[i
]) + 1;
2885 * Allocate the new string...
2888 if ((p
->browse_attrs
= calloc(1, length
)) == NULL
)
2889 cupsdLogMessage(CUPSD_LOG_ERROR
,
2890 "Unable to allocate %d bytes for browse data!",
2895 * Got the allocated string, now copy the options and attributes over...
2898 sprintf(p
->browse_attrs
, "job-sheets=%s,%s lease-duration=%d",
2899 p
->job_sheets
[0], p
->job_sheets
[1], BrowseTimeout
);
2900 attrptr
= p
->browse_attrs
+ strlen(p
->browse_attrs
);
2902 if (BrowseLocalOptions
)
2904 sprintf(attrptr
, " ipp-options=%s", BrowseLocalOptions
);
2905 attrptr
+= strlen(attrptr
);
2908 for (i
= p
->num_options
, option
= p
->options
;
2913 strcpy(attrptr
, option
->name
);
2914 attrptr
+= strlen(attrptr
);
2920 for (valptr
= option
->value
; *valptr
; valptr
++)
2922 if (strchr(" \"\'\\", *valptr
))
2925 *attrptr
++ = *valptr
;
2930 if (p
->num_auth_info_required
> 0)
2932 strcpy(attrptr
, "auth-info-required");
2935 for (i
= 0; i
< p
->num_auth_info_required
; i
++)
2937 *attrptr
++ = i
? ',' : '=';
2938 strcpy(attrptr
, p
->auth_info_required
[i
]);
2939 attrptr
+= strlen(attrptr
);
2948 * Populate the document-format-supported attribute...
2951 add_printer_formats(p
);
2953 DEBUG_printf(("cupsdSetPrinterAttrs: leaving name = %s, type = %x\n", p
->name
,
2957 * Add name-default attributes...
2960 add_printer_defaults(p
);
2964 * Write the IRIX printer config and status files...
2967 write_irix_config(p
);
2968 write_irix_state(p
);
2972 * Let the browse protocols reflect the change
2975 cupsdRegisterPrinter(p
);
2980 * 'cupsdSetPrinterReasons()' - Set/update the reasons strings.
2984 cupsdSetPrinterReasons(
2985 cupsd_printer_t
*p
, /* I - Printer */
2986 const char *s
) /* I - Reasons strings */
2988 int i
; /* Looping var */
2989 const char *sptr
; /* Pointer into reasons */
2990 char reason
[255], /* Reason string */
2991 *rptr
; /* Pointer into reason */
2994 if (s
[0] == '-' || s
[0] == '+')
2997 * Add/remove reasons...
3005 * Replace reasons...
3010 for (i
= 0; i
< p
->num_reasons
; i
++)
3011 free(p
->reasons
[i
]);
3016 if (!strcmp(s
, "none"))
3020 * Loop through all of the reasons...
3026 * Skip leading whitespace and commas...
3029 while (isspace(*sptr
& 255) || *sptr
== ',')
3032 for (rptr
= reason
; *sptr
&& !isspace(*sptr
& 255) && *sptr
!= ','; sptr
++)
3033 if (rptr
< (reason
+ sizeof(reason
) - 1))
3047 for (i
= 0; i
< p
->num_reasons
; i
++)
3048 if (!strcasecmp(reason
, p
->reasons
[i
]))
3051 * Found a match, so remove it...
3055 free(p
->reasons
[i
]);
3057 if (i
< p
->num_reasons
)
3058 memmove(p
->reasons
+ i
, p
->reasons
+ i
+ 1,
3059 (p
->num_reasons
- i
) * sizeof(char *));
3063 if (!strcmp(reason
, "paused") && p
->state
== IPP_PRINTER_STOPPED
)
3064 cupsdSetPrinterState(p
, IPP_PRINTER_IDLE
, 1);
3067 else if (p
->num_reasons
< (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
3073 for (i
= 0; i
< p
->num_reasons
; i
++)
3074 if (!strcasecmp(reason
, p
->reasons
[i
]))
3077 if (i
>= p
->num_reasons
)
3079 p
->reasons
[i
] = strdup(reason
);
3082 if (!strcmp(reason
, "paused") && p
->state
!= IPP_PRINTER_STOPPED
)
3083 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, 1);
3091 * 'cupsdSetPrinterState()' - Update the current state of a printer.
3095 cupsdSetPrinterState(
3096 cupsd_printer_t
*p
, /* I - Printer to change */
3097 ipp_pstate_t s
, /* I - New state */
3098 int update
) /* I - Update printers.conf? */
3100 ipp_pstate_t old_state
; /* Old printer state */
3104 * Can't set status of remote printers...
3107 if (p
->type
& CUPS_PRINTER_DISCOVERED
)
3111 * Set the new state...
3114 old_state
= p
->state
;
3119 cupsdAddEvent(s
== IPP_PRINTER_STOPPED
? CUPSD_EVENT_PRINTER_STOPPED
:
3120 CUPSD_EVENT_PRINTER_STATE
, p
, NULL
,
3121 "%s \"%s\" state changed.",
3122 (p
->type
& CUPS_PRINTER_CLASS
) ? "Class" : "Printer",
3126 * Let the browse code know this needs to be updated...
3130 p
->state_time
= time(NULL
);
3134 write_irix_state(p
);
3138 cupsdAddPrinterHistory(p
);
3141 * Let the browse protocols reflect the change...
3145 cupsdRegisterPrinter(p
);
3148 * Save the printer configuration if a printer goes from idle or processing
3149 * to stopped (or visa-versa)...
3152 if ((old_state
== IPP_PRINTER_STOPPED
) != (s
== IPP_PRINTER_STOPPED
) &&
3155 if (p
->type
& CUPS_PRINTER_CLASS
)
3156 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
3158 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
3164 * 'cupsdStopPrinter()' - Stop a printer from printing any jobs...
3168 cupsdStopPrinter(cupsd_printer_t
*p
, /* I - Printer to stop */
3169 int update
)/* I - Update printers.conf? */
3171 cupsd_job_t
*job
; /* Active print job */
3175 * Set the printer state...
3178 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, update
);
3181 * See if we have a job printing on this printer...
3187 * Get pointer to job...
3190 job
= (cupsd_job_t
*)p
->job
;
3196 cupsdStopJob(job
, 0);
3199 * Reset the state to pending...
3202 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
3203 job
->state_value
= IPP_JOB_PENDING
;
3206 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
3208 cupsdAddEvent(CUPSD_EVENT_JOB_STOPPED
, p
, job
,
3209 "Job stopped due to printer being paused");
3215 * 'cupsdUpdatePrinterPPD()' - Update keywords in a printer's PPD file.
3218 int /* O - 1 if successful, 0 otherwise */
3219 cupsdUpdatePrinterPPD(
3220 cupsd_printer_t
*p
, /* I - Printer */
3221 int num_keywords
, /* I - Number of keywords */
3222 cups_option_t
*keywords
) /* I - Keywords */
3224 int i
; /* Looping var */
3225 cups_file_t
*src
, /* Original file */
3226 *dst
; /* New file */
3227 char srcfile
[1024], /* Original filename */
3228 dstfile
[1024], /* New filename */
3229 line
[1024], /* Line from file */
3230 keystring
[41]; /* Keyword from line */
3231 cups_option_t
*keyword
; /* Current keyword */
3234 cupsdLogMessage(CUPSD_LOG_INFO
, "Updating keywords in PPD file for %s...",
3238 * Get the old and new PPD filenames...
3241 snprintf(srcfile
, sizeof(srcfile
), "%s/ppd/%s.ppd.O", ServerRoot
, p
->name
);
3242 snprintf(dstfile
, sizeof(srcfile
), "%s/ppd/%s.ppd", ServerRoot
, p
->name
);
3245 * Rename the old file and open the old and new...
3248 if (rename(dstfile
, srcfile
))
3250 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to backup PPD file for %s: %s",
3251 p
->name
, strerror(errno
));
3255 if ((src
= cupsFileOpen(srcfile
, "r")) == NULL
)
3257 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to open PPD file \"%s\": %s",
3258 srcfile
, strerror(errno
));
3259 rename(srcfile
, dstfile
);
3263 if ((dst
= cupsFileOpen(dstfile
, "w")) == NULL
)
3265 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to create PPD file \"%s\": %s",
3266 dstfile
, strerror(errno
));
3268 rename(srcfile
, dstfile
);
3273 * Copy the first line and then write out all of the keywords...
3276 if (!cupsFileGets(src
, line
, sizeof(line
)))
3278 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to read PPD file \"%s\": %s",
3279 srcfile
, strerror(errno
));
3282 rename(srcfile
, dstfile
);
3286 cupsFilePrintf(dst
, "%s\n", line
);
3288 for (i
= num_keywords
, keyword
= keywords
; i
> 0; i
--, keyword
++)
3290 cupsdLogMessage(CUPSD_LOG_DEBUG
, "*%s: %s", keyword
->name
, keyword
->value
);
3291 cupsFilePrintf(dst
, "*%s: %s\n", keyword
->name
, keyword
->value
);
3295 * Then copy the rest of the PPD file, dropping any keywords we changed.
3298 while (cupsFileGets(src
, line
, sizeof(line
)))
3301 * Skip keywords we've already set...
3304 if (sscanf(line
, "*%40[^:]:", keystring
) == 1 &&
3305 cupsGetOption(keystring
, num_keywords
, keywords
))
3309 * Otherwise write the line...
3312 cupsFilePrintf(dst
, "%s\n", line
);
3316 * Close files and return...
3327 * 'cupsdUpdatePrinters()' - Update printers after a partial reload.
3331 cupsdUpdatePrinters(void)
3333 cupsd_printer_t
*p
; /* Current printer */
3337 * Loop through the printers and recreate the printer attributes
3338 * for any local printers since the policy and/or access control
3339 * stuff may have changed. Also, if browsing is disabled, remove
3340 * any remote printers...
3343 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3345 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3348 * Remove remote printers if we are no longer browsing...
3352 (p
->type
& (CUPS_PRINTER_IMPLICIT
| CUPS_PRINTER_DISCOVERED
)))
3354 if (p
->type
& CUPS_PRINTER_IMPLICIT
)
3355 cupsArrayRemove(ImplicitPrinters
, p
);
3357 cupsArraySave(Printers
);
3358 cupsdDeletePrinter(p
, 0);
3359 cupsArrayRestore(Printers
);
3364 * Update the operation policy pointer...
3367 if ((p
->op_policy_ptr
= cupsdFindPolicy(p
->op_policy
)) == NULL
)
3368 p
->op_policy_ptr
= DefaultPolicyPtr
;
3371 * Update printer attributes as needed...
3374 if (!(p
->type
& CUPS_PRINTER_DISCOVERED
))
3375 cupsdSetPrinterAttrs(p
);
3381 * 'cupsdValidateDest()' - Validate a printer/class destination.
3384 const char * /* O - Printer or class name */
3386 const char *uri
, /* I - Printer URI */
3387 cups_ptype_t
*dtype
, /* O - Type (printer or class) */
3388 cupsd_printer_t
**printer
) /* O - Printer pointer */
3390 cupsd_printer_t
*p
; /* Current printer */
3391 char localname
[1024],/* Localized hostname */
3392 *lptr
, /* Pointer into localized hostname */
3393 *sptr
, /* Pointer into server name */
3394 *rptr
, /* Pointer into resource */
3395 scheme
[32], /* Scheme portion of URI */
3396 username
[64], /* Username portion of URI */
3397 hostname
[HTTP_MAX_HOST
],
3398 /* Host portion of URI */
3399 resource
[HTTP_MAX_URI
];
3400 /* Resource portion of URI */
3401 int port
; /* Port portion of URI */
3404 DEBUG_printf(("cupsdValidateDest(uri=\"%s\", dtype=%p, printer=%p)\n", uri
,
3408 * Initialize return values...
3415 *dtype
= (cups_ptype_t
)0;
3418 * Pull the hostname and resource from the URI...
3421 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
, scheme
, sizeof(scheme
),
3422 username
, sizeof(username
), hostname
, sizeof(hostname
),
3423 &port
, resource
, sizeof(resource
));
3426 * See if the resource is a class or printer...
3429 if (!strncmp(resource
, "/classes/", 9))
3435 rptr
= resource
+ 9;
3437 else if (!strncmp(resource
, "/printers/", 10))
3443 rptr
= resource
+ 10;
3448 * Bad resource name...
3455 * See if the printer or class name exists...
3458 p
= cupsdFindDest(rptr
);
3460 if (p
== NULL
&& strchr(rptr
, '@') == NULL
)
3468 *dtype
= p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
|
3469 CUPS_PRINTER_REMOTE
| CUPS_PRINTER_DISCOVERED
);
3475 * Change localhost to the server name...
3478 if (!strcasecmp(hostname
, "localhost"))
3479 strlcpy(hostname
, ServerName
, sizeof(hostname
));
3481 strlcpy(localname
, hostname
, sizeof(localname
));
3483 if (!strcasecmp(hostname
, ServerName
))
3486 * Localize the hostname...
3489 lptr
= strchr(localname
, '.');
3490 sptr
= strchr(ServerName
, '.');
3492 if (sptr
!= NULL
&& lptr
!= NULL
)
3495 * Strip the common domain name components...
3498 while (lptr
!= NULL
)
3500 if (!strcasecmp(lptr
, sptr
))
3506 lptr
= strchr(lptr
+ 1, '.');
3511 DEBUG_printf(("localized hostname is \"%s\"...\n", localname
));
3514 * Find a matching printer or class...
3517 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3519 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3520 if (!strcasecmp(p
->hostname
, localname
) &&
3521 !strcasecmp(p
->name
, rptr
))
3527 *dtype
= p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
|
3528 CUPS_PRINTER_REMOTE
| CUPS_PRINTER_DISCOVERED
);
3538 * 'cupsdWritePrintcap()' - Write a pseudo-printcap file for older applications
3543 cupsdWritePrintcap(void)
3545 cups_file_t
*fp
; /* printcap file */
3546 cupsd_printer_t
*p
; /* Current printer */
3551 * Update the IRIX printer state for the default printer; if
3552 * no printers remain, then the default printer file will be
3556 write_irix_state(DefaultPrinter
);
3560 * See if we have a printcap file; if not, don't bother writing it.
3563 if (!Printcap
|| !*Printcap
)
3567 * Open the printcap file...
3570 if ((fp
= cupsFileOpen(Printcap
, "w")) == NULL
)
3574 * Put a comment header at the top so that users will know where the
3575 * data has come from...
3579 "# This file was automatically generated by cupsd(8) from the\n");
3580 cupsFilePrintf(fp
, "# %s/printers.conf file. All changes to this file\n",
3582 cupsFilePuts(fp
, "# will be lost.\n");
3587 * Write a new printcap with the current list of printers.
3590 switch (PrintcapFormat
)
3594 * Each printer is put in the file as:
3604 cupsFilePrintf(fp
, "%s|%s:rm=%s:rp=%s:\n", DefaultPrinter
->name
,
3605 DefaultPrinter
->info
, ServerName
,
3606 DefaultPrinter
->name
);
3608 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3610 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3611 if (p
!= DefaultPrinter
)
3612 cupsFilePrintf(fp
, "%s|%s:rm=%s:rp=%s:\n", p
->name
, p
->info
,
3613 ServerName
, p
->name
);
3616 case PRINTCAP_SOLARIS
:
3618 * Each printer is put in the file as:
3620 * _all:all=Printer1,Printer2,Printer3,...,PrinterN
3621 * _default:use=DefaultPrinter
3623 * :bsdaddr=ServerName,Printer1:\
3624 * :description=Description:
3626 * :bsdaddr=ServerName,Printer2:\
3627 * :description=Description:
3629 * :bsdaddr=ServerName,Printer3:\
3630 * :description=Description:
3633 * :bsdaddr=ServerName,PrinterN:\
3634 * :description=Description:
3637 cupsFilePuts(fp
, "_all:all=");
3638 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3640 p
= (cupsd_printer_t
*)cupsArrayCurrent(Printers
))
3641 cupsFilePrintf(fp
, "%s%c", p
->name
,
3642 cupsArrayNext(Printers
) ? ',' : '\n');
3645 cupsFilePrintf(fp
, "_default:use=%s\n", DefaultPrinter
->name
);
3647 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3649 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3650 cupsFilePrintf(fp
, "%s:\\\n"
3651 "\t:bsdaddr=%s,%s:\\\n"
3652 "\t:description=%s:\n",
3653 p
->name
, ServerName
, p
->name
,
3654 p
->info
? p
->info
: "");
3668 * 'cupsdSanitizeURI()' - Sanitize a device URI...
3671 char * /* O - New device URI */
3672 cupsdSanitizeURI(const char *uri
, /* I - Original device URI */
3673 char *buffer
, /* O - New device URI */
3674 int buflen
) /* I - Size of new device URI buffer */
3676 char *start
, /* Start of data after scheme */
3677 *slash
, /* First slash after scheme:// */
3678 *ptr
; /* Pointer into user@host:port part */
3682 * Range check input...
3685 if (!uri
|| !buffer
|| buflen
< 2)
3689 * Copy the device URI to the new buffer...
3692 strlcpy(buffer
, uri
, buflen
);
3695 * Find the end of the scheme:// part...
3698 if ((ptr
= strchr(buffer
, ':')) == NULL
)
3699 return (buffer
); /* No scheme: part... */
3701 for (start
= ptr
+ 1; *start
; start
++)
3706 * Find the next slash (/) in the URI...
3709 if ((slash
= strchr(start
, '/')) == NULL
)
3710 slash
= start
+ strlen(start
); /* No slash, point to the end */
3713 * Check for an @ sign before the slash...
3716 if ((ptr
= strchr(start
, '@')) != NULL
&& ptr
< slash
)
3719 * Found an @ sign and it is before the resource part, so we have
3720 * an authentication string. Copy the remaining URI over the
3721 * authentication string...
3724 _cups_strcpy(start
, ptr
+ 1);
3728 * Return the new device URI...
3736 * 'add_printer_defaults()' - Add name-default attributes to the printer attributes.
3740 add_printer_defaults(cupsd_printer_t
*p
)/* I - Printer */
3742 int i
; /* Looping var */
3743 int num_options
; /* Number of default options */
3744 cups_option_t
*options
, /* Default options */
3745 *option
; /* Current option */
3746 char name
[256]; /* name-default */
3750 * Maintain a common array of default attribute names...
3753 if (!CommonDefaults
)
3755 CommonDefaults
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
3757 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("copies-default"));
3758 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("document-format-default"));
3759 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("finishings-default"));
3760 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-hold-until-default"));
3761 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-priority-default"));
3762 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-sheets-default"));
3763 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("media-default"));
3764 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("number-up-default"));
3765 cupsArrayAdd(CommonDefaults
,
3766 _cupsStrAlloc("orientation-requested-default"));
3767 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("sides-default"));
3771 * Add all of the default options from the .conf files...
3774 for (num_options
= 0, options
= NULL
, i
= p
->num_options
, option
= p
->options
;
3778 if (strcmp(option
->name
, "ipp-options") &&
3779 strcmp(option
->name
, "job-sheets") &&
3780 strcmp(option
->name
, "lease-duration"))
3782 snprintf(name
, sizeof(name
), "%s-default", option
->name
);
3783 num_options
= cupsAddOption(name
, option
->value
, num_options
, &options
);
3785 if (!cupsArrayFind(CommonDefaults
, name
))
3786 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc(name
));
3791 * Convert options to IPP attributes...
3794 cupsEncodeOptions2(p
->attrs
, num_options
, options
, IPP_TAG_PRINTER
);
3795 cupsFreeOptions(num_options
, options
);
3798 * Add standard -default attributes as needed...
3801 if (!cupsGetOption("copies", p
->num_options
, p
->options
))
3802 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
, "copies-default",
3805 if (!cupsGetOption("document-format", p
->num_options
, p
->options
))
3806 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_MIMETYPE
,
3807 "document-format-default", NULL
, "application/octet-stream");
3809 if (!cupsGetOption("job-hold-until", p
->num_options
, p
->options
))
3810 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3811 "job-hold-until-default", NULL
, "no-hold");
3813 if (!cupsGetOption("job-priority", p
->num_options
, p
->options
))
3814 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3815 "job-priority-default", 50);
3817 if (!cupsGetOption("number-up", p
->num_options
, p
->options
))
3818 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3819 "number-up-default", 1);
3821 if (!cupsGetOption("orientation-requested", p
->num_options
, p
->options
))
3822 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NOVALUE
,
3823 "orientation-requested-default", NULL
, NULL
);
3825 if (!cupsGetOption("notify-lease-duration", p
->num_options
, p
->options
))
3826 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3827 "notify-lease-duration-default", DefaultLeaseDuration
);
3829 if (!cupsGetOption("notify-events", p
->num_options
, p
->options
))
3830 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3831 "notify-events-default", NULL
, "job-completed");
3836 * 'add_printer_filter()' - Add a MIME filter for a printer.
3841 cupsd_printer_t
*p
, /* I - Printer to add to */
3842 mime_type_t
*filtertype
, /* I - Filter or prefilter MIME type */
3843 const char *filter
) /* I - Filter to add */
3845 char super
[MIME_MAX_SUPER
], /* Super-type for filter */
3846 type
[MIME_MAX_TYPE
], /* Type for filter */
3847 program
[1024]; /* Program/filter name */
3848 int cost
; /* Cost of filter */
3849 mime_type_t
*temptype
; /* MIME type looping var */
3850 char filename
[1024]; /* Full filter filename */
3854 * Parse the filter string; it should be in the following format:
3856 * super/type cost program
3859 if (sscanf(filter
, "%15[^/]/%31s%d%*[ \t]%1023[^\n]", super
, type
, &cost
,
3862 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: invalid filter string \"%s\"!",
3868 * See if the filter program exists; if not, stop the printer and flag
3872 if (strcmp(program
, "-"))
3874 if (program
[0] == '/')
3875 strlcpy(filename
, program
, sizeof(filename
));
3877 snprintf(filename
, sizeof(filename
), "%s/filter/%s", ServerBin
, program
);
3879 if (access(filename
, X_OK
))
3881 snprintf(p
->state_message
, sizeof(p
->state_message
),
3882 "Filter \"%s\" for printer \"%s\" not available: %s",
3883 program
, p
->name
, strerror(errno
));
3884 cupsdSetPrinterReasons(p
, "+cups-missing-filter-error");
3885 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, 0);
3887 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s", p
->state_message
);
3892 * Mark the CUPS_PRINTER_COMMANDS bit if we have a filter for
3893 * application/vnd.cups-command...
3896 if (!strcasecmp(super
, "application") &&
3897 !strcasecmp(type
, "vnd.cups-command"))
3898 p
->type
|= CUPS_PRINTER_COMMANDS
;
3901 * Add the filter to the MIME database, supporting wildcards as needed...
3904 for (temptype
= mimeFirstType(MimeDatabase
);
3906 temptype
= mimeNextType(MimeDatabase
))
3907 if (((super
[0] == '*' && strcasecmp(temptype
->super
, "printer")) ||
3908 !strcasecmp(temptype
->super
, super
)) &&
3909 (type
[0] == '*' || !strcasecmp(temptype
->type
, type
)))
3911 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3912 "add_printer_filter: %s: adding filter %s/%s %s/%s %d %s",
3913 p
->name
, temptype
->super
, temptype
->type
,
3914 filtertype
->super
, filtertype
->type
,
3916 mimeAddFilter(MimeDatabase
, temptype
, filtertype
, cost
, program
);
3922 * 'add_printer_formats()' - Add document-format-supported values for a printer.
3926 add_printer_formats(cupsd_printer_t
*p
) /* I - Printer */
3928 int i
; /* Looping var */
3929 mime_type_t
*type
; /* Current MIME type */
3930 cups_array_t
*filters
; /* Filters */
3931 ipp_attribute_t
*attr
; /* document-format-supported attribute */
3932 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
3933 /* MIME type name */
3937 * Raw (and remote) queues advertise all of the supported MIME
3941 cupsArrayDelete(p
->filetypes
);
3942 p
->filetypes
= NULL
;
3946 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
,
3947 (ipp_tag_t
)(IPP_TAG_MIMETYPE
| IPP_TAG_COPY
),
3948 "document-format-supported", NumMimeTypes
, NULL
, MimeTypes
);
3953 * Otherwise, loop through the supported MIME types and see if there
3954 * are filters for them...
3957 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_printer_formats: %d types, %d filters",
3958 mimeNumTypes(MimeDatabase
), mimeNumFilters(MimeDatabase
));
3960 p
->filetypes
= cupsArrayNew(NULL
, NULL
);
3962 for (type
= mimeFirstType(MimeDatabase
);
3964 type
= mimeNextType(MimeDatabase
))
3966 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
3968 if ((filters
= mimeFilter(MimeDatabase
, type
, p
->filetype
, NULL
)) != NULL
)
3970 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3971 "add_printer_formats: %s: %s needs %d filters",
3972 p
->name
, mimetype
, cupsArrayCount(filters
));
3974 cupsArrayDelete(filters
);
3975 cupsArrayAdd(p
->filetypes
, type
);
3978 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3979 "add_printer_formats: %s: %s not supported",
3983 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3984 "add_printer_formats: %s: %d supported types",
3985 p
->name
, cupsArrayCount(p
->filetypes
) + 1);
3988 * Add the file formats that can be filtered...
3991 if ((type
= mimeType(MimeDatabase
, "application", "octet-stream")) == NULL
||
3992 !cupsArrayFind(p
->filetypes
, type
))
3997 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_MIMETYPE
,
3998 "document-format-supported",
3999 cupsArrayCount(p
->filetypes
) + 1, NULL
, NULL
);
4002 attr
->values
[0].string
.text
= _cupsStrAlloc("application/octet-stream");
4004 for (type
= (mime_type_t
*)cupsArrayFirst(p
->filetypes
);
4006 i
++, type
= (mime_type_t
*)cupsArrayNext(p
->filetypes
))
4008 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
4010 attr
->values
[i
].string
.text
= _cupsStrAlloc(mimetype
);
4015 char pdl
[1024]; /* Buffer to build pdl list */
4016 mime_filter_t
*filter
; /* MIME filter looping var */
4021 if (mimeType(MimeDatabase
, "application", "pdf"))
4022 strlcat(pdl
, "application/pdf,", sizeof(pdl
));
4024 if (mimeType(MimeDatabase
, "application", "postscript"))
4025 strlcat(pdl
, "application/postscript,", sizeof(pdl
));
4027 if (mimeType(MimeDatabase
, "application", "vnd.cups-raster"))
4028 strlcat(pdl
, "application/vnd.cups-raster,", sizeof(pdl
));
4031 * Determine if this is a Tioga PrintJobMgr based queue...
4034 for (filter
= (mime_filter_t
*)cupsArrayFirst(MimeDatabase
->filters
);
4036 filter
= (mime_filter_t
*)cupsArrayNext(MimeDatabase
->filters
))
4038 if (filter
->dst
== p
->filetype
&& filter
->filter
&&
4039 strstr(filter
->filter
, "PrintJobMgr"))
4044 * We only support raw printing if this is not a Tioga PrintJobMgr based
4045 * queue and if application/octet-stream is a known conversion...
4048 if (!filter
&& mimeType(MimeDatabase
, "application", "octet-stream"))
4049 strlcat(pdl
, "application/octet-stream,", sizeof(pdl
));
4051 if (mimeType(MimeDatabase
, "image", "png"))
4052 strlcat(pdl
, "image/png,", sizeof(pdl
));
4055 pdl
[strlen(pdl
) - 1] = '\0'; /* Remove trailing comma */
4057 cupsdSetString(&p
->pdl
, pdl
);
4059 #endif /* HAVE_DNSSD */
4064 * 'compare_printers()' - Compare two printers.
4067 static int /* O - Result of comparison */
4068 compare_printers(void *first
, /* I - First printer */
4069 void *second
, /* I - Second printer */
4070 void *data
) /* I - App data (not used) */
4072 return (strcasecmp(((cupsd_printer_t
*)first
)->name
,
4073 ((cupsd_printer_t
*)second
)->name
));
4078 * 'delete_printer_filters()' - Delete all MIME filters for a printer.
4082 delete_printer_filters(
4083 cupsd_printer_t
*p
) /* I - Printer to remove from */
4085 mime_filter_t
*filter
; /* MIME filter looping var */
4089 * Range check input...
4096 * Remove all filters from the MIME database that have a destination
4097 * type == printer...
4100 for (filter
= mimeFirstFilter(MimeDatabase
);
4102 filter
= mimeNextFilter(MimeDatabase
))
4103 if (filter
->dst
== p
->filetype
)
4106 * Delete the current filter...
4109 mimeDeleteFilter(MimeDatabase
, filter
);
4116 * 'write_irix_config()' - Update the config files used by the IRIX
4121 write_irix_config(cupsd_printer_t
*p
) /* I - Printer to update */
4123 char filename
[1024]; /* Interface script filename */
4124 cups_file_t
*fp
; /* Interface script file */
4125 ipp_attribute_t
*attr
; /* Attribute data */
4129 * Add dummy interface and GUI scripts to fool SGI's "challenged" printing
4130 * tools. First the interface script that tells the tools what kind of
4131 * printer we have...
4134 snprintf(filename
, sizeof(filename
), "/var/spool/lp/interface/%s", p
->name
);
4136 if (p
->type
& CUPS_PRINTER_CLASS
)
4138 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
4140 cupsFilePuts(fp
, "#!/bin/sh\n");
4142 if ((attr
= ippFindAttribute(p
->attrs
, "printer-make-and-model",
4143 IPP_TAG_TEXT
)) != NULL
)
4144 cupsFilePrintf(fp
, "NAME=\"%s\"\n", attr
->values
[0].string
.text
);
4145 else if (p
->type
& CUPS_PRINTER_CLASS
)
4146 cupsFilePuts(fp
, "NAME=\"Printer Class\"\n");
4148 cupsFilePuts(fp
, "NAME=\"Remote Destination\"\n");
4150 if (p
->type
& CUPS_PRINTER_COLOR
)
4151 cupsFilePuts(fp
, "TYPE=ColorPostScript\n");
4153 cupsFilePuts(fp
, "TYPE=MonoPostScript\n");
4155 cupsFilePrintf(fp
, "HOSTNAME=%s\n", ServerName
);
4156 cupsFilePrintf(fp
, "HOSTPRINTER=%s\n", p
->name
);
4160 chmod(filename
, 0755);
4161 chown(filename
, User
, Group
);
4165 * Then the member file that tells which device file the queue is connected
4166 * to... Networked printers use "/dev/null" in this file, so that's what
4167 * we use (the actual device URI can confuse some apps...)
4170 snprintf(filename
, sizeof(filename
), "/var/spool/lp/member/%s", p
->name
);
4172 if (p
->type
& CUPS_PRINTER_CLASS
)
4174 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
4176 cupsFilePuts(fp
, "/dev/null\n");
4180 chmod(filename
, 0644);
4181 chown(filename
, User
, Group
);
4185 * The gui_interface file is a script or program that launches a GUI
4186 * option panel for the printer, using options specified on the
4187 * command-line in the third argument. The option panel must send
4188 * any printing options to stdout on a single line when the user
4189 * accepts them, or nothing if the user cancels the dialog.
4191 * The default options panel program is /usr/bin/glpoptions, from
4192 * the ESP Print Pro software. You can select another using the
4193 * PrintcapGUI option.
4196 snprintf(filename
, sizeof(filename
), "/var/spool/lp/gui_interface/ELF/%s.gui", p
->name
);
4198 if (p
->type
& CUPS_PRINTER_CLASS
)
4200 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
4202 cupsFilePuts(fp
, "#!/bin/sh\n");
4203 cupsFilePrintf(fp
, "%s -d %s -o \"$3\"\n", PrintcapGUI
, p
->name
);
4207 chmod(filename
, 0755);
4208 chown(filename
, User
, Group
);
4212 * The POD config file is needed by the printstatus command to show
4213 * the printer location and device.
4216 snprintf(filename
, sizeof(filename
), "/var/spool/lp/pod/%s.config", p
->name
);
4218 if (p
->type
& CUPS_PRINTER_CLASS
)
4220 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
4222 cupsFilePrintf(fp
, "Printer Class | %s\n",
4223 (p
->type
& CUPS_PRINTER_COLOR
) ? "ColorPostScript" : "MonoPostScript");
4224 cupsFilePrintf(fp
, "Printer Model | %s\n", p
->make_model
? p
->make_model
: "");
4225 cupsFilePrintf(fp
, "Location Code | %s\n", p
->location
? p
->location
: "");
4226 cupsFilePrintf(fp
, "Physical Location | %s\n", p
->info
? p
->info
: "");
4227 cupsFilePrintf(fp
, "Port Path | %s\n", p
->device_uri
? p
->device_uri
: "");
4228 cupsFilePrintf(fp
, "Config Path | /var/spool/lp/pod/%s.config\n", p
->name
);
4229 cupsFilePrintf(fp
, "Active Status Path | /var/spool/lp/pod/%s.status\n", p
->name
);
4230 cupsFilePuts(fp
, "Status Update Wait | 10 seconds\n");
4234 chmod(filename
, 0664);
4235 chown(filename
, User
, Group
);
4241 * 'write_irix_state()' - Update the status files used by IRIX printing
4246 write_irix_state(cupsd_printer_t
*p
) /* I - Printer to update */
4248 char filename
[1024]; /* Interface script filename */
4249 cups_file_t
*fp
; /* Interface script file */
4250 int tag
; /* Status tag value */
4256 * The POD status file is needed for the printstatus window to
4257 * provide the current status of the printer.
4260 snprintf(filename
, sizeof(filename
), "/var/spool/lp/pod/%s.status", p
->name
);
4262 if (p
->type
& CUPS_PRINTER_CLASS
)
4264 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
4266 cupsFilePrintf(fp
, "Operational Status | %s\n",
4267 (p
->state
== IPP_PRINTER_IDLE
) ? "Idle" :
4268 (p
->state
== IPP_PRINTER_PROCESSING
) ? "Busy" :
4270 cupsFilePrintf(fp
, "Information | 01 00 00 | %s\n", CUPS_SVERSION
);
4271 cupsFilePrintf(fp
, "Information | 02 00 00 | Device URI: %s\n",
4272 p
->device_uri
? p
->device_uri
: "");
4273 cupsFilePrintf(fp
, "Information | 03 00 00 | %s jobs\n",
4274 p
->accepting
? "Accepting" : "Not accepting");
4275 cupsFilePrintf(fp
, "Information | 04 00 00 | %s\n", p
->state_message
);
4279 chmod(filename
, 0664);
4280 chown(filename
, User
, Group
);
4284 * The activeicons file is needed to provide desktop icons for printers:
4286 * [ quoted from /usr/lib/print/tagit ]
4288 * --- Type of printer tags (base values)
4290 * Dumb=66048 # 0x10200
4291 * DumbColor=66080 # 0x10220
4292 * Raster=66112 # 0x10240
4293 * ColorRaster=66144 # 0x10260
4294 * Plotter=66176 # 0x10280
4295 * PostScript=66208 # 0x102A0
4296 * ColorPostScript=66240 # 0x102C0
4297 * MonoPostScript=66272 # 0x102E0
4299 * --- Printer state modifiers for local printers
4304 * Unknown=3 # 0x3 (Faulted due to unknown reason)
4306 * --- Printer state modifiers for network printers
4310 * NetFaulted=10 # 0xA
4311 * NetUnknown=11 # 0xB (Faulted due to unknown reason)
4314 snprintf(filename
, sizeof(filename
), "/var/spool/lp/activeicons/%s", p
->name
);
4316 if (p
->type
& CUPS_PRINTER_CLASS
)
4318 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
4320 if (p
->type
& CUPS_PRINTER_COLOR
)
4325 if (p
->type
& CUPS_PRINTER_REMOTE
)
4328 if (p
->state
== IPP_PRINTER_PROCESSING
)
4331 else if (p
->state
== IPP_PRINTER_STOPPED
)
4334 cupsFilePuts(fp
, "#!/bin/sh\n");
4335 cupsFilePrintf(fp
, "#Tag %d\n", tag
);
4339 chmod(filename
, 0755);
4340 chown(filename
, User
, Group
);
4345 * The default file is needed by the printers window to show
4346 * the default printer.
4349 snprintf(filename
, sizeof(filename
), "/var/spool/lp/default");
4351 if (DefaultPrinter
!= NULL
)
4353 if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
4355 cupsFilePrintf(fp
, "%s\n", DefaultPrinter
->name
);
4359 chmod(filename
, 0644);
4360 chown(filename
, User
, Group
);
4370 * End of "$Id: printers.c 7879 2008-08-28 00:08:56Z mike $".