2 * "$Id: printers.c 5305 2006-03-18 03:05:12Z 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
);
725 free(p
->browse_attrs
);
728 cupsdClearString(&p
->recoverable
);
729 #endif /* __APPLE__ */
731 cupsFreeOptions(p
->num_options
, p
->options
);
736 * Restore the previous position in the Printers array...
739 cupsArrayRestore(Printers
);
744 * 'cupsdFindDest()' - Find a destination in the list.
747 cupsd_printer_t
* /* O - Destination in list */
748 cupsdFindDest(const char *name
) /* I - Name of printer or class to find */
750 cupsd_printer_t key
; /* Search key */
753 key
.name
= (char *)name
;
754 return ((cupsd_printer_t
*)cupsArrayFind(Printers
, &key
));
759 * 'cupsdFindPrinter()' - Find a printer in the list.
762 cupsd_printer_t
* /* O - Printer in list */
763 cupsdFindPrinter(const char *name
) /* I - Name of printer to find */
765 cupsd_printer_t
*p
; /* Printer in list */
768 if ((p
= cupsdFindDest(name
)) != NULL
&& (p
->type
& CUPS_PRINTER_CLASS
))
776 * 'cupsdFreePrinterUsers()' - Free allow/deny users.
780 cupsdFreePrinterUsers(
781 cupsd_printer_t
*p
) /* I - Printer */
783 int i
; /* Looping var */
786 if (!p
|| !p
->num_users
)
789 for (i
= 0; i
< p
->num_users
; i
++)
790 free((void *)p
->users
[i
]);
800 * 'cupsdLoadAllPrinters()' - Load printers from the printers.conf file.
804 cupsdLoadAllPrinters(void)
806 cups_file_t
*fp
; /* printers.conf file */
807 int linenum
; /* Current line number */
808 char line
[1024], /* Line from file */
809 *value
, /* Pointer to value */
810 *valueptr
; /* Pointer into value */
811 cupsd_printer_t
*p
; /* Current printer */
815 * Open the printers.conf file...
818 snprintf(line
, sizeof(line
), "%s/printers.conf", ServerRoot
);
819 if ((fp
= cupsFileOpen(line
, "r")) == NULL
)
822 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to open %s - %s", line
,
828 * Read printer configurations until we hit EOF...
834 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
837 * Decode the directive...
840 if (!strcasecmp(line
, "<Printer") ||
841 !strcasecmp(line
, "<DefaultPrinter"))
844 * <Printer name> or <DefaultPrinter name>
847 if (p
== NULL
&& value
)
850 * Add the printer and a base file type...
853 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Loading printer %s...", value
);
855 p
= cupsdAddPrinter(value
);
857 p
->state
= IPP_PRINTER_IDLE
;
860 * Set the default printer as needed...
863 if (!strcasecmp(line
, "<DefaultPrinter"))
868 cupsdLogMessage(CUPSD_LOG_ERROR
,
869 "Syntax error on line %d of printers.conf.", linenum
);
873 else if (!strcasecmp(line
, "</Printer>"))
878 * Close out the current printer...
881 cupsdSetPrinterAttrs(p
);
882 cupsdAddPrinterHistory(p
);
884 if (p
->device_uri
&& strncmp(p
->device_uri
, "file:", 5) &&
885 p
->state
!= IPP_PRINTER_STOPPED
)
888 * See if the backend exists...
891 snprintf(line
, sizeof(line
), "%s/backend/%s", ServerBin
,
894 if ((valueptr
= strchr(line
+ strlen(ServerBin
), ':')) != NULL
)
895 *valueptr
= '\0'; /* Chop everything but URI scheme */
900 * Backend does not exist, stop printer...
903 p
->state
= IPP_PRINTER_STOPPED
;
904 snprintf(p
->state_message
, sizeof(p
->state_message
),
905 "Backend %s does not exist!", line
);
913 cupsdLogMessage(CUPSD_LOG_ERROR
,
914 "Syntax error on line %d of printers.conf.", linenum
);
920 cupsdLogMessage(CUPSD_LOG_ERROR
,
921 "Syntax error on line %d of printers.conf.", linenum
);
924 else if (!strcasecmp(line
, "Info"))
927 cupsdSetString(&p
->info
, value
);
929 else if (!strcasecmp(line
, "Location"))
932 cupsdSetString(&p
->location
, value
);
934 else if (!strcasecmp(line
, "DeviceURI"))
937 cupsdSetString(&p
->device_uri
, value
);
940 cupsdLogMessage(CUPSD_LOG_ERROR
,
941 "Syntax error on line %d of printers.conf.", linenum
);
945 else if (!strcasecmp(line
, "Option") && value
)
951 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
954 cupsdLogMessage(CUPSD_LOG_ERROR
,
955 "Syntax error on line %d of printers.conf.", linenum
);
958 for (; *valueptr
&& isspace(*valueptr
& 255); *valueptr
++ = '\0');
960 p
->num_options
= cupsAddOption(value
, valueptr
, p
->num_options
,
964 else if (!strcasecmp(line
, "PortMonitor"))
966 if (value
&& strcmp(value
, "none"))
967 cupsdSetString(&p
->port_monitor
, value
);
969 cupsdClearString(&p
->port_monitor
);
972 cupsdLogMessage(CUPSD_LOG_ERROR
,
973 "Syntax error on line %d of printers.conf.", linenum
);
977 else if (!strcasecmp(line
, "State"))
980 * Set the initial queue state...
983 if (value
&& !strcasecmp(value
, "idle"))
984 p
->state
= IPP_PRINTER_IDLE
;
985 else if (value
&& !strcasecmp(value
, "stopped"))
986 p
->state
= IPP_PRINTER_STOPPED
;
989 cupsdLogMessage(CUPSD_LOG_ERROR
,
990 "Syntax error on line %d of printers.conf.", linenum
);
994 else if (!strcasecmp(line
, "StateMessage"))
997 * Set the initial queue state message...
1001 strlcpy(p
->state_message
, value
, sizeof(p
->state_message
));
1003 else if (!strcasecmp(line
, "StateTime"))
1006 * Set the state time...
1010 p
->state_time
= atoi(value
);
1012 else if (!strcasecmp(line
, "Accepting"))
1015 * Set the initial accepting state...
1019 (!strcasecmp(value
, "yes") ||
1020 !strcasecmp(value
, "on") ||
1021 !strcasecmp(value
, "true")))
1024 (!strcasecmp(value
, "no") ||
1025 !strcasecmp(value
, "off") ||
1026 !strcasecmp(value
, "false")))
1030 cupsdLogMessage(CUPSD_LOG_ERROR
,
1031 "Syntax error on line %d of printers.conf.", linenum
);
1035 else if (!strcasecmp(line
, "Shared"))
1038 * Set the initial shared state...
1042 (!strcasecmp(value
, "yes") ||
1043 !strcasecmp(value
, "on") ||
1044 !strcasecmp(value
, "true")))
1047 (!strcasecmp(value
, "no") ||
1048 !strcasecmp(value
, "off") ||
1049 !strcasecmp(value
, "false")))
1053 cupsdLogMessage(CUPSD_LOG_ERROR
,
1054 "Syntax error on line %d of printers.conf.", linenum
);
1058 else if (!strcasecmp(line
, "JobSheets"))
1061 * Set the initial job sheets...
1066 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1071 cupsdSetString(&p
->job_sheets
[0], value
);
1073 while (isspace(*valueptr
& 255))
1078 for (value
= valueptr
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1083 cupsdSetString(&p
->job_sheets
[1], value
);
1088 cupsdLogMessage(CUPSD_LOG_ERROR
,
1089 "Syntax error on line %d of printers.conf.", linenum
);
1093 else if (!strcasecmp(line
, "AllowUser"))
1098 cupsdAddPrinterUser(p
, value
);
1102 cupsdLogMessage(CUPSD_LOG_ERROR
,
1103 "Syntax error on line %d of printers.conf.", linenum
);
1107 else if (!strcasecmp(line
, "DenyUser"))
1112 cupsdAddPrinterUser(p
, value
);
1116 cupsdLogMessage(CUPSD_LOG_ERROR
,
1117 "Syntax error on line %d of printers.conf.", linenum
);
1121 else if (!strcasecmp(line
, "QuotaPeriod"))
1124 p
->quota_period
= atoi(value
);
1127 cupsdLogMessage(CUPSD_LOG_ERROR
,
1128 "Syntax error on line %d of printers.conf.", linenum
);
1132 else if (!strcasecmp(line
, "PageLimit"))
1135 p
->page_limit
= atoi(value
);
1138 cupsdLogMessage(CUPSD_LOG_ERROR
,
1139 "Syntax error on line %d of printers.conf.", linenum
);
1143 else if (!strcasecmp(line
, "KLimit"))
1146 p
->k_limit
= atoi(value
);
1149 cupsdLogMessage(CUPSD_LOG_ERROR
,
1150 "Syntax error on line %d of printers.conf.", linenum
);
1154 else if (!strcasecmp(line
, "OpPolicy"))
1157 cupsdSetString(&p
->op_policy
, value
);
1160 cupsdLogMessage(CUPSD_LOG_ERROR
,
1161 "Syntax error on line %d of printers.conf.", linenum
);
1165 else if (!strcasecmp(line
, "ErrorPolicy"))
1168 cupsdSetString(&p
->error_policy
, value
);
1171 cupsdLogMessage(CUPSD_LOG_ERROR
,
1172 "Syntax error on line %d of printers.conf.", linenum
);
1179 * Something else we don't understand...
1182 cupsdLogMessage(CUPSD_LOG_ERROR
,
1183 "Unknown configuration directive %s on line %d of printers.conf.",
1193 * 'cupsdRenamePrinter()' - Rename a printer.
1198 cupsd_printer_t
*p
, /* I - Printer */
1199 const char *name
) /* I - New name */
1202 * Remove the printer from the array(s) first...
1205 cupsArrayRemove(Printers
, p
);
1207 if (p
->type
& CUPS_PRINTER_IMPLICIT
)
1208 cupsArrayRemove(ImplicitPrinters
, p
);
1211 * Rename the printer type...
1214 mimeDeleteType(MimeDatabase
, p
->filetype
);
1215 p
->filetype
= mimeAddType(MimeDatabase
, "printer", name
);
1218 * Rename the printer...
1221 cupsdSetStringf(&p
->name
, name
);
1224 * Reset printer attributes...
1227 cupsdSetPrinterAttrs(p
);
1230 * Add the printer back to the printer array(s)...
1233 cupsArrayAdd(Printers
, p
);
1234 if (p
->type
& CUPS_PRINTER_IMPLICIT
)
1235 cupsArrayAdd(ImplicitPrinters
, p
);
1240 * 'cupsdSaveAllPrinters()' - Save all printer definitions to the printers.conf
1245 cupsdSaveAllPrinters(void)
1247 int i
; /* Looping var */
1248 cups_file_t
*fp
; /* printers.conf file */
1249 char temp
[1024]; /* Temporary string */
1250 char backup
[1024]; /* printers.conf.O file */
1251 cupsd_printer_t
*printer
; /* Current printer class */
1252 time_t curtime
; /* Current time */
1253 struct tm
*curdate
; /* Current date */
1254 cups_option_t
*option
; /* Current option */
1258 * Create the printers.conf file...
1261 snprintf(temp
, sizeof(temp
), "%s/printers.conf", ServerRoot
);
1262 snprintf(backup
, sizeof(backup
), "%s/printers.conf.O", ServerRoot
);
1264 if (rename(temp
, backup
))
1266 if (errno
!= ENOENT
)
1267 cupsdLogMessage(CUPSD_LOG_ERROR
,
1268 "Unable to backup printers.conf - %s", strerror(errno
));
1271 if ((fp
= cupsFileOpen(temp
, "w")) == NULL
)
1273 cupsdLogMessage(CUPSD_LOG_ERROR
,
1274 "Unable to save printers.conf - %s", strerror(errno
));
1276 if (rename(backup
, temp
))
1277 cupsdLogMessage(CUPSD_LOG_ERROR
,
1278 "Unable to restore printers.conf - %s", strerror(errno
));
1282 cupsdLogMessage(CUPSD_LOG_INFO
, "Saving printers.conf...");
1285 * Restrict access to the file...
1288 fchown(cupsFileNumber(fp
), getuid(), Group
);
1289 fchmod(cupsFileNumber(fp
), 0600);
1292 * Write a small header to the file...
1295 curtime
= time(NULL
);
1296 curdate
= localtime(&curtime
);
1297 strftime(temp
, sizeof(temp
) - 1, "%Y-%m-%d %H:%M", curdate
);
1299 cupsFilePuts(fp
, "# Printer configuration file for " CUPS_SVERSION
"\n");
1300 cupsFilePrintf(fp
, "# Written by cupsd on %s\n", temp
);
1303 * Write each local printer known to the system...
1306 for (printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
1308 printer
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
1311 * Skip remote destinations and printer classes...
1314 if ((printer
->type
& CUPS_PRINTER_REMOTE
) ||
1315 (printer
->type
& CUPS_PRINTER_CLASS
) ||
1316 (printer
->type
& CUPS_PRINTER_IMPLICIT
))
1320 * Write printers as needed...
1323 if (printer
== DefaultPrinter
)
1324 cupsFilePrintf(fp
, "<DefaultPrinter %s>\n", printer
->name
);
1326 cupsFilePrintf(fp
, "<Printer %s>\n", printer
->name
);
1329 cupsFilePrintf(fp
, "Info %s\n", printer
->info
);
1331 if (printer
->location
)
1332 cupsFilePrintf(fp
, "Location %s\n", printer
->location
);
1334 if (printer
->device_uri
)
1335 cupsFilePrintf(fp
, "DeviceURI %s\n", printer
->device_uri
);
1337 if (printer
->port_monitor
)
1338 cupsFilePrintf(fp
, "PortMonitor %s\n", printer
->port_monitor
);
1340 if (printer
->state
== IPP_PRINTER_STOPPED
)
1342 cupsFilePuts(fp
, "State Stopped\n");
1343 cupsFilePrintf(fp
, "StateMessage %s\n", printer
->state_message
);
1346 cupsFilePuts(fp
, "State Idle\n");
1348 cupsFilePrintf(fp
, "StateTime %d\n", (int)printer
->state_time
);
1350 if (printer
->accepting
)
1351 cupsFilePuts(fp
, "Accepting Yes\n");
1353 cupsFilePuts(fp
, "Accepting No\n");
1355 if (printer
->shared
)
1356 cupsFilePuts(fp
, "Shared Yes\n");
1358 cupsFilePuts(fp
, "Shared No\n");
1360 cupsFilePrintf(fp
, "JobSheets %s %s\n", printer
->job_sheets
[0],
1361 printer
->job_sheets
[1]);
1363 cupsFilePrintf(fp
, "QuotaPeriod %d\n", printer
->quota_period
);
1364 cupsFilePrintf(fp
, "PageLimit %d\n", printer
->page_limit
);
1365 cupsFilePrintf(fp
, "KLimit %d\n", printer
->k_limit
);
1367 for (i
= 0; i
< printer
->num_users
; i
++)
1368 cupsFilePrintf(fp
, "%sUser %s\n", printer
->deny_users
? "Deny" : "Allow",
1371 if (printer
->op_policy
)
1372 cupsFilePrintf(fp
, "OpPolicy %s\n", printer
->op_policy
);
1373 if (printer
->error_policy
)
1374 cupsFilePrintf(fp
, "ErrorPolicy %s\n", printer
->error_policy
);
1376 for (i
= printer
->num_options
, option
= printer
->options
;
1379 cupsFilePrintf(fp
, "Option %s %s\n", option
->name
, option
->value
);
1381 cupsFilePuts(fp
, "</Printer>\n");
1385 * Make IRIX desktop & printer status happy
1388 write_irix_state(printer
);
1397 * 'cupsdSetPrinterAttrs()' - Set printer attributes based upon the PPD file.
1401 cupsdSetPrinterAttrs(cupsd_printer_t
*p
)/* I - Printer to setup */
1403 int i
, /* Looping var */
1404 length
; /* Length of browse attributes */
1405 char uri
[HTTP_MAX_URI
]; /* URI for printer */
1406 char resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
1407 char filename
[1024]; /* Name of PPD file */
1408 int num_media
; /* Number of media options */
1409 cupsd_location_t
*auth
; /* Pointer to authentication element */
1410 const char *auth_supported
; /* Authentication supported */
1411 cups_ptype_t printer_type
; /* Printer type data */
1412 ppd_file_t
*ppd
; /* PPD file data */
1413 ppd_option_t
*input_slot
, /* InputSlot options */
1414 *media_type
, /* MediaType options */
1415 *page_size
, /* PageSize options */
1416 *output_bin
, /* OutputBin options */
1417 *media_quality
, /* EFMediaQualityMode options */
1418 *duplex
; /* Duplex options */
1419 ppd_attr_t
*ppdattr
; /* PPD attribute */
1420 ipp_attribute_t
*attr
; /* Attribute data */
1421 ipp_value_t
*val
; /* Attribute value */
1422 int num_finishings
; /* Number of finishings */
1423 ipp_finish_t finishings
[5]; /* finishings-supported values */
1424 cups_option_t
*option
; /* Current printer option */
1425 static const char * const sides
[3] = /* sides-supported values */
1428 "two-sided-long-edge",
1429 "two-sided-short-edge"
1433 DEBUG_printf(("cupsdSetPrinterAttrs: entering name = %s, type = %x\n", p
->name
,
1437 * Make sure that we have the common attributes defined...
1441 cupsdCreateCommonData();
1444 * Clear out old filters, if any...
1447 delete_printer_filters(p
);
1450 * Figure out the authentication that is required for the printer.
1453 auth_supported
= "requesting-user-name";
1454 if (!(p
->type
& CUPS_PRINTER_REMOTE
))
1456 if (p
->type
& CUPS_PRINTER_CLASS
)
1457 snprintf(resource
, sizeof(resource
), "/classes/%s", p
->name
);
1459 snprintf(resource
, sizeof(resource
), "/printers/%s", p
->name
);
1461 if ((auth
= cupsdFindBest(resource
, HTTP_POST
)) == NULL
)
1462 auth
= cupsdFindPolicyOp(p
->op_policy_ptr
, IPP_PRINT_JOB
);
1466 if (auth
->type
== AUTH_BASIC
|| auth
->type
== AUTH_BASICDIGEST
)
1467 auth_supported
= "basic";
1468 else if (auth
->type
== AUTH_DIGEST
)
1469 auth_supported
= "digest";
1471 if (auth
->type
!= AUTH_NONE
)
1472 p
->type
|= CUPS_PRINTER_AUTHENTICATED
;
1474 p
->type
&= ~CUPS_PRINTER_AUTHENTICATED
;
1477 p
->type
&= ~CUPS_PRINTER_AUTHENTICATED
;
1481 * Create the required IPP attributes for a printer...
1485 ippDelete(p
->attrs
);
1487 p
->attrs
= ippNew();
1489 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
1490 "uri-authentication-supported", NULL
, auth_supported
);
1491 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
1492 "uri-security-supported", NULL
, "none");
1493 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
, "printer-name", NULL
,
1495 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-location",
1496 NULL
, p
->location
? p
->location
: "");
1497 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-info",
1498 NULL
, p
->info
? p
->info
: "");
1499 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "printer-more-info",
1505 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
1506 "requesting-user-name-denied", p
->num_users
, NULL
,
1509 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
1510 "requesting-user-name-allowed", p
->num_users
, NULL
,
1514 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
1515 "job-quota-period", p
->quota_period
);
1516 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
1517 "job-k-limit", p
->k_limit
);
1518 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
1519 "job-page-limit", p
->page_limit
);
1521 if (cupsArrayCount(Banners
) > 0 && !(p
->type
& CUPS_PRINTER_REMOTE
))
1524 * Setup the job-sheets-default attribute...
1527 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
1528 "job-sheets-default", 2, NULL
, NULL
);
1532 attr
->values
[0].string
.text
= _cupsStrAlloc(Classification
?
1533 Classification
: p
->job_sheets
[0]);
1534 attr
->values
[1].string
.text
= _cupsStrAlloc(Classification
?
1535 Classification
: p
->job_sheets
[1]);
1539 printer_type
= p
->type
;
1543 if (p
->type
& CUPS_PRINTER_REMOTE
)
1546 * Tell the client this is a remote printer of some type...
1549 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
1550 "printer-uri-supported", NULL
, p
->uri
);
1553 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
1554 "printer-make-and-model", NULL
, p
->make_model
);
1556 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "device-uri", NULL
,
1564 * Assign additional attributes depending on whether this is a printer
1568 p
->type
&= ~CUPS_PRINTER_OPTIONS
;
1570 if (p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
))
1575 * Add class-specific attributes...
1578 if ((p
->type
& CUPS_PRINTER_IMPLICIT
) && p
->num_printers
> 0 &&
1579 p
->printers
[0]->make_model
)
1580 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
1581 "printer-make-and-model", NULL
, p
->printers
[0]->make_model
);
1583 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
1584 "printer-make-and-model", NULL
, "Local Printer Class");
1586 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "device-uri", NULL
,
1587 "file:///dev/null");
1589 if (p
->num_printers
> 0)
1592 * Add a list of member URIs and names...
1595 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
1596 "member-uris", p
->num_printers
, NULL
, NULL
);
1597 p
->type
|= CUPS_PRINTER_OPTIONS
;
1599 for (i
= 0; i
< p
->num_printers
; i
++)
1602 attr
->values
[i
].string
.text
= _cupsStrAlloc(p
->printers
[i
]->uri
);
1604 p
->type
&= ~CUPS_PRINTER_OPTIONS
| p
->printers
[i
]->type
;
1607 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
1608 "member-names", p
->num_printers
, NULL
, NULL
);
1612 for (i
= 0; i
< p
->num_printers
; i
++)
1613 attr
->values
[i
].string
.text
= _cupsStrAlloc(p
->printers
[i
]->name
);
1620 * Add printer-specific attributes... Start by sanitizing the device
1621 * URI so it doesn't have a username or password in it...
1625 strcpy(uri
, "file:/dev/null");
1626 else if (strstr(p
->device_uri
, "://") != NULL
)
1629 * http://..., ipp://..., etc.
1632 cupsdSanitizeURI(p
->device_uri
, uri
, sizeof(uri
));
1637 * file:..., serial:..., etc.
1640 strlcpy(uri
, p
->device_uri
, sizeof(uri
));
1643 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "device-uri", NULL
,
1647 * Assign additional attributes from the PPD file (if any)...
1650 p
->type
|= CUPS_PRINTER_BW
;
1651 finishings
[0] = IPP_FINISHINGS_NONE
;
1654 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
1657 if ((ppd
= ppdOpenFile(filename
)) != NULL
)
1660 * Add make/model and other various attributes...
1663 if (ppd
->color_device
)
1664 p
->type
|= CUPS_PRINTER_COLOR
;
1665 if (ppd
->variable_sizes
)
1666 p
->type
|= CUPS_PRINTER_VARIABLE
;
1667 if (!ppd
->manual_copies
)
1668 p
->type
|= CUPS_PRINTER_COPIES
;
1669 if ((ppdattr
= ppdFindAttr(ppd
, "cupsFax", NULL
)) != NULL
)
1670 if (ppdattr
->value
&& !strcasecmp(ppdattr
->value
, "true"))
1671 p
->type
|= CUPS_PRINTER_FAX
;
1673 ippAddBoolean(p
->attrs
, IPP_TAG_PRINTER
, "color-supported",
1675 if (ppd
->throughput
)
1676 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
1677 "pages-per-minute", ppd
->throughput
);
1682 * The NickName can be localized in the character set specified
1683 * by the LanugageEncoding attribute. However, ppdOpen2() has
1684 * already converted the ppd->nickname member to UTF-8 for us
1685 * (the original attribute value is available separately)
1688 cupsdSetString(&p
->make_model
, ppd
->nickname
);
1690 else if (ppd
->modelname
)
1693 * Model name can only contain specific characters...
1696 cupsdSetString(&p
->make_model
, ppd
->modelname
);
1699 cupsdSetString(&p
->make_model
, "Bad PPD File");
1701 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
1702 "printer-make-and-model", NULL
, p
->make_model
);
1705 * Add media options from the PPD file...
1708 if ((input_slot
= ppdFindOption(ppd
, "InputSlot")) != NULL
)
1709 num_media
= input_slot
->num_choices
;
1713 if ((media_type
= ppdFindOption(ppd
, "MediaType")) != NULL
)
1714 num_media
+= media_type
->num_choices
;
1716 if ((page_size
= ppdFindOption(ppd
, "PageSize")) != NULL
)
1717 num_media
+= page_size
->num_choices
;
1719 if ((media_quality
= ppdFindOption(ppd
, "EFMediaQualityMode")) != NULL
)
1720 num_media
+= media_quality
->num_choices
;
1724 cupsdLogMessage(CUPSD_LOG_CRIT
,
1725 "The PPD file for printer %s contains no media "
1726 "options and is therefore invalid!", p
->name
);
1730 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
1731 "media-supported", num_media
, NULL
, NULL
);
1736 if (input_slot
!= NULL
)
1737 for (i
= 0; i
< input_slot
->num_choices
; i
++, val
++)
1738 val
->string
.text
= _cupsStrAlloc(input_slot
->choices
[i
].choice
);
1740 if (media_type
!= NULL
)
1741 for (i
= 0; i
< media_type
->num_choices
; i
++, val
++)
1742 val
->string
.text
= _cupsStrAlloc(media_type
->choices
[i
].choice
);
1744 if (media_quality
!= NULL
)
1745 for (i
= 0; i
< media_quality
->num_choices
; i
++, val
++)
1746 val
->string
.text
= _cupsStrAlloc(media_quality
->choices
[i
].choice
);
1748 if (page_size
!= NULL
)
1750 for (i
= 0; i
< page_size
->num_choices
; i
++, val
++)
1751 val
->string
.text
= _cupsStrAlloc(page_size
->choices
[i
].choice
);
1753 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
1754 "media-default", NULL
, page_size
->defchoice
);
1756 else if (input_slot
!= NULL
)
1757 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
1758 "media-default", NULL
, input_slot
->defchoice
);
1759 else if (media_type
!= NULL
)
1760 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
1761 "media-default", NULL
, media_type
->defchoice
);
1762 else if (media_quality
!= NULL
)
1763 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
1764 "media-default", NULL
, media_quality
->defchoice
);
1766 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
1767 "media-default", NULL
, "none");
1775 if ((output_bin
= ppdFindOption(ppd
, "OutputBin")) != NULL
)
1777 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
1778 "output-bin-supported", output_bin
->num_choices
,
1783 for (i
= 0, val
= attr
->values
;
1784 i
< output_bin
->num_choices
;
1786 val
->string
.text
= _cupsStrAlloc(output_bin
->choices
[i
].choice
);
1794 if ((duplex
= ppdFindOption(ppd
, "Duplex")) == NULL
)
1795 if ((duplex
= ppdFindOption(ppd
, "EFDuplex")) == NULL
)
1796 if ((duplex
= ppdFindOption(ppd
, "EFDuplexing")) == NULL
)
1797 if ((duplex
= ppdFindOption(ppd
, "KD03Duplex")) == NULL
)
1798 duplex
= ppdFindOption(ppd
, "JCLDuplex");
1800 if (duplex
&& duplex
->num_choices
> 1)
1802 p
->type
|= CUPS_PRINTER_DUPLEX
;
1804 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
1805 "sides-supported", 3, NULL
, sides
);
1807 if (!strcasecmp(duplex
->defchoice
, "DuplexTumble"))
1808 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
1809 "sides-default", NULL
, "two-sided-short-edge");
1810 else if (!strcasecmp(duplex
->defchoice
, "DuplexNoTumble"))
1811 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
1812 "sides-default", NULL
, "two-sided-long-edge");
1814 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
1815 "sides-default", NULL
, "one-sided");
1818 if (ppdFindOption(ppd
, "Collate") != NULL
)
1819 p
->type
|= CUPS_PRINTER_COLLATE
;
1821 if (ppdFindOption(ppd
, "StapleLocation") != NULL
)
1823 p
->type
|= CUPS_PRINTER_STAPLE
;
1824 finishings
[num_finishings
++] = IPP_FINISHINGS_STAPLE
;
1827 if (ppdFindOption(ppd
, "BindEdge") != NULL
)
1829 p
->type
|= CUPS_PRINTER_BIND
;
1830 finishings
[num_finishings
++] = IPP_FINISHINGS_BIND
;
1833 for (i
= 0; i
< ppd
->num_sizes
; i
++)
1834 if (ppd
->sizes
[i
].length
> 1728)
1835 p
->type
|= CUPS_PRINTER_LARGE
;
1836 else if (ppd
->sizes
[i
].length
> 1008)
1837 p
->type
|= CUPS_PRINTER_MEDIUM
;
1839 p
->type
|= CUPS_PRINTER_SMALL
;
1842 * Add a filter from application/vnd.cups-raw to printer/name to
1843 * handle "raw" printing by users.
1846 add_printer_filter(p
, "application/vnd.cups-raw 0 -");
1849 * Add any filters in the PPD file...
1852 DEBUG_printf(("ppd->num_filters = %d\n", ppd
->num_filters
));
1853 for (i
= 0; i
< ppd
->num_filters
; i
++)
1855 DEBUG_printf(("ppd->filters[%d] = \"%s\"\n", i
, ppd
->filters
[i
]));
1856 add_printer_filter(p
, ppd
->filters
[i
]);
1859 if (ppd
->num_filters
== 0)
1862 * If there are no filters, add a PostScript printing filter.
1865 add_printer_filter(p
, "application/vnd.cups-postscript 0 -");
1869 * Show current and available port monitors for this printer...
1872 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
, "port-monitor",
1873 NULL
, p
->port_monitor
? p
->port_monitor
: "none");
1876 for (i
= 1, ppdattr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
1878 i
++, ppdattr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
));
1882 if (strstr(ppd
->protocols
, "TBCP"))
1884 else if (strstr(ppd
->protocols
, "BCP"))
1888 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
1889 "port-monitor-supported", i
, NULL
, NULL
);
1891 attr
->values
[0].string
.text
= _cupsStrAlloc("none");
1893 for (i
= 1, ppdattr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
1895 i
++, ppdattr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
))
1896 attr
->values
[i
].string
.text
= _cupsStrAlloc(ppdattr
->value
);
1900 if (strstr(ppd
->protocols
, "TBCP"))
1901 attr
->values
[i
].string
.text
= _cupsStrAlloc("tbcp");
1902 else if (strstr(ppd
->protocols
, "BCP"))
1903 attr
->values
[i
].string
.text
= _cupsStrAlloc("bcp");
1907 * Close the PPD and set the type...
1912 printer_type
= p
->type
;
1914 else if (!access(filename
, 0))
1916 int pline
; /* PPD line number */
1917 ppd_status_t pstatus
; /* PPD load status */
1920 pstatus
= ppdLastError(&pline
);
1922 cupsdLogMessage(CUPSD_LOG_ERROR
, "PPD file for %s cannot be loaded!",
1925 if (pstatus
<= PPD_ALLOC_ERROR
)
1926 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s", strerror(errno
));
1928 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s on line %d.",
1929 ppdErrorString(pstatus
), pline
);
1931 cupsdLogMessage(CUPSD_LOG_INFO
,
1932 "Hint: Run \"cupstestppd %s\" and fix any errors.",
1936 * Add a filter from application/vnd.cups-raw to printer/name to
1937 * handle "raw" printing by users.
1940 add_printer_filter(p
, "application/vnd.cups-raw 0 -");
1943 * Add a PostScript filter, since this is still possibly PS printer.
1946 add_printer_filter(p
, "application/vnd.cups-postscript 0 -");
1951 * If we have an interface script, add a filter entry for it...
1954 snprintf(filename
, sizeof(filename
), "%s/interfaces/%s", ServerRoot
,
1956 if (!access(filename
, X_OK
))
1959 * Yes, we have a System V style interface script; use it!
1962 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
1963 "printer-make-and-model", NULL
, "Local System V Printer");
1965 snprintf(filename
, sizeof(filename
), "*/* 0 %s/interfaces/%s",
1966 ServerRoot
, p
->name
);
1967 add_printer_filter(p
, filename
);
1969 else if (p
->device_uri
&&
1970 !strncmp(p
->device_uri
, "ipp://", 6) &&
1971 (strstr(p
->device_uri
, "/printers/") != NULL
||
1972 strstr(p
->device_uri
, "/classes/") != NULL
))
1975 * Tell the client this is really a hard-wired remote printer.
1978 printer_type
|= CUPS_PRINTER_REMOTE
;
1981 * Point the printer-uri-supported attribute to the
1985 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
1986 "printer-uri-supported", NULL
, p
->device_uri
);
1989 * Then set the make-and-model accordingly...
1992 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
1993 "printer-make-and-model", NULL
, "Remote Printer");
1996 * Print all files directly...
2004 * Otherwise we have neither - treat this as a "dumb" printer
2005 * with no PPD file...
2008 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
2009 "printer-make-and-model", NULL
, "Local Raw Printer");
2015 ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
2016 "finishings-supported", num_finishings
, (int *)finishings
);
2017 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
2018 "finishings-default", IPP_FINISHINGS_NONE
);
2023 * Copy the printer options into a browse attributes string we can re-use.
2026 if (!(p
->type
& CUPS_PRINTER_REMOTE
))
2028 const char *valptr
; /* Pointer into value */
2029 char *attrptr
; /* Pointer into attribute string */
2033 * Free the old browse attributes as needed...
2036 if (p
->browse_attrs
)
2037 free(p
->browse_attrs
);
2040 * Compute the length of all attributes + job-sheets, lease-duration,
2041 * and BrowseLocalOptions.
2044 for (length
= 1, i
= p
->num_options
, option
= p
->options
;
2048 length
+= strlen(option
->name
) + 2;
2052 for (valptr
= option
->value
; *valptr
; valptr
++)
2053 if (strchr(" \"\'\\", *valptr
))
2060 length
+= 13 + strlen(p
->job_sheets
[0]) + strlen(p
->job_sheets
[1]);
2062 if (BrowseLocalOptions
)
2063 length
+= 12 + strlen(BrowseLocalOptions
);
2066 * Allocate the new string...
2069 if ((p
->browse_attrs
= calloc(1, length
)) == NULL
)
2070 cupsdLogMessage(CUPSD_LOG_ERROR
,
2071 "Unable to allocate %d bytes for browse data!",
2076 * Got the allocated string, now copy the options and attributes over...
2079 sprintf(p
->browse_attrs
, "job-sheets=%s,%s lease-duration=%d",
2080 p
->job_sheets
[0], p
->job_sheets
[1], BrowseTimeout
);
2081 attrptr
= p
->browse_attrs
+ strlen(p
->browse_attrs
);
2083 if (BrowseLocalOptions
)
2085 sprintf(attrptr
, " ipp-options=%s", BrowseLocalOptions
);
2086 attrptr
+= strlen(attrptr
);
2089 for (i
= p
->num_options
, option
= p
->options
;
2094 strcpy(attrptr
, option
->name
);
2095 attrptr
+= strlen(attrptr
);
2101 for (valptr
= option
->value
; *valptr
; valptr
++)
2103 if (strchr(" \"\'\\", *valptr
))
2106 *attrptr
++ = *valptr
;
2116 * Populate the document-format-supported attribute...
2119 add_printer_formats(p
);
2121 DEBUG_printf(("cupsdSetPrinterAttrs: leaving name = %s, type = %x\n", p
->name
,
2125 * Add name-default attributes...
2128 add_printer_defaults(p
);
2132 * Write the IRIX printer config and status files...
2135 write_irix_config(p
);
2136 write_irix_state(p
);
2142 * 'cupsdSetPrinterReasons()' - Set/update the reasons strings.
2146 cupsdSetPrinterReasons(
2147 cupsd_printer_t
*p
, /* I - Printer */
2148 const char *s
) /* I - Reasons strings */
2150 int i
; /* Looping var */
2151 const char *sptr
; /* Pointer into reasons */
2152 char reason
[255], /* Reason string */
2153 *rptr
; /* Pointer into reason */
2156 if (s
[0] == '-' || s
[0] == '+')
2159 * Add/remove reasons...
2167 * Replace reasons...
2172 for (i
= 0; i
< p
->num_reasons
; i
++)
2173 free(p
->reasons
[i
]);
2179 * Loop through all of the reasons...
2185 * Skip leading whitespace and commas...
2188 while (isspace(*sptr
& 255) || *sptr
== ',')
2191 for (rptr
= reason
; *sptr
&& !isspace(*sptr
& 255) && *sptr
!= ','; sptr
++)
2192 if (rptr
< (reason
+ sizeof(reason
) - 1))
2206 for (i
= 0; i
< p
->num_reasons
; i
++)
2207 if (!strcasecmp(reason
, p
->reasons
[i
]))
2210 * Found a match, so remove it...
2214 free(p
->reasons
[i
]);
2216 if (i
< p
->num_reasons
)
2217 memmove(p
->reasons
+ i
, p
->reasons
+ i
+ 1,
2218 (p
->num_reasons
- i
) * sizeof(char *));
2223 else if (p
->num_reasons
< (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
2229 for (i
= 0; i
< p
->num_reasons
; i
++)
2230 if (!strcasecmp(reason
, p
->reasons
[i
]))
2233 if (i
>= p
->num_reasons
)
2235 p
->reasons
[i
] = strdup(reason
);
2244 * 'cupsdSetPrinterState()' - Update the current state of a printer.
2248 cupsdSetPrinterState(
2249 cupsd_printer_t
*p
, /* I - Printer to change */
2250 ipp_pstate_t s
, /* I - New state */
2251 int update
) /* I - Update printers.conf? */
2253 ipp_pstate_t old_state
; /* Old printer state */
2257 * Can't set status of remote printers...
2260 if (p
->type
& CUPS_PRINTER_REMOTE
)
2264 * Set the new state...
2267 old_state
= p
->state
;
2273 * Let the browse code know this needs to be updated...
2277 p
->state_time
= time(NULL
);
2281 write_irix_state(p
);
2285 cupsdAddPrinterHistory(p
);
2288 * Save the printer configuration if a printer goes from idle or processing
2289 * to stopped (or visa-versa)...
2292 if ((old_state
== IPP_PRINTER_STOPPED
) != (s
== IPP_PRINTER_STOPPED
) &&
2295 if (p
->type
& CUPS_PRINTER_CLASS
)
2296 cupsdSaveAllClasses();
2298 cupsdSaveAllPrinters();
2304 * 'cupsdStopPrinter()' - Stop a printer from printing any jobs...
2308 cupsdStopPrinter(cupsd_printer_t
*p
, /* I - Printer to stop */
2309 int update
)/* I - Update printers.conf? */
2311 cupsd_job_t
*job
; /* Active print job */
2315 * Set the printer state...
2318 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, update
);
2321 * See if we have a job printing on this printer...
2327 * Get pointer to job...
2330 job
= (cupsd_job_t
*)p
->job
;
2336 cupsdStopJob(job
, 0);
2339 * Reset the state to pending...
2342 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
2343 job
->state_value
= IPP_JOB_PENDING
;
2351 * 'cupsdUpdatePrinters()' - Update printers after a partial reload.
2355 cupsdUpdatePrinters(void)
2357 cupsd_printer_t
*p
; /* Current printer */
2361 * Loop through the printers and recreate the printer attributes
2362 * for any local printers since the policy and/or access control
2363 * stuff may have changed. Also, if browsing is disabled, remove
2364 * any remote printers...
2367 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
2369 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
2371 if (!Browsing
&& (p
->type
& (CUPS_PRINTER_IMPLICIT
| CUPS_PRINTER_REMOTE
)))
2373 if (p
->type
& CUPS_PRINTER_IMPLICIT
)
2374 cupsArrayRemove(ImplicitPrinters
, p
);
2376 cupsArraySave(Printers
);
2377 cupsdDeletePrinter(p
, 0);
2378 cupsArrayRestore(Printers
);
2381 else if (!(p
->type
& CUPS_PRINTER_REMOTE
))
2382 cupsdSetPrinterAttrs(p
);
2385 * Update the operation policy pointer...
2388 if ((p
->op_policy_ptr
= cupsdFindPolicy(p
->op_policy
)) == NULL
)
2389 p
->op_policy_ptr
= DefaultPolicyPtr
;
2395 * 'cupsdValidateDest()' - Validate a printer/class destination.
2398 const char * /* O - Printer or class name */
2400 const char *hostname
, /* I - Host name */
2401 const char *resource
, /* I - Resource name */
2402 cups_ptype_t
*dtype
, /* O - Type (printer or class) */
2403 cupsd_printer_t
**printer
) /* O - Printer pointer */
2405 cupsd_printer_t
*p
; /* Current printer */
2406 char localname
[1024],/* Localized hostname */
2407 *lptr
, /* Pointer into localized hostname */
2408 *sptr
; /* Pointer into server name */
2411 DEBUG_printf(("cupsdValidateDest(\"%s\", \"%s\", %p, %p)\n", hostname
, resource
,
2415 * Initialize return values...
2421 *dtype
= (cups_ptype_t
)0;
2424 * See if the resource is a class or printer...
2427 if (!strncmp(resource
, "/classes/", 9))
2435 else if (!strncmp(resource
, "/printers/", 10))
2446 * Bad resource name...
2453 * See if the printer or class name exists...
2456 p
= cupsdFindDest(resource
);
2458 if (p
== NULL
&& strchr(resource
, '@') == NULL
)
2465 *dtype
= p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
|
2466 CUPS_PRINTER_REMOTE
);
2471 * Change localhost to the server name...
2474 if (!strcasecmp(hostname
, "localhost"))
2475 hostname
= ServerName
;
2477 strlcpy(localname
, hostname
, sizeof(localname
));
2479 if (!strcasecmp(hostname
, ServerName
))
2482 * Localize the hostname...
2485 lptr
= strchr(localname
, '.');
2486 sptr
= strchr(ServerName
, '.');
2488 if (sptr
!= NULL
&& lptr
!= NULL
)
2491 * Strip the common domain name components...
2494 while (lptr
!= NULL
)
2496 if (!strcasecmp(lptr
, sptr
))
2502 lptr
= strchr(lptr
+ 1, '.');
2507 DEBUG_printf(("localized hostname is \"%s\"...\n", localname
));
2510 * Find a matching printer or class...
2513 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
2515 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
2516 if (!strcasecmp(p
->hostname
, localname
) &&
2517 !strcasecmp(p
->name
, resource
))
2522 *dtype
= p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
|
2523 CUPS_PRINTER_REMOTE
);
2532 * 'cupsdWritePrintcap()' - Write a pseudo-printcap file for older applications
2537 cupsdWritePrintcap(void)
2539 cups_file_t
*fp
; /* printcap file */
2540 cupsd_printer_t
*p
; /* Current printer */
2545 * Update the IRIX printer state for the default printer; if
2546 * no printers remain, then the default printer file will be
2550 write_irix_state(DefaultPrinter
);
2554 * See if we have a printcap file; if not, don't bother writing it.
2557 if (!Printcap
|| !*Printcap
)
2561 * Open the printcap file...
2564 if ((fp
= cupsFileOpen(Printcap
, "w")) == NULL
)
2568 * Put a comment header at the top so that users will know where the
2569 * data has come from...
2572 cupsFilePuts(fp
, "# This file was automatically generated by cupsd(8) from the\n");
2573 cupsFilePrintf(fp
, "# %s/printers.conf file. All changes to this file\n",
2575 cupsFilePuts(fp
, "# will be lost.\n");
2580 * Write a new printcap with the current list of printers.
2583 switch (PrintcapFormat
)
2587 * Each printer is put in the file as:
2597 cupsFilePrintf(fp
, "%s|%s:rm=%s:rp=%s:\n", DefaultPrinter
->name
,
2598 DefaultPrinter
->info
, ServerName
, DefaultPrinter
->name
);
2600 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
2602 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
2603 if (p
!= DefaultPrinter
)
2604 cupsFilePrintf(fp
, "%s|%s:rm=%s:rp=%s:\n", p
->name
, p
->info
,
2605 ServerName
, p
->name
);
2608 case PRINTCAP_SOLARIS
:
2610 * Each printer is put in the file as:
2612 * _all:all=Printer1,Printer2,Printer3,...,PrinterN
2613 * _default:use=DefaultPrinter
2615 * :bsdaddr=ServerName,Printer1:\
2616 * :description=Description:
2618 * :bsdaddr=ServerName,Printer2:\
2619 * :description=Description:
2621 * :bsdaddr=ServerName,Printer3:\
2622 * :description=Description:
2625 * :bsdaddr=ServerName,PrinterN:\
2626 * :description=Description:
2629 cupsFilePuts(fp
, "_all:all=");
2630 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
2632 p
= (cupsd_printer_t
*)cupsArrayCurrent(Printers
))
2633 cupsFilePrintf(fp
, "%s%c", p
->name
,
2634 cupsArrayNext(Printers
) ? ',' : '\n');
2637 cupsFilePrintf(fp
, "_default:use=%s\n", DefaultPrinter
->name
);
2639 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
2641 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
2642 cupsFilePrintf(fp
, "%s:\\\n"
2643 "\t:bsdaddr=%s,%s:\\\n"
2644 "\t:description=%s:\n",
2645 p
->name
, ServerName
, p
->name
, p
->info
? p
->info
: "");
2659 * 'cupsdSanitizeURI()' - Sanitize a device URI...
2662 char * /* O - New device URI */
2663 cupsdSanitizeURI(const char *uri
, /* I - Original device URI */
2664 char *buffer
, /* O - New device URI */
2665 int buflen
) /* I - Size of new device URI buffer */
2667 char *start
, /* Start of data after scheme */
2668 *slash
, /* First slash after scheme:// */
2669 *ptr
; /* Pointer into user@host:port part */
2673 * Range check input...
2676 if (!uri
|| !buffer
|| buflen
< 2)
2680 * Copy the device URI to the new buffer...
2683 strlcpy(buffer
, uri
, buflen
);
2686 * Find the end of the scheme:// part...
2689 if ((ptr
= strchr(buffer
, ':')) == NULL
)
2690 return (buffer
); /* No scheme: part... */
2692 for (start
= ptr
+ 1; *start
; start
++)
2697 * Find the next slash (/) in the URI...
2700 if ((slash
= strchr(start
, '/')) == NULL
)
2701 slash
= start
+ strlen(start
); /* No slash, point to the end */
2704 * Check for an @ sign before the slash...
2707 if ((ptr
= strchr(start
, '@')) != NULL
&& ptr
< slash
)
2710 * Found an @ sign and it is before the resource part, so we have
2711 * an authentication string. Copy the remaining URI over the
2712 * authentication string...
2715 _cups_strcpy(start
, ptr
+ 1);
2719 * Return the new device URI...
2727 * 'add_printer_defaults()' - Add name-default attributes to the printer attributes.
2731 add_printer_defaults(cupsd_printer_t
*p
)/* I - Printer */
2733 int i
; /* Looping var */
2734 int num_options
; /* Number of default options */
2735 cups_option_t
*options
, /* Default options */
2736 *option
; /* Current option */
2737 char name
[256]; /* name-default */
2741 * Add all of the default options from the .conf files...
2744 for (num_options
= 0, i
= p
->num_options
, option
= p
->options
;
2748 if (strcmp(option
->name
, "ipp-options") &&
2749 strcmp(option
->name
, "job-sheets") &&
2750 strcmp(option
->name
, "lease-duration"))
2752 snprintf(name
, sizeof(name
), "%s-default", option
->name
);
2753 num_options
= cupsAddOption(name
, option
->value
, num_options
, &options
);
2758 * Convert options to IPP attributes...
2761 cupsEncodeOptions2(p
->attrs
, num_options
, options
, IPP_TAG_PRINTER
);
2762 cupsFreeOptions(num_options
, options
);
2765 * Add standard -default attributes as needed...
2768 if (!cupsGetOption("copies", p
->num_options
, p
->options
))
2769 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
, "copies-default",
2772 if (!cupsGetOption("job-hold-until", p
->num_options
, p
->options
))
2773 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2774 "job-hold-until-default", NULL
, "no-hold");
2776 if (!cupsGetOption("job-priority", p
->num_options
, p
->options
))
2777 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2778 "job-priority-default", 50);
2780 if (!cupsGetOption("number-up", p
->num_options
, p
->options
))
2781 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2782 "number-up-default", 1);
2784 if (!cupsGetOption("orientation-requested", p
->num_options
, p
->options
))
2785 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
2786 "orientation-requested-default", IPP_PORTRAIT
);
2791 * 'add_printer_filter()' - Add a MIME filter for a printer.
2796 cupsd_printer_t
*p
, /* I - Printer to add to */
2797 const char *filter
) /* I - Filter to add */
2799 char super
[MIME_MAX_SUPER
], /* Super-type for filter */
2800 type
[MIME_MAX_TYPE
], /* Type for filter */
2801 program
[1024]; /* Program/filter name */
2802 int cost
; /* Cost of filter */
2803 mime_type_t
*temptype
; /* MIME type looping var */
2804 char filename
[1024]; /* Full filter filename */
2808 * Parse the filter string; it should be in the following format:
2810 * super/type cost program
2813 if (sscanf(filter
, "%15[^/]/%31s%d%1023s", super
, type
, &cost
, program
) != 4)
2815 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: invalid filter string \"%s\"!",
2821 * See if the filter program exists; if not, stop the printer and flag
2825 if (strcmp(program
, "-"))
2827 if (program
[0] == '/')
2828 strlcpy(filename
, program
, sizeof(filename
));
2830 snprintf(filename
, sizeof(filename
), "%s/filter/%s", ServerBin
, program
);
2832 if (access(filename
, X_OK
))
2834 snprintf(p
->state_message
, sizeof(p
->state_message
),
2835 "Filter \"%s\" for printer \"%s\" not available: %s",
2836 program
, p
->name
, strerror(errno
));
2837 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, 0);
2838 cupsdSetPrinterReasons(p
, "+cups-missing-filter-error");
2839 cupsdAddPrinterHistory(p
);
2841 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s", p
->state_message
);
2846 * Mark the CUPS_PRINTER_COMMANDS bit if we have a filter for
2847 * application/vnd.cups-command...
2850 if (!strcasecmp(super
, "application") &&
2851 !strcasecmp(type
, "vnd.cups-command"))
2852 p
->type
|= CUPS_PRINTER_COMMANDS
;
2855 * Add the filter to the MIME database, supporting wildcards as needed...
2858 for (temptype
= mimeFirstType(MimeDatabase
);
2860 temptype
= mimeNextType(MimeDatabase
))
2861 if (((super
[0] == '*' && strcasecmp(temptype
->super
, "printer")) ||
2862 !strcasecmp(temptype
->super
, super
)) &&
2863 (type
[0] == '*' || !strcasecmp(temptype
->type
, type
)))
2865 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
2866 "add_printer_filter: %s: adding filter %s/%s %s/%s %d %s",
2867 p
->name
, temptype
->super
, temptype
->type
,
2868 p
->filetype
->super
, p
->filetype
->type
,
2870 mimeAddFilter(MimeDatabase
, temptype
, p
->filetype
, cost
, program
);
2876 * 'add_printer_formats()' - Add document-format-supported values for a printer.
2880 add_printer_formats(cupsd_printer_t
*p
) /* I - Printer */
2882 int i
; /* Looping var */
2883 mime_type_t
*type
; /* Current MIME type */
2884 cups_array_t
*filters
; /* Filters */
2885 int num_types
; /* Number of supported types */
2886 const char **types
; /* Array of supported type names */
2887 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
2888 /* MIME type name */
2892 * Raw (and remote) queues advertise all of the supported MIME
2898 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
,
2899 (ipp_tag_t
)(IPP_TAG_MIMETYPE
| IPP_TAG_COPY
),
2900 "document-format-supported", NumMimeTypes
, NULL
, MimeTypes
);
2905 * Otherwise, loop through the supported MIME types and see if there
2906 * are filters for them...
2909 if ((types
= calloc(NumMimeTypes
, sizeof(char *))) == NULL
)
2911 cupsdLogMessage(CUPSD_LOG_EMERG
,
2912 "Unable to allocate memory for \"%s\" MIME type list!",
2917 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_printer_formats: %d types, %d filters",
2918 mimeNumTypes(MimeDatabase
), mimeNumFilters(MimeDatabase
));
2920 types
[0] = _cupsStrAlloc("application/octet-stream");
2922 for (num_types
= 1, type
= mimeFirstType(MimeDatabase
);
2924 type
= mimeNextType(MimeDatabase
))
2926 if (!strcasecmp(type
->super
, "application") &&
2927 !strcasecmp(type
->type
, "octet-stream"))
2930 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
2932 if ((filters
= mimeFilter(MimeDatabase
, type
, p
->filetype
, NULL
)) != NULL
)
2934 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
2935 "add_printer_formats: %s: %s needs %d filters",
2936 p
->name
, mimetype
, cupsArrayCount(filters
));
2938 cupsArrayDelete(filters
);
2939 types
[num_types
] = _cupsStrAlloc(mimetype
);
2943 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
2944 "add_printer_formats: %s: %s not supported",
2948 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
2949 "add_printer_formats: %s: %d supported types",
2950 p
->name
, num_types
);
2953 * Add the file formats that can be filtered...
2956 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_MIMETYPE
,
2957 "document-format-supported", num_types
, NULL
, types
);
2960 * Free the temporary data...
2963 for (i
= 0; i
< num_types
; i
++)
2964 _cupsStrFree(types
[i
]);
2971 * 'compare_printers()' - Compare two printers.
2974 static int /* O - Result of comparison */
2975 compare_printers(void *first
, /* I - First printer */
2976 void *second
, /* I - Second printer */
2977 void *data
) /* I - App data (not used) */
2979 return (strcasecmp(((cupsd_printer_t
*)first
)->name
,
2980 ((cupsd_printer_t
*)second
)->name
));
2985 * 'delete_printer_filters()' - Delete all MIME filters for a printer.
2989 delete_printer_filters(
2990 cupsd_printer_t
*p
) /* I - Printer to remove from */
2992 mime_filter_t
*filter
; /* MIME filter looping var */
2996 * Range check input...
3003 * Remove all filters from the MIME database that have a destination
3004 * type == printer...
3007 for (filter
= mimeFirstFilter(MimeDatabase
);
3009 filter
= mimeNextFilter(MimeDatabase
))
3010 if (filter
->dst
== p
->filetype
)
3013 * Delete the current filter...
3016 mimeDeleteFilter(MimeDatabase
, filter
);
3023 * 'write_irix_config()' - Update the config files used by the IRIX
3028 write_irix_config(cupsd_printer_t
*p
) /* I - Printer to update */
3030 char filename
[1024]; /* Interface script filename */
3031 cups_file_t
*fp
; /* Interface script file */
3036 * Add dummy interface and GUI scripts to fool SGI's "challenged" printing
3037 * tools. First the interface script that tells the tools what kind of
3038 * printer we have...
3041 snprintf(filename
, sizeof(filename
), "/var/spool/lp/interface/%s", p
->name
);
3043 if (p
->type
& CUPS_PRINTER_CLASS
)
3045 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
3047 cupsFilePuts(fp
, "#!/bin/sh\n");
3049 if ((attr
= ippFindAttribute(p
->attrs
, "printer-make-and-model",
3050 IPP_TAG_TEXT
)) != NULL
)
3051 cupsFilePrintf(fp
, "NAME=\"%s\"\n", attr
->values
[0].string
.text
);
3052 else if (p
->type
& CUPS_PRINTER_CLASS
)
3053 cupsFilePuts(fp
, "NAME=\"Printer Class\"\n");
3055 cupsFilePuts(fp
, "NAME=\"Remote Destination\"\n");
3057 if (p
->type
& CUPS_PRINTER_COLOR
)
3058 cupsFilePuts(fp
, "TYPE=ColorPostScript\n");
3060 cupsFilePuts(fp
, "TYPE=MonoPostScript\n");
3062 cupsFilePrintf(fp
, "HOSTNAME=%s\n", ServerName
);
3063 cupsFilePrintf(fp
, "HOSTPRINTER=%s\n", p
->name
);
3067 chmod(filename
, 0755);
3068 chown(filename
, User
, Group
);
3072 * Then the member file that tells which device file the queue is connected
3073 * to... Networked printers use "/dev/null" in this file, so that's what
3074 * we use (the actual device URI can confuse some apps...)
3077 snprintf(filename
, sizeof(filename
), "/var/spool/lp/member/%s", p
->name
);
3079 if (p
->type
& CUPS_PRINTER_CLASS
)
3081 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
3083 cupsFilePuts(fp
, "/dev/null\n");
3087 chmod(filename
, 0644);
3088 chown(filename
, User
, Group
);
3092 * The gui_interface file is a script or program that launches a GUI
3093 * option panel for the printer, using options specified on the
3094 * command-line in the third argument. The option panel must send
3095 * any printing options to stdout on a single line when the user
3096 * accepts them, or nothing if the user cancels the dialog.
3098 * The default options panel program is /usr/bin/glpoptions, from
3099 * the ESP Print Pro software. You can select another using the
3100 * PrintcapGUI option.
3103 snprintf(filename
, sizeof(filename
), "/var/spool/lp/gui_interface/ELF/%s.gui", p
->name
);
3105 if (p
->type
& CUPS_PRINTER_CLASS
)
3107 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
3109 cupsFilePuts(fp
, "#!/bin/sh\n");
3110 cupsFilePrintf(fp
, "%s -d %s -o \"$3\"\n", PrintcapGUI
, p
->name
);
3114 chmod(filename
, 0755);
3115 chown(filename
, User
, Group
);
3119 * The POD config file is needed by the printstatus command to show
3120 * the printer location and device.
3123 snprintf(filename
, sizeof(filename
), "/var/spool/lp/pod/%s.config", p
->name
);
3125 if (p
->type
& CUPS_PRINTER_CLASS
)
3127 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
3129 cupsFilePrintf(fp
, "Printer Class | %s\n",
3130 (p
->type
& CUPS_PRINTER_COLOR
) ? "ColorPostScript" : "MonoPostScript");
3131 cupsFilePrintf(fp
, "Printer Model | %s\n", p
->make_model
? p
->make_model
: "");
3132 cupsFilePrintf(fp
, "Location Code | %s\n", p
->location
? p
->location
: "");
3133 cupsFilePrintf(fp
, "Physical Location | %s\n", p
->info
? p
->info
: "");
3134 cupsFilePrintf(fp
, "Port Path | %s\n", p
->device_uri
? p
->device_uri
: "");
3135 cupsFilePrintf(fp
, "Config Path | /var/spool/lp/pod/%s.config\n", p
->name
);
3136 cupsFilePrintf(fp
, "Active Status Path | /var/spool/lp/pod/%s.status\n", p
->name
);
3137 cupsFilePuts(fp
, "Status Update Wait | 10 seconds\n");
3141 chmod(filename
, 0664);
3142 chown(filename
, User
, Group
);
3148 * 'write_irix_state()' - Update the status files used by IRIX printing
3153 write_irix_state(cupsd_printer_t
*p
) /* I - Printer to update */
3155 char filename
[1024]; /* Interface script filename */
3156 cups_file_t
*fp
; /* Interface script file */
3157 int tag
; /* Status tag value */
3163 * The POD status file is needed for the printstatus window to
3164 * provide the current status of the printer.
3167 snprintf(filename
, sizeof(filename
), "/var/spool/lp/pod/%s.status", p
->name
);
3169 if (p
->type
& CUPS_PRINTER_CLASS
)
3171 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
3173 cupsFilePrintf(fp
, "Operational Status | %s\n",
3174 (p
->state
== IPP_PRINTER_IDLE
) ? "Idle" :
3175 (p
->state
== IPP_PRINTER_PROCESSING
) ? "Busy" :
3177 cupsFilePrintf(fp
, "Information | 01 00 00 | %s\n", CUPS_SVERSION
);
3178 cupsFilePrintf(fp
, "Information | 02 00 00 | Device URI: %s\n",
3179 p
->device_uri
? p
->device_uri
: "");
3180 cupsFilePrintf(fp
, "Information | 03 00 00 | %s jobs\n",
3181 p
->accepting
? "Accepting" : "Not accepting");
3182 cupsFilePrintf(fp
, "Information | 04 00 00 | %s\n", p
->state_message
);
3186 chmod(filename
, 0664);
3187 chown(filename
, User
, Group
);
3191 * The activeicons file is needed to provide desktop icons for printers:
3193 * [ quoted from /usr/lib/print/tagit ]
3195 * --- Type of printer tags (base values)
3197 * Dumb=66048 # 0x10200
3198 * DumbColor=66080 # 0x10220
3199 * Raster=66112 # 0x10240
3200 * ColorRaster=66144 # 0x10260
3201 * Plotter=66176 # 0x10280
3202 * PostScript=66208 # 0x102A0
3203 * ColorPostScript=66240 # 0x102C0
3204 * MonoPostScript=66272 # 0x102E0
3206 * --- Printer state modifiers for local printers
3211 * Unknown=3 # 0x3 (Faulted due to unknown reason)
3213 * --- Printer state modifiers for network printers
3217 * NetFaulted=10 # 0xA
3218 * NetUnknown=11 # 0xB (Faulted due to unknown reason)
3221 snprintf(filename
, sizeof(filename
), "/var/spool/lp/activeicons/%s", p
->name
);
3223 if (p
->type
& CUPS_PRINTER_CLASS
)
3225 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
3227 if (p
->type
& CUPS_PRINTER_COLOR
)
3232 if (p
->type
& CUPS_PRINTER_REMOTE
)
3235 if (p
->state
== IPP_PRINTER_PROCESSING
)
3238 else if (p
->state
== IPP_PRINTER_STOPPED
)
3241 cupsFilePuts(fp
, "#!/bin/sh\n");
3242 cupsFilePrintf(fp
, "#Tag %d\n", tag
);
3246 chmod(filename
, 0755);
3247 chown(filename
, User
, Group
);
3252 * The default file is needed by the printers window to show
3253 * the default printer.
3256 snprintf(filename
, sizeof(filename
), "/var/spool/lp/default");
3258 if (DefaultPrinter
!= NULL
)
3260 if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
3262 cupsFilePrintf(fp
, "%s\n", DefaultPrinter
->name
);
3266 chmod(filename
, 0644);
3267 chown(filename
, User
, Group
);
3277 * End of "$Id: printers.c 5305 2006-03-18 03:05:12Z mike $".