2 * "$Id: printers.c 6539 2007-05-23 15:08:29Z mike $"
4 * Printer routines for the Common UNIX Printing System (CUPS).
6 * Copyright 1997-2007 by Easy Software Products, all rights reserved.
8 * These coded instructions, statements, and computer programs are the
9 * property of Easy Software Products and are protected by Federal
10 * copyright law. Distribution and use rights are outlined in the file
11 * "LICENSE.txt" which should have been included with this file. If this
12 * file is missing or damaged please contact Easy Software Products
15 * Attn: CUPS Licensing Information
16 * Easy Software Products
17 * 44141 Airport View Drive, Suite 204
18 * Hollywood, Maryland 20636 USA
20 * Voice: (301) 373-9600
21 * EMail: cups-info@cups.org
22 * WWW: http://www.cups.org
26 * cupsdAddPrinter() - Add a printer to the system.
27 * cupsdAddPrinterHistory() - Add the current printer state to the history.
28 * cupsdAddPrinterUser() - Add a user to the ACL.
29 * cupsdCreateCommonData() - Create the common printer data.
30 * cupsdDeleteAllPrinters() - Delete all printers from the system.
31 * cupsdDeletePrinter() - Delete a printer from the system.
32 * cupsdFindPrinter() - Find a printer in the list.
33 * cupsdFreePrinterUsers() - Free allow/deny users.
34 * cupsdLoadAllPrinters() - Load printers from the printers.conf file.
35 * cupsdRenamePrinter() - Rename a printer.
36 * cupsdSaveAllPrinters() - Save all printer definitions to the
38 * cupsdSetPrinterAttrs() - Set printer attributes based upon the PPD
40 * cupsdSetPrinterReasons() - Set/update the reasons strings.
41 * cupsdSetPrinterState() - Update the current state of a printer.
42 * cupsdStopPrinter() - Stop a printer from printing any jobs...
43 * cupsdUpdatePrinters() - Update printers after a partial reload.
44 * cupsdValidateDest() - Validate a printer/class destination.
45 * cupsdWritePrintcap() - Write a pseudo-printcap file for older
46 * applications that need it...
47 * cupsdSanitizeURI() - Sanitize a device URI...
48 * add_printer_defaults() - Add name-default attributes to the printer
50 * add_printer_filter() - Add a MIME filter for a printer.
51 * add_printer_formats() - Add document-format-supported values for
53 * compare_printers() - Compare two printers.
54 * delete_printer_filters() - Delete all MIME filters for a printer.
55 * write_irix_config() - Update the config files used by the IRIX
57 * write_irix_state() - Update the status files used by IRIX
58 * printing desktop tools.
62 * Include necessary headers...
70 * Currently Bonjour printers that are shared by CUPS servers are added
71 * manually by the user on Mac OS X systems. While these printers *are*
72 * remote queues, the current print dialog will not show them if they
73 * (correctly) have the CUPS_PRINTER_REMOTE bit set. This may change
74 * in future releases, however the code to do this is currently disabled.
76 * Define BONJOUR_IS_REMOTE to 1 to get the correct behavior...
79 #define BONJOUR_IS_REMOTE 0
86 static void add_printer_defaults(cupsd_printer_t
*p
);
87 static void add_printer_filter(cupsd_printer_t
*p
, mime_type_t
*type
,
89 static void add_printer_formats(cupsd_printer_t
*p
);
90 static int compare_printers(void *first
, void *second
, void *data
);
91 static void delete_printer_filters(cupsd_printer_t
*p
);
93 static void write_irix_config(cupsd_printer_t
*p
);
94 static void write_irix_state(cupsd_printer_t
*p
);
99 * 'cupsdAddPrinter()' - Add a printer to the system.
102 cupsd_printer_t
* /* O - New printer */
103 cupsdAddPrinter(const char *name
) /* I - Name of printer */
105 cupsd_printer_t
*p
; /* New printer */
109 * Range check input...
112 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdAddPrinter(\"%s\")", name
);
115 * Create a new printer entity...
118 if ((p
= calloc(1, sizeof(cupsd_printer_t
))) == NULL
)
120 cupsdLogMessage(CUPSD_LOG_CRIT
, "Unable to allocate memory for printer - %s",
125 cupsdSetString(&p
->name
, name
);
126 cupsdSetString(&p
->info
, name
);
127 cupsdSetString(&p
->hostname
, ServerName
);
129 cupsdSetStringf(&p
->uri
, "ipp://%s:%d/printers/%s", ServerName
, LocalPort
, name
);
130 cupsdSetStringf(&p
->device_uri
, "file:/dev/null");
132 p
->state
= IPP_PRINTER_STOPPED
;
133 p
->state_time
= time(NULL
);
135 p
->shared
= DefaultShared
;
136 p
->filetype
= mimeAddType(MimeDatabase
, "printer", name
);
138 cupsdSetString(&p
->job_sheets
[0], "none");
139 cupsdSetString(&p
->job_sheets
[1], "none");
141 cupsdSetString(&p
->error_policy
, ErrorPolicy
);
142 cupsdSetString(&p
->op_policy
, DefaultPolicy
);
144 p
->op_policy_ptr
= DefaultPolicyPtr
;
146 if (MaxPrinterHistory
)
147 p
->history
= calloc(MaxPrinterHistory
, sizeof(ipp_t
*));
150 * Insert the printer in the printer list alphabetically...
154 Printers
= cupsArrayNew(compare_printers
, NULL
);
156 cupsArrayAdd(Printers
, p
);
158 if (!ImplicitPrinters
)
159 ImplicitPrinters
= cupsArrayNew(compare_printers
, NULL
);
162 * Return the new printer...
170 * 'cupsdAddPrinterHistory()' - Add the current printer state to the history.
174 cupsdAddPrinterHistory(
175 cupsd_printer_t
*p
) /* I - Printer */
177 ipp_t
*history
; /* History collection */
181 * Stop early if we aren't keeping history data...
184 if (MaxPrinterHistory
<= 0)
188 * Retire old history data as needed...
191 p
->sequence_number
++;
193 if (p
->num_history
>= MaxPrinterHistory
)
196 ippDelete(p
->history
[0]);
197 memmove(p
->history
, p
->history
+ 1, p
->num_history
* sizeof(ipp_t
*));
201 * Create a collection containing the current printer-state, printer-up-time,
202 * printer-state-message, and printer-state-reasons attributes.
206 ippAddInteger(history
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-state",
208 ippAddBoolean(history
, IPP_TAG_PRINTER
, "printer-is-accepting-jobs",
210 ippAddBoolean(history
, IPP_TAG_PRINTER
, "printer-is-shared", p
->shared
);
211 ippAddString(history
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-state-message",
212 NULL
, p
->state_message
);
215 ippAddString(history
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
216 "com.apple.print.recoverable-message", NULL
, p
->recoverable
);
217 #endif /* __APPLE__ */
218 if (p
->num_reasons
== 0)
219 ippAddString(history
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
220 "printer-state-reasons", NULL
,
221 p
->state
== IPP_PRINTER_STOPPED
? "paused" : "none");
223 ippAddStrings(history
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
224 "printer-state-reasons", p
->num_reasons
, NULL
,
225 (const char * const *)p
->reasons
);
226 ippAddInteger(history
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
227 "printer-state-change-time", p
->state_time
);
228 ippAddInteger(history
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
229 "printer-state-sequence-number", p
->sequence_number
);
231 p
->history
[p
->num_history
] = history
;
237 * 'cupsdAddPrinterUser()' - Add a user to the ACL.
242 cupsd_printer_t
*p
, /* I - Printer */
243 const char *username
) /* I - User */
245 const char **temp
; /* Temporary array pointer */
251 if (p
->num_users
== 0)
252 temp
= malloc(sizeof(char **));
254 temp
= realloc(p
->users
, sizeof(char **) * (p
->num_users
+ 1));
260 temp
+= p
->num_users
;
262 if ((*temp
= strdup(username
)) != NULL
)
268 * 'cupsdCreateCommonData()' - Create the common printer data.
272 cupsdCreateCommonData(void)
274 int i
; /* Looping var */
275 ipp_attribute_t
*attr
; /* Attribute data */
276 cups_dir_t
*dir
; /* Notifier directory */
277 cups_dentry_t
*dent
; /* Notifier directory entry */
278 cups_array_t
*notifiers
; /* Notifier array */
279 char filename
[1024], /* Filename */
280 *notifier
; /* Current notifier */
281 static const int nups
[] = /* number-up-supported values */
282 { 1, 2, 4, 6, 9, 16 };
283 static const int orients
[4] =/* orientation-requested-supported values */
287 IPP_REVERSE_LANDSCAPE
,
290 static const char * const holds
[] = /* job-hold-until-supported values */
301 static const char * const versions
[] =/* ipp-versions-supported values */
306 static const int ops
[] = /* operations-supported values */
313 IPP_GET_JOB_ATTRIBUTES
,
315 IPP_GET_PRINTER_ATTRIBUTES
,
321 IPP_SET_JOB_ATTRIBUTES
,
322 IPP_CREATE_PRINTER_SUBSCRIPTION
,
323 IPP_CREATE_JOB_SUBSCRIPTION
,
324 IPP_GET_SUBSCRIPTION_ATTRIBUTES
,
325 IPP_GET_SUBSCRIPTIONS
,
326 IPP_RENEW_SUBSCRIPTION
,
327 IPP_CANCEL_SUBSCRIPTION
,
328 IPP_GET_NOTIFICATIONS
,
344 CUPS_AUTHENTICATE_JOB
,
347 static const char * const charsets
[] =/* charset-supported values */
352 static const char * const compressions
[] =
353 { /* document-compression-supported values */
357 #endif /* HAVE_LIBZ */
359 static const char * const multiple_document_handling
[] =
360 { /* multiple-document-handling-supported values */
361 "separate-documents-uncollated-copies",
362 "separate-documents-collated-copies"
364 static const char * const errors
[] = /* printer-error-policy-supported values */
370 static const char * const notify_attrs
[] =
371 { /* notify-attributes-supported values */
372 "printer-state-change-time",
373 "notify-lease-expiration-time",
374 "notify-subscriber-user-name"
376 static const char * const notify_events
[] =
377 { /* notify-events-supported values */
379 "job-config-changed",
386 "printer-config-changed",
388 "printer-finishings-changed",
389 "printer-media-changed",
393 "printer-state-changed",
403 ippDelete(CommonData
);
405 CommonData
= ippNew();
408 * This list of attributes is sorted to improve performance when the
409 * client provides a requested-attributes attribute...
412 /* charset-configured */
413 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_CHARSET
,
414 "charset-configured", NULL
, DefaultCharset
);
416 /* charset-supported */
417 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_CHARSET
,
418 "charset-supported", sizeof(charsets
) / sizeof(charsets
[0]),
421 /* compression-supported */
422 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
423 "compression-supported",
424 sizeof(compressions
) / sizeof(compressions
[0]),
427 /* copies-supported */
428 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "copies-supported", 1, MaxCopies
);
431 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "cups-version",
432 NULL
, CUPS_SVERSION
+ 6);
434 /* generated-natural-language-supported */
435 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_LANGUAGE
,
436 "generated-natural-language-supported", NULL
, DefaultLanguage
);
438 /* ipp-versions-supported */
439 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
440 "ipp-versions-supported", sizeof(versions
) / sizeof(versions
[0]),
443 /* job-hold-until-supported */
444 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
445 "job-hold-until-supported", sizeof(holds
) / sizeof(holds
[0]),
448 /* job-priority-supported */
449 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
450 "job-priority-supported", 100);
452 /* job-sheets-supported */
453 if (cupsArrayCount(Banners
) > 0)
456 * Setup the job-sheets-supported attribute...
459 if (Classification
&& !ClassifyOverride
)
460 attr
= ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
461 "job-sheets-supported", NULL
, Classification
);
463 attr
= ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
464 "job-sheets-supported", cupsArrayCount(Banners
) + 1,
468 cupsdLogMessage(CUPSD_LOG_EMERG
,
469 "Unable to allocate memory for "
470 "job-sheets-supported attribute: %s!", strerror(errno
));
471 else if (!Classification
|| ClassifyOverride
)
473 cupsd_banner_t
*banner
; /* Current banner */
476 attr
->values
[0].string
.text
= _cupsStrAlloc("none");
478 for (i
= 1, banner
= (cupsd_banner_t
*)cupsArrayFirst(Banners
);
480 i
++, banner
= (cupsd_banner_t
*)cupsArrayNext(Banners
))
481 attr
->values
[i
].string
.text
= _cupsStrAlloc(banner
->name
);
485 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
486 "job-sheets-supported", NULL
, "none");
488 /* multiple-document-handling-supported */
489 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
490 "multiple-document-handling-supported",
491 sizeof(multiple_document_handling
) /
492 sizeof(multiple_document_handling
[0]), NULL
,
493 multiple_document_handling
);
495 /* multiple-document-jobs-supported */
496 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
,
497 "multiple-document-jobs-supported", 1);
499 /* multiple-operation-time-out */
500 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
501 "multiple-operation-time-out", 60);
503 /* natural-language-configured */
504 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_LANGUAGE
,
505 "natural-language-configured", NULL
, DefaultLanguage
);
507 /* notify-attributes-supported */
508 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
509 "notify-attributes-supported",
510 (int)(sizeof(notify_attrs
) / sizeof(notify_attrs
[0])),
513 /* notify-lease-duration-supported */
514 ippAddRange(CommonData
, IPP_TAG_PRINTER
,
515 "notify-lease-duration-supported", 0,
516 MaxLeaseDuration
? MaxLeaseDuration
: 2147483647);
518 /* notify-max-events-supported */
519 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
520 "notify-max-events-supported", MaxEvents
);
522 /* notify-events-supported */
523 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
524 "notify-events-supported",
525 (int)(sizeof(notify_events
) / sizeof(notify_events
[0])),
526 NULL
, notify_events
);
528 /* notify-pull-method-supported */
529 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
530 "notify-pull-method-supported", NULL
, "ippget");
532 /* notify-schemes-supported */
533 snprintf(filename
, sizeof(filename
), "%s/notifier", ServerBin
);
534 if ((dir
= cupsDirOpen(filename
)) != NULL
)
536 notifiers
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
538 while ((dent
= cupsDirRead(dir
)) != NULL
)
539 if (S_ISREG(dent
->fileinfo
.st_mode
) &&
540 (dent
->fileinfo
.st_mode
& S_IXOTH
) != 0)
541 cupsArrayAdd(notifiers
, _cupsStrAlloc(dent
->filename
));
543 if (cupsArrayCount(notifiers
) > 0)
545 attr
= ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
546 "notify-schemes-supported",
547 cupsArrayCount(notifiers
), NULL
, NULL
);
549 for (i
= 0, notifier
= (char *)cupsArrayFirst(notifiers
);
551 i
++, notifier
= (char *)cupsArrayNext(notifiers
))
552 attr
->values
[i
].string
.text
= notifier
;
555 cupsArrayDelete(notifiers
);
559 /* number-up-supported */
560 ippAddIntegers(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
561 "number-up-supported", sizeof(nups
) / sizeof(nups
[0]), nups
);
563 /* operations-supported */
564 ippAddIntegers(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
565 "operations-supported",
566 sizeof(ops
) / sizeof(ops
[0]) + JobFiles
- 1, ops
);
568 /* orientation-requested-supported */
569 ippAddIntegers(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
570 "orientation-requested-supported", 4, orients
);
572 /* page-ranges-supported */
573 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
, "page-ranges-supported", 1);
575 /* pdf-override-supported */
576 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
577 "pdl-override-supported", NULL
, "not-attempted");
579 /* printer-error-policy-supported */
580 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
581 "printer-error-policy-supported",
582 sizeof(errors
) / sizeof(errors
[0]), NULL
, errors
);
584 /* printer-op-policy-supported */
585 attr
= ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
586 "printer-op-policy-supported", NumPolicies
, NULL
, NULL
);
587 for (i
= 0; i
< NumPolicies
; i
++)
588 attr
->values
[i
].string
.text
= _cupsStrAlloc(Policies
[i
]->name
);
593 * 'cupsdDeleteAllPrinters()' - Delete all printers from the system.
597 cupsdDeleteAllPrinters(void)
599 cupsd_printer_t
*p
; /* Pointer to current printer/class */
602 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
604 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
605 if (!(p
->type
& CUPS_PRINTER_CLASS
))
606 cupsdDeletePrinter(p
, 0);
611 * 'cupsdDeletePrinter()' - Delete a printer from the system.
616 cupsd_printer_t
*p
, /* I - Printer to delete */
617 int update
) /* I - Update printers.conf? */
619 int i
; /* Looping var */
621 char filename
[1024]; /* Interface script filename */
625 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdDeletePrinter(p=%p(%s), update=%d)",
629 * Save the current position in the Printers array...
632 cupsArraySave(Printers
);
635 * Stop printing on this printer...
638 cupsdStopPrinter(p
, update
);
641 * If this printer is the next for browsing, point to the next one...
646 cupsArrayFind(Printers
, p
);
647 BrowseNext
= (cupsd_printer_t
*)cupsArrayNext(Printers
);
651 * Remove the printer from the list...
654 cupsArrayRemove(Printers
, p
);
656 if (p
->type
& CUPS_PRINTER_IMPLICIT
)
657 cupsArrayRemove(ImplicitPrinters
, p
);
660 * Remove the dummy interface/icon/option files under IRIX...
664 snprintf(filename
, sizeof(filename
), "/var/spool/lp/interface/%s", p
->name
);
667 snprintf(filename
, sizeof(filename
), "/var/spool/lp/gui_interface/ELF/%s.gui",
671 snprintf(filename
, sizeof(filename
), "/var/spool/lp/activeicons/%s", p
->name
);
674 snprintf(filename
, sizeof(filename
), "/var/spool/lp/pod/%s.config", p
->name
);
677 snprintf(filename
, sizeof(filename
), "/var/spool/lp/pod/%s.status", p
->name
);
680 snprintf(filename
, sizeof(filename
), "/var/spool/lp/member/%s", p
->name
);
685 * If p is the default printer, assign a different one...
688 if (p
== DefaultPrinter
)
690 DefaultPrinter
= NULL
;
692 if (UseNetworkDefault
)
695 * Find the first network default printer and use it...
698 cupsd_printer_t
*dp
; /* New default printer */
701 for (dp
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
703 dp
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
704 if (dp
!= p
&& (dp
->type
& CUPS_PRINTER_DEFAULT
))
713 * Remove this printer from any classes...
716 if (!(p
->type
& CUPS_PRINTER_IMPLICIT
))
718 cupsdDeletePrinterFromClasses(p
);
721 * Deregister from any browse protocols...
724 cupsdDeregisterPrinter(p
, 1);
728 * Free all memory used by the printer...
731 if (p
->printers
!= NULL
)
734 if (MaxPrinterHistory
)
736 for (i
= 0; i
< p
->num_history
; i
++)
737 ippDelete(p
->history
[i
]);
742 for (i
= 0; i
< p
->num_reasons
; i
++)
747 delete_printer_filters(p
);
749 mimeDeleteType(MimeDatabase
, p
->filetype
);
750 mimeDeleteType(MimeDatabase
, p
->prefiltertype
);
752 cupsdFreePrinterUsers(p
);
755 cupsdClearString(&p
->uri
);
756 cupsdClearString(&p
->hostname
);
757 cupsdClearString(&p
->name
);
758 cupsdClearString(&p
->location
);
759 cupsdClearString(&p
->make_model
);
760 cupsdClearString(&p
->info
);
761 cupsdClearString(&p
->job_sheets
[0]);
762 cupsdClearString(&p
->job_sheets
[1]);
763 cupsdClearString(&p
->device_uri
);
764 cupsdClearString(&p
->port_monitor
);
765 cupsdClearString(&p
->op_policy
);
766 cupsdClearString(&p
->error_policy
);
768 cupsdClearString(&p
->alert
);
769 cupsdClearString(&p
->alert_description
);
772 cupsdClearString(&p
->product
);
773 cupsdClearString(&p
->pdl
);
774 #endif /* HAVE_DNSSD */
776 cupsArrayDelete(p
->filetypes
);
779 free(p
->browse_attrs
);
782 cupsdClearString(&p
->recoverable
);
783 #endif /* __APPLE__ */
785 cupsFreeOptions(p
->num_options
, p
->options
);
790 * Restore the previous position in the Printers array...
793 cupsArrayRestore(Printers
);
798 * 'cupsdFindDest()' - Find a destination in the list.
801 cupsd_printer_t
* /* O - Destination in list */
802 cupsdFindDest(const char *name
) /* I - Name of printer or class to find */
804 cupsd_printer_t key
; /* Search key */
807 key
.name
= (char *)name
;
808 return ((cupsd_printer_t
*)cupsArrayFind(Printers
, &key
));
813 * 'cupsdFindPrinter()' - Find a printer in the list.
816 cupsd_printer_t
* /* O - Printer in list */
817 cupsdFindPrinter(const char *name
) /* I - Name of printer to find */
819 cupsd_printer_t
*p
; /* Printer in list */
822 if ((p
= cupsdFindDest(name
)) != NULL
&& (p
->type
& CUPS_PRINTER_CLASS
))
830 * 'cupsdFreePrinterUsers()' - Free allow/deny users.
834 cupsdFreePrinterUsers(
835 cupsd_printer_t
*p
) /* I - Printer */
837 int i
; /* Looping var */
840 if (!p
|| !p
->num_users
)
843 for (i
= 0; i
< p
->num_users
; i
++)
844 free((void *)p
->users
[i
]);
854 * 'cupsdLoadAllPrinters()' - Load printers from the printers.conf file.
858 cupsdLoadAllPrinters(void)
860 cups_file_t
*fp
; /* printers.conf file */
861 int linenum
; /* Current line number */
862 char line
[1024], /* Line from file */
863 *value
, /* Pointer to value */
864 *valueptr
; /* Pointer into value */
865 cupsd_printer_t
*p
; /* Current printer */
869 * Open the printers.conf file...
872 snprintf(line
, sizeof(line
), "%s/printers.conf", ServerRoot
);
873 if ((fp
= cupsFileOpen(line
, "r")) == NULL
)
876 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to open %s - %s", line
,
882 * Read printer configurations until we hit EOF...
888 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
891 * Decode the directive...
894 if (!strcasecmp(line
, "<Printer") ||
895 !strcasecmp(line
, "<DefaultPrinter"))
898 * <Printer name> or <DefaultPrinter name>
901 if (p
== NULL
&& value
)
904 * Add the printer and a base file type...
907 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Loading printer %s...", value
);
909 p
= cupsdAddPrinter(value
);
911 p
->state
= IPP_PRINTER_IDLE
;
914 * Set the default printer as needed...
917 if (!strcasecmp(line
, "<DefaultPrinter"))
922 cupsdLogMessage(CUPSD_LOG_ERROR
,
923 "Syntax error on line %d of printers.conf.", linenum
);
927 else if (!strcasecmp(line
, "</Printer>"))
932 * Close out the current printer...
935 cupsdSetPrinterAttrs(p
);
936 cupsdAddPrinterHistory(p
);
938 if (p
->device_uri
&& strncmp(p
->device_uri
, "file:", 5) &&
939 p
->state
!= IPP_PRINTER_STOPPED
)
942 * See if the backend exists...
945 snprintf(line
, sizeof(line
), "%s/backend/%s", ServerBin
,
948 if ((valueptr
= strchr(line
+ strlen(ServerBin
), ':')) != NULL
)
949 *valueptr
= '\0'; /* Chop everything but URI scheme */
954 * Backend does not exist, stop printer...
957 p
->state
= IPP_PRINTER_STOPPED
;
958 snprintf(p
->state_message
, sizeof(p
->state_message
),
959 "Backend %s does not exist!", line
);
967 cupsdLogMessage(CUPSD_LOG_ERROR
,
968 "Syntax error on line %d of printers.conf.", linenum
);
974 cupsdLogMessage(CUPSD_LOG_ERROR
,
975 "Syntax error on line %d of printers.conf.", linenum
);
978 else if (!strcasecmp(line
, "AuthInfoRequired"))
980 if (!cupsdSetAuthInfoRequired(p
, value
, NULL
))
981 cupsdLogMessage(CUPSD_LOG_ERROR
,
982 "Bad AuthInfoRequired on line %d of printers.conf.",
985 else if (!strcasecmp(line
, "Info"))
988 cupsdSetString(&p
->info
, value
);
990 else if (!strcasecmp(line
, "Location"))
993 cupsdSetString(&p
->location
, value
);
995 else if (!strcasecmp(line
, "DeviceURI"))
998 cupsdSetString(&p
->device_uri
, value
);
1001 cupsdLogMessage(CUPSD_LOG_ERROR
,
1002 "Syntax error on line %d of printers.conf.", linenum
);
1006 else if (!strcasecmp(line
, "Option") && value
)
1012 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1015 cupsdLogMessage(CUPSD_LOG_ERROR
,
1016 "Syntax error on line %d of printers.conf.", linenum
);
1019 for (; *valueptr
&& isspace(*valueptr
& 255); *valueptr
++ = '\0');
1021 p
->num_options
= cupsAddOption(value
, valueptr
, p
->num_options
,
1025 else if (!strcasecmp(line
, "PortMonitor"))
1027 if (value
&& strcmp(value
, "none"))
1028 cupsdSetString(&p
->port_monitor
, value
);
1030 cupsdClearString(&p
->port_monitor
);
1033 cupsdLogMessage(CUPSD_LOG_ERROR
,
1034 "Syntax error on line %d of printers.conf.", linenum
);
1038 else if (!strcasecmp(line
, "State"))
1041 * Set the initial queue state...
1044 if (value
&& !strcasecmp(value
, "idle"))
1045 p
->state
= IPP_PRINTER_IDLE
;
1046 else if (value
&& !strcasecmp(value
, "stopped"))
1047 p
->state
= IPP_PRINTER_STOPPED
;
1050 cupsdLogMessage(CUPSD_LOG_ERROR
,
1051 "Syntax error on line %d of printers.conf.", linenum
);
1055 else if (!strcasecmp(line
, "StateMessage"))
1058 * Set the initial queue state message...
1062 strlcpy(p
->state_message
, value
, sizeof(p
->state_message
));
1064 else if (!strcasecmp(line
, "StateTime"))
1067 * Set the state time...
1071 p
->state_time
= atoi(value
);
1073 else if (!strcasecmp(line
, "Accepting"))
1076 * Set the initial accepting state...
1080 (!strcasecmp(value
, "yes") ||
1081 !strcasecmp(value
, "on") ||
1082 !strcasecmp(value
, "true")))
1085 (!strcasecmp(value
, "no") ||
1086 !strcasecmp(value
, "off") ||
1087 !strcasecmp(value
, "false")))
1091 cupsdLogMessage(CUPSD_LOG_ERROR
,
1092 "Syntax error on line %d of printers.conf.", linenum
);
1096 else if (!strcasecmp(line
, "Shared"))
1099 * Set the initial shared state...
1103 (!strcasecmp(value
, "yes") ||
1104 !strcasecmp(value
, "on") ||
1105 !strcasecmp(value
, "true")))
1108 (!strcasecmp(value
, "no") ||
1109 !strcasecmp(value
, "off") ||
1110 !strcasecmp(value
, "false")))
1114 cupsdLogMessage(CUPSD_LOG_ERROR
,
1115 "Syntax error on line %d of printers.conf.", linenum
);
1119 else if (!strcasecmp(line
, "JobSheets"))
1122 * Set the initial job sheets...
1127 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1132 cupsdSetString(&p
->job_sheets
[0], value
);
1134 while (isspace(*valueptr
& 255))
1139 for (value
= valueptr
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1144 cupsdSetString(&p
->job_sheets
[1], value
);
1149 cupsdLogMessage(CUPSD_LOG_ERROR
,
1150 "Syntax error on line %d of printers.conf.", linenum
);
1154 else if (!strcasecmp(line
, "AllowUser"))
1159 cupsdAddPrinterUser(p
, value
);
1163 cupsdLogMessage(CUPSD_LOG_ERROR
,
1164 "Syntax error on line %d of printers.conf.", linenum
);
1168 else if (!strcasecmp(line
, "DenyUser"))
1173 cupsdAddPrinterUser(p
, value
);
1177 cupsdLogMessage(CUPSD_LOG_ERROR
,
1178 "Syntax error on line %d of printers.conf.", linenum
);
1182 else if (!strcasecmp(line
, "QuotaPeriod"))
1185 p
->quota_period
= atoi(value
);
1188 cupsdLogMessage(CUPSD_LOG_ERROR
,
1189 "Syntax error on line %d of printers.conf.", linenum
);
1193 else if (!strcasecmp(line
, "PageLimit"))
1196 p
->page_limit
= atoi(value
);
1199 cupsdLogMessage(CUPSD_LOG_ERROR
,
1200 "Syntax error on line %d of printers.conf.", linenum
);
1204 else if (!strcasecmp(line
, "KLimit"))
1207 p
->k_limit
= atoi(value
);
1210 cupsdLogMessage(CUPSD_LOG_ERROR
,
1211 "Syntax error on line %d of printers.conf.", linenum
);
1215 else if (!strcasecmp(line
, "OpPolicy"))
1219 cupsd_policy_t
*pol
; /* Policy */
1222 if ((pol
= cupsdFindPolicy(value
)) != NULL
)
1224 cupsdSetString(&p
->op_policy
, value
);
1225 p
->op_policy_ptr
= pol
;
1228 cupsdLogMessage(CUPSD_LOG_ERROR
,
1229 "Bad policy \"%s\" on line %d of printers.conf",
1234 cupsdLogMessage(CUPSD_LOG_ERROR
,
1235 "Syntax error on line %d of printers.conf.", linenum
);
1239 else if (!strcasecmp(line
, "ErrorPolicy"))
1242 cupsdSetString(&p
->error_policy
, value
);
1245 cupsdLogMessage(CUPSD_LOG_ERROR
,
1246 "Syntax error on line %d of printers.conf.", linenum
);
1253 * Something else we don't understand...
1256 cupsdLogMessage(CUPSD_LOG_ERROR
,
1257 "Unknown configuration directive %s on line %d of printers.conf.",
1267 * 'cupsdRenamePrinter()' - Rename a printer.
1272 cupsd_printer_t
*p
, /* I - Printer */
1273 const char *name
) /* I - New name */
1276 * Remove the printer from the array(s) first...
1279 cupsArrayRemove(Printers
, p
);
1281 if (p
->type
& CUPS_PRINTER_IMPLICIT
)
1282 cupsArrayRemove(ImplicitPrinters
, p
);
1285 * Rename the printer type...
1288 mimeDeleteType(MimeDatabase
, p
->filetype
);
1289 p
->filetype
= mimeAddType(MimeDatabase
, "printer", name
);
1291 mimeDeleteType(MimeDatabase
, p
->prefiltertype
);
1292 p
->prefiltertype
= mimeAddType(MimeDatabase
, "prefilter", name
);
1295 * Rename the printer...
1298 cupsdSetString(&p
->name
, name
);
1301 * Reset printer attributes...
1304 cupsdSetPrinterAttrs(p
);
1307 * Add the printer back to the printer array(s)...
1310 cupsArrayAdd(Printers
, p
);
1312 if (p
->type
& CUPS_PRINTER_IMPLICIT
)
1313 cupsArrayAdd(ImplicitPrinters
, p
);
1318 * 'cupsdSaveAllPrinters()' - Save all printer definitions to the printers.conf
1323 cupsdSaveAllPrinters(void)
1325 int i
; /* Looping var */
1326 cups_file_t
*fp
; /* printers.conf file */
1327 char temp
[1024]; /* Temporary string */
1328 char backup
[1024]; /* printers.conf.O file */
1329 cupsd_printer_t
*printer
; /* Current printer class */
1330 time_t curtime
; /* Current time */
1331 struct tm
*curdate
; /* Current date */
1332 cups_option_t
*option
; /* Current option */
1333 const char *ptr
; /* Pointer into info/location */
1337 * Create the printers.conf file...
1340 snprintf(temp
, sizeof(temp
), "%s/printers.conf", ServerRoot
);
1341 snprintf(backup
, sizeof(backup
), "%s/printers.conf.O", ServerRoot
);
1343 if (rename(temp
, backup
))
1345 if (errno
!= ENOENT
)
1346 cupsdLogMessage(CUPSD_LOG_ERROR
,
1347 "Unable to backup printers.conf - %s", strerror(errno
));
1350 if ((fp
= cupsFileOpen(temp
, "w")) == NULL
)
1352 cupsdLogMessage(CUPSD_LOG_ERROR
,
1353 "Unable to save printers.conf - %s", strerror(errno
));
1355 if (rename(backup
, temp
))
1356 cupsdLogMessage(CUPSD_LOG_ERROR
,
1357 "Unable to restore printers.conf - %s", strerror(errno
));
1361 cupsdLogMessage(CUPSD_LOG_INFO
, "Saving printers.conf...");
1364 * Restrict access to the file...
1367 fchown(cupsFileNumber(fp
), getuid(), Group
);
1368 fchmod(cupsFileNumber(fp
), 0600);
1371 * Write a small header to the file...
1374 curtime
= time(NULL
);
1375 curdate
= localtime(&curtime
);
1376 strftime(temp
, sizeof(temp
) - 1, "%Y-%m-%d %H:%M", curdate
);
1378 cupsFilePuts(fp
, "# Printer configuration file for " CUPS_SVERSION
"\n");
1379 cupsFilePrintf(fp
, "# Written by cupsd on %s\n", temp
);
1382 * Write each local printer known to the system...
1385 for (printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
1387 printer
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
1390 * Skip remote destinations and printer classes...
1393 if ((printer
->type
& CUPS_PRINTER_REMOTE
) ||
1394 (printer
->type
& CUPS_PRINTER_CLASS
) ||
1395 (printer
->type
& CUPS_PRINTER_IMPLICIT
))
1399 * Write printers as needed...
1402 if (printer
== DefaultPrinter
)
1403 cupsFilePrintf(fp
, "<DefaultPrinter %s>\n", printer
->name
);
1405 cupsFilePrintf(fp
, "<Printer %s>\n", printer
->name
);
1407 if (printer
->num_auth_info_required
> 0)
1409 cupsFilePrintf(fp
, "AuthInfoRequired %s", printer
->auth_info_required
[0]);
1410 for (i
= 1; i
< printer
->num_auth_info_required
; i
++)
1411 cupsFilePrintf(fp
, ",%s", printer
->auth_info_required
[i
]);
1412 cupsFilePutChar(fp
, '\n');
1417 if ((ptr
= strchr(printer
->info
, '#')) != NULL
)
1420 * Need to quote the first # in the info string...
1423 cupsFilePuts(fp
, "Info ");
1424 cupsFileWrite(fp
, printer
->info
, ptr
- printer
->info
);
1425 cupsFilePutChar(fp
, '\\');
1426 cupsFilePuts(fp
, ptr
);
1427 cupsFilePutChar(fp
, '\n');
1430 cupsFilePrintf(fp
, "Info %s\n", printer
->info
);
1433 if (printer
->location
)
1435 if ((ptr
= strchr(printer
->info
, '#')) != NULL
)
1438 * Need to quote the first # in the location string...
1441 cupsFilePuts(fp
, "Location ");
1442 cupsFileWrite(fp
, printer
->location
, ptr
- printer
->location
);
1443 cupsFilePutChar(fp
, '\\');
1444 cupsFilePuts(fp
, ptr
);
1445 cupsFilePutChar(fp
, '\n');
1448 cupsFilePrintf(fp
, "Location %s\n", printer
->location
);
1450 if (printer
->device_uri
)
1451 cupsFilePrintf(fp
, "DeviceURI %s\n", printer
->device_uri
);
1453 if (printer
->port_monitor
)
1454 cupsFilePrintf(fp
, "PortMonitor %s\n", printer
->port_monitor
);
1456 if (printer
->state
== IPP_PRINTER_STOPPED
)
1458 cupsFilePuts(fp
, "State Stopped\n");
1459 cupsFilePrintf(fp
, "StateMessage %s\n", printer
->state_message
);
1462 cupsFilePuts(fp
, "State Idle\n");
1464 cupsFilePrintf(fp
, "StateTime %d\n", (int)printer
->state_time
);
1466 if (printer
->accepting
)
1467 cupsFilePuts(fp
, "Accepting Yes\n");
1469 cupsFilePuts(fp
, "Accepting No\n");
1471 if (printer
->shared
)
1472 cupsFilePuts(fp
, "Shared Yes\n");
1474 cupsFilePuts(fp
, "Shared No\n");
1476 cupsFilePrintf(fp
, "JobSheets %s %s\n", printer
->job_sheets
[0],
1477 printer
->job_sheets
[1]);
1479 cupsFilePrintf(fp
, "QuotaPeriod %d\n", printer
->quota_period
);
1480 cupsFilePrintf(fp
, "PageLimit %d\n", printer
->page_limit
);
1481 cupsFilePrintf(fp
, "KLimit %d\n", printer
->k_limit
);
1483 for (i
= 0; i
< printer
->num_users
; i
++)
1484 cupsFilePrintf(fp
, "%sUser %s\n", printer
->deny_users
? "Deny" : "Allow",
1487 if (printer
->op_policy
)
1488 cupsFilePrintf(fp
, "OpPolicy %s\n", printer
->op_policy
);
1489 if (printer
->error_policy
)
1490 cupsFilePrintf(fp
, "ErrorPolicy %s\n", printer
->error_policy
);
1492 for (i
= printer
->num_options
, option
= printer
->options
;
1495 cupsFilePrintf(fp
, "Option %s %s\n", option
->name
, option
->value
);
1497 cupsFilePuts(fp
, "</Printer>\n");
1501 * Make IRIX desktop & printer status happy
1504 write_irix_state(printer
);
1513 * 'cupsdSetAuthInfoRequired()' - Set the required authentication info.
1516 int /* O - 1 if value OK, 0 otherwise */
1517 cupsdSetAuthInfoRequired(
1518 cupsd_printer_t
*p
, /* I - Printer */
1519 const char *values
, /* I - Plain text value (or NULL) */
1520 ipp_attribute_t
*attr
) /* I - IPP attribute value (or NULL) */
1522 int i
; /* Looping var */
1525 p
->num_auth_info_required
= 0;
1528 * Do we have a plain text value?
1534 * Yes, grab the keywords...
1537 const char *end
; /* End of current value */
1540 while (*values
&& p
->num_auth_info_required
< 4)
1542 if ((end
= strchr(values
, ',')) == NULL
)
1543 end
= values
+ strlen(values
);
1545 if ((end
- values
) == 4 && !strncmp(values
, "none", 4))
1547 if (p
->num_auth_info_required
!= 0 || *end
)
1550 p
->auth_info_required
[p
->num_auth_info_required
] = "none";
1551 p
->num_auth_info_required
++;
1555 else if ((end
- values
) == 9 && !strncmp(values
, "negotiate", 9))
1557 if (p
->num_auth_info_required
!= 0 || *end
)
1560 p
->auth_info_required
[p
->num_auth_info_required
] = "negotiate";
1561 p
->num_auth_info_required
++;
1565 else if ((end
- values
) == 6 && !strncmp(values
, "domain", 6))
1567 p
->auth_info_required
[p
->num_auth_info_required
] = "domain";
1568 p
->num_auth_info_required
++;
1570 else if ((end
- values
) == 8 && !strncmp(values
, "password", 8))
1572 p
->auth_info_required
[p
->num_auth_info_required
] = "password";
1573 p
->num_auth_info_required
++;
1575 else if ((end
- values
) == 8 && !strncmp(values
, "username", 8))
1577 p
->auth_info_required
[p
->num_auth_info_required
] = "username";
1578 p
->num_auth_info_required
++;
1584 if (p
->num_auth_info_required
== 0)
1586 p
->auth_info_required
[0] = "none";
1587 p
->num_auth_info_required
= 1;
1594 * Grab values from an attribute instead...
1597 if (!attr
|| attr
->num_values
> 4)
1600 for (i
= 0; i
< attr
->num_values
; i
++)
1602 if (!strcmp(attr
->values
[i
].string
.text
, "none"))
1604 if (p
->num_auth_info_required
!= 0 || attr
->num_values
!= 1)
1607 p
->auth_info_required
[p
->num_auth_info_required
] = "none";
1608 p
->num_auth_info_required
++;
1612 else if (!strcmp(attr
->values
[i
].string
.text
, "negotiate"))
1614 if (p
->num_auth_info_required
!= 0 || attr
->num_values
!= 1)
1617 p
->auth_info_required
[p
->num_auth_info_required
] = "negotiate";
1618 p
->num_auth_info_required
++;
1622 else if (!strcmp(attr
->values
[i
].string
.text
, "domain"))
1624 p
->auth_info_required
[p
->num_auth_info_required
] = "domain";
1625 p
->num_auth_info_required
++;
1627 else if (!strcmp(attr
->values
[i
].string
.text
, "password"))
1629 p
->auth_info_required
[p
->num_auth_info_required
] = "password";
1630 p
->num_auth_info_required
++;
1632 else if (!strcmp(attr
->values
[i
].string
.text
, "username"))
1634 p
->auth_info_required
[p
->num_auth_info_required
] = "username";
1635 p
->num_auth_info_required
++;
1646 * 'cupsdSetPrinterAttrs()' - Set printer attributes based upon the PPD file.
1650 cupsdSetPrinterAttrs(cupsd_printer_t
*p
)/* I - Printer to setup */
1652 int i
, /* Looping var */
1653 length
; /* Length of browse attributes */
1654 char uri
[HTTP_MAX_URI
]; /* URI for printer */
1655 char resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
1656 char filename
[1024]; /* Name of PPD file */
1657 int num_media
; /* Number of media options */
1658 cupsd_location_t
*auth
; /* Pointer to authentication element */
1659 const char *auth_supported
; /* Authentication supported */
1660 cups_ptype_t printer_type
; /* Printer type data */
1661 ppd_file_t
*ppd
; /* PPD file data */
1662 ppd_option_t
*input_slot
, /* InputSlot options */
1663 *media_type
, /* MediaType options */
1664 *page_size
, /* PageSize options */
1665 *output_bin
, /* OutputBin options */
1666 *media_quality
, /* EFMediaQualityMode options */
1667 *duplex
; /* Duplex options */
1668 ppd_attr_t
*ppdattr
; /* PPD attribute */
1669 ipp_attribute_t
*attr
; /* Attribute data */
1670 ipp_value_t
*val
; /* Attribute value */
1671 int num_finishings
; /* Number of finishings */
1672 int finishings
[5]; /* finishings-supported values */
1673 cups_option_t
*option
; /* Current printer option */
1674 static const char * const sides
[3] = /* sides-supported values */
1677 "two-sided-long-edge",
1678 "two-sided-short-edge"
1682 DEBUG_printf(("cupsdSetPrinterAttrs: entering name = %s, type = %x\n", p
->name
,
1686 * Make sure that we have the common attributes defined...
1690 cupsdCreateCommonData();
1693 * Clear out old filters, if any...
1696 delete_printer_filters(p
);
1699 * Figure out the authentication that is required for the printer.
1702 auth_supported
= "requesting-user-name";
1703 if (!(p
->type
& CUPS_PRINTER_REMOTE
))
1705 if (p
->type
& CUPS_PRINTER_CLASS
)
1706 snprintf(resource
, sizeof(resource
), "/classes/%s", p
->name
);
1708 snprintf(resource
, sizeof(resource
), "/printers/%s", p
->name
);
1710 if ((auth
= cupsdFindBest(resource
, HTTP_POST
)) == NULL
||
1711 auth
->type
== AUTH_NONE
)
1712 auth
= cupsdFindPolicyOp(p
->op_policy_ptr
, IPP_PRINT_JOB
);
1716 if (auth
->type
== AUTH_BASIC
|| auth
->type
== AUTH_BASICDIGEST
)
1718 auth_supported
= "basic";
1719 cupsdSetAuthInfoRequired(p
, "username,password", NULL
);
1721 else if (auth
->type
== AUTH_DIGEST
)
1723 auth_supported
= "digest";
1724 cupsdSetAuthInfoRequired(p
, "username,password", NULL
);
1727 else if (auth
->type
== AUTH_NEGOTIATE
)
1729 auth_supported
= "negotiate";
1730 cupsdSetAuthInfoRequired(p
, "negotiate", NULL
);
1732 #endif /* HAVE_GSSAPI */
1734 if (auth
->type
!= AUTH_NONE
)
1735 p
->type
|= CUPS_PRINTER_AUTHENTICATED
;
1737 p
->type
&= ~CUPS_PRINTER_AUTHENTICATED
;
1740 p
->type
&= ~CUPS_PRINTER_AUTHENTICATED
;
1744 * Create the required IPP attributes for a printer...
1748 ippDelete(p
->attrs
);
1750 p
->attrs
= ippNew();
1752 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
1753 "uri-authentication-supported", NULL
, auth_supported
);
1754 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
1755 "uri-security-supported", NULL
, "none");
1756 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
, "printer-name", NULL
,
1758 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-location",
1759 NULL
, p
->location
? p
->location
: "");
1760 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-info",
1761 NULL
, p
->info
? p
->info
: "");
1762 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "printer-more-info",
1768 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
1769 "requesting-user-name-denied", p
->num_users
, NULL
,
1772 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
1773 "requesting-user-name-allowed", p
->num_users
, NULL
,
1777 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
1778 "job-quota-period", p
->quota_period
);
1779 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
1780 "job-k-limit", p
->k_limit
);
1781 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
1782 "job-page-limit", p
->page_limit
);
1783 if (p
->num_auth_info_required
)
1784 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
1785 "auth-info-required", p
->num_auth_info_required
,
1786 NULL
, p
->auth_info_required
);
1788 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
1789 "auth-info-required", NULL
, "none");
1791 if (cupsArrayCount(Banners
) > 0 && !(p
->type
& CUPS_PRINTER_REMOTE
))
1794 * Setup the job-sheets-default attribute...
1797 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
1798 "job-sheets-default", 2, NULL
, NULL
);
1802 attr
->values
[0].string
.text
= _cupsStrAlloc(Classification
?
1803 Classification
: p
->job_sheets
[0]);
1804 attr
->values
[1].string
.text
= _cupsStrAlloc(Classification
?
1805 Classification
: p
->job_sheets
[1]);
1809 printer_type
= p
->type
;
1814 if (p
->type
& CUPS_PRINTER_REMOTE
)
1817 * Tell the client this is a remote printer of some type...
1820 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
1821 "printer-uri-supported", NULL
, p
->uri
);
1824 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
1825 "printer-make-and-model", NULL
, p
->make_model
);
1827 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "device-uri", NULL
,
1836 * Assign additional attributes depending on whether this is a printer
1840 p
->type
&= ~CUPS_PRINTER_OPTIONS
;
1842 if (p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
))
1847 * Add class-specific attributes...
1850 if ((p
->type
& CUPS_PRINTER_IMPLICIT
) && p
->num_printers
> 0 &&
1851 p
->printers
[0]->make_model
)
1852 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
1853 "printer-make-and-model", NULL
, p
->printers
[0]->make_model
);
1855 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
1856 "printer-make-and-model", NULL
, "Local Printer Class");
1858 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "device-uri", NULL
,
1859 "file:///dev/null");
1861 if (p
->num_printers
> 0)
1864 * Add a list of member URIs and names...
1867 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
1868 "member-uris", p
->num_printers
, NULL
, NULL
);
1869 p
->type
|= CUPS_PRINTER_OPTIONS
;
1871 for (i
= 0; i
< p
->num_printers
; i
++)
1874 attr
->values
[i
].string
.text
= _cupsStrAlloc(p
->printers
[i
]->uri
);
1876 p
->type
&= ~CUPS_PRINTER_OPTIONS
| p
->printers
[i
]->type
;
1879 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
1880 "member-names", p
->num_printers
, NULL
, NULL
);
1884 for (i
= 0; i
< p
->num_printers
; i
++)
1885 attr
->values
[i
].string
.text
= _cupsStrAlloc(p
->printers
[i
]->name
);
1892 * Add printer-specific attributes... Start by sanitizing the device
1893 * URI so it doesn't have a username or password in it...
1897 strcpy(uri
, "file:/dev/null");
1898 else if (strstr(p
->device_uri
, "://") != NULL
)
1901 * http://..., ipp://..., etc.
1904 cupsdSanitizeURI(p
->device_uri
, uri
, sizeof(uri
));
1909 * file:..., serial:..., etc.
1912 strlcpy(uri
, p
->device_uri
, sizeof(uri
));
1915 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "device-uri", NULL
,
1919 * Assign additional attributes from the PPD file (if any)...
1922 p
->type
|= CUPS_PRINTER_BW
;
1923 finishings
[0] = IPP_FINISHINGS_NONE
;
1926 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
1929 if ((ppd
= ppdOpenFile(filename
)) != NULL
)
1932 * Add make/model and other various attributes...
1935 if (ppd
->color_device
)
1936 p
->type
|= CUPS_PRINTER_COLOR
;
1937 if (ppd
->variable_sizes
)
1938 p
->type
|= CUPS_PRINTER_VARIABLE
;
1939 if (!ppd
->manual_copies
)
1940 p
->type
|= CUPS_PRINTER_COPIES
;
1941 if ((ppdattr
= ppdFindAttr(ppd
, "cupsFax", NULL
)) != NULL
)
1942 if (ppdattr
->value
&& !strcasecmp(ppdattr
->value
, "true"))
1943 p
->type
|= CUPS_PRINTER_FAX
;
1945 ippAddBoolean(p
->attrs
, IPP_TAG_PRINTER
, "color-supported",
1947 if (ppd
->throughput
)
1948 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
1949 "pages-per-minute", ppd
->throughput
);
1954 * The NickName can be localized in the character set specified
1955 * by the LanugageEncoding attribute. However, ppdOpen2() has
1956 * already converted the ppd->nickname member to UTF-8 for us
1957 * (the original attribute value is available separately)
1960 cupsdSetString(&p
->make_model
, ppd
->nickname
);
1962 else if (ppd
->modelname
)
1965 * Model name can only contain specific characters...
1968 cupsdSetString(&p
->make_model
, ppd
->modelname
);
1971 cupsdSetString(&p
->make_model
, "Bad PPD File");
1973 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
1974 "printer-make-and-model", NULL
, p
->make_model
);
1977 * Add media options from the PPD file...
1980 if ((input_slot
= ppdFindOption(ppd
, "InputSlot")) != NULL
)
1981 num_media
= input_slot
->num_choices
;
1985 if ((media_type
= ppdFindOption(ppd
, "MediaType")) != NULL
)
1986 num_media
+= media_type
->num_choices
;
1988 if ((page_size
= ppdFindOption(ppd
, "PageSize")) != NULL
)
1989 num_media
+= page_size
->num_choices
;
1991 if ((media_quality
= ppdFindOption(ppd
, "EFMediaQualityMode")) != NULL
)
1992 num_media
+= media_quality
->num_choices
;
1996 cupsdLogMessage(CUPSD_LOG_CRIT
,
1997 "The PPD file for printer %s contains no media "
1998 "options and is therefore invalid!", p
->name
);
2002 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2003 "media-supported", num_media
, NULL
, NULL
);
2008 if (input_slot
!= NULL
)
2009 for (i
= 0; i
< input_slot
->num_choices
; i
++, val
++)
2010 val
->string
.text
= _cupsStrAlloc(input_slot
->choices
[i
].choice
);
2012 if (media_type
!= NULL
)
2013 for (i
= 0; i
< media_type
->num_choices
; i
++, val
++)
2014 val
->string
.text
= _cupsStrAlloc(media_type
->choices
[i
].choice
);
2016 if (media_quality
!= NULL
)
2017 for (i
= 0; i
< media_quality
->num_choices
; i
++, val
++)
2018 val
->string
.text
= _cupsStrAlloc(media_quality
->choices
[i
].choice
);
2020 if (page_size
!= NULL
)
2022 for (i
= 0; i
< page_size
->num_choices
; i
++, val
++)
2023 val
->string
.text
= _cupsStrAlloc(page_size
->choices
[i
].choice
);
2025 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2026 "media-default", NULL
, page_size
->defchoice
);
2028 else if (input_slot
!= NULL
)
2029 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2030 "media-default", NULL
, input_slot
->defchoice
);
2031 else if (media_type
!= NULL
)
2032 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2033 "media-default", NULL
, media_type
->defchoice
);
2034 else if (media_quality
!= NULL
)
2035 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2036 "media-default", NULL
, media_quality
->defchoice
);
2038 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2039 "media-default", NULL
, "none");
2047 if ((output_bin
= ppdFindOption(ppd
, "OutputBin")) != NULL
)
2049 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2050 "output-bin-supported", output_bin
->num_choices
,
2055 for (i
= 0, val
= attr
->values
;
2056 i
< output_bin
->num_choices
;
2058 val
->string
.text
= _cupsStrAlloc(output_bin
->choices
[i
].choice
);
2066 if ((duplex
= ppdFindOption(ppd
, "Duplex")) == NULL
)
2067 if ((duplex
= ppdFindOption(ppd
, "EFDuplex")) == NULL
)
2068 if ((duplex
= ppdFindOption(ppd
, "EFDuplexing")) == NULL
)
2069 if ((duplex
= ppdFindOption(ppd
, "KD03Duplex")) == NULL
)
2070 duplex
= ppdFindOption(ppd
, "JCLDuplex");
2072 if (duplex
&& duplex
->num_choices
> 1)
2074 p
->type
|= CUPS_PRINTER_DUPLEX
;
2076 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2077 "sides-supported", 3, NULL
, sides
);
2079 if (!strcasecmp(duplex
->defchoice
, "DuplexTumble"))
2080 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2081 "sides-default", NULL
, "two-sided-short-edge");
2082 else if (!strcasecmp(duplex
->defchoice
, "DuplexNoTumble"))
2083 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2084 "sides-default", NULL
, "two-sided-long-edge");
2086 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2087 "sides-default", NULL
, "one-sided");
2090 if (ppdFindOption(ppd
, "Collate") != NULL
)
2091 p
->type
|= CUPS_PRINTER_COLLATE
;
2093 if (ppdFindOption(ppd
, "StapleLocation") != NULL
)
2095 p
->type
|= CUPS_PRINTER_STAPLE
;
2096 finishings
[num_finishings
++] = IPP_FINISHINGS_STAPLE
;
2099 if (ppdFindOption(ppd
, "BindEdge") != NULL
)
2101 p
->type
|= CUPS_PRINTER_BIND
;
2102 finishings
[num_finishings
++] = IPP_FINISHINGS_BIND
;
2105 for (i
= 0; i
< ppd
->num_sizes
; i
++)
2106 if (ppd
->sizes
[i
].length
> 1728)
2107 p
->type
|= CUPS_PRINTER_LARGE
;
2108 else if (ppd
->sizes
[i
].length
> 1008)
2109 p
->type
|= CUPS_PRINTER_MEDIUM
;
2111 p
->type
|= CUPS_PRINTER_SMALL
;
2114 * Add a filter from application/vnd.cups-raw to printer/name to
2115 * handle "raw" printing by users.
2118 add_printer_filter(p
, p
->filetype
, "application/vnd.cups-raw 0 -");
2121 * Add any pre-filters in the PPD file...
2124 if ((ppdattr
= ppdFindAttr(ppd
, "cupsPreFilter", NULL
)) != NULL
)
2126 p
->prefiltertype
= mimeAddType(MimeDatabase
, "prefilter", p
->name
);
2128 for (; ppdattr
; ppdattr
= ppdFindNextAttr(ppd
, "cupsPreFilter", NULL
))
2130 add_printer_filter(p
, p
->prefiltertype
, ppdattr
->value
);
2134 * Add any filters in the PPD file...
2137 DEBUG_printf(("ppd->num_filters = %d\n", ppd
->num_filters
));
2138 for (i
= 0; i
< ppd
->num_filters
; i
++)
2140 DEBUG_printf(("ppd->filters[%d] = \"%s\"\n", i
, ppd
->filters
[i
]));
2141 add_printer_filter(p
, p
->filetype
, ppd
->filters
[i
]);
2144 if (ppd
->num_filters
== 0)
2147 * If there are no filters, add a PostScript printing filter.
2150 add_printer_filter(p
, p
->filetype
,
2151 "application/vnd.cups-postscript 0 -");
2155 * Show current and available port monitors for this printer...
2158 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
, "port-monitor",
2159 NULL
, p
->port_monitor
? p
->port_monitor
: "none");
2162 for (i
= 1, ppdattr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
2164 i
++, ppdattr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
));
2168 if (strstr(ppd
->protocols
, "TBCP"))
2170 else if (strstr(ppd
->protocols
, "BCP"))
2174 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2175 "port-monitor-supported", i
, NULL
, NULL
);
2177 attr
->values
[0].string
.text
= _cupsStrAlloc("none");
2179 for (i
= 1, ppdattr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
2181 i
++, ppdattr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
))
2182 attr
->values
[i
].string
.text
= _cupsStrAlloc(ppdattr
->value
);
2186 if (strstr(ppd
->protocols
, "TBCP"))
2187 attr
->values
[i
].string
.text
= _cupsStrAlloc("tbcp");
2188 else if (strstr(ppd
->protocols
, "BCP"))
2189 attr
->values
[i
].string
.text
= _cupsStrAlloc("bcp");
2193 cupsdSetString(&p
->product
, ppd
->product
);
2194 #endif /* HAVE_DNSSD */
2196 #if BONJOUR_IS_REMOTE
2197 ppdattr
= ppdFindAttr(ppd
, "APRemoteQueueID", NULL
);
2198 #endif /* BONJOUR_IS_REMOTE */
2201 * Close the PPD and set the type...
2206 printer_type
= p
->type
;
2208 #if BONJOUR_IS_REMOTE
2212 * This is a shared Bonjour printer...
2215 printer_type
|= CUPS_PRINTER_REMOTE
;
2217 #endif /* BONJOUR_IS_REMOTE */
2219 else if (!access(filename
, 0))
2221 int pline
; /* PPD line number */
2222 ppd_status_t pstatus
; /* PPD load status */
2225 pstatus
= ppdLastError(&pline
);
2227 cupsdLogMessage(CUPSD_LOG_ERROR
, "PPD file for %s cannot be loaded!",
2230 if (pstatus
<= PPD_ALLOC_ERROR
)
2231 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s", strerror(errno
));
2233 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s on line %d.",
2234 ppdErrorString(pstatus
), pline
);
2236 cupsdLogMessage(CUPSD_LOG_INFO
,
2237 "Hint: Run \"cupstestppd %s\" and fix any errors.",
2241 * Add a filter from application/vnd.cups-raw to printer/name to
2242 * handle "raw" printing by users.
2245 add_printer_filter(p
, p
->filetype
, "application/vnd.cups-raw 0 -");
2248 * Add a PostScript filter, since this is still possibly PS printer.
2251 add_printer_filter(p
, p
->filetype
,
2252 "application/vnd.cups-postscript 0 -");
2257 * If we have an interface script, add a filter entry for it...
2260 snprintf(filename
, sizeof(filename
), "%s/interfaces/%s", ServerRoot
,
2262 if (!access(filename
, X_OK
))
2265 * Yes, we have a System V style interface script; use it!
2268 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
2269 "printer-make-and-model", NULL
,
2270 "Local System V Printer");
2272 snprintf(filename
, sizeof(filename
), "*/* 0 %s/interfaces/%s",
2273 ServerRoot
, p
->name
);
2274 add_printer_filter(p
, p
->filetype
, filename
);
2276 else if (p
->device_uri
&&
2277 !strncmp(p
->device_uri
, "ipp://", 6) &&
2278 (strstr(p
->device_uri
, "/printers/") != NULL
||
2279 strstr(p
->device_uri
, "/classes/") != NULL
))
2282 * Tell the client this is really a hard-wired remote printer.
2285 printer_type
|= CUPS_PRINTER_REMOTE
;
2288 * Point the printer-uri-supported attribute to the
2292 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
2293 "printer-uri-supported", NULL
, p
->device_uri
);
2296 * Then set the make-and-model accordingly...
2299 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
2300 "printer-make-and-model", NULL
, "Remote Printer");
2303 * Print all files directly...
2312 * Otherwise we have neither - treat this as a "dumb" printer
2313 * with no PPD file...
2316 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
2317 "printer-make-and-model", NULL
, "Local Raw Printer");
2323 ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
2324 "finishings-supported", num_finishings
, finishings
);
2325 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
2326 "finishings-default", IPP_FINISHINGS_NONE
);
2331 * Save the local printer type value, which may have the CUPS_PRINTER_REMOTE
2332 * bit set. We use this value when sending the printer-type attribute to
2333 * clients so they know whether the printer is really remote. Doing it
2334 * this way prevents the browsing code from timing out hardwired remote
2338 p
->external_type
= printer_type
;
2341 * Copy the printer options into a browse attributes string we can re-use.
2344 if (!(printer_type
& CUPS_PRINTER_REMOTE
))
2346 const char *valptr
; /* Pointer into value */
2347 char *attrptr
; /* Pointer into attribute string */
2351 * Free the old browse attributes as needed...
2354 if (p
->browse_attrs
)
2355 free(p
->browse_attrs
);
2358 * Compute the length of all attributes + job-sheets, lease-duration,
2359 * and BrowseLocalOptions.
2362 for (length
= 1, i
= p
->num_options
, option
= p
->options
;
2366 length
+= strlen(option
->name
) + 2;
2370 for (valptr
= option
->value
; *valptr
; valptr
++)
2371 if (strchr(" \"\'\\", *valptr
))
2378 length
+= 13 + strlen(p
->job_sheets
[0]) + strlen(p
->job_sheets
[1]);
2380 if (BrowseLocalOptions
)
2381 length
+= 12 + strlen(BrowseLocalOptions
);
2383 if (p
->num_auth_info_required
> 0)
2385 length
+= 18; /* auth-info-required */
2387 for (i
= 0; i
< p
->num_auth_info_required
; i
++)
2388 length
+= strlen(p
->auth_info_required
[i
]) + 1;
2392 * Allocate the new string...
2395 if ((p
->browse_attrs
= calloc(1, length
)) == NULL
)
2396 cupsdLogMessage(CUPSD_LOG_ERROR
,
2397 "Unable to allocate %d bytes for browse data!",
2402 * Got the allocated string, now copy the options and attributes over...
2405 sprintf(p
->browse_attrs
, "job-sheets=%s,%s lease-duration=%d",
2406 p
->job_sheets
[0], p
->job_sheets
[1], BrowseTimeout
);
2407 attrptr
= p
->browse_attrs
+ strlen(p
->browse_attrs
);
2409 if (BrowseLocalOptions
)
2411 sprintf(attrptr
, " ipp-options=%s", BrowseLocalOptions
);
2412 attrptr
+= strlen(attrptr
);
2415 for (i
= p
->num_options
, option
= p
->options
;
2420 strcpy(attrptr
, option
->name
);
2421 attrptr
+= strlen(attrptr
);
2427 for (valptr
= option
->value
; *valptr
; valptr
++)
2429 if (strchr(" \"\'\\", *valptr
))
2432 *attrptr
++ = *valptr
;
2437 if (p
->num_auth_info_required
> 0)
2439 strcpy(attrptr
, "auth-info-required");
2442 for (i
= 0; i
< p
->num_auth_info_required
; i
++)
2444 *attrptr
++ = i
? ',' : '=';
2445 strcpy(attrptr
, p
->auth_info_required
[i
]);
2446 attrptr
+= strlen(attrptr
);
2455 * Populate the document-format-supported attribute...
2458 add_printer_formats(p
);
2460 DEBUG_printf(("cupsdSetPrinterAttrs: leaving name = %s, type = %x\n", p
->name
,
2464 * Add name-default attributes...
2467 add_printer_defaults(p
);
2471 * Write the IRIX printer config and status files...
2474 write_irix_config(p
);
2475 write_irix_state(p
);
2479 * Let the browse protocols reflect the change
2482 cupsdRegisterPrinter(p
);
2487 * 'cupsdSetPrinterReasons()' - Set/update the reasons strings.
2491 cupsdSetPrinterReasons(
2492 cupsd_printer_t
*p
, /* I - Printer */
2493 const char *s
) /* I - Reasons strings */
2495 int i
; /* Looping var */
2496 const char *sptr
; /* Pointer into reasons */
2497 char reason
[255], /* Reason string */
2498 *rptr
; /* Pointer into reason */
2501 if (s
[0] == '-' || s
[0] == '+')
2504 * Add/remove reasons...
2512 * Replace reasons...
2517 for (i
= 0; i
< p
->num_reasons
; i
++)
2518 free(p
->reasons
[i
]);
2524 * Loop through all of the reasons...
2530 * Skip leading whitespace and commas...
2533 while (isspace(*sptr
& 255) || *sptr
== ',')
2536 for (rptr
= reason
; *sptr
&& !isspace(*sptr
& 255) && *sptr
!= ','; sptr
++)
2537 if (rptr
< (reason
+ sizeof(reason
) - 1))
2551 for (i
= 0; i
< p
->num_reasons
; i
++)
2552 if (!strcasecmp(reason
, p
->reasons
[i
]))
2555 * Found a match, so remove it...
2559 free(p
->reasons
[i
]);
2561 if (i
< p
->num_reasons
)
2562 memmove(p
->reasons
+ i
, p
->reasons
+ i
+ 1,
2563 (p
->num_reasons
- i
) * sizeof(char *));
2567 if (!strcmp(reason
, "paused") && p
->state
== IPP_PRINTER_STOPPED
)
2568 cupsdSetPrinterState(p
, IPP_PRINTER_IDLE
, 1);
2571 else if (p
->num_reasons
< (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
2577 for (i
= 0; i
< p
->num_reasons
; i
++)
2578 if (!strcasecmp(reason
, p
->reasons
[i
]))
2581 if (i
>= p
->num_reasons
)
2583 p
->reasons
[i
] = strdup(reason
);
2586 if (!strcmp(reason
, "paused") && p
->state
!= IPP_PRINTER_STOPPED
)
2587 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, 1);
2595 * 'cupsdSetPrinterState()' - Update the current state of a printer.
2599 cupsdSetPrinterState(
2600 cupsd_printer_t
*p
, /* I - Printer to change */
2601 ipp_pstate_t s
, /* I - New state */
2602 int update
) /* I - Update printers.conf? */
2604 ipp_pstate_t old_state
; /* Old printer state */
2608 * Can't set status of remote printers...
2611 if (p
->type
& CUPS_PRINTER_REMOTE
)
2615 * Set the new state...
2618 old_state
= p
->state
;
2623 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE_CHANGED
, p
, NULL
,
2624 "%s \"%s\" state changed.",
2625 (p
->type
& CUPS_PRINTER_CLASS
) ? "Class" : "Printer",
2629 * Let the browse code know this needs to be updated...
2633 p
->state_time
= time(NULL
);
2637 write_irix_state(p
);
2641 cupsdAddPrinterHistory(p
);
2644 * Let the browse protocols reflect the change...
2647 cupsdRegisterPrinter(p
);
2650 * Save the printer configuration if a printer goes from idle or processing
2651 * to stopped (or visa-versa)...
2654 if ((old_state
== IPP_PRINTER_STOPPED
) != (s
== IPP_PRINTER_STOPPED
) &&
2657 if (p
->type
& CUPS_PRINTER_CLASS
)
2658 cupsdSaveAllClasses();
2660 cupsdSaveAllPrinters();
2666 * 'cupsdStopPrinter()' - Stop a printer from printing any jobs...
2670 cupsdStopPrinter(cupsd_printer_t
*p
, /* I - Printer to stop */
2671 int update
)/* I - Update printers.conf? */
2673 cupsd_job_t
*job
; /* Active print job */
2677 * Set the printer state...
2680 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, update
);
2683 * See if we have a job printing on this printer...
2689 * Get pointer to job...
2692 job
= (cupsd_job_t
*)p
->job
;
2698 cupsdStopJob(job
, 0);
2701 * Reset the state to pending...
2704 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
2705 job
->state_value
= IPP_JOB_PENDING
;
2709 cupsdAddEvent(CUPSD_EVENT_JOB_STOPPED
, p
, job
,
2710 "Job stopped due to printer being paused");
2716 * 'cupsdUpdatePrinters()' - Update printers after a partial reload.
2720 cupsdUpdatePrinters(void)
2722 cupsd_printer_t
*p
; /* Current printer */
2726 * Loop through the printers and recreate the printer attributes
2727 * for any local printers since the policy and/or access control
2728 * stuff may have changed. Also, if browsing is disabled, remove
2729 * any remote printers...
2732 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
2734 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
2737 * Remove remote printers if we are no longer browsing...
2740 if (!Browsing
&& (p
->type
& (CUPS_PRINTER_IMPLICIT
| CUPS_PRINTER_REMOTE
)))
2742 if (p
->type
& CUPS_PRINTER_IMPLICIT
)
2743 cupsArrayRemove(ImplicitPrinters
, p
);
2745 cupsArraySave(Printers
);
2746 cupsdDeletePrinter(p
, 0);
2747 cupsArrayRestore(Printers
);
2752 * Update the operation policy pointer...
2755 if ((p
->op_policy_ptr
= cupsdFindPolicy(p
->op_policy
)) == NULL
)
2756 p
->op_policy_ptr
= DefaultPolicyPtr
;
2759 * Update printer attributes as needed...
2762 if (!(p
->type
& CUPS_PRINTER_REMOTE
))
2763 cupsdSetPrinterAttrs(p
);
2769 * 'cupsdValidateDest()' - Validate a printer/class destination.
2772 const char * /* O - Printer or class name */
2774 const char *uri
, /* I - Printer URI */
2775 cups_ptype_t
*dtype
, /* O - Type (printer or class) */
2776 cupsd_printer_t
**printer
) /* O - Printer pointer */
2778 cupsd_printer_t
*p
; /* Current printer */
2779 char localname
[1024],/* Localized hostname */
2780 *lptr
, /* Pointer into localized hostname */
2781 *sptr
, /* Pointer into server name */
2782 *rptr
, /* Pointer into resource */
2783 scheme
[32], /* Scheme portion of URI */
2784 username
[64], /* Username portion of URI */
2785 hostname
[HTTP_MAX_HOST
],
2786 /* Host portion of URI */
2787 resource
[HTTP_MAX_URI
];
2788 /* Resource portion of URI */
2789 int port
; /* Port portion of URI */
2792 DEBUG_printf(("cupsdValidateDest(uri=\"%s\", dtype=%p, printer=%p)\n", uri
,
2796 * Initialize return values...
2803 *dtype
= (cups_ptype_t
)0;
2806 * Pull the hostname and resource from the URI...
2809 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
, scheme
, sizeof(scheme
),
2810 username
, sizeof(username
), hostname
, sizeof(hostname
),
2811 &port
, resource
, sizeof(resource
));
2814 * See if the resource is a class or printer...
2817 if (!strncmp(resource
, "/classes/", 9))
2823 rptr
= resource
+ 9;
2825 else if (!strncmp(resource
, "/printers/", 10))
2831 rptr
= resource
+ 10;
2836 * Bad resource name...
2843 * See if the printer or class name exists...
2846 p
= cupsdFindDest(rptr
);
2848 if (p
== NULL
&& strchr(rptr
, '@') == NULL
)
2856 *dtype
= p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
|
2857 CUPS_PRINTER_REMOTE
);
2863 * Change localhost to the server name...
2866 if (!strcasecmp(hostname
, "localhost"))
2867 strlcpy(hostname
, ServerName
, sizeof(hostname
));
2869 strlcpy(localname
, hostname
, sizeof(localname
));
2871 if (!strcasecmp(hostname
, ServerName
))
2874 * Localize the hostname...
2877 lptr
= strchr(localname
, '.');
2878 sptr
= strchr(ServerName
, '.');
2880 if (sptr
!= NULL
&& lptr
!= NULL
)
2883 * Strip the common domain name components...
2886 while (lptr
!= NULL
)
2888 if (!strcasecmp(lptr
, sptr
))
2894 lptr
= strchr(lptr
+ 1, '.');
2899 DEBUG_printf(("localized hostname is \"%s\"...\n", localname
));
2902 * Find a matching printer or class...
2905 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
2907 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
2908 if (!strcasecmp(p
->hostname
, localname
) &&
2909 !strcasecmp(p
->name
, rptr
))
2915 *dtype
= p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
|
2916 CUPS_PRINTER_REMOTE
);
2926 * 'cupsdWritePrintcap()' - Write a pseudo-printcap file for older applications
2931 cupsdWritePrintcap(void)
2933 cups_file_t
*fp
; /* printcap file */
2934 cupsd_printer_t
*p
; /* Current printer */
2939 * Update the IRIX printer state for the default printer; if
2940 * no printers remain, then the default printer file will be
2944 write_irix_state(DefaultPrinter
);
2948 * See if we have a printcap file; if not, don't bother writing it.
2951 if (!Printcap
|| !*Printcap
)
2955 * Open the printcap file...
2958 if ((fp
= cupsFileOpen(Printcap
, "w")) == NULL
)
2962 * Put a comment header at the top so that users will know where the
2963 * data has come from...
2966 cupsFilePuts(fp
, "# This file was automatically generated by cupsd(8) from the\n");
2967 cupsFilePrintf(fp
, "# %s/printers.conf file. All changes to this file\n",
2969 cupsFilePuts(fp
, "# will be lost.\n");
2974 * Write a new printcap with the current list of printers.
2977 switch (PrintcapFormat
)
2981 * Each printer is put in the file as:
2991 cupsFilePrintf(fp
, "%s|%s:rm=%s:rp=%s:\n", DefaultPrinter
->name
,
2992 DefaultPrinter
->info
, ServerName
, DefaultPrinter
->name
);
2994 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
2996 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
2997 if (p
!= DefaultPrinter
)
2998 cupsFilePrintf(fp
, "%s|%s:rm=%s:rp=%s:\n", p
->name
, p
->info
,
2999 ServerName
, p
->name
);
3002 case PRINTCAP_SOLARIS
:
3004 * Each printer is put in the file as:
3006 * _all:all=Printer1,Printer2,Printer3,...,PrinterN
3007 * _default:use=DefaultPrinter
3009 * :bsdaddr=ServerName,Printer1:\
3010 * :description=Description:
3012 * :bsdaddr=ServerName,Printer2:\
3013 * :description=Description:
3015 * :bsdaddr=ServerName,Printer3:\
3016 * :description=Description:
3019 * :bsdaddr=ServerName,PrinterN:\
3020 * :description=Description:
3023 cupsFilePuts(fp
, "_all:all=");
3024 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3026 p
= (cupsd_printer_t
*)cupsArrayCurrent(Printers
))
3027 cupsFilePrintf(fp
, "%s%c", p
->name
,
3028 cupsArrayNext(Printers
) ? ',' : '\n');
3031 cupsFilePrintf(fp
, "_default:use=%s\n", DefaultPrinter
->name
);
3033 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3035 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3036 cupsFilePrintf(fp
, "%s:\\\n"
3037 "\t:bsdaddr=%s,%s:\\\n"
3038 "\t:description=%s:\n",
3039 p
->name
, ServerName
, p
->name
, p
->info
? p
->info
: "");
3053 * 'cupsdSanitizeURI()' - Sanitize a device URI...
3056 char * /* O - New device URI */
3057 cupsdSanitizeURI(const char *uri
, /* I - Original device URI */
3058 char *buffer
, /* O - New device URI */
3059 int buflen
) /* I - Size of new device URI buffer */
3061 char *start
, /* Start of data after scheme */
3062 *slash
, /* First slash after scheme:// */
3063 *ptr
; /* Pointer into user@host:port part */
3067 * Range check input...
3070 if (!uri
|| !buffer
|| buflen
< 2)
3074 * Copy the device URI to the new buffer...
3077 strlcpy(buffer
, uri
, buflen
);
3080 * Find the end of the scheme:// part...
3083 if ((ptr
= strchr(buffer
, ':')) == NULL
)
3084 return (buffer
); /* No scheme: part... */
3086 for (start
= ptr
+ 1; *start
; start
++)
3091 * Find the next slash (/) in the URI...
3094 if ((slash
= strchr(start
, '/')) == NULL
)
3095 slash
= start
+ strlen(start
); /* No slash, point to the end */
3098 * Check for an @ sign before the slash...
3101 if ((ptr
= strchr(start
, '@')) != NULL
&& ptr
< slash
)
3104 * Found an @ sign and it is before the resource part, so we have
3105 * an authentication string. Copy the remaining URI over the
3106 * authentication string...
3109 _cups_strcpy(start
, ptr
+ 1);
3113 * Return the new device URI...
3121 * 'add_printer_defaults()' - Add name-default attributes to the printer attributes.
3125 add_printer_defaults(cupsd_printer_t
*p
)/* I - Printer */
3127 int i
; /* Looping var */
3128 int num_options
; /* Number of default options */
3129 cups_option_t
*options
, /* Default options */
3130 *option
; /* Current option */
3131 char name
[256]; /* name-default */
3135 * Maintain a common array of default attribute names...
3138 if (!CommonDefaults
)
3140 CommonDefaults
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
3142 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("copies-default"));
3143 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("document-format-default"));
3144 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("finishings-default"));
3145 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-hold-until-default"));
3146 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-priority-default"));
3147 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-sheets-default"));
3148 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("media-default"));
3149 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("number-up-default"));
3150 cupsArrayAdd(CommonDefaults
,
3151 _cupsStrAlloc("orientation-requested-default"));
3152 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("sides-default"));
3156 * Add all of the default options from the .conf files...
3159 for (num_options
= 0, i
= p
->num_options
, option
= p
->options
;
3163 if (strcmp(option
->name
, "ipp-options") &&
3164 strcmp(option
->name
, "job-sheets") &&
3165 strcmp(option
->name
, "lease-duration"))
3167 snprintf(name
, sizeof(name
), "%s-default", option
->name
);
3168 num_options
= cupsAddOption(name
, option
->value
, num_options
, &options
);
3170 if (!cupsArrayFind(CommonDefaults
, name
))
3171 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc(name
));
3176 * Convert options to IPP attributes...
3179 cupsEncodeOptions2(p
->attrs
, num_options
, options
, IPP_TAG_PRINTER
);
3180 cupsFreeOptions(num_options
, options
);
3183 * Add standard -default attributes as needed...
3186 if (!cupsGetOption("copies", p
->num_options
, p
->options
))
3187 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
, "copies-default",
3190 if (!cupsGetOption("document-format", p
->num_options
, p
->options
))
3191 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_MIMETYPE
,
3192 "document-format-default", NULL
, "application/octet-stream");
3194 if (!cupsGetOption("job-hold-until", p
->num_options
, p
->options
))
3195 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3196 "job-hold-until-default", NULL
, "no-hold");
3198 if (!cupsGetOption("job-priority", p
->num_options
, p
->options
))
3199 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3200 "job-priority-default", 50);
3202 if (!cupsGetOption("number-up", p
->num_options
, p
->options
))
3203 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3204 "number-up-default", 1);
3206 if (!cupsGetOption("orientation-requested", p
->num_options
, p
->options
))
3207 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
3208 "orientation-requested-default", IPP_PORTRAIT
);
3210 if (!cupsGetOption("notify-lease-duration", p
->num_options
, p
->options
))
3211 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3212 "notify-lease-duration-default", DefaultLeaseDuration
);
3214 if (!cupsGetOption("notify-events", p
->num_options
, p
->options
))
3215 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3216 "notify-events-default", NULL
, "job-completed");
3221 * 'add_printer_filter()' - Add a MIME filter for a printer.
3226 cupsd_printer_t
*p
, /* I - Printer to add to */
3227 mime_type_t
*filtertype
, /* I - Filter or prefilter MIME type */
3228 const char *filter
) /* I - Filter to add */
3230 char super
[MIME_MAX_SUPER
], /* Super-type for filter */
3231 type
[MIME_MAX_TYPE
], /* Type for filter */
3232 program
[1024]; /* Program/filter name */
3233 int cost
; /* Cost of filter */
3234 mime_type_t
*temptype
; /* MIME type looping var */
3235 char filename
[1024]; /* Full filter filename */
3239 * Parse the filter string; it should be in the following format:
3241 * super/type cost program
3244 if (sscanf(filter
, "%15[^/]/%31s%d%1023s", super
, type
, &cost
, program
) != 4)
3246 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: invalid filter string \"%s\"!",
3252 * See if the filter program exists; if not, stop the printer and flag
3256 if (strcmp(program
, "-"))
3258 if (program
[0] == '/')
3259 strlcpy(filename
, program
, sizeof(filename
));
3261 snprintf(filename
, sizeof(filename
), "%s/filter/%s", ServerBin
, program
);
3263 if (access(filename
, X_OK
))
3265 snprintf(p
->state_message
, sizeof(p
->state_message
),
3266 "Filter \"%s\" for printer \"%s\" not available: %s",
3267 program
, p
->name
, strerror(errno
));
3268 cupsdSetPrinterReasons(p
, "+cups-missing-filter-error");
3269 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, 0);
3271 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s", p
->state_message
);
3276 * Mark the CUPS_PRINTER_COMMANDS bit if we have a filter for
3277 * application/vnd.cups-command...
3280 if (!strcasecmp(super
, "application") &&
3281 !strcasecmp(type
, "vnd.cups-command"))
3282 p
->type
|= CUPS_PRINTER_COMMANDS
;
3285 * Add the filter to the MIME database, supporting wildcards as needed...
3288 for (temptype
= mimeFirstType(MimeDatabase
);
3290 temptype
= mimeNextType(MimeDatabase
))
3291 if (((super
[0] == '*' && strcasecmp(temptype
->super
, "printer")) ||
3292 !strcasecmp(temptype
->super
, super
)) &&
3293 (type
[0] == '*' || !strcasecmp(temptype
->type
, type
)))
3295 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3296 "add_printer_filter: %s: adding filter %s/%s %s/%s %d %s",
3297 p
->name
, temptype
->super
, temptype
->type
,
3298 filtertype
->super
, filtertype
->type
,
3300 mimeAddFilter(MimeDatabase
, temptype
, filtertype
, cost
, program
);
3306 * 'add_printer_formats()' - Add document-format-supported values for a printer.
3310 add_printer_formats(cupsd_printer_t
*p
) /* I - Printer */
3312 int i
; /* Looping var */
3313 mime_type_t
*type
; /* Current MIME type */
3314 cups_array_t
*filters
; /* Filters */
3315 ipp_attribute_t
*attr
; /* document-format-supported attribute */
3316 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
3317 /* MIME type name */
3321 * Raw (and remote) queues advertise all of the supported MIME
3325 cupsArrayDelete(p
->filetypes
);
3326 p
->filetypes
= NULL
;
3330 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
,
3331 (ipp_tag_t
)(IPP_TAG_MIMETYPE
| IPP_TAG_COPY
),
3332 "document-format-supported", NumMimeTypes
, NULL
, MimeTypes
);
3337 * Otherwise, loop through the supported MIME types and see if there
3338 * are filters for them...
3341 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_printer_formats: %d types, %d filters",
3342 mimeNumTypes(MimeDatabase
), mimeNumFilters(MimeDatabase
));
3344 p
->filetypes
= cupsArrayNew(NULL
, NULL
);
3346 for (type
= mimeFirstType(MimeDatabase
);
3348 type
= mimeNextType(MimeDatabase
))
3350 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
3352 if ((filters
= mimeFilter(MimeDatabase
, type
, p
->filetype
, NULL
)) != NULL
)
3354 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3355 "add_printer_formats: %s: %s needs %d filters",
3356 p
->name
, mimetype
, cupsArrayCount(filters
));
3358 cupsArrayDelete(filters
);
3359 cupsArrayAdd(p
->filetypes
, type
);
3362 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3363 "add_printer_formats: %s: %s not supported",
3367 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3368 "add_printer_formats: %s: %d supported types",
3369 p
->name
, cupsArrayCount(p
->filetypes
) + 1);
3372 * Add the file formats that can be filtered...
3375 if ((type
= mimeType(MimeDatabase
, "application", "octet-stream")) == NULL
||
3376 !cupsArrayFind(p
->filetypes
, type
))
3381 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_MIMETYPE
,
3382 "document-format-supported",
3383 cupsArrayCount(p
->filetypes
) + 1, NULL
, NULL
);
3386 attr
->values
[0].string
.text
= _cupsStrAlloc("application/octet-stream");
3388 for (type
= (mime_type_t
*)cupsArrayFirst(p
->filetypes
);
3390 i
++, type
= (mime_type_t
*)cupsArrayNext(p
->filetypes
))
3392 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
3394 attr
->values
[i
].string
.text
= _cupsStrAlloc(mimetype
);
3399 char pdl
[1024]; /* Buffer to build pdl list */
3400 mime_filter_t
*filter
; /* MIME filter looping var */
3405 if (mimeType(MimeDatabase
, "application", "pdf"))
3406 strlcat(pdl
, "application/pdf,", sizeof(pdl
));
3408 if (mimeType(MimeDatabase
, "application", "postscript"))
3409 strlcat(pdl
, "application/postscript,", sizeof(pdl
));
3411 if (mimeType(MimeDatabase
, "application", "vnd.cups-raster"))
3412 strlcat(pdl
, "application/vnd.cups-raster,", sizeof(pdl
));
3415 * Determine if this is a Tioga PrintJobMgr based queue...
3418 for (filter
= (mime_filter_t
*)cupsArrayFirst(MimeDatabase
->filters
);
3420 filter
= (mime_filter_t
*)cupsArrayNext(MimeDatabase
->filters
))
3422 if (filter
->dst
== p
->filetype
&& filter
->filter
&&
3423 strstr(filter
->filter
, "PrintJobMgr"))
3428 * We only support raw printing if this is not a Tioga PrintJobMgr based
3429 * queue and if application/octet-stream is a known conversion...
3432 if (!filter
&& mimeType(MimeDatabase
, "application", "octet-stream"))
3433 strlcat(pdl
, "application/octet-stream,", sizeof(pdl
));
3435 if (mimeType(MimeDatabase
, "image", "png"))
3436 strlcat(pdl
, "image/png,", sizeof(pdl
));
3439 pdl
[strlen(pdl
) - 1] = '\0'; /* Remove trailing comma */
3441 cupsdSetString(&p
->pdl
, pdl
);
3443 #endif /* HAVE_DNSSD */
3448 * 'compare_printers()' - Compare two printers.
3451 static int /* O - Result of comparison */
3452 compare_printers(void *first
, /* I - First printer */
3453 void *second
, /* I - Second printer */
3454 void *data
) /* I - App data (not used) */
3456 return (strcasecmp(((cupsd_printer_t
*)first
)->name
,
3457 ((cupsd_printer_t
*)second
)->name
));
3462 * 'delete_printer_filters()' - Delete all MIME filters for a printer.
3466 delete_printer_filters(
3467 cupsd_printer_t
*p
) /* I - Printer to remove from */
3469 mime_filter_t
*filter
; /* MIME filter looping var */
3473 * Range check input...
3480 * Remove all filters from the MIME database that have a destination
3481 * type == printer...
3484 for (filter
= mimeFirstFilter(MimeDatabase
);
3486 filter
= mimeNextFilter(MimeDatabase
))
3487 if (filter
->dst
== p
->filetype
)
3490 * Delete the current filter...
3493 mimeDeleteFilter(MimeDatabase
, filter
);
3500 * 'write_irix_config()' - Update the config files used by the IRIX
3505 write_irix_config(cupsd_printer_t
*p
) /* I - Printer to update */
3507 char filename
[1024]; /* Interface script filename */
3508 cups_file_t
*fp
; /* Interface script file */
3509 ipp_attribute_t
*attr
; /* Attribute data */
3513 * Add dummy interface and GUI scripts to fool SGI's "challenged" printing
3514 * tools. First the interface script that tells the tools what kind of
3515 * printer we have...
3518 snprintf(filename
, sizeof(filename
), "/var/spool/lp/interface/%s", p
->name
);
3520 if (p
->type
& CUPS_PRINTER_CLASS
)
3522 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
3524 cupsFilePuts(fp
, "#!/bin/sh\n");
3526 if ((attr
= ippFindAttribute(p
->attrs
, "printer-make-and-model",
3527 IPP_TAG_TEXT
)) != NULL
)
3528 cupsFilePrintf(fp
, "NAME=\"%s\"\n", attr
->values
[0].string
.text
);
3529 else if (p
->type
& CUPS_PRINTER_CLASS
)
3530 cupsFilePuts(fp
, "NAME=\"Printer Class\"\n");
3532 cupsFilePuts(fp
, "NAME=\"Remote Destination\"\n");
3534 if (p
->type
& CUPS_PRINTER_COLOR
)
3535 cupsFilePuts(fp
, "TYPE=ColorPostScript\n");
3537 cupsFilePuts(fp
, "TYPE=MonoPostScript\n");
3539 cupsFilePrintf(fp
, "HOSTNAME=%s\n", ServerName
);
3540 cupsFilePrintf(fp
, "HOSTPRINTER=%s\n", p
->name
);
3544 chmod(filename
, 0755);
3545 chown(filename
, User
, Group
);
3549 * Then the member file that tells which device file the queue is connected
3550 * to... Networked printers use "/dev/null" in this file, so that's what
3551 * we use (the actual device URI can confuse some apps...)
3554 snprintf(filename
, sizeof(filename
), "/var/spool/lp/member/%s", p
->name
);
3556 if (p
->type
& CUPS_PRINTER_CLASS
)
3558 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
3560 cupsFilePuts(fp
, "/dev/null\n");
3564 chmod(filename
, 0644);
3565 chown(filename
, User
, Group
);
3569 * The gui_interface file is a script or program that launches a GUI
3570 * option panel for the printer, using options specified on the
3571 * command-line in the third argument. The option panel must send
3572 * any printing options to stdout on a single line when the user
3573 * accepts them, or nothing if the user cancels the dialog.
3575 * The default options panel program is /usr/bin/glpoptions, from
3576 * the ESP Print Pro software. You can select another using the
3577 * PrintcapGUI option.
3580 snprintf(filename
, sizeof(filename
), "/var/spool/lp/gui_interface/ELF/%s.gui", p
->name
);
3582 if (p
->type
& CUPS_PRINTER_CLASS
)
3584 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
3586 cupsFilePuts(fp
, "#!/bin/sh\n");
3587 cupsFilePrintf(fp
, "%s -d %s -o \"$3\"\n", PrintcapGUI
, p
->name
);
3591 chmod(filename
, 0755);
3592 chown(filename
, User
, Group
);
3596 * The POD config file is needed by the printstatus command to show
3597 * the printer location and device.
3600 snprintf(filename
, sizeof(filename
), "/var/spool/lp/pod/%s.config", p
->name
);
3602 if (p
->type
& CUPS_PRINTER_CLASS
)
3604 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
3606 cupsFilePrintf(fp
, "Printer Class | %s\n",
3607 (p
->type
& CUPS_PRINTER_COLOR
) ? "ColorPostScript" : "MonoPostScript");
3608 cupsFilePrintf(fp
, "Printer Model | %s\n", p
->make_model
? p
->make_model
: "");
3609 cupsFilePrintf(fp
, "Location Code | %s\n", p
->location
? p
->location
: "");
3610 cupsFilePrintf(fp
, "Physical Location | %s\n", p
->info
? p
->info
: "");
3611 cupsFilePrintf(fp
, "Port Path | %s\n", p
->device_uri
? p
->device_uri
: "");
3612 cupsFilePrintf(fp
, "Config Path | /var/spool/lp/pod/%s.config\n", p
->name
);
3613 cupsFilePrintf(fp
, "Active Status Path | /var/spool/lp/pod/%s.status\n", p
->name
);
3614 cupsFilePuts(fp
, "Status Update Wait | 10 seconds\n");
3618 chmod(filename
, 0664);
3619 chown(filename
, User
, Group
);
3625 * 'write_irix_state()' - Update the status files used by IRIX printing
3630 write_irix_state(cupsd_printer_t
*p
) /* I - Printer to update */
3632 char filename
[1024]; /* Interface script filename */
3633 cups_file_t
*fp
; /* Interface script file */
3634 int tag
; /* Status tag value */
3640 * The POD status file is needed for the printstatus window to
3641 * provide the current status of the printer.
3644 snprintf(filename
, sizeof(filename
), "/var/spool/lp/pod/%s.status", p
->name
);
3646 if (p
->type
& CUPS_PRINTER_CLASS
)
3648 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
3650 cupsFilePrintf(fp
, "Operational Status | %s\n",
3651 (p
->state
== IPP_PRINTER_IDLE
) ? "Idle" :
3652 (p
->state
== IPP_PRINTER_PROCESSING
) ? "Busy" :
3654 cupsFilePrintf(fp
, "Information | 01 00 00 | %s\n", CUPS_SVERSION
);
3655 cupsFilePrintf(fp
, "Information | 02 00 00 | Device URI: %s\n",
3656 p
->device_uri
? p
->device_uri
: "");
3657 cupsFilePrintf(fp
, "Information | 03 00 00 | %s jobs\n",
3658 p
->accepting
? "Accepting" : "Not accepting");
3659 cupsFilePrintf(fp
, "Information | 04 00 00 | %s\n", p
->state_message
);
3663 chmod(filename
, 0664);
3664 chown(filename
, User
, Group
);
3668 * The activeicons file is needed to provide desktop icons for printers:
3670 * [ quoted from /usr/lib/print/tagit ]
3672 * --- Type of printer tags (base values)
3674 * Dumb=66048 # 0x10200
3675 * DumbColor=66080 # 0x10220
3676 * Raster=66112 # 0x10240
3677 * ColorRaster=66144 # 0x10260
3678 * Plotter=66176 # 0x10280
3679 * PostScript=66208 # 0x102A0
3680 * ColorPostScript=66240 # 0x102C0
3681 * MonoPostScript=66272 # 0x102E0
3683 * --- Printer state modifiers for local printers
3688 * Unknown=3 # 0x3 (Faulted due to unknown reason)
3690 * --- Printer state modifiers for network printers
3694 * NetFaulted=10 # 0xA
3695 * NetUnknown=11 # 0xB (Faulted due to unknown reason)
3698 snprintf(filename
, sizeof(filename
), "/var/spool/lp/activeicons/%s", p
->name
);
3700 if (p
->type
& CUPS_PRINTER_CLASS
)
3702 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
3704 if (p
->type
& CUPS_PRINTER_COLOR
)
3709 if (p
->type
& CUPS_PRINTER_REMOTE
)
3712 if (p
->state
== IPP_PRINTER_PROCESSING
)
3715 else if (p
->state
== IPP_PRINTER_STOPPED
)
3718 cupsFilePuts(fp
, "#!/bin/sh\n");
3719 cupsFilePrintf(fp
, "#Tag %d\n", tag
);
3723 chmod(filename
, 0755);
3724 chown(filename
, User
, Group
);
3729 * The default file is needed by the printers window to show
3730 * the default printer.
3733 snprintf(filename
, sizeof(filename
), "/var/spool/lp/default");
3735 if (DefaultPrinter
!= NULL
)
3737 if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
3739 cupsFilePrintf(fp
, "%s\n", DefaultPrinter
->name
);
3743 chmod(filename
, 0644);
3744 chown(filename
, User
, Group
);
3754 * End of "$Id: printers.c 6539 2007-05-23 15:08:29Z mike $".