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...
72 static void add_printer_defaults(cupsd_printer_t
*p
);
73 static void add_printer_filter(cupsd_printer_t
*p
, const char *filter
);
74 static void add_printer_formats(cupsd_printer_t
*p
);
75 static int compare_printers(void *first
, void *second
, void *data
);
76 static void delete_printer_filters(cupsd_printer_t
*p
);
78 static void write_irix_config(cupsd_printer_t
*p
);
79 static void write_irix_state(cupsd_printer_t
*p
);
84 * 'cupsdAddPrinter()' - Add a printer to the system.
87 cupsd_printer_t
* /* O - New printer */
88 cupsdAddPrinter(const char *name
) /* I - Name of printer */
90 cupsd_printer_t
*p
; /* New printer */
94 * Range check input...
97 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdAddPrinter(\"%s\")", name
);
100 * Create a new printer entity...
103 if ((p
= calloc(1, sizeof(cupsd_printer_t
))) == NULL
)
105 cupsdLogMessage(CUPSD_LOG_CRIT
, "Unable to allocate memory for printer - %s",
110 cupsdSetString(&p
->name
, name
);
111 cupsdSetString(&p
->info
, name
);
112 cupsdSetString(&p
->hostname
, ServerName
);
114 cupsdSetStringf(&p
->uri
, "ipp://%s:%d/printers/%s", ServerName
, LocalPort
, name
);
115 cupsdSetStringf(&p
->device_uri
, "file:/dev/null");
117 p
->state
= IPP_PRINTER_STOPPED
;
118 p
->state_time
= time(NULL
);
120 p
->shared
= DefaultShared
;
121 p
->filetype
= mimeAddType(MimeDatabase
, "printer", name
);
123 cupsdSetString(&p
->job_sheets
[0], "none");
124 cupsdSetString(&p
->job_sheets
[1], "none");
126 cupsdSetString(&p
->error_policy
, "stop-printer");
127 cupsdSetString(&p
->op_policy
, DefaultPolicy
);
129 p
->op_policy_ptr
= DefaultPolicyPtr
;
131 if (MaxPrinterHistory
)
132 p
->history
= calloc(MaxPrinterHistory
, sizeof(ipp_t
*));
135 * Insert the printer in the printer list alphabetically...
139 Printers
= cupsArrayNew(compare_printers
, NULL
);
141 cupsArrayAdd(Printers
, p
);
143 if (!ImplicitPrinters
)
144 ImplicitPrinters
= cupsArrayNew(compare_printers
, NULL
);
147 * Return the new printer...
155 * 'cupsdAddPrinterHistory()' - Add the current printer state to the history.
159 cupsdAddPrinterHistory(
160 cupsd_printer_t
*p
) /* I - Printer */
162 ipp_t
*history
; /* History collection */
166 * Stop early if we aren't keeping history data...
169 if (MaxPrinterHistory
<= 0)
173 * Retire old history data as needed...
176 p
->sequence_number
++;
178 if (p
->num_history
>= MaxPrinterHistory
)
181 ippDelete(p
->history
[0]);
182 memmove(p
->history
, p
->history
+ 1, p
->num_history
* sizeof(ipp_t
*));
186 * Create a collection containing the current printer-state, printer-up-time,
187 * printer-state-message, and printer-state-reasons attributes.
191 ippAddInteger(history
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-state",
193 ippAddBoolean(history
, IPP_TAG_PRINTER
, "printer-is-accepting-jobs",
195 ippAddBoolean(history
, IPP_TAG_PRINTER
, "printer-is-shared", p
->shared
);
196 ippAddString(history
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-state-message",
197 NULL
, p
->state_message
);
200 ippAddString(history
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
201 "com.apple.print.recoverable-message", NULL
, p
->recoverable
);
202 #endif /* __APPLE__ */
203 if (p
->num_reasons
== 0)
204 ippAddString(history
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
205 "printer-state-reasons", NULL
,
206 p
->state
== IPP_PRINTER_STOPPED
? "paused" : "none");
208 ippAddStrings(history
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
209 "printer-state-reasons", p
->num_reasons
, NULL
,
210 (const char * const *)p
->reasons
);
211 ippAddInteger(history
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
212 "printer-state-change-time", p
->state_time
);
213 ippAddInteger(history
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
214 "printer-state-sequence-number", p
->sequence_number
);
216 p
->history
[p
->num_history
] = history
;
222 * 'cupsdAddPrinterUser()' - Add a user to the ACL.
227 cupsd_printer_t
*p
, /* I - Printer */
228 const char *username
) /* I - User */
230 const char **temp
; /* Temporary array pointer */
236 if (p
->num_users
== 0)
237 temp
= malloc(sizeof(char **));
239 temp
= realloc(p
->users
, sizeof(char **) * (p
->num_users
+ 1));
245 temp
+= p
->num_users
;
247 if ((*temp
= strdup(username
)) != NULL
)
253 * 'cupsdCreateCommonData()' - Create the common printer data.
257 cupsdCreateCommonData(void)
259 int i
; /* Looping var */
260 ipp_attribute_t
*attr
; /* Attribute data */
261 cups_dir_t
*dir
; /* Notifier directory */
262 cups_dentry_t
*dent
; /* Notifier directory entry */
263 cups_array_t
*notifiers
; /* Notifier array */
264 char filename
[1024], /* Filename */
265 *notifier
; /* Current notifier */
266 static const int nups
[] = /* number-up-supported values */
267 { 1, 2, 4, 6, 9, 16 };
268 static const ipp_orient_t orients
[4] =/* orientation-requested-supported values */
272 IPP_REVERSE_LANDSCAPE
,
275 static const char * const holds
[] = /* job-hold-until-supported values */
286 static const char * const versions
[] =/* ipp-versions-supported values */
291 static const ipp_op_t ops
[] = /* operations-supported values */
298 IPP_GET_JOB_ATTRIBUTES
,
300 IPP_GET_PRINTER_ATTRIBUTES
,
306 IPP_SET_JOB_ATTRIBUTES
,
307 IPP_CREATE_PRINTER_SUBSCRIPTION
,
308 IPP_CREATE_JOB_SUBSCRIPTION
,
309 IPP_GET_SUBSCRIPTION_ATTRIBUTES
,
310 IPP_GET_SUBSCRIPTIONS
,
311 IPP_RENEW_SUBSCRIPTION
,
312 IPP_CANCEL_SUBSCRIPTION
,
313 IPP_GET_NOTIFICATIONS
,
329 CUPS_AUTHENTICATE_JOB
,
332 static const char * const charsets
[] =/* charset-supported values */
337 static const char * const compressions
[] =
338 { /* document-compression-supported values */
342 #endif /* HAVE_LIBZ */
344 static const char * const multiple_document_handling
[] =
345 { /* multiple-document-handling-supported values */
346 "separate-documents-uncollated-copies",
347 "separate-documents-collated-copies"
349 static const char * const errors
[] = /* printer-error-policy-supported values */
355 static const char * const notify_attrs
[] =
356 { /* notify-attributes-supported values */
357 "printer-state-change-time",
358 "notify-lease-expiration-time",
359 "notify-subscriber-user-name"
361 static const char * const notify_events
[] =
362 { /* notify-events-supported values */
364 "job-config-changed",
371 "printer-config-changed",
373 "printer-finishings-changed",
374 "printer-media-changed",
378 "printer-state-changed",
388 ippDelete(CommonData
);
390 CommonData
= ippNew();
393 * This list of attributes is sorted to improve performance when the
394 * client provides a requested-attributes attribute...
397 /* charset-configured */
398 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_CHARSET
,
399 "charset-configured", NULL
, DefaultCharset
);
401 /* charset-supported */
402 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_CHARSET
,
403 "charset-supported", sizeof(charsets
) / sizeof(charsets
[0]),
406 /* compression-supported */
407 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
408 "compression-supported",
409 sizeof(compressions
) / sizeof(compressions
[0]),
412 /* copies-supported */
413 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "copies-supported", 1, MaxCopies
);
415 /* generated-natural-language-supported */
416 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_LANGUAGE
,
417 "generated-natural-language-supported", NULL
, DefaultLanguage
);
419 /* ipp-versions-supported */
420 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
421 "ipp-versions-supported", sizeof(versions
) / sizeof(versions
[0]),
424 /* job-hold-until-supported */
425 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
426 "job-hold-until-supported", sizeof(holds
) / sizeof(holds
[0]),
429 /* job-priority-supported */
430 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
431 "job-priority-supported", 100);
433 /* job-sheets-supported */
434 if (cupsArrayCount(Banners
) > 0)
437 * Setup the job-sheets-supported attribute...
440 if (Classification
&& !ClassifyOverride
)
441 attr
= ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
442 "job-sheets-supported", NULL
, Classification
);
444 attr
= ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
445 "job-sheets-supported", cupsArrayCount(Banners
) + 1,
449 cupsdLogMessage(CUPSD_LOG_EMERG
,
450 "Unable to allocate memory for "
451 "job-sheets-supported attribute: %s!", strerror(errno
));
452 else if (!Classification
|| ClassifyOverride
)
454 cupsd_banner_t
*banner
; /* Current banner */
457 attr
->values
[0].string
.text
= _cupsStrAlloc("none");
459 for (i
= 1, banner
= (cupsd_banner_t
*)cupsArrayFirst(Banners
);
461 i
++, banner
= (cupsd_banner_t
*)cupsArrayNext(Banners
))
462 attr
->values
[i
].string
.text
= _cupsStrAlloc(banner
->name
);
466 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
467 "job-sheets-supported", NULL
, "none");
469 /* multiple-document-handling-supported */
470 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
471 "multiple-document-handling-supported",
472 sizeof(multiple_document_handling
) /
473 sizeof(multiple_document_handling
[0]), NULL
,
474 multiple_document_handling
);
476 /* multiple-document-jobs-supported */
477 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
,
478 "multiple-document-jobs-supported", 1);
480 /* multiple-operation-time-out */
481 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
482 "multiple-operation-time-out", 60);
484 /* natural-language-configured */
485 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_LANGUAGE
,
486 "natural-language-configured", NULL
, DefaultLanguage
);
488 /* notify-attributes-supported */
489 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
490 "notify-attributes-supported",
491 (int)(sizeof(notify_attrs
) / sizeof(notify_attrs
[0])),
494 /* notify-lease-duration-default */
495 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
496 "notify-lease-duration-default", DefaultLeaseDuration
);
498 /* notify-lease-duration-supported */
499 ippAddRange(CommonData
, IPP_TAG_PRINTER
,
500 "notify-lease-duration-supported", 0,
501 MaxLeaseDuration
? MaxLeaseDuration
: 2147483647);
503 /* notify-max-events-supported */
504 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
505 "notify-max-events-supported", MaxEvents
);
507 /* notify-events-default */
508 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
509 "notify-events-default", NULL
, "job-completed");
511 /* notify-events-supported */
512 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
513 "notify-events-supported",
514 (int)(sizeof(notify_events
) / sizeof(notify_events
[0])),
515 NULL
, notify_events
);
517 /* notify-pull-method-supported */
518 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
519 "notify-pull-method-supported", NULL
, "ippget");
521 /* notify-schemes-supported */
522 snprintf(filename
, sizeof(filename
), "%s/notifier", ServerBin
);
523 if ((dir
= cupsDirOpen(filename
)) != NULL
)
525 notifiers
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
527 while ((dent
= cupsDirRead(dir
)) != NULL
)
528 if (S_ISREG(dent
->fileinfo
.st_mode
) &&
529 (dent
->fileinfo
.st_mode
& S_IXOTH
) != 0)
530 cupsArrayAdd(notifiers
, _cupsStrAlloc(dent
->filename
));
532 if (cupsArrayCount(notifiers
) > 0)
534 attr
= ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
535 "notify-schemes-supported",
536 cupsArrayCount(notifiers
), NULL
, NULL
);
538 for (i
= 0, notifier
= (char *)cupsArrayFirst(notifiers
);
540 i
++, notifier
= (char *)cupsArrayNext(notifiers
))
541 attr
->values
[i
].string
.text
= notifier
;
544 cupsArrayDelete(notifiers
);
547 /* number-up-supported */
548 ippAddIntegers(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
549 "number-up-supported", sizeof(nups
) / sizeof(nups
[0]), nups
);
551 /* operations-supported */
552 ippAddIntegers(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
553 "operations-supported",
554 sizeof(ops
) / sizeof(ops
[0]) + JobFiles
- 1, (int *)ops
);
556 /* orientation-requested-supported */
557 ippAddIntegers(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
558 "orientation-requested-supported", 4, (int *)orients
);
560 /* page-ranges-supported */
561 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
, "page-ranges-supported", 1);
563 /* pdf-override-supported */
564 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
565 "pdl-override-supported", NULL
, "not-attempted");
567 /* printer-error-policy-supported */
568 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
569 "printer-error-policy-supported",
570 sizeof(errors
) / sizeof(errors
[0]), NULL
, errors
);
572 /* printer-op-policy-supported */
573 attr
= ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
574 "printer-op-policy-supported", NumPolicies
, NULL
, NULL
);
575 for (i
= 0; i
< NumPolicies
; i
++)
576 attr
->values
[i
].string
.text
= _cupsStrAlloc(Policies
[i
]->name
);
581 * 'cupsdDeleteAllPrinters()' - Delete all printers from the system.
585 cupsdDeleteAllPrinters(void)
587 cupsd_printer_t
*p
; /* Pointer to current printer/class */
590 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
592 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
593 if (!(p
->type
& CUPS_PRINTER_CLASS
))
594 cupsdDeletePrinter(p
, 0);
599 * 'cupsdDeletePrinter()' - Delete a printer from the system.
604 cupsd_printer_t
*p
, /* I - Printer to delete */
605 int update
) /* I - Update printers.conf? */
607 int i
; /* Looping var */
609 char filename
[1024]; /* Interface script filename */
613 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdDeletePrinter(p=%p(%s), update=%d)",
617 * Save the current position in the Printers array...
620 cupsArraySave(Printers
);
623 * Stop printing on this printer...
626 cupsdStopPrinter(p
, update
);
629 * If this printer is the next for browsing, point to the next one...
634 cupsArrayFind(Printers
, p
);
635 BrowseNext
= (cupsd_printer_t
*)cupsArrayNext(Printers
);
639 * Remove the printer from the list...
642 cupsArrayRemove(Printers
, p
);
645 * Remove the dummy interface/icon/option files under IRIX...
649 snprintf(filename
, sizeof(filename
), "/var/spool/lp/interface/%s", p
->name
);
652 snprintf(filename
, sizeof(filename
), "/var/spool/lp/gui_interface/ELF/%s.gui",
656 snprintf(filename
, sizeof(filename
), "/var/spool/lp/activeicons/%s", p
->name
);
659 snprintf(filename
, sizeof(filename
), "/var/spool/lp/pod/%s.config", p
->name
);
662 snprintf(filename
, sizeof(filename
), "/var/spool/lp/pod/%s.status", p
->name
);
665 snprintf(filename
, sizeof(filename
), "/var/spool/lp/member/%s", p
->name
);
670 * If p is the default printer, assign a different one...
673 if (p
== DefaultPrinter
)
675 DefaultPrinter
= NULL
;
677 if (UseNetworkDefault
)
680 * Find the first network default printer and use it...
683 cupsd_printer_t
*dp
; /* New default printer */
686 for (dp
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
688 dp
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
689 if (dp
!= p
&& (dp
->type
& CUPS_PRINTER_DEFAULT
))
698 * Remove this printer from any classes and send a browse delete message...
701 if (!(p
->type
& CUPS_PRINTER_IMPLICIT
))
703 cupsdDeletePrinterFromClasses(p
);
704 cupsdSendBrowseDelete(p
);
708 * Free all memory used by the printer...
711 if (p
->printers
!= NULL
)
714 if (MaxPrinterHistory
)
716 for (i
= 0; i
< p
->num_history
; i
++)
717 ippDelete(p
->history
[i
]);
722 for (i
= 0; i
< p
->num_reasons
; i
++)
727 delete_printer_filters(p
);
729 mimeDeleteType(MimeDatabase
, p
->filetype
);
731 cupsdFreePrinterUsers(p
);
734 cupsdClearString(&p
->uri
);
735 cupsdClearString(&p
->hostname
);
736 cupsdClearString(&p
->name
);
737 cupsdClearString(&p
->location
);
738 cupsdClearString(&p
->make_model
);
739 cupsdClearString(&p
->info
);
740 cupsdClearString(&p
->job_sheets
[0]);
741 cupsdClearString(&p
->job_sheets
[1]);
742 cupsdClearString(&p
->device_uri
);
743 cupsdClearString(&p
->port_monitor
);
744 cupsdClearString(&p
->op_policy
);
745 cupsdClearString(&p
->error_policy
);
747 cupsArrayDelete(p
->filetypes
);
750 free(p
->browse_attrs
);
753 cupsdClearString(&p
->recoverable
);
754 #endif /* __APPLE__ */
756 cupsFreeOptions(p
->num_options
, p
->options
);
761 * Restore the previous position in the Printers array...
764 cupsArrayRestore(Printers
);
769 * 'cupsdFindDest()' - Find a destination in the list.
772 cupsd_printer_t
* /* O - Destination in list */
773 cupsdFindDest(const char *name
) /* I - Name of printer or class to find */
775 cupsd_printer_t key
; /* Search key */
778 key
.name
= (char *)name
;
779 return ((cupsd_printer_t
*)cupsArrayFind(Printers
, &key
));
784 * 'cupsdFindPrinter()' - Find a printer in the list.
787 cupsd_printer_t
* /* O - Printer in list */
788 cupsdFindPrinter(const char *name
) /* I - Name of printer to find */
790 cupsd_printer_t
*p
; /* Printer in list */
793 if ((p
= cupsdFindDest(name
)) != NULL
&& (p
->type
& CUPS_PRINTER_CLASS
))
801 * 'cupsdFreePrinterUsers()' - Free allow/deny users.
805 cupsdFreePrinterUsers(
806 cupsd_printer_t
*p
) /* I - Printer */
808 int i
; /* Looping var */
811 if (!p
|| !p
->num_users
)
814 for (i
= 0; i
< p
->num_users
; i
++)
815 free((void *)p
->users
[i
]);
825 * 'cupsdLoadAllPrinters()' - Load printers from the printers.conf file.
829 cupsdLoadAllPrinters(void)
831 cups_file_t
*fp
; /* printers.conf file */
832 int linenum
; /* Current line number */
833 char line
[1024], /* Line from file */
834 *value
, /* Pointer to value */
835 *valueptr
; /* Pointer into value */
836 cupsd_printer_t
*p
; /* Current printer */
840 * Open the printers.conf file...
843 snprintf(line
, sizeof(line
), "%s/printers.conf", ServerRoot
);
844 if ((fp
= cupsFileOpen(line
, "r")) == NULL
)
847 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to open %s - %s", line
,
853 * Read printer configurations until we hit EOF...
859 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
862 * Decode the directive...
865 if (!strcasecmp(line
, "<Printer") ||
866 !strcasecmp(line
, "<DefaultPrinter"))
869 * <Printer name> or <DefaultPrinter name>
872 if (p
== NULL
&& value
)
875 * Add the printer and a base file type...
878 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Loading printer %s...", value
);
880 p
= cupsdAddPrinter(value
);
882 p
->state
= IPP_PRINTER_IDLE
;
885 * Set the default printer as needed...
888 if (!strcasecmp(line
, "<DefaultPrinter"))
893 cupsdLogMessage(CUPSD_LOG_ERROR
,
894 "Syntax error on line %d of printers.conf.", linenum
);
898 else if (!strcasecmp(line
, "</Printer>"))
903 * Close out the current printer...
906 cupsdSetPrinterAttrs(p
);
907 cupsdAddPrinterHistory(p
);
909 if (p
->device_uri
&& strncmp(p
->device_uri
, "file:", 5) &&
910 p
->state
!= IPP_PRINTER_STOPPED
)
913 * See if the backend exists...
916 snprintf(line
, sizeof(line
), "%s/backend/%s", ServerBin
,
919 if ((valueptr
= strchr(line
+ strlen(ServerBin
), ':')) != NULL
)
920 *valueptr
= '\0'; /* Chop everything but URI scheme */
925 * Backend does not exist, stop printer...
928 p
->state
= IPP_PRINTER_STOPPED
;
929 snprintf(p
->state_message
, sizeof(p
->state_message
),
930 "Backend %s does not exist!", line
);
938 cupsdLogMessage(CUPSD_LOG_ERROR
,
939 "Syntax error on line %d of printers.conf.", linenum
);
945 cupsdLogMessage(CUPSD_LOG_ERROR
,
946 "Syntax error on line %d of printers.conf.", linenum
);
949 else if (!strcasecmp(line
, "Info"))
952 cupsdSetString(&p
->info
, value
);
954 else if (!strcasecmp(line
, "Location"))
957 cupsdSetString(&p
->location
, value
);
959 else if (!strcasecmp(line
, "DeviceURI"))
962 cupsdSetString(&p
->device_uri
, value
);
965 cupsdLogMessage(CUPSD_LOG_ERROR
,
966 "Syntax error on line %d of printers.conf.", linenum
);
970 else if (!strcasecmp(line
, "Option") && value
)
976 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
979 cupsdLogMessage(CUPSD_LOG_ERROR
,
980 "Syntax error on line %d of printers.conf.", linenum
);
983 for (; *valueptr
&& isspace(*valueptr
& 255); *valueptr
++ = '\0');
985 p
->num_options
= cupsAddOption(value
, valueptr
, p
->num_options
,
989 else if (!strcasecmp(line
, "PortMonitor"))
991 if (value
&& strcmp(value
, "none"))
992 cupsdSetString(&p
->port_monitor
, value
);
994 cupsdClearString(&p
->port_monitor
);
997 cupsdLogMessage(CUPSD_LOG_ERROR
,
998 "Syntax error on line %d of printers.conf.", linenum
);
1002 else if (!strcasecmp(line
, "State"))
1005 * Set the initial queue state...
1008 if (value
&& !strcasecmp(value
, "idle"))
1009 p
->state
= IPP_PRINTER_IDLE
;
1010 else if (value
&& !strcasecmp(value
, "stopped"))
1011 p
->state
= IPP_PRINTER_STOPPED
;
1014 cupsdLogMessage(CUPSD_LOG_ERROR
,
1015 "Syntax error on line %d of printers.conf.", linenum
);
1019 else if (!strcasecmp(line
, "StateMessage"))
1022 * Set the initial queue state message...
1026 strlcpy(p
->state_message
, value
, sizeof(p
->state_message
));
1028 else if (!strcasecmp(line
, "StateTime"))
1031 * Set the state time...
1035 p
->state_time
= atoi(value
);
1037 else if (!strcasecmp(line
, "Accepting"))
1040 * Set the initial accepting 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
, "Shared"))
1063 * Set the initial shared state...
1067 (!strcasecmp(value
, "yes") ||
1068 !strcasecmp(value
, "on") ||
1069 !strcasecmp(value
, "true")))
1072 (!strcasecmp(value
, "no") ||
1073 !strcasecmp(value
, "off") ||
1074 !strcasecmp(value
, "false")))
1078 cupsdLogMessage(CUPSD_LOG_ERROR
,
1079 "Syntax error on line %d of printers.conf.", linenum
);
1083 else if (!strcasecmp(line
, "JobSheets"))
1086 * Set the initial job sheets...
1091 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1096 cupsdSetString(&p
->job_sheets
[0], value
);
1098 while (isspace(*valueptr
& 255))
1103 for (value
= valueptr
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1108 cupsdSetString(&p
->job_sheets
[1], value
);
1113 cupsdLogMessage(CUPSD_LOG_ERROR
,
1114 "Syntax error on line %d of printers.conf.", linenum
);
1118 else if (!strcasecmp(line
, "AllowUser"))
1123 cupsdAddPrinterUser(p
, value
);
1127 cupsdLogMessage(CUPSD_LOG_ERROR
,
1128 "Syntax error on line %d of printers.conf.", linenum
);
1132 else if (!strcasecmp(line
, "DenyUser"))
1137 cupsdAddPrinterUser(p
, value
);
1141 cupsdLogMessage(CUPSD_LOG_ERROR
,
1142 "Syntax error on line %d of printers.conf.", linenum
);
1146 else if (!strcasecmp(line
, "QuotaPeriod"))
1149 p
->quota_period
= atoi(value
);
1152 cupsdLogMessage(CUPSD_LOG_ERROR
,
1153 "Syntax error on line %d of printers.conf.", linenum
);
1157 else if (!strcasecmp(line
, "PageLimit"))
1160 p
->page_limit
= atoi(value
);
1163 cupsdLogMessage(CUPSD_LOG_ERROR
,
1164 "Syntax error on line %d of printers.conf.", linenum
);
1168 else if (!strcasecmp(line
, "KLimit"))
1171 p
->k_limit
= atoi(value
);
1174 cupsdLogMessage(CUPSD_LOG_ERROR
,
1175 "Syntax error on line %d of printers.conf.", linenum
);
1179 else if (!strcasecmp(line
, "OpPolicy"))
1182 cupsdSetString(&p
->op_policy
, value
);
1185 cupsdLogMessage(CUPSD_LOG_ERROR
,
1186 "Syntax error on line %d of printers.conf.", linenum
);
1190 else if (!strcasecmp(line
, "ErrorPolicy"))
1193 cupsdSetString(&p
->error_policy
, value
);
1196 cupsdLogMessage(CUPSD_LOG_ERROR
,
1197 "Syntax error on line %d of printers.conf.", linenum
);
1204 * Something else we don't understand...
1207 cupsdLogMessage(CUPSD_LOG_ERROR
,
1208 "Unknown configuration directive %s on line %d of printers.conf.",
1218 * 'cupsdRenamePrinter()' - Rename a printer.
1223 cupsd_printer_t
*p
, /* I - Printer */
1224 const char *name
) /* I - New name */
1227 * Remove the printer from the array(s) first...
1230 cupsArrayRemove(Printers
, p
);
1232 if (p
->type
& CUPS_PRINTER_IMPLICIT
)
1233 cupsArrayRemove(ImplicitPrinters
, p
);
1236 * Rename the printer type...
1239 mimeDeleteType(MimeDatabase
, p
->filetype
);
1240 p
->filetype
= mimeAddType(MimeDatabase
, "printer", name
);
1243 * Rename the printer...
1246 cupsdSetString(&p
->name
, name
);
1249 * Reset printer attributes...
1252 cupsdSetPrinterAttrs(p
);
1255 * Add the printer back to the printer array(s)...
1258 cupsArrayAdd(Printers
, p
);
1259 if (p
->type
& CUPS_PRINTER_IMPLICIT
)
1260 cupsArrayAdd(ImplicitPrinters
, p
);
1265 * 'cupsdSaveAllPrinters()' - Save all printer definitions to the printers.conf
1270 cupsdSaveAllPrinters(void)
1272 int i
; /* Looping var */
1273 cups_file_t
*fp
; /* printers.conf file */
1274 char temp
[1024]; /* Temporary string */
1275 char backup
[1024]; /* printers.conf.O file */
1276 cupsd_printer_t
*printer
; /* Current printer class */
1277 time_t curtime
; /* Current time */
1278 struct tm
*curdate
; /* Current date */
1279 cups_option_t
*option
; /* Current option */
1283 * Create the printers.conf file...
1286 snprintf(temp
, sizeof(temp
), "%s/printers.conf", ServerRoot
);
1287 snprintf(backup
, sizeof(backup
), "%s/printers.conf.O", ServerRoot
);
1289 if (rename(temp
, backup
))
1291 if (errno
!= ENOENT
)
1292 cupsdLogMessage(CUPSD_LOG_ERROR
,
1293 "Unable to backup printers.conf - %s", strerror(errno
));
1296 if ((fp
= cupsFileOpen(temp
, "w")) == NULL
)
1298 cupsdLogMessage(CUPSD_LOG_ERROR
,
1299 "Unable to save printers.conf - %s", strerror(errno
));
1301 if (rename(backup
, temp
))
1302 cupsdLogMessage(CUPSD_LOG_ERROR
,
1303 "Unable to restore printers.conf - %s", strerror(errno
));
1307 cupsdLogMessage(CUPSD_LOG_INFO
, "Saving printers.conf...");
1310 * Restrict access to the file...
1313 fchown(cupsFileNumber(fp
), getuid(), Group
);
1314 fchmod(cupsFileNumber(fp
), 0600);
1317 * Write a small header to the file...
1320 curtime
= time(NULL
);
1321 curdate
= localtime(&curtime
);
1322 strftime(temp
, sizeof(temp
) - 1, "%Y-%m-%d %H:%M", curdate
);
1324 cupsFilePuts(fp
, "# Printer configuration file for " CUPS_SVERSION
"\n");
1325 cupsFilePrintf(fp
, "# Written by cupsd on %s\n", temp
);
1328 * Write each local printer known to the system...
1331 for (printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
1333 printer
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
1336 * Skip remote destinations and printer classes...
1339 if ((printer
->type
& CUPS_PRINTER_REMOTE
) ||
1340 (printer
->type
& CUPS_PRINTER_CLASS
) ||
1341 (printer
->type
& CUPS_PRINTER_IMPLICIT
))
1345 * Write printers as needed...
1348 if (printer
== DefaultPrinter
)
1349 cupsFilePrintf(fp
, "<DefaultPrinter %s>\n", printer
->name
);
1351 cupsFilePrintf(fp
, "<Printer %s>\n", printer
->name
);
1354 cupsFilePrintf(fp
, "Info %s\n", printer
->info
);
1356 if (printer
->location
)
1357 cupsFilePrintf(fp
, "Location %s\n", printer
->location
);
1359 if (printer
->device_uri
)
1360 cupsFilePrintf(fp
, "DeviceURI %s\n", printer
->device_uri
);
1362 if (printer
->port_monitor
)
1363 cupsFilePrintf(fp
, "PortMonitor %s\n", printer
->port_monitor
);
1365 if (printer
->state
== IPP_PRINTER_STOPPED
)
1367 cupsFilePuts(fp
, "State Stopped\n");
1368 cupsFilePrintf(fp
, "StateMessage %s\n", printer
->state_message
);
1371 cupsFilePuts(fp
, "State Idle\n");
1373 cupsFilePrintf(fp
, "StateTime %d\n", (int)printer
->state_time
);
1375 if (printer
->accepting
)
1376 cupsFilePuts(fp
, "Accepting Yes\n");
1378 cupsFilePuts(fp
, "Accepting No\n");
1380 if (printer
->shared
)
1381 cupsFilePuts(fp
, "Shared Yes\n");
1383 cupsFilePuts(fp
, "Shared No\n");
1385 cupsFilePrintf(fp
, "JobSheets %s %s\n", printer
->job_sheets
[0],
1386 printer
->job_sheets
[1]);
1388 cupsFilePrintf(fp
, "QuotaPeriod %d\n", printer
->quota_period
);
1389 cupsFilePrintf(fp
, "PageLimit %d\n", printer
->page_limit
);
1390 cupsFilePrintf(fp
, "KLimit %d\n", printer
->k_limit
);
1392 for (i
= 0; i
< printer
->num_users
; i
++)
1393 cupsFilePrintf(fp
, "%sUser %s\n", printer
->deny_users
? "Deny" : "Allow",
1396 if (printer
->op_policy
)
1397 cupsFilePrintf(fp
, "OpPolicy %s\n", printer
->op_policy
);
1398 if (printer
->error_policy
)
1399 cupsFilePrintf(fp
, "ErrorPolicy %s\n", printer
->error_policy
);
1401 for (i
= printer
->num_options
, option
= printer
->options
;
1404 cupsFilePrintf(fp
, "Option %s %s\n", option
->name
, option
->value
);
1406 cupsFilePuts(fp
, "</Printer>\n");
1410 * Make IRIX desktop & printer status happy
1413 write_irix_state(printer
);
1422 * 'cupsdSetPrinterAttrs()' - Set printer attributes based upon the PPD file.
1426 cupsdSetPrinterAttrs(cupsd_printer_t
*p
)/* I - Printer to setup */
1428 int i
, /* Looping var */
1429 length
; /* Length of browse attributes */
1430 char uri
[HTTP_MAX_URI
]; /* URI for printer */
1431 char resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
1432 char filename
[1024]; /* Name of PPD file */
1433 int num_media
; /* Number of media options */
1434 cupsd_location_t
*auth
; /* Pointer to authentication element */
1435 const char *auth_supported
; /* Authentication supported */
1436 cups_ptype_t printer_type
; /* Printer type data */
1437 ppd_file_t
*ppd
; /* PPD file data */
1438 ppd_option_t
*input_slot
, /* InputSlot options */
1439 *media_type
, /* MediaType options */
1440 *page_size
, /* PageSize options */
1441 *output_bin
, /* OutputBin options */
1442 *media_quality
, /* EFMediaQualityMode options */
1443 *duplex
; /* Duplex options */
1444 ppd_attr_t
*ppdattr
; /* PPD attribute */
1445 ipp_attribute_t
*attr
; /* Attribute data */
1446 ipp_value_t
*val
; /* Attribute value */
1447 int num_finishings
; /* Number of finishings */
1448 ipp_finish_t finishings
[5]; /* finishings-supported values */
1449 cups_option_t
*option
; /* Current printer option */
1450 static const char * const sides
[3] = /* sides-supported values */
1453 "two-sided-long-edge",
1454 "two-sided-short-edge"
1458 DEBUG_printf(("cupsdSetPrinterAttrs: entering name = %s, type = %x\n", p
->name
,
1462 * Make sure that we have the common attributes defined...
1466 cupsdCreateCommonData();
1469 * Clear out old filters, if any...
1472 delete_printer_filters(p
);
1475 * Figure out the authentication that is required for the printer.
1478 auth_supported
= "requesting-user-name";
1479 if (!(p
->type
& CUPS_PRINTER_REMOTE
))
1481 if (p
->type
& CUPS_PRINTER_CLASS
)
1482 snprintf(resource
, sizeof(resource
), "/classes/%s", p
->name
);
1484 snprintf(resource
, sizeof(resource
), "/printers/%s", p
->name
);
1486 if ((auth
= cupsdFindBest(resource
, HTTP_POST
)) == NULL
)
1487 auth
= cupsdFindPolicyOp(p
->op_policy_ptr
, IPP_PRINT_JOB
);
1491 if (auth
->type
== AUTH_BASIC
|| auth
->type
== AUTH_BASICDIGEST
)
1492 auth_supported
= "basic";
1493 else if (auth
->type
== AUTH_DIGEST
)
1494 auth_supported
= "digest";
1496 if (auth
->type
!= AUTH_NONE
)
1497 p
->type
|= CUPS_PRINTER_AUTHENTICATED
;
1499 p
->type
&= ~CUPS_PRINTER_AUTHENTICATED
;
1502 p
->type
&= ~CUPS_PRINTER_AUTHENTICATED
;
1506 * Create the required IPP attributes for a printer...
1510 ippDelete(p
->attrs
);
1512 p
->attrs
= ippNew();
1514 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
1515 "uri-authentication-supported", NULL
, auth_supported
);
1516 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
1517 "uri-security-supported", NULL
, "none");
1518 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
, "printer-name", NULL
,
1520 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-location",
1521 NULL
, p
->location
? p
->location
: "");
1522 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-info",
1523 NULL
, p
->info
? p
->info
: "");
1524 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "printer-more-info",
1530 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
1531 "requesting-user-name-denied", p
->num_users
, NULL
,
1534 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
1535 "requesting-user-name-allowed", p
->num_users
, NULL
,
1539 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
1540 "job-quota-period", p
->quota_period
);
1541 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
1542 "job-k-limit", p
->k_limit
);
1543 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
1544 "job-page-limit", p
->page_limit
);
1546 if (cupsArrayCount(Banners
) > 0 && !(p
->type
& CUPS_PRINTER_REMOTE
))
1549 * Setup the job-sheets-default attribute...
1552 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
1553 "job-sheets-default", 2, NULL
, NULL
);
1557 attr
->values
[0].string
.text
= _cupsStrAlloc(Classification
?
1558 Classification
: p
->job_sheets
[0]);
1559 attr
->values
[1].string
.text
= _cupsStrAlloc(Classification
?
1560 Classification
: p
->job_sheets
[1]);
1564 printer_type
= p
->type
;
1568 if (p
->type
& CUPS_PRINTER_REMOTE
)
1571 * Tell the client this is a remote printer of some type...
1574 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
1575 "printer-uri-supported", NULL
, p
->uri
);
1578 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
1579 "printer-make-and-model", NULL
, p
->make_model
);
1581 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "device-uri", NULL
,
1589 * Assign additional attributes depending on whether this is a printer
1593 p
->type
&= ~CUPS_PRINTER_OPTIONS
;
1595 if (p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
))
1600 * Add class-specific attributes...
1603 if ((p
->type
& CUPS_PRINTER_IMPLICIT
) && p
->num_printers
> 0 &&
1604 p
->printers
[0]->make_model
)
1605 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
1606 "printer-make-and-model", NULL
, p
->printers
[0]->make_model
);
1608 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
1609 "printer-make-and-model", NULL
, "Local Printer Class");
1611 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "device-uri", NULL
,
1612 "file:///dev/null");
1614 if (p
->num_printers
> 0)
1617 * Add a list of member URIs and names...
1620 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
1621 "member-uris", p
->num_printers
, NULL
, NULL
);
1622 p
->type
|= CUPS_PRINTER_OPTIONS
;
1624 for (i
= 0; i
< p
->num_printers
; i
++)
1627 attr
->values
[i
].string
.text
= _cupsStrAlloc(p
->printers
[i
]->uri
);
1629 p
->type
&= ~CUPS_PRINTER_OPTIONS
| p
->printers
[i
]->type
;
1632 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
1633 "member-names", p
->num_printers
, NULL
, NULL
);
1637 for (i
= 0; i
< p
->num_printers
; i
++)
1638 attr
->values
[i
].string
.text
= _cupsStrAlloc(p
->printers
[i
]->name
);
1645 * Add printer-specific attributes... Start by sanitizing the device
1646 * URI so it doesn't have a username or password in it...
1650 strcpy(uri
, "file:/dev/null");
1651 else if (strstr(p
->device_uri
, "://") != NULL
)
1654 * http://..., ipp://..., etc.
1657 cupsdSanitizeURI(p
->device_uri
, uri
, sizeof(uri
));
1662 * file:..., serial:..., etc.
1665 strlcpy(uri
, p
->device_uri
, sizeof(uri
));
1668 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "device-uri", NULL
,
1672 * Assign additional attributes from the PPD file (if any)...
1675 p
->type
|= CUPS_PRINTER_BW
;
1676 finishings
[0] = IPP_FINISHINGS_NONE
;
1679 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
1682 if ((ppd
= ppdOpenFile(filename
)) != NULL
)
1685 * Add make/model and other various attributes...
1688 if (ppd
->color_device
)
1689 p
->type
|= CUPS_PRINTER_COLOR
;
1690 if (ppd
->variable_sizes
)
1691 p
->type
|= CUPS_PRINTER_VARIABLE
;
1692 if (!ppd
->manual_copies
)
1693 p
->type
|= CUPS_PRINTER_COPIES
;
1694 if ((ppdattr
= ppdFindAttr(ppd
, "cupsFax", NULL
)) != NULL
)
1695 if (ppdattr
->value
&& !strcasecmp(ppdattr
->value
, "true"))
1696 p
->type
|= CUPS_PRINTER_FAX
;
1698 ippAddBoolean(p
->attrs
, IPP_TAG_PRINTER
, "color-supported",
1700 if (ppd
->throughput
)
1701 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
1702 "pages-per-minute", ppd
->throughput
);
1707 * The NickName can be localized in the character set specified
1708 * by the LanugageEncoding attribute. However, ppdOpen2() has
1709 * already converted the ppd->nickname member to UTF-8 for us
1710 * (the original attribute value is available separately)
1713 cupsdSetString(&p
->make_model
, ppd
->nickname
);
1715 else if (ppd
->modelname
)
1718 * Model name can only contain specific characters...
1721 cupsdSetString(&p
->make_model
, ppd
->modelname
);
1724 cupsdSetString(&p
->make_model
, "Bad PPD File");
1726 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
1727 "printer-make-and-model", NULL
, p
->make_model
);
1730 * Add media options from the PPD file...
1733 if ((input_slot
= ppdFindOption(ppd
, "InputSlot")) != NULL
)
1734 num_media
= input_slot
->num_choices
;
1738 if ((media_type
= ppdFindOption(ppd
, "MediaType")) != NULL
)
1739 num_media
+= media_type
->num_choices
;
1741 if ((page_size
= ppdFindOption(ppd
, "PageSize")) != NULL
)
1742 num_media
+= page_size
->num_choices
;
1744 if ((media_quality
= ppdFindOption(ppd
, "EFMediaQualityMode")) != NULL
)
1745 num_media
+= media_quality
->num_choices
;
1749 cupsdLogMessage(CUPSD_LOG_CRIT
,
1750 "The PPD file for printer %s contains no media "
1751 "options and is therefore invalid!", p
->name
);
1755 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
1756 "media-supported", num_media
, NULL
, NULL
);
1761 if (input_slot
!= NULL
)
1762 for (i
= 0; i
< input_slot
->num_choices
; i
++, val
++)
1763 val
->string
.text
= _cupsStrAlloc(input_slot
->choices
[i
].choice
);
1765 if (media_type
!= NULL
)
1766 for (i
= 0; i
< media_type
->num_choices
; i
++, val
++)
1767 val
->string
.text
= _cupsStrAlloc(media_type
->choices
[i
].choice
);
1769 if (media_quality
!= NULL
)
1770 for (i
= 0; i
< media_quality
->num_choices
; i
++, val
++)
1771 val
->string
.text
= _cupsStrAlloc(media_quality
->choices
[i
].choice
);
1773 if (page_size
!= NULL
)
1775 for (i
= 0; i
< page_size
->num_choices
; i
++, val
++)
1776 val
->string
.text
= _cupsStrAlloc(page_size
->choices
[i
].choice
);
1778 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
1779 "media-default", NULL
, page_size
->defchoice
);
1781 else if (input_slot
!= NULL
)
1782 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
1783 "media-default", NULL
, input_slot
->defchoice
);
1784 else if (media_type
!= NULL
)
1785 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
1786 "media-default", NULL
, media_type
->defchoice
);
1787 else if (media_quality
!= NULL
)
1788 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
1789 "media-default", NULL
, media_quality
->defchoice
);
1791 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
1792 "media-default", NULL
, "none");
1800 if ((output_bin
= ppdFindOption(ppd
, "OutputBin")) != NULL
)
1802 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
1803 "output-bin-supported", output_bin
->num_choices
,
1808 for (i
= 0, val
= attr
->values
;
1809 i
< output_bin
->num_choices
;
1811 val
->string
.text
= _cupsStrAlloc(output_bin
->choices
[i
].choice
);
1819 if ((duplex
= ppdFindOption(ppd
, "Duplex")) == NULL
)
1820 if ((duplex
= ppdFindOption(ppd
, "EFDuplex")) == NULL
)
1821 if ((duplex
= ppdFindOption(ppd
, "EFDuplexing")) == NULL
)
1822 if ((duplex
= ppdFindOption(ppd
, "KD03Duplex")) == NULL
)
1823 duplex
= ppdFindOption(ppd
, "JCLDuplex");
1825 if (duplex
&& duplex
->num_choices
> 1)
1827 p
->type
|= CUPS_PRINTER_DUPLEX
;
1829 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
1830 "sides-supported", 3, NULL
, sides
);
1832 if (!strcasecmp(duplex
->defchoice
, "DuplexTumble"))
1833 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
1834 "sides-default", NULL
, "two-sided-short-edge");
1835 else if (!strcasecmp(duplex
->defchoice
, "DuplexNoTumble"))
1836 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
1837 "sides-default", NULL
, "two-sided-long-edge");
1839 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
1840 "sides-default", NULL
, "one-sided");
1843 if (ppdFindOption(ppd
, "Collate") != NULL
)
1844 p
->type
|= CUPS_PRINTER_COLLATE
;
1846 if (ppdFindOption(ppd
, "StapleLocation") != NULL
)
1848 p
->type
|= CUPS_PRINTER_STAPLE
;
1849 finishings
[num_finishings
++] = IPP_FINISHINGS_STAPLE
;
1852 if (ppdFindOption(ppd
, "BindEdge") != NULL
)
1854 p
->type
|= CUPS_PRINTER_BIND
;
1855 finishings
[num_finishings
++] = IPP_FINISHINGS_BIND
;
1858 for (i
= 0; i
< ppd
->num_sizes
; i
++)
1859 if (ppd
->sizes
[i
].length
> 1728)
1860 p
->type
|= CUPS_PRINTER_LARGE
;
1861 else if (ppd
->sizes
[i
].length
> 1008)
1862 p
->type
|= CUPS_PRINTER_MEDIUM
;
1864 p
->type
|= CUPS_PRINTER_SMALL
;
1867 * Add a filter from application/vnd.cups-raw to printer/name to
1868 * handle "raw" printing by users.
1871 add_printer_filter(p
, "application/vnd.cups-raw 0 -");
1874 * Add any filters in the PPD file...
1877 DEBUG_printf(("ppd->num_filters = %d\n", ppd
->num_filters
));
1878 for (i
= 0; i
< ppd
->num_filters
; i
++)
1880 DEBUG_printf(("ppd->filters[%d] = \"%s\"\n", i
, ppd
->filters
[i
]));
1881 add_printer_filter(p
, ppd
->filters
[i
]);
1884 if (ppd
->num_filters
== 0)
1887 * If there are no filters, add a PostScript printing filter.
1890 add_printer_filter(p
, "application/vnd.cups-postscript 0 -");
1894 * Show current and available port monitors for this printer...
1897 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
, "port-monitor",
1898 NULL
, p
->port_monitor
? p
->port_monitor
: "none");
1901 for (i
= 1, ppdattr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
1903 i
++, ppdattr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
));
1907 if (strstr(ppd
->protocols
, "TBCP"))
1909 else if (strstr(ppd
->protocols
, "BCP"))
1913 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
1914 "port-monitor-supported", i
, NULL
, NULL
);
1916 attr
->values
[0].string
.text
= _cupsStrAlloc("none");
1918 for (i
= 1, ppdattr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
1920 i
++, ppdattr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
))
1921 attr
->values
[i
].string
.text
= _cupsStrAlloc(ppdattr
->value
);
1925 if (strstr(ppd
->protocols
, "TBCP"))
1926 attr
->values
[i
].string
.text
= _cupsStrAlloc("tbcp");
1927 else if (strstr(ppd
->protocols
, "BCP"))
1928 attr
->values
[i
].string
.text
= _cupsStrAlloc("bcp");
1932 * Close the PPD and set the type...
1937 printer_type
= p
->type
;
1939 else if (!access(filename
, 0))
1941 int pline
; /* PPD line number */
1942 ppd_status_t pstatus
; /* PPD load status */
1945 pstatus
= ppdLastError(&pline
);
1947 cupsdLogMessage(CUPSD_LOG_ERROR
, "PPD file for %s cannot be loaded!",
1950 if (pstatus
<= PPD_ALLOC_ERROR
)
1951 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s", strerror(errno
));
1953 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s on line %d.",
1954 ppdErrorString(pstatus
), pline
);
1956 cupsdLogMessage(CUPSD_LOG_INFO
,
1957 "Hint: Run \"cupstestppd %s\" and fix any errors.",
1961 * Add a filter from application/vnd.cups-raw to printer/name to
1962 * handle "raw" printing by users.
1965 add_printer_filter(p
, "application/vnd.cups-raw 0 -");
1968 * Add a PostScript filter, since this is still possibly PS printer.
1971 add_printer_filter(p
, "application/vnd.cups-postscript 0 -");
1976 * If we have an interface script, add a filter entry for it...
1979 snprintf(filename
, sizeof(filename
), "%s/interfaces/%s", ServerRoot
,
1981 if (!access(filename
, X_OK
))
1984 * Yes, we have a System V style interface script; use it!
1987 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
1988 "printer-make-and-model", NULL
, "Local System V Printer");
1990 snprintf(filename
, sizeof(filename
), "*/* 0 %s/interfaces/%s",
1991 ServerRoot
, p
->name
);
1992 add_printer_filter(p
, filename
);
1994 else if (p
->device_uri
&&
1995 !strncmp(p
->device_uri
, "ipp://", 6) &&
1996 (strstr(p
->device_uri
, "/printers/") != NULL
||
1997 strstr(p
->device_uri
, "/classes/") != NULL
))
2000 * Tell the client this is really a hard-wired remote printer.
2003 printer_type
|= CUPS_PRINTER_REMOTE
;
2006 * Point the printer-uri-supported attribute to the
2010 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
2011 "printer-uri-supported", NULL
, p
->device_uri
);
2014 * Then set the make-and-model accordingly...
2017 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
2018 "printer-make-and-model", NULL
, "Remote Printer");
2021 * Print all files directly...
2029 * Otherwise we have neither - treat this as a "dumb" printer
2030 * with no PPD file...
2033 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
2034 "printer-make-and-model", NULL
, "Local Raw Printer");
2040 ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
2041 "finishings-supported", num_finishings
, (int *)finishings
);
2042 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
2043 "finishings-default", IPP_FINISHINGS_NONE
);
2048 * Copy the printer options into a browse attributes string we can re-use.
2051 if (!(p
->type
& CUPS_PRINTER_REMOTE
))
2053 const char *valptr
; /* Pointer into value */
2054 char *attrptr
; /* Pointer into attribute string */
2058 * Free the old browse attributes as needed...
2061 if (p
->browse_attrs
)
2062 free(p
->browse_attrs
);
2065 * Compute the length of all attributes + job-sheets, lease-duration,
2066 * and BrowseLocalOptions.
2069 for (length
= 1, i
= p
->num_options
, option
= p
->options
;
2073 length
+= strlen(option
->name
) + 2;
2077 for (valptr
= option
->value
; *valptr
; valptr
++)
2078 if (strchr(" \"\'\\", *valptr
))
2085 length
+= 13 + strlen(p
->job_sheets
[0]) + strlen(p
->job_sheets
[1]);
2087 if (BrowseLocalOptions
)
2088 length
+= 12 + strlen(BrowseLocalOptions
);
2091 * Allocate the new string...
2094 if ((p
->browse_attrs
= calloc(1, length
)) == NULL
)
2095 cupsdLogMessage(CUPSD_LOG_ERROR
,
2096 "Unable to allocate %d bytes for browse data!",
2101 * Got the allocated string, now copy the options and attributes over...
2104 sprintf(p
->browse_attrs
, "job-sheets=%s,%s lease-duration=%d",
2105 p
->job_sheets
[0], p
->job_sheets
[1], BrowseTimeout
);
2106 attrptr
= p
->browse_attrs
+ strlen(p
->browse_attrs
);
2108 if (BrowseLocalOptions
)
2110 sprintf(attrptr
, " ipp-options=%s", BrowseLocalOptions
);
2111 attrptr
+= strlen(attrptr
);
2114 for (i
= p
->num_options
, option
= p
->options
;
2119 strcpy(attrptr
, option
->name
);
2120 attrptr
+= strlen(attrptr
);
2126 for (valptr
= option
->value
; *valptr
; valptr
++)
2128 if (strchr(" \"\'\\", *valptr
))
2131 *attrptr
++ = *valptr
;
2141 * Populate the document-format-supported attribute...
2144 add_printer_formats(p
);
2146 DEBUG_printf(("cupsdSetPrinterAttrs: leaving name = %s, type = %x\n", p
->name
,
2150 * Add name-default attributes...
2153 add_printer_defaults(p
);
2157 * Write the IRIX printer config and status files...
2160 write_irix_config(p
);
2161 write_irix_state(p
);
2167 * 'cupsdSetPrinterReasons()' - Set/update the reasons strings.
2171 cupsdSetPrinterReasons(
2172 cupsd_printer_t
*p
, /* I - Printer */
2173 const char *s
) /* I - Reasons strings */
2175 int i
; /* Looping var */
2176 const char *sptr
; /* Pointer into reasons */
2177 char reason
[255], /* Reason string */
2178 *rptr
; /* Pointer into reason */
2181 if (s
[0] == '-' || s
[0] == '+')
2184 * Add/remove reasons...
2192 * Replace reasons...
2197 for (i
= 0; i
< p
->num_reasons
; i
++)
2198 free(p
->reasons
[i
]);
2204 * Loop through all of the reasons...
2210 * Skip leading whitespace and commas...
2213 while (isspace(*sptr
& 255) || *sptr
== ',')
2216 for (rptr
= reason
; *sptr
&& !isspace(*sptr
& 255) && *sptr
!= ','; sptr
++)
2217 if (rptr
< (reason
+ sizeof(reason
) - 1))
2231 for (i
= 0; i
< p
->num_reasons
; i
++)
2232 if (!strcasecmp(reason
, p
->reasons
[i
]))
2235 * Found a match, so remove it...
2239 free(p
->reasons
[i
]);
2241 if (i
< p
->num_reasons
)
2242 memmove(p
->reasons
+ i
, p
->reasons
+ i
+ 1,
2243 (p
->num_reasons
- i
) * sizeof(char *));
2248 else if (p
->num_reasons
< (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
2254 for (i
= 0; i
< p
->num_reasons
; i
++)
2255 if (!strcasecmp(reason
, p
->reasons
[i
]))
2258 if (i
>= p
->num_reasons
)
2260 p
->reasons
[i
] = strdup(reason
);
2269 * 'cupsdSetPrinterState()' - Update the current state of a printer.
2273 cupsdSetPrinterState(
2274 cupsd_printer_t
*p
, /* I - Printer to change */
2275 ipp_pstate_t s
, /* I - New state */
2276 int update
) /* I - Update printers.conf? */
2278 ipp_pstate_t old_state
; /* Old printer state */
2282 * Can't set status of remote printers...
2285 if (p
->type
& CUPS_PRINTER_REMOTE
)
2289 * Set the new state...
2292 old_state
= p
->state
;
2297 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE_CHANGED
, p
, NULL
,
2298 "%s \"%s\" state changed.",
2299 (p
->type
& CUPS_PRINTER_CLASS
) ? "Class" : "Printer",
2303 * Let the browse code know this needs to be updated...
2307 p
->state_time
= time(NULL
);
2311 write_irix_state(p
);
2315 cupsdAddPrinterHistory(p
);
2318 * Save the printer configuration if a printer goes from idle or processing
2319 * to stopped (or visa-versa)...
2322 if ((old_state
== IPP_PRINTER_STOPPED
) != (s
== IPP_PRINTER_STOPPED
) &&
2325 if (p
->type
& CUPS_PRINTER_CLASS
)
2326 cupsdSaveAllClasses();
2328 cupsdSaveAllPrinters();
2334 * 'cupsdStopPrinter()' - Stop a printer from printing any jobs...
2338 cupsdStopPrinter(cupsd_printer_t
*p
, /* I - Printer to stop */
2339 int update
)/* I - Update printers.conf? */
2341 cupsd_job_t
*job
; /* Active print job */
2345 * Set the printer state...
2348 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, update
);
2351 * See if we have a job printing on this printer...
2357 * Get pointer to job...
2360 job
= (cupsd_job_t
*)p
->job
;
2366 cupsdStopJob(job
, 0);
2369 * Reset the state to pending...
2372 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
2373 job
->state_value
= IPP_JOB_PENDING
;
2381 * 'cupsdUpdatePrinters()' - Update printers after a partial reload.
2385 cupsdUpdatePrinters(void)
2387 cupsd_printer_t
*p
; /* Current printer */
2391 * Loop through the printers and recreate the printer attributes
2392 * for any local printers since the policy and/or access control
2393 * stuff may have changed. Also, if browsing is disabled, remove
2394 * any remote printers...
2397 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
2399 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
2401 if (!Browsing
&& (p
->type
& (CUPS_PRINTER_IMPLICIT
| CUPS_PRINTER_REMOTE
)))
2403 if (p
->type
& CUPS_PRINTER_IMPLICIT
)
2404 cupsArrayRemove(ImplicitPrinters
, p
);
2406 cupsArraySave(Printers
);
2407 cupsdDeletePrinter(p
, 0);
2408 cupsArrayRestore(Printers
);
2411 else if (!(p
->type
& CUPS_PRINTER_REMOTE
))
2412 cupsdSetPrinterAttrs(p
);
2415 * Update the operation policy pointer...
2418 if ((p
->op_policy_ptr
= cupsdFindPolicy(p
->op_policy
)) == NULL
)
2419 p
->op_policy_ptr
= DefaultPolicyPtr
;
2425 * 'cupsdValidateDest()' - Validate a printer/class destination.
2428 const char * /* O - Printer or class name */
2430 const char *uri
, /* I - Printer URI */
2431 cups_ptype_t
*dtype
, /* O - Type (printer or class) */
2432 cupsd_printer_t
**printer
) /* O - Printer pointer */
2434 cupsd_printer_t
*p
; /* Current printer */
2435 char localname
[1024],/* Localized hostname */
2436 *lptr
, /* Pointer into localized hostname */
2437 *sptr
, /* Pointer into server name */
2438 *rptr
, /* Pointer into resource */
2439 scheme
[32], /* Scheme portion of URI */
2440 username
[64], /* Username portion of URI */
2441 hostname
[HTTP_MAX_HOST
],
2442 /* Host portion of URI */
2443 resource
[HTTP_MAX_URI
];
2444 /* Resource portion of URI */
2445 int port
; /* Port portion of URI */
2448 DEBUG_printf(("cupsdValidateDest(uri=\"%s\", dtype=%p, printer=%p)\n", uri
,
2452 * Initialize return values...
2459 *dtype
= (cups_ptype_t
)0;
2462 * Pull the hostname and resource from the URI...
2465 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
, scheme
, sizeof(scheme
),
2466 username
, sizeof(username
), hostname
, sizeof(hostname
),
2467 &port
, resource
, sizeof(resource
));
2470 * See if the resource is a class or printer...
2473 if (!strncmp(resource
, "/classes/", 9))
2479 rptr
= resource
+ 9;
2481 else if (!strncmp(resource
, "/printers/", 10))
2487 rptr
= resource
+ 10;
2492 * Bad resource name...
2499 * See if the printer or class name exists...
2502 p
= cupsdFindDest(rptr
);
2504 if (p
== NULL
&& strchr(rptr
, '@') == NULL
)
2512 *dtype
= p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
|
2513 CUPS_PRINTER_REMOTE
);
2519 * Change localhost to the server name...
2522 if (!strcasecmp(hostname
, "localhost"))
2523 strlcpy(hostname
, ServerName
, sizeof(hostname
));
2525 strlcpy(localname
, hostname
, sizeof(localname
));
2527 if (!strcasecmp(hostname
, ServerName
))
2530 * Localize the hostname...
2533 lptr
= strchr(localname
, '.');
2534 sptr
= strchr(ServerName
, '.');
2536 if (sptr
!= NULL
&& lptr
!= NULL
)
2539 * Strip the common domain name components...
2542 while (lptr
!= NULL
)
2544 if (!strcasecmp(lptr
, sptr
))
2550 lptr
= strchr(lptr
+ 1, '.');
2555 DEBUG_printf(("localized hostname is \"%s\"...\n", localname
));
2558 * Find a matching printer or class...
2561 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
2563 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
2564 if (!strcasecmp(p
->hostname
, localname
) &&
2565 !strcasecmp(p
->name
, rptr
))
2571 *dtype
= p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
|
2572 CUPS_PRINTER_REMOTE
);
2582 * 'cupsdWritePrintcap()' - Write a pseudo-printcap file for older applications
2587 cupsdWritePrintcap(void)
2589 cups_file_t
*fp
; /* printcap file */
2590 cupsd_printer_t
*p
; /* Current printer */
2595 * Update the IRIX printer state for the default printer; if
2596 * no printers remain, then the default printer file will be
2600 write_irix_state(DefaultPrinter
);
2604 * See if we have a printcap file; if not, don't bother writing it.
2607 if (!Printcap
|| !*Printcap
)
2611 * Open the printcap file...
2614 if ((fp
= cupsFileOpen(Printcap
, "w")) == NULL
)
2618 * Put a comment header at the top so that users will know where the
2619 * data has come from...
2622 cupsFilePuts(fp
, "# This file was automatically generated by cupsd(8) from the\n");
2623 cupsFilePrintf(fp
, "# %s/printers.conf file. All changes to this file\n",
2625 cupsFilePuts(fp
, "# will be lost.\n");
2630 * Write a new printcap with the current list of printers.
2633 switch (PrintcapFormat
)
2637 * Each printer is put in the file as:
2647 cupsFilePrintf(fp
, "%s|%s:rm=%s:rp=%s:\n", DefaultPrinter
->name
,
2648 DefaultPrinter
->info
, ServerName
, DefaultPrinter
->name
);
2650 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
2652 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
2653 if (p
!= DefaultPrinter
)
2654 cupsFilePrintf(fp
, "%s|%s:rm=%s:rp=%s:\n", p
->name
, p
->info
,
2655 ServerName
, p
->name
);
2658 case PRINTCAP_SOLARIS
:
2660 * Each printer is put in the file as:
2662 * _all:all=Printer1,Printer2,Printer3,...,PrinterN
2663 * _default:use=DefaultPrinter
2665 * :bsdaddr=ServerName,Printer1:\
2666 * :description=Description:
2668 * :bsdaddr=ServerName,Printer2:\
2669 * :description=Description:
2671 * :bsdaddr=ServerName,Printer3:\
2672 * :description=Description:
2675 * :bsdaddr=ServerName,PrinterN:\
2676 * :description=Description:
2679 cupsFilePuts(fp
, "_all:all=");
2680 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
2682 p
= (cupsd_printer_t
*)cupsArrayCurrent(Printers
))
2683 cupsFilePrintf(fp
, "%s%c", p
->name
,
2684 cupsArrayNext(Printers
) ? ',' : '\n');
2687 cupsFilePrintf(fp
, "_default:use=%s\n", DefaultPrinter
->name
);
2689 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
2691 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
2692 cupsFilePrintf(fp
, "%s:\\\n"
2693 "\t:bsdaddr=%s,%s:\\\n"
2694 "\t:description=%s:\n",
2695 p
->name
, ServerName
, p
->name
, p
->info
? p
->info
: "");
2709 * 'cupsdSanitizeURI()' - Sanitize a device URI...
2712 char * /* O - New device URI */
2713 cupsdSanitizeURI(const char *uri
, /* I - Original device URI */
2714 char *buffer
, /* O - New device URI */
2715 int buflen
) /* I - Size of new device URI buffer */
2717 char *start
, /* Start of data after scheme */
2718 *slash
, /* First slash after scheme:// */
2719 *ptr
; /* Pointer into user@host:port part */
2723 * Range check input...
2726 if (!uri
|| !buffer
|| buflen
< 2)
2730 * Copy the device URI to the new buffer...
2733 strlcpy(buffer
, uri
, buflen
);
2736 * Find the end of the scheme:// part...
2739 if ((ptr
= strchr(buffer
, ':')) == NULL
)
2740 return (buffer
); /* No scheme: part... */
2742 for (start
= ptr
+ 1; *start
; start
++)
2747 * Find the next slash (/) in the URI...
2750 if ((slash
= strchr(start
, '/')) == NULL
)
2751 slash
= start
+ strlen(start
); /* No slash, point to the end */
2754 * Check for an @ sign before the slash...
2757 if ((ptr
= strchr(start
, '@')) != NULL
&& ptr
< slash
)
2760 * Found an @ sign and it is before the resource part, so we have
2761 * an authentication string. Copy the remaining URI over the
2762 * authentication string...
2765 _cups_strcpy(start
, ptr
+ 1);
2769 * Return the new device URI...
2777 * 'add_printer_defaults()' - Add name-default attributes to the printer attributes.
2781 add_printer_defaults(cupsd_printer_t
*p
)/* I - Printer */
2783 int i
; /* Looping var */
2784 int num_options
; /* Number of default options */
2785 cups_option_t
*options
, /* Default options */
2786 *option
; /* Current option */
2787 char name
[256]; /* name-default */
2791 * Add all of the default options from the .conf files...
2794 for (num_options
= 0, i
= p
->num_options
, option
= p
->options
;
2798 if (strcmp(option
->name
, "ipp-options") &&
2799 strcmp(option
->name
, "job-sheets") &&
2800 strcmp(option
->name
, "lease-duration"))
2802 snprintf(name
, sizeof(name
), "%s-default", option
->name
);
2803 num_options
= cupsAddOption(name
, option
->value
, num_options
, &options
);
2808 * Convert options to IPP attributes...
2811 cupsEncodeOptions2(p
->attrs
, num_options
, options
, IPP_TAG_PRINTER
);
2812 cupsFreeOptions(num_options
, options
);
2815 * Add standard -default attributes as needed...
2818 if (!cupsGetOption("copies", p
->num_options
, p
->options
))
2819 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
, "copies-default",
2822 if (!cupsGetOption("document-format", p
->num_options
, p
->options
))
2823 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_MIMETYPE
,
2824 "document-format-default", NULL
, "application/octet-stream");
2826 if (!cupsGetOption("job-hold-until", p
->num_options
, p
->options
))
2827 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2828 "job-hold-until-default", NULL
, "no-hold");
2830 if (!cupsGetOption("job-priority", p
->num_options
, p
->options
))
2831 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2832 "job-priority-default", 50);
2834 if (!cupsGetOption("number-up", p
->num_options
, p
->options
))
2835 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2836 "number-up-default", 1);
2838 if (!cupsGetOption("orientation-requested", p
->num_options
, p
->options
))
2839 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
2840 "orientation-requested-default", IPP_PORTRAIT
);
2845 * 'add_printer_filter()' - Add a MIME filter for a printer.
2850 cupsd_printer_t
*p
, /* I - Printer to add to */
2851 const char *filter
) /* I - Filter to add */
2853 char super
[MIME_MAX_SUPER
], /* Super-type for filter */
2854 type
[MIME_MAX_TYPE
], /* Type for filter */
2855 program
[1024]; /* Program/filter name */
2856 int cost
; /* Cost of filter */
2857 mime_type_t
*temptype
; /* MIME type looping var */
2858 char filename
[1024]; /* Full filter filename */
2862 * Parse the filter string; it should be in the following format:
2864 * super/type cost program
2867 if (sscanf(filter
, "%15[^/]/%31s%d%1023s", super
, type
, &cost
, program
) != 4)
2869 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: invalid filter string \"%s\"!",
2875 * See if the filter program exists; if not, stop the printer and flag
2879 if (strcmp(program
, "-"))
2881 if (program
[0] == '/')
2882 strlcpy(filename
, program
, sizeof(filename
));
2884 snprintf(filename
, sizeof(filename
), "%s/filter/%s", ServerBin
, program
);
2886 if (access(filename
, X_OK
))
2888 snprintf(p
->state_message
, sizeof(p
->state_message
),
2889 "Filter \"%s\" for printer \"%s\" not available: %s",
2890 program
, p
->name
, strerror(errno
));
2891 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, 0);
2892 cupsdSetPrinterReasons(p
, "+cups-missing-filter-error");
2893 cupsdAddPrinterHistory(p
);
2895 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s", p
->state_message
);
2900 * Mark the CUPS_PRINTER_COMMANDS bit if we have a filter for
2901 * application/vnd.cups-command...
2904 if (!strcasecmp(super
, "application") &&
2905 !strcasecmp(type
, "vnd.cups-command"))
2906 p
->type
|= CUPS_PRINTER_COMMANDS
;
2909 * Add the filter to the MIME database, supporting wildcards as needed...
2912 for (temptype
= mimeFirstType(MimeDatabase
);
2914 temptype
= mimeNextType(MimeDatabase
))
2915 if (((super
[0] == '*' && strcasecmp(temptype
->super
, "printer")) ||
2916 !strcasecmp(temptype
->super
, super
)) &&
2917 (type
[0] == '*' || !strcasecmp(temptype
->type
, type
)))
2919 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
2920 "add_printer_filter: %s: adding filter %s/%s %s/%s %d %s",
2921 p
->name
, temptype
->super
, temptype
->type
,
2922 p
->filetype
->super
, p
->filetype
->type
,
2924 mimeAddFilter(MimeDatabase
, temptype
, p
->filetype
, cost
, program
);
2930 * 'add_printer_formats()' - Add document-format-supported values for a printer.
2934 add_printer_formats(cupsd_printer_t
*p
) /* I - Printer */
2936 int i
; /* Looping var */
2937 mime_type_t
*type
; /* Current MIME type */
2938 cups_array_t
*filters
; /* Filters */
2939 ipp_attribute_t
*attr
; /* document-format-supported attribute */
2940 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
2941 /* MIME type name */
2945 * Raw (and remote) queues advertise all of the supported MIME
2949 cupsArrayDelete(p
->filetypes
);
2950 p
->filetypes
= NULL
;
2954 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
,
2955 (ipp_tag_t
)(IPP_TAG_MIMETYPE
| IPP_TAG_COPY
),
2956 "document-format-supported", NumMimeTypes
, NULL
, MimeTypes
);
2961 * Otherwise, loop through the supported MIME types and see if there
2962 * are filters for them...
2965 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_printer_formats: %d types, %d filters",
2966 mimeNumTypes(MimeDatabase
), mimeNumFilters(MimeDatabase
));
2968 p
->filetypes
= cupsArrayNew(NULL
, NULL
);
2970 for (type
= mimeFirstType(MimeDatabase
);
2972 type
= mimeNextType(MimeDatabase
))
2974 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
2976 if ((filters
= mimeFilter(MimeDatabase
, type
, p
->filetype
, NULL
)) != NULL
)
2978 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
2979 "add_printer_formats: %s: %s needs %d filters",
2980 p
->name
, mimetype
, cupsArrayCount(filters
));
2982 cupsArrayDelete(filters
);
2983 cupsArrayAdd(p
->filetypes
, type
);
2986 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
2987 "add_printer_formats: %s: %s not supported",
2991 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
2992 "add_printer_formats: %s: %d supported types",
2993 p
->name
, cupsArrayCount(p
->filetypes
) + 1);
2996 * Add the file formats that can be filtered...
2999 if ((type
= mimeType(MimeDatabase
, "application", "octet-stream")) == NULL
||
3000 !cupsArrayFind(p
->filetypes
, type
))
3005 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_MIMETYPE
,
3006 "document-format-supported",
3007 cupsArrayCount(p
->filetypes
) + 1, NULL
, NULL
);
3010 attr
->values
[0].string
.text
= _cupsStrAlloc("application/octet-stream");
3012 for (type
= (mime_type_t
*)cupsArrayFirst(p
->filetypes
);
3014 i
++, type
= (mime_type_t
*)cupsArrayNext(p
->filetypes
))
3016 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
3018 attr
->values
[i
].string
.text
= _cupsStrAlloc(mimetype
);
3024 * 'compare_printers()' - Compare two printers.
3027 static int /* O - Result of comparison */
3028 compare_printers(void *first
, /* I - First printer */
3029 void *second
, /* I - Second printer */
3030 void *data
) /* I - App data (not used) */
3032 return (strcasecmp(((cupsd_printer_t
*)first
)->name
,
3033 ((cupsd_printer_t
*)second
)->name
));
3038 * 'delete_printer_filters()' - Delete all MIME filters for a printer.
3042 delete_printer_filters(
3043 cupsd_printer_t
*p
) /* I - Printer to remove from */
3045 mime_filter_t
*filter
; /* MIME filter looping var */
3049 * Range check input...
3056 * Remove all filters from the MIME database that have a destination
3057 * type == printer...
3060 for (filter
= mimeFirstFilter(MimeDatabase
);
3062 filter
= mimeNextFilter(MimeDatabase
))
3063 if (filter
->dst
== p
->filetype
)
3066 * Delete the current filter...
3069 mimeDeleteFilter(MimeDatabase
, filter
);
3076 * 'write_irix_config()' - Update the config files used by the IRIX
3081 write_irix_config(cupsd_printer_t
*p
) /* I - Printer to update */
3083 char filename
[1024]; /* Interface script filename */
3084 cups_file_t
*fp
; /* Interface script file */
3085 ipp_attribute_t
*attr
; /* Attribute data */
3089 * Add dummy interface and GUI scripts to fool SGI's "challenged" printing
3090 * tools. First the interface script that tells the tools what kind of
3091 * printer we have...
3094 snprintf(filename
, sizeof(filename
), "/var/spool/lp/interface/%s", p
->name
);
3096 if (p
->type
& CUPS_PRINTER_CLASS
)
3098 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
3100 cupsFilePuts(fp
, "#!/bin/sh\n");
3102 if ((attr
= ippFindAttribute(p
->attrs
, "printer-make-and-model",
3103 IPP_TAG_TEXT
)) != NULL
)
3104 cupsFilePrintf(fp
, "NAME=\"%s\"\n", attr
->values
[0].string
.text
);
3105 else if (p
->type
& CUPS_PRINTER_CLASS
)
3106 cupsFilePuts(fp
, "NAME=\"Printer Class\"\n");
3108 cupsFilePuts(fp
, "NAME=\"Remote Destination\"\n");
3110 if (p
->type
& CUPS_PRINTER_COLOR
)
3111 cupsFilePuts(fp
, "TYPE=ColorPostScript\n");
3113 cupsFilePuts(fp
, "TYPE=MonoPostScript\n");
3115 cupsFilePrintf(fp
, "HOSTNAME=%s\n", ServerName
);
3116 cupsFilePrintf(fp
, "HOSTPRINTER=%s\n", p
->name
);
3120 chmod(filename
, 0755);
3121 chown(filename
, User
, Group
);
3125 * Then the member file that tells which device file the queue is connected
3126 * to... Networked printers use "/dev/null" in this file, so that's what
3127 * we use (the actual device URI can confuse some apps...)
3130 snprintf(filename
, sizeof(filename
), "/var/spool/lp/member/%s", p
->name
);
3132 if (p
->type
& CUPS_PRINTER_CLASS
)
3134 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
3136 cupsFilePuts(fp
, "/dev/null\n");
3140 chmod(filename
, 0644);
3141 chown(filename
, User
, Group
);
3145 * The gui_interface file is a script or program that launches a GUI
3146 * option panel for the printer, using options specified on the
3147 * command-line in the third argument. The option panel must send
3148 * any printing options to stdout on a single line when the user
3149 * accepts them, or nothing if the user cancels the dialog.
3151 * The default options panel program is /usr/bin/glpoptions, from
3152 * the ESP Print Pro software. You can select another using the
3153 * PrintcapGUI option.
3156 snprintf(filename
, sizeof(filename
), "/var/spool/lp/gui_interface/ELF/%s.gui", p
->name
);
3158 if (p
->type
& CUPS_PRINTER_CLASS
)
3160 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
3162 cupsFilePuts(fp
, "#!/bin/sh\n");
3163 cupsFilePrintf(fp
, "%s -d %s -o \"$3\"\n", PrintcapGUI
, p
->name
);
3167 chmod(filename
, 0755);
3168 chown(filename
, User
, Group
);
3172 * The POD config file is needed by the printstatus command to show
3173 * the printer location and device.
3176 snprintf(filename
, sizeof(filename
), "/var/spool/lp/pod/%s.config", p
->name
);
3178 if (p
->type
& CUPS_PRINTER_CLASS
)
3180 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
3182 cupsFilePrintf(fp
, "Printer Class | %s\n",
3183 (p
->type
& CUPS_PRINTER_COLOR
) ? "ColorPostScript" : "MonoPostScript");
3184 cupsFilePrintf(fp
, "Printer Model | %s\n", p
->make_model
? p
->make_model
: "");
3185 cupsFilePrintf(fp
, "Location Code | %s\n", p
->location
? p
->location
: "");
3186 cupsFilePrintf(fp
, "Physical Location | %s\n", p
->info
? p
->info
: "");
3187 cupsFilePrintf(fp
, "Port Path | %s\n", p
->device_uri
? p
->device_uri
: "");
3188 cupsFilePrintf(fp
, "Config Path | /var/spool/lp/pod/%s.config\n", p
->name
);
3189 cupsFilePrintf(fp
, "Active Status Path | /var/spool/lp/pod/%s.status\n", p
->name
);
3190 cupsFilePuts(fp
, "Status Update Wait | 10 seconds\n");
3194 chmod(filename
, 0664);
3195 chown(filename
, User
, Group
);
3201 * 'write_irix_state()' - Update the status files used by IRIX printing
3206 write_irix_state(cupsd_printer_t
*p
) /* I - Printer to update */
3208 char filename
[1024]; /* Interface script filename */
3209 cups_file_t
*fp
; /* Interface script file */
3210 int tag
; /* Status tag value */
3216 * The POD status file is needed for the printstatus window to
3217 * provide the current status of the printer.
3220 snprintf(filename
, sizeof(filename
), "/var/spool/lp/pod/%s.status", p
->name
);
3222 if (p
->type
& CUPS_PRINTER_CLASS
)
3224 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
3226 cupsFilePrintf(fp
, "Operational Status | %s\n",
3227 (p
->state
== IPP_PRINTER_IDLE
) ? "Idle" :
3228 (p
->state
== IPP_PRINTER_PROCESSING
) ? "Busy" :
3230 cupsFilePrintf(fp
, "Information | 01 00 00 | %s\n", CUPS_SVERSION
);
3231 cupsFilePrintf(fp
, "Information | 02 00 00 | Device URI: %s\n",
3232 p
->device_uri
? p
->device_uri
: "");
3233 cupsFilePrintf(fp
, "Information | 03 00 00 | %s jobs\n",
3234 p
->accepting
? "Accepting" : "Not accepting");
3235 cupsFilePrintf(fp
, "Information | 04 00 00 | %s\n", p
->state_message
);
3239 chmod(filename
, 0664);
3240 chown(filename
, User
, Group
);
3244 * The activeicons file is needed to provide desktop icons for printers:
3246 * [ quoted from /usr/lib/print/tagit ]
3248 * --- Type of printer tags (base values)
3250 * Dumb=66048 # 0x10200
3251 * DumbColor=66080 # 0x10220
3252 * Raster=66112 # 0x10240
3253 * ColorRaster=66144 # 0x10260
3254 * Plotter=66176 # 0x10280
3255 * PostScript=66208 # 0x102A0
3256 * ColorPostScript=66240 # 0x102C0
3257 * MonoPostScript=66272 # 0x102E0
3259 * --- Printer state modifiers for local printers
3264 * Unknown=3 # 0x3 (Faulted due to unknown reason)
3266 * --- Printer state modifiers for network printers
3270 * NetFaulted=10 # 0xA
3271 * NetUnknown=11 # 0xB (Faulted due to unknown reason)
3274 snprintf(filename
, sizeof(filename
), "/var/spool/lp/activeicons/%s", p
->name
);
3276 if (p
->type
& CUPS_PRINTER_CLASS
)
3278 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
3280 if (p
->type
& CUPS_PRINTER_COLOR
)
3285 if (p
->type
& CUPS_PRINTER_REMOTE
)
3288 if (p
->state
== IPP_PRINTER_PROCESSING
)
3291 else if (p
->state
== IPP_PRINTER_STOPPED
)
3294 cupsFilePuts(fp
, "#!/bin/sh\n");
3295 cupsFilePrintf(fp
, "#Tag %d\n", tag
);
3299 chmod(filename
, 0755);
3300 chown(filename
, User
, Group
);
3305 * The default file is needed by the printers window to show
3306 * the default printer.
3309 snprintf(filename
, sizeof(filename
), "/var/spool/lp/default");
3311 if (DefaultPrinter
!= NULL
)
3313 if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
3315 cupsFilePrintf(fp
, "%s\n", DefaultPrinter
->name
);
3319 chmod(filename
, 0644);
3320 chown(filename
, User
, Group
);