2 * "$Id: printers.c 7968 2008-09-19 23:03:01Z mike $"
4 * Printer routines for the Common UNIX Printing System (CUPS).
6 * Copyright 2007-2010 by Apple Inc.
7 * Copyright 1997-2007 by Easy Software Products, all rights reserved.
9 * These coded instructions, statements, and computer programs are the
10 * property of Apple Inc. and are protected by Federal copyright
11 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
12 * which should have been included with this file. If this file is
13 * file is missing or damaged, see the license at "http://www.cups.org/".
17 * cupsdAddPrinter() - Add a printer to the system.
18 * cupsdAddPrinterHistory() - Add the current printer state to the history.
19 * cupsdAddPrinterUser() - Add a user to the ACL.
20 * cupsdCreateCommonData() - Create the common printer data.
21 * cupsdDeleteAllPrinters() - Delete all printers from the system.
22 * cupsdDeletePrinter() - Delete a printer from the system.
23 * cupsdFindDest() - Find a destination in the list.
24 * cupsdFindPrinter() - Find a printer in the list.
25 * cupsdFreePrinterUsers() - Free allow/deny users.
26 * cupsdLoadAllPrinters() - Load printers from the printers.conf file.
27 * cupsdRenamePrinter() - Rename a printer.
28 * cupsdSaveAllPrinters() - Save all printer definitions to the
30 * cupsdSetAuthInfoRequired() - Set the required authentication info.
31 * cupsdSetDeviceURI() - Set the device URI for a printer.
32 * cupsdSetPrinterAttr() - Set a printer attribute.
33 * cupsdSetPrinterAttrs() - Set printer attributes based upon the PPD
35 * cupsdSetPrinterReasons() - Set/update the reasons strings.
36 * cupsdSetPrinterState() - Update the current state of a printer.
37 * cupsdStopPrinter() - Stop a printer from printing any jobs...
38 * cupsdUpdatePrinterPPD() - Update keywords in a printer's PPD file.
39 * cupsdUpdatePrinters() - Update printers after a partial reload.
40 * cupsdValidateDest() - Validate a printer/class destination.
41 * cupsdWritePrintcap() - Write a pseudo-printcap file for older
42 * applications that need it...
43 * add_printer_defaults() - Add name-default attributes to the printer
45 * add_printer_filter() - Add a MIME filter for a printer.
46 * add_printer_formats() - Add document-format-supported values for a
48 * add_string_array() - Add a string to an array of CUPS strings.
49 * compare_printers() - Compare two printers.
50 * delete_printer_filters() - Delete all MIME filters for a printer.
51 * delete_string_array() - Delete an array of CUPS strings.
52 * load_ppd() - Load a cached PPD file, updating the cache as
54 * new_media_col() - Create a media-col collection value.
55 * write_irix_config() - Update the config files used by the IRIX
57 * write_irix_state() - Update the status files used by IRIX printing
59 * write_xml_string() - Write a string with XML escaping.
63 * Include necessary headers...
74 static void add_printer_defaults(cupsd_printer_t
*p
);
75 static void add_printer_filter(cupsd_printer_t
*p
, mime_type_t
*type
,
77 static void add_printer_formats(cupsd_printer_t
*p
);
78 static void add_string_array(cups_array_t
**a
, const char *s
);
79 static int compare_printers(void *first
, void *second
, void *data
);
80 static void delete_printer_filters(cupsd_printer_t
*p
);
81 static void delete_string_array(cups_array_t
**a
);
82 static void load_ppd(cupsd_printer_t
*p
);
83 static ipp_t
*new_media_col(_pwg_size_t
*size
, const char *source
,
86 static void write_irix_config(cupsd_printer_t
*p
);
87 static void write_irix_state(cupsd_printer_t
*p
);
89 static void write_xml_string(cups_file_t
*fp
, const char *s
);
93 * 'cupsdAddPrinter()' - Add a printer to the system.
96 cupsd_printer_t
* /* O - New printer */
97 cupsdAddPrinter(const char *name
) /* I - Name of printer */
99 cupsd_printer_t
*p
; /* New printer */
103 * Range check input...
106 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdAddPrinter(\"%s\")", name
);
109 * Create a new printer entity...
112 if ((p
= calloc(1, sizeof(cupsd_printer_t
))) == NULL
)
114 cupsdLogMessage(CUPSD_LOG_CRIT
, "Unable to allocate memory for printer - %s",
119 cupsdSetString(&p
->name
, name
);
120 cupsdSetString(&p
->info
, name
);
121 cupsdSetString(&p
->hostname
, ServerName
);
123 cupsdSetStringf(&p
->uri
, "ipp://%s:%d/printers/%s", ServerName
, RemotePort
,
125 cupsdSetDeviceURI(p
, "file:///dev/null");
127 p
->state
= IPP_PRINTER_STOPPED
;
128 p
->state_time
= time(NULL
);
130 p
->shared
= DefaultShared
;
131 p
->filetype
= mimeAddType(MimeDatabase
, "printer", name
);
133 cupsdSetString(&p
->job_sheets
[0], "none");
134 cupsdSetString(&p
->job_sheets
[1], "none");
136 cupsdSetString(&p
->error_policy
, ErrorPolicy
);
137 cupsdSetString(&p
->op_policy
, DefaultPolicy
);
139 p
->op_policy_ptr
= DefaultPolicyPtr
;
141 if (MaxPrinterHistory
)
142 p
->history
= calloc(MaxPrinterHistory
, sizeof(ipp_t
*));
145 * Insert the printer in the printer list alphabetically...
149 Printers
= cupsArrayNew(compare_printers
, NULL
);
151 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
152 "cupsdAddPrinter: Adding %s to Printers", p
->name
);
153 cupsArrayAdd(Printers
, p
);
155 if (!ImplicitPrinters
)
156 ImplicitPrinters
= cupsArrayNew(compare_printers
, NULL
);
159 * Return the new printer...
167 * 'cupsdAddPrinterHistory()' - Add the current printer state to the history.
171 cupsdAddPrinterHistory(
172 cupsd_printer_t
*p
) /* I - Printer */
174 ipp_t
*history
; /* History collection */
178 * Stop early if we aren't keeping history data...
181 if (MaxPrinterHistory
<= 0)
185 * Retire old history data as needed...
188 p
->sequence_number
++;
190 if (p
->num_history
>= MaxPrinterHistory
)
193 ippDelete(p
->history
[0]);
194 memmove(p
->history
, p
->history
+ 1, p
->num_history
* sizeof(ipp_t
*));
198 * Create a collection containing the current printer-state, printer-up-time,
199 * printer-state-message, and printer-state-reasons attributes.
203 ippAddInteger(history
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-state",
205 ippAddBoolean(history
, IPP_TAG_PRINTER
, "printer-is-accepting-jobs",
207 ippAddBoolean(history
, IPP_TAG_PRINTER
, "printer-is-shared", p
->shared
);
208 ippAddString(history
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-state-message",
209 NULL
, p
->state_message
);
210 if (p
->num_reasons
== 0)
211 ippAddString(history
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
212 "printer-state-reasons", NULL
, "none");
214 ippAddStrings(history
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
215 "printer-state-reasons", p
->num_reasons
, NULL
,
216 (const char * const *)p
->reasons
);
217 ippAddInteger(history
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
218 "printer-state-change-time", p
->state_time
);
219 ippAddInteger(history
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
220 "printer-state-sequence-number", p
->sequence_number
);
222 p
->history
[p
->num_history
] = history
;
228 * 'cupsdAddPrinterUser()' - Add a user to the ACL.
233 cupsd_printer_t
*p
, /* I - Printer */
234 const char *username
) /* I - User */
236 const char **temp
; /* Temporary array pointer */
242 if (p
->num_users
== 0)
243 temp
= malloc(sizeof(char **));
245 temp
= realloc(p
->users
, sizeof(char **) * (p
->num_users
+ 1));
251 temp
+= p
->num_users
;
253 if ((*temp
= strdup(username
)) != NULL
)
259 * 'cupsdCreateCommonData()' - Create the common printer data.
263 cupsdCreateCommonData(void)
265 int i
; /* Looping var */
266 ipp_attribute_t
*attr
; /* Attribute data */
267 cups_dir_t
*dir
; /* Notifier directory */
268 cups_dentry_t
*dent
; /* Notifier directory entry */
269 cups_array_t
*notifiers
; /* Notifier array */
270 char filename
[1024], /* Filename */
271 *notifier
; /* Current notifier */
272 cupsd_policy_t
*p
; /* Current policy */
273 static const int nups
[] = /* number-up-supported values */
274 { 1, 2, 4, 6, 9, 16 };
275 static const int orients
[4] =/* orientation-requested-supported values */
279 IPP_REVERSE_LANDSCAPE
,
282 static const char * const holds
[] = /* job-hold-until-supported values */
293 static const char * const versions
[] =/* ipp-versions-supported values */
300 static const int ops
[] = /* operations-supported values */
307 IPP_GET_JOB_ATTRIBUTES
,
309 IPP_GET_PRINTER_ATTRIBUTES
,
315 IPP_SET_PRINTER_ATTRIBUTES
,
316 IPP_SET_JOB_ATTRIBUTES
,
317 IPP_GET_PRINTER_SUPPORTED_VALUES
,
318 IPP_CREATE_PRINTER_SUBSCRIPTION
,
319 IPP_CREATE_JOB_SUBSCRIPTION
,
320 IPP_GET_SUBSCRIPTION_ATTRIBUTES
,
321 IPP_GET_SUBSCRIPTIONS
,
322 IPP_RENEW_SUBSCRIPTION
,
323 IPP_CANCEL_SUBSCRIPTION
,
324 IPP_GET_NOTIFICATIONS
,
328 IPP_RELEASE_HELD_NEW_JOBS
,
342 CUPS_AUTHENTICATE_JOB
,
347 static const char * const charsets
[] =/* charset-supported values */
352 static const char * const compressions
[] =
353 { /* document-compression-supported values */
357 #endif /* HAVE_LIBZ */
359 static const char * const media_col_supported
[] =
360 { /* media-col-supported values */
361 "media-bottom-margin",
364 "media-right-margin",
369 static const char * const multiple_document_handling
[] =
370 { /* multiple-document-handling-supported values */
371 "separate-documents-uncollated-copies",
372 "separate-documents-collated-copies"
374 static const char * const notify_attrs
[] =
375 { /* notify-attributes-supported values */
376 "printer-state-change-time",
377 "notify-lease-expiration-time",
378 "notify-subscriber-user-name"
380 static const char * const notify_events
[] =
381 { /* notify-events-supported values */
383 "job-config-changed",
390 "printer-config-changed",
392 "printer-finishings-changed",
393 "printer-media-changed",
397 "printer-state-changed",
404 static const char * const job_creation
[] =
405 { /* job-creation-attributes-supported */
414 "multiple-document-handling",
417 "orientation-requested",
420 "printer-resolution",
423 static const char * const job_settable
[] =
424 { /* job-settable-attributes-supported */
432 "multiple-document-handling",
435 "orientation-requested",
438 "printer-resolution",
441 static const char * const printer_settable
[] =
442 { /* printer-settable-attributes-supported */
449 ippDelete(CommonData
);
451 CommonData
= ippNew();
454 * This list of attributes is sorted to improve performance when the
455 * client provides a requested-attributes attribute...
458 /* charset-configured */
459 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_CHARSET
| IPP_TAG_COPY
,
460 "charset-configured", NULL
, "utf-8");
462 /* charset-supported */
463 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_CHARSET
| IPP_TAG_COPY
,
464 "charset-supported", sizeof(charsets
) / sizeof(charsets
[0]),
467 /* compression-supported */
468 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
469 "compression-supported",
470 sizeof(compressions
) / sizeof(compressions
[0]),
473 /* copies-supported */
474 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "copies-supported", 1, MaxCopies
);
477 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
| IPP_TAG_COPY
,
478 "cups-version", NULL
, CUPS_SVERSION
+ 6);
480 /* generated-natural-language-supported (no IPP_TAG_COPY) */
481 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_LANGUAGE
,
482 "generated-natural-language-supported", NULL
, DefaultLanguage
);
484 /* ipp-versions-supported */
485 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
486 "ipp-versions-supported", sizeof(versions
) / sizeof(versions
[0]),
489 /* job-creation-attributes-supported */
490 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
491 "job-creation-attributes-supported",
492 sizeof(job_creation
) / sizeof(job_creation
[0]),
495 /* job-hold-until-supported */
496 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
497 "job-hold-until-supported", sizeof(holds
) / sizeof(holds
[0]),
500 /* job-priority-supported */
501 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
502 "job-priority-supported", 100);
504 /* job-settable-attributes-supported */
505 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
506 "job-settable-attributes-supported",
507 sizeof(job_settable
) / sizeof(job_settable
[0]),
510 /* job-sheets-supported */
511 if (cupsArrayCount(Banners
) > 0)
514 * Setup the job-sheets-supported attribute...
517 if (Classification
&& !ClassifyOverride
)
518 attr
= ippAddString(CommonData
, IPP_TAG_PRINTER
,
519 IPP_TAG_NAME
| IPP_TAG_COPY
,
520 "job-sheets-supported", NULL
, Classification
);
522 attr
= ippAddStrings(CommonData
, IPP_TAG_PRINTER
,
523 IPP_TAG_NAME
| IPP_TAG_COPY
,
524 "job-sheets-supported", cupsArrayCount(Banners
) + 1,
528 cupsdLogMessage(CUPSD_LOG_EMERG
,
529 "Unable to allocate memory for "
530 "job-sheets-supported attribute: %s!", strerror(errno
));
531 else if (!Classification
|| ClassifyOverride
)
533 cupsd_banner_t
*banner
; /* Current banner */
536 attr
->values
[0].string
.text
= _cupsStrAlloc("none");
538 for (i
= 1, banner
= (cupsd_banner_t
*)cupsArrayFirst(Banners
);
540 i
++, banner
= (cupsd_banner_t
*)cupsArrayNext(Banners
))
541 attr
->values
[i
].string
.text
= banner
->name
;
545 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
546 "job-sheets-supported", NULL
, "none");
548 /* media-col-supported */
549 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
550 "media-col-supported",
551 sizeof(media_col_supported
) /
552 sizeof(media_col_supported
[0]), NULL
,
553 media_col_supported
);
555 /* multiple-document-handling-supported */
556 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
557 "multiple-document-handling-supported",
558 sizeof(multiple_document_handling
) /
559 sizeof(multiple_document_handling
[0]), NULL
,
560 multiple_document_handling
);
562 /* multiple-document-jobs-supported */
563 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
,
564 "multiple-document-jobs-supported", 1);
566 /* multiple-operation-time-out */
567 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
568 "multiple-operation-time-out", MultipleOperationTimeout
);
570 /* natural-language-configured (no IPP_TAG_COPY) */
571 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_LANGUAGE
,
572 "natural-language-configured", NULL
, DefaultLanguage
);
574 /* notify-attributes-supported */
575 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
576 "notify-attributes-supported",
577 (int)(sizeof(notify_attrs
) / sizeof(notify_attrs
[0])),
580 /* notify-lease-duration-supported */
581 ippAddRange(CommonData
, IPP_TAG_PRINTER
,
582 "notify-lease-duration-supported", 0,
583 MaxLeaseDuration
? MaxLeaseDuration
: 2147483647);
585 /* notify-max-events-supported */
586 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
587 "notify-max-events-supported", MaxEvents
);
589 /* notify-events-supported */
590 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
591 "notify-events-supported",
592 (int)(sizeof(notify_events
) / sizeof(notify_events
[0])),
593 NULL
, notify_events
);
595 /* notify-pull-method-supported */
596 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
597 "notify-pull-method-supported", NULL
, "ippget");
599 /* notify-schemes-supported */
600 snprintf(filename
, sizeof(filename
), "%s/notifier", ServerBin
);
601 if ((dir
= cupsDirOpen(filename
)) != NULL
)
603 notifiers
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
605 while ((dent
= cupsDirRead(dir
)) != NULL
)
606 if (S_ISREG(dent
->fileinfo
.st_mode
) &&
607 (dent
->fileinfo
.st_mode
& S_IXOTH
) != 0)
608 cupsArrayAdd(notifiers
, _cupsStrAlloc(dent
->filename
));
610 if (cupsArrayCount(notifiers
) > 0)
612 attr
= ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
613 "notify-schemes-supported",
614 cupsArrayCount(notifiers
), NULL
, NULL
);
616 for (i
= 0, notifier
= (char *)cupsArrayFirst(notifiers
);
618 i
++, notifier
= (char *)cupsArrayNext(notifiers
))
619 attr
->values
[i
].string
.text
= notifier
;
622 cupsArrayDelete(notifiers
);
626 /* number-up-supported */
627 ippAddIntegers(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
628 "number-up-supported", sizeof(nups
) / sizeof(nups
[0]), nups
);
630 /* operations-supported */
631 ippAddIntegers(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
632 "operations-supported",
633 sizeof(ops
) / sizeof(ops
[0]) + JobFiles
- 1, ops
);
635 /* orientation-requested-supported */
636 ippAddIntegers(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
637 "orientation-requested-supported", 4, orients
);
639 /* page-ranges-supported */
640 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
, "page-ranges-supported", 1);
642 /* pdf-override-supported */
643 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
644 "pdl-override-supported", NULL
, "not-attempted");
646 /* printer-op-policy-supported */
647 attr
= ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
648 "printer-op-policy-supported", cupsArrayCount(Policies
),
650 for (i
= 0, p
= (cupsd_policy_t
*)cupsArrayFirst(Policies
);
652 i
++, p
= (cupsd_policy_t
*)cupsArrayNext(Policies
))
653 attr
->values
[i
].string
.text
= p
->name
;
655 /* printer-settable-attributes-supported */
656 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
657 "printer-settable-attributes-supported",
658 sizeof(printer_settable
) / sizeof(printer_settable
[0]),
659 NULL
, printer_settable
);
661 /* server-is-sharing-printers */
662 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
, "server-is-sharing-printers",
663 BrowseLocalProtocols
!= 0 && Browsing
);
668 * 'cupsdDeleteAllPrinters()' - Delete all printers from the system.
672 cupsdDeleteAllPrinters(void)
674 cupsd_printer_t
*p
; /* Pointer to current printer/class */
677 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
679 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
681 p
->op_policy_ptr
= DefaultPolicyPtr
;
682 cupsdDeletePrinter(p
, 0);
688 * 'cupsdDeletePrinter()' - Delete a printer from the system.
691 int /* O - 1 if classes affected, 0 otherwise */
693 cupsd_printer_t
*p
, /* I - Printer to delete */
694 int update
) /* I - Update printers.conf? */
696 int i
, /* Looping var */
697 changed
= 0; /* Class changed? */
699 char filename
[1024]; /* Interface script filename */
703 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdDeletePrinter(p=%p(%s), update=%d)",
707 * Save the current position in the Printers array...
710 cupsArraySave(Printers
);
713 * Stop printing on this printer...
716 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, update
);
719 cupsdSetJobState(p
->job
, IPP_JOB_PENDING
, CUPSD_JOB_FORCE
,
720 update
? "Job stopped due to printer being deleted." :
724 * If this printer is the next for browsing, point to the next one...
729 cupsArrayFind(Printers
, p
);
730 BrowseNext
= (cupsd_printer_t
*)cupsArrayNext(Printers
);
734 * Remove the printer from the list...
737 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
738 "cupsdDeletePrinter: Removing %s from Printers", p
->name
);
739 cupsArrayRemove(Printers
, p
);
741 if (p
->type
& CUPS_PRINTER_IMPLICIT
)
743 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
744 "cupsdDeletePrinter: Removing %s from ImplicitPrinters",
746 cupsArrayRemove(ImplicitPrinters
, p
);
750 * Remove the dummy interface/icon/option files under IRIX...
754 snprintf(filename
, sizeof(filename
), "/var/spool/lp/interface/%s", p
->name
);
757 snprintf(filename
, sizeof(filename
), "/var/spool/lp/gui_interface/ELF/%s.gui",
761 snprintf(filename
, sizeof(filename
), "/var/spool/lp/activeicons/%s", p
->name
);
764 snprintf(filename
, sizeof(filename
), "/var/spool/lp/pod/%s.config", p
->name
);
767 snprintf(filename
, sizeof(filename
), "/var/spool/lp/pod/%s.status", p
->name
);
770 snprintf(filename
, sizeof(filename
), "/var/spool/lp/member/%s", p
->name
);
775 * If p is the default printer, assign a different one...
778 if (p
== DefaultPrinter
)
780 DefaultPrinter
= NULL
;
782 if (UseNetworkDefault
)
785 * Find the first network default printer and use it...
788 cupsd_printer_t
*dp
; /* New default printer */
791 for (dp
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
793 dp
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
794 if (dp
!= p
&& (dp
->type
& CUPS_PRINTER_DEFAULT
))
803 * Remove this printer from any classes...
806 if (!(p
->type
& CUPS_PRINTER_IMPLICIT
))
808 changed
= cupsdDeletePrinterFromClasses(p
);
811 * Deregister from any browse protocols...
814 cupsdDeregisterPrinter(p
, 1);
818 * Free all memory used by the printer...
821 if (p
->printers
!= NULL
)
824 if (MaxPrinterHistory
)
826 for (i
= 0; i
< p
->num_history
; i
++)
827 ippDelete(p
->history
[i
]);
832 delete_printer_filters(p
);
834 for (i
= 0; i
< p
->num_reasons
; i
++)
835 _cupsStrFree(p
->reasons
[i
]);
838 ippDelete(p
->ppd_attrs
);
840 mimeDeleteType(MimeDatabase
, p
->filetype
);
841 mimeDeleteType(MimeDatabase
, p
->prefiltertype
);
843 delete_string_array(&(p
->filters
));
844 delete_string_array(&(p
->pre_filters
));
846 cupsdFreePrinterUsers(p
);
849 cupsdClearString(&p
->uri
);
850 cupsdClearString(&p
->hostname
);
851 cupsdClearString(&p
->name
);
852 cupsdClearString(&p
->location
);
853 cupsdClearString(&p
->make_model
);
854 cupsdClearString(&p
->info
);
855 cupsdClearString(&p
->job_sheets
[0]);
856 cupsdClearString(&p
->job_sheets
[1]);
857 cupsdClearString(&p
->device_uri
);
858 cupsdClearString(&p
->sanitized_device_uri
);
859 cupsdClearString(&p
->port_monitor
);
860 cupsdClearString(&p
->op_policy
);
861 cupsdClearString(&p
->error_policy
);
863 cupsdClearString(&p
->alert
);
864 cupsdClearString(&p
->alert_description
);
867 cupsdClearString(&p
->product
);
868 cupsdClearString(&p
->pdl
);
869 #endif /* HAVE_DNSSD */
871 cupsArrayDelete(p
->filetypes
);
874 free(p
->browse_attrs
);
876 cupsFreeOptions(p
->num_options
, p
->options
);
881 * Restore the previous position in the Printers array...
884 cupsArrayRestore(Printers
);
891 * 'cupsdFindDest()' - Find a destination in the list.
894 cupsd_printer_t
* /* O - Destination in list */
895 cupsdFindDest(const char *name
) /* I - Name of printer or class to find */
897 cupsd_printer_t key
; /* Search key */
900 key
.name
= (char *)name
;
901 return ((cupsd_printer_t
*)cupsArrayFind(Printers
, &key
));
906 * 'cupsdFindPrinter()' - Find a printer in the list.
909 cupsd_printer_t
* /* O - Printer in list */
910 cupsdFindPrinter(const char *name
) /* I - Name of printer to find */
912 cupsd_printer_t
*p
; /* Printer in list */
915 if ((p
= cupsdFindDest(name
)) != NULL
&& (p
->type
& CUPS_PRINTER_CLASS
))
923 * 'cupsdFreePrinterUsers()' - Free allow/deny users.
927 cupsdFreePrinterUsers(
928 cupsd_printer_t
*p
) /* I - Printer */
930 int i
; /* Looping var */
933 if (!p
|| !p
->num_users
)
936 for (i
= 0; i
< p
->num_users
; i
++)
937 free((void *)p
->users
[i
]);
947 * 'cupsdLoadAllPrinters()' - Load printers from the printers.conf file.
951 cupsdLoadAllPrinters(void)
953 int i
; /* Looping var */
954 cups_file_t
*fp
; /* printers.conf file */
955 int linenum
; /* Current line number */
956 char line
[4096], /* Line from file */
957 *value
, /* Pointer to value */
958 *valueptr
; /* Pointer into value */
959 cupsd_printer_t
*p
; /* Current printer */
963 * Open the printers.conf file...
966 snprintf(line
, sizeof(line
), "%s/printers.conf", ServerRoot
);
967 if ((fp
= cupsFileOpen(line
, "r")) == NULL
)
970 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to open %s - %s", line
,
976 * Read printer configurations until we hit EOF...
982 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
985 * Decode the directive...
988 if (!strcasecmp(line
, "<Printer") ||
989 !strcasecmp(line
, "<DefaultPrinter"))
992 * <Printer name> or <DefaultPrinter name>
995 if (p
== NULL
&& value
)
998 * Add the printer and a base file type...
1001 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Loading printer %s...", value
);
1003 p
= cupsdAddPrinter(value
);
1005 p
->state
= IPP_PRINTER_IDLE
;
1008 * Set the default printer as needed...
1011 if (!strcasecmp(line
, "<DefaultPrinter"))
1015 cupsdLogMessage(CUPSD_LOG_ERROR
,
1016 "Syntax error on line %d of printers.conf.", linenum
);
1018 else if (!strcasecmp(line
, "</Printer>"))
1023 * Close out the current printer...
1026 cupsdSetPrinterAttrs(p
);
1027 cupsdAddPrinterHistory(p
);
1029 if (strncmp(p
->device_uri
, "file:", 5) &&
1030 p
->state
!= IPP_PRINTER_STOPPED
)
1033 * See if the backend exists...
1036 snprintf(line
, sizeof(line
), "%s/backend/%s", ServerBin
,
1039 if ((valueptr
= strchr(line
+ strlen(ServerBin
), ':')) != NULL
)
1040 *valueptr
= '\0'; /* Chop everything but URI scheme */
1042 if (access(line
, 0))
1045 * Backend does not exist, stop printer...
1048 p
->state
= IPP_PRINTER_STOPPED
;
1049 snprintf(p
->state_message
, sizeof(p
->state_message
),
1050 "Backend %s does not exist!", line
);
1057 cupsdLogMessage(CUPSD_LOG_ERROR
,
1058 "Syntax error on line %d of printers.conf.", linenum
);
1062 cupsdLogMessage(CUPSD_LOG_ERROR
,
1063 "Syntax error on line %d of printers.conf.", linenum
);
1065 else if (!strcasecmp(line
, "AuthInfoRequired"))
1067 if (!cupsdSetAuthInfoRequired(p
, value
, NULL
))
1068 cupsdLogMessage(CUPSD_LOG_ERROR
,
1069 "Bad AuthInfoRequired on line %d of printers.conf.",
1072 else if (!strcasecmp(line
, "Info"))
1075 cupsdSetString(&p
->info
, value
);
1077 else if (!strcasecmp(line
, "MakeModel"))
1080 cupsdSetString(&p
->make_model
, value
);
1082 else if (!strcasecmp(line
, "Location"))
1085 cupsdSetString(&p
->location
, value
);
1087 else if (!strcasecmp(line
, "DeviceURI"))
1090 cupsdSetDeviceURI(p
, value
);
1092 cupsdLogMessage(CUPSD_LOG_ERROR
,
1093 "Syntax error on line %d of printers.conf.", linenum
);
1095 else if (!strcasecmp(line
, "Option") && value
)
1101 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1104 cupsdLogMessage(CUPSD_LOG_ERROR
,
1105 "Syntax error on line %d of printers.conf.", linenum
);
1108 for (; *valueptr
&& isspace(*valueptr
& 255); *valueptr
++ = '\0');
1110 p
->num_options
= cupsAddOption(value
, valueptr
, p
->num_options
,
1114 else if (!strcasecmp(line
, "PortMonitor"))
1116 if (value
&& strcmp(value
, "none"))
1117 cupsdSetString(&p
->port_monitor
, value
);
1119 cupsdClearString(&p
->port_monitor
);
1121 cupsdLogMessage(CUPSD_LOG_ERROR
,
1122 "Syntax error on line %d of printers.conf.", linenum
);
1124 else if (!strcasecmp(line
, "Reason"))
1127 strcmp(value
, "connecting-to-device") &&
1128 strcmp(value
, "cups-insecure-filter-warning") &&
1129 strcmp(value
, "cups-missing-filter-warning"))
1131 for (i
= 0 ; i
< p
->num_reasons
; i
++)
1132 if (!strcmp(value
, p
->reasons
[i
]))
1135 if (i
>= p
->num_reasons
&&
1136 p
->num_reasons
< (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
1138 p
->reasons
[p
->num_reasons
] = _cupsStrAlloc(value
);
1143 cupsdLogMessage(CUPSD_LOG_ERROR
,
1144 "Syntax error on line %d of printers.conf.", linenum
);
1146 else if (!strcasecmp(line
, "State"))
1149 * Set the initial queue state...
1152 if (value
&& !strcasecmp(value
, "idle"))
1153 p
->state
= IPP_PRINTER_IDLE
;
1154 else if (value
&& !strcasecmp(value
, "stopped"))
1156 p
->state
= IPP_PRINTER_STOPPED
;
1158 for (i
= 0 ; i
< p
->num_reasons
; i
++)
1159 if (!strcmp("paused", p
->reasons
[i
]))
1162 if (i
>= p
->num_reasons
&&
1163 p
->num_reasons
< (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
1165 p
->reasons
[p
->num_reasons
] = _cupsStrAlloc("paused");
1170 cupsdLogMessage(CUPSD_LOG_ERROR
,
1171 "Syntax error on line %d of printers.conf.", linenum
);
1173 else if (!strcasecmp(line
, "StateMessage"))
1176 * Set the initial queue state message...
1180 strlcpy(p
->state_message
, value
, sizeof(p
->state_message
));
1182 else if (!strcasecmp(line
, "StateTime"))
1185 * Set the state time...
1189 p
->state_time
= atoi(value
);
1191 else if (!strcasecmp(line
, "Accepting"))
1194 * Set the initial accepting state...
1198 (!strcasecmp(value
, "yes") ||
1199 !strcasecmp(value
, "on") ||
1200 !strcasecmp(value
, "true")))
1203 (!strcasecmp(value
, "no") ||
1204 !strcasecmp(value
, "off") ||
1205 !strcasecmp(value
, "false")))
1208 cupsdLogMessage(CUPSD_LOG_ERROR
,
1209 "Syntax error on line %d of printers.conf.", linenum
);
1211 else if (!strcasecmp(line
, "Type"))
1214 p
->type
= atoi(value
);
1216 cupsdLogMessage(CUPSD_LOG_ERROR
,
1217 "Syntax error on line %d of printers.conf.", linenum
);
1219 else if (!strcasecmp(line
, "Product"))
1224 p
->product
= _cupsStrAlloc(value
);
1225 #endif /* HAVE_DNSSD */
1228 cupsdLogMessage(CUPSD_LOG_ERROR
,
1229 "Syntax error on line %d of printers.conf.", linenum
);
1231 else if (!strcasecmp(line
, "Filter"))
1236 p
->filters
= cupsArrayNew(NULL
, NULL
);
1238 cupsArrayAdd(p
->filters
, _cupsStrAlloc(value
));
1241 cupsdLogMessage(CUPSD_LOG_ERROR
,
1242 "Syntax error on line %d of printers.conf.", linenum
);
1244 else if (!strcasecmp(line
, "PreFilter"))
1248 if (!p
->pre_filters
)
1249 p
->pre_filters
= cupsArrayNew(NULL
, NULL
);
1251 cupsArrayAdd(p
->pre_filters
, _cupsStrAlloc(value
));
1254 cupsdLogMessage(CUPSD_LOG_ERROR
,
1255 "Syntax error on line %d of printers.conf.", linenum
);
1257 else if (!strcasecmp(line
, "Shared"))
1260 * Set the initial shared state...
1264 (!strcasecmp(value
, "yes") ||
1265 !strcasecmp(value
, "on") ||
1266 !strcasecmp(value
, "true")))
1269 (!strcasecmp(value
, "no") ||
1270 !strcasecmp(value
, "off") ||
1271 !strcasecmp(value
, "false")))
1274 cupsdLogMessage(CUPSD_LOG_ERROR
,
1275 "Syntax error on line %d of printers.conf.", linenum
);
1277 else if (!strcasecmp(line
, "JobSheets"))
1280 * Set the initial job sheets...
1285 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1290 cupsdSetString(&p
->job_sheets
[0], value
);
1292 while (isspace(*valueptr
& 255))
1297 for (value
= valueptr
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1302 cupsdSetString(&p
->job_sheets
[1], value
);
1306 cupsdLogMessage(CUPSD_LOG_ERROR
,
1307 "Syntax error on line %d of printers.conf.", linenum
);
1309 else if (!strcasecmp(line
, "AllowUser"))
1314 cupsdAddPrinterUser(p
, value
);
1317 cupsdLogMessage(CUPSD_LOG_ERROR
,
1318 "Syntax error on line %d of printers.conf.", linenum
);
1320 else if (!strcasecmp(line
, "DenyUser"))
1325 cupsdAddPrinterUser(p
, value
);
1328 cupsdLogMessage(CUPSD_LOG_ERROR
,
1329 "Syntax error on line %d of printers.conf.", linenum
);
1331 else if (!strcasecmp(line
, "QuotaPeriod"))
1334 p
->quota_period
= atoi(value
);
1336 cupsdLogMessage(CUPSD_LOG_ERROR
,
1337 "Syntax error on line %d of printers.conf.", linenum
);
1339 else if (!strcasecmp(line
, "PageLimit"))
1342 p
->page_limit
= atoi(value
);
1344 cupsdLogMessage(CUPSD_LOG_ERROR
,
1345 "Syntax error on line %d of printers.conf.", linenum
);
1347 else if (!strcasecmp(line
, "KLimit"))
1350 p
->k_limit
= atoi(value
);
1352 cupsdLogMessage(CUPSD_LOG_ERROR
,
1353 "Syntax error on line %d of printers.conf.", linenum
);
1355 else if (!strcasecmp(line
, "OpPolicy"))
1359 cupsd_policy_t
*pol
; /* Policy */
1362 if ((pol
= cupsdFindPolicy(value
)) != NULL
)
1364 cupsdSetString(&p
->op_policy
, value
);
1365 p
->op_policy_ptr
= pol
;
1368 cupsdLogMessage(CUPSD_LOG_ERROR
,
1369 "Bad policy \"%s\" on line %d of printers.conf",
1373 cupsdLogMessage(CUPSD_LOG_ERROR
,
1374 "Syntax error on line %d of printers.conf.", linenum
);
1376 else if (!strcasecmp(line
, "ErrorPolicy"))
1379 cupsdSetString(&p
->error_policy
, value
);
1381 cupsdLogMessage(CUPSD_LOG_ERROR
,
1382 "Syntax error on line %d of printers.conf.", linenum
);
1384 else if (!strcasecmp(line
, "Attribute") && value
)
1386 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1389 cupsdLogMessage(CUPSD_LOG_ERROR
,
1390 "Syntax error on line %d of printers.conf.", linenum
);
1393 for (; *valueptr
&& isspace(*valueptr
& 255); *valueptr
++ = '\0');
1396 cupsdSetPrinterAttrs(p
);
1398 if (!strcmp(value
, "marker-change-time"))
1399 p
->marker_time
= atoi(valueptr
);
1401 cupsdSetPrinterAttr(p
, value
, valueptr
);
1407 * Something else we don't understand...
1410 cupsdLogMessage(CUPSD_LOG_ERROR
,
1411 "Unknown configuration directive %s on line %d of printers.conf.",
1421 * 'cupsdRenamePrinter()' - Rename a printer.
1426 cupsd_printer_t
*p
, /* I - Printer */
1427 const char *name
) /* I - New name */
1430 * Remove the printer from the array(s) first...
1433 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1434 "cupsdRenamePrinter: Removing %s from Printers", p
->name
);
1435 cupsArrayRemove(Printers
, p
);
1437 if (p
->type
& CUPS_PRINTER_IMPLICIT
)
1439 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1440 "cupsdRenamePrinter: Removing %s from ImplicitPrinters",
1442 cupsArrayRemove(ImplicitPrinters
, p
);
1446 * Rename the printer type...
1449 mimeDeleteType(MimeDatabase
, p
->filetype
);
1450 p
->filetype
= mimeAddType(MimeDatabase
, "printer", name
);
1452 mimeDeleteType(MimeDatabase
, p
->prefiltertype
);
1453 p
->prefiltertype
= mimeAddType(MimeDatabase
, "prefilter", name
);
1456 * Rename the printer...
1459 cupsdSetString(&p
->name
, name
);
1462 * Reset printer attributes...
1465 cupsdSetPrinterAttrs(p
);
1468 * Add the printer back to the printer array(s)...
1471 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1472 "cupsdRenamePrinter: Adding %s to Printers", p
->name
);
1473 cupsArrayAdd(Printers
, p
);
1475 if (p
->type
& CUPS_PRINTER_IMPLICIT
)
1477 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1478 "cupsdRenamePrinter: Adding %s to ImplicitPrinters",
1480 cupsArrayAdd(ImplicitPrinters
, p
);
1486 * 'cupsdSaveAllPrinters()' - Save all printer definitions to the printers.conf
1491 cupsdSaveAllPrinters(void)
1493 int i
; /* Looping var */
1494 cups_file_t
*fp
; /* printers.conf file */
1495 char temp
[1024], /* Temporary string */
1496 backup
[1024], /* printers.conf.O file */
1497 value
[2048], /* Value string */
1498 *ptr
; /* Pointer into value */
1499 cupsd_printer_t
*printer
; /* Current printer class */
1500 time_t curtime
; /* Current time */
1501 struct tm
*curdate
; /* Current date */
1502 cups_option_t
*option
; /* Current option */
1503 ipp_attribute_t
*marker
; /* Current marker attribute */
1507 * Create the printers.conf file...
1510 snprintf(temp
, sizeof(temp
), "%s/printers.conf", ServerRoot
);
1511 snprintf(backup
, sizeof(backup
), "%s/printers.conf.O", ServerRoot
);
1513 if (rename(temp
, backup
))
1515 if (errno
!= ENOENT
)
1516 cupsdLogMessage(CUPSD_LOG_ERROR
,
1517 "Unable to backup printers.conf - %s", strerror(errno
));
1520 if ((fp
= cupsFileOpen(temp
, "w")) == NULL
)
1522 cupsdLogMessage(CUPSD_LOG_ERROR
,
1523 "Unable to save printers.conf - %s", strerror(errno
));
1525 if (rename(backup
, temp
))
1526 cupsdLogMessage(CUPSD_LOG_ERROR
,
1527 "Unable to restore printers.conf - %s", strerror(errno
));
1531 cupsdLogMessage(CUPSD_LOG_INFO
, "Saving printers.conf...");
1534 * Restrict access to the file...
1537 fchown(cupsFileNumber(fp
), getuid(), Group
);
1538 fchmod(cupsFileNumber(fp
), 0600);
1541 * Write a small header to the file...
1544 curtime
= time(NULL
);
1545 curdate
= localtime(&curtime
);
1546 strftime(temp
, sizeof(temp
) - 1, "%Y-%m-%d %H:%M", curdate
);
1548 cupsFilePuts(fp
, "# Printer configuration file for " CUPS_SVERSION
"\n");
1549 cupsFilePrintf(fp
, "# Written by cupsd on %s\n", temp
);
1550 cupsFilePuts(fp
, "# DO NOT EDIT THIS FILE WHEN CUPSD IS RUNNING\n");
1553 * Write each local printer known to the system...
1556 for (printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
1558 printer
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
1561 * Skip remote destinations and printer classes...
1564 if ((printer
->type
& CUPS_PRINTER_DISCOVERED
) ||
1565 (printer
->type
& CUPS_PRINTER_CLASS
) ||
1566 (printer
->type
& CUPS_PRINTER_IMPLICIT
))
1570 * Write printers as needed...
1573 if (printer
== DefaultPrinter
)
1574 cupsFilePrintf(fp
, "<DefaultPrinter %s>\n", printer
->name
);
1576 cupsFilePrintf(fp
, "<Printer %s>\n", printer
->name
);
1578 if (printer
->num_auth_info_required
> 0)
1580 switch (printer
->num_auth_info_required
)
1583 strlcpy(value
, printer
->auth_info_required
[0], sizeof(value
));
1587 snprintf(value
, sizeof(value
), "%s,%s",
1588 printer
->auth_info_required
[0],
1589 printer
->auth_info_required
[1]);
1594 snprintf(value
, sizeof(value
), "%s,%s,%s",
1595 printer
->auth_info_required
[0],
1596 printer
->auth_info_required
[1],
1597 printer
->auth_info_required
[2]);
1601 cupsFilePutConf(fp
, "AuthInfoRequired", value
);
1605 cupsFilePutConf(fp
, "Info", printer
->info
);
1607 if (printer
->location
)
1608 cupsFilePutConf(fp
, "Location", printer
->location
);
1610 if (printer
->make_model
)
1611 cupsFilePutConf(fp
, "MakeModel", printer
->make_model
);
1613 cupsFilePutConf(fp
, "DeviceURI", printer
->device_uri
);
1615 if (printer
->port_monitor
)
1616 cupsFilePutConf(fp
, "PortMonitor", printer
->port_monitor
);
1618 if (printer
->state
== IPP_PRINTER_STOPPED
)
1620 cupsFilePuts(fp
, "State Stopped\n");
1622 if (printer
->state_message
)
1623 cupsFilePutConf(fp
, "StateMessage", printer
->state_message
);
1626 cupsFilePuts(fp
, "State Idle\n");
1628 cupsFilePrintf(fp
, "StateTime %d\n", (int)printer
->state_time
);
1630 for (i
= 0; i
< printer
->num_reasons
; i
++)
1631 if (strcmp(printer
->reasons
[i
], "connecting-to-device") &&
1632 strcmp(printer
->reasons
[i
], "cups-insecure-filter-warning") &&
1633 strcmp(printer
->reasons
[i
], "cups-missing-filter-warning"))
1634 cupsFilePutConf(fp
, "Reason", printer
->reasons
[i
]);
1636 cupsFilePrintf(fp
, "Type %d\n", printer
->type
);
1639 if (printer
->product
)
1640 cupsFilePutConf(fp
, "Product", printer
->product
);
1641 #endif /* HAVE_DNSSD */
1643 for (ptr
= (char *)cupsArrayFirst(printer
->filters
);
1645 ptr
= (char *)cupsArrayNext(printer
->filters
))
1646 cupsFilePutConf(fp
, "Filter", ptr
);
1648 for (ptr
= (char *)cupsArrayFirst(printer
->pre_filters
);
1650 ptr
= (char *)cupsArrayNext(printer
->pre_filters
))
1651 cupsFilePutConf(fp
, "PreFilter", ptr
);
1653 if (printer
->accepting
)
1654 cupsFilePuts(fp
, "Accepting Yes\n");
1656 cupsFilePuts(fp
, "Accepting No\n");
1658 if (printer
->shared
)
1659 cupsFilePuts(fp
, "Shared Yes\n");
1661 cupsFilePuts(fp
, "Shared No\n");
1663 snprintf(value
, sizeof(value
), "%s %s", printer
->job_sheets
[0],
1664 printer
->job_sheets
[1]);
1665 cupsFilePutConf(fp
, "JobSheets", value
);
1667 cupsFilePrintf(fp
, "QuotaPeriod %d\n", printer
->quota_period
);
1668 cupsFilePrintf(fp
, "PageLimit %d\n", printer
->page_limit
);
1669 cupsFilePrintf(fp
, "KLimit %d\n", printer
->k_limit
);
1671 for (i
= 0; i
< printer
->num_users
; i
++)
1672 cupsFilePutConf(fp
, printer
->deny_users
? "DenyUser" : "AllowUser",
1675 if (printer
->op_policy
)
1676 cupsFilePutConf(fp
, "OpPolicy", printer
->op_policy
);
1677 if (printer
->error_policy
)
1678 cupsFilePutConf(fp
, "ErrorPolicy", printer
->error_policy
);
1680 for (i
= printer
->num_options
, option
= printer
->options
;
1684 snprintf(value
, sizeof(value
), "%s %s", option
->name
, option
->value
);
1685 cupsFilePutConf(fp
, "Option", value
);
1688 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-colors",
1689 IPP_TAG_NAME
)) != NULL
)
1691 snprintf(value
, sizeof(value
), "%s ", marker
->name
);
1693 for (i
= 0, ptr
= value
+ strlen(value
);
1694 i
< marker
->num_values
&& ptr
< (value
+ sizeof(value
) - 1);
1700 strlcpy(ptr
, marker
->values
[i
].string
.text
,
1701 value
+ sizeof(value
) - ptr
);
1706 cupsFilePutConf(fp
, "Attribute", value
);
1709 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-levels",
1710 IPP_TAG_INTEGER
)) != NULL
)
1712 cupsFilePrintf(fp
, "Attribute %s %d", marker
->name
,
1713 marker
->values
[0].integer
);
1714 for (i
= 1; i
< marker
->num_values
; i
++)
1715 cupsFilePrintf(fp
, ",%d", marker
->values
[i
].integer
);
1716 cupsFilePuts(fp
, "\n");
1719 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-low-levels",
1720 IPP_TAG_INTEGER
)) != NULL
)
1722 cupsFilePrintf(fp
, "Attribute %s %d", marker
->name
,
1723 marker
->values
[0].integer
);
1724 for (i
= 1; i
< marker
->num_values
; i
++)
1725 cupsFilePrintf(fp
, ",%d", marker
->values
[i
].integer
);
1726 cupsFilePuts(fp
, "\n");
1729 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-high-levels",
1730 IPP_TAG_INTEGER
)) != NULL
)
1732 cupsFilePrintf(fp
, "Attribute %s %d", marker
->name
,
1733 marker
->values
[0].integer
);
1734 for (i
= 1; i
< marker
->num_values
; i
++)
1735 cupsFilePrintf(fp
, ",%d", marker
->values
[i
].integer
);
1736 cupsFilePuts(fp
, "\n");
1739 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-message",
1740 IPP_TAG_TEXT
)) != NULL
)
1742 snprintf(value
, sizeof(value
), "%s %s", marker
->name
,
1743 marker
->values
[0].string
.text
);
1745 cupsFilePutConf(fp
, "Attribute", value
);
1748 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-names",
1749 IPP_TAG_NAME
)) != NULL
)
1751 snprintf(value
, sizeof(value
), "%s ", marker
->name
);
1753 for (i
= 0, ptr
= value
+ strlen(value
);
1754 i
< marker
->num_values
&& ptr
< (value
+ sizeof(value
) - 1);
1760 strlcpy(ptr
, marker
->values
[i
].string
.text
,
1761 value
+ sizeof(value
) - ptr
);
1766 cupsFilePutConf(fp
, "Attribute", value
);
1769 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-types",
1770 IPP_TAG_KEYWORD
)) != NULL
)
1772 snprintf(value
, sizeof(value
), "%s ", marker
->name
);
1774 for (i
= 0, ptr
= value
+ strlen(value
);
1775 i
< marker
->num_values
&& ptr
< (value
+ sizeof(value
) - 1);
1781 strlcpy(ptr
, marker
->values
[i
].string
.text
,
1782 value
+ sizeof(value
) - ptr
);
1787 cupsFilePutConf(fp
, "Attribute", value
);
1790 if (printer
->marker_time
)
1791 cupsFilePrintf(fp
, "Attribute marker-change-time %ld\n",
1792 (long)printer
->marker_time
);
1794 cupsFilePuts(fp
, "</Printer>\n");
1798 * Make IRIX desktop & printer status happy
1801 write_irix_state(printer
);
1810 * 'cupsdSetAuthInfoRequired()' - Set the required authentication info.
1813 int /* O - 1 if value OK, 0 otherwise */
1814 cupsdSetAuthInfoRequired(
1815 cupsd_printer_t
*p
, /* I - Printer */
1816 const char *values
, /* I - Plain text value (or NULL) */
1817 ipp_attribute_t
*attr
) /* I - IPP attribute value (or NULL) */
1819 int i
; /* Looping var */
1822 p
->num_auth_info_required
= 0;
1825 * Do we have a plain text value?
1831 * Yes, grab the keywords...
1834 const char *end
; /* End of current value */
1837 while (*values
&& p
->num_auth_info_required
< 4)
1839 if ((end
= strchr(values
, ',')) == NULL
)
1840 end
= values
+ strlen(values
);
1842 if ((end
- values
) == 4 && !strncmp(values
, "none", 4))
1844 if (p
->num_auth_info_required
!= 0 || *end
)
1847 p
->auth_info_required
[p
->num_auth_info_required
] = "none";
1848 p
->num_auth_info_required
++;
1852 else if ((end
- values
) == 9 && !strncmp(values
, "negotiate", 9))
1854 if (p
->num_auth_info_required
!= 0 || *end
)
1857 p
->auth_info_required
[p
->num_auth_info_required
] = "negotiate";
1858 p
->num_auth_info_required
++;
1860 else if ((end
- values
) == 6 && !strncmp(values
, "domain", 6))
1862 p
->auth_info_required
[p
->num_auth_info_required
] = "domain";
1863 p
->num_auth_info_required
++;
1865 else if ((end
- values
) == 8 && !strncmp(values
, "password", 8))
1867 p
->auth_info_required
[p
->num_auth_info_required
] = "password";
1868 p
->num_auth_info_required
++;
1870 else if ((end
- values
) == 8 && !strncmp(values
, "username", 8))
1872 p
->auth_info_required
[p
->num_auth_info_required
] = "username";
1873 p
->num_auth_info_required
++;
1878 values
= (*end
) ? end
+ 1 : end
;
1881 if (p
->num_auth_info_required
== 0)
1883 p
->auth_info_required
[0] = "none";
1884 p
->num_auth_info_required
= 1;
1888 * Update the printer-type value as needed...
1891 if (p
->num_auth_info_required
> 1 ||
1892 strcmp(p
->auth_info_required
[0], "none"))
1893 p
->type
|= CUPS_PRINTER_AUTHENTICATED
;
1895 p
->type
&= ~CUPS_PRINTER_AUTHENTICATED
;
1901 * Grab values from an attribute instead...
1904 if (!attr
|| attr
->num_values
> 4)
1908 * Update the printer-type value as needed...
1911 if (attr
->num_values
> 1 ||
1912 strcmp(attr
->values
[0].string
.text
, "none"))
1913 p
->type
|= CUPS_PRINTER_AUTHENTICATED
;
1915 p
->type
&= ~CUPS_PRINTER_AUTHENTICATED
;
1917 for (i
= 0; i
< attr
->num_values
; i
++)
1919 if (!strcmp(attr
->values
[i
].string
.text
, "none"))
1921 if (p
->num_auth_info_required
!= 0 || attr
->num_values
!= 1)
1924 p
->auth_info_required
[p
->num_auth_info_required
] = "none";
1925 p
->num_auth_info_required
++;
1929 else if (!strcmp(attr
->values
[i
].string
.text
, "negotiate"))
1931 if (p
->num_auth_info_required
!= 0 || attr
->num_values
!= 1)
1934 p
->auth_info_required
[p
->num_auth_info_required
] = "negotiate";
1935 p
->num_auth_info_required
++;
1939 else if (!strcmp(attr
->values
[i
].string
.text
, "domain"))
1941 p
->auth_info_required
[p
->num_auth_info_required
] = "domain";
1942 p
->num_auth_info_required
++;
1944 else if (!strcmp(attr
->values
[i
].string
.text
, "password"))
1946 p
->auth_info_required
[p
->num_auth_info_required
] = "password";
1947 p
->num_auth_info_required
++;
1949 else if (!strcmp(attr
->values
[i
].string
.text
, "username"))
1951 p
->auth_info_required
[p
->num_auth_info_required
] = "username";
1952 p
->num_auth_info_required
++;
1963 * 'cupsdSetDeviceURI()' - Set the device URI for a printer.
1967 cupsdSetDeviceURI(cupsd_printer_t
*p
, /* I - Printer */
1968 const char *uri
) /* I - Device URI */
1970 char buffer
[1024], /* URI buffer */
1971 *start
, /* Start of data after scheme */
1972 *slash
, /* First slash after scheme:// */
1973 *ptr
; /* Pointer into user@host:port part */
1977 * Set the full device URI..
1980 cupsdSetString(&(p
->device_uri
), uri
);
1983 * Copy the device URI to a temporary buffer so we can sanitize any auth
1987 strlcpy(buffer
, uri
, sizeof(buffer
));
1990 * Find the end of the scheme:// part...
1993 if ((ptr
= strchr(buffer
, ':')) != NULL
)
1995 for (start
= ptr
+ 1; *start
; start
++)
2000 * Find the next slash (/) in the URI...
2003 if ((slash
= strchr(start
, '/')) == NULL
)
2004 slash
= start
+ strlen(start
); /* No slash, point to the end */
2007 * Check for an @ sign before the slash...
2010 if ((ptr
= strchr(start
, '@')) != NULL
&& ptr
< slash
)
2013 * Found an @ sign and it is before the resource part, so we have
2014 * an authentication string. Copy the remaining URI over the
2015 * authentication string...
2018 _cups_strcpy(start
, ptr
+ 1);
2023 * Save the sanitized URI...
2026 cupsdSetString(&(p
->sanitized_device_uri
), buffer
);
2031 * 'cupsdSetPrinterAttr()' - Set a printer attribute.
2035 cupsdSetPrinterAttr(
2036 cupsd_printer_t
*p
, /* I - Printer */
2037 const char *name
, /* I - Attribute name */
2038 char *value
) /* I - Attribute value string */
2040 ipp_attribute_t
*attr
; /* Attribute */
2041 int i
, /* Looping var */
2042 count
; /* Number of values */
2043 char *ptr
; /* Pointer into value */
2044 ipp_tag_t value_tag
; /* Value tag for this attribute */
2048 * Don't allow empty values...
2051 if (!*value
&& strcmp(name
, "marker-message"))
2053 cupsdLogMessage(CUPSD_LOG_ERROR
, "Ignoring empty \"%s\" attribute", name
);
2058 * Count the number of values...
2061 for (count
= 1, ptr
= value
;
2062 (ptr
= strchr(ptr
, ',')) != NULL
;
2066 * Then add or update the attribute as needed...
2069 if (!strcmp(name
, "marker-levels") || !strcmp(name
, "marker-low-levels") ||
2070 !strcmp(name
, "marker-high-levels"))
2076 if ((attr
= ippFindAttribute(p
->attrs
, name
, IPP_TAG_INTEGER
)) != NULL
&&
2077 attr
->num_values
< count
)
2079 ippDeleteAttribute(p
->attrs
, attr
);
2084 attr
->num_values
= count
;
2086 attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
, name
,
2091 cupsdLogMessage(CUPSD_LOG_ERROR
,
2092 "Unable to allocate memory for printer attribute "
2093 "(%d values)", count
);
2097 for (i
= 0; i
< count
; i
++)
2099 if ((ptr
= strchr(value
, ',')) != NULL
)
2102 attr
->values
[i
].integer
= strtol(value
, NULL
, 10);
2111 * Name or keyword values...
2114 if (!strcmp(name
, "marker-types"))
2115 value_tag
= IPP_TAG_KEYWORD
;
2116 else if (!strcmp(name
, "marker-message"))
2117 value_tag
= IPP_TAG_TEXT
;
2119 value_tag
= IPP_TAG_NAME
;
2121 if ((attr
= ippFindAttribute(p
->attrs
, name
, value_tag
)) != NULL
&&
2122 attr
->num_values
< count
)
2124 ippDeleteAttribute(p
->attrs
, attr
);
2130 for (i
= 0; i
< attr
->num_values
; i
++)
2131 _cupsStrFree(attr
->values
[i
].string
.text
);
2133 attr
->num_values
= count
;
2136 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, value_tag
, name
,
2141 cupsdLogMessage(CUPSD_LOG_ERROR
,
2142 "Unable to allocate memory for printer attribute "
2143 "(%d values)", count
);
2147 for (i
= 0; i
< count
; i
++)
2149 if ((ptr
= strchr(value
, ',')) != NULL
)
2152 attr
->values
[i
].string
.text
= _cupsStrAlloc(value
);
2162 * 'cupsdSetPrinterAttrs()' - Set printer attributes based upon the PPD file.
2166 cupsdSetPrinterAttrs(cupsd_printer_t
*p
)/* I - Printer to setup */
2168 int i
, /* Looping var */
2169 length
; /* Length of browse attributes */
2170 char resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
2171 int num_air
; /* Number of auth-info-required values */
2172 const char * const *air
; /* auth-info-required values */
2173 cupsd_location_t
*auth
; /* Pointer to authentication element */
2174 const char *auth_supported
; /* Authentication supported */
2175 ipp_t
*oldattrs
; /* Old printer attributes */
2176 ipp_attribute_t
*attr
; /* Attribute data */
2177 cups_option_t
*option
; /* Current printer option */
2178 char *filter
; /* Current filter */
2179 static const char * const air_none
[] =
2180 { /* No authentication */
2183 static const char * const air_userpass
[] =
2184 { /* Basic/Digest authentication */
2190 DEBUG_printf(("cupsdSetPrinterAttrs: entering name = %s, type = %x\n", p
->name
,
2194 * Make sure that we have the common attributes defined...
2198 cupsdCreateCommonData();
2201 * Clear out old filters, if any...
2204 delete_printer_filters(p
);
2207 * Figure out the authentication that is required for the printer.
2210 auth_supported
= "requesting-user-name";
2214 if (p
->num_auth_info_required
> 0 && strcmp(p
->auth_info_required
[0], "none"))
2216 num_air
= p
->num_auth_info_required
;
2217 air
= p
->auth_info_required
;
2219 else if ((p
->type
& CUPS_PRINTER_AUTHENTICATED
) &&
2220 (p
->type
& CUPS_PRINTER_DISCOVERED
))
2226 if (p
->type
& CUPS_PRINTER_CLASS
)
2227 snprintf(resource
, sizeof(resource
), "/classes/%s", p
->name
);
2229 snprintf(resource
, sizeof(resource
), "/printers/%s", p
->name
);
2231 if ((auth
= cupsdFindBest(resource
, HTTP_POST
)) == NULL
||
2232 auth
->type
== CUPSD_AUTH_NONE
)
2233 auth
= cupsdFindPolicyOp(p
->op_policy_ptr
, IPP_PRINT_JOB
);
2237 int auth_type
; /* Authentication type */
2240 if ((auth_type
= auth
->type
) == CUPSD_AUTH_DEFAULT
)
2241 auth_type
= DefaultAuthType
;
2243 if (auth_type
== CUPSD_AUTH_BASIC
|| auth_type
== CUPSD_AUTH_BASICDIGEST
)
2244 auth_supported
= "basic";
2245 else if (auth_type
== CUPSD_AUTH_DIGEST
)
2246 auth_supported
= "digest";
2248 else if (auth_type
== CUPSD_AUTH_NEGOTIATE
)
2249 auth_supported
= "negotiate";
2250 #endif /* HAVE_GSSAPI */
2252 if (!(p
->type
& CUPS_PRINTER_DISCOVERED
))
2254 if (auth_type
!= CUPSD_AUTH_NONE
)
2255 p
->type
|= CUPS_PRINTER_AUTHENTICATED
;
2257 p
->type
&= ~CUPS_PRINTER_AUTHENTICATED
;
2260 else if (!(p
->type
& CUPS_PRINTER_DISCOVERED
))
2261 p
->type
&= ~CUPS_PRINTER_AUTHENTICATED
;
2264 * Create the required IPP attributes for a printer...
2267 oldattrs
= p
->attrs
;
2268 p
->attrs
= ippNew();
2270 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2271 "uri-authentication-supported", NULL
, auth_supported
);
2272 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2273 "uri-security-supported", NULL
, "none");
2274 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
, "printer-name", NULL
,
2276 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-location",
2277 NULL
, p
->location
? p
->location
: "");
2278 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-info",
2279 NULL
, p
->info
? p
->info
: "");
2284 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2285 "requesting-user-name-denied", p
->num_users
, NULL
,
2288 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2289 "requesting-user-name-allowed", p
->num_users
, NULL
,
2293 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2294 "job-quota-period", p
->quota_period
);
2295 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2296 "job-k-limit", p
->k_limit
);
2297 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2298 "job-page-limit", p
->page_limit
);
2299 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2300 "auth-info-required", num_air
, NULL
, air
);
2302 if (cupsArrayCount(Banners
) > 0 && !(p
->type
& CUPS_PRINTER_DISCOVERED
))
2305 * Setup the job-sheets-default attribute...
2308 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2309 "job-sheets-default", 2, NULL
, NULL
);
2313 attr
->values
[0].string
.text
= _cupsStrAlloc(Classification
?
2314 Classification
: p
->job_sheets
[0]);
2315 attr
->values
[1].string
.text
= _cupsStrAlloc(Classification
?
2316 Classification
: p
->job_sheets
[1]);
2323 if (p
->type
& CUPS_PRINTER_DISCOVERED
)
2326 * Tell the client this is a remote printer of some type...
2329 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
2330 "printer-uri-supported", NULL
, p
->uri
);
2332 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "printer-more-info",
2336 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
2337 "printer-make-and-model", NULL
, p
->make_model
);
2339 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "device-uri", NULL
,
2348 * Assign additional attributes depending on whether this is a printer
2352 if (p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
))
2355 p
->type
&= ~CUPS_PRINTER_OPTIONS
;
2358 * Add class-specific attributes...
2361 if ((p
->type
& CUPS_PRINTER_IMPLICIT
) && p
->num_printers
> 0 &&
2362 p
->printers
[0]->make_model
)
2363 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
2364 "printer-make-and-model", NULL
, p
->printers
[0]->make_model
);
2366 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
2367 "printer-make-and-model", NULL
, "Local Printer Class");
2369 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "device-uri", NULL
,
2370 "file:///dev/null");
2372 if (p
->num_printers
> 0)
2375 * Add a list of member names; URIs are added in copy_printer_attrs...
2378 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2379 "member-names", p
->num_printers
, NULL
, NULL
);
2380 p
->type
|= CUPS_PRINTER_OPTIONS
;
2382 for (i
= 0; i
< p
->num_printers
; i
++)
2385 attr
->values
[i
].string
.text
= _cupsStrRetain(p
->printers
[i
]->name
);
2387 p
->type
&= ~CUPS_PRINTER_OPTIONS
| p
->printers
[i
]->type
;
2394 * Add printer-specific attributes...
2397 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "device-uri", NULL
,
2398 p
->sanitized_device_uri
);
2401 * Assign additional attributes from the PPD file (if any)...
2407 * Add filters for printer...
2410 cupsdSetPrinterReasons(p
, "-cups-missing-filter-warning,"
2411 "cups-insecure-filter-warning");
2413 for (filter
= (char *)cupsArrayFirst(p
->filters
);
2415 filter
= (char *)cupsArrayNext(p
->filters
))
2416 add_printer_filter(p
, p
->filetype
, filter
);
2420 p
->prefiltertype
= mimeAddType(MimeDatabase
, "prefilter", p
->name
);
2422 for (filter
= (char *)cupsArrayFirst(p
->pre_filters
);
2424 filter
= (char *)cupsArrayNext(p
->pre_filters
))
2425 add_printer_filter(p
, p
->prefiltertype
, filter
);
2431 * Copy marker attributes as needed...
2436 ipp_attribute_t
*oldattr
; /* Old attribute */
2439 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-colors",
2440 IPP_TAG_NAME
)) != NULL
)
2442 if ((attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2443 "marker-colors", oldattr
->num_values
, NULL
,
2446 for (i
= 0; i
< oldattr
->num_values
; i
++)
2447 attr
->values
[i
].string
.text
=
2448 _cupsStrRetain(oldattr
->values
[i
].string
.text
);
2452 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-levels",
2453 IPP_TAG_INTEGER
)) != NULL
)
2455 if ((attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2456 "marker-levels", oldattr
->num_values
,
2459 for (i
= 0; i
< oldattr
->num_values
; i
++)
2460 attr
->values
[i
].integer
= oldattr
->values
[i
].integer
;
2464 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-message",
2465 IPP_TAG_TEXT
)) != NULL
)
2466 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "marker-message",
2467 NULL
, oldattr
->values
[0].string
.text
);
2469 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-low-levels",
2470 IPP_TAG_INTEGER
)) != NULL
)
2472 if ((attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2473 "marker-low-levels", oldattr
->num_values
,
2476 for (i
= 0; i
< oldattr
->num_values
; i
++)
2477 attr
->values
[i
].integer
= oldattr
->values
[i
].integer
;
2481 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-high-levels",
2482 IPP_TAG_INTEGER
)) != NULL
)
2484 if ((attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2485 "marker-high-levels", oldattr
->num_values
,
2488 for (i
= 0; i
< oldattr
->num_values
; i
++)
2489 attr
->values
[i
].integer
= oldattr
->values
[i
].integer
;
2493 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-names",
2494 IPP_TAG_NAME
)) != NULL
)
2496 if ((attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2497 "marker-names", oldattr
->num_values
, NULL
,
2500 for (i
= 0; i
< oldattr
->num_values
; i
++)
2501 attr
->values
[i
].string
.text
=
2502 _cupsStrRetain(oldattr
->values
[i
].string
.text
);
2506 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-types",
2507 IPP_TAG_KEYWORD
)) != NULL
)
2509 if ((attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2510 "marker-types", oldattr
->num_values
, NULL
,
2513 for (i
= 0; i
< oldattr
->num_values
; i
++)
2514 attr
->values
[i
].string
.text
=
2515 _cupsStrRetain(oldattr
->values
[i
].string
.text
);
2519 ippDelete(oldattrs
);
2523 * Force sharing off for remote queues...
2526 if (p
->type
& (CUPS_PRINTER_REMOTE
| CUPS_PRINTER_IMPLICIT
))
2531 * Copy the printer options into a browse attributes string we can re-use.
2534 const char *valptr
; /* Pointer into value */
2535 char *attrptr
; /* Pointer into attribute string */
2539 * Free the old browse attributes as needed...
2542 if (p
->browse_attrs
)
2543 free(p
->browse_attrs
);
2546 * Compute the length of all attributes + job-sheets, lease-duration,
2547 * and BrowseLocalOptions.
2550 for (length
= 1, i
= p
->num_options
, option
= p
->options
;
2554 length
+= strlen(option
->name
) + 2;
2558 for (valptr
= option
->value
; *valptr
; valptr
++)
2559 if (strchr(" \"\'\\", *valptr
))
2566 length
+= 13 + strlen(p
->job_sheets
[0]) + strlen(p
->job_sheets
[1]);
2568 if (BrowseLocalOptions
)
2569 length
+= 12 + strlen(BrowseLocalOptions
);
2572 * Allocate the new string...
2575 if ((p
->browse_attrs
= calloc(1, length
)) == NULL
)
2576 cupsdLogMessage(CUPSD_LOG_ERROR
,
2577 "Unable to allocate %d bytes for browse data!",
2582 * Got the allocated string, now copy the options and attributes over...
2585 sprintf(p
->browse_attrs
, "job-sheets=%s,%s lease-duration=%d",
2586 p
->job_sheets
[0], p
->job_sheets
[1], BrowseTimeout
);
2587 attrptr
= p
->browse_attrs
+ strlen(p
->browse_attrs
);
2589 if (BrowseLocalOptions
)
2591 sprintf(attrptr
, " ipp-options=%s", BrowseLocalOptions
);
2592 attrptr
+= strlen(attrptr
);
2595 for (i
= p
->num_options
, option
= p
->options
;
2600 strcpy(attrptr
, option
->name
);
2601 attrptr
+= strlen(attrptr
);
2607 for (valptr
= option
->value
; *valptr
; valptr
++)
2609 if (strchr(" \"\'\\", *valptr
))
2612 *attrptr
++ = *valptr
;
2620 * Populate the document-format-supported attribute...
2623 add_printer_formats(p
);
2625 DEBUG_printf(("cupsdSetPrinterAttrs: leaving name = %s, type = %x\n", p
->name
,
2629 * Add name-default attributes...
2632 add_printer_defaults(p
);
2636 * Write the IRIX printer config and status files...
2639 write_irix_config(p
);
2640 write_irix_state(p
);
2644 * Let the browse protocols reflect the change
2647 cupsdRegisterPrinter(p
);
2652 * 'cupsdSetPrinterReasons()' - Set/update the reasons strings.
2655 int /* O - 1 if something changed, 0 otherwise */
2656 cupsdSetPrinterReasons(
2657 cupsd_printer_t
*p
, /* I - Printer */
2658 const char *s
) /* I - Reasons strings */
2660 int i
, /* Looping var */
2661 changed
= 0; /* Did something change? */
2662 const char *sptr
; /* Pointer into reasons */
2663 char reason
[255], /* Reason string */
2664 *rptr
; /* Pointer into reason */
2667 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
2668 "cupsdSetPrinterReasons(p=%p(%s),s=\"%s\"", p
, p
->name
, s
);
2670 if (s
[0] == '-' || s
[0] == '+')
2673 * Add/remove reasons...
2681 * Replace reasons...
2686 for (i
= 0; i
< p
->num_reasons
; i
++)
2687 _cupsStrFree(p
->reasons
[i
]);
2692 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
2694 if (PrintcapFormat
== PRINTCAP_PLIST
)
2695 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
2698 if (!strcmp(s
, "none"))
2702 * Loop through all of the reasons...
2708 * Skip leading whitespace and commas...
2711 while (isspace(*sptr
& 255) || *sptr
== ',')
2714 for (rptr
= reason
; *sptr
&& !isspace(*sptr
& 255) && *sptr
!= ','; sptr
++)
2715 if (rptr
< (reason
+ sizeof(reason
) - 1))
2729 for (i
= 0; i
< p
->num_reasons
; i
++)
2730 if (!strcmp(reason
, p
->reasons
[i
]))
2733 * Found a match, so remove it...
2738 _cupsStrFree(p
->reasons
[i
]);
2740 if (i
< p
->num_reasons
)
2741 memmove(p
->reasons
+ i
, p
->reasons
+ i
+ 1,
2742 (p
->num_reasons
- i
) * sizeof(char *));
2744 if (!strcmp(reason
, "paused") && p
->state
== IPP_PRINTER_STOPPED
)
2745 cupsdSetPrinterState(p
, IPP_PRINTER_IDLE
, 1);
2747 if (strcmp(reason
, "connecting-to-device"))
2749 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
2751 if (PrintcapFormat
== PRINTCAP_PLIST
)
2752 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
2757 else if (p
->num_reasons
< (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
2763 for (i
= 0; i
< p
->num_reasons
; i
++)
2764 if (!strcmp(reason
, p
->reasons
[i
]))
2767 if (i
>= p
->num_reasons
)
2769 if (i
>= (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
2771 cupsdLogMessage(CUPSD_LOG_ALERT
,
2772 "Too many printer-state-reasons values for %s (%d)",
2777 p
->reasons
[i
] = _cupsStrAlloc(reason
);
2781 if (!strcmp(reason
, "paused") && p
->state
!= IPP_PRINTER_STOPPED
)
2782 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, 1);
2784 if (strcmp(reason
, "connecting-to-device"))
2786 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
2788 if (PrintcapFormat
== PRINTCAP_PLIST
)
2789 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
2800 * 'cupsdSetPrinterState()' - Update the current state of a printer.
2804 cupsdSetPrinterState(
2805 cupsd_printer_t
*p
, /* I - Printer to change */
2806 ipp_pstate_t s
, /* I - New state */
2807 int update
) /* I - Update printers.conf? */
2809 ipp_pstate_t old_state
; /* Old printer state */
2810 static const char * const printer_states
[] =
2811 { /* State strings */
2819 * Can't set status of remote printers...
2822 if (p
->type
& CUPS_PRINTER_DISCOVERED
)
2826 * Set the new state...
2829 if (PrintcapFormat
== PRINTCAP_PLIST
)
2830 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
2832 old_state
= p
->state
;
2837 cupsdAddEvent(s
== IPP_PRINTER_STOPPED
? CUPSD_EVENT_PRINTER_STOPPED
:
2838 CUPSD_EVENT_PRINTER_STATE
, p
, NULL
,
2839 "%s \"%s\" state changed to %s.",
2840 (p
->type
& CUPS_PRINTER_CLASS
) ? "Class" : "Printer",
2841 p
->name
, printer_states
[p
->state
]);
2844 * Let the browse code know this needs to be updated...
2848 p
->state_time
= time(NULL
);
2852 write_irix_state(p
);
2857 * Set/clear the paused reason as needed...
2860 if (s
== IPP_PRINTER_STOPPED
)
2861 cupsdSetPrinterReasons(p
, "+paused");
2863 cupsdSetPrinterReasons(p
, "-paused");
2866 * Clear the message for the queue when going to processing...
2869 if (s
== IPP_PRINTER_PROCESSING
)
2870 p
->state_message
[0] = '\0';
2873 * Update the printer history...
2876 cupsdAddPrinterHistory(p
);
2879 * Let the browse protocols reflect the change...
2883 cupsdRegisterPrinter(p
);
2886 * Save the printer configuration if a printer goes from idle or processing
2887 * to stopped (or visa-versa)...
2891 (old_state
== IPP_PRINTER_STOPPED
) != (s
== IPP_PRINTER_STOPPED
))
2893 if (p
->type
& CUPS_PRINTER_CLASS
)
2894 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
2896 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
2902 * 'cupsdStopPrinter()' - Stop a printer from printing any jobs...
2906 cupsdStopPrinter(cupsd_printer_t
*p
, /* I - Printer to stop */
2907 int update
)/* I - Update printers.conf? */
2910 * Set the printer state...
2913 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, update
);
2916 * See if we have a job printing on this printer...
2919 if (p
->job
&& p
->job
->state_value
== IPP_JOB_PROCESSING
)
2920 cupsdSetJobState(p
->job
, IPP_JOB_PENDING
, CUPSD_JOB_DEFAULT
,
2921 "Job stopped due to printer being paused.");
2926 * 'cupsdUpdatePrinterPPD()' - Update keywords in a printer's PPD file.
2929 int /* O - 1 if successful, 0 otherwise */
2930 cupsdUpdatePrinterPPD(
2931 cupsd_printer_t
*p
, /* I - Printer */
2932 int num_keywords
, /* I - Number of keywords */
2933 cups_option_t
*keywords
) /* I - Keywords */
2935 int i
; /* Looping var */
2936 cups_file_t
*src
, /* Original file */
2937 *dst
; /* New file */
2938 char srcfile
[1024], /* Original filename */
2939 dstfile
[1024], /* New filename */
2940 line
[1024], /* Line from file */
2941 keystring
[41]; /* Keyword from line */
2942 cups_option_t
*keyword
; /* Current keyword */
2945 cupsdLogMessage(CUPSD_LOG_INFO
, "Updating keywords in PPD file for %s...",
2949 * Get the old and new PPD filenames...
2952 snprintf(srcfile
, sizeof(srcfile
), "%s/ppd/%s.ppd.O", ServerRoot
, p
->name
);
2953 snprintf(dstfile
, sizeof(srcfile
), "%s/ppd/%s.ppd", ServerRoot
, p
->name
);
2956 * Rename the old file and open the old and new...
2959 if (rename(dstfile
, srcfile
))
2961 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to backup PPD file for %s: %s",
2962 p
->name
, strerror(errno
));
2966 if ((src
= cupsFileOpen(srcfile
, "r")) == NULL
)
2968 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to open PPD file \"%s\": %s",
2969 srcfile
, strerror(errno
));
2970 rename(srcfile
, dstfile
);
2974 if ((dst
= cupsFileOpen(dstfile
, "w")) == NULL
)
2976 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to create PPD file \"%s\": %s",
2977 dstfile
, strerror(errno
));
2979 rename(srcfile
, dstfile
);
2984 * Copy the first line and then write out all of the keywords...
2987 if (!cupsFileGets(src
, line
, sizeof(line
)))
2989 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to read PPD file \"%s\": %s",
2990 srcfile
, strerror(errno
));
2993 rename(srcfile
, dstfile
);
2997 cupsFilePrintf(dst
, "%s\n", line
);
2999 for (i
= num_keywords
, keyword
= keywords
; i
> 0; i
--, keyword
++)
3001 cupsdLogMessage(CUPSD_LOG_DEBUG
, "*%s: %s", keyword
->name
, keyword
->value
);
3002 cupsFilePrintf(dst
, "*%s: %s\n", keyword
->name
, keyword
->value
);
3006 * Then copy the rest of the PPD file, dropping any keywords we changed.
3009 while (cupsFileGets(src
, line
, sizeof(line
)))
3012 * Skip keywords we've already set...
3015 if (sscanf(line
, "*%40[^:]:", keystring
) == 1 &&
3016 cupsGetOption(keystring
, num_keywords
, keywords
))
3020 * Otherwise write the line...
3023 cupsFilePrintf(dst
, "%s\n", line
);
3027 * Close files and return...
3038 * 'cupsdUpdatePrinters()' - Update printers after a partial reload.
3042 cupsdUpdatePrinters(void)
3044 cupsd_printer_t
*p
; /* Current printer */
3048 * Loop through the printers and recreate the printer attributes
3049 * for any local printers since the policy and/or access control
3050 * stuff may have changed. Also, if browsing is disabled, remove
3051 * any remote printers...
3054 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3056 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3059 * Remove remote printers if we are no longer browsing...
3063 (p
->type
& (CUPS_PRINTER_IMPLICIT
| CUPS_PRINTER_DISCOVERED
)))
3065 if (p
->type
& CUPS_PRINTER_IMPLICIT
)
3066 cupsArrayRemove(ImplicitPrinters
, p
);
3068 cupsArraySave(Printers
);
3069 cupsdDeletePrinter(p
, 0);
3070 cupsArrayRestore(Printers
);
3075 * Update the operation policy pointer...
3078 if ((p
->op_policy_ptr
= cupsdFindPolicy(p
->op_policy
)) == NULL
)
3079 p
->op_policy_ptr
= DefaultPolicyPtr
;
3082 * Update printer attributes as needed...
3085 if (!(p
->type
& CUPS_PRINTER_DISCOVERED
))
3086 cupsdSetPrinterAttrs(p
);
3092 * 'cupsdValidateDest()' - Validate a printer/class destination.
3095 const char * /* O - Printer or class name */
3097 const char *uri
, /* I - Printer URI */
3098 cups_ptype_t
*dtype
, /* O - Type (printer or class) */
3099 cupsd_printer_t
**printer
) /* O - Printer pointer */
3101 cupsd_printer_t
*p
; /* Current printer */
3102 char localname
[1024],/* Localized hostname */
3103 *lptr
, /* Pointer into localized hostname */
3104 *sptr
, /* Pointer into server name */
3105 *rptr
, /* Pointer into resource */
3106 scheme
[32], /* Scheme portion of URI */
3107 username
[64], /* Username portion of URI */
3108 hostname
[HTTP_MAX_HOST
],
3109 /* Host portion of URI */
3110 resource
[HTTP_MAX_URI
];
3111 /* Resource portion of URI */
3112 int port
; /* Port portion of URI */
3115 DEBUG_printf(("cupsdValidateDest(uri=\"%s\", dtype=%p, printer=%p)\n", uri
,
3119 * Initialize return values...
3126 *dtype
= (cups_ptype_t
)0;
3129 * Pull the hostname and resource from the URI...
3132 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
, scheme
, sizeof(scheme
),
3133 username
, sizeof(username
), hostname
, sizeof(hostname
),
3134 &port
, resource
, sizeof(resource
));
3137 * See if the resource is a class or printer...
3140 if (!strncmp(resource
, "/classes/", 9))
3146 rptr
= resource
+ 9;
3148 else if (!strncmp(resource
, "/printers/", 10))
3154 rptr
= resource
+ 10;
3159 * Bad resource name...
3166 * See if the printer or class name exists...
3169 p
= cupsdFindDest(rptr
);
3171 if (p
== NULL
&& strchr(rptr
, '@') == NULL
)
3179 *dtype
= p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
|
3180 CUPS_PRINTER_REMOTE
| CUPS_PRINTER_DISCOVERED
);
3186 * Change localhost to the server name...
3189 if (!strcasecmp(hostname
, "localhost"))
3190 strlcpy(hostname
, ServerName
, sizeof(hostname
));
3192 strlcpy(localname
, hostname
, sizeof(localname
));
3194 if (!strcasecmp(hostname
, ServerName
))
3197 * Localize the hostname...
3200 lptr
= strchr(localname
, '.');
3201 sptr
= strchr(ServerName
, '.');
3203 if (sptr
!= NULL
&& lptr
!= NULL
)
3206 * Strip the common domain name components...
3209 while (lptr
!= NULL
)
3211 if (!strcasecmp(lptr
, sptr
))
3217 lptr
= strchr(lptr
+ 1, '.');
3222 DEBUG_printf(("localized hostname is \"%s\"...\n", localname
));
3225 * Find a matching printer or class...
3228 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3230 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3231 if (!strcasecmp(p
->hostname
, localname
) &&
3232 !strcasecmp(p
->name
, rptr
))
3238 *dtype
= p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
|
3239 CUPS_PRINTER_REMOTE
| CUPS_PRINTER_DISCOVERED
);
3249 * 'cupsdWritePrintcap()' - Write a pseudo-printcap file for older applications
3254 cupsdWritePrintcap(void)
3256 int i
; /* Looping var */
3257 cups_file_t
*fp
; /* Printcap file */
3258 cupsd_printer_t
*p
; /* Current printer */
3263 * Update the IRIX printer state for the default printer; if
3264 * no printers remain, then the default printer file will be
3268 write_irix_state(DefaultPrinter
);
3272 * See if we have a printcap file; if not, don't bother writing it.
3275 if (!Printcap
|| !*Printcap
)
3278 cupsdLogMessage(CUPSD_LOG_INFO
, "Generating printcap %s...", Printcap
);
3281 * Open the printcap file...
3284 if ((fp
= cupsFileOpen(Printcap
, "w")) == NULL
)
3288 * Put a comment header at the top so that users will know where the
3289 * data has come from...
3292 if (PrintcapFormat
!= PRINTCAP_PLIST
)
3293 cupsFilePrintf(fp
, "# This file was automatically generated by cupsd(8) "
3295 "# %s/printers.conf file. All changes to this file\n"
3296 "# will be lost.\n", ServerRoot
);
3299 * Write a new printcap with the current list of printers.
3302 switch (PrintcapFormat
)
3306 * Each printer is put in the file as:
3316 cupsFilePrintf(fp
, "%s|%s:rm=%s:rp=%s:\n", DefaultPrinter
->name
,
3317 DefaultPrinter
->info
, ServerName
,
3318 DefaultPrinter
->name
);
3320 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3322 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3323 if (p
!= DefaultPrinter
)
3324 cupsFilePrintf(fp
, "%s|%s:rm=%s:rp=%s:\n", p
->name
, p
->info
,
3325 ServerName
, p
->name
);
3328 case PRINTCAP_PLIST
:
3330 * Each printer is written as a dictionary in a plist file.
3331 * Currently the printer-name, printer-info, printer-is-accepting-jobs,
3332 * printer-location, printer-make-and-model, printer-state,
3333 * printer-state-reasons, printer-type, and (sanitized) device-uri.
3336 cupsFilePuts(fp
, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
3337 "<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD "
3338 "PLIST 1.0//EN\" \"http://www.apple.com/DTDs/"
3339 "PropertyList-1.0.dtd\">\n"
3340 "<plist version=\"1.0\">\n"
3343 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3345 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3347 cupsFilePuts(fp
, "\t<dict>\n"
3348 "\t\t<key>printer-name</key>\n"
3350 write_xml_string(fp
, p
->name
);
3351 cupsFilePuts(fp
, "</string>\n"
3352 "\t\t<key>printer-info</key>\n"
3354 write_xml_string(fp
, p
->info
);
3355 cupsFilePrintf(fp
, "</string>\n"
3356 "\t\t<key>printer-is-accepting-jobs</key>\n"
3358 "\t\t<key>printer-location</key>\n"
3359 "\t\t<string>", p
->accepting
? "true" : "false");
3360 write_xml_string(fp
, p
->location
);
3361 cupsFilePuts(fp
, "</string>\n"
3362 "\t\t<key>printer-make-and-model</key>\n"
3364 write_xml_string(fp
, p
->make_model
);
3365 cupsFilePrintf(fp
, "</string>\n"
3366 "\t\t<key>printer-state</key>\n"
3367 "\t\t<integer>%d</integer>\n"
3368 "\t\t<key>printer-state-reasons</key>\n"
3369 "\t\t<array>\n", p
->state
);
3370 for (i
= 0; i
< p
->num_reasons
; i
++)
3372 cupsFilePuts(fp
, "\t\t\t<string>");
3373 write_xml_string(fp
, p
->reasons
[i
]);
3374 cupsFilePuts(fp
, "</string>\n");
3376 cupsFilePrintf(fp
, "\t\t</array>\n"
3377 "\t\t<key>printer-type</key>\n"
3378 "\t\t<integer>%d</integer>\n"
3379 "\t\t<key>device-uri</key>\n"
3380 "\t\t<string>", p
->type
);
3381 write_xml_string(fp
, p
->sanitized_device_uri
);
3382 cupsFilePuts(fp
, "</string>\n"
3385 cupsFilePuts(fp
, "</array>\n"
3389 case PRINTCAP_SOLARIS
:
3391 * Each printer is put in the file as:
3393 * _all:all=Printer1,Printer2,Printer3,...,PrinterN
3394 * _default:use=DefaultPrinter
3396 * :bsdaddr=ServerName,Printer1:\
3397 * :description=Description:
3399 * :bsdaddr=ServerName,Printer2:\
3400 * :description=Description:
3402 * :bsdaddr=ServerName,Printer3:\
3403 * :description=Description:
3406 * :bsdaddr=ServerName,PrinterN:\
3407 * :description=Description:
3410 cupsFilePuts(fp
, "_all:all=");
3411 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3413 p
= (cupsd_printer_t
*)cupsArrayCurrent(Printers
))
3414 cupsFilePrintf(fp
, "%s%c", p
->name
,
3415 cupsArrayNext(Printers
) ? ',' : '\n');
3418 cupsFilePrintf(fp
, "_default:use=%s\n", DefaultPrinter
->name
);
3420 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3422 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3423 cupsFilePrintf(fp
, "%s:\\\n"
3424 "\t:bsdaddr=%s,%s:\\\n"
3425 "\t:description=%s:\n",
3426 p
->name
, ServerName
, p
->name
,
3427 p
->info
? p
->info
: "");
3440 * 'add_printer_defaults()' - Add name-default attributes to the printer attributes.
3444 add_printer_defaults(cupsd_printer_t
*p
)/* I - Printer */
3446 int i
; /* Looping var */
3447 int num_options
; /* Number of default options */
3448 cups_option_t
*options
, /* Default options */
3449 *option
; /* Current option */
3450 char name
[256]; /* name-default */
3454 * Maintain a common array of default attribute names...
3457 if (!CommonDefaults
)
3459 CommonDefaults
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
3461 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("copies-default"));
3462 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("document-format-default"));
3463 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("finishings-default"));
3464 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-hold-until-default"));
3465 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-priority-default"));
3466 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-sheets-default"));
3467 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("media-default"));
3468 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("media-col-default"));
3469 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("number-up-default"));
3470 cupsArrayAdd(CommonDefaults
,
3471 _cupsStrAlloc("orientation-requested-default"));
3472 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("sides-default"));
3476 * Add all of the default options from the .conf files...
3479 for (num_options
= 0, options
= NULL
, i
= p
->num_options
, option
= p
->options
;
3483 if (strcmp(option
->name
, "ipp-options") &&
3484 strcmp(option
->name
, "job-sheets") &&
3485 strcmp(option
->name
, "lease-duration"))
3487 snprintf(name
, sizeof(name
), "%s-default", option
->name
);
3488 num_options
= cupsAddOption(name
, option
->value
, num_options
, &options
);
3490 if (!cupsArrayFind(CommonDefaults
, name
))
3491 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc(name
));
3496 * Convert options to IPP attributes...
3499 cupsEncodeOptions2(p
->attrs
, num_options
, options
, IPP_TAG_PRINTER
);
3500 cupsFreeOptions(num_options
, options
);
3503 * Add standard -default attributes as needed...
3506 if (!cupsGetOption("copies", p
->num_options
, p
->options
))
3507 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
, "copies-default",
3510 if (!cupsGetOption("document-format", p
->num_options
, p
->options
))
3511 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_MIMETYPE
,
3512 "document-format-default", NULL
, "application/octet-stream");
3514 if (!cupsGetOption("job-hold-until", p
->num_options
, p
->options
))
3515 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3516 "job-hold-until-default", NULL
, "no-hold");
3518 if (!cupsGetOption("job-priority", p
->num_options
, p
->options
))
3519 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3520 "job-priority-default", 50);
3522 if (!cupsGetOption("number-up", p
->num_options
, p
->options
))
3523 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3524 "number-up-default", 1);
3526 if (!cupsGetOption("notify-lease-duration", p
->num_options
, p
->options
))
3527 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3528 "notify-lease-duration-default", DefaultLeaseDuration
);
3530 if (!cupsGetOption("notify-events", p
->num_options
, p
->options
))
3531 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3532 "notify-events-default", NULL
, "job-completed");
3534 if (!cupsGetOption("orientation-requested", p
->num_options
, p
->options
))
3535 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NOVALUE
,
3536 "orientation-requested-default", NULL
, NULL
);
3538 if (!cupsGetOption("print-quality", p
->num_options
, p
->options
))
3539 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
3540 "print-quality-default", IPP_QUALITY_NORMAL
);
3545 * 'add_printer_filter()' - Add a MIME filter for a printer.
3550 cupsd_printer_t
*p
, /* I - Printer to add to */
3551 mime_type_t
*filtertype
, /* I - Filter or prefilter MIME type */
3552 const char *filter
) /* I - Filter to add */
3554 char super
[MIME_MAX_SUPER
], /* Super-type for filter */
3555 type
[MIME_MAX_TYPE
], /* Type for filter */
3556 program
[1024]; /* Program/filter name */
3557 int cost
; /* Cost of filter */
3558 mime_type_t
*temptype
; /* MIME type looping var */
3559 char filename
[1024], /* Full filter filename */
3560 *dirsep
; /* Pointer to directory separator */
3561 struct stat fileinfo
; /* File information */
3565 * Parse the filter string; it should be in the following format:
3567 * super/type cost program
3570 if (sscanf(filter
, "%15[^/]/%31s%d%*[ \t]%1023[^\n]", super
, type
, &cost
,
3573 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: invalid filter string \"%s\"!",
3579 * See if the filter program exists; if not, stop the printer and flag
3583 if (strcmp(program
, "-"))
3585 if (program
[0] == '/')
3586 strlcpy(filename
, program
, sizeof(filename
));
3588 snprintf(filename
, sizeof(filename
), "%s/filter/%s", ServerBin
, program
);
3590 if (stat(filename
, &fileinfo
))
3592 memset(&fileinfo
, 0, sizeof(fileinfo
));
3594 snprintf(p
->state_message
, sizeof(p
->state_message
),
3595 "Filter \"%s\" for printer \"%s\" not available: %s",
3596 filename
, p
->name
, strerror(errno
));
3597 cupsdSetPrinterReasons(p
, "+cups-missing-filter-warning");
3599 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s", p
->state_message
);
3603 * When running as root, do additional security checks...
3609 * Only use filters that are owned by root and do not have group or world
3610 * write permissions.
3613 if (fileinfo
.st_uid
||
3614 (fileinfo
.st_mode
& (S_ISUID
| S_IWGRP
| S_IWOTH
)) != 0)
3616 if (fileinfo
.st_uid
)
3617 snprintf(p
->state_message
, sizeof(p
->state_message
),
3618 "Filter \"%s\" for printer \"%s\" not owned by root",
3621 snprintf(p
->state_message
, sizeof(p
->state_message
),
3622 "Filter \"%s\" for printer \"%s\" has insecure permissions "
3623 "(0%o)", filename
, p
->name
, fileinfo
.st_mode
);
3625 cupsdSetPrinterReasons(p
, "+cups-insecure-filter-warning");
3627 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s", p
->state_message
);
3629 else if (fileinfo
.st_mode
)
3632 * Similarly, check that the parent directory is also owned by root and
3633 * does not have world write permissions.
3636 if ((dirsep
= strrchr(filename
, '/')) != NULL
)
3639 if (!stat(filename
, &fileinfo
) &&
3641 (fileinfo
.st_mode
& (S_ISUID
| S_IWGRP
| S_IWOTH
)) != 0))
3643 if (fileinfo
.st_uid
)
3644 snprintf(p
->state_message
, sizeof(p
->state_message
),
3645 "Filter directory \"%s\" for printer \"%s\" not owned by "
3646 "root", filename
, p
->name
);
3648 snprintf(p
->state_message
, sizeof(p
->state_message
),
3649 "Filter directory \"%s\" for printer \"%s\" has insecure "
3650 "permissions (0%o)", filename
, p
->name
, fileinfo
.st_mode
);
3652 cupsdSetPrinterReasons(p
, "+cups-insecure-filter-warning");
3654 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s", p
->state_message
);
3661 * Add the filter to the MIME database, supporting wildcards as needed...
3664 for (temptype
= mimeFirstType(MimeDatabase
);
3666 temptype
= mimeNextType(MimeDatabase
))
3667 if (((super
[0] == '*' && strcasecmp(temptype
->super
, "printer")) ||
3668 !strcasecmp(temptype
->super
, super
)) &&
3669 (type
[0] == '*' || !strcasecmp(temptype
->type
, type
)))
3671 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3672 "add_printer_filter: %s: adding filter %s/%s %s/%s %d %s",
3673 p
->name
, temptype
->super
, temptype
->type
,
3674 filtertype
->super
, filtertype
->type
,
3676 mimeAddFilter(MimeDatabase
, temptype
, filtertype
, cost
, program
);
3682 * 'add_printer_formats()' - Add document-format-supported values for a printer.
3686 add_printer_formats(cupsd_printer_t
*p
) /* I - Printer */
3688 int i
; /* Looping var */
3689 mime_type_t
*type
; /* Current MIME type */
3690 cups_array_t
*filters
; /* Filters */
3691 ipp_attribute_t
*attr
; /* document-format-supported attribute */
3692 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
3693 /* MIME type name */
3697 * Raw (and remote) queues advertise all of the supported MIME
3701 cupsArrayDelete(p
->filetypes
);
3702 p
->filetypes
= NULL
;
3706 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
,
3707 (ipp_tag_t
)(IPP_TAG_MIMETYPE
| IPP_TAG_COPY
),
3708 "document-format-supported", NumMimeTypes
, NULL
, MimeTypes
);
3713 * Otherwise, loop through the supported MIME types and see if there
3714 * are filters for them...
3717 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_printer_formats: %d types, %d filters",
3718 mimeNumTypes(MimeDatabase
), mimeNumFilters(MimeDatabase
));
3720 p
->filetypes
= cupsArrayNew(NULL
, NULL
);
3722 for (type
= mimeFirstType(MimeDatabase
);
3724 type
= mimeNextType(MimeDatabase
))
3726 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
3728 if ((filters
= mimeFilter(MimeDatabase
, type
, p
->filetype
, NULL
)) != NULL
)
3730 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3731 "add_printer_formats: %s: %s needs %d filters",
3732 p
->name
, mimetype
, cupsArrayCount(filters
));
3734 cupsArrayDelete(filters
);
3735 cupsArrayAdd(p
->filetypes
, type
);
3738 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3739 "add_printer_formats: %s: %s not supported",
3744 * Add the file formats that can be filtered...
3747 if ((type
= mimeType(MimeDatabase
, "application", "octet-stream")) == NULL
||
3748 !cupsArrayFind(p
->filetypes
, type
))
3753 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3754 "add_printer_formats: %s: %d supported types",
3755 p
->name
, cupsArrayCount(p
->filetypes
) + i
);
3757 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_MIMETYPE
,
3758 "document-format-supported",
3759 cupsArrayCount(p
->filetypes
) + i
, NULL
, NULL
);
3762 attr
->values
[0].string
.text
= _cupsStrAlloc("application/octet-stream");
3764 for (type
= (mime_type_t
*)cupsArrayFirst(p
->filetypes
);
3766 i
++, type
= (mime_type_t
*)cupsArrayNext(p
->filetypes
))
3768 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
3770 attr
->values
[i
].string
.text
= _cupsStrAlloc(mimetype
);
3775 char pdl
[1024]; /* Buffer to build pdl list */
3776 mime_filter_t
*filter
; /* MIME filter looping var */
3780 * We only support raw printing if this is not a Tioga PrintJobMgr based
3781 * queue and if application/octet-stream is a known type...
3784 for (filter
= (mime_filter_t
*)cupsArrayFirst(MimeDatabase
->filters
);
3786 filter
= (mime_filter_t
*)cupsArrayNext(MimeDatabase
->filters
))
3788 if (filter
->dst
== p
->filetype
&& filter
->filter
&&
3789 strstr(filter
->filter
, "PrintJobMgr"))
3795 if (!filter
&& mimeType(MimeDatabase
, "application", "octet-stream"))
3796 strlcat(pdl
, "application/octet-stream,", sizeof(pdl
));
3799 * Then list a bunch of formats that are supported by the printer...
3802 for (type
= (mime_type_t
*)cupsArrayFirst(p
->filetypes
);
3804 type
= (mime_type_t
*)cupsArrayNext(p
->filetypes
))
3806 if (!strcasecmp(type
->super
, "application"))
3808 if (!strcasecmp(type
->type
, "pdf"))
3809 strlcat(pdl
, "application/pdf,", sizeof(pdl
));
3810 else if (!strcasecmp(type
->type
, "postscript"))
3811 strlcat(pdl
, "application/postscript,", sizeof(pdl
));
3813 else if (!strcasecmp(type
->super
, "image"))
3815 if (!strcasecmp(type
->type
, "jpeg"))
3816 strlcat(pdl
, "image/jpeg,", sizeof(pdl
));
3817 else if (!strcasecmp(type
->type
, "png"))
3818 strlcat(pdl
, "image/png,", sizeof(pdl
));
3823 pdl
[strlen(pdl
) - 1] = '\0'; /* Remove trailing comma */
3825 cupsdSetString(&p
->pdl
, pdl
);
3827 #endif /* HAVE_DNSSD */
3832 * 'add_string_array()' - Add a string to an array of CUPS strings.
3836 add_string_array(cups_array_t
**a
, /* I - Array */
3837 const char *s
) /* I - String */
3840 *a
= cupsArrayNew(NULL
, NULL
);
3842 cupsArrayAdd(*a
, _cupsStrAlloc(s
));
3847 * 'compare_printers()' - Compare two printers.
3850 static int /* O - Result of comparison */
3851 compare_printers(void *first
, /* I - First printer */
3852 void *second
, /* I - Second printer */
3853 void *data
) /* I - App data (not used) */
3855 return (strcasecmp(((cupsd_printer_t
*)first
)->name
,
3856 ((cupsd_printer_t
*)second
)->name
));
3861 * 'delete_printer_filters()' - Delete all MIME filters for a printer.
3865 delete_printer_filters(
3866 cupsd_printer_t
*p
) /* I - Printer to remove from */
3868 mime_filter_t
*filter
; /* MIME filter looping var */
3872 * Range check input...
3879 * Remove all filters from the MIME database that have a destination
3880 * type == printer...
3883 for (filter
= mimeFirstFilter(MimeDatabase
);
3885 filter
= mimeNextFilter(MimeDatabase
))
3886 if (filter
->dst
== p
->filetype
|| filter
->dst
== p
->prefiltertype
)
3889 * Delete the current filter...
3892 mimeDeleteFilter(MimeDatabase
, filter
);
3895 cupsdSetPrinterReasons(p
, "-cups-insecure-filter-warning"
3896 ",cups-missing-filter-warning");
3901 * 'delete_string_array()' - Delete an array of CUPS strings.
3905 delete_string_array(cups_array_t
**a
) /* I - Array */
3907 char *ptr
; /* Current string */
3910 for (ptr
= (char *)cupsArrayFirst(*a
);
3912 ptr
= (char *)cupsArrayNext(*a
))
3915 cupsArrayDelete(*a
);
3921 * 'load_ppd()' - Load a cached PPD file, updating the cache as needed.
3925 load_ppd(cupsd_printer_t
*p
) /* I - Printer */
3927 int i
, j
, k
; /* Looping vars */
3928 cups_file_t
*cache
; /* IPP cache file */
3929 char cache_name
[1024]; /* IPP cache filename */
3930 struct stat cache_info
; /* IPP cache file info */
3931 char pwg_name
[1024]; /* PWG cache filename */
3932 struct stat pwg_info
; /* PWG cache file info */
3933 ppd_file_t
*ppd
; /* PPD file */
3934 char ppd_name
[1024]; /* PPD filename */
3935 struct stat ppd_info
; /* PPD file info */
3936 int num_media
; /* Number of media options */
3937 ppd_size_t
*size
; /* Current PPD size */
3938 ppd_option_t
*duplex
, /* Duplex option */
3939 *output_bin
, /* OutputBin option */
3940 *output_mode
, /* OutputMode option */
3941 *resolution
; /* (Set|JCL|)Resolution option */
3942 ppd_choice_t
*choice
, /* Current PPD choice */
3943 *input_slot
, /* Current input slot */
3944 *media_type
; /* Current media type */
3945 ppd_attr_t
*ppd_attr
; /* PPD attribute */
3946 int xdpi
, /* Horizontal resolution */
3947 ydpi
; /* Vertical resolution */
3948 const char *resptr
; /* Pointer into resolution keyword */
3949 _pwg_size_t
*pwgsize
; /* Current PWG size */
3950 _pwg_map_t
*pwgsource
, /* Current PWG source */
3951 *pwgtype
; /* Current PWG type */
3952 ipp_attribute_t
*attr
; /* Attribute data */
3953 ipp_value_t
*val
; /* Attribute value */
3954 int num_finishings
, /* Number of finishings */
3955 finishings
[5]; /* finishings-supported values */
3956 int num_qualities
, /* Number of print-quality values */
3957 qualities
[3]; /* print-quality values */
3958 int num_margins
, /* Number of media-*-margin-supported values */
3959 margins
[16]; /* media-*-margin-supported values */
3960 static const char * const sides
[3] = /* sides-supported values */
3963 "two-sided-long-edge",
3964 "two-sided-short-edge"
3966 static const char * const standard_commands
[] =
3967 { /* Standard CUPS commands */
3975 * Check to see if the cache is up-to-date...
3978 snprintf(cache_name
, sizeof(cache_name
), "%s/%s.ipp2", CacheDir
, p
->name
);
3979 if (stat(cache_name
, &cache_info
))
3980 cache_info
.st_mtime
= 0;
3982 snprintf(pwg_name
, sizeof(pwg_name
), "%s/%s.pwg", CacheDir
, p
->name
);
3983 if (stat(pwg_name
, &pwg_info
))
3984 pwg_info
.st_mtime
= 0;
3986 snprintf(ppd_name
, sizeof(ppd_name
), "%s/ppd/%s.ppd", ServerRoot
, p
->name
);
3987 if (stat(ppd_name
, &ppd_info
))
3988 ppd_info
.st_mtime
= 1;
3990 ippDelete(p
->ppd_attrs
);
3991 p
->ppd_attrs
= ippNew();
3993 _pwgDestroy(p
->pwg
);
3996 if (pwg_info
.st_mtime
>= ppd_info
.st_mtime
)
3997 p
->pwg
= _pwgCreateWithFile(pwg_name
);
3999 if (cache_info
.st_mtime
>= ppd_info
.st_mtime
&& p
->pwg
&&
4000 (cache
= cupsFileOpen(cache_name
, "r")) != NULL
)
4003 * Load cached information and return...
4006 cupsdLogMessage(CUPSD_LOG_DEBUG
, "load_ppd: Loading %s...", cache_name
);
4008 if (ippReadIO(cache
, (ipp_iocb_t
)cupsFileRead
, 1, NULL
,
4009 p
->ppd_attrs
) == IPP_DATA
)
4011 cupsFileClose(cache
);
4015 cupsFileClose(cache
);
4019 * Reload PPD attributes from disk...
4022 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
4024 _pwgDestroy(p
->pwg
);
4027 cupsdLogMessage(CUPSD_LOG_DEBUG
, "load_ppd: Loading %s...", ppd_name
);
4029 delete_string_array(&(p
->filters
));
4030 delete_string_array(&(p
->pre_filters
));
4032 p
->type
&= ~CUPS_PRINTER_OPTIONS
;
4033 p
->type
|= CUPS_PRINTER_BW
;
4035 finishings
[0] = IPP_FINISHINGS_NONE
;
4038 if ((ppd
= ppdOpenFile(ppd_name
)) != NULL
)
4041 * Add make/model and other various attributes...
4044 p
->pwg
= _pwgCreateWithPPD(ppd
);
4046 ppdMarkDefaults(ppd
);
4048 if (ppd
->color_device
)
4049 p
->type
|= CUPS_PRINTER_COLOR
;
4050 if (ppd
->variable_sizes
)
4051 p
->type
|= CUPS_PRINTER_VARIABLE
;
4052 if (!ppd
->manual_copies
)
4053 p
->type
|= CUPS_PRINTER_COPIES
;
4054 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsFax", NULL
)) != NULL
)
4055 if (ppd_attr
->value
&& !strcasecmp(ppd_attr
->value
, "true"))
4056 p
->type
|= CUPS_PRINTER_FAX
;
4058 ippAddBoolean(p
->ppd_attrs
, IPP_TAG_PRINTER
, "color-supported",
4060 if (ppd
->throughput
)
4062 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4063 "pages-per-minute", ppd
->throughput
);
4064 if (ppd
->color_device
)
4065 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4066 "pages-per-minute-color", ppd
->throughput
);
4071 if ((output_mode
= ppdFindOption(ppd
, "OutputMode")) != NULL
)
4073 if (ppdFindChoice(output_mode
, "draft") ||
4074 ppdFindChoice(output_mode
, "fast"))
4075 qualities
[num_qualities
++] = IPP_QUALITY_DRAFT
;
4076 if (ppdFindChoice(output_mode
, "normal") ||
4077 ppdFindChoice(output_mode
, "good"))
4078 qualities
[num_qualities
++] = IPP_QUALITY_NORMAL
;
4079 if (ppdFindChoice(output_mode
, "best") ||
4080 ppdFindChoice(output_mode
, "high"))
4081 qualities
[num_qualities
++] = IPP_QUALITY_HIGH
;
4083 else if ((ppd_attr
= ppdFindAttr(ppd
, "APPrinterPreset", NULL
)) != NULL
)
4087 if (strstr(ppd_attr
->spec
, "draft") ||
4088 strstr(ppd_attr
->spec
, "Draft"))
4090 qualities
[num_qualities
++] = IPP_QUALITY_DRAFT
;
4094 while ((ppd_attr
= ppdFindNextAttr(ppd
, "APPrinterPreset",
4097 qualities
[num_qualities
++] = IPP_QUALITY_NORMAL
;
4098 qualities
[num_qualities
++] = IPP_QUALITY_HIGH
;
4101 if (num_qualities
== 0)
4102 qualities
[num_qualities
++] = IPP_QUALITY_NORMAL
;
4104 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
4105 "print-quality-supported", num_qualities
, qualities
);
4110 * The NickName can be localized in the character set specified
4111 * by the LanugageEncoding attribute. However, ppdOpen2() has
4112 * already converted the ppd->nickname member to UTF-8 for us
4113 * (the original attribute value is available separately)
4116 cupsdSetString(&p
->make_model
, ppd
->nickname
);
4118 else if (ppd
->modelname
)
4121 * Model name can only contain specific characters...
4124 cupsdSetString(&p
->make_model
, ppd
->modelname
);
4127 cupsdSetString(&p
->make_model
, "Bad PPD File");
4129 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
4130 "printer-make-and-model", NULL
, p
->make_model
);
4133 * Add media options from the PPD file...
4136 if (ppd
->num_sizes
== 0 || !p
->pwg
)
4138 if (!ppdFindAttr(ppd
, "APScannerOnly", NULL
))
4139 cupsdLogMessage(CUPSD_LOG_CRIT
,
4140 "The PPD file for printer %s contains no media "
4141 "options and is therefore invalid!", p
->name
);
4143 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4144 "media-default", NULL
, "unknown");
4145 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4146 "media-supported", NULL
, "unknown");
4154 if ((size
= ppdPageSize(ppd
, NULL
)) != NULL
)
4155 pwgsize
= _pwgGetSize(p
->pwg
, size
->name
);
4159 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4160 "media-default", NULL
,
4161 pwgsize
? pwgsize
->map
.pwg
: "unknown");
4169 input_slot
= ppdFindMarkedChoice(ppd
, "InputSlot");
4170 media_type
= ppdFindMarkedChoice(ppd
, "MediaType");
4172 ippAddCollection(p
->ppd_attrs
, IPP_TAG_PRINTER
, "media-col-default",
4173 new_media_col(pwgsize
,
4175 _pwgGetSource(p
->pwg
,
4176 input_slot
->choice
) :
4180 media_type
->choice
) :
4188 num_media
= p
->pwg
->num_sizes
;
4189 if (p
->pwg
->custom_min_keyword
)
4192 if ((attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4193 "media-supported", num_media
, NULL
,
4198 for (i
= p
->pwg
->num_sizes
, pwgsize
= p
->pwg
->sizes
;
4200 i
--, pwgsize
++, val
++)
4201 val
->string
.text
= _cupsStrRetain(pwgsize
->map
.pwg
);
4203 if (p
->pwg
->custom_min_keyword
)
4205 val
->string
.text
= _cupsStrRetain(p
->pwg
->custom_min_keyword
);
4207 val
->string
.text
= _cupsStrRetain(p
->pwg
->custom_max_keyword
);
4212 * media-source-supported
4215 if (p
->pwg
->num_sources
> 0 &&
4216 (attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4217 "media-source-supported", p
->pwg
->num_sources
,
4218 NULL
, NULL
)) != NULL
)
4220 for (i
= p
->pwg
->num_sources
, pwgsource
= p
->pwg
->sources
,
4223 i
--, pwgsource
++, val
++)
4224 val
->string
.text
= _cupsStrRetain(pwgsource
->pwg
);
4228 * media-type-supported
4231 if (p
->pwg
->num_types
> 0 &&
4232 (attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4233 "media-type-supported", p
->pwg
->num_types
,
4234 NULL
, NULL
)) != NULL
)
4236 for (i
= p
->pwg
->num_types
, pwgtype
= p
->pwg
->types
,
4239 i
--, pwgtype
++, val
++)
4240 val
->string
.text
= _cupsStrRetain(pwgtype
->pwg
);
4244 * media-*-margin-supported
4247 for (i
= p
->pwg
->num_sizes
, pwgsize
= p
->pwg
->sizes
, num_margins
= 0;
4248 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4251 for (j
= 0; j
< num_margins
; j
++)
4252 if (pwgsize
->bottom
== margins
[j
])
4255 if (j
>= num_margins
)
4257 margins
[num_margins
] = pwgsize
->bottom
;
4262 if (num_margins
> 0)
4263 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4264 "media-bottom-margin-supported", num_margins
, margins
);
4266 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4267 "media-bottom-margin-supported", 0);
4269 for (i
= p
->pwg
->num_sizes
, pwgsize
= p
->pwg
->sizes
, num_margins
= 0;
4270 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4273 for (j
= 0; j
< num_margins
; j
++)
4274 if (pwgsize
->left
== margins
[j
])
4277 if (j
>= num_margins
)
4279 margins
[num_margins
] = pwgsize
->left
;
4284 if (num_margins
> 0)
4285 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4286 "media-left-margin-supported", num_margins
, margins
);
4288 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4289 "media-left-margin-supported", 0);
4291 for (i
= p
->pwg
->num_sizes
, pwgsize
= p
->pwg
->sizes
, num_margins
= 0;
4292 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4295 for (j
= 0; j
< num_margins
; j
++)
4296 if (pwgsize
->right
== margins
[j
])
4299 if (j
>= num_margins
)
4301 margins
[num_margins
] = pwgsize
->right
;
4306 if (num_margins
> 0)
4307 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4308 "media-right-margin-supported", num_margins
, margins
);
4310 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4311 "media-right-margin-supported", 0);
4313 for (i
= p
->pwg
->num_sizes
, pwgsize
= p
->pwg
->sizes
, num_margins
= 0;
4314 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4317 for (j
= 0; j
< num_margins
; j
++)
4318 if (pwgsize
->top
== margins
[j
])
4321 if (j
>= num_margins
)
4323 margins
[num_margins
] = pwgsize
->top
;
4328 if (num_margins
> 0)
4329 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4330 "media-top-margin-supported", num_margins
, margins
);
4332 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4333 "media-top-margin-supported", 0);
4336 * media-col-database
4339 num_media
= p
->pwg
->num_sizes
;
4340 if (p
->pwg
->num_sources
)
4342 if (p
->pwg
->num_types
> 0)
4343 num_media
+= p
->pwg
->num_sizes
* p
->pwg
->num_sources
*
4346 num_media
+= p
->pwg
->num_sizes
* p
->pwg
->num_sources
;
4348 else if (p
->pwg
->num_types
)
4349 num_media
+= p
->pwg
->num_sizes
* p
->pwg
->num_types
;
4351 if ((attr
= ippAddCollections(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4352 "media-col-database", num_media
,
4355 for (i
= p
->pwg
->num_sizes
, pwgsize
= p
->pwg
->sizes
, val
= attr
->values
;
4360 * Start by adding the page size without source or type...
4363 ppdMarkOption(ppd
, "PageSize", pwgsize
->map
.ppd
);
4365 val
->collection
= new_media_col(pwgsize
, NULL
, NULL
);
4369 * Then add the specific, supported combinations of size, source, and
4373 if (p
->pwg
->num_sources
> 0)
4375 for (j
= p
->pwg
->num_sources
, pwgsource
= p
->pwg
->sources
;
4379 ppdMarkOption(ppd
, "InputSlot", pwgsource
->ppd
);
4381 if (p
->pwg
->num_types
> 0)
4383 for (k
= p
->pwg
->num_types
, pwgtype
= p
->pwg
->types
;
4387 if (!ppdMarkOption(ppd
, "MediaType", pwgtype
->ppd
))
4389 val
->collection
= new_media_col(pwgsize
, pwgsource
->pwg
,
4395 else if (!ppdConflicts(ppd
))
4397 val
->collection
= new_media_col(pwgsize
, pwgsource
->pwg
, NULL
);
4402 else if (p
->pwg
->num_types
> 0)
4404 for (j
= p
->pwg
->num_types
, pwgtype
= p
->pwg
->types
;
4408 if (!ppdMarkOption(ppd
, "MediaType", pwgtype
->ppd
))
4410 val
->collection
= new_media_col(pwgsize
, NULL
, pwgtype
->pwg
);
4418 * Update the number of media-col-database values...
4421 attr
->num_values
= val
- attr
->values
;
4429 if ((output_bin
= ppdFindOption(ppd
, "OutputBin")) != NULL
)
4431 attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4432 "output-bin-supported", output_bin
->num_choices
,
4437 for (i
= 0, val
= attr
->values
;
4438 i
< output_bin
->num_choices
;
4440 val
->string
.text
= _cupsStrAlloc(output_bin
->choices
[i
].choice
);
4443 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4444 "output-bin-default", NULL
, output_bin
->defchoice
);
4448 * Printer resolutions...
4451 if ((resolution
= ppdFindOption(ppd
, "Resolution")) == NULL
)
4452 if ((resolution
= ppdFindOption(ppd
, "JCLResolution")) == NULL
)
4453 if ((resolution
= ppdFindOption(ppd
, "SetResolution")) == NULL
)
4454 resolution
= ppdFindOption(ppd
, "CNRes_PGP");
4459 * Report all supported resolutions...
4462 attr
= ippAddResolutions(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4463 "printer-resolution-supported",
4464 resolution
->num_choices
, IPP_RES_PER_INCH
,
4467 for (i
= 0, choice
= resolution
->choices
;
4468 i
< resolution
->num_choices
;
4471 xdpi
= (int)strtol(choice
->choice
, (char **)&resptr
, 10);
4472 if (resptr
> choice
->choice
&& xdpi
> 0)
4475 ydpi
= (int)strtol(resptr
+ 1, (char **)&resptr
, 10);
4480 if (xdpi
<= 0 || ydpi
<= 0)
4482 cupsdLogMessage(CUPSD_LOG_WARN
,
4483 "Bad resolution \"%s\" for printer %s.",
4484 choice
->choice
, p
->name
);
4488 attr
->values
[i
].resolution
.xres
= xdpi
;
4489 attr
->values
[i
].resolution
.yres
= ydpi
;
4490 attr
->values
[i
].resolution
.units
= IPP_RES_PER_INCH
;
4493 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4494 "printer-resolution-default", IPP_RES_PER_INCH
,
4498 else if ((ppd_attr
= ppdFindAttr(ppd
, "DefaultResolution", NULL
)) != NULL
&&
4502 * Just the DefaultResolution to report...
4505 xdpi
= (int)strtol(ppd_attr
->value
, (char **)&resptr
, 10);
4506 if (resptr
> ppd_attr
->value
&& xdpi
> 0)
4509 ydpi
= (int)strtol(resptr
+ 1, (char **)&resptr
, 10);
4514 if (xdpi
<= 0 || ydpi
<= 0)
4516 cupsdLogMessage(CUPSD_LOG_WARN
,
4517 "Bad default resolution \"%s\" for printer %s.",
4518 ppd_attr
->value
, p
->name
);
4522 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4523 "printer-resolution-default", IPP_RES_PER_INCH
,
4525 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4526 "printer-resolution-supported", IPP_RES_PER_INCH
,
4532 * No resolutions in PPD - make one up...
4535 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4536 "printer-resolution-default", IPP_RES_PER_INCH
,
4538 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4539 "printer-resolution-supported", IPP_RES_PER_INCH
,
4547 if ((duplex
= ppdFindOption(ppd
, "Duplex")) == NULL
)
4548 if ((duplex
= ppdFindOption(ppd
, "EFDuplex")) == NULL
)
4549 if ((duplex
= ppdFindOption(ppd
, "EFDuplexing")) == NULL
)
4550 if ((duplex
= ppdFindOption(ppd
, "KD03Duplex")) == NULL
)
4551 duplex
= ppdFindOption(ppd
, "JCLDuplex");
4553 if (duplex
&& duplex
->num_choices
> 1 &&
4554 !ppdInstallableConflict(ppd
, duplex
->keyword
, "DuplexTumble"))
4556 p
->type
|= CUPS_PRINTER_DUPLEX
;
4558 ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4559 "sides-supported", 3, NULL
, sides
);
4561 if (!strcasecmp(duplex
->defchoice
, "DuplexTumble"))
4562 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4563 "sides-default", NULL
, "two-sided-short-edge");
4564 else if (!strcasecmp(duplex
->defchoice
, "DuplexNoTumble"))
4565 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4566 "sides-default", NULL
, "two-sided-long-edge");
4568 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4569 "sides-default", NULL
, "one-sided");
4572 if (ppdFindOption(ppd
, "Collate") != NULL
)
4573 p
->type
|= CUPS_PRINTER_COLLATE
;
4575 if (ppdFindOption(ppd
, "StapleLocation") != NULL
)
4577 p
->type
|= CUPS_PRINTER_STAPLE
;
4578 finishings
[num_finishings
++] = IPP_FINISHINGS_STAPLE
;
4581 if (ppdFindOption(ppd
, "BindEdge") != NULL
)
4583 p
->type
|= CUPS_PRINTER_BIND
;
4584 finishings
[num_finishings
++] = IPP_FINISHINGS_BIND
;
4587 for (i
= 0; i
< ppd
->num_sizes
; i
++)
4588 if (ppd
->sizes
[i
].length
> 1728)
4589 p
->type
|= CUPS_PRINTER_LARGE
;
4590 else if (ppd
->sizes
[i
].length
> 1008)
4591 p
->type
|= CUPS_PRINTER_MEDIUM
;
4593 p
->type
|= CUPS_PRINTER_SMALL
;
4595 if ((ppd_attr
= ppdFindAttr(ppd
, "APICADriver", NULL
)) != NULL
&&
4596 ppd_attr
->value
&& !strcasecmp(ppd_attr
->value
, "true"))
4598 if ((ppd_attr
= ppdFindAttr(ppd
, "APScannerOnly", NULL
)) != NULL
&&
4599 ppd_attr
->value
&& !strcasecmp(ppd_attr
->value
, "true"))
4600 p
->type
|= CUPS_PRINTER_SCANNER
;
4602 p
->type
|= CUPS_PRINTER_MFP
;
4606 * Add a filter from application/vnd.cups-raw to printer/name to
4607 * handle "raw" printing by users.
4610 add_string_array(&(p
->filters
), "application/vnd.cups-raw 0 -");
4613 * Add any pre-filters in the PPD file...
4616 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsPreFilter", NULL
)) != NULL
)
4618 for (; ppd_attr
; ppd_attr
= ppdFindNextAttr(ppd
, "cupsPreFilter", NULL
))
4619 if (ppd_attr
->value
)
4620 add_string_array(&(p
->pre_filters
), ppd_attr
->value
);
4624 * Add any filters in the PPD file...
4627 DEBUG_printf(("ppd->num_filters = %d\n", ppd
->num_filters
));
4628 for (i
= 0; i
< ppd
->num_filters
; i
++)
4630 DEBUG_printf(("ppd->filters[%d] = \"%s\"\n", i
, ppd
->filters
[i
]));
4631 add_string_array(&(p
->filters
), ppd
->filters
[i
]);
4633 if (!strncasecmp(ppd
->filters
[i
], "application/vnd.cups-command", 28) &&
4634 isspace(ppd
->filters
[i
][28] & 255))
4635 p
->type
|= CUPS_PRINTER_COMMANDS
;
4638 if (ppd
->num_filters
== 0)
4641 * If there are no filters, add PostScript printing filters.
4644 add_string_array(&(p
->filters
),
4645 "application/vnd.cups-command 0 commandtops");
4646 add_string_array(&(p
->filters
),
4647 "application/vnd.cups-postscript 0 -");
4649 p
->type
|= CUPS_PRINTER_COMMANDS
;
4651 else if (!(p
->type
& CUPS_PRINTER_COMMANDS
))
4654 * See if this is a PostScript device without a command filter...
4657 for (i
= 0; i
< ppd
->num_filters
; i
++)
4658 if (!strncasecmp(ppd
->filters
[i
],
4659 "application/vnd.cups-postscript", 31) &&
4660 isspace(ppd
->filters
[i
][31] & 255))
4663 if (i
< ppd
->num_filters
)
4666 * Add the generic PostScript command filter...
4669 add_string_array(&(p
->filters
),
4670 "application/vnd.cups-command 0 commandtops");
4671 p
->type
|= CUPS_PRINTER_COMMANDS
;
4675 if (p
->type
& CUPS_PRINTER_COMMANDS
)
4677 char *commands
, /* Copy of commands */
4678 *start
, /* Start of name */
4679 *end
; /* End of name */
4680 int count
; /* Number of commands */
4683 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsCommands", NULL
)) != NULL
&&
4684 ppd_attr
->value
&& ppd_attr
->value
[0])
4686 for (count
= 0, start
= ppd_attr
->value
; *start
; count
++)
4688 while (isspace(*start
& 255))
4694 while (*start
&& !isspace(*start
& 255))
4704 * Make a copy of the commands string and count how many ...
4707 attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4708 "printer-commands", count
, NULL
, NULL
);
4710 commands
= strdup(ppd_attr
->value
);
4712 for (count
= 0, start
= commands
; *start
; count
++)
4714 while (isspace(*start
& 255))
4721 while (*end
&& !isspace(*end
& 255))
4727 attr
->values
[count
].string
.text
= _cupsStrAlloc(start
);
4737 * Add the standard list of commands...
4740 ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4742 (int)(sizeof(standard_commands
) /
4743 sizeof(standard_commands
[0])), NULL
,
4750 * No commands supported...
4753 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4754 "printer-commands", NULL
, "none");
4758 * Show current and available port monitors for this printer...
4761 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
, "port-monitor",
4762 NULL
, p
->port_monitor
? p
->port_monitor
: "none");
4764 for (i
= 1, ppd_attr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
4766 i
++, ppd_attr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
));
4770 if (strstr(ppd
->protocols
, "TBCP"))
4772 else if (strstr(ppd
->protocols
, "BCP"))
4776 attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
4777 "port-monitor-supported", i
, NULL
, NULL
);
4779 attr
->values
[0].string
.text
= _cupsStrAlloc("none");
4781 for (i
= 1, ppd_attr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
4783 i
++, ppd_attr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
))
4784 attr
->values
[i
].string
.text
= _cupsStrAlloc(ppd_attr
->value
);
4788 if (strstr(ppd
->protocols
, "TBCP"))
4789 attr
->values
[i
].string
.text
= _cupsStrAlloc("tbcp");
4790 else if (strstr(ppd
->protocols
, "BCP"))
4791 attr
->values
[i
].string
.text
= _cupsStrAlloc("bcp");
4795 cupsdSetString(&p
->product
, ppd
->product
);
4796 #endif /* HAVE_DNSSD */
4798 if (ppdFindAttr(ppd
, "APRemoteQueueID", NULL
))
4799 p
->type
|= CUPS_PRINTER_REMOTE
;
4802 * Close the PPD and set the type...
4807 else if (!access(ppd_name
, 0))
4809 int pline
; /* PPD line number */
4810 ppd_status_t pstatus
; /* PPD load status */
4813 pstatus
= ppdLastError(&pline
);
4815 cupsdLogMessage(CUPSD_LOG_ERROR
, "PPD file for %s cannot be loaded!",
4818 if (pstatus
<= PPD_ALLOC_ERROR
)
4819 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s", strerror(errno
));
4821 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s on line %d.",
4822 ppdErrorString(pstatus
), pline
);
4824 cupsdLogMessage(CUPSD_LOG_INFO
,
4825 "Hint: Run \"cupstestppd %s\" and fix any errors.",
4829 * Add a filter from application/vnd.cups-raw to printer/name to
4830 * handle "raw" printing by users.
4833 add_string_array(&(p
->filters
), "application/vnd.cups-raw 0 -");
4836 * Add a PostScript filter, since this is still possibly PS printer.
4839 add_string_array(&(p
->filters
), "application/vnd.cups-postscript 0 -");
4844 * If we have an interface script, add a filter entry for it...
4847 char interface
[1024]; /* Interface script */
4850 snprintf(interface
, sizeof(interface
), "%s/interfaces/%s", ServerRoot
,
4852 if (!access(interface
, X_OK
))
4855 * Yes, we have a System V style interface script; use it!
4858 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
4859 "printer-make-and-model", NULL
,
4860 "Local System V Printer");
4862 snprintf(interface
, sizeof(interface
), "*/* 0 %s/interfaces/%s",
4863 ServerRoot
, p
->name
);
4864 add_string_array(&(p
->filters
), interface
);
4866 else if (!strncmp(p
->device_uri
, "ipp://", 6) &&
4867 (strstr(p
->device_uri
, "/printers/") != NULL
||
4868 strstr(p
->device_uri
, "/classes/") != NULL
||
4869 (strstr(p
->device_uri
, "._ipp.") != NULL
&&
4870 !strcmp(p
->device_uri
+ strlen(p
->device_uri
) - 5,
4874 * Tell the client this is really a hard-wired remote printer.
4877 p
->type
|= CUPS_PRINTER_REMOTE
;
4880 * Point the printer-uri-supported attribute to the
4884 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
4885 "printer-uri-supported", NULL
, p
->device_uri
);
4888 * Then set the make-and-model accordingly...
4891 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
4892 "printer-make-and-model", NULL
, "Remote Printer");
4895 * Print all files directly...
4904 * Otherwise we have neither - treat this as a "dumb" printer
4905 * with no PPD file...
4908 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
4909 "printer-make-and-model", NULL
, "Local Raw Printer");
4915 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
4916 "finishings-supported", num_finishings
, finishings
);
4917 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
4918 "finishings-default", IPP_FINISHINGS_NONE
);
4920 if (ppd
&& (cache
= cupsFileOpen(cache_name
, "w9")) != NULL
)
4923 * Save cached PPD attributes to disk...
4926 cupsdLogMessage(CUPSD_LOG_DEBUG
, "load_ppd: Saving %s...", cache_name
);
4928 p
->ppd_attrs
->state
= IPP_IDLE
;
4930 if (ippWriteIO(cache
, (ipp_iocb_t
)cupsFileWrite
, 1, NULL
,
4931 p
->ppd_attrs
) != IPP_DATA
)
4933 cupsdLogMessage(CUPSD_LOG_ERROR
,
4934 "Unable to save PPD cache file \"%s\" - %s", cache_name
,
4939 cupsFileClose(cache
);
4941 _pwgWriteFile(p
->pwg
, pwg_name
);
4946 * Remove cache files...
4949 if (cache_info
.st_mtime
)
4952 if (pwg_info
.st_mtime
)
4959 * 'new_media_col()' - Create a media-col collection value.
4962 static ipp_t
* /* O - Collection value */
4963 new_media_col(_pwg_size_t
*size
, /* I - media-size/margin values */
4964 const char *source
, /* I - media-source value */
4965 const char *type
) /* I - media-type value */
4967 ipp_t
*media_col
, /* Collection value */
4968 *media_size
; /* media-size value */
4971 media_col
= ippNew();
4973 media_size
= ippNew();
4974 ippAddInteger(media_size
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4975 "x-dimension", size
->width
);
4976 ippAddInteger(media_size
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4977 "y-dimension", size
->length
);
4979 ippAddCollection(media_col
, IPP_TAG_PRINTER
, "media-size", media_size
);
4980 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4981 "media-bottom-margin", size
->bottom
);
4982 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4983 "media-left-margin", size
->left
);
4984 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4985 "media-right-margin", size
->right
);
4986 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4987 "media-top-margin", size
->top
);
4990 ippAddString(media_col
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
, "media-source",
4994 ippAddString(media_col
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
, "media-type",
5003 * 'write_irix_config()' - Update the config files used by the IRIX
5008 write_irix_config(cupsd_printer_t
*p
) /* I - Printer to update */
5010 char filename
[1024]; /* Interface script filename */
5011 cups_file_t
*fp
; /* Interface script file */
5012 ipp_attribute_t
*attr
; /* Attribute data */
5016 * Add dummy interface and GUI scripts to fool SGI's "challenged" printing
5017 * tools. First the interface script that tells the tools what kind of
5018 * printer we have...
5021 snprintf(filename
, sizeof(filename
), "/var/spool/lp/interface/%s", p
->name
);
5023 if (p
->type
& CUPS_PRINTER_CLASS
)
5025 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
5027 cupsFilePuts(fp
, "#!/bin/sh\n");
5029 if ((attr
= ippFindAttribute(p
->attrs
, "printer-make-and-model",
5030 IPP_TAG_TEXT
)) != NULL
)
5031 cupsFilePrintf(fp
, "NAME=\"%s\"\n", attr
->values
[0].string
.text
);
5032 else if (p
->type
& CUPS_PRINTER_CLASS
)
5033 cupsFilePuts(fp
, "NAME=\"Printer Class\"\n");
5035 cupsFilePuts(fp
, "NAME=\"Remote Destination\"\n");
5037 if (p
->type
& CUPS_PRINTER_COLOR
)
5038 cupsFilePuts(fp
, "TYPE=ColorPostScript\n");
5040 cupsFilePuts(fp
, "TYPE=MonoPostScript\n");
5042 cupsFilePrintf(fp
, "HOSTNAME=%s\n", ServerName
);
5043 cupsFilePrintf(fp
, "HOSTPRINTER=%s\n", p
->name
);
5047 chmod(filename
, 0755);
5048 chown(filename
, User
, Group
);
5052 * Then the member file that tells which device file the queue is connected
5053 * to... Networked printers use "/dev/null" in this file, so that's what
5054 * we use (the actual device URI can confuse some apps...)
5057 snprintf(filename
, sizeof(filename
), "/var/spool/lp/member/%s", p
->name
);
5059 if (p
->type
& CUPS_PRINTER_CLASS
)
5061 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
5063 cupsFilePuts(fp
, "/dev/null\n");
5067 chmod(filename
, 0644);
5068 chown(filename
, User
, Group
);
5072 * The gui_interface file is a script or program that launches a GUI
5073 * option panel for the printer, using options specified on the
5074 * command-line in the third argument. The option panel must send
5075 * any printing options to stdout on a single line when the user
5076 * accepts them, or nothing if the user cancels the dialog.
5078 * The default options panel program is /usr/bin/glpoptions, from
5079 * the ESP Print Pro software. You can select another using the
5080 * PrintcapGUI option.
5083 snprintf(filename
, sizeof(filename
), "/var/spool/lp/gui_interface/ELF/%s.gui", p
->name
);
5085 if (p
->type
& CUPS_PRINTER_CLASS
)
5087 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
5089 cupsFilePuts(fp
, "#!/bin/sh\n");
5090 cupsFilePrintf(fp
, "%s -d %s -o \"$3\"\n", PrintcapGUI
, p
->name
);
5094 chmod(filename
, 0755);
5095 chown(filename
, User
, Group
);
5099 * The POD config file is needed by the printstatus command to show
5100 * the printer location and device.
5103 snprintf(filename
, sizeof(filename
), "/var/spool/lp/pod/%s.config", p
->name
);
5105 if (p
->type
& CUPS_PRINTER_CLASS
)
5107 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
5109 cupsFilePrintf(fp
, "Printer Class | %s\n",
5110 (p
->type
& CUPS_PRINTER_COLOR
) ? "ColorPostScript" : "MonoPostScript");
5111 cupsFilePrintf(fp
, "Printer Model | %s\n", p
->make_model
? p
->make_model
: "");
5112 cupsFilePrintf(fp
, "Location Code | %s\n", p
->location
? p
->location
: "");
5113 cupsFilePrintf(fp
, "Physical Location | %s\n", p
->info
? p
->info
: "");
5114 cupsFilePrintf(fp
, "Port Path | %s\n", p
->device_uri
);
5115 cupsFilePrintf(fp
, "Config Path | /var/spool/lp/pod/%s.config\n", p
->name
);
5116 cupsFilePrintf(fp
, "Active Status Path | /var/spool/lp/pod/%s.status\n", p
->name
);
5117 cupsFilePuts(fp
, "Status Update Wait | 10 seconds\n");
5121 chmod(filename
, 0664);
5122 chown(filename
, User
, Group
);
5128 * 'write_irix_state()' - Update the status files used by IRIX printing
5133 write_irix_state(cupsd_printer_t
*p
) /* I - Printer to update */
5135 char filename
[1024]; /* Interface script filename */
5136 cups_file_t
*fp
; /* Interface script file */
5137 int tag
; /* Status tag value */
5143 * The POD status file is needed for the printstatus window to
5144 * provide the current status of the printer.
5147 snprintf(filename
, sizeof(filename
), "/var/spool/lp/pod/%s.status", p
->name
);
5149 if (p
->type
& CUPS_PRINTER_CLASS
)
5151 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
5153 cupsFilePrintf(fp
, "Operational Status | %s\n",
5154 (p
->state
== IPP_PRINTER_IDLE
) ? "Idle" :
5155 (p
->state
== IPP_PRINTER_PROCESSING
) ? "Busy" :
5157 cupsFilePrintf(fp
, "Information | 01 00 00 | %s\n", CUPS_SVERSION
);
5158 cupsFilePrintf(fp
, "Information | 02 00 00 | Device URI: %s\n",
5160 cupsFilePrintf(fp
, "Information | 03 00 00 | %s jobs\n",
5161 p
->accepting
? "Accepting" : "Not accepting");
5162 cupsFilePrintf(fp
, "Information | 04 00 00 | %s\n", p
->state_message
);
5166 chmod(filename
, 0664);
5167 chown(filename
, User
, Group
);
5171 * The activeicons file is needed to provide desktop icons for printers:
5173 * [ quoted from /usr/lib/print/tagit ]
5175 * --- Type of printer tags (base values)
5177 * Dumb=66048 # 0x10200
5178 * DumbColor=66080 # 0x10220
5179 * Raster=66112 # 0x10240
5180 * ColorRaster=66144 # 0x10260
5181 * Plotter=66176 # 0x10280
5182 * PostScript=66208 # 0x102A0
5183 * ColorPostScript=66240 # 0x102C0
5184 * MonoPostScript=66272 # 0x102E0
5186 * --- Printer state modifiers for local printers
5191 * Unknown=3 # 0x3 (Faulted due to unknown reason)
5193 * --- Printer state modifiers for network printers
5197 * NetFaulted=10 # 0xA
5198 * NetUnknown=11 # 0xB (Faulted due to unknown reason)
5201 snprintf(filename
, sizeof(filename
), "/var/spool/lp/activeicons/%s", p
->name
);
5203 if (p
->type
& CUPS_PRINTER_CLASS
)
5205 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
5207 if (p
->type
& CUPS_PRINTER_COLOR
)
5212 if (p
->type
& CUPS_PRINTER_REMOTE
)
5215 if (p
->state
== IPP_PRINTER_PROCESSING
)
5218 else if (p
->state
== IPP_PRINTER_STOPPED
)
5221 cupsFilePuts(fp
, "#!/bin/sh\n");
5222 cupsFilePrintf(fp
, "#Tag %d\n", tag
);
5226 chmod(filename
, 0755);
5227 chown(filename
, User
, Group
);
5232 * The default file is needed by the printers window to show
5233 * the default printer.
5236 snprintf(filename
, sizeof(filename
), "/var/spool/lp/default");
5238 if (DefaultPrinter
!= NULL
)
5240 if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
5242 cupsFilePrintf(fp
, "%s\n", DefaultPrinter
->name
);
5246 chmod(filename
, 0644);
5247 chown(filename
, User
, Group
);
5257 * 'write_xml_string()' - Write a string with XML escaping.
5261 write_xml_string(cups_file_t
*fp
, /* I - File to write to */
5262 const char *s
) /* I - String to write */
5264 const char *start
; /* Start of current sequence */
5270 for (start
= s
; *s
; s
++)
5275 cupsFileWrite(fp
, start
, s
- start
);
5277 cupsFilePuts(fp
, "&");
5283 cupsFileWrite(fp
, start
, s
- start
);
5285 cupsFilePuts(fp
, "<");
5291 cupsFilePuts(fp
, start
);
5296 * End of "$Id: printers.c 7968 2008-09-19 23:03:01Z mike $".