2 * "$Id: printers.c 5047 2006-02-02 05:14:15Z mike $"
4 * Printer routines for the Common UNIX Printing System (CUPS).
6 * Copyright 1997-2006 by Easy Software Products, all rights reserved.
8 * These coded instructions, statements, and computer programs are the
9 * property of Easy Software Products and are protected by Federal
10 * copyright law. Distribution and use rights are outlined in the file
11 * "LICENSE.txt" which should have been included with this file. If this
12 * file is missing or damaged please contact Easy Software Products
15 * Attn: CUPS Licensing Information
16 * Easy Software Products
17 * 44141 Airport View Drive, Suite 204
18 * Hollywood, Maryland 20636 USA
20 * Voice: (301) 373-9600
21 * EMail: cups-info@cups.org
22 * WWW: http://www.cups.org
26 * cupsdAddPrinter() - Add a printer to the system.
27 * cupsdAddPrinterFilter() - Add a MIME filter for a printer.
28 * cupsdAddPrinterHistory() - Add the current printer state to the history.
29 * cupsdAddPrinterUser() - Add a user to the ACL.
30 * cupsdDeleteAllPrinters() - Delete all printers from the system.
31 * cupsdDeletePrinter() - Delete a printer from the system.
32 * cupsdDeletePrinterFilters() - Delete all MIME filters for a printer.
33 * cupsdFindPrinter() - Find a printer in the list.
34 * cupsdFreePrinterUsers() - Free allow/deny users.
35 * cupsdLoadAllPrinters() - Load printers from the printers.conf file.
36 * cupsdSaveAllPrinters() - Save all printer definitions to the
38 * cupsdSetPrinterAttrs() - Set printer attributes based upon the PPD
40 * cupsdSetPrinterReasons() - Set/update the reasons strings.
41 * cupsdSetPrinterState() - Update the current state of a printer.
42 * cupsdStopPrinter() - Stop a printer from printing any jobs...
43 * cupsdUpdatePrinters() - Update printers after a partial reload.
44 * cupsdValidateDest() - Validate a printer/class destination.
45 * cupsdWritePrintcap() - Write a pseudo-printcap file for older
46 * applications that need it...
47 * cupsdSanitizeURI() - Sanitize a device URI...
48 * compare_printers() - Compare two printers.
49 * write_irix_config() - Update the config files used by the IRIX
51 * write_irix_state() - Update the status files used by IRIX
52 * printing desktop tools.
56 * Include necessary headers...
66 static int compare_printers(void *first
, void *second
, void *data
);
68 static void write_irix_config(cupsd_printer_t
*p
);
69 static void write_irix_state(cupsd_printer_t
*p
);
74 * 'cupsdAddPrinter()' - Add a printer to the system.
77 cupsd_printer_t
* /* O - New printer */
78 cupsdAddPrinter(const char *name
) /* I - Name of printer */
80 cupsd_printer_t
*p
; /* New printer */
84 * Range check input...
87 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdAddPrinter(\"%s\")", name
);
90 * Create a new printer entity...
93 if ((p
= calloc(1, sizeof(cupsd_printer_t
))) == NULL
)
95 cupsdLogMessage(CUPSD_LOG_CRIT
, "Unable to allocate memory for printer - %s",
100 cupsdSetString(&p
->name
, name
);
101 cupsdSetString(&p
->info
, name
);
102 cupsdSetString(&p
->hostname
, ServerName
);
104 cupsdSetStringf(&p
->uri
, "ipp://%s:%d/printers/%s", ServerName
, LocalPort
, name
);
105 cupsdSetStringf(&p
->device_uri
, "file:/dev/null");
107 p
->state
= IPP_PRINTER_STOPPED
;
108 p
->state_time
= time(NULL
);
110 p
->shared
= DefaultShared
;
111 p
->filetype
= mimeAddType(MimeDatabase
, "printer", name
);
113 cupsdSetString(&p
->job_sheets
[0], "none");
114 cupsdSetString(&p
->job_sheets
[1], "none");
116 cupsdSetString(&p
->error_policy
, "stop-printer");
117 cupsdSetString(&p
->op_policy
, DefaultPolicy
);
119 p
->op_policy_ptr
= DefaultPolicyPtr
;
121 if (MaxPrinterHistory
)
122 p
->history
= calloc(MaxPrinterHistory
, sizeof(ipp_t
*));
125 * Insert the printer in the printer list alphabetically...
129 Printers
= cupsArrayNew(compare_printers
, NULL
);
131 cupsArrayAdd(Printers
, p
);
133 if (!ImplicitPrinters
)
134 ImplicitPrinters
= cupsArrayNew(compare_printers
, NULL
);
137 * Return the new printer...
145 * 'cupsdAddPrinterFilter()' - Add a MIME filter for a printer.
149 cupsdAddPrinterFilter(
150 cupsd_printer_t
*p
, /* I - Printer to add to */
151 const char *filter
) /* I - Filter to add */
153 char super
[MIME_MAX_SUPER
], /* Super-type for filter */
154 type
[MIME_MAX_TYPE
], /* Type for filter */
155 program
[1024]; /* Program/filter name */
156 int cost
; /* Cost of filter */
157 mime_type_t
*temptype
; /* MIME type looping var */
161 * Range check input...
164 if (p
== NULL
|| p
->filetype
== NULL
|| filter
== NULL
)
168 * Parse the filter string; it should be in the following format:
170 * super/type cost program
173 if (sscanf(filter
, "%15[^/]/%31s%d%1023s", super
, type
, &cost
, program
) != 4)
175 cupsdLogMessage(CUPSD_LOG_ERROR
,
176 "cupsdAddPrinterFilter: Invalid filter string \"%s\"!",
182 * Add the filter to the MIME database, supporting wildcards as needed...
185 for (temptype
= mimeFirstType(MimeDatabase
);
187 temptype
= mimeNextType(MimeDatabase
))
188 if (((super
[0] == '*' && strcasecmp(temptype
->super
, "printer")) ||
189 !strcasecmp(temptype
->super
, super
)) &&
190 (type
[0] == '*' || !strcasecmp(temptype
->type
, type
)))
192 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "Adding filter %s/%s %s/%s %d %s",
193 temptype
->super
, temptype
->type
,
194 p
->filetype
->super
, p
->filetype
->type
,
196 mimeAddFilter(MimeDatabase
, temptype
, p
->filetype
, cost
, program
);
202 * 'cupsdAddPrinterHistory()' - Add the current printer state to the history.
206 cupsdAddPrinterHistory(
207 cupsd_printer_t
*p
) /* I - Printer */
209 ipp_t
*history
; /* History collection */
213 * Stop early if we aren't keeping history data...
216 if (MaxPrinterHistory
<= 0)
220 * Retire old history data as needed...
223 p
->sequence_number
++;
225 if (p
->num_history
>= MaxPrinterHistory
)
228 ippDelete(p
->history
[0]);
229 memmove(p
->history
, p
->history
+ 1, p
->num_history
* sizeof(ipp_t
*));
233 * Create a collection containing the current printer-state, printer-up-time,
234 * printer-state-message, and printer-state-reasons attributes.
238 ippAddInteger(history
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-state",
240 ippAddBoolean(history
, IPP_TAG_PRINTER
, "printer-is-accepting-jobs",
242 ippAddBoolean(history
, IPP_TAG_PRINTER
, "printer-is-shared", p
->shared
);
243 ippAddString(history
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-state-message",
244 NULL
, p
->state_message
);
247 ippAddString(history
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
248 "com.apple.print.recoverable-message", NULL
, p
->recoverable
);
249 #endif /* __APPLE__ */
250 if (p
->num_reasons
== 0)
251 ippAddString(history
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
252 "printer-state-reasons", NULL
,
253 p
->state
== IPP_PRINTER_STOPPED
? "paused" : "none");
255 ippAddStrings(history
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
256 "printer-state-reasons", p
->num_reasons
, NULL
,
257 (const char * const *)p
->reasons
);
258 ippAddInteger(history
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
259 "printer-state-change-time", p
->state_time
);
260 ippAddInteger(history
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
261 "printer-state-sequence-number", p
->sequence_number
);
263 p
->history
[p
->num_history
] = history
;
269 * 'cupsdAddPrinterUser()' - Add a user to the ACL.
274 cupsd_printer_t
*p
, /* I - Printer */
275 const char *username
) /* I - User */
277 const char **temp
; /* Temporary array pointer */
283 if (p
->num_users
== 0)
284 temp
= malloc(sizeof(char **));
286 temp
= realloc(p
->users
, sizeof(char **) * (p
->num_users
+ 1));
292 temp
+= p
->num_users
;
294 if ((*temp
= strdup(username
)) != NULL
)
300 * 'cupsdCreateCommonData()' - Create the common printer data.
304 cupsdCreateCommonData(void)
306 int i
; /* Looping var */
307 ipp_attribute_t
*attr
; /* Attribute data */
308 static const int nups
[] = /* number-up-supported values */
309 { 1, 2, 4, 6, 9, 16 };
310 static const ipp_orient_t orients
[4] =/* orientation-requested-supported values */
314 IPP_REVERSE_LANDSCAPE
,
317 static const char * const holds
[] = /* job-hold-until-supported values */
328 static const char * const versions
[] =/* ipp-versions-supported values */
333 static const ipp_op_t ops
[] = /* operations-supported values */
340 IPP_GET_JOB_ATTRIBUTES
,
342 IPP_GET_PRINTER_ATTRIBUTES
,
348 IPP_SET_JOB_ATTRIBUTES
,
349 IPP_CREATE_PRINTER_SUBSCRIPTION
,
350 IPP_CREATE_JOB_SUBSCRIPTION
,
351 IPP_GET_SUBSCRIPTION_ATTRIBUTES
,
352 IPP_GET_SUBSCRIPTIONS
,
353 IPP_RENEW_SUBSCRIPTION
,
354 IPP_CANCEL_SUBSCRIPTION
,
355 IPP_GET_NOTIFICATIONS
,
371 CUPS_AUTHENTICATE_JOB
,
374 static const char * const charsets
[] =/* charset-supported values */
379 static const char * const compressions
[] =
380 { /* document-compression-supported values */
384 #endif /* HAVE_LIBZ */
386 static const char * const multiple_document_handling
[] =
387 { /* multiple-document-handling-supported values */
388 "separate-documents-uncollated-copies",
389 "separate-documents-collated-copies"
391 static const char * const errors
[] = /* printer-error-policy-supported values */
397 static const char * const notify_attrs
[] =
398 { /* notify-attributes-supported values */
399 "printer-state-change-time",
400 "notify-lease-expiration-time",
401 "notify-subscriber-user-name"
403 static const char * const notify_events
[] =
404 { /* notify-events-supported values */
406 "job-config-changed",
413 "printer-config-changed",
415 "printer-finishings-changed",
416 "printer-media-changed",
420 "printer-state-changed",
430 ippDelete(CommonData
);
432 CommonData
= ippNew();
435 * This list of attributes is sorted to improve performance when the
436 * client provides a requested-attributes attribute...
439 /* charset-configured */
440 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_CHARSET
,
441 "charset-configured", NULL
, DefaultCharset
);
443 /* charset-supported */
444 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_CHARSET
,
445 "charset-supported", sizeof(charsets
) / sizeof(charsets
[0]),
448 /* compression-supported */
449 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
450 "compression-supported",
451 sizeof(compressions
) / sizeof(compressions
[0]),
454 /* TODO: move to printer-specific section! */
456 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
457 "copies-default", 1);
459 /* copies-supported */
460 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "copies-supported", 1, MaxCopies
);
462 /* TODO: move to printer-specific section! */
463 /* document-format-default */
464 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_MIMETYPE
,
465 "document-format-default", NULL
, "application/octet-stream");
467 /* document-format-supported */
468 ippAddStrings(CommonData
, IPP_TAG_PRINTER
,
469 (ipp_tag_t
)(IPP_TAG_MIMETYPE
| IPP_TAG_COPY
),
470 "document-format-supported", NumMimeTypes
, NULL
, MimeTypes
);
472 /* generated-natural-language-supported */
473 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_LANGUAGE
,
474 "generated-natural-language-supported", NULL
, DefaultLanguage
);
476 /* ipp-versions-supported */
477 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
478 "ipp-versions-supported", sizeof(versions
) / sizeof(versions
[0]),
481 /* TODO: move to printer-specific section! */
482 /* job-hold-until-default */
483 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
484 "job-hold-until-default", NULL
, "no-hold");
486 /* job-hold-until-supported */
487 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
488 "job-hold-until-supported", sizeof(holds
) / sizeof(holds
[0]),
491 /* TODO: move to printer-specific section! */
492 /* job-priority-default */
493 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
494 "job-priority-default", 50);
496 /* job-priority-supported */
497 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
498 "job-priority-supported", 100);
500 /* job-sheets-supported */
501 if (cupsArrayCount(Banners
) > 0)
504 * Setup the job-sheets-supported attribute...
507 if (Classification
&& !ClassifyOverride
)
508 attr
= ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
509 "job-sheets-supported", NULL
, Classification
);
511 attr
= ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
512 "job-sheets-supported", cupsArrayCount(Banners
) + 1,
516 cupsdLogMessage(CUPSD_LOG_EMERG
,
517 "cupsdSetPrinterAttrs: Unable to allocate memory for "
518 "job-sheets-supported attribute: %s!", strerror(errno
));
519 else if (!Classification
|| ClassifyOverride
)
521 cupsd_banner_t
*banner
; /* Current banner */
524 attr
->values
[0].string
.text
= _cups_sp_alloc("none");
526 for (i
= 1, banner
= (cupsd_banner_t
*)cupsArrayFirst(Banners
);
528 i
++, banner
= (cupsd_banner_t
*)cupsArrayNext(Banners
))
529 attr
->values
[i
].string
.text
= _cups_sp_alloc(banner
->name
);
533 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
534 "job-sheets-supported", NULL
, "none");
536 /* multiple-document-handling-supported */
537 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
538 "multiple-document-handling-supported",
539 sizeof(multiple_document_handling
) /
540 sizeof(multiple_document_handling
[0]), NULL
,
541 multiple_document_handling
);
543 /* multiple-document-jobs-supported */
544 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
,
545 "multiple-document-jobs-supported", 1);
547 /* multiple-operation-time-out */
548 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
549 "multiple-operation-time-out", 60);
551 /* natural-language-configured */
552 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_LANGUAGE
,
553 "natural-language-configured", NULL
, DefaultLanguage
);
555 /* notify-attributes-supported */
556 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
557 "notify-attributes-supported",
558 (int)(sizeof(notify_attrs
) / sizeof(notify_attrs
[0])),
561 /* TODO: move to printer-specific section! */
562 /* notify-lease-duration-default */
563 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
564 "notify-lease-duration-default", DefaultLeaseDuration
);
566 /* notify-lease-duration-supported */
567 ippAddRange(CommonData
, IPP_TAG_PRINTER
,
568 "notify-lease-duration-supported", 0,
569 MaxLeaseDuration
? MaxLeaseDuration
: 2147483647);
571 /* notify-max-events-supported */
572 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
573 "notify-max-events-supported", MaxEvents
);
575 /* notify-notify-events-default */
576 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
577 "notify-events-default", NULL
, "job-completed");
579 /* notify-notify-events-supported */
580 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
581 "notify-events-supported",
582 (int)(sizeof(notify_events
) / sizeof(notify_events
[0])),
583 NULL
, notify_events
);
585 /* notify-pull-method-supported */
586 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
587 "notify-pull-method-supported", NULL
, "ippget");
589 /* TODO: scan notifier directory */
590 /* notify-schemes-supported */
591 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
592 "notify-schemes-supported", NULL
, "mailto");
594 /* TODO: move to printer-specific section! */
595 /* number-up-default */
596 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
597 "number-up-default", 1);
599 /* number-up-supported */
600 ippAddIntegers(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
601 "number-up-supported", sizeof(nups
) / sizeof(nups
[0]), nups
);
603 /* operations-supported */
604 ippAddIntegers(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
605 "operations-supported",
606 sizeof(ops
) / sizeof(ops
[0]) + JobFiles
- 1, (int *)ops
);
608 /* TODO: move to printer-specific section! */
609 /* orientation-requested-default */
610 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
611 "orientation-requested-default", IPP_PORTRAIT
);
613 /* orientation-requested-supported */
614 ippAddIntegers(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
615 "orientation-requested-supported", 4, (int *)orients
);
617 /* page-ranges-supported */
618 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
, "page-ranges-supported", 1);
620 /* pdf-override-supported */
621 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
622 "pdl-override-supported", NULL
, "not-attempted");
624 /* printer-error-policy-supported */
625 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
626 "printer-error-policy-supported",
627 sizeof(errors
) / sizeof(errors
[0]), NULL
, errors
);
629 /* printer-op-policy-supported */
630 attr
= ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
631 "printer-op-policy-supported", NumPolicies
, NULL
, NULL
);
632 for (i
= 0; i
< NumPolicies
; i
++)
633 attr
->values
[i
].string
.text
= _cups_sp_alloc(Policies
[i
]->name
);
638 * 'cupsdDeleteAllPrinters()' - Delete all printers from the system.
642 cupsdDeleteAllPrinters(void)
644 cupsd_printer_t
*p
; /* Pointer to current printer/class */
647 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
649 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
650 if (!(p
->type
& CUPS_PRINTER_CLASS
))
651 cupsdDeletePrinter(p
, 0);
656 * 'cupsdDeletePrinter()' - Delete a printer from the system.
661 cupsd_printer_t
*p
, /* I - Printer to delete */
662 int update
) /* I - Update printers.conf? */
664 int i
; /* Looping var */
666 char filename
[1024]; /* Interface script filename */
670 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdDeletePrinter(p=%p(%s), update=%d)",
674 * Save the current position in the Printers array...
677 cupsArraySave(Printers
);
680 * Stop printing on this printer...
683 cupsdStopPrinter(p
, update
);
686 * If this printer is the next for browsing, point to the next one...
691 cupsArrayFind(Printers
, p
);
692 BrowseNext
= (cupsd_printer_t
*)cupsArrayNext(Printers
);
696 * Remove the printer from the list...
699 cupsArrayRemove(Printers
, p
);
702 * Remove the dummy interface/icon/option files under IRIX...
706 snprintf(filename
, sizeof(filename
), "/var/spool/lp/interface/%s", p
->name
);
709 snprintf(filename
, sizeof(filename
), "/var/spool/lp/gui_interface/ELF/%s.gui",
713 snprintf(filename
, sizeof(filename
), "/var/spool/lp/activeicons/%s", p
->name
);
716 snprintf(filename
, sizeof(filename
), "/var/spool/lp/pod/%s.config", p
->name
);
719 snprintf(filename
, sizeof(filename
), "/var/spool/lp/pod/%s.status", p
->name
);
722 snprintf(filename
, sizeof(filename
), "/var/spool/lp/member/%s", p
->name
);
727 * If p is the default printer, assign a different one...
730 if (p
== DefaultPrinter
)
732 DefaultPrinter
= NULL
;
734 if (UseNetworkDefault
)
737 * Find the first network default printer and use it...
740 cupsd_printer_t
*dp
; /* New default printer */
743 for (dp
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
745 dp
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
746 if (dp
!= p
&& (dp
->type
& CUPS_PRINTER_DEFAULT
))
755 * Remove this printer from any classes and send a browse delete message...
758 if (!(p
->type
& CUPS_PRINTER_IMPLICIT
))
760 cupsdDeletePrinterFromClasses(p
);
761 cupsdSendBrowseDelete(p
);
765 * Free all memory used by the printer...
768 if (p
->printers
!= NULL
)
771 if (MaxPrinterHistory
)
773 for (i
= 0; i
< p
->num_history
; i
++)
774 ippDelete(p
->history
[i
]);
779 for (i
= 0; i
< p
->num_reasons
; i
++)
784 cupsdDeletePrinterFilters(p
);
786 mimeDeleteType(MimeDatabase
, p
->filetype
);
788 cupsdFreePrinterUsers(p
);
791 cupsdClearString(&p
->uri
);
792 cupsdClearString(&p
->hostname
);
793 cupsdClearString(&p
->name
);
794 cupsdClearString(&p
->location
);
795 cupsdClearString(&p
->make_model
);
796 cupsdClearString(&p
->info
);
797 cupsdClearString(&p
->job_sheets
[0]);
798 cupsdClearString(&p
->job_sheets
[1]);
799 cupsdClearString(&p
->device_uri
);
800 cupsdClearString(&p
->port_monitor
);
801 cupsdClearString(&p
->op_policy
);
802 cupsdClearString(&p
->error_policy
);
805 cupsdClearString(&p
->recoverable
);
806 #endif /* __APPLE__ */
811 * Restore the previous position in the Printers array...
814 cupsArrayRestore(Printers
);
819 * 'cupsdDeletePrinterFilters()' - Delete all MIME filters for a printer.
823 cupsdDeletePrinterFilters(
824 cupsd_printer_t
*p
) /* I - Printer to remove from */
826 mime_filter_t
*filter
; /* MIME filter looping var */
830 * Range check input...
837 * Remove all filters from the MIME database that have a destination
841 for (filter
= mimeFirstFilter(MimeDatabase
);
843 filter
= mimeNextFilter(MimeDatabase
))
844 if (filter
->dst
== p
->filetype
)
847 * Delete the current filter...
850 mimeDeleteFilter(MimeDatabase
, filter
);
856 * 'cupsdFindDest()' - Find a destination in the list.
859 cupsd_printer_t
* /* O - Destination in list */
860 cupsdFindDest(const char *name
) /* I - Name of printer or class to find */
862 cupsd_printer_t key
; /* Search key */
865 key
.name
= (char *)name
;
866 return ((cupsd_printer_t
*)cupsArrayFind(Printers
, &key
));
871 * 'cupsdFindPrinter()' - Find a printer in the list.
874 cupsd_printer_t
* /* O - Printer in list */
875 cupsdFindPrinter(const char *name
) /* I - Name of printer to find */
877 cupsd_printer_t
*p
; /* Printer in list */
880 if ((p
= cupsdFindDest(name
)) != NULL
&& (p
->type
& CUPS_PRINTER_CLASS
))
888 * 'cupsdFreePrinterUsers()' - Free allow/deny users.
892 cupsdFreePrinterUsers(
893 cupsd_printer_t
*p
) /* I - Printer */
895 int i
; /* Looping var */
898 if (!p
|| !p
->num_users
)
901 for (i
= 0; i
< p
->num_users
; i
++)
902 free((void *)p
->users
[i
]);
912 * 'cupsdLoadAllPrinters()' - Load printers from the printers.conf file.
916 cupsdLoadAllPrinters(void)
918 cups_file_t
*fp
; /* printers.conf file */
919 int linenum
; /* Current line number */
920 char line
[1024], /* Line from file */
921 *value
, /* Pointer to value */
922 *valueptr
; /* Pointer into value */
923 cupsd_printer_t
*p
; /* Current printer */
927 * Open the printers.conf file...
930 snprintf(line
, sizeof(line
), "%s/printers.conf", ServerRoot
);
931 if ((fp
= cupsFileOpen(line
, "r")) == NULL
)
934 cupsdLogMessage(CUPSD_LOG_ERROR
,
935 "cupsdLoadAllPrinters: Unable to open %s - %s", line
,
941 * Read printer configurations until we hit EOF...
947 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
950 * Decode the directive...
953 if (!strcasecmp(line
, "<Printer") ||
954 !strcasecmp(line
, "<DefaultPrinter"))
957 * <Printer name> or <DefaultPrinter name>
960 if (p
== NULL
&& value
)
963 * Add the printer and a base file type...
966 cupsdLogMessage(CUPSD_LOG_DEBUG
,
967 "cupsdLoadAllPrinters: Loading printer %s...", value
);
969 p
= cupsdAddPrinter(value
);
971 p
->state
= IPP_PRINTER_IDLE
;
974 * Set the default printer as needed...
977 if (!strcasecmp(line
, "<DefaultPrinter"))
982 cupsdLogMessage(CUPSD_LOG_ERROR
,
983 "Syntax error on line %d of printers.conf.", linenum
);
987 else if (!strcasecmp(line
, "</Printer>"))
992 * Close out the current printer...
995 cupsdSetPrinterAttrs(p
);
996 cupsdAddPrinterHistory(p
);
998 if (p
->device_uri
&& strncmp(p
->device_uri
, "file:", 5) &&
999 p
->state
!= IPP_PRINTER_STOPPED
)
1002 * See if the backend exists...
1005 snprintf(line
, sizeof(line
), "%s/backend/%s", ServerBin
,
1008 if ((valueptr
= strchr(line
+ strlen(ServerBin
), ':')) != NULL
)
1009 *valueptr
= '\0'; /* Chop everything but URI scheme */
1011 if (access(line
, 0))
1014 * Backend does not exist, stop printer...
1017 p
->state
= IPP_PRINTER_STOPPED
;
1018 snprintf(p
->state_message
, sizeof(p
->state_message
),
1019 "Backend %s does not exist!", line
);
1027 cupsdLogMessage(CUPSD_LOG_ERROR
,
1028 "Syntax error on line %d of printers.conf.", linenum
);
1034 cupsdLogMessage(CUPSD_LOG_ERROR
,
1035 "Syntax error on line %d of printers.conf.", linenum
);
1038 else if (!strcasecmp(line
, "Info"))
1041 cupsdSetString(&p
->info
, value
);
1043 else if (!strcasecmp(line
, "Location"))
1046 cupsdSetString(&p
->location
, value
);
1048 else if (!strcasecmp(line
, "DeviceURI"))
1051 cupsdSetString(&p
->device_uri
, value
);
1054 cupsdLogMessage(CUPSD_LOG_ERROR
,
1055 "Syntax error on line %d of printers.conf.", linenum
);
1059 else if (!strcasecmp(line
, "PortMonitor"))
1061 if (value
&& strcmp(value
, "none"))
1062 cupsdSetString(&p
->port_monitor
, value
);
1064 cupsdClearString(&p
->port_monitor
);
1067 cupsdLogMessage(CUPSD_LOG_ERROR
,
1068 "Syntax error on line %d of printers.conf.", linenum
);
1072 else if (!strcasecmp(line
, "State"))
1075 * Set the initial queue state...
1078 if (value
&& !strcasecmp(value
, "idle"))
1079 p
->state
= IPP_PRINTER_IDLE
;
1080 else if (value
&& !strcasecmp(value
, "stopped"))
1081 p
->state
= IPP_PRINTER_STOPPED
;
1084 cupsdLogMessage(CUPSD_LOG_ERROR
,
1085 "Syntax error on line %d of printers.conf.", linenum
);
1089 else if (!strcasecmp(line
, "StateMessage"))
1092 * Set the initial queue state message...
1096 strlcpy(p
->state_message
, value
, sizeof(p
->state_message
));
1098 else if (!strcasecmp(line
, "StateTime"))
1101 * Set the state time...
1105 p
->state_time
= atoi(value
);
1107 else if (!strcasecmp(line
, "Accepting"))
1110 * Set the initial accepting state...
1114 (!strcasecmp(value
, "yes") ||
1115 !strcasecmp(value
, "on") ||
1116 !strcasecmp(value
, "true")))
1119 (!strcasecmp(value
, "no") ||
1120 !strcasecmp(value
, "off") ||
1121 !strcasecmp(value
, "false")))
1125 cupsdLogMessage(CUPSD_LOG_ERROR
,
1126 "Syntax error on line %d of printers.conf.", linenum
);
1130 else if (!strcasecmp(line
, "Shared"))
1133 * Set the initial shared state...
1137 (!strcasecmp(value
, "yes") ||
1138 !strcasecmp(value
, "on") ||
1139 !strcasecmp(value
, "true")))
1142 (!strcasecmp(value
, "no") ||
1143 !strcasecmp(value
, "off") ||
1144 !strcasecmp(value
, "false")))
1148 cupsdLogMessage(CUPSD_LOG_ERROR
,
1149 "Syntax error on line %d of printers.conf.", linenum
);
1153 else if (!strcasecmp(line
, "JobSheets"))
1156 * Set the initial job sheets...
1161 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1166 cupsdSetString(&p
->job_sheets
[0], value
);
1168 while (isspace(*valueptr
& 255))
1173 for (value
= valueptr
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1178 cupsdSetString(&p
->job_sheets
[1], value
);
1183 cupsdLogMessage(CUPSD_LOG_ERROR
,
1184 "Syntax error on line %d of printers.conf.", linenum
);
1188 else if (!strcasecmp(line
, "AllowUser"))
1193 cupsdAddPrinterUser(p
, value
);
1197 cupsdLogMessage(CUPSD_LOG_ERROR
,
1198 "Syntax error on line %d of printers.conf.", linenum
);
1202 else if (!strcasecmp(line
, "DenyUser"))
1207 cupsdAddPrinterUser(p
, value
);
1211 cupsdLogMessage(CUPSD_LOG_ERROR
,
1212 "Syntax error on line %d of printers.conf.", linenum
);
1216 else if (!strcasecmp(line
, "QuotaPeriod"))
1219 p
->quota_period
= atoi(value
);
1222 cupsdLogMessage(CUPSD_LOG_ERROR
,
1223 "Syntax error on line %d of printers.conf.", linenum
);
1227 else if (!strcasecmp(line
, "PageLimit"))
1230 p
->page_limit
= atoi(value
);
1233 cupsdLogMessage(CUPSD_LOG_ERROR
,
1234 "Syntax error on line %d of printers.conf.", linenum
);
1238 else if (!strcasecmp(line
, "KLimit"))
1241 p
->k_limit
= atoi(value
);
1244 cupsdLogMessage(CUPSD_LOG_ERROR
,
1245 "Syntax error on line %d of printers.conf.", linenum
);
1249 else if (!strcasecmp(line
, "OpPolicy"))
1252 cupsdSetString(&p
->op_policy
, value
);
1255 cupsdLogMessage(CUPSD_LOG_ERROR
,
1256 "Syntax error on line %d of printers.conf.", linenum
);
1260 else if (!strcasecmp(line
, "ErrorPolicy"))
1263 cupsdSetString(&p
->error_policy
, value
);
1266 cupsdLogMessage(CUPSD_LOG_ERROR
,
1267 "Syntax error on line %d of printers.conf.", linenum
);
1274 * Something else we don't understand...
1277 cupsdLogMessage(CUPSD_LOG_ERROR
,
1278 "Unknown configuration directive %s on line %d of printers.conf.",
1288 * 'cupsdSaveAllPrinters()' - Save all printer definitions to the printers.conf
1293 cupsdSaveAllPrinters(void)
1295 int i
; /* Looping var */
1296 cups_file_t
*fp
; /* printers.conf file */
1297 char temp
[1024]; /* Temporary string */
1298 char backup
[1024]; /* printers.conf.O file */
1299 cupsd_printer_t
*printer
; /* Current printer class */
1300 time_t curtime
; /* Current time */
1301 struct tm
*curdate
; /* Current date */
1305 * Create the printers.conf file...
1308 snprintf(temp
, sizeof(temp
), "%s/printers.conf", ServerRoot
);
1309 snprintf(backup
, sizeof(backup
), "%s/printers.conf.O", ServerRoot
);
1311 if (rename(temp
, backup
))
1313 if (errno
!= ENOENT
)
1314 cupsdLogMessage(CUPSD_LOG_ERROR
,
1315 "Unable to backup printers.conf - %s", strerror(errno
));
1318 if ((fp
= cupsFileOpen(temp
, "w")) == NULL
)
1320 cupsdLogMessage(CUPSD_LOG_ERROR
,
1321 "Unable to save printers.conf - %s", strerror(errno
));
1323 if (rename(backup
, temp
))
1324 cupsdLogMessage(CUPSD_LOG_ERROR
,
1325 "Unable to restore printers.conf - %s", strerror(errno
));
1329 cupsdLogMessage(CUPSD_LOG_INFO
, "Saving printers.conf...");
1332 * Restrict access to the file...
1335 fchown(cupsFileNumber(fp
), getuid(), Group
);
1336 fchmod(cupsFileNumber(fp
), 0600);
1339 * Write a small header to the file...
1342 curtime
= time(NULL
);
1343 curdate
= localtime(&curtime
);
1344 strftime(temp
, sizeof(temp
) - 1, "%Y-%m-%d %H:%M", curdate
);
1346 cupsFilePuts(fp
, "# Printer configuration file for " CUPS_SVERSION
"\n");
1347 cupsFilePrintf(fp
, "# Written by cupsd on %s\n", temp
);
1350 * Write each local printer known to the system...
1353 for (printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
1355 printer
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
1358 * Skip remote destinations and printer classes...
1361 if ((printer
->type
& CUPS_PRINTER_REMOTE
) ||
1362 (printer
->type
& CUPS_PRINTER_CLASS
) ||
1363 (printer
->type
& CUPS_PRINTER_IMPLICIT
))
1367 * Write printers as needed...
1370 if (printer
== DefaultPrinter
)
1371 cupsFilePrintf(fp
, "<DefaultPrinter %s>\n", printer
->name
);
1373 cupsFilePrintf(fp
, "<Printer %s>\n", printer
->name
);
1376 cupsFilePrintf(fp
, "Info %s\n", printer
->info
);
1378 if (printer
->location
)
1379 cupsFilePrintf(fp
, "Location %s\n", printer
->location
);
1381 if (printer
->device_uri
)
1382 cupsFilePrintf(fp
, "DeviceURI %s\n", printer
->device_uri
);
1384 if (printer
->port_monitor
)
1385 cupsFilePrintf(fp
, "PortMonitor %s\n", printer
->port_monitor
);
1387 if (printer
->state
== IPP_PRINTER_STOPPED
)
1389 cupsFilePuts(fp
, "State Stopped\n");
1390 cupsFilePrintf(fp
, "StateMessage %s\n", printer
->state_message
);
1393 cupsFilePuts(fp
, "State Idle\n");
1395 cupsFilePrintf(fp
, "StateTime %d\n", (int)printer
->state_time
);
1397 if (printer
->accepting
)
1398 cupsFilePuts(fp
, "Accepting Yes\n");
1400 cupsFilePuts(fp
, "Accepting No\n");
1402 if (printer
->shared
)
1403 cupsFilePuts(fp
, "Shared Yes\n");
1405 cupsFilePuts(fp
, "Shared No\n");
1407 cupsFilePrintf(fp
, "JobSheets %s %s\n", printer
->job_sheets
[0],
1408 printer
->job_sheets
[1]);
1410 cupsFilePrintf(fp
, "QuotaPeriod %d\n", printer
->quota_period
);
1411 cupsFilePrintf(fp
, "PageLimit %d\n", printer
->page_limit
);
1412 cupsFilePrintf(fp
, "KLimit %d\n", printer
->k_limit
);
1414 for (i
= 0; i
< printer
->num_users
; i
++)
1415 cupsFilePrintf(fp
, "%sUser %s\n", printer
->deny_users
? "Deny" : "Allow",
1418 if (printer
->op_policy
)
1419 cupsFilePrintf(fp
, "OpPolicy %s\n", printer
->op_policy
);
1420 if (printer
->error_policy
)
1421 cupsFilePrintf(fp
, "ErrorPolicy %s\n", printer
->error_policy
);
1423 cupsFilePuts(fp
, "</Printer>\n");
1427 * Make IRIX desktop & printer status happy
1430 write_irix_state(printer
);
1439 * 'cupsdSetPrinterAttrs()' - Set printer attributes based upon the PPD file.
1443 cupsdSetPrinterAttrs(cupsd_printer_t
*p
)/* I - Printer to setup */
1445 char uri
[HTTP_MAX_URI
];
1446 /* URI for printer */
1447 char resource
[HTTP_MAX_URI
];
1448 /* Resource portion of URI */
1449 int i
; /* Looping var */
1450 char filename
[1024]; /* Name of PPD file */
1451 int num_media
; /* Number of media options */
1452 cupsd_location_t
*auth
; /* Pointer to authentication element */
1453 const char *auth_supported
;/* Authentication supported */
1454 cups_ptype_t printer_type
; /* Printer type data */
1455 ppd_file_t
*ppd
; /* PPD file data */
1456 ppd_option_t
*input_slot
, /* InputSlot options */
1457 *media_type
, /* MediaType options */
1458 *page_size
, /* PageSize options */
1459 *output_bin
, /* OutputBin options */
1460 *media_quality
; /* EFMediaQualityMode options */
1461 ppd_attr_t
*ppdattr
; /* PPD attribute */
1462 ipp_attribute_t
*attr
; /* Attribute data */
1463 ipp_value_t
*val
; /* Attribute value */
1464 int num_finishings
; /* Number of finishings */
1465 ipp_finish_t finishings
[5]; /* finishings-supported values */
1466 static const char * const sides
[3] = /* sides-supported values */
1474 DEBUG_printf(("cupsdSetPrinterAttrs: entering name = %s, type = %x\n", p
->name
,
1478 * Make sure that we have the common attributes defined...
1482 cupsdCreateCommonData();
1485 * Clear out old filters, if any...
1488 cupsdDeletePrinterFilters(p
);
1491 * Figure out the authentication that is required for the printer.
1494 auth_supported
= "requesting-user-name";
1495 if (!(p
->type
& CUPS_PRINTER_REMOTE
))
1497 if (p
->type
& CUPS_PRINTER_CLASS
)
1498 snprintf(resource
, sizeof(resource
), "/classes/%s", p
->name
);
1500 snprintf(resource
, sizeof(resource
), "/printers/%s", p
->name
);
1502 if ((auth
= cupsdFindBest(resource
, HTTP_POST
)) == NULL
)
1503 auth
= cupsdFindPolicyOp(p
->op_policy_ptr
, IPP_PRINT_JOB
);
1507 if (auth
->type
== AUTH_BASIC
|| auth
->type
== AUTH_BASICDIGEST
)
1508 auth_supported
= "basic";
1509 else if (auth
->type
== AUTH_DIGEST
)
1510 auth_supported
= "digest";
1512 if (auth
->type
!= AUTH_NONE
)
1513 p
->type
|= CUPS_PRINTER_AUTHENTICATED
;
1515 p
->type
&= ~CUPS_PRINTER_AUTHENTICATED
;
1518 p
->type
&= ~CUPS_PRINTER_AUTHENTICATED
;
1522 * Create the required IPP attributes for a printer...
1526 ippDelete(p
->attrs
);
1528 p
->attrs
= ippNew();
1530 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
1531 "uri-authentication-supported", NULL
, auth_supported
);
1532 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
1533 "uri-security-supported", NULL
, "none");
1534 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
, "printer-name", NULL
,
1536 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-location",
1537 NULL
, p
->location
? p
->location
: "");
1538 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-info",
1539 NULL
, p
->info
? p
->info
: "");
1540 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "printer-more-info",
1546 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
1547 "requesting-user-name-denied", p
->num_users
, NULL
,
1550 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
1551 "requesting-user-name-allowed", p
->num_users
, NULL
,
1555 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
1556 "job-quota-period", p
->quota_period
);
1557 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
1558 "job-k-limit", p
->k_limit
);
1559 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
1560 "job-page-limit", p
->page_limit
);
1562 if (cupsArrayCount(Banners
) > 0 && !(p
->type
& CUPS_PRINTER_REMOTE
))
1565 * Setup the job-sheets-default attribute...
1568 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
1569 "job-sheets-default", 2, NULL
, NULL
);
1573 attr
->values
[0].string
.text
= _cups_sp_alloc(Classification
?
1574 Classification
: p
->job_sheets
[0]);
1575 attr
->values
[1].string
.text
= _cups_sp_alloc(Classification
?
1576 Classification
: p
->job_sheets
[1]);
1580 printer_type
= p
->type
;
1584 if (p
->type
& CUPS_PRINTER_REMOTE
)
1587 * Tell the client this is a remote printer of some type...
1590 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
1591 "printer-uri-supported", NULL
, p
->uri
);
1594 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
1595 "printer-make-and-model", NULL
, p
->make_model
);
1597 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "device-uri", NULL
,
1605 * Assign additional attributes depending on whether this is a printer
1609 p
->type
&= ~CUPS_PRINTER_OPTIONS
;
1611 if (p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
))
1616 * Add class-specific attributes...
1619 if ((p
->type
& CUPS_PRINTER_IMPLICIT
) && p
->num_printers
> 0 &&
1620 p
->printers
[0]->make_model
)
1621 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
1622 "printer-make-and-model", NULL
, p
->printers
[0]->make_model
);
1624 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
1625 "printer-make-and-model", NULL
, "Local Printer Class");
1627 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "device-uri", NULL
,
1628 "file:///dev/null");
1630 if (p
->num_printers
> 0)
1633 * Add a list of member URIs and names...
1636 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
1637 "member-uris", p
->num_printers
, NULL
, NULL
);
1638 p
->type
|= CUPS_PRINTER_OPTIONS
;
1640 for (i
= 0; i
< p
->num_printers
; i
++)
1643 attr
->values
[i
].string
.text
= _cups_sp_alloc(p
->printers
[i
]->uri
);
1645 p
->type
&= ~CUPS_PRINTER_OPTIONS
| p
->printers
[i
]->type
;
1648 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
1649 "member-names", p
->num_printers
, NULL
, NULL
);
1653 for (i
= 0; i
< p
->num_printers
; i
++)
1654 attr
->values
[i
].string
.text
= _cups_sp_alloc(p
->printers
[i
]->name
);
1661 * Add printer-specific attributes... Start by sanitizing the device
1662 * URI so it doesn't have a username or password in it...
1666 strcpy(uri
, "file:/dev/null");
1667 else if (strstr(p
->device_uri
, "://") != NULL
)
1670 * http://..., ipp://..., etc.
1673 cupsdSanitizeURI(p
->device_uri
, uri
, sizeof(uri
));
1678 * file:..., serial:..., etc.
1681 strlcpy(uri
, p
->device_uri
, sizeof(uri
));
1684 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "device-uri", NULL
,
1688 * Assign additional attributes from the PPD file (if any)...
1691 p
->type
|= CUPS_PRINTER_BW
;
1692 finishings
[0] = IPP_FINISHINGS_NONE
;
1695 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
1698 if ((ppd
= ppdOpenFile(filename
)) != NULL
)
1701 * Add make/model and other various attributes...
1704 if (ppd
->color_device
)
1705 p
->type
|= CUPS_PRINTER_COLOR
;
1706 if (ppd
->variable_sizes
)
1707 p
->type
|= CUPS_PRINTER_VARIABLE
;
1708 if (!ppd
->manual_copies
)
1709 p
->type
|= CUPS_PRINTER_COPIES
;
1710 if ((ppdattr
= ppdFindAttr(ppd
, "cupsFax", NULL
)) != NULL
)
1711 if (ppdattr
->value
&& !strcasecmp(ppdattr
->value
, "true"))
1712 p
->type
|= CUPS_PRINTER_FAX
;
1714 ippAddBoolean(p
->attrs
, IPP_TAG_PRINTER
, "color-supported",
1716 if (ppd
->throughput
)
1717 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
1718 "pages-per-minute", ppd
->throughput
);
1721 cupsdSetString(&p
->make_model
, ppd
->nickname
);
1722 else if (ppd
->modelname
)
1723 cupsdSetString(&p
->make_model
, ppd
->modelname
);
1725 cupsdSetString(&p
->make_model
, "Bad PPD File");
1728 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
1729 "printer-make-and-model", NULL
, p
->make_model
);
1732 * Add media options from the PPD file...
1735 if ((input_slot
= ppdFindOption(ppd
, "InputSlot")) != NULL
)
1736 num_media
= input_slot
->num_choices
;
1740 if ((media_type
= ppdFindOption(ppd
, "MediaType")) != NULL
)
1741 num_media
+= media_type
->num_choices
;
1743 if ((page_size
= ppdFindOption(ppd
, "PageSize")) != NULL
)
1744 num_media
+= page_size
->num_choices
;
1746 if ((media_quality
= ppdFindOption(ppd
, "EFMediaQualityMode")) != NULL
)
1747 num_media
+= media_quality
->num_choices
;
1751 cupsdLogMessage(CUPSD_LOG_CRIT
, "cupsdSetPrinterAttrs: The PPD file for printer %s "
1752 "contains no media options and is therefore "
1753 "invalid!", p
->name
);
1757 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
1758 "media-supported", num_media
, NULL
, NULL
);
1763 if (input_slot
!= NULL
)
1764 for (i
= 0; i
< input_slot
->num_choices
; i
++, val
++)
1765 val
->string
.text
= _cups_sp_alloc(input_slot
->choices
[i
].choice
);
1767 if (media_type
!= NULL
)
1768 for (i
= 0; i
< media_type
->num_choices
; i
++, val
++)
1769 val
->string
.text
= _cups_sp_alloc(media_type
->choices
[i
].choice
);
1771 if (media_quality
!= NULL
)
1772 for (i
= 0; i
< media_quality
->num_choices
; i
++, val
++)
1773 val
->string
.text
= _cups_sp_alloc(media_quality
->choices
[i
].choice
);
1775 if (page_size
!= NULL
)
1777 for (i
= 0; i
< page_size
->num_choices
; i
++, val
++)
1778 val
->string
.text
= _cups_sp_alloc(page_size
->choices
[i
].choice
);
1780 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
, "media-default",
1781 NULL
, page_size
->defchoice
);
1783 else if (input_slot
!= NULL
)
1784 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
, "media-default",
1785 NULL
, input_slot
->defchoice
);
1786 else if (media_type
!= NULL
)
1787 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
, "media-default",
1788 NULL
, media_type
->defchoice
);
1789 else if (media_quality
!= NULL
)
1790 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
, "media-default",
1791 NULL
, media_quality
->defchoice
);
1793 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
, "media-default",
1802 if ((output_bin
= ppdFindOption(ppd
, "OutputBin")) != NULL
)
1804 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
1805 "output-bin-supported", output_bin
->num_choices
,
1810 for (i
= 0, val
= attr
->values
;
1811 i
< output_bin
->num_choices
;
1813 val
->string
.text
= _cups_sp_alloc(output_bin
->choices
[i
].choice
);
1821 if (ppdFindOption(ppd
, "Duplex") != NULL
)
1823 p
->type
|= CUPS_PRINTER_DUPLEX
;
1825 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
, "sides-supported",
1827 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
, "sides-default",
1831 if (ppdFindOption(ppd
, "Collate") != NULL
)
1832 p
->type
|= CUPS_PRINTER_COLLATE
;
1834 if (ppdFindOption(ppd
, "StapleLocation") != NULL
)
1836 p
->type
|= CUPS_PRINTER_STAPLE
;
1837 finishings
[num_finishings
++] = IPP_FINISHINGS_STAPLE
;
1840 if (ppdFindOption(ppd
, "BindEdge") != NULL
)
1842 p
->type
|= CUPS_PRINTER_BIND
;
1843 finishings
[num_finishings
++] = IPP_FINISHINGS_BIND
;
1846 for (i
= 0; i
< ppd
->num_sizes
; i
++)
1847 if (ppd
->sizes
[i
].length
> 1728)
1848 p
->type
|= CUPS_PRINTER_LARGE
;
1849 else if (ppd
->sizes
[i
].length
> 1008)
1850 p
->type
|= CUPS_PRINTER_MEDIUM
;
1852 p
->type
|= CUPS_PRINTER_SMALL
;
1855 * Add a filter from application/vnd.cups-raw to printer/name to
1856 * handle "raw" printing by users.
1859 cupsdAddPrinterFilter(p
, "application/vnd.cups-raw 0 -");
1862 * Add any filters in the PPD file...
1865 DEBUG_printf(("ppd->num_filters = %d\n", ppd
->num_filters
));
1866 for (i
= 0; i
< ppd
->num_filters
; i
++)
1868 DEBUG_printf(("ppd->filters[%d] = \"%s\"\n", i
, ppd
->filters
[i
]));
1869 cupsdAddPrinterFilter(p
, ppd
->filters
[i
]);
1872 if (ppd
->num_filters
== 0)
1875 * If there are no filters, add a PostScript printing filter.
1878 cupsdAddPrinterFilter(p
, "application/vnd.cups-postscript 0 -");
1882 * Show current and available port monitors for this printer...
1885 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
, "port-monitor",
1886 NULL
, p
->port_monitor
? p
->port_monitor
: "none");
1889 for (i
= 1, ppdattr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
1891 i
++, ppdattr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
));
1895 if (strstr(ppd
->protocols
, "TBCP"))
1897 else if (strstr(ppd
->protocols
, "BCP"))
1901 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
1902 "port-monitor-supported", i
, NULL
, NULL
);
1904 attr
->values
[0].string
.text
= _cups_sp_alloc("none");
1906 for (i
= 1, ppdattr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
1908 i
++, ppdattr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
))
1909 attr
->values
[i
].string
.text
= _cups_sp_alloc(ppdattr
->value
);
1913 if (strstr(ppd
->protocols
, "TBCP"))
1914 attr
->values
[i
].string
.text
= _cups_sp_alloc("tbcp");
1915 else if (strstr(ppd
->protocols
, "BCP"))
1916 attr
->values
[i
].string
.text
= _cups_sp_alloc("bcp");
1920 * Close the PPD and set the type...
1925 printer_type
= p
->type
;
1927 else if (!access(filename
, 0))
1929 int pline
; /* PPD line number */
1930 ppd_status_t pstatus
; /* PPD load status */
1933 pstatus
= ppdLastError(&pline
);
1935 cupsdLogMessage(CUPSD_LOG_ERROR
, "PPD file for %s cannot be loaded!", p
->name
);
1937 if (pstatus
<= PPD_ALLOC_ERROR
)
1938 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s", strerror(errno
));
1940 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s on line %d.", ppdErrorString(pstatus
),
1943 cupsdLogMessage(CUPSD_LOG_INFO
, "Hint: Run \"cupstestppd %s\" and fix any errors.",
1947 * Add a filter from application/vnd.cups-raw to printer/name to
1948 * handle "raw" printing by users.
1951 cupsdAddPrinterFilter(p
, "application/vnd.cups-raw 0 -");
1954 * Add a PostScript filter, since this is still possibly PS printer.
1957 cupsdAddPrinterFilter(p
, "application/vnd.cups-postscript 0 -");
1962 * If we have an interface script, add a filter entry for it...
1965 snprintf(filename
, sizeof(filename
), "%s/interfaces/%s", ServerRoot
,
1967 if (access(filename
, X_OK
) == 0)
1970 * Yes, we have a System V style interface script; use it!
1973 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
1974 "printer-make-and-model", NULL
, "Local System V Printer");
1976 snprintf(filename
, sizeof(filename
), "*/* 0 %s/interfaces/%s",
1977 ServerRoot
, p
->name
);
1978 cupsdAddPrinterFilter(p
, filename
);
1980 else if (p
->device_uri
&&
1981 !strncmp(p
->device_uri
, "ipp://", 6) &&
1982 (strstr(p
->device_uri
, "/printers/") != NULL
||
1983 strstr(p
->device_uri
, "/classes/") != NULL
))
1986 * Tell the client this is really a hard-wired remote printer.
1989 printer_type
|= CUPS_PRINTER_REMOTE
;
1992 * Point the printer-uri-supported attribute to the
1996 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
1997 "printer-uri-supported", NULL
, p
->device_uri
);
2000 * Then set the make-and-model accordingly...
2003 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
2004 "printer-make-and-model", NULL
, "Remote Printer");
2007 * Print all files directly...
2015 * Otherwise we have neither - treat this as a "dumb" printer
2016 * with no PPD file...
2019 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
2020 "printer-make-and-model", NULL
, "Local Raw Printer");
2026 ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
2027 "finishings-supported", num_finishings
, (int *)finishings
);
2028 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
2029 "finishings-default", IPP_FINISHINGS_NONE
);
2033 DEBUG_printf(("cupsdSetPrinterAttrs: leaving name = %s, type = %x\n", p
->name
,
2038 * Write the IRIX printer config and status files...
2041 write_irix_config(p
);
2042 write_irix_state(p
);
2048 * 'cupsdSetPrinterReasons()' - Set/update the reasons strings.
2052 cupsdSetPrinterReasons(
2053 cupsd_printer_t
*p
, /* I - Printer */
2054 const char *s
) /* I - Reasons strings */
2056 int i
; /* Looping var */
2057 const char *sptr
; /* Pointer into reasons */
2058 char reason
[255], /* Reason string */
2059 *rptr
; /* Pointer into reason */
2062 if (s
[0] == '-' || s
[0] == '+')
2065 * Add/remove reasons...
2073 * Replace reasons...
2078 for (i
= 0; i
< p
->num_reasons
; i
++)
2079 free(p
->reasons
[i
]);
2085 * Loop through all of the reasons...
2091 * Skip leading whitespace and commas...
2094 while (isspace(*sptr
& 255) || *sptr
== ',')
2097 for (rptr
= reason
; *sptr
&& !isspace(*sptr
& 255) && *sptr
!= ','; sptr
++)
2098 if (rptr
< (reason
+ sizeof(reason
) - 1))
2112 for (i
= 0; i
< p
->num_reasons
; i
++)
2113 if (!strcasecmp(reason
, p
->reasons
[i
]))
2116 * Found a match, so remove it...
2120 free(p
->reasons
[i
]);
2122 if (i
< p
->num_reasons
)
2123 memmove(p
->reasons
+ i
, p
->reasons
+ i
+ 1,
2124 (p
->num_reasons
- i
) * sizeof(char *));
2129 else if (p
->num_reasons
< (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
2135 for (i
= 0; i
< p
->num_reasons
; i
++)
2136 if (!strcasecmp(reason
, p
->reasons
[i
]))
2139 if (i
>= p
->num_reasons
)
2141 p
->reasons
[i
] = strdup(reason
);
2150 * 'cupsdSetPrinterState()' - Update the current state of a printer.
2154 cupsdSetPrinterState(
2155 cupsd_printer_t
*p
, /* I - Printer to change */
2156 ipp_pstate_t s
, /* I - New state */
2157 int update
) /* I - Update printers.conf? */
2159 ipp_pstate_t old_state
; /* Old printer state */
2163 * Can't set status of remote printers...
2166 if (p
->type
& CUPS_PRINTER_REMOTE
)
2170 * Set the new state...
2173 old_state
= p
->state
;
2179 * Let the browse code know this needs to be updated...
2183 p
->state_time
= time(NULL
);
2187 write_irix_state(p
);
2191 cupsdAddPrinterHistory(p
);
2194 * Save the printer configuration if a printer goes from idle or processing
2195 * to stopped (or visa-versa)...
2198 if ((old_state
== IPP_PRINTER_STOPPED
) != (s
== IPP_PRINTER_STOPPED
) &&
2201 if (p
->type
& CUPS_PRINTER_CLASS
)
2202 cupsdSaveAllClasses();
2204 cupsdSaveAllPrinters();
2210 * 'cupsdStopPrinter()' - Stop a printer from printing any jobs...
2214 cupsdStopPrinter(cupsd_printer_t
*p
, /* I - Printer to stop */
2215 int update
)/* I - Update printers.conf? */
2217 cupsd_job_t
*job
; /* Active print job */
2221 * Set the printer state...
2224 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, update
);
2227 * See if we have a job printing on this printer...
2233 * Get pointer to job...
2236 job
= (cupsd_job_t
*)p
->job
;
2242 cupsdStopJob(job
, 0);
2245 * Reset the state to pending...
2248 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
2256 * 'cupsdUpdatePrinters()' - Update printers after a partial reload.
2260 cupsdUpdatePrinters(void)
2262 cupsd_printer_t
*p
; /* Current printer */
2266 * Loop through the printers and recreate the printer attributes
2267 * for any local printers since the policy and/or access control
2268 * stuff may have changed. Also, if browsing is disabled, remove
2269 * any remote printers...
2272 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
2274 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
2276 if (!Browsing
&& (p
->type
& (CUPS_PRINTER_IMPLICIT
| CUPS_PRINTER_REMOTE
)))
2278 if (p
->type
& CUPS_PRINTER_IMPLICIT
)
2279 cupsArrayRemove(ImplicitPrinters
, p
);
2281 cupsArraySave(Printers
);
2282 cupsdDeletePrinter(p
, 0);
2283 cupsArrayRestore(Printers
);
2286 else if (!(p
->type
& CUPS_PRINTER_REMOTE
))
2287 cupsdSetPrinterAttrs(p
);
2290 * Update the operation policy pointer...
2293 if ((p
->op_policy_ptr
= cupsdFindPolicy(p
->op_policy
)) == NULL
)
2294 p
->op_policy_ptr
= DefaultPolicyPtr
;
2300 * 'cupsdValidateDest()' - Validate a printer/class destination.
2303 const char * /* O - Printer or class name */
2305 const char *hostname
, /* I - Host name */
2306 const char *resource
, /* I - Resource name */
2307 cups_ptype_t
*dtype
, /* O - Type (printer or class) */
2308 cupsd_printer_t
**printer
) /* O - Printer pointer */
2310 cupsd_printer_t
*p
; /* Current printer */
2311 char localname
[1024],/* Localized hostname */
2312 *lptr
, /* Pointer into localized hostname */
2313 *sptr
; /* Pointer into server name */
2316 DEBUG_printf(("cupsdValidateDest(\"%s\", \"%s\", %p, %p)\n", hostname
, resource
,
2320 * Initialize return values...
2326 *dtype
= (cups_ptype_t
)0;
2329 * See if the resource is a class or printer...
2332 if (!strncmp(resource
, "/classes/", 9))
2340 else if (!strncmp(resource
, "/printers/", 10))
2351 * Bad resource name...
2358 * See if the printer or class name exists...
2361 p
= cupsdFindDest(resource
);
2363 if (p
== NULL
&& strchr(resource
, '@') == NULL
)
2370 *dtype
= p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
|
2371 CUPS_PRINTER_REMOTE
);
2376 * Change localhost to the server name...
2379 if (!strcasecmp(hostname
, "localhost"))
2380 hostname
= ServerName
;
2382 strlcpy(localname
, hostname
, sizeof(localname
));
2384 if (!strcasecmp(hostname
, ServerName
))
2387 * Localize the hostname...
2390 lptr
= strchr(localname
, '.');
2391 sptr
= strchr(ServerName
, '.');
2393 if (sptr
!= NULL
&& lptr
!= NULL
)
2396 * Strip the common domain name components...
2399 while (lptr
!= NULL
)
2401 if (!strcasecmp(lptr
, sptr
))
2407 lptr
= strchr(lptr
+ 1, '.');
2412 DEBUG_printf(("localized hostname is \"%s\"...\n", localname
));
2415 * Find a matching printer or class...
2418 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
2420 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
2421 if (!strcasecmp(p
->hostname
, localname
) &&
2422 !strcasecmp(p
->name
, resource
))
2427 *dtype
= p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
|
2428 CUPS_PRINTER_REMOTE
);
2437 * 'cupsdWritePrintcap()' - Write a pseudo-printcap file for older applications
2442 cupsdWritePrintcap(void)
2444 cups_file_t
*fp
; /* printcap file */
2445 cupsd_printer_t
*p
; /* Current printer */
2450 * Update the IRIX printer state for the default printer; if
2451 * no printers remain, then the default printer file will be
2455 write_irix_state(DefaultPrinter
);
2459 * See if we have a printcap file; if not, don't bother writing it.
2462 if (!Printcap
|| !*Printcap
)
2466 * Open the printcap file...
2469 if ((fp
= cupsFileOpen(Printcap
, "w")) == NULL
)
2473 * Put a comment header at the top so that users will know where the
2474 * data has come from...
2477 cupsFilePuts(fp
, "# This file was automatically generated by cupsd(8) from the\n");
2478 cupsFilePrintf(fp
, "# %s/printers.conf file. All changes to this file\n",
2480 cupsFilePuts(fp
, "# will be lost.\n");
2485 * Write a new printcap with the current list of printers.
2488 switch (PrintcapFormat
)
2492 * Each printer is put in the file as:
2502 cupsFilePrintf(fp
, "%s|%s:rm=%s:rp=%s:\n", DefaultPrinter
->name
,
2503 DefaultPrinter
->info
, ServerName
, DefaultPrinter
->name
);
2505 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
2507 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
2508 if (p
!= DefaultPrinter
)
2509 cupsFilePrintf(fp
, "%s|%s:rm=%s:rp=%s:\n", p
->name
, p
->info
,
2510 ServerName
, p
->name
);
2513 case PRINTCAP_SOLARIS
:
2515 * Each printer is put in the file as:
2517 * _all:all=Printer1,Printer2,Printer3,...,PrinterN
2518 * _default:use=DefaultPrinter
2520 * :bsdaddr=ServerName,Printer1:\
2521 * :description=Description:
2523 * :bsdaddr=ServerName,Printer2:\
2524 * :description=Description:
2526 * :bsdaddr=ServerName,Printer3:\
2527 * :description=Description:
2530 * :bsdaddr=ServerName,PrinterN:\
2531 * :description=Description:
2534 cupsFilePuts(fp
, "_all:all=");
2535 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
2537 p
= (cupsd_printer_t
*)cupsArrayCurrent(Printers
))
2538 cupsFilePrintf(fp
, "%s%c", p
->name
,
2539 cupsArrayNext(Printers
) ? ',' : '\n');
2542 cupsFilePrintf(fp
, "_default:use=%s\n", DefaultPrinter
->name
);
2544 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
2546 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
2547 cupsFilePrintf(fp
, "%s:\\\n"
2548 "\t:bsdaddr=%s,%s:\\\n"
2549 "\t:description=%s:\n",
2550 p
->name
, ServerName
, p
->name
, p
->info
? p
->info
: "");
2564 * 'cupsdSanitizeURI()' - Sanitize a device URI...
2567 char * /* O - New device URI */
2568 cupsdSanitizeURI(const char *uri
, /* I - Original device URI */
2569 char *buffer
, /* O - New device URI */
2570 int buflen
) /* I - Size of new device URI buffer */
2572 char *start
, /* Start of data after scheme */
2573 *slash
, /* First slash after scheme:// */
2574 *ptr
; /* Pointer into user@host:port part */
2578 * Range check input...
2581 if (!uri
|| !buffer
|| buflen
< 2)
2585 * Copy the device URI to the new buffer...
2588 strlcpy(buffer
, uri
, buflen
);
2591 * Find the end of the scheme:// part...
2594 if ((ptr
= strchr(buffer
, ':')) == NULL
)
2595 return (buffer
); /* No scheme: part... */
2597 for (start
= ptr
+ 1; *start
; start
++)
2602 * Find the next slash (/) in the URI...
2605 if ((slash
= strchr(start
, '/')) == NULL
)
2606 slash
= start
+ strlen(start
); /* No slash, point to the end */
2609 * Check for an @ sign before the slash...
2612 if ((ptr
= strchr(start
, '@')) != NULL
&& ptr
< slash
)
2615 * Found an @ sign and it is before the resource part, so we have
2616 * an authentication string. Copy the remaining URI over the
2617 * authentication string...
2620 _cups_strcpy(start
, ptr
+ 1);
2624 * Return the new device URI...
2632 * 'compare_printers()' - Compare two printers.
2635 static int /* O - Result of comparison */
2636 compare_printers(void *first
, /* I - First printer */
2637 void *second
, /* I - Second printer */
2638 void *data
) /* I - App data (not used) */
2640 return (strcasecmp(((cupsd_printer_t
*)first
)->name
,
2641 ((cupsd_printer_t
*)second
)->name
));
2647 * 'write_irix_config()' - Update the config files used by the IRIX
2652 write_irix_config(cupsd_printer_t
*p
) /* I - Printer to update */
2654 char filename
[1024]; /* Interface script filename */
2655 cups_file_t
*fp
; /* Interface script file */
2660 * Add dummy interface and GUI scripts to fool SGI's "challenged" printing
2661 * tools. First the interface script that tells the tools what kind of
2662 * printer we have...
2665 snprintf(filename
, sizeof(filename
), "/var/spool/lp/interface/%s", p
->name
);
2667 if (p
->type
& CUPS_PRINTER_CLASS
)
2669 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
2671 cupsFilePuts(fp
, "#!/bin/sh\n");
2673 if ((attr
= ippFindAttribute(p
->attrs
, "printer-make-and-model",
2674 IPP_TAG_TEXT
)) != NULL
)
2675 cupsFilePrintf(fp
, "NAME=\"%s\"\n", attr
->values
[0].string
.text
);
2676 else if (p
->type
& CUPS_PRINTER_CLASS
)
2677 cupsFilePuts(fp
, "NAME=\"Printer Class\"\n");
2679 cupsFilePuts(fp
, "NAME=\"Remote Destination\"\n");
2681 if (p
->type
& CUPS_PRINTER_COLOR
)
2682 cupsFilePuts(fp
, "TYPE=ColorPostScript\n");
2684 cupsFilePuts(fp
, "TYPE=MonoPostScript\n");
2686 cupsFilePrintf(fp
, "HOSTNAME=%s\n", ServerName
);
2687 cupsFilePrintf(fp
, "HOSTPRINTER=%s\n", p
->name
);
2691 chmod(filename
, 0755);
2692 chown(filename
, User
, Group
);
2696 * Then the member file that tells which device file the queue is connected
2697 * to... Networked printers use "/dev/null" in this file, so that's what
2698 * we use (the actual device URI can confuse some apps...)
2701 snprintf(filename
, sizeof(filename
), "/var/spool/lp/member/%s", p
->name
);
2703 if (p
->type
& CUPS_PRINTER_CLASS
)
2705 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
2707 cupsFilePuts(fp
, "/dev/null\n");
2711 chmod(filename
, 0644);
2712 chown(filename
, User
, Group
);
2716 * The gui_interface file is a script or program that launches a GUI
2717 * option panel for the printer, using options specified on the
2718 * command-line in the third argument. The option panel must send
2719 * any printing options to stdout on a single line when the user
2720 * accepts them, or nothing if the user cancels the dialog.
2722 * The default options panel program is /usr/bin/glpoptions, from
2723 * the ESP Print Pro software. You can select another using the
2724 * PrintcapGUI option.
2727 snprintf(filename
, sizeof(filename
), "/var/spool/lp/gui_interface/ELF/%s.gui", p
->name
);
2729 if (p
->type
& CUPS_PRINTER_CLASS
)
2731 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
2733 cupsFilePuts(fp
, "#!/bin/sh\n");
2734 cupsFilePrintf(fp
, "%s -d %s -o \"$3\"\n", PrintcapGUI
, p
->name
);
2738 chmod(filename
, 0755);
2739 chown(filename
, User
, Group
);
2743 * The POD config file is needed by the printstatus command to show
2744 * the printer location and device.
2747 snprintf(filename
, sizeof(filename
), "/var/spool/lp/pod/%s.config", p
->name
);
2749 if (p
->type
& CUPS_PRINTER_CLASS
)
2751 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
2753 cupsFilePrintf(fp
, "Printer Class | %s\n",
2754 (p
->type
& CUPS_PRINTER_COLOR
) ? "ColorPostScript" : "MonoPostScript");
2755 cupsFilePrintf(fp
, "Printer Model | %s\n", p
->make_model
? p
->make_model
: "");
2756 cupsFilePrintf(fp
, "Location Code | %s\n", p
->location
? p
->location
: "");
2757 cupsFilePrintf(fp
, "Physical Location | %s\n", p
->info
? p
->info
: "");
2758 cupsFilePrintf(fp
, "Port Path | %s\n", p
->device_uri
? p
->device_uri
: "");
2759 cupsFilePrintf(fp
, "Config Path | /var/spool/lp/pod/%s.config\n", p
->name
);
2760 cupsFilePrintf(fp
, "Active Status Path | /var/spool/lp/pod/%s.status\n", p
->name
);
2761 cupsFilePuts(fp
, "Status Update Wait | 10 seconds\n");
2765 chmod(filename
, 0664);
2766 chown(filename
, User
, Group
);
2772 * 'write_irix_state()' - Update the status files used by IRIX printing
2777 write_irix_state(cupsd_printer_t
*p
) /* I - Printer to update */
2779 char filename
[1024]; /* Interface script filename */
2780 cups_file_t
*fp
; /* Interface script file */
2781 int tag
; /* Status tag value */
2787 * The POD status file is needed for the printstatus window to
2788 * provide the current status of the printer.
2791 snprintf(filename
, sizeof(filename
), "/var/spool/lp/pod/%s.status", p
->name
);
2793 if (p
->type
& CUPS_PRINTER_CLASS
)
2795 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
2797 cupsFilePrintf(fp
, "Operational Status | %s\n",
2798 (p
->state
== IPP_PRINTER_IDLE
) ? "Idle" :
2799 (p
->state
== IPP_PRINTER_PROCESSING
) ? "Busy" :
2801 cupsFilePrintf(fp
, "Information | 01 00 00 | %s\n", CUPS_SVERSION
);
2802 cupsFilePrintf(fp
, "Information | 02 00 00 | Device URI: %s\n",
2803 p
->device_uri
? p
->device_uri
: "");
2804 cupsFilePrintf(fp
, "Information | 03 00 00 | %s jobs\n",
2805 p
->accepting
? "Accepting" : "Not accepting");
2806 cupsFilePrintf(fp
, "Information | 04 00 00 | %s\n", p
->state_message
);
2810 chmod(filename
, 0664);
2811 chown(filename
, User
, Group
);
2815 * The activeicons file is needed to provide desktop icons for printers:
2817 * [ quoted from /usr/lib/print/tagit ]
2819 * --- Type of printer tags (base values)
2821 * Dumb=66048 # 0x10200
2822 * DumbColor=66080 # 0x10220
2823 * Raster=66112 # 0x10240
2824 * ColorRaster=66144 # 0x10260
2825 * Plotter=66176 # 0x10280
2826 * PostScript=66208 # 0x102A0
2827 * ColorPostScript=66240 # 0x102C0
2828 * MonoPostScript=66272 # 0x102E0
2830 * --- Printer state modifiers for local printers
2835 * Unknown=3 # 0x3 (Faulted due to unknown reason)
2837 * --- Printer state modifiers for network printers
2841 * NetFaulted=10 # 0xA
2842 * NetUnknown=11 # 0xB (Faulted due to unknown reason)
2845 snprintf(filename
, sizeof(filename
), "/var/spool/lp/activeicons/%s", p
->name
);
2847 if (p
->type
& CUPS_PRINTER_CLASS
)
2849 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
2851 if (p
->type
& CUPS_PRINTER_COLOR
)
2856 if (p
->type
& CUPS_PRINTER_REMOTE
)
2859 if (p
->state
== IPP_PRINTER_PROCESSING
)
2862 else if (p
->state
== IPP_PRINTER_STOPPED
)
2865 cupsFilePuts(fp
, "#!/bin/sh\n");
2866 cupsFilePrintf(fp
, "#Tag %d\n", tag
);
2870 chmod(filename
, 0755);
2871 chown(filename
, User
, Group
);
2876 * The default file is needed by the printers window to show
2877 * the default printer.
2880 snprintf(filename
, sizeof(filename
), "/var/spool/lp/default");
2882 if (DefaultPrinter
!= NULL
)
2884 if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
2886 cupsFilePrintf(fp
, "%s\n", DefaultPrinter
->name
);
2890 chmod(filename
, 0644);
2891 chown(filename
, User
, Group
);
2901 * End of "$Id: printers.c 5047 2006-02-02 05:14:15Z mike $".