2 * "$Id: printers.c 7677 2008-06-19 23:22:19Z 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 if (auth
->type
== CUPSD_AUTH_BASIC
|| auth
->type
== CUPSD_AUTH_BASICDIGEST
)
2062 auth_supported
= "basic";
2066 else if (auth
->type
== CUPSD_AUTH_DIGEST
)
2068 auth_supported
= "digest";
2073 else if (auth
->type
== CUPSD_AUTH_NEGOTIATE
)
2075 auth_supported
= "negotiate";
2077 air
= air_negotiate
;
2079 #endif /* HAVE_GSSAPI */
2081 if (auth
->type
!= CUPSD_AUTH_NONE
)
2082 p
->type
|= CUPS_PRINTER_AUTHENTICATED
;
2084 p
->type
&= ~CUPS_PRINTER_AUTHENTICATED
;
2087 p
->type
&= ~CUPS_PRINTER_AUTHENTICATED
;
2089 else if (p
->type
& CUPS_PRINTER_AUTHENTICATED
)
2096 * Create the required IPP attributes for a printer...
2099 oldattrs
= p
->attrs
;
2100 p
->attrs
= ippNew();
2102 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2103 "uri-authentication-supported", NULL
, auth_supported
);
2104 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2105 "uri-security-supported", NULL
, "none");
2106 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
, "printer-name", NULL
,
2108 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-location",
2109 NULL
, p
->location
? p
->location
: "");
2110 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-info",
2111 NULL
, p
->info
? p
->info
: "");
2112 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "printer-more-info",
2118 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2119 "requesting-user-name-denied", p
->num_users
, NULL
,
2122 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2123 "requesting-user-name-allowed", p
->num_users
, NULL
,
2127 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2128 "job-quota-period", p
->quota_period
);
2129 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2130 "job-k-limit", p
->k_limit
);
2131 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2132 "job-page-limit", p
->page_limit
);
2133 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2134 "auth-info-required", num_air
, NULL
, air
);
2136 if (cupsArrayCount(Banners
) > 0 && !(p
->type
& CUPS_PRINTER_DISCOVERED
))
2139 * Setup the job-sheets-default attribute...
2142 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2143 "job-sheets-default", 2, NULL
, NULL
);
2147 attr
->values
[0].string
.text
= _cupsStrAlloc(Classification
?
2148 Classification
: p
->job_sheets
[0]);
2149 attr
->values
[1].string
.text
= _cupsStrAlloc(Classification
?
2150 Classification
: p
->job_sheets
[1]);
2157 if (p
->type
& CUPS_PRINTER_DISCOVERED
)
2160 * Tell the client this is a remote printer of some type...
2163 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
2164 "printer-uri-supported", NULL
, p
->uri
);
2167 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
2168 "printer-make-and-model", NULL
, p
->make_model
);
2170 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "device-uri", NULL
,
2179 * Assign additional attributes depending on whether this is a printer
2183 p
->type
&= ~CUPS_PRINTER_OPTIONS
;
2185 if (p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
))
2190 * Add class-specific attributes...
2193 if ((p
->type
& CUPS_PRINTER_IMPLICIT
) && p
->num_printers
> 0 &&
2194 p
->printers
[0]->make_model
)
2195 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
2196 "printer-make-and-model", NULL
, p
->printers
[0]->make_model
);
2198 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
2199 "printer-make-and-model", NULL
, "Local Printer Class");
2201 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "device-uri", NULL
,
2202 "file:///dev/null");
2204 if (p
->num_printers
> 0)
2207 * Add a list of member names; URIs are added in copy_printer_attrs...
2210 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2211 "member-names", p
->num_printers
, NULL
, NULL
);
2212 p
->type
|= CUPS_PRINTER_OPTIONS
;
2214 for (i
= 0; i
< p
->num_printers
; i
++)
2217 attr
->values
[i
].string
.text
= _cupsStrAlloc(p
->printers
[i
]->name
);
2219 p
->type
&= ~CUPS_PRINTER_OPTIONS
| p
->printers
[i
]->type
;
2226 * Add printer-specific attributes... Start by sanitizing the device
2227 * URI so it doesn't have a username or password in it...
2231 strcpy(uri
, "file:/dev/null");
2232 else if (strstr(p
->device_uri
, "://") != NULL
)
2235 * http://..., ipp://..., etc.
2238 cupsdSanitizeURI(p
->device_uri
, uri
, sizeof(uri
));
2243 * file:..., serial:..., etc.
2246 strlcpy(uri
, p
->device_uri
, sizeof(uri
));
2249 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "device-uri", NULL
,
2253 * Assign additional attributes from the PPD file (if any)...
2256 p
->type
|= CUPS_PRINTER_BW
;
2257 finishings
[0] = IPP_FINISHINGS_NONE
;
2260 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
2263 if ((ppd
= ppdOpenFile(filename
)) != NULL
)
2266 * Add make/model and other various attributes...
2269 if (ppd
->color_device
)
2270 p
->type
|= CUPS_PRINTER_COLOR
;
2271 if (ppd
->variable_sizes
)
2272 p
->type
|= CUPS_PRINTER_VARIABLE
;
2273 if (!ppd
->manual_copies
)
2274 p
->type
|= CUPS_PRINTER_COPIES
;
2275 if ((ppdattr
= ppdFindAttr(ppd
, "cupsFax", NULL
)) != NULL
)
2276 if (ppdattr
->value
&& !strcasecmp(ppdattr
->value
, "true"))
2277 p
->type
|= CUPS_PRINTER_FAX
;
2279 ippAddBoolean(p
->attrs
, IPP_TAG_PRINTER
, "color-supported",
2281 if (ppd
->throughput
)
2282 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2283 "pages-per-minute", ppd
->throughput
);
2288 * The NickName can be localized in the character set specified
2289 * by the LanugageEncoding attribute. However, ppdOpen2() has
2290 * already converted the ppd->nickname member to UTF-8 for us
2291 * (the original attribute value is available separately)
2294 cupsdSetString(&p
->make_model
, ppd
->nickname
);
2296 else if (ppd
->modelname
)
2299 * Model name can only contain specific characters...
2302 cupsdSetString(&p
->make_model
, ppd
->modelname
);
2305 cupsdSetString(&p
->make_model
, "Bad PPD File");
2307 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
2308 "printer-make-and-model", NULL
, p
->make_model
);
2311 * Add media options from the PPD file...
2314 if ((input_slot
= ppdFindOption(ppd
, "InputSlot")) != NULL
)
2315 num_media
= input_slot
->num_choices
;
2319 if ((media_type
= ppdFindOption(ppd
, "MediaType")) != NULL
)
2320 num_media
+= media_type
->num_choices
;
2322 if ((page_size
= ppdFindOption(ppd
, "PageSize")) != NULL
)
2323 num_media
+= page_size
->num_choices
;
2325 if ((media_quality
= ppdFindOption(ppd
, "EFMediaQualityMode")) != NULL
)
2326 num_media
+= media_quality
->num_choices
;
2330 cupsdLogMessage(CUPSD_LOG_CRIT
,
2331 "The PPD file for printer %s contains no media "
2332 "options and is therefore invalid!", p
->name
);
2336 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2337 "media-supported", num_media
, NULL
, NULL
);
2342 if (input_slot
!= NULL
)
2343 for (i
= 0; i
< input_slot
->num_choices
; i
++, val
++)
2344 val
->string
.text
= _cupsStrAlloc(input_slot
->choices
[i
].choice
);
2346 if (media_type
!= NULL
)
2347 for (i
= 0; i
< media_type
->num_choices
; i
++, val
++)
2348 val
->string
.text
= _cupsStrAlloc(media_type
->choices
[i
].choice
);
2350 if (media_quality
!= NULL
)
2351 for (i
= 0; i
< media_quality
->num_choices
; i
++, val
++)
2352 val
->string
.text
= _cupsStrAlloc(media_quality
->choices
[i
].choice
);
2354 if (page_size
!= NULL
)
2356 for (i
= 0; i
< page_size
->num_choices
; i
++, val
++)
2357 val
->string
.text
= _cupsStrAlloc(page_size
->choices
[i
].choice
);
2359 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2360 "media-default", NULL
, page_size
->defchoice
);
2362 else if (input_slot
!= NULL
)
2363 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2364 "media-default", NULL
, input_slot
->defchoice
);
2365 else if (media_type
!= NULL
)
2366 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2367 "media-default", NULL
, media_type
->defchoice
);
2368 else if (media_quality
!= NULL
)
2369 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2370 "media-default", NULL
, media_quality
->defchoice
);
2372 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2373 "media-default", NULL
, "none");
2381 if ((output_bin
= ppdFindOption(ppd
, "OutputBin")) != NULL
)
2383 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2384 "output-bin-supported", output_bin
->num_choices
,
2389 for (i
= 0, val
= attr
->values
;
2390 i
< output_bin
->num_choices
;
2392 val
->string
.text
= _cupsStrAlloc(output_bin
->choices
[i
].choice
);
2400 if ((duplex
= ppdFindOption(ppd
, "Duplex")) == NULL
)
2401 if ((duplex
= ppdFindOption(ppd
, "EFDuplex")) == NULL
)
2402 if ((duplex
= ppdFindOption(ppd
, "EFDuplexing")) == NULL
)
2403 if ((duplex
= ppdFindOption(ppd
, "KD03Duplex")) == NULL
)
2404 duplex
= ppdFindOption(ppd
, "JCLDuplex");
2406 if (duplex
&& duplex
->num_choices
> 1 &&
2407 !ppdInstallableConflict(ppd
, duplex
->keyword
, "DuplexTumble"))
2409 p
->type
|= CUPS_PRINTER_DUPLEX
;
2411 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2412 "sides-supported", 3, NULL
, sides
);
2414 if (!strcasecmp(duplex
->defchoice
, "DuplexTumble"))
2415 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2416 "sides-default", NULL
, "two-sided-short-edge");
2417 else if (!strcasecmp(duplex
->defchoice
, "DuplexNoTumble"))
2418 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2419 "sides-default", NULL
, "two-sided-long-edge");
2421 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2422 "sides-default", NULL
, "one-sided");
2425 if (ppdFindOption(ppd
, "Collate") != NULL
)
2426 p
->type
|= CUPS_PRINTER_COLLATE
;
2428 if (ppdFindOption(ppd
, "StapleLocation") != NULL
)
2430 p
->type
|= CUPS_PRINTER_STAPLE
;
2431 finishings
[num_finishings
++] = IPP_FINISHINGS_STAPLE
;
2434 if (ppdFindOption(ppd
, "BindEdge") != NULL
)
2436 p
->type
|= CUPS_PRINTER_BIND
;
2437 finishings
[num_finishings
++] = IPP_FINISHINGS_BIND
;
2440 for (i
= 0; i
< ppd
->num_sizes
; i
++)
2441 if (ppd
->sizes
[i
].length
> 1728)
2442 p
->type
|= CUPS_PRINTER_LARGE
;
2443 else if (ppd
->sizes
[i
].length
> 1008)
2444 p
->type
|= CUPS_PRINTER_MEDIUM
;
2446 p
->type
|= CUPS_PRINTER_SMALL
;
2449 * Add a filter from application/vnd.cups-raw to printer/name to
2450 * handle "raw" printing by users.
2453 add_printer_filter(p
, p
->filetype
, "application/vnd.cups-raw 0 -");
2456 * Add any pre-filters in the PPD file...
2459 if ((ppdattr
= ppdFindAttr(ppd
, "cupsPreFilter", NULL
)) != NULL
)
2461 p
->prefiltertype
= mimeAddType(MimeDatabase
, "prefilter", p
->name
);
2463 for (; ppdattr
; ppdattr
= ppdFindNextAttr(ppd
, "cupsPreFilter", NULL
))
2465 add_printer_filter(p
, p
->prefiltertype
, ppdattr
->value
);
2469 * Add any filters in the PPD file...
2472 DEBUG_printf(("ppd->num_filters = %d\n", ppd
->num_filters
));
2473 for (i
= 0; i
< ppd
->num_filters
; i
++)
2475 DEBUG_printf(("ppd->filters[%d] = \"%s\"\n", i
, ppd
->filters
[i
]));
2476 add_printer_filter(p
, p
->filetype
, ppd
->filters
[i
]);
2479 if (ppd
->num_filters
== 0)
2482 * If there are no filters, add PostScript printing filters.
2485 add_printer_filter(p
, p
->filetype
,
2486 "application/vnd.cups-command 0 commandtops");
2487 add_printer_filter(p
, p
->filetype
,
2488 "application/vnd.cups-postscript 0 -");
2490 p
->type
|= CUPS_PRINTER_COMMANDS
;
2492 else if (!(p
->type
& CUPS_PRINTER_COMMANDS
))
2495 * See if this is a PostScript device without a command filter...
2498 for (i
= 0; i
< ppd
->num_filters
; i
++)
2499 if (!strncasecmp(ppd
->filters
[i
],
2500 "application/vnd.cups-postscript", 31))
2503 if (i
< ppd
->num_filters
)
2506 * Add the generic PostScript command filter...
2509 add_printer_filter(p
, p
->filetype
,
2510 "application/vnd.cups-command 0 commandtops");
2511 p
->type
|= CUPS_PRINTER_COMMANDS
;
2515 if (p
->type
& CUPS_PRINTER_COMMANDS
)
2517 char *commands
, /* Copy of commands */
2518 *start
, /* Start of name */
2519 *end
; /* End of name */
2520 int count
; /* Number of commands */
2523 if ((ppdattr
= ppdFindAttr(ppd
, "cupsCommands", NULL
)) != NULL
&&
2524 ppdattr
->value
&& ppdattr
->value
[0])
2526 for (count
= 0, start
= ppdattr
->value
; *start
; count
++)
2528 while (isspace(*start
& 255))
2534 while (*start
&& !isspace(*start
& 255))
2544 * Make a copy of the commands string and count how many ...
2547 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2548 "printer-commands", count
, NULL
, NULL
);
2550 commands
= strdup(ppdattr
->value
);
2552 for (count
= 0, start
= commands
; *start
; count
++)
2554 while (isspace(*start
& 255))
2561 while (*end
&& !isspace(*end
& 255))
2567 attr
->values
[count
].string
.text
= _cupsStrAlloc(start
);
2577 * Add the standard list of commands...
2580 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2582 (int)(sizeof(standard_commands
) /
2583 sizeof(standard_commands
[0])), NULL
,
2590 * No commands supported...
2593 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2594 "printer-commands", NULL
, "none");
2598 * Show current and available port monitors for this printer...
2601 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
, "port-monitor",
2602 NULL
, p
->port_monitor
? p
->port_monitor
: "none");
2604 for (i
= 1, ppdattr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
2606 i
++, ppdattr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
));
2610 if (strstr(ppd
->protocols
, "TBCP"))
2612 else if (strstr(ppd
->protocols
, "BCP"))
2616 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2617 "port-monitor-supported", i
, NULL
, NULL
);
2619 attr
->values
[0].string
.text
= _cupsStrAlloc("none");
2621 for (i
= 1, ppdattr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
2623 i
++, ppdattr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
))
2624 attr
->values
[i
].string
.text
= _cupsStrAlloc(ppdattr
->value
);
2628 if (strstr(ppd
->protocols
, "TBCP"))
2629 attr
->values
[i
].string
.text
= _cupsStrAlloc("tbcp");
2630 else if (strstr(ppd
->protocols
, "BCP"))
2631 attr
->values
[i
].string
.text
= _cupsStrAlloc("bcp");
2635 cupsdSetString(&p
->product
, ppd
->product
);
2636 #endif /* HAVE_DNSSD */
2638 if (ppdFindAttr(ppd
, "APRemoteQueueID", NULL
))
2639 p
->type
|= CUPS_PRINTER_REMOTE
;
2642 * Close the PPD and set the type...
2647 else if (!access(filename
, 0))
2649 int pline
; /* PPD line number */
2650 ppd_status_t pstatus
; /* PPD load status */
2653 pstatus
= ppdLastError(&pline
);
2655 cupsdLogMessage(CUPSD_LOG_ERROR
, "PPD file for %s cannot be loaded!",
2658 if (pstatus
<= PPD_ALLOC_ERROR
)
2659 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s", strerror(errno
));
2661 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s on line %d.",
2662 ppdErrorString(pstatus
), pline
);
2664 cupsdLogMessage(CUPSD_LOG_INFO
,
2665 "Hint: Run \"cupstestppd %s\" and fix any errors.",
2669 * Add a filter from application/vnd.cups-raw to printer/name to
2670 * handle "raw" printing by users.
2673 add_printer_filter(p
, p
->filetype
, "application/vnd.cups-raw 0 -");
2676 * Add a PostScript filter, since this is still possibly PS printer.
2679 add_printer_filter(p
, p
->filetype
,
2680 "application/vnd.cups-postscript 0 -");
2685 * If we have an interface script, add a filter entry for it...
2688 snprintf(filename
, sizeof(filename
), "%s/interfaces/%s", ServerRoot
,
2690 if (!access(filename
, X_OK
))
2693 * Yes, we have a System V style interface script; use it!
2696 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
2697 "printer-make-and-model", NULL
,
2698 "Local System V Printer");
2700 snprintf(filename
, sizeof(filename
), "*/* 0 %s/interfaces/%s",
2701 ServerRoot
, p
->name
);
2702 add_printer_filter(p
, p
->filetype
, filename
);
2704 else if (p
->device_uri
&&
2705 !strncmp(p
->device_uri
, "ipp://", 6) &&
2706 (strstr(p
->device_uri
, "/printers/") != NULL
||
2707 strstr(p
->device_uri
, "/classes/") != NULL
))
2710 * Tell the client this is really a hard-wired remote printer.
2713 p
->type
|= CUPS_PRINTER_REMOTE
;
2716 * Point the printer-uri-supported attribute to the
2720 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
2721 "printer-uri-supported", NULL
, p
->device_uri
);
2724 * Then set the make-and-model accordingly...
2727 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
2728 "printer-make-and-model", NULL
, "Remote Printer");
2731 * Print all files directly...
2740 * Otherwise we have neither - treat this as a "dumb" printer
2741 * with no PPD file...
2744 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
2745 "printer-make-and-model", NULL
, "Local Raw Printer");
2751 ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
2752 "finishings-supported", num_finishings
, finishings
);
2753 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
2754 "finishings-default", IPP_FINISHINGS_NONE
);
2759 * Copy marker attributes as needed...
2764 ipp_attribute_t
*oldattr
; /* Old attribute */
2767 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-colors",
2768 IPP_TAG_NAME
)) != NULL
)
2770 if ((attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2771 "marker-colors", oldattr
->num_values
, NULL
,
2774 for (i
= 0; i
< oldattr
->num_values
; i
++)
2775 attr
->values
[i
].string
.text
=
2776 _cupsStrAlloc(oldattr
->values
[i
].string
.text
);
2780 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-levels",
2781 IPP_TAG_INTEGER
)) != NULL
)
2783 if ((attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2784 "marker-levels", oldattr
->num_values
,
2787 for (i
= 0; i
< oldattr
->num_values
; i
++)
2788 attr
->values
[i
].integer
= oldattr
->values
[i
].integer
;
2792 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-names",
2793 IPP_TAG_NAME
)) != NULL
)
2795 if ((attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2796 "marker-names", oldattr
->num_values
, NULL
,
2799 for (i
= 0; i
< oldattr
->num_values
; i
++)
2800 attr
->values
[i
].string
.text
=
2801 _cupsStrAlloc(oldattr
->values
[i
].string
.text
);
2805 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-types",
2806 IPP_TAG_KEYWORD
)) != NULL
)
2808 if ((attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2809 "marker-types", oldattr
->num_values
, NULL
,
2812 for (i
= 0; i
< oldattr
->num_values
; i
++)
2813 attr
->values
[i
].string
.text
=
2814 _cupsStrAlloc(oldattr
->values
[i
].string
.text
);
2818 ippDelete(oldattrs
);
2822 * Force sharing off for remote queues...
2825 if (p
->type
& (CUPS_PRINTER_REMOTE
| CUPS_PRINTER_IMPLICIT
))
2830 * Copy the printer options into a browse attributes string we can re-use.
2833 const char *valptr
; /* Pointer into value */
2834 char *attrptr
; /* Pointer into attribute string */
2838 * Free the old browse attributes as needed...
2841 if (p
->browse_attrs
)
2842 free(p
->browse_attrs
);
2845 * Compute the length of all attributes + job-sheets, lease-duration,
2846 * and BrowseLocalOptions.
2849 for (length
= 1, i
= p
->num_options
, option
= p
->options
;
2853 length
+= strlen(option
->name
) + 2;
2857 for (valptr
= option
->value
; *valptr
; valptr
++)
2858 if (strchr(" \"\'\\", *valptr
))
2865 length
+= 13 + strlen(p
->job_sheets
[0]) + strlen(p
->job_sheets
[1]);
2867 if (BrowseLocalOptions
)
2868 length
+= 12 + strlen(BrowseLocalOptions
);
2870 if (p
->num_auth_info_required
> 0)
2872 length
+= 18; /* auth-info-required */
2874 for (i
= 0; i
< p
->num_auth_info_required
; i
++)
2875 length
+= strlen(p
->auth_info_required
[i
]) + 1;
2879 * Allocate the new string...
2882 if ((p
->browse_attrs
= calloc(1, length
)) == NULL
)
2883 cupsdLogMessage(CUPSD_LOG_ERROR
,
2884 "Unable to allocate %d bytes for browse data!",
2889 * Got the allocated string, now copy the options and attributes over...
2892 sprintf(p
->browse_attrs
, "job-sheets=%s,%s lease-duration=%d",
2893 p
->job_sheets
[0], p
->job_sheets
[1], BrowseTimeout
);
2894 attrptr
= p
->browse_attrs
+ strlen(p
->browse_attrs
);
2896 if (BrowseLocalOptions
)
2898 sprintf(attrptr
, " ipp-options=%s", BrowseLocalOptions
);
2899 attrptr
+= strlen(attrptr
);
2902 for (i
= p
->num_options
, option
= p
->options
;
2907 strcpy(attrptr
, option
->name
);
2908 attrptr
+= strlen(attrptr
);
2914 for (valptr
= option
->value
; *valptr
; valptr
++)
2916 if (strchr(" \"\'\\", *valptr
))
2919 *attrptr
++ = *valptr
;
2924 if (p
->num_auth_info_required
> 0)
2926 strcpy(attrptr
, "auth-info-required");
2929 for (i
= 0; i
< p
->num_auth_info_required
; i
++)
2931 *attrptr
++ = i
? ',' : '=';
2932 strcpy(attrptr
, p
->auth_info_required
[i
]);
2933 attrptr
+= strlen(attrptr
);
2942 * Populate the document-format-supported attribute...
2945 add_printer_formats(p
);
2947 DEBUG_printf(("cupsdSetPrinterAttrs: leaving name = %s, type = %x\n", p
->name
,
2951 * Add name-default attributes...
2954 add_printer_defaults(p
);
2958 * Write the IRIX printer config and status files...
2961 write_irix_config(p
);
2962 write_irix_state(p
);
2966 * Let the browse protocols reflect the change
2969 cupsdRegisterPrinter(p
);
2974 * 'cupsdSetPrinterReasons()' - Set/update the reasons strings.
2978 cupsdSetPrinterReasons(
2979 cupsd_printer_t
*p
, /* I - Printer */
2980 const char *s
) /* I - Reasons strings */
2982 int i
; /* Looping var */
2983 const char *sptr
; /* Pointer into reasons */
2984 char reason
[255], /* Reason string */
2985 *rptr
; /* Pointer into reason */
2988 if (s
[0] == '-' || s
[0] == '+')
2991 * Add/remove reasons...
2999 * Replace reasons...
3004 for (i
= 0; i
< p
->num_reasons
; i
++)
3005 free(p
->reasons
[i
]);
3010 if (!strcmp(s
, "none"))
3014 * Loop through all of the reasons...
3020 * Skip leading whitespace and commas...
3023 while (isspace(*sptr
& 255) || *sptr
== ',')
3026 for (rptr
= reason
; *sptr
&& !isspace(*sptr
& 255) && *sptr
!= ','; sptr
++)
3027 if (rptr
< (reason
+ sizeof(reason
) - 1))
3041 for (i
= 0; i
< p
->num_reasons
; i
++)
3042 if (!strcasecmp(reason
, p
->reasons
[i
]))
3045 * Found a match, so remove it...
3049 free(p
->reasons
[i
]);
3051 if (i
< p
->num_reasons
)
3052 memmove(p
->reasons
+ i
, p
->reasons
+ i
+ 1,
3053 (p
->num_reasons
- i
) * sizeof(char *));
3057 if (!strcmp(reason
, "paused") && p
->state
== IPP_PRINTER_STOPPED
)
3058 cupsdSetPrinterState(p
, IPP_PRINTER_IDLE
, 1);
3061 else if (p
->num_reasons
< (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
3067 for (i
= 0; i
< p
->num_reasons
; i
++)
3068 if (!strcasecmp(reason
, p
->reasons
[i
]))
3071 if (i
>= p
->num_reasons
)
3073 p
->reasons
[i
] = strdup(reason
);
3076 if (!strcmp(reason
, "paused") && p
->state
!= IPP_PRINTER_STOPPED
)
3077 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, 1);
3085 * 'cupsdSetPrinterState()' - Update the current state of a printer.
3089 cupsdSetPrinterState(
3090 cupsd_printer_t
*p
, /* I - Printer to change */
3091 ipp_pstate_t s
, /* I - New state */
3092 int update
) /* I - Update printers.conf? */
3094 ipp_pstate_t old_state
; /* Old printer state */
3098 * Can't set status of remote printers...
3101 if (p
->type
& CUPS_PRINTER_DISCOVERED
)
3105 * Set the new state...
3108 old_state
= p
->state
;
3113 cupsdAddEvent(s
== IPP_PRINTER_STOPPED
? CUPSD_EVENT_PRINTER_STOPPED
:
3114 CUPSD_EVENT_PRINTER_STATE
, p
, NULL
,
3115 "%s \"%s\" state changed.",
3116 (p
->type
& CUPS_PRINTER_CLASS
) ? "Class" : "Printer",
3120 * Let the browse code know this needs to be updated...
3124 p
->state_time
= time(NULL
);
3128 write_irix_state(p
);
3132 cupsdAddPrinterHistory(p
);
3135 * Let the browse protocols reflect the change...
3139 cupsdRegisterPrinter(p
);
3142 * Save the printer configuration if a printer goes from idle or processing
3143 * to stopped (or visa-versa)...
3146 if ((old_state
== IPP_PRINTER_STOPPED
) != (s
== IPP_PRINTER_STOPPED
) &&
3149 if (p
->type
& CUPS_PRINTER_CLASS
)
3150 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
3152 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
3158 * 'cupsdStopPrinter()' - Stop a printer from printing any jobs...
3162 cupsdStopPrinter(cupsd_printer_t
*p
, /* I - Printer to stop */
3163 int update
)/* I - Update printers.conf? */
3165 cupsd_job_t
*job
; /* Active print job */
3169 * Set the printer state...
3172 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, update
);
3175 * See if we have a job printing on this printer...
3181 * Get pointer to job...
3184 job
= (cupsd_job_t
*)p
->job
;
3190 cupsdStopJob(job
, 0);
3193 * Reset the state to pending...
3196 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
3197 job
->state_value
= IPP_JOB_PENDING
;
3200 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
3202 cupsdAddEvent(CUPSD_EVENT_JOB_STOPPED
, p
, job
,
3203 "Job stopped due to printer being paused");
3209 * 'cupsdUpdatePrinterPPD()' - Update keywords in a printer's PPD file.
3212 int /* O - 1 if successful, 0 otherwise */
3213 cupsdUpdatePrinterPPD(
3214 cupsd_printer_t
*p
, /* I - Printer */
3215 int num_keywords
, /* I - Number of keywords */
3216 cups_option_t
*keywords
) /* I - Keywords */
3218 int i
; /* Looping var */
3219 cups_file_t
*src
, /* Original file */
3220 *dst
; /* New file */
3221 char srcfile
[1024], /* Original filename */
3222 dstfile
[1024], /* New filename */
3223 line
[1024], /* Line from file */
3224 keystring
[41]; /* Keyword from line */
3225 cups_option_t
*keyword
; /* Current keyword */
3228 cupsdLogMessage(CUPSD_LOG_INFO
, "Updating keywords in PPD file for %s...",
3232 * Get the old and new PPD filenames...
3235 snprintf(srcfile
, sizeof(srcfile
), "%s/ppd/%s.ppd.O", ServerRoot
, p
->name
);
3236 snprintf(dstfile
, sizeof(srcfile
), "%s/ppd/%s.ppd", ServerRoot
, p
->name
);
3239 * Rename the old file and open the old and new...
3242 if (rename(dstfile
, srcfile
))
3244 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to backup PPD file for %s: %s",
3245 p
->name
, strerror(errno
));
3249 if ((src
= cupsFileOpen(srcfile
, "r")) == NULL
)
3251 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to open PPD file \"%s\": %s",
3252 srcfile
, strerror(errno
));
3253 rename(srcfile
, dstfile
);
3257 if ((dst
= cupsFileOpen(dstfile
, "w")) == NULL
)
3259 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to create PPD file \"%s\": %s",
3260 dstfile
, strerror(errno
));
3262 rename(srcfile
, dstfile
);
3267 * Copy the first line and then write out all of the keywords...
3270 if (!cupsFileGets(src
, line
, sizeof(line
)))
3272 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to read PPD file \"%s\": %s",
3273 srcfile
, strerror(errno
));
3276 rename(srcfile
, dstfile
);
3280 cupsFilePrintf(dst
, "%s\n", line
);
3282 for (i
= num_keywords
, keyword
= keywords
; i
> 0; i
--, keyword
++)
3284 cupsdLogMessage(CUPSD_LOG_DEBUG
, "*%s: %s", keyword
->name
, keyword
->value
);
3285 cupsFilePrintf(dst
, "*%s: %s\n", keyword
->name
, keyword
->value
);
3289 * Then copy the rest of the PPD file, dropping any keywords we changed.
3292 while (cupsFileGets(src
, line
, sizeof(line
)))
3295 * Skip keywords we've already set...
3298 if (sscanf(line
, "*%40[^:]:", keystring
) == 1 &&
3299 cupsGetOption(keystring
, num_keywords
, keywords
))
3303 * Otherwise write the line...
3306 cupsFilePrintf(dst
, "%s\n", line
);
3310 * Close files and return...
3321 * 'cupsdUpdatePrinters()' - Update printers after a partial reload.
3325 cupsdUpdatePrinters(void)
3327 cupsd_printer_t
*p
; /* Current printer */
3331 * Loop through the printers and recreate the printer attributes
3332 * for any local printers since the policy and/or access control
3333 * stuff may have changed. Also, if browsing is disabled, remove
3334 * any remote printers...
3337 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3339 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3342 * Remove remote printers if we are no longer browsing...
3346 (p
->type
& (CUPS_PRINTER_IMPLICIT
| CUPS_PRINTER_DISCOVERED
)))
3348 if (p
->type
& CUPS_PRINTER_IMPLICIT
)
3349 cupsArrayRemove(ImplicitPrinters
, p
);
3351 cupsArraySave(Printers
);
3352 cupsdDeletePrinter(p
, 0);
3353 cupsArrayRestore(Printers
);
3358 * Update the operation policy pointer...
3361 if ((p
->op_policy_ptr
= cupsdFindPolicy(p
->op_policy
)) == NULL
)
3362 p
->op_policy_ptr
= DefaultPolicyPtr
;
3365 * Update printer attributes as needed...
3368 if (!(p
->type
& CUPS_PRINTER_DISCOVERED
))
3369 cupsdSetPrinterAttrs(p
);
3375 * 'cupsdValidateDest()' - Validate a printer/class destination.
3378 const char * /* O - Printer or class name */
3380 const char *uri
, /* I - Printer URI */
3381 cups_ptype_t
*dtype
, /* O - Type (printer or class) */
3382 cupsd_printer_t
**printer
) /* O - Printer pointer */
3384 cupsd_printer_t
*p
; /* Current printer */
3385 char localname
[1024],/* Localized hostname */
3386 *lptr
, /* Pointer into localized hostname */
3387 *sptr
, /* Pointer into server name */
3388 *rptr
, /* Pointer into resource */
3389 scheme
[32], /* Scheme portion of URI */
3390 username
[64], /* Username portion of URI */
3391 hostname
[HTTP_MAX_HOST
],
3392 /* Host portion of URI */
3393 resource
[HTTP_MAX_URI
];
3394 /* Resource portion of URI */
3395 int port
; /* Port portion of URI */
3398 DEBUG_printf(("cupsdValidateDest(uri=\"%s\", dtype=%p, printer=%p)\n", uri
,
3402 * Initialize return values...
3409 *dtype
= (cups_ptype_t
)0;
3412 * Pull the hostname and resource from the URI...
3415 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
, scheme
, sizeof(scheme
),
3416 username
, sizeof(username
), hostname
, sizeof(hostname
),
3417 &port
, resource
, sizeof(resource
));
3420 * See if the resource is a class or printer...
3423 if (!strncmp(resource
, "/classes/", 9))
3429 rptr
= resource
+ 9;
3431 else if (!strncmp(resource
, "/printers/", 10))
3437 rptr
= resource
+ 10;
3442 * Bad resource name...
3449 * See if the printer or class name exists...
3452 p
= cupsdFindDest(rptr
);
3454 if (p
== NULL
&& strchr(rptr
, '@') == NULL
)
3462 *dtype
= p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
|
3463 CUPS_PRINTER_REMOTE
| CUPS_PRINTER_DISCOVERED
);
3469 * Change localhost to the server name...
3472 if (!strcasecmp(hostname
, "localhost"))
3473 strlcpy(hostname
, ServerName
, sizeof(hostname
));
3475 strlcpy(localname
, hostname
, sizeof(localname
));
3477 if (!strcasecmp(hostname
, ServerName
))
3480 * Localize the hostname...
3483 lptr
= strchr(localname
, '.');
3484 sptr
= strchr(ServerName
, '.');
3486 if (sptr
!= NULL
&& lptr
!= NULL
)
3489 * Strip the common domain name components...
3492 while (lptr
!= NULL
)
3494 if (!strcasecmp(lptr
, sptr
))
3500 lptr
= strchr(lptr
+ 1, '.');
3505 DEBUG_printf(("localized hostname is \"%s\"...\n", localname
));
3508 * Find a matching printer or class...
3511 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3513 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3514 if (!strcasecmp(p
->hostname
, localname
) &&
3515 !strcasecmp(p
->name
, rptr
))
3521 *dtype
= p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
|
3522 CUPS_PRINTER_REMOTE
| CUPS_PRINTER_DISCOVERED
);
3532 * 'cupsdWritePrintcap()' - Write a pseudo-printcap file for older applications
3537 cupsdWritePrintcap(void)
3539 cups_file_t
*fp
; /* printcap file */
3540 cupsd_printer_t
*p
; /* Current printer */
3545 * Update the IRIX printer state for the default printer; if
3546 * no printers remain, then the default printer file will be
3550 write_irix_state(DefaultPrinter
);
3554 * See if we have a printcap file; if not, don't bother writing it.
3557 if (!Printcap
|| !*Printcap
)
3561 * Open the printcap file...
3564 if ((fp
= cupsFileOpen(Printcap
, "w")) == NULL
)
3568 * Put a comment header at the top so that users will know where the
3569 * data has come from...
3573 "# This file was automatically generated by cupsd(8) from the\n");
3574 cupsFilePrintf(fp
, "# %s/printers.conf file. All changes to this file\n",
3576 cupsFilePuts(fp
, "# will be lost.\n");
3581 * Write a new printcap with the current list of printers.
3584 switch (PrintcapFormat
)
3588 * Each printer is put in the file as:
3598 cupsFilePrintf(fp
, "%s|%s:rm=%s:rp=%s:\n", DefaultPrinter
->name
,
3599 DefaultPrinter
->info
, ServerName
,
3600 DefaultPrinter
->name
);
3602 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3604 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3605 if (p
!= DefaultPrinter
)
3606 cupsFilePrintf(fp
, "%s|%s:rm=%s:rp=%s:\n", p
->name
, p
->info
,
3607 ServerName
, p
->name
);
3610 case PRINTCAP_SOLARIS
:
3612 * Each printer is put in the file as:
3614 * _all:all=Printer1,Printer2,Printer3,...,PrinterN
3615 * _default:use=DefaultPrinter
3617 * :bsdaddr=ServerName,Printer1:\
3618 * :description=Description:
3620 * :bsdaddr=ServerName,Printer2:\
3621 * :description=Description:
3623 * :bsdaddr=ServerName,Printer3:\
3624 * :description=Description:
3627 * :bsdaddr=ServerName,PrinterN:\
3628 * :description=Description:
3631 cupsFilePuts(fp
, "_all:all=");
3632 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3634 p
= (cupsd_printer_t
*)cupsArrayCurrent(Printers
))
3635 cupsFilePrintf(fp
, "%s%c", p
->name
,
3636 cupsArrayNext(Printers
) ? ',' : '\n');
3639 cupsFilePrintf(fp
, "_default:use=%s\n", DefaultPrinter
->name
);
3641 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3643 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3644 cupsFilePrintf(fp
, "%s:\\\n"
3645 "\t:bsdaddr=%s,%s:\\\n"
3646 "\t:description=%s:\n",
3647 p
->name
, ServerName
, p
->name
,
3648 p
->info
? p
->info
: "");
3662 * 'cupsdSanitizeURI()' - Sanitize a device URI...
3665 char * /* O - New device URI */
3666 cupsdSanitizeURI(const char *uri
, /* I - Original device URI */
3667 char *buffer
, /* O - New device URI */
3668 int buflen
) /* I - Size of new device URI buffer */
3670 char *start
, /* Start of data after scheme */
3671 *slash
, /* First slash after scheme:// */
3672 *ptr
; /* Pointer into user@host:port part */
3676 * Range check input...
3679 if (!uri
|| !buffer
|| buflen
< 2)
3683 * Copy the device URI to the new buffer...
3686 strlcpy(buffer
, uri
, buflen
);
3689 * Find the end of the scheme:// part...
3692 if ((ptr
= strchr(buffer
, ':')) == NULL
)
3693 return (buffer
); /* No scheme: part... */
3695 for (start
= ptr
+ 1; *start
; start
++)
3700 * Find the next slash (/) in the URI...
3703 if ((slash
= strchr(start
, '/')) == NULL
)
3704 slash
= start
+ strlen(start
); /* No slash, point to the end */
3707 * Check for an @ sign before the slash...
3710 if ((ptr
= strchr(start
, '@')) != NULL
&& ptr
< slash
)
3713 * Found an @ sign and it is before the resource part, so we have
3714 * an authentication string. Copy the remaining URI over the
3715 * authentication string...
3718 _cups_strcpy(start
, ptr
+ 1);
3722 * Return the new device URI...
3730 * 'add_printer_defaults()' - Add name-default attributes to the printer attributes.
3734 add_printer_defaults(cupsd_printer_t
*p
)/* I - Printer */
3736 int i
; /* Looping var */
3737 int num_options
; /* Number of default options */
3738 cups_option_t
*options
, /* Default options */
3739 *option
; /* Current option */
3740 char name
[256]; /* name-default */
3744 * Maintain a common array of default attribute names...
3747 if (!CommonDefaults
)
3749 CommonDefaults
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
3751 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("copies-default"));
3752 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("document-format-default"));
3753 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("finishings-default"));
3754 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-hold-until-default"));
3755 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-priority-default"));
3756 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-sheets-default"));
3757 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("media-default"));
3758 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("number-up-default"));
3759 cupsArrayAdd(CommonDefaults
,
3760 _cupsStrAlloc("orientation-requested-default"));
3761 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("sides-default"));
3765 * Add all of the default options from the .conf files...
3768 for (num_options
= 0, options
= NULL
, i
= p
->num_options
, option
= p
->options
;
3772 if (strcmp(option
->name
, "ipp-options") &&
3773 strcmp(option
->name
, "job-sheets") &&
3774 strcmp(option
->name
, "lease-duration"))
3776 snprintf(name
, sizeof(name
), "%s-default", option
->name
);
3777 num_options
= cupsAddOption(name
, option
->value
, num_options
, &options
);
3779 if (!cupsArrayFind(CommonDefaults
, name
))
3780 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc(name
));
3785 * Convert options to IPP attributes...
3788 cupsEncodeOptions2(p
->attrs
, num_options
, options
, IPP_TAG_PRINTER
);
3789 cupsFreeOptions(num_options
, options
);
3792 * Add standard -default attributes as needed...
3795 if (!cupsGetOption("copies", p
->num_options
, p
->options
))
3796 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
, "copies-default",
3799 if (!cupsGetOption("document-format", p
->num_options
, p
->options
))
3800 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_MIMETYPE
,
3801 "document-format-default", NULL
, "application/octet-stream");
3803 if (!cupsGetOption("job-hold-until", p
->num_options
, p
->options
))
3804 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3805 "job-hold-until-default", NULL
, "no-hold");
3807 if (!cupsGetOption("job-priority", p
->num_options
, p
->options
))
3808 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3809 "job-priority-default", 50);
3811 if (!cupsGetOption("number-up", p
->num_options
, p
->options
))
3812 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3813 "number-up-default", 1);
3815 if (!cupsGetOption("orientation-requested", p
->num_options
, p
->options
))
3816 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NOVALUE
,
3817 "orientation-requested-default", NULL
, NULL
);
3819 if (!cupsGetOption("notify-lease-duration", p
->num_options
, p
->options
))
3820 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3821 "notify-lease-duration-default", DefaultLeaseDuration
);
3823 if (!cupsGetOption("notify-events", p
->num_options
, p
->options
))
3824 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3825 "notify-events-default", NULL
, "job-completed");
3830 * 'add_printer_filter()' - Add a MIME filter for a printer.
3835 cupsd_printer_t
*p
, /* I - Printer to add to */
3836 mime_type_t
*filtertype
, /* I - Filter or prefilter MIME type */
3837 const char *filter
) /* I - Filter to add */
3839 char super
[MIME_MAX_SUPER
], /* Super-type for filter */
3840 type
[MIME_MAX_TYPE
], /* Type for filter */
3841 program
[1024]; /* Program/filter name */
3842 int cost
; /* Cost of filter */
3843 mime_type_t
*temptype
; /* MIME type looping var */
3844 char filename
[1024]; /* Full filter filename */
3848 * Parse the filter string; it should be in the following format:
3850 * super/type cost program
3853 if (sscanf(filter
, "%15[^/]/%31s%d%*[ \t]%1023[^\n]", super
, type
, &cost
,
3856 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: invalid filter string \"%s\"!",
3862 * See if the filter program exists; if not, stop the printer and flag
3866 if (strcmp(program
, "-"))
3868 if (program
[0] == '/')
3869 strlcpy(filename
, program
, sizeof(filename
));
3871 snprintf(filename
, sizeof(filename
), "%s/filter/%s", ServerBin
, program
);
3873 if (access(filename
, X_OK
))
3875 snprintf(p
->state_message
, sizeof(p
->state_message
),
3876 "Filter \"%s\" for printer \"%s\" not available: %s",
3877 program
, p
->name
, strerror(errno
));
3878 cupsdSetPrinterReasons(p
, "+cups-missing-filter-error");
3879 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, 0);
3881 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s", p
->state_message
);
3886 * Mark the CUPS_PRINTER_COMMANDS bit if we have a filter for
3887 * application/vnd.cups-command...
3890 if (!strcasecmp(super
, "application") &&
3891 !strcasecmp(type
, "vnd.cups-command"))
3892 p
->type
|= CUPS_PRINTER_COMMANDS
;
3895 * Add the filter to the MIME database, supporting wildcards as needed...
3898 for (temptype
= mimeFirstType(MimeDatabase
);
3900 temptype
= mimeNextType(MimeDatabase
))
3901 if (((super
[0] == '*' && strcasecmp(temptype
->super
, "printer")) ||
3902 !strcasecmp(temptype
->super
, super
)) &&
3903 (type
[0] == '*' || !strcasecmp(temptype
->type
, type
)))
3905 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3906 "add_printer_filter: %s: adding filter %s/%s %s/%s %d %s",
3907 p
->name
, temptype
->super
, temptype
->type
,
3908 filtertype
->super
, filtertype
->type
,
3910 mimeAddFilter(MimeDatabase
, temptype
, filtertype
, cost
, program
);
3916 * 'add_printer_formats()' - Add document-format-supported values for a printer.
3920 add_printer_formats(cupsd_printer_t
*p
) /* I - Printer */
3922 int i
; /* Looping var */
3923 mime_type_t
*type
; /* Current MIME type */
3924 cups_array_t
*filters
; /* Filters */
3925 ipp_attribute_t
*attr
; /* document-format-supported attribute */
3926 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
3927 /* MIME type name */
3931 * Raw (and remote) queues advertise all of the supported MIME
3935 cupsArrayDelete(p
->filetypes
);
3936 p
->filetypes
= NULL
;
3940 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
,
3941 (ipp_tag_t
)(IPP_TAG_MIMETYPE
| IPP_TAG_COPY
),
3942 "document-format-supported", NumMimeTypes
, NULL
, MimeTypes
);
3947 * Otherwise, loop through the supported MIME types and see if there
3948 * are filters for them...
3951 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_printer_formats: %d types, %d filters",
3952 mimeNumTypes(MimeDatabase
), mimeNumFilters(MimeDatabase
));
3954 p
->filetypes
= cupsArrayNew(NULL
, NULL
);
3956 for (type
= mimeFirstType(MimeDatabase
);
3958 type
= mimeNextType(MimeDatabase
))
3960 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
3962 if ((filters
= mimeFilter(MimeDatabase
, type
, p
->filetype
, NULL
)) != NULL
)
3964 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3965 "add_printer_formats: %s: %s needs %d filters",
3966 p
->name
, mimetype
, cupsArrayCount(filters
));
3968 cupsArrayDelete(filters
);
3969 cupsArrayAdd(p
->filetypes
, type
);
3972 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3973 "add_printer_formats: %s: %s not supported",
3977 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3978 "add_printer_formats: %s: %d supported types",
3979 p
->name
, cupsArrayCount(p
->filetypes
) + 1);
3982 * Add the file formats that can be filtered...
3985 if ((type
= mimeType(MimeDatabase
, "application", "octet-stream")) == NULL
||
3986 !cupsArrayFind(p
->filetypes
, type
))
3991 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_MIMETYPE
,
3992 "document-format-supported",
3993 cupsArrayCount(p
->filetypes
) + 1, NULL
, NULL
);
3996 attr
->values
[0].string
.text
= _cupsStrAlloc("application/octet-stream");
3998 for (type
= (mime_type_t
*)cupsArrayFirst(p
->filetypes
);
4000 i
++, type
= (mime_type_t
*)cupsArrayNext(p
->filetypes
))
4002 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
4004 attr
->values
[i
].string
.text
= _cupsStrAlloc(mimetype
);
4009 char pdl
[1024]; /* Buffer to build pdl list */
4010 mime_filter_t
*filter
; /* MIME filter looping var */
4015 if (mimeType(MimeDatabase
, "application", "pdf"))
4016 strlcat(pdl
, "application/pdf,", sizeof(pdl
));
4018 if (mimeType(MimeDatabase
, "application", "postscript"))
4019 strlcat(pdl
, "application/postscript,", sizeof(pdl
));
4021 if (mimeType(MimeDatabase
, "application", "vnd.cups-raster"))
4022 strlcat(pdl
, "application/vnd.cups-raster,", sizeof(pdl
));
4025 * Determine if this is a Tioga PrintJobMgr based queue...
4028 for (filter
= (mime_filter_t
*)cupsArrayFirst(MimeDatabase
->filters
);
4030 filter
= (mime_filter_t
*)cupsArrayNext(MimeDatabase
->filters
))
4032 if (filter
->dst
== p
->filetype
&& filter
->filter
&&
4033 strstr(filter
->filter
, "PrintJobMgr"))
4038 * We only support raw printing if this is not a Tioga PrintJobMgr based
4039 * queue and if application/octet-stream is a known conversion...
4042 if (!filter
&& mimeType(MimeDatabase
, "application", "octet-stream"))
4043 strlcat(pdl
, "application/octet-stream,", sizeof(pdl
));
4045 if (mimeType(MimeDatabase
, "image", "png"))
4046 strlcat(pdl
, "image/png,", sizeof(pdl
));
4049 pdl
[strlen(pdl
) - 1] = '\0'; /* Remove trailing comma */
4051 cupsdSetString(&p
->pdl
, pdl
);
4053 #endif /* HAVE_DNSSD */
4058 * 'compare_printers()' - Compare two printers.
4061 static int /* O - Result of comparison */
4062 compare_printers(void *first
, /* I - First printer */
4063 void *second
, /* I - Second printer */
4064 void *data
) /* I - App data (not used) */
4066 return (strcasecmp(((cupsd_printer_t
*)first
)->name
,
4067 ((cupsd_printer_t
*)second
)->name
));
4072 * 'delete_printer_filters()' - Delete all MIME filters for a printer.
4076 delete_printer_filters(
4077 cupsd_printer_t
*p
) /* I - Printer to remove from */
4079 mime_filter_t
*filter
; /* MIME filter looping var */
4083 * Range check input...
4090 * Remove all filters from the MIME database that have a destination
4091 * type == printer...
4094 for (filter
= mimeFirstFilter(MimeDatabase
);
4096 filter
= mimeNextFilter(MimeDatabase
))
4097 if (filter
->dst
== p
->filetype
)
4100 * Delete the current filter...
4103 mimeDeleteFilter(MimeDatabase
, filter
);
4110 * 'write_irix_config()' - Update the config files used by the IRIX
4115 write_irix_config(cupsd_printer_t
*p
) /* I - Printer to update */
4117 char filename
[1024]; /* Interface script filename */
4118 cups_file_t
*fp
; /* Interface script file */
4119 ipp_attribute_t
*attr
; /* Attribute data */
4123 * Add dummy interface and GUI scripts to fool SGI's "challenged" printing
4124 * tools. First the interface script that tells the tools what kind of
4125 * printer we have...
4128 snprintf(filename
, sizeof(filename
), "/var/spool/lp/interface/%s", p
->name
);
4130 if (p
->type
& CUPS_PRINTER_CLASS
)
4132 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
4134 cupsFilePuts(fp
, "#!/bin/sh\n");
4136 if ((attr
= ippFindAttribute(p
->attrs
, "printer-make-and-model",
4137 IPP_TAG_TEXT
)) != NULL
)
4138 cupsFilePrintf(fp
, "NAME=\"%s\"\n", attr
->values
[0].string
.text
);
4139 else if (p
->type
& CUPS_PRINTER_CLASS
)
4140 cupsFilePuts(fp
, "NAME=\"Printer Class\"\n");
4142 cupsFilePuts(fp
, "NAME=\"Remote Destination\"\n");
4144 if (p
->type
& CUPS_PRINTER_COLOR
)
4145 cupsFilePuts(fp
, "TYPE=ColorPostScript\n");
4147 cupsFilePuts(fp
, "TYPE=MonoPostScript\n");
4149 cupsFilePrintf(fp
, "HOSTNAME=%s\n", ServerName
);
4150 cupsFilePrintf(fp
, "HOSTPRINTER=%s\n", p
->name
);
4154 chmod(filename
, 0755);
4155 chown(filename
, User
, Group
);
4159 * Then the member file that tells which device file the queue is connected
4160 * to... Networked printers use "/dev/null" in this file, so that's what
4161 * we use (the actual device URI can confuse some apps...)
4164 snprintf(filename
, sizeof(filename
), "/var/spool/lp/member/%s", p
->name
);
4166 if (p
->type
& CUPS_PRINTER_CLASS
)
4168 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
4170 cupsFilePuts(fp
, "/dev/null\n");
4174 chmod(filename
, 0644);
4175 chown(filename
, User
, Group
);
4179 * The gui_interface file is a script or program that launches a GUI
4180 * option panel for the printer, using options specified on the
4181 * command-line in the third argument. The option panel must send
4182 * any printing options to stdout on a single line when the user
4183 * accepts them, or nothing if the user cancels the dialog.
4185 * The default options panel program is /usr/bin/glpoptions, from
4186 * the ESP Print Pro software. You can select another using the
4187 * PrintcapGUI option.
4190 snprintf(filename
, sizeof(filename
), "/var/spool/lp/gui_interface/ELF/%s.gui", p
->name
);
4192 if (p
->type
& CUPS_PRINTER_CLASS
)
4194 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
4196 cupsFilePuts(fp
, "#!/bin/sh\n");
4197 cupsFilePrintf(fp
, "%s -d %s -o \"$3\"\n", PrintcapGUI
, p
->name
);
4201 chmod(filename
, 0755);
4202 chown(filename
, User
, Group
);
4206 * The POD config file is needed by the printstatus command to show
4207 * the printer location and device.
4210 snprintf(filename
, sizeof(filename
), "/var/spool/lp/pod/%s.config", p
->name
);
4212 if (p
->type
& CUPS_PRINTER_CLASS
)
4214 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
4216 cupsFilePrintf(fp
, "Printer Class | %s\n",
4217 (p
->type
& CUPS_PRINTER_COLOR
) ? "ColorPostScript" : "MonoPostScript");
4218 cupsFilePrintf(fp
, "Printer Model | %s\n", p
->make_model
? p
->make_model
: "");
4219 cupsFilePrintf(fp
, "Location Code | %s\n", p
->location
? p
->location
: "");
4220 cupsFilePrintf(fp
, "Physical Location | %s\n", p
->info
? p
->info
: "");
4221 cupsFilePrintf(fp
, "Port Path | %s\n", p
->device_uri
? p
->device_uri
: "");
4222 cupsFilePrintf(fp
, "Config Path | /var/spool/lp/pod/%s.config\n", p
->name
);
4223 cupsFilePrintf(fp
, "Active Status Path | /var/spool/lp/pod/%s.status\n", p
->name
);
4224 cupsFilePuts(fp
, "Status Update Wait | 10 seconds\n");
4228 chmod(filename
, 0664);
4229 chown(filename
, User
, Group
);
4235 * 'write_irix_state()' - Update the status files used by IRIX printing
4240 write_irix_state(cupsd_printer_t
*p
) /* I - Printer to update */
4242 char filename
[1024]; /* Interface script filename */
4243 cups_file_t
*fp
; /* Interface script file */
4244 int tag
; /* Status tag value */
4250 * The POD status file is needed for the printstatus window to
4251 * provide the current status of the printer.
4254 snprintf(filename
, sizeof(filename
), "/var/spool/lp/pod/%s.status", p
->name
);
4256 if (p
->type
& CUPS_PRINTER_CLASS
)
4258 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
4260 cupsFilePrintf(fp
, "Operational Status | %s\n",
4261 (p
->state
== IPP_PRINTER_IDLE
) ? "Idle" :
4262 (p
->state
== IPP_PRINTER_PROCESSING
) ? "Busy" :
4264 cupsFilePrintf(fp
, "Information | 01 00 00 | %s\n", CUPS_SVERSION
);
4265 cupsFilePrintf(fp
, "Information | 02 00 00 | Device URI: %s\n",
4266 p
->device_uri
? p
->device_uri
: "");
4267 cupsFilePrintf(fp
, "Information | 03 00 00 | %s jobs\n",
4268 p
->accepting
? "Accepting" : "Not accepting");
4269 cupsFilePrintf(fp
, "Information | 04 00 00 | %s\n", p
->state_message
);
4273 chmod(filename
, 0664);
4274 chown(filename
, User
, Group
);
4278 * The activeicons file is needed to provide desktop icons for printers:
4280 * [ quoted from /usr/lib/print/tagit ]
4282 * --- Type of printer tags (base values)
4284 * Dumb=66048 # 0x10200
4285 * DumbColor=66080 # 0x10220
4286 * Raster=66112 # 0x10240
4287 * ColorRaster=66144 # 0x10260
4288 * Plotter=66176 # 0x10280
4289 * PostScript=66208 # 0x102A0
4290 * ColorPostScript=66240 # 0x102C0
4291 * MonoPostScript=66272 # 0x102E0
4293 * --- Printer state modifiers for local printers
4298 * Unknown=3 # 0x3 (Faulted due to unknown reason)
4300 * --- Printer state modifiers for network printers
4304 * NetFaulted=10 # 0xA
4305 * NetUnknown=11 # 0xB (Faulted due to unknown reason)
4308 snprintf(filename
, sizeof(filename
), "/var/spool/lp/activeicons/%s", p
->name
);
4310 if (p
->type
& CUPS_PRINTER_CLASS
)
4312 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
4314 if (p
->type
& CUPS_PRINTER_COLOR
)
4319 if (p
->type
& CUPS_PRINTER_REMOTE
)
4322 if (p
->state
== IPP_PRINTER_PROCESSING
)
4325 else if (p
->state
== IPP_PRINTER_STOPPED
)
4328 cupsFilePuts(fp
, "#!/bin/sh\n");
4329 cupsFilePrintf(fp
, "#Tag %d\n", tag
);
4333 chmod(filename
, 0755);
4334 chown(filename
, User
, Group
);
4339 * The default file is needed by the printers window to show
4340 * the default printer.
4343 snprintf(filename
, sizeof(filename
), "/var/spool/lp/default");
4345 if (DefaultPrinter
!= NULL
)
4347 if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
4349 cupsFilePrintf(fp
, "%s\n", DefaultPrinter
->name
);
4353 chmod(filename
, 0644);
4354 chown(filename
, User
, Group
);
4364 * End of "$Id: printers.c 7677 2008-06-19 23:22:19Z mike $".