2 * "$Id: printers.c 4903 2006-01-10 20:02:46Z 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 printers.conf
37 * cupsdSetPrinterAttrs() - Set printer attributes based upon the PPD file.
38 * cupsdSetPrinterReasons() - Set/update the reasons strings.
39 * cupsdSetPrinterState() - Update the current state of a printer.
40 * cupsdStopPrinter() - Stop a printer from printing any jobs...
41 * cupsdUpdatePrinters() - Update printers after a partial reload.
42 * cupsdValidateDest() - Validate a printer/class destination.
43 * cupsdWritePrintcap() - Write a pseudo-printcap file for older
44 * applications that need it...
45 * cupsdSanitizeURI() - Sanitize a device URI...
46 * compare_printers() - Compare two printers.
47 * write_irix_config() - Update the config files used by the IRIX
49 * write_irix_state() - Update the status files used by IRIX printing
54 * Include necessary headers...
64 static int compare_printers(void *first
, void *second
, void *data
);
66 static void write_irix_config(cupsd_printer_t
*p
);
67 static void write_irix_state(cupsd_printer_t
*p
);
72 * 'cupsdAddPrinter()' - Add a printer to the system.
75 cupsd_printer_t
* /* O - New printer */
76 cupsdAddPrinter(const char *name
) /* I - Name of printer */
78 cupsd_printer_t
*p
; /* New printer */
82 * Range check input...
85 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdAddPrinter(\"%s\")", name
);
88 * Create a new printer entity...
91 if ((p
= calloc(1, sizeof(cupsd_printer_t
))) == NULL
)
93 cupsdLogMessage(CUPSD_LOG_CRIT
, "Unable to allocate memory for printer - %s",
98 cupsdSetString(&p
->name
, name
);
99 cupsdSetString(&p
->info
, name
);
100 cupsdSetString(&p
->hostname
, ServerName
);
102 cupsdSetStringf(&p
->uri
, "ipp://%s:%d/printers/%s", ServerName
, LocalPort
, name
);
103 cupsdSetStringf(&p
->device_uri
, "file:/dev/null");
105 p
->state
= IPP_PRINTER_STOPPED
;
106 p
->state_time
= time(NULL
);
109 p
->filetype
= mimeAddType(MimeDatabase
, "printer", name
);
111 cupsdSetString(&p
->job_sheets
[0], "none");
112 cupsdSetString(&p
->job_sheets
[1], "none");
114 cupsdSetString(&p
->error_policy
, "stop-printer");
115 cupsdSetString(&p
->op_policy
, DefaultPolicy
);
117 p
->op_policy_ptr
= DefaultPolicyPtr
;
119 if (MaxPrinterHistory
)
120 p
->history
= calloc(MaxPrinterHistory
, sizeof(ipp_t
*));
123 * Insert the printer in the printer list alphabetically...
127 Printers
= cupsArrayNew(compare_printers
, NULL
);
129 cupsArrayAdd(Printers
, p
);
131 if (!ImplicitPrinters
)
132 ImplicitPrinters
= cupsArrayNew(compare_printers
, NULL
);
135 * Return the new printer...
143 * 'cupsdAddPrinterFilter()' - Add a MIME filter for a printer.
147 cupsdAddPrinterFilter(
148 cupsd_printer_t
*p
, /* I - Printer to add to */
149 const char *filter
) /* I - Filter to add */
151 int i
; /* Looping var */
152 char super
[MIME_MAX_SUPER
], /* Super-type for filter */
153 type
[MIME_MAX_TYPE
], /* Type for filter */
154 program
[1024]; /* Program/filter name */
155 int cost
; /* Cost of filter */
156 mime_type_t
**temptype
; /* MIME type looping var */
160 * Range check input...
163 if (p
== NULL
|| p
->filetype
== NULL
|| filter
== NULL
)
167 * Parse the filter string; it should be in the following format:
169 * super/type cost program
172 if (sscanf(filter
, "%15[^/]/%31s%d%1023s", super
, type
, &cost
, program
) != 4)
174 cupsdLogMessage(CUPSD_LOG_ERROR
,
175 "cupsdAddPrinterFilter: Invalid filter string \"%s\"!",
181 * Add the filter to the MIME database, supporting wildcards as needed...
184 for (temptype
= MimeDatabase
->types
, i
= MimeDatabase
->num_types
;
187 if (((super
[0] == '*' && strcasecmp((*temptype
)->super
, "printer") != 0) ||
188 !strcasecmp((*temptype
)->super
, super
)) &&
189 (type
[0] == '*' || !strcasecmp((*temptype
)->type
, type
)))
191 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "Adding filter %s/%s %s/%s %d %s",
192 (*temptype
)->super
, (*temptype
)->type
,
193 p
->filetype
->super
, p
->filetype
->type
,
195 mimeAddFilter(MimeDatabase
, *temptype
, p
->filetype
, cost
, program
);
201 * 'cupsdAddPrinterHistory()' - Add the current printer state to the history.
205 cupsdAddPrinterHistory(
206 cupsd_printer_t
*p
) /* I - Printer */
208 ipp_t
*history
; /* History collection */
212 * Stop early if we aren't keeping history data...
215 if (MaxPrinterHistory
<= 0)
219 * Retire old history data as needed...
222 p
->sequence_number
++;
224 if (p
->num_history
>= MaxPrinterHistory
)
227 ippDelete(p
->history
[0]);
228 memmove(p
->history
, p
->history
+ 1, p
->num_history
* sizeof(ipp_t
*));
232 * Create a collection containing the current printer-state, printer-up-time,
233 * printer-state-message, and printer-state-reasons attributes.
237 ippAddInteger(history
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-state",
239 ippAddBoolean(history
, IPP_TAG_PRINTER
, "printer-is-accepting-jobs",
241 ippAddString(history
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-state-message",
242 NULL
, p
->state_message
);
243 if (p
->num_reasons
== 0)
244 ippAddString(history
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
245 "printer-state-reasons", NULL
,
246 p
->state
== IPP_PRINTER_STOPPED
? "paused" : "none");
248 ippAddStrings(history
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
249 "printer-state-reasons", p
->num_reasons
, NULL
,
250 (const char * const *)p
->reasons
);
251 ippAddInteger(history
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
252 "printer-state-change-time", p
->state_time
);
253 ippAddInteger(history
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
254 "printer-state-sequence-number", p
->sequence_number
);
256 p
->history
[p
->num_history
] = history
;
262 * 'cupsdAddPrinterUser()' - Add a user to the ACL.
267 cupsd_printer_t
*p
, /* I - Printer */
268 const char *username
) /* I - User */
270 const char **temp
; /* Temporary array pointer */
276 if (p
->num_users
== 0)
277 temp
= malloc(sizeof(char **));
279 temp
= realloc(p
->users
, sizeof(char **) * (p
->num_users
+ 1));
285 temp
+= p
->num_users
;
287 if ((*temp
= strdup(username
)) != NULL
)
293 * 'cupsdCreateCommonData()' - Create the common printer data.
297 cupsdCreateCommonData(void)
299 int i
; /* Looping var */
300 ipp_attribute_t
*attr
; /* Attribute data */
301 static const int nups
[] = /* number-up-supported values */
302 { 1, 2, 4, 6, 9, 16 };
303 static const ipp_orient_t orients
[4] =/* orientation-requested-supported values */
307 IPP_REVERSE_LANDSCAPE
,
310 static const char * const holds
[] = /* job-hold-until-supported values */
321 static const char * const versions
[] =/* ipp-versions-supported values */
326 static const ipp_op_t ops
[] = /* operations-supported values */
333 IPP_GET_JOB_ATTRIBUTES
,
335 IPP_GET_PRINTER_ATTRIBUTES
,
341 IPP_SET_JOB_ATTRIBUTES
,
342 IPP_CREATE_PRINTER_SUBSCRIPTION
,
343 IPP_CREATE_JOB_SUBSCRIPTION
,
344 IPP_GET_SUBSCRIPTION_ATTRIBUTES
,
345 IPP_GET_SUBSCRIPTIONS
,
346 IPP_RENEW_SUBSCRIPTION
,
347 IPP_CANCEL_SUBSCRIPTION
,
348 IPP_GET_NOTIFICATIONS
,
364 CUPS_AUTHENTICATE_JOB
,
367 static const char * const charsets
[] =/* charset-supported values */
372 static const char * const compressions
[] =
373 { /* document-compression-supported values */
377 #endif /* HAVE_LIBZ */
379 static const char * const multiple_document_handling
[] =
380 { /* multiple-document-handling-supported values */
381 "separate-documents-uncollated-copies",
382 "separate-documents-collated-copies"
384 static const char * const errors
[] = /* printer-error-policy-supported values */
390 static const char * const notify_attrs
[] =
391 { /* notify-attributes-supported values */
392 "printer-state-change-time",
393 "notify-lease-expiration-time",
394 "notify-subscriber-user-name"
396 static const char * const notify_events
[] =
397 { /* notify-events-supported values */
399 "job-config-changed",
406 "printer-config-changed",
408 "printer-finishings-changed",
409 "printer-media-changed",
413 "printer-state-changed",
423 ippDelete(CommonData
);
425 CommonData
= ippNew();
428 * This list of attributes is sorted to improve performance when the
429 * client provides a requested-attributes attribute...
432 /* charset-configured */
433 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_CHARSET
,
434 "charset-configured", NULL
, DefaultCharset
);
436 /* charset-supported */
437 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_CHARSET
,
438 "charset-supported", sizeof(charsets
) / sizeof(charsets
[0]),
441 /* compression-supported */
442 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
443 "compression-supported",
444 sizeof(compressions
) / sizeof(compressions
[0]),
447 /* TODO: move to printer-specific section! */
449 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
450 "copies-default", 1);
452 /* copies-supported */
453 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "copies-supported", 1, MaxCopies
);
455 /* TODO: move to printer-specific section! */
456 /* document-format-default */
457 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_MIMETYPE
,
458 "document-format-default", NULL
, "application/octet-stream");
460 /* document-format-supported */
461 ippAddStrings(CommonData
, IPP_TAG_PRINTER
,
462 (ipp_tag_t
)(IPP_TAG_MIMETYPE
| IPP_TAG_COPY
),
463 "document-format-supported", NumMimeTypes
, NULL
, MimeTypes
);
465 /* generated-natural-language-supported */
466 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_LANGUAGE
,
467 "generated-natural-language-supported", NULL
, DefaultLanguage
);
469 /* ipp-versions-supported */
470 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
471 "ipp-versions-supported", sizeof(versions
) / sizeof(versions
[0]),
474 /* TODO: move to printer-specific section! */
475 /* job-hold-until-default */
476 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
477 "job-hold-until-default", NULL
, "no-hold");
479 /* job-hold-until-supported */
480 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
481 "job-hold-until-supported", sizeof(holds
) / sizeof(holds
[0]),
484 /* TODO: move to printer-specific section! */
485 /* job-priority-default */
486 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
487 "job-priority-default", 50);
489 /* job-priority-supported */
490 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
491 "job-priority-supported", 100);
493 /* job-sheets-supported */
497 * Setup the job-sheets-supported attribute...
500 if (Classification
&& !ClassifyOverride
)
501 attr
= ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
502 "job-sheets-supported", NULL
, Classification
);
504 attr
= ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
505 "job-sheets-supported", NumBanners
+ 1, NULL
, NULL
);
508 cupsdLogMessage(CUPSD_LOG_EMERG
,
509 "cupsdSetPrinterAttrs: Unable to allocate memory for "
510 "job-sheets-supported attribute: %s!", strerror(errno
));
511 else if (!Classification
|| ClassifyOverride
)
513 attr
->values
[0].string
.text
= strdup("none");
515 for (i
= 0; i
< NumBanners
; i
++)
516 attr
->values
[i
+ 1].string
.text
= strdup(Banners
[i
].name
);
520 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
521 "job-sheets-supported", NULL
, "none");
523 /* multiple-document-handling-supported */
524 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
525 "multiple-document-handling-supported",
526 sizeof(multiple_document_handling
) /
527 sizeof(multiple_document_handling
[0]), NULL
,
528 multiple_document_handling
);
530 /* multiple-document-jobs-supported */
531 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
,
532 "multiple-document-jobs-supported", 1);
534 /* multiple-operation-time-out */
535 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
536 "multiple-operation-time-out", 60);
538 /* natural-language-configured */
539 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_LANGUAGE
,
540 "natural-language-configured", NULL
, DefaultLanguage
);
542 /* notify-attributes-supported */
543 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
544 "notify-attributes-supported",
545 (int)(sizeof(notify_attrs
) / sizeof(notify_attrs
[0])),
548 /* TODO: move to printer-specific section! */
549 /* notify-lease-duration-default */
550 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
551 "notify-lease-duration-default", DefaultLeaseDuration
);
553 /* notify-lease-duration-supported */
554 ippAddRange(CommonData
, IPP_TAG_PRINTER
,
555 "notify-lease-duration-supported", 0,
556 MaxLeaseDuration
? MaxLeaseDuration
: 2147483647);
558 /* notify-max-events-supported */
559 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
560 "notify-max-events-supported", MaxEvents
);
562 /* notify-notify-events-default */
563 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
564 "notify-events-default", NULL
, "job-completed");
566 /* notify-notify-events-supported */
567 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
568 "notify-events-supported",
569 (int)(sizeof(notify_events
) / sizeof(notify_events
[0])),
570 NULL
, notify_events
);
572 /* notify-pull-method-supported */
573 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
574 "notify-pull-method-supported", NULL
, "ippget");
576 /* TODO: scan notifier directory */
577 /* notify-schemes-supported */
578 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
579 "notify-schemes-supported", NULL
, "mailto");
581 /* TODO: move to printer-specific section! */
582 /* number-up-default */
583 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
584 "number-up-default", 1);
586 /* number-up-supported */
587 ippAddIntegers(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
588 "number-up-supported", sizeof(nups
) / sizeof(nups
[0]), nups
);
590 /* operations-supported */
591 ippAddIntegers(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
592 "operations-supported",
593 sizeof(ops
) / sizeof(ops
[0]) + JobFiles
- 1, (int *)ops
);
595 /* TODO: move to printer-specific section! */
596 /* orientation-requested-default */
597 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
598 "orientation-requested-default", IPP_PORTRAIT
);
600 /* orientation-requested-supported */
601 ippAddIntegers(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
602 "orientation-requested-supported", 4, (int *)orients
);
604 /* page-ranges-supported */
605 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
, "page-ranges-supported", 1);
607 /* pdf-override-supported */
608 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
609 "pdl-override-supported", NULL
, "not-attempted");
611 /* printer-error-policy-supported */
612 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
613 "printer-error-policy-supported",
614 sizeof(errors
) / sizeof(errors
[0]), NULL
, errors
);
616 /* printer-op-policy-supported */
617 attr
= ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
618 "printer-op-policy-supported", NumPolicies
, NULL
, NULL
);
619 for (i
= 0; i
< NumPolicies
; i
++)
620 attr
->values
[i
].string
.text
= strdup(Policies
[i
]->name
);
625 * 'cupsdDeleteAllPrinters()' - Delete all printers from the system.
629 cupsdDeleteAllPrinters(void)
631 cupsd_printer_t
*p
; /* Pointer to current printer/class */
634 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
636 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
637 if (!(p
->type
& CUPS_PRINTER_CLASS
))
638 cupsdDeletePrinter(p
, 0);
643 * 'cupsdDeletePrinter()' - Delete a printer from the system.
648 cupsd_printer_t
*p
, /* I - Printer to delete */
649 int update
) /* I - Update printers.conf? */
651 int i
; /* Looping var */
653 char filename
[1024]; /* Interface script filename */
657 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdDeletePrinter(p=%p(%s), update=%d)",
661 * Save the current position in the Printers array...
664 cupsArraySave(Printers
);
667 * Stop printing on this printer...
670 cupsdStopPrinter(p
, update
);
673 * If this printer is the next for browsing, point to the next one...
678 cupsArrayFind(Printers
, p
);
679 BrowseNext
= (cupsd_printer_t
*)cupsArrayNext(Printers
);
683 * Remove the printer from the list...
686 cupsArrayRemove(Printers
, p
);
689 * Remove the dummy interface/icon/option files under IRIX...
693 snprintf(filename
, sizeof(filename
), "/var/spool/lp/interface/%s", p
->name
);
696 snprintf(filename
, sizeof(filename
), "/var/spool/lp/gui_interface/ELF/%s.gui",
700 snprintf(filename
, sizeof(filename
), "/var/spool/lp/activeicons/%s", p
->name
);
703 snprintf(filename
, sizeof(filename
), "/var/spool/lp/pod/%s.config", p
->name
);
706 snprintf(filename
, sizeof(filename
), "/var/spool/lp/pod/%s.status", p
->name
);
709 snprintf(filename
, sizeof(filename
), "/var/spool/lp/member/%s", p
->name
);
714 * If p is the default printer, assign the next one...
717 if (p
== DefaultPrinter
)
718 DefaultPrinter
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
721 * Remove this printer from any classes and send a browse delete message...
724 if (!(p
->type
& CUPS_PRINTER_IMPLICIT
))
726 cupsdDeletePrinterFromClasses(p
);
727 cupsdSendBrowseDelete(p
);
731 * Free all memory used by the printer...
734 if (p
->printers
!= NULL
)
737 if (MaxPrinterHistory
)
739 for (i
= 0; i
< p
->num_history
; i
++)
740 ippDelete(p
->history
[i
]);
745 for (i
= 0; i
< p
->num_reasons
; i
++)
750 cupsdDeletePrinterFilters(p
);
752 cupsdFreePrinterUsers(p
);
755 cupsdClearString(&p
->uri
);
756 cupsdClearString(&p
->hostname
);
757 cupsdClearString(&p
->name
);
758 cupsdClearString(&p
->location
);
759 cupsdClearString(&p
->make_model
);
760 cupsdClearString(&p
->info
);
761 cupsdClearString(&p
->job_sheets
[0]);
762 cupsdClearString(&p
->job_sheets
[1]);
763 cupsdClearString(&p
->device_uri
);
764 cupsdClearString(&p
->port_monitor
);
765 cupsdClearString(&p
->op_policy
);
766 cupsdClearString(&p
->error_policy
);
771 * Restore the previous position in the Printers array...
774 cupsArrayRestore(Printers
);
779 * 'cupsdDeletePrinterFilters()' - Delete all MIME filters for a printer.
783 cupsdDeletePrinterFilters(
784 cupsd_printer_t
*p
) /* I - Printer to remove from */
786 int i
; /* Looping var */
787 mime_filter_t
*filter
; /* MIME filter looping var */
791 * Range check input...
798 * Remove all filters from the MIME database that have a destination
802 for (filter
= MimeDatabase
->filters
, i
= MimeDatabase
->num_filters
;
805 if (filter
->dst
== p
->filetype
)
808 * Delete the current filter...
811 MimeDatabase
->num_filters
--;
814 memmove(filter
, filter
+ 1, sizeof(mime_filter_t
) * (i
- 1));
822 * 'cupsdFindDest()' - Find a destination in the list.
825 cupsd_printer_t
* /* O - Destination in list */
826 cupsdFindDest(const char *name
) /* I - Name of printer or class to find */
828 cupsd_printer_t key
; /* Search key */
831 key
.name
= (char *)name
;
832 return ((cupsd_printer_t
*)cupsArrayFind(Printers
, &key
));
837 * 'cupsdFindPrinter()' - Find a printer in the list.
840 cupsd_printer_t
* /* O - Printer in list */
841 cupsdFindPrinter(const char *name
) /* I - Name of printer to find */
843 cupsd_printer_t
*p
; /* Printer in list */
846 if ((p
= cupsdFindDest(name
)) != NULL
&& (p
->type
& CUPS_PRINTER_CLASS
))
854 * 'cupsdFreePrinterUsers()' - Free allow/deny users.
858 cupsdFreePrinterUsers(
859 cupsd_printer_t
*p
) /* I - Printer */
861 int i
; /* Looping var */
864 if (!p
|| !p
->num_users
)
867 for (i
= 0; i
< p
->num_users
; i
++)
868 free((void *)p
->users
[i
]);
878 * 'cupsdLoadAllPrinters()' - Load printers from the printers.conf file.
882 cupsdLoadAllPrinters(void)
884 cups_file_t
*fp
; /* printers.conf file */
885 int linenum
; /* Current line number */
886 char line
[1024], /* Line from file */
887 *value
, /* Pointer to value */
888 *valueptr
; /* Pointer into value */
889 cupsd_printer_t
*p
; /* Current printer */
893 * Open the printers.conf file...
896 snprintf(line
, sizeof(line
), "%s/printers.conf", ServerRoot
);
897 if ((fp
= cupsFileOpen(line
, "r")) == NULL
)
899 cupsdLogMessage(CUPSD_LOG_ERROR
,
900 "cupsdLoadAllPrinters: Unable to open %s - %s", line
,
906 * Read printer configurations until we hit EOF...
912 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
915 * Decode the directive...
918 if (!strcasecmp(line
, "<Printer") ||
919 !strcasecmp(line
, "<DefaultPrinter"))
922 * <Printer name> or <DefaultPrinter name>
925 if (p
== NULL
&& value
)
928 * Add the printer and a base file type...
931 cupsdLogMessage(CUPSD_LOG_DEBUG
,
932 "cupsdLoadAllPrinters: Loading printer %s...", value
);
934 p
= cupsdAddPrinter(value
);
936 p
->state
= IPP_PRINTER_IDLE
;
939 * Set the default printer as needed...
942 if (!strcasecmp(line
, "<DefaultPrinter"))
947 cupsdLogMessage(CUPSD_LOG_ERROR
,
948 "Syntax error on line %d of printers.conf.", linenum
);
952 else if (!strcasecmp(line
, "</Printer>"))
957 * Close out the current printer...
960 cupsdSetPrinterAttrs(p
);
961 cupsdAddPrinterHistory(p
);
963 if (p
->device_uri
&& strncmp(p
->device_uri
, "file:", 5) &&
964 p
->state
!= IPP_PRINTER_STOPPED
)
967 * See if the backend exists...
970 snprintf(line
, sizeof(line
), "%s/backend/%s", ServerBin
,
973 if ((valueptr
= strchr(line
+ strlen(ServerBin
), ':')) != NULL
)
974 *valueptr
= '\0'; /* Chop everything but URI scheme */
979 * Backend does not exist, stop printer...
982 p
->state
= IPP_PRINTER_STOPPED
;
983 snprintf(p
->state_message
, sizeof(p
->state_message
),
984 "Backend %s does not exist!", line
);
992 cupsdLogMessage(CUPSD_LOG_ERROR
,
993 "Syntax error on line %d of printers.conf.", linenum
);
999 cupsdLogMessage(CUPSD_LOG_ERROR
,
1000 "Syntax error on line %d of printers.conf.", linenum
);
1003 else if (!strcasecmp(line
, "Info"))
1006 cupsdSetString(&p
->info
, value
);
1008 else if (!strcasecmp(line
, "Location"))
1011 cupsdSetString(&p
->location
, value
);
1013 else if (!strcasecmp(line
, "DeviceURI"))
1016 cupsdSetString(&p
->device_uri
, value
);
1019 cupsdLogMessage(CUPSD_LOG_ERROR
,
1020 "Syntax error on line %d of printers.conf.", linenum
);
1024 else if (!strcasecmp(line
, "PortMonitor"))
1026 if (value
&& strcmp(value
, "none"))
1027 cupsdSetString(&p
->port_monitor
, value
);
1029 cupsdClearString(&p
->port_monitor
);
1032 cupsdLogMessage(CUPSD_LOG_ERROR
,
1033 "Syntax error on line %d of printers.conf.", linenum
);
1037 else if (!strcasecmp(line
, "State"))
1040 * Set the initial queue state...
1043 if (value
&& !strcasecmp(value
, "idle"))
1044 p
->state
= IPP_PRINTER_IDLE
;
1045 else if (value
&& !strcasecmp(value
, "stopped"))
1046 p
->state
= IPP_PRINTER_STOPPED
;
1049 cupsdLogMessage(CUPSD_LOG_ERROR
,
1050 "Syntax error on line %d of printers.conf.", linenum
);
1054 else if (!strcasecmp(line
, "StateMessage"))
1057 * Set the initial queue state message...
1061 strlcpy(p
->state_message
, value
, sizeof(p
->state_message
));
1063 else if (!strcasecmp(line
, "StateTime"))
1066 * Set the state time...
1070 p
->state_time
= atoi(value
);
1072 else if (!strcasecmp(line
, "Accepting"))
1075 * Set the initial accepting state...
1079 (!strcasecmp(value
, "yes") ||
1080 !strcasecmp(value
, "on") ||
1081 !strcasecmp(value
, "true")))
1084 (!strcasecmp(value
, "no") ||
1085 !strcasecmp(value
, "off") ||
1086 !strcasecmp(value
, "false")))
1090 cupsdLogMessage(CUPSD_LOG_ERROR
,
1091 "Syntax error on line %d of printers.conf.", linenum
);
1095 else if (!strcasecmp(line
, "Shared"))
1098 * Set the initial shared state...
1102 (!strcasecmp(value
, "yes") ||
1103 !strcasecmp(value
, "on") ||
1104 !strcasecmp(value
, "true")))
1107 (!strcasecmp(value
, "no") ||
1108 !strcasecmp(value
, "off") ||
1109 !strcasecmp(value
, "false")))
1113 cupsdLogMessage(CUPSD_LOG_ERROR
,
1114 "Syntax error on line %d of printers.conf.", linenum
);
1118 else if (!strcasecmp(line
, "JobSheets"))
1121 * Set the initial job sheets...
1126 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1131 cupsdSetString(&p
->job_sheets
[0], value
);
1133 while (isspace(*valueptr
& 255))
1138 for (value
= valueptr
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1143 cupsdSetString(&p
->job_sheets
[1], value
);
1148 cupsdLogMessage(CUPSD_LOG_ERROR
,
1149 "Syntax error on line %d of printers.conf.", linenum
);
1153 else if (!strcasecmp(line
, "AllowUser"))
1158 cupsdAddPrinterUser(p
, value
);
1162 cupsdLogMessage(CUPSD_LOG_ERROR
,
1163 "Syntax error on line %d of printers.conf.", linenum
);
1167 else if (!strcasecmp(line
, "DenyUser"))
1172 cupsdAddPrinterUser(p
, value
);
1176 cupsdLogMessage(CUPSD_LOG_ERROR
,
1177 "Syntax error on line %d of printers.conf.", linenum
);
1181 else if (!strcasecmp(line
, "QuotaPeriod"))
1184 p
->quota_period
= atoi(value
);
1187 cupsdLogMessage(CUPSD_LOG_ERROR
,
1188 "Syntax error on line %d of printers.conf.", linenum
);
1192 else if (!strcasecmp(line
, "PageLimit"))
1195 p
->page_limit
= atoi(value
);
1198 cupsdLogMessage(CUPSD_LOG_ERROR
,
1199 "Syntax error on line %d of printers.conf.", linenum
);
1203 else if (!strcasecmp(line
, "KLimit"))
1206 p
->k_limit
= atoi(value
);
1209 cupsdLogMessage(CUPSD_LOG_ERROR
,
1210 "Syntax error on line %d of printers.conf.", linenum
);
1214 else if (!strcasecmp(line
, "OpPolicy"))
1217 cupsdSetString(&p
->op_policy
, value
);
1220 cupsdLogMessage(CUPSD_LOG_ERROR
,
1221 "Syntax error on line %d of printers.conf.", linenum
);
1225 else if (!strcasecmp(line
, "ErrorPolicy"))
1228 cupsdSetString(&p
->error_policy
, value
);
1231 cupsdLogMessage(CUPSD_LOG_ERROR
,
1232 "Syntax error on line %d of printers.conf.", linenum
);
1239 * Something else we don't understand...
1242 cupsdLogMessage(CUPSD_LOG_ERROR
,
1243 "Unknown configuration directive %s on line %d of printers.conf.",
1253 * 'cupsdSaveAllPrinters()' - Save all printer definitions to the printers.conf
1258 cupsdSaveAllPrinters(void)
1260 int i
; /* Looping var */
1261 cups_file_t
*fp
; /* printers.conf file */
1262 char temp
[1024]; /* Temporary string */
1263 char backup
[1024]; /* printers.conf.O file */
1264 cupsd_printer_t
*printer
; /* Current printer class */
1265 time_t curtime
; /* Current time */
1266 struct tm
*curdate
; /* Current date */
1270 * Create the printers.conf file...
1273 snprintf(temp
, sizeof(temp
), "%s/printers.conf", ServerRoot
);
1274 snprintf(backup
, sizeof(backup
), "%s/printers.conf.O", ServerRoot
);
1276 if (rename(temp
, backup
))
1278 if (errno
!= ENOENT
)
1279 cupsdLogMessage(CUPSD_LOG_ERROR
,
1280 "Unable to backup printers.conf - %s", strerror(errno
));
1283 if ((fp
= cupsFileOpen(temp
, "w")) == NULL
)
1285 cupsdLogMessage(CUPSD_LOG_ERROR
,
1286 "Unable to save printers.conf - %s", strerror(errno
));
1288 if (rename(backup
, temp
))
1289 cupsdLogMessage(CUPSD_LOG_ERROR
,
1290 "Unable to restore printers.conf - %s", strerror(errno
));
1294 cupsdLogMessage(CUPSD_LOG_INFO
, "Saving printers.conf...");
1297 * Restrict access to the file...
1300 fchown(cupsFileNumber(fp
), getuid(), Group
);
1301 fchmod(cupsFileNumber(fp
), ConfigFilePerm
);
1304 * Write a small header to the file...
1307 curtime
= time(NULL
);
1308 curdate
= localtime(&curtime
);
1309 strftime(temp
, sizeof(temp
) - 1, "%Y-%m-%d %H:%M", curdate
);
1311 cupsFilePuts(fp
, "# Printer configuration file for " CUPS_SVERSION
"\n");
1312 cupsFilePrintf(fp
, "# Written by cupsd on %s\n", temp
);
1315 * Write each local printer known to the system...
1318 for (printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
1320 printer
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
1323 * Skip remote destinations and printer classes...
1326 if ((printer
->type
& CUPS_PRINTER_REMOTE
) ||
1327 (printer
->type
& CUPS_PRINTER_CLASS
) ||
1328 (printer
->type
& CUPS_PRINTER_IMPLICIT
))
1332 * Write printers as needed...
1335 if (printer
== DefaultPrinter
)
1336 cupsFilePrintf(fp
, "<DefaultPrinter %s>\n", printer
->name
);
1338 cupsFilePrintf(fp
, "<Printer %s>\n", printer
->name
);
1341 cupsFilePrintf(fp
, "Info %s\n", printer
->info
);
1343 if (printer
->location
)
1344 cupsFilePrintf(fp
, "Location %s\n", printer
->location
);
1346 if (printer
->device_uri
)
1347 cupsFilePrintf(fp
, "DeviceURI %s\n", printer
->device_uri
);
1349 if (printer
->port_monitor
)
1350 cupsFilePrintf(fp
, "PortMonitor %s\n", printer
->port_monitor
);
1352 if (printer
->state
== IPP_PRINTER_STOPPED
)
1354 cupsFilePuts(fp
, "State Stopped\n");
1355 cupsFilePrintf(fp
, "StateMessage %s\n", printer
->state_message
);
1358 cupsFilePuts(fp
, "State Idle\n");
1360 cupsFilePrintf(fp
, "StateTime %d\n", (int)printer
->state_time
);
1362 if (printer
->accepting
)
1363 cupsFilePuts(fp
, "Accepting Yes\n");
1365 cupsFilePuts(fp
, "Accepting No\n");
1367 if (printer
->shared
)
1368 cupsFilePuts(fp
, "Shared Yes\n");
1370 cupsFilePuts(fp
, "Shared No\n");
1372 cupsFilePrintf(fp
, "JobSheets %s %s\n", printer
->job_sheets
[0],
1373 printer
->job_sheets
[1]);
1375 cupsFilePrintf(fp
, "QuotaPeriod %d\n", printer
->quota_period
);
1376 cupsFilePrintf(fp
, "PageLimit %d\n", printer
->page_limit
);
1377 cupsFilePrintf(fp
, "KLimit %d\n", printer
->k_limit
);
1379 for (i
= 0; i
< printer
->num_users
; i
++)
1380 cupsFilePrintf(fp
, "%sUser %s\n", printer
->deny_users
? "Deny" : "Allow",
1383 if (printer
->op_policy
)
1384 cupsFilePrintf(fp
, "OpPolicy %s\n", printer
->op_policy
);
1385 if (printer
->error_policy
)
1386 cupsFilePrintf(fp
, "ErrorPolicy %s\n", printer
->error_policy
);
1388 cupsFilePuts(fp
, "</Printer>\n");
1392 * Make IRIX desktop & printer status happy
1395 write_irix_state(printer
);
1404 * 'cupsdSetPrinterAttrs()' - Set printer attributes based upon the PPD file.
1408 cupsdSetPrinterAttrs(cupsd_printer_t
*p
)/* I - Printer to setup */
1410 char uri
[HTTP_MAX_URI
];
1411 /* URI for printer */
1412 char resource
[HTTP_MAX_URI
];
1413 /* Resource portion of URI */
1414 int i
; /* Looping var */
1415 char filename
[1024]; /* Name of PPD file */
1416 int num_media
; /* Number of media options */
1417 cupsd_location_t
*auth
; /* Pointer to authentication element */
1418 const char *auth_supported
;/* Authentication supported */
1419 cups_ptype_t cupsd_printer_type
;
1420 /* Printer type data */
1421 ppd_file_t
*ppd
; /* PPD file data */
1422 ppd_option_t
*input_slot
, /* InputSlot options */
1423 *media_type
, /* MediaType options */
1424 *page_size
, /* PageSize options */
1425 *output_bin
, /* OutputBin options */
1426 *media_quality
; /* EFMediaQualityMode options */
1427 ppd_attr_t
*ppdattr
; /* PPD attribute */
1428 ipp_attribute_t
*attr
; /* Attribute data */
1429 ipp_value_t
*val
; /* Attribute value */
1430 int num_finishings
; /* Number of finishings */
1431 ipp_finish_t finishings
[5]; /* finishings-supported values */
1432 static const char * const sides
[3] = /* sides-supported values */
1440 DEBUG_printf(("cupsdSetPrinterAttrs: entering name = %s, type = %x\n", p
->name
,
1444 * Make sure that we have the common attributes defined...
1448 cupsdCreateCommonData();
1451 * Clear out old filters, if any...
1454 cupsdDeletePrinterFilters(p
);
1457 * Figure out the authentication that is required for the printer.
1460 auth_supported
= "requesting-user-name";
1461 if (!(p
->type
& CUPS_PRINTER_REMOTE
))
1463 if (p
->type
& CUPS_PRINTER_CLASS
)
1464 snprintf(resource
, sizeof(resource
), "/classes/%s", p
->name
);
1466 snprintf(resource
, sizeof(resource
), "/printers/%s", p
->name
);
1468 if ((auth
= cupsdFindBest(resource
, HTTP_POST
)) == NULL
)
1469 auth
= cupsdFindPolicyOp(p
->op_policy_ptr
, IPP_PRINT_JOB
);
1473 if (auth
->type
== AUTH_BASIC
|| auth
->type
== AUTH_BASICDIGEST
)
1474 auth_supported
= "basic";
1475 else if (auth
->type
== AUTH_DIGEST
)
1476 auth_supported
= "digest";
1478 if (auth
->type
!= AUTH_NONE
)
1479 p
->type
|= CUPS_PRINTER_AUTHENTICATED
;
1481 p
->type
&= ~CUPS_PRINTER_AUTHENTICATED
;
1484 p
->type
&= ~CUPS_PRINTER_AUTHENTICATED
;
1488 * Create the required IPP attributes for a printer...
1492 ippDelete(p
->attrs
);
1494 p
->attrs
= ippNew();
1496 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
1497 "uri-authentication-supported", NULL
, auth_supported
);
1498 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
1499 "uri-security-supported", NULL
, "none");
1500 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
, "printer-name", NULL
,
1502 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-location",
1503 NULL
, p
->location
? p
->location
: "");
1504 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-info",
1505 NULL
, p
->info
? p
->info
: "");
1506 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "printer-more-info",
1512 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
1513 "requesting-user-name-denied", p
->num_users
, NULL
,
1516 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
1517 "requesting-user-name-allowed", p
->num_users
, NULL
,
1521 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
1522 "job-quota-period", p
->quota_period
);
1523 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
1524 "job-k-limit", p
->k_limit
);
1525 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
1526 "job-page-limit", p
->page_limit
);
1528 if (NumBanners
> 0 && !(p
->type
& CUPS_PRINTER_REMOTE
))
1531 * Setup the job-sheets-default attribute...
1534 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
1535 "job-sheets-default", 2, NULL
, NULL
);
1539 attr
->values
[0].string
.text
= strdup(Classification
?
1540 Classification
: p
->job_sheets
[0]);
1541 attr
->values
[1].string
.text
= strdup(Classification
?
1542 Classification
: p
->job_sheets
[1]);
1546 cupsd_printer_type
= p
->type
;
1550 if (p
->type
& CUPS_PRINTER_REMOTE
)
1553 * Tell the client this is a remote printer of some type...
1556 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
1557 "printer-uri-supported", NULL
, p
->uri
);
1560 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
1561 "printer-make-and-model", NULL
, p
->make_model
);
1568 * Assign additional attributes depending on whether this is a printer
1572 p
->type
&= ~CUPS_PRINTER_OPTIONS
;
1574 if (p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
))
1579 * Add class-specific attributes...
1582 if ((p
->type
& CUPS_PRINTER_IMPLICIT
) && p
->num_printers
> 0 &&
1583 p
->printers
[0]->make_model
)
1584 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
1585 "printer-make-and-model", NULL
, p
->printers
[0]->make_model
);
1587 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
1588 "printer-make-and-model", NULL
, "Local Printer Class");
1590 if (p
->num_printers
> 0)
1593 * Add a list of member URIs and names...
1596 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
1597 "member-uris", p
->num_printers
, NULL
, NULL
);
1598 p
->type
|= CUPS_PRINTER_OPTIONS
;
1600 for (i
= 0; i
< p
->num_printers
; i
++)
1603 attr
->values
[i
].string
.text
= strdup(p
->printers
[i
]->uri
);
1605 p
->type
&= ~CUPS_PRINTER_OPTIONS
| p
->printers
[i
]->type
;
1608 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
1609 "member-names", p
->num_printers
, NULL
, NULL
);
1613 for (i
= 0; i
< p
->num_printers
; i
++)
1614 attr
->values
[i
].string
.text
= strdup(p
->printers
[i
]->name
);
1621 * Add printer-specific attributes... Start by sanitizing the device
1622 * URI so it doesn't have a username or password in it...
1626 strcpy(uri
, "file:/dev/null");
1627 else if (strstr(p
->device_uri
, "://") != NULL
)
1630 * http://..., ipp://..., etc.
1633 cupsdSanitizeURI(p
->device_uri
, uri
, sizeof(uri
));
1638 * file:..., serial:..., etc.
1641 strlcpy(uri
, p
->device_uri
, sizeof(uri
));
1644 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "device-uri", NULL
,
1648 * Assign additional attributes from the PPD file (if any)...
1651 p
->type
|= CUPS_PRINTER_BW
;
1652 finishings
[0] = IPP_FINISHINGS_NONE
;
1655 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
1658 if ((ppd
= ppdOpenFile(filename
)) != NULL
)
1661 * Add make/model and other various attributes...
1664 if (ppd
->color_device
)
1665 p
->type
|= CUPS_PRINTER_COLOR
;
1666 if (ppd
->variable_sizes
)
1667 p
->type
|= CUPS_PRINTER_VARIABLE
;
1668 if (!ppd
->manual_copies
)
1669 p
->type
|= CUPS_PRINTER_COPIES
;
1670 if ((ppdattr
= ppdFindAttr(ppd
, "cupsFax", NULL
)) != NULL
)
1671 if (ppdattr
->value
&& !strcasecmp(ppdattr
->value
, "true"))
1672 p
->type
|= CUPS_PRINTER_FAX
;
1674 ippAddBoolean(p
->attrs
, IPP_TAG_PRINTER
, "color-supported",
1676 if (ppd
->throughput
)
1677 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
1678 "pages-per-minute", ppd
->throughput
);
1681 cupsdSetString(&p
->make_model
, ppd
->nickname
);
1682 else if (ppd
->modelname
)
1683 cupsdSetString(&p
->make_model
, ppd
->modelname
);
1685 cupsdSetString(&p
->make_model
, "Bad PPD File");
1688 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
1689 "printer-make-and-model", NULL
, p
->make_model
);
1692 * Add media options from the PPD file...
1695 if ((input_slot
= ppdFindOption(ppd
, "InputSlot")) != NULL
)
1696 num_media
= input_slot
->num_choices
;
1700 if ((media_type
= ppdFindOption(ppd
, "MediaType")) != NULL
)
1701 num_media
+= media_type
->num_choices
;
1703 if ((page_size
= ppdFindOption(ppd
, "PageSize")) != NULL
)
1704 num_media
+= page_size
->num_choices
;
1706 if ((media_quality
= ppdFindOption(ppd
, "EFMediaQualityMode")) != NULL
)
1707 num_media
+= media_quality
->num_choices
;
1711 cupsdLogMessage(CUPSD_LOG_CRIT
, "cupsdSetPrinterAttrs: The PPD file for printer %s "
1712 "contains no media options and is therefore "
1713 "invalid!", p
->name
);
1717 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
1718 "media-supported", num_media
, NULL
, NULL
);
1723 if (input_slot
!= NULL
)
1724 for (i
= 0; i
< input_slot
->num_choices
; i
++, val
++)
1725 val
->string
.text
= strdup(input_slot
->choices
[i
].choice
);
1727 if (media_type
!= NULL
)
1728 for (i
= 0; i
< media_type
->num_choices
; i
++, val
++)
1729 val
->string
.text
= strdup(media_type
->choices
[i
].choice
);
1731 if (media_quality
!= NULL
)
1732 for (i
= 0; i
< media_quality
->num_choices
; i
++, val
++)
1733 val
->string
.text
= strdup(media_quality
->choices
[i
].choice
);
1735 if (page_size
!= NULL
)
1737 for (i
= 0; i
< page_size
->num_choices
; i
++, val
++)
1738 val
->string
.text
= strdup(page_size
->choices
[i
].choice
);
1740 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
, "media-default",
1741 NULL
, page_size
->defchoice
);
1743 else if (input_slot
!= NULL
)
1744 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
, "media-default",
1745 NULL
, input_slot
->defchoice
);
1746 else if (media_type
!= NULL
)
1747 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
, "media-default",
1748 NULL
, media_type
->defchoice
);
1749 else if (media_quality
!= NULL
)
1750 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
, "media-default",
1751 NULL
, media_quality
->defchoice
);
1753 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
, "media-default",
1762 if ((output_bin
= ppdFindOption(ppd
, "OutputBin")) != NULL
)
1764 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
1765 "output-bin-supported", output_bin
->num_choices
,
1770 for (i
= 0, val
= attr
->values
;
1771 i
< output_bin
->num_choices
;
1773 val
->string
.text
= strdup(output_bin
->choices
[i
].choice
);
1781 if (ppdFindOption(ppd
, "Duplex") != NULL
)
1783 p
->type
|= CUPS_PRINTER_DUPLEX
;
1785 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
, "sides-supported",
1787 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
, "sides-default",
1791 if (ppdFindOption(ppd
, "Collate") != NULL
)
1792 p
->type
|= CUPS_PRINTER_COLLATE
;
1794 if (ppdFindOption(ppd
, "StapleLocation") != NULL
)
1796 p
->type
|= CUPS_PRINTER_STAPLE
;
1797 finishings
[num_finishings
++] = IPP_FINISHINGS_STAPLE
;
1800 if (ppdFindOption(ppd
, "BindEdge") != NULL
)
1802 p
->type
|= CUPS_PRINTER_BIND
;
1803 finishings
[num_finishings
++] = IPP_FINISHINGS_BIND
;
1806 for (i
= 0; i
< ppd
->num_sizes
; i
++)
1807 if (ppd
->sizes
[i
].length
> 1728)
1808 p
->type
|= CUPS_PRINTER_LARGE
;
1809 else if (ppd
->sizes
[i
].length
> 1008)
1810 p
->type
|= CUPS_PRINTER_MEDIUM
;
1812 p
->type
|= CUPS_PRINTER_SMALL
;
1815 * Add a filter from application/vnd.cups-raw to printer/name to
1816 * handle "raw" printing by users.
1819 cupsdAddPrinterFilter(p
, "application/vnd.cups-raw 0 -");
1822 * Add any filters in the PPD file...
1825 DEBUG_printf(("ppd->num_filters = %d\n", ppd
->num_filters
));
1826 for (i
= 0; i
< ppd
->num_filters
; i
++)
1828 DEBUG_printf(("ppd->filters[%d] = \"%s\"\n", i
, ppd
->filters
[i
]));
1829 cupsdAddPrinterFilter(p
, ppd
->filters
[i
]);
1832 if (ppd
->num_filters
== 0)
1835 * If there are no filters, add a PostScript printing filter.
1838 cupsdAddPrinterFilter(p
, "application/vnd.cups-postscript 0 -");
1842 * Show current and available port monitors for this printer...
1845 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
, "port-monitor",
1846 NULL
, p
->port_monitor
? p
->port_monitor
: "none");
1849 for (i
= 1, ppdattr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
1851 i
++, ppdattr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
));
1855 if (strstr(ppd
->protocols
, "TBCP"))
1857 else if (strstr(ppd
->protocols
, "BCP"))
1861 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
1862 "port-monitor-supported", i
, NULL
, NULL
);
1864 attr
->values
[0].string
.text
= strdup("none");
1866 for (i
= 1, ppdattr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
1868 i
++, ppdattr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
))
1869 attr
->values
[i
].string
.text
= strdup(ppdattr
->value
);
1873 if (strstr(ppd
->protocols
, "TBCP"))
1874 attr
->values
[i
].string
.text
= strdup("tbcp");
1875 else if (strstr(ppd
->protocols
, "BCP"))
1876 attr
->values
[i
].string
.text
= strdup("bcp");
1880 * Close the PPD and set the type...
1885 cupsd_printer_type
= p
->type
;
1887 else if (!access(filename
, 0))
1889 int pline
; /* PPD line number */
1890 ppd_status_t pstatus
; /* PPD load status */
1893 pstatus
= ppdLastError(&pline
);
1895 cupsdLogMessage(CUPSD_LOG_ERROR
, "PPD file for %s cannot be loaded!", p
->name
);
1897 if (pstatus
<= PPD_ALLOC_ERROR
)
1898 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s", strerror(errno
));
1900 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s on line %d.", ppdErrorString(pstatus
),
1903 cupsdLogMessage(CUPSD_LOG_INFO
, "Hint: Run \"cupstestppd %s\" and fix any errors.",
1907 * Add a filter from application/vnd.cups-raw to printer/name to
1908 * handle "raw" printing by users.
1911 cupsdAddPrinterFilter(p
, "application/vnd.cups-raw 0 -");
1914 * Add a PostScript filter, since this is still possibly PS printer.
1917 cupsdAddPrinterFilter(p
, "application/vnd.cups-postscript 0 -");
1922 * If we have an interface script, add a filter entry for it...
1925 snprintf(filename
, sizeof(filename
), "%s/interfaces/%s", ServerRoot
,
1927 if (access(filename
, X_OK
) == 0)
1930 * Yes, we have a System V style interface script; use it!
1933 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
1934 "printer-make-and-model", NULL
, "Local System V Printer");
1936 snprintf(filename
, sizeof(filename
), "*/* 0 %s/interfaces/%s",
1937 ServerRoot
, p
->name
);
1938 cupsdAddPrinterFilter(p
, filename
);
1940 else if (p
->device_uri
&&
1941 !strncmp(p
->device_uri
, "ipp://", 6) &&
1942 (strstr(p
->device_uri
, "/printers/") != NULL
||
1943 strstr(p
->device_uri
, "/classes/") != NULL
))
1946 * Tell the client this is really a hard-wired remote printer.
1949 cupsd_printer_type
|= CUPS_PRINTER_REMOTE
;
1952 * Point the printer-uri-supported attribute to the
1956 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
1957 "printer-uri-supported", NULL
, p
->device_uri
);
1960 * Then set the make-and-model accordingly...
1963 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
1964 "printer-make-and-model", NULL
, "Remote Printer");
1967 * Print all files directly...
1975 * Otherwise we have neither - treat this as a "dumb" printer
1976 * with no PPD file...
1979 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
1980 "printer-make-and-model", NULL
, "Local Raw Printer");
1986 ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
1987 "finishings-supported", num_finishings
, (int *)finishings
);
1988 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
1989 "finishings-default", IPP_FINISHINGS_NONE
);
1994 * Add the CUPS-specific printer-type attribute...
1998 p
->type
|= CUPS_PRINTER_NOT_SHARED
;
2000 p
->type
&= ~CUPS_PRINTER_NOT_SHARED
;
2002 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-type",
2003 cupsd_printer_type
);
2005 DEBUG_printf(("cupsdSetPrinterAttrs: leaving name = %s, type = %x\n", p
->name
,
2010 * Write the IRIX printer config and status files...
2013 write_irix_config(p
);
2014 write_irix_state(p
);
2020 * 'cupsdSetPrinterReasons()' - Set/update the reasons strings.
2024 cupsdSetPrinterReasons(
2025 cupsd_printer_t
*p
, /* I - Printer */
2026 const char *s
) /* I - Reasons strings */
2028 int i
; /* Looping var */
2029 const char *sptr
; /* Pointer into reasons */
2030 char reason
[255], /* Reason string */
2031 *rptr
; /* Pointer into reason */
2034 if (s
[0] == '-' || s
[0] == '+')
2037 * Add/remove reasons...
2045 * Replace reasons...
2050 for (i
= 0; i
< p
->num_reasons
; i
++)
2051 free(p
->reasons
[i
]);
2057 * Loop through all of the reasons...
2063 * Skip leading whitespace and commas...
2066 while (isspace(*sptr
& 255) || *sptr
== ',')
2069 for (rptr
= reason
; *sptr
&& !isspace(*sptr
& 255) && *sptr
!= ','; sptr
++)
2070 if (rptr
< (reason
+ sizeof(reason
) - 1))
2084 for (i
= 0; i
< p
->num_reasons
; i
++)
2085 if (!strcasecmp(reason
, p
->reasons
[i
]))
2088 * Found a match, so remove it...
2092 free(p
->reasons
[i
]);
2094 if (i
< p
->num_reasons
)
2095 memmove(p
->reasons
+ i
, p
->reasons
+ i
+ 1,
2096 (p
->num_reasons
- i
) * sizeof(char *));
2101 else if (p
->num_reasons
< (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
2107 for (i
= 0; i
< p
->num_reasons
; i
++)
2108 if (!strcasecmp(reason
, p
->reasons
[i
]))
2111 if (i
>= p
->num_reasons
)
2113 p
->reasons
[i
] = strdup(reason
);
2122 * 'cupsdSetPrinterState()' - Update the current state of a printer.
2126 cupsdSetPrinterState(
2127 cupsd_printer_t
*p
, /* I - Printer to change */
2128 ipp_pstate_t s
, /* I - New state */
2129 int update
) /* I - Update printers.conf? */
2131 ipp_pstate_t old_state
; /* Old printer state */
2135 * Can't set status of remote printers...
2138 if (p
->type
& CUPS_PRINTER_REMOTE
)
2142 * Set the new state...
2145 old_state
= p
->state
;
2151 * Let the browse code know this needs to be updated...
2155 p
->state_time
= time(NULL
);
2159 write_irix_state(p
);
2163 cupsdAddPrinterHistory(p
);
2166 * Save the printer configuration if a printer goes from idle or processing
2167 * to stopped (or visa-versa)...
2170 if ((old_state
== IPP_PRINTER_STOPPED
) != (s
== IPP_PRINTER_STOPPED
) &&
2173 if (p
->type
& CUPS_PRINTER_CLASS
)
2174 cupsdSaveAllClasses();
2176 cupsdSaveAllPrinters();
2182 * 'cupsdStopPrinter()' - Stop a printer from printing any jobs...
2186 cupsdStopPrinter(cupsd_printer_t
*p
, /* I - Printer to stop */
2187 int update
)/* I - Update printers.conf? */
2189 cupsd_job_t
*job
; /* Active print job */
2193 * Set the printer state...
2196 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, update
);
2199 * See if we have a job printing on this printer...
2205 * Get pointer to job...
2208 job
= (cupsd_job_t
*)p
->job
;
2214 cupsdStopJob(job
, 0);
2217 * Reset the state to pending...
2220 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
2228 * 'cupsdUpdatePrinters()' - Update printers after a partial reload.
2232 cupsdUpdatePrinters(void)
2234 cupsd_printer_t
*p
; /* Current printer */
2238 * Loop through the printers and recreate the printer attributes
2239 * for any local printers since the policy and/or access control
2240 * stuff may have changed. Also, if browsing is disabled, remove
2241 * any remote printers...
2244 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
2246 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
2248 if (!Browsing
&& (p
->type
& (CUPS_PRINTER_IMPLICIT
| CUPS_PRINTER_REMOTE
)))
2250 if (p
->type
& CUPS_PRINTER_IMPLICIT
)
2251 cupsArrayRemove(ImplicitPrinters
, p
);
2253 cupsArraySave(Printers
);
2254 cupsdDeletePrinter(p
, 0);
2255 cupsArrayRestore(Printers
);
2258 else if (!(p
->type
& CUPS_PRINTER_REMOTE
))
2259 cupsdSetPrinterAttrs(p
);
2262 * Update the operation policy pointer...
2265 if ((p
->op_policy_ptr
= cupsdFindPolicy(p
->op_policy
)) == NULL
)
2266 p
->op_policy_ptr
= DefaultPolicyPtr
;
2272 * 'cupsdValidateDest()' - Validate a printer/class destination.
2275 const char * /* O - Printer or class name */
2277 const char *hostname
, /* I - Host name */
2278 const char *resource
, /* I - Resource name */
2279 cups_ptype_t
*dtype
, /* O - Type (printer or class) */
2280 cupsd_printer_t
**printer
) /* O - Printer pointer */
2282 cupsd_printer_t
*p
; /* Current printer */
2283 char localname
[1024],/* Localized hostname */
2284 *lptr
, /* Pointer into localized hostname */
2285 *sptr
; /* Pointer into server name */
2288 DEBUG_printf(("cupsdValidateDest(\"%s\", \"%s\", %p, %p)\n", hostname
, resource
,
2292 * Initialize return values...
2298 *dtype
= (cups_ptype_t
)0;
2301 * See if the resource is a class or printer...
2304 if (!strncmp(resource
, "/classes/", 9))
2312 else if (!strncmp(resource
, "/printers/", 10))
2323 * Bad resource name...
2330 * See if the printer or class name exists...
2333 p
= cupsdFindDest(resource
);
2335 if (p
== NULL
&& strchr(resource
, '@') == NULL
)
2342 *dtype
= p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
|
2343 CUPS_PRINTER_REMOTE
);
2348 * Change localhost to the server name...
2351 if (!strcasecmp(hostname
, "localhost"))
2352 hostname
= ServerName
;
2354 strlcpy(localname
, hostname
, sizeof(localname
));
2356 if (!strcasecmp(hostname
, ServerName
))
2359 * Localize the hostname...
2362 lptr
= strchr(localname
, '.');
2363 sptr
= strchr(ServerName
, '.');
2365 if (sptr
!= NULL
&& lptr
!= NULL
)
2368 * Strip the common domain name components...
2371 while (lptr
!= NULL
)
2373 if (!strcasecmp(lptr
, sptr
))
2379 lptr
= strchr(lptr
+ 1, '.');
2384 DEBUG_printf(("localized hostname is \"%s\"...\n", localname
));
2387 * Find a matching printer or class...
2390 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
2392 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
2393 if (!strcasecmp(p
->hostname
, localname
) &&
2394 !strcasecmp(p
->name
, resource
))
2399 *dtype
= p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
|
2400 CUPS_PRINTER_REMOTE
);
2409 * 'cupsdWritePrintcap()' - Write a pseudo-printcap file for older applications
2414 cupsdWritePrintcap(void)
2416 cups_file_t
*fp
; /* printcap file */
2417 cupsd_printer_t
*p
; /* Current printer */
2422 * Update the IRIX printer state for the default printer; if
2423 * no printers remain, then the default printer file will be
2427 write_irix_state(DefaultPrinter
);
2431 * See if we have a printcap file; if not, don't bother writing it.
2434 if (!Printcap
|| !*Printcap
)
2438 * Open the printcap file...
2441 if ((fp
= cupsFileOpen(Printcap
, "w")) == NULL
)
2445 * Put a comment header at the top so that users will know where the
2446 * data has come from...
2449 cupsFilePuts(fp
, "# This file was automatically generated by cupsd(8) from the\n");
2450 cupsFilePrintf(fp
, "# %s/printers.conf file. All changes to this file\n",
2452 cupsFilePuts(fp
, "# will be lost.\n");
2457 * Write a new printcap with the current list of printers.
2460 switch (PrintcapFormat
)
2464 * Each printer is put in the file as:
2474 cupsFilePrintf(fp
, "%s|%s:rm=%s:rp=%s:\n", DefaultPrinter
->name
,
2475 DefaultPrinter
->info
, ServerName
, DefaultPrinter
->name
);
2477 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
2479 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
2480 if (p
!= DefaultPrinter
)
2481 cupsFilePrintf(fp
, "%s|%s:rm=%s:rp=%s:\n", p
->name
, p
->info
,
2482 ServerName
, p
->name
);
2485 case PRINTCAP_SOLARIS
:
2487 * Each printer is put in the file as:
2489 * _all:all=Printer1,Printer2,Printer3,...,PrinterN
2490 * _default:use=DefaultPrinter
2492 * :bsdaddr=ServerName,Printer1:\
2493 * :description=Description:
2495 * :bsdaddr=ServerName,Printer2:\
2496 * :description=Description:
2498 * :bsdaddr=ServerName,Printer3:\
2499 * :description=Description:
2502 * :bsdaddr=ServerName,PrinterN:\
2503 * :description=Description:
2506 cupsFilePuts(fp
, "_all:all=");
2507 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
2509 p
= (cupsd_printer_t
*)cupsArrayCurrent(Printers
))
2510 cupsFilePrintf(fp
, "%s%c", p
->name
,
2511 cupsArrayNext(Printers
) ? ',' : '\n');
2514 cupsFilePrintf(fp
, "_default:use=%s\n", DefaultPrinter
->name
);
2516 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
2518 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
2519 cupsFilePrintf(fp
, "%s:\\\n"
2520 "\t:bsdaddr=%s,%s:\\\n"
2521 "\t:description=%s:\n",
2522 p
->name
, ServerName
, p
->name
, p
->info
? p
->info
: "");
2536 * 'cupsdSanitizeURI()' - Sanitize a device URI...
2539 char * /* O - New device URI */
2540 cupsdSanitizeURI(const char *uri
, /* I - Original device URI */
2541 char *buffer
, /* O - New device URI */
2542 int buflen
) /* I - Size of new device URI buffer */
2544 char *start
, /* Start of data after scheme */
2545 *slash
, /* First slash after scheme:// */
2546 *ptr
; /* Pointer into user@host:port part */
2550 * Range check input...
2553 if (!uri
|| !buffer
|| buflen
< 2)
2557 * Copy the device URI to the new buffer...
2560 strlcpy(buffer
, uri
, buflen
);
2563 * Find the end of the scheme:// part...
2566 if ((ptr
= strchr(buffer
, ':')) == NULL
)
2567 return (buffer
); /* No scheme: part... */
2569 for (start
= ptr
+ 1; *start
; start
++)
2574 * Find the next slash (/) in the URI...
2577 if ((slash
= strchr(start
, '/')) == NULL
)
2578 slash
= start
+ strlen(start
); /* No slash, point to the end */
2581 * Check for an @ sign before the slash...
2584 if ((ptr
= strchr(start
, '@')) != NULL
&& ptr
< slash
)
2587 * Found an @ sign and it is before the resource part, so we have
2588 * an authentication string. Copy the remaining URI over the
2589 * authentication string...
2592 _cups_strcpy(start
, ptr
+ 1);
2596 * Return the new device URI...
2604 * 'compare_printers()' - Compare two printers.
2607 static int /* O - Result of comparison */
2608 compare_printers(void *first
, /* I - First printer */
2609 void *second
, /* I - Second printer */
2610 void *data
) /* I - App data (not used) */
2612 return (strcasecmp(((cupsd_printer_t
*)first
)->name
,
2613 ((cupsd_printer_t
*)second
)->name
));
2619 * 'write_irix_config()' - Update the config files used by the IRIX
2624 write_irix_config(cupsd_printer_t
*p
) /* I - Printer to update */
2626 char filename
[1024]; /* Interface script filename */
2627 cups_file_t
*fp
; /* Interface script file */
2632 * Add dummy interface and GUI scripts to fool SGI's "challenged" printing
2633 * tools. First the interface script that tells the tools what kind of
2634 * printer we have...
2637 snprintf(filename
, sizeof(filename
), "/var/spool/lp/interface/%s", p
->name
);
2639 if (p
->type
& CUPS_PRINTER_CLASS
)
2641 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
2643 cupsFilePuts(fp
, "#!/bin/sh\n");
2645 if ((attr
= ippFindAttribute(p
->attrs
, "printer-make-and-model",
2646 IPP_TAG_TEXT
)) != NULL
)
2647 cupsFilePrintf(fp
, "NAME=\"%s\"\n", attr
->values
[0].string
.text
);
2648 else if (p
->type
& CUPS_PRINTER_CLASS
)
2649 cupsFilePuts(fp
, "NAME=\"Printer Class\"\n");
2651 cupsFilePuts(fp
, "NAME=\"Remote Destination\"\n");
2653 if (p
->type
& CUPS_PRINTER_COLOR
)
2654 cupsFilePuts(fp
, "TYPE=ColorPostScript\n");
2656 cupsFilePuts(fp
, "TYPE=MonoPostScript\n");
2658 cupsFilePrintf(fp
, "HOSTNAME=%s\n", ServerName
);
2659 cupsFilePrintf(fp
, "HOSTPRINTER=%s\n", p
->name
);
2663 chmod(filename
, 0755);
2664 chown(filename
, User
, Group
);
2668 * Then the member file that tells which device file the queue is connected
2669 * to... Networked printers use "/dev/null" in this file, so that's what
2670 * we use (the actual device URI can confuse some apps...)
2673 snprintf(filename
, sizeof(filename
), "/var/spool/lp/member/%s", p
->name
);
2675 if (p
->type
& CUPS_PRINTER_CLASS
)
2677 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
2679 cupsFilePuts(fp
, "/dev/null\n");
2683 chmod(filename
, 0644);
2684 chown(filename
, User
, Group
);
2688 * The gui_interface file is a script or program that launches a GUI
2689 * option panel for the printer, using options specified on the
2690 * command-line in the third argument. The option panel must send
2691 * any printing options to stdout on a single line when the user
2692 * accepts them, or nothing if the user cancels the dialog.
2694 * The default options panel program is /usr/bin/glpoptions, from
2695 * the ESP Print Pro software. You can select another using the
2696 * PrintcapGUI option.
2699 snprintf(filename
, sizeof(filename
), "/var/spool/lp/gui_interface/ELF/%s.gui", p
->name
);
2701 if (p
->type
& CUPS_PRINTER_CLASS
)
2703 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
2705 cupsFilePuts(fp
, "#!/bin/sh\n");
2706 cupsFilePrintf(fp
, "%s -d %s -o \"$3\"\n", PrintcapGUI
, p
->name
);
2710 chmod(filename
, 0755);
2711 chown(filename
, User
, Group
);
2715 * The POD config file is needed by the printstatus command to show
2716 * the printer location and device.
2719 snprintf(filename
, sizeof(filename
), "/var/spool/lp/pod/%s.config", p
->name
);
2721 if (p
->type
& CUPS_PRINTER_CLASS
)
2723 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
2725 cupsFilePrintf(fp
, "Printer Class | %s\n",
2726 (p
->type
& CUPS_PRINTER_COLOR
) ? "ColorPostScript" : "MonoPostScript");
2727 cupsFilePrintf(fp
, "Printer Model | %s\n", p
->make_model
? p
->make_model
: "");
2728 cupsFilePrintf(fp
, "Location Code | %s\n", p
->location
? p
->location
: "");
2729 cupsFilePrintf(fp
, "Physical Location | %s\n", p
->info
? p
->info
: "");
2730 cupsFilePrintf(fp
, "Port Path | %s\n", p
->device_uri
? p
->device_uri
: "");
2731 cupsFilePrintf(fp
, "Config Path | /var/spool/lp/pod/%s.config\n", p
->name
);
2732 cupsFilePrintf(fp
, "Active Status Path | /var/spool/lp/pod/%s.status\n", p
->name
);
2733 cupsFilePuts(fp
, "Status Update Wait | 10 seconds\n");
2737 chmod(filename
, 0664);
2738 chown(filename
, User
, Group
);
2744 * 'write_irix_state()' - Update the status files used by IRIX printing
2749 write_irix_state(cupsd_printer_t
*p
) /* I - Printer to update */
2751 char filename
[1024]; /* Interface script filename */
2752 cups_file_t
*fp
; /* Interface script file */
2753 int tag
; /* Status tag value */
2759 * The POD status file is needed for the printstatus window to
2760 * provide the current status of the printer.
2763 snprintf(filename
, sizeof(filename
), "/var/spool/lp/pod/%s.status", p
->name
);
2765 if (p
->type
& CUPS_PRINTER_CLASS
)
2767 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
2769 cupsFilePrintf(fp
, "Operational Status | %s\n",
2770 (p
->state
== IPP_PRINTER_IDLE
) ? "Idle" :
2771 (p
->state
== IPP_PRINTER_PROCESSING
) ? "Busy" :
2773 cupsFilePrintf(fp
, "Information | 01 00 00 | %s\n", CUPS_SVERSION
);
2774 cupsFilePrintf(fp
, "Information | 02 00 00 | Device URI: %s\n",
2775 p
->device_uri
? p
->device_uri
: "");
2776 cupsFilePrintf(fp
, "Information | 03 00 00 | %s jobs\n",
2777 p
->accepting
? "Accepting" : "Not accepting");
2778 cupsFilePrintf(fp
, "Information | 04 00 00 | %s\n", p
->state_message
);
2782 chmod(filename
, 0664);
2783 chown(filename
, User
, Group
);
2787 * The activeicons file is needed to provide desktop icons for printers:
2789 * [ quoted from /usr/lib/print/tagit ]
2791 * --- Type of printer tags (base values)
2793 * Dumb=66048 # 0x10200
2794 * DumbColor=66080 # 0x10220
2795 * Raster=66112 # 0x10240
2796 * ColorRaster=66144 # 0x10260
2797 * Plotter=66176 # 0x10280
2798 * PostScript=66208 # 0x102A0
2799 * ColorPostScript=66240 # 0x102C0
2800 * MonoPostScript=66272 # 0x102E0
2802 * --- Printer state modifiers for local printers
2807 * Unknown=3 # 0x3 (Faulted due to unknown reason)
2809 * --- Printer state modifiers for network printers
2813 * NetFaulted=10 # 0xA
2814 * NetUnknown=11 # 0xB (Faulted due to unknown reason)
2817 snprintf(filename
, sizeof(filename
), "/var/spool/lp/activeicons/%s", p
->name
);
2819 if (p
->type
& CUPS_PRINTER_CLASS
)
2821 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
2823 if (p
->type
& CUPS_PRINTER_COLOR
)
2828 if (p
->type
& CUPS_PRINTER_REMOTE
)
2831 if (p
->state
== IPP_PRINTER_PROCESSING
)
2834 else if (p
->state
== IPP_PRINTER_STOPPED
)
2837 cupsFilePuts(fp
, "#!/bin/sh\n");
2838 cupsFilePrintf(fp
, "#Tag %d\n", tag
);
2842 chmod(filename
, 0755);
2843 chown(filename
, User
, Group
);
2848 * The default file is needed by the printers window to show
2849 * the default printer.
2852 snprintf(filename
, sizeof(filename
), "/var/spool/lp/default");
2854 if (DefaultPrinter
!= NULL
)
2856 if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
2858 cupsFilePrintf(fp
, "%s\n", DefaultPrinter
->name
);
2862 chmod(filename
, 0644);
2863 chown(filename
, User
, Group
);
2873 * End of "$Id: printers.c 4903 2006-01-10 20:02:46Z mike $".