2 * "$Id: printers.c 6595 2007-06-21 22:29:57Z 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 * cupsdSetAuthInfoRequired() - Set the required authentication info.
39 * cupsdSetPrinterAttrs() - Set printer attributes based upon the PPD
41 * cupsdSetPrinterReasons() - Set/update the reasons strings.
42 * cupsdSetPrinterState() - Update the current state of a printer.
43 * cupsdStopPrinter() - Stop a printer from printing any jobs...
44 * cupsdUpdatePrinters() - Update printers after a partial reload.
45 * cupsdValidateDest() - Validate a printer/class destination.
46 * cupsdWritePrintcap() - Write a pseudo-printcap file for older
47 * applications that need it...
48 * cupsdSanitizeURI() - Sanitize a device URI...
49 * add_printer_defaults() - Add name-default attributes to the printer
51 * add_printer_filter() - Add a MIME filter for a printer.
52 * add_printer_formats() - Add document-format-supported values for
54 * compare_printers() - Compare two printers.
55 * delete_printer_filters() - Delete all MIME filters for a printer.
56 * write_irix_config() - Update the config files used by the IRIX
58 * write_irix_state() - Update the status files used by IRIX
59 * printing desktop tools.
63 * Include necessary headers...
74 static void add_printer_defaults(cupsd_printer_t
*p
);
75 static void add_printer_filter(cupsd_printer_t
*p
, mime_type_t
*type
,
77 static void add_printer_formats(cupsd_printer_t
*p
);
78 static int compare_printers(void *first
, void *second
, void *data
);
79 static void delete_printer_filters(cupsd_printer_t
*p
);
81 static void write_irix_config(cupsd_printer_t
*p
);
82 static void write_irix_state(cupsd_printer_t
*p
);
87 * 'cupsdAddPrinter()' - Add a printer to the system.
90 cupsd_printer_t
* /* O - New printer */
91 cupsdAddPrinter(const char *name
) /* I - Name of printer */
93 cupsd_printer_t
*p
; /* New printer */
97 * Range check input...
100 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdAddPrinter(\"%s\")", name
);
103 * Create a new printer entity...
106 if ((p
= calloc(1, sizeof(cupsd_printer_t
))) == NULL
)
108 cupsdLogMessage(CUPSD_LOG_CRIT
, "Unable to allocate memory for printer - %s",
113 cupsdSetString(&p
->name
, name
);
114 cupsdSetString(&p
->info
, name
);
115 cupsdSetString(&p
->hostname
, ServerName
);
117 cupsdSetStringf(&p
->uri
, "ipp://%s:%d/printers/%s", ServerName
, LocalPort
, name
);
118 cupsdSetStringf(&p
->device_uri
, "file:/dev/null");
120 p
->state
= IPP_PRINTER_STOPPED
;
121 p
->state_time
= time(NULL
);
123 p
->shared
= DefaultShared
;
124 p
->filetype
= mimeAddType(MimeDatabase
, "printer", name
);
126 cupsdSetString(&p
->job_sheets
[0], "none");
127 cupsdSetString(&p
->job_sheets
[1], "none");
129 cupsdSetString(&p
->error_policy
, ErrorPolicy
);
130 cupsdSetString(&p
->op_policy
, DefaultPolicy
);
132 p
->op_policy_ptr
= DefaultPolicyPtr
;
134 if (MaxPrinterHistory
)
135 p
->history
= calloc(MaxPrinterHistory
, sizeof(ipp_t
*));
138 * Insert the printer in the printer list alphabetically...
142 Printers
= cupsArrayNew(compare_printers
, NULL
);
144 cupsArrayAdd(Printers
, p
);
146 if (!ImplicitPrinters
)
147 ImplicitPrinters
= cupsArrayNew(compare_printers
, NULL
);
150 * Return the new printer...
158 * 'cupsdAddPrinterHistory()' - Add the current printer state to the history.
162 cupsdAddPrinterHistory(
163 cupsd_printer_t
*p
) /* I - Printer */
165 ipp_t
*history
; /* History collection */
169 * Stop early if we aren't keeping history data...
172 if (MaxPrinterHistory
<= 0)
176 * Retire old history data as needed...
179 p
->sequence_number
++;
181 if (p
->num_history
>= MaxPrinterHistory
)
184 ippDelete(p
->history
[0]);
185 memmove(p
->history
, p
->history
+ 1, p
->num_history
* sizeof(ipp_t
*));
189 * Create a collection containing the current printer-state, printer-up-time,
190 * printer-state-message, and printer-state-reasons attributes.
194 ippAddInteger(history
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-state",
196 ippAddBoolean(history
, IPP_TAG_PRINTER
, "printer-is-accepting-jobs",
198 ippAddBoolean(history
, IPP_TAG_PRINTER
, "printer-is-shared", p
->shared
);
199 ippAddString(history
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-state-message",
200 NULL
, p
->state_message
);
203 ippAddString(history
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
204 "com.apple.print.recoverable-message", NULL
, p
->recoverable
);
205 #endif /* __APPLE__ */
206 if (p
->num_reasons
== 0)
207 ippAddString(history
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
208 "printer-state-reasons", NULL
,
209 p
->state
== IPP_PRINTER_STOPPED
? "paused" : "none");
211 ippAddStrings(history
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
212 "printer-state-reasons", p
->num_reasons
, NULL
,
213 (const char * const *)p
->reasons
);
214 ippAddInteger(history
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
215 "printer-state-change-time", p
->state_time
);
216 ippAddInteger(history
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
217 "printer-state-sequence-number", p
->sequence_number
);
219 p
->history
[p
->num_history
] = history
;
225 * 'cupsdAddPrinterUser()' - Add a user to the ACL.
230 cupsd_printer_t
*p
, /* I - Printer */
231 const char *username
) /* I - User */
233 const char **temp
; /* Temporary array pointer */
239 if (p
->num_users
== 0)
240 temp
= malloc(sizeof(char **));
242 temp
= realloc(p
->users
, sizeof(char **) * (p
->num_users
+ 1));
248 temp
+= p
->num_users
;
250 if ((*temp
= strdup(username
)) != NULL
)
256 * 'cupsdCreateCommonData()' - Create the common printer data.
260 cupsdCreateCommonData(void)
262 int i
; /* Looping var */
263 ipp_attribute_t
*attr
; /* Attribute data */
264 cups_dir_t
*dir
; /* Notifier directory */
265 cups_dentry_t
*dent
; /* Notifier directory entry */
266 cups_array_t
*notifiers
; /* Notifier array */
267 char filename
[1024], /* Filename */
268 *notifier
; /* Current notifier */
269 static const int nups
[] = /* number-up-supported values */
270 { 1, 2, 4, 6, 9, 16 };
271 static const int orients
[4] =/* orientation-requested-supported values */
275 IPP_REVERSE_LANDSCAPE
,
278 static const char * const holds
[] = /* job-hold-until-supported values */
289 static const char * const versions
[] =/* ipp-versions-supported values */
294 static const int ops
[] = /* operations-supported values */
301 IPP_GET_JOB_ATTRIBUTES
,
303 IPP_GET_PRINTER_ATTRIBUTES
,
309 IPP_SET_JOB_ATTRIBUTES
,
310 IPP_CREATE_PRINTER_SUBSCRIPTION
,
311 IPP_CREATE_JOB_SUBSCRIPTION
,
312 IPP_GET_SUBSCRIPTION_ATTRIBUTES
,
313 IPP_GET_SUBSCRIPTIONS
,
314 IPP_RENEW_SUBSCRIPTION
,
315 IPP_CANCEL_SUBSCRIPTION
,
316 IPP_GET_NOTIFICATIONS
,
332 CUPS_AUTHENTICATE_JOB
,
335 static const char * const charsets
[] =/* charset-supported values */
340 static const char * const compressions
[] =
341 { /* document-compression-supported values */
345 #endif /* HAVE_LIBZ */
347 static const char * const multiple_document_handling
[] =
348 { /* multiple-document-handling-supported values */
349 "separate-documents-uncollated-copies",
350 "separate-documents-collated-copies"
352 static const char * const errors
[] = /* printer-error-policy-supported values */
358 static const char * const notify_attrs
[] =
359 { /* notify-attributes-supported values */
360 "printer-state-change-time",
361 "notify-lease-expiration-time",
362 "notify-subscriber-user-name"
364 static const char * const notify_events
[] =
365 { /* notify-events-supported values */
367 "job-config-changed",
374 "printer-config-changed",
376 "printer-finishings-changed",
377 "printer-media-changed",
381 "printer-state-changed",
391 ippDelete(CommonData
);
393 CommonData
= ippNew();
396 * This list of attributes is sorted to improve performance when the
397 * client provides a requested-attributes attribute...
400 /* charset-configured */
401 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_CHARSET
,
402 "charset-configured", NULL
, DefaultCharset
);
404 /* charset-supported */
405 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_CHARSET
,
406 "charset-supported", sizeof(charsets
) / sizeof(charsets
[0]),
409 /* compression-supported */
410 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
411 "compression-supported",
412 sizeof(compressions
) / sizeof(compressions
[0]),
415 /* copies-supported */
416 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "copies-supported", 1, MaxCopies
);
419 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "cups-version",
420 NULL
, CUPS_SVERSION
+ 6);
422 /* generated-natural-language-supported */
423 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_LANGUAGE
,
424 "generated-natural-language-supported", NULL
, DefaultLanguage
);
426 /* ipp-versions-supported */
427 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
428 "ipp-versions-supported", sizeof(versions
) / sizeof(versions
[0]),
431 /* job-hold-until-supported */
432 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
433 "job-hold-until-supported", sizeof(holds
) / sizeof(holds
[0]),
436 /* job-priority-supported */
437 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
438 "job-priority-supported", 100);
440 /* job-sheets-supported */
441 if (cupsArrayCount(Banners
) > 0)
444 * Setup the job-sheets-supported attribute...
447 if (Classification
&& !ClassifyOverride
)
448 attr
= ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
449 "job-sheets-supported", NULL
, Classification
);
451 attr
= ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
452 "job-sheets-supported", cupsArrayCount(Banners
) + 1,
456 cupsdLogMessage(CUPSD_LOG_EMERG
,
457 "Unable to allocate memory for "
458 "job-sheets-supported attribute: %s!", strerror(errno
));
459 else if (!Classification
|| ClassifyOverride
)
461 cupsd_banner_t
*banner
; /* Current banner */
464 attr
->values
[0].string
.text
= _cupsStrAlloc("none");
466 for (i
= 1, banner
= (cupsd_banner_t
*)cupsArrayFirst(Banners
);
468 i
++, banner
= (cupsd_banner_t
*)cupsArrayNext(Banners
))
469 attr
->values
[i
].string
.text
= _cupsStrAlloc(banner
->name
);
473 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
474 "job-sheets-supported", NULL
, "none");
476 /* multiple-document-handling-supported */
477 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
478 "multiple-document-handling-supported",
479 sizeof(multiple_document_handling
) /
480 sizeof(multiple_document_handling
[0]), NULL
,
481 multiple_document_handling
);
483 /* multiple-document-jobs-supported */
484 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
,
485 "multiple-document-jobs-supported", 1);
487 /* multiple-operation-time-out */
488 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
489 "multiple-operation-time-out", 60);
491 /* natural-language-configured */
492 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_LANGUAGE
,
493 "natural-language-configured", NULL
, DefaultLanguage
);
495 /* notify-attributes-supported */
496 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
497 "notify-attributes-supported",
498 (int)(sizeof(notify_attrs
) / sizeof(notify_attrs
[0])),
501 /* notify-lease-duration-supported */
502 ippAddRange(CommonData
, IPP_TAG_PRINTER
,
503 "notify-lease-duration-supported", 0,
504 MaxLeaseDuration
? MaxLeaseDuration
: 2147483647);
506 /* notify-max-events-supported */
507 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
508 "notify-max-events-supported", MaxEvents
);
510 /* notify-events-supported */
511 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
512 "notify-events-supported",
513 (int)(sizeof(notify_events
) / sizeof(notify_events
[0])),
514 NULL
, notify_events
);
516 /* notify-pull-method-supported */
517 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
518 "notify-pull-method-supported", NULL
, "ippget");
520 /* notify-schemes-supported */
521 snprintf(filename
, sizeof(filename
), "%s/notifier", ServerBin
);
522 if ((dir
= cupsDirOpen(filename
)) != NULL
)
524 notifiers
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
526 while ((dent
= cupsDirRead(dir
)) != NULL
)
527 if (S_ISREG(dent
->fileinfo
.st_mode
) &&
528 (dent
->fileinfo
.st_mode
& S_IXOTH
) != 0)
529 cupsArrayAdd(notifiers
, _cupsStrAlloc(dent
->filename
));
531 if (cupsArrayCount(notifiers
) > 0)
533 attr
= ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
534 "notify-schemes-supported",
535 cupsArrayCount(notifiers
), NULL
, NULL
);
537 for (i
= 0, notifier
= (char *)cupsArrayFirst(notifiers
);
539 i
++, notifier
= (char *)cupsArrayNext(notifiers
))
540 attr
->values
[i
].string
.text
= notifier
;
543 cupsArrayDelete(notifiers
);
547 /* number-up-supported */
548 ippAddIntegers(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
549 "number-up-supported", sizeof(nups
) / sizeof(nups
[0]), nups
);
551 /* operations-supported */
552 ippAddIntegers(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
553 "operations-supported",
554 sizeof(ops
) / sizeof(ops
[0]) + JobFiles
- 1, ops
);
556 /* orientation-requested-supported */
557 ippAddIntegers(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
558 "orientation-requested-supported", 4, orients
);
560 /* page-ranges-supported */
561 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
, "page-ranges-supported", 1);
563 /* pdf-override-supported */
564 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
565 "pdl-override-supported", NULL
, "not-attempted");
567 /* printer-error-policy-supported */
568 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
569 "printer-error-policy-supported",
570 sizeof(errors
) / sizeof(errors
[0]), NULL
, errors
);
572 /* printer-op-policy-supported */
573 attr
= ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
574 "printer-op-policy-supported", NumPolicies
, NULL
, NULL
);
575 for (i
= 0; i
< NumPolicies
; i
++)
576 attr
->values
[i
].string
.text
= _cupsStrAlloc(Policies
[i
]->name
);
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
++;
1553 else if ((end
- values
) == 6 && !strncmp(values
, "domain", 6))
1555 p
->auth_info_required
[p
->num_auth_info_required
] = "domain";
1556 p
->num_auth_info_required
++;
1558 else if ((end
- values
) == 8 && !strncmp(values
, "password", 8))
1560 p
->auth_info_required
[p
->num_auth_info_required
] = "password";
1561 p
->num_auth_info_required
++;
1563 else if ((end
- values
) == 8 && !strncmp(values
, "username", 8))
1565 p
->auth_info_required
[p
->num_auth_info_required
] = "username";
1566 p
->num_auth_info_required
++;
1571 values
= (*end
) ? end
+ 1 : end
;
1574 if (p
->num_auth_info_required
== 0)
1576 p
->auth_info_required
[0] = "none";
1577 p
->num_auth_info_required
= 1;
1581 * Update the printer-type value as needed...
1584 if (p
->num_auth_info_required
> 1 ||
1585 strcmp(p
->auth_info_required
[0], "none"))
1586 p
->type
|= CUPS_PRINTER_AUTHENTICATED
;
1588 p
->type
&= ~CUPS_PRINTER_AUTHENTICATED
;
1594 * Grab values from an attribute instead...
1597 if (!attr
|| attr
->num_values
> 4)
1601 * Update the printer-type value as needed...
1604 if (attr
->num_values
> 1 ||
1605 strcmp(attr
->values
[0].string
.text
, "none"))
1606 p
->type
|= CUPS_PRINTER_AUTHENTICATED
;
1608 p
->type
&= ~CUPS_PRINTER_AUTHENTICATED
;
1610 for (i
= 0; i
< attr
->num_values
; i
++)
1612 if (!strcmp(attr
->values
[i
].string
.text
, "none"))
1614 if (p
->num_auth_info_required
!= 0 || attr
->num_values
!= 1)
1617 p
->auth_info_required
[p
->num_auth_info_required
] = "none";
1618 p
->num_auth_info_required
++;
1622 else if (!strcmp(attr
->values
[i
].string
.text
, "negotiate"))
1624 if (p
->num_auth_info_required
!= 0 || attr
->num_values
!= 1)
1627 p
->auth_info_required
[p
->num_auth_info_required
] = "negotiate";
1628 p
->num_auth_info_required
++;
1632 else if (!strcmp(attr
->values
[i
].string
.text
, "domain"))
1634 p
->auth_info_required
[p
->num_auth_info_required
] = "domain";
1635 p
->num_auth_info_required
++;
1637 else if (!strcmp(attr
->values
[i
].string
.text
, "password"))
1639 p
->auth_info_required
[p
->num_auth_info_required
] = "password";
1640 p
->num_auth_info_required
++;
1642 else if (!strcmp(attr
->values
[i
].string
.text
, "username"))
1644 p
->auth_info_required
[p
->num_auth_info_required
] = "username";
1645 p
->num_auth_info_required
++;
1656 * 'cupsdSetPrinterAttrs()' - Set printer attributes based upon the PPD file.
1660 cupsdSetPrinterAttrs(cupsd_printer_t
*p
)/* I - Printer to setup */
1662 int i
, /* Looping var */
1663 length
; /* Length of browse attributes */
1664 char uri
[HTTP_MAX_URI
]; /* URI for printer */
1665 char resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
1666 char filename
[1024]; /* Name of PPD file */
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"
1691 DEBUG_printf(("cupsdSetPrinterAttrs: entering name = %s, type = %x\n", p
->name
,
1695 * Make sure that we have the common attributes defined...
1699 cupsdCreateCommonData();
1702 * Clear out old filters, if any...
1705 delete_printer_filters(p
);
1708 * Figure out the authentication that is required for the printer.
1711 auth_supported
= "requesting-user-name";
1712 if (!(p
->type
& CUPS_PRINTER_DISCOVERED
))
1714 if (p
->type
& CUPS_PRINTER_CLASS
)
1715 snprintf(resource
, sizeof(resource
), "/classes/%s", p
->name
);
1717 snprintf(resource
, sizeof(resource
), "/printers/%s", p
->name
);
1719 if ((auth
= cupsdFindBest(resource
, HTTP_POST
)) == NULL
||
1720 auth
->type
== AUTH_NONE
)
1721 auth
= cupsdFindPolicyOp(p
->op_policy_ptr
, IPP_PRINT_JOB
);
1725 if (auth
->type
== AUTH_BASIC
|| auth
->type
== AUTH_BASICDIGEST
)
1727 auth_supported
= "basic";
1728 cupsdSetAuthInfoRequired(p
, "username,password", NULL
);
1730 else if (auth
->type
== AUTH_DIGEST
)
1732 auth_supported
= "digest";
1733 cupsdSetAuthInfoRequired(p
, "username,password", NULL
);
1736 else if (auth
->type
== AUTH_NEGOTIATE
)
1738 auth_supported
= "negotiate";
1739 cupsdSetAuthInfoRequired(p
, "negotiate", NULL
);
1741 #endif /* HAVE_GSSAPI */
1743 if (auth
->type
!= AUTH_NONE
)
1744 p
->type
|= CUPS_PRINTER_AUTHENTICATED
;
1746 p
->type
&= ~CUPS_PRINTER_AUTHENTICATED
;
1749 p
->type
&= ~CUPS_PRINTER_AUTHENTICATED
;
1753 * Create the required IPP attributes for a printer...
1757 ippDelete(p
->attrs
);
1759 p
->attrs
= ippNew();
1761 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
1762 "uri-authentication-supported", NULL
, auth_supported
);
1763 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
1764 "uri-security-supported", NULL
, "none");
1765 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
, "printer-name", NULL
,
1767 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-location",
1768 NULL
, p
->location
? p
->location
: "");
1769 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-info",
1770 NULL
, p
->info
? p
->info
: "");
1771 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "printer-more-info",
1777 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
1778 "requesting-user-name-denied", p
->num_users
, NULL
,
1781 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
1782 "requesting-user-name-allowed", p
->num_users
, NULL
,
1786 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
1787 "job-quota-period", p
->quota_period
);
1788 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
1789 "job-k-limit", p
->k_limit
);
1790 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
1791 "job-page-limit", p
->page_limit
);
1792 if (p
->num_auth_info_required
)
1793 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
1794 "auth-info-required", p
->num_auth_info_required
,
1795 NULL
, p
->auth_info_required
);
1797 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
1798 "auth-info-required", NULL
, "none");
1800 if (cupsArrayCount(Banners
) > 0 && !(p
->type
& CUPS_PRINTER_DISCOVERED
))
1803 * Setup the job-sheets-default attribute...
1806 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
1807 "job-sheets-default", 2, NULL
, NULL
);
1811 attr
->values
[0].string
.text
= _cupsStrAlloc(Classification
?
1812 Classification
: p
->job_sheets
[0]);
1813 attr
->values
[1].string
.text
= _cupsStrAlloc(Classification
?
1814 Classification
: p
->job_sheets
[1]);
1821 if (p
->type
& CUPS_PRINTER_DISCOVERED
)
1824 * Tell the client this is a remote printer of some type...
1827 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
1828 "printer-uri-supported", NULL
, p
->uri
);
1831 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
1832 "printer-make-and-model", NULL
, p
->make_model
);
1834 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "device-uri", NULL
,
1843 * Assign additional attributes depending on whether this is a printer
1847 p
->type
&= ~CUPS_PRINTER_OPTIONS
;
1849 if (p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
))
1854 * Add class-specific attributes...
1857 if ((p
->type
& CUPS_PRINTER_IMPLICIT
) && p
->num_printers
> 0 &&
1858 p
->printers
[0]->make_model
)
1859 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
1860 "printer-make-and-model", NULL
, p
->printers
[0]->make_model
);
1862 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
1863 "printer-make-and-model", NULL
, "Local Printer Class");
1865 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "device-uri", NULL
,
1866 "file:///dev/null");
1868 if (p
->num_printers
> 0)
1871 * Add a list of member URIs and names...
1874 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
1875 "member-uris", p
->num_printers
, NULL
, NULL
);
1876 p
->type
|= CUPS_PRINTER_OPTIONS
;
1878 for (i
= 0; i
< p
->num_printers
; i
++)
1881 attr
->values
[i
].string
.text
= _cupsStrAlloc(p
->printers
[i
]->uri
);
1883 p
->type
&= ~CUPS_PRINTER_OPTIONS
| p
->printers
[i
]->type
;
1886 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
1887 "member-names", p
->num_printers
, NULL
, NULL
);
1891 for (i
= 0; i
< p
->num_printers
; i
++)
1892 attr
->values
[i
].string
.text
= _cupsStrAlloc(p
->printers
[i
]->name
);
1899 * Add printer-specific attributes... Start by sanitizing the device
1900 * URI so it doesn't have a username or password in it...
1904 strcpy(uri
, "file:/dev/null");
1905 else if (strstr(p
->device_uri
, "://") != NULL
)
1908 * http://..., ipp://..., etc.
1911 cupsdSanitizeURI(p
->device_uri
, uri
, sizeof(uri
));
1916 * file:..., serial:..., etc.
1919 strlcpy(uri
, p
->device_uri
, sizeof(uri
));
1922 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "device-uri", NULL
,
1926 * Assign additional attributes from the PPD file (if any)...
1929 p
->type
|= CUPS_PRINTER_BW
;
1930 finishings
[0] = IPP_FINISHINGS_NONE
;
1933 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
1936 if ((ppd
= ppdOpenFile(filename
)) != NULL
)
1939 * Add make/model and other various attributes...
1942 if (ppd
->color_device
)
1943 p
->type
|= CUPS_PRINTER_COLOR
;
1944 if (ppd
->variable_sizes
)
1945 p
->type
|= CUPS_PRINTER_VARIABLE
;
1946 if (!ppd
->manual_copies
)
1947 p
->type
|= CUPS_PRINTER_COPIES
;
1948 if ((ppdattr
= ppdFindAttr(ppd
, "cupsFax", NULL
)) != NULL
)
1949 if (ppdattr
->value
&& !strcasecmp(ppdattr
->value
, "true"))
1950 p
->type
|= CUPS_PRINTER_FAX
;
1952 ippAddBoolean(p
->attrs
, IPP_TAG_PRINTER
, "color-supported",
1954 if (ppd
->throughput
)
1955 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
1956 "pages-per-minute", ppd
->throughput
);
1961 * The NickName can be localized in the character set specified
1962 * by the LanugageEncoding attribute. However, ppdOpen2() has
1963 * already converted the ppd->nickname member to UTF-8 for us
1964 * (the original attribute value is available separately)
1967 cupsdSetString(&p
->make_model
, ppd
->nickname
);
1969 else if (ppd
->modelname
)
1972 * Model name can only contain specific characters...
1975 cupsdSetString(&p
->make_model
, ppd
->modelname
);
1978 cupsdSetString(&p
->make_model
, "Bad PPD File");
1980 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
1981 "printer-make-and-model", NULL
, p
->make_model
);
1984 * Add media options from the PPD file...
1987 if ((input_slot
= ppdFindOption(ppd
, "InputSlot")) != NULL
)
1988 num_media
= input_slot
->num_choices
;
1992 if ((media_type
= ppdFindOption(ppd
, "MediaType")) != NULL
)
1993 num_media
+= media_type
->num_choices
;
1995 if ((page_size
= ppdFindOption(ppd
, "PageSize")) != NULL
)
1996 num_media
+= page_size
->num_choices
;
1998 if ((media_quality
= ppdFindOption(ppd
, "EFMediaQualityMode")) != NULL
)
1999 num_media
+= media_quality
->num_choices
;
2003 cupsdLogMessage(CUPSD_LOG_CRIT
,
2004 "The PPD file for printer %s contains no media "
2005 "options and is therefore invalid!", p
->name
);
2009 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2010 "media-supported", num_media
, NULL
, NULL
);
2015 if (input_slot
!= NULL
)
2016 for (i
= 0; i
< input_slot
->num_choices
; i
++, val
++)
2017 val
->string
.text
= _cupsStrAlloc(input_slot
->choices
[i
].choice
);
2019 if (media_type
!= NULL
)
2020 for (i
= 0; i
< media_type
->num_choices
; i
++, val
++)
2021 val
->string
.text
= _cupsStrAlloc(media_type
->choices
[i
].choice
);
2023 if (media_quality
!= NULL
)
2024 for (i
= 0; i
< media_quality
->num_choices
; i
++, val
++)
2025 val
->string
.text
= _cupsStrAlloc(media_quality
->choices
[i
].choice
);
2027 if (page_size
!= NULL
)
2029 for (i
= 0; i
< page_size
->num_choices
; i
++, val
++)
2030 val
->string
.text
= _cupsStrAlloc(page_size
->choices
[i
].choice
);
2032 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2033 "media-default", NULL
, page_size
->defchoice
);
2035 else if (input_slot
!= NULL
)
2036 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2037 "media-default", NULL
, input_slot
->defchoice
);
2038 else if (media_type
!= NULL
)
2039 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2040 "media-default", NULL
, media_type
->defchoice
);
2041 else if (media_quality
!= NULL
)
2042 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2043 "media-default", NULL
, media_quality
->defchoice
);
2045 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2046 "media-default", NULL
, "none");
2054 if ((output_bin
= ppdFindOption(ppd
, "OutputBin")) != NULL
)
2056 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2057 "output-bin-supported", output_bin
->num_choices
,
2062 for (i
= 0, val
= attr
->values
;
2063 i
< output_bin
->num_choices
;
2065 val
->string
.text
= _cupsStrAlloc(output_bin
->choices
[i
].choice
);
2073 if ((duplex
= ppdFindOption(ppd
, "Duplex")) == NULL
)
2074 if ((duplex
= ppdFindOption(ppd
, "EFDuplex")) == NULL
)
2075 if ((duplex
= ppdFindOption(ppd
, "EFDuplexing")) == NULL
)
2076 if ((duplex
= ppdFindOption(ppd
, "KD03Duplex")) == NULL
)
2077 duplex
= ppdFindOption(ppd
, "JCLDuplex");
2079 if (duplex
&& duplex
->num_choices
> 1)
2081 p
->type
|= CUPS_PRINTER_DUPLEX
;
2083 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2084 "sides-supported", 3, NULL
, sides
);
2086 if (!strcasecmp(duplex
->defchoice
, "DuplexTumble"))
2087 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2088 "sides-default", NULL
, "two-sided-short-edge");
2089 else if (!strcasecmp(duplex
->defchoice
, "DuplexNoTumble"))
2090 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2091 "sides-default", NULL
, "two-sided-long-edge");
2093 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2094 "sides-default", NULL
, "one-sided");
2097 if (ppdFindOption(ppd
, "Collate") != NULL
)
2098 p
->type
|= CUPS_PRINTER_COLLATE
;
2100 if (ppdFindOption(ppd
, "StapleLocation") != NULL
)
2102 p
->type
|= CUPS_PRINTER_STAPLE
;
2103 finishings
[num_finishings
++] = IPP_FINISHINGS_STAPLE
;
2106 if (ppdFindOption(ppd
, "BindEdge") != NULL
)
2108 p
->type
|= CUPS_PRINTER_BIND
;
2109 finishings
[num_finishings
++] = IPP_FINISHINGS_BIND
;
2112 for (i
= 0; i
< ppd
->num_sizes
; i
++)
2113 if (ppd
->sizes
[i
].length
> 1728)
2114 p
->type
|= CUPS_PRINTER_LARGE
;
2115 else if (ppd
->sizes
[i
].length
> 1008)
2116 p
->type
|= CUPS_PRINTER_MEDIUM
;
2118 p
->type
|= CUPS_PRINTER_SMALL
;
2121 * Add a filter from application/vnd.cups-raw to printer/name to
2122 * handle "raw" printing by users.
2125 add_printer_filter(p
, p
->filetype
, "application/vnd.cups-raw 0 -");
2128 * Add any pre-filters in the PPD file...
2131 if ((ppdattr
= ppdFindAttr(ppd
, "cupsPreFilter", NULL
)) != NULL
)
2133 p
->prefiltertype
= mimeAddType(MimeDatabase
, "prefilter", p
->name
);
2135 for (; ppdattr
; ppdattr
= ppdFindNextAttr(ppd
, "cupsPreFilter", NULL
))
2137 add_printer_filter(p
, p
->prefiltertype
, ppdattr
->value
);
2141 * Add any filters in the PPD file...
2144 DEBUG_printf(("ppd->num_filters = %d\n", ppd
->num_filters
));
2145 for (i
= 0; i
< ppd
->num_filters
; i
++)
2147 DEBUG_printf(("ppd->filters[%d] = \"%s\"\n", i
, ppd
->filters
[i
]));
2148 add_printer_filter(p
, p
->filetype
, ppd
->filters
[i
]);
2151 if (ppd
->num_filters
== 0)
2154 * If there are no filters, add a PostScript printing filter.
2157 add_printer_filter(p
, p
->filetype
,
2158 "application/vnd.cups-postscript 0 -");
2162 * Show current and available port monitors for this printer...
2165 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
, "port-monitor",
2166 NULL
, p
->port_monitor
? p
->port_monitor
: "none");
2168 for (i
= 1, ppdattr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
2170 i
++, ppdattr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
));
2174 if (strstr(ppd
->protocols
, "TBCP"))
2176 else if (strstr(ppd
->protocols
, "BCP"))
2180 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2181 "port-monitor-supported", i
, NULL
, NULL
);
2183 attr
->values
[0].string
.text
= _cupsStrAlloc("none");
2185 for (i
= 1, ppdattr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
2187 i
++, ppdattr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
))
2188 attr
->values
[i
].string
.text
= _cupsStrAlloc(ppdattr
->value
);
2192 if (strstr(ppd
->protocols
, "TBCP"))
2193 attr
->values
[i
].string
.text
= _cupsStrAlloc("tbcp");
2194 else if (strstr(ppd
->protocols
, "BCP"))
2195 attr
->values
[i
].string
.text
= _cupsStrAlloc("bcp");
2199 cupsdSetString(&p
->product
, ppd
->product
);
2200 #endif /* HAVE_DNSSD */
2202 if (ppdFindAttr(ppd
, "APRemoteQueueID", NULL
))
2203 p
->type
|= CUPS_PRINTER_REMOTE
;
2206 * Close the PPD and set the type...
2211 else if (!access(filename
, 0))
2213 int pline
; /* PPD line number */
2214 ppd_status_t pstatus
; /* PPD load status */
2217 pstatus
= ppdLastError(&pline
);
2219 cupsdLogMessage(CUPSD_LOG_ERROR
, "PPD file for %s cannot be loaded!",
2222 if (pstatus
<= PPD_ALLOC_ERROR
)
2223 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s", strerror(errno
));
2225 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s on line %d.",
2226 ppdErrorString(pstatus
), pline
);
2228 cupsdLogMessage(CUPSD_LOG_INFO
,
2229 "Hint: Run \"cupstestppd %s\" and fix any errors.",
2233 * Add a filter from application/vnd.cups-raw to printer/name to
2234 * handle "raw" printing by users.
2237 add_printer_filter(p
, p
->filetype
, "application/vnd.cups-raw 0 -");
2240 * Add a PostScript filter, since this is still possibly PS printer.
2243 add_printer_filter(p
, p
->filetype
,
2244 "application/vnd.cups-postscript 0 -");
2249 * If we have an interface script, add a filter entry for it...
2252 snprintf(filename
, sizeof(filename
), "%s/interfaces/%s", ServerRoot
,
2254 if (!access(filename
, X_OK
))
2257 * Yes, we have a System V style interface script; use it!
2260 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
2261 "printer-make-and-model", NULL
,
2262 "Local System V Printer");
2264 snprintf(filename
, sizeof(filename
), "*/* 0 %s/interfaces/%s",
2265 ServerRoot
, p
->name
);
2266 add_printer_filter(p
, p
->filetype
, filename
);
2268 else if (p
->device_uri
&&
2269 !strncmp(p
->device_uri
, "ipp://", 6) &&
2270 (strstr(p
->device_uri
, "/printers/") != NULL
||
2271 strstr(p
->device_uri
, "/classes/") != NULL
))
2274 * Tell the client this is really a hard-wired remote printer.
2277 p
->type
|= CUPS_PRINTER_REMOTE
;
2280 * Point the printer-uri-supported attribute to the
2284 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
2285 "printer-uri-supported", NULL
, p
->device_uri
);
2288 * Then set the make-and-model accordingly...
2291 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
2292 "printer-make-and-model", NULL
, "Remote Printer");
2295 * Print all files directly...
2304 * Otherwise we have neither - treat this as a "dumb" printer
2305 * with no PPD file...
2308 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
2309 "printer-make-and-model", NULL
, "Local Raw Printer");
2315 ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
2316 "finishings-supported", num_finishings
, finishings
);
2317 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
2318 "finishings-default", IPP_FINISHINGS_NONE
);
2323 * Copy the printer options into a browse attributes string we can re-use.
2326 if (!(p
->type
& CUPS_PRINTER_DISCOVERED
))
2328 const char *valptr
; /* Pointer into value */
2329 char *attrptr
; /* Pointer into attribute string */
2333 * Free the old browse attributes as needed...
2336 if (p
->browse_attrs
)
2337 free(p
->browse_attrs
);
2340 * Compute the length of all attributes + job-sheets, lease-duration,
2341 * and BrowseLocalOptions.
2344 for (length
= 1, i
= p
->num_options
, option
= p
->options
;
2348 length
+= strlen(option
->name
) + 2;
2352 for (valptr
= option
->value
; *valptr
; valptr
++)
2353 if (strchr(" \"\'\\", *valptr
))
2360 length
+= 13 + strlen(p
->job_sheets
[0]) + strlen(p
->job_sheets
[1]);
2362 if (BrowseLocalOptions
)
2363 length
+= 12 + strlen(BrowseLocalOptions
);
2365 if (p
->num_auth_info_required
> 0)
2367 length
+= 18; /* auth-info-required */
2369 for (i
= 0; i
< p
->num_auth_info_required
; i
++)
2370 length
+= strlen(p
->auth_info_required
[i
]) + 1;
2374 * Allocate the new string...
2377 if ((p
->browse_attrs
= calloc(1, length
)) == NULL
)
2378 cupsdLogMessage(CUPSD_LOG_ERROR
,
2379 "Unable to allocate %d bytes for browse data!",
2384 * Got the allocated string, now copy the options and attributes over...
2387 sprintf(p
->browse_attrs
, "job-sheets=%s,%s lease-duration=%d",
2388 p
->job_sheets
[0], p
->job_sheets
[1], BrowseTimeout
);
2389 attrptr
= p
->browse_attrs
+ strlen(p
->browse_attrs
);
2391 if (BrowseLocalOptions
)
2393 sprintf(attrptr
, " ipp-options=%s", BrowseLocalOptions
);
2394 attrptr
+= strlen(attrptr
);
2397 for (i
= p
->num_options
, option
= p
->options
;
2402 strcpy(attrptr
, option
->name
);
2403 attrptr
+= strlen(attrptr
);
2409 for (valptr
= option
->value
; *valptr
; valptr
++)
2411 if (strchr(" \"\'\\", *valptr
))
2414 *attrptr
++ = *valptr
;
2419 if (p
->num_auth_info_required
> 0)
2421 strcpy(attrptr
, "auth-info-required");
2424 for (i
= 0; i
< p
->num_auth_info_required
; i
++)
2426 *attrptr
++ = i
? ',' : '=';
2427 strcpy(attrptr
, p
->auth_info_required
[i
]);
2428 attrptr
+= strlen(attrptr
);
2437 * Populate the document-format-supported attribute...
2440 add_printer_formats(p
);
2442 DEBUG_printf(("cupsdSetPrinterAttrs: leaving name = %s, type = %x\n", p
->name
,
2446 * Add name-default attributes...
2449 add_printer_defaults(p
);
2453 * Write the IRIX printer config and status files...
2456 write_irix_config(p
);
2457 write_irix_state(p
);
2461 * Let the browse protocols reflect the change
2464 cupsdRegisterPrinter(p
);
2469 * 'cupsdSetPrinterReasons()' - Set/update the reasons strings.
2473 cupsdSetPrinterReasons(
2474 cupsd_printer_t
*p
, /* I - Printer */
2475 const char *s
) /* I - Reasons strings */
2477 int i
; /* Looping var */
2478 const char *sptr
; /* Pointer into reasons */
2479 char reason
[255], /* Reason string */
2480 *rptr
; /* Pointer into reason */
2483 if (s
[0] == '-' || s
[0] == '+')
2486 * Add/remove reasons...
2494 * Replace reasons...
2499 for (i
= 0; i
< p
->num_reasons
; i
++)
2500 free(p
->reasons
[i
]);
2506 * Loop through all of the reasons...
2512 * Skip leading whitespace and commas...
2515 while (isspace(*sptr
& 255) || *sptr
== ',')
2518 for (rptr
= reason
; *sptr
&& !isspace(*sptr
& 255) && *sptr
!= ','; sptr
++)
2519 if (rptr
< (reason
+ sizeof(reason
) - 1))
2533 for (i
= 0; i
< p
->num_reasons
; i
++)
2534 if (!strcasecmp(reason
, p
->reasons
[i
]))
2537 * Found a match, so remove it...
2541 free(p
->reasons
[i
]);
2543 if (i
< p
->num_reasons
)
2544 memmove(p
->reasons
+ i
, p
->reasons
+ i
+ 1,
2545 (p
->num_reasons
- i
) * sizeof(char *));
2549 if (!strcmp(reason
, "paused") && p
->state
== IPP_PRINTER_STOPPED
)
2550 cupsdSetPrinterState(p
, IPP_PRINTER_IDLE
, 1);
2553 else if (p
->num_reasons
< (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
2559 for (i
= 0; i
< p
->num_reasons
; i
++)
2560 if (!strcasecmp(reason
, p
->reasons
[i
]))
2563 if (i
>= p
->num_reasons
)
2565 p
->reasons
[i
] = strdup(reason
);
2568 if (!strcmp(reason
, "paused") && p
->state
!= IPP_PRINTER_STOPPED
)
2569 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, 1);
2577 * 'cupsdSetPrinterState()' - Update the current state of a printer.
2581 cupsdSetPrinterState(
2582 cupsd_printer_t
*p
, /* I - Printer to change */
2583 ipp_pstate_t s
, /* I - New state */
2584 int update
) /* I - Update printers.conf? */
2586 ipp_pstate_t old_state
; /* Old printer state */
2590 * Can't set status of remote printers...
2593 if (p
->type
& CUPS_PRINTER_DISCOVERED
)
2597 * Set the new state...
2600 old_state
= p
->state
;
2605 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE_CHANGED
, p
, NULL
,
2606 "%s \"%s\" state changed.",
2607 (p
->type
& CUPS_PRINTER_CLASS
) ? "Class" : "Printer",
2611 * Let the browse code know this needs to be updated...
2615 p
->state_time
= time(NULL
);
2619 write_irix_state(p
);
2623 cupsdAddPrinterHistory(p
);
2626 * Let the browse protocols reflect the change...
2629 cupsdRegisterPrinter(p
);
2632 * Save the printer configuration if a printer goes from idle or processing
2633 * to stopped (or visa-versa)...
2636 if ((old_state
== IPP_PRINTER_STOPPED
) != (s
== IPP_PRINTER_STOPPED
) &&
2639 if (p
->type
& CUPS_PRINTER_CLASS
)
2640 cupsdSaveAllClasses();
2642 cupsdSaveAllPrinters();
2648 * 'cupsdStopPrinter()' - Stop a printer from printing any jobs...
2652 cupsdStopPrinter(cupsd_printer_t
*p
, /* I - Printer to stop */
2653 int update
)/* I - Update printers.conf? */
2655 cupsd_job_t
*job
; /* Active print job */
2659 * Set the printer state...
2662 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, update
);
2665 * See if we have a job printing on this printer...
2671 * Get pointer to job...
2674 job
= (cupsd_job_t
*)p
->job
;
2680 cupsdStopJob(job
, 0);
2683 * Reset the state to pending...
2686 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
2687 job
->state_value
= IPP_JOB_PENDING
;
2691 cupsdAddEvent(CUPSD_EVENT_JOB_STOPPED
, p
, job
,
2692 "Job stopped due to printer being paused");
2698 * 'cupsdUpdatePrinters()' - Update printers after a partial reload.
2702 cupsdUpdatePrinters(void)
2704 cupsd_printer_t
*p
; /* Current printer */
2708 * Loop through the printers and recreate the printer attributes
2709 * for any local printers since the policy and/or access control
2710 * stuff may have changed. Also, if browsing is disabled, remove
2711 * any remote printers...
2714 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
2716 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
2719 * Remove remote printers if we are no longer browsing...
2723 (p
->type
& (CUPS_PRINTER_IMPLICIT
| CUPS_PRINTER_DISCOVERED
)))
2725 if (p
->type
& CUPS_PRINTER_IMPLICIT
)
2726 cupsArrayRemove(ImplicitPrinters
, p
);
2728 cupsArraySave(Printers
);
2729 cupsdDeletePrinter(p
, 0);
2730 cupsArrayRestore(Printers
);
2735 * Update the operation policy pointer...
2738 if ((p
->op_policy_ptr
= cupsdFindPolicy(p
->op_policy
)) == NULL
)
2739 p
->op_policy_ptr
= DefaultPolicyPtr
;
2742 * Update printer attributes as needed...
2745 if (!(p
->type
& CUPS_PRINTER_DISCOVERED
))
2746 cupsdSetPrinterAttrs(p
);
2752 * 'cupsdValidateDest()' - Validate a printer/class destination.
2755 const char * /* O - Printer or class name */
2757 const char *uri
, /* I - Printer URI */
2758 cups_ptype_t
*dtype
, /* O - Type (printer or class) */
2759 cupsd_printer_t
**printer
) /* O - Printer pointer */
2761 cupsd_printer_t
*p
; /* Current printer */
2762 char localname
[1024],/* Localized hostname */
2763 *lptr
, /* Pointer into localized hostname */
2764 *sptr
, /* Pointer into server name */
2765 *rptr
, /* Pointer into resource */
2766 scheme
[32], /* Scheme portion of URI */
2767 username
[64], /* Username portion of URI */
2768 hostname
[HTTP_MAX_HOST
],
2769 /* Host portion of URI */
2770 resource
[HTTP_MAX_URI
];
2771 /* Resource portion of URI */
2772 int port
; /* Port portion of URI */
2775 DEBUG_printf(("cupsdValidateDest(uri=\"%s\", dtype=%p, printer=%p)\n", uri
,
2779 * Initialize return values...
2786 *dtype
= (cups_ptype_t
)0;
2789 * Pull the hostname and resource from the URI...
2792 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
, scheme
, sizeof(scheme
),
2793 username
, sizeof(username
), hostname
, sizeof(hostname
),
2794 &port
, resource
, sizeof(resource
));
2797 * See if the resource is a class or printer...
2800 if (!strncmp(resource
, "/classes/", 9))
2806 rptr
= resource
+ 9;
2808 else if (!strncmp(resource
, "/printers/", 10))
2814 rptr
= resource
+ 10;
2819 * Bad resource name...
2826 * See if the printer or class name exists...
2829 p
= cupsdFindDest(rptr
);
2831 if (p
== NULL
&& strchr(rptr
, '@') == NULL
)
2839 *dtype
= p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
|
2840 CUPS_PRINTER_REMOTE
| CUPS_PRINTER_DISCOVERED
);
2846 * Change localhost to the server name...
2849 if (!strcasecmp(hostname
, "localhost"))
2850 strlcpy(hostname
, ServerName
, sizeof(hostname
));
2852 strlcpy(localname
, hostname
, sizeof(localname
));
2854 if (!strcasecmp(hostname
, ServerName
))
2857 * Localize the hostname...
2860 lptr
= strchr(localname
, '.');
2861 sptr
= strchr(ServerName
, '.');
2863 if (sptr
!= NULL
&& lptr
!= NULL
)
2866 * Strip the common domain name components...
2869 while (lptr
!= NULL
)
2871 if (!strcasecmp(lptr
, sptr
))
2877 lptr
= strchr(lptr
+ 1, '.');
2882 DEBUG_printf(("localized hostname is \"%s\"...\n", localname
));
2885 * Find a matching printer or class...
2888 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
2890 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
2891 if (!strcasecmp(p
->hostname
, localname
) &&
2892 !strcasecmp(p
->name
, rptr
))
2898 *dtype
= p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
|
2899 CUPS_PRINTER_REMOTE
| CUPS_PRINTER_DISCOVERED
);
2909 * 'cupsdWritePrintcap()' - Write a pseudo-printcap file for older applications
2914 cupsdWritePrintcap(void)
2916 cups_file_t
*fp
; /* printcap file */
2917 cupsd_printer_t
*p
; /* Current printer */
2922 * Update the IRIX printer state for the default printer; if
2923 * no printers remain, then the default printer file will be
2927 write_irix_state(DefaultPrinter
);
2931 * See if we have a printcap file; if not, don't bother writing it.
2934 if (!Printcap
|| !*Printcap
)
2938 * Open the printcap file...
2941 if ((fp
= cupsFileOpen(Printcap
, "w")) == NULL
)
2945 * Put a comment header at the top so that users will know where the
2946 * data has come from...
2949 cupsFilePuts(fp
, "# This file was automatically generated by cupsd(8) from the\n");
2950 cupsFilePrintf(fp
, "# %s/printers.conf file. All changes to this file\n",
2952 cupsFilePuts(fp
, "# will be lost.\n");
2957 * Write a new printcap with the current list of printers.
2960 switch (PrintcapFormat
)
2964 * Each printer is put in the file as:
2974 cupsFilePrintf(fp
, "%s|%s:rm=%s:rp=%s:\n", DefaultPrinter
->name
,
2975 DefaultPrinter
->info
, ServerName
, DefaultPrinter
->name
);
2977 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
2979 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
2980 if (p
!= DefaultPrinter
)
2981 cupsFilePrintf(fp
, "%s|%s:rm=%s:rp=%s:\n", p
->name
, p
->info
,
2982 ServerName
, p
->name
);
2985 case PRINTCAP_SOLARIS
:
2987 * Each printer is put in the file as:
2989 * _all:all=Printer1,Printer2,Printer3,...,PrinterN
2990 * _default:use=DefaultPrinter
2992 * :bsdaddr=ServerName,Printer1:\
2993 * :description=Description:
2995 * :bsdaddr=ServerName,Printer2:\
2996 * :description=Description:
2998 * :bsdaddr=ServerName,Printer3:\
2999 * :description=Description:
3002 * :bsdaddr=ServerName,PrinterN:\
3003 * :description=Description:
3006 cupsFilePuts(fp
, "_all:all=");
3007 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3009 p
= (cupsd_printer_t
*)cupsArrayCurrent(Printers
))
3010 cupsFilePrintf(fp
, "%s%c", p
->name
,
3011 cupsArrayNext(Printers
) ? ',' : '\n');
3014 cupsFilePrintf(fp
, "_default:use=%s\n", DefaultPrinter
->name
);
3016 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3018 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3019 cupsFilePrintf(fp
, "%s:\\\n"
3020 "\t:bsdaddr=%s,%s:\\\n"
3021 "\t:description=%s:\n",
3022 p
->name
, ServerName
, p
->name
, p
->info
? p
->info
: "");
3036 * 'cupsdSanitizeURI()' - Sanitize a device URI...
3039 char * /* O - New device URI */
3040 cupsdSanitizeURI(const char *uri
, /* I - Original device URI */
3041 char *buffer
, /* O - New device URI */
3042 int buflen
) /* I - Size of new device URI buffer */
3044 char *start
, /* Start of data after scheme */
3045 *slash
, /* First slash after scheme:// */
3046 *ptr
; /* Pointer into user@host:port part */
3050 * Range check input...
3053 if (!uri
|| !buffer
|| buflen
< 2)
3057 * Copy the device URI to the new buffer...
3060 strlcpy(buffer
, uri
, buflen
);
3063 * Find the end of the scheme:// part...
3066 if ((ptr
= strchr(buffer
, ':')) == NULL
)
3067 return (buffer
); /* No scheme: part... */
3069 for (start
= ptr
+ 1; *start
; start
++)
3074 * Find the next slash (/) in the URI...
3077 if ((slash
= strchr(start
, '/')) == NULL
)
3078 slash
= start
+ strlen(start
); /* No slash, point to the end */
3081 * Check for an @ sign before the slash...
3084 if ((ptr
= strchr(start
, '@')) != NULL
&& ptr
< slash
)
3087 * Found an @ sign and it is before the resource part, so we have
3088 * an authentication string. Copy the remaining URI over the
3089 * authentication string...
3092 _cups_strcpy(start
, ptr
+ 1);
3096 * Return the new device URI...
3104 * 'add_printer_defaults()' - Add name-default attributes to the printer attributes.
3108 add_printer_defaults(cupsd_printer_t
*p
)/* I - Printer */
3110 int i
; /* Looping var */
3111 int num_options
; /* Number of default options */
3112 cups_option_t
*options
, /* Default options */
3113 *option
; /* Current option */
3114 char name
[256]; /* name-default */
3118 * Maintain a common array of default attribute names...
3121 if (!CommonDefaults
)
3123 CommonDefaults
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
3125 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("copies-default"));
3126 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("document-format-default"));
3127 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("finishings-default"));
3128 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-hold-until-default"));
3129 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-priority-default"));
3130 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-sheets-default"));
3131 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("media-default"));
3132 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("number-up-default"));
3133 cupsArrayAdd(CommonDefaults
,
3134 _cupsStrAlloc("orientation-requested-default"));
3135 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("sides-default"));
3139 * Add all of the default options from the .conf files...
3142 for (num_options
= 0, i
= p
->num_options
, option
= p
->options
;
3146 if (strcmp(option
->name
, "ipp-options") &&
3147 strcmp(option
->name
, "job-sheets") &&
3148 strcmp(option
->name
, "lease-duration"))
3150 snprintf(name
, sizeof(name
), "%s-default", option
->name
);
3151 num_options
= cupsAddOption(name
, option
->value
, num_options
, &options
);
3153 if (!cupsArrayFind(CommonDefaults
, name
))
3154 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc(name
));
3159 * Convert options to IPP attributes...
3162 cupsEncodeOptions2(p
->attrs
, num_options
, options
, IPP_TAG_PRINTER
);
3163 cupsFreeOptions(num_options
, options
);
3166 * Add standard -default attributes as needed...
3169 if (!cupsGetOption("copies", p
->num_options
, p
->options
))
3170 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
, "copies-default",
3173 if (!cupsGetOption("document-format", p
->num_options
, p
->options
))
3174 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_MIMETYPE
,
3175 "document-format-default", NULL
, "application/octet-stream");
3177 if (!cupsGetOption("job-hold-until", p
->num_options
, p
->options
))
3178 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3179 "job-hold-until-default", NULL
, "no-hold");
3181 if (!cupsGetOption("job-priority", p
->num_options
, p
->options
))
3182 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3183 "job-priority-default", 50);
3185 if (!cupsGetOption("number-up", p
->num_options
, p
->options
))
3186 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3187 "number-up-default", 1);
3189 if (!cupsGetOption("orientation-requested", p
->num_options
, p
->options
))
3190 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
3191 "orientation-requested-default", IPP_PORTRAIT
);
3193 if (!cupsGetOption("notify-lease-duration", p
->num_options
, p
->options
))
3194 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3195 "notify-lease-duration-default", DefaultLeaseDuration
);
3197 if (!cupsGetOption("notify-events", p
->num_options
, p
->options
))
3198 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3199 "notify-events-default", NULL
, "job-completed");
3204 * 'add_printer_filter()' - Add a MIME filter for a printer.
3209 cupsd_printer_t
*p
, /* I - Printer to add to */
3210 mime_type_t
*filtertype
, /* I - Filter or prefilter MIME type */
3211 const char *filter
) /* I - Filter to add */
3213 char super
[MIME_MAX_SUPER
], /* Super-type for filter */
3214 type
[MIME_MAX_TYPE
], /* Type for filter */
3215 program
[1024]; /* Program/filter name */
3216 int cost
; /* Cost of filter */
3217 mime_type_t
*temptype
; /* MIME type looping var */
3218 char filename
[1024]; /* Full filter filename */
3222 * Parse the filter string; it should be in the following format:
3224 * super/type cost program
3227 if (sscanf(filter
, "%15[^/]/%31s%d%1023s", super
, type
, &cost
, program
) != 4)
3229 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: invalid filter string \"%s\"!",
3235 * See if the filter program exists; if not, stop the printer and flag
3239 if (strcmp(program
, "-"))
3241 if (program
[0] == '/')
3242 strlcpy(filename
, program
, sizeof(filename
));
3244 snprintf(filename
, sizeof(filename
), "%s/filter/%s", ServerBin
, program
);
3246 if (access(filename
, X_OK
))
3248 snprintf(p
->state_message
, sizeof(p
->state_message
),
3249 "Filter \"%s\" for printer \"%s\" not available: %s",
3250 program
, p
->name
, strerror(errno
));
3251 cupsdSetPrinterReasons(p
, "+cups-missing-filter-error");
3252 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, 0);
3254 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s", p
->state_message
);
3259 * Mark the CUPS_PRINTER_COMMANDS bit if we have a filter for
3260 * application/vnd.cups-command...
3263 if (!strcasecmp(super
, "application") &&
3264 !strcasecmp(type
, "vnd.cups-command"))
3265 p
->type
|= CUPS_PRINTER_COMMANDS
;
3268 * Add the filter to the MIME database, supporting wildcards as needed...
3271 for (temptype
= mimeFirstType(MimeDatabase
);
3273 temptype
= mimeNextType(MimeDatabase
))
3274 if (((super
[0] == '*' && strcasecmp(temptype
->super
, "printer")) ||
3275 !strcasecmp(temptype
->super
, super
)) &&
3276 (type
[0] == '*' || !strcasecmp(temptype
->type
, type
)))
3278 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3279 "add_printer_filter: %s: adding filter %s/%s %s/%s %d %s",
3280 p
->name
, temptype
->super
, temptype
->type
,
3281 filtertype
->super
, filtertype
->type
,
3283 mimeAddFilter(MimeDatabase
, temptype
, filtertype
, cost
, program
);
3289 * 'add_printer_formats()' - Add document-format-supported values for a printer.
3293 add_printer_formats(cupsd_printer_t
*p
) /* I - Printer */
3295 int i
; /* Looping var */
3296 mime_type_t
*type
; /* Current MIME type */
3297 cups_array_t
*filters
; /* Filters */
3298 ipp_attribute_t
*attr
; /* document-format-supported attribute */
3299 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
3300 /* MIME type name */
3304 * Raw (and remote) queues advertise all of the supported MIME
3308 cupsArrayDelete(p
->filetypes
);
3309 p
->filetypes
= NULL
;
3313 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
,
3314 (ipp_tag_t
)(IPP_TAG_MIMETYPE
| IPP_TAG_COPY
),
3315 "document-format-supported", NumMimeTypes
, NULL
, MimeTypes
);
3320 * Otherwise, loop through the supported MIME types and see if there
3321 * are filters for them...
3324 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_printer_formats: %d types, %d filters",
3325 mimeNumTypes(MimeDatabase
), mimeNumFilters(MimeDatabase
));
3327 p
->filetypes
= cupsArrayNew(NULL
, NULL
);
3329 for (type
= mimeFirstType(MimeDatabase
);
3331 type
= mimeNextType(MimeDatabase
))
3333 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
3335 if ((filters
= mimeFilter(MimeDatabase
, type
, p
->filetype
, NULL
)) != NULL
)
3337 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3338 "add_printer_formats: %s: %s needs %d filters",
3339 p
->name
, mimetype
, cupsArrayCount(filters
));
3341 cupsArrayDelete(filters
);
3342 cupsArrayAdd(p
->filetypes
, type
);
3345 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3346 "add_printer_formats: %s: %s not supported",
3350 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3351 "add_printer_formats: %s: %d supported types",
3352 p
->name
, cupsArrayCount(p
->filetypes
) + 1);
3355 * Add the file formats that can be filtered...
3358 if ((type
= mimeType(MimeDatabase
, "application", "octet-stream")) == NULL
||
3359 !cupsArrayFind(p
->filetypes
, type
))
3364 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_MIMETYPE
,
3365 "document-format-supported",
3366 cupsArrayCount(p
->filetypes
) + 1, NULL
, NULL
);
3369 attr
->values
[0].string
.text
= _cupsStrAlloc("application/octet-stream");
3371 for (type
= (mime_type_t
*)cupsArrayFirst(p
->filetypes
);
3373 i
++, type
= (mime_type_t
*)cupsArrayNext(p
->filetypes
))
3375 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
3377 attr
->values
[i
].string
.text
= _cupsStrAlloc(mimetype
);
3382 char pdl
[1024]; /* Buffer to build pdl list */
3383 mime_filter_t
*filter
; /* MIME filter looping var */
3388 if (mimeType(MimeDatabase
, "application", "pdf"))
3389 strlcat(pdl
, "application/pdf,", sizeof(pdl
));
3391 if (mimeType(MimeDatabase
, "application", "postscript"))
3392 strlcat(pdl
, "application/postscript,", sizeof(pdl
));
3394 if (mimeType(MimeDatabase
, "application", "vnd.cups-raster"))
3395 strlcat(pdl
, "application/vnd.cups-raster,", sizeof(pdl
));
3398 * Determine if this is a Tioga PrintJobMgr based queue...
3401 for (filter
= (mime_filter_t
*)cupsArrayFirst(MimeDatabase
->filters
);
3403 filter
= (mime_filter_t
*)cupsArrayNext(MimeDatabase
->filters
))
3405 if (filter
->dst
== p
->filetype
&& filter
->filter
&&
3406 strstr(filter
->filter
, "PrintJobMgr"))
3411 * We only support raw printing if this is not a Tioga PrintJobMgr based
3412 * queue and if application/octet-stream is a known conversion...
3415 if (!filter
&& mimeType(MimeDatabase
, "application", "octet-stream"))
3416 strlcat(pdl
, "application/octet-stream,", sizeof(pdl
));
3418 if (mimeType(MimeDatabase
, "image", "png"))
3419 strlcat(pdl
, "image/png,", sizeof(pdl
));
3422 pdl
[strlen(pdl
) - 1] = '\0'; /* Remove trailing comma */
3424 cupsdSetString(&p
->pdl
, pdl
);
3426 #endif /* HAVE_DNSSD */
3431 * 'compare_printers()' - Compare two printers.
3434 static int /* O - Result of comparison */
3435 compare_printers(void *first
, /* I - First printer */
3436 void *second
, /* I - Second printer */
3437 void *data
) /* I - App data (not used) */
3439 return (strcasecmp(((cupsd_printer_t
*)first
)->name
,
3440 ((cupsd_printer_t
*)second
)->name
));
3445 * 'delete_printer_filters()' - Delete all MIME filters for a printer.
3449 delete_printer_filters(
3450 cupsd_printer_t
*p
) /* I - Printer to remove from */
3452 mime_filter_t
*filter
; /* MIME filter looping var */
3456 * Range check input...
3463 * Remove all filters from the MIME database that have a destination
3464 * type == printer...
3467 for (filter
= mimeFirstFilter(MimeDatabase
);
3469 filter
= mimeNextFilter(MimeDatabase
))
3470 if (filter
->dst
== p
->filetype
)
3473 * Delete the current filter...
3476 mimeDeleteFilter(MimeDatabase
, filter
);
3483 * 'write_irix_config()' - Update the config files used by the IRIX
3488 write_irix_config(cupsd_printer_t
*p
) /* I - Printer to update */
3490 char filename
[1024]; /* Interface script filename */
3491 cups_file_t
*fp
; /* Interface script file */
3492 ipp_attribute_t
*attr
; /* Attribute data */
3496 * Add dummy interface and GUI scripts to fool SGI's "challenged" printing
3497 * tools. First the interface script that tells the tools what kind of
3498 * printer we have...
3501 snprintf(filename
, sizeof(filename
), "/var/spool/lp/interface/%s", p
->name
);
3503 if (p
->type
& CUPS_PRINTER_CLASS
)
3505 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
3507 cupsFilePuts(fp
, "#!/bin/sh\n");
3509 if ((attr
= ippFindAttribute(p
->attrs
, "printer-make-and-model",
3510 IPP_TAG_TEXT
)) != NULL
)
3511 cupsFilePrintf(fp
, "NAME=\"%s\"\n", attr
->values
[0].string
.text
);
3512 else if (p
->type
& CUPS_PRINTER_CLASS
)
3513 cupsFilePuts(fp
, "NAME=\"Printer Class\"\n");
3515 cupsFilePuts(fp
, "NAME=\"Remote Destination\"\n");
3517 if (p
->type
& CUPS_PRINTER_COLOR
)
3518 cupsFilePuts(fp
, "TYPE=ColorPostScript\n");
3520 cupsFilePuts(fp
, "TYPE=MonoPostScript\n");
3522 cupsFilePrintf(fp
, "HOSTNAME=%s\n", ServerName
);
3523 cupsFilePrintf(fp
, "HOSTPRINTER=%s\n", p
->name
);
3527 chmod(filename
, 0755);
3528 chown(filename
, User
, Group
);
3532 * Then the member file that tells which device file the queue is connected
3533 * to... Networked printers use "/dev/null" in this file, so that's what
3534 * we use (the actual device URI can confuse some apps...)
3537 snprintf(filename
, sizeof(filename
), "/var/spool/lp/member/%s", p
->name
);
3539 if (p
->type
& CUPS_PRINTER_CLASS
)
3541 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
3543 cupsFilePuts(fp
, "/dev/null\n");
3547 chmod(filename
, 0644);
3548 chown(filename
, User
, Group
);
3552 * The gui_interface file is a script or program that launches a GUI
3553 * option panel for the printer, using options specified on the
3554 * command-line in the third argument. The option panel must send
3555 * any printing options to stdout on a single line when the user
3556 * accepts them, or nothing if the user cancels the dialog.
3558 * The default options panel program is /usr/bin/glpoptions, from
3559 * the ESP Print Pro software. You can select another using the
3560 * PrintcapGUI option.
3563 snprintf(filename
, sizeof(filename
), "/var/spool/lp/gui_interface/ELF/%s.gui", p
->name
);
3565 if (p
->type
& CUPS_PRINTER_CLASS
)
3567 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
3569 cupsFilePuts(fp
, "#!/bin/sh\n");
3570 cupsFilePrintf(fp
, "%s -d %s -o \"$3\"\n", PrintcapGUI
, p
->name
);
3574 chmod(filename
, 0755);
3575 chown(filename
, User
, Group
);
3579 * The POD config file is needed by the printstatus command to show
3580 * the printer location and device.
3583 snprintf(filename
, sizeof(filename
), "/var/spool/lp/pod/%s.config", p
->name
);
3585 if (p
->type
& CUPS_PRINTER_CLASS
)
3587 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
3589 cupsFilePrintf(fp
, "Printer Class | %s\n",
3590 (p
->type
& CUPS_PRINTER_COLOR
) ? "ColorPostScript" : "MonoPostScript");
3591 cupsFilePrintf(fp
, "Printer Model | %s\n", p
->make_model
? p
->make_model
: "");
3592 cupsFilePrintf(fp
, "Location Code | %s\n", p
->location
? p
->location
: "");
3593 cupsFilePrintf(fp
, "Physical Location | %s\n", p
->info
? p
->info
: "");
3594 cupsFilePrintf(fp
, "Port Path | %s\n", p
->device_uri
? p
->device_uri
: "");
3595 cupsFilePrintf(fp
, "Config Path | /var/spool/lp/pod/%s.config\n", p
->name
);
3596 cupsFilePrintf(fp
, "Active Status Path | /var/spool/lp/pod/%s.status\n", p
->name
);
3597 cupsFilePuts(fp
, "Status Update Wait | 10 seconds\n");
3601 chmod(filename
, 0664);
3602 chown(filename
, User
, Group
);
3608 * 'write_irix_state()' - Update the status files used by IRIX printing
3613 write_irix_state(cupsd_printer_t
*p
) /* I - Printer to update */
3615 char filename
[1024]; /* Interface script filename */
3616 cups_file_t
*fp
; /* Interface script file */
3617 int tag
; /* Status tag value */
3623 * The POD status file is needed for the printstatus window to
3624 * provide the current status of the printer.
3627 snprintf(filename
, sizeof(filename
), "/var/spool/lp/pod/%s.status", p
->name
);
3629 if (p
->type
& CUPS_PRINTER_CLASS
)
3631 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
3633 cupsFilePrintf(fp
, "Operational Status | %s\n",
3634 (p
->state
== IPP_PRINTER_IDLE
) ? "Idle" :
3635 (p
->state
== IPP_PRINTER_PROCESSING
) ? "Busy" :
3637 cupsFilePrintf(fp
, "Information | 01 00 00 | %s\n", CUPS_SVERSION
);
3638 cupsFilePrintf(fp
, "Information | 02 00 00 | Device URI: %s\n",
3639 p
->device_uri
? p
->device_uri
: "");
3640 cupsFilePrintf(fp
, "Information | 03 00 00 | %s jobs\n",
3641 p
->accepting
? "Accepting" : "Not accepting");
3642 cupsFilePrintf(fp
, "Information | 04 00 00 | %s\n", p
->state_message
);
3646 chmod(filename
, 0664);
3647 chown(filename
, User
, Group
);
3651 * The activeicons file is needed to provide desktop icons for printers:
3653 * [ quoted from /usr/lib/print/tagit ]
3655 * --- Type of printer tags (base values)
3657 * Dumb=66048 # 0x10200
3658 * DumbColor=66080 # 0x10220
3659 * Raster=66112 # 0x10240
3660 * ColorRaster=66144 # 0x10260
3661 * Plotter=66176 # 0x10280
3662 * PostScript=66208 # 0x102A0
3663 * ColorPostScript=66240 # 0x102C0
3664 * MonoPostScript=66272 # 0x102E0
3666 * --- Printer state modifiers for local printers
3671 * Unknown=3 # 0x3 (Faulted due to unknown reason)
3673 * --- Printer state modifiers for network printers
3677 * NetFaulted=10 # 0xA
3678 * NetUnknown=11 # 0xB (Faulted due to unknown reason)
3681 snprintf(filename
, sizeof(filename
), "/var/spool/lp/activeicons/%s", p
->name
);
3683 if (p
->type
& CUPS_PRINTER_CLASS
)
3685 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
3687 if (p
->type
& CUPS_PRINTER_COLOR
)
3692 if (p
->type
& CUPS_PRINTER_REMOTE
)
3695 if (p
->state
== IPP_PRINTER_PROCESSING
)
3698 else if (p
->state
== IPP_PRINTER_STOPPED
)
3701 cupsFilePuts(fp
, "#!/bin/sh\n");
3702 cupsFilePrintf(fp
, "#Tag %d\n", tag
);
3706 chmod(filename
, 0755);
3707 chown(filename
, User
, Group
);
3712 * The default file is needed by the printers window to show
3713 * the default printer.
3716 snprintf(filename
, sizeof(filename
), "/var/spool/lp/default");
3718 if (DefaultPrinter
!= NULL
)
3720 if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
3722 cupsFilePrintf(fp
, "%s\n", DefaultPrinter
->name
);
3726 chmod(filename
, 0644);
3727 chown(filename
, User
, Group
);
3737 * End of "$Id: printers.c 6595 2007-06-21 22:29:57Z mike $".