2 * "$Id: printers.c 6354 2007-03-19 06:16:32Z mike $"
4 * Printer routines for the Common UNIX Printing System (CUPS).
6 * Copyright 1997-2007 by Easy Software Products, all rights reserved.
8 * These coded instructions, statements, and computer programs are the
9 * property of Easy Software Products and are protected by Federal
10 * copyright law. Distribution and use rights are outlined in the file
11 * "LICENSE.txt" which should have been included with this file. If this
12 * file is missing or damaged please contact Easy Software Products
15 * Attn: CUPS Licensing Information
16 * Easy Software Products
17 * 44141 Airport View Drive, Suite 204
18 * Hollywood, Maryland 20636 USA
20 * Voice: (301) 373-9600
21 * EMail: cups-info@cups.org
22 * WWW: http://www.cups.org
26 * cupsdAddPrinter() - Add a printer to the system.
27 * cupsdAddPrinterHistory() - Add the current printer state to the history.
28 * cupsdAddPrinterUser() - Add a user to the ACL.
29 * cupsdDeleteAllPrinters() - Delete all printers from the system.
30 * cupsdDeletePrinter() - Delete a printer from the system.
31 * cupsdFindPrinter() - Find a printer in the list.
32 * cupsdFreePrinterUsers() - Free allow/deny users.
33 * cupsdLoadAllPrinters() - Load printers from the printers.conf file.
34 * cupsdRenamePrinter() - Rename a printer.
35 * cupsdSaveAllPrinters() - Save all printer definitions to the
37 * cupsdSetPrinterAttrs() - Set printer attributes based upon the PPD
39 * cupsdSetPrinterReasons() - Set/update the reasons strings.
40 * cupsdSetPrinterState() - Update the current state of a printer.
41 * cupsdStopPrinter() - Stop a printer from printing any jobs...
42 * cupsdUpdatePrinters() - Update printers after a partial reload.
43 * cupsdValidateDest() - Validate a printer/class destination.
44 * cupsdWritePrintcap() - Write a pseudo-printcap file for older
45 * applications that need it...
46 * cupsdSanitizeURI() - Sanitize a device URI...
47 * add_printer_defaults() - Add name-default attributes to the printer
49 * add_printer_filter() - Add a MIME filter for a printer.
50 * add_printer_formats() - Add document-format-supported values for
52 * compare_printers() - Compare two printers.
53 * delete_printer_filters() - Delete all MIME filters for a printer.
54 * write_irix_config() - Update the config files used by the IRIX
56 * write_irix_state() - Update the status files used by IRIX
57 * printing desktop tools.
61 * Include necessary headers...
72 static void add_printer_defaults(cupsd_printer_t
*p
);
73 static void add_printer_filter(cupsd_printer_t
*p
, mime_type_t
*type
,
75 static void add_printer_formats(cupsd_printer_t
*p
);
76 static int compare_printers(void *first
, void *second
, void *data
);
77 static void delete_printer_filters(cupsd_printer_t
*p
);
79 static void write_irix_config(cupsd_printer_t
*p
);
80 static void write_irix_state(cupsd_printer_t
*p
);
85 * 'cupsdAddPrinter()' - Add a printer to the system.
88 cupsd_printer_t
* /* O - New printer */
89 cupsdAddPrinter(const char *name
) /* I - Name of printer */
91 cupsd_printer_t
*p
; /* New printer */
95 * Range check input...
98 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdAddPrinter(\"%s\")", name
);
101 * Create a new printer entity...
104 if ((p
= calloc(1, sizeof(cupsd_printer_t
))) == NULL
)
106 cupsdLogMessage(CUPSD_LOG_CRIT
, "Unable to allocate memory for printer - %s",
111 cupsdSetString(&p
->name
, name
);
112 cupsdSetString(&p
->info
, name
);
113 cupsdSetString(&p
->hostname
, ServerName
);
115 cupsdSetStringf(&p
->uri
, "ipp://%s:%d/printers/%s", ServerName
, LocalPort
, name
);
116 cupsdSetStringf(&p
->device_uri
, "file:/dev/null");
118 p
->state
= IPP_PRINTER_STOPPED
;
119 p
->state_time
= time(NULL
);
121 p
->shared
= DefaultShared
;
122 p
->filetype
= mimeAddType(MimeDatabase
, "printer", name
);
124 cupsdSetString(&p
->job_sheets
[0], "none");
125 cupsdSetString(&p
->job_sheets
[1], "none");
127 cupsdSetString(&p
->error_policy
, "stop-printer");
128 cupsdSetString(&p
->op_policy
, DefaultPolicy
);
130 p
->op_policy_ptr
= DefaultPolicyPtr
;
132 if (MaxPrinterHistory
)
133 p
->history
= calloc(MaxPrinterHistory
, sizeof(ipp_t
*));
136 * Insert the printer in the printer list alphabetically...
140 Printers
= cupsArrayNew(compare_printers
, NULL
);
142 cupsArrayAdd(Printers
, p
);
144 if (!ImplicitPrinters
)
145 ImplicitPrinters
= cupsArrayNew(compare_printers
, NULL
);
148 * Return the new printer...
156 * 'cupsdAddPrinterHistory()' - Add the current printer state to the history.
160 cupsdAddPrinterHistory(
161 cupsd_printer_t
*p
) /* I - Printer */
163 ipp_t
*history
; /* History collection */
167 * Stop early if we aren't keeping history data...
170 if (MaxPrinterHistory
<= 0)
174 * Retire old history data as needed...
177 p
->sequence_number
++;
179 if (p
->num_history
>= MaxPrinterHistory
)
182 ippDelete(p
->history
[0]);
183 memmove(p
->history
, p
->history
+ 1, p
->num_history
* sizeof(ipp_t
*));
187 * Create a collection containing the current printer-state, printer-up-time,
188 * printer-state-message, and printer-state-reasons attributes.
192 ippAddInteger(history
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-state",
194 ippAddBoolean(history
, IPP_TAG_PRINTER
, "printer-is-accepting-jobs",
196 ippAddBoolean(history
, IPP_TAG_PRINTER
, "printer-is-shared", p
->shared
);
197 ippAddString(history
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-state-message",
198 NULL
, p
->state_message
);
201 ippAddString(history
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
202 "com.apple.print.recoverable-message", NULL
, p
->recoverable
);
203 #endif /* __APPLE__ */
204 if (p
->num_reasons
== 0)
205 ippAddString(history
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
206 "printer-state-reasons", NULL
,
207 p
->state
== IPP_PRINTER_STOPPED
? "paused" : "none");
209 ippAddStrings(history
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
210 "printer-state-reasons", p
->num_reasons
, NULL
,
211 (const char * const *)p
->reasons
);
212 ippAddInteger(history
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
213 "printer-state-change-time", p
->state_time
);
214 ippAddInteger(history
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
215 "printer-state-sequence-number", p
->sequence_number
);
217 p
->history
[p
->num_history
] = history
;
223 * 'cupsdAddPrinterUser()' - Add a user to the ACL.
228 cupsd_printer_t
*p
, /* I - Printer */
229 const char *username
) /* I - User */
231 const char **temp
; /* Temporary array pointer */
237 if (p
->num_users
== 0)
238 temp
= malloc(sizeof(char **));
240 temp
= realloc(p
->users
, sizeof(char **) * (p
->num_users
+ 1));
246 temp
+= p
->num_users
;
248 if ((*temp
= strdup(username
)) != NULL
)
254 * 'cupsdCreateCommonData()' - Create the common printer data.
258 cupsdCreateCommonData(void)
260 int i
; /* Looping var */
261 ipp_attribute_t
*attr
; /* Attribute data */
262 cups_dir_t
*dir
; /* Notifier directory */
263 cups_dentry_t
*dent
; /* Notifier directory entry */
264 cups_array_t
*notifiers
; /* Notifier array */
265 char filename
[1024], /* Filename */
266 *notifier
; /* Current notifier */
267 static const int nups
[] = /* number-up-supported values */
268 { 1, 2, 4, 6, 9, 16 };
269 static const ipp_orient_t orients
[4] =/* orientation-requested-supported values */
273 IPP_REVERSE_LANDSCAPE
,
276 static const char * const holds
[] = /* job-hold-until-supported values */
287 static const char * const versions
[] =/* ipp-versions-supported values */
292 static const ipp_op_t ops
[] = /* operations-supported values */
299 IPP_GET_JOB_ATTRIBUTES
,
301 IPP_GET_PRINTER_ATTRIBUTES
,
307 IPP_SET_JOB_ATTRIBUTES
,
308 IPP_CREATE_PRINTER_SUBSCRIPTION
,
309 IPP_CREATE_JOB_SUBSCRIPTION
,
310 IPP_GET_SUBSCRIPTION_ATTRIBUTES
,
311 IPP_GET_SUBSCRIPTIONS
,
312 IPP_RENEW_SUBSCRIPTION
,
313 IPP_CANCEL_SUBSCRIPTION
,
314 IPP_GET_NOTIFICATIONS
,
330 CUPS_AUTHENTICATE_JOB
,
333 static const char * const charsets
[] =/* charset-supported values */
338 static const char * const compressions
[] =
339 { /* document-compression-supported values */
343 #endif /* HAVE_LIBZ */
345 static const char * const multiple_document_handling
[] =
346 { /* multiple-document-handling-supported values */
347 "separate-documents-uncollated-copies",
348 "separate-documents-collated-copies"
350 static const char * const errors
[] = /* printer-error-policy-supported values */
356 static const char * const notify_attrs
[] =
357 { /* notify-attributes-supported values */
358 "printer-state-change-time",
359 "notify-lease-expiration-time",
360 "notify-subscriber-user-name"
362 static const char * const notify_events
[] =
363 { /* notify-events-supported values */
365 "job-config-changed",
372 "printer-config-changed",
374 "printer-finishings-changed",
375 "printer-media-changed",
379 "printer-state-changed",
389 ippDelete(CommonData
);
391 CommonData
= ippNew();
394 * This list of attributes is sorted to improve performance when the
395 * client provides a requested-attributes attribute...
398 /* charset-configured */
399 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_CHARSET
,
400 "charset-configured", NULL
, DefaultCharset
);
402 /* charset-supported */
403 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_CHARSET
,
404 "charset-supported", sizeof(charsets
) / sizeof(charsets
[0]),
407 /* compression-supported */
408 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
409 "compression-supported",
410 sizeof(compressions
) / sizeof(compressions
[0]),
413 /* copies-supported */
414 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "copies-supported", 1, MaxCopies
);
416 /* generated-natural-language-supported */
417 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_LANGUAGE
,
418 "generated-natural-language-supported", NULL
, DefaultLanguage
);
420 /* ipp-versions-supported */
421 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
422 "ipp-versions-supported", sizeof(versions
) / sizeof(versions
[0]),
425 /* job-hold-until-supported */
426 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
427 "job-hold-until-supported", sizeof(holds
) / sizeof(holds
[0]),
430 /* job-priority-supported */
431 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
432 "job-priority-supported", 100);
434 /* job-sheets-supported */
435 if (cupsArrayCount(Banners
) > 0)
438 * Setup the job-sheets-supported attribute...
441 if (Classification
&& !ClassifyOverride
)
442 attr
= ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
443 "job-sheets-supported", NULL
, Classification
);
445 attr
= ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
446 "job-sheets-supported", cupsArrayCount(Banners
) + 1,
450 cupsdLogMessage(CUPSD_LOG_EMERG
,
451 "Unable to allocate memory for "
452 "job-sheets-supported attribute: %s!", strerror(errno
));
453 else if (!Classification
|| ClassifyOverride
)
455 cupsd_banner_t
*banner
; /* Current banner */
458 attr
->values
[0].string
.text
= _cupsStrAlloc("none");
460 for (i
= 1, banner
= (cupsd_banner_t
*)cupsArrayFirst(Banners
);
462 i
++, banner
= (cupsd_banner_t
*)cupsArrayNext(Banners
))
463 attr
->values
[i
].string
.text
= _cupsStrAlloc(banner
->name
);
467 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
468 "job-sheets-supported", NULL
, "none");
470 /* multiple-document-handling-supported */
471 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
472 "multiple-document-handling-supported",
473 sizeof(multiple_document_handling
) /
474 sizeof(multiple_document_handling
[0]), NULL
,
475 multiple_document_handling
);
477 /* multiple-document-jobs-supported */
478 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
,
479 "multiple-document-jobs-supported", 1);
481 /* multiple-operation-time-out */
482 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
483 "multiple-operation-time-out", 60);
485 /* natural-language-configured */
486 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_LANGUAGE
,
487 "natural-language-configured", NULL
, DefaultLanguage
);
489 /* notify-attributes-supported */
490 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
491 "notify-attributes-supported",
492 (int)(sizeof(notify_attrs
) / sizeof(notify_attrs
[0])),
495 /* notify-lease-duration-supported */
496 ippAddRange(CommonData
, IPP_TAG_PRINTER
,
497 "notify-lease-duration-supported", 0,
498 MaxLeaseDuration
? MaxLeaseDuration
: 2147483647);
500 /* notify-max-events-supported */
501 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
502 "notify-max-events-supported", MaxEvents
);
504 /* notify-events-supported */
505 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
506 "notify-events-supported",
507 (int)(sizeof(notify_events
) / sizeof(notify_events
[0])),
508 NULL
, notify_events
);
510 /* notify-pull-method-supported */
511 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
512 "notify-pull-method-supported", NULL
, "ippget");
514 /* notify-schemes-supported */
515 snprintf(filename
, sizeof(filename
), "%s/notifier", ServerBin
);
516 if ((dir
= cupsDirOpen(filename
)) != NULL
)
518 notifiers
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
520 while ((dent
= cupsDirRead(dir
)) != NULL
)
521 if (S_ISREG(dent
->fileinfo
.st_mode
) &&
522 (dent
->fileinfo
.st_mode
& S_IXOTH
) != 0)
523 cupsArrayAdd(notifiers
, _cupsStrAlloc(dent
->filename
));
525 if (cupsArrayCount(notifiers
) > 0)
527 attr
= ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
528 "notify-schemes-supported",
529 cupsArrayCount(notifiers
), NULL
, NULL
);
531 for (i
= 0, notifier
= (char *)cupsArrayFirst(notifiers
);
533 i
++, notifier
= (char *)cupsArrayNext(notifiers
))
534 attr
->values
[i
].string
.text
= notifier
;
537 cupsArrayDelete(notifiers
);
541 /* number-up-supported */
542 ippAddIntegers(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
543 "number-up-supported", sizeof(nups
) / sizeof(nups
[0]), nups
);
545 /* operations-supported */
546 ippAddIntegers(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
547 "operations-supported",
548 sizeof(ops
) / sizeof(ops
[0]) + JobFiles
- 1, (int *)ops
);
550 /* orientation-requested-supported */
551 ippAddIntegers(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
552 "orientation-requested-supported", 4, (int *)orients
);
554 /* page-ranges-supported */
555 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
, "page-ranges-supported", 1);
557 /* pdf-override-supported */
558 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
559 "pdl-override-supported", NULL
, "not-attempted");
561 /* printer-error-policy-supported */
562 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
563 "printer-error-policy-supported",
564 sizeof(errors
) / sizeof(errors
[0]), NULL
, errors
);
566 /* printer-op-policy-supported */
567 attr
= ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
568 "printer-op-policy-supported", NumPolicies
, NULL
, NULL
);
569 for (i
= 0; i
< NumPolicies
; i
++)
570 attr
->values
[i
].string
.text
= _cupsStrAlloc(Policies
[i
]->name
);
575 * 'cupsdDeleteAllPrinters()' - Delete all printers from the system.
579 cupsdDeleteAllPrinters(void)
581 cupsd_printer_t
*p
; /* Pointer to current printer/class */
584 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
586 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
587 if (!(p
->type
& CUPS_PRINTER_CLASS
))
588 cupsdDeletePrinter(p
, 0);
593 * 'cupsdDeletePrinter()' - Delete a printer from the system.
598 cupsd_printer_t
*p
, /* I - Printer to delete */
599 int update
) /* I - Update printers.conf? */
601 int i
; /* Looping var */
603 char filename
[1024]; /* Interface script filename */
607 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdDeletePrinter(p=%p(%s), update=%d)",
611 * Save the current position in the Printers array...
614 cupsArraySave(Printers
);
617 * Stop printing on this printer...
620 cupsdStopPrinter(p
, update
);
623 * If this printer is the next for browsing, point to the next one...
628 cupsArrayFind(Printers
, p
);
629 BrowseNext
= (cupsd_printer_t
*)cupsArrayNext(Printers
);
633 * Remove the printer from the list...
636 cupsArrayRemove(Printers
, p
);
638 if (p
->type
& CUPS_PRINTER_IMPLICIT
)
639 cupsArrayRemove(ImplicitPrinters
, p
);
642 * Remove the dummy interface/icon/option files under IRIX...
646 snprintf(filename
, sizeof(filename
), "/var/spool/lp/interface/%s", p
->name
);
649 snprintf(filename
, sizeof(filename
), "/var/spool/lp/gui_interface/ELF/%s.gui",
653 snprintf(filename
, sizeof(filename
), "/var/spool/lp/activeicons/%s", p
->name
);
656 snprintf(filename
, sizeof(filename
), "/var/spool/lp/pod/%s.config", p
->name
);
659 snprintf(filename
, sizeof(filename
), "/var/spool/lp/pod/%s.status", p
->name
);
662 snprintf(filename
, sizeof(filename
), "/var/spool/lp/member/%s", p
->name
);
667 * If p is the default printer, assign a different one...
670 if (p
== DefaultPrinter
)
672 DefaultPrinter
= NULL
;
674 if (UseNetworkDefault
)
677 * Find the first network default printer and use it...
680 cupsd_printer_t
*dp
; /* New default printer */
683 for (dp
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
685 dp
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
686 if (dp
!= p
&& (dp
->type
& CUPS_PRINTER_DEFAULT
))
695 * Remove this printer from any classes...
698 if (!(p
->type
& CUPS_PRINTER_IMPLICIT
))
700 cupsdDeletePrinterFromClasses(p
);
703 * Deregister from any browse protocols...
706 cupsdDeregisterPrinter(p
, 1);
710 * Free all memory used by the printer...
713 if (p
->printers
!= NULL
)
716 if (MaxPrinterHistory
)
718 for (i
= 0; i
< p
->num_history
; i
++)
719 ippDelete(p
->history
[i
]);
724 for (i
= 0; i
< p
->num_reasons
; i
++)
729 delete_printer_filters(p
);
731 mimeDeleteType(MimeDatabase
, p
->filetype
);
732 mimeDeleteType(MimeDatabase
, p
->prefiltertype
);
734 cupsdFreePrinterUsers(p
);
737 cupsdClearString(&p
->uri
);
738 cupsdClearString(&p
->hostname
);
739 cupsdClearString(&p
->name
);
740 cupsdClearString(&p
->location
);
741 cupsdClearString(&p
->make_model
);
742 cupsdClearString(&p
->info
);
743 cupsdClearString(&p
->job_sheets
[0]);
744 cupsdClearString(&p
->job_sheets
[1]);
745 cupsdClearString(&p
->device_uri
);
746 cupsdClearString(&p
->port_monitor
);
747 cupsdClearString(&p
->op_policy
);
748 cupsdClearString(&p
->error_policy
);
751 cupsdClearString(&p
->product
);
752 cupsdClearString(&p
->pdl
);
753 #endif /* HAVE_DNSSD */
755 cupsArrayDelete(p
->filetypes
);
758 free(p
->browse_attrs
);
761 cupsdClearString(&p
->recoverable
);
762 #endif /* __APPLE__ */
764 cupsFreeOptions(p
->num_options
, p
->options
);
769 * Restore the previous position in the Printers array...
772 cupsArrayRestore(Printers
);
777 * 'cupsdFindDest()' - Find a destination in the list.
780 cupsd_printer_t
* /* O - Destination in list */
781 cupsdFindDest(const char *name
) /* I - Name of printer or class to find */
783 cupsd_printer_t key
; /* Search key */
786 key
.name
= (char *)name
;
787 return ((cupsd_printer_t
*)cupsArrayFind(Printers
, &key
));
792 * 'cupsdFindPrinter()' - Find a printer in the list.
795 cupsd_printer_t
* /* O - Printer in list */
796 cupsdFindPrinter(const char *name
) /* I - Name of printer to find */
798 cupsd_printer_t
*p
; /* Printer in list */
801 if ((p
= cupsdFindDest(name
)) != NULL
&& (p
->type
& CUPS_PRINTER_CLASS
))
809 * 'cupsdFreePrinterUsers()' - Free allow/deny users.
813 cupsdFreePrinterUsers(
814 cupsd_printer_t
*p
) /* I - Printer */
816 int i
; /* Looping var */
819 if (!p
|| !p
->num_users
)
822 for (i
= 0; i
< p
->num_users
; i
++)
823 free((void *)p
->users
[i
]);
833 * 'cupsdLoadAllPrinters()' - Load printers from the printers.conf file.
837 cupsdLoadAllPrinters(void)
839 cups_file_t
*fp
; /* printers.conf file */
840 int linenum
; /* Current line number */
841 char line
[1024], /* Line from file */
842 *value
, /* Pointer to value */
843 *valueptr
; /* Pointer into value */
844 cupsd_printer_t
*p
; /* Current printer */
848 * Open the printers.conf file...
851 snprintf(line
, sizeof(line
), "%s/printers.conf", ServerRoot
);
852 if ((fp
= cupsFileOpen(line
, "r")) == NULL
)
855 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to open %s - %s", line
,
861 * Read printer configurations until we hit EOF...
867 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
870 * Decode the directive...
873 if (!strcasecmp(line
, "<Printer") ||
874 !strcasecmp(line
, "<DefaultPrinter"))
877 * <Printer name> or <DefaultPrinter name>
880 if (p
== NULL
&& value
)
883 * Add the printer and a base file type...
886 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Loading printer %s...", value
);
888 p
= cupsdAddPrinter(value
);
890 p
->state
= IPP_PRINTER_IDLE
;
893 * Set the default printer as needed...
896 if (!strcasecmp(line
, "<DefaultPrinter"))
901 cupsdLogMessage(CUPSD_LOG_ERROR
,
902 "Syntax error on line %d of printers.conf.", linenum
);
906 else if (!strcasecmp(line
, "</Printer>"))
911 * Close out the current printer...
914 cupsdSetPrinterAttrs(p
);
915 cupsdAddPrinterHistory(p
);
917 if (p
->device_uri
&& strncmp(p
->device_uri
, "file:", 5) &&
918 p
->state
!= IPP_PRINTER_STOPPED
)
921 * See if the backend exists...
924 snprintf(line
, sizeof(line
), "%s/backend/%s", ServerBin
,
927 if ((valueptr
= strchr(line
+ strlen(ServerBin
), ':')) != NULL
)
928 *valueptr
= '\0'; /* Chop everything but URI scheme */
933 * Backend does not exist, stop printer...
936 p
->state
= IPP_PRINTER_STOPPED
;
937 snprintf(p
->state_message
, sizeof(p
->state_message
),
938 "Backend %s does not exist!", line
);
946 cupsdLogMessage(CUPSD_LOG_ERROR
,
947 "Syntax error on line %d of printers.conf.", linenum
);
953 cupsdLogMessage(CUPSD_LOG_ERROR
,
954 "Syntax error on line %d of printers.conf.", linenum
);
957 else if (!strcasecmp(line
, "AuthInfoRequired"))
959 if (!cupsdSetAuthInfoRequired(p
, value
, NULL
))
960 cupsdLogMessage(CUPSD_LOG_ERROR
,
961 "Bad AuthInfoRequired on line %d of printers.conf.",
964 else if (!strcasecmp(line
, "Info"))
967 cupsdSetString(&p
->info
, value
);
969 else if (!strcasecmp(line
, "Location"))
972 cupsdSetString(&p
->location
, value
);
974 else if (!strcasecmp(line
, "DeviceURI"))
977 cupsdSetString(&p
->device_uri
, value
);
980 cupsdLogMessage(CUPSD_LOG_ERROR
,
981 "Syntax error on line %d of printers.conf.", linenum
);
985 else if (!strcasecmp(line
, "Option") && value
)
991 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
994 cupsdLogMessage(CUPSD_LOG_ERROR
,
995 "Syntax error on line %d of printers.conf.", linenum
);
998 for (; *valueptr
&& isspace(*valueptr
& 255); *valueptr
++ = '\0');
1000 p
->num_options
= cupsAddOption(value
, valueptr
, p
->num_options
,
1004 else if (!strcasecmp(line
, "PortMonitor"))
1006 if (value
&& strcmp(value
, "none"))
1007 cupsdSetString(&p
->port_monitor
, value
);
1009 cupsdClearString(&p
->port_monitor
);
1012 cupsdLogMessage(CUPSD_LOG_ERROR
,
1013 "Syntax error on line %d of printers.conf.", linenum
);
1017 else if (!strcasecmp(line
, "State"))
1020 * Set the initial queue state...
1023 if (value
&& !strcasecmp(value
, "idle"))
1024 p
->state
= IPP_PRINTER_IDLE
;
1025 else if (value
&& !strcasecmp(value
, "stopped"))
1026 p
->state
= IPP_PRINTER_STOPPED
;
1029 cupsdLogMessage(CUPSD_LOG_ERROR
,
1030 "Syntax error on line %d of printers.conf.", linenum
);
1034 else if (!strcasecmp(line
, "StateMessage"))
1037 * Set the initial queue state message...
1041 strlcpy(p
->state_message
, value
, sizeof(p
->state_message
));
1043 else if (!strcasecmp(line
, "StateTime"))
1046 * Set the state time...
1050 p
->state_time
= atoi(value
);
1052 else if (!strcasecmp(line
, "Accepting"))
1055 * Set the initial accepting state...
1059 (!strcasecmp(value
, "yes") ||
1060 !strcasecmp(value
, "on") ||
1061 !strcasecmp(value
, "true")))
1064 (!strcasecmp(value
, "no") ||
1065 !strcasecmp(value
, "off") ||
1066 !strcasecmp(value
, "false")))
1070 cupsdLogMessage(CUPSD_LOG_ERROR
,
1071 "Syntax error on line %d of printers.conf.", linenum
);
1075 else if (!strcasecmp(line
, "Shared"))
1078 * Set the initial shared state...
1082 (!strcasecmp(value
, "yes") ||
1083 !strcasecmp(value
, "on") ||
1084 !strcasecmp(value
, "true")))
1087 (!strcasecmp(value
, "no") ||
1088 !strcasecmp(value
, "off") ||
1089 !strcasecmp(value
, "false")))
1093 cupsdLogMessage(CUPSD_LOG_ERROR
,
1094 "Syntax error on line %d of printers.conf.", linenum
);
1098 else if (!strcasecmp(line
, "JobSheets"))
1101 * Set the initial job sheets...
1106 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1111 cupsdSetString(&p
->job_sheets
[0], value
);
1113 while (isspace(*valueptr
& 255))
1118 for (value
= valueptr
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1123 cupsdSetString(&p
->job_sheets
[1], value
);
1128 cupsdLogMessage(CUPSD_LOG_ERROR
,
1129 "Syntax error on line %d of printers.conf.", linenum
);
1133 else if (!strcasecmp(line
, "AllowUser"))
1138 cupsdAddPrinterUser(p
, value
);
1142 cupsdLogMessage(CUPSD_LOG_ERROR
,
1143 "Syntax error on line %d of printers.conf.", linenum
);
1147 else if (!strcasecmp(line
, "DenyUser"))
1152 cupsdAddPrinterUser(p
, value
);
1156 cupsdLogMessage(CUPSD_LOG_ERROR
,
1157 "Syntax error on line %d of printers.conf.", linenum
);
1161 else if (!strcasecmp(line
, "QuotaPeriod"))
1164 p
->quota_period
= atoi(value
);
1167 cupsdLogMessage(CUPSD_LOG_ERROR
,
1168 "Syntax error on line %d of printers.conf.", linenum
);
1172 else if (!strcasecmp(line
, "PageLimit"))
1175 p
->page_limit
= atoi(value
);
1178 cupsdLogMessage(CUPSD_LOG_ERROR
,
1179 "Syntax error on line %d of printers.conf.", linenum
);
1183 else if (!strcasecmp(line
, "KLimit"))
1186 p
->k_limit
= atoi(value
);
1189 cupsdLogMessage(CUPSD_LOG_ERROR
,
1190 "Syntax error on line %d of printers.conf.", linenum
);
1194 else if (!strcasecmp(line
, "OpPolicy"))
1197 cupsdSetString(&p
->op_policy
, value
);
1200 cupsdLogMessage(CUPSD_LOG_ERROR
,
1201 "Syntax error on line %d of printers.conf.", linenum
);
1205 else if (!strcasecmp(line
, "ErrorPolicy"))
1208 cupsdSetString(&p
->error_policy
, value
);
1211 cupsdLogMessage(CUPSD_LOG_ERROR
,
1212 "Syntax error on line %d of printers.conf.", linenum
);
1219 * Something else we don't understand...
1222 cupsdLogMessage(CUPSD_LOG_ERROR
,
1223 "Unknown configuration directive %s on line %d of printers.conf.",
1233 * 'cupsdRenamePrinter()' - Rename a printer.
1238 cupsd_printer_t
*p
, /* I - Printer */
1239 const char *name
) /* I - New name */
1242 * Remove the printer from the array(s) first...
1245 cupsArrayRemove(Printers
, p
);
1247 if (p
->type
& CUPS_PRINTER_IMPLICIT
)
1248 cupsArrayRemove(ImplicitPrinters
, p
);
1251 * Rename the printer type...
1254 mimeDeleteType(MimeDatabase
, p
->filetype
);
1255 p
->filetype
= mimeAddType(MimeDatabase
, "printer", name
);
1257 mimeDeleteType(MimeDatabase
, p
->prefiltertype
);
1258 p
->prefiltertype
= mimeAddType(MimeDatabase
, "prefilter", name
);
1261 * Rename the printer...
1264 cupsdSetString(&p
->name
, name
);
1267 * Reset printer attributes...
1270 cupsdSetPrinterAttrs(p
);
1273 * Add the printer back to the printer array(s)...
1276 cupsArrayAdd(Printers
, p
);
1278 if (p
->type
& CUPS_PRINTER_IMPLICIT
)
1279 cupsArrayAdd(ImplicitPrinters
, p
);
1284 * 'cupsdSaveAllPrinters()' - Save all printer definitions to the printers.conf
1289 cupsdSaveAllPrinters(void)
1291 int i
; /* Looping var */
1292 cups_file_t
*fp
; /* printers.conf file */
1293 char temp
[1024]; /* Temporary string */
1294 char backup
[1024]; /* printers.conf.O file */
1295 cupsd_printer_t
*printer
; /* Current printer class */
1296 time_t curtime
; /* Current time */
1297 struct tm
*curdate
; /* Current date */
1298 cups_option_t
*option
; /* Current option */
1299 const char *ptr
; /* Pointer into info/location */
1303 * Create the printers.conf file...
1306 snprintf(temp
, sizeof(temp
), "%s/printers.conf", ServerRoot
);
1307 snprintf(backup
, sizeof(backup
), "%s/printers.conf.O", ServerRoot
);
1309 if (rename(temp
, backup
))
1311 if (errno
!= ENOENT
)
1312 cupsdLogMessage(CUPSD_LOG_ERROR
,
1313 "Unable to backup printers.conf - %s", strerror(errno
));
1316 if ((fp
= cupsFileOpen(temp
, "w")) == NULL
)
1318 cupsdLogMessage(CUPSD_LOG_ERROR
,
1319 "Unable to save printers.conf - %s", strerror(errno
));
1321 if (rename(backup
, temp
))
1322 cupsdLogMessage(CUPSD_LOG_ERROR
,
1323 "Unable to restore printers.conf - %s", strerror(errno
));
1327 cupsdLogMessage(CUPSD_LOG_INFO
, "Saving printers.conf...");
1330 * Restrict access to the file...
1333 fchown(cupsFileNumber(fp
), getuid(), Group
);
1334 fchmod(cupsFileNumber(fp
), 0600);
1337 * Write a small header to the file...
1340 curtime
= time(NULL
);
1341 curdate
= localtime(&curtime
);
1342 strftime(temp
, sizeof(temp
) - 1, "%Y-%m-%d %H:%M", curdate
);
1344 cupsFilePuts(fp
, "# Printer configuration file for " CUPS_SVERSION
"\n");
1345 cupsFilePrintf(fp
, "# Written by cupsd on %s\n", temp
);
1348 * Write each local printer known to the system...
1351 for (printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
1353 printer
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
1356 * Skip remote destinations and printer classes...
1359 if ((printer
->type
& CUPS_PRINTER_REMOTE
) ||
1360 (printer
->type
& CUPS_PRINTER_CLASS
) ||
1361 (printer
->type
& CUPS_PRINTER_IMPLICIT
))
1365 * Write printers as needed...
1368 if (printer
== DefaultPrinter
)
1369 cupsFilePrintf(fp
, "<DefaultPrinter %s>\n", printer
->name
);
1371 cupsFilePrintf(fp
, "<Printer %s>\n", printer
->name
);
1373 if (printer
->num_auth_info_required
> 0)
1375 cupsFilePrintf(fp
, "AuthInfoRequired %s", printer
->auth_info_required
[0]);
1376 for (i
= 1; i
< printer
->num_auth_info_required
; i
++)
1377 cupsFilePrintf(fp
, ",%s", printer
->auth_info_required
[i
]);
1378 cupsFilePutChar(fp
, '\n');
1383 if ((ptr
= strchr(printer
->info
, '#')) != NULL
)
1386 * Need to quote the first # in the info string...
1389 cupsFilePuts(fp
, "Info ");
1390 cupsFileWrite(fp
, printer
->info
, ptr
- printer
->info
);
1391 cupsFilePutChar(fp
, '\\');
1392 cupsFilePuts(fp
, ptr
);
1393 cupsFilePutChar(fp
, '\n');
1396 cupsFilePrintf(fp
, "Info %s\n", printer
->info
);
1399 if (printer
->location
)
1401 if ((ptr
= strchr(printer
->info
, '#')) != NULL
)
1404 * Need to quote the first # in the location string...
1407 cupsFilePuts(fp
, "Location ");
1408 cupsFileWrite(fp
, printer
->location
, ptr
- printer
->location
);
1409 cupsFilePutChar(fp
, '\\');
1410 cupsFilePuts(fp
, ptr
);
1411 cupsFilePutChar(fp
, '\n');
1414 cupsFilePrintf(fp
, "Location %s\n", printer
->location
);
1416 if (printer
->device_uri
)
1417 cupsFilePrintf(fp
, "DeviceURI %s\n", printer
->device_uri
);
1419 if (printer
->port_monitor
)
1420 cupsFilePrintf(fp
, "PortMonitor %s\n", printer
->port_monitor
);
1422 if (printer
->state
== IPP_PRINTER_STOPPED
)
1424 cupsFilePuts(fp
, "State Stopped\n");
1425 cupsFilePrintf(fp
, "StateMessage %s\n", printer
->state_message
);
1428 cupsFilePuts(fp
, "State Idle\n");
1430 cupsFilePrintf(fp
, "StateTime %d\n", (int)printer
->state_time
);
1432 if (printer
->accepting
)
1433 cupsFilePuts(fp
, "Accepting Yes\n");
1435 cupsFilePuts(fp
, "Accepting No\n");
1437 if (printer
->shared
)
1438 cupsFilePuts(fp
, "Shared Yes\n");
1440 cupsFilePuts(fp
, "Shared No\n");
1442 cupsFilePrintf(fp
, "JobSheets %s %s\n", printer
->job_sheets
[0],
1443 printer
->job_sheets
[1]);
1445 cupsFilePrintf(fp
, "QuotaPeriod %d\n", printer
->quota_period
);
1446 cupsFilePrintf(fp
, "PageLimit %d\n", printer
->page_limit
);
1447 cupsFilePrintf(fp
, "KLimit %d\n", printer
->k_limit
);
1449 for (i
= 0; i
< printer
->num_users
; i
++)
1450 cupsFilePrintf(fp
, "%sUser %s\n", printer
->deny_users
? "Deny" : "Allow",
1453 if (printer
->op_policy
)
1454 cupsFilePrintf(fp
, "OpPolicy %s\n", printer
->op_policy
);
1455 if (printer
->error_policy
)
1456 cupsFilePrintf(fp
, "ErrorPolicy %s\n", printer
->error_policy
);
1458 for (i
= printer
->num_options
, option
= printer
->options
;
1461 cupsFilePrintf(fp
, "Option %s %s\n", option
->name
, option
->value
);
1463 cupsFilePuts(fp
, "</Printer>\n");
1467 * Make IRIX desktop & printer status happy
1470 write_irix_state(printer
);
1479 * 'cupsdSetAuthInfoRequired()' - Set the required authentication info.
1482 int /* O - 1 if value OK, 0 otherwise */
1483 cupsdSetAuthInfoRequired(
1484 cupsd_printer_t
*p
, /* I - Printer */
1485 const char *values
, /* I - Plain text value (or NULL) */
1486 ipp_attribute_t
*attr
) /* I - IPP attribute value (or NULL) */
1488 int i
; /* Looping var */
1491 p
->num_auth_info_required
= 0;
1494 * Do we have a plain text value?
1500 * Yes, grab the keywords...
1503 const char *end
; /* End of current value */
1506 while (*values
&& p
->num_auth_info_required
< 4)
1508 if ((end
= strchr(values
, ',')) == NULL
)
1509 end
= values
+ strlen(values
);
1511 if (!strncmp(values
, "none", end
- values
))
1513 if (p
->num_auth_info_required
!= 0 || *end
)
1516 p
->auth_info_required
[p
->num_auth_info_required
] = "none";
1517 p
->num_auth_info_required
++;
1521 else if (!strncmp(values
, "domain", end
- values
))
1523 p
->auth_info_required
[p
->num_auth_info_required
] = "domain";
1524 p
->num_auth_info_required
++;
1526 else if (!strncmp(values
, "password", end
- values
))
1528 p
->auth_info_required
[p
->num_auth_info_required
] = "password";
1529 p
->num_auth_info_required
++;
1531 else if (!strncmp(values
, "username", end
- values
))
1533 p
->auth_info_required
[p
->num_auth_info_required
] = "username";
1534 p
->num_auth_info_required
++;
1540 if (p
->num_auth_info_required
== 0)
1542 p
->auth_info_required
[0] = "none";
1543 p
->num_auth_info_required
= 1;
1550 * Grab values from an attribute instead...
1553 if (!attr
|| attr
->num_values
> 4)
1556 for (i
= 0; i
< attr
->num_values
; i
++)
1558 if (!strcmp(attr
->values
[i
].string
.text
, "none"))
1560 if (p
->num_auth_info_required
!= 0 || attr
->num_values
!= 1)
1563 p
->auth_info_required
[p
->num_auth_info_required
] = "none";
1564 p
->num_auth_info_required
++;
1568 else if (!strcmp(attr
->values
[i
].string
.text
, "domain"))
1570 p
->auth_info_required
[p
->num_auth_info_required
] = "domain";
1571 p
->num_auth_info_required
++;
1573 else if (!strcmp(attr
->values
[i
].string
.text
, "password"))
1575 p
->auth_info_required
[p
->num_auth_info_required
] = "password";
1576 p
->num_auth_info_required
++;
1578 else if (!strcmp(attr
->values
[i
].string
.text
, "username"))
1580 p
->auth_info_required
[p
->num_auth_info_required
] = "username";
1581 p
->num_auth_info_required
++;
1592 * 'cupsdSetPrinterAttrs()' - Set printer attributes based upon the PPD file.
1596 cupsdSetPrinterAttrs(cupsd_printer_t
*p
)/* I - Printer to setup */
1598 int i
, /* Looping var */
1599 length
; /* Length of browse attributes */
1600 char uri
[HTTP_MAX_URI
]; /* URI for printer */
1601 char resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
1602 char filename
[1024]; /* Name of PPD file */
1603 int num_media
; /* Number of media options */
1604 cupsd_location_t
*auth
; /* Pointer to authentication element */
1605 const char *auth_supported
; /* Authentication supported */
1606 cups_ptype_t printer_type
; /* Printer type data */
1607 ppd_file_t
*ppd
; /* PPD file data */
1608 ppd_option_t
*input_slot
, /* InputSlot options */
1609 *media_type
, /* MediaType options */
1610 *page_size
, /* PageSize options */
1611 *output_bin
, /* OutputBin options */
1612 *media_quality
, /* EFMediaQualityMode options */
1613 *duplex
; /* Duplex options */
1614 ppd_attr_t
*ppdattr
; /* PPD attribute */
1615 ipp_attribute_t
*attr
; /* Attribute data */
1616 ipp_value_t
*val
; /* Attribute value */
1617 int num_finishings
; /* Number of finishings */
1618 ipp_finish_t finishings
[5]; /* finishings-supported values */
1619 cups_option_t
*option
; /* Current printer option */
1620 static const char * const sides
[3] = /* sides-supported values */
1623 "two-sided-long-edge",
1624 "two-sided-short-edge"
1628 DEBUG_printf(("cupsdSetPrinterAttrs: entering name = %s, type = %x\n", p
->name
,
1632 * Make sure that we have the common attributes defined...
1636 cupsdCreateCommonData();
1639 * Clear out old filters, if any...
1642 delete_printer_filters(p
);
1645 * Figure out the authentication that is required for the printer.
1648 auth_supported
= "requesting-user-name";
1649 if (!(p
->type
& CUPS_PRINTER_REMOTE
))
1651 if (p
->type
& CUPS_PRINTER_CLASS
)
1652 snprintf(resource
, sizeof(resource
), "/classes/%s", p
->name
);
1654 snprintf(resource
, sizeof(resource
), "/printers/%s", p
->name
);
1656 if ((auth
= cupsdFindBest(resource
, HTTP_POST
)) == NULL
||
1657 auth
->type
== AUTH_NONE
)
1658 auth
= cupsdFindPolicyOp(p
->op_policy_ptr
, IPP_PRINT_JOB
);
1662 if (auth
->type
== AUTH_BASIC
|| auth
->type
== AUTH_BASICDIGEST
)
1663 auth_supported
= "basic";
1664 else if (auth
->type
== AUTH_DIGEST
)
1665 auth_supported
= "digest";
1667 if (auth
->type
!= AUTH_NONE
)
1668 p
->type
|= CUPS_PRINTER_AUTHENTICATED
;
1670 p
->type
&= ~CUPS_PRINTER_AUTHENTICATED
;
1673 p
->type
&= ~CUPS_PRINTER_AUTHENTICATED
;
1677 * Create the required IPP attributes for a printer...
1681 ippDelete(p
->attrs
);
1683 p
->attrs
= ippNew();
1685 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
1686 "uri-authentication-supported", NULL
, auth_supported
);
1687 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
1688 "uri-security-supported", NULL
, "none");
1689 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
, "printer-name", NULL
,
1691 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-location",
1692 NULL
, p
->location
? p
->location
: "");
1693 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-info",
1694 NULL
, p
->info
? p
->info
: "");
1695 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "printer-more-info",
1701 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
1702 "requesting-user-name-denied", p
->num_users
, NULL
,
1705 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
1706 "requesting-user-name-allowed", p
->num_users
, NULL
,
1710 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
1711 "job-quota-period", p
->quota_period
);
1712 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
1713 "job-k-limit", p
->k_limit
);
1714 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
1715 "job-page-limit", p
->page_limit
);
1716 if (p
->num_auth_info_required
)
1717 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
1718 "auth-info-required", p
->num_auth_info_required
,
1719 NULL
, p
->auth_info_required
);
1721 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
1722 "auth-info-required", NULL
, "none");
1724 if (cupsArrayCount(Banners
) > 0 && !(p
->type
& CUPS_PRINTER_REMOTE
))
1727 * Setup the job-sheets-default attribute...
1730 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
1731 "job-sheets-default", 2, NULL
, NULL
);
1735 attr
->values
[0].string
.text
= _cupsStrAlloc(Classification
?
1736 Classification
: p
->job_sheets
[0]);
1737 attr
->values
[1].string
.text
= _cupsStrAlloc(Classification
?
1738 Classification
: p
->job_sheets
[1]);
1742 printer_type
= p
->type
;
1747 if (p
->type
& CUPS_PRINTER_REMOTE
)
1750 * Tell the client this is a remote printer of some type...
1753 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
1754 "printer-uri-supported", NULL
, p
->uri
);
1757 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
1758 "printer-make-and-model", NULL
, p
->make_model
);
1760 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "device-uri", NULL
,
1769 * Assign additional attributes depending on whether this is a printer
1773 p
->type
&= ~CUPS_PRINTER_OPTIONS
;
1775 if (p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
))
1780 * Add class-specific attributes...
1783 if ((p
->type
& CUPS_PRINTER_IMPLICIT
) && p
->num_printers
> 0 &&
1784 p
->printers
[0]->make_model
)
1785 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
1786 "printer-make-and-model", NULL
, p
->printers
[0]->make_model
);
1788 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
1789 "printer-make-and-model", NULL
, "Local Printer Class");
1791 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "device-uri", NULL
,
1792 "file:///dev/null");
1794 if (p
->num_printers
> 0)
1797 * Add a list of member URIs and names...
1800 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
1801 "member-uris", p
->num_printers
, NULL
, NULL
);
1802 p
->type
|= CUPS_PRINTER_OPTIONS
;
1804 for (i
= 0; i
< p
->num_printers
; i
++)
1807 attr
->values
[i
].string
.text
= _cupsStrAlloc(p
->printers
[i
]->uri
);
1809 p
->type
&= ~CUPS_PRINTER_OPTIONS
| p
->printers
[i
]->type
;
1812 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
1813 "member-names", p
->num_printers
, NULL
, NULL
);
1817 for (i
= 0; i
< p
->num_printers
; i
++)
1818 attr
->values
[i
].string
.text
= _cupsStrAlloc(p
->printers
[i
]->name
);
1825 * Add printer-specific attributes... Start by sanitizing the device
1826 * URI so it doesn't have a username or password in it...
1830 strcpy(uri
, "file:/dev/null");
1831 else if (strstr(p
->device_uri
, "://") != NULL
)
1834 * http://..., ipp://..., etc.
1837 cupsdSanitizeURI(p
->device_uri
, uri
, sizeof(uri
));
1842 * file:..., serial:..., etc.
1845 strlcpy(uri
, p
->device_uri
, sizeof(uri
));
1848 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "device-uri", NULL
,
1852 * Assign additional attributes from the PPD file (if any)...
1855 p
->type
|= CUPS_PRINTER_BW
;
1856 finishings
[0] = IPP_FINISHINGS_NONE
;
1859 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
1862 if ((ppd
= ppdOpenFile(filename
)) != NULL
)
1865 * Add make/model and other various attributes...
1868 if (ppd
->color_device
)
1869 p
->type
|= CUPS_PRINTER_COLOR
;
1870 if (ppd
->variable_sizes
)
1871 p
->type
|= CUPS_PRINTER_VARIABLE
;
1872 if (!ppd
->manual_copies
)
1873 p
->type
|= CUPS_PRINTER_COPIES
;
1874 if ((ppdattr
= ppdFindAttr(ppd
, "cupsFax", NULL
)) != NULL
)
1875 if (ppdattr
->value
&& !strcasecmp(ppdattr
->value
, "true"))
1876 p
->type
|= CUPS_PRINTER_FAX
;
1878 ippAddBoolean(p
->attrs
, IPP_TAG_PRINTER
, "color-supported",
1880 if (ppd
->throughput
)
1881 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
1882 "pages-per-minute", ppd
->throughput
);
1887 * The NickName can be localized in the character set specified
1888 * by the LanugageEncoding attribute. However, ppdOpen2() has
1889 * already converted the ppd->nickname member to UTF-8 for us
1890 * (the original attribute value is available separately)
1893 cupsdSetString(&p
->make_model
, ppd
->nickname
);
1895 else if (ppd
->modelname
)
1898 * Model name can only contain specific characters...
1901 cupsdSetString(&p
->make_model
, ppd
->modelname
);
1904 cupsdSetString(&p
->make_model
, "Bad PPD File");
1906 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
1907 "printer-make-and-model", NULL
, p
->make_model
);
1910 * Add media options from the PPD file...
1913 if ((input_slot
= ppdFindOption(ppd
, "InputSlot")) != NULL
)
1914 num_media
= input_slot
->num_choices
;
1918 if ((media_type
= ppdFindOption(ppd
, "MediaType")) != NULL
)
1919 num_media
+= media_type
->num_choices
;
1921 if ((page_size
= ppdFindOption(ppd
, "PageSize")) != NULL
)
1922 num_media
+= page_size
->num_choices
;
1924 if ((media_quality
= ppdFindOption(ppd
, "EFMediaQualityMode")) != NULL
)
1925 num_media
+= media_quality
->num_choices
;
1929 cupsdLogMessage(CUPSD_LOG_CRIT
,
1930 "The PPD file for printer %s contains no media "
1931 "options and is therefore invalid!", p
->name
);
1935 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
1936 "media-supported", num_media
, NULL
, NULL
);
1941 if (input_slot
!= NULL
)
1942 for (i
= 0; i
< input_slot
->num_choices
; i
++, val
++)
1943 val
->string
.text
= _cupsStrAlloc(input_slot
->choices
[i
].choice
);
1945 if (media_type
!= NULL
)
1946 for (i
= 0; i
< media_type
->num_choices
; i
++, val
++)
1947 val
->string
.text
= _cupsStrAlloc(media_type
->choices
[i
].choice
);
1949 if (media_quality
!= NULL
)
1950 for (i
= 0; i
< media_quality
->num_choices
; i
++, val
++)
1951 val
->string
.text
= _cupsStrAlloc(media_quality
->choices
[i
].choice
);
1953 if (page_size
!= NULL
)
1955 for (i
= 0; i
< page_size
->num_choices
; i
++, val
++)
1956 val
->string
.text
= _cupsStrAlloc(page_size
->choices
[i
].choice
);
1958 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
1959 "media-default", NULL
, page_size
->defchoice
);
1961 else if (input_slot
!= NULL
)
1962 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
1963 "media-default", NULL
, input_slot
->defchoice
);
1964 else if (media_type
!= NULL
)
1965 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
1966 "media-default", NULL
, media_type
->defchoice
);
1967 else if (media_quality
!= NULL
)
1968 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
1969 "media-default", NULL
, media_quality
->defchoice
);
1971 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
1972 "media-default", NULL
, "none");
1980 if ((output_bin
= ppdFindOption(ppd
, "OutputBin")) != NULL
)
1982 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
1983 "output-bin-supported", output_bin
->num_choices
,
1988 for (i
= 0, val
= attr
->values
;
1989 i
< output_bin
->num_choices
;
1991 val
->string
.text
= _cupsStrAlloc(output_bin
->choices
[i
].choice
);
1999 if ((duplex
= ppdFindOption(ppd
, "Duplex")) == NULL
)
2000 if ((duplex
= ppdFindOption(ppd
, "EFDuplex")) == NULL
)
2001 if ((duplex
= ppdFindOption(ppd
, "EFDuplexing")) == NULL
)
2002 if ((duplex
= ppdFindOption(ppd
, "KD03Duplex")) == NULL
)
2003 duplex
= ppdFindOption(ppd
, "JCLDuplex");
2005 if (duplex
&& duplex
->num_choices
> 1)
2007 p
->type
|= CUPS_PRINTER_DUPLEX
;
2009 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2010 "sides-supported", 3, NULL
, sides
);
2012 if (!strcasecmp(duplex
->defchoice
, "DuplexTumble"))
2013 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2014 "sides-default", NULL
, "two-sided-short-edge");
2015 else if (!strcasecmp(duplex
->defchoice
, "DuplexNoTumble"))
2016 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2017 "sides-default", NULL
, "two-sided-long-edge");
2019 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2020 "sides-default", NULL
, "one-sided");
2023 if (ppdFindOption(ppd
, "Collate") != NULL
)
2024 p
->type
|= CUPS_PRINTER_COLLATE
;
2026 if (ppdFindOption(ppd
, "StapleLocation") != NULL
)
2028 p
->type
|= CUPS_PRINTER_STAPLE
;
2029 finishings
[num_finishings
++] = IPP_FINISHINGS_STAPLE
;
2032 if (ppdFindOption(ppd
, "BindEdge") != NULL
)
2034 p
->type
|= CUPS_PRINTER_BIND
;
2035 finishings
[num_finishings
++] = IPP_FINISHINGS_BIND
;
2038 for (i
= 0; i
< ppd
->num_sizes
; i
++)
2039 if (ppd
->sizes
[i
].length
> 1728)
2040 p
->type
|= CUPS_PRINTER_LARGE
;
2041 else if (ppd
->sizes
[i
].length
> 1008)
2042 p
->type
|= CUPS_PRINTER_MEDIUM
;
2044 p
->type
|= CUPS_PRINTER_SMALL
;
2047 * Add a filter from application/vnd.cups-raw to printer/name to
2048 * handle "raw" printing by users.
2051 add_printer_filter(p
, p
->filetype
, "application/vnd.cups-raw 0 -");
2054 * Add any pre-filters in the PPD file...
2057 if ((ppdattr
= ppdFindAttr(ppd
, "cupsPreFilter", NULL
)) != NULL
)
2059 p
->prefiltertype
= mimeAddType(MimeDatabase
, "prefilter", p
->name
);
2061 for (; ppdattr
; ppdattr
= ppdFindNextAttr(ppd
, "cupsPreFilter", NULL
))
2063 add_printer_filter(p
, p
->prefiltertype
, ppdattr
->value
);
2067 * Add any filters in the PPD file...
2070 DEBUG_printf(("ppd->num_filters = %d\n", ppd
->num_filters
));
2071 for (i
= 0; i
< ppd
->num_filters
; i
++)
2073 DEBUG_printf(("ppd->filters[%d] = \"%s\"\n", i
, ppd
->filters
[i
]));
2074 add_printer_filter(p
, p
->filetype
, ppd
->filters
[i
]);
2077 if (ppd
->num_filters
== 0)
2080 * If there are no filters, add a PostScript printing filter.
2083 add_printer_filter(p
, p
->filetype
,
2084 "application/vnd.cups-postscript 0 -");
2088 * Show current and available port monitors for this printer...
2091 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
, "port-monitor",
2092 NULL
, p
->port_monitor
? p
->port_monitor
: "none");
2095 for (i
= 1, ppdattr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
2097 i
++, ppdattr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
));
2101 if (strstr(ppd
->protocols
, "TBCP"))
2103 else if (strstr(ppd
->protocols
, "BCP"))
2107 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2108 "port-monitor-supported", i
, NULL
, NULL
);
2110 attr
->values
[0].string
.text
= _cupsStrAlloc("none");
2112 for (i
= 1, ppdattr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
2114 i
++, ppdattr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
))
2115 attr
->values
[i
].string
.text
= _cupsStrAlloc(ppdattr
->value
);
2119 if (strstr(ppd
->protocols
, "TBCP"))
2120 attr
->values
[i
].string
.text
= _cupsStrAlloc("tbcp");
2121 else if (strstr(ppd
->protocols
, "BCP"))
2122 attr
->values
[i
].string
.text
= _cupsStrAlloc("bcp");
2126 cupsdSetString(&p
->product
, ppd
->product
);
2127 #endif /* HAVE_DNSSD */
2130 * Close the PPD and set the type...
2135 printer_type
= p
->type
;
2137 else if (!access(filename
, 0))
2139 int pline
; /* PPD line number */
2140 ppd_status_t pstatus
; /* PPD load status */
2143 pstatus
= ppdLastError(&pline
);
2145 cupsdLogMessage(CUPSD_LOG_ERROR
, "PPD file for %s cannot be loaded!",
2148 if (pstatus
<= PPD_ALLOC_ERROR
)
2149 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s", strerror(errno
));
2151 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s on line %d.",
2152 ppdErrorString(pstatus
), pline
);
2154 cupsdLogMessage(CUPSD_LOG_INFO
,
2155 "Hint: Run \"cupstestppd %s\" and fix any errors.",
2159 * Add a filter from application/vnd.cups-raw to printer/name to
2160 * handle "raw" printing by users.
2163 add_printer_filter(p
, p
->filetype
, "application/vnd.cups-raw 0 -");
2166 * Add a PostScript filter, since this is still possibly PS printer.
2169 add_printer_filter(p
, p
->filetype
,
2170 "application/vnd.cups-postscript 0 -");
2175 * If we have an interface script, add a filter entry for it...
2178 snprintf(filename
, sizeof(filename
), "%s/interfaces/%s", ServerRoot
,
2180 if (!access(filename
, X_OK
))
2183 * Yes, we have a System V style interface script; use it!
2186 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
2187 "printer-make-and-model", NULL
,
2188 "Local System V Printer");
2190 snprintf(filename
, sizeof(filename
), "*/* 0 %s/interfaces/%s",
2191 ServerRoot
, p
->name
);
2192 add_printer_filter(p
, p
->filetype
, filename
);
2194 else if (p
->device_uri
&&
2195 !strncmp(p
->device_uri
, "ipp://", 6) &&
2196 (strstr(p
->device_uri
, "/printers/") != NULL
||
2197 strstr(p
->device_uri
, "/classes/") != NULL
))
2200 * Tell the client this is really a hard-wired remote printer.
2203 printer_type
|= CUPS_PRINTER_REMOTE
;
2206 * Point the printer-uri-supported attribute to the
2210 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
2211 "printer-uri-supported", NULL
, p
->device_uri
);
2214 * Then set the make-and-model accordingly...
2217 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
2218 "printer-make-and-model", NULL
, "Remote Printer");
2221 * Print all files directly...
2230 * Otherwise we have neither - treat this as a "dumb" printer
2231 * with no PPD file...
2234 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
2235 "printer-make-and-model", NULL
, "Local Raw Printer");
2241 ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
2242 "finishings-supported", num_finishings
, (int *)finishings
);
2243 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
2244 "finishings-default", IPP_FINISHINGS_NONE
);
2249 * Copy the printer options into a browse attributes string we can re-use.
2252 if (!(p
->type
& CUPS_PRINTER_REMOTE
))
2254 const char *valptr
; /* Pointer into value */
2255 char *attrptr
; /* Pointer into attribute string */
2259 * Free the old browse attributes as needed...
2262 if (p
->browse_attrs
)
2263 free(p
->browse_attrs
);
2266 * Compute the length of all attributes + job-sheets, lease-duration,
2267 * and BrowseLocalOptions.
2270 for (length
= 1, i
= p
->num_options
, option
= p
->options
;
2274 length
+= strlen(option
->name
) + 2;
2278 for (valptr
= option
->value
; *valptr
; valptr
++)
2279 if (strchr(" \"\'\\", *valptr
))
2286 length
+= 13 + strlen(p
->job_sheets
[0]) + strlen(p
->job_sheets
[1]);
2288 if (BrowseLocalOptions
)
2289 length
+= 12 + strlen(BrowseLocalOptions
);
2291 if (p
->num_auth_info_required
> 0)
2293 length
+= 18; /* auth-info-required */
2295 for (i
= 0; i
< p
->num_auth_info_required
; i
++)
2296 length
+= strlen(p
->auth_info_required
[i
]) + 1;
2300 * Allocate the new string...
2303 if ((p
->browse_attrs
= calloc(1, length
)) == NULL
)
2304 cupsdLogMessage(CUPSD_LOG_ERROR
,
2305 "Unable to allocate %d bytes for browse data!",
2310 * Got the allocated string, now copy the options and attributes over...
2313 sprintf(p
->browse_attrs
, "job-sheets=%s,%s lease-duration=%d",
2314 p
->job_sheets
[0], p
->job_sheets
[1], BrowseTimeout
);
2315 attrptr
= p
->browse_attrs
+ strlen(p
->browse_attrs
);
2317 if (BrowseLocalOptions
)
2319 sprintf(attrptr
, " ipp-options=%s", BrowseLocalOptions
);
2320 attrptr
+= strlen(attrptr
);
2323 for (i
= p
->num_options
, option
= p
->options
;
2328 strcpy(attrptr
, option
->name
);
2329 attrptr
+= strlen(attrptr
);
2335 for (valptr
= option
->value
; *valptr
; valptr
++)
2337 if (strchr(" \"\'\\", *valptr
))
2340 *attrptr
++ = *valptr
;
2345 if (p
->num_auth_info_required
> 0)
2347 strcpy(attrptr
, "auth-info-required");
2350 for (i
= 0; i
< p
->num_auth_info_required
; i
++)
2352 *attrptr
++ = i
? ',' : '=';
2353 strcpy(attrptr
, p
->auth_info_required
[i
]);
2354 attrptr
+= strlen(attrptr
);
2363 * Populate the document-format-supported attribute...
2366 add_printer_formats(p
);
2368 DEBUG_printf(("cupsdSetPrinterAttrs: leaving name = %s, type = %x\n", p
->name
,
2372 * Add name-default attributes...
2375 add_printer_defaults(p
);
2379 * Write the IRIX printer config and status files...
2382 write_irix_config(p
);
2383 write_irix_state(p
);
2387 * Let the browse protocols reflect the change
2390 cupsdRegisterPrinter(p
);
2395 * 'cupsdSetPrinterReasons()' - Set/update the reasons strings.
2399 cupsdSetPrinterReasons(
2400 cupsd_printer_t
*p
, /* I - Printer */
2401 const char *s
) /* I - Reasons strings */
2403 int i
; /* Looping var */
2404 const char *sptr
; /* Pointer into reasons */
2405 char reason
[255], /* Reason string */
2406 *rptr
; /* Pointer into reason */
2409 if (s
[0] == '-' || s
[0] == '+')
2412 * Add/remove reasons...
2420 * Replace reasons...
2425 for (i
= 0; i
< p
->num_reasons
; i
++)
2426 free(p
->reasons
[i
]);
2432 * Loop through all of the reasons...
2438 * Skip leading whitespace and commas...
2441 while (isspace(*sptr
& 255) || *sptr
== ',')
2444 for (rptr
= reason
; *sptr
&& !isspace(*sptr
& 255) && *sptr
!= ','; sptr
++)
2445 if (rptr
< (reason
+ sizeof(reason
) - 1))
2459 for (i
= 0; i
< p
->num_reasons
; i
++)
2460 if (!strcasecmp(reason
, p
->reasons
[i
]))
2463 * Found a match, so remove it...
2467 free(p
->reasons
[i
]);
2469 if (i
< p
->num_reasons
)
2470 memmove(p
->reasons
+ i
, p
->reasons
+ i
+ 1,
2471 (p
->num_reasons
- i
) * sizeof(char *));
2476 else if (p
->num_reasons
< (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
2482 for (i
= 0; i
< p
->num_reasons
; i
++)
2483 if (!strcasecmp(reason
, p
->reasons
[i
]))
2486 if (i
>= p
->num_reasons
)
2488 p
->reasons
[i
] = strdup(reason
);
2497 * 'cupsdSetPrinterState()' - Update the current state of a printer.
2501 cupsdSetPrinterState(
2502 cupsd_printer_t
*p
, /* I - Printer to change */
2503 ipp_pstate_t s
, /* I - New state */
2504 int update
) /* I - Update printers.conf? */
2506 ipp_pstate_t old_state
; /* Old printer state */
2510 * Can't set status of remote printers...
2513 if (p
->type
& CUPS_PRINTER_REMOTE
)
2517 * Set the new state...
2520 old_state
= p
->state
;
2525 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE_CHANGED
, p
, NULL
,
2526 "%s \"%s\" state changed.",
2527 (p
->type
& CUPS_PRINTER_CLASS
) ? "Class" : "Printer",
2531 * Let the browse code know this needs to be updated...
2535 p
->state_time
= time(NULL
);
2539 write_irix_state(p
);
2543 cupsdAddPrinterHistory(p
);
2546 * Let the browse protocols reflect the change...
2549 cupsdRegisterPrinter(p
);
2552 * Save the printer configuration if a printer goes from idle or processing
2553 * to stopped (or visa-versa)...
2556 if ((old_state
== IPP_PRINTER_STOPPED
) != (s
== IPP_PRINTER_STOPPED
) &&
2559 if (p
->type
& CUPS_PRINTER_CLASS
)
2560 cupsdSaveAllClasses();
2562 cupsdSaveAllPrinters();
2568 * 'cupsdStopPrinter()' - Stop a printer from printing any jobs...
2572 cupsdStopPrinter(cupsd_printer_t
*p
, /* I - Printer to stop */
2573 int update
)/* I - Update printers.conf? */
2575 cupsd_job_t
*job
; /* Active print job */
2579 * Set the printer state...
2582 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, update
);
2585 * See if we have a job printing on this printer...
2591 * Get pointer to job...
2594 job
= (cupsd_job_t
*)p
->job
;
2600 cupsdStopJob(job
, 0);
2603 * Reset the state to pending...
2606 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
2607 job
->state_value
= IPP_JOB_PENDING
;
2611 cupsdAddEvent(CUPSD_EVENT_JOB_STOPPED
, p
, job
,
2612 "Job stopped due to printer being paused");
2618 * 'cupsdUpdatePrinters()' - Update printers after a partial reload.
2622 cupsdUpdatePrinters(void)
2624 cupsd_printer_t
*p
; /* Current printer */
2628 * Loop through the printers and recreate the printer attributes
2629 * for any local printers since the policy and/or access control
2630 * stuff may have changed. Also, if browsing is disabled, remove
2631 * any remote printers...
2634 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
2636 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
2639 * Remove remote printers if we are no longer browsing...
2642 if (!Browsing
&& (p
->type
& (CUPS_PRINTER_IMPLICIT
| CUPS_PRINTER_REMOTE
)))
2644 if (p
->type
& CUPS_PRINTER_IMPLICIT
)
2645 cupsArrayRemove(ImplicitPrinters
, p
);
2647 cupsArraySave(Printers
);
2648 cupsdDeletePrinter(p
, 0);
2649 cupsArrayRestore(Printers
);
2654 * Update the operation policy pointer...
2657 if ((p
->op_policy_ptr
= cupsdFindPolicy(p
->op_policy
)) == NULL
)
2658 p
->op_policy_ptr
= DefaultPolicyPtr
;
2661 * Update printer attributes as needed...
2664 if (!(p
->type
& CUPS_PRINTER_REMOTE
))
2665 cupsdSetPrinterAttrs(p
);
2671 * 'cupsdValidateDest()' - Validate a printer/class destination.
2674 const char * /* O - Printer or class name */
2676 const char *uri
, /* I - Printer URI */
2677 cups_ptype_t
*dtype
, /* O - Type (printer or class) */
2678 cupsd_printer_t
**printer
) /* O - Printer pointer */
2680 cupsd_printer_t
*p
; /* Current printer */
2681 char localname
[1024],/* Localized hostname */
2682 *lptr
, /* Pointer into localized hostname */
2683 *sptr
, /* Pointer into server name */
2684 *rptr
, /* Pointer into resource */
2685 scheme
[32], /* Scheme portion of URI */
2686 username
[64], /* Username portion of URI */
2687 hostname
[HTTP_MAX_HOST
],
2688 /* Host portion of URI */
2689 resource
[HTTP_MAX_URI
];
2690 /* Resource portion of URI */
2691 int port
; /* Port portion of URI */
2694 DEBUG_printf(("cupsdValidateDest(uri=\"%s\", dtype=%p, printer=%p)\n", uri
,
2698 * Initialize return values...
2705 *dtype
= (cups_ptype_t
)0;
2708 * Pull the hostname and resource from the URI...
2711 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
, scheme
, sizeof(scheme
),
2712 username
, sizeof(username
), hostname
, sizeof(hostname
),
2713 &port
, resource
, sizeof(resource
));
2716 * See if the resource is a class or printer...
2719 if (!strncmp(resource
, "/classes/", 9))
2725 rptr
= resource
+ 9;
2727 else if (!strncmp(resource
, "/printers/", 10))
2733 rptr
= resource
+ 10;
2738 * Bad resource name...
2745 * See if the printer or class name exists...
2748 p
= cupsdFindDest(rptr
);
2750 if (p
== NULL
&& strchr(rptr
, '@') == NULL
)
2758 *dtype
= p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
|
2759 CUPS_PRINTER_REMOTE
);
2765 * Change localhost to the server name...
2768 if (!strcasecmp(hostname
, "localhost"))
2769 strlcpy(hostname
, ServerName
, sizeof(hostname
));
2771 strlcpy(localname
, hostname
, sizeof(localname
));
2773 if (!strcasecmp(hostname
, ServerName
))
2776 * Localize the hostname...
2779 lptr
= strchr(localname
, '.');
2780 sptr
= strchr(ServerName
, '.');
2782 if (sptr
!= NULL
&& lptr
!= NULL
)
2785 * Strip the common domain name components...
2788 while (lptr
!= NULL
)
2790 if (!strcasecmp(lptr
, sptr
))
2796 lptr
= strchr(lptr
+ 1, '.');
2801 DEBUG_printf(("localized hostname is \"%s\"...\n", localname
));
2804 * Find a matching printer or class...
2807 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
2809 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
2810 if (!strcasecmp(p
->hostname
, localname
) &&
2811 !strcasecmp(p
->name
, rptr
))
2817 *dtype
= p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
|
2818 CUPS_PRINTER_REMOTE
);
2828 * 'cupsdWritePrintcap()' - Write a pseudo-printcap file for older applications
2833 cupsdWritePrintcap(void)
2835 cups_file_t
*fp
; /* printcap file */
2836 cupsd_printer_t
*p
; /* Current printer */
2841 * Update the IRIX printer state for the default printer; if
2842 * no printers remain, then the default printer file will be
2846 write_irix_state(DefaultPrinter
);
2850 * See if we have a printcap file; if not, don't bother writing it.
2853 if (!Printcap
|| !*Printcap
)
2857 * Open the printcap file...
2860 if ((fp
= cupsFileOpen(Printcap
, "w")) == NULL
)
2864 * Put a comment header at the top so that users will know where the
2865 * data has come from...
2868 cupsFilePuts(fp
, "# This file was automatically generated by cupsd(8) from the\n");
2869 cupsFilePrintf(fp
, "# %s/printers.conf file. All changes to this file\n",
2871 cupsFilePuts(fp
, "# will be lost.\n");
2876 * Write a new printcap with the current list of printers.
2879 switch (PrintcapFormat
)
2883 * Each printer is put in the file as:
2893 cupsFilePrintf(fp
, "%s|%s:rm=%s:rp=%s:\n", DefaultPrinter
->name
,
2894 DefaultPrinter
->info
, ServerName
, DefaultPrinter
->name
);
2896 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
2898 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
2899 if (p
!= DefaultPrinter
)
2900 cupsFilePrintf(fp
, "%s|%s:rm=%s:rp=%s:\n", p
->name
, p
->info
,
2901 ServerName
, p
->name
);
2904 case PRINTCAP_SOLARIS
:
2906 * Each printer is put in the file as:
2908 * _all:all=Printer1,Printer2,Printer3,...,PrinterN
2909 * _default:use=DefaultPrinter
2911 * :bsdaddr=ServerName,Printer1:\
2912 * :description=Description:
2914 * :bsdaddr=ServerName,Printer2:\
2915 * :description=Description:
2917 * :bsdaddr=ServerName,Printer3:\
2918 * :description=Description:
2921 * :bsdaddr=ServerName,PrinterN:\
2922 * :description=Description:
2925 cupsFilePuts(fp
, "_all:all=");
2926 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
2928 p
= (cupsd_printer_t
*)cupsArrayCurrent(Printers
))
2929 cupsFilePrintf(fp
, "%s%c", p
->name
,
2930 cupsArrayNext(Printers
) ? ',' : '\n');
2933 cupsFilePrintf(fp
, "_default:use=%s\n", DefaultPrinter
->name
);
2935 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
2937 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
2938 cupsFilePrintf(fp
, "%s:\\\n"
2939 "\t:bsdaddr=%s,%s:\\\n"
2940 "\t:description=%s:\n",
2941 p
->name
, ServerName
, p
->name
, p
->info
? p
->info
: "");
2955 * 'cupsdSanitizeURI()' - Sanitize a device URI...
2958 char * /* O - New device URI */
2959 cupsdSanitizeURI(const char *uri
, /* I - Original device URI */
2960 char *buffer
, /* O - New device URI */
2961 int buflen
) /* I - Size of new device URI buffer */
2963 char *start
, /* Start of data after scheme */
2964 *slash
, /* First slash after scheme:// */
2965 *ptr
; /* Pointer into user@host:port part */
2969 * Range check input...
2972 if (!uri
|| !buffer
|| buflen
< 2)
2976 * Copy the device URI to the new buffer...
2979 strlcpy(buffer
, uri
, buflen
);
2982 * Find the end of the scheme:// part...
2985 if ((ptr
= strchr(buffer
, ':')) == NULL
)
2986 return (buffer
); /* No scheme: part... */
2988 for (start
= ptr
+ 1; *start
; start
++)
2993 * Find the next slash (/) in the URI...
2996 if ((slash
= strchr(start
, '/')) == NULL
)
2997 slash
= start
+ strlen(start
); /* No slash, point to the end */
3000 * Check for an @ sign before the slash...
3003 if ((ptr
= strchr(start
, '@')) != NULL
&& ptr
< slash
)
3006 * Found an @ sign and it is before the resource part, so we have
3007 * an authentication string. Copy the remaining URI over the
3008 * authentication string...
3011 _cups_strcpy(start
, ptr
+ 1);
3015 * Return the new device URI...
3023 * 'add_printer_defaults()' - Add name-default attributes to the printer attributes.
3027 add_printer_defaults(cupsd_printer_t
*p
)/* I - Printer */
3029 int i
; /* Looping var */
3030 int num_options
; /* Number of default options */
3031 cups_option_t
*options
, /* Default options */
3032 *option
; /* Current option */
3033 char name
[256]; /* name-default */
3037 * Maintain a common array of default attribute names...
3040 if (!CommonDefaults
)
3042 CommonDefaults
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
3044 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("copies-default"));
3045 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("document-format-default"));
3046 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("finishings-default"));
3047 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-hold-until-default"));
3048 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-priority-default"));
3049 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-sheets-default"));
3050 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("media-default"));
3051 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("number-up-default"));
3052 cupsArrayAdd(CommonDefaults
,
3053 _cupsStrAlloc("orientation-requested-default"));
3054 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("sides-default"));
3058 * Add all of the default options from the .conf files...
3061 for (num_options
= 0, i
= p
->num_options
, option
= p
->options
;
3065 if (strcmp(option
->name
, "ipp-options") &&
3066 strcmp(option
->name
, "job-sheets") &&
3067 strcmp(option
->name
, "lease-duration"))
3069 snprintf(name
, sizeof(name
), "%s-default", option
->name
);
3070 num_options
= cupsAddOption(name
, option
->value
, num_options
, &options
);
3072 if (!cupsArrayFind(CommonDefaults
, name
))
3073 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc(name
));
3078 * Convert options to IPP attributes...
3081 cupsEncodeOptions2(p
->attrs
, num_options
, options
, IPP_TAG_PRINTER
);
3082 cupsFreeOptions(num_options
, options
);
3085 * Add standard -default attributes as needed...
3088 if (!cupsGetOption("copies", p
->num_options
, p
->options
))
3089 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
, "copies-default",
3092 if (!cupsGetOption("document-format", p
->num_options
, p
->options
))
3093 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_MIMETYPE
,
3094 "document-format-default", NULL
, "application/octet-stream");
3096 if (!cupsGetOption("job-hold-until", p
->num_options
, p
->options
))
3097 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3098 "job-hold-until-default", NULL
, "no-hold");
3100 if (!cupsGetOption("job-priority", p
->num_options
, p
->options
))
3101 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3102 "job-priority-default", 50);
3104 if (!cupsGetOption("number-up", p
->num_options
, p
->options
))
3105 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3106 "number-up-default", 1);
3108 if (!cupsGetOption("orientation-requested", p
->num_options
, p
->options
))
3109 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
3110 "orientation-requested-default", IPP_PORTRAIT
);
3112 if (!cupsGetOption("notify-lease-duration", p
->num_options
, p
->options
))
3113 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3114 "notify-lease-duration-default", DefaultLeaseDuration
);
3116 if (!cupsGetOption("notify-events", p
->num_options
, p
->options
))
3117 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3118 "notify-events-default", NULL
, "job-completed");
3123 * 'add_printer_filter()' - Add a MIME filter for a printer.
3128 cupsd_printer_t
*p
, /* I - Printer to add to */
3129 mime_type_t
*filtertype
, /* I - Filter or prefilter MIME type */
3130 const char *filter
) /* I - Filter to add */
3132 char super
[MIME_MAX_SUPER
], /* Super-type for filter */
3133 type
[MIME_MAX_TYPE
], /* Type for filter */
3134 program
[1024]; /* Program/filter name */
3135 int cost
; /* Cost of filter */
3136 mime_type_t
*temptype
; /* MIME type looping var */
3137 char filename
[1024]; /* Full filter filename */
3141 * Parse the filter string; it should be in the following format:
3143 * super/type cost program
3146 if (sscanf(filter
, "%15[^/]/%31s%d%1023s", super
, type
, &cost
, program
) != 4)
3148 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: invalid filter string \"%s\"!",
3154 * See if the filter program exists; if not, stop the printer and flag
3158 if (strcmp(program
, "-"))
3160 if (program
[0] == '/')
3161 strlcpy(filename
, program
, sizeof(filename
));
3163 snprintf(filename
, sizeof(filename
), "%s/filter/%s", ServerBin
, program
);
3165 if (access(filename
, X_OK
))
3167 snprintf(p
->state_message
, sizeof(p
->state_message
),
3168 "Filter \"%s\" for printer \"%s\" not available: %s",
3169 program
, p
->name
, strerror(errno
));
3170 cupsdSetPrinterReasons(p
, "+cups-missing-filter-error");
3171 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, 0);
3173 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s", p
->state_message
);
3178 * Mark the CUPS_PRINTER_COMMANDS bit if we have a filter for
3179 * application/vnd.cups-command...
3182 if (!strcasecmp(super
, "application") &&
3183 !strcasecmp(type
, "vnd.cups-command"))
3184 p
->type
|= CUPS_PRINTER_COMMANDS
;
3187 * Add the filter to the MIME database, supporting wildcards as needed...
3190 for (temptype
= mimeFirstType(MimeDatabase
);
3192 temptype
= mimeNextType(MimeDatabase
))
3193 if (((super
[0] == '*' && strcasecmp(temptype
->super
, "printer")) ||
3194 !strcasecmp(temptype
->super
, super
)) &&
3195 (type
[0] == '*' || !strcasecmp(temptype
->type
, type
)))
3197 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3198 "add_printer_filter: %s: adding filter %s/%s %s/%s %d %s",
3199 p
->name
, temptype
->super
, temptype
->type
,
3200 filtertype
->super
, filtertype
->type
,
3202 mimeAddFilter(MimeDatabase
, temptype
, filtertype
, cost
, program
);
3208 * 'add_printer_formats()' - Add document-format-supported values for a printer.
3212 add_printer_formats(cupsd_printer_t
*p
) /* I - Printer */
3214 int i
; /* Looping var */
3215 mime_type_t
*type
; /* Current MIME type */
3216 cups_array_t
*filters
; /* Filters */
3217 ipp_attribute_t
*attr
; /* document-format-supported attribute */
3218 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
3219 /* MIME type name */
3223 * Raw (and remote) queues advertise all of the supported MIME
3227 cupsArrayDelete(p
->filetypes
);
3228 p
->filetypes
= NULL
;
3232 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
,
3233 (ipp_tag_t
)(IPP_TAG_MIMETYPE
| IPP_TAG_COPY
),
3234 "document-format-supported", NumMimeTypes
, NULL
, MimeTypes
);
3239 * Otherwise, loop through the supported MIME types and see if there
3240 * are filters for them...
3243 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_printer_formats: %d types, %d filters",
3244 mimeNumTypes(MimeDatabase
), mimeNumFilters(MimeDatabase
));
3246 p
->filetypes
= cupsArrayNew(NULL
, NULL
);
3248 for (type
= mimeFirstType(MimeDatabase
);
3250 type
= mimeNextType(MimeDatabase
))
3252 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
3254 if ((filters
= mimeFilter(MimeDatabase
, type
, p
->filetype
, NULL
)) != NULL
)
3256 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3257 "add_printer_formats: %s: %s needs %d filters",
3258 p
->name
, mimetype
, cupsArrayCount(filters
));
3260 cupsArrayDelete(filters
);
3261 cupsArrayAdd(p
->filetypes
, type
);
3264 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3265 "add_printer_formats: %s: %s not supported",
3269 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3270 "add_printer_formats: %s: %d supported types",
3271 p
->name
, cupsArrayCount(p
->filetypes
) + 1);
3274 * Add the file formats that can be filtered...
3277 if ((type
= mimeType(MimeDatabase
, "application", "octet-stream")) == NULL
||
3278 !cupsArrayFind(p
->filetypes
, type
))
3283 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_MIMETYPE
,
3284 "document-format-supported",
3285 cupsArrayCount(p
->filetypes
) + 1, NULL
, NULL
);
3288 attr
->values
[0].string
.text
= _cupsStrAlloc("application/octet-stream");
3290 for (type
= (mime_type_t
*)cupsArrayFirst(p
->filetypes
);
3292 i
++, type
= (mime_type_t
*)cupsArrayNext(p
->filetypes
))
3294 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
3296 attr
->values
[i
].string
.text
= _cupsStrAlloc(mimetype
);
3301 char pdl
[1024]; /* Buffer to build pdl list */
3302 mime_filter_t
*filter
; /* MIME filter looping var */
3307 if (mimeType(MimeDatabase
, "application", "pdf"))
3308 strlcat(pdl
, "application/pdf,", sizeof(pdl
));
3310 if (mimeType(MimeDatabase
, "application", "postscript"))
3311 strlcat(pdl
, "application/postscript,", sizeof(pdl
));
3313 if (mimeType(MimeDatabase
, "application", "vnd.cups-raster"))
3314 strlcat(pdl
, "application/vnd.cups-raster,", sizeof(pdl
));
3317 * Determine if this is a Tioga PrintJobMgr based queue...
3320 for (filter
= (mime_filter_t
*)cupsArrayFirst(MimeDatabase
->filters
);
3322 filter
= (mime_filter_t
*)cupsArrayNext(MimeDatabase
->filters
))
3324 if (filter
->dst
== p
->filetype
&& filter
->filter
&&
3325 strstr(filter
->filter
, "PrintJobMgr"))
3330 * We only support raw printing if this is not a Tioga PrintJobMgr based
3331 * queue and if application/octet-stream is a known conversion...
3334 if (!filter
&& mimeType(MimeDatabase
, "application", "octet-stream"))
3335 strlcat(pdl
, "application/octet-stream,", sizeof(pdl
));
3337 if (mimeType(MimeDatabase
, "image", "png"))
3338 strlcat(pdl
, "image/png,", sizeof(pdl
));
3341 pdl
[strlen(pdl
) - 1] = '\0'; /* Remove trailing comma */
3343 cupsdSetString(&p
->pdl
, pdl
);
3345 #endif /* HAVE_DNSSD */
3350 * 'compare_printers()' - Compare two printers.
3353 static int /* O - Result of comparison */
3354 compare_printers(void *first
, /* I - First printer */
3355 void *second
, /* I - Second printer */
3356 void *data
) /* I - App data (not used) */
3358 return (strcasecmp(((cupsd_printer_t
*)first
)->name
,
3359 ((cupsd_printer_t
*)second
)->name
));
3364 * 'delete_printer_filters()' - Delete all MIME filters for a printer.
3368 delete_printer_filters(
3369 cupsd_printer_t
*p
) /* I - Printer to remove from */
3371 mime_filter_t
*filter
; /* MIME filter looping var */
3375 * Range check input...
3382 * Remove all filters from the MIME database that have a destination
3383 * type == printer...
3386 for (filter
= mimeFirstFilter(MimeDatabase
);
3388 filter
= mimeNextFilter(MimeDatabase
))
3389 if (filter
->dst
== p
->filetype
)
3392 * Delete the current filter...
3395 mimeDeleteFilter(MimeDatabase
, filter
);
3402 * 'write_irix_config()' - Update the config files used by the IRIX
3407 write_irix_config(cupsd_printer_t
*p
) /* I - Printer to update */
3409 char filename
[1024]; /* Interface script filename */
3410 cups_file_t
*fp
; /* Interface script file */
3411 ipp_attribute_t
*attr
; /* Attribute data */
3415 * Add dummy interface and GUI scripts to fool SGI's "challenged" printing
3416 * tools. First the interface script that tells the tools what kind of
3417 * printer we have...
3420 snprintf(filename
, sizeof(filename
), "/var/spool/lp/interface/%s", p
->name
);
3422 if (p
->type
& CUPS_PRINTER_CLASS
)
3424 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
3426 cupsFilePuts(fp
, "#!/bin/sh\n");
3428 if ((attr
= ippFindAttribute(p
->attrs
, "printer-make-and-model",
3429 IPP_TAG_TEXT
)) != NULL
)
3430 cupsFilePrintf(fp
, "NAME=\"%s\"\n", attr
->values
[0].string
.text
);
3431 else if (p
->type
& CUPS_PRINTER_CLASS
)
3432 cupsFilePuts(fp
, "NAME=\"Printer Class\"\n");
3434 cupsFilePuts(fp
, "NAME=\"Remote Destination\"\n");
3436 if (p
->type
& CUPS_PRINTER_COLOR
)
3437 cupsFilePuts(fp
, "TYPE=ColorPostScript\n");
3439 cupsFilePuts(fp
, "TYPE=MonoPostScript\n");
3441 cupsFilePrintf(fp
, "HOSTNAME=%s\n", ServerName
);
3442 cupsFilePrintf(fp
, "HOSTPRINTER=%s\n", p
->name
);
3446 chmod(filename
, 0755);
3447 chown(filename
, User
, Group
);
3451 * Then the member file that tells which device file the queue is connected
3452 * to... Networked printers use "/dev/null" in this file, so that's what
3453 * we use (the actual device URI can confuse some apps...)
3456 snprintf(filename
, sizeof(filename
), "/var/spool/lp/member/%s", p
->name
);
3458 if (p
->type
& CUPS_PRINTER_CLASS
)
3460 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
3462 cupsFilePuts(fp
, "/dev/null\n");
3466 chmod(filename
, 0644);
3467 chown(filename
, User
, Group
);
3471 * The gui_interface file is a script or program that launches a GUI
3472 * option panel for the printer, using options specified on the
3473 * command-line in the third argument. The option panel must send
3474 * any printing options to stdout on a single line when the user
3475 * accepts them, or nothing if the user cancels the dialog.
3477 * The default options panel program is /usr/bin/glpoptions, from
3478 * the ESP Print Pro software. You can select another using the
3479 * PrintcapGUI option.
3482 snprintf(filename
, sizeof(filename
), "/var/spool/lp/gui_interface/ELF/%s.gui", p
->name
);
3484 if (p
->type
& CUPS_PRINTER_CLASS
)
3486 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
3488 cupsFilePuts(fp
, "#!/bin/sh\n");
3489 cupsFilePrintf(fp
, "%s -d %s -o \"$3\"\n", PrintcapGUI
, p
->name
);
3493 chmod(filename
, 0755);
3494 chown(filename
, User
, Group
);
3498 * The POD config file is needed by the printstatus command to show
3499 * the printer location and device.
3502 snprintf(filename
, sizeof(filename
), "/var/spool/lp/pod/%s.config", p
->name
);
3504 if (p
->type
& CUPS_PRINTER_CLASS
)
3506 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
3508 cupsFilePrintf(fp
, "Printer Class | %s\n",
3509 (p
->type
& CUPS_PRINTER_COLOR
) ? "ColorPostScript" : "MonoPostScript");
3510 cupsFilePrintf(fp
, "Printer Model | %s\n", p
->make_model
? p
->make_model
: "");
3511 cupsFilePrintf(fp
, "Location Code | %s\n", p
->location
? p
->location
: "");
3512 cupsFilePrintf(fp
, "Physical Location | %s\n", p
->info
? p
->info
: "");
3513 cupsFilePrintf(fp
, "Port Path | %s\n", p
->device_uri
? p
->device_uri
: "");
3514 cupsFilePrintf(fp
, "Config Path | /var/spool/lp/pod/%s.config\n", p
->name
);
3515 cupsFilePrintf(fp
, "Active Status Path | /var/spool/lp/pod/%s.status\n", p
->name
);
3516 cupsFilePuts(fp
, "Status Update Wait | 10 seconds\n");
3520 chmod(filename
, 0664);
3521 chown(filename
, User
, Group
);
3527 * 'write_irix_state()' - Update the status files used by IRIX printing
3532 write_irix_state(cupsd_printer_t
*p
) /* I - Printer to update */
3534 char filename
[1024]; /* Interface script filename */
3535 cups_file_t
*fp
; /* Interface script file */
3536 int tag
; /* Status tag value */
3542 * The POD status file is needed for the printstatus window to
3543 * provide the current status of the printer.
3546 snprintf(filename
, sizeof(filename
), "/var/spool/lp/pod/%s.status", p
->name
);
3548 if (p
->type
& CUPS_PRINTER_CLASS
)
3550 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
3552 cupsFilePrintf(fp
, "Operational Status | %s\n",
3553 (p
->state
== IPP_PRINTER_IDLE
) ? "Idle" :
3554 (p
->state
== IPP_PRINTER_PROCESSING
) ? "Busy" :
3556 cupsFilePrintf(fp
, "Information | 01 00 00 | %s\n", CUPS_SVERSION
);
3557 cupsFilePrintf(fp
, "Information | 02 00 00 | Device URI: %s\n",
3558 p
->device_uri
? p
->device_uri
: "");
3559 cupsFilePrintf(fp
, "Information | 03 00 00 | %s jobs\n",
3560 p
->accepting
? "Accepting" : "Not accepting");
3561 cupsFilePrintf(fp
, "Information | 04 00 00 | %s\n", p
->state_message
);
3565 chmod(filename
, 0664);
3566 chown(filename
, User
, Group
);
3570 * The activeicons file is needed to provide desktop icons for printers:
3572 * [ quoted from /usr/lib/print/tagit ]
3574 * --- Type of printer tags (base values)
3576 * Dumb=66048 # 0x10200
3577 * DumbColor=66080 # 0x10220
3578 * Raster=66112 # 0x10240
3579 * ColorRaster=66144 # 0x10260
3580 * Plotter=66176 # 0x10280
3581 * PostScript=66208 # 0x102A0
3582 * ColorPostScript=66240 # 0x102C0
3583 * MonoPostScript=66272 # 0x102E0
3585 * --- Printer state modifiers for local printers
3590 * Unknown=3 # 0x3 (Faulted due to unknown reason)
3592 * --- Printer state modifiers for network printers
3596 * NetFaulted=10 # 0xA
3597 * NetUnknown=11 # 0xB (Faulted due to unknown reason)
3600 snprintf(filename
, sizeof(filename
), "/var/spool/lp/activeicons/%s", p
->name
);
3602 if (p
->type
& CUPS_PRINTER_CLASS
)
3604 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
3606 if (p
->type
& CUPS_PRINTER_COLOR
)
3611 if (p
->type
& CUPS_PRINTER_REMOTE
)
3614 if (p
->state
== IPP_PRINTER_PROCESSING
)
3617 else if (p
->state
== IPP_PRINTER_STOPPED
)
3620 cupsFilePuts(fp
, "#!/bin/sh\n");
3621 cupsFilePrintf(fp
, "#Tag %d\n", tag
);
3625 chmod(filename
, 0755);
3626 chown(filename
, User
, Group
);
3631 * The default file is needed by the printers window to show
3632 * the default printer.
3635 snprintf(filename
, sizeof(filename
), "/var/spool/lp/default");
3637 if (DefaultPrinter
!= NULL
)
3639 if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
3641 cupsFilePrintf(fp
, "%s\n", DefaultPrinter
->name
);
3645 chmod(filename
, 0644);
3646 chown(filename
, User
, Group
);
3656 * End of "$Id: printers.c 6354 2007-03-19 06:16:32Z mike $".