2 * "$Id: printers.c 6678 2007-07-16 18:03:35Z mike $"
4 * Printer routines for the Common UNIX Printing System (CUPS).
6 * Copyright 2007 by Apple Inc.
7 * Copyright 1997-2007 by Easy Software Products, all rights reserved.
9 * These coded instructions, statements, and computer programs are the
10 * property of Apple Inc. and are protected by Federal copyright
11 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
12 * which should have been included with this file. If this file is
13 * file is missing or damaged, see the license at "http://www.cups.org/".
17 * cupsdAddPrinter() - Add a printer to the system.
18 * cupsdAddPrinterHistory() - Add the current printer state to the history.
19 * cupsdAddPrinterUser() - Add a user to the ACL.
20 * cupsdCreateCommonData() - Create the common printer data.
21 * cupsdDeleteAllPrinters() - Delete all printers from the system.
22 * cupsdDeletePrinter() - Delete a printer from the system.
23 * cupsdFindPrinter() - Find a printer in the list.
24 * cupsdFreePrinterUsers() - Free allow/deny users.
25 * cupsdLoadAllPrinters() - Load printers from the printers.conf file.
26 * cupsdRenamePrinter() - Rename a printer.
27 * cupsdSaveAllPrinters() - Save all printer definitions to the
29 * cupsdSetAuthInfoRequired() - Set the required authentication info.
30 * cupsdSetPrinterAttrs() - Set printer attributes based upon the PPD
32 * cupsdSetPrinterReasons() - Set/update the reasons strings.
33 * cupsdSetPrinterState() - Update the current state of a printer.
34 * cupsdStopPrinter() - Stop a printer from printing any jobs...
35 * cupsdUpdatePrinters() - Update printers after a partial reload.
36 * cupsdValidateDest() - Validate a printer/class destination.
37 * cupsdWritePrintcap() - Write a pseudo-printcap file for older
38 * applications that need it...
39 * cupsdSanitizeURI() - Sanitize a device URI...
40 * add_printer_defaults() - Add name-default attributes to the printer
42 * add_printer_filter() - Add a MIME filter for a printer.
43 * add_printer_formats() - Add document-format-supported values for
45 * compare_printers() - Compare two printers.
46 * delete_printer_filters() - Delete all MIME filters for a printer.
47 * write_irix_config() - Update the config files used by the IRIX
49 * write_irix_state() - Update the status files used by IRIX
50 * printing desktop tools.
54 * Include necessary headers...
65 static void add_printer_defaults(cupsd_printer_t
*p
);
66 static void add_printer_filter(cupsd_printer_t
*p
, mime_type_t
*type
,
68 static void add_printer_formats(cupsd_printer_t
*p
);
69 static int compare_printers(void *first
, void *second
, void *data
);
70 static void delete_printer_filters(cupsd_printer_t
*p
);
72 static void write_irix_config(cupsd_printer_t
*p
);
73 static void write_irix_state(cupsd_printer_t
*p
);
78 * 'cupsdAddPrinter()' - Add a printer to the system.
81 cupsd_printer_t
* /* O - New printer */
82 cupsdAddPrinter(const char *name
) /* I - Name of printer */
84 cupsd_printer_t
*p
; /* New printer */
88 * Range check input...
91 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdAddPrinter(\"%s\")", name
);
94 * Create a new printer entity...
97 if ((p
= calloc(1, sizeof(cupsd_printer_t
))) == NULL
)
99 cupsdLogMessage(CUPSD_LOG_CRIT
, "Unable to allocate memory for printer - %s",
104 cupsdSetString(&p
->name
, name
);
105 cupsdSetString(&p
->info
, name
);
106 cupsdSetString(&p
->hostname
, ServerName
);
108 cupsdSetStringf(&p
->uri
, "ipp://%s:%d/printers/%s", ServerName
, LocalPort
, name
);
109 cupsdSetStringf(&p
->device_uri
, "file:/dev/null");
111 p
->state
= IPP_PRINTER_STOPPED
;
112 p
->state_time
= time(NULL
);
114 p
->shared
= DefaultShared
;
115 p
->filetype
= mimeAddType(MimeDatabase
, "printer", name
);
117 cupsdSetString(&p
->job_sheets
[0], "none");
118 cupsdSetString(&p
->job_sheets
[1], "none");
120 cupsdSetString(&p
->error_policy
, ErrorPolicy
);
121 cupsdSetString(&p
->op_policy
, DefaultPolicy
);
123 p
->op_policy_ptr
= DefaultPolicyPtr
;
125 if (MaxPrinterHistory
)
126 p
->history
= calloc(MaxPrinterHistory
, sizeof(ipp_t
*));
129 * Insert the printer in the printer list alphabetically...
133 Printers
= cupsArrayNew(compare_printers
, NULL
);
135 cupsArrayAdd(Printers
, p
);
137 if (!ImplicitPrinters
)
138 ImplicitPrinters
= cupsArrayNew(compare_printers
, NULL
);
141 * Return the new printer...
149 * 'cupsdAddPrinterHistory()' - Add the current printer state to the history.
153 cupsdAddPrinterHistory(
154 cupsd_printer_t
*p
) /* I - Printer */
156 ipp_t
*history
; /* History collection */
160 * Stop early if we aren't keeping history data...
163 if (MaxPrinterHistory
<= 0)
167 * Retire old history data as needed...
170 p
->sequence_number
++;
172 if (p
->num_history
>= MaxPrinterHistory
)
175 ippDelete(p
->history
[0]);
176 memmove(p
->history
, p
->history
+ 1, p
->num_history
* sizeof(ipp_t
*));
180 * Create a collection containing the current printer-state, printer-up-time,
181 * printer-state-message, and printer-state-reasons attributes.
185 ippAddInteger(history
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-state",
187 ippAddBoolean(history
, IPP_TAG_PRINTER
, "printer-is-accepting-jobs",
189 ippAddBoolean(history
, IPP_TAG_PRINTER
, "printer-is-shared", p
->shared
);
190 ippAddString(history
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-state-message",
191 NULL
, p
->state_message
);
194 ippAddString(history
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
195 "com.apple.print.recoverable-message", NULL
, p
->recoverable
);
196 #endif /* __APPLE__ */
197 if (p
->num_reasons
== 0)
198 ippAddString(history
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
199 "printer-state-reasons", NULL
,
200 p
->state
== IPP_PRINTER_STOPPED
? "paused" : "none");
202 ippAddStrings(history
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
203 "printer-state-reasons", p
->num_reasons
, NULL
,
204 (const char * const *)p
->reasons
);
205 ippAddInteger(history
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
206 "printer-state-change-time", p
->state_time
);
207 ippAddInteger(history
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
208 "printer-state-sequence-number", p
->sequence_number
);
210 p
->history
[p
->num_history
] = history
;
216 * 'cupsdAddPrinterUser()' - Add a user to the ACL.
221 cupsd_printer_t
*p
, /* I - Printer */
222 const char *username
) /* I - User */
224 const char **temp
; /* Temporary array pointer */
230 if (p
->num_users
== 0)
231 temp
= malloc(sizeof(char **));
233 temp
= realloc(p
->users
, sizeof(char **) * (p
->num_users
+ 1));
239 temp
+= p
->num_users
;
241 if ((*temp
= strdup(username
)) != NULL
)
247 * 'cupsdCreateCommonData()' - Create the common printer data.
251 cupsdCreateCommonData(void)
253 int i
; /* Looping var */
254 ipp_attribute_t
*attr
; /* Attribute data */
255 cups_dir_t
*dir
; /* Notifier directory */
256 cups_dentry_t
*dent
; /* Notifier directory entry */
257 cups_array_t
*notifiers
; /* Notifier array */
258 char filename
[1024], /* Filename */
259 *notifier
; /* Current notifier */
260 static const int nups
[] = /* number-up-supported values */
261 { 1, 2, 4, 6, 9, 16 };
262 static const int orients
[4] =/* orientation-requested-supported values */
266 IPP_REVERSE_LANDSCAPE
,
269 static const char * const holds
[] = /* job-hold-until-supported values */
280 static const char * const versions
[] =/* ipp-versions-supported values */
285 static const int ops
[] = /* operations-supported values */
292 IPP_GET_JOB_ATTRIBUTES
,
294 IPP_GET_PRINTER_ATTRIBUTES
,
300 IPP_SET_JOB_ATTRIBUTES
,
301 IPP_CREATE_PRINTER_SUBSCRIPTION
,
302 IPP_CREATE_JOB_SUBSCRIPTION
,
303 IPP_GET_SUBSCRIPTION_ATTRIBUTES
,
304 IPP_GET_SUBSCRIPTIONS
,
305 IPP_RENEW_SUBSCRIPTION
,
306 IPP_CANCEL_SUBSCRIPTION
,
307 IPP_GET_NOTIFICATIONS
,
323 CUPS_AUTHENTICATE_JOB
,
326 static const char * const charsets
[] =/* charset-supported values */
331 static const char * const compressions
[] =
332 { /* document-compression-supported values */
336 #endif /* HAVE_LIBZ */
338 static const char * const multiple_document_handling
[] =
339 { /* multiple-document-handling-supported values */
340 "separate-documents-uncollated-copies",
341 "separate-documents-collated-copies"
343 static const char * const errors
[] = /* printer-error-policy-supported values */
349 static const char * const notify_attrs
[] =
350 { /* notify-attributes-supported values */
351 "printer-state-change-time",
352 "notify-lease-expiration-time",
353 "notify-subscriber-user-name"
355 static const char * const notify_events
[] =
356 { /* notify-events-supported values */
358 "job-config-changed",
365 "printer-config-changed",
367 "printer-finishings-changed",
368 "printer-media-changed",
372 "printer-state-changed",
382 ippDelete(CommonData
);
384 CommonData
= ippNew();
387 * This list of attributes is sorted to improve performance when the
388 * client provides a requested-attributes attribute...
391 /* charset-configured */
392 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_CHARSET
,
393 "charset-configured", NULL
, DefaultCharset
);
395 /* charset-supported */
396 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_CHARSET
,
397 "charset-supported", sizeof(charsets
) / sizeof(charsets
[0]),
400 /* compression-supported */
401 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
402 "compression-supported",
403 sizeof(compressions
) / sizeof(compressions
[0]),
406 /* copies-supported */
407 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "copies-supported", 1, MaxCopies
);
410 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "cups-version",
411 NULL
, CUPS_SVERSION
+ 6);
413 /* generated-natural-language-supported */
414 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_LANGUAGE
,
415 "generated-natural-language-supported", NULL
, DefaultLanguage
);
417 /* ipp-versions-supported */
418 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
419 "ipp-versions-supported", sizeof(versions
) / sizeof(versions
[0]),
422 /* job-hold-until-supported */
423 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
424 "job-hold-until-supported", sizeof(holds
) / sizeof(holds
[0]),
427 /* job-priority-supported */
428 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
429 "job-priority-supported", 100);
431 /* job-sheets-supported */
432 if (cupsArrayCount(Banners
) > 0)
435 * Setup the job-sheets-supported attribute...
438 if (Classification
&& !ClassifyOverride
)
439 attr
= ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
440 "job-sheets-supported", NULL
, Classification
);
442 attr
= ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
443 "job-sheets-supported", cupsArrayCount(Banners
) + 1,
447 cupsdLogMessage(CUPSD_LOG_EMERG
,
448 "Unable to allocate memory for "
449 "job-sheets-supported attribute: %s!", strerror(errno
));
450 else if (!Classification
|| ClassifyOverride
)
452 cupsd_banner_t
*banner
; /* Current banner */
455 attr
->values
[0].string
.text
= _cupsStrAlloc("none");
457 for (i
= 1, banner
= (cupsd_banner_t
*)cupsArrayFirst(Banners
);
459 i
++, banner
= (cupsd_banner_t
*)cupsArrayNext(Banners
))
460 attr
->values
[i
].string
.text
= _cupsStrAlloc(banner
->name
);
464 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
465 "job-sheets-supported", NULL
, "none");
467 /* multiple-document-handling-supported */
468 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
469 "multiple-document-handling-supported",
470 sizeof(multiple_document_handling
) /
471 sizeof(multiple_document_handling
[0]), NULL
,
472 multiple_document_handling
);
474 /* multiple-document-jobs-supported */
475 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
,
476 "multiple-document-jobs-supported", 1);
478 /* multiple-operation-time-out */
479 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
480 "multiple-operation-time-out", 60);
482 /* natural-language-configured */
483 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_LANGUAGE
,
484 "natural-language-configured", NULL
, DefaultLanguage
);
486 /* notify-attributes-supported */
487 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
488 "notify-attributes-supported",
489 (int)(sizeof(notify_attrs
) / sizeof(notify_attrs
[0])),
492 /* notify-lease-duration-supported */
493 ippAddRange(CommonData
, IPP_TAG_PRINTER
,
494 "notify-lease-duration-supported", 0,
495 MaxLeaseDuration
? MaxLeaseDuration
: 2147483647);
497 /* notify-max-events-supported */
498 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
499 "notify-max-events-supported", MaxEvents
);
501 /* notify-events-supported */
502 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
503 "notify-events-supported",
504 (int)(sizeof(notify_events
) / sizeof(notify_events
[0])),
505 NULL
, notify_events
);
507 /* notify-pull-method-supported */
508 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
509 "notify-pull-method-supported", NULL
, "ippget");
511 /* notify-schemes-supported */
512 snprintf(filename
, sizeof(filename
), "%s/notifier", ServerBin
);
513 if ((dir
= cupsDirOpen(filename
)) != NULL
)
515 notifiers
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
517 while ((dent
= cupsDirRead(dir
)) != NULL
)
518 if (S_ISREG(dent
->fileinfo
.st_mode
) &&
519 (dent
->fileinfo
.st_mode
& S_IXOTH
) != 0)
520 cupsArrayAdd(notifiers
, _cupsStrAlloc(dent
->filename
));
522 if (cupsArrayCount(notifiers
) > 0)
524 attr
= ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
525 "notify-schemes-supported",
526 cupsArrayCount(notifiers
), NULL
, NULL
);
528 for (i
= 0, notifier
= (char *)cupsArrayFirst(notifiers
);
530 i
++, notifier
= (char *)cupsArrayNext(notifiers
))
531 attr
->values
[i
].string
.text
= notifier
;
534 cupsArrayDelete(notifiers
);
538 /* number-up-supported */
539 ippAddIntegers(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
540 "number-up-supported", sizeof(nups
) / sizeof(nups
[0]), nups
);
542 /* operations-supported */
543 ippAddIntegers(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
544 "operations-supported",
545 sizeof(ops
) / sizeof(ops
[0]) + JobFiles
- 1, ops
);
547 /* orientation-requested-supported */
548 ippAddIntegers(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
549 "orientation-requested-supported", 4, orients
);
551 /* page-ranges-supported */
552 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
, "page-ranges-supported", 1);
554 /* pdf-override-supported */
555 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
556 "pdl-override-supported", NULL
, "not-attempted");
558 /* printer-error-policy-supported */
559 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
560 "printer-error-policy-supported",
561 sizeof(errors
) / sizeof(errors
[0]), NULL
, errors
);
563 /* printer-op-policy-supported */
564 attr
= ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
565 "printer-op-policy-supported", NumPolicies
, NULL
, NULL
);
566 for (i
= 0; i
< NumPolicies
; i
++)
567 attr
->values
[i
].string
.text
= _cupsStrAlloc(Policies
[i
]->name
);
572 * 'cupsdDeleteAllPrinters()' - Delete all printers from the system.
576 cupsdDeleteAllPrinters(void)
578 cupsd_printer_t
*p
; /* Pointer to current printer/class */
581 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
583 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
584 if (!(p
->type
& CUPS_PRINTER_CLASS
))
585 cupsdDeletePrinter(p
, 0);
590 * 'cupsdDeletePrinter()' - Delete a printer from the system.
595 cupsd_printer_t
*p
, /* I - Printer to delete */
596 int update
) /* I - Update printers.conf? */
598 int i
; /* Looping var */
600 char filename
[1024]; /* Interface script filename */
604 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdDeletePrinter(p=%p(%s), update=%d)",
608 * Save the current position in the Printers array...
611 cupsArraySave(Printers
);
614 * Stop printing on this printer...
617 cupsdStopPrinter(p
, update
);
620 * If this printer is the next for browsing, point to the next one...
625 cupsArrayFind(Printers
, p
);
626 BrowseNext
= (cupsd_printer_t
*)cupsArrayNext(Printers
);
630 * Remove the printer from the list...
633 cupsArrayRemove(Printers
, p
);
635 if (p
->type
& CUPS_PRINTER_IMPLICIT
)
636 cupsArrayRemove(ImplicitPrinters
, p
);
639 * Remove the dummy interface/icon/option files under IRIX...
643 snprintf(filename
, sizeof(filename
), "/var/spool/lp/interface/%s", p
->name
);
646 snprintf(filename
, sizeof(filename
), "/var/spool/lp/gui_interface/ELF/%s.gui",
650 snprintf(filename
, sizeof(filename
), "/var/spool/lp/activeicons/%s", p
->name
);
653 snprintf(filename
, sizeof(filename
), "/var/spool/lp/pod/%s.config", p
->name
);
656 snprintf(filename
, sizeof(filename
), "/var/spool/lp/pod/%s.status", p
->name
);
659 snprintf(filename
, sizeof(filename
), "/var/spool/lp/member/%s", p
->name
);
664 * If p is the default printer, assign a different one...
667 if (p
== DefaultPrinter
)
669 DefaultPrinter
= NULL
;
671 if (UseNetworkDefault
)
674 * Find the first network default printer and use it...
677 cupsd_printer_t
*dp
; /* New default printer */
680 for (dp
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
682 dp
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
683 if (dp
!= p
&& (dp
->type
& CUPS_PRINTER_DEFAULT
))
692 * Remove this printer from any classes...
695 if (!(p
->type
& CUPS_PRINTER_IMPLICIT
))
697 cupsdDeletePrinterFromClasses(p
);
700 * Deregister from any browse protocols...
703 cupsdDeregisterPrinter(p
, 1);
707 * Free all memory used by the printer...
710 if (p
->printers
!= NULL
)
713 if (MaxPrinterHistory
)
715 for (i
= 0; i
< p
->num_history
; i
++)
716 ippDelete(p
->history
[i
]);
721 for (i
= 0; i
< p
->num_reasons
; i
++)
726 delete_printer_filters(p
);
728 mimeDeleteType(MimeDatabase
, p
->filetype
);
729 mimeDeleteType(MimeDatabase
, p
->prefiltertype
);
731 cupsdFreePrinterUsers(p
);
734 cupsdClearString(&p
->uri
);
735 cupsdClearString(&p
->hostname
);
736 cupsdClearString(&p
->name
);
737 cupsdClearString(&p
->location
);
738 cupsdClearString(&p
->make_model
);
739 cupsdClearString(&p
->info
);
740 cupsdClearString(&p
->job_sheets
[0]);
741 cupsdClearString(&p
->job_sheets
[1]);
742 cupsdClearString(&p
->device_uri
);
743 cupsdClearString(&p
->port_monitor
);
744 cupsdClearString(&p
->op_policy
);
745 cupsdClearString(&p
->error_policy
);
747 cupsdClearString(&p
->alert
);
748 cupsdClearString(&p
->alert_description
);
751 cupsdClearString(&p
->product
);
752 cupsdClearString(&p
->pdl
);
753 #endif /* HAVE_DNSSD */
755 cupsArrayDelete(p
->filetypes
);
758 free(p
->browse_attrs
);
761 cupsdClearString(&p
->recoverable
);
762 #endif /* __APPLE__ */
764 cupsFreeOptions(p
->num_options
, p
->options
);
769 * Restore the previous position in the Printers array...
772 cupsArrayRestore(Printers
);
777 * 'cupsdFindDest()' - Find a destination in the list.
780 cupsd_printer_t
* /* O - Destination in list */
781 cupsdFindDest(const char *name
) /* I - Name of printer or class to find */
783 cupsd_printer_t key
; /* Search key */
786 key
.name
= (char *)name
;
787 return ((cupsd_printer_t
*)cupsArrayFind(Printers
, &key
));
792 * 'cupsdFindPrinter()' - Find a printer in the list.
795 cupsd_printer_t
* /* O - Printer in list */
796 cupsdFindPrinter(const char *name
) /* I - Name of printer to find */
798 cupsd_printer_t
*p
; /* Printer in list */
801 if ((p
= cupsdFindDest(name
)) != NULL
&& (p
->type
& CUPS_PRINTER_CLASS
))
809 * 'cupsdFreePrinterUsers()' - Free allow/deny users.
813 cupsdFreePrinterUsers(
814 cupsd_printer_t
*p
) /* I - Printer */
816 int i
; /* Looping var */
819 if (!p
|| !p
->num_users
)
822 for (i
= 0; i
< p
->num_users
; i
++)
823 free((void *)p
->users
[i
]);
833 * 'cupsdLoadAllPrinters()' - Load printers from the printers.conf file.
837 cupsdLoadAllPrinters(void)
839 cups_file_t
*fp
; /* printers.conf file */
840 int linenum
; /* Current line number */
841 char line
[1024], /* Line from file */
842 *value
, /* Pointer to value */
843 *valueptr
; /* Pointer into value */
844 cupsd_printer_t
*p
; /* Current printer */
848 * Open the printers.conf file...
851 snprintf(line
, sizeof(line
), "%s/printers.conf", ServerRoot
);
852 if ((fp
= cupsFileOpen(line
, "r")) == NULL
)
855 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to open %s - %s", line
,
861 * Read printer configurations until we hit EOF...
867 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
870 * Decode the directive...
873 if (!strcasecmp(line
, "<Printer") ||
874 !strcasecmp(line
, "<DefaultPrinter"))
877 * <Printer name> or <DefaultPrinter name>
880 if (p
== NULL
&& value
)
883 * Add the printer and a base file type...
886 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Loading printer %s...", value
);
888 p
= cupsdAddPrinter(value
);
890 p
->state
= IPP_PRINTER_IDLE
;
893 * Set the default printer as needed...
896 if (!strcasecmp(line
, "<DefaultPrinter"))
901 cupsdLogMessage(CUPSD_LOG_ERROR
,
902 "Syntax error on line %d of printers.conf.", linenum
);
906 else if (!strcasecmp(line
, "</Printer>"))
911 * Close out the current printer...
914 cupsdSetPrinterAttrs(p
);
915 cupsdAddPrinterHistory(p
);
917 if (p
->device_uri
&& strncmp(p
->device_uri
, "file:", 5) &&
918 p
->state
!= IPP_PRINTER_STOPPED
)
921 * See if the backend exists...
924 snprintf(line
, sizeof(line
), "%s/backend/%s", ServerBin
,
927 if ((valueptr
= strchr(line
+ strlen(ServerBin
), ':')) != NULL
)
928 *valueptr
= '\0'; /* Chop everything but URI scheme */
933 * Backend does not exist, stop printer...
936 p
->state
= IPP_PRINTER_STOPPED
;
937 snprintf(p
->state_message
, sizeof(p
->state_message
),
938 "Backend %s does not exist!", line
);
946 cupsdLogMessage(CUPSD_LOG_ERROR
,
947 "Syntax error on line %d of printers.conf.", linenum
);
953 cupsdLogMessage(CUPSD_LOG_ERROR
,
954 "Syntax error on line %d of printers.conf.", linenum
);
957 else if (!strcasecmp(line
, "AuthInfoRequired"))
959 if (!cupsdSetAuthInfoRequired(p
, value
, NULL
))
960 cupsdLogMessage(CUPSD_LOG_ERROR
,
961 "Bad AuthInfoRequired on line %d of printers.conf.",
964 else if (!strcasecmp(line
, "Info"))
967 cupsdSetString(&p
->info
, value
);
969 else if (!strcasecmp(line
, "Location"))
972 cupsdSetString(&p
->location
, value
);
974 else if (!strcasecmp(line
, "DeviceURI"))
977 cupsdSetString(&p
->device_uri
, value
);
980 cupsdLogMessage(CUPSD_LOG_ERROR
,
981 "Syntax error on line %d of printers.conf.", linenum
);
985 else if (!strcasecmp(line
, "Option") && value
)
991 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
994 cupsdLogMessage(CUPSD_LOG_ERROR
,
995 "Syntax error on line %d of printers.conf.", linenum
);
998 for (; *valueptr
&& isspace(*valueptr
& 255); *valueptr
++ = '\0');
1000 p
->num_options
= cupsAddOption(value
, valueptr
, p
->num_options
,
1004 else if (!strcasecmp(line
, "PortMonitor"))
1006 if (value
&& strcmp(value
, "none"))
1007 cupsdSetString(&p
->port_monitor
, value
);
1009 cupsdClearString(&p
->port_monitor
);
1012 cupsdLogMessage(CUPSD_LOG_ERROR
,
1013 "Syntax error on line %d of printers.conf.", linenum
);
1017 else if (!strcasecmp(line
, "State"))
1020 * Set the initial queue state...
1023 if (value
&& !strcasecmp(value
, "idle"))
1024 p
->state
= IPP_PRINTER_IDLE
;
1025 else if (value
&& !strcasecmp(value
, "stopped"))
1026 p
->state
= IPP_PRINTER_STOPPED
;
1029 cupsdLogMessage(CUPSD_LOG_ERROR
,
1030 "Syntax error on line %d of printers.conf.", linenum
);
1034 else if (!strcasecmp(line
, "StateMessage"))
1037 * Set the initial queue state message...
1041 strlcpy(p
->state_message
, value
, sizeof(p
->state_message
));
1043 else if (!strcasecmp(line
, "StateTime"))
1046 * Set the state time...
1050 p
->state_time
= atoi(value
);
1052 else if (!strcasecmp(line
, "Accepting"))
1055 * Set the initial accepting state...
1059 (!strcasecmp(value
, "yes") ||
1060 !strcasecmp(value
, "on") ||
1061 !strcasecmp(value
, "true")))
1064 (!strcasecmp(value
, "no") ||
1065 !strcasecmp(value
, "off") ||
1066 !strcasecmp(value
, "false")))
1070 cupsdLogMessage(CUPSD_LOG_ERROR
,
1071 "Syntax error on line %d of printers.conf.", linenum
);
1075 else if (!strcasecmp(line
, "Shared"))
1078 * Set the initial shared state...
1082 (!strcasecmp(value
, "yes") ||
1083 !strcasecmp(value
, "on") ||
1084 !strcasecmp(value
, "true")))
1087 (!strcasecmp(value
, "no") ||
1088 !strcasecmp(value
, "off") ||
1089 !strcasecmp(value
, "false")))
1093 cupsdLogMessage(CUPSD_LOG_ERROR
,
1094 "Syntax error on line %d of printers.conf.", linenum
);
1098 else if (!strcasecmp(line
, "JobSheets"))
1101 * Set the initial job sheets...
1106 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1111 cupsdSetString(&p
->job_sheets
[0], value
);
1113 while (isspace(*valueptr
& 255))
1118 for (value
= valueptr
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1123 cupsdSetString(&p
->job_sheets
[1], value
);
1128 cupsdLogMessage(CUPSD_LOG_ERROR
,
1129 "Syntax error on line %d of printers.conf.", linenum
);
1133 else if (!strcasecmp(line
, "AllowUser"))
1138 cupsdAddPrinterUser(p
, value
);
1142 cupsdLogMessage(CUPSD_LOG_ERROR
,
1143 "Syntax error on line %d of printers.conf.", linenum
);
1147 else if (!strcasecmp(line
, "DenyUser"))
1152 cupsdAddPrinterUser(p
, value
);
1156 cupsdLogMessage(CUPSD_LOG_ERROR
,
1157 "Syntax error on line %d of printers.conf.", linenum
);
1161 else if (!strcasecmp(line
, "QuotaPeriod"))
1164 p
->quota_period
= atoi(value
);
1167 cupsdLogMessage(CUPSD_LOG_ERROR
,
1168 "Syntax error on line %d of printers.conf.", linenum
);
1172 else if (!strcasecmp(line
, "PageLimit"))
1175 p
->page_limit
= atoi(value
);
1178 cupsdLogMessage(CUPSD_LOG_ERROR
,
1179 "Syntax error on line %d of printers.conf.", linenum
);
1183 else if (!strcasecmp(line
, "KLimit"))
1186 p
->k_limit
= atoi(value
);
1189 cupsdLogMessage(CUPSD_LOG_ERROR
,
1190 "Syntax error on line %d of printers.conf.", linenum
);
1194 else if (!strcasecmp(line
, "OpPolicy"))
1198 cupsd_policy_t
*pol
; /* Policy */
1201 if ((pol
= cupsdFindPolicy(value
)) != NULL
)
1203 cupsdSetString(&p
->op_policy
, value
);
1204 p
->op_policy_ptr
= pol
;
1207 cupsdLogMessage(CUPSD_LOG_ERROR
,
1208 "Bad policy \"%s\" on line %d of printers.conf",
1213 cupsdLogMessage(CUPSD_LOG_ERROR
,
1214 "Syntax error on line %d of printers.conf.", linenum
);
1218 else if (!strcasecmp(line
, "ErrorPolicy"))
1221 cupsdSetString(&p
->error_policy
, value
);
1224 cupsdLogMessage(CUPSD_LOG_ERROR
,
1225 "Syntax error on line %d of printers.conf.", linenum
);
1232 * Something else we don't understand...
1235 cupsdLogMessage(CUPSD_LOG_ERROR
,
1236 "Unknown configuration directive %s on line %d of printers.conf.",
1246 * 'cupsdRenamePrinter()' - Rename a printer.
1251 cupsd_printer_t
*p
, /* I - Printer */
1252 const char *name
) /* I - New name */
1255 * Remove the printer from the array(s) first...
1258 cupsArrayRemove(Printers
, p
);
1260 if (p
->type
& CUPS_PRINTER_IMPLICIT
)
1261 cupsArrayRemove(ImplicitPrinters
, p
);
1264 * Rename the printer type...
1267 mimeDeleteType(MimeDatabase
, p
->filetype
);
1268 p
->filetype
= mimeAddType(MimeDatabase
, "printer", name
);
1270 mimeDeleteType(MimeDatabase
, p
->prefiltertype
);
1271 p
->prefiltertype
= mimeAddType(MimeDatabase
, "prefilter", name
);
1274 * Rename the printer...
1277 cupsdSetString(&p
->name
, name
);
1280 * Reset printer attributes...
1283 cupsdSetPrinterAttrs(p
);
1286 * Add the printer back to the printer array(s)...
1289 cupsArrayAdd(Printers
, p
);
1291 if (p
->type
& CUPS_PRINTER_IMPLICIT
)
1292 cupsArrayAdd(ImplicitPrinters
, p
);
1297 * 'cupsdSaveAllPrinters()' - Save all printer definitions to the printers.conf
1302 cupsdSaveAllPrinters(void)
1304 int i
; /* Looping var */
1305 cups_file_t
*fp
; /* printers.conf file */
1306 char temp
[1024]; /* Temporary string */
1307 char backup
[1024]; /* printers.conf.O file */
1308 cupsd_printer_t
*printer
; /* Current printer class */
1309 time_t curtime
; /* Current time */
1310 struct tm
*curdate
; /* Current date */
1311 cups_option_t
*option
; /* Current option */
1312 const char *ptr
; /* Pointer into info/location */
1316 * Create the printers.conf file...
1319 snprintf(temp
, sizeof(temp
), "%s/printers.conf", ServerRoot
);
1320 snprintf(backup
, sizeof(backup
), "%s/printers.conf.O", ServerRoot
);
1322 if (rename(temp
, backup
))
1324 if (errno
!= ENOENT
)
1325 cupsdLogMessage(CUPSD_LOG_ERROR
,
1326 "Unable to backup printers.conf - %s", strerror(errno
));
1329 if ((fp
= cupsFileOpen(temp
, "w")) == NULL
)
1331 cupsdLogMessage(CUPSD_LOG_ERROR
,
1332 "Unable to save printers.conf - %s", strerror(errno
));
1334 if (rename(backup
, temp
))
1335 cupsdLogMessage(CUPSD_LOG_ERROR
,
1336 "Unable to restore printers.conf - %s", strerror(errno
));
1340 cupsdLogMessage(CUPSD_LOG_INFO
, "Saving printers.conf...");
1343 * Restrict access to the file...
1346 fchown(cupsFileNumber(fp
), getuid(), Group
);
1347 fchmod(cupsFileNumber(fp
), 0600);
1350 * Write a small header to the file...
1353 curtime
= time(NULL
);
1354 curdate
= localtime(&curtime
);
1355 strftime(temp
, sizeof(temp
) - 1, "%Y-%m-%d %H:%M", curdate
);
1357 cupsFilePuts(fp
, "# Printer configuration file for " CUPS_SVERSION
"\n");
1358 cupsFilePrintf(fp
, "# Written by cupsd on %s\n", temp
);
1361 * Write each local printer known to the system...
1364 for (printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
1366 printer
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
1369 * Skip remote destinations and printer classes...
1372 if ((printer
->type
& CUPS_PRINTER_DISCOVERED
) ||
1373 (printer
->type
& CUPS_PRINTER_CLASS
) ||
1374 (printer
->type
& CUPS_PRINTER_IMPLICIT
))
1378 * Write printers as needed...
1381 if (printer
== DefaultPrinter
)
1382 cupsFilePrintf(fp
, "<DefaultPrinter %s>\n", printer
->name
);
1384 cupsFilePrintf(fp
, "<Printer %s>\n", printer
->name
);
1386 if (printer
->num_auth_info_required
> 0)
1388 cupsFilePrintf(fp
, "AuthInfoRequired %s", printer
->auth_info_required
[0]);
1389 for (i
= 1; i
< printer
->num_auth_info_required
; i
++)
1390 cupsFilePrintf(fp
, ",%s", printer
->auth_info_required
[i
]);
1391 cupsFilePutChar(fp
, '\n');
1396 if ((ptr
= strchr(printer
->info
, '#')) != NULL
)
1399 * Need to quote the first # in the info string...
1402 cupsFilePuts(fp
, "Info ");
1403 cupsFileWrite(fp
, printer
->info
, ptr
- printer
->info
);
1404 cupsFilePutChar(fp
, '\\');
1405 cupsFilePuts(fp
, ptr
);
1406 cupsFilePutChar(fp
, '\n');
1409 cupsFilePrintf(fp
, "Info %s\n", printer
->info
);
1412 if (printer
->location
)
1414 if ((ptr
= strchr(printer
->info
, '#')) != NULL
)
1417 * Need to quote the first # in the location string...
1420 cupsFilePuts(fp
, "Location ");
1421 cupsFileWrite(fp
, printer
->location
, ptr
- printer
->location
);
1422 cupsFilePutChar(fp
, '\\');
1423 cupsFilePuts(fp
, ptr
);
1424 cupsFilePutChar(fp
, '\n');
1427 cupsFilePrintf(fp
, "Location %s\n", printer
->location
);
1429 if (printer
->device_uri
)
1430 cupsFilePrintf(fp
, "DeviceURI %s\n", printer
->device_uri
);
1432 if (printer
->port_monitor
)
1433 cupsFilePrintf(fp
, "PortMonitor %s\n", printer
->port_monitor
);
1435 if (printer
->state
== IPP_PRINTER_STOPPED
)
1437 cupsFilePuts(fp
, "State Stopped\n");
1438 cupsFilePrintf(fp
, "StateMessage %s\n", printer
->state_message
);
1441 cupsFilePuts(fp
, "State Idle\n");
1443 cupsFilePrintf(fp
, "StateTime %d\n", (int)printer
->state_time
);
1445 if (printer
->accepting
)
1446 cupsFilePuts(fp
, "Accepting Yes\n");
1448 cupsFilePuts(fp
, "Accepting No\n");
1450 if (printer
->shared
)
1451 cupsFilePuts(fp
, "Shared Yes\n");
1453 cupsFilePuts(fp
, "Shared No\n");
1455 cupsFilePrintf(fp
, "JobSheets %s %s\n", printer
->job_sheets
[0],
1456 printer
->job_sheets
[1]);
1458 cupsFilePrintf(fp
, "QuotaPeriod %d\n", printer
->quota_period
);
1459 cupsFilePrintf(fp
, "PageLimit %d\n", printer
->page_limit
);
1460 cupsFilePrintf(fp
, "KLimit %d\n", printer
->k_limit
);
1462 for (i
= 0; i
< printer
->num_users
; i
++)
1463 cupsFilePrintf(fp
, "%sUser %s\n", printer
->deny_users
? "Deny" : "Allow",
1466 if (printer
->op_policy
)
1467 cupsFilePrintf(fp
, "OpPolicy %s\n", printer
->op_policy
);
1468 if (printer
->error_policy
)
1469 cupsFilePrintf(fp
, "ErrorPolicy %s\n", printer
->error_policy
);
1471 for (i
= printer
->num_options
, option
= printer
->options
;
1474 cupsFilePrintf(fp
, "Option %s %s\n", option
->name
, option
->value
);
1476 cupsFilePuts(fp
, "</Printer>\n");
1480 * Make IRIX desktop & printer status happy
1483 write_irix_state(printer
);
1492 * 'cupsdSetAuthInfoRequired()' - Set the required authentication info.
1495 int /* O - 1 if value OK, 0 otherwise */
1496 cupsdSetAuthInfoRequired(
1497 cupsd_printer_t
*p
, /* I - Printer */
1498 const char *values
, /* I - Plain text value (or NULL) */
1499 ipp_attribute_t
*attr
) /* I - IPP attribute value (or NULL) */
1501 int i
; /* Looping var */
1504 p
->num_auth_info_required
= 0;
1507 * Do we have a plain text value?
1513 * Yes, grab the keywords...
1516 const char *end
; /* End of current value */
1519 while (*values
&& p
->num_auth_info_required
< 4)
1521 if ((end
= strchr(values
, ',')) == NULL
)
1522 end
= values
+ strlen(values
);
1524 if ((end
- values
) == 4 && !strncmp(values
, "none", 4))
1526 if (p
->num_auth_info_required
!= 0 || *end
)
1529 p
->auth_info_required
[p
->num_auth_info_required
] = "none";
1530 p
->num_auth_info_required
++;
1534 else if ((end
- values
) == 9 && !strncmp(values
, "negotiate", 9))
1536 if (p
->num_auth_info_required
!= 0 || *end
)
1539 p
->auth_info_required
[p
->num_auth_info_required
] = "negotiate";
1540 p
->num_auth_info_required
++;
1542 else if ((end
- values
) == 6 && !strncmp(values
, "domain", 6))
1544 p
->auth_info_required
[p
->num_auth_info_required
] = "domain";
1545 p
->num_auth_info_required
++;
1547 else if ((end
- values
) == 8 && !strncmp(values
, "password", 8))
1549 p
->auth_info_required
[p
->num_auth_info_required
] = "password";
1550 p
->num_auth_info_required
++;
1552 else if ((end
- values
) == 8 && !strncmp(values
, "username", 8))
1554 p
->auth_info_required
[p
->num_auth_info_required
] = "username";
1555 p
->num_auth_info_required
++;
1560 values
= (*end
) ? end
+ 1 : end
;
1563 if (p
->num_auth_info_required
== 0)
1565 p
->auth_info_required
[0] = "none";
1566 p
->num_auth_info_required
= 1;
1570 * Update the printer-type value as needed...
1573 if (p
->num_auth_info_required
> 1 ||
1574 strcmp(p
->auth_info_required
[0], "none"))
1575 p
->type
|= CUPS_PRINTER_AUTHENTICATED
;
1577 p
->type
&= ~CUPS_PRINTER_AUTHENTICATED
;
1583 * Grab values from an attribute instead...
1586 if (!attr
|| attr
->num_values
> 4)
1590 * Update the printer-type value as needed...
1593 if (attr
->num_values
> 1 ||
1594 strcmp(attr
->values
[0].string
.text
, "none"))
1595 p
->type
|= CUPS_PRINTER_AUTHENTICATED
;
1597 p
->type
&= ~CUPS_PRINTER_AUTHENTICATED
;
1599 for (i
= 0; i
< attr
->num_values
; i
++)
1601 if (!strcmp(attr
->values
[i
].string
.text
, "none"))
1603 if (p
->num_auth_info_required
!= 0 || attr
->num_values
!= 1)
1606 p
->auth_info_required
[p
->num_auth_info_required
] = "none";
1607 p
->num_auth_info_required
++;
1611 else if (!strcmp(attr
->values
[i
].string
.text
, "negotiate"))
1613 if (p
->num_auth_info_required
!= 0 || attr
->num_values
!= 1)
1616 p
->auth_info_required
[p
->num_auth_info_required
] = "negotiate";
1617 p
->num_auth_info_required
++;
1621 else if (!strcmp(attr
->values
[i
].string
.text
, "domain"))
1623 p
->auth_info_required
[p
->num_auth_info_required
] = "domain";
1624 p
->num_auth_info_required
++;
1626 else if (!strcmp(attr
->values
[i
].string
.text
, "password"))
1628 p
->auth_info_required
[p
->num_auth_info_required
] = "password";
1629 p
->num_auth_info_required
++;
1631 else if (!strcmp(attr
->values
[i
].string
.text
, "username"))
1633 p
->auth_info_required
[p
->num_auth_info_required
] = "username";
1634 p
->num_auth_info_required
++;
1645 * 'cupsdSetPrinterAttrs()' - Set printer attributes based upon the PPD file.
1649 cupsdSetPrinterAttrs(cupsd_printer_t
*p
)/* I - Printer to setup */
1651 int i
, /* Looping var */
1652 length
; /* Length of browse attributes */
1653 char uri
[HTTP_MAX_URI
]; /* URI for printer */
1654 char resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
1655 char filename
[1024]; /* Name of PPD file */
1656 int num_air
; /* Number of auth-info-required values */
1657 const char * const *air
; /* auth-info-required values */
1658 int num_media
; /* Number of media options */
1659 cupsd_location_t
*auth
; /* Pointer to authentication element */
1660 const char *auth_supported
; /* Authentication supported */
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"
1680 static const char * const air_userpass
[] =
1681 { /* Basic/Digest authentication */
1685 static const char * const air_negotiate
[] =
1686 { /* Kerberos authentication */
1689 static const char * const air_none
[] =
1690 { /* No authentication */
1695 DEBUG_printf(("cupsdSetPrinterAttrs: entering name = %s, type = %x\n", p
->name
,
1699 * Make sure that we have the common attributes defined...
1703 cupsdCreateCommonData();
1706 * Clear out old filters, if any...
1709 delete_printer_filters(p
);
1712 * Figure out the authentication that is required for the printer.
1715 auth_supported
= "requesting-user-name";
1719 if (p
->num_auth_info_required
> 0 && strcmp(p
->auth_info_required
[0], "none"))
1721 num_air
= p
->num_auth_info_required
;
1722 air
= p
->auth_info_required
;
1724 if (!strcmp(air
[0], "username"))
1725 auth_supported
= "basic";
1727 auth_supported
= "negotiate";
1729 else if (!(p
->type
& CUPS_PRINTER_DISCOVERED
))
1731 if (p
->type
& CUPS_PRINTER_CLASS
)
1732 snprintf(resource
, sizeof(resource
), "/classes/%s", p
->name
);
1734 snprintf(resource
, sizeof(resource
), "/printers/%s", p
->name
);
1736 if ((auth
= cupsdFindBest(resource
, HTTP_POST
)) == NULL
||
1737 auth
->type
== AUTH_NONE
)
1738 auth
= cupsdFindPolicyOp(p
->op_policy_ptr
, IPP_PRINT_JOB
);
1742 if (auth
->type
== AUTH_BASIC
|| auth
->type
== AUTH_BASICDIGEST
)
1744 auth_supported
= "basic";
1748 else if (auth
->type
== AUTH_DIGEST
)
1750 auth_supported
= "digest";
1755 else if (auth
->type
== AUTH_NEGOTIATE
)
1757 auth_supported
= "negotiate";
1759 air
= air_negotiate
;
1761 #endif /* HAVE_GSSAPI */
1763 if (auth
->type
!= AUTH_NONE
)
1764 p
->type
|= CUPS_PRINTER_AUTHENTICATED
;
1766 p
->type
&= ~CUPS_PRINTER_AUTHENTICATED
;
1769 p
->type
&= ~CUPS_PRINTER_AUTHENTICATED
;
1771 else if (p
->type
& CUPS_PRINTER_AUTHENTICATED
)
1778 * Create the required IPP attributes for a printer...
1782 ippDelete(p
->attrs
);
1784 p
->attrs
= ippNew();
1786 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
1787 "uri-authentication-supported", NULL
, auth_supported
);
1788 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
1789 "uri-security-supported", NULL
, "none");
1790 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
, "printer-name", NULL
,
1792 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-location",
1793 NULL
, p
->location
? p
->location
: "");
1794 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-info",
1795 NULL
, p
->info
? p
->info
: "");
1796 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "printer-more-info",
1802 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
1803 "requesting-user-name-denied", p
->num_users
, NULL
,
1806 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
1807 "requesting-user-name-allowed", p
->num_users
, NULL
,
1811 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
1812 "job-quota-period", p
->quota_period
);
1813 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
1814 "job-k-limit", p
->k_limit
);
1815 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
1816 "job-page-limit", p
->page_limit
);
1817 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
1818 "auth-info-required", num_air
, NULL
, air
);
1820 if (cupsArrayCount(Banners
) > 0 && !(p
->type
& CUPS_PRINTER_DISCOVERED
))
1823 * Setup the job-sheets-default attribute...
1826 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
1827 "job-sheets-default", 2, NULL
, NULL
);
1831 attr
->values
[0].string
.text
= _cupsStrAlloc(Classification
?
1832 Classification
: p
->job_sheets
[0]);
1833 attr
->values
[1].string
.text
= _cupsStrAlloc(Classification
?
1834 Classification
: p
->job_sheets
[1]);
1841 if (p
->type
& CUPS_PRINTER_DISCOVERED
)
1844 * Tell the client this is a remote printer of some type...
1847 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
1848 "printer-uri-supported", NULL
, p
->uri
);
1851 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
1852 "printer-make-and-model", NULL
, p
->make_model
);
1854 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "device-uri", NULL
,
1863 * Assign additional attributes depending on whether this is a printer
1867 p
->type
&= ~CUPS_PRINTER_OPTIONS
;
1869 if (p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
))
1874 * Add class-specific attributes...
1877 if ((p
->type
& CUPS_PRINTER_IMPLICIT
) && p
->num_printers
> 0 &&
1878 p
->printers
[0]->make_model
)
1879 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
1880 "printer-make-and-model", NULL
, p
->printers
[0]->make_model
);
1882 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
1883 "printer-make-and-model", NULL
, "Local Printer Class");
1885 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "device-uri", NULL
,
1886 "file:///dev/null");
1888 if (p
->num_printers
> 0)
1891 * Add a list of member URIs and names...
1894 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
1895 "member-uris", p
->num_printers
, NULL
, NULL
);
1896 p
->type
|= CUPS_PRINTER_OPTIONS
;
1898 for (i
= 0; i
< p
->num_printers
; i
++)
1901 attr
->values
[i
].string
.text
= _cupsStrAlloc(p
->printers
[i
]->uri
);
1903 p
->type
&= ~CUPS_PRINTER_OPTIONS
| p
->printers
[i
]->type
;
1906 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
1907 "member-names", p
->num_printers
, NULL
, NULL
);
1911 for (i
= 0; i
< p
->num_printers
; i
++)
1912 attr
->values
[i
].string
.text
= _cupsStrAlloc(p
->printers
[i
]->name
);
1919 * Add printer-specific attributes... Start by sanitizing the device
1920 * URI so it doesn't have a username or password in it...
1924 strcpy(uri
, "file:/dev/null");
1925 else if (strstr(p
->device_uri
, "://") != NULL
)
1928 * http://..., ipp://..., etc.
1931 cupsdSanitizeURI(p
->device_uri
, uri
, sizeof(uri
));
1936 * file:..., serial:..., etc.
1939 strlcpy(uri
, p
->device_uri
, sizeof(uri
));
1942 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "device-uri", NULL
,
1946 * Assign additional attributes from the PPD file (if any)...
1949 p
->type
|= CUPS_PRINTER_BW
;
1950 finishings
[0] = IPP_FINISHINGS_NONE
;
1953 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
1956 if ((ppd
= ppdOpenFile(filename
)) != NULL
)
1959 * Add make/model and other various attributes...
1962 if (ppd
->color_device
)
1963 p
->type
|= CUPS_PRINTER_COLOR
;
1964 if (ppd
->variable_sizes
)
1965 p
->type
|= CUPS_PRINTER_VARIABLE
;
1966 if (!ppd
->manual_copies
)
1967 p
->type
|= CUPS_PRINTER_COPIES
;
1968 if ((ppdattr
= ppdFindAttr(ppd
, "cupsFax", NULL
)) != NULL
)
1969 if (ppdattr
->value
&& !strcasecmp(ppdattr
->value
, "true"))
1970 p
->type
|= CUPS_PRINTER_FAX
;
1972 ippAddBoolean(p
->attrs
, IPP_TAG_PRINTER
, "color-supported",
1974 if (ppd
->throughput
)
1975 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
1976 "pages-per-minute", ppd
->throughput
);
1981 * The NickName can be localized in the character set specified
1982 * by the LanugageEncoding attribute. However, ppdOpen2() has
1983 * already converted the ppd->nickname member to UTF-8 for us
1984 * (the original attribute value is available separately)
1987 cupsdSetString(&p
->make_model
, ppd
->nickname
);
1989 else if (ppd
->modelname
)
1992 * Model name can only contain specific characters...
1995 cupsdSetString(&p
->make_model
, ppd
->modelname
);
1998 cupsdSetString(&p
->make_model
, "Bad PPD File");
2000 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
2001 "printer-make-and-model", NULL
, p
->make_model
);
2004 * Add media options from the PPD file...
2007 if ((input_slot
= ppdFindOption(ppd
, "InputSlot")) != NULL
)
2008 num_media
= input_slot
->num_choices
;
2012 if ((media_type
= ppdFindOption(ppd
, "MediaType")) != NULL
)
2013 num_media
+= media_type
->num_choices
;
2015 if ((page_size
= ppdFindOption(ppd
, "PageSize")) != NULL
)
2016 num_media
+= page_size
->num_choices
;
2018 if ((media_quality
= ppdFindOption(ppd
, "EFMediaQualityMode")) != NULL
)
2019 num_media
+= media_quality
->num_choices
;
2023 cupsdLogMessage(CUPSD_LOG_CRIT
,
2024 "The PPD file for printer %s contains no media "
2025 "options and is therefore invalid!", p
->name
);
2029 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2030 "media-supported", num_media
, NULL
, NULL
);
2035 if (input_slot
!= NULL
)
2036 for (i
= 0; i
< input_slot
->num_choices
; i
++, val
++)
2037 val
->string
.text
= _cupsStrAlloc(input_slot
->choices
[i
].choice
);
2039 if (media_type
!= NULL
)
2040 for (i
= 0; i
< media_type
->num_choices
; i
++, val
++)
2041 val
->string
.text
= _cupsStrAlloc(media_type
->choices
[i
].choice
);
2043 if (media_quality
!= NULL
)
2044 for (i
= 0; i
< media_quality
->num_choices
; i
++, val
++)
2045 val
->string
.text
= _cupsStrAlloc(media_quality
->choices
[i
].choice
);
2047 if (page_size
!= NULL
)
2049 for (i
= 0; i
< page_size
->num_choices
; i
++, val
++)
2050 val
->string
.text
= _cupsStrAlloc(page_size
->choices
[i
].choice
);
2052 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2053 "media-default", NULL
, page_size
->defchoice
);
2055 else if (input_slot
!= NULL
)
2056 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2057 "media-default", NULL
, input_slot
->defchoice
);
2058 else if (media_type
!= NULL
)
2059 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2060 "media-default", NULL
, media_type
->defchoice
);
2061 else if (media_quality
!= NULL
)
2062 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2063 "media-default", NULL
, media_quality
->defchoice
);
2065 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2066 "media-default", NULL
, "none");
2074 if ((output_bin
= ppdFindOption(ppd
, "OutputBin")) != NULL
)
2076 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2077 "output-bin-supported", output_bin
->num_choices
,
2082 for (i
= 0, val
= attr
->values
;
2083 i
< output_bin
->num_choices
;
2085 val
->string
.text
= _cupsStrAlloc(output_bin
->choices
[i
].choice
);
2093 if ((duplex
= ppdFindOption(ppd
, "Duplex")) == NULL
)
2094 if ((duplex
= ppdFindOption(ppd
, "EFDuplex")) == NULL
)
2095 if ((duplex
= ppdFindOption(ppd
, "EFDuplexing")) == NULL
)
2096 if ((duplex
= ppdFindOption(ppd
, "KD03Duplex")) == NULL
)
2097 duplex
= ppdFindOption(ppd
, "JCLDuplex");
2099 if (duplex
&& duplex
->num_choices
> 1)
2101 p
->type
|= CUPS_PRINTER_DUPLEX
;
2103 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2104 "sides-supported", 3, NULL
, sides
);
2106 if (!strcasecmp(duplex
->defchoice
, "DuplexTumble"))
2107 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2108 "sides-default", NULL
, "two-sided-short-edge");
2109 else if (!strcasecmp(duplex
->defchoice
, "DuplexNoTumble"))
2110 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2111 "sides-default", NULL
, "two-sided-long-edge");
2113 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2114 "sides-default", NULL
, "one-sided");
2117 if (ppdFindOption(ppd
, "Collate") != NULL
)
2118 p
->type
|= CUPS_PRINTER_COLLATE
;
2120 if (ppdFindOption(ppd
, "StapleLocation") != NULL
)
2122 p
->type
|= CUPS_PRINTER_STAPLE
;
2123 finishings
[num_finishings
++] = IPP_FINISHINGS_STAPLE
;
2126 if (ppdFindOption(ppd
, "BindEdge") != NULL
)
2128 p
->type
|= CUPS_PRINTER_BIND
;
2129 finishings
[num_finishings
++] = IPP_FINISHINGS_BIND
;
2132 for (i
= 0; i
< ppd
->num_sizes
; i
++)
2133 if (ppd
->sizes
[i
].length
> 1728)
2134 p
->type
|= CUPS_PRINTER_LARGE
;
2135 else if (ppd
->sizes
[i
].length
> 1008)
2136 p
->type
|= CUPS_PRINTER_MEDIUM
;
2138 p
->type
|= CUPS_PRINTER_SMALL
;
2141 * Add a filter from application/vnd.cups-raw to printer/name to
2142 * handle "raw" printing by users.
2145 add_printer_filter(p
, p
->filetype
, "application/vnd.cups-raw 0 -");
2148 * Add any pre-filters in the PPD file...
2151 if ((ppdattr
= ppdFindAttr(ppd
, "cupsPreFilter", NULL
)) != NULL
)
2153 p
->prefiltertype
= mimeAddType(MimeDatabase
, "prefilter", p
->name
);
2155 for (; ppdattr
; ppdattr
= ppdFindNextAttr(ppd
, "cupsPreFilter", NULL
))
2157 add_printer_filter(p
, p
->prefiltertype
, ppdattr
->value
);
2161 * Add any filters in the PPD file...
2164 DEBUG_printf(("ppd->num_filters = %d\n", ppd
->num_filters
));
2165 for (i
= 0; i
< ppd
->num_filters
; i
++)
2167 DEBUG_printf(("ppd->filters[%d] = \"%s\"\n", i
, ppd
->filters
[i
]));
2168 add_printer_filter(p
, p
->filetype
, ppd
->filters
[i
]);
2171 if (ppd
->num_filters
== 0)
2174 * If there are no filters, add a PostScript printing filter.
2177 add_printer_filter(p
, p
->filetype
,
2178 "application/vnd.cups-postscript 0 -");
2182 * Show current and available port monitors for this printer...
2185 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
, "port-monitor",
2186 NULL
, p
->port_monitor
? p
->port_monitor
: "none");
2188 for (i
= 1, ppdattr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
2190 i
++, ppdattr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
));
2194 if (strstr(ppd
->protocols
, "TBCP"))
2196 else if (strstr(ppd
->protocols
, "BCP"))
2200 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2201 "port-monitor-supported", i
, NULL
, NULL
);
2203 attr
->values
[0].string
.text
= _cupsStrAlloc("none");
2205 for (i
= 1, ppdattr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
2207 i
++, ppdattr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
))
2208 attr
->values
[i
].string
.text
= _cupsStrAlloc(ppdattr
->value
);
2212 if (strstr(ppd
->protocols
, "TBCP"))
2213 attr
->values
[i
].string
.text
= _cupsStrAlloc("tbcp");
2214 else if (strstr(ppd
->protocols
, "BCP"))
2215 attr
->values
[i
].string
.text
= _cupsStrAlloc("bcp");
2219 cupsdSetString(&p
->product
, ppd
->product
);
2220 #endif /* HAVE_DNSSD */
2222 if (ppdFindAttr(ppd
, "APRemoteQueueID", NULL
))
2223 p
->type
|= CUPS_PRINTER_REMOTE
;
2226 * Close the PPD and set the type...
2231 else if (!access(filename
, 0))
2233 int pline
; /* PPD line number */
2234 ppd_status_t pstatus
; /* PPD load status */
2237 pstatus
= ppdLastError(&pline
);
2239 cupsdLogMessage(CUPSD_LOG_ERROR
, "PPD file for %s cannot be loaded!",
2242 if (pstatus
<= PPD_ALLOC_ERROR
)
2243 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s", strerror(errno
));
2245 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s on line %d.",
2246 ppdErrorString(pstatus
), pline
);
2248 cupsdLogMessage(CUPSD_LOG_INFO
,
2249 "Hint: Run \"cupstestppd %s\" and fix any errors.",
2253 * Add a filter from application/vnd.cups-raw to printer/name to
2254 * handle "raw" printing by users.
2257 add_printer_filter(p
, p
->filetype
, "application/vnd.cups-raw 0 -");
2260 * Add a PostScript filter, since this is still possibly PS printer.
2263 add_printer_filter(p
, p
->filetype
,
2264 "application/vnd.cups-postscript 0 -");
2269 * If we have an interface script, add a filter entry for it...
2272 snprintf(filename
, sizeof(filename
), "%s/interfaces/%s", ServerRoot
,
2274 if (!access(filename
, X_OK
))
2277 * Yes, we have a System V style interface script; use it!
2280 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
2281 "printer-make-and-model", NULL
,
2282 "Local System V Printer");
2284 snprintf(filename
, sizeof(filename
), "*/* 0 %s/interfaces/%s",
2285 ServerRoot
, p
->name
);
2286 add_printer_filter(p
, p
->filetype
, filename
);
2288 else if (p
->device_uri
&&
2289 !strncmp(p
->device_uri
, "ipp://", 6) &&
2290 (strstr(p
->device_uri
, "/printers/") != NULL
||
2291 strstr(p
->device_uri
, "/classes/") != NULL
))
2294 * Tell the client this is really a hard-wired remote printer.
2297 p
->type
|= CUPS_PRINTER_REMOTE
;
2300 * Point the printer-uri-supported attribute to the
2304 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
2305 "printer-uri-supported", NULL
, p
->device_uri
);
2308 * Then set the make-and-model accordingly...
2311 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
2312 "printer-make-and-model", NULL
, "Remote Printer");
2315 * Print all files directly...
2324 * Otherwise we have neither - treat this as a "dumb" printer
2325 * with no PPD file...
2328 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
2329 "printer-make-and-model", NULL
, "Local Raw Printer");
2335 ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
2336 "finishings-supported", num_finishings
, finishings
);
2337 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
2338 "finishings-default", IPP_FINISHINGS_NONE
);
2343 * Force sharing off for remote queues...
2346 if (p
->type
& (CUPS_PRINTER_REMOTE
| CUPS_PRINTER_IMPLICIT
))
2351 * Copy the printer options into a browse attributes string we can re-use.
2354 const char *valptr
; /* Pointer into value */
2355 char *attrptr
; /* Pointer into attribute string */
2359 * Free the old browse attributes as needed...
2362 if (p
->browse_attrs
)
2363 free(p
->browse_attrs
);
2366 * Compute the length of all attributes + job-sheets, lease-duration,
2367 * and BrowseLocalOptions.
2370 for (length
= 1, i
= p
->num_options
, option
= p
->options
;
2374 length
+= strlen(option
->name
) + 2;
2378 for (valptr
= option
->value
; *valptr
; valptr
++)
2379 if (strchr(" \"\'\\", *valptr
))
2386 length
+= 13 + strlen(p
->job_sheets
[0]) + strlen(p
->job_sheets
[1]);
2388 if (BrowseLocalOptions
)
2389 length
+= 12 + strlen(BrowseLocalOptions
);
2391 if (p
->num_auth_info_required
> 0)
2393 length
+= 18; /* auth-info-required */
2395 for (i
= 0; i
< p
->num_auth_info_required
; i
++)
2396 length
+= strlen(p
->auth_info_required
[i
]) + 1;
2400 * Allocate the new string...
2403 if ((p
->browse_attrs
= calloc(1, length
)) == NULL
)
2404 cupsdLogMessage(CUPSD_LOG_ERROR
,
2405 "Unable to allocate %d bytes for browse data!",
2410 * Got the allocated string, now copy the options and attributes over...
2413 sprintf(p
->browse_attrs
, "job-sheets=%s,%s lease-duration=%d",
2414 p
->job_sheets
[0], p
->job_sheets
[1], BrowseTimeout
);
2415 attrptr
= p
->browse_attrs
+ strlen(p
->browse_attrs
);
2417 if (BrowseLocalOptions
)
2419 sprintf(attrptr
, " ipp-options=%s", BrowseLocalOptions
);
2420 attrptr
+= strlen(attrptr
);
2423 for (i
= p
->num_options
, option
= p
->options
;
2428 strcpy(attrptr
, option
->name
);
2429 attrptr
+= strlen(attrptr
);
2435 for (valptr
= option
->value
; *valptr
; valptr
++)
2437 if (strchr(" \"\'\\", *valptr
))
2440 *attrptr
++ = *valptr
;
2445 if (p
->num_auth_info_required
> 0)
2447 strcpy(attrptr
, "auth-info-required");
2450 for (i
= 0; i
< p
->num_auth_info_required
; i
++)
2452 *attrptr
++ = i
? ',' : '=';
2453 strcpy(attrptr
, p
->auth_info_required
[i
]);
2454 attrptr
+= strlen(attrptr
);
2463 * Populate the document-format-supported attribute...
2466 add_printer_formats(p
);
2468 DEBUG_printf(("cupsdSetPrinterAttrs: leaving name = %s, type = %x\n", p
->name
,
2472 * Add name-default attributes...
2475 add_printer_defaults(p
);
2479 * Write the IRIX printer config and status files...
2482 write_irix_config(p
);
2483 write_irix_state(p
);
2487 * Let the browse protocols reflect the change
2490 cupsdRegisterPrinter(p
);
2495 * 'cupsdSetPrinterReasons()' - Set/update the reasons strings.
2499 cupsdSetPrinterReasons(
2500 cupsd_printer_t
*p
, /* I - Printer */
2501 const char *s
) /* I - Reasons strings */
2503 int i
; /* Looping var */
2504 const char *sptr
; /* Pointer into reasons */
2505 char reason
[255], /* Reason string */
2506 *rptr
; /* Pointer into reason */
2509 if (s
[0] == '-' || s
[0] == '+')
2512 * Add/remove reasons...
2520 * Replace reasons...
2525 for (i
= 0; i
< p
->num_reasons
; i
++)
2526 free(p
->reasons
[i
]);
2531 if (!strcmp(s
, "none"))
2535 * Loop through all of the reasons...
2541 * Skip leading whitespace and commas...
2544 while (isspace(*sptr
& 255) || *sptr
== ',')
2547 for (rptr
= reason
; *sptr
&& !isspace(*sptr
& 255) && *sptr
!= ','; sptr
++)
2548 if (rptr
< (reason
+ sizeof(reason
) - 1))
2562 for (i
= 0; i
< p
->num_reasons
; i
++)
2563 if (!strcasecmp(reason
, p
->reasons
[i
]))
2566 * Found a match, so remove it...
2570 free(p
->reasons
[i
]);
2572 if (i
< p
->num_reasons
)
2573 memmove(p
->reasons
+ i
, p
->reasons
+ i
+ 1,
2574 (p
->num_reasons
- i
) * sizeof(char *));
2578 if (!strcmp(reason
, "paused") && p
->state
== IPP_PRINTER_STOPPED
)
2579 cupsdSetPrinterState(p
, IPP_PRINTER_IDLE
, 1);
2582 else if (p
->num_reasons
< (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
2588 for (i
= 0; i
< p
->num_reasons
; i
++)
2589 if (!strcasecmp(reason
, p
->reasons
[i
]))
2592 if (i
>= p
->num_reasons
)
2594 p
->reasons
[i
] = strdup(reason
);
2597 if (!strcmp(reason
, "paused") && p
->state
!= IPP_PRINTER_STOPPED
)
2598 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, 1);
2606 * 'cupsdSetPrinterState()' - Update the current state of a printer.
2610 cupsdSetPrinterState(
2611 cupsd_printer_t
*p
, /* I - Printer to change */
2612 ipp_pstate_t s
, /* I - New state */
2613 int update
) /* I - Update printers.conf? */
2615 ipp_pstate_t old_state
; /* Old printer state */
2619 * Can't set status of remote printers...
2622 if (p
->type
& CUPS_PRINTER_DISCOVERED
)
2626 * Set the new state...
2629 old_state
= p
->state
;
2634 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE_CHANGED
, p
, NULL
,
2635 "%s \"%s\" state changed.",
2636 (p
->type
& CUPS_PRINTER_CLASS
) ? "Class" : "Printer",
2640 * Let the browse code know this needs to be updated...
2644 p
->state_time
= time(NULL
);
2648 write_irix_state(p
);
2652 cupsdAddPrinterHistory(p
);
2655 * Let the browse protocols reflect the change...
2658 cupsdRegisterPrinter(p
);
2661 * Save the printer configuration if a printer goes from idle or processing
2662 * to stopped (or visa-versa)...
2665 if ((old_state
== IPP_PRINTER_STOPPED
) != (s
== IPP_PRINTER_STOPPED
) &&
2668 if (p
->type
& CUPS_PRINTER_CLASS
)
2669 cupsdSaveAllClasses();
2671 cupsdSaveAllPrinters();
2677 * 'cupsdStopPrinter()' - Stop a printer from printing any jobs...
2681 cupsdStopPrinter(cupsd_printer_t
*p
, /* I - Printer to stop */
2682 int update
)/* I - Update printers.conf? */
2684 cupsd_job_t
*job
; /* Active print job */
2688 * Set the printer state...
2691 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, update
);
2694 * See if we have a job printing on this printer...
2700 * Get pointer to job...
2703 job
= (cupsd_job_t
*)p
->job
;
2709 cupsdStopJob(job
, 0);
2712 * Reset the state to pending...
2715 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
2716 job
->state_value
= IPP_JOB_PENDING
;
2720 cupsdAddEvent(CUPSD_EVENT_JOB_STOPPED
, p
, job
,
2721 "Job stopped due to printer being paused");
2727 * 'cupsdUpdatePrinters()' - Update printers after a partial reload.
2731 cupsdUpdatePrinters(void)
2733 cupsd_printer_t
*p
; /* Current printer */
2737 * Loop through the printers and recreate the printer attributes
2738 * for any local printers since the policy and/or access control
2739 * stuff may have changed. Also, if browsing is disabled, remove
2740 * any remote printers...
2743 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
2745 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
2748 * Remove remote printers if we are no longer browsing...
2752 (p
->type
& (CUPS_PRINTER_IMPLICIT
| CUPS_PRINTER_DISCOVERED
)))
2754 if (p
->type
& CUPS_PRINTER_IMPLICIT
)
2755 cupsArrayRemove(ImplicitPrinters
, p
);
2757 cupsArraySave(Printers
);
2758 cupsdDeletePrinter(p
, 0);
2759 cupsArrayRestore(Printers
);
2764 * Update the operation policy pointer...
2767 if ((p
->op_policy_ptr
= cupsdFindPolicy(p
->op_policy
)) == NULL
)
2768 p
->op_policy_ptr
= DefaultPolicyPtr
;
2771 * Update printer attributes as needed...
2774 if (!(p
->type
& CUPS_PRINTER_DISCOVERED
))
2775 cupsdSetPrinterAttrs(p
);
2781 * 'cupsdValidateDest()' - Validate a printer/class destination.
2784 const char * /* O - Printer or class name */
2786 const char *uri
, /* I - Printer URI */
2787 cups_ptype_t
*dtype
, /* O - Type (printer or class) */
2788 cupsd_printer_t
**printer
) /* O - Printer pointer */
2790 cupsd_printer_t
*p
; /* Current printer */
2791 char localname
[1024],/* Localized hostname */
2792 *lptr
, /* Pointer into localized hostname */
2793 *sptr
, /* Pointer into server name */
2794 *rptr
, /* Pointer into resource */
2795 scheme
[32], /* Scheme portion of URI */
2796 username
[64], /* Username portion of URI */
2797 hostname
[HTTP_MAX_HOST
],
2798 /* Host portion of URI */
2799 resource
[HTTP_MAX_URI
];
2800 /* Resource portion of URI */
2801 int port
; /* Port portion of URI */
2804 DEBUG_printf(("cupsdValidateDest(uri=\"%s\", dtype=%p, printer=%p)\n", uri
,
2808 * Initialize return values...
2815 *dtype
= (cups_ptype_t
)0;
2818 * Pull the hostname and resource from the URI...
2821 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
, scheme
, sizeof(scheme
),
2822 username
, sizeof(username
), hostname
, sizeof(hostname
),
2823 &port
, resource
, sizeof(resource
));
2826 * See if the resource is a class or printer...
2829 if (!strncmp(resource
, "/classes/", 9))
2835 rptr
= resource
+ 9;
2837 else if (!strncmp(resource
, "/printers/", 10))
2843 rptr
= resource
+ 10;
2848 * Bad resource name...
2855 * See if the printer or class name exists...
2858 p
= cupsdFindDest(rptr
);
2860 if (p
== NULL
&& strchr(rptr
, '@') == NULL
)
2868 *dtype
= p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
|
2869 CUPS_PRINTER_REMOTE
| CUPS_PRINTER_DISCOVERED
);
2875 * Change localhost to the server name...
2878 if (!strcasecmp(hostname
, "localhost"))
2879 strlcpy(hostname
, ServerName
, sizeof(hostname
));
2881 strlcpy(localname
, hostname
, sizeof(localname
));
2883 if (!strcasecmp(hostname
, ServerName
))
2886 * Localize the hostname...
2889 lptr
= strchr(localname
, '.');
2890 sptr
= strchr(ServerName
, '.');
2892 if (sptr
!= NULL
&& lptr
!= NULL
)
2895 * Strip the common domain name components...
2898 while (lptr
!= NULL
)
2900 if (!strcasecmp(lptr
, sptr
))
2906 lptr
= strchr(lptr
+ 1, '.');
2911 DEBUG_printf(("localized hostname is \"%s\"...\n", localname
));
2914 * Find a matching printer or class...
2917 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
2919 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
2920 if (!strcasecmp(p
->hostname
, localname
) &&
2921 !strcasecmp(p
->name
, rptr
))
2927 *dtype
= p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
|
2928 CUPS_PRINTER_REMOTE
| CUPS_PRINTER_DISCOVERED
);
2938 * 'cupsdWritePrintcap()' - Write a pseudo-printcap file for older applications
2943 cupsdWritePrintcap(void)
2945 cups_file_t
*fp
; /* printcap file */
2946 cupsd_printer_t
*p
; /* Current printer */
2951 * Update the IRIX printer state for the default printer; if
2952 * no printers remain, then the default printer file will be
2956 write_irix_state(DefaultPrinter
);
2960 * See if we have a printcap file; if not, don't bother writing it.
2963 if (!Printcap
|| !*Printcap
)
2967 * Open the printcap file...
2970 if ((fp
= cupsFileOpen(Printcap
, "w")) == NULL
)
2974 * Put a comment header at the top so that users will know where the
2975 * data has come from...
2978 cupsFilePuts(fp
, "# This file was automatically generated by cupsd(8) from the\n");
2979 cupsFilePrintf(fp
, "# %s/printers.conf file. All changes to this file\n",
2981 cupsFilePuts(fp
, "# will be lost.\n");
2986 * Write a new printcap with the current list of printers.
2989 switch (PrintcapFormat
)
2993 * Each printer is put in the file as:
3003 cupsFilePrintf(fp
, "%s|%s:rm=%s:rp=%s:\n", DefaultPrinter
->name
,
3004 DefaultPrinter
->info
, ServerName
, DefaultPrinter
->name
);
3006 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3008 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3009 if (p
!= DefaultPrinter
)
3010 cupsFilePrintf(fp
, "%s|%s:rm=%s:rp=%s:\n", p
->name
, p
->info
,
3011 ServerName
, p
->name
);
3014 case PRINTCAP_SOLARIS
:
3016 * Each printer is put in the file as:
3018 * _all:all=Printer1,Printer2,Printer3,...,PrinterN
3019 * _default:use=DefaultPrinter
3021 * :bsdaddr=ServerName,Printer1:\
3022 * :description=Description:
3024 * :bsdaddr=ServerName,Printer2:\
3025 * :description=Description:
3027 * :bsdaddr=ServerName,Printer3:\
3028 * :description=Description:
3031 * :bsdaddr=ServerName,PrinterN:\
3032 * :description=Description:
3035 cupsFilePuts(fp
, "_all:all=");
3036 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3038 p
= (cupsd_printer_t
*)cupsArrayCurrent(Printers
))
3039 cupsFilePrintf(fp
, "%s%c", p
->name
,
3040 cupsArrayNext(Printers
) ? ',' : '\n');
3043 cupsFilePrintf(fp
, "_default:use=%s\n", DefaultPrinter
->name
);
3045 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3047 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3048 cupsFilePrintf(fp
, "%s:\\\n"
3049 "\t:bsdaddr=%s,%s:\\\n"
3050 "\t:description=%s:\n",
3051 p
->name
, ServerName
, p
->name
, p
->info
? p
->info
: "");
3065 * 'cupsdSanitizeURI()' - Sanitize a device URI...
3068 char * /* O - New device URI */
3069 cupsdSanitizeURI(const char *uri
, /* I - Original device URI */
3070 char *buffer
, /* O - New device URI */
3071 int buflen
) /* I - Size of new device URI buffer */
3073 char *start
, /* Start of data after scheme */
3074 *slash
, /* First slash after scheme:// */
3075 *ptr
; /* Pointer into user@host:port part */
3079 * Range check input...
3082 if (!uri
|| !buffer
|| buflen
< 2)
3086 * Copy the device URI to the new buffer...
3089 strlcpy(buffer
, uri
, buflen
);
3092 * Find the end of the scheme:// part...
3095 if ((ptr
= strchr(buffer
, ':')) == NULL
)
3096 return (buffer
); /* No scheme: part... */
3098 for (start
= ptr
+ 1; *start
; start
++)
3103 * Find the next slash (/) in the URI...
3106 if ((slash
= strchr(start
, '/')) == NULL
)
3107 slash
= start
+ strlen(start
); /* No slash, point to the end */
3110 * Check for an @ sign before the slash...
3113 if ((ptr
= strchr(start
, '@')) != NULL
&& ptr
< slash
)
3116 * Found an @ sign and it is before the resource part, so we have
3117 * an authentication string. Copy the remaining URI over the
3118 * authentication string...
3121 _cups_strcpy(start
, ptr
+ 1);
3125 * Return the new device URI...
3133 * 'add_printer_defaults()' - Add name-default attributes to the printer attributes.
3137 add_printer_defaults(cupsd_printer_t
*p
)/* I - Printer */
3139 int i
; /* Looping var */
3140 int num_options
; /* Number of default options */
3141 cups_option_t
*options
, /* Default options */
3142 *option
; /* Current option */
3143 char name
[256]; /* name-default */
3147 * Maintain a common array of default attribute names...
3150 if (!CommonDefaults
)
3152 CommonDefaults
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
3154 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("copies-default"));
3155 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("document-format-default"));
3156 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("finishings-default"));
3157 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-hold-until-default"));
3158 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-priority-default"));
3159 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-sheets-default"));
3160 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("media-default"));
3161 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("number-up-default"));
3162 cupsArrayAdd(CommonDefaults
,
3163 _cupsStrAlloc("orientation-requested-default"));
3164 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("sides-default"));
3168 * Add all of the default options from the .conf files...
3171 for (num_options
= 0, i
= p
->num_options
, option
= p
->options
;
3175 if (strcmp(option
->name
, "ipp-options") &&
3176 strcmp(option
->name
, "job-sheets") &&
3177 strcmp(option
->name
, "lease-duration"))
3179 snprintf(name
, sizeof(name
), "%s-default", option
->name
);
3180 num_options
= cupsAddOption(name
, option
->value
, num_options
, &options
);
3182 if (!cupsArrayFind(CommonDefaults
, name
))
3183 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc(name
));
3188 * Convert options to IPP attributes...
3191 cupsEncodeOptions2(p
->attrs
, num_options
, options
, IPP_TAG_PRINTER
);
3192 cupsFreeOptions(num_options
, options
);
3195 * Add standard -default attributes as needed...
3198 if (!cupsGetOption("copies", p
->num_options
, p
->options
))
3199 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
, "copies-default",
3202 if (!cupsGetOption("document-format", p
->num_options
, p
->options
))
3203 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_MIMETYPE
,
3204 "document-format-default", NULL
, "application/octet-stream");
3206 if (!cupsGetOption("job-hold-until", p
->num_options
, p
->options
))
3207 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3208 "job-hold-until-default", NULL
, "no-hold");
3210 if (!cupsGetOption("job-priority", p
->num_options
, p
->options
))
3211 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3212 "job-priority-default", 50);
3214 if (!cupsGetOption("number-up", p
->num_options
, p
->options
))
3215 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3216 "number-up-default", 1);
3218 if (!cupsGetOption("orientation-requested", p
->num_options
, p
->options
))
3219 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
3220 "orientation-requested-default", IPP_PORTRAIT
);
3222 if (!cupsGetOption("notify-lease-duration", p
->num_options
, p
->options
))
3223 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3224 "notify-lease-duration-default", DefaultLeaseDuration
);
3226 if (!cupsGetOption("notify-events", p
->num_options
, p
->options
))
3227 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3228 "notify-events-default", NULL
, "job-completed");
3233 * 'add_printer_filter()' - Add a MIME filter for a printer.
3238 cupsd_printer_t
*p
, /* I - Printer to add to */
3239 mime_type_t
*filtertype
, /* I - Filter or prefilter MIME type */
3240 const char *filter
) /* I - Filter to add */
3242 char super
[MIME_MAX_SUPER
], /* Super-type for filter */
3243 type
[MIME_MAX_TYPE
], /* Type for filter */
3244 program
[1024]; /* Program/filter name */
3245 int cost
; /* Cost of filter */
3246 mime_type_t
*temptype
; /* MIME type looping var */
3247 char filename
[1024]; /* Full filter filename */
3251 * Parse the filter string; it should be in the following format:
3253 * super/type cost program
3256 if (sscanf(filter
, "%15[^/]/%31s%d%1023s", super
, type
, &cost
, program
) != 4)
3258 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: invalid filter string \"%s\"!",
3264 * See if the filter program exists; if not, stop the printer and flag
3268 if (strcmp(program
, "-"))
3270 if (program
[0] == '/')
3271 strlcpy(filename
, program
, sizeof(filename
));
3273 snprintf(filename
, sizeof(filename
), "%s/filter/%s", ServerBin
, program
);
3275 if (access(filename
, X_OK
))
3277 snprintf(p
->state_message
, sizeof(p
->state_message
),
3278 "Filter \"%s\" for printer \"%s\" not available: %s",
3279 program
, p
->name
, strerror(errno
));
3280 cupsdSetPrinterReasons(p
, "+cups-missing-filter-error");
3281 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, 0);
3283 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s", p
->state_message
);
3288 * Mark the CUPS_PRINTER_COMMANDS bit if we have a filter for
3289 * application/vnd.cups-command...
3292 if (!strcasecmp(super
, "application") &&
3293 !strcasecmp(type
, "vnd.cups-command"))
3294 p
->type
|= CUPS_PRINTER_COMMANDS
;
3297 * Add the filter to the MIME database, supporting wildcards as needed...
3300 for (temptype
= mimeFirstType(MimeDatabase
);
3302 temptype
= mimeNextType(MimeDatabase
))
3303 if (((super
[0] == '*' && strcasecmp(temptype
->super
, "printer")) ||
3304 !strcasecmp(temptype
->super
, super
)) &&
3305 (type
[0] == '*' || !strcasecmp(temptype
->type
, type
)))
3307 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3308 "add_printer_filter: %s: adding filter %s/%s %s/%s %d %s",
3309 p
->name
, temptype
->super
, temptype
->type
,
3310 filtertype
->super
, filtertype
->type
,
3312 mimeAddFilter(MimeDatabase
, temptype
, filtertype
, cost
, program
);
3318 * 'add_printer_formats()' - Add document-format-supported values for a printer.
3322 add_printer_formats(cupsd_printer_t
*p
) /* I - Printer */
3324 int i
; /* Looping var */
3325 mime_type_t
*type
; /* Current MIME type */
3326 cups_array_t
*filters
; /* Filters */
3327 ipp_attribute_t
*attr
; /* document-format-supported attribute */
3328 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
3329 /* MIME type name */
3333 * Raw (and remote) queues advertise all of the supported MIME
3337 cupsArrayDelete(p
->filetypes
);
3338 p
->filetypes
= NULL
;
3342 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
,
3343 (ipp_tag_t
)(IPP_TAG_MIMETYPE
| IPP_TAG_COPY
),
3344 "document-format-supported", NumMimeTypes
, NULL
, MimeTypes
);
3349 * Otherwise, loop through the supported MIME types and see if there
3350 * are filters for them...
3353 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_printer_formats: %d types, %d filters",
3354 mimeNumTypes(MimeDatabase
), mimeNumFilters(MimeDatabase
));
3356 p
->filetypes
= cupsArrayNew(NULL
, NULL
);
3358 for (type
= mimeFirstType(MimeDatabase
);
3360 type
= mimeNextType(MimeDatabase
))
3362 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
3364 if ((filters
= mimeFilter(MimeDatabase
, type
, p
->filetype
, NULL
)) != NULL
)
3366 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3367 "add_printer_formats: %s: %s needs %d filters",
3368 p
->name
, mimetype
, cupsArrayCount(filters
));
3370 cupsArrayDelete(filters
);
3371 cupsArrayAdd(p
->filetypes
, type
);
3374 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3375 "add_printer_formats: %s: %s not supported",
3379 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3380 "add_printer_formats: %s: %d supported types",
3381 p
->name
, cupsArrayCount(p
->filetypes
) + 1);
3384 * Add the file formats that can be filtered...
3387 if ((type
= mimeType(MimeDatabase
, "application", "octet-stream")) == NULL
||
3388 !cupsArrayFind(p
->filetypes
, type
))
3393 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_MIMETYPE
,
3394 "document-format-supported",
3395 cupsArrayCount(p
->filetypes
) + 1, NULL
, NULL
);
3398 attr
->values
[0].string
.text
= _cupsStrAlloc("application/octet-stream");
3400 for (type
= (mime_type_t
*)cupsArrayFirst(p
->filetypes
);
3402 i
++, type
= (mime_type_t
*)cupsArrayNext(p
->filetypes
))
3404 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
3406 attr
->values
[i
].string
.text
= _cupsStrAlloc(mimetype
);
3411 char pdl
[1024]; /* Buffer to build pdl list */
3412 mime_filter_t
*filter
; /* MIME filter looping var */
3417 if (mimeType(MimeDatabase
, "application", "pdf"))
3418 strlcat(pdl
, "application/pdf,", sizeof(pdl
));
3420 if (mimeType(MimeDatabase
, "application", "postscript"))
3421 strlcat(pdl
, "application/postscript,", sizeof(pdl
));
3423 if (mimeType(MimeDatabase
, "application", "vnd.cups-raster"))
3424 strlcat(pdl
, "application/vnd.cups-raster,", sizeof(pdl
));
3427 * Determine if this is a Tioga PrintJobMgr based queue...
3430 for (filter
= (mime_filter_t
*)cupsArrayFirst(MimeDatabase
->filters
);
3432 filter
= (mime_filter_t
*)cupsArrayNext(MimeDatabase
->filters
))
3434 if (filter
->dst
== p
->filetype
&& filter
->filter
&&
3435 strstr(filter
->filter
, "PrintJobMgr"))
3440 * We only support raw printing if this is not a Tioga PrintJobMgr based
3441 * queue and if application/octet-stream is a known conversion...
3444 if (!filter
&& mimeType(MimeDatabase
, "application", "octet-stream"))
3445 strlcat(pdl
, "application/octet-stream,", sizeof(pdl
));
3447 if (mimeType(MimeDatabase
, "image", "png"))
3448 strlcat(pdl
, "image/png,", sizeof(pdl
));
3451 pdl
[strlen(pdl
) - 1] = '\0'; /* Remove trailing comma */
3453 cupsdSetString(&p
->pdl
, pdl
);
3455 #endif /* HAVE_DNSSD */
3460 * 'compare_printers()' - Compare two printers.
3463 static int /* O - Result of comparison */
3464 compare_printers(void *first
, /* I - First printer */
3465 void *second
, /* I - Second printer */
3466 void *data
) /* I - App data (not used) */
3468 return (strcasecmp(((cupsd_printer_t
*)first
)->name
,
3469 ((cupsd_printer_t
*)second
)->name
));
3474 * 'delete_printer_filters()' - Delete all MIME filters for a printer.
3478 delete_printer_filters(
3479 cupsd_printer_t
*p
) /* I - Printer to remove from */
3481 mime_filter_t
*filter
; /* MIME filter looping var */
3485 * Range check input...
3492 * Remove all filters from the MIME database that have a destination
3493 * type == printer...
3496 for (filter
= mimeFirstFilter(MimeDatabase
);
3498 filter
= mimeNextFilter(MimeDatabase
))
3499 if (filter
->dst
== p
->filetype
)
3502 * Delete the current filter...
3505 mimeDeleteFilter(MimeDatabase
, filter
);
3512 * 'write_irix_config()' - Update the config files used by the IRIX
3517 write_irix_config(cupsd_printer_t
*p
) /* I - Printer to update */
3519 char filename
[1024]; /* Interface script filename */
3520 cups_file_t
*fp
; /* Interface script file */
3521 ipp_attribute_t
*attr
; /* Attribute data */
3525 * Add dummy interface and GUI scripts to fool SGI's "challenged" printing
3526 * tools. First the interface script that tells the tools what kind of
3527 * printer we have...
3530 snprintf(filename
, sizeof(filename
), "/var/spool/lp/interface/%s", p
->name
);
3532 if (p
->type
& CUPS_PRINTER_CLASS
)
3534 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
3536 cupsFilePuts(fp
, "#!/bin/sh\n");
3538 if ((attr
= ippFindAttribute(p
->attrs
, "printer-make-and-model",
3539 IPP_TAG_TEXT
)) != NULL
)
3540 cupsFilePrintf(fp
, "NAME=\"%s\"\n", attr
->values
[0].string
.text
);
3541 else if (p
->type
& CUPS_PRINTER_CLASS
)
3542 cupsFilePuts(fp
, "NAME=\"Printer Class\"\n");
3544 cupsFilePuts(fp
, "NAME=\"Remote Destination\"\n");
3546 if (p
->type
& CUPS_PRINTER_COLOR
)
3547 cupsFilePuts(fp
, "TYPE=ColorPostScript\n");
3549 cupsFilePuts(fp
, "TYPE=MonoPostScript\n");
3551 cupsFilePrintf(fp
, "HOSTNAME=%s\n", ServerName
);
3552 cupsFilePrintf(fp
, "HOSTPRINTER=%s\n", p
->name
);
3556 chmod(filename
, 0755);
3557 chown(filename
, User
, Group
);
3561 * Then the member file that tells which device file the queue is connected
3562 * to... Networked printers use "/dev/null" in this file, so that's what
3563 * we use (the actual device URI can confuse some apps...)
3566 snprintf(filename
, sizeof(filename
), "/var/spool/lp/member/%s", p
->name
);
3568 if (p
->type
& CUPS_PRINTER_CLASS
)
3570 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
3572 cupsFilePuts(fp
, "/dev/null\n");
3576 chmod(filename
, 0644);
3577 chown(filename
, User
, Group
);
3581 * The gui_interface file is a script or program that launches a GUI
3582 * option panel for the printer, using options specified on the
3583 * command-line in the third argument. The option panel must send
3584 * any printing options to stdout on a single line when the user
3585 * accepts them, or nothing if the user cancels the dialog.
3587 * The default options panel program is /usr/bin/glpoptions, from
3588 * the ESP Print Pro software. You can select another using the
3589 * PrintcapGUI option.
3592 snprintf(filename
, sizeof(filename
), "/var/spool/lp/gui_interface/ELF/%s.gui", p
->name
);
3594 if (p
->type
& CUPS_PRINTER_CLASS
)
3596 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
3598 cupsFilePuts(fp
, "#!/bin/sh\n");
3599 cupsFilePrintf(fp
, "%s -d %s -o \"$3\"\n", PrintcapGUI
, p
->name
);
3603 chmod(filename
, 0755);
3604 chown(filename
, User
, Group
);
3608 * The POD config file is needed by the printstatus command to show
3609 * the printer location and device.
3612 snprintf(filename
, sizeof(filename
), "/var/spool/lp/pod/%s.config", p
->name
);
3614 if (p
->type
& CUPS_PRINTER_CLASS
)
3616 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
3618 cupsFilePrintf(fp
, "Printer Class | %s\n",
3619 (p
->type
& CUPS_PRINTER_COLOR
) ? "ColorPostScript" : "MonoPostScript");
3620 cupsFilePrintf(fp
, "Printer Model | %s\n", p
->make_model
? p
->make_model
: "");
3621 cupsFilePrintf(fp
, "Location Code | %s\n", p
->location
? p
->location
: "");
3622 cupsFilePrintf(fp
, "Physical Location | %s\n", p
->info
? p
->info
: "");
3623 cupsFilePrintf(fp
, "Port Path | %s\n", p
->device_uri
? p
->device_uri
: "");
3624 cupsFilePrintf(fp
, "Config Path | /var/spool/lp/pod/%s.config\n", p
->name
);
3625 cupsFilePrintf(fp
, "Active Status Path | /var/spool/lp/pod/%s.status\n", p
->name
);
3626 cupsFilePuts(fp
, "Status Update Wait | 10 seconds\n");
3630 chmod(filename
, 0664);
3631 chown(filename
, User
, Group
);
3637 * 'write_irix_state()' - Update the status files used by IRIX printing
3642 write_irix_state(cupsd_printer_t
*p
) /* I - Printer to update */
3644 char filename
[1024]; /* Interface script filename */
3645 cups_file_t
*fp
; /* Interface script file */
3646 int tag
; /* Status tag value */
3652 * The POD status file is needed for the printstatus window to
3653 * provide the current status of the printer.
3656 snprintf(filename
, sizeof(filename
), "/var/spool/lp/pod/%s.status", p
->name
);
3658 if (p
->type
& CUPS_PRINTER_CLASS
)
3660 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
3662 cupsFilePrintf(fp
, "Operational Status | %s\n",
3663 (p
->state
== IPP_PRINTER_IDLE
) ? "Idle" :
3664 (p
->state
== IPP_PRINTER_PROCESSING
) ? "Busy" :
3666 cupsFilePrintf(fp
, "Information | 01 00 00 | %s\n", CUPS_SVERSION
);
3667 cupsFilePrintf(fp
, "Information | 02 00 00 | Device URI: %s\n",
3668 p
->device_uri
? p
->device_uri
: "");
3669 cupsFilePrintf(fp
, "Information | 03 00 00 | %s jobs\n",
3670 p
->accepting
? "Accepting" : "Not accepting");
3671 cupsFilePrintf(fp
, "Information | 04 00 00 | %s\n", p
->state_message
);
3675 chmod(filename
, 0664);
3676 chown(filename
, User
, Group
);
3680 * The activeicons file is needed to provide desktop icons for printers:
3682 * [ quoted from /usr/lib/print/tagit ]
3684 * --- Type of printer tags (base values)
3686 * Dumb=66048 # 0x10200
3687 * DumbColor=66080 # 0x10220
3688 * Raster=66112 # 0x10240
3689 * ColorRaster=66144 # 0x10260
3690 * Plotter=66176 # 0x10280
3691 * PostScript=66208 # 0x102A0
3692 * ColorPostScript=66240 # 0x102C0
3693 * MonoPostScript=66272 # 0x102E0
3695 * --- Printer state modifiers for local printers
3700 * Unknown=3 # 0x3 (Faulted due to unknown reason)
3702 * --- Printer state modifiers for network printers
3706 * NetFaulted=10 # 0xA
3707 * NetUnknown=11 # 0xB (Faulted due to unknown reason)
3710 snprintf(filename
, sizeof(filename
), "/var/spool/lp/activeicons/%s", p
->name
);
3712 if (p
->type
& CUPS_PRINTER_CLASS
)
3714 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
3716 if (p
->type
& CUPS_PRINTER_COLOR
)
3721 if (p
->type
& CUPS_PRINTER_REMOTE
)
3724 if (p
->state
== IPP_PRINTER_PROCESSING
)
3727 else if (p
->state
== IPP_PRINTER_STOPPED
)
3730 cupsFilePuts(fp
, "#!/bin/sh\n");
3731 cupsFilePrintf(fp
, "#Tag %d\n", tag
);
3735 chmod(filename
, 0755);
3736 chown(filename
, User
, Group
);
3741 * The default file is needed by the printers window to show
3742 * the default printer.
3745 snprintf(filename
, sizeof(filename
), "/var/spool/lp/default");
3747 if (DefaultPrinter
!= NULL
)
3749 if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
3751 cupsFilePrintf(fp
, "%s\n", DefaultPrinter
->name
);
3755 chmod(filename
, 0644);
3756 chown(filename
, User
, Group
);
3766 * End of "$Id: printers.c 6678 2007-07-16 18:03:35Z mike $".