2 * "$Id: printers.c 5330 2006-03-23 21:07:20Z mike $"
4 * Printer routines for the Common UNIX Printing System (CUPS).
6 * Copyright 1997-2006 by Easy Software Products, all rights reserved.
8 * These coded instructions, statements, and computer programs are the
9 * property of Easy Software Products and are protected by Federal
10 * copyright law. Distribution and use rights are outlined in the file
11 * "LICENSE.txt" which should have been included with this file. If this
12 * file is missing or damaged please contact Easy Software Products
15 * Attn: CUPS Licensing Information
16 * Easy Software Products
17 * 44141 Airport View Drive, Suite 204
18 * Hollywood, Maryland 20636 USA
20 * Voice: (301) 373-9600
21 * EMail: cups-info@cups.org
22 * WWW: http://www.cups.org
26 * cupsdAddPrinter() - Add a printer to the system.
27 * 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...
71 static void add_printer_defaults(cupsd_printer_t
*p
);
72 static void add_printer_filter(cupsd_printer_t
*p
, const char *filter
);
73 static void add_printer_formats(cupsd_printer_t
*p
);
74 static int compare_printers(void *first
, void *second
, void *data
);
75 static void delete_printer_filters(cupsd_printer_t
*p
);
77 static void write_irix_config(cupsd_printer_t
*p
);
78 static void write_irix_state(cupsd_printer_t
*p
);
83 * 'cupsdAddPrinter()' - Add a printer to the system.
86 cupsd_printer_t
* /* O - New printer */
87 cupsdAddPrinter(const char *name
) /* I - Name of printer */
89 cupsd_printer_t
*p
; /* New printer */
93 * Range check input...
96 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdAddPrinter(\"%s\")", name
);
99 * Create a new printer entity...
102 if ((p
= calloc(1, sizeof(cupsd_printer_t
))) == NULL
)
104 cupsdLogMessage(CUPSD_LOG_CRIT
, "Unable to allocate memory for printer - %s",
109 cupsdSetString(&p
->name
, name
);
110 cupsdSetString(&p
->info
, name
);
111 cupsdSetString(&p
->hostname
, ServerName
);
113 cupsdSetStringf(&p
->uri
, "ipp://%s:%d/printers/%s", ServerName
, LocalPort
, name
);
114 cupsdSetStringf(&p
->device_uri
, "file:/dev/null");
116 p
->state
= IPP_PRINTER_STOPPED
;
117 p
->state_time
= time(NULL
);
119 p
->shared
= DefaultShared
;
120 p
->filetype
= mimeAddType(MimeDatabase
, "printer", name
);
122 cupsdSetString(&p
->job_sheets
[0], "none");
123 cupsdSetString(&p
->job_sheets
[1], "none");
125 cupsdSetString(&p
->error_policy
, "stop-printer");
126 cupsdSetString(&p
->op_policy
, DefaultPolicy
);
128 p
->op_policy_ptr
= DefaultPolicyPtr
;
130 if (MaxPrinterHistory
)
131 p
->history
= calloc(MaxPrinterHistory
, sizeof(ipp_t
*));
134 * Insert the printer in the printer list alphabetically...
138 Printers
= cupsArrayNew(compare_printers
, NULL
);
140 cupsArrayAdd(Printers
, p
);
142 if (!ImplicitPrinters
)
143 ImplicitPrinters
= cupsArrayNew(compare_printers
, NULL
);
146 * Return the new printer...
154 * 'cupsdAddPrinterHistory()' - Add the current printer state to the history.
158 cupsdAddPrinterHistory(
159 cupsd_printer_t
*p
) /* I - Printer */
161 ipp_t
*history
; /* History collection */
165 * Stop early if we aren't keeping history data...
168 if (MaxPrinterHistory
<= 0)
172 * Retire old history data as needed...
175 p
->sequence_number
++;
177 if (p
->num_history
>= MaxPrinterHistory
)
180 ippDelete(p
->history
[0]);
181 memmove(p
->history
, p
->history
+ 1, p
->num_history
* sizeof(ipp_t
*));
185 * Create a collection containing the current printer-state, printer-up-time,
186 * printer-state-message, and printer-state-reasons attributes.
190 ippAddInteger(history
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-state",
192 ippAddBoolean(history
, IPP_TAG_PRINTER
, "printer-is-accepting-jobs",
194 ippAddBoolean(history
, IPP_TAG_PRINTER
, "printer-is-shared", p
->shared
);
195 ippAddString(history
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-state-message",
196 NULL
, p
->state_message
);
199 ippAddString(history
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
200 "com.apple.print.recoverable-message", NULL
, p
->recoverable
);
201 #endif /* __APPLE__ */
202 if (p
->num_reasons
== 0)
203 ippAddString(history
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
204 "printer-state-reasons", NULL
,
205 p
->state
== IPP_PRINTER_STOPPED
? "paused" : "none");
207 ippAddStrings(history
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
208 "printer-state-reasons", p
->num_reasons
, NULL
,
209 (const char * const *)p
->reasons
);
210 ippAddInteger(history
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
211 "printer-state-change-time", p
->state_time
);
212 ippAddInteger(history
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
213 "printer-state-sequence-number", p
->sequence_number
);
215 p
->history
[p
->num_history
] = history
;
221 * 'cupsdAddPrinterUser()' - Add a user to the ACL.
226 cupsd_printer_t
*p
, /* I - Printer */
227 const char *username
) /* I - User */
229 const char **temp
; /* Temporary array pointer */
235 if (p
->num_users
== 0)
236 temp
= malloc(sizeof(char **));
238 temp
= realloc(p
->users
, sizeof(char **) * (p
->num_users
+ 1));
244 temp
+= p
->num_users
;
246 if ((*temp
= strdup(username
)) != NULL
)
252 * 'cupsdCreateCommonData()' - Create the common printer data.
256 cupsdCreateCommonData(void)
258 int i
; /* Looping var */
259 ipp_attribute_t
*attr
; /* Attribute data */
260 static const int nups
[] = /* number-up-supported values */
261 { 1, 2, 4, 6, 9, 16 };
262 static const ipp_orient_t orients
[4] =/* orientation-requested-supported values */
266 IPP_REVERSE_LANDSCAPE
,
269 static const char * const holds
[] = /* job-hold-until-supported values */
280 static const char * const versions
[] =/* ipp-versions-supported values */
285 static const ipp_op_t ops
[] = /* operations-supported values */
292 IPP_GET_JOB_ATTRIBUTES
,
294 IPP_GET_PRINTER_ATTRIBUTES
,
300 IPP_SET_JOB_ATTRIBUTES
,
301 IPP_CREATE_PRINTER_SUBSCRIPTION
,
302 IPP_CREATE_JOB_SUBSCRIPTION
,
303 IPP_GET_SUBSCRIPTION_ATTRIBUTES
,
304 IPP_GET_SUBSCRIPTIONS
,
305 IPP_RENEW_SUBSCRIPTION
,
306 IPP_CANCEL_SUBSCRIPTION
,
307 IPP_GET_NOTIFICATIONS
,
323 CUPS_AUTHENTICATE_JOB
,
326 static const char * const charsets
[] =/* charset-supported values */
331 static const char * const compressions
[] =
332 { /* document-compression-supported values */
336 #endif /* HAVE_LIBZ */
338 static const char * const multiple_document_handling
[] =
339 { /* multiple-document-handling-supported values */
340 "separate-documents-uncollated-copies",
341 "separate-documents-collated-copies"
343 static const char * const errors
[] = /* printer-error-policy-supported values */
349 static const char * const notify_attrs
[] =
350 { /* notify-attributes-supported values */
351 "printer-state-change-time",
352 "notify-lease-expiration-time",
353 "notify-subscriber-user-name"
355 static const char * const notify_events
[] =
356 { /* notify-events-supported values */
358 "job-config-changed",
365 "printer-config-changed",
367 "printer-finishings-changed",
368 "printer-media-changed",
372 "printer-state-changed",
382 ippDelete(CommonData
);
384 CommonData
= ippNew();
387 * This list of attributes is sorted to improve performance when the
388 * client provides a requested-attributes attribute...
391 /* charset-configured */
392 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_CHARSET
,
393 "charset-configured", NULL
, DefaultCharset
);
395 /* charset-supported */
396 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_CHARSET
,
397 "charset-supported", sizeof(charsets
) / sizeof(charsets
[0]),
400 /* compression-supported */
401 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
402 "compression-supported",
403 sizeof(compressions
) / sizeof(compressions
[0]),
406 /* copies-supported */
407 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "copies-supported", 1, MaxCopies
);
409 /* document-format-default */
410 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_MIMETYPE
,
411 "document-format-default", NULL
, "application/octet-stream");
413 /* generated-natural-language-supported */
414 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_LANGUAGE
,
415 "generated-natural-language-supported", NULL
, DefaultLanguage
);
417 /* ipp-versions-supported */
418 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
419 "ipp-versions-supported", sizeof(versions
) / sizeof(versions
[0]),
422 /* job-hold-until-supported */
423 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
424 "job-hold-until-supported", sizeof(holds
) / sizeof(holds
[0]),
427 /* job-priority-supported */
428 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
429 "job-priority-supported", 100);
431 /* job-sheets-supported */
432 if (cupsArrayCount(Banners
) > 0)
435 * Setup the job-sheets-supported attribute...
438 if (Classification
&& !ClassifyOverride
)
439 attr
= ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
440 "job-sheets-supported", NULL
, Classification
);
442 attr
= ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
443 "job-sheets-supported", cupsArrayCount(Banners
) + 1,
447 cupsdLogMessage(CUPSD_LOG_EMERG
,
448 "Unable to allocate memory for "
449 "job-sheets-supported attribute: %s!", strerror(errno
));
450 else if (!Classification
|| ClassifyOverride
)
452 cupsd_banner_t
*banner
; /* Current banner */
455 attr
->values
[0].string
.text
= _cupsStrAlloc("none");
457 for (i
= 1, banner
= (cupsd_banner_t
*)cupsArrayFirst(Banners
);
459 i
++, banner
= (cupsd_banner_t
*)cupsArrayNext(Banners
))
460 attr
->values
[i
].string
.text
= _cupsStrAlloc(banner
->name
);
464 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
465 "job-sheets-supported", NULL
, "none");
467 /* multiple-document-handling-supported */
468 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
469 "multiple-document-handling-supported",
470 sizeof(multiple_document_handling
) /
471 sizeof(multiple_document_handling
[0]), NULL
,
472 multiple_document_handling
);
474 /* multiple-document-jobs-supported */
475 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
,
476 "multiple-document-jobs-supported", 1);
478 /* multiple-operation-time-out */
479 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
480 "multiple-operation-time-out", 60);
482 /* natural-language-configured */
483 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_LANGUAGE
,
484 "natural-language-configured", NULL
, DefaultLanguage
);
486 /* notify-attributes-supported */
487 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
488 "notify-attributes-supported",
489 (int)(sizeof(notify_attrs
) / sizeof(notify_attrs
[0])),
492 /* notify-lease-duration-default */
493 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
494 "notify-lease-duration-default", DefaultLeaseDuration
);
496 /* notify-lease-duration-supported */
497 ippAddRange(CommonData
, IPP_TAG_PRINTER
,
498 "notify-lease-duration-supported", 0,
499 MaxLeaseDuration
? MaxLeaseDuration
: 2147483647);
501 /* notify-max-events-supported */
502 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
503 "notify-max-events-supported", MaxEvents
);
505 /* notify-notify-events-default */
506 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
507 "notify-events-default", NULL
, "job-completed");
509 /* notify-notify-events-supported */
510 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
511 "notify-events-supported",
512 (int)(sizeof(notify_events
) / sizeof(notify_events
[0])),
513 NULL
, notify_events
);
515 /* notify-pull-method-supported */
516 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
517 "notify-pull-method-supported", NULL
, "ippget");
519 /* TODO: scan notifier directory */
520 /* notify-schemes-supported */
521 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
522 "notify-schemes-supported", NULL
, "mailto");
524 /* number-up-supported */
525 ippAddIntegers(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
526 "number-up-supported", sizeof(nups
) / sizeof(nups
[0]), nups
);
528 /* operations-supported */
529 ippAddIntegers(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
530 "operations-supported",
531 sizeof(ops
) / sizeof(ops
[0]) + JobFiles
- 1, (int *)ops
);
533 /* orientation-requested-supported */
534 ippAddIntegers(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
535 "orientation-requested-supported", 4, (int *)orients
);
537 /* page-ranges-supported */
538 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
, "page-ranges-supported", 1);
540 /* pdf-override-supported */
541 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
542 "pdl-override-supported", NULL
, "not-attempted");
544 /* printer-error-policy-supported */
545 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
546 "printer-error-policy-supported",
547 sizeof(errors
) / sizeof(errors
[0]), NULL
, errors
);
549 /* printer-op-policy-supported */
550 attr
= ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
551 "printer-op-policy-supported", NumPolicies
, NULL
, NULL
);
552 for (i
= 0; i
< NumPolicies
; i
++)
553 attr
->values
[i
].string
.text
= _cupsStrAlloc(Policies
[i
]->name
);
558 * 'cupsdDeleteAllPrinters()' - Delete all printers from the system.
562 cupsdDeleteAllPrinters(void)
564 cupsd_printer_t
*p
; /* Pointer to current printer/class */
567 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
569 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
570 if (!(p
->type
& CUPS_PRINTER_CLASS
))
571 cupsdDeletePrinter(p
, 0);
576 * 'cupsdDeletePrinter()' - Delete a printer from the system.
581 cupsd_printer_t
*p
, /* I - Printer to delete */
582 int update
) /* I - Update printers.conf? */
584 int i
; /* Looping var */
586 char filename
[1024]; /* Interface script filename */
590 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdDeletePrinter(p=%p(%s), update=%d)",
594 * Save the current position in the Printers array...
597 cupsArraySave(Printers
);
600 * Stop printing on this printer...
603 cupsdStopPrinter(p
, update
);
606 * If this printer is the next for browsing, point to the next one...
611 cupsArrayFind(Printers
, p
);
612 BrowseNext
= (cupsd_printer_t
*)cupsArrayNext(Printers
);
616 * Remove the printer from the list...
619 cupsArrayRemove(Printers
, p
);
622 * Remove the dummy interface/icon/option files under IRIX...
626 snprintf(filename
, sizeof(filename
), "/var/spool/lp/interface/%s", p
->name
);
629 snprintf(filename
, sizeof(filename
), "/var/spool/lp/gui_interface/ELF/%s.gui",
633 snprintf(filename
, sizeof(filename
), "/var/spool/lp/activeicons/%s", p
->name
);
636 snprintf(filename
, sizeof(filename
), "/var/spool/lp/pod/%s.config", p
->name
);
639 snprintf(filename
, sizeof(filename
), "/var/spool/lp/pod/%s.status", p
->name
);
642 snprintf(filename
, sizeof(filename
), "/var/spool/lp/member/%s", p
->name
);
647 * If p is the default printer, assign a different one...
650 if (p
== DefaultPrinter
)
652 DefaultPrinter
= NULL
;
654 if (UseNetworkDefault
)
657 * Find the first network default printer and use it...
660 cupsd_printer_t
*dp
; /* New default printer */
663 for (dp
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
665 dp
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
666 if (dp
!= p
&& (dp
->type
& CUPS_PRINTER_DEFAULT
))
675 * Remove this printer from any classes and send a browse delete message...
678 if (!(p
->type
& CUPS_PRINTER_IMPLICIT
))
680 cupsdDeletePrinterFromClasses(p
);
681 cupsdSendBrowseDelete(p
);
685 * Free all memory used by the printer...
688 if (p
->printers
!= NULL
)
691 if (MaxPrinterHistory
)
693 for (i
= 0; i
< p
->num_history
; i
++)
694 ippDelete(p
->history
[i
]);
699 for (i
= 0; i
< p
->num_reasons
; i
++)
704 delete_printer_filters(p
);
706 mimeDeleteType(MimeDatabase
, p
->filetype
);
708 cupsdFreePrinterUsers(p
);
711 cupsdClearString(&p
->uri
);
712 cupsdClearString(&p
->hostname
);
713 cupsdClearString(&p
->name
);
714 cupsdClearString(&p
->location
);
715 cupsdClearString(&p
->make_model
);
716 cupsdClearString(&p
->info
);
717 cupsdClearString(&p
->job_sheets
[0]);
718 cupsdClearString(&p
->job_sheets
[1]);
719 cupsdClearString(&p
->device_uri
);
720 cupsdClearString(&p
->port_monitor
);
721 cupsdClearString(&p
->op_policy
);
722 cupsdClearString(&p
->error_policy
);
724 cupsArrayDelete(p
->filetypes
);
727 free(p
->browse_attrs
);
730 cupsdClearString(&p
->recoverable
);
731 #endif /* __APPLE__ */
733 cupsFreeOptions(p
->num_options
, p
->options
);
738 * Restore the previous position in the Printers array...
741 cupsArrayRestore(Printers
);
746 * 'cupsdFindDest()' - Find a destination in the list.
749 cupsd_printer_t
* /* O - Destination in list */
750 cupsdFindDest(const char *name
) /* I - Name of printer or class to find */
752 cupsd_printer_t key
; /* Search key */
755 key
.name
= (char *)name
;
756 return ((cupsd_printer_t
*)cupsArrayFind(Printers
, &key
));
761 * 'cupsdFindPrinter()' - Find a printer in the list.
764 cupsd_printer_t
* /* O - Printer in list */
765 cupsdFindPrinter(const char *name
) /* I - Name of printer to find */
767 cupsd_printer_t
*p
; /* Printer in list */
770 if ((p
= cupsdFindDest(name
)) != NULL
&& (p
->type
& CUPS_PRINTER_CLASS
))
778 * 'cupsdFreePrinterUsers()' - Free allow/deny users.
782 cupsdFreePrinterUsers(
783 cupsd_printer_t
*p
) /* I - Printer */
785 int i
; /* Looping var */
788 if (!p
|| !p
->num_users
)
791 for (i
= 0; i
< p
->num_users
; i
++)
792 free((void *)p
->users
[i
]);
802 * 'cupsdLoadAllPrinters()' - Load printers from the printers.conf file.
806 cupsdLoadAllPrinters(void)
808 cups_file_t
*fp
; /* printers.conf file */
809 int linenum
; /* Current line number */
810 char line
[1024], /* Line from file */
811 *value
, /* Pointer to value */
812 *valueptr
; /* Pointer into value */
813 cupsd_printer_t
*p
; /* Current printer */
817 * Open the printers.conf file...
820 snprintf(line
, sizeof(line
), "%s/printers.conf", ServerRoot
);
821 if ((fp
= cupsFileOpen(line
, "r")) == NULL
)
824 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to open %s - %s", line
,
830 * Read printer configurations until we hit EOF...
836 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
839 * Decode the directive...
842 if (!strcasecmp(line
, "<Printer") ||
843 !strcasecmp(line
, "<DefaultPrinter"))
846 * <Printer name> or <DefaultPrinter name>
849 if (p
== NULL
&& value
)
852 * Add the printer and a base file type...
855 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Loading printer %s...", value
);
857 p
= cupsdAddPrinter(value
);
859 p
->state
= IPP_PRINTER_IDLE
;
862 * Set the default printer as needed...
865 if (!strcasecmp(line
, "<DefaultPrinter"))
870 cupsdLogMessage(CUPSD_LOG_ERROR
,
871 "Syntax error on line %d of printers.conf.", linenum
);
875 else if (!strcasecmp(line
, "</Printer>"))
880 * Close out the current printer...
883 cupsdSetPrinterAttrs(p
);
884 cupsdAddPrinterHistory(p
);
886 if (p
->device_uri
&& strncmp(p
->device_uri
, "file:", 5) &&
887 p
->state
!= IPP_PRINTER_STOPPED
)
890 * See if the backend exists...
893 snprintf(line
, sizeof(line
), "%s/backend/%s", ServerBin
,
896 if ((valueptr
= strchr(line
+ strlen(ServerBin
), ':')) != NULL
)
897 *valueptr
= '\0'; /* Chop everything but URI scheme */
902 * Backend does not exist, stop printer...
905 p
->state
= IPP_PRINTER_STOPPED
;
906 snprintf(p
->state_message
, sizeof(p
->state_message
),
907 "Backend %s does not exist!", line
);
915 cupsdLogMessage(CUPSD_LOG_ERROR
,
916 "Syntax error on line %d of printers.conf.", linenum
);
922 cupsdLogMessage(CUPSD_LOG_ERROR
,
923 "Syntax error on line %d of printers.conf.", linenum
);
926 else if (!strcasecmp(line
, "Info"))
929 cupsdSetString(&p
->info
, value
);
931 else if (!strcasecmp(line
, "Location"))
934 cupsdSetString(&p
->location
, value
);
936 else if (!strcasecmp(line
, "DeviceURI"))
939 cupsdSetString(&p
->device_uri
, value
);
942 cupsdLogMessage(CUPSD_LOG_ERROR
,
943 "Syntax error on line %d of printers.conf.", linenum
);
947 else if (!strcasecmp(line
, "Option") && value
)
953 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
956 cupsdLogMessage(CUPSD_LOG_ERROR
,
957 "Syntax error on line %d of printers.conf.", linenum
);
960 for (; *valueptr
&& isspace(*valueptr
& 255); *valueptr
++ = '\0');
962 p
->num_options
= cupsAddOption(value
, valueptr
, p
->num_options
,
966 else if (!strcasecmp(line
, "PortMonitor"))
968 if (value
&& strcmp(value
, "none"))
969 cupsdSetString(&p
->port_monitor
, value
);
971 cupsdClearString(&p
->port_monitor
);
974 cupsdLogMessage(CUPSD_LOG_ERROR
,
975 "Syntax error on line %d of printers.conf.", linenum
);
979 else if (!strcasecmp(line
, "State"))
982 * Set the initial queue state...
985 if (value
&& !strcasecmp(value
, "idle"))
986 p
->state
= IPP_PRINTER_IDLE
;
987 else if (value
&& !strcasecmp(value
, "stopped"))
988 p
->state
= IPP_PRINTER_STOPPED
;
991 cupsdLogMessage(CUPSD_LOG_ERROR
,
992 "Syntax error on line %d of printers.conf.", linenum
);
996 else if (!strcasecmp(line
, "StateMessage"))
999 * Set the initial queue state message...
1003 strlcpy(p
->state_message
, value
, sizeof(p
->state_message
));
1005 else if (!strcasecmp(line
, "StateTime"))
1008 * Set the state time...
1012 p
->state_time
= atoi(value
);
1014 else if (!strcasecmp(line
, "Accepting"))
1017 * Set the initial accepting state...
1021 (!strcasecmp(value
, "yes") ||
1022 !strcasecmp(value
, "on") ||
1023 !strcasecmp(value
, "true")))
1026 (!strcasecmp(value
, "no") ||
1027 !strcasecmp(value
, "off") ||
1028 !strcasecmp(value
, "false")))
1032 cupsdLogMessage(CUPSD_LOG_ERROR
,
1033 "Syntax error on line %d of printers.conf.", linenum
);
1037 else if (!strcasecmp(line
, "Shared"))
1040 * Set the initial shared state...
1044 (!strcasecmp(value
, "yes") ||
1045 !strcasecmp(value
, "on") ||
1046 !strcasecmp(value
, "true")))
1049 (!strcasecmp(value
, "no") ||
1050 !strcasecmp(value
, "off") ||
1051 !strcasecmp(value
, "false")))
1055 cupsdLogMessage(CUPSD_LOG_ERROR
,
1056 "Syntax error on line %d of printers.conf.", linenum
);
1060 else if (!strcasecmp(line
, "JobSheets"))
1063 * Set the initial job sheets...
1068 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1073 cupsdSetString(&p
->job_sheets
[0], value
);
1075 while (isspace(*valueptr
& 255))
1080 for (value
= valueptr
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1085 cupsdSetString(&p
->job_sheets
[1], value
);
1090 cupsdLogMessage(CUPSD_LOG_ERROR
,
1091 "Syntax error on line %d of printers.conf.", linenum
);
1095 else if (!strcasecmp(line
, "AllowUser"))
1100 cupsdAddPrinterUser(p
, value
);
1104 cupsdLogMessage(CUPSD_LOG_ERROR
,
1105 "Syntax error on line %d of printers.conf.", linenum
);
1109 else if (!strcasecmp(line
, "DenyUser"))
1114 cupsdAddPrinterUser(p
, value
);
1118 cupsdLogMessage(CUPSD_LOG_ERROR
,
1119 "Syntax error on line %d of printers.conf.", linenum
);
1123 else if (!strcasecmp(line
, "QuotaPeriod"))
1126 p
->quota_period
= atoi(value
);
1129 cupsdLogMessage(CUPSD_LOG_ERROR
,
1130 "Syntax error on line %d of printers.conf.", linenum
);
1134 else if (!strcasecmp(line
, "PageLimit"))
1137 p
->page_limit
= atoi(value
);
1140 cupsdLogMessage(CUPSD_LOG_ERROR
,
1141 "Syntax error on line %d of printers.conf.", linenum
);
1145 else if (!strcasecmp(line
, "KLimit"))
1148 p
->k_limit
= atoi(value
);
1151 cupsdLogMessage(CUPSD_LOG_ERROR
,
1152 "Syntax error on line %d of printers.conf.", linenum
);
1156 else if (!strcasecmp(line
, "OpPolicy"))
1159 cupsdSetString(&p
->op_policy
, value
);
1162 cupsdLogMessage(CUPSD_LOG_ERROR
,
1163 "Syntax error on line %d of printers.conf.", linenum
);
1167 else if (!strcasecmp(line
, "ErrorPolicy"))
1170 cupsdSetString(&p
->error_policy
, value
);
1173 cupsdLogMessage(CUPSD_LOG_ERROR
,
1174 "Syntax error on line %d of printers.conf.", linenum
);
1181 * Something else we don't understand...
1184 cupsdLogMessage(CUPSD_LOG_ERROR
,
1185 "Unknown configuration directive %s on line %d of printers.conf.",
1195 * 'cupsdRenamePrinter()' - Rename a printer.
1200 cupsd_printer_t
*p
, /* I - Printer */
1201 const char *name
) /* I - New name */
1204 * Remove the printer from the array(s) first...
1207 cupsArrayRemove(Printers
, p
);
1209 if (p
->type
& CUPS_PRINTER_IMPLICIT
)
1210 cupsArrayRemove(ImplicitPrinters
, p
);
1213 * Rename the printer type...
1216 mimeDeleteType(MimeDatabase
, p
->filetype
);
1217 p
->filetype
= mimeAddType(MimeDatabase
, "printer", name
);
1220 * Rename the printer...
1223 cupsdSetStringf(&p
->name
, name
);
1226 * Reset printer attributes...
1229 cupsdSetPrinterAttrs(p
);
1232 * Add the printer back to the printer array(s)...
1235 cupsArrayAdd(Printers
, p
);
1236 if (p
->type
& CUPS_PRINTER_IMPLICIT
)
1237 cupsArrayAdd(ImplicitPrinters
, p
);
1242 * 'cupsdSaveAllPrinters()' - Save all printer definitions to the printers.conf
1247 cupsdSaveAllPrinters(void)
1249 int i
; /* Looping var */
1250 cups_file_t
*fp
; /* printers.conf file */
1251 char temp
[1024]; /* Temporary string */
1252 char backup
[1024]; /* printers.conf.O file */
1253 cupsd_printer_t
*printer
; /* Current printer class */
1254 time_t curtime
; /* Current time */
1255 struct tm
*curdate
; /* Current date */
1256 cups_option_t
*option
; /* Current option */
1260 * Create the printers.conf file...
1263 snprintf(temp
, sizeof(temp
), "%s/printers.conf", ServerRoot
);
1264 snprintf(backup
, sizeof(backup
), "%s/printers.conf.O", ServerRoot
);
1266 if (rename(temp
, backup
))
1268 if (errno
!= ENOENT
)
1269 cupsdLogMessage(CUPSD_LOG_ERROR
,
1270 "Unable to backup printers.conf - %s", strerror(errno
));
1273 if ((fp
= cupsFileOpen(temp
, "w")) == NULL
)
1275 cupsdLogMessage(CUPSD_LOG_ERROR
,
1276 "Unable to save printers.conf - %s", strerror(errno
));
1278 if (rename(backup
, temp
))
1279 cupsdLogMessage(CUPSD_LOG_ERROR
,
1280 "Unable to restore printers.conf - %s", strerror(errno
));
1284 cupsdLogMessage(CUPSD_LOG_INFO
, "Saving printers.conf...");
1287 * Restrict access to the file...
1290 fchown(cupsFileNumber(fp
), getuid(), Group
);
1291 fchmod(cupsFileNumber(fp
), 0600);
1294 * Write a small header to the file...
1297 curtime
= time(NULL
);
1298 curdate
= localtime(&curtime
);
1299 strftime(temp
, sizeof(temp
) - 1, "%Y-%m-%d %H:%M", curdate
);
1301 cupsFilePuts(fp
, "# Printer configuration file for " CUPS_SVERSION
"\n");
1302 cupsFilePrintf(fp
, "# Written by cupsd on %s\n", temp
);
1305 * Write each local printer known to the system...
1308 for (printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
1310 printer
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
1313 * Skip remote destinations and printer classes...
1316 if ((printer
->type
& CUPS_PRINTER_REMOTE
) ||
1317 (printer
->type
& CUPS_PRINTER_CLASS
) ||
1318 (printer
->type
& CUPS_PRINTER_IMPLICIT
))
1322 * Write printers as needed...
1325 if (printer
== DefaultPrinter
)
1326 cupsFilePrintf(fp
, "<DefaultPrinter %s>\n", printer
->name
);
1328 cupsFilePrintf(fp
, "<Printer %s>\n", printer
->name
);
1331 cupsFilePrintf(fp
, "Info %s\n", printer
->info
);
1333 if (printer
->location
)
1334 cupsFilePrintf(fp
, "Location %s\n", printer
->location
);
1336 if (printer
->device_uri
)
1337 cupsFilePrintf(fp
, "DeviceURI %s\n", printer
->device_uri
);
1339 if (printer
->port_monitor
)
1340 cupsFilePrintf(fp
, "PortMonitor %s\n", printer
->port_monitor
);
1342 if (printer
->state
== IPP_PRINTER_STOPPED
)
1344 cupsFilePuts(fp
, "State Stopped\n");
1345 cupsFilePrintf(fp
, "StateMessage %s\n", printer
->state_message
);
1348 cupsFilePuts(fp
, "State Idle\n");
1350 cupsFilePrintf(fp
, "StateTime %d\n", (int)printer
->state_time
);
1352 if (printer
->accepting
)
1353 cupsFilePuts(fp
, "Accepting Yes\n");
1355 cupsFilePuts(fp
, "Accepting No\n");
1357 if (printer
->shared
)
1358 cupsFilePuts(fp
, "Shared Yes\n");
1360 cupsFilePuts(fp
, "Shared No\n");
1362 cupsFilePrintf(fp
, "JobSheets %s %s\n", printer
->job_sheets
[0],
1363 printer
->job_sheets
[1]);
1365 cupsFilePrintf(fp
, "QuotaPeriod %d\n", printer
->quota_period
);
1366 cupsFilePrintf(fp
, "PageLimit %d\n", printer
->page_limit
);
1367 cupsFilePrintf(fp
, "KLimit %d\n", printer
->k_limit
);
1369 for (i
= 0; i
< printer
->num_users
; i
++)
1370 cupsFilePrintf(fp
, "%sUser %s\n", printer
->deny_users
? "Deny" : "Allow",
1373 if (printer
->op_policy
)
1374 cupsFilePrintf(fp
, "OpPolicy %s\n", printer
->op_policy
);
1375 if (printer
->error_policy
)
1376 cupsFilePrintf(fp
, "ErrorPolicy %s\n", printer
->error_policy
);
1378 for (i
= printer
->num_options
, option
= printer
->options
;
1381 cupsFilePrintf(fp
, "Option %s %s\n", option
->name
, option
->value
);
1383 cupsFilePuts(fp
, "</Printer>\n");
1387 * Make IRIX desktop & printer status happy
1390 write_irix_state(printer
);
1399 * 'cupsdSetPrinterAttrs()' - Set printer attributes based upon the PPD file.
1403 cupsdSetPrinterAttrs(cupsd_printer_t
*p
)/* I - Printer to setup */
1405 int i
, /* Looping var */
1406 length
; /* Length of browse attributes */
1407 char uri
[HTTP_MAX_URI
]; /* URI for printer */
1408 char resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
1409 char filename
[1024]; /* Name of PPD file */
1410 int num_media
; /* Number of media options */
1411 cupsd_location_t
*auth
; /* Pointer to authentication element */
1412 const char *auth_supported
; /* Authentication supported */
1413 cups_ptype_t printer_type
; /* Printer type data */
1414 ppd_file_t
*ppd
; /* PPD file data */
1415 ppd_option_t
*input_slot
, /* InputSlot options */
1416 *media_type
, /* MediaType options */
1417 *page_size
, /* PageSize options */
1418 *output_bin
, /* OutputBin options */
1419 *media_quality
, /* EFMediaQualityMode options */
1420 *duplex
; /* Duplex options */
1421 ppd_attr_t
*ppdattr
; /* PPD attribute */
1422 ipp_attribute_t
*attr
; /* Attribute data */
1423 ipp_value_t
*val
; /* Attribute value */
1424 int num_finishings
; /* Number of finishings */
1425 ipp_finish_t finishings
[5]; /* finishings-supported values */
1426 cups_option_t
*option
; /* Current printer option */
1427 static const char * const sides
[3] = /* sides-supported values */
1430 "two-sided-long-edge",
1431 "two-sided-short-edge"
1435 DEBUG_printf(("cupsdSetPrinterAttrs: entering name = %s, type = %x\n", p
->name
,
1439 * Make sure that we have the common attributes defined...
1443 cupsdCreateCommonData();
1446 * Clear out old filters, if any...
1449 delete_printer_filters(p
);
1452 * Figure out the authentication that is required for the printer.
1455 auth_supported
= "requesting-user-name";
1456 if (!(p
->type
& CUPS_PRINTER_REMOTE
))
1458 if (p
->type
& CUPS_PRINTER_CLASS
)
1459 snprintf(resource
, sizeof(resource
), "/classes/%s", p
->name
);
1461 snprintf(resource
, sizeof(resource
), "/printers/%s", p
->name
);
1463 if ((auth
= cupsdFindBest(resource
, HTTP_POST
)) == NULL
)
1464 auth
= cupsdFindPolicyOp(p
->op_policy_ptr
, IPP_PRINT_JOB
);
1468 if (auth
->type
== AUTH_BASIC
|| auth
->type
== AUTH_BASICDIGEST
)
1469 auth_supported
= "basic";
1470 else if (auth
->type
== AUTH_DIGEST
)
1471 auth_supported
= "digest";
1473 if (auth
->type
!= AUTH_NONE
)
1474 p
->type
|= CUPS_PRINTER_AUTHENTICATED
;
1476 p
->type
&= ~CUPS_PRINTER_AUTHENTICATED
;
1479 p
->type
&= ~CUPS_PRINTER_AUTHENTICATED
;
1483 * Create the required IPP attributes for a printer...
1487 ippDelete(p
->attrs
);
1489 p
->attrs
= ippNew();
1491 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
1492 "uri-authentication-supported", NULL
, auth_supported
);
1493 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
1494 "uri-security-supported", NULL
, "none");
1495 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
, "printer-name", NULL
,
1497 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-location",
1498 NULL
, p
->location
? p
->location
: "");
1499 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-info",
1500 NULL
, p
->info
? p
->info
: "");
1501 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "printer-more-info",
1507 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
1508 "requesting-user-name-denied", p
->num_users
, NULL
,
1511 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
1512 "requesting-user-name-allowed", p
->num_users
, NULL
,
1516 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
1517 "job-quota-period", p
->quota_period
);
1518 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
1519 "job-k-limit", p
->k_limit
);
1520 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
1521 "job-page-limit", p
->page_limit
);
1523 if (cupsArrayCount(Banners
) > 0 && !(p
->type
& CUPS_PRINTER_REMOTE
))
1526 * Setup the job-sheets-default attribute...
1529 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
1530 "job-sheets-default", 2, NULL
, NULL
);
1534 attr
->values
[0].string
.text
= _cupsStrAlloc(Classification
?
1535 Classification
: p
->job_sheets
[0]);
1536 attr
->values
[1].string
.text
= _cupsStrAlloc(Classification
?
1537 Classification
: p
->job_sheets
[1]);
1541 printer_type
= p
->type
;
1545 if (p
->type
& CUPS_PRINTER_REMOTE
)
1548 * Tell the client this is a remote printer of some type...
1551 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
1552 "printer-uri-supported", NULL
, p
->uri
);
1555 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
1556 "printer-make-and-model", NULL
, p
->make_model
);
1558 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "device-uri", NULL
,
1566 * Assign additional attributes depending on whether this is a printer
1570 p
->type
&= ~CUPS_PRINTER_OPTIONS
;
1572 if (p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
))
1577 * Add class-specific attributes...
1580 if ((p
->type
& CUPS_PRINTER_IMPLICIT
) && p
->num_printers
> 0 &&
1581 p
->printers
[0]->make_model
)
1582 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
1583 "printer-make-and-model", NULL
, p
->printers
[0]->make_model
);
1585 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
1586 "printer-make-and-model", NULL
, "Local Printer Class");
1588 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "device-uri", NULL
,
1589 "file:///dev/null");
1591 if (p
->num_printers
> 0)
1594 * Add a list of member URIs and names...
1597 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
1598 "member-uris", p
->num_printers
, NULL
, NULL
);
1599 p
->type
|= CUPS_PRINTER_OPTIONS
;
1601 for (i
= 0; i
< p
->num_printers
; i
++)
1604 attr
->values
[i
].string
.text
= _cupsStrAlloc(p
->printers
[i
]->uri
);
1606 p
->type
&= ~CUPS_PRINTER_OPTIONS
| p
->printers
[i
]->type
;
1609 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
1610 "member-names", p
->num_printers
, NULL
, NULL
);
1614 for (i
= 0; i
< p
->num_printers
; i
++)
1615 attr
->values
[i
].string
.text
= _cupsStrAlloc(p
->printers
[i
]->name
);
1622 * Add printer-specific attributes... Start by sanitizing the device
1623 * URI so it doesn't have a username or password in it...
1627 strcpy(uri
, "file:/dev/null");
1628 else if (strstr(p
->device_uri
, "://") != NULL
)
1631 * http://..., ipp://..., etc.
1634 cupsdSanitizeURI(p
->device_uri
, uri
, sizeof(uri
));
1639 * file:..., serial:..., etc.
1642 strlcpy(uri
, p
->device_uri
, sizeof(uri
));
1645 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "device-uri", NULL
,
1649 * Assign additional attributes from the PPD file (if any)...
1652 p
->type
|= CUPS_PRINTER_BW
;
1653 finishings
[0] = IPP_FINISHINGS_NONE
;
1656 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
1659 if ((ppd
= ppdOpenFile(filename
)) != NULL
)
1662 * Add make/model and other various attributes...
1665 if (ppd
->color_device
)
1666 p
->type
|= CUPS_PRINTER_COLOR
;
1667 if (ppd
->variable_sizes
)
1668 p
->type
|= CUPS_PRINTER_VARIABLE
;
1669 if (!ppd
->manual_copies
)
1670 p
->type
|= CUPS_PRINTER_COPIES
;
1671 if ((ppdattr
= ppdFindAttr(ppd
, "cupsFax", NULL
)) != NULL
)
1672 if (ppdattr
->value
&& !strcasecmp(ppdattr
->value
, "true"))
1673 p
->type
|= CUPS_PRINTER_FAX
;
1675 ippAddBoolean(p
->attrs
, IPP_TAG_PRINTER
, "color-supported",
1677 if (ppd
->throughput
)
1678 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
1679 "pages-per-minute", ppd
->throughput
);
1684 * The NickName can be localized in the character set specified
1685 * by the LanugageEncoding attribute. However, ppdOpen2() has
1686 * already converted the ppd->nickname member to UTF-8 for us
1687 * (the original attribute value is available separately)
1690 cupsdSetString(&p
->make_model
, ppd
->nickname
);
1692 else if (ppd
->modelname
)
1695 * Model name can only contain specific characters...
1698 cupsdSetString(&p
->make_model
, ppd
->modelname
);
1701 cupsdSetString(&p
->make_model
, "Bad PPD File");
1703 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
1704 "printer-make-and-model", NULL
, p
->make_model
);
1707 * Add media options from the PPD file...
1710 if ((input_slot
= ppdFindOption(ppd
, "InputSlot")) != NULL
)
1711 num_media
= input_slot
->num_choices
;
1715 if ((media_type
= ppdFindOption(ppd
, "MediaType")) != NULL
)
1716 num_media
+= media_type
->num_choices
;
1718 if ((page_size
= ppdFindOption(ppd
, "PageSize")) != NULL
)
1719 num_media
+= page_size
->num_choices
;
1721 if ((media_quality
= ppdFindOption(ppd
, "EFMediaQualityMode")) != NULL
)
1722 num_media
+= media_quality
->num_choices
;
1726 cupsdLogMessage(CUPSD_LOG_CRIT
,
1727 "The PPD file for printer %s contains no media "
1728 "options and is therefore invalid!", p
->name
);
1732 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
1733 "media-supported", num_media
, NULL
, NULL
);
1738 if (input_slot
!= NULL
)
1739 for (i
= 0; i
< input_slot
->num_choices
; i
++, val
++)
1740 val
->string
.text
= _cupsStrAlloc(input_slot
->choices
[i
].choice
);
1742 if (media_type
!= NULL
)
1743 for (i
= 0; i
< media_type
->num_choices
; i
++, val
++)
1744 val
->string
.text
= _cupsStrAlloc(media_type
->choices
[i
].choice
);
1746 if (media_quality
!= NULL
)
1747 for (i
= 0; i
< media_quality
->num_choices
; i
++, val
++)
1748 val
->string
.text
= _cupsStrAlloc(media_quality
->choices
[i
].choice
);
1750 if (page_size
!= NULL
)
1752 for (i
= 0; i
< page_size
->num_choices
; i
++, val
++)
1753 val
->string
.text
= _cupsStrAlloc(page_size
->choices
[i
].choice
);
1755 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
1756 "media-default", NULL
, page_size
->defchoice
);
1758 else if (input_slot
!= NULL
)
1759 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
1760 "media-default", NULL
, input_slot
->defchoice
);
1761 else if (media_type
!= NULL
)
1762 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
1763 "media-default", NULL
, media_type
->defchoice
);
1764 else if (media_quality
!= NULL
)
1765 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
1766 "media-default", NULL
, media_quality
->defchoice
);
1768 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
1769 "media-default", NULL
, "none");
1777 if ((output_bin
= ppdFindOption(ppd
, "OutputBin")) != NULL
)
1779 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
1780 "output-bin-supported", output_bin
->num_choices
,
1785 for (i
= 0, val
= attr
->values
;
1786 i
< output_bin
->num_choices
;
1788 val
->string
.text
= _cupsStrAlloc(output_bin
->choices
[i
].choice
);
1796 if ((duplex
= ppdFindOption(ppd
, "Duplex")) == NULL
)
1797 if ((duplex
= ppdFindOption(ppd
, "EFDuplex")) == NULL
)
1798 if ((duplex
= ppdFindOption(ppd
, "EFDuplexing")) == NULL
)
1799 if ((duplex
= ppdFindOption(ppd
, "KD03Duplex")) == NULL
)
1800 duplex
= ppdFindOption(ppd
, "JCLDuplex");
1802 if (duplex
&& duplex
->num_choices
> 1)
1804 p
->type
|= CUPS_PRINTER_DUPLEX
;
1806 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
1807 "sides-supported", 3, NULL
, sides
);
1809 if (!strcasecmp(duplex
->defchoice
, "DuplexTumble"))
1810 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
1811 "sides-default", NULL
, "two-sided-short-edge");
1812 else if (!strcasecmp(duplex
->defchoice
, "DuplexNoTumble"))
1813 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
1814 "sides-default", NULL
, "two-sided-long-edge");
1816 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
1817 "sides-default", NULL
, "one-sided");
1820 if (ppdFindOption(ppd
, "Collate") != NULL
)
1821 p
->type
|= CUPS_PRINTER_COLLATE
;
1823 if (ppdFindOption(ppd
, "StapleLocation") != NULL
)
1825 p
->type
|= CUPS_PRINTER_STAPLE
;
1826 finishings
[num_finishings
++] = IPP_FINISHINGS_STAPLE
;
1829 if (ppdFindOption(ppd
, "BindEdge") != NULL
)
1831 p
->type
|= CUPS_PRINTER_BIND
;
1832 finishings
[num_finishings
++] = IPP_FINISHINGS_BIND
;
1835 for (i
= 0; i
< ppd
->num_sizes
; i
++)
1836 if (ppd
->sizes
[i
].length
> 1728)
1837 p
->type
|= CUPS_PRINTER_LARGE
;
1838 else if (ppd
->sizes
[i
].length
> 1008)
1839 p
->type
|= CUPS_PRINTER_MEDIUM
;
1841 p
->type
|= CUPS_PRINTER_SMALL
;
1844 * Add a filter from application/vnd.cups-raw to printer/name to
1845 * handle "raw" printing by users.
1848 add_printer_filter(p
, "application/vnd.cups-raw 0 -");
1851 * Add any filters in the PPD file...
1854 DEBUG_printf(("ppd->num_filters = %d\n", ppd
->num_filters
));
1855 for (i
= 0; i
< ppd
->num_filters
; i
++)
1857 DEBUG_printf(("ppd->filters[%d] = \"%s\"\n", i
, ppd
->filters
[i
]));
1858 add_printer_filter(p
, ppd
->filters
[i
]);
1861 if (ppd
->num_filters
== 0)
1864 * If there are no filters, add a PostScript printing filter.
1867 add_printer_filter(p
, "application/vnd.cups-postscript 0 -");
1871 * Show current and available port monitors for this printer...
1874 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
, "port-monitor",
1875 NULL
, p
->port_monitor
? p
->port_monitor
: "none");
1878 for (i
= 1, ppdattr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
1880 i
++, ppdattr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
));
1884 if (strstr(ppd
->protocols
, "TBCP"))
1886 else if (strstr(ppd
->protocols
, "BCP"))
1890 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
1891 "port-monitor-supported", i
, NULL
, NULL
);
1893 attr
->values
[0].string
.text
= _cupsStrAlloc("none");
1895 for (i
= 1, ppdattr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
1897 i
++, ppdattr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
))
1898 attr
->values
[i
].string
.text
= _cupsStrAlloc(ppdattr
->value
);
1902 if (strstr(ppd
->protocols
, "TBCP"))
1903 attr
->values
[i
].string
.text
= _cupsStrAlloc("tbcp");
1904 else if (strstr(ppd
->protocols
, "BCP"))
1905 attr
->values
[i
].string
.text
= _cupsStrAlloc("bcp");
1909 * Close the PPD and set the type...
1914 printer_type
= p
->type
;
1916 else if (!access(filename
, 0))
1918 int pline
; /* PPD line number */
1919 ppd_status_t pstatus
; /* PPD load status */
1922 pstatus
= ppdLastError(&pline
);
1924 cupsdLogMessage(CUPSD_LOG_ERROR
, "PPD file for %s cannot be loaded!",
1927 if (pstatus
<= PPD_ALLOC_ERROR
)
1928 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s", strerror(errno
));
1930 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s on line %d.",
1931 ppdErrorString(pstatus
), pline
);
1933 cupsdLogMessage(CUPSD_LOG_INFO
,
1934 "Hint: Run \"cupstestppd %s\" and fix any errors.",
1938 * Add a filter from application/vnd.cups-raw to printer/name to
1939 * handle "raw" printing by users.
1942 add_printer_filter(p
, "application/vnd.cups-raw 0 -");
1945 * Add a PostScript filter, since this is still possibly PS printer.
1948 add_printer_filter(p
, "application/vnd.cups-postscript 0 -");
1953 * If we have an interface script, add a filter entry for it...
1956 snprintf(filename
, sizeof(filename
), "%s/interfaces/%s", ServerRoot
,
1958 if (!access(filename
, X_OK
))
1961 * Yes, we have a System V style interface script; use it!
1964 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
1965 "printer-make-and-model", NULL
, "Local System V Printer");
1967 snprintf(filename
, sizeof(filename
), "*/* 0 %s/interfaces/%s",
1968 ServerRoot
, p
->name
);
1969 add_printer_filter(p
, filename
);
1971 else if (p
->device_uri
&&
1972 !strncmp(p
->device_uri
, "ipp://", 6) &&
1973 (strstr(p
->device_uri
, "/printers/") != NULL
||
1974 strstr(p
->device_uri
, "/classes/") != NULL
))
1977 * Tell the client this is really a hard-wired remote printer.
1980 printer_type
|= CUPS_PRINTER_REMOTE
;
1983 * Point the printer-uri-supported attribute to the
1987 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
1988 "printer-uri-supported", NULL
, p
->device_uri
);
1991 * Then set the make-and-model accordingly...
1994 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
1995 "printer-make-and-model", NULL
, "Remote Printer");
1998 * Print all files directly...
2006 * Otherwise we have neither - treat this as a "dumb" printer
2007 * with no PPD file...
2010 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
2011 "printer-make-and-model", NULL
, "Local Raw Printer");
2017 ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
2018 "finishings-supported", num_finishings
, (int *)finishings
);
2019 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
2020 "finishings-default", IPP_FINISHINGS_NONE
);
2025 * Copy the printer options into a browse attributes string we can re-use.
2028 if (!(p
->type
& CUPS_PRINTER_REMOTE
))
2030 const char *valptr
; /* Pointer into value */
2031 char *attrptr
; /* Pointer into attribute string */
2035 * Free the old browse attributes as needed...
2038 if (p
->browse_attrs
)
2039 free(p
->browse_attrs
);
2042 * Compute the length of all attributes + job-sheets, lease-duration,
2043 * and BrowseLocalOptions.
2046 for (length
= 1, i
= p
->num_options
, option
= p
->options
;
2050 length
+= strlen(option
->name
) + 2;
2054 for (valptr
= option
->value
; *valptr
; valptr
++)
2055 if (strchr(" \"\'\\", *valptr
))
2062 length
+= 13 + strlen(p
->job_sheets
[0]) + strlen(p
->job_sheets
[1]);
2064 if (BrowseLocalOptions
)
2065 length
+= 12 + strlen(BrowseLocalOptions
);
2068 * Allocate the new string...
2071 if ((p
->browse_attrs
= calloc(1, length
)) == NULL
)
2072 cupsdLogMessage(CUPSD_LOG_ERROR
,
2073 "Unable to allocate %d bytes for browse data!",
2078 * Got the allocated string, now copy the options and attributes over...
2081 sprintf(p
->browse_attrs
, "job-sheets=%s,%s lease-duration=%d",
2082 p
->job_sheets
[0], p
->job_sheets
[1], BrowseTimeout
);
2083 attrptr
= p
->browse_attrs
+ strlen(p
->browse_attrs
);
2085 if (BrowseLocalOptions
)
2087 sprintf(attrptr
, " ipp-options=%s", BrowseLocalOptions
);
2088 attrptr
+= strlen(attrptr
);
2091 for (i
= p
->num_options
, option
= p
->options
;
2096 strcpy(attrptr
, option
->name
);
2097 attrptr
+= strlen(attrptr
);
2103 for (valptr
= option
->value
; *valptr
; valptr
++)
2105 if (strchr(" \"\'\\", *valptr
))
2108 *attrptr
++ = *valptr
;
2118 * Populate the document-format-supported attribute...
2121 add_printer_formats(p
);
2123 DEBUG_printf(("cupsdSetPrinterAttrs: leaving name = %s, type = %x\n", p
->name
,
2127 * Add name-default attributes...
2130 add_printer_defaults(p
);
2134 * Write the IRIX printer config and status files...
2137 write_irix_config(p
);
2138 write_irix_state(p
);
2144 * 'cupsdSetPrinterReasons()' - Set/update the reasons strings.
2148 cupsdSetPrinterReasons(
2149 cupsd_printer_t
*p
, /* I - Printer */
2150 const char *s
) /* I - Reasons strings */
2152 int i
; /* Looping var */
2153 const char *sptr
; /* Pointer into reasons */
2154 char reason
[255], /* Reason string */
2155 *rptr
; /* Pointer into reason */
2158 if (s
[0] == '-' || s
[0] == '+')
2161 * Add/remove reasons...
2169 * Replace reasons...
2174 for (i
= 0; i
< p
->num_reasons
; i
++)
2175 free(p
->reasons
[i
]);
2181 * Loop through all of the reasons...
2187 * Skip leading whitespace and commas...
2190 while (isspace(*sptr
& 255) || *sptr
== ',')
2193 for (rptr
= reason
; *sptr
&& !isspace(*sptr
& 255) && *sptr
!= ','; sptr
++)
2194 if (rptr
< (reason
+ sizeof(reason
) - 1))
2208 for (i
= 0; i
< p
->num_reasons
; i
++)
2209 if (!strcasecmp(reason
, p
->reasons
[i
]))
2212 * Found a match, so remove it...
2216 free(p
->reasons
[i
]);
2218 if (i
< p
->num_reasons
)
2219 memmove(p
->reasons
+ i
, p
->reasons
+ i
+ 1,
2220 (p
->num_reasons
- i
) * sizeof(char *));
2225 else if (p
->num_reasons
< (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
2231 for (i
= 0; i
< p
->num_reasons
; i
++)
2232 if (!strcasecmp(reason
, p
->reasons
[i
]))
2235 if (i
>= p
->num_reasons
)
2237 p
->reasons
[i
] = strdup(reason
);
2246 * 'cupsdSetPrinterState()' - Update the current state of a printer.
2250 cupsdSetPrinterState(
2251 cupsd_printer_t
*p
, /* I - Printer to change */
2252 ipp_pstate_t s
, /* I - New state */
2253 int update
) /* I - Update printers.conf? */
2255 ipp_pstate_t old_state
; /* Old printer state */
2259 * Can't set status of remote printers...
2262 if (p
->type
& CUPS_PRINTER_REMOTE
)
2266 * Set the new state...
2269 old_state
= p
->state
;
2275 * Let the browse code know this needs to be updated...
2279 p
->state_time
= time(NULL
);
2283 write_irix_state(p
);
2287 cupsdAddPrinterHistory(p
);
2290 * Save the printer configuration if a printer goes from idle or processing
2291 * to stopped (or visa-versa)...
2294 if ((old_state
== IPP_PRINTER_STOPPED
) != (s
== IPP_PRINTER_STOPPED
) &&
2297 if (p
->type
& CUPS_PRINTER_CLASS
)
2298 cupsdSaveAllClasses();
2300 cupsdSaveAllPrinters();
2306 * 'cupsdStopPrinter()' - Stop a printer from printing any jobs...
2310 cupsdStopPrinter(cupsd_printer_t
*p
, /* I - Printer to stop */
2311 int update
)/* I - Update printers.conf? */
2313 cupsd_job_t
*job
; /* Active print job */
2317 * Set the printer state...
2320 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, update
);
2323 * See if we have a job printing on this printer...
2329 * Get pointer to job...
2332 job
= (cupsd_job_t
*)p
->job
;
2338 cupsdStopJob(job
, 0);
2341 * Reset the state to pending...
2344 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
2345 job
->state_value
= IPP_JOB_PENDING
;
2353 * 'cupsdUpdatePrinters()' - Update printers after a partial reload.
2357 cupsdUpdatePrinters(void)
2359 cupsd_printer_t
*p
; /* Current printer */
2363 * Loop through the printers and recreate the printer attributes
2364 * for any local printers since the policy and/or access control
2365 * stuff may have changed. Also, if browsing is disabled, remove
2366 * any remote printers...
2369 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
2371 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
2373 if (!Browsing
&& (p
->type
& (CUPS_PRINTER_IMPLICIT
| CUPS_PRINTER_REMOTE
)))
2375 if (p
->type
& CUPS_PRINTER_IMPLICIT
)
2376 cupsArrayRemove(ImplicitPrinters
, p
);
2378 cupsArraySave(Printers
);
2379 cupsdDeletePrinter(p
, 0);
2380 cupsArrayRestore(Printers
);
2383 else if (!(p
->type
& CUPS_PRINTER_REMOTE
))
2384 cupsdSetPrinterAttrs(p
);
2387 * Update the operation policy pointer...
2390 if ((p
->op_policy_ptr
= cupsdFindPolicy(p
->op_policy
)) == NULL
)
2391 p
->op_policy_ptr
= DefaultPolicyPtr
;
2397 * 'cupsdValidateDest()' - Validate a printer/class destination.
2400 const char * /* O - Printer or class name */
2402 const char *hostname
, /* I - Host name */
2403 const char *resource
, /* I - Resource name */
2404 cups_ptype_t
*dtype
, /* O - Type (printer or class) */
2405 cupsd_printer_t
**printer
) /* O - Printer pointer */
2407 cupsd_printer_t
*p
; /* Current printer */
2408 char localname
[1024],/* Localized hostname */
2409 *lptr
, /* Pointer into localized hostname */
2410 *sptr
; /* Pointer into server name */
2413 DEBUG_printf(("cupsdValidateDest(\"%s\", \"%s\", %p, %p)\n", hostname
, resource
,
2417 * Initialize return values...
2423 *dtype
= (cups_ptype_t
)0;
2426 * See if the resource is a class or printer...
2429 if (!strncmp(resource
, "/classes/", 9))
2437 else if (!strncmp(resource
, "/printers/", 10))
2448 * Bad resource name...
2455 * See if the printer or class name exists...
2458 p
= cupsdFindDest(resource
);
2460 if (p
== NULL
&& strchr(resource
, '@') == NULL
)
2467 *dtype
= p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
|
2468 CUPS_PRINTER_REMOTE
);
2473 * Change localhost to the server name...
2476 if (!strcasecmp(hostname
, "localhost"))
2477 hostname
= ServerName
;
2479 strlcpy(localname
, hostname
, sizeof(localname
));
2481 if (!strcasecmp(hostname
, ServerName
))
2484 * Localize the hostname...
2487 lptr
= strchr(localname
, '.');
2488 sptr
= strchr(ServerName
, '.');
2490 if (sptr
!= NULL
&& lptr
!= NULL
)
2493 * Strip the common domain name components...
2496 while (lptr
!= NULL
)
2498 if (!strcasecmp(lptr
, sptr
))
2504 lptr
= strchr(lptr
+ 1, '.');
2509 DEBUG_printf(("localized hostname is \"%s\"...\n", localname
));
2512 * Find a matching printer or class...
2515 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
2517 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
2518 if (!strcasecmp(p
->hostname
, localname
) &&
2519 !strcasecmp(p
->name
, resource
))
2524 *dtype
= p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
|
2525 CUPS_PRINTER_REMOTE
);
2534 * 'cupsdWritePrintcap()' - Write a pseudo-printcap file for older applications
2539 cupsdWritePrintcap(void)
2541 cups_file_t
*fp
; /* printcap file */
2542 cupsd_printer_t
*p
; /* Current printer */
2547 * Update the IRIX printer state for the default printer; if
2548 * no printers remain, then the default printer file will be
2552 write_irix_state(DefaultPrinter
);
2556 * See if we have a printcap file; if not, don't bother writing it.
2559 if (!Printcap
|| !*Printcap
)
2563 * Open the printcap file...
2566 if ((fp
= cupsFileOpen(Printcap
, "w")) == NULL
)
2570 * Put a comment header at the top so that users will know where the
2571 * data has come from...
2574 cupsFilePuts(fp
, "# This file was automatically generated by cupsd(8) from the\n");
2575 cupsFilePrintf(fp
, "# %s/printers.conf file. All changes to this file\n",
2577 cupsFilePuts(fp
, "# will be lost.\n");
2582 * Write a new printcap with the current list of printers.
2585 switch (PrintcapFormat
)
2589 * Each printer is put in the file as:
2599 cupsFilePrintf(fp
, "%s|%s:rm=%s:rp=%s:\n", DefaultPrinter
->name
,
2600 DefaultPrinter
->info
, ServerName
, DefaultPrinter
->name
);
2602 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
2604 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
2605 if (p
!= DefaultPrinter
)
2606 cupsFilePrintf(fp
, "%s|%s:rm=%s:rp=%s:\n", p
->name
, p
->info
,
2607 ServerName
, p
->name
);
2610 case PRINTCAP_SOLARIS
:
2612 * Each printer is put in the file as:
2614 * _all:all=Printer1,Printer2,Printer3,...,PrinterN
2615 * _default:use=DefaultPrinter
2617 * :bsdaddr=ServerName,Printer1:\
2618 * :description=Description:
2620 * :bsdaddr=ServerName,Printer2:\
2621 * :description=Description:
2623 * :bsdaddr=ServerName,Printer3:\
2624 * :description=Description:
2627 * :bsdaddr=ServerName,PrinterN:\
2628 * :description=Description:
2631 cupsFilePuts(fp
, "_all:all=");
2632 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
2634 p
= (cupsd_printer_t
*)cupsArrayCurrent(Printers
))
2635 cupsFilePrintf(fp
, "%s%c", p
->name
,
2636 cupsArrayNext(Printers
) ? ',' : '\n');
2639 cupsFilePrintf(fp
, "_default:use=%s\n", DefaultPrinter
->name
);
2641 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
2643 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
2644 cupsFilePrintf(fp
, "%s:\\\n"
2645 "\t:bsdaddr=%s,%s:\\\n"
2646 "\t:description=%s:\n",
2647 p
->name
, ServerName
, p
->name
, p
->info
? p
->info
: "");
2661 * 'cupsdSanitizeURI()' - Sanitize a device URI...
2664 char * /* O - New device URI */
2665 cupsdSanitizeURI(const char *uri
, /* I - Original device URI */
2666 char *buffer
, /* O - New device URI */
2667 int buflen
) /* I - Size of new device URI buffer */
2669 char *start
, /* Start of data after scheme */
2670 *slash
, /* First slash after scheme:// */
2671 *ptr
; /* Pointer into user@host:port part */
2675 * Range check input...
2678 if (!uri
|| !buffer
|| buflen
< 2)
2682 * Copy the device URI to the new buffer...
2685 strlcpy(buffer
, uri
, buflen
);
2688 * Find the end of the scheme:// part...
2691 if ((ptr
= strchr(buffer
, ':')) == NULL
)
2692 return (buffer
); /* No scheme: part... */
2694 for (start
= ptr
+ 1; *start
; start
++)
2699 * Find the next slash (/) in the URI...
2702 if ((slash
= strchr(start
, '/')) == NULL
)
2703 slash
= start
+ strlen(start
); /* No slash, point to the end */
2706 * Check for an @ sign before the slash...
2709 if ((ptr
= strchr(start
, '@')) != NULL
&& ptr
< slash
)
2712 * Found an @ sign and it is before the resource part, so we have
2713 * an authentication string. Copy the remaining URI over the
2714 * authentication string...
2717 _cups_strcpy(start
, ptr
+ 1);
2721 * Return the new device URI...
2729 * 'add_printer_defaults()' - Add name-default attributes to the printer attributes.
2733 add_printer_defaults(cupsd_printer_t
*p
)/* I - Printer */
2735 int i
; /* Looping var */
2736 int num_options
; /* Number of default options */
2737 cups_option_t
*options
, /* Default options */
2738 *option
; /* Current option */
2739 char name
[256]; /* name-default */
2743 * Add all of the default options from the .conf files...
2746 for (num_options
= 0, i
= p
->num_options
, option
= p
->options
;
2750 if (strcmp(option
->name
, "ipp-options") &&
2751 strcmp(option
->name
, "job-sheets") &&
2752 strcmp(option
->name
, "lease-duration"))
2754 snprintf(name
, sizeof(name
), "%s-default", option
->name
);
2755 num_options
= cupsAddOption(name
, option
->value
, num_options
, &options
);
2760 * Convert options to IPP attributes...
2763 cupsEncodeOptions2(p
->attrs
, num_options
, options
, IPP_TAG_PRINTER
);
2764 cupsFreeOptions(num_options
, options
);
2767 * Add standard -default attributes as needed...
2770 if (!cupsGetOption("copies", p
->num_options
, p
->options
))
2771 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
, "copies-default",
2774 if (!cupsGetOption("job-hold-until", p
->num_options
, p
->options
))
2775 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2776 "job-hold-until-default", NULL
, "no-hold");
2778 if (!cupsGetOption("job-priority", p
->num_options
, p
->options
))
2779 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2780 "job-priority-default", 50);
2782 if (!cupsGetOption("number-up", p
->num_options
, p
->options
))
2783 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2784 "number-up-default", 1);
2786 if (!cupsGetOption("orientation-requested", p
->num_options
, p
->options
))
2787 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
2788 "orientation-requested-default", IPP_PORTRAIT
);
2793 * 'add_printer_filter()' - Add a MIME filter for a printer.
2798 cupsd_printer_t
*p
, /* I - Printer to add to */
2799 const char *filter
) /* I - Filter to add */
2801 char super
[MIME_MAX_SUPER
], /* Super-type for filter */
2802 type
[MIME_MAX_TYPE
], /* Type for filter */
2803 program
[1024]; /* Program/filter name */
2804 int cost
; /* Cost of filter */
2805 mime_type_t
*temptype
; /* MIME type looping var */
2806 char filename
[1024]; /* Full filter filename */
2810 * Parse the filter string; it should be in the following format:
2812 * super/type cost program
2815 if (sscanf(filter
, "%15[^/]/%31s%d%1023s", super
, type
, &cost
, program
) != 4)
2817 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: invalid filter string \"%s\"!",
2823 * See if the filter program exists; if not, stop the printer and flag
2827 if (strcmp(program
, "-"))
2829 if (program
[0] == '/')
2830 strlcpy(filename
, program
, sizeof(filename
));
2832 snprintf(filename
, sizeof(filename
), "%s/filter/%s", ServerBin
, program
);
2834 if (access(filename
, X_OK
))
2836 snprintf(p
->state_message
, sizeof(p
->state_message
),
2837 "Filter \"%s\" for printer \"%s\" not available: %s",
2838 program
, p
->name
, strerror(errno
));
2839 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, 0);
2840 cupsdSetPrinterReasons(p
, "+cups-missing-filter-error");
2841 cupsdAddPrinterHistory(p
);
2843 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s", p
->state_message
);
2848 * Mark the CUPS_PRINTER_COMMANDS bit if we have a filter for
2849 * application/vnd.cups-command...
2852 if (!strcasecmp(super
, "application") &&
2853 !strcasecmp(type
, "vnd.cups-command"))
2854 p
->type
|= CUPS_PRINTER_COMMANDS
;
2857 * Add the filter to the MIME database, supporting wildcards as needed...
2860 for (temptype
= mimeFirstType(MimeDatabase
);
2862 temptype
= mimeNextType(MimeDatabase
))
2863 if (((super
[0] == '*' && strcasecmp(temptype
->super
, "printer")) ||
2864 !strcasecmp(temptype
->super
, super
)) &&
2865 (type
[0] == '*' || !strcasecmp(temptype
->type
, type
)))
2867 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
2868 "add_printer_filter: %s: adding filter %s/%s %s/%s %d %s",
2869 p
->name
, temptype
->super
, temptype
->type
,
2870 p
->filetype
->super
, p
->filetype
->type
,
2872 mimeAddFilter(MimeDatabase
, temptype
, p
->filetype
, cost
, program
);
2878 * 'add_printer_formats()' - Add document-format-supported values for a printer.
2882 add_printer_formats(cupsd_printer_t
*p
) /* I - Printer */
2884 int i
; /* Looping var */
2885 mime_type_t
*type
; /* Current MIME type */
2886 cups_array_t
*filters
; /* Filters */
2887 ipp_attribute_t
*attr
; /* document-format-supported attribute */
2888 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
2889 /* MIME type name */
2893 * Raw (and remote) queues advertise all of the supported MIME
2897 cupsArrayDelete(p
->filetypes
);
2898 p
->filetypes
= NULL
;
2902 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
,
2903 (ipp_tag_t
)(IPP_TAG_MIMETYPE
| IPP_TAG_COPY
),
2904 "document-format-supported", NumMimeTypes
, NULL
, MimeTypes
);
2909 * Otherwise, loop through the supported MIME types and see if there
2910 * are filters for them...
2913 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_printer_formats: %d types, %d filters",
2914 mimeNumTypes(MimeDatabase
), mimeNumFilters(MimeDatabase
));
2916 p
->filetypes
= cupsArrayNew(NULL
, NULL
);
2918 for (type
= mimeFirstType(MimeDatabase
);
2920 type
= mimeNextType(MimeDatabase
))
2922 if (!strcasecmp(type
->super
, "application") &&
2923 !strcasecmp(type
->type
, "octet-stream"))
2926 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
2928 if ((filters
= mimeFilter(MimeDatabase
, type
, p
->filetype
, NULL
)) != NULL
)
2930 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
2931 "add_printer_formats: %s: %s needs %d filters",
2932 p
->name
, mimetype
, cupsArrayCount(filters
));
2934 cupsArrayDelete(filters
);
2935 cupsArrayAdd(p
->filetypes
, type
);
2938 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
2939 "add_printer_formats: %s: %s not supported",
2943 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
2944 "add_printer_formats: %s: %d supported types",
2945 p
->name
, cupsArrayCount(p
->filetypes
) + 1);
2948 * Add the file formats that can be filtered...
2952 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_MIMETYPE
,
2953 "document-format-supported",
2954 cupsArrayCount(p
->filetypes
) + 1, NULL
, NULL
);
2956 attr
->values
[0].string
.text
= _cupsStrAlloc("application/octet-stream");
2958 for (i
= 1, type
= (mime_type_t
*)cupsArrayFirst(p
->filetypes
);
2960 i
++, type
= (mime_type_t
*)cupsArrayNext(p
->filetypes
))
2962 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
2964 attr
->values
[i
].string
.text
= _cupsStrAlloc(mimetype
);
2970 * 'compare_printers()' - Compare two printers.
2973 static int /* O - Result of comparison */
2974 compare_printers(void *first
, /* I - First printer */
2975 void *second
, /* I - Second printer */
2976 void *data
) /* I - App data (not used) */
2978 return (strcasecmp(((cupsd_printer_t
*)first
)->name
,
2979 ((cupsd_printer_t
*)second
)->name
));
2984 * 'delete_printer_filters()' - Delete all MIME filters for a printer.
2988 delete_printer_filters(
2989 cupsd_printer_t
*p
) /* I - Printer to remove from */
2991 mime_filter_t
*filter
; /* MIME filter looping var */
2995 * Range check input...
3002 * Remove all filters from the MIME database that have a destination
3003 * type == printer...
3006 for (filter
= mimeFirstFilter(MimeDatabase
);
3008 filter
= mimeNextFilter(MimeDatabase
))
3009 if (filter
->dst
== p
->filetype
)
3012 * Delete the current filter...
3015 mimeDeleteFilter(MimeDatabase
, filter
);
3022 * 'write_irix_config()' - Update the config files used by the IRIX
3027 write_irix_config(cupsd_printer_t
*p
) /* I - Printer to update */
3029 char filename
[1024]; /* Interface script filename */
3030 cups_file_t
*fp
; /* Interface script file */
3035 * Add dummy interface and GUI scripts to fool SGI's "challenged" printing
3036 * tools. First the interface script that tells the tools what kind of
3037 * printer we have...
3040 snprintf(filename
, sizeof(filename
), "/var/spool/lp/interface/%s", p
->name
);
3042 if (p
->type
& CUPS_PRINTER_CLASS
)
3044 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
3046 cupsFilePuts(fp
, "#!/bin/sh\n");
3048 if ((attr
= ippFindAttribute(p
->attrs
, "printer-make-and-model",
3049 IPP_TAG_TEXT
)) != NULL
)
3050 cupsFilePrintf(fp
, "NAME=\"%s\"\n", attr
->values
[0].string
.text
);
3051 else if (p
->type
& CUPS_PRINTER_CLASS
)
3052 cupsFilePuts(fp
, "NAME=\"Printer Class\"\n");
3054 cupsFilePuts(fp
, "NAME=\"Remote Destination\"\n");
3056 if (p
->type
& CUPS_PRINTER_COLOR
)
3057 cupsFilePuts(fp
, "TYPE=ColorPostScript\n");
3059 cupsFilePuts(fp
, "TYPE=MonoPostScript\n");
3061 cupsFilePrintf(fp
, "HOSTNAME=%s\n", ServerName
);
3062 cupsFilePrintf(fp
, "HOSTPRINTER=%s\n", p
->name
);
3066 chmod(filename
, 0755);
3067 chown(filename
, User
, Group
);
3071 * Then the member file that tells which device file the queue is connected
3072 * to... Networked printers use "/dev/null" in this file, so that's what
3073 * we use (the actual device URI can confuse some apps...)
3076 snprintf(filename
, sizeof(filename
), "/var/spool/lp/member/%s", p
->name
);
3078 if (p
->type
& CUPS_PRINTER_CLASS
)
3080 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
3082 cupsFilePuts(fp
, "/dev/null\n");
3086 chmod(filename
, 0644);
3087 chown(filename
, User
, Group
);
3091 * The gui_interface file is a script or program that launches a GUI
3092 * option panel for the printer, using options specified on the
3093 * command-line in the third argument. The option panel must send
3094 * any printing options to stdout on a single line when the user
3095 * accepts them, or nothing if the user cancels the dialog.
3097 * The default options panel program is /usr/bin/glpoptions, from
3098 * the ESP Print Pro software. You can select another using the
3099 * PrintcapGUI option.
3102 snprintf(filename
, sizeof(filename
), "/var/spool/lp/gui_interface/ELF/%s.gui", p
->name
);
3104 if (p
->type
& CUPS_PRINTER_CLASS
)
3106 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
3108 cupsFilePuts(fp
, "#!/bin/sh\n");
3109 cupsFilePrintf(fp
, "%s -d %s -o \"$3\"\n", PrintcapGUI
, p
->name
);
3113 chmod(filename
, 0755);
3114 chown(filename
, User
, Group
);
3118 * The POD config file is needed by the printstatus command to show
3119 * the printer location and device.
3122 snprintf(filename
, sizeof(filename
), "/var/spool/lp/pod/%s.config", p
->name
);
3124 if (p
->type
& CUPS_PRINTER_CLASS
)
3126 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
3128 cupsFilePrintf(fp
, "Printer Class | %s\n",
3129 (p
->type
& CUPS_PRINTER_COLOR
) ? "ColorPostScript" : "MonoPostScript");
3130 cupsFilePrintf(fp
, "Printer Model | %s\n", p
->make_model
? p
->make_model
: "");
3131 cupsFilePrintf(fp
, "Location Code | %s\n", p
->location
? p
->location
: "");
3132 cupsFilePrintf(fp
, "Physical Location | %s\n", p
->info
? p
->info
: "");
3133 cupsFilePrintf(fp
, "Port Path | %s\n", p
->device_uri
? p
->device_uri
: "");
3134 cupsFilePrintf(fp
, "Config Path | /var/spool/lp/pod/%s.config\n", p
->name
);
3135 cupsFilePrintf(fp
, "Active Status Path | /var/spool/lp/pod/%s.status\n", p
->name
);
3136 cupsFilePuts(fp
, "Status Update Wait | 10 seconds\n");
3140 chmod(filename
, 0664);
3141 chown(filename
, User
, Group
);
3147 * 'write_irix_state()' - Update the status files used by IRIX printing
3152 write_irix_state(cupsd_printer_t
*p
) /* I - Printer to update */
3154 char filename
[1024]; /* Interface script filename */
3155 cups_file_t
*fp
; /* Interface script file */
3156 int tag
; /* Status tag value */
3162 * The POD status file is needed for the printstatus window to
3163 * provide the current status of the printer.
3166 snprintf(filename
, sizeof(filename
), "/var/spool/lp/pod/%s.status", p
->name
);
3168 if (p
->type
& CUPS_PRINTER_CLASS
)
3170 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
3172 cupsFilePrintf(fp
, "Operational Status | %s\n",
3173 (p
->state
== IPP_PRINTER_IDLE
) ? "Idle" :
3174 (p
->state
== IPP_PRINTER_PROCESSING
) ? "Busy" :
3176 cupsFilePrintf(fp
, "Information | 01 00 00 | %s\n", CUPS_SVERSION
);
3177 cupsFilePrintf(fp
, "Information | 02 00 00 | Device URI: %s\n",
3178 p
->device_uri
? p
->device_uri
: "");
3179 cupsFilePrintf(fp
, "Information | 03 00 00 | %s jobs\n",
3180 p
->accepting
? "Accepting" : "Not accepting");
3181 cupsFilePrintf(fp
, "Information | 04 00 00 | %s\n", p
->state_message
);
3185 chmod(filename
, 0664);
3186 chown(filename
, User
, Group
);
3190 * The activeicons file is needed to provide desktop icons for printers:
3192 * [ quoted from /usr/lib/print/tagit ]
3194 * --- Type of printer tags (base values)
3196 * Dumb=66048 # 0x10200
3197 * DumbColor=66080 # 0x10220
3198 * Raster=66112 # 0x10240
3199 * ColorRaster=66144 # 0x10260
3200 * Plotter=66176 # 0x10280
3201 * PostScript=66208 # 0x102A0
3202 * ColorPostScript=66240 # 0x102C0
3203 * MonoPostScript=66272 # 0x102E0
3205 * --- Printer state modifiers for local printers
3210 * Unknown=3 # 0x3 (Faulted due to unknown reason)
3212 * --- Printer state modifiers for network printers
3216 * NetFaulted=10 # 0xA
3217 * NetUnknown=11 # 0xB (Faulted due to unknown reason)
3220 snprintf(filename
, sizeof(filename
), "/var/spool/lp/activeicons/%s", p
->name
);
3222 if (p
->type
& CUPS_PRINTER_CLASS
)
3224 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
3226 if (p
->type
& CUPS_PRINTER_COLOR
)
3231 if (p
->type
& CUPS_PRINTER_REMOTE
)
3234 if (p
->state
== IPP_PRINTER_PROCESSING
)
3237 else if (p
->state
== IPP_PRINTER_STOPPED
)
3240 cupsFilePuts(fp
, "#!/bin/sh\n");
3241 cupsFilePrintf(fp
, "#Tag %d\n", tag
);
3245 chmod(filename
, 0755);
3246 chown(filename
, User
, Group
);
3251 * The default file is needed by the printers window to show
3252 * the default printer.
3255 snprintf(filename
, sizeof(filename
), "/var/spool/lp/default");
3257 if (DefaultPrinter
!= NULL
)
3259 if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
3261 cupsFilePrintf(fp
, "%s\n", DefaultPrinter
->name
);
3265 chmod(filename
, 0644);
3266 chown(filename
, User
, Group
);
3276 * End of "$Id: printers.c 5330 2006-03-23 21:07:20Z mike $".