2 * "$Id: printers.c 6970 2007-09-17 23:58:28Z mike $"
4 * Printer routines for the Common UNIX Printing System (CUPS).
6 * Copyright 2007-2008 by Apple Inc.
7 * Copyright 1997-2007 by Easy Software Products, all rights reserved.
9 * These coded instructions, statements, and computer programs are the
10 * property of Apple Inc. and are protected by Federal copyright
11 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
12 * which should have been included with this file. If this file is
13 * file is missing or damaged, see the license at "http://www.cups.org/".
17 * cupsdAddPrinter() - Add a printer to the system.
18 * cupsdAddPrinterHistory() - Add the current printer state to the history.
19 * cupsdAddPrinterUser() - Add a user to the ACL.
20 * cupsdCreateCommonData() - Create the common printer data.
21 * cupsdDeleteAllPrinters() - Delete all printers from the system.
22 * cupsdDeletePrinter() - Delete a printer from the system.
23 * cupsdFindPrinter() - Find a printer in the list.
24 * cupsdFreePrinterUsers() - Free allow/deny users.
25 * cupsdLoadAllPrinters() - Load printers from the printers.conf file.
26 * cupsdRenamePrinter() - Rename a printer.
27 * cupsdSaveAllPrinters() - Save all printer definitions to the
29 * cupsdSetAuthInfoRequired() - Set the required authentication info.
30 * cupsdSetPrinterAttr() - Set a printer attribute.
31 * cupsdSetPrinterAttrs() - Set printer attributes based upon the PPD
33 * cupsdSetPrinterReasons() - Set/update the reasons strings.
34 * cupsdSetPrinterState() - Update the current state of a printer.
35 * cupsdStopPrinter() - Stop a printer from printing any jobs...
36 * cupsdUpdatePrinters() - Update printers after a partial reload.
37 * cupsdValidateDest() - Validate a printer/class destination.
38 * cupsdWritePrintcap() - Write a pseudo-printcap file for older
39 * applications that need it...
40 * cupsdSanitizeURI() - Sanitize a device URI...
41 * add_printer_defaults() - Add name-default attributes to the printer
43 * add_printer_filter() - Add a MIME filter for a printer.
44 * add_printer_formats() - Add document-format-supported values for
46 * compare_printers() - Compare two printers.
47 * delete_printer_filters() - Delete all MIME filters for a printer.
48 * write_irix_config() - Update the config files used by the IRIX
50 * write_irix_state() - Update the status files used by IRIX
51 * printing desktop tools.
55 * Include necessary headers...
66 static void add_printer_defaults(cupsd_printer_t
*p
);
67 static void add_printer_filter(cupsd_printer_t
*p
, mime_type_t
*type
,
69 static void add_printer_formats(cupsd_printer_t
*p
);
70 static int compare_printers(void *first
, void *second
, void *data
);
71 static void delete_printer_filters(cupsd_printer_t
*p
);
73 static void write_irix_config(cupsd_printer_t
*p
);
74 static void write_irix_state(cupsd_printer_t
*p
);
79 * 'cupsdAddPrinter()' - Add a printer to the system.
82 cupsd_printer_t
* /* O - New printer */
83 cupsdAddPrinter(const char *name
) /* I - Name of printer */
85 cupsd_printer_t
*p
; /* New printer */
89 * Range check input...
92 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdAddPrinter(\"%s\")", name
);
95 * Create a new printer entity...
98 if ((p
= calloc(1, sizeof(cupsd_printer_t
))) == NULL
)
100 cupsdLogMessage(CUPSD_LOG_CRIT
, "Unable to allocate memory for printer - %s",
105 cupsdSetString(&p
->name
, name
);
106 cupsdSetString(&p
->info
, name
);
107 cupsdSetString(&p
->hostname
, ServerName
);
109 cupsdSetStringf(&p
->uri
, "ipp://%s:%d/printers/%s", ServerName
, LocalPort
, name
);
110 cupsdSetStringf(&p
->device_uri
, "file:/dev/null");
112 p
->state
= IPP_PRINTER_STOPPED
;
113 p
->state_time
= time(NULL
);
115 p
->shared
= DefaultShared
;
116 p
->filetype
= mimeAddType(MimeDatabase
, "printer", name
);
118 cupsdSetString(&p
->job_sheets
[0], "none");
119 cupsdSetString(&p
->job_sheets
[1], "none");
121 cupsdSetString(&p
->error_policy
, ErrorPolicy
);
122 cupsdSetString(&p
->op_policy
, DefaultPolicy
);
124 p
->op_policy_ptr
= DefaultPolicyPtr
;
126 if (MaxPrinterHistory
)
127 p
->history
= calloc(MaxPrinterHistory
, sizeof(ipp_t
*));
130 * Insert the printer in the printer list alphabetically...
134 Printers
= cupsArrayNew(compare_printers
, NULL
);
136 cupsArrayAdd(Printers
, p
);
138 if (!ImplicitPrinters
)
139 ImplicitPrinters
= cupsArrayNew(compare_printers
, NULL
);
142 * Return the new printer...
150 * 'cupsdAddPrinterHistory()' - Add the current printer state to the history.
154 cupsdAddPrinterHistory(
155 cupsd_printer_t
*p
) /* I - Printer */
157 ipp_t
*history
; /* History collection */
161 * Stop early if we aren't keeping history data...
164 if (MaxPrinterHistory
<= 0)
168 * Retire old history data as needed...
171 p
->sequence_number
++;
173 if (p
->num_history
>= MaxPrinterHistory
)
176 ippDelete(p
->history
[0]);
177 memmove(p
->history
, p
->history
+ 1, p
->num_history
* sizeof(ipp_t
*));
181 * Create a collection containing the current printer-state, printer-up-time,
182 * printer-state-message, and printer-state-reasons attributes.
186 ippAddInteger(history
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-state",
188 ippAddBoolean(history
, IPP_TAG_PRINTER
, "printer-is-accepting-jobs",
190 ippAddBoolean(history
, IPP_TAG_PRINTER
, "printer-is-shared", p
->shared
);
191 ippAddString(history
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-state-message",
192 NULL
, p
->state_message
);
195 ippAddString(history
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
196 "com.apple.print.recoverable-message", NULL
, p
->recoverable
);
197 #endif /* __APPLE__ */
198 if (p
->num_reasons
== 0)
199 ippAddString(history
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
200 "printer-state-reasons", NULL
,
201 p
->state
== IPP_PRINTER_STOPPED
? "paused" : "none");
203 ippAddStrings(history
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
204 "printer-state-reasons", p
->num_reasons
, NULL
,
205 (const char * const *)p
->reasons
);
206 ippAddInteger(history
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
207 "printer-state-change-time", p
->state_time
);
208 ippAddInteger(history
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
209 "printer-state-sequence-number", p
->sequence_number
);
211 p
->history
[p
->num_history
] = history
;
217 * 'cupsdAddPrinterUser()' - Add a user to the ACL.
222 cupsd_printer_t
*p
, /* I - Printer */
223 const char *username
) /* I - User */
225 const char **temp
; /* Temporary array pointer */
231 if (p
->num_users
== 0)
232 temp
= malloc(sizeof(char **));
234 temp
= realloc(p
->users
, sizeof(char **) * (p
->num_users
+ 1));
240 temp
+= p
->num_users
;
242 if ((*temp
= strdup(username
)) != NULL
)
248 * 'cupsdCreateCommonData()' - Create the common printer data.
252 cupsdCreateCommonData(void)
254 int i
; /* Looping var */
255 ipp_attribute_t
*attr
; /* Attribute data */
256 cups_dir_t
*dir
; /* Notifier directory */
257 cups_dentry_t
*dent
; /* Notifier directory entry */
258 cups_array_t
*notifiers
; /* Notifier array */
259 char filename
[1024], /* Filename */
260 *notifier
; /* Current notifier */
261 cupsd_policy_t
*p
; /* Current policy */
262 static const int nups
[] = /* number-up-supported values */
263 { 1, 2, 4, 6, 9, 16 };
264 static const int orients
[4] =/* orientation-requested-supported values */
268 IPP_REVERSE_LANDSCAPE
,
271 static const char * const holds
[] = /* job-hold-until-supported values */
282 static const char * const versions
[] =/* ipp-versions-supported values */
287 static const int ops
[] = /* operations-supported values */
294 IPP_GET_JOB_ATTRIBUTES
,
296 IPP_GET_PRINTER_ATTRIBUTES
,
302 IPP_SET_JOB_ATTRIBUTES
,
303 IPP_CREATE_PRINTER_SUBSCRIPTION
,
304 IPP_CREATE_JOB_SUBSCRIPTION
,
305 IPP_GET_SUBSCRIPTION_ATTRIBUTES
,
306 IPP_GET_SUBSCRIPTIONS
,
307 IPP_RENEW_SUBSCRIPTION
,
308 IPP_CANCEL_SUBSCRIPTION
,
309 IPP_GET_NOTIFICATIONS
,
325 CUPS_AUTHENTICATE_JOB
,
330 static const char * const charsets
[] =/* charset-supported values */
335 static const char * const compressions
[] =
336 { /* document-compression-supported values */
340 #endif /* HAVE_LIBZ */
342 static const char * const multiple_document_handling
[] =
343 { /* multiple-document-handling-supported values */
344 "separate-documents-uncollated-copies",
345 "separate-documents-collated-copies"
347 static const char * const errors
[] = /* printer-error-policy-supported values */
353 static const char * const notify_attrs
[] =
354 { /* notify-attributes-supported values */
355 "printer-state-change-time",
356 "notify-lease-expiration-time",
357 "notify-subscriber-user-name"
359 static const char * const notify_events
[] =
360 { /* notify-events-supported values */
362 "job-config-changed",
369 "printer-config-changed",
371 "printer-finishings-changed",
372 "printer-media-changed",
376 "printer-state-changed",
386 ippDelete(CommonData
);
388 CommonData
= ippNew();
391 * This list of attributes is sorted to improve performance when the
392 * client provides a requested-attributes attribute...
395 /* charset-configured */
396 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_CHARSET
,
397 "charset-configured", NULL
, DefaultCharset
);
399 /* charset-supported */
400 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_CHARSET
,
401 "charset-supported", sizeof(charsets
) / sizeof(charsets
[0]),
404 /* compression-supported */
405 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
406 "compression-supported",
407 sizeof(compressions
) / sizeof(compressions
[0]),
410 /* copies-supported */
411 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "copies-supported", 1, MaxCopies
);
414 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "cups-version",
415 NULL
, CUPS_SVERSION
+ 6);
417 /* generated-natural-language-supported */
418 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_LANGUAGE
,
419 "generated-natural-language-supported", NULL
, DefaultLanguage
);
421 /* ipp-versions-supported */
422 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
423 "ipp-versions-supported", sizeof(versions
) / sizeof(versions
[0]),
426 /* job-hold-until-supported */
427 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
428 "job-hold-until-supported", sizeof(holds
) / sizeof(holds
[0]),
431 /* job-priority-supported */
432 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
433 "job-priority-supported", 100);
435 /* job-sheets-supported */
436 if (cupsArrayCount(Banners
) > 0)
439 * Setup the job-sheets-supported attribute...
442 if (Classification
&& !ClassifyOverride
)
443 attr
= ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
444 "job-sheets-supported", NULL
, Classification
);
446 attr
= ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
447 "job-sheets-supported", cupsArrayCount(Banners
) + 1,
451 cupsdLogMessage(CUPSD_LOG_EMERG
,
452 "Unable to allocate memory for "
453 "job-sheets-supported attribute: %s!", strerror(errno
));
454 else if (!Classification
|| ClassifyOverride
)
456 cupsd_banner_t
*banner
; /* Current banner */
459 attr
->values
[0].string
.text
= _cupsStrAlloc("none");
461 for (i
= 1, banner
= (cupsd_banner_t
*)cupsArrayFirst(Banners
);
463 i
++, banner
= (cupsd_banner_t
*)cupsArrayNext(Banners
))
464 attr
->values
[i
].string
.text
= _cupsStrAlloc(banner
->name
);
468 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
469 "job-sheets-supported", NULL
, "none");
471 /* multiple-document-handling-supported */
472 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
473 "multiple-document-handling-supported",
474 sizeof(multiple_document_handling
) /
475 sizeof(multiple_document_handling
[0]), NULL
,
476 multiple_document_handling
);
478 /* multiple-document-jobs-supported */
479 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
,
480 "multiple-document-jobs-supported", 1);
482 /* multiple-operation-time-out */
483 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
484 "multiple-operation-time-out", 60);
486 /* natural-language-configured */
487 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_LANGUAGE
,
488 "natural-language-configured", NULL
, DefaultLanguage
);
490 /* notify-attributes-supported */
491 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
492 "notify-attributes-supported",
493 (int)(sizeof(notify_attrs
) / sizeof(notify_attrs
[0])),
496 /* notify-lease-duration-supported */
497 ippAddRange(CommonData
, IPP_TAG_PRINTER
,
498 "notify-lease-duration-supported", 0,
499 MaxLeaseDuration
? MaxLeaseDuration
: 2147483647);
501 /* notify-max-events-supported */
502 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
503 "notify-max-events-supported", MaxEvents
);
505 /* notify-events-supported */
506 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
507 "notify-events-supported",
508 (int)(sizeof(notify_events
) / sizeof(notify_events
[0])),
509 NULL
, notify_events
);
511 /* notify-pull-method-supported */
512 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
513 "notify-pull-method-supported", NULL
, "ippget");
515 /* notify-schemes-supported */
516 snprintf(filename
, sizeof(filename
), "%s/notifier", ServerBin
);
517 if ((dir
= cupsDirOpen(filename
)) != NULL
)
519 notifiers
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
521 while ((dent
= cupsDirRead(dir
)) != NULL
)
522 if (S_ISREG(dent
->fileinfo
.st_mode
) &&
523 (dent
->fileinfo
.st_mode
& S_IXOTH
) != 0)
524 cupsArrayAdd(notifiers
, _cupsStrAlloc(dent
->filename
));
526 if (cupsArrayCount(notifiers
) > 0)
528 attr
= ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
529 "notify-schemes-supported",
530 cupsArrayCount(notifiers
), NULL
, NULL
);
532 for (i
= 0, notifier
= (char *)cupsArrayFirst(notifiers
);
534 i
++, notifier
= (char *)cupsArrayNext(notifiers
))
535 attr
->values
[i
].string
.text
= notifier
;
538 cupsArrayDelete(notifiers
);
542 /* number-up-supported */
543 ippAddIntegers(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
544 "number-up-supported", sizeof(nups
) / sizeof(nups
[0]), nups
);
546 /* operations-supported */
547 ippAddIntegers(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
548 "operations-supported",
549 sizeof(ops
) / sizeof(ops
[0]) + JobFiles
- 1, ops
);
551 /* orientation-requested-supported */
552 ippAddIntegers(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
553 "orientation-requested-supported", 4, orients
);
555 /* page-ranges-supported */
556 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
, "page-ranges-supported", 1);
558 /* pdf-override-supported */
559 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
560 "pdl-override-supported", NULL
, "not-attempted");
562 /* printer-error-policy-supported */
563 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
564 "printer-error-policy-supported",
565 sizeof(errors
) / sizeof(errors
[0]), NULL
, errors
);
567 /* printer-op-policy-supported */
568 attr
= ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
569 "printer-op-policy-supported", cupsArrayCount(Policies
),
571 for (i
= 0, p
= (cupsd_policy_t
*)cupsArrayFirst(Policies
);
573 i
++, p
= (cupsd_policy_t
*)cupsArrayNext(Policies
))
574 attr
->values
[i
].string
.text
= _cupsStrAlloc(p
->name
);
576 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
, "server-is-sharing-printers",
577 BrowseLocalProtocols
!= 0 && Browsing
);
582 * 'cupsdDeleteAllPrinters()' - Delete all printers from the system.
586 cupsdDeleteAllPrinters(void)
588 cupsd_printer_t
*p
; /* Pointer to current printer/class */
591 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
593 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
594 if (!(p
->type
& CUPS_PRINTER_CLASS
))
595 cupsdDeletePrinter(p
, 0);
600 * 'cupsdDeletePrinter()' - Delete a printer from the system.
605 cupsd_printer_t
*p
, /* I - Printer to delete */
606 int update
) /* I - Update printers.conf? */
608 int i
; /* Looping var */
610 char filename
[1024]; /* Interface script filename */
614 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdDeletePrinter(p=%p(%s), update=%d)",
618 * Save the current position in the Printers array...
621 cupsArraySave(Printers
);
624 * Stop printing on this printer...
627 cupsdStopPrinter(p
, update
);
630 * If this printer is the next for browsing, point to the next one...
635 cupsArrayFind(Printers
, p
);
636 BrowseNext
= (cupsd_printer_t
*)cupsArrayNext(Printers
);
640 * Remove the printer from the list...
643 cupsArrayRemove(Printers
, p
);
645 if (p
->type
& CUPS_PRINTER_IMPLICIT
)
646 cupsArrayRemove(ImplicitPrinters
, p
);
649 * Remove the dummy interface/icon/option files under IRIX...
653 snprintf(filename
, sizeof(filename
), "/var/spool/lp/interface/%s", p
->name
);
656 snprintf(filename
, sizeof(filename
), "/var/spool/lp/gui_interface/ELF/%s.gui",
660 snprintf(filename
, sizeof(filename
), "/var/spool/lp/activeicons/%s", p
->name
);
663 snprintf(filename
, sizeof(filename
), "/var/spool/lp/pod/%s.config", p
->name
);
666 snprintf(filename
, sizeof(filename
), "/var/spool/lp/pod/%s.status", p
->name
);
669 snprintf(filename
, sizeof(filename
), "/var/spool/lp/member/%s", p
->name
);
674 * If p is the default printer, assign a different one...
677 if (p
== DefaultPrinter
)
679 DefaultPrinter
= NULL
;
681 if (UseNetworkDefault
)
684 * Find the first network default printer and use it...
687 cupsd_printer_t
*dp
; /* New default printer */
690 for (dp
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
692 dp
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
693 if (dp
!= p
&& (dp
->type
& CUPS_PRINTER_DEFAULT
))
702 * Remove this printer from any classes...
705 if (!(p
->type
& CUPS_PRINTER_IMPLICIT
))
707 cupsdDeletePrinterFromClasses(p
);
710 * Deregister from any browse protocols...
713 cupsdDeregisterPrinter(p
, 1);
717 * Free all memory used by the printer...
720 if (p
->printers
!= NULL
)
723 if (MaxPrinterHistory
)
725 for (i
= 0; i
< p
->num_history
; i
++)
726 ippDelete(p
->history
[i
]);
731 for (i
= 0; i
< p
->num_reasons
; i
++)
736 delete_printer_filters(p
);
738 mimeDeleteType(MimeDatabase
, p
->filetype
);
739 mimeDeleteType(MimeDatabase
, p
->prefiltertype
);
741 cupsdFreePrinterUsers(p
);
744 cupsdClearString(&p
->uri
);
745 cupsdClearString(&p
->hostname
);
746 cupsdClearString(&p
->name
);
747 cupsdClearString(&p
->location
);
748 cupsdClearString(&p
->make_model
);
749 cupsdClearString(&p
->info
);
750 cupsdClearString(&p
->job_sheets
[0]);
751 cupsdClearString(&p
->job_sheets
[1]);
752 cupsdClearString(&p
->device_uri
);
753 cupsdClearString(&p
->port_monitor
);
754 cupsdClearString(&p
->op_policy
);
755 cupsdClearString(&p
->error_policy
);
757 cupsdClearString(&p
->alert
);
758 cupsdClearString(&p
->alert_description
);
761 cupsdClearString(&p
->product
);
762 cupsdClearString(&p
->pdl
);
763 #endif /* HAVE_DNSSD */
765 cupsArrayDelete(p
->filetypes
);
768 free(p
->browse_attrs
);
771 cupsdClearString(&p
->recoverable
);
772 #endif /* __APPLE__ */
774 cupsFreeOptions(p
->num_options
, p
->options
);
779 * Restore the previous position in the Printers array...
782 cupsArrayRestore(Printers
);
787 * 'cupsdFindDest()' - Find a destination in the list.
790 cupsd_printer_t
* /* O - Destination in list */
791 cupsdFindDest(const char *name
) /* I - Name of printer or class to find */
793 cupsd_printer_t key
; /* Search key */
796 key
.name
= (char *)name
;
797 return ((cupsd_printer_t
*)cupsArrayFind(Printers
, &key
));
802 * 'cupsdFindPrinter()' - Find a printer in the list.
805 cupsd_printer_t
* /* O - Printer in list */
806 cupsdFindPrinter(const char *name
) /* I - Name of printer to find */
808 cupsd_printer_t
*p
; /* Printer in list */
811 if ((p
= cupsdFindDest(name
)) != NULL
&& (p
->type
& CUPS_PRINTER_CLASS
))
819 * 'cupsdFreePrinterUsers()' - Free allow/deny users.
823 cupsdFreePrinterUsers(
824 cupsd_printer_t
*p
) /* I - Printer */
826 int i
; /* Looping var */
829 if (!p
|| !p
->num_users
)
832 for (i
= 0; i
< p
->num_users
; i
++)
833 free((void *)p
->users
[i
]);
843 * 'cupsdLoadAllPrinters()' - Load printers from the printers.conf file.
847 cupsdLoadAllPrinters(void)
849 cups_file_t
*fp
; /* printers.conf file */
850 int linenum
; /* Current line number */
851 char line
[1024], /* Line from file */
852 *value
, /* Pointer to value */
853 *valueptr
; /* Pointer into value */
854 cupsd_printer_t
*p
; /* Current printer */
858 * Open the printers.conf file...
861 snprintf(line
, sizeof(line
), "%s/printers.conf", ServerRoot
);
862 if ((fp
= cupsFileOpen(line
, "r")) == NULL
)
865 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to open %s - %s", line
,
871 * Read printer configurations until we hit EOF...
877 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
880 * Decode the directive...
883 if (!strcasecmp(line
, "<Printer") ||
884 !strcasecmp(line
, "<DefaultPrinter"))
887 * <Printer name> or <DefaultPrinter name>
890 if (p
== NULL
&& value
)
893 * Add the printer and a base file type...
896 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Loading printer %s...", value
);
898 p
= cupsdAddPrinter(value
);
900 p
->state
= IPP_PRINTER_IDLE
;
903 * Set the default printer as needed...
906 if (!strcasecmp(line
, "<DefaultPrinter"))
911 cupsdLogMessage(CUPSD_LOG_ERROR
,
912 "Syntax error on line %d of printers.conf.", linenum
);
916 else if (!strcasecmp(line
, "</Printer>"))
921 * Close out the current printer...
924 cupsdSetPrinterAttrs(p
);
925 cupsdAddPrinterHistory(p
);
927 if (p
->device_uri
&& strncmp(p
->device_uri
, "file:", 5) &&
928 p
->state
!= IPP_PRINTER_STOPPED
)
931 * See if the backend exists...
934 snprintf(line
, sizeof(line
), "%s/backend/%s", ServerBin
,
937 if ((valueptr
= strchr(line
+ strlen(ServerBin
), ':')) != NULL
)
938 *valueptr
= '\0'; /* Chop everything but URI scheme */
943 * Backend does not exist, stop printer...
946 p
->state
= IPP_PRINTER_STOPPED
;
947 snprintf(p
->state_message
, sizeof(p
->state_message
),
948 "Backend %s does not exist!", line
);
956 cupsdLogMessage(CUPSD_LOG_ERROR
,
957 "Syntax error on line %d of printers.conf.", linenum
);
963 cupsdLogMessage(CUPSD_LOG_ERROR
,
964 "Syntax error on line %d of printers.conf.", linenum
);
967 else if (!strcasecmp(line
, "AuthInfoRequired"))
969 if (!cupsdSetAuthInfoRequired(p
, value
, NULL
))
970 cupsdLogMessage(CUPSD_LOG_ERROR
,
971 "Bad AuthInfoRequired on line %d of printers.conf.",
974 else if (!strcasecmp(line
, "Info"))
977 cupsdSetString(&p
->info
, value
);
979 else if (!strcasecmp(line
, "Location"))
982 cupsdSetString(&p
->location
, value
);
984 else if (!strcasecmp(line
, "DeviceURI"))
987 cupsdSetString(&p
->device_uri
, value
);
990 cupsdLogMessage(CUPSD_LOG_ERROR
,
991 "Syntax error on line %d of printers.conf.", linenum
);
995 else if (!strcasecmp(line
, "Option") && value
)
1001 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1004 cupsdLogMessage(CUPSD_LOG_ERROR
,
1005 "Syntax error on line %d of printers.conf.", linenum
);
1008 for (; *valueptr
&& isspace(*valueptr
& 255); *valueptr
++ = '\0');
1010 p
->num_options
= cupsAddOption(value
, valueptr
, p
->num_options
,
1014 else if (!strcasecmp(line
, "PortMonitor"))
1016 if (value
&& strcmp(value
, "none"))
1017 cupsdSetString(&p
->port_monitor
, value
);
1019 cupsdClearString(&p
->port_monitor
);
1022 cupsdLogMessage(CUPSD_LOG_ERROR
,
1023 "Syntax error on line %d of printers.conf.", linenum
);
1027 else if (!strcasecmp(line
, "State"))
1030 * Set the initial queue state...
1033 if (value
&& !strcasecmp(value
, "idle"))
1034 p
->state
= IPP_PRINTER_IDLE
;
1035 else if (value
&& !strcasecmp(value
, "stopped"))
1036 p
->state
= IPP_PRINTER_STOPPED
;
1039 cupsdLogMessage(CUPSD_LOG_ERROR
,
1040 "Syntax error on line %d of printers.conf.", linenum
);
1044 else if (!strcasecmp(line
, "StateMessage"))
1047 * Set the initial queue state message...
1051 strlcpy(p
->state_message
, value
, sizeof(p
->state_message
));
1053 else if (!strcasecmp(line
, "StateTime"))
1056 * Set the state time...
1060 p
->state_time
= atoi(value
);
1062 else if (!strcasecmp(line
, "Accepting"))
1065 * Set the initial accepting state...
1069 (!strcasecmp(value
, "yes") ||
1070 !strcasecmp(value
, "on") ||
1071 !strcasecmp(value
, "true")))
1074 (!strcasecmp(value
, "no") ||
1075 !strcasecmp(value
, "off") ||
1076 !strcasecmp(value
, "false")))
1080 cupsdLogMessage(CUPSD_LOG_ERROR
,
1081 "Syntax error on line %d of printers.conf.", linenum
);
1085 else if (!strcasecmp(line
, "Shared"))
1088 * Set the initial shared state...
1092 (!strcasecmp(value
, "yes") ||
1093 !strcasecmp(value
, "on") ||
1094 !strcasecmp(value
, "true")))
1097 (!strcasecmp(value
, "no") ||
1098 !strcasecmp(value
, "off") ||
1099 !strcasecmp(value
, "false")))
1103 cupsdLogMessage(CUPSD_LOG_ERROR
,
1104 "Syntax error on line %d of printers.conf.", linenum
);
1108 else if (!strcasecmp(line
, "JobSheets"))
1111 * Set the initial job sheets...
1116 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1121 cupsdSetString(&p
->job_sheets
[0], value
);
1123 while (isspace(*valueptr
& 255))
1128 for (value
= valueptr
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1133 cupsdSetString(&p
->job_sheets
[1], value
);
1138 cupsdLogMessage(CUPSD_LOG_ERROR
,
1139 "Syntax error on line %d of printers.conf.", linenum
);
1143 else if (!strcasecmp(line
, "AllowUser"))
1148 cupsdAddPrinterUser(p
, value
);
1152 cupsdLogMessage(CUPSD_LOG_ERROR
,
1153 "Syntax error on line %d of printers.conf.", linenum
);
1157 else if (!strcasecmp(line
, "DenyUser"))
1162 cupsdAddPrinterUser(p
, value
);
1166 cupsdLogMessage(CUPSD_LOG_ERROR
,
1167 "Syntax error on line %d of printers.conf.", linenum
);
1171 else if (!strcasecmp(line
, "QuotaPeriod"))
1174 p
->quota_period
= atoi(value
);
1177 cupsdLogMessage(CUPSD_LOG_ERROR
,
1178 "Syntax error on line %d of printers.conf.", linenum
);
1182 else if (!strcasecmp(line
, "PageLimit"))
1185 p
->page_limit
= atoi(value
);
1188 cupsdLogMessage(CUPSD_LOG_ERROR
,
1189 "Syntax error on line %d of printers.conf.", linenum
);
1193 else if (!strcasecmp(line
, "KLimit"))
1196 p
->k_limit
= atoi(value
);
1199 cupsdLogMessage(CUPSD_LOG_ERROR
,
1200 "Syntax error on line %d of printers.conf.", linenum
);
1204 else if (!strcasecmp(line
, "OpPolicy"))
1208 cupsd_policy_t
*pol
; /* Policy */
1211 if ((pol
= cupsdFindPolicy(value
)) != NULL
)
1213 cupsdSetString(&p
->op_policy
, value
);
1214 p
->op_policy_ptr
= pol
;
1217 cupsdLogMessage(CUPSD_LOG_ERROR
,
1218 "Bad policy \"%s\" on line %d of printers.conf",
1223 cupsdLogMessage(CUPSD_LOG_ERROR
,
1224 "Syntax error on line %d of printers.conf.", linenum
);
1228 else if (!strcasecmp(line
, "ErrorPolicy"))
1231 cupsdSetString(&p
->error_policy
, value
);
1234 cupsdLogMessage(CUPSD_LOG_ERROR
,
1235 "Syntax error on line %d of printers.conf.", linenum
);
1242 * Something else we don't understand...
1245 cupsdLogMessage(CUPSD_LOG_ERROR
,
1246 "Unknown configuration directive %s on line %d of printers.conf.",
1256 * 'cupsdRenamePrinter()' - Rename a printer.
1261 cupsd_printer_t
*p
, /* I - Printer */
1262 const char *name
) /* I - New name */
1265 * Remove the printer from the array(s) first...
1268 cupsArrayRemove(Printers
, p
);
1270 if (p
->type
& CUPS_PRINTER_IMPLICIT
)
1271 cupsArrayRemove(ImplicitPrinters
, p
);
1274 * Rename the printer type...
1277 mimeDeleteType(MimeDatabase
, p
->filetype
);
1278 p
->filetype
= mimeAddType(MimeDatabase
, "printer", name
);
1280 mimeDeleteType(MimeDatabase
, p
->prefiltertype
);
1281 p
->prefiltertype
= mimeAddType(MimeDatabase
, "prefilter", name
);
1284 * Rename the printer...
1287 cupsdSetString(&p
->name
, name
);
1290 * Reset printer attributes...
1293 cupsdSetPrinterAttrs(p
);
1296 * Add the printer back to the printer array(s)...
1299 cupsArrayAdd(Printers
, p
);
1301 if (p
->type
& CUPS_PRINTER_IMPLICIT
)
1302 cupsArrayAdd(ImplicitPrinters
, p
);
1307 * 'cupsdSaveAllPrinters()' - Save all printer definitions to the printers.conf
1312 cupsdSaveAllPrinters(void)
1314 int i
; /* Looping var */
1315 cups_file_t
*fp
; /* printers.conf file */
1316 char temp
[1024]; /* Temporary string */
1317 char backup
[1024]; /* printers.conf.O file */
1318 cupsd_printer_t
*printer
; /* Current printer class */
1319 time_t curtime
; /* Current time */
1320 struct tm
*curdate
; /* Current date */
1321 cups_option_t
*option
; /* Current option */
1322 const char *ptr
; /* Pointer into info/location */
1326 * Create the printers.conf file...
1329 snprintf(temp
, sizeof(temp
), "%s/printers.conf", ServerRoot
);
1330 snprintf(backup
, sizeof(backup
), "%s/printers.conf.O", ServerRoot
);
1332 if (rename(temp
, backup
))
1334 if (errno
!= ENOENT
)
1335 cupsdLogMessage(CUPSD_LOG_ERROR
,
1336 "Unable to backup printers.conf - %s", strerror(errno
));
1339 if ((fp
= cupsFileOpen(temp
, "w")) == NULL
)
1341 cupsdLogMessage(CUPSD_LOG_ERROR
,
1342 "Unable to save printers.conf - %s", strerror(errno
));
1344 if (rename(backup
, temp
))
1345 cupsdLogMessage(CUPSD_LOG_ERROR
,
1346 "Unable to restore printers.conf - %s", strerror(errno
));
1350 cupsdLogMessage(CUPSD_LOG_INFO
, "Saving printers.conf...");
1353 * Restrict access to the file...
1356 fchown(cupsFileNumber(fp
), getuid(), Group
);
1357 fchmod(cupsFileNumber(fp
), 0600);
1360 * Write a small header to the file...
1363 curtime
= time(NULL
);
1364 curdate
= localtime(&curtime
);
1365 strftime(temp
, sizeof(temp
) - 1, "%Y-%m-%d %H:%M", curdate
);
1367 cupsFilePuts(fp
, "# Printer configuration file for " CUPS_SVERSION
"\n");
1368 cupsFilePrintf(fp
, "# Written by cupsd on %s\n", temp
);
1371 * Write each local printer known to the system...
1374 for (printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
1376 printer
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
1379 * Skip remote destinations and printer classes...
1382 if ((printer
->type
& CUPS_PRINTER_DISCOVERED
) ||
1383 (printer
->type
& CUPS_PRINTER_CLASS
) ||
1384 (printer
->type
& CUPS_PRINTER_IMPLICIT
))
1388 * Write printers as needed...
1391 if (printer
== DefaultPrinter
)
1392 cupsFilePrintf(fp
, "<DefaultPrinter %s>\n", printer
->name
);
1394 cupsFilePrintf(fp
, "<Printer %s>\n", printer
->name
);
1396 if (printer
->num_auth_info_required
> 0)
1398 cupsFilePrintf(fp
, "AuthInfoRequired %s", printer
->auth_info_required
[0]);
1399 for (i
= 1; i
< printer
->num_auth_info_required
; i
++)
1400 cupsFilePrintf(fp
, ",%s", printer
->auth_info_required
[i
]);
1401 cupsFilePutChar(fp
, '\n');
1406 if ((ptr
= strchr(printer
->info
, '#')) != NULL
)
1409 * Need to quote the first # in the info string...
1412 cupsFilePuts(fp
, "Info ");
1413 cupsFileWrite(fp
, printer
->info
, ptr
- printer
->info
);
1414 cupsFilePutChar(fp
, '\\');
1415 cupsFilePuts(fp
, ptr
);
1416 cupsFilePutChar(fp
, '\n');
1419 cupsFilePrintf(fp
, "Info %s\n", printer
->info
);
1422 if (printer
->location
)
1424 if ((ptr
= strchr(printer
->info
, '#')) != NULL
)
1427 * Need to quote the first # in the location string...
1430 cupsFilePuts(fp
, "Location ");
1431 cupsFileWrite(fp
, printer
->location
, ptr
- printer
->location
);
1432 cupsFilePutChar(fp
, '\\');
1433 cupsFilePuts(fp
, ptr
);
1434 cupsFilePutChar(fp
, '\n');
1437 cupsFilePrintf(fp
, "Location %s\n", printer
->location
);
1439 if (printer
->device_uri
)
1440 cupsFilePrintf(fp
, "DeviceURI %s\n", printer
->device_uri
);
1442 if (printer
->port_monitor
)
1443 cupsFilePrintf(fp
, "PortMonitor %s\n", printer
->port_monitor
);
1445 if (printer
->state
== IPP_PRINTER_STOPPED
)
1447 cupsFilePuts(fp
, "State Stopped\n");
1448 cupsFilePrintf(fp
, "StateMessage %s\n", printer
->state_message
);
1451 cupsFilePuts(fp
, "State Idle\n");
1453 cupsFilePrintf(fp
, "StateTime %d\n", (int)printer
->state_time
);
1455 if (printer
->accepting
)
1456 cupsFilePuts(fp
, "Accepting Yes\n");
1458 cupsFilePuts(fp
, "Accepting No\n");
1460 if (printer
->shared
)
1461 cupsFilePuts(fp
, "Shared Yes\n");
1463 cupsFilePuts(fp
, "Shared No\n");
1465 cupsFilePrintf(fp
, "JobSheets %s %s\n", printer
->job_sheets
[0],
1466 printer
->job_sheets
[1]);
1468 cupsFilePrintf(fp
, "QuotaPeriod %d\n", printer
->quota_period
);
1469 cupsFilePrintf(fp
, "PageLimit %d\n", printer
->page_limit
);
1470 cupsFilePrintf(fp
, "KLimit %d\n", printer
->k_limit
);
1472 for (i
= 0; i
< printer
->num_users
; i
++)
1473 cupsFilePrintf(fp
, "%sUser %s\n", printer
->deny_users
? "Deny" : "Allow",
1476 if (printer
->op_policy
)
1477 cupsFilePrintf(fp
, "OpPolicy %s\n", printer
->op_policy
);
1478 if (printer
->error_policy
)
1479 cupsFilePrintf(fp
, "ErrorPolicy %s\n", printer
->error_policy
);
1481 for (i
= printer
->num_options
, option
= printer
->options
;
1484 cupsFilePrintf(fp
, "Option %s %s\n", option
->name
, option
->value
);
1486 cupsFilePuts(fp
, "</Printer>\n");
1490 * Make IRIX desktop & printer status happy
1493 write_irix_state(printer
);
1502 * 'cupsdSetAuthInfoRequired()' - Set the required authentication info.
1505 int /* O - 1 if value OK, 0 otherwise */
1506 cupsdSetAuthInfoRequired(
1507 cupsd_printer_t
*p
, /* I - Printer */
1508 const char *values
, /* I - Plain text value (or NULL) */
1509 ipp_attribute_t
*attr
) /* I - IPP attribute value (or NULL) */
1511 int i
; /* Looping var */
1514 p
->num_auth_info_required
= 0;
1517 * Do we have a plain text value?
1523 * Yes, grab the keywords...
1526 const char *end
; /* End of current value */
1529 while (*values
&& p
->num_auth_info_required
< 4)
1531 if ((end
= strchr(values
, ',')) == NULL
)
1532 end
= values
+ strlen(values
);
1534 if ((end
- values
) == 4 && !strncmp(values
, "none", 4))
1536 if (p
->num_auth_info_required
!= 0 || *end
)
1539 p
->auth_info_required
[p
->num_auth_info_required
] = "none";
1540 p
->num_auth_info_required
++;
1544 else if ((end
- values
) == 9 && !strncmp(values
, "negotiate", 9))
1546 if (p
->num_auth_info_required
!= 0 || *end
)
1549 p
->auth_info_required
[p
->num_auth_info_required
] = "negotiate";
1550 p
->num_auth_info_required
++;
1552 else if ((end
- values
) == 6 && !strncmp(values
, "domain", 6))
1554 p
->auth_info_required
[p
->num_auth_info_required
] = "domain";
1555 p
->num_auth_info_required
++;
1557 else if ((end
- values
) == 8 && !strncmp(values
, "password", 8))
1559 p
->auth_info_required
[p
->num_auth_info_required
] = "password";
1560 p
->num_auth_info_required
++;
1562 else if ((end
- values
) == 8 && !strncmp(values
, "username", 8))
1564 p
->auth_info_required
[p
->num_auth_info_required
] = "username";
1565 p
->num_auth_info_required
++;
1570 values
= (*end
) ? end
+ 1 : end
;
1573 if (p
->num_auth_info_required
== 0)
1575 p
->auth_info_required
[0] = "none";
1576 p
->num_auth_info_required
= 1;
1580 * Update the printer-type value as needed...
1583 if (p
->num_auth_info_required
> 1 ||
1584 strcmp(p
->auth_info_required
[0], "none"))
1585 p
->type
|= CUPS_PRINTER_AUTHENTICATED
;
1587 p
->type
&= ~CUPS_PRINTER_AUTHENTICATED
;
1593 * Grab values from an attribute instead...
1596 if (!attr
|| attr
->num_values
> 4)
1600 * Update the printer-type value as needed...
1603 if (attr
->num_values
> 1 ||
1604 strcmp(attr
->values
[0].string
.text
, "none"))
1605 p
->type
|= CUPS_PRINTER_AUTHENTICATED
;
1607 p
->type
&= ~CUPS_PRINTER_AUTHENTICATED
;
1609 for (i
= 0; i
< attr
->num_values
; i
++)
1611 if (!strcmp(attr
->values
[i
].string
.text
, "none"))
1613 if (p
->num_auth_info_required
!= 0 || attr
->num_values
!= 1)
1616 p
->auth_info_required
[p
->num_auth_info_required
] = "none";
1617 p
->num_auth_info_required
++;
1621 else if (!strcmp(attr
->values
[i
].string
.text
, "negotiate"))
1623 if (p
->num_auth_info_required
!= 0 || attr
->num_values
!= 1)
1626 p
->auth_info_required
[p
->num_auth_info_required
] = "negotiate";
1627 p
->num_auth_info_required
++;
1631 else if (!strcmp(attr
->values
[i
].string
.text
, "domain"))
1633 p
->auth_info_required
[p
->num_auth_info_required
] = "domain";
1634 p
->num_auth_info_required
++;
1636 else if (!strcmp(attr
->values
[i
].string
.text
, "password"))
1638 p
->auth_info_required
[p
->num_auth_info_required
] = "password";
1639 p
->num_auth_info_required
++;
1641 else if (!strcmp(attr
->values
[i
].string
.text
, "username"))
1643 p
->auth_info_required
[p
->num_auth_info_required
] = "username";
1644 p
->num_auth_info_required
++;
1655 * 'cupsdSetPrinterAttr()' - Set a printer attribute.
1659 cupsdSetPrinterAttr(
1660 cupsd_printer_t
*p
, /* I - Printer */
1661 const char *name
, /* I - Attribute name */
1662 char *value
) /* I - Attribute value string */
1664 ipp_attribute_t
*attr
; /* Attribute */
1665 int i
, /* Looping var */
1666 count
; /* Number of values */
1667 char *ptr
; /* Pointer into value */
1668 ipp_tag_t value_tag
; /* Value tag for this attribute */
1672 * Count the number of values...
1675 for (count
= 1, ptr
= value
;
1676 (ptr
= strchr(ptr
, ',')) != NULL
;
1680 * Then add or update the attribute as needed...
1683 if (!strcmp(name
, "marker-levels"))
1689 if ((attr
= ippFindAttribute(p
->attrs
, name
, IPP_TAG_INTEGER
)) != NULL
&&
1690 attr
->num_values
< count
)
1692 ippDeleteAttribute(p
->attrs
, attr
);
1697 attr
->num_values
= count
;
1699 attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
, name
,
1704 cupsdLogMessage(CUPSD_LOG_ERROR
,
1705 "Unable to allocate memory for printer attribute "
1706 "(%d values)", count
);
1710 for (i
= 0; i
< count
; i
++)
1712 if ((ptr
= strchr(value
, ',')) != NULL
)
1715 attr
->values
[i
].integer
= strtol(value
, NULL
, 10);
1724 * Name or keyword values...
1727 if (!strcmp(name
, "marker-types"))
1728 value_tag
= IPP_TAG_KEYWORD
;
1730 value_tag
= IPP_TAG_NAME
;
1732 if ((attr
= ippFindAttribute(p
->attrs
, name
, value_tag
)) != NULL
&&
1733 attr
->num_values
< count
)
1735 ippDeleteAttribute(p
->attrs
, attr
);
1740 attr
->num_values
= count
;
1742 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, value_tag
, name
,
1747 cupsdLogMessage(CUPSD_LOG_ERROR
,
1748 "Unable to allocate memory for printer attribute "
1749 "(%d values)", count
);
1753 for (i
= 0; i
< count
; i
++)
1755 if ((ptr
= strchr(value
, ',')) != NULL
)
1758 _cupsStrFree(attr
->values
[i
].string
.text
);
1759 attr
->values
[i
].string
.text
= _cupsStrAlloc(value
);
1769 * 'cupsdSetPrinterAttrs()' - Set printer attributes based upon the PPD file.
1773 cupsdSetPrinterAttrs(cupsd_printer_t
*p
)/* I - Printer to setup */
1775 int i
, /* Looping var */
1776 length
; /* Length of browse attributes */
1777 char uri
[HTTP_MAX_URI
]; /* URI for printer */
1778 char resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
1779 char filename
[1024]; /* Name of PPD file */
1780 int num_air
; /* Number of auth-info-required values */
1781 const char * const *air
; /* auth-info-required values */
1782 int num_media
; /* Number of media options */
1783 cupsd_location_t
*auth
; /* Pointer to authentication element */
1784 const char *auth_supported
; /* Authentication supported */
1785 ppd_file_t
*ppd
; /* PPD file data */
1786 ppd_option_t
*input_slot
, /* InputSlot options */
1787 *media_type
, /* MediaType options */
1788 *page_size
, /* PageSize options */
1789 *output_bin
, /* OutputBin options */
1790 *media_quality
, /* EFMediaQualityMode options */
1791 *duplex
; /* Duplex options */
1792 ppd_attr_t
*ppdattr
; /* PPD attribute */
1793 ipp_attribute_t
*attr
; /* Attribute data */
1794 ipp_value_t
*val
; /* Attribute value */
1795 int num_finishings
; /* Number of finishings */
1796 int finishings
[5]; /* finishings-supported values */
1797 cups_option_t
*option
; /* Current printer option */
1798 static const char * const sides
[3] = /* sides-supported values */
1801 "two-sided-long-edge",
1802 "two-sided-short-edge"
1804 static const char * const air_userpass
[] =
1805 { /* Basic/Digest authentication */
1810 static const char * const air_negotiate
[] =
1811 { /* Kerberos authentication */
1814 #endif /* HAVE_GSSAPI */
1815 static const char * const air_none
[] =
1816 { /* No authentication */
1821 DEBUG_printf(("cupsdSetPrinterAttrs: entering name = %s, type = %x\n", p
->name
,
1825 * Make sure that we have the common attributes defined...
1829 cupsdCreateCommonData();
1832 * Clear out old filters, if any...
1835 delete_printer_filters(p
);
1838 * Figure out the authentication that is required for the printer.
1841 auth_supported
= "requesting-user-name";
1845 if (p
->num_auth_info_required
> 0 && strcmp(p
->auth_info_required
[0], "none"))
1847 num_air
= p
->num_auth_info_required
;
1848 air
= p
->auth_info_required
;
1850 if (!strcmp(air
[0], "username"))
1851 auth_supported
= "basic";
1853 auth_supported
= "negotiate";
1855 else if (!(p
->type
& CUPS_PRINTER_DISCOVERED
))
1857 if (p
->type
& CUPS_PRINTER_CLASS
)
1858 snprintf(resource
, sizeof(resource
), "/classes/%s", p
->name
);
1860 snprintf(resource
, sizeof(resource
), "/printers/%s", p
->name
);
1862 if ((auth
= cupsdFindBest(resource
, HTTP_POST
)) == NULL
||
1863 auth
->type
== CUPSD_AUTH_NONE
)
1864 auth
= cupsdFindPolicyOp(p
->op_policy_ptr
, IPP_PRINT_JOB
);
1868 if (auth
->type
== CUPSD_AUTH_BASIC
|| auth
->type
== CUPSD_AUTH_BASICDIGEST
)
1870 auth_supported
= "basic";
1874 else if (auth
->type
== CUPSD_AUTH_DIGEST
)
1876 auth_supported
= "digest";
1881 else if (auth
->type
== CUPSD_AUTH_NEGOTIATE
)
1883 auth_supported
= "negotiate";
1885 air
= air_negotiate
;
1887 #endif /* HAVE_GSSAPI */
1889 if (auth
->type
!= CUPSD_AUTH_NONE
)
1890 p
->type
|= CUPS_PRINTER_AUTHENTICATED
;
1892 p
->type
&= ~CUPS_PRINTER_AUTHENTICATED
;
1895 p
->type
&= ~CUPS_PRINTER_AUTHENTICATED
;
1897 else if (p
->type
& CUPS_PRINTER_AUTHENTICATED
)
1904 * Create the required IPP attributes for a printer...
1908 ippDelete(p
->attrs
);
1910 p
->attrs
= ippNew();
1912 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
1913 "uri-authentication-supported", NULL
, auth_supported
);
1914 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
1915 "uri-security-supported", NULL
, "none");
1916 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
, "printer-name", NULL
,
1918 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-location",
1919 NULL
, p
->location
? p
->location
: "");
1920 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-info",
1921 NULL
, p
->info
? p
->info
: "");
1922 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "printer-more-info",
1928 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
1929 "requesting-user-name-denied", p
->num_users
, NULL
,
1932 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
1933 "requesting-user-name-allowed", p
->num_users
, NULL
,
1937 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
1938 "job-quota-period", p
->quota_period
);
1939 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
1940 "job-k-limit", p
->k_limit
);
1941 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
1942 "job-page-limit", p
->page_limit
);
1943 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
1944 "auth-info-required", num_air
, NULL
, air
);
1946 if (cupsArrayCount(Banners
) > 0 && !(p
->type
& CUPS_PRINTER_DISCOVERED
))
1949 * Setup the job-sheets-default attribute...
1952 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
1953 "job-sheets-default", 2, NULL
, NULL
);
1957 attr
->values
[0].string
.text
= _cupsStrAlloc(Classification
?
1958 Classification
: p
->job_sheets
[0]);
1959 attr
->values
[1].string
.text
= _cupsStrAlloc(Classification
?
1960 Classification
: p
->job_sheets
[1]);
1967 if (p
->type
& CUPS_PRINTER_DISCOVERED
)
1970 * Tell the client this is a remote printer of some type...
1973 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
1974 "printer-uri-supported", NULL
, p
->uri
);
1977 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
1978 "printer-make-and-model", NULL
, p
->make_model
);
1980 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "device-uri", NULL
,
1989 * Assign additional attributes depending on whether this is a printer
1993 p
->type
&= ~CUPS_PRINTER_OPTIONS
;
1995 if (p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
))
2000 * Add class-specific attributes...
2003 if ((p
->type
& CUPS_PRINTER_IMPLICIT
) && p
->num_printers
> 0 &&
2004 p
->printers
[0]->make_model
)
2005 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
2006 "printer-make-and-model", NULL
, p
->printers
[0]->make_model
);
2008 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
2009 "printer-make-and-model", NULL
, "Local Printer Class");
2011 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "device-uri", NULL
,
2012 "file:///dev/null");
2014 if (p
->num_printers
> 0)
2017 * Add a list of member URIs and names...
2020 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
2021 "member-uris", p
->num_printers
, NULL
, NULL
);
2022 p
->type
|= CUPS_PRINTER_OPTIONS
;
2024 for (i
= 0; i
< p
->num_printers
; i
++)
2027 attr
->values
[i
].string
.text
= _cupsStrAlloc(p
->printers
[i
]->uri
);
2029 p
->type
&= ~CUPS_PRINTER_OPTIONS
| p
->printers
[i
]->type
;
2032 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2033 "member-names", p
->num_printers
, NULL
, NULL
);
2037 for (i
= 0; i
< p
->num_printers
; i
++)
2038 attr
->values
[i
].string
.text
= _cupsStrAlloc(p
->printers
[i
]->name
);
2045 * Add printer-specific attributes... Start by sanitizing the device
2046 * URI so it doesn't have a username or password in it...
2050 strcpy(uri
, "file:/dev/null");
2051 else if (strstr(p
->device_uri
, "://") != NULL
)
2054 * http://..., ipp://..., etc.
2057 cupsdSanitizeURI(p
->device_uri
, uri
, sizeof(uri
));
2062 * file:..., serial:..., etc.
2065 strlcpy(uri
, p
->device_uri
, sizeof(uri
));
2068 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "device-uri", NULL
,
2072 * Assign additional attributes from the PPD file (if any)...
2075 p
->type
|= CUPS_PRINTER_BW
;
2076 finishings
[0] = IPP_FINISHINGS_NONE
;
2079 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
2082 if ((ppd
= ppdOpenFile(filename
)) != NULL
)
2085 * Add make/model and other various attributes...
2088 if (ppd
->color_device
)
2089 p
->type
|= CUPS_PRINTER_COLOR
;
2090 if (ppd
->variable_sizes
)
2091 p
->type
|= CUPS_PRINTER_VARIABLE
;
2092 if (!ppd
->manual_copies
)
2093 p
->type
|= CUPS_PRINTER_COPIES
;
2094 if ((ppdattr
= ppdFindAttr(ppd
, "cupsFax", NULL
)) != NULL
)
2095 if (ppdattr
->value
&& !strcasecmp(ppdattr
->value
, "true"))
2096 p
->type
|= CUPS_PRINTER_FAX
;
2098 ippAddBoolean(p
->attrs
, IPP_TAG_PRINTER
, "color-supported",
2100 if (ppd
->throughput
)
2101 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2102 "pages-per-minute", ppd
->throughput
);
2107 * The NickName can be localized in the character set specified
2108 * by the LanugageEncoding attribute. However, ppdOpen2() has
2109 * already converted the ppd->nickname member to UTF-8 for us
2110 * (the original attribute value is available separately)
2113 cupsdSetString(&p
->make_model
, ppd
->nickname
);
2115 else if (ppd
->modelname
)
2118 * Model name can only contain specific characters...
2121 cupsdSetString(&p
->make_model
, ppd
->modelname
);
2124 cupsdSetString(&p
->make_model
, "Bad PPD File");
2126 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
2127 "printer-make-and-model", NULL
, p
->make_model
);
2130 * Add media options from the PPD file...
2133 if ((input_slot
= ppdFindOption(ppd
, "InputSlot")) != NULL
)
2134 num_media
= input_slot
->num_choices
;
2138 if ((media_type
= ppdFindOption(ppd
, "MediaType")) != NULL
)
2139 num_media
+= media_type
->num_choices
;
2141 if ((page_size
= ppdFindOption(ppd
, "PageSize")) != NULL
)
2142 num_media
+= page_size
->num_choices
;
2144 if ((media_quality
= ppdFindOption(ppd
, "EFMediaQualityMode")) != NULL
)
2145 num_media
+= media_quality
->num_choices
;
2149 cupsdLogMessage(CUPSD_LOG_CRIT
,
2150 "The PPD file for printer %s contains no media "
2151 "options and is therefore invalid!", p
->name
);
2155 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2156 "media-supported", num_media
, NULL
, NULL
);
2161 if (input_slot
!= NULL
)
2162 for (i
= 0; i
< input_slot
->num_choices
; i
++, val
++)
2163 val
->string
.text
= _cupsStrAlloc(input_slot
->choices
[i
].choice
);
2165 if (media_type
!= NULL
)
2166 for (i
= 0; i
< media_type
->num_choices
; i
++, val
++)
2167 val
->string
.text
= _cupsStrAlloc(media_type
->choices
[i
].choice
);
2169 if (media_quality
!= NULL
)
2170 for (i
= 0; i
< media_quality
->num_choices
; i
++, val
++)
2171 val
->string
.text
= _cupsStrAlloc(media_quality
->choices
[i
].choice
);
2173 if (page_size
!= NULL
)
2175 for (i
= 0; i
< page_size
->num_choices
; i
++, val
++)
2176 val
->string
.text
= _cupsStrAlloc(page_size
->choices
[i
].choice
);
2178 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2179 "media-default", NULL
, page_size
->defchoice
);
2181 else if (input_slot
!= NULL
)
2182 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2183 "media-default", NULL
, input_slot
->defchoice
);
2184 else if (media_type
!= NULL
)
2185 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2186 "media-default", NULL
, media_type
->defchoice
);
2187 else if (media_quality
!= NULL
)
2188 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2189 "media-default", NULL
, media_quality
->defchoice
);
2191 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2192 "media-default", NULL
, "none");
2200 if ((output_bin
= ppdFindOption(ppd
, "OutputBin")) != NULL
)
2202 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2203 "output-bin-supported", output_bin
->num_choices
,
2208 for (i
= 0, val
= attr
->values
;
2209 i
< output_bin
->num_choices
;
2211 val
->string
.text
= _cupsStrAlloc(output_bin
->choices
[i
].choice
);
2219 if ((duplex
= ppdFindOption(ppd
, "Duplex")) == NULL
)
2220 if ((duplex
= ppdFindOption(ppd
, "EFDuplex")) == NULL
)
2221 if ((duplex
= ppdFindOption(ppd
, "EFDuplexing")) == NULL
)
2222 if ((duplex
= ppdFindOption(ppd
, "KD03Duplex")) == NULL
)
2223 duplex
= ppdFindOption(ppd
, "JCLDuplex");
2225 if (duplex
&& duplex
->num_choices
> 1)
2227 p
->type
|= CUPS_PRINTER_DUPLEX
;
2229 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2230 "sides-supported", 3, NULL
, sides
);
2232 if (!strcasecmp(duplex
->defchoice
, "DuplexTumble"))
2233 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2234 "sides-default", NULL
, "two-sided-short-edge");
2235 else if (!strcasecmp(duplex
->defchoice
, "DuplexNoTumble"))
2236 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2237 "sides-default", NULL
, "two-sided-long-edge");
2239 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2240 "sides-default", NULL
, "one-sided");
2243 if (ppdFindOption(ppd
, "Collate") != NULL
)
2244 p
->type
|= CUPS_PRINTER_COLLATE
;
2246 if (ppdFindOption(ppd
, "StapleLocation") != NULL
)
2248 p
->type
|= CUPS_PRINTER_STAPLE
;
2249 finishings
[num_finishings
++] = IPP_FINISHINGS_STAPLE
;
2252 if (ppdFindOption(ppd
, "BindEdge") != NULL
)
2254 p
->type
|= CUPS_PRINTER_BIND
;
2255 finishings
[num_finishings
++] = IPP_FINISHINGS_BIND
;
2258 for (i
= 0; i
< ppd
->num_sizes
; i
++)
2259 if (ppd
->sizes
[i
].length
> 1728)
2260 p
->type
|= CUPS_PRINTER_LARGE
;
2261 else if (ppd
->sizes
[i
].length
> 1008)
2262 p
->type
|= CUPS_PRINTER_MEDIUM
;
2264 p
->type
|= CUPS_PRINTER_SMALL
;
2267 * Add a filter from application/vnd.cups-raw to printer/name to
2268 * handle "raw" printing by users.
2271 add_printer_filter(p
, p
->filetype
, "application/vnd.cups-raw 0 -");
2274 * Add any pre-filters in the PPD file...
2277 if ((ppdattr
= ppdFindAttr(ppd
, "cupsPreFilter", NULL
)) != NULL
)
2279 p
->prefiltertype
= mimeAddType(MimeDatabase
, "prefilter", p
->name
);
2281 for (; ppdattr
; ppdattr
= ppdFindNextAttr(ppd
, "cupsPreFilter", NULL
))
2283 add_printer_filter(p
, p
->prefiltertype
, ppdattr
->value
);
2287 * Add any filters in the PPD file...
2290 DEBUG_printf(("ppd->num_filters = %d\n", ppd
->num_filters
));
2291 for (i
= 0; i
< ppd
->num_filters
; i
++)
2293 DEBUG_printf(("ppd->filters[%d] = \"%s\"\n", i
, ppd
->filters
[i
]));
2294 add_printer_filter(p
, p
->filetype
, ppd
->filters
[i
]);
2297 if (ppd
->num_filters
== 0)
2300 * If there are no filters, add a PostScript printing filter.
2303 add_printer_filter(p
, p
->filetype
,
2304 "application/vnd.cups-postscript 0 -");
2308 * Show current and available port monitors for this printer...
2311 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
, "port-monitor",
2312 NULL
, p
->port_monitor
? p
->port_monitor
: "none");
2314 for (i
= 1, ppdattr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
2316 i
++, ppdattr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
));
2320 if (strstr(ppd
->protocols
, "TBCP"))
2322 else if (strstr(ppd
->protocols
, "BCP"))
2326 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2327 "port-monitor-supported", i
, NULL
, NULL
);
2329 attr
->values
[0].string
.text
= _cupsStrAlloc("none");
2331 for (i
= 1, ppdattr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
2333 i
++, ppdattr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
))
2334 attr
->values
[i
].string
.text
= _cupsStrAlloc(ppdattr
->value
);
2338 if (strstr(ppd
->protocols
, "TBCP"))
2339 attr
->values
[i
].string
.text
= _cupsStrAlloc("tbcp");
2340 else if (strstr(ppd
->protocols
, "BCP"))
2341 attr
->values
[i
].string
.text
= _cupsStrAlloc("bcp");
2345 cupsdSetString(&p
->product
, ppd
->product
);
2346 #endif /* HAVE_DNSSD */
2348 if (ppdFindAttr(ppd
, "APRemoteQueueID", NULL
))
2349 p
->type
|= CUPS_PRINTER_REMOTE
;
2352 * Close the PPD and set the type...
2357 else if (!access(filename
, 0))
2359 int pline
; /* PPD line number */
2360 ppd_status_t pstatus
; /* PPD load status */
2363 pstatus
= ppdLastError(&pline
);
2365 cupsdLogMessage(CUPSD_LOG_ERROR
, "PPD file for %s cannot be loaded!",
2368 if (pstatus
<= PPD_ALLOC_ERROR
)
2369 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s", strerror(errno
));
2371 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s on line %d.",
2372 ppdErrorString(pstatus
), pline
);
2374 cupsdLogMessage(CUPSD_LOG_INFO
,
2375 "Hint: Run \"cupstestppd %s\" and fix any errors.",
2379 * Add a filter from application/vnd.cups-raw to printer/name to
2380 * handle "raw" printing by users.
2383 add_printer_filter(p
, p
->filetype
, "application/vnd.cups-raw 0 -");
2386 * Add a PostScript filter, since this is still possibly PS printer.
2389 add_printer_filter(p
, p
->filetype
,
2390 "application/vnd.cups-postscript 0 -");
2395 * If we have an interface script, add a filter entry for it...
2398 snprintf(filename
, sizeof(filename
), "%s/interfaces/%s", ServerRoot
,
2400 if (!access(filename
, X_OK
))
2403 * Yes, we have a System V style interface script; use it!
2406 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
2407 "printer-make-and-model", NULL
,
2408 "Local System V Printer");
2410 snprintf(filename
, sizeof(filename
), "*/* 0 %s/interfaces/%s",
2411 ServerRoot
, p
->name
);
2412 add_printer_filter(p
, p
->filetype
, filename
);
2414 else if (p
->device_uri
&&
2415 !strncmp(p
->device_uri
, "ipp://", 6) &&
2416 (strstr(p
->device_uri
, "/printers/") != NULL
||
2417 strstr(p
->device_uri
, "/classes/") != NULL
))
2420 * Tell the client this is really a hard-wired remote printer.
2423 p
->type
|= CUPS_PRINTER_REMOTE
;
2426 * Point the printer-uri-supported attribute to the
2430 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
2431 "printer-uri-supported", NULL
, p
->device_uri
);
2434 * Then set the make-and-model accordingly...
2437 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
2438 "printer-make-and-model", NULL
, "Remote Printer");
2441 * Print all files directly...
2450 * Otherwise we have neither - treat this as a "dumb" printer
2451 * with no PPD file...
2454 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
2455 "printer-make-and-model", NULL
, "Local Raw Printer");
2461 ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
2462 "finishings-supported", num_finishings
, finishings
);
2463 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
2464 "finishings-default", IPP_FINISHINGS_NONE
);
2469 * Force sharing off for remote queues...
2472 if (p
->type
& (CUPS_PRINTER_REMOTE
| CUPS_PRINTER_IMPLICIT
))
2477 * Copy the printer options into a browse attributes string we can re-use.
2480 const char *valptr
; /* Pointer into value */
2481 char *attrptr
; /* Pointer into attribute string */
2485 * Free the old browse attributes as needed...
2488 if (p
->browse_attrs
)
2489 free(p
->browse_attrs
);
2492 * Compute the length of all attributes + job-sheets, lease-duration,
2493 * and BrowseLocalOptions.
2496 for (length
= 1, i
= p
->num_options
, option
= p
->options
;
2500 length
+= strlen(option
->name
) + 2;
2504 for (valptr
= option
->value
; *valptr
; valptr
++)
2505 if (strchr(" \"\'\\", *valptr
))
2512 length
+= 13 + strlen(p
->job_sheets
[0]) + strlen(p
->job_sheets
[1]);
2514 if (BrowseLocalOptions
)
2515 length
+= 12 + strlen(BrowseLocalOptions
);
2517 if (p
->num_auth_info_required
> 0)
2519 length
+= 18; /* auth-info-required */
2521 for (i
= 0; i
< p
->num_auth_info_required
; i
++)
2522 length
+= strlen(p
->auth_info_required
[i
]) + 1;
2526 * Allocate the new string...
2529 if ((p
->browse_attrs
= calloc(1, length
)) == NULL
)
2530 cupsdLogMessage(CUPSD_LOG_ERROR
,
2531 "Unable to allocate %d bytes for browse data!",
2536 * Got the allocated string, now copy the options and attributes over...
2539 sprintf(p
->browse_attrs
, "job-sheets=%s,%s lease-duration=%d",
2540 p
->job_sheets
[0], p
->job_sheets
[1], BrowseTimeout
);
2541 attrptr
= p
->browse_attrs
+ strlen(p
->browse_attrs
);
2543 if (BrowseLocalOptions
)
2545 sprintf(attrptr
, " ipp-options=%s", BrowseLocalOptions
);
2546 attrptr
+= strlen(attrptr
);
2549 for (i
= p
->num_options
, option
= p
->options
;
2554 strcpy(attrptr
, option
->name
);
2555 attrptr
+= strlen(attrptr
);
2561 for (valptr
= option
->value
; *valptr
; valptr
++)
2563 if (strchr(" \"\'\\", *valptr
))
2566 *attrptr
++ = *valptr
;
2571 if (p
->num_auth_info_required
> 0)
2573 strcpy(attrptr
, "auth-info-required");
2576 for (i
= 0; i
< p
->num_auth_info_required
; i
++)
2578 *attrptr
++ = i
? ',' : '=';
2579 strcpy(attrptr
, p
->auth_info_required
[i
]);
2580 attrptr
+= strlen(attrptr
);
2589 * Populate the document-format-supported attribute...
2592 add_printer_formats(p
);
2594 DEBUG_printf(("cupsdSetPrinterAttrs: leaving name = %s, type = %x\n", p
->name
,
2598 * Add name-default attributes...
2601 add_printer_defaults(p
);
2605 * Write the IRIX printer config and status files...
2608 write_irix_config(p
);
2609 write_irix_state(p
);
2613 * Let the browse protocols reflect the change
2616 cupsdRegisterPrinter(p
);
2621 * 'cupsdSetPrinterReasons()' - Set/update the reasons strings.
2625 cupsdSetPrinterReasons(
2626 cupsd_printer_t
*p
, /* I - Printer */
2627 const char *s
) /* I - Reasons strings */
2629 int i
; /* Looping var */
2630 const char *sptr
; /* Pointer into reasons */
2631 char reason
[255], /* Reason string */
2632 *rptr
; /* Pointer into reason */
2635 if (s
[0] == '-' || s
[0] == '+')
2638 * Add/remove reasons...
2646 * Replace reasons...
2651 for (i
= 0; i
< p
->num_reasons
; i
++)
2652 free(p
->reasons
[i
]);
2657 if (!strcmp(s
, "none"))
2661 * Loop through all of the reasons...
2667 * Skip leading whitespace and commas...
2670 while (isspace(*sptr
& 255) || *sptr
== ',')
2673 for (rptr
= reason
; *sptr
&& !isspace(*sptr
& 255) && *sptr
!= ','; sptr
++)
2674 if (rptr
< (reason
+ sizeof(reason
) - 1))
2688 for (i
= 0; i
< p
->num_reasons
; i
++)
2689 if (!strcasecmp(reason
, p
->reasons
[i
]))
2692 * Found a match, so remove it...
2696 free(p
->reasons
[i
]);
2698 if (i
< p
->num_reasons
)
2699 memmove(p
->reasons
+ i
, p
->reasons
+ i
+ 1,
2700 (p
->num_reasons
- i
) * sizeof(char *));
2704 if (!strcmp(reason
, "paused") && p
->state
== IPP_PRINTER_STOPPED
)
2705 cupsdSetPrinterState(p
, IPP_PRINTER_IDLE
, 1);
2708 else if (p
->num_reasons
< (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
2714 for (i
= 0; i
< p
->num_reasons
; i
++)
2715 if (!strcasecmp(reason
, p
->reasons
[i
]))
2718 if (i
>= p
->num_reasons
)
2720 p
->reasons
[i
] = strdup(reason
);
2723 if (!strcmp(reason
, "paused") && p
->state
!= IPP_PRINTER_STOPPED
)
2724 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, 1);
2732 * 'cupsdSetPrinterState()' - Update the current state of a printer.
2736 cupsdSetPrinterState(
2737 cupsd_printer_t
*p
, /* I - Printer to change */
2738 ipp_pstate_t s
, /* I - New state */
2739 int update
) /* I - Update printers.conf? */
2741 ipp_pstate_t old_state
; /* Old printer state */
2745 * Can't set status of remote printers...
2748 if (p
->type
& CUPS_PRINTER_DISCOVERED
)
2752 * Set the new state...
2755 old_state
= p
->state
;
2760 cupsdAddEvent(s
== IPP_PRINTER_STOPPED
? CUPSD_EVENT_PRINTER_STOPPED
:
2761 CUPSD_EVENT_PRINTER_STATE
, p
, NULL
,
2762 "%s \"%s\" state changed.",
2763 (p
->type
& CUPS_PRINTER_CLASS
) ? "Class" : "Printer",
2767 * Let the browse code know this needs to be updated...
2771 p
->state_time
= time(NULL
);
2775 write_irix_state(p
);
2779 cupsdAddPrinterHistory(p
);
2782 * Let the browse protocols reflect the change...
2785 cupsdRegisterPrinter(p
);
2788 * Save the printer configuration if a printer goes from idle or processing
2789 * to stopped (or visa-versa)...
2792 if ((old_state
== IPP_PRINTER_STOPPED
) != (s
== IPP_PRINTER_STOPPED
) &&
2795 if (p
->type
& CUPS_PRINTER_CLASS
)
2796 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
2798 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
2804 * 'cupsdStopPrinter()' - Stop a printer from printing any jobs...
2808 cupsdStopPrinter(cupsd_printer_t
*p
, /* I - Printer to stop */
2809 int update
)/* I - Update printers.conf? */
2811 cupsd_job_t
*job
; /* Active print job */
2815 * Set the printer state...
2818 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, update
);
2821 * See if we have a job printing on this printer...
2827 * Get pointer to job...
2830 job
= (cupsd_job_t
*)p
->job
;
2836 cupsdStopJob(job
, 0);
2839 * Reset the state to pending...
2842 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
2843 job
->state_value
= IPP_JOB_PENDING
;
2846 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
2848 cupsdAddEvent(CUPSD_EVENT_JOB_STOPPED
, p
, job
,
2849 "Job stopped due to printer being paused");
2855 * 'cupsdUpdatePrinters()' - Update printers after a partial reload.
2859 cupsdUpdatePrinters(void)
2861 cupsd_printer_t
*p
; /* Current printer */
2865 * Loop through the printers and recreate the printer attributes
2866 * for any local printers since the policy and/or access control
2867 * stuff may have changed. Also, if browsing is disabled, remove
2868 * any remote printers...
2871 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
2873 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
2876 * Remove remote printers if we are no longer browsing...
2880 (p
->type
& (CUPS_PRINTER_IMPLICIT
| CUPS_PRINTER_DISCOVERED
)))
2882 if (p
->type
& CUPS_PRINTER_IMPLICIT
)
2883 cupsArrayRemove(ImplicitPrinters
, p
);
2885 cupsArraySave(Printers
);
2886 cupsdDeletePrinter(p
, 0);
2887 cupsArrayRestore(Printers
);
2892 * Update the operation policy pointer...
2895 if ((p
->op_policy_ptr
= cupsdFindPolicy(p
->op_policy
)) == NULL
)
2896 p
->op_policy_ptr
= DefaultPolicyPtr
;
2899 * Update printer attributes as needed...
2902 if (!(p
->type
& CUPS_PRINTER_DISCOVERED
))
2903 cupsdSetPrinterAttrs(p
);
2909 * 'cupsdValidateDest()' - Validate a printer/class destination.
2912 const char * /* O - Printer or class name */
2914 const char *uri
, /* I - Printer URI */
2915 cups_ptype_t
*dtype
, /* O - Type (printer or class) */
2916 cupsd_printer_t
**printer
) /* O - Printer pointer */
2918 cupsd_printer_t
*p
; /* Current printer */
2919 char localname
[1024],/* Localized hostname */
2920 *lptr
, /* Pointer into localized hostname */
2921 *sptr
, /* Pointer into server name */
2922 *rptr
, /* Pointer into resource */
2923 scheme
[32], /* Scheme portion of URI */
2924 username
[64], /* Username portion of URI */
2925 hostname
[HTTP_MAX_HOST
],
2926 /* Host portion of URI */
2927 resource
[HTTP_MAX_URI
];
2928 /* Resource portion of URI */
2929 int port
; /* Port portion of URI */
2932 DEBUG_printf(("cupsdValidateDest(uri=\"%s\", dtype=%p, printer=%p)\n", uri
,
2936 * Initialize return values...
2943 *dtype
= (cups_ptype_t
)0;
2946 * Pull the hostname and resource from the URI...
2949 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
, scheme
, sizeof(scheme
),
2950 username
, sizeof(username
), hostname
, sizeof(hostname
),
2951 &port
, resource
, sizeof(resource
));
2954 * See if the resource is a class or printer...
2957 if (!strncmp(resource
, "/classes/", 9))
2963 rptr
= resource
+ 9;
2965 else if (!strncmp(resource
, "/printers/", 10))
2971 rptr
= resource
+ 10;
2976 * Bad resource name...
2983 * See if the printer or class name exists...
2986 p
= cupsdFindDest(rptr
);
2988 if (p
== NULL
&& strchr(rptr
, '@') == NULL
)
2996 *dtype
= p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
|
2997 CUPS_PRINTER_REMOTE
| CUPS_PRINTER_DISCOVERED
);
3003 * Change localhost to the server name...
3006 if (!strcasecmp(hostname
, "localhost"))
3007 strlcpy(hostname
, ServerName
, sizeof(hostname
));
3009 strlcpy(localname
, hostname
, sizeof(localname
));
3011 if (!strcasecmp(hostname
, ServerName
))
3014 * Localize the hostname...
3017 lptr
= strchr(localname
, '.');
3018 sptr
= strchr(ServerName
, '.');
3020 if (sptr
!= NULL
&& lptr
!= NULL
)
3023 * Strip the common domain name components...
3026 while (lptr
!= NULL
)
3028 if (!strcasecmp(lptr
, sptr
))
3034 lptr
= strchr(lptr
+ 1, '.');
3039 DEBUG_printf(("localized hostname is \"%s\"...\n", localname
));
3042 * Find a matching printer or class...
3045 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3047 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3048 if (!strcasecmp(p
->hostname
, localname
) &&
3049 !strcasecmp(p
->name
, rptr
))
3055 *dtype
= p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
|
3056 CUPS_PRINTER_REMOTE
| CUPS_PRINTER_DISCOVERED
);
3066 * 'cupsdWritePrintcap()' - Write a pseudo-printcap file for older applications
3071 cupsdWritePrintcap(void)
3073 cups_file_t
*fp
; /* printcap file */
3074 cupsd_printer_t
*p
; /* Current printer */
3079 * Update the IRIX printer state for the default printer; if
3080 * no printers remain, then the default printer file will be
3084 write_irix_state(DefaultPrinter
);
3088 * See if we have a printcap file; if not, don't bother writing it.
3091 if (!Printcap
|| !*Printcap
)
3095 * Open the printcap file...
3098 if ((fp
= cupsFileOpen(Printcap
, "w")) == NULL
)
3102 * Put a comment header at the top so that users will know where the
3103 * data has come from...
3107 "# This file was automatically generated by cupsd(8) from the\n");
3108 cupsFilePrintf(fp
, "# %s/printers.conf file. All changes to this file\n",
3110 cupsFilePuts(fp
, "# will be lost.\n");
3115 * Write a new printcap with the current list of printers.
3118 switch (PrintcapFormat
)
3122 * Each printer is put in the file as:
3132 cupsFilePrintf(fp
, "%s|%s:rm=%s:rp=%s:\n", DefaultPrinter
->name
,
3133 DefaultPrinter
->info
, ServerName
,
3134 DefaultPrinter
->name
);
3136 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3138 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3139 if (p
!= DefaultPrinter
)
3140 cupsFilePrintf(fp
, "%s|%s:rm=%s:rp=%s:\n", p
->name
, p
->info
,
3141 ServerName
, p
->name
);
3144 case PRINTCAP_SOLARIS
:
3146 * Each printer is put in the file as:
3148 * _all:all=Printer1,Printer2,Printer3,...,PrinterN
3149 * _default:use=DefaultPrinter
3151 * :bsdaddr=ServerName,Printer1:\
3152 * :description=Description:
3154 * :bsdaddr=ServerName,Printer2:\
3155 * :description=Description:
3157 * :bsdaddr=ServerName,Printer3:\
3158 * :description=Description:
3161 * :bsdaddr=ServerName,PrinterN:\
3162 * :description=Description:
3165 cupsFilePuts(fp
, "_all:all=");
3166 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3168 p
= (cupsd_printer_t
*)cupsArrayCurrent(Printers
))
3169 cupsFilePrintf(fp
, "%s%c", p
->name
,
3170 cupsArrayNext(Printers
) ? ',' : '\n');
3173 cupsFilePrintf(fp
, "_default:use=%s\n", DefaultPrinter
->name
);
3175 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3177 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3178 cupsFilePrintf(fp
, "%s:\\\n"
3179 "\t:bsdaddr=%s,%s:\\\n"
3180 "\t:description=%s:\n",
3181 p
->name
, ServerName
, p
->name
,
3182 p
->info
? p
->info
: "");
3196 * 'cupsdSanitizeURI()' - Sanitize a device URI...
3199 char * /* O - New device URI */
3200 cupsdSanitizeURI(const char *uri
, /* I - Original device URI */
3201 char *buffer
, /* O - New device URI */
3202 int buflen
) /* I - Size of new device URI buffer */
3204 char *start
, /* Start of data after scheme */
3205 *slash
, /* First slash after scheme:// */
3206 *ptr
; /* Pointer into user@host:port part */
3210 * Range check input...
3213 if (!uri
|| !buffer
|| buflen
< 2)
3217 * Copy the device URI to the new buffer...
3220 strlcpy(buffer
, uri
, buflen
);
3223 * Find the end of the scheme:// part...
3226 if ((ptr
= strchr(buffer
, ':')) == NULL
)
3227 return (buffer
); /* No scheme: part... */
3229 for (start
= ptr
+ 1; *start
; start
++)
3234 * Find the next slash (/) in the URI...
3237 if ((slash
= strchr(start
, '/')) == NULL
)
3238 slash
= start
+ strlen(start
); /* No slash, point to the end */
3241 * Check for an @ sign before the slash...
3244 if ((ptr
= strchr(start
, '@')) != NULL
&& ptr
< slash
)
3247 * Found an @ sign and it is before the resource part, so we have
3248 * an authentication string. Copy the remaining URI over the
3249 * authentication string...
3252 _cups_strcpy(start
, ptr
+ 1);
3256 * Return the new device URI...
3264 * 'add_printer_defaults()' - Add name-default attributes to the printer attributes.
3268 add_printer_defaults(cupsd_printer_t
*p
)/* I - Printer */
3270 int i
; /* Looping var */
3271 int num_options
; /* Number of default options */
3272 cups_option_t
*options
, /* Default options */
3273 *option
; /* Current option */
3274 char name
[256]; /* name-default */
3278 * Maintain a common array of default attribute names...
3281 if (!CommonDefaults
)
3283 CommonDefaults
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
3285 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("copies-default"));
3286 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("document-format-default"));
3287 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("finishings-default"));
3288 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-hold-until-default"));
3289 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-priority-default"));
3290 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-sheets-default"));
3291 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("media-default"));
3292 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("number-up-default"));
3293 cupsArrayAdd(CommonDefaults
,
3294 _cupsStrAlloc("orientation-requested-default"));
3295 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("sides-default"));
3299 * Add all of the default options from the .conf files...
3302 for (num_options
= 0, i
= p
->num_options
, option
= p
->options
;
3306 if (strcmp(option
->name
, "ipp-options") &&
3307 strcmp(option
->name
, "job-sheets") &&
3308 strcmp(option
->name
, "lease-duration"))
3310 snprintf(name
, sizeof(name
), "%s-default", option
->name
);
3311 num_options
= cupsAddOption(name
, option
->value
, num_options
, &options
);
3313 if (!cupsArrayFind(CommonDefaults
, name
))
3314 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc(name
));
3319 * Convert options to IPP attributes...
3322 cupsEncodeOptions2(p
->attrs
, num_options
, options
, IPP_TAG_PRINTER
);
3323 cupsFreeOptions(num_options
, options
);
3326 * Add standard -default attributes as needed...
3329 if (!cupsGetOption("copies", p
->num_options
, p
->options
))
3330 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
, "copies-default",
3333 if (!cupsGetOption("document-format", p
->num_options
, p
->options
))
3334 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_MIMETYPE
,
3335 "document-format-default", NULL
, "application/octet-stream");
3337 if (!cupsGetOption("job-hold-until", p
->num_options
, p
->options
))
3338 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3339 "job-hold-until-default", NULL
, "no-hold");
3341 if (!cupsGetOption("job-priority", p
->num_options
, p
->options
))
3342 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3343 "job-priority-default", 50);
3345 if (!cupsGetOption("number-up", p
->num_options
, p
->options
))
3346 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3347 "number-up-default", 1);
3349 if (!cupsGetOption("orientation-requested", p
->num_options
, p
->options
))
3350 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NOVALUE
,
3351 "orientation-requested-default", NULL
, NULL
);
3353 if (!cupsGetOption("notify-lease-duration", p
->num_options
, p
->options
))
3354 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3355 "notify-lease-duration-default", DefaultLeaseDuration
);
3357 if (!cupsGetOption("notify-events", p
->num_options
, p
->options
))
3358 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3359 "notify-events-default", NULL
, "job-completed");
3364 * 'add_printer_filter()' - Add a MIME filter for a printer.
3369 cupsd_printer_t
*p
, /* I - Printer to add to */
3370 mime_type_t
*filtertype
, /* I - Filter or prefilter MIME type */
3371 const char *filter
) /* I - Filter to add */
3373 char super
[MIME_MAX_SUPER
], /* Super-type for filter */
3374 type
[MIME_MAX_TYPE
], /* Type for filter */
3375 program
[1024]; /* Program/filter name */
3376 int cost
; /* Cost of filter */
3377 mime_type_t
*temptype
; /* MIME type looping var */
3378 char filename
[1024]; /* Full filter filename */
3382 * Parse the filter string; it should be in the following format:
3384 * super/type cost program
3387 if (sscanf(filter
, "%15[^/]/%31s%d%1023s", super
, type
, &cost
, program
) != 4)
3389 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: invalid filter string \"%s\"!",
3395 * See if the filter program exists; if not, stop the printer and flag
3399 if (strcmp(program
, "-"))
3401 if (program
[0] == '/')
3402 strlcpy(filename
, program
, sizeof(filename
));
3404 snprintf(filename
, sizeof(filename
), "%s/filter/%s", ServerBin
, program
);
3406 if (access(filename
, X_OK
))
3408 snprintf(p
->state_message
, sizeof(p
->state_message
),
3409 "Filter \"%s\" for printer \"%s\" not available: %s",
3410 program
, p
->name
, strerror(errno
));
3411 cupsdSetPrinterReasons(p
, "+cups-missing-filter-error");
3412 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, 0);
3414 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s", p
->state_message
);
3419 * Mark the CUPS_PRINTER_COMMANDS bit if we have a filter for
3420 * application/vnd.cups-command...
3423 if (!strcasecmp(super
, "application") &&
3424 !strcasecmp(type
, "vnd.cups-command"))
3425 p
->type
|= CUPS_PRINTER_COMMANDS
;
3428 * Add the filter to the MIME database, supporting wildcards as needed...
3431 for (temptype
= mimeFirstType(MimeDatabase
);
3433 temptype
= mimeNextType(MimeDatabase
))
3434 if (((super
[0] == '*' && strcasecmp(temptype
->super
, "printer")) ||
3435 !strcasecmp(temptype
->super
, super
)) &&
3436 (type
[0] == '*' || !strcasecmp(temptype
->type
, type
)))
3438 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3439 "add_printer_filter: %s: adding filter %s/%s %s/%s %d %s",
3440 p
->name
, temptype
->super
, temptype
->type
,
3441 filtertype
->super
, filtertype
->type
,
3443 mimeAddFilter(MimeDatabase
, temptype
, filtertype
, cost
, program
);
3449 * 'add_printer_formats()' - Add document-format-supported values for a printer.
3453 add_printer_formats(cupsd_printer_t
*p
) /* I - Printer */
3455 int i
; /* Looping var */
3456 mime_type_t
*type
; /* Current MIME type */
3457 cups_array_t
*filters
; /* Filters */
3458 ipp_attribute_t
*attr
; /* document-format-supported attribute */
3459 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
3460 /* MIME type name */
3464 * Raw (and remote) queues advertise all of the supported MIME
3468 cupsArrayDelete(p
->filetypes
);
3469 p
->filetypes
= NULL
;
3473 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
,
3474 (ipp_tag_t
)(IPP_TAG_MIMETYPE
| IPP_TAG_COPY
),
3475 "document-format-supported", NumMimeTypes
, NULL
, MimeTypes
);
3480 * Otherwise, loop through the supported MIME types and see if there
3481 * are filters for them...
3484 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_printer_formats: %d types, %d filters",
3485 mimeNumTypes(MimeDatabase
), mimeNumFilters(MimeDatabase
));
3487 p
->filetypes
= cupsArrayNew(NULL
, NULL
);
3489 for (type
= mimeFirstType(MimeDatabase
);
3491 type
= mimeNextType(MimeDatabase
))
3493 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
3495 if ((filters
= mimeFilter(MimeDatabase
, type
, p
->filetype
, NULL
)) != NULL
)
3497 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3498 "add_printer_formats: %s: %s needs %d filters",
3499 p
->name
, mimetype
, cupsArrayCount(filters
));
3501 cupsArrayDelete(filters
);
3502 cupsArrayAdd(p
->filetypes
, type
);
3505 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3506 "add_printer_formats: %s: %s not supported",
3510 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3511 "add_printer_formats: %s: %d supported types",
3512 p
->name
, cupsArrayCount(p
->filetypes
) + 1);
3515 * Add the file formats that can be filtered...
3518 if ((type
= mimeType(MimeDatabase
, "application", "octet-stream")) == NULL
||
3519 !cupsArrayFind(p
->filetypes
, type
))
3524 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_MIMETYPE
,
3525 "document-format-supported",
3526 cupsArrayCount(p
->filetypes
) + 1, NULL
, NULL
);
3529 attr
->values
[0].string
.text
= _cupsStrAlloc("application/octet-stream");
3531 for (type
= (mime_type_t
*)cupsArrayFirst(p
->filetypes
);
3533 i
++, type
= (mime_type_t
*)cupsArrayNext(p
->filetypes
))
3535 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
3537 attr
->values
[i
].string
.text
= _cupsStrAlloc(mimetype
);
3542 char pdl
[1024]; /* Buffer to build pdl list */
3543 mime_filter_t
*filter
; /* MIME filter looping var */
3548 if (mimeType(MimeDatabase
, "application", "pdf"))
3549 strlcat(pdl
, "application/pdf,", sizeof(pdl
));
3551 if (mimeType(MimeDatabase
, "application", "postscript"))
3552 strlcat(pdl
, "application/postscript,", sizeof(pdl
));
3554 if (mimeType(MimeDatabase
, "application", "vnd.cups-raster"))
3555 strlcat(pdl
, "application/vnd.cups-raster,", sizeof(pdl
));
3558 * Determine if this is a Tioga PrintJobMgr based queue...
3561 for (filter
= (mime_filter_t
*)cupsArrayFirst(MimeDatabase
->filters
);
3563 filter
= (mime_filter_t
*)cupsArrayNext(MimeDatabase
->filters
))
3565 if (filter
->dst
== p
->filetype
&& filter
->filter
&&
3566 strstr(filter
->filter
, "PrintJobMgr"))
3571 * We only support raw printing if this is not a Tioga PrintJobMgr based
3572 * queue and if application/octet-stream is a known conversion...
3575 if (!filter
&& mimeType(MimeDatabase
, "application", "octet-stream"))
3576 strlcat(pdl
, "application/octet-stream,", sizeof(pdl
));
3578 if (mimeType(MimeDatabase
, "image", "png"))
3579 strlcat(pdl
, "image/png,", sizeof(pdl
));
3582 pdl
[strlen(pdl
) - 1] = '\0'; /* Remove trailing comma */
3584 cupsdSetString(&p
->pdl
, pdl
);
3586 #endif /* HAVE_DNSSD */
3591 * 'compare_printers()' - Compare two printers.
3594 static int /* O - Result of comparison */
3595 compare_printers(void *first
, /* I - First printer */
3596 void *second
, /* I - Second printer */
3597 void *data
) /* I - App data (not used) */
3599 return (strcasecmp(((cupsd_printer_t
*)first
)->name
,
3600 ((cupsd_printer_t
*)second
)->name
));
3605 * 'delete_printer_filters()' - Delete all MIME filters for a printer.
3609 delete_printer_filters(
3610 cupsd_printer_t
*p
) /* I - Printer to remove from */
3612 mime_filter_t
*filter
; /* MIME filter looping var */
3616 * Range check input...
3623 * Remove all filters from the MIME database that have a destination
3624 * type == printer...
3627 for (filter
= mimeFirstFilter(MimeDatabase
);
3629 filter
= mimeNextFilter(MimeDatabase
))
3630 if (filter
->dst
== p
->filetype
)
3633 * Delete the current filter...
3636 mimeDeleteFilter(MimeDatabase
, filter
);
3643 * 'write_irix_config()' - Update the config files used by the IRIX
3648 write_irix_config(cupsd_printer_t
*p
) /* I - Printer to update */
3650 char filename
[1024]; /* Interface script filename */
3651 cups_file_t
*fp
; /* Interface script file */
3652 ipp_attribute_t
*attr
; /* Attribute data */
3656 * Add dummy interface and GUI scripts to fool SGI's "challenged" printing
3657 * tools. First the interface script that tells the tools what kind of
3658 * printer we have...
3661 snprintf(filename
, sizeof(filename
), "/var/spool/lp/interface/%s", p
->name
);
3663 if (p
->type
& CUPS_PRINTER_CLASS
)
3665 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
3667 cupsFilePuts(fp
, "#!/bin/sh\n");
3669 if ((attr
= ippFindAttribute(p
->attrs
, "printer-make-and-model",
3670 IPP_TAG_TEXT
)) != NULL
)
3671 cupsFilePrintf(fp
, "NAME=\"%s\"\n", attr
->values
[0].string
.text
);
3672 else if (p
->type
& CUPS_PRINTER_CLASS
)
3673 cupsFilePuts(fp
, "NAME=\"Printer Class\"\n");
3675 cupsFilePuts(fp
, "NAME=\"Remote Destination\"\n");
3677 if (p
->type
& CUPS_PRINTER_COLOR
)
3678 cupsFilePuts(fp
, "TYPE=ColorPostScript\n");
3680 cupsFilePuts(fp
, "TYPE=MonoPostScript\n");
3682 cupsFilePrintf(fp
, "HOSTNAME=%s\n", ServerName
);
3683 cupsFilePrintf(fp
, "HOSTPRINTER=%s\n", p
->name
);
3687 chmod(filename
, 0755);
3688 chown(filename
, User
, Group
);
3692 * Then the member file that tells which device file the queue is connected
3693 * to... Networked printers use "/dev/null" in this file, so that's what
3694 * we use (the actual device URI can confuse some apps...)
3697 snprintf(filename
, sizeof(filename
), "/var/spool/lp/member/%s", p
->name
);
3699 if (p
->type
& CUPS_PRINTER_CLASS
)
3701 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
3703 cupsFilePuts(fp
, "/dev/null\n");
3707 chmod(filename
, 0644);
3708 chown(filename
, User
, Group
);
3712 * The gui_interface file is a script or program that launches a GUI
3713 * option panel for the printer, using options specified on the
3714 * command-line in the third argument. The option panel must send
3715 * any printing options to stdout on a single line when the user
3716 * accepts them, or nothing if the user cancels the dialog.
3718 * The default options panel program is /usr/bin/glpoptions, from
3719 * the ESP Print Pro software. You can select another using the
3720 * PrintcapGUI option.
3723 snprintf(filename
, sizeof(filename
), "/var/spool/lp/gui_interface/ELF/%s.gui", p
->name
);
3725 if (p
->type
& CUPS_PRINTER_CLASS
)
3727 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
3729 cupsFilePuts(fp
, "#!/bin/sh\n");
3730 cupsFilePrintf(fp
, "%s -d %s -o \"$3\"\n", PrintcapGUI
, p
->name
);
3734 chmod(filename
, 0755);
3735 chown(filename
, User
, Group
);
3739 * The POD config file is needed by the printstatus command to show
3740 * the printer location and device.
3743 snprintf(filename
, sizeof(filename
), "/var/spool/lp/pod/%s.config", p
->name
);
3745 if (p
->type
& CUPS_PRINTER_CLASS
)
3747 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
3749 cupsFilePrintf(fp
, "Printer Class | %s\n",
3750 (p
->type
& CUPS_PRINTER_COLOR
) ? "ColorPostScript" : "MonoPostScript");
3751 cupsFilePrintf(fp
, "Printer Model | %s\n", p
->make_model
? p
->make_model
: "");
3752 cupsFilePrintf(fp
, "Location Code | %s\n", p
->location
? p
->location
: "");
3753 cupsFilePrintf(fp
, "Physical Location | %s\n", p
->info
? p
->info
: "");
3754 cupsFilePrintf(fp
, "Port Path | %s\n", p
->device_uri
? p
->device_uri
: "");
3755 cupsFilePrintf(fp
, "Config Path | /var/spool/lp/pod/%s.config\n", p
->name
);
3756 cupsFilePrintf(fp
, "Active Status Path | /var/spool/lp/pod/%s.status\n", p
->name
);
3757 cupsFilePuts(fp
, "Status Update Wait | 10 seconds\n");
3761 chmod(filename
, 0664);
3762 chown(filename
, User
, Group
);
3768 * 'write_irix_state()' - Update the status files used by IRIX printing
3773 write_irix_state(cupsd_printer_t
*p
) /* I - Printer to update */
3775 char filename
[1024]; /* Interface script filename */
3776 cups_file_t
*fp
; /* Interface script file */
3777 int tag
; /* Status tag value */
3783 * The POD status file is needed for the printstatus window to
3784 * provide the current status of the printer.
3787 snprintf(filename
, sizeof(filename
), "/var/spool/lp/pod/%s.status", p
->name
);
3789 if (p
->type
& CUPS_PRINTER_CLASS
)
3791 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
3793 cupsFilePrintf(fp
, "Operational Status | %s\n",
3794 (p
->state
== IPP_PRINTER_IDLE
) ? "Idle" :
3795 (p
->state
== IPP_PRINTER_PROCESSING
) ? "Busy" :
3797 cupsFilePrintf(fp
, "Information | 01 00 00 | %s\n", CUPS_SVERSION
);
3798 cupsFilePrintf(fp
, "Information | 02 00 00 | Device URI: %s\n",
3799 p
->device_uri
? p
->device_uri
: "");
3800 cupsFilePrintf(fp
, "Information | 03 00 00 | %s jobs\n",
3801 p
->accepting
? "Accepting" : "Not accepting");
3802 cupsFilePrintf(fp
, "Information | 04 00 00 | %s\n", p
->state_message
);
3806 chmod(filename
, 0664);
3807 chown(filename
, User
, Group
);
3811 * The activeicons file is needed to provide desktop icons for printers:
3813 * [ quoted from /usr/lib/print/tagit ]
3815 * --- Type of printer tags (base values)
3817 * Dumb=66048 # 0x10200
3818 * DumbColor=66080 # 0x10220
3819 * Raster=66112 # 0x10240
3820 * ColorRaster=66144 # 0x10260
3821 * Plotter=66176 # 0x10280
3822 * PostScript=66208 # 0x102A0
3823 * ColorPostScript=66240 # 0x102C0
3824 * MonoPostScript=66272 # 0x102E0
3826 * --- Printer state modifiers for local printers
3831 * Unknown=3 # 0x3 (Faulted due to unknown reason)
3833 * --- Printer state modifiers for network printers
3837 * NetFaulted=10 # 0xA
3838 * NetUnknown=11 # 0xB (Faulted due to unknown reason)
3841 snprintf(filename
, sizeof(filename
), "/var/spool/lp/activeicons/%s", p
->name
);
3843 if (p
->type
& CUPS_PRINTER_CLASS
)
3845 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
3847 if (p
->type
& CUPS_PRINTER_COLOR
)
3852 if (p
->type
& CUPS_PRINTER_REMOTE
)
3855 if (p
->state
== IPP_PRINTER_PROCESSING
)
3858 else if (p
->state
== IPP_PRINTER_STOPPED
)
3861 cupsFilePuts(fp
, "#!/bin/sh\n");
3862 cupsFilePrintf(fp
, "#Tag %d\n", tag
);
3866 chmod(filename
, 0755);
3867 chown(filename
, User
, Group
);
3872 * The default file is needed by the printers window to show
3873 * the default printer.
3876 snprintf(filename
, sizeof(filename
), "/var/spool/lp/default");
3878 if (DefaultPrinter
!= NULL
)
3880 if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
3882 cupsFilePrintf(fp
, "%s\n", DefaultPrinter
->name
);
3886 chmod(filename
, 0644);
3887 chown(filename
, User
, Group
);
3897 * End of "$Id: printers.c 6970 2007-09-17 23:58:28Z mike $".