2 * "$Id: printers.c 6970 2007-09-17 23:58:28Z mike $"
4 * Printer routines for the Common UNIX Printing System (CUPS).
6 * Copyright 2007 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 * cupsdSetPrinterAttrs() - Set printer attributes based upon the PPD
32 * cupsdSetPrinterReasons() - Set/update the reasons strings.
33 * cupsdSetPrinterState() - Update the current state of a printer.
34 * cupsdStopPrinter() - Stop a printer from printing any jobs...
35 * cupsdUpdatePrinters() - Update printers after a partial reload.
36 * cupsdValidateDest() - Validate a printer/class destination.
37 * cupsdWritePrintcap() - Write a pseudo-printcap file for older
38 * applications that need it...
39 * cupsdSanitizeURI() - Sanitize a device URI...
40 * add_printer_defaults() - Add name-default attributes to the printer
42 * add_printer_filter() - Add a MIME filter for a printer.
43 * add_printer_formats() - Add document-format-supported values for
45 * compare_printers() - Compare two printers.
46 * delete_printer_filters() - Delete all MIME filters for a printer.
47 * write_irix_config() - Update the config files used by the IRIX
49 * write_irix_state() - Update the status files used by IRIX
50 * printing desktop tools.
54 * Include necessary headers...
65 static void add_printer_defaults(cupsd_printer_t
*p
);
66 static void add_printer_filter(cupsd_printer_t
*p
, mime_type_t
*type
,
68 static void add_printer_formats(cupsd_printer_t
*p
);
69 static int compare_printers(void *first
, void *second
, void *data
);
70 static void delete_printer_filters(cupsd_printer_t
*p
);
72 static void write_irix_config(cupsd_printer_t
*p
);
73 static void write_irix_state(cupsd_printer_t
*p
);
78 * 'cupsdAddPrinter()' - Add a printer to the system.
81 cupsd_printer_t
* /* O - New printer */
82 cupsdAddPrinter(const char *name
) /* I - Name of printer */
84 cupsd_printer_t
*p
; /* New printer */
88 * Range check input...
91 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdAddPrinter(\"%s\")", name
);
94 * Create a new printer entity...
97 if ((p
= calloc(1, sizeof(cupsd_printer_t
))) == NULL
)
99 cupsdLogMessage(CUPSD_LOG_CRIT
, "Unable to allocate memory for printer - %s",
104 cupsdSetString(&p
->name
, name
);
105 cupsdSetString(&p
->info
, name
);
106 cupsdSetString(&p
->hostname
, ServerName
);
108 cupsdSetStringf(&p
->uri
, "ipp://%s:%d/printers/%s", ServerName
, LocalPort
, name
);
109 cupsdSetStringf(&p
->device_uri
, "file:/dev/null");
111 p
->state
= IPP_PRINTER_STOPPED
;
112 p
->state_time
= time(NULL
);
114 p
->shared
= DefaultShared
;
115 p
->filetype
= mimeAddType(MimeDatabase
, "printer", name
);
117 cupsdSetString(&p
->job_sheets
[0], "none");
118 cupsdSetString(&p
->job_sheets
[1], "none");
120 cupsdSetString(&p
->error_policy
, ErrorPolicy
);
121 cupsdSetString(&p
->op_policy
, DefaultPolicy
);
123 p
->op_policy_ptr
= DefaultPolicyPtr
;
125 if (MaxPrinterHistory
)
126 p
->history
= calloc(MaxPrinterHistory
, sizeof(ipp_t
*));
129 * Insert the printer in the printer list alphabetically...
133 Printers
= cupsArrayNew(compare_printers
, NULL
);
135 cupsArrayAdd(Printers
, p
);
137 if (!ImplicitPrinters
)
138 ImplicitPrinters
= cupsArrayNew(compare_printers
, NULL
);
141 * Return the new printer...
149 * 'cupsdAddPrinterHistory()' - Add the current printer state to the history.
153 cupsdAddPrinterHistory(
154 cupsd_printer_t
*p
) /* I - Printer */
156 ipp_t
*history
; /* History collection */
160 * Stop early if we aren't keeping history data...
163 if (MaxPrinterHistory
<= 0)
167 * Retire old history data as needed...
170 p
->sequence_number
++;
172 if (p
->num_history
>= MaxPrinterHistory
)
175 ippDelete(p
->history
[0]);
176 memmove(p
->history
, p
->history
+ 1, p
->num_history
* sizeof(ipp_t
*));
180 * Create a collection containing the current printer-state, printer-up-time,
181 * printer-state-message, and printer-state-reasons attributes.
185 ippAddInteger(history
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-state",
187 ippAddBoolean(history
, IPP_TAG_PRINTER
, "printer-is-accepting-jobs",
189 ippAddBoolean(history
, IPP_TAG_PRINTER
, "printer-is-shared", p
->shared
);
190 ippAddString(history
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-state-message",
191 NULL
, p
->state_message
);
194 ippAddString(history
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
195 "com.apple.print.recoverable-message", NULL
, p
->recoverable
);
196 #endif /* __APPLE__ */
197 if (p
->num_reasons
== 0)
198 ippAddString(history
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
199 "printer-state-reasons", NULL
,
200 p
->state
== IPP_PRINTER_STOPPED
? "paused" : "none");
202 ippAddStrings(history
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
203 "printer-state-reasons", p
->num_reasons
, NULL
,
204 (const char * const *)p
->reasons
);
205 ippAddInteger(history
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
206 "printer-state-change-time", p
->state_time
);
207 ippAddInteger(history
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
208 "printer-state-sequence-number", p
->sequence_number
);
210 p
->history
[p
->num_history
] = history
;
216 * 'cupsdAddPrinterUser()' - Add a user to the ACL.
221 cupsd_printer_t
*p
, /* I - Printer */
222 const char *username
) /* I - User */
224 const char **temp
; /* Temporary array pointer */
230 if (p
->num_users
== 0)
231 temp
= malloc(sizeof(char **));
233 temp
= realloc(p
->users
, sizeof(char **) * (p
->num_users
+ 1));
239 temp
+= p
->num_users
;
241 if ((*temp
= strdup(username
)) != NULL
)
247 * 'cupsdCreateCommonData()' - Create the common printer data.
251 cupsdCreateCommonData(void)
253 int i
; /* Looping var */
254 ipp_attribute_t
*attr
; /* Attribute data */
255 cups_dir_t
*dir
; /* Notifier directory */
256 cups_dentry_t
*dent
; /* Notifier directory entry */
257 cups_array_t
*notifiers
; /* Notifier array */
258 char filename
[1024], /* Filename */
259 *notifier
; /* Current notifier */
260 cupsd_policy_t
*p
; /* Current policy */
261 static const int nups
[] = /* number-up-supported values */
262 { 1, 2, 4, 6, 9, 16 };
263 static const int orients
[4] =/* orientation-requested-supported values */
267 IPP_REVERSE_LANDSCAPE
,
270 static const char * const holds
[] = /* job-hold-until-supported values */
281 static const char * const versions
[] =/* ipp-versions-supported values */
286 static const int ops
[] = /* operations-supported values */
293 IPP_GET_JOB_ATTRIBUTES
,
295 IPP_GET_PRINTER_ATTRIBUTES
,
301 IPP_SET_JOB_ATTRIBUTES
,
302 IPP_CREATE_PRINTER_SUBSCRIPTION
,
303 IPP_CREATE_JOB_SUBSCRIPTION
,
304 IPP_GET_SUBSCRIPTION_ATTRIBUTES
,
305 IPP_GET_SUBSCRIPTIONS
,
306 IPP_RENEW_SUBSCRIPTION
,
307 IPP_CANCEL_SUBSCRIPTION
,
308 IPP_GET_NOTIFICATIONS
,
324 CUPS_AUTHENTICATE_JOB
,
329 static const char * const charsets
[] =/* charset-supported values */
334 static const char * const compressions
[] =
335 { /* document-compression-supported values */
339 #endif /* HAVE_LIBZ */
341 static const char * const multiple_document_handling
[] =
342 { /* multiple-document-handling-supported values */
343 "separate-documents-uncollated-copies",
344 "separate-documents-collated-copies"
346 static const char * const errors
[] = /* printer-error-policy-supported values */
352 static const char * const notify_attrs
[] =
353 { /* notify-attributes-supported values */
354 "printer-state-change-time",
355 "notify-lease-expiration-time",
356 "notify-subscriber-user-name"
358 static const char * const notify_events
[] =
359 { /* notify-events-supported values */
361 "job-config-changed",
368 "printer-config-changed",
370 "printer-finishings-changed",
371 "printer-media-changed",
375 "printer-state-changed",
385 ippDelete(CommonData
);
387 CommonData
= ippNew();
390 * This list of attributes is sorted to improve performance when the
391 * client provides a requested-attributes attribute...
394 /* charset-configured */
395 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_CHARSET
,
396 "charset-configured", NULL
, DefaultCharset
);
398 /* charset-supported */
399 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_CHARSET
,
400 "charset-supported", sizeof(charsets
) / sizeof(charsets
[0]),
403 /* compression-supported */
404 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
405 "compression-supported",
406 sizeof(compressions
) / sizeof(compressions
[0]),
409 /* copies-supported */
410 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "copies-supported", 1, MaxCopies
);
413 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "cups-version",
414 NULL
, CUPS_SVERSION
+ 6);
416 /* generated-natural-language-supported */
417 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_LANGUAGE
,
418 "generated-natural-language-supported", NULL
, DefaultLanguage
);
420 /* ipp-versions-supported */
421 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
422 "ipp-versions-supported", sizeof(versions
) / sizeof(versions
[0]),
425 /* job-hold-until-supported */
426 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
427 "job-hold-until-supported", sizeof(holds
) / sizeof(holds
[0]),
430 /* job-priority-supported */
431 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
432 "job-priority-supported", 100);
434 /* job-sheets-supported */
435 if (cupsArrayCount(Banners
) > 0)
438 * Setup the job-sheets-supported attribute...
441 if (Classification
&& !ClassifyOverride
)
442 attr
= ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
443 "job-sheets-supported", NULL
, Classification
);
445 attr
= ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
446 "job-sheets-supported", cupsArrayCount(Banners
) + 1,
450 cupsdLogMessage(CUPSD_LOG_EMERG
,
451 "Unable to allocate memory for "
452 "job-sheets-supported attribute: %s!", strerror(errno
));
453 else if (!Classification
|| ClassifyOverride
)
455 cupsd_banner_t
*banner
; /* Current banner */
458 attr
->values
[0].string
.text
= _cupsStrAlloc("none");
460 for (i
= 1, banner
= (cupsd_banner_t
*)cupsArrayFirst(Banners
);
462 i
++, banner
= (cupsd_banner_t
*)cupsArrayNext(Banners
))
463 attr
->values
[i
].string
.text
= _cupsStrAlloc(banner
->name
);
467 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
468 "job-sheets-supported", NULL
, "none");
470 /* multiple-document-handling-supported */
471 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
472 "multiple-document-handling-supported",
473 sizeof(multiple_document_handling
) /
474 sizeof(multiple_document_handling
[0]), NULL
,
475 multiple_document_handling
);
477 /* multiple-document-jobs-supported */
478 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
,
479 "multiple-document-jobs-supported", 1);
481 /* multiple-operation-time-out */
482 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
483 "multiple-operation-time-out", 60);
485 /* natural-language-configured */
486 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_LANGUAGE
,
487 "natural-language-configured", NULL
, DefaultLanguage
);
489 /* notify-attributes-supported */
490 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
491 "notify-attributes-supported",
492 (int)(sizeof(notify_attrs
) / sizeof(notify_attrs
[0])),
495 /* notify-lease-duration-supported */
496 ippAddRange(CommonData
, IPP_TAG_PRINTER
,
497 "notify-lease-duration-supported", 0,
498 MaxLeaseDuration
? MaxLeaseDuration
: 2147483647);
500 /* notify-max-events-supported */
501 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
502 "notify-max-events-supported", MaxEvents
);
504 /* notify-events-supported */
505 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
506 "notify-events-supported",
507 (int)(sizeof(notify_events
) / sizeof(notify_events
[0])),
508 NULL
, notify_events
);
510 /* notify-pull-method-supported */
511 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
512 "notify-pull-method-supported", NULL
, "ippget");
514 /* notify-schemes-supported */
515 snprintf(filename
, sizeof(filename
), "%s/notifier", ServerBin
);
516 if ((dir
= cupsDirOpen(filename
)) != NULL
)
518 notifiers
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
520 while ((dent
= cupsDirRead(dir
)) != NULL
)
521 if (S_ISREG(dent
->fileinfo
.st_mode
) &&
522 (dent
->fileinfo
.st_mode
& S_IXOTH
) != 0)
523 cupsArrayAdd(notifiers
, _cupsStrAlloc(dent
->filename
));
525 if (cupsArrayCount(notifiers
) > 0)
527 attr
= ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
528 "notify-schemes-supported",
529 cupsArrayCount(notifiers
), NULL
, NULL
);
531 for (i
= 0, notifier
= (char *)cupsArrayFirst(notifiers
);
533 i
++, notifier
= (char *)cupsArrayNext(notifiers
))
534 attr
->values
[i
].string
.text
= notifier
;
537 cupsArrayDelete(notifiers
);
541 /* number-up-supported */
542 ippAddIntegers(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
543 "number-up-supported", sizeof(nups
) / sizeof(nups
[0]), nups
);
545 /* operations-supported */
546 ippAddIntegers(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
547 "operations-supported",
548 sizeof(ops
) / sizeof(ops
[0]) + JobFiles
- 1, ops
);
550 /* orientation-requested-supported */
551 ippAddIntegers(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
552 "orientation-requested-supported", 4, orients
);
554 /* page-ranges-supported */
555 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
, "page-ranges-supported", 1);
557 /* pdf-override-supported */
558 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
559 "pdl-override-supported", NULL
, "not-attempted");
561 /* printer-error-policy-supported */
562 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
563 "printer-error-policy-supported",
564 sizeof(errors
) / sizeof(errors
[0]), NULL
, errors
);
566 /* printer-op-policy-supported */
567 attr
= ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
568 "printer-op-policy-supported", cupsArrayCount(Policies
),
570 for (i
= 0, p
= (cupsd_policy_t
*)cupsArrayFirst(Policies
);
572 i
++, p
= (cupsd_policy_t
*)cupsArrayNext(Policies
))
573 attr
->values
[i
].string
.text
= _cupsStrAlloc(p
->name
);
575 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
, "server-is-sharing-printers",
576 BrowseLocalProtocols
!= 0 && Browsing
);
581 * 'cupsdDeleteAllPrinters()' - Delete all printers from the system.
585 cupsdDeleteAllPrinters(void)
587 cupsd_printer_t
*p
; /* Pointer to current printer/class */
590 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
592 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
593 if (!(p
->type
& CUPS_PRINTER_CLASS
))
594 cupsdDeletePrinter(p
, 0);
599 * 'cupsdDeletePrinter()' - Delete a printer from the system.
604 cupsd_printer_t
*p
, /* I - Printer to delete */
605 int update
) /* I - Update printers.conf? */
607 int i
; /* Looping var */
609 char filename
[1024]; /* Interface script filename */
613 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdDeletePrinter(p=%p(%s), update=%d)",
617 * Save the current position in the Printers array...
620 cupsArraySave(Printers
);
623 * Stop printing on this printer...
626 cupsdStopPrinter(p
, update
);
629 * If this printer is the next for browsing, point to the next one...
634 cupsArrayFind(Printers
, p
);
635 BrowseNext
= (cupsd_printer_t
*)cupsArrayNext(Printers
);
639 * Remove the printer from the list...
642 cupsArrayRemove(Printers
, p
);
644 if (p
->type
& CUPS_PRINTER_IMPLICIT
)
645 cupsArrayRemove(ImplicitPrinters
, p
);
648 * Remove the dummy interface/icon/option files under IRIX...
652 snprintf(filename
, sizeof(filename
), "/var/spool/lp/interface/%s", p
->name
);
655 snprintf(filename
, sizeof(filename
), "/var/spool/lp/gui_interface/ELF/%s.gui",
659 snprintf(filename
, sizeof(filename
), "/var/spool/lp/activeicons/%s", p
->name
);
662 snprintf(filename
, sizeof(filename
), "/var/spool/lp/pod/%s.config", p
->name
);
665 snprintf(filename
, sizeof(filename
), "/var/spool/lp/pod/%s.status", p
->name
);
668 snprintf(filename
, sizeof(filename
), "/var/spool/lp/member/%s", p
->name
);
673 * If p is the default printer, assign a different one...
676 if (p
== DefaultPrinter
)
678 DefaultPrinter
= NULL
;
680 if (UseNetworkDefault
)
683 * Find the first network default printer and use it...
686 cupsd_printer_t
*dp
; /* New default printer */
689 for (dp
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
691 dp
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
692 if (dp
!= p
&& (dp
->type
& CUPS_PRINTER_DEFAULT
))
701 * Remove this printer from any classes...
704 if (!(p
->type
& CUPS_PRINTER_IMPLICIT
))
706 cupsdDeletePrinterFromClasses(p
);
709 * Deregister from any browse protocols...
712 cupsdDeregisterPrinter(p
, 1);
716 * Free all memory used by the printer...
719 if (p
->printers
!= NULL
)
722 if (MaxPrinterHistory
)
724 for (i
= 0; i
< p
->num_history
; i
++)
725 ippDelete(p
->history
[i
]);
730 for (i
= 0; i
< p
->num_reasons
; i
++)
735 delete_printer_filters(p
);
737 mimeDeleteType(MimeDatabase
, p
->filetype
);
738 mimeDeleteType(MimeDatabase
, p
->prefiltertype
);
740 cupsdFreePrinterUsers(p
);
743 cupsdClearString(&p
->uri
);
744 cupsdClearString(&p
->hostname
);
745 cupsdClearString(&p
->name
);
746 cupsdClearString(&p
->location
);
747 cupsdClearString(&p
->make_model
);
748 cupsdClearString(&p
->info
);
749 cupsdClearString(&p
->job_sheets
[0]);
750 cupsdClearString(&p
->job_sheets
[1]);
751 cupsdClearString(&p
->device_uri
);
752 cupsdClearString(&p
->port_monitor
);
753 cupsdClearString(&p
->op_policy
);
754 cupsdClearString(&p
->error_policy
);
756 cupsdClearString(&p
->alert
);
757 cupsdClearString(&p
->alert_description
);
760 cupsdClearString(&p
->product
);
761 cupsdClearString(&p
->pdl
);
762 #endif /* HAVE_DNSSD */
764 cupsArrayDelete(p
->filetypes
);
767 free(p
->browse_attrs
);
770 cupsdClearString(&p
->recoverable
);
771 #endif /* __APPLE__ */
773 cupsFreeOptions(p
->num_options
, p
->options
);
778 * Restore the previous position in the Printers array...
781 cupsArrayRestore(Printers
);
786 * 'cupsdFindDest()' - Find a destination in the list.
789 cupsd_printer_t
* /* O - Destination in list */
790 cupsdFindDest(const char *name
) /* I - Name of printer or class to find */
792 cupsd_printer_t key
; /* Search key */
795 key
.name
= (char *)name
;
796 return ((cupsd_printer_t
*)cupsArrayFind(Printers
, &key
));
801 * 'cupsdFindPrinter()' - Find a printer in the list.
804 cupsd_printer_t
* /* O - Printer in list */
805 cupsdFindPrinter(const char *name
) /* I - Name of printer to find */
807 cupsd_printer_t
*p
; /* Printer in list */
810 if ((p
= cupsdFindDest(name
)) != NULL
&& (p
->type
& CUPS_PRINTER_CLASS
))
818 * 'cupsdFreePrinterUsers()' - Free allow/deny users.
822 cupsdFreePrinterUsers(
823 cupsd_printer_t
*p
) /* I - Printer */
825 int i
; /* Looping var */
828 if (!p
|| !p
->num_users
)
831 for (i
= 0; i
< p
->num_users
; i
++)
832 free((void *)p
->users
[i
]);
842 * 'cupsdLoadAllPrinters()' - Load printers from the printers.conf file.
846 cupsdLoadAllPrinters(void)
848 cups_file_t
*fp
; /* printers.conf file */
849 int linenum
; /* Current line number */
850 char line
[1024], /* Line from file */
851 *value
, /* Pointer to value */
852 *valueptr
; /* Pointer into value */
853 cupsd_printer_t
*p
; /* Current printer */
857 * Open the printers.conf file...
860 snprintf(line
, sizeof(line
), "%s/printers.conf", ServerRoot
);
861 if ((fp
= cupsFileOpen(line
, "r")) == NULL
)
864 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to open %s - %s", line
,
870 * Read printer configurations until we hit EOF...
876 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
879 * Decode the directive...
882 if (!strcasecmp(line
, "<Printer") ||
883 !strcasecmp(line
, "<DefaultPrinter"))
886 * <Printer name> or <DefaultPrinter name>
889 if (p
== NULL
&& value
)
892 * Add the printer and a base file type...
895 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Loading printer %s...", value
);
897 p
= cupsdAddPrinter(value
);
899 p
->state
= IPP_PRINTER_IDLE
;
902 * Set the default printer as needed...
905 if (!strcasecmp(line
, "<DefaultPrinter"))
910 cupsdLogMessage(CUPSD_LOG_ERROR
,
911 "Syntax error on line %d of printers.conf.", linenum
);
915 else if (!strcasecmp(line
, "</Printer>"))
920 * Close out the current printer...
923 cupsdSetPrinterAttrs(p
);
924 cupsdAddPrinterHistory(p
);
926 if (p
->device_uri
&& strncmp(p
->device_uri
, "file:", 5) &&
927 p
->state
!= IPP_PRINTER_STOPPED
)
930 * See if the backend exists...
933 snprintf(line
, sizeof(line
), "%s/backend/%s", ServerBin
,
936 if ((valueptr
= strchr(line
+ strlen(ServerBin
), ':')) != NULL
)
937 *valueptr
= '\0'; /* Chop everything but URI scheme */
942 * Backend does not exist, stop printer...
945 p
->state
= IPP_PRINTER_STOPPED
;
946 snprintf(p
->state_message
, sizeof(p
->state_message
),
947 "Backend %s does not exist!", line
);
955 cupsdLogMessage(CUPSD_LOG_ERROR
,
956 "Syntax error on line %d of printers.conf.", linenum
);
962 cupsdLogMessage(CUPSD_LOG_ERROR
,
963 "Syntax error on line %d of printers.conf.", linenum
);
966 else if (!strcasecmp(line
, "AuthInfoRequired"))
968 if (!cupsdSetAuthInfoRequired(p
, value
, NULL
))
969 cupsdLogMessage(CUPSD_LOG_ERROR
,
970 "Bad AuthInfoRequired on line %d of printers.conf.",
973 else if (!strcasecmp(line
, "Info"))
976 cupsdSetString(&p
->info
, value
);
978 else if (!strcasecmp(line
, "Location"))
981 cupsdSetString(&p
->location
, value
);
983 else if (!strcasecmp(line
, "DeviceURI"))
986 cupsdSetString(&p
->device_uri
, value
);
989 cupsdLogMessage(CUPSD_LOG_ERROR
,
990 "Syntax error on line %d of printers.conf.", linenum
);
994 else if (!strcasecmp(line
, "Option") && value
)
1000 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1003 cupsdLogMessage(CUPSD_LOG_ERROR
,
1004 "Syntax error on line %d of printers.conf.", linenum
);
1007 for (; *valueptr
&& isspace(*valueptr
& 255); *valueptr
++ = '\0');
1009 p
->num_options
= cupsAddOption(value
, valueptr
, p
->num_options
,
1013 else if (!strcasecmp(line
, "PortMonitor"))
1015 if (value
&& strcmp(value
, "none"))
1016 cupsdSetString(&p
->port_monitor
, value
);
1018 cupsdClearString(&p
->port_monitor
);
1021 cupsdLogMessage(CUPSD_LOG_ERROR
,
1022 "Syntax error on line %d of printers.conf.", linenum
);
1026 else if (!strcasecmp(line
, "State"))
1029 * Set the initial queue state...
1032 if (value
&& !strcasecmp(value
, "idle"))
1033 p
->state
= IPP_PRINTER_IDLE
;
1034 else if (value
&& !strcasecmp(value
, "stopped"))
1035 p
->state
= IPP_PRINTER_STOPPED
;
1038 cupsdLogMessage(CUPSD_LOG_ERROR
,
1039 "Syntax error on line %d of printers.conf.", linenum
);
1043 else if (!strcasecmp(line
, "StateMessage"))
1046 * Set the initial queue state message...
1050 strlcpy(p
->state_message
, value
, sizeof(p
->state_message
));
1052 else if (!strcasecmp(line
, "StateTime"))
1055 * Set the state time...
1059 p
->state_time
= atoi(value
);
1061 else if (!strcasecmp(line
, "Accepting"))
1064 * Set the initial accepting state...
1068 (!strcasecmp(value
, "yes") ||
1069 !strcasecmp(value
, "on") ||
1070 !strcasecmp(value
, "true")))
1073 (!strcasecmp(value
, "no") ||
1074 !strcasecmp(value
, "off") ||
1075 !strcasecmp(value
, "false")))
1079 cupsdLogMessage(CUPSD_LOG_ERROR
,
1080 "Syntax error on line %d of printers.conf.", linenum
);
1084 else if (!strcasecmp(line
, "Shared"))
1087 * Set the initial shared state...
1091 (!strcasecmp(value
, "yes") ||
1092 !strcasecmp(value
, "on") ||
1093 !strcasecmp(value
, "true")))
1096 (!strcasecmp(value
, "no") ||
1097 !strcasecmp(value
, "off") ||
1098 !strcasecmp(value
, "false")))
1102 cupsdLogMessage(CUPSD_LOG_ERROR
,
1103 "Syntax error on line %d of printers.conf.", linenum
);
1107 else if (!strcasecmp(line
, "JobSheets"))
1110 * Set the initial job sheets...
1115 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1120 cupsdSetString(&p
->job_sheets
[0], value
);
1122 while (isspace(*valueptr
& 255))
1127 for (value
= valueptr
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1132 cupsdSetString(&p
->job_sheets
[1], value
);
1137 cupsdLogMessage(CUPSD_LOG_ERROR
,
1138 "Syntax error on line %d of printers.conf.", linenum
);
1142 else if (!strcasecmp(line
, "AllowUser"))
1147 cupsdAddPrinterUser(p
, value
);
1151 cupsdLogMessage(CUPSD_LOG_ERROR
,
1152 "Syntax error on line %d of printers.conf.", linenum
);
1156 else if (!strcasecmp(line
, "DenyUser"))
1161 cupsdAddPrinterUser(p
, value
);
1165 cupsdLogMessage(CUPSD_LOG_ERROR
,
1166 "Syntax error on line %d of printers.conf.", linenum
);
1170 else if (!strcasecmp(line
, "QuotaPeriod"))
1173 p
->quota_period
= atoi(value
);
1176 cupsdLogMessage(CUPSD_LOG_ERROR
,
1177 "Syntax error on line %d of printers.conf.", linenum
);
1181 else if (!strcasecmp(line
, "PageLimit"))
1184 p
->page_limit
= atoi(value
);
1187 cupsdLogMessage(CUPSD_LOG_ERROR
,
1188 "Syntax error on line %d of printers.conf.", linenum
);
1192 else if (!strcasecmp(line
, "KLimit"))
1195 p
->k_limit
= atoi(value
);
1198 cupsdLogMessage(CUPSD_LOG_ERROR
,
1199 "Syntax error on line %d of printers.conf.", linenum
);
1203 else if (!strcasecmp(line
, "OpPolicy"))
1207 cupsd_policy_t
*pol
; /* Policy */
1210 if ((pol
= cupsdFindPolicy(value
)) != NULL
)
1212 cupsdSetString(&p
->op_policy
, value
);
1213 p
->op_policy_ptr
= pol
;
1216 cupsdLogMessage(CUPSD_LOG_ERROR
,
1217 "Bad policy \"%s\" on line %d of printers.conf",
1222 cupsdLogMessage(CUPSD_LOG_ERROR
,
1223 "Syntax error on line %d of printers.conf.", linenum
);
1227 else if (!strcasecmp(line
, "ErrorPolicy"))
1230 cupsdSetString(&p
->error_policy
, value
);
1233 cupsdLogMessage(CUPSD_LOG_ERROR
,
1234 "Syntax error on line %d of printers.conf.", linenum
);
1241 * Something else we don't understand...
1244 cupsdLogMessage(CUPSD_LOG_ERROR
,
1245 "Unknown configuration directive %s on line %d of printers.conf.",
1255 * 'cupsdRenamePrinter()' - Rename a printer.
1260 cupsd_printer_t
*p
, /* I - Printer */
1261 const char *name
) /* I - New name */
1264 * Remove the printer from the array(s) first...
1267 cupsArrayRemove(Printers
, p
);
1269 if (p
->type
& CUPS_PRINTER_IMPLICIT
)
1270 cupsArrayRemove(ImplicitPrinters
, p
);
1273 * Rename the printer type...
1276 mimeDeleteType(MimeDatabase
, p
->filetype
);
1277 p
->filetype
= mimeAddType(MimeDatabase
, "printer", name
);
1279 mimeDeleteType(MimeDatabase
, p
->prefiltertype
);
1280 p
->prefiltertype
= mimeAddType(MimeDatabase
, "prefilter", name
);
1283 * Rename the printer...
1286 cupsdSetString(&p
->name
, name
);
1289 * Reset printer attributes...
1292 cupsdSetPrinterAttrs(p
);
1295 * Add the printer back to the printer array(s)...
1298 cupsArrayAdd(Printers
, p
);
1300 if (p
->type
& CUPS_PRINTER_IMPLICIT
)
1301 cupsArrayAdd(ImplicitPrinters
, p
);
1306 * 'cupsdSaveAllPrinters()' - Save all printer definitions to the printers.conf
1311 cupsdSaveAllPrinters(void)
1313 int i
; /* Looping var */
1314 cups_file_t
*fp
; /* printers.conf file */
1315 char temp
[1024]; /* Temporary string */
1316 char backup
[1024]; /* printers.conf.O file */
1317 cupsd_printer_t
*printer
; /* Current printer class */
1318 time_t curtime
; /* Current time */
1319 struct tm
*curdate
; /* Current date */
1320 cups_option_t
*option
; /* Current option */
1321 const char *ptr
; /* Pointer into info/location */
1325 * Create the printers.conf file...
1328 snprintf(temp
, sizeof(temp
), "%s/printers.conf", ServerRoot
);
1329 snprintf(backup
, sizeof(backup
), "%s/printers.conf.O", ServerRoot
);
1331 if (rename(temp
, backup
))
1333 if (errno
!= ENOENT
)
1334 cupsdLogMessage(CUPSD_LOG_ERROR
,
1335 "Unable to backup printers.conf - %s", strerror(errno
));
1338 if ((fp
= cupsFileOpen(temp
, "w")) == NULL
)
1340 cupsdLogMessage(CUPSD_LOG_ERROR
,
1341 "Unable to save printers.conf - %s", strerror(errno
));
1343 if (rename(backup
, temp
))
1344 cupsdLogMessage(CUPSD_LOG_ERROR
,
1345 "Unable to restore printers.conf - %s", strerror(errno
));
1349 cupsdLogMessage(CUPSD_LOG_INFO
, "Saving printers.conf...");
1352 * Restrict access to the file...
1355 fchown(cupsFileNumber(fp
), getuid(), Group
);
1356 fchmod(cupsFileNumber(fp
), 0600);
1359 * Write a small header to the file...
1362 curtime
= time(NULL
);
1363 curdate
= localtime(&curtime
);
1364 strftime(temp
, sizeof(temp
) - 1, "%Y-%m-%d %H:%M", curdate
);
1366 cupsFilePuts(fp
, "# Printer configuration file for " CUPS_SVERSION
"\n");
1367 cupsFilePrintf(fp
, "# Written by cupsd on %s\n", temp
);
1370 * Write each local printer known to the system...
1373 for (printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
1375 printer
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
1378 * Skip remote destinations and printer classes...
1381 if ((printer
->type
& CUPS_PRINTER_DISCOVERED
) ||
1382 (printer
->type
& CUPS_PRINTER_CLASS
) ||
1383 (printer
->type
& CUPS_PRINTER_IMPLICIT
))
1387 * Write printers as needed...
1390 if (printer
== DefaultPrinter
)
1391 cupsFilePrintf(fp
, "<DefaultPrinter %s>\n", printer
->name
);
1393 cupsFilePrintf(fp
, "<Printer %s>\n", printer
->name
);
1395 if (printer
->num_auth_info_required
> 0)
1397 cupsFilePrintf(fp
, "AuthInfoRequired %s", printer
->auth_info_required
[0]);
1398 for (i
= 1; i
< printer
->num_auth_info_required
; i
++)
1399 cupsFilePrintf(fp
, ",%s", printer
->auth_info_required
[i
]);
1400 cupsFilePutChar(fp
, '\n');
1405 if ((ptr
= strchr(printer
->info
, '#')) != NULL
)
1408 * Need to quote the first # in the info string...
1411 cupsFilePuts(fp
, "Info ");
1412 cupsFileWrite(fp
, printer
->info
, ptr
- printer
->info
);
1413 cupsFilePutChar(fp
, '\\');
1414 cupsFilePuts(fp
, ptr
);
1415 cupsFilePutChar(fp
, '\n');
1418 cupsFilePrintf(fp
, "Info %s\n", printer
->info
);
1421 if (printer
->location
)
1423 if ((ptr
= strchr(printer
->info
, '#')) != NULL
)
1426 * Need to quote the first # in the location string...
1429 cupsFilePuts(fp
, "Location ");
1430 cupsFileWrite(fp
, printer
->location
, ptr
- printer
->location
);
1431 cupsFilePutChar(fp
, '\\');
1432 cupsFilePuts(fp
, ptr
);
1433 cupsFilePutChar(fp
, '\n');
1436 cupsFilePrintf(fp
, "Location %s\n", printer
->location
);
1438 if (printer
->device_uri
)
1439 cupsFilePrintf(fp
, "DeviceURI %s\n", printer
->device_uri
);
1441 if (printer
->port_monitor
)
1442 cupsFilePrintf(fp
, "PortMonitor %s\n", printer
->port_monitor
);
1444 if (printer
->state
== IPP_PRINTER_STOPPED
)
1446 cupsFilePuts(fp
, "State Stopped\n");
1447 cupsFilePrintf(fp
, "StateMessage %s\n", printer
->state_message
);
1450 cupsFilePuts(fp
, "State Idle\n");
1452 cupsFilePrintf(fp
, "StateTime %d\n", (int)printer
->state_time
);
1454 if (printer
->accepting
)
1455 cupsFilePuts(fp
, "Accepting Yes\n");
1457 cupsFilePuts(fp
, "Accepting No\n");
1459 if (printer
->shared
)
1460 cupsFilePuts(fp
, "Shared Yes\n");
1462 cupsFilePuts(fp
, "Shared No\n");
1464 cupsFilePrintf(fp
, "JobSheets %s %s\n", printer
->job_sheets
[0],
1465 printer
->job_sheets
[1]);
1467 cupsFilePrintf(fp
, "QuotaPeriod %d\n", printer
->quota_period
);
1468 cupsFilePrintf(fp
, "PageLimit %d\n", printer
->page_limit
);
1469 cupsFilePrintf(fp
, "KLimit %d\n", printer
->k_limit
);
1471 for (i
= 0; i
< printer
->num_users
; i
++)
1472 cupsFilePrintf(fp
, "%sUser %s\n", printer
->deny_users
? "Deny" : "Allow",
1475 if (printer
->op_policy
)
1476 cupsFilePrintf(fp
, "OpPolicy %s\n", printer
->op_policy
);
1477 if (printer
->error_policy
)
1478 cupsFilePrintf(fp
, "ErrorPolicy %s\n", printer
->error_policy
);
1480 for (i
= printer
->num_options
, option
= printer
->options
;
1483 cupsFilePrintf(fp
, "Option %s %s\n", option
->name
, option
->value
);
1485 cupsFilePuts(fp
, "</Printer>\n");
1489 * Make IRIX desktop & printer status happy
1492 write_irix_state(printer
);
1501 * 'cupsdSetAuthInfoRequired()' - Set the required authentication info.
1504 int /* O - 1 if value OK, 0 otherwise */
1505 cupsdSetAuthInfoRequired(
1506 cupsd_printer_t
*p
, /* I - Printer */
1507 const char *values
, /* I - Plain text value (or NULL) */
1508 ipp_attribute_t
*attr
) /* I - IPP attribute value (or NULL) */
1510 int i
; /* Looping var */
1513 p
->num_auth_info_required
= 0;
1516 * Do we have a plain text value?
1522 * Yes, grab the keywords...
1525 const char *end
; /* End of current value */
1528 while (*values
&& p
->num_auth_info_required
< 4)
1530 if ((end
= strchr(values
, ',')) == NULL
)
1531 end
= values
+ strlen(values
);
1533 if ((end
- values
) == 4 && !strncmp(values
, "none", 4))
1535 if (p
->num_auth_info_required
!= 0 || *end
)
1538 p
->auth_info_required
[p
->num_auth_info_required
] = "none";
1539 p
->num_auth_info_required
++;
1543 else if ((end
- values
) == 9 && !strncmp(values
, "negotiate", 9))
1545 if (p
->num_auth_info_required
!= 0 || *end
)
1548 p
->auth_info_required
[p
->num_auth_info_required
] = "negotiate";
1549 p
->num_auth_info_required
++;
1551 else if ((end
- values
) == 6 && !strncmp(values
, "domain", 6))
1553 p
->auth_info_required
[p
->num_auth_info_required
] = "domain";
1554 p
->num_auth_info_required
++;
1556 else if ((end
- values
) == 8 && !strncmp(values
, "password", 8))
1558 p
->auth_info_required
[p
->num_auth_info_required
] = "password";
1559 p
->num_auth_info_required
++;
1561 else if ((end
- values
) == 8 && !strncmp(values
, "username", 8))
1563 p
->auth_info_required
[p
->num_auth_info_required
] = "username";
1564 p
->num_auth_info_required
++;
1569 values
= (*end
) ? end
+ 1 : end
;
1572 if (p
->num_auth_info_required
== 0)
1574 p
->auth_info_required
[0] = "none";
1575 p
->num_auth_info_required
= 1;
1579 * Update the printer-type value as needed...
1582 if (p
->num_auth_info_required
> 1 ||
1583 strcmp(p
->auth_info_required
[0], "none"))
1584 p
->type
|= CUPS_PRINTER_AUTHENTICATED
;
1586 p
->type
&= ~CUPS_PRINTER_AUTHENTICATED
;
1592 * Grab values from an attribute instead...
1595 if (!attr
|| attr
->num_values
> 4)
1599 * Update the printer-type value as needed...
1602 if (attr
->num_values
> 1 ||
1603 strcmp(attr
->values
[0].string
.text
, "none"))
1604 p
->type
|= CUPS_PRINTER_AUTHENTICATED
;
1606 p
->type
&= ~CUPS_PRINTER_AUTHENTICATED
;
1608 for (i
= 0; i
< attr
->num_values
; i
++)
1610 if (!strcmp(attr
->values
[i
].string
.text
, "none"))
1612 if (p
->num_auth_info_required
!= 0 || attr
->num_values
!= 1)
1615 p
->auth_info_required
[p
->num_auth_info_required
] = "none";
1616 p
->num_auth_info_required
++;
1620 else if (!strcmp(attr
->values
[i
].string
.text
, "negotiate"))
1622 if (p
->num_auth_info_required
!= 0 || attr
->num_values
!= 1)
1625 p
->auth_info_required
[p
->num_auth_info_required
] = "negotiate";
1626 p
->num_auth_info_required
++;
1630 else if (!strcmp(attr
->values
[i
].string
.text
, "domain"))
1632 p
->auth_info_required
[p
->num_auth_info_required
] = "domain";
1633 p
->num_auth_info_required
++;
1635 else if (!strcmp(attr
->values
[i
].string
.text
, "password"))
1637 p
->auth_info_required
[p
->num_auth_info_required
] = "password";
1638 p
->num_auth_info_required
++;
1640 else if (!strcmp(attr
->values
[i
].string
.text
, "username"))
1642 p
->auth_info_required
[p
->num_auth_info_required
] = "username";
1643 p
->num_auth_info_required
++;
1654 * 'cupsdSetPrinterAttrs()' - Set printer attributes based upon the PPD file.
1658 cupsdSetPrinterAttrs(cupsd_printer_t
*p
)/* I - Printer to setup */
1660 int i
, /* Looping var */
1661 length
; /* Length of browse attributes */
1662 char uri
[HTTP_MAX_URI
]; /* URI for printer */
1663 char resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
1664 char filename
[1024]; /* Name of PPD file */
1665 int num_air
; /* Number of auth-info-required values */
1666 const char * const *air
; /* auth-info-required values */
1667 int num_media
; /* Number of media options */
1668 cupsd_location_t
*auth
; /* Pointer to authentication element */
1669 const char *auth_supported
; /* Authentication supported */
1670 ppd_file_t
*ppd
; /* PPD file data */
1671 ppd_option_t
*input_slot
, /* InputSlot options */
1672 *media_type
, /* MediaType options */
1673 *page_size
, /* PageSize options */
1674 *output_bin
, /* OutputBin options */
1675 *media_quality
, /* EFMediaQualityMode options */
1676 *duplex
; /* Duplex options */
1677 ppd_attr_t
*ppdattr
; /* PPD attribute */
1678 ipp_attribute_t
*attr
; /* Attribute data */
1679 ipp_value_t
*val
; /* Attribute value */
1680 int num_finishings
; /* Number of finishings */
1681 int finishings
[5]; /* finishings-supported values */
1682 cups_option_t
*option
; /* Current printer option */
1683 static const char * const sides
[3] = /* sides-supported values */
1686 "two-sided-long-edge",
1687 "two-sided-short-edge"
1689 static const char * const air_userpass
[] =
1690 { /* Basic/Digest authentication */
1694 static const char * const air_negotiate
[] =
1695 { /* Kerberos authentication */
1698 static const char * const air_none
[] =
1699 { /* No authentication */
1704 DEBUG_printf(("cupsdSetPrinterAttrs: entering name = %s, type = %x\n", p
->name
,
1708 * Make sure that we have the common attributes defined...
1712 cupsdCreateCommonData();
1715 * Clear out old filters, if any...
1718 delete_printer_filters(p
);
1721 * Figure out the authentication that is required for the printer.
1724 auth_supported
= "requesting-user-name";
1728 if (p
->num_auth_info_required
> 0 && strcmp(p
->auth_info_required
[0], "none"))
1730 num_air
= p
->num_auth_info_required
;
1731 air
= p
->auth_info_required
;
1733 if (!strcmp(air
[0], "username"))
1734 auth_supported
= "basic";
1736 auth_supported
= "negotiate";
1738 else if (!(p
->type
& CUPS_PRINTER_DISCOVERED
))
1740 if (p
->type
& CUPS_PRINTER_CLASS
)
1741 snprintf(resource
, sizeof(resource
), "/classes/%s", p
->name
);
1743 snprintf(resource
, sizeof(resource
), "/printers/%s", p
->name
);
1745 if ((auth
= cupsdFindBest(resource
, HTTP_POST
)) == NULL
||
1746 auth
->type
== AUTH_NONE
)
1747 auth
= cupsdFindPolicyOp(p
->op_policy_ptr
, IPP_PRINT_JOB
);
1751 if (auth
->type
== AUTH_BASIC
|| auth
->type
== AUTH_BASICDIGEST
)
1753 auth_supported
= "basic";
1757 else if (auth
->type
== AUTH_DIGEST
)
1759 auth_supported
= "digest";
1764 else if (auth
->type
== AUTH_NEGOTIATE
)
1766 auth_supported
= "negotiate";
1768 air
= air_negotiate
;
1770 #endif /* HAVE_GSSAPI */
1772 if (auth
->type
!= AUTH_NONE
)
1773 p
->type
|= CUPS_PRINTER_AUTHENTICATED
;
1775 p
->type
&= ~CUPS_PRINTER_AUTHENTICATED
;
1778 p
->type
&= ~CUPS_PRINTER_AUTHENTICATED
;
1780 else if (p
->type
& CUPS_PRINTER_AUTHENTICATED
)
1787 * Create the required IPP attributes for a printer...
1791 ippDelete(p
->attrs
);
1793 p
->attrs
= ippNew();
1795 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
1796 "uri-authentication-supported", NULL
, auth_supported
);
1797 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
1798 "uri-security-supported", NULL
, "none");
1799 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
, "printer-name", NULL
,
1801 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-location",
1802 NULL
, p
->location
? p
->location
: "");
1803 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-info",
1804 NULL
, p
->info
? p
->info
: "");
1805 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "printer-more-info",
1811 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
1812 "requesting-user-name-denied", p
->num_users
, NULL
,
1815 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
1816 "requesting-user-name-allowed", p
->num_users
, NULL
,
1820 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
1821 "job-quota-period", p
->quota_period
);
1822 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
1823 "job-k-limit", p
->k_limit
);
1824 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
1825 "job-page-limit", p
->page_limit
);
1826 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
1827 "auth-info-required", num_air
, NULL
, air
);
1829 if (cupsArrayCount(Banners
) > 0 && !(p
->type
& CUPS_PRINTER_DISCOVERED
))
1832 * Setup the job-sheets-default attribute...
1835 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
1836 "job-sheets-default", 2, NULL
, NULL
);
1840 attr
->values
[0].string
.text
= _cupsStrAlloc(Classification
?
1841 Classification
: p
->job_sheets
[0]);
1842 attr
->values
[1].string
.text
= _cupsStrAlloc(Classification
?
1843 Classification
: p
->job_sheets
[1]);
1850 if (p
->type
& CUPS_PRINTER_DISCOVERED
)
1853 * Tell the client this is a remote printer of some type...
1856 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
1857 "printer-uri-supported", NULL
, p
->uri
);
1860 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
1861 "printer-make-and-model", NULL
, p
->make_model
);
1863 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "device-uri", NULL
,
1872 * Assign additional attributes depending on whether this is a printer
1876 p
->type
&= ~CUPS_PRINTER_OPTIONS
;
1878 if (p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
))
1883 * Add class-specific attributes...
1886 if ((p
->type
& CUPS_PRINTER_IMPLICIT
) && p
->num_printers
> 0 &&
1887 p
->printers
[0]->make_model
)
1888 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
1889 "printer-make-and-model", NULL
, p
->printers
[0]->make_model
);
1891 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
1892 "printer-make-and-model", NULL
, "Local Printer Class");
1894 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "device-uri", NULL
,
1895 "file:///dev/null");
1897 if (p
->num_printers
> 0)
1900 * Add a list of member URIs and names...
1903 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
1904 "member-uris", p
->num_printers
, NULL
, NULL
);
1905 p
->type
|= CUPS_PRINTER_OPTIONS
;
1907 for (i
= 0; i
< p
->num_printers
; i
++)
1910 attr
->values
[i
].string
.text
= _cupsStrAlloc(p
->printers
[i
]->uri
);
1912 p
->type
&= ~CUPS_PRINTER_OPTIONS
| p
->printers
[i
]->type
;
1915 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
1916 "member-names", p
->num_printers
, NULL
, NULL
);
1920 for (i
= 0; i
< p
->num_printers
; i
++)
1921 attr
->values
[i
].string
.text
= _cupsStrAlloc(p
->printers
[i
]->name
);
1928 * Add printer-specific attributes... Start by sanitizing the device
1929 * URI so it doesn't have a username or password in it...
1933 strcpy(uri
, "file:/dev/null");
1934 else if (strstr(p
->device_uri
, "://") != NULL
)
1937 * http://..., ipp://..., etc.
1940 cupsdSanitizeURI(p
->device_uri
, uri
, sizeof(uri
));
1945 * file:..., serial:..., etc.
1948 strlcpy(uri
, p
->device_uri
, sizeof(uri
));
1951 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "device-uri", NULL
,
1955 * Assign additional attributes from the PPD file (if any)...
1958 p
->type
|= CUPS_PRINTER_BW
;
1959 finishings
[0] = IPP_FINISHINGS_NONE
;
1962 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
1965 if ((ppd
= ppdOpenFile(filename
)) != NULL
)
1968 * Add make/model and other various attributes...
1971 if (ppd
->color_device
)
1972 p
->type
|= CUPS_PRINTER_COLOR
;
1973 if (ppd
->variable_sizes
)
1974 p
->type
|= CUPS_PRINTER_VARIABLE
;
1975 if (!ppd
->manual_copies
)
1976 p
->type
|= CUPS_PRINTER_COPIES
;
1977 if ((ppdattr
= ppdFindAttr(ppd
, "cupsFax", NULL
)) != NULL
)
1978 if (ppdattr
->value
&& !strcasecmp(ppdattr
->value
, "true"))
1979 p
->type
|= CUPS_PRINTER_FAX
;
1981 ippAddBoolean(p
->attrs
, IPP_TAG_PRINTER
, "color-supported",
1983 if (ppd
->throughput
)
1984 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
1985 "pages-per-minute", ppd
->throughput
);
1990 * The NickName can be localized in the character set specified
1991 * by the LanugageEncoding attribute. However, ppdOpen2() has
1992 * already converted the ppd->nickname member to UTF-8 for us
1993 * (the original attribute value is available separately)
1996 cupsdSetString(&p
->make_model
, ppd
->nickname
);
1998 else if (ppd
->modelname
)
2001 * Model name can only contain specific characters...
2004 cupsdSetString(&p
->make_model
, ppd
->modelname
);
2007 cupsdSetString(&p
->make_model
, "Bad PPD File");
2009 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
2010 "printer-make-and-model", NULL
, p
->make_model
);
2013 * Add media options from the PPD file...
2016 if ((input_slot
= ppdFindOption(ppd
, "InputSlot")) != NULL
)
2017 num_media
= input_slot
->num_choices
;
2021 if ((media_type
= ppdFindOption(ppd
, "MediaType")) != NULL
)
2022 num_media
+= media_type
->num_choices
;
2024 if ((page_size
= ppdFindOption(ppd
, "PageSize")) != NULL
)
2025 num_media
+= page_size
->num_choices
;
2027 if ((media_quality
= ppdFindOption(ppd
, "EFMediaQualityMode")) != NULL
)
2028 num_media
+= media_quality
->num_choices
;
2032 cupsdLogMessage(CUPSD_LOG_CRIT
,
2033 "The PPD file for printer %s contains no media "
2034 "options and is therefore invalid!", p
->name
);
2038 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2039 "media-supported", num_media
, NULL
, NULL
);
2044 if (input_slot
!= NULL
)
2045 for (i
= 0; i
< input_slot
->num_choices
; i
++, val
++)
2046 val
->string
.text
= _cupsStrAlloc(input_slot
->choices
[i
].choice
);
2048 if (media_type
!= NULL
)
2049 for (i
= 0; i
< media_type
->num_choices
; i
++, val
++)
2050 val
->string
.text
= _cupsStrAlloc(media_type
->choices
[i
].choice
);
2052 if (media_quality
!= NULL
)
2053 for (i
= 0; i
< media_quality
->num_choices
; i
++, val
++)
2054 val
->string
.text
= _cupsStrAlloc(media_quality
->choices
[i
].choice
);
2056 if (page_size
!= NULL
)
2058 for (i
= 0; i
< page_size
->num_choices
; i
++, val
++)
2059 val
->string
.text
= _cupsStrAlloc(page_size
->choices
[i
].choice
);
2061 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2062 "media-default", NULL
, page_size
->defchoice
);
2064 else if (input_slot
!= NULL
)
2065 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2066 "media-default", NULL
, input_slot
->defchoice
);
2067 else if (media_type
!= NULL
)
2068 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2069 "media-default", NULL
, media_type
->defchoice
);
2070 else if (media_quality
!= NULL
)
2071 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2072 "media-default", NULL
, media_quality
->defchoice
);
2074 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2075 "media-default", NULL
, "none");
2083 if ((output_bin
= ppdFindOption(ppd
, "OutputBin")) != NULL
)
2085 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2086 "output-bin-supported", output_bin
->num_choices
,
2091 for (i
= 0, val
= attr
->values
;
2092 i
< output_bin
->num_choices
;
2094 val
->string
.text
= _cupsStrAlloc(output_bin
->choices
[i
].choice
);
2102 if ((duplex
= ppdFindOption(ppd
, "Duplex")) == NULL
)
2103 if ((duplex
= ppdFindOption(ppd
, "EFDuplex")) == NULL
)
2104 if ((duplex
= ppdFindOption(ppd
, "EFDuplexing")) == NULL
)
2105 if ((duplex
= ppdFindOption(ppd
, "KD03Duplex")) == NULL
)
2106 duplex
= ppdFindOption(ppd
, "JCLDuplex");
2108 if (duplex
&& duplex
->num_choices
> 1)
2110 p
->type
|= CUPS_PRINTER_DUPLEX
;
2112 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2113 "sides-supported", 3, NULL
, sides
);
2115 if (!strcasecmp(duplex
->defchoice
, "DuplexTumble"))
2116 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2117 "sides-default", NULL
, "two-sided-short-edge");
2118 else if (!strcasecmp(duplex
->defchoice
, "DuplexNoTumble"))
2119 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2120 "sides-default", NULL
, "two-sided-long-edge");
2122 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2123 "sides-default", NULL
, "one-sided");
2126 if (ppdFindOption(ppd
, "Collate") != NULL
)
2127 p
->type
|= CUPS_PRINTER_COLLATE
;
2129 if (ppdFindOption(ppd
, "StapleLocation") != NULL
)
2131 p
->type
|= CUPS_PRINTER_STAPLE
;
2132 finishings
[num_finishings
++] = IPP_FINISHINGS_STAPLE
;
2135 if (ppdFindOption(ppd
, "BindEdge") != NULL
)
2137 p
->type
|= CUPS_PRINTER_BIND
;
2138 finishings
[num_finishings
++] = IPP_FINISHINGS_BIND
;
2141 for (i
= 0; i
< ppd
->num_sizes
; i
++)
2142 if (ppd
->sizes
[i
].length
> 1728)
2143 p
->type
|= CUPS_PRINTER_LARGE
;
2144 else if (ppd
->sizes
[i
].length
> 1008)
2145 p
->type
|= CUPS_PRINTER_MEDIUM
;
2147 p
->type
|= CUPS_PRINTER_SMALL
;
2150 * Add a filter from application/vnd.cups-raw to printer/name to
2151 * handle "raw" printing by users.
2154 add_printer_filter(p
, p
->filetype
, "application/vnd.cups-raw 0 -");
2157 * Add any pre-filters in the PPD file...
2160 if ((ppdattr
= ppdFindAttr(ppd
, "cupsPreFilter", NULL
)) != NULL
)
2162 p
->prefiltertype
= mimeAddType(MimeDatabase
, "prefilter", p
->name
);
2164 for (; ppdattr
; ppdattr
= ppdFindNextAttr(ppd
, "cupsPreFilter", NULL
))
2166 add_printer_filter(p
, p
->prefiltertype
, ppdattr
->value
);
2170 * Add any filters in the PPD file...
2173 DEBUG_printf(("ppd->num_filters = %d\n", ppd
->num_filters
));
2174 for (i
= 0; i
< ppd
->num_filters
; i
++)
2176 DEBUG_printf(("ppd->filters[%d] = \"%s\"\n", i
, ppd
->filters
[i
]));
2177 add_printer_filter(p
, p
->filetype
, ppd
->filters
[i
]);
2180 if (ppd
->num_filters
== 0)
2183 * If there are no filters, add a PostScript printing filter.
2186 add_printer_filter(p
, p
->filetype
,
2187 "application/vnd.cups-postscript 0 -");
2191 * Show current and available port monitors for this printer...
2194 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
, "port-monitor",
2195 NULL
, p
->port_monitor
? p
->port_monitor
: "none");
2197 for (i
= 1, ppdattr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
2199 i
++, ppdattr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
));
2203 if (strstr(ppd
->protocols
, "TBCP"))
2205 else if (strstr(ppd
->protocols
, "BCP"))
2209 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2210 "port-monitor-supported", i
, NULL
, NULL
);
2212 attr
->values
[0].string
.text
= _cupsStrAlloc("none");
2214 for (i
= 1, ppdattr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
2216 i
++, ppdattr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
))
2217 attr
->values
[i
].string
.text
= _cupsStrAlloc(ppdattr
->value
);
2221 if (strstr(ppd
->protocols
, "TBCP"))
2222 attr
->values
[i
].string
.text
= _cupsStrAlloc("tbcp");
2223 else if (strstr(ppd
->protocols
, "BCP"))
2224 attr
->values
[i
].string
.text
= _cupsStrAlloc("bcp");
2228 cupsdSetString(&p
->product
, ppd
->product
);
2229 #endif /* HAVE_DNSSD */
2231 if (ppdFindAttr(ppd
, "APRemoteQueueID", NULL
))
2232 p
->type
|= CUPS_PRINTER_REMOTE
;
2235 * Close the PPD and set the type...
2240 else if (!access(filename
, 0))
2242 int pline
; /* PPD line number */
2243 ppd_status_t pstatus
; /* PPD load status */
2246 pstatus
= ppdLastError(&pline
);
2248 cupsdLogMessage(CUPSD_LOG_ERROR
, "PPD file for %s cannot be loaded!",
2251 if (pstatus
<= PPD_ALLOC_ERROR
)
2252 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s", strerror(errno
));
2254 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s on line %d.",
2255 ppdErrorString(pstatus
), pline
);
2257 cupsdLogMessage(CUPSD_LOG_INFO
,
2258 "Hint: Run \"cupstestppd %s\" and fix any errors.",
2262 * Add a filter from application/vnd.cups-raw to printer/name to
2263 * handle "raw" printing by users.
2266 add_printer_filter(p
, p
->filetype
, "application/vnd.cups-raw 0 -");
2269 * Add a PostScript filter, since this is still possibly PS printer.
2272 add_printer_filter(p
, p
->filetype
,
2273 "application/vnd.cups-postscript 0 -");
2278 * If we have an interface script, add a filter entry for it...
2281 snprintf(filename
, sizeof(filename
), "%s/interfaces/%s", ServerRoot
,
2283 if (!access(filename
, X_OK
))
2286 * Yes, we have a System V style interface script; use it!
2289 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
2290 "printer-make-and-model", NULL
,
2291 "Local System V Printer");
2293 snprintf(filename
, sizeof(filename
), "*/* 0 %s/interfaces/%s",
2294 ServerRoot
, p
->name
);
2295 add_printer_filter(p
, p
->filetype
, filename
);
2297 else if (p
->device_uri
&&
2298 !strncmp(p
->device_uri
, "ipp://", 6) &&
2299 (strstr(p
->device_uri
, "/printers/") != NULL
||
2300 strstr(p
->device_uri
, "/classes/") != NULL
))
2303 * Tell the client this is really a hard-wired remote printer.
2306 p
->type
|= CUPS_PRINTER_REMOTE
;
2309 * Point the printer-uri-supported attribute to the
2313 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
2314 "printer-uri-supported", NULL
, p
->device_uri
);
2317 * Then set the make-and-model accordingly...
2320 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
2321 "printer-make-and-model", NULL
, "Remote Printer");
2324 * Print all files directly...
2333 * Otherwise we have neither - treat this as a "dumb" printer
2334 * with no PPD file...
2337 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
2338 "printer-make-and-model", NULL
, "Local Raw Printer");
2344 ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
2345 "finishings-supported", num_finishings
, finishings
);
2346 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
2347 "finishings-default", IPP_FINISHINGS_NONE
);
2352 * Force sharing off for remote queues...
2355 if (p
->type
& (CUPS_PRINTER_REMOTE
| CUPS_PRINTER_IMPLICIT
))
2360 * Copy the printer options into a browse attributes string we can re-use.
2363 const char *valptr
; /* Pointer into value */
2364 char *attrptr
; /* Pointer into attribute string */
2368 * Free the old browse attributes as needed...
2371 if (p
->browse_attrs
)
2372 free(p
->browse_attrs
);
2375 * Compute the length of all attributes + job-sheets, lease-duration,
2376 * and BrowseLocalOptions.
2379 for (length
= 1, i
= p
->num_options
, option
= p
->options
;
2383 length
+= strlen(option
->name
) + 2;
2387 for (valptr
= option
->value
; *valptr
; valptr
++)
2388 if (strchr(" \"\'\\", *valptr
))
2395 length
+= 13 + strlen(p
->job_sheets
[0]) + strlen(p
->job_sheets
[1]);
2397 if (BrowseLocalOptions
)
2398 length
+= 12 + strlen(BrowseLocalOptions
);
2400 if (p
->num_auth_info_required
> 0)
2402 length
+= 18; /* auth-info-required */
2404 for (i
= 0; i
< p
->num_auth_info_required
; i
++)
2405 length
+= strlen(p
->auth_info_required
[i
]) + 1;
2409 * Allocate the new string...
2412 if ((p
->browse_attrs
= calloc(1, length
)) == NULL
)
2413 cupsdLogMessage(CUPSD_LOG_ERROR
,
2414 "Unable to allocate %d bytes for browse data!",
2419 * Got the allocated string, now copy the options and attributes over...
2422 sprintf(p
->browse_attrs
, "job-sheets=%s,%s lease-duration=%d",
2423 p
->job_sheets
[0], p
->job_sheets
[1], BrowseTimeout
);
2424 attrptr
= p
->browse_attrs
+ strlen(p
->browse_attrs
);
2426 if (BrowseLocalOptions
)
2428 sprintf(attrptr
, " ipp-options=%s", BrowseLocalOptions
);
2429 attrptr
+= strlen(attrptr
);
2432 for (i
= p
->num_options
, option
= p
->options
;
2437 strcpy(attrptr
, option
->name
);
2438 attrptr
+= strlen(attrptr
);
2444 for (valptr
= option
->value
; *valptr
; valptr
++)
2446 if (strchr(" \"\'\\", *valptr
))
2449 *attrptr
++ = *valptr
;
2454 if (p
->num_auth_info_required
> 0)
2456 strcpy(attrptr
, "auth-info-required");
2459 for (i
= 0; i
< p
->num_auth_info_required
; i
++)
2461 *attrptr
++ = i
? ',' : '=';
2462 strcpy(attrptr
, p
->auth_info_required
[i
]);
2463 attrptr
+= strlen(attrptr
);
2472 * Populate the document-format-supported attribute...
2475 add_printer_formats(p
);
2477 DEBUG_printf(("cupsdSetPrinterAttrs: leaving name = %s, type = %x\n", p
->name
,
2481 * Add name-default attributes...
2484 add_printer_defaults(p
);
2488 * Write the IRIX printer config and status files...
2491 write_irix_config(p
);
2492 write_irix_state(p
);
2496 * Let the browse protocols reflect the change
2499 cupsdRegisterPrinter(p
);
2504 * 'cupsdSetPrinterReasons()' - Set/update the reasons strings.
2508 cupsdSetPrinterReasons(
2509 cupsd_printer_t
*p
, /* I - Printer */
2510 const char *s
) /* I - Reasons strings */
2512 int i
; /* Looping var */
2513 const char *sptr
; /* Pointer into reasons */
2514 char reason
[255], /* Reason string */
2515 *rptr
; /* Pointer into reason */
2518 if (s
[0] == '-' || s
[0] == '+')
2521 * Add/remove reasons...
2529 * Replace reasons...
2534 for (i
= 0; i
< p
->num_reasons
; i
++)
2535 free(p
->reasons
[i
]);
2540 if (!strcmp(s
, "none"))
2544 * Loop through all of the reasons...
2550 * Skip leading whitespace and commas...
2553 while (isspace(*sptr
& 255) || *sptr
== ',')
2556 for (rptr
= reason
; *sptr
&& !isspace(*sptr
& 255) && *sptr
!= ','; sptr
++)
2557 if (rptr
< (reason
+ sizeof(reason
) - 1))
2571 for (i
= 0; i
< p
->num_reasons
; i
++)
2572 if (!strcasecmp(reason
, p
->reasons
[i
]))
2575 * Found a match, so remove it...
2579 free(p
->reasons
[i
]);
2581 if (i
< p
->num_reasons
)
2582 memmove(p
->reasons
+ i
, p
->reasons
+ i
+ 1,
2583 (p
->num_reasons
- i
) * sizeof(char *));
2587 if (!strcmp(reason
, "paused") && p
->state
== IPP_PRINTER_STOPPED
)
2588 cupsdSetPrinterState(p
, IPP_PRINTER_IDLE
, 1);
2591 else if (p
->num_reasons
< (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
2597 for (i
= 0; i
< p
->num_reasons
; i
++)
2598 if (!strcasecmp(reason
, p
->reasons
[i
]))
2601 if (i
>= p
->num_reasons
)
2603 p
->reasons
[i
] = strdup(reason
);
2606 if (!strcmp(reason
, "paused") && p
->state
!= IPP_PRINTER_STOPPED
)
2607 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, 1);
2615 * 'cupsdSetPrinterState()' - Update the current state of a printer.
2619 cupsdSetPrinterState(
2620 cupsd_printer_t
*p
, /* I - Printer to change */
2621 ipp_pstate_t s
, /* I - New state */
2622 int update
) /* I - Update printers.conf? */
2624 ipp_pstate_t old_state
; /* Old printer state */
2628 * Can't set status of remote printers...
2631 if (p
->type
& CUPS_PRINTER_DISCOVERED
)
2635 * Set the new state...
2638 old_state
= p
->state
;
2643 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE_CHANGED
, p
, NULL
,
2644 "%s \"%s\" state changed.",
2645 (p
->type
& CUPS_PRINTER_CLASS
) ? "Class" : "Printer",
2649 * Let the browse code know this needs to be updated...
2653 p
->state_time
= time(NULL
);
2657 write_irix_state(p
);
2661 cupsdAddPrinterHistory(p
);
2664 * Let the browse protocols reflect the change...
2667 cupsdRegisterPrinter(p
);
2670 * Save the printer configuration if a printer goes from idle or processing
2671 * to stopped (or visa-versa)...
2674 if ((old_state
== IPP_PRINTER_STOPPED
) != (s
== IPP_PRINTER_STOPPED
) &&
2677 if (p
->type
& CUPS_PRINTER_CLASS
)
2678 cupsdSaveAllClasses();
2680 cupsdSaveAllPrinters();
2686 * 'cupsdStopPrinter()' - Stop a printer from printing any jobs...
2690 cupsdStopPrinter(cupsd_printer_t
*p
, /* I - Printer to stop */
2691 int update
)/* I - Update printers.conf? */
2693 cupsd_job_t
*job
; /* Active print job */
2697 * Set the printer state...
2700 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, update
);
2703 * See if we have a job printing on this printer...
2709 * Get pointer to job...
2712 job
= (cupsd_job_t
*)p
->job
;
2718 cupsdStopJob(job
, 0);
2721 * Reset the state to pending...
2724 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
2725 job
->state_value
= IPP_JOB_PENDING
;
2729 cupsdAddEvent(CUPSD_EVENT_JOB_STOPPED
, p
, job
,
2730 "Job stopped due to printer being paused");
2736 * 'cupsdUpdatePrinters()' - Update printers after a partial reload.
2740 cupsdUpdatePrinters(void)
2742 cupsd_printer_t
*p
; /* Current printer */
2746 * Loop through the printers and recreate the printer attributes
2747 * for any local printers since the policy and/or access control
2748 * stuff may have changed. Also, if browsing is disabled, remove
2749 * any remote printers...
2752 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
2754 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
2757 * Remove remote printers if we are no longer browsing...
2761 (p
->type
& (CUPS_PRINTER_IMPLICIT
| CUPS_PRINTER_DISCOVERED
)))
2763 if (p
->type
& CUPS_PRINTER_IMPLICIT
)
2764 cupsArrayRemove(ImplicitPrinters
, p
);
2766 cupsArraySave(Printers
);
2767 cupsdDeletePrinter(p
, 0);
2768 cupsArrayRestore(Printers
);
2773 * Update the operation policy pointer...
2776 if ((p
->op_policy_ptr
= cupsdFindPolicy(p
->op_policy
)) == NULL
)
2777 p
->op_policy_ptr
= DefaultPolicyPtr
;
2780 * Update printer attributes as needed...
2783 if (!(p
->type
& CUPS_PRINTER_DISCOVERED
))
2784 cupsdSetPrinterAttrs(p
);
2790 * 'cupsdValidateDest()' - Validate a printer/class destination.
2793 const char * /* O - Printer or class name */
2795 const char *uri
, /* I - Printer URI */
2796 cups_ptype_t
*dtype
, /* O - Type (printer or class) */
2797 cupsd_printer_t
**printer
) /* O - Printer pointer */
2799 cupsd_printer_t
*p
; /* Current printer */
2800 char localname
[1024],/* Localized hostname */
2801 *lptr
, /* Pointer into localized hostname */
2802 *sptr
, /* Pointer into server name */
2803 *rptr
, /* Pointer into resource */
2804 scheme
[32], /* Scheme portion of URI */
2805 username
[64], /* Username portion of URI */
2806 hostname
[HTTP_MAX_HOST
],
2807 /* Host portion of URI */
2808 resource
[HTTP_MAX_URI
];
2809 /* Resource portion of URI */
2810 int port
; /* Port portion of URI */
2813 DEBUG_printf(("cupsdValidateDest(uri=\"%s\", dtype=%p, printer=%p)\n", uri
,
2817 * Initialize return values...
2824 *dtype
= (cups_ptype_t
)0;
2827 * Pull the hostname and resource from the URI...
2830 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
, scheme
, sizeof(scheme
),
2831 username
, sizeof(username
), hostname
, sizeof(hostname
),
2832 &port
, resource
, sizeof(resource
));
2835 * See if the resource is a class or printer...
2838 if (!strncmp(resource
, "/classes/", 9))
2844 rptr
= resource
+ 9;
2846 else if (!strncmp(resource
, "/printers/", 10))
2852 rptr
= resource
+ 10;
2857 * Bad resource name...
2864 * See if the printer or class name exists...
2867 p
= cupsdFindDest(rptr
);
2869 if (p
== NULL
&& strchr(rptr
, '@') == NULL
)
2877 *dtype
= p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
|
2878 CUPS_PRINTER_REMOTE
| CUPS_PRINTER_DISCOVERED
);
2884 * Change localhost to the server name...
2887 if (!strcasecmp(hostname
, "localhost"))
2888 strlcpy(hostname
, ServerName
, sizeof(hostname
));
2890 strlcpy(localname
, hostname
, sizeof(localname
));
2892 if (!strcasecmp(hostname
, ServerName
))
2895 * Localize the hostname...
2898 lptr
= strchr(localname
, '.');
2899 sptr
= strchr(ServerName
, '.');
2901 if (sptr
!= NULL
&& lptr
!= NULL
)
2904 * Strip the common domain name components...
2907 while (lptr
!= NULL
)
2909 if (!strcasecmp(lptr
, sptr
))
2915 lptr
= strchr(lptr
+ 1, '.');
2920 DEBUG_printf(("localized hostname is \"%s\"...\n", localname
));
2923 * Find a matching printer or class...
2926 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
2928 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
2929 if (!strcasecmp(p
->hostname
, localname
) &&
2930 !strcasecmp(p
->name
, rptr
))
2936 *dtype
= p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
|
2937 CUPS_PRINTER_REMOTE
| CUPS_PRINTER_DISCOVERED
);
2947 * 'cupsdWritePrintcap()' - Write a pseudo-printcap file for older applications
2952 cupsdWritePrintcap(void)
2954 cups_file_t
*fp
; /* printcap file */
2955 cupsd_printer_t
*p
; /* Current printer */
2960 * Update the IRIX printer state for the default printer; if
2961 * no printers remain, then the default printer file will be
2965 write_irix_state(DefaultPrinter
);
2969 * See if we have a printcap file; if not, don't bother writing it.
2972 if (!Printcap
|| !*Printcap
)
2976 * Open the printcap file...
2979 if ((fp
= cupsFileOpen(Printcap
, "w")) == NULL
)
2983 * Put a comment header at the top so that users will know where the
2984 * data has come from...
2988 "# This file was automatically generated by cupsd(8) from the\n");
2989 cupsFilePrintf(fp
, "# %s/printers.conf file. All changes to this file\n",
2991 cupsFilePuts(fp
, "# will be lost.\n");
2996 * Write a new printcap with the current list of printers.
2999 switch (PrintcapFormat
)
3003 * Each printer is put in the file as:
3013 cupsFilePrintf(fp
, "%s|%s:rm=%s:rp=%s:\n", DefaultPrinter
->name
,
3014 DefaultPrinter
->info
, ServerName
,
3015 DefaultPrinter
->name
);
3017 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3019 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3020 if (p
!= DefaultPrinter
)
3021 cupsFilePrintf(fp
, "%s|%s:rm=%s:rp=%s:\n", p
->name
, p
->info
,
3022 ServerName
, p
->name
);
3025 case PRINTCAP_SOLARIS
:
3027 * Each printer is put in the file as:
3029 * _all:all=Printer1,Printer2,Printer3,...,PrinterN
3030 * _default:use=DefaultPrinter
3032 * :bsdaddr=ServerName,Printer1:\
3033 * :description=Description:
3035 * :bsdaddr=ServerName,Printer2:\
3036 * :description=Description:
3038 * :bsdaddr=ServerName,Printer3:\
3039 * :description=Description:
3042 * :bsdaddr=ServerName,PrinterN:\
3043 * :description=Description:
3046 cupsFilePuts(fp
, "_all:all=");
3047 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3049 p
= (cupsd_printer_t
*)cupsArrayCurrent(Printers
))
3050 cupsFilePrintf(fp
, "%s%c", p
->name
,
3051 cupsArrayNext(Printers
) ? ',' : '\n');
3054 cupsFilePrintf(fp
, "_default:use=%s\n", DefaultPrinter
->name
);
3056 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3058 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3059 cupsFilePrintf(fp
, "%s:\\\n"
3060 "\t:bsdaddr=%s,%s:\\\n"
3061 "\t:description=%s:\n",
3062 p
->name
, ServerName
, p
->name
,
3063 p
->info
? p
->info
: "");
3077 * 'cupsdSanitizeURI()' - Sanitize a device URI...
3080 char * /* O - New device URI */
3081 cupsdSanitizeURI(const char *uri
, /* I - Original device URI */
3082 char *buffer
, /* O - New device URI */
3083 int buflen
) /* I - Size of new device URI buffer */
3085 char *start
, /* Start of data after scheme */
3086 *slash
, /* First slash after scheme:// */
3087 *ptr
; /* Pointer into user@host:port part */
3091 * Range check input...
3094 if (!uri
|| !buffer
|| buflen
< 2)
3098 * Copy the device URI to the new buffer...
3101 strlcpy(buffer
, uri
, buflen
);
3104 * Find the end of the scheme:// part...
3107 if ((ptr
= strchr(buffer
, ':')) == NULL
)
3108 return (buffer
); /* No scheme: part... */
3110 for (start
= ptr
+ 1; *start
; start
++)
3115 * Find the next slash (/) in the URI...
3118 if ((slash
= strchr(start
, '/')) == NULL
)
3119 slash
= start
+ strlen(start
); /* No slash, point to the end */
3122 * Check for an @ sign before the slash...
3125 if ((ptr
= strchr(start
, '@')) != NULL
&& ptr
< slash
)
3128 * Found an @ sign and it is before the resource part, so we have
3129 * an authentication string. Copy the remaining URI over the
3130 * authentication string...
3133 _cups_strcpy(start
, ptr
+ 1);
3137 * Return the new device URI...
3145 * 'add_printer_defaults()' - Add name-default attributes to the printer attributes.
3149 add_printer_defaults(cupsd_printer_t
*p
)/* I - Printer */
3151 int i
; /* Looping var */
3152 int num_options
; /* Number of default options */
3153 cups_option_t
*options
, /* Default options */
3154 *option
; /* Current option */
3155 char name
[256]; /* name-default */
3159 * Maintain a common array of default attribute names...
3162 if (!CommonDefaults
)
3164 CommonDefaults
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
3166 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("copies-default"));
3167 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("document-format-default"));
3168 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("finishings-default"));
3169 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-hold-until-default"));
3170 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-priority-default"));
3171 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-sheets-default"));
3172 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("media-default"));
3173 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("number-up-default"));
3174 cupsArrayAdd(CommonDefaults
,
3175 _cupsStrAlloc("orientation-requested-default"));
3176 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("sides-default"));
3180 * Add all of the default options from the .conf files...
3183 for (num_options
= 0, i
= p
->num_options
, option
= p
->options
;
3187 if (strcmp(option
->name
, "ipp-options") &&
3188 strcmp(option
->name
, "job-sheets") &&
3189 strcmp(option
->name
, "lease-duration"))
3191 snprintf(name
, sizeof(name
), "%s-default", option
->name
);
3192 num_options
= cupsAddOption(name
, option
->value
, num_options
, &options
);
3194 if (!cupsArrayFind(CommonDefaults
, name
))
3195 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc(name
));
3200 * Convert options to IPP attributes...
3203 cupsEncodeOptions2(p
->attrs
, num_options
, options
, IPP_TAG_PRINTER
);
3204 cupsFreeOptions(num_options
, options
);
3207 * Add standard -default attributes as needed...
3210 if (!cupsGetOption("copies", p
->num_options
, p
->options
))
3211 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
, "copies-default",
3214 if (!cupsGetOption("document-format", p
->num_options
, p
->options
))
3215 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_MIMETYPE
,
3216 "document-format-default", NULL
, "application/octet-stream");
3218 if (!cupsGetOption("job-hold-until", p
->num_options
, p
->options
))
3219 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3220 "job-hold-until-default", NULL
, "no-hold");
3222 if (!cupsGetOption("job-priority", p
->num_options
, p
->options
))
3223 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3224 "job-priority-default", 50);
3226 if (!cupsGetOption("number-up", p
->num_options
, p
->options
))
3227 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3228 "number-up-default", 1);
3230 if (!cupsGetOption("orientation-requested", p
->num_options
, p
->options
))
3231 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NOVALUE
,
3232 "orientation-requested-default", NULL
, NULL
);
3234 if (!cupsGetOption("notify-lease-duration", p
->num_options
, p
->options
))
3235 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3236 "notify-lease-duration-default", DefaultLeaseDuration
);
3238 if (!cupsGetOption("notify-events", p
->num_options
, p
->options
))
3239 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3240 "notify-events-default", NULL
, "job-completed");
3245 * 'add_printer_filter()' - Add a MIME filter for a printer.
3250 cupsd_printer_t
*p
, /* I - Printer to add to */
3251 mime_type_t
*filtertype
, /* I - Filter or prefilter MIME type */
3252 const char *filter
) /* I - Filter to add */
3254 char super
[MIME_MAX_SUPER
], /* Super-type for filter */
3255 type
[MIME_MAX_TYPE
], /* Type for filter */
3256 program
[1024]; /* Program/filter name */
3257 int cost
; /* Cost of filter */
3258 mime_type_t
*temptype
; /* MIME type looping var */
3259 char filename
[1024]; /* Full filter filename */
3263 * Parse the filter string; it should be in the following format:
3265 * super/type cost program
3268 if (sscanf(filter
, "%15[^/]/%31s%d%1023s", super
, type
, &cost
, program
) != 4)
3270 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: invalid filter string \"%s\"!",
3276 * See if the filter program exists; if not, stop the printer and flag
3280 if (strcmp(program
, "-"))
3282 if (program
[0] == '/')
3283 strlcpy(filename
, program
, sizeof(filename
));
3285 snprintf(filename
, sizeof(filename
), "%s/filter/%s", ServerBin
, program
);
3287 if (access(filename
, X_OK
))
3289 snprintf(p
->state_message
, sizeof(p
->state_message
),
3290 "Filter \"%s\" for printer \"%s\" not available: %s",
3291 program
, p
->name
, strerror(errno
));
3292 cupsdSetPrinterReasons(p
, "+cups-missing-filter-error");
3293 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, 0);
3295 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s", p
->state_message
);
3300 * Mark the CUPS_PRINTER_COMMANDS bit if we have a filter for
3301 * application/vnd.cups-command...
3304 if (!strcasecmp(super
, "application") &&
3305 !strcasecmp(type
, "vnd.cups-command"))
3306 p
->type
|= CUPS_PRINTER_COMMANDS
;
3309 * Add the filter to the MIME database, supporting wildcards as needed...
3312 for (temptype
= mimeFirstType(MimeDatabase
);
3314 temptype
= mimeNextType(MimeDatabase
))
3315 if (((super
[0] == '*' && strcasecmp(temptype
->super
, "printer")) ||
3316 !strcasecmp(temptype
->super
, super
)) &&
3317 (type
[0] == '*' || !strcasecmp(temptype
->type
, type
)))
3319 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3320 "add_printer_filter: %s: adding filter %s/%s %s/%s %d %s",
3321 p
->name
, temptype
->super
, temptype
->type
,
3322 filtertype
->super
, filtertype
->type
,
3324 mimeAddFilter(MimeDatabase
, temptype
, filtertype
, cost
, program
);
3330 * 'add_printer_formats()' - Add document-format-supported values for a printer.
3334 add_printer_formats(cupsd_printer_t
*p
) /* I - Printer */
3336 int i
; /* Looping var */
3337 mime_type_t
*type
; /* Current MIME type */
3338 cups_array_t
*filters
; /* Filters */
3339 ipp_attribute_t
*attr
; /* document-format-supported attribute */
3340 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
3341 /* MIME type name */
3345 * Raw (and remote) queues advertise all of the supported MIME
3349 cupsArrayDelete(p
->filetypes
);
3350 p
->filetypes
= NULL
;
3354 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
,
3355 (ipp_tag_t
)(IPP_TAG_MIMETYPE
| IPP_TAG_COPY
),
3356 "document-format-supported", NumMimeTypes
, NULL
, MimeTypes
);
3361 * Otherwise, loop through the supported MIME types and see if there
3362 * are filters for them...
3365 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_printer_formats: %d types, %d filters",
3366 mimeNumTypes(MimeDatabase
), mimeNumFilters(MimeDatabase
));
3368 p
->filetypes
= cupsArrayNew(NULL
, NULL
);
3370 for (type
= mimeFirstType(MimeDatabase
);
3372 type
= mimeNextType(MimeDatabase
))
3374 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
3376 if ((filters
= mimeFilter(MimeDatabase
, type
, p
->filetype
, NULL
)) != NULL
)
3378 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3379 "add_printer_formats: %s: %s needs %d filters",
3380 p
->name
, mimetype
, cupsArrayCount(filters
));
3382 cupsArrayDelete(filters
);
3383 cupsArrayAdd(p
->filetypes
, type
);
3386 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3387 "add_printer_formats: %s: %s not supported",
3391 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3392 "add_printer_formats: %s: %d supported types",
3393 p
->name
, cupsArrayCount(p
->filetypes
) + 1);
3396 * Add the file formats that can be filtered...
3399 if ((type
= mimeType(MimeDatabase
, "application", "octet-stream")) == NULL
||
3400 !cupsArrayFind(p
->filetypes
, type
))
3405 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_MIMETYPE
,
3406 "document-format-supported",
3407 cupsArrayCount(p
->filetypes
) + 1, NULL
, NULL
);
3410 attr
->values
[0].string
.text
= _cupsStrAlloc("application/octet-stream");
3412 for (type
= (mime_type_t
*)cupsArrayFirst(p
->filetypes
);
3414 i
++, type
= (mime_type_t
*)cupsArrayNext(p
->filetypes
))
3416 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
3418 attr
->values
[i
].string
.text
= _cupsStrAlloc(mimetype
);
3423 char pdl
[1024]; /* Buffer to build pdl list */
3424 mime_filter_t
*filter
; /* MIME filter looping var */
3429 if (mimeType(MimeDatabase
, "application", "pdf"))
3430 strlcat(pdl
, "application/pdf,", sizeof(pdl
));
3432 if (mimeType(MimeDatabase
, "application", "postscript"))
3433 strlcat(pdl
, "application/postscript,", sizeof(pdl
));
3435 if (mimeType(MimeDatabase
, "application", "vnd.cups-raster"))
3436 strlcat(pdl
, "application/vnd.cups-raster,", sizeof(pdl
));
3439 * Determine if this is a Tioga PrintJobMgr based queue...
3442 for (filter
= (mime_filter_t
*)cupsArrayFirst(MimeDatabase
->filters
);
3444 filter
= (mime_filter_t
*)cupsArrayNext(MimeDatabase
->filters
))
3446 if (filter
->dst
== p
->filetype
&& filter
->filter
&&
3447 strstr(filter
->filter
, "PrintJobMgr"))
3452 * We only support raw printing if this is not a Tioga PrintJobMgr based
3453 * queue and if application/octet-stream is a known conversion...
3456 if (!filter
&& mimeType(MimeDatabase
, "application", "octet-stream"))
3457 strlcat(pdl
, "application/octet-stream,", sizeof(pdl
));
3459 if (mimeType(MimeDatabase
, "image", "png"))
3460 strlcat(pdl
, "image/png,", sizeof(pdl
));
3463 pdl
[strlen(pdl
) - 1] = '\0'; /* Remove trailing comma */
3465 cupsdSetString(&p
->pdl
, pdl
);
3467 #endif /* HAVE_DNSSD */
3472 * 'compare_printers()' - Compare two printers.
3475 static int /* O - Result of comparison */
3476 compare_printers(void *first
, /* I - First printer */
3477 void *second
, /* I - Second printer */
3478 void *data
) /* I - App data (not used) */
3480 return (strcasecmp(((cupsd_printer_t
*)first
)->name
,
3481 ((cupsd_printer_t
*)second
)->name
));
3486 * 'delete_printer_filters()' - Delete all MIME filters for a printer.
3490 delete_printer_filters(
3491 cupsd_printer_t
*p
) /* I - Printer to remove from */
3493 mime_filter_t
*filter
; /* MIME filter looping var */
3497 * Range check input...
3504 * Remove all filters from the MIME database that have a destination
3505 * type == printer...
3508 for (filter
= mimeFirstFilter(MimeDatabase
);
3510 filter
= mimeNextFilter(MimeDatabase
))
3511 if (filter
->dst
== p
->filetype
)
3514 * Delete the current filter...
3517 mimeDeleteFilter(MimeDatabase
, filter
);
3524 * 'write_irix_config()' - Update the config files used by the IRIX
3529 write_irix_config(cupsd_printer_t
*p
) /* I - Printer to update */
3531 char filename
[1024]; /* Interface script filename */
3532 cups_file_t
*fp
; /* Interface script file */
3533 ipp_attribute_t
*attr
; /* Attribute data */
3537 * Add dummy interface and GUI scripts to fool SGI's "challenged" printing
3538 * tools. First the interface script that tells the tools what kind of
3539 * printer we have...
3542 snprintf(filename
, sizeof(filename
), "/var/spool/lp/interface/%s", p
->name
);
3544 if (p
->type
& CUPS_PRINTER_CLASS
)
3546 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
3548 cupsFilePuts(fp
, "#!/bin/sh\n");
3550 if ((attr
= ippFindAttribute(p
->attrs
, "printer-make-and-model",
3551 IPP_TAG_TEXT
)) != NULL
)
3552 cupsFilePrintf(fp
, "NAME=\"%s\"\n", attr
->values
[0].string
.text
);
3553 else if (p
->type
& CUPS_PRINTER_CLASS
)
3554 cupsFilePuts(fp
, "NAME=\"Printer Class\"\n");
3556 cupsFilePuts(fp
, "NAME=\"Remote Destination\"\n");
3558 if (p
->type
& CUPS_PRINTER_COLOR
)
3559 cupsFilePuts(fp
, "TYPE=ColorPostScript\n");
3561 cupsFilePuts(fp
, "TYPE=MonoPostScript\n");
3563 cupsFilePrintf(fp
, "HOSTNAME=%s\n", ServerName
);
3564 cupsFilePrintf(fp
, "HOSTPRINTER=%s\n", p
->name
);
3568 chmod(filename
, 0755);
3569 chown(filename
, User
, Group
);
3573 * Then the member file that tells which device file the queue is connected
3574 * to... Networked printers use "/dev/null" in this file, so that's what
3575 * we use (the actual device URI can confuse some apps...)
3578 snprintf(filename
, sizeof(filename
), "/var/spool/lp/member/%s", p
->name
);
3580 if (p
->type
& CUPS_PRINTER_CLASS
)
3582 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
3584 cupsFilePuts(fp
, "/dev/null\n");
3588 chmod(filename
, 0644);
3589 chown(filename
, User
, Group
);
3593 * The gui_interface file is a script or program that launches a GUI
3594 * option panel for the printer, using options specified on the
3595 * command-line in the third argument. The option panel must send
3596 * any printing options to stdout on a single line when the user
3597 * accepts them, or nothing if the user cancels the dialog.
3599 * The default options panel program is /usr/bin/glpoptions, from
3600 * the ESP Print Pro software. You can select another using the
3601 * PrintcapGUI option.
3604 snprintf(filename
, sizeof(filename
), "/var/spool/lp/gui_interface/ELF/%s.gui", p
->name
);
3606 if (p
->type
& CUPS_PRINTER_CLASS
)
3608 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
3610 cupsFilePuts(fp
, "#!/bin/sh\n");
3611 cupsFilePrintf(fp
, "%s -d %s -o \"$3\"\n", PrintcapGUI
, p
->name
);
3615 chmod(filename
, 0755);
3616 chown(filename
, User
, Group
);
3620 * The POD config file is needed by the printstatus command to show
3621 * the printer location and device.
3624 snprintf(filename
, sizeof(filename
), "/var/spool/lp/pod/%s.config", p
->name
);
3626 if (p
->type
& CUPS_PRINTER_CLASS
)
3628 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
3630 cupsFilePrintf(fp
, "Printer Class | %s\n",
3631 (p
->type
& CUPS_PRINTER_COLOR
) ? "ColorPostScript" : "MonoPostScript");
3632 cupsFilePrintf(fp
, "Printer Model | %s\n", p
->make_model
? p
->make_model
: "");
3633 cupsFilePrintf(fp
, "Location Code | %s\n", p
->location
? p
->location
: "");
3634 cupsFilePrintf(fp
, "Physical Location | %s\n", p
->info
? p
->info
: "");
3635 cupsFilePrintf(fp
, "Port Path | %s\n", p
->device_uri
? p
->device_uri
: "");
3636 cupsFilePrintf(fp
, "Config Path | /var/spool/lp/pod/%s.config\n", p
->name
);
3637 cupsFilePrintf(fp
, "Active Status Path | /var/spool/lp/pod/%s.status\n", p
->name
);
3638 cupsFilePuts(fp
, "Status Update Wait | 10 seconds\n");
3642 chmod(filename
, 0664);
3643 chown(filename
, User
, Group
);
3649 * 'write_irix_state()' - Update the status files used by IRIX printing
3654 write_irix_state(cupsd_printer_t
*p
) /* I - Printer to update */
3656 char filename
[1024]; /* Interface script filename */
3657 cups_file_t
*fp
; /* Interface script file */
3658 int tag
; /* Status tag value */
3664 * The POD status file is needed for the printstatus window to
3665 * provide the current status of the printer.
3668 snprintf(filename
, sizeof(filename
), "/var/spool/lp/pod/%s.status", p
->name
);
3670 if (p
->type
& CUPS_PRINTER_CLASS
)
3672 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
3674 cupsFilePrintf(fp
, "Operational Status | %s\n",
3675 (p
->state
== IPP_PRINTER_IDLE
) ? "Idle" :
3676 (p
->state
== IPP_PRINTER_PROCESSING
) ? "Busy" :
3678 cupsFilePrintf(fp
, "Information | 01 00 00 | %s\n", CUPS_SVERSION
);
3679 cupsFilePrintf(fp
, "Information | 02 00 00 | Device URI: %s\n",
3680 p
->device_uri
? p
->device_uri
: "");
3681 cupsFilePrintf(fp
, "Information | 03 00 00 | %s jobs\n",
3682 p
->accepting
? "Accepting" : "Not accepting");
3683 cupsFilePrintf(fp
, "Information | 04 00 00 | %s\n", p
->state_message
);
3687 chmod(filename
, 0664);
3688 chown(filename
, User
, Group
);
3692 * The activeicons file is needed to provide desktop icons for printers:
3694 * [ quoted from /usr/lib/print/tagit ]
3696 * --- Type of printer tags (base values)
3698 * Dumb=66048 # 0x10200
3699 * DumbColor=66080 # 0x10220
3700 * Raster=66112 # 0x10240
3701 * ColorRaster=66144 # 0x10260
3702 * Plotter=66176 # 0x10280
3703 * PostScript=66208 # 0x102A0
3704 * ColorPostScript=66240 # 0x102C0
3705 * MonoPostScript=66272 # 0x102E0
3707 * --- Printer state modifiers for local printers
3712 * Unknown=3 # 0x3 (Faulted due to unknown reason)
3714 * --- Printer state modifiers for network printers
3718 * NetFaulted=10 # 0xA
3719 * NetUnknown=11 # 0xB (Faulted due to unknown reason)
3722 snprintf(filename
, sizeof(filename
), "/var/spool/lp/activeicons/%s", p
->name
);
3724 if (p
->type
& CUPS_PRINTER_CLASS
)
3726 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
3728 if (p
->type
& CUPS_PRINTER_COLOR
)
3733 if (p
->type
& CUPS_PRINTER_REMOTE
)
3736 if (p
->state
== IPP_PRINTER_PROCESSING
)
3739 else if (p
->state
== IPP_PRINTER_STOPPED
)
3742 cupsFilePuts(fp
, "#!/bin/sh\n");
3743 cupsFilePrintf(fp
, "#Tag %d\n", tag
);
3747 chmod(filename
, 0755);
3748 chown(filename
, User
, Group
);
3753 * The default file is needed by the printers window to show
3754 * the default printer.
3757 snprintf(filename
, sizeof(filename
), "/var/spool/lp/default");
3759 if (DefaultPrinter
!= NULL
)
3761 if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
3763 cupsFilePrintf(fp
, "%s\n", DefaultPrinter
->name
);
3767 chmod(filename
, 0644);
3768 chown(filename
, User
, Group
);
3778 * End of "$Id: printers.c 6970 2007-09-17 23:58:28Z mike $".