2 * "$Id: printers.c 7968 2008-09-19 23:03:01Z mike $"
4 * Printer routines for the Common UNIX Printing System (CUPS).
6 * Copyright 2007-2008 by Apple Inc.
7 * Copyright 1997-2007 by Easy Software Products, all rights reserved.
9 * These coded instructions, statements, and computer programs are the
10 * property of Apple Inc. and are protected by Federal copyright
11 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
12 * which should have been included with this file. If this file is
13 * file is missing or damaged, see the license at "http://www.cups.org/".
17 * cupsdAddPrinter() - Add a printer to the system.
18 * cupsdAddPrinterHistory() - Add the current printer state to the history.
19 * cupsdAddPrinterUser() - Add a user to the ACL.
20 * cupsdCreateCommonData() - Create the common printer data.
21 * cupsdDeleteAllPrinters() - Delete all printers from the system.
22 * cupsdDeletePrinter() - Delete a printer from the system.
23 * cupsdFindPrinter() - Find a printer in the list.
24 * cupsdFreePrinterUsers() - Free allow/deny users.
25 * cupsdLoadAllPrinters() - Load printers from the printers.conf file.
26 * cupsdRenamePrinter() - Rename a printer.
27 * cupsdSaveAllPrinters() - Save all printer definitions to the
29 * cupsdSetAuthInfoRequired() - Set the required authentication info.
30 * cupsdSetDeviceURI() - Set the device URI for a printer.
31 * cupsdSetPrinterAttr() - Set a printer attribute.
32 * cupsdSetPrinterAttrs() - Set printer attributes based upon the PPD
34 * cupsdSetPrinterReasons() - Set/update the reasons strings.
35 * cupsdSetPrinterState() - Update the current state of a printer.
36 * cupsdStopPrinter() - Stop a printer from printing any jobs...
37 * cupsdUpdatePrinters() - Update printers after a partial reload.
38 * cupsdValidateDest() - Validate a printer/class destination.
39 * cupsdWritePrintcap() - Write a pseudo-printcap file for older
40 * applications that need it...
41 * add_printer_defaults() - Add name-default attributes to the printer
43 * add_printer_filter() - Add a MIME filter for a printer.
44 * add_printer_formats() - Add document-format-supported values for
46 * compare_printers() - Compare two printers.
47 * delete_printer_filters() - Delete all MIME filters for a printer.
48 * write_irix_config() - Update the config files used by the IRIX
50 * write_irix_state() - Update the status files used by IRIX
51 * printing desktop tools.
52 * write_xml_string() - Write a string with XML escaping.
56 * Include necessary headers...
67 static void add_printer_defaults(cupsd_printer_t
*p
);
68 static void add_printer_filter(cupsd_printer_t
*p
, mime_type_t
*type
,
70 static void add_printer_formats(cupsd_printer_t
*p
);
71 static int compare_printers(void *first
, void *second
, void *data
);
72 static void delete_printer_filters(cupsd_printer_t
*p
);
74 static void write_irix_config(cupsd_printer_t
*p
);
75 static void write_irix_state(cupsd_printer_t
*p
);
77 static void write_xml_string(cups_file_t
*fp
, const char *s
);
81 * 'cupsdAddPrinter()' - Add a printer to the system.
84 cupsd_printer_t
* /* O - New printer */
85 cupsdAddPrinter(const char *name
) /* I - Name of printer */
87 cupsd_printer_t
*p
; /* New printer */
91 * Range check input...
94 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdAddPrinter(\"%s\")", name
);
97 * Create a new printer entity...
100 if ((p
= calloc(1, sizeof(cupsd_printer_t
))) == NULL
)
102 cupsdLogMessage(CUPSD_LOG_CRIT
, "Unable to allocate memory for printer - %s",
107 cupsdSetString(&p
->name
, name
);
108 cupsdSetString(&p
->info
, name
);
109 cupsdSetString(&p
->hostname
, ServerName
);
111 cupsdSetStringf(&p
->uri
, "ipp://%s:%d/printers/%s", ServerName
, LocalPort
, name
);
112 cupsdSetDeviceURI(p
, "file:/dev/null");
114 p
->state
= IPP_PRINTER_STOPPED
;
115 p
->state_time
= time(NULL
);
117 p
->shared
= DefaultShared
;
118 p
->filetype
= mimeAddType(MimeDatabase
, "printer", name
);
120 cupsdSetString(&p
->job_sheets
[0], "none");
121 cupsdSetString(&p
->job_sheets
[1], "none");
123 cupsdSetString(&p
->error_policy
, ErrorPolicy
);
124 cupsdSetString(&p
->op_policy
, DefaultPolicy
);
126 p
->op_policy_ptr
= DefaultPolicyPtr
;
128 if (MaxPrinterHistory
)
129 p
->history
= calloc(MaxPrinterHistory
, sizeof(ipp_t
*));
132 * Insert the printer in the printer list alphabetically...
136 Printers
= cupsArrayNew(compare_printers
, NULL
);
138 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
139 "cupsdAddPrinter: Adding %s to Printers", p
->name
);
140 cupsArrayAdd(Printers
, p
);
142 if (!ImplicitPrinters
)
143 ImplicitPrinters
= cupsArrayNew(compare_printers
, NULL
);
146 * Return the new printer...
154 * 'cupsdAddPrinterHistory()' - Add the current printer state to the history.
158 cupsdAddPrinterHistory(
159 cupsd_printer_t
*p
) /* I - Printer */
161 ipp_t
*history
; /* History collection */
165 * Stop early if we aren't keeping history data...
168 if (MaxPrinterHistory
<= 0)
172 * Retire old history data as needed...
175 p
->sequence_number
++;
177 if (p
->num_history
>= MaxPrinterHistory
)
180 ippDelete(p
->history
[0]);
181 memmove(p
->history
, p
->history
+ 1, p
->num_history
* sizeof(ipp_t
*));
185 * Create a collection containing the current printer-state, printer-up-time,
186 * printer-state-message, and printer-state-reasons attributes.
190 ippAddInteger(history
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-state",
192 ippAddBoolean(history
, IPP_TAG_PRINTER
, "printer-is-accepting-jobs",
194 ippAddBoolean(history
, IPP_TAG_PRINTER
, "printer-is-shared", p
->shared
);
195 ippAddString(history
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-state-message",
196 NULL
, p
->state_message
);
199 ippAddString(history
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
200 "com.apple.print.recoverable-message", NULL
, p
->recoverable
);
201 #endif /* __APPLE__ */
202 if (p
->num_reasons
== 0)
203 ippAddString(history
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
204 "printer-state-reasons", NULL
,
205 p
->state
== IPP_PRINTER_STOPPED
? "paused" : "none");
207 ippAddStrings(history
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
208 "printer-state-reasons", p
->num_reasons
, NULL
,
209 (const char * const *)p
->reasons
);
210 ippAddInteger(history
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
211 "printer-state-change-time", p
->state_time
);
212 ippAddInteger(history
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
213 "printer-state-sequence-number", p
->sequence_number
);
215 p
->history
[p
->num_history
] = history
;
221 * 'cupsdAddPrinterUser()' - Add a user to the ACL.
226 cupsd_printer_t
*p
, /* I - Printer */
227 const char *username
) /* I - User */
229 const char **temp
; /* Temporary array pointer */
235 if (p
->num_users
== 0)
236 temp
= malloc(sizeof(char **));
238 temp
= realloc(p
->users
, sizeof(char **) * (p
->num_users
+ 1));
244 temp
+= p
->num_users
;
246 if ((*temp
= strdup(username
)) != NULL
)
252 * 'cupsdCreateCommonData()' - Create the common printer data.
256 cupsdCreateCommonData(void)
258 int i
; /* Looping var */
259 ipp_attribute_t
*attr
; /* Attribute data */
260 cups_dir_t
*dir
; /* Notifier directory */
261 cups_dentry_t
*dent
; /* Notifier directory entry */
262 cups_array_t
*notifiers
; /* Notifier array */
263 char filename
[1024], /* Filename */
264 *notifier
; /* Current notifier */
265 cupsd_policy_t
*p
; /* Current policy */
266 static const int nups
[] = /* number-up-supported values */
267 { 1, 2, 4, 6, 9, 16 };
268 static const int orients
[4] =/* orientation-requested-supported values */
272 IPP_REVERSE_LANDSCAPE
,
275 static const char * const holds
[] = /* job-hold-until-supported values */
286 static const char * const versions
[] =/* ipp-versions-supported values */
291 static const int ops
[] = /* operations-supported values */
298 IPP_GET_JOB_ATTRIBUTES
,
300 IPP_GET_PRINTER_ATTRIBUTES
,
306 IPP_SET_JOB_ATTRIBUTES
,
307 IPP_CREATE_PRINTER_SUBSCRIPTION
,
308 IPP_CREATE_JOB_SUBSCRIPTION
,
309 IPP_GET_SUBSCRIPTION_ATTRIBUTES
,
310 IPP_GET_SUBSCRIPTIONS
,
311 IPP_RENEW_SUBSCRIPTION
,
312 IPP_CANCEL_SUBSCRIPTION
,
313 IPP_GET_NOTIFICATIONS
,
329 CUPS_AUTHENTICATE_JOB
,
334 static const char * const charsets
[] =/* charset-supported values */
339 static const char * const compressions
[] =
340 { /* document-compression-supported values */
344 #endif /* HAVE_LIBZ */
346 static const char * const multiple_document_handling
[] =
347 { /* multiple-document-handling-supported values */
348 "separate-documents-uncollated-copies",
349 "separate-documents-collated-copies"
351 static const char * const errors
[] = /* printer-error-policy-supported values */
358 static const char * const notify_attrs
[] =
359 { /* notify-attributes-supported values */
360 "printer-state-change-time",
361 "notify-lease-expiration-time",
362 "notify-subscriber-user-name"
364 static const char * const notify_events
[] =
365 { /* notify-events-supported values */
367 "job-config-changed",
374 "printer-config-changed",
376 "printer-finishings-changed",
377 "printer-media-changed",
381 "printer-state-changed",
388 static const char * const job_settable
[] =
389 { /* job-settable-attributes-supported */
395 "multiple-document-handling",
397 "orientation-requested",
400 "printer-resolution",
406 ippDelete(CommonData
);
408 CommonData
= ippNew();
411 * This list of attributes is sorted to improve performance when the
412 * client provides a requested-attributes attribute...
415 /* charset-configured */
416 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_CHARSET
| IPP_TAG_COPY
,
417 "charset-configured", NULL
, DefaultCharset
);
419 /* charset-supported */
420 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_CHARSET
| IPP_TAG_COPY
,
421 "charset-supported", sizeof(charsets
) / sizeof(charsets
[0]),
424 /* compression-supported */
425 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
426 "compression-supported",
427 sizeof(compressions
) / sizeof(compressions
[0]),
430 /* copies-supported */
431 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "copies-supported", 1, MaxCopies
);
434 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
| IPP_TAG_COPY
,
435 "cups-version", NULL
, CUPS_SVERSION
+ 6);
437 /* generated-natural-language-supported */
438 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_LANGUAGE
| IPP_TAG_COPY
,
439 "generated-natural-language-supported", NULL
, DefaultLanguage
);
441 /* ipp-versions-supported */
442 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
443 "ipp-versions-supported", sizeof(versions
) / sizeof(versions
[0]),
446 /* job-hold-until-supported */
447 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
448 "job-hold-until-supported", sizeof(holds
) / sizeof(holds
[0]),
451 /* job-priority-supported */
452 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
453 "job-priority-supported", 100);
455 /* job-settable-attributes-supported */
456 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
457 "job-settable-attributes-supported",
458 sizeof(job_settable
) / sizeof(job_settable
[0]),
461 /* job-sheets-supported */
462 if (cupsArrayCount(Banners
) > 0)
465 * Setup the job-sheets-supported attribute...
468 if (Classification
&& !ClassifyOverride
)
469 attr
= ippAddString(CommonData
, IPP_TAG_PRINTER
,
470 IPP_TAG_NAME
| IPP_TAG_COPY
,
471 "job-sheets-supported", NULL
, Classification
);
473 attr
= ippAddStrings(CommonData
, IPP_TAG_PRINTER
,
474 IPP_TAG_NAME
| IPP_TAG_COPY
,
475 "job-sheets-supported", cupsArrayCount(Banners
) + 1,
479 cupsdLogMessage(CUPSD_LOG_EMERG
,
480 "Unable to allocate memory for "
481 "job-sheets-supported attribute: %s!", strerror(errno
));
482 else if (!Classification
|| ClassifyOverride
)
484 cupsd_banner_t
*banner
; /* Current banner */
487 attr
->values
[0].string
.text
= _cupsStrAlloc("none");
489 for (i
= 1, banner
= (cupsd_banner_t
*)cupsArrayFirst(Banners
);
491 i
++, banner
= (cupsd_banner_t
*)cupsArrayNext(Banners
))
492 attr
->values
[i
].string
.text
= banner
->name
;
496 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
497 "job-sheets-supported", NULL
, "none");
499 /* multiple-document-handling-supported */
500 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
501 "multiple-document-handling-supported",
502 sizeof(multiple_document_handling
) /
503 sizeof(multiple_document_handling
[0]), NULL
,
504 multiple_document_handling
);
506 /* multiple-document-jobs-supported */
507 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
,
508 "multiple-document-jobs-supported", 1);
510 /* multiple-operation-time-out */
511 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
512 "multiple-operation-time-out", 60);
514 /* natural-language-configured */
515 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_LANGUAGE
| IPP_TAG_COPY
,
516 "natural-language-configured", NULL
, DefaultLanguage
);
518 /* notify-attributes-supported */
519 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
520 "notify-attributes-supported",
521 (int)(sizeof(notify_attrs
) / sizeof(notify_attrs
[0])),
524 /* notify-lease-duration-supported */
525 ippAddRange(CommonData
, IPP_TAG_PRINTER
,
526 "notify-lease-duration-supported", 0,
527 MaxLeaseDuration
? MaxLeaseDuration
: 2147483647);
529 /* notify-max-events-supported */
530 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
531 "notify-max-events-supported", MaxEvents
);
533 /* notify-events-supported */
534 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
535 "notify-events-supported",
536 (int)(sizeof(notify_events
) / sizeof(notify_events
[0])),
537 NULL
, notify_events
);
539 /* notify-pull-method-supported */
540 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
541 "notify-pull-method-supported", NULL
, "ippget");
543 /* notify-schemes-supported */
544 snprintf(filename
, sizeof(filename
), "%s/notifier", ServerBin
);
545 if ((dir
= cupsDirOpen(filename
)) != NULL
)
547 notifiers
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
549 while ((dent
= cupsDirRead(dir
)) != NULL
)
550 if (S_ISREG(dent
->fileinfo
.st_mode
) &&
551 (dent
->fileinfo
.st_mode
& S_IXOTH
) != 0)
552 cupsArrayAdd(notifiers
, _cupsStrAlloc(dent
->filename
));
554 if (cupsArrayCount(notifiers
) > 0)
556 attr
= ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
557 "notify-schemes-supported",
558 cupsArrayCount(notifiers
), NULL
, NULL
);
560 for (i
= 0, notifier
= (char *)cupsArrayFirst(notifiers
);
562 i
++, notifier
= (char *)cupsArrayNext(notifiers
))
563 attr
->values
[i
].string
.text
= notifier
;
566 cupsArrayDelete(notifiers
);
570 /* number-up-supported */
571 ippAddIntegers(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
572 "number-up-supported", sizeof(nups
) / sizeof(nups
[0]), nups
);
574 /* operations-supported */
575 ippAddIntegers(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
576 "operations-supported",
577 sizeof(ops
) / sizeof(ops
[0]) + JobFiles
- 1, ops
);
579 /* orientation-requested-supported */
580 ippAddIntegers(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
581 "orientation-requested-supported", 4, orients
);
583 /* page-ranges-supported */
584 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
, "page-ranges-supported", 1);
586 /* pdf-override-supported */
587 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
588 "pdl-override-supported", NULL
, "not-attempted");
590 /* printer-error-policy-supported */
591 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
592 "printer-error-policy-supported",
593 sizeof(errors
) / sizeof(errors
[0]), NULL
, errors
);
595 /* printer-op-policy-supported */
596 attr
= ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
597 "printer-op-policy-supported", cupsArrayCount(Policies
),
599 for (i
= 0, p
= (cupsd_policy_t
*)cupsArrayFirst(Policies
);
601 i
++, p
= (cupsd_policy_t
*)cupsArrayNext(Policies
))
602 attr
->values
[i
].string
.text
= p
->name
;
604 /* server-is-sharing-printers */
605 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
, "server-is-sharing-printers",
606 BrowseLocalProtocols
!= 0 && Browsing
);
611 * 'cupsdDeleteAllPrinters()' - Delete all printers from the system.
615 cupsdDeleteAllPrinters(void)
617 cupsd_printer_t
*p
; /* Pointer to current printer/class */
620 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
622 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
623 cupsdDeletePrinter(p
, 0);
628 * 'cupsdDeletePrinter()' - Delete a printer from the system.
633 cupsd_printer_t
*p
, /* I - Printer to delete */
634 int update
) /* I - Update printers.conf? */
636 int i
; /* Looping var */
638 char filename
[1024]; /* Interface script filename */
642 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdDeletePrinter(p=%p(%s), update=%d)",
646 * Save the current position in the Printers array...
649 cupsArraySave(Printers
);
652 * Stop printing on this printer...
655 cupsdStopPrinter(p
, update
);
658 * If this printer is the next for browsing, point to the next one...
663 cupsArrayFind(Printers
, p
);
664 BrowseNext
= (cupsd_printer_t
*)cupsArrayNext(Printers
);
668 * Remove the printer from the list...
671 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
672 "cupsdDeletePrinter: Removing %s from Printers", p
->name
);
673 cupsArrayRemove(Printers
, p
);
675 if (p
->type
& CUPS_PRINTER_IMPLICIT
)
677 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
678 "cupsdDeletePrinter: Removing %s from ImplicitPrinters",
680 cupsArrayRemove(ImplicitPrinters
, p
);
684 * Remove the dummy interface/icon/option files under IRIX...
688 snprintf(filename
, sizeof(filename
), "/var/spool/lp/interface/%s", p
->name
);
691 snprintf(filename
, sizeof(filename
), "/var/spool/lp/gui_interface/ELF/%s.gui",
695 snprintf(filename
, sizeof(filename
), "/var/spool/lp/activeicons/%s", p
->name
);
698 snprintf(filename
, sizeof(filename
), "/var/spool/lp/pod/%s.config", p
->name
);
701 snprintf(filename
, sizeof(filename
), "/var/spool/lp/pod/%s.status", p
->name
);
704 snprintf(filename
, sizeof(filename
), "/var/spool/lp/member/%s", p
->name
);
709 * If p is the default printer, assign a different one...
712 if (p
== DefaultPrinter
)
714 DefaultPrinter
= NULL
;
716 if (UseNetworkDefault
)
719 * Find the first network default printer and use it...
722 cupsd_printer_t
*dp
; /* New default printer */
725 for (dp
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
727 dp
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
728 if (dp
!= p
&& (dp
->type
& CUPS_PRINTER_DEFAULT
))
737 * Remove this printer from any classes...
740 if (!(p
->type
& CUPS_PRINTER_IMPLICIT
))
742 cupsdDeletePrinterFromClasses(p
);
745 * Deregister from any browse protocols...
748 cupsdDeregisterPrinter(p
, 1);
752 * Free all memory used by the printer...
755 if (p
->printers
!= NULL
)
758 if (MaxPrinterHistory
)
760 for (i
= 0; i
< p
->num_history
; i
++)
761 ippDelete(p
->history
[i
]);
766 for (i
= 0; i
< p
->num_reasons
; i
++)
767 _cupsStrFree(p
->reasons
[i
]);
771 delete_printer_filters(p
);
773 mimeDeleteType(MimeDatabase
, p
->filetype
);
774 mimeDeleteType(MimeDatabase
, p
->prefiltertype
);
776 cupsdFreePrinterUsers(p
);
779 cupsdClearString(&p
->uri
);
780 cupsdClearString(&p
->hostname
);
781 cupsdClearString(&p
->name
);
782 cupsdClearString(&p
->location
);
783 cupsdClearString(&p
->make_model
);
784 cupsdClearString(&p
->info
);
785 cupsdClearString(&p
->job_sheets
[0]);
786 cupsdClearString(&p
->job_sheets
[1]);
787 cupsdClearString(&p
->device_uri
);
788 cupsdClearString(&p
->sanitized_device_uri
);
789 cupsdClearString(&p
->port_monitor
);
790 cupsdClearString(&p
->op_policy
);
791 cupsdClearString(&p
->error_policy
);
793 cupsdClearString(&p
->alert
);
794 cupsdClearString(&p
->alert_description
);
797 cupsdClearString(&p
->product
);
798 cupsdClearString(&p
->pdl
);
799 #endif /* HAVE_DNSSD */
801 cupsArrayDelete(p
->filetypes
);
804 free(p
->browse_attrs
);
807 cupsdClearString(&p
->recoverable
);
808 #endif /* __APPLE__ */
810 cupsFreeOptions(p
->num_options
, p
->options
);
815 * Restore the previous position in the Printers array...
818 cupsArrayRestore(Printers
);
823 * 'cupsdFindDest()' - Find a destination in the list.
826 cupsd_printer_t
* /* O - Destination in list */
827 cupsdFindDest(const char *name
) /* I - Name of printer or class to find */
829 cupsd_printer_t key
; /* Search key */
832 key
.name
= (char *)name
;
833 return ((cupsd_printer_t
*)cupsArrayFind(Printers
, &key
));
838 * 'cupsdFindPrinter()' - Find a printer in the list.
841 cupsd_printer_t
* /* O - Printer in list */
842 cupsdFindPrinter(const char *name
) /* I - Name of printer to find */
844 cupsd_printer_t
*p
; /* Printer in list */
847 if ((p
= cupsdFindDest(name
)) != NULL
&& (p
->type
& CUPS_PRINTER_CLASS
))
855 * 'cupsdFreePrinterUsers()' - Free allow/deny users.
859 cupsdFreePrinterUsers(
860 cupsd_printer_t
*p
) /* I - Printer */
862 int i
; /* Looping var */
865 if (!p
|| !p
->num_users
)
868 for (i
= 0; i
< p
->num_users
; i
++)
869 free((void *)p
->users
[i
]);
879 * 'cupsdLoadAllPrinters()' - Load printers from the printers.conf file.
883 cupsdLoadAllPrinters(void)
885 cups_file_t
*fp
; /* printers.conf file */
886 int linenum
; /* Current line number */
887 char line
[1024], /* Line from file */
888 *value
, /* Pointer to value */
889 *valueptr
; /* Pointer into value */
890 cupsd_printer_t
*p
; /* Current printer */
894 * Open the printers.conf file...
897 snprintf(line
, sizeof(line
), "%s/printers.conf", ServerRoot
);
898 if ((fp
= cupsFileOpen(line
, "r")) == NULL
)
901 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to open %s - %s", line
,
907 * Read printer configurations until we hit EOF...
913 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
916 * Decode the directive...
919 if (!strcasecmp(line
, "<Printer") ||
920 !strcasecmp(line
, "<DefaultPrinter"))
923 * <Printer name> or <DefaultPrinter name>
926 if (p
== NULL
&& value
)
929 * Add the printer and a base file type...
932 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Loading printer %s...", value
);
934 p
= cupsdAddPrinter(value
);
936 p
->state
= IPP_PRINTER_IDLE
;
939 * Set the default printer as needed...
942 if (!strcasecmp(line
, "<DefaultPrinter"))
946 cupsdLogMessage(CUPSD_LOG_ERROR
,
947 "Syntax error on line %d of printers.conf.", linenum
);
949 else if (!strcasecmp(line
, "</Printer>"))
954 * Close out the current printer...
957 cupsdSetPrinterAttrs(p
);
958 cupsdAddPrinterHistory(p
);
960 if (strncmp(p
->device_uri
, "file:", 5) &&
961 p
->state
!= IPP_PRINTER_STOPPED
)
964 * See if the backend exists...
967 snprintf(line
, sizeof(line
), "%s/backend/%s", ServerBin
,
970 if ((valueptr
= strchr(line
+ strlen(ServerBin
), ':')) != NULL
)
971 *valueptr
= '\0'; /* Chop everything but URI scheme */
976 * Backend does not exist, stop printer...
979 p
->state
= IPP_PRINTER_STOPPED
;
980 snprintf(p
->state_message
, sizeof(p
->state_message
),
981 "Backend %s does not exist!", line
);
988 cupsdLogMessage(CUPSD_LOG_ERROR
,
989 "Syntax error on line %d of printers.conf.", linenum
);
993 cupsdLogMessage(CUPSD_LOG_ERROR
,
994 "Syntax error on line %d of printers.conf.", linenum
);
996 else if (!strcasecmp(line
, "AuthInfoRequired"))
998 if (!cupsdSetAuthInfoRequired(p
, value
, NULL
))
999 cupsdLogMessage(CUPSD_LOG_ERROR
,
1000 "Bad AuthInfoRequired on line %d of printers.conf.",
1003 else if (!strcasecmp(line
, "Info"))
1006 cupsdSetString(&p
->info
, value
);
1008 else if (!strcasecmp(line
, "MakeModel"))
1011 cupsdSetString(&p
->make_model
, value
);
1013 else if (!strcasecmp(line
, "Location"))
1016 cupsdSetString(&p
->location
, value
);
1018 else if (!strcasecmp(line
, "DeviceURI"))
1021 cupsdSetDeviceURI(p
, value
);
1023 cupsdLogMessage(CUPSD_LOG_ERROR
,
1024 "Syntax error on line %d of printers.conf.", linenum
);
1026 else if (!strcasecmp(line
, "Option") && value
)
1032 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1035 cupsdLogMessage(CUPSD_LOG_ERROR
,
1036 "Syntax error on line %d of printers.conf.", linenum
);
1039 for (; *valueptr
&& isspace(*valueptr
& 255); *valueptr
++ = '\0');
1041 p
->num_options
= cupsAddOption(value
, valueptr
, p
->num_options
,
1045 else if (!strcasecmp(line
, "PortMonitor"))
1047 if (value
&& strcmp(value
, "none"))
1048 cupsdSetString(&p
->port_monitor
, value
);
1050 cupsdClearString(&p
->port_monitor
);
1052 cupsdLogMessage(CUPSD_LOG_ERROR
,
1053 "Syntax error on line %d of printers.conf.", linenum
);
1055 else if (!strcasecmp(line
, "Reason"))
1058 p
->num_reasons
< (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
1060 p
->reasons
[p
->num_reasons
] = _cupsStrAlloc(value
);
1064 cupsdLogMessage(CUPSD_LOG_ERROR
,
1065 "Syntax error on line %d of printers.conf.", linenum
);
1067 else if (!strcasecmp(line
, "State"))
1070 * Set the initial queue state...
1073 if (value
&& !strcasecmp(value
, "idle"))
1074 p
->state
= IPP_PRINTER_IDLE
;
1075 else if (value
&& !strcasecmp(value
, "stopped"))
1076 p
->state
= IPP_PRINTER_STOPPED
;
1078 cupsdLogMessage(CUPSD_LOG_ERROR
,
1079 "Syntax error on line %d of printers.conf.", linenum
);
1081 else if (!strcasecmp(line
, "StateMessage"))
1084 * Set the initial queue state message...
1088 strlcpy(p
->state_message
, value
, sizeof(p
->state_message
));
1090 else if (!strcasecmp(line
, "StateTime"))
1093 * Set the state time...
1097 p
->state_time
= atoi(value
);
1099 else if (!strcasecmp(line
, "Accepting"))
1102 * Set the initial accepting state...
1106 (!strcasecmp(value
, "yes") ||
1107 !strcasecmp(value
, "on") ||
1108 !strcasecmp(value
, "true")))
1111 (!strcasecmp(value
, "no") ||
1112 !strcasecmp(value
, "off") ||
1113 !strcasecmp(value
, "false")))
1116 cupsdLogMessage(CUPSD_LOG_ERROR
,
1117 "Syntax error on line %d of printers.conf.", linenum
);
1119 else if (!strcasecmp(line
, "Type"))
1122 p
->type
= atoi(value
);
1124 cupsdLogMessage(CUPSD_LOG_ERROR
,
1125 "Syntax error on line %d of printers.conf.", linenum
);
1127 else if (!strcasecmp(line
, "Product"))
1132 p
->product
= _cupsStrAlloc(value
);
1133 #endif /* HAVE_DNSSD */
1136 cupsdLogMessage(CUPSD_LOG_ERROR
,
1137 "Syntax error on line %d of printers.conf.", linenum
);
1139 else if (!strcasecmp(line
, "Filter"))
1144 p
->filters
= cupsArrayNew(NULL
, NULL
);
1146 cupsArrayAdd(p
->filters
, _cupsStrAlloc(value
));
1149 cupsdLogMessage(CUPSD_LOG_ERROR
,
1150 "Syntax error on line %d of printers.conf.", linenum
);
1152 else if (!strcasecmp(line
, "PreFilter"))
1156 if (!p
->pre_filters
)
1157 p
->pre_filters
= cupsArrayNew(NULL
, NULL
);
1159 cupsArrayAdd(p
->pre_filters
, _cupsStrAlloc(value
));
1162 cupsdLogMessage(CUPSD_LOG_ERROR
,
1163 "Syntax error on line %d of printers.conf.", linenum
);
1165 else if (!strcasecmp(line
, "Shared"))
1168 * Set the initial shared state...
1172 (!strcasecmp(value
, "yes") ||
1173 !strcasecmp(value
, "on") ||
1174 !strcasecmp(value
, "true")))
1177 (!strcasecmp(value
, "no") ||
1178 !strcasecmp(value
, "off") ||
1179 !strcasecmp(value
, "false")))
1182 cupsdLogMessage(CUPSD_LOG_ERROR
,
1183 "Syntax error on line %d of printers.conf.", linenum
);
1185 else if (!strcasecmp(line
, "JobSheets"))
1188 * Set the initial job sheets...
1193 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1198 cupsdSetString(&p
->job_sheets
[0], value
);
1200 while (isspace(*valueptr
& 255))
1205 for (value
= valueptr
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1210 cupsdSetString(&p
->job_sheets
[1], value
);
1214 cupsdLogMessage(CUPSD_LOG_ERROR
,
1215 "Syntax error on line %d of printers.conf.", linenum
);
1217 else if (!strcasecmp(line
, "AllowUser"))
1222 cupsdAddPrinterUser(p
, value
);
1225 cupsdLogMessage(CUPSD_LOG_ERROR
,
1226 "Syntax error on line %d of printers.conf.", linenum
);
1228 else if (!strcasecmp(line
, "DenyUser"))
1233 cupsdAddPrinterUser(p
, value
);
1236 cupsdLogMessage(CUPSD_LOG_ERROR
,
1237 "Syntax error on line %d of printers.conf.", linenum
);
1239 else if (!strcasecmp(line
, "QuotaPeriod"))
1242 p
->quota_period
= atoi(value
);
1244 cupsdLogMessage(CUPSD_LOG_ERROR
,
1245 "Syntax error on line %d of printers.conf.", linenum
);
1247 else if (!strcasecmp(line
, "PageLimit"))
1250 p
->page_limit
= atoi(value
);
1252 cupsdLogMessage(CUPSD_LOG_ERROR
,
1253 "Syntax error on line %d of printers.conf.", linenum
);
1255 else if (!strcasecmp(line
, "KLimit"))
1258 p
->k_limit
= atoi(value
);
1260 cupsdLogMessage(CUPSD_LOG_ERROR
,
1261 "Syntax error on line %d of printers.conf.", linenum
);
1263 else if (!strcasecmp(line
, "OpPolicy"))
1267 cupsd_policy_t
*pol
; /* Policy */
1270 if ((pol
= cupsdFindPolicy(value
)) != NULL
)
1272 cupsdSetString(&p
->op_policy
, value
);
1273 p
->op_policy_ptr
= pol
;
1276 cupsdLogMessage(CUPSD_LOG_ERROR
,
1277 "Bad policy \"%s\" on line %d of printers.conf",
1281 cupsdLogMessage(CUPSD_LOG_ERROR
,
1282 "Syntax error on line %d of printers.conf.", linenum
);
1284 else if (!strcasecmp(line
, "ErrorPolicy"))
1287 cupsdSetString(&p
->error_policy
, value
);
1289 cupsdLogMessage(CUPSD_LOG_ERROR
,
1290 "Syntax error on line %d of printers.conf.", linenum
);
1292 else if (!strcasecmp(line
, "Attribute") && value
)
1294 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1297 cupsdLogMessage(CUPSD_LOG_ERROR
,
1298 "Syntax error on line %d of printers.conf.", linenum
);
1301 for (; *valueptr
&& isspace(*valueptr
& 255); *valueptr
++ = '\0');
1304 cupsdSetPrinterAttrs(p
);
1306 cupsdSetPrinterAttr(p
, value
, valueptr
);
1308 if (!strncmp(value
, "marker-", 7))
1309 p
->marker_time
= time(NULL
);
1315 * Something else we don't understand...
1318 cupsdLogMessage(CUPSD_LOG_ERROR
,
1319 "Unknown configuration directive %s on line %d of printers.conf.",
1329 * 'cupsdRenamePrinter()' - Rename a printer.
1334 cupsd_printer_t
*p
, /* I - Printer */
1335 const char *name
) /* I - New name */
1338 * Remove the printer from the array(s) first...
1341 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1342 "cupsdRenamePrinter: Removing %s from Printers", p
->name
);
1343 cupsArrayRemove(Printers
, p
);
1345 if (p
->type
& CUPS_PRINTER_IMPLICIT
)
1347 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1348 "cupsdRenamePrinter: Removing %s from ImplicitPrinters",
1350 cupsArrayRemove(ImplicitPrinters
, p
);
1354 * Rename the printer type...
1357 mimeDeleteType(MimeDatabase
, p
->filetype
);
1358 p
->filetype
= mimeAddType(MimeDatabase
, "printer", name
);
1360 mimeDeleteType(MimeDatabase
, p
->prefiltertype
);
1361 p
->prefiltertype
= mimeAddType(MimeDatabase
, "prefilter", name
);
1364 * Rename the printer...
1367 cupsdSetString(&p
->name
, name
);
1370 * Reset printer attributes...
1373 cupsdSetPrinterAttrs(p
);
1376 * Add the printer back to the printer array(s)...
1379 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1380 "cupsdRenamePrinter: Adding %s to Printers", p
->name
);
1381 cupsArrayAdd(Printers
, p
);
1383 if (p
->type
& CUPS_PRINTER_IMPLICIT
)
1385 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1386 "cupsdRenamePrinter: Adding %s to ImplicitPrinters",
1388 cupsArrayAdd(ImplicitPrinters
, p
);
1394 * 'cupsdSaveAllPrinters()' - Save all printer definitions to the printers.conf
1399 cupsdSaveAllPrinters(void)
1401 int i
; /* Looping var */
1402 cups_file_t
*fp
; /* printers.conf file */
1403 char temp
[1024], /* Temporary string */
1404 backup
[1024], /* printers.conf.O file */
1405 value
[2048], /* Value string */
1406 *ptr
; /* Pointer into value */
1407 cupsd_printer_t
*printer
; /* Current printer class */
1408 time_t curtime
; /* Current time */
1409 struct tm
*curdate
; /* Current date */
1410 cups_option_t
*option
; /* Current option */
1411 ipp_attribute_t
*marker
; /* Current marker attribute */
1415 * Create the printers.conf file...
1418 snprintf(temp
, sizeof(temp
), "%s/printers.conf", ServerRoot
);
1419 snprintf(backup
, sizeof(backup
), "%s/printers.conf.O", ServerRoot
);
1421 if (rename(temp
, backup
))
1423 if (errno
!= ENOENT
)
1424 cupsdLogMessage(CUPSD_LOG_ERROR
,
1425 "Unable to backup printers.conf - %s", strerror(errno
));
1428 if ((fp
= cupsFileOpen(temp
, "w")) == NULL
)
1430 cupsdLogMessage(CUPSD_LOG_ERROR
,
1431 "Unable to save printers.conf - %s", strerror(errno
));
1433 if (rename(backup
, temp
))
1434 cupsdLogMessage(CUPSD_LOG_ERROR
,
1435 "Unable to restore printers.conf - %s", strerror(errno
));
1439 cupsdLogMessage(CUPSD_LOG_INFO
, "Saving printers.conf...");
1442 * Restrict access to the file...
1445 fchown(cupsFileNumber(fp
), getuid(), Group
);
1446 fchmod(cupsFileNumber(fp
), 0600);
1449 * Write a small header to the file...
1452 curtime
= time(NULL
);
1453 curdate
= localtime(&curtime
);
1454 strftime(temp
, sizeof(temp
) - 1, "%Y-%m-%d %H:%M", curdate
);
1456 cupsFilePuts(fp
, "# Printer configuration file for " CUPS_SVERSION
"\n");
1457 cupsFilePrintf(fp
, "# Written by cupsd on %s\n", temp
);
1460 * Write each local printer known to the system...
1463 for (printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
1465 printer
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
1468 * Skip remote destinations and printer classes...
1471 if ((printer
->type
& CUPS_PRINTER_DISCOVERED
) ||
1472 (printer
->type
& CUPS_PRINTER_CLASS
) ||
1473 (printer
->type
& CUPS_PRINTER_IMPLICIT
))
1477 * Write printers as needed...
1480 if (printer
== DefaultPrinter
)
1481 cupsFilePrintf(fp
, "<DefaultPrinter %s>\n", printer
->name
);
1483 cupsFilePrintf(fp
, "<Printer %s>\n", printer
->name
);
1485 if (printer
->num_auth_info_required
> 0)
1487 switch (printer
->num_auth_info_required
)
1490 strlcpy(value
, printer
->auth_info_required
[0], sizeof(value
));
1494 snprintf(value
, sizeof(value
), "%s,%s",
1495 printer
->auth_info_required
[0],
1496 printer
->auth_info_required
[1]);
1501 snprintf(value
, sizeof(value
), "%s,%s,%s",
1502 printer
->auth_info_required
[0],
1503 printer
->auth_info_required
[1],
1504 printer
->auth_info_required
[2]);
1508 cupsFilePutConf(fp
, "AuthInfoRequired", value
);
1512 cupsFilePutConf(fp
, "Info", printer
->info
);
1514 if (printer
->location
)
1515 cupsFilePutConf(fp
, "Location", printer
->location
);
1517 if (printer
->make_model
)
1518 cupsFilePutConf(fp
, "MakeModel", printer
->make_model
);
1520 cupsFilePutConf(fp
, "DeviceURI", printer
->device_uri
);
1522 if (printer
->port_monitor
)
1523 cupsFilePutConf(fp
, "PortMonitor", printer
->port_monitor
);
1525 if (printer
->state
== IPP_PRINTER_STOPPED
)
1527 cupsFilePuts(fp
, "State Stopped\n");
1529 if (printer
->state_message
)
1530 cupsFilePutConf(fp
, "StateMessage", printer
->state_message
);
1533 cupsFilePuts(fp
, "State Idle\n");
1535 cupsFilePrintf(fp
, "StateTime %d\n", (int)printer
->state_time
);
1537 for (i
= 0; i
< printer
->num_reasons
; i
++)
1538 cupsFilePutConf(fp
, "Reason", printer
->reasons
[i
]);
1540 cupsFilePrintf(fp
, "Type %d", printer
->type
);
1543 if (printer
->product
)
1544 cupsFilePutConf(fp
, "Product", printer
->product
);
1545 #endif /* HAVE_DNSSD */
1547 for (ptr
= (char *)cupsArrayFirst(printer
->filters
);
1549 ptr
= (char *)cupsArrayNext(printer
->filters
))
1550 cupsFilePutConf(fp
, "Filter", ptr
);
1552 for (ptr
= (char *)cupsArrayFirst(printer
->pre_filters
);
1554 ptr
= (char *)cupsArrayNext(printer
->pre_filters
))
1555 cupsFilePutConf(fp
, "PreFilter", ptr
);
1557 if (printer
->accepting
)
1558 cupsFilePuts(fp
, "Accepting Yes\n");
1560 cupsFilePuts(fp
, "Accepting No\n");
1562 if (printer
->shared
)
1563 cupsFilePuts(fp
, "Shared Yes\n");
1565 cupsFilePuts(fp
, "Shared No\n");
1567 snprintf(value
, sizeof(value
), "%s %s", printer
->job_sheets
[0],
1568 printer
->job_sheets
[1]);
1569 cupsFilePutConf(fp
, "JobSheets", value
);
1571 cupsFilePrintf(fp
, "QuotaPeriod %d\n", printer
->quota_period
);
1572 cupsFilePrintf(fp
, "PageLimit %d\n", printer
->page_limit
);
1573 cupsFilePrintf(fp
, "KLimit %d\n", printer
->k_limit
);
1575 for (i
= 0; i
< printer
->num_users
; i
++)
1576 cupsFilePutConf(fp
, printer
->deny_users
? "DenyUser" : "AllowUser",
1579 if (printer
->op_policy
)
1580 cupsFilePutConf(fp
, "OpPolicy", printer
->op_policy
);
1581 if (printer
->error_policy
)
1582 cupsFilePutConf(fp
, "ErrorPolicy", printer
->error_policy
);
1584 for (i
= printer
->num_options
, option
= printer
->options
;
1588 snprintf(value
, sizeof(value
), "%s %s", option
->name
, option
->value
);
1589 cupsFilePutConf(fp
, "Option", value
);
1592 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-colors",
1593 IPP_TAG_NAME
)) != NULL
)
1595 snprintf(value
, sizeof(value
), "%s ", marker
->name
);
1597 for (i
= 0, ptr
= value
+ strlen(value
);
1598 i
< marker
->num_values
&& ptr
< (value
+ sizeof(value
) - 1);
1604 strlcpy(ptr
, marker
->values
[i
].string
.text
,
1605 value
+ sizeof(value
) - ptr
);
1610 cupsFilePutConf(fp
, "Attribute", value
);
1613 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-levels",
1614 IPP_TAG_INTEGER
)) != NULL
)
1616 cupsFilePrintf(fp
, "Attribute %s %d", marker
->name
,
1617 marker
->values
[0].integer
);
1618 for (i
= 1; i
< marker
->num_values
; i
++)
1619 cupsFilePrintf(fp
, ",%d", marker
->values
[i
].integer
);
1620 cupsFilePuts(fp
, "\n");
1623 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-message",
1624 IPP_TAG_TEXT
)) != NULL
)
1626 snprintf(value
, sizeof(value
), "%s %s", marker
->name
,
1627 marker
->values
[0].string
.text
);
1629 cupsFilePutConf(fp
, "Attribute", value
);
1632 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-names",
1633 IPP_TAG_NAME
)) != NULL
)
1635 snprintf(value
, sizeof(value
), "%s ", marker
->name
);
1637 for (i
= 0, ptr
= value
+ strlen(value
);
1638 i
< marker
->num_values
&& ptr
< (value
+ sizeof(value
) - 1);
1644 strlcpy(ptr
, marker
->values
[i
].string
.text
,
1645 value
+ sizeof(value
) - ptr
);
1650 cupsFilePutConf(fp
, "Attribute", value
);
1653 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-types",
1654 IPP_TAG_KEYWORD
)) != NULL
)
1656 snprintf(value
, sizeof(value
), "%s ", marker
->name
);
1658 for (i
= 0, ptr
= value
+ strlen(value
);
1659 i
< marker
->num_values
&& ptr
< (value
+ sizeof(value
) - 1);
1665 strlcpy(ptr
, marker
->values
[i
].string
.text
,
1666 value
+ sizeof(value
) - ptr
);
1671 cupsFilePutConf(fp
, "Attribute", value
);
1674 cupsFilePuts(fp
, "</Printer>\n");
1678 * Make IRIX desktop & printer status happy
1681 write_irix_state(printer
);
1690 * 'cupsdSetAuthInfoRequired()' - Set the required authentication info.
1693 int /* O - 1 if value OK, 0 otherwise */
1694 cupsdSetAuthInfoRequired(
1695 cupsd_printer_t
*p
, /* I - Printer */
1696 const char *values
, /* I - Plain text value (or NULL) */
1697 ipp_attribute_t
*attr
) /* I - IPP attribute value (or NULL) */
1699 int i
; /* Looping var */
1702 p
->num_auth_info_required
= 0;
1705 * Do we have a plain text value?
1711 * Yes, grab the keywords...
1714 const char *end
; /* End of current value */
1717 while (*values
&& p
->num_auth_info_required
< 4)
1719 if ((end
= strchr(values
, ',')) == NULL
)
1720 end
= values
+ strlen(values
);
1722 if ((end
- values
) == 4 && !strncmp(values
, "none", 4))
1724 if (p
->num_auth_info_required
!= 0 || *end
)
1727 p
->auth_info_required
[p
->num_auth_info_required
] = "none";
1728 p
->num_auth_info_required
++;
1732 else if ((end
- values
) == 9 && !strncmp(values
, "negotiate", 9))
1734 if (p
->num_auth_info_required
!= 0 || *end
)
1737 p
->auth_info_required
[p
->num_auth_info_required
] = "negotiate";
1738 p
->num_auth_info_required
++;
1740 else if ((end
- values
) == 6 && !strncmp(values
, "domain", 6))
1742 p
->auth_info_required
[p
->num_auth_info_required
] = "domain";
1743 p
->num_auth_info_required
++;
1745 else if ((end
- values
) == 8 && !strncmp(values
, "password", 8))
1747 p
->auth_info_required
[p
->num_auth_info_required
] = "password";
1748 p
->num_auth_info_required
++;
1750 else if ((end
- values
) == 8 && !strncmp(values
, "username", 8))
1752 p
->auth_info_required
[p
->num_auth_info_required
] = "username";
1753 p
->num_auth_info_required
++;
1758 values
= (*end
) ? end
+ 1 : end
;
1761 if (p
->num_auth_info_required
== 0)
1763 p
->auth_info_required
[0] = "none";
1764 p
->num_auth_info_required
= 1;
1768 * Update the printer-type value as needed...
1771 if (p
->num_auth_info_required
> 1 ||
1772 strcmp(p
->auth_info_required
[0], "none"))
1773 p
->type
|= CUPS_PRINTER_AUTHENTICATED
;
1775 p
->type
&= ~CUPS_PRINTER_AUTHENTICATED
;
1781 * Grab values from an attribute instead...
1784 if (!attr
|| attr
->num_values
> 4)
1788 * Update the printer-type value as needed...
1791 if (attr
->num_values
> 1 ||
1792 strcmp(attr
->values
[0].string
.text
, "none"))
1793 p
->type
|= CUPS_PRINTER_AUTHENTICATED
;
1795 p
->type
&= ~CUPS_PRINTER_AUTHENTICATED
;
1797 for (i
= 0; i
< attr
->num_values
; i
++)
1799 if (!strcmp(attr
->values
[i
].string
.text
, "none"))
1801 if (p
->num_auth_info_required
!= 0 || attr
->num_values
!= 1)
1804 p
->auth_info_required
[p
->num_auth_info_required
] = "none";
1805 p
->num_auth_info_required
++;
1809 else if (!strcmp(attr
->values
[i
].string
.text
, "negotiate"))
1811 if (p
->num_auth_info_required
!= 0 || attr
->num_values
!= 1)
1814 p
->auth_info_required
[p
->num_auth_info_required
] = "negotiate";
1815 p
->num_auth_info_required
++;
1819 else if (!strcmp(attr
->values
[i
].string
.text
, "domain"))
1821 p
->auth_info_required
[p
->num_auth_info_required
] = "domain";
1822 p
->num_auth_info_required
++;
1824 else if (!strcmp(attr
->values
[i
].string
.text
, "password"))
1826 p
->auth_info_required
[p
->num_auth_info_required
] = "password";
1827 p
->num_auth_info_required
++;
1829 else if (!strcmp(attr
->values
[i
].string
.text
, "username"))
1831 p
->auth_info_required
[p
->num_auth_info_required
] = "username";
1832 p
->num_auth_info_required
++;
1843 * 'cupsdSetDeviceURI()' - Set the device URI for a printer.
1847 cupsdSetDeviceURI(cupsd_printer_t
*p
, /* I - Printer */
1848 const char *uri
) /* I - Device URI */
1850 char buffer
[1024], /* URI buffer */
1851 *start
, /* Start of data after scheme */
1852 *slash
, /* First slash after scheme:// */
1853 *ptr
; /* Pointer into user@host:port part */
1857 * Set the full device URI..
1860 cupsdSetString(&(p
->device_uri
), uri
);
1863 * Copy the device URI to a temporary buffer so we can sanitize any auth
1867 strlcpy(buffer
, uri
, sizeof(buffer
));
1870 * Find the end of the scheme:// part...
1873 if ((ptr
= strchr(buffer
, ':')) != NULL
)
1875 for (start
= ptr
+ 1; *start
; start
++)
1880 * Find the next slash (/) in the URI...
1883 if ((slash
= strchr(start
, '/')) == NULL
)
1884 slash
= start
+ strlen(start
); /* No slash, point to the end */
1887 * Check for an @ sign before the slash...
1890 if ((ptr
= strchr(start
, '@')) != NULL
&& ptr
< slash
)
1893 * Found an @ sign and it is before the resource part, so we have
1894 * an authentication string. Copy the remaining URI over the
1895 * authentication string...
1898 _cups_strcpy(start
, ptr
+ 1);
1903 * Save the sanitized URI...
1906 cupsdSetString(&(p
->sanitized_device_uri
), buffer
);
1911 * 'cupsdSetPrinterAttr()' - Set a printer attribute.
1915 cupsdSetPrinterAttr(
1916 cupsd_printer_t
*p
, /* I - Printer */
1917 const char *name
, /* I - Attribute name */
1918 char *value
) /* I - Attribute value string */
1920 ipp_attribute_t
*attr
; /* Attribute */
1921 int i
, /* Looping var */
1922 count
; /* Number of values */
1923 char *ptr
; /* Pointer into value */
1924 ipp_tag_t value_tag
; /* Value tag for this attribute */
1928 * Count the number of values...
1931 for (count
= 1, ptr
= value
;
1932 (ptr
= strchr(ptr
, ',')) != NULL
;
1936 * Then add or update the attribute as needed...
1939 if (!strcmp(name
, "marker-levels"))
1945 if ((attr
= ippFindAttribute(p
->attrs
, name
, IPP_TAG_INTEGER
)) != NULL
&&
1946 attr
->num_values
< count
)
1948 ippDeleteAttribute(p
->attrs
, attr
);
1953 attr
->num_values
= count
;
1955 attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
, name
,
1960 cupsdLogMessage(CUPSD_LOG_ERROR
,
1961 "Unable to allocate memory for printer attribute "
1962 "(%d values)", count
);
1966 for (i
= 0; i
< count
; i
++)
1968 if ((ptr
= strchr(value
, ',')) != NULL
)
1971 attr
->values
[i
].integer
= strtol(value
, NULL
, 10);
1980 * Name or keyword values...
1983 if (!strcmp(name
, "marker-types"))
1984 value_tag
= IPP_TAG_KEYWORD
;
1985 else if (!strcmp(name
, "marker-message"))
1986 value_tag
= IPP_TAG_TEXT
;
1988 value_tag
= IPP_TAG_NAME
;
1990 if ((attr
= ippFindAttribute(p
->attrs
, name
, value_tag
)) != NULL
&&
1991 attr
->num_values
< count
)
1993 ippDeleteAttribute(p
->attrs
, attr
);
1999 for (i
= 0; i
< attr
->num_values
; i
++)
2000 _cupsStrFree(attr
->values
[i
].string
.text
);
2002 attr
->num_values
= count
;
2005 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, value_tag
, name
,
2010 cupsdLogMessage(CUPSD_LOG_ERROR
,
2011 "Unable to allocate memory for printer attribute "
2012 "(%d values)", count
);
2016 for (i
= 0; i
< count
; i
++)
2018 if ((ptr
= strchr(value
, ',')) != NULL
)
2021 attr
->values
[i
].string
.text
= _cupsStrAlloc(value
);
2028 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
2033 * 'cupsdSetPrinterAttrs()' - Set printer attributes based upon the PPD file.
2037 cupsdSetPrinterAttrs(cupsd_printer_t
*p
)/* I - Printer to setup */
2039 int i
, /* Looping var */
2040 length
; /* Length of browse attributes */
2041 char resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
2042 char filename
[1024]; /* Name of PPD file */
2043 int num_air
; /* Number of auth-info-required values */
2044 const char * const *air
; /* auth-info-required values */
2045 int num_media
; /* Number of media options */
2046 cupsd_location_t
*auth
; /* Pointer to authentication element */
2047 const char *auth_supported
; /* Authentication supported */
2048 ppd_file_t
*ppd
; /* PPD file data */
2049 ppd_option_t
*input_slot
, /* InputSlot options */
2050 *media_type
, /* MediaType options */
2051 *page_size
, /* PageSize options */
2052 *output_bin
, /* OutputBin options */
2053 *media_quality
, /* EFMediaQualityMode options */
2054 *duplex
; /* Duplex options */
2055 ppd_attr_t
*ppdattr
; /* PPD attribute */
2056 ipp_t
*oldattrs
; /* Old printer attributes */
2057 ipp_attribute_t
*attr
; /* Attribute data */
2058 ipp_value_t
*val
; /* Attribute value */
2059 int num_finishings
; /* Number of finishings */
2060 int finishings
[5]; /* finishings-supported values */
2061 cups_option_t
*option
; /* Current printer option */
2062 static const char * const sides
[3] = /* sides-supported values */
2065 "two-sided-long-edge",
2066 "two-sided-short-edge"
2068 static const char * const air_userpass
[] =
2069 { /* Basic/Digest authentication */
2074 static const char * const air_negotiate
[] =
2075 { /* Kerberos authentication */
2078 #endif /* HAVE_GSSAPI */
2079 static const char * const air_none
[] =
2080 { /* No authentication */
2083 static const char * const standard_commands
[] =
2084 { /* Standard CUPS commands */
2087 "PrintSelfTestPage",
2092 DEBUG_printf(("cupsdSetPrinterAttrs: entering name = %s, type = %x\n", p
->name
,
2096 * Make sure that we have the common attributes defined...
2100 cupsdCreateCommonData();
2103 * Clear out old filters, if any...
2106 delete_printer_filters(p
);
2109 * Figure out the authentication that is required for the printer.
2112 auth_supported
= "requesting-user-name";
2116 if (p
->num_auth_info_required
> 0 && strcmp(p
->auth_info_required
[0], "none"))
2118 num_air
= p
->num_auth_info_required
;
2119 air
= p
->auth_info_required
;
2121 if (!strcmp(air
[0], "username"))
2122 auth_supported
= "basic";
2124 auth_supported
= "negotiate";
2126 else if (!(p
->type
& CUPS_PRINTER_DISCOVERED
))
2128 if (p
->type
& CUPS_PRINTER_CLASS
)
2129 snprintf(resource
, sizeof(resource
), "/classes/%s", p
->name
);
2131 snprintf(resource
, sizeof(resource
), "/printers/%s", p
->name
);
2133 if ((auth
= cupsdFindBest(resource
, HTTP_POST
)) == NULL
||
2134 auth
->type
== CUPSD_AUTH_NONE
)
2135 auth
= cupsdFindPolicyOp(p
->op_policy_ptr
, IPP_PRINT_JOB
);
2139 int auth_type
; /* Authentication type */
2142 if ((auth_type
= auth
->type
) == CUPSD_AUTH_DEFAULT
)
2143 auth_type
= DefaultAuthType
;
2145 if (auth_type
== CUPSD_AUTH_BASIC
|| auth_type
== CUPSD_AUTH_BASICDIGEST
)
2147 auth_supported
= "basic";
2151 else if (auth_type
== CUPSD_AUTH_DIGEST
)
2153 auth_supported
= "digest";
2158 else if (auth_type
== CUPSD_AUTH_NEGOTIATE
)
2160 auth_supported
= "negotiate";
2162 air
= air_negotiate
;
2164 #endif /* HAVE_GSSAPI */
2166 if (auth_type
!= CUPSD_AUTH_NONE
)
2167 p
->type
|= CUPS_PRINTER_AUTHENTICATED
;
2169 p
->type
&= ~CUPS_PRINTER_AUTHENTICATED
;
2172 p
->type
&= ~CUPS_PRINTER_AUTHENTICATED
;
2174 else if (p
->type
& CUPS_PRINTER_AUTHENTICATED
)
2181 * Create the required IPP attributes for a printer...
2184 oldattrs
= p
->attrs
;
2185 p
->attrs
= ippNew();
2187 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2188 "uri-authentication-supported", NULL
, auth_supported
);
2189 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2190 "uri-security-supported", NULL
, "none");
2191 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
, "printer-name", NULL
,
2193 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-location",
2194 NULL
, p
->location
? p
->location
: "");
2195 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-info",
2196 NULL
, p
->info
? p
->info
: "");
2201 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2202 "requesting-user-name-denied", p
->num_users
, NULL
,
2205 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2206 "requesting-user-name-allowed", p
->num_users
, NULL
,
2210 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2211 "job-quota-period", p
->quota_period
);
2212 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2213 "job-k-limit", p
->k_limit
);
2214 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2215 "job-page-limit", p
->page_limit
);
2216 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2217 "auth-info-required", num_air
, NULL
, air
);
2219 if (cupsArrayCount(Banners
) > 0 && !(p
->type
& CUPS_PRINTER_DISCOVERED
))
2222 * Setup the job-sheets-default attribute...
2225 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2226 "job-sheets-default", 2, NULL
, NULL
);
2230 attr
->values
[0].string
.text
= _cupsStrAlloc(Classification
?
2231 Classification
: p
->job_sheets
[0]);
2232 attr
->values
[1].string
.text
= _cupsStrAlloc(Classification
?
2233 Classification
: p
->job_sheets
[1]);
2240 if (p
->type
& CUPS_PRINTER_DISCOVERED
)
2243 * Tell the client this is a remote printer of some type...
2246 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
2247 "printer-uri-supported", NULL
, p
->uri
);
2249 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "printer-more-info",
2253 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
2254 "printer-make-and-model", NULL
, p
->make_model
);
2256 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "device-uri", NULL
,
2265 * Assign additional attributes depending on whether this is a printer
2269 p
->type
&= ~CUPS_PRINTER_OPTIONS
;
2271 if (p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
))
2276 * Add class-specific attributes...
2279 if ((p
->type
& CUPS_PRINTER_IMPLICIT
) && p
->num_printers
> 0 &&
2280 p
->printers
[0]->make_model
)
2281 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
2282 "printer-make-and-model", NULL
, p
->printers
[0]->make_model
);
2284 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
2285 "printer-make-and-model", NULL
, "Local Printer Class");
2287 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "device-uri", NULL
,
2288 "file:///dev/null");
2290 if (p
->num_printers
> 0)
2293 * Add a list of member names; URIs are added in copy_printer_attrs...
2296 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2297 "member-names", p
->num_printers
, NULL
, NULL
);
2298 p
->type
|= CUPS_PRINTER_OPTIONS
;
2300 for (i
= 0; i
< p
->num_printers
; i
++)
2303 attr
->values
[i
].string
.text
= _cupsStrAlloc(p
->printers
[i
]->name
);
2305 p
->type
&= ~CUPS_PRINTER_OPTIONS
| p
->printers
[i
]->type
;
2312 * Add printer-specific attributes...
2315 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "device-uri", NULL
,
2316 p
->sanitized_device_uri
);
2319 * Assign additional attributes from the PPD file (if any)...
2322 p
->type
|= CUPS_PRINTER_BW
;
2323 finishings
[0] = IPP_FINISHINGS_NONE
;
2326 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
2329 if ((ppd
= ppdOpenFile(filename
)) != NULL
)
2332 * Add make/model and other various attributes...
2335 if (ppd
->color_device
)
2336 p
->type
|= CUPS_PRINTER_COLOR
;
2337 if (ppd
->variable_sizes
)
2338 p
->type
|= CUPS_PRINTER_VARIABLE
;
2339 if (!ppd
->manual_copies
)
2340 p
->type
|= CUPS_PRINTER_COPIES
;
2341 if ((ppdattr
= ppdFindAttr(ppd
, "cupsFax", NULL
)) != NULL
)
2342 if (ppdattr
->value
&& !strcasecmp(ppdattr
->value
, "true"))
2343 p
->type
|= CUPS_PRINTER_FAX
;
2345 ippAddBoolean(p
->attrs
, IPP_TAG_PRINTER
, "color-supported",
2347 if (ppd
->throughput
)
2348 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2349 "pages-per-minute", ppd
->throughput
);
2354 * The NickName can be localized in the character set specified
2355 * by the LanugageEncoding attribute. However, ppdOpen2() has
2356 * already converted the ppd->nickname member to UTF-8 for us
2357 * (the original attribute value is available separately)
2360 cupsdSetString(&p
->make_model
, ppd
->nickname
);
2362 else if (ppd
->modelname
)
2365 * Model name can only contain specific characters...
2368 cupsdSetString(&p
->make_model
, ppd
->modelname
);
2371 cupsdSetString(&p
->make_model
, "Bad PPD File");
2373 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
2374 "printer-make-and-model", NULL
, p
->make_model
);
2377 * Add media options from the PPD file...
2380 if ((input_slot
= ppdFindOption(ppd
, "InputSlot")) != NULL
)
2381 num_media
= input_slot
->num_choices
;
2385 if ((media_type
= ppdFindOption(ppd
, "MediaType")) != NULL
)
2386 num_media
+= media_type
->num_choices
;
2388 if ((page_size
= ppdFindOption(ppd
, "PageSize")) != NULL
)
2389 num_media
+= page_size
->num_choices
;
2391 if ((media_quality
= ppdFindOption(ppd
, "EFMediaQualityMode")) != NULL
)
2392 num_media
+= media_quality
->num_choices
;
2396 cupsdLogMessage(CUPSD_LOG_CRIT
,
2397 "The PPD file for printer %s contains no media "
2398 "options and is therefore invalid!", p
->name
);
2402 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2403 "media-supported", num_media
, NULL
, NULL
);
2408 if (input_slot
!= NULL
)
2409 for (i
= 0; i
< input_slot
->num_choices
; i
++, val
++)
2410 val
->string
.text
= _cupsStrAlloc(input_slot
->choices
[i
].choice
);
2412 if (media_type
!= NULL
)
2413 for (i
= 0; i
< media_type
->num_choices
; i
++, val
++)
2414 val
->string
.text
= _cupsStrAlloc(media_type
->choices
[i
].choice
);
2416 if (media_quality
!= NULL
)
2417 for (i
= 0; i
< media_quality
->num_choices
; i
++, val
++)
2418 val
->string
.text
= _cupsStrAlloc(media_quality
->choices
[i
].choice
);
2420 if (page_size
!= NULL
)
2422 for (i
= 0; i
< page_size
->num_choices
; i
++, val
++)
2423 val
->string
.text
= _cupsStrAlloc(page_size
->choices
[i
].choice
);
2425 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2426 "media-default", NULL
, page_size
->defchoice
);
2428 else if (input_slot
!= NULL
)
2429 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2430 "media-default", NULL
, input_slot
->defchoice
);
2431 else if (media_type
!= NULL
)
2432 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2433 "media-default", NULL
, media_type
->defchoice
);
2434 else if (media_quality
!= NULL
)
2435 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2436 "media-default", NULL
, media_quality
->defchoice
);
2438 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2439 "media-default", NULL
, "none");
2447 if ((output_bin
= ppdFindOption(ppd
, "OutputBin")) != NULL
)
2449 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2450 "output-bin-supported", output_bin
->num_choices
,
2455 for (i
= 0, val
= attr
->values
;
2456 i
< output_bin
->num_choices
;
2458 val
->string
.text
= _cupsStrAlloc(output_bin
->choices
[i
].choice
);
2466 if ((duplex
= ppdFindOption(ppd
, "Duplex")) == NULL
)
2467 if ((duplex
= ppdFindOption(ppd
, "EFDuplex")) == NULL
)
2468 if ((duplex
= ppdFindOption(ppd
, "EFDuplexing")) == NULL
)
2469 if ((duplex
= ppdFindOption(ppd
, "KD03Duplex")) == NULL
)
2470 duplex
= ppdFindOption(ppd
, "JCLDuplex");
2472 if (duplex
&& duplex
->num_choices
> 1 &&
2473 !ppdInstallableConflict(ppd
, duplex
->keyword
, "DuplexTumble"))
2475 p
->type
|= CUPS_PRINTER_DUPLEX
;
2477 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2478 "sides-supported", 3, NULL
, sides
);
2480 if (!strcasecmp(duplex
->defchoice
, "DuplexTumble"))
2481 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2482 "sides-default", NULL
, "two-sided-short-edge");
2483 else if (!strcasecmp(duplex
->defchoice
, "DuplexNoTumble"))
2484 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2485 "sides-default", NULL
, "two-sided-long-edge");
2487 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2488 "sides-default", NULL
, "one-sided");
2491 if (ppdFindOption(ppd
, "Collate") != NULL
)
2492 p
->type
|= CUPS_PRINTER_COLLATE
;
2494 if (ppdFindOption(ppd
, "StapleLocation") != NULL
)
2496 p
->type
|= CUPS_PRINTER_STAPLE
;
2497 finishings
[num_finishings
++] = IPP_FINISHINGS_STAPLE
;
2500 if (ppdFindOption(ppd
, "BindEdge") != NULL
)
2502 p
->type
|= CUPS_PRINTER_BIND
;
2503 finishings
[num_finishings
++] = IPP_FINISHINGS_BIND
;
2506 for (i
= 0; i
< ppd
->num_sizes
; i
++)
2507 if (ppd
->sizes
[i
].length
> 1728)
2508 p
->type
|= CUPS_PRINTER_LARGE
;
2509 else if (ppd
->sizes
[i
].length
> 1008)
2510 p
->type
|= CUPS_PRINTER_MEDIUM
;
2512 p
->type
|= CUPS_PRINTER_SMALL
;
2515 * Add a filter from application/vnd.cups-raw to printer/name to
2516 * handle "raw" printing by users.
2519 add_printer_filter(p
, p
->filetype
, "application/vnd.cups-raw 0 -");
2522 * Add any pre-filters in the PPD file...
2525 if ((ppdattr
= ppdFindAttr(ppd
, "cupsPreFilter", NULL
)) != NULL
)
2527 p
->prefiltertype
= mimeAddType(MimeDatabase
, "prefilter", p
->name
);
2529 for (; ppdattr
; ppdattr
= ppdFindNextAttr(ppd
, "cupsPreFilter", NULL
))
2531 add_printer_filter(p
, p
->prefiltertype
, ppdattr
->value
);
2535 * Add any filters in the PPD file...
2538 DEBUG_printf(("ppd->num_filters = %d\n", ppd
->num_filters
));
2539 for (i
= 0; i
< ppd
->num_filters
; i
++)
2541 DEBUG_printf(("ppd->filters[%d] = \"%s\"\n", i
, ppd
->filters
[i
]));
2542 add_printer_filter(p
, p
->filetype
, ppd
->filters
[i
]);
2545 if (ppd
->num_filters
== 0)
2548 * If there are no filters, add PostScript printing filters.
2551 add_printer_filter(p
, p
->filetype
,
2552 "application/vnd.cups-command 0 commandtops");
2553 add_printer_filter(p
, p
->filetype
,
2554 "application/vnd.cups-postscript 0 -");
2556 p
->type
|= CUPS_PRINTER_COMMANDS
;
2558 else if (!(p
->type
& CUPS_PRINTER_COMMANDS
))
2561 * See if this is a PostScript device without a command filter...
2564 for (i
= 0; i
< ppd
->num_filters
; i
++)
2565 if (!strncasecmp(ppd
->filters
[i
],
2566 "application/vnd.cups-postscript", 31))
2569 if (i
< ppd
->num_filters
)
2572 * Add the generic PostScript command filter...
2575 add_printer_filter(p
, p
->filetype
,
2576 "application/vnd.cups-command 0 commandtops");
2577 p
->type
|= CUPS_PRINTER_COMMANDS
;
2581 if (p
->type
& CUPS_PRINTER_COMMANDS
)
2583 char *commands
, /* Copy of commands */
2584 *start
, /* Start of name */
2585 *end
; /* End of name */
2586 int count
; /* Number of commands */
2589 if ((ppdattr
= ppdFindAttr(ppd
, "cupsCommands", NULL
)) != NULL
&&
2590 ppdattr
->value
&& ppdattr
->value
[0])
2592 for (count
= 0, start
= ppdattr
->value
; *start
; count
++)
2594 while (isspace(*start
& 255))
2600 while (*start
&& !isspace(*start
& 255))
2610 * Make a copy of the commands string and count how many ...
2613 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2614 "printer-commands", count
, NULL
, NULL
);
2616 commands
= strdup(ppdattr
->value
);
2618 for (count
= 0, start
= commands
; *start
; count
++)
2620 while (isspace(*start
& 255))
2627 while (*end
&& !isspace(*end
& 255))
2633 attr
->values
[count
].string
.text
= _cupsStrAlloc(start
);
2643 * Add the standard list of commands...
2646 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2648 (int)(sizeof(standard_commands
) /
2649 sizeof(standard_commands
[0])), NULL
,
2656 * No commands supported...
2659 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2660 "printer-commands", NULL
, "none");
2664 * Show current and available port monitors for this printer...
2667 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
, "port-monitor",
2668 NULL
, p
->port_monitor
? p
->port_monitor
: "none");
2670 for (i
= 1, ppdattr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
2672 i
++, ppdattr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
));
2676 if (strstr(ppd
->protocols
, "TBCP"))
2678 else if (strstr(ppd
->protocols
, "BCP"))
2682 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2683 "port-monitor-supported", i
, NULL
, NULL
);
2685 attr
->values
[0].string
.text
= _cupsStrAlloc("none");
2687 for (i
= 1, ppdattr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
2689 i
++, ppdattr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
))
2690 attr
->values
[i
].string
.text
= _cupsStrAlloc(ppdattr
->value
);
2694 if (strstr(ppd
->protocols
, "TBCP"))
2695 attr
->values
[i
].string
.text
= _cupsStrAlloc("tbcp");
2696 else if (strstr(ppd
->protocols
, "BCP"))
2697 attr
->values
[i
].string
.text
= _cupsStrAlloc("bcp");
2701 cupsdSetString(&p
->product
, ppd
->product
);
2702 #endif /* HAVE_DNSSD */
2704 if (ppdFindAttr(ppd
, "APRemoteQueueID", NULL
))
2705 p
->type
|= CUPS_PRINTER_REMOTE
;
2708 * Close the PPD and set the type...
2713 else if (!access(filename
, 0))
2715 int pline
; /* PPD line number */
2716 ppd_status_t pstatus
; /* PPD load status */
2719 pstatus
= ppdLastError(&pline
);
2721 cupsdLogMessage(CUPSD_LOG_ERROR
, "PPD file for %s cannot be loaded!",
2724 if (pstatus
<= PPD_ALLOC_ERROR
)
2725 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s", strerror(errno
));
2727 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s on line %d.",
2728 ppdErrorString(pstatus
), pline
);
2730 cupsdLogMessage(CUPSD_LOG_INFO
,
2731 "Hint: Run \"cupstestppd %s\" and fix any errors.",
2735 * Add a filter from application/vnd.cups-raw to printer/name to
2736 * handle "raw" printing by users.
2739 add_printer_filter(p
, p
->filetype
, "application/vnd.cups-raw 0 -");
2742 * Add a PostScript filter, since this is still possibly PS printer.
2745 add_printer_filter(p
, p
->filetype
,
2746 "application/vnd.cups-postscript 0 -");
2751 * If we have an interface script, add a filter entry for it...
2754 snprintf(filename
, sizeof(filename
), "%s/interfaces/%s", ServerRoot
,
2756 if (!access(filename
, X_OK
))
2759 * Yes, we have a System V style interface script; use it!
2762 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
2763 "printer-make-and-model", NULL
,
2764 "Local System V Printer");
2766 snprintf(filename
, sizeof(filename
), "*/* 0 %s/interfaces/%s",
2767 ServerRoot
, p
->name
);
2768 add_printer_filter(p
, p
->filetype
, filename
);
2770 else if (!strncmp(p
->device_uri
, "ipp://", 6) &&
2771 (strstr(p
->device_uri
, "/printers/") != NULL
||
2772 strstr(p
->device_uri
, "/classes/") != NULL
||
2773 (strstr(p
->device_uri
, "._ipp.") != NULL
&&
2774 !strcmp(p
->device_uri
+ strlen(p
->device_uri
) - 5,
2778 * Tell the client this is really a hard-wired remote printer.
2781 p
->type
|= CUPS_PRINTER_REMOTE
;
2784 * Point the printer-uri-supported attribute to the
2788 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
2789 "printer-uri-supported", NULL
, p
->device_uri
);
2792 * Then set the make-and-model accordingly...
2795 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
2796 "printer-make-and-model", NULL
, "Remote Printer");
2799 * Print all files directly...
2808 * Otherwise we have neither - treat this as a "dumb" printer
2809 * with no PPD file...
2812 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
2813 "printer-make-and-model", NULL
, "Local Raw Printer");
2819 ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
2820 "finishings-supported", num_finishings
, finishings
);
2821 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
2822 "finishings-default", IPP_FINISHINGS_NONE
);
2827 * Copy marker attributes as needed...
2832 ipp_attribute_t
*oldattr
; /* Old attribute */
2835 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-colors",
2836 IPP_TAG_NAME
)) != NULL
)
2838 if ((attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2839 "marker-colors", oldattr
->num_values
, NULL
,
2842 for (i
= 0; i
< oldattr
->num_values
; i
++)
2843 attr
->values
[i
].string
.text
=
2844 _cupsStrAlloc(oldattr
->values
[i
].string
.text
);
2848 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-levels",
2849 IPP_TAG_INTEGER
)) != NULL
)
2851 if ((attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2852 "marker-levels", oldattr
->num_values
,
2855 for (i
= 0; i
< oldattr
->num_values
; i
++)
2856 attr
->values
[i
].integer
= oldattr
->values
[i
].integer
;
2860 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-names",
2861 IPP_TAG_NAME
)) != NULL
)
2863 if ((attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2864 "marker-names", oldattr
->num_values
, NULL
,
2867 for (i
= 0; i
< oldattr
->num_values
; i
++)
2868 attr
->values
[i
].string
.text
=
2869 _cupsStrAlloc(oldattr
->values
[i
].string
.text
);
2873 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-types",
2874 IPP_TAG_KEYWORD
)) != NULL
)
2876 if ((attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2877 "marker-types", oldattr
->num_values
, NULL
,
2880 for (i
= 0; i
< oldattr
->num_values
; i
++)
2881 attr
->values
[i
].string
.text
=
2882 _cupsStrAlloc(oldattr
->values
[i
].string
.text
);
2886 ippDelete(oldattrs
);
2890 * Force sharing off for remote queues...
2893 if (p
->type
& (CUPS_PRINTER_REMOTE
| CUPS_PRINTER_IMPLICIT
))
2898 * Copy the printer options into a browse attributes string we can re-use.
2901 const char *valptr
; /* Pointer into value */
2902 char *attrptr
; /* Pointer into attribute string */
2906 * Free the old browse attributes as needed...
2909 if (p
->browse_attrs
)
2910 free(p
->browse_attrs
);
2913 * Compute the length of all attributes + job-sheets, lease-duration,
2914 * and BrowseLocalOptions.
2917 for (length
= 1, i
= p
->num_options
, option
= p
->options
;
2921 length
+= strlen(option
->name
) + 2;
2925 for (valptr
= option
->value
; *valptr
; valptr
++)
2926 if (strchr(" \"\'\\", *valptr
))
2933 length
+= 13 + strlen(p
->job_sheets
[0]) + strlen(p
->job_sheets
[1]);
2935 if (BrowseLocalOptions
)
2936 length
+= 12 + strlen(BrowseLocalOptions
);
2938 if (p
->num_auth_info_required
> 0)
2940 length
+= 18; /* auth-info-required */
2942 for (i
= 0; i
< p
->num_auth_info_required
; i
++)
2943 length
+= strlen(p
->auth_info_required
[i
]) + 1;
2947 * Allocate the new string...
2950 if ((p
->browse_attrs
= calloc(1, length
)) == NULL
)
2951 cupsdLogMessage(CUPSD_LOG_ERROR
,
2952 "Unable to allocate %d bytes for browse data!",
2957 * Got the allocated string, now copy the options and attributes over...
2960 sprintf(p
->browse_attrs
, "job-sheets=%s,%s lease-duration=%d",
2961 p
->job_sheets
[0], p
->job_sheets
[1], BrowseTimeout
);
2962 attrptr
= p
->browse_attrs
+ strlen(p
->browse_attrs
);
2964 if (BrowseLocalOptions
)
2966 sprintf(attrptr
, " ipp-options=%s", BrowseLocalOptions
);
2967 attrptr
+= strlen(attrptr
);
2970 for (i
= p
->num_options
, option
= p
->options
;
2975 strcpy(attrptr
, option
->name
);
2976 attrptr
+= strlen(attrptr
);
2982 for (valptr
= option
->value
; *valptr
; valptr
++)
2984 if (strchr(" \"\'\\", *valptr
))
2987 *attrptr
++ = *valptr
;
2992 if (p
->num_auth_info_required
> 0)
2994 strcpy(attrptr
, "auth-info-required");
2997 for (i
= 0; i
< p
->num_auth_info_required
; i
++)
2999 *attrptr
++ = i
? ',' : '=';
3000 strcpy(attrptr
, p
->auth_info_required
[i
]);
3001 attrptr
+= strlen(attrptr
);
3010 * Populate the document-format-supported attribute...
3013 add_printer_formats(p
);
3015 DEBUG_printf(("cupsdSetPrinterAttrs: leaving name = %s, type = %x\n", p
->name
,
3019 * Add name-default attributes...
3022 add_printer_defaults(p
);
3026 * Write the IRIX printer config and status files...
3029 write_irix_config(p
);
3030 write_irix_state(p
);
3034 * Let the browse protocols reflect the change
3037 cupsdRegisterPrinter(p
);
3042 * 'cupsdSetPrinterReasons()' - Set/update the reasons strings.
3046 cupsdSetPrinterReasons(
3047 cupsd_printer_t
*p
, /* I - Printer */
3048 const char *s
) /* I - Reasons strings */
3050 int i
; /* Looping var */
3051 const char *sptr
; /* Pointer into reasons */
3052 char reason
[255], /* Reason string */
3053 *rptr
; /* Pointer into reason */
3056 if (s
[0] == '-' || s
[0] == '+')
3059 * Add/remove reasons...
3067 * Replace reasons...
3072 for (i
= 0; i
< p
->num_reasons
; i
++)
3073 _cupsStrFree(p
->reasons
[i
]);
3077 if (PrintcapFormat
== PRINTCAP_PLIST
)
3078 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
3081 if (!strcmp(s
, "none"))
3085 * Loop through all of the reasons...
3091 * Skip leading whitespace and commas...
3094 while (isspace(*sptr
& 255) || *sptr
== ',')
3097 for (rptr
= reason
; *sptr
&& !isspace(*sptr
& 255) && *sptr
!= ','; sptr
++)
3098 if (rptr
< (reason
+ sizeof(reason
) - 1))
3112 for (i
= 0; i
< p
->num_reasons
; i
++)
3113 if (!strcasecmp(reason
, p
->reasons
[i
]))
3116 * Found a match, so remove it...
3120 _cupsStrFree(p
->reasons
[i
]);
3122 if (i
< p
->num_reasons
)
3123 memmove(p
->reasons
+ i
, p
->reasons
+ i
+ 1,
3124 (p
->num_reasons
- i
) * sizeof(char *));
3128 if (!strcmp(reason
, "paused") && p
->state
== IPP_PRINTER_STOPPED
)
3129 cupsdSetPrinterState(p
, IPP_PRINTER_IDLE
, 1);
3131 if (PrintcapFormat
== PRINTCAP_PLIST
)
3132 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
3135 else if (p
->num_reasons
< (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
3141 for (i
= 0; i
< p
->num_reasons
; i
++)
3142 if (!strcasecmp(reason
, p
->reasons
[i
]))
3145 if (i
>= p
->num_reasons
)
3147 p
->reasons
[i
] = _cupsStrAlloc(reason
);
3150 if (!strcmp(reason
, "paused") && p
->state
!= IPP_PRINTER_STOPPED
)
3151 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, 1);
3153 if (PrintcapFormat
== PRINTCAP_PLIST
)
3154 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
3162 * 'cupsdSetPrinterState()' - Update the current state of a printer.
3166 cupsdSetPrinterState(
3167 cupsd_printer_t
*p
, /* I - Printer to change */
3168 ipp_pstate_t s
, /* I - New state */
3169 int update
) /* I - Update printers.conf? */
3171 ipp_pstate_t old_state
; /* Old printer state */
3175 * Can't set status of remote printers...
3178 if (p
->type
& CUPS_PRINTER_DISCOVERED
)
3182 * Set the new state...
3185 if (PrintcapFormat
== PRINTCAP_PLIST
)
3186 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
3188 old_state
= p
->state
;
3193 cupsdAddEvent(s
== IPP_PRINTER_STOPPED
? CUPSD_EVENT_PRINTER_STOPPED
:
3194 CUPSD_EVENT_PRINTER_STATE
, p
, NULL
,
3195 "%s \"%s\" state changed.",
3196 (p
->type
& CUPS_PRINTER_CLASS
) ? "Class" : "Printer",
3200 * Let the browse code know this needs to be updated...
3204 p
->state_time
= time(NULL
);
3208 write_irix_state(p
);
3212 cupsdAddPrinterHistory(p
);
3215 * Let the browse protocols reflect the change...
3219 cupsdRegisterPrinter(p
);
3222 * Save the printer configuration if a printer goes from idle or processing
3223 * to stopped (or visa-versa)...
3226 if ((old_state
== IPP_PRINTER_STOPPED
) != (s
== IPP_PRINTER_STOPPED
) &&
3229 if (p
->type
& CUPS_PRINTER_CLASS
)
3230 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
3232 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
3238 * 'cupsdStopPrinter()' - Stop a printer from printing any jobs...
3242 cupsdStopPrinter(cupsd_printer_t
*p
, /* I - Printer to stop */
3243 int update
)/* I - Update printers.conf? */
3245 cupsd_job_t
*job
; /* Active print job */
3249 * Set the printer state...
3252 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, update
);
3255 * See if we have a job printing on this printer...
3261 * Get pointer to job...
3264 job
= (cupsd_job_t
*)p
->job
;
3270 cupsdStopJob(job
, 0);
3273 * Reset the state to pending...
3276 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
3277 job
->state_value
= IPP_JOB_PENDING
;
3280 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
3282 cupsdAddEvent(CUPSD_EVENT_JOB_STOPPED
, p
, job
,
3283 "Job stopped due to printer being paused");
3289 * 'cupsdUpdatePrinterPPD()' - Update keywords in a printer's PPD file.
3292 int /* O - 1 if successful, 0 otherwise */
3293 cupsdUpdatePrinterPPD(
3294 cupsd_printer_t
*p
, /* I - Printer */
3295 int num_keywords
, /* I - Number of keywords */
3296 cups_option_t
*keywords
) /* I - Keywords */
3298 int i
; /* Looping var */
3299 cups_file_t
*src
, /* Original file */
3300 *dst
; /* New file */
3301 char srcfile
[1024], /* Original filename */
3302 dstfile
[1024], /* New filename */
3303 line
[1024], /* Line from file */
3304 keystring
[41]; /* Keyword from line */
3305 cups_option_t
*keyword
; /* Current keyword */
3308 cupsdLogMessage(CUPSD_LOG_INFO
, "Updating keywords in PPD file for %s...",
3312 * Get the old and new PPD filenames...
3315 snprintf(srcfile
, sizeof(srcfile
), "%s/ppd/%s.ppd.O", ServerRoot
, p
->name
);
3316 snprintf(dstfile
, sizeof(srcfile
), "%s/ppd/%s.ppd", ServerRoot
, p
->name
);
3319 * Rename the old file and open the old and new...
3322 if (rename(dstfile
, srcfile
))
3324 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to backup PPD file for %s: %s",
3325 p
->name
, strerror(errno
));
3329 if ((src
= cupsFileOpen(srcfile
, "r")) == NULL
)
3331 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to open PPD file \"%s\": %s",
3332 srcfile
, strerror(errno
));
3333 rename(srcfile
, dstfile
);
3337 if ((dst
= cupsFileOpen(dstfile
, "w")) == NULL
)
3339 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to create PPD file \"%s\": %s",
3340 dstfile
, strerror(errno
));
3342 rename(srcfile
, dstfile
);
3347 * Copy the first line and then write out all of the keywords...
3350 if (!cupsFileGets(src
, line
, sizeof(line
)))
3352 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to read PPD file \"%s\": %s",
3353 srcfile
, strerror(errno
));
3356 rename(srcfile
, dstfile
);
3360 cupsFilePrintf(dst
, "%s\n", line
);
3362 for (i
= num_keywords
, keyword
= keywords
; i
> 0; i
--, keyword
++)
3364 cupsdLogMessage(CUPSD_LOG_DEBUG
, "*%s: %s", keyword
->name
, keyword
->value
);
3365 cupsFilePrintf(dst
, "*%s: %s\n", keyword
->name
, keyword
->value
);
3369 * Then copy the rest of the PPD file, dropping any keywords we changed.
3372 while (cupsFileGets(src
, line
, sizeof(line
)))
3375 * Skip keywords we've already set...
3378 if (sscanf(line
, "*%40[^:]:", keystring
) == 1 &&
3379 cupsGetOption(keystring
, num_keywords
, keywords
))
3383 * Otherwise write the line...
3386 cupsFilePrintf(dst
, "%s\n", line
);
3390 * Close files and return...
3401 * 'cupsdUpdatePrinters()' - Update printers after a partial reload.
3405 cupsdUpdatePrinters(void)
3407 cupsd_printer_t
*p
; /* Current printer */
3411 * Loop through the printers and recreate the printer attributes
3412 * for any local printers since the policy and/or access control
3413 * stuff may have changed. Also, if browsing is disabled, remove
3414 * any remote printers...
3417 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3419 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3422 * Remove remote printers if we are no longer browsing...
3426 (p
->type
& (CUPS_PRINTER_IMPLICIT
| CUPS_PRINTER_DISCOVERED
)))
3428 if (p
->type
& CUPS_PRINTER_IMPLICIT
)
3429 cupsArrayRemove(ImplicitPrinters
, p
);
3431 cupsArraySave(Printers
);
3432 cupsdDeletePrinter(p
, 0);
3433 cupsArrayRestore(Printers
);
3438 * Update the operation policy pointer...
3441 if ((p
->op_policy_ptr
= cupsdFindPolicy(p
->op_policy
)) == NULL
)
3442 p
->op_policy_ptr
= DefaultPolicyPtr
;
3445 * Update printer attributes as needed...
3448 if (!(p
->type
& CUPS_PRINTER_DISCOVERED
))
3449 cupsdSetPrinterAttrs(p
);
3455 * 'cupsdValidateDest()' - Validate a printer/class destination.
3458 const char * /* O - Printer or class name */
3460 const char *uri
, /* I - Printer URI */
3461 cups_ptype_t
*dtype
, /* O - Type (printer or class) */
3462 cupsd_printer_t
**printer
) /* O - Printer pointer */
3464 cupsd_printer_t
*p
; /* Current printer */
3465 char localname
[1024],/* Localized hostname */
3466 *lptr
, /* Pointer into localized hostname */
3467 *sptr
, /* Pointer into server name */
3468 *rptr
, /* Pointer into resource */
3469 scheme
[32], /* Scheme portion of URI */
3470 username
[64], /* Username portion of URI */
3471 hostname
[HTTP_MAX_HOST
],
3472 /* Host portion of URI */
3473 resource
[HTTP_MAX_URI
];
3474 /* Resource portion of URI */
3475 int port
; /* Port portion of URI */
3478 DEBUG_printf(("cupsdValidateDest(uri=\"%s\", dtype=%p, printer=%p)\n", uri
,
3482 * Initialize return values...
3489 *dtype
= (cups_ptype_t
)0;
3492 * Pull the hostname and resource from the URI...
3495 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
, scheme
, sizeof(scheme
),
3496 username
, sizeof(username
), hostname
, sizeof(hostname
),
3497 &port
, resource
, sizeof(resource
));
3500 * See if the resource is a class or printer...
3503 if (!strncmp(resource
, "/classes/", 9))
3509 rptr
= resource
+ 9;
3511 else if (!strncmp(resource
, "/printers/", 10))
3517 rptr
= resource
+ 10;
3522 * Bad resource name...
3529 * See if the printer or class name exists...
3532 p
= cupsdFindDest(rptr
);
3534 if (p
== NULL
&& strchr(rptr
, '@') == NULL
)
3542 *dtype
= p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
|
3543 CUPS_PRINTER_REMOTE
| CUPS_PRINTER_DISCOVERED
);
3549 * Change localhost to the server name...
3552 if (!strcasecmp(hostname
, "localhost"))
3553 strlcpy(hostname
, ServerName
, sizeof(hostname
));
3555 strlcpy(localname
, hostname
, sizeof(localname
));
3557 if (!strcasecmp(hostname
, ServerName
))
3560 * Localize the hostname...
3563 lptr
= strchr(localname
, '.');
3564 sptr
= strchr(ServerName
, '.');
3566 if (sptr
!= NULL
&& lptr
!= NULL
)
3569 * Strip the common domain name components...
3572 while (lptr
!= NULL
)
3574 if (!strcasecmp(lptr
, sptr
))
3580 lptr
= strchr(lptr
+ 1, '.');
3585 DEBUG_printf(("localized hostname is \"%s\"...\n", localname
));
3588 * Find a matching printer or class...
3591 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3593 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3594 if (!strcasecmp(p
->hostname
, localname
) &&
3595 !strcasecmp(p
->name
, rptr
))
3601 *dtype
= p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
|
3602 CUPS_PRINTER_REMOTE
| CUPS_PRINTER_DISCOVERED
);
3612 * 'cupsdWritePrintcap()' - Write a pseudo-printcap file for older applications
3617 cupsdWritePrintcap(void)
3619 int i
; /* Looping var */
3620 cups_file_t
*fp
; /* Printcap file */
3621 cupsd_printer_t
*p
; /* Current printer */
3626 * Update the IRIX printer state for the default printer; if
3627 * no printers remain, then the default printer file will be
3631 write_irix_state(DefaultPrinter
);
3635 * See if we have a printcap file; if not, don't bother writing it.
3638 if (!Printcap
|| !*Printcap
)
3642 * Open the printcap file...
3645 if ((fp
= cupsFileOpen(Printcap
, "w")) == NULL
)
3649 * Put a comment header at the top so that users will know where the
3650 * data has come from...
3653 if (PrintcapFormat
!= PRINTCAP_PLIST
)
3654 cupsFilePrintf(fp
, "# This file was automatically generated by cupsd(8) "
3656 "# %s/printers.conf file. All changes to this file\n"
3657 "# will be lost.\n", ServerRoot
);
3662 * Write a new printcap with the current list of printers.
3665 switch (PrintcapFormat
)
3669 * Each printer is put in the file as:
3679 cupsFilePrintf(fp
, "%s|%s:rm=%s:rp=%s:\n", DefaultPrinter
->name
,
3680 DefaultPrinter
->info
, ServerName
,
3681 DefaultPrinter
->name
);
3683 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3685 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3686 if (p
!= DefaultPrinter
)
3687 cupsFilePrintf(fp
, "%s|%s:rm=%s:rp=%s:\n", p
->name
, p
->info
,
3688 ServerName
, p
->name
);
3691 case PRINTCAP_PLIST
:
3693 * Each printer is written as a dictionary in a plist file.
3694 * Currently the printer-name, printer-info, printer-is-accepting-jobs,
3695 * printer-location, printer-make-and-model, printer-state,
3696 * printer-state-reasons, printer-type, and (sanitized) device-uri.
3699 cupsFilePuts(fp
, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
3700 "<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD "
3701 "PLIST 1.0//EN\" \"http://www.apple.com/DTDs/"
3702 "PropertyList-1.0.dtd\">\n"
3703 "<plist version=\"1.0\">\n"
3706 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3708 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3710 cupsFilePuts(fp
, "\t<dict>\n"
3711 "\t\t<key>printer-name</key>\n"
3713 write_xml_string(fp
, p
->name
);
3714 cupsFilePuts(fp
, "</string>\n"
3715 "\t\t<key>printer-info</key>\n"
3717 write_xml_string(fp
, p
->info
);
3718 cupsFilePrintf(fp
, "</string>\n"
3719 "\t\t<key>printer-is-accepting-jobs</key>\n"
3721 "\t\t<key>printer-location</key>\n"
3722 "\t\t<string>", p
->accepting
? "true" : "false");
3723 write_xml_string(fp
, p
->location
);
3724 cupsFilePuts(fp
, "</string>\n"
3725 "\t\t<key>printer-make-and-model</key>\n"
3727 write_xml_string(fp
, p
->make_model
);
3728 cupsFilePrintf(fp
, "</string>\n"
3729 "\t\t<key>printer-state</key>\n"
3730 "\t\t<integer>%d</integer>\n"
3731 "\t\t<key>printer-state-reasons</key>\n"
3732 "\t\t<array>\n", p
->state
);
3733 for (i
= 0; i
< p
->num_reasons
; i
++)
3735 cupsFilePuts(fp
, "\t\t\t<string>");
3736 write_xml_string(fp
, p
->reasons
[i
]);
3737 cupsFilePuts(fp
, "</string>\n");
3739 cupsFilePrintf(fp
, "\t\t</array>\n"
3740 "\t\t<key>printer-type</key>\n"
3741 "\t\t<integer>%d</integer>\n"
3742 "\t\t<key>device-uri</key>\n"
3743 "\t\t<string>", p
->type
);
3744 write_xml_string(fp
, p
->sanitized_device_uri
);
3745 cupsFilePuts(fp
, "</string>\n"
3748 cupsFilePuts(fp
, "</array>\n"
3752 case PRINTCAP_SOLARIS
:
3754 * Each printer is put in the file as:
3756 * _all:all=Printer1,Printer2,Printer3,...,PrinterN
3757 * _default:use=DefaultPrinter
3759 * :bsdaddr=ServerName,Printer1:\
3760 * :description=Description:
3762 * :bsdaddr=ServerName,Printer2:\
3763 * :description=Description:
3765 * :bsdaddr=ServerName,Printer3:\
3766 * :description=Description:
3769 * :bsdaddr=ServerName,PrinterN:\
3770 * :description=Description:
3773 cupsFilePuts(fp
, "_all:all=");
3774 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3776 p
= (cupsd_printer_t
*)cupsArrayCurrent(Printers
))
3777 cupsFilePrintf(fp
, "%s%c", p
->name
,
3778 cupsArrayNext(Printers
) ? ',' : '\n');
3781 cupsFilePrintf(fp
, "_default:use=%s\n", DefaultPrinter
->name
);
3783 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3785 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3786 cupsFilePrintf(fp
, "%s:\\\n"
3787 "\t:bsdaddr=%s,%s:\\\n"
3788 "\t:description=%s:\n",
3789 p
->name
, ServerName
, p
->name
,
3790 p
->info
? p
->info
: "");
3804 * 'add_printer_defaults()' - Add name-default attributes to the printer attributes.
3808 add_printer_defaults(cupsd_printer_t
*p
)/* I - Printer */
3810 int i
; /* Looping var */
3811 int num_options
; /* Number of default options */
3812 cups_option_t
*options
, /* Default options */
3813 *option
; /* Current option */
3814 char name
[256]; /* name-default */
3818 * Maintain a common array of default attribute names...
3821 if (!CommonDefaults
)
3823 CommonDefaults
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
3825 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("copies-default"));
3826 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("document-format-default"));
3827 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("finishings-default"));
3828 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-hold-until-default"));
3829 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-priority-default"));
3830 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-sheets-default"));
3831 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("media-default"));
3832 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("number-up-default"));
3833 cupsArrayAdd(CommonDefaults
,
3834 _cupsStrAlloc("orientation-requested-default"));
3835 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("sides-default"));
3839 * Add all of the default options from the .conf files...
3842 for (num_options
= 0, options
= NULL
, i
= p
->num_options
, option
= p
->options
;
3846 if (strcmp(option
->name
, "ipp-options") &&
3847 strcmp(option
->name
, "job-sheets") &&
3848 strcmp(option
->name
, "lease-duration"))
3850 snprintf(name
, sizeof(name
), "%s-default", option
->name
);
3851 num_options
= cupsAddOption(name
, option
->value
, num_options
, &options
);
3853 if (!cupsArrayFind(CommonDefaults
, name
))
3854 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc(name
));
3859 * Convert options to IPP attributes...
3862 cupsEncodeOptions2(p
->attrs
, num_options
, options
, IPP_TAG_PRINTER
);
3863 cupsFreeOptions(num_options
, options
);
3866 * Add standard -default attributes as needed...
3869 if (!cupsGetOption("copies", p
->num_options
, p
->options
))
3870 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
, "copies-default",
3873 if (!cupsGetOption("document-format", p
->num_options
, p
->options
))
3874 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_MIMETYPE
,
3875 "document-format-default", NULL
, "application/octet-stream");
3877 if (!cupsGetOption("job-hold-until", p
->num_options
, p
->options
))
3878 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3879 "job-hold-until-default", NULL
, "no-hold");
3881 if (!cupsGetOption("job-priority", p
->num_options
, p
->options
))
3882 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3883 "job-priority-default", 50);
3885 if (!cupsGetOption("number-up", p
->num_options
, p
->options
))
3886 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3887 "number-up-default", 1);
3889 if (!cupsGetOption("orientation-requested", p
->num_options
, p
->options
))
3890 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NOVALUE
,
3891 "orientation-requested-default", NULL
, NULL
);
3893 if (!cupsGetOption("notify-lease-duration", p
->num_options
, p
->options
))
3894 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3895 "notify-lease-duration-default", DefaultLeaseDuration
);
3897 if (!cupsGetOption("notify-events", p
->num_options
, p
->options
))
3898 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3899 "notify-events-default", NULL
, "job-completed");
3904 * 'add_printer_filter()' - Add a MIME filter for a printer.
3909 cupsd_printer_t
*p
, /* I - Printer to add to */
3910 mime_type_t
*filtertype
, /* I - Filter or prefilter MIME type */
3911 const char *filter
) /* I - Filter to add */
3913 char super
[MIME_MAX_SUPER
], /* Super-type for filter */
3914 type
[MIME_MAX_TYPE
], /* Type for filter */
3915 program
[1024]; /* Program/filter name */
3916 int cost
; /* Cost of filter */
3917 mime_type_t
*temptype
; /* MIME type looping var */
3918 char filename
[1024]; /* Full filter filename */
3922 * Parse the filter string; it should be in the following format:
3924 * super/type cost program
3927 if (sscanf(filter
, "%15[^/]/%31s%d%*[ \t]%1023[^\n]", super
, type
, &cost
,
3930 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: invalid filter string \"%s\"!",
3936 * See if the filter program exists; if not, stop the printer and flag
3940 if (strcmp(program
, "-"))
3942 if (program
[0] == '/')
3943 strlcpy(filename
, program
, sizeof(filename
));
3945 snprintf(filename
, sizeof(filename
), "%s/filter/%s", ServerBin
, program
);
3947 if (access(filename
, X_OK
))
3949 snprintf(p
->state_message
, sizeof(p
->state_message
),
3950 "Filter \"%s\" for printer \"%s\" not available: %s",
3951 program
, p
->name
, strerror(errno
));
3952 cupsdSetPrinterReasons(p
, "+cups-missing-filter-error");
3953 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, 0);
3955 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s", p
->state_message
);
3960 * Mark the CUPS_PRINTER_COMMANDS bit if we have a filter for
3961 * application/vnd.cups-command...
3964 if (!strcasecmp(super
, "application") &&
3965 !strcasecmp(type
, "vnd.cups-command"))
3966 p
->type
|= CUPS_PRINTER_COMMANDS
;
3969 * Add the filter to the MIME database, supporting wildcards as needed...
3972 for (temptype
= mimeFirstType(MimeDatabase
);
3974 temptype
= mimeNextType(MimeDatabase
))
3975 if (((super
[0] == '*' && strcasecmp(temptype
->super
, "printer")) ||
3976 !strcasecmp(temptype
->super
, super
)) &&
3977 (type
[0] == '*' || !strcasecmp(temptype
->type
, type
)))
3979 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3980 "add_printer_filter: %s: adding filter %s/%s %s/%s %d %s",
3981 p
->name
, temptype
->super
, temptype
->type
,
3982 filtertype
->super
, filtertype
->type
,
3984 mimeAddFilter(MimeDatabase
, temptype
, filtertype
, cost
, program
);
3990 * 'add_printer_formats()' - Add document-format-supported values for a printer.
3994 add_printer_formats(cupsd_printer_t
*p
) /* I - Printer */
3996 int i
; /* Looping var */
3997 mime_type_t
*type
; /* Current MIME type */
3998 cups_array_t
*filters
; /* Filters */
3999 ipp_attribute_t
*attr
; /* document-format-supported attribute */
4000 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
4001 /* MIME type name */
4005 * Raw (and remote) queues advertise all of the supported MIME
4009 cupsArrayDelete(p
->filetypes
);
4010 p
->filetypes
= NULL
;
4014 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
,
4015 (ipp_tag_t
)(IPP_TAG_MIMETYPE
| IPP_TAG_COPY
),
4016 "document-format-supported", NumMimeTypes
, NULL
, MimeTypes
);
4021 * Otherwise, loop through the supported MIME types and see if there
4022 * are filters for them...
4025 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_printer_formats: %d types, %d filters",
4026 mimeNumTypes(MimeDatabase
), mimeNumFilters(MimeDatabase
));
4028 p
->filetypes
= cupsArrayNew(NULL
, NULL
);
4030 for (type
= mimeFirstType(MimeDatabase
);
4032 type
= mimeNextType(MimeDatabase
))
4034 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
4036 if ((filters
= mimeFilter(MimeDatabase
, type
, p
->filetype
, NULL
)) != NULL
)
4038 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4039 "add_printer_formats: %s: %s needs %d filters",
4040 p
->name
, mimetype
, cupsArrayCount(filters
));
4042 cupsArrayDelete(filters
);
4043 cupsArrayAdd(p
->filetypes
, type
);
4046 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4047 "add_printer_formats: %s: %s not supported",
4051 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4052 "add_printer_formats: %s: %d supported types",
4053 p
->name
, cupsArrayCount(p
->filetypes
) + 1);
4056 * Add the file formats that can be filtered...
4059 if ((type
= mimeType(MimeDatabase
, "application", "octet-stream")) == NULL
||
4060 !cupsArrayFind(p
->filetypes
, type
))
4065 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_MIMETYPE
,
4066 "document-format-supported",
4067 cupsArrayCount(p
->filetypes
) + 1, NULL
, NULL
);
4070 attr
->values
[0].string
.text
= _cupsStrAlloc("application/octet-stream");
4072 for (type
= (mime_type_t
*)cupsArrayFirst(p
->filetypes
);
4074 i
++, type
= (mime_type_t
*)cupsArrayNext(p
->filetypes
))
4076 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
4078 attr
->values
[i
].string
.text
= _cupsStrAlloc(mimetype
);
4083 char pdl
[1024]; /* Buffer to build pdl list */
4084 mime_filter_t
*filter
; /* MIME filter looping var */
4089 if (mimeType(MimeDatabase
, "application", "pdf"))
4090 strlcat(pdl
, "application/pdf,", sizeof(pdl
));
4092 if (mimeType(MimeDatabase
, "application", "postscript"))
4093 strlcat(pdl
, "application/postscript,", sizeof(pdl
));
4095 if (mimeType(MimeDatabase
, "application", "vnd.cups-raster"))
4096 strlcat(pdl
, "application/vnd.cups-raster,", sizeof(pdl
));
4099 * Determine if this is a Tioga PrintJobMgr based queue...
4102 for (filter
= (mime_filter_t
*)cupsArrayFirst(MimeDatabase
->filters
);
4104 filter
= (mime_filter_t
*)cupsArrayNext(MimeDatabase
->filters
))
4106 if (filter
->dst
== p
->filetype
&& filter
->filter
&&
4107 strstr(filter
->filter
, "PrintJobMgr"))
4112 * We only support raw printing if this is not a Tioga PrintJobMgr based
4113 * queue and if application/octet-stream is a known conversion...
4116 if (!filter
&& mimeType(MimeDatabase
, "application", "octet-stream"))
4117 strlcat(pdl
, "application/octet-stream,", sizeof(pdl
));
4119 if (mimeType(MimeDatabase
, "image", "png"))
4120 strlcat(pdl
, "image/png,", sizeof(pdl
));
4123 pdl
[strlen(pdl
) - 1] = '\0'; /* Remove trailing comma */
4125 cupsdSetString(&p
->pdl
, pdl
);
4127 #endif /* HAVE_DNSSD */
4132 * 'compare_printers()' - Compare two printers.
4135 static int /* O - Result of comparison */
4136 compare_printers(void *first
, /* I - First printer */
4137 void *second
, /* I - Second printer */
4138 void *data
) /* I - App data (not used) */
4140 return (strcasecmp(((cupsd_printer_t
*)first
)->name
,
4141 ((cupsd_printer_t
*)second
)->name
));
4146 * 'delete_printer_filters()' - Delete all MIME filters for a printer.
4150 delete_printer_filters(
4151 cupsd_printer_t
*p
) /* I - Printer to remove from */
4153 mime_filter_t
*filter
; /* MIME filter looping var */
4157 * Range check input...
4164 * Remove all filters from the MIME database that have a destination
4165 * type == printer...
4168 for (filter
= mimeFirstFilter(MimeDatabase
);
4170 filter
= mimeNextFilter(MimeDatabase
))
4171 if (filter
->dst
== p
->filetype
)
4174 * Delete the current filter...
4177 mimeDeleteFilter(MimeDatabase
, filter
);
4184 * 'write_irix_config()' - Update the config files used by the IRIX
4189 write_irix_config(cupsd_printer_t
*p
) /* I - Printer to update */
4191 char filename
[1024]; /* Interface script filename */
4192 cups_file_t
*fp
; /* Interface script file */
4193 ipp_attribute_t
*attr
; /* Attribute data */
4197 * Add dummy interface and GUI scripts to fool SGI's "challenged" printing
4198 * tools. First the interface script that tells the tools what kind of
4199 * printer we have...
4202 snprintf(filename
, sizeof(filename
), "/var/spool/lp/interface/%s", p
->name
);
4204 if (p
->type
& CUPS_PRINTER_CLASS
)
4206 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
4208 cupsFilePuts(fp
, "#!/bin/sh\n");
4210 if ((attr
= ippFindAttribute(p
->attrs
, "printer-make-and-model",
4211 IPP_TAG_TEXT
)) != NULL
)
4212 cupsFilePrintf(fp
, "NAME=\"%s\"\n", attr
->values
[0].string
.text
);
4213 else if (p
->type
& CUPS_PRINTER_CLASS
)
4214 cupsFilePuts(fp
, "NAME=\"Printer Class\"\n");
4216 cupsFilePuts(fp
, "NAME=\"Remote Destination\"\n");
4218 if (p
->type
& CUPS_PRINTER_COLOR
)
4219 cupsFilePuts(fp
, "TYPE=ColorPostScript\n");
4221 cupsFilePuts(fp
, "TYPE=MonoPostScript\n");
4223 cupsFilePrintf(fp
, "HOSTNAME=%s\n", ServerName
);
4224 cupsFilePrintf(fp
, "HOSTPRINTER=%s\n", p
->name
);
4228 chmod(filename
, 0755);
4229 chown(filename
, User
, Group
);
4233 * Then the member file that tells which device file the queue is connected
4234 * to... Networked printers use "/dev/null" in this file, so that's what
4235 * we use (the actual device URI can confuse some apps...)
4238 snprintf(filename
, sizeof(filename
), "/var/spool/lp/member/%s", p
->name
);
4240 if (p
->type
& CUPS_PRINTER_CLASS
)
4242 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
4244 cupsFilePuts(fp
, "/dev/null\n");
4248 chmod(filename
, 0644);
4249 chown(filename
, User
, Group
);
4253 * The gui_interface file is a script or program that launches a GUI
4254 * option panel for the printer, using options specified on the
4255 * command-line in the third argument. The option panel must send
4256 * any printing options to stdout on a single line when the user
4257 * accepts them, or nothing if the user cancels the dialog.
4259 * The default options panel program is /usr/bin/glpoptions, from
4260 * the ESP Print Pro software. You can select another using the
4261 * PrintcapGUI option.
4264 snprintf(filename
, sizeof(filename
), "/var/spool/lp/gui_interface/ELF/%s.gui", p
->name
);
4266 if (p
->type
& CUPS_PRINTER_CLASS
)
4268 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
4270 cupsFilePuts(fp
, "#!/bin/sh\n");
4271 cupsFilePrintf(fp
, "%s -d %s -o \"$3\"\n", PrintcapGUI
, p
->name
);
4275 chmod(filename
, 0755);
4276 chown(filename
, User
, Group
);
4280 * The POD config file is needed by the printstatus command to show
4281 * the printer location and device.
4284 snprintf(filename
, sizeof(filename
), "/var/spool/lp/pod/%s.config", p
->name
);
4286 if (p
->type
& CUPS_PRINTER_CLASS
)
4288 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
4290 cupsFilePrintf(fp
, "Printer Class | %s\n",
4291 (p
->type
& CUPS_PRINTER_COLOR
) ? "ColorPostScript" : "MonoPostScript");
4292 cupsFilePrintf(fp
, "Printer Model | %s\n", p
->make_model
? p
->make_model
: "");
4293 cupsFilePrintf(fp
, "Location Code | %s\n", p
->location
? p
->location
: "");
4294 cupsFilePrintf(fp
, "Physical Location | %s\n", p
->info
? p
->info
: "");
4295 cupsFilePrintf(fp
, "Port Path | %s\n", p
->device_uri
);
4296 cupsFilePrintf(fp
, "Config Path | /var/spool/lp/pod/%s.config\n", p
->name
);
4297 cupsFilePrintf(fp
, "Active Status Path | /var/spool/lp/pod/%s.status\n", p
->name
);
4298 cupsFilePuts(fp
, "Status Update Wait | 10 seconds\n");
4302 chmod(filename
, 0664);
4303 chown(filename
, User
, Group
);
4309 * 'write_irix_state()' - Update the status files used by IRIX printing
4314 write_irix_state(cupsd_printer_t
*p
) /* I - Printer to update */
4316 char filename
[1024]; /* Interface script filename */
4317 cups_file_t
*fp
; /* Interface script file */
4318 int tag
; /* Status tag value */
4324 * The POD status file is needed for the printstatus window to
4325 * provide the current status of the printer.
4328 snprintf(filename
, sizeof(filename
), "/var/spool/lp/pod/%s.status", p
->name
);
4330 if (p
->type
& CUPS_PRINTER_CLASS
)
4332 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
4334 cupsFilePrintf(fp
, "Operational Status | %s\n",
4335 (p
->state
== IPP_PRINTER_IDLE
) ? "Idle" :
4336 (p
->state
== IPP_PRINTER_PROCESSING
) ? "Busy" :
4338 cupsFilePrintf(fp
, "Information | 01 00 00 | %s\n", CUPS_SVERSION
);
4339 cupsFilePrintf(fp
, "Information | 02 00 00 | Device URI: %s\n",
4341 cupsFilePrintf(fp
, "Information | 03 00 00 | %s jobs\n",
4342 p
->accepting
? "Accepting" : "Not accepting");
4343 cupsFilePrintf(fp
, "Information | 04 00 00 | %s\n", p
->state_message
);
4347 chmod(filename
, 0664);
4348 chown(filename
, User
, Group
);
4352 * The activeicons file is needed to provide desktop icons for printers:
4354 * [ quoted from /usr/lib/print/tagit ]
4356 * --- Type of printer tags (base values)
4358 * Dumb=66048 # 0x10200
4359 * DumbColor=66080 # 0x10220
4360 * Raster=66112 # 0x10240
4361 * ColorRaster=66144 # 0x10260
4362 * Plotter=66176 # 0x10280
4363 * PostScript=66208 # 0x102A0
4364 * ColorPostScript=66240 # 0x102C0
4365 * MonoPostScript=66272 # 0x102E0
4367 * --- Printer state modifiers for local printers
4372 * Unknown=3 # 0x3 (Faulted due to unknown reason)
4374 * --- Printer state modifiers for network printers
4378 * NetFaulted=10 # 0xA
4379 * NetUnknown=11 # 0xB (Faulted due to unknown reason)
4382 snprintf(filename
, sizeof(filename
), "/var/spool/lp/activeicons/%s", p
->name
);
4384 if (p
->type
& CUPS_PRINTER_CLASS
)
4386 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
4388 if (p
->type
& CUPS_PRINTER_COLOR
)
4393 if (p
->type
& CUPS_PRINTER_REMOTE
)
4396 if (p
->state
== IPP_PRINTER_PROCESSING
)
4399 else if (p
->state
== IPP_PRINTER_STOPPED
)
4402 cupsFilePuts(fp
, "#!/bin/sh\n");
4403 cupsFilePrintf(fp
, "#Tag %d\n", tag
);
4407 chmod(filename
, 0755);
4408 chown(filename
, User
, Group
);
4413 * The default file is needed by the printers window to show
4414 * the default printer.
4417 snprintf(filename
, sizeof(filename
), "/var/spool/lp/default");
4419 if (DefaultPrinter
!= NULL
)
4421 if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
4423 cupsFilePrintf(fp
, "%s\n", DefaultPrinter
->name
);
4427 chmod(filename
, 0644);
4428 chown(filename
, User
, Group
);
4438 * 'write_xml_string()' - Write a string with XML escaping.
4442 write_xml_string(cups_file_t
*fp
, /* I - File to write to */
4443 const char *s
) /* I - String to write */
4445 const char *start
; /* Start of current sequence */
4451 for (start
= s
; *s
; s
++)
4456 cupsFileWrite(fp
, start
, s
- start
);
4458 cupsFilePuts(fp
, "&");
4464 cupsFileWrite(fp
, start
, s
- start
);
4466 cupsFilePuts(fp
, "<");
4472 cupsFilePuts(fp
, start
);
4477 * End of "$Id: printers.c 7968 2008-09-19 23:03:01Z mike $".