2 * "$Id: printers.c,v 1.150 2003/04/25 15:23:22 mike Exp $"
4 * Printer routines for the Common UNIX Printing System (CUPS).
6 * Copyright 1997-2003 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-3111 USA
20 * Voice: (301) 373-9603
21 * EMail: cups-info@cups.org
22 * WWW: http://www.cups.org
26 * AddPrinter() - Add a printer to the system.
27 * AddPrinterFilter() - Add a MIME filter for a printer.
28 * AddPrinterHistory() - Add the current printer state to the history.
29 * AddPrinterUser() - Add a user to the ACL.
30 * DeleteAllPrinters() - Delete all printers from the system.
31 * DeletePrinter() - Delete a printer from the system.
32 * DeletePrinterFilters() - Delete all MIME filters for a printer.
33 * FindPrinter() - Find a printer in the list.
34 * FreePrinterUsers() - Free allow/deny users.
35 * LoadAllPrinters() - Load printers from the printers.conf file.
36 * SaveAllPrinters() - Save all printer definitions to the printers.conf
37 * SetPrinterAttrs() - Set printer attributes based upon the PPD file.
38 * SetPrinterReasons() - Set/update the reasons strings.
39 * SetPrinterState() - Update the current state of a printer.
40 * SortPrinters() - Sort the printer list when a printer name is
42 * StopPrinter() - Stop a printer from printing any jobs...
43 * ValidateDest() - Validate a printer/class destination.
44 * WritePrintcap() - Write a pseudo-printcap file for older
45 * applications that need it...
46 * write_irix_config() - Update the config files used by the IRIX
48 * write_irix_state() - Update the status files used by IRIX printing
53 * Include necessary headers...
64 static void write_irix_config(printer_t
*p
);
65 static void write_irix_state(printer_t
*p
);
70 * 'AddPrinter()' - Add a printer to the system.
73 printer_t
* /* O - New printer */
74 AddPrinter(const char *name
) /* I - Name of printer */
76 printer_t
*p
, /* New printer */
77 *current
, /* Current printer in list */
78 *prev
; /* Previous printer in list */
82 * Range check input...
85 LogMessage(L_DEBUG2
, "AddPrinter(\"%s\")", name
? name
: "(null)");
91 * Create a new printer entity...
94 if ((p
= calloc(1, sizeof(printer_t
))) == NULL
)
96 LogMessage(L_ERROR
, "Unable to allocate memory for printer - %s",
101 SetString(&p
->name
, name
);
102 SetString(&p
->info
, name
);
103 SetString(&p
->hostname
, ServerName
);
104 SetStringf(&p
->uri
, "ipp://%s:%d/printers/%s", ServerName
,
105 ntohs(Listeners
[0].address
.sin_port
), name
);
106 SetStringf(&p
->device_uri
, "file:/dev/null");
108 p
->state
= IPP_PRINTER_STOPPED
;
110 p
->filetype
= mimeAddType(MimeDatabase
, "printer", name
);
112 SetString(&p
->job_sheets
[0], "none");
113 SetString(&p
->job_sheets
[1], "none");
115 if (MaxPrinterHistory
)
116 p
->history
= calloc(MaxPrinterHistory
, sizeof(ipp_t
*));
119 * Insert the printer in the printer list alphabetically...
122 for (prev
= NULL
, current
= Printers
;
124 prev
= current
, current
= current
->next
)
125 if (strcasecmp(p
->name
, current
->name
) < 0)
129 * Insert this printer before the current one...
140 * Write a new /etc/printcap or /var/spool/lp/pstatus file.
150 * 'AddPrinterFilter()' - Add a MIME filter for a printer.
154 AddPrinterFilter(printer_t
*p
, /* I - Printer to add to */
155 const char *filter
) /* I - Filter to add */
157 int i
; /* Looping var */
158 char super
[MIME_MAX_SUPER
], /* Super-type for filter */
159 type
[MIME_MAX_TYPE
], /* Type for filter */
160 program
[1024]; /* Program/filter name */
161 int cost
; /* Cost of filter */
162 mime_type_t
**temptype
; /* MIME type looping var */
166 * Range check input...
169 if (p
== NULL
|| p
->filetype
== NULL
|| filter
== NULL
)
173 * Parse the filter string; it should be in the following format:
175 * super/type cost program
178 if (sscanf(filter
, "%15[^/]/%31s%d%1023s", super
, type
, &cost
, program
) != 4)
180 LogMessage(L_ERROR
, "AddPrinterFilter: Invalid filter string \"%s\"!",
186 * Add the filter to the MIME database, supporting wildcards as needed...
189 for (temptype
= MimeDatabase
->types
, i
= MimeDatabase
->num_types
;
192 if (((super
[0] == '*' && strcasecmp((*temptype
)->super
, "printer") != 0) ||
193 strcasecmp((*temptype
)->super
, super
) == 0) &&
194 (type
[0] == '*' || strcasecmp((*temptype
)->type
, type
) == 0))
196 LogMessage(L_DEBUG2
, "Adding filter %s/%s %s/%s %d %s",
197 (*temptype
)->super
, (*temptype
)->type
,
198 p
->filetype
->super
, p
->filetype
->type
,
200 mimeAddFilter(MimeDatabase
, *temptype
, p
->filetype
, cost
, program
);
206 * 'AddPrinterHistory()' - Add the current printer state to the history.
210 AddPrinterHistory(printer_t
*p
) /* I - Printer */
212 ipp_t
*history
; /* History collection */
216 * Stop early if we aren't keeping history data...
219 if (MaxPrinterHistory
<= 0)
223 * Retire old history data as needed...
226 p
->sequence_number
++;
228 if (p
->num_history
>= MaxPrinterHistory
)
231 ippDelete(p
->history
[0]);
232 memmove(p
->history
, p
->history
+ 1, p
->num_history
* sizeof(ipp_t
*));
236 * Create a collection containing the current printer-state, printer-up-time,
237 * printer-state-message, and printer-state-reasons attributes.
241 ippAddInteger(history
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-state",
243 ippAddBoolean(history
, IPP_TAG_PRINTER
, "printer-is-accepting-jobs",
245 ippAddString(history
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-state-message",
246 NULL
, p
->state_message
);
247 if (p
->num_reasons
== 0)
248 ippAddString(history
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
249 "printer-state-reasons", NULL
,
250 p
->state
== IPP_PRINTER_STOPPED
? "paused" : "none");
252 ippAddStrings(history
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
253 "printer-state-reasons", p
->num_reasons
, NULL
,
254 (const char * const *)p
->reasons
);
255 ippAddInteger(history
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
256 "printer-state-time", p
->state_time
);
257 ippAddInteger(history
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
258 "printer-state-sequence-number", p
->sequence_number
);
260 p
->history
[p
->num_history
] = history
;
266 * 'AddPrinterUser()' - Add a user to the ACL.
270 AddPrinterUser(printer_t
*p
, /* I - Printer */
271 const char *username
) /* I - User */
273 const char **temp
; /* Temporary array pointer */
279 if (p
->num_users
== 0)
280 temp
= malloc(sizeof(char **));
282 temp
= realloc(p
->users
, sizeof(char **) * (p
->num_users
+ 1));
288 temp
+= p
->num_users
;
290 if ((*temp
= strdup(username
)) != NULL
)
296 * 'DeleteAllPrinters()' - Delete all printers from the system.
300 DeleteAllPrinters(void)
302 printer_t
*p
, /* Pointer to current printer/class */
303 *next
; /* Pointer to next printer in list */
306 for (p
= Printers
; p
!= NULL
; p
= next
)
310 if (!(p
->type
& CUPS_PRINTER_CLASS
))
316 ippDelete(CommonData
);
323 * 'DeletePrinter()' - Delete a printer from the system.
327 DeletePrinter(printer_t
*p
) /* I - Printer to delete */
329 int i
; /* Looping var */
330 printer_t
*current
, /* Current printer in list */
331 *prev
; /* Previous printer in list */
333 char filename
[1024]; /* Interface script filename */
337 DEBUG_printf(("DeletePrinter(%08x): p->name = \"%s\"...\n", p
, p
->name
));
340 * Range check input...
347 * Remove the printer from the list...
350 for (prev
= NULL
, current
= Printers
;
352 prev
= current
, current
= current
->next
)
358 LogMessage(L_ERROR
, "Tried to delete a non-existent printer %s!\n",
366 prev
->next
= p
->next
;
369 * Stop printing on this printer...
375 * Remove the dummy interface/icon/option files under IRIX...
379 snprintf(filename
, sizeof(filename
), "/var/spool/lp/interface/%s", p
->name
);
382 snprintf(filename
, sizeof(filename
), "/var/spool/lp/gui_interface/ELF/%s.gui",
386 snprintf(filename
, sizeof(filename
), "/var/spool/lp/activeicons/%s", p
->name
);
389 snprintf(filename
, sizeof(filename
), "/var/spool/lp/pod/%s.config", p
->name
);
392 snprintf(filename
, sizeof(filename
), "/var/spool/lp/pod/%s.status", p
->name
);
395 snprintf(filename
, sizeof(filename
), "/var/spool/lp/member/%s", p
->name
);
400 * If p is the default printer, assign the next one...
403 if (p
== DefaultPrinter
)
405 DefaultPrinter
= Printers
;
411 * Remove this printer from any classes...
414 if (!(p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
)))
415 DeletePrinterFromClasses(p
);
418 * Free all memory used by the printer...
421 if (p
->printers
!= NULL
)
424 if (MaxPrinterHistory
)
426 for (i
= 0; i
< p
->num_history
; i
++)
427 ippDelete(p
->history
[i
]);
432 for (i
= 0; i
< p
->num_reasons
; i
++)
437 DeletePrinterFilters(p
);
442 ClearString(&p
->uri
);
443 ClearString(&p
->hostname
);
444 ClearString(&p
->name
);
445 ClearString(&p
->location
);
446 ClearString(&p
->make_model
);
447 ClearString(&p
->info
);
448 ClearString(&p
->job_sheets
[0]);
449 ClearString(&p
->job_sheets
[1]);
450 ClearString(&p
->device_uri
);
455 * Write a new /etc/printcap file...
463 * 'DeletePrinterFilters()' - Delete all MIME filters for a printer.
467 DeletePrinterFilters(printer_t
*p
) /* I - Printer to remove from */
469 int i
; /* Looping var */
470 mime_filter_t
*filter
; /* MIME filter looping var */
474 * Range check input...
481 * Remove all filters from the MIME database that have a destination
485 for (filter
= MimeDatabase
->filters
, i
= MimeDatabase
->num_filters
;
488 if (filter
->dst
== p
->filetype
)
491 * Delete the current filter...
494 MimeDatabase
->num_filters
--;
497 memcpy(filter
, filter
+ 1, sizeof(mime_filter_t
) * (i
- 1));
505 * 'FindDest()' - Find a destination in the list.
508 printer_t
* /* O - Destination in list */
509 FindDest(const char *name
) /* I - Name of printer or class to find */
511 printer_t
*p
; /* Current destination */
512 int diff
; /* Difference */
515 for (p
= Printers
; p
!= NULL
; p
= p
->next
)
516 if ((diff
= strcasecmp(name
, p
->name
)) == 0)/* name == p->name */
518 else if (diff
< 0) /* name < p->name */
526 * 'FindPrinter()' - Find a printer in the list.
529 printer_t
* /* O - Printer in list */
530 FindPrinter(const char *name
) /* I - Name of printer to find */
532 printer_t
*p
; /* Current printer */
533 int diff
; /* Difference */
536 for (p
= Printers
; p
!= NULL
; p
= p
->next
)
537 if ((diff
= strcasecmp(name
, p
->name
)) == 0 &&
538 !(p
->type
& CUPS_PRINTER_CLASS
)) /* name == p->name */
540 else if (diff
< 0) /* name < p->name */
548 * 'FreePrinterUsers()' - Free allow/deny users.
552 FreePrinterUsers(printer_t
*p
) /* I - Printer */
554 int i
; /* Looping var */
557 if (!p
|| !p
->num_users
)
560 for (i
= 0; i
< p
->num_users
; i
++)
561 free((void *)p
->users
[i
]);
571 * 'LoadAllPrinters()' - Load printers from the printers.conf file.
575 LoadAllPrinters(void)
577 cups_file_t
*fp
; /* printers.conf file */
578 int linenum
; /* Current line number */
579 int len
; /* Length of line */
580 char line
[1024], /* Line from file */
581 name
[256], /* Parameter name */
582 *nameptr
, /* Pointer into name */
583 *value
, /* Pointer to value */
584 *valueptr
; /* Pointer into value */
585 printer_t
*p
; /* Current printer */
589 * Open the printers.conf file...
592 snprintf(line
, sizeof(line
), "%s/printers.conf", ServerRoot
);
593 if ((fp
= cupsFileOpen(line
, "r")) == NULL
)
595 LogMessage(L_ERROR
, "LoadAllPrinters: Unable to open %s - %s", line
,
601 * Read printer configurations until we hit EOF...
607 while (cupsFileGets(fp
, line
, sizeof(line
)) != NULL
)
612 * Skip comment lines...
619 * Strip trailing whitespace, if any...
624 while (len
> 0 && isspace(line
[len
- 1]))
631 * Extract the name from the beginning of the line...
634 for (value
= line
; isspace(*value
); value
++);
636 for (nameptr
= name
; *value
!= '\0' && !isspace(*value
) &&
637 nameptr
< (name
+ sizeof(name
) - 1);)
638 *nameptr
++ = *value
++;
641 while (isspace(*value
))
648 * Decode the directive...
651 if (strcmp(name
, "<Printer") == 0 ||
652 strcmp(name
, "<DefaultPrinter") == 0)
655 * <Printer name> or <DefaultPrinter name>
658 if (line
[len
- 1] == '>' && p
== NULL
)
661 * Add the printer and a base file type...
664 line
[len
- 1] = '\0';
666 LogMessage(L_DEBUG
, "LoadAllPrinters: Loading printer %s...", value
);
668 p
= AddPrinter(value
);
670 p
->state
= IPP_PRINTER_IDLE
;
673 * Set the default printer as needed...
676 if (strcmp(name
, "<DefaultPrinter") == 0)
681 LogMessage(L_ERROR
, "Syntax error on line %d of printers.conf.",
686 else if (strcmp(name
, "</Printer>") == 0)
691 AddPrinterHistory(p
);
696 LogMessage(L_ERROR
, "Syntax error on line %d of printers.conf.",
703 LogMessage(L_ERROR
, "Syntax error on line %d of printers.conf.",
707 else if (strcmp(name
, "Info") == 0)
708 SetString(&p
->info
, value
);
709 else if (strcmp(name
, "Location") == 0)
710 SetString(&p
->location
, value
);
711 else if (strcmp(name
, "DeviceURI") == 0)
712 SetString(&p
->device_uri
, value
);
713 else if (strcmp(name
, "State") == 0)
716 * Set the initial queue state...
719 if (strcasecmp(value
, "idle") == 0)
720 p
->state
= IPP_PRINTER_IDLE
;
721 else if (strcasecmp(value
, "stopped") == 0)
722 p
->state
= IPP_PRINTER_STOPPED
;
724 else if (strcmp(name
, "StateMessage") == 0)
727 * Set the initial queue state message...
730 while (isspace(*value
))
733 strlcpy(p
->state_message
, value
, sizeof(p
->state_message
));
735 else if (strcmp(name
, "Accepting") == 0)
738 * Set the initial accepting state...
741 if (strcasecmp(value
, "yes") == 0)
746 else if (strcmp(name
, "JobSheets") == 0)
749 * Set the initial job sheets...
752 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
); valueptr
++);
757 SetString(&p
->job_sheets
[0], value
);
759 while (isspace(*valueptr
))
764 for (value
= valueptr
; *valueptr
&& !isspace(*valueptr
); valueptr
++);
769 SetString(&p
->job_sheets
[1], value
);
772 else if (strcmp(name
, "AllowUser") == 0)
775 AddPrinterUser(p
, value
);
777 else if (strcmp(name
, "DenyUser") == 0)
780 AddPrinterUser(p
, value
);
782 else if (strcmp(name
, "QuotaPeriod") == 0)
783 p
->quota_period
= atoi(value
);
784 else if (strcmp(name
, "PageLimit") == 0)
785 p
->page_limit
= atoi(value
);
786 else if (strcmp(name
, "KLimit") == 0)
787 p
->k_limit
= atoi(value
);
791 * Something else we don't understand...
794 LogMessage(L_ERROR
, "Unknown configuration directive %s on line %d of printers.conf.",
804 * 'SaveAllPrinters()' - Save all printer definitions to the printers.conf
809 SaveAllPrinters(void)
811 int i
; /* Looping var */
812 cups_file_t
*fp
; /* printers.conf file */
813 char temp
[1024]; /* Temporary string */
814 char backup
[1024]; /* printers.conf.O file */
815 printer_t
*printer
; /* Current printer class */
816 time_t curtime
; /* Current time */
817 struct tm
*curdate
; /* Current date */
821 * Create the printers.conf file...
824 snprintf(temp
, sizeof(temp
), "%s/printers.conf", ServerRoot
);
825 snprintf(backup
, sizeof(backup
), "%s/printers.conf.O", ServerRoot
);
827 if (rename(temp
, backup
))
828 LogMessage(L_ERROR
, "Unable to backup printers.conf - %s", strerror(errno
));
830 if ((fp
= cupsFileOpen(temp
, "w")) == NULL
)
832 LogMessage(L_ERROR
, "Unable to save printers.conf - %s", strerror(errno
));
834 if (rename(backup
, temp
))
835 LogMessage(L_ERROR
, "Unable to restore printers.conf - %s", strerror(errno
));
839 LogMessage(L_INFO
, "Saving printers.conf...");
842 * Restrict access to the file...
845 fchown(cupsFileNumber(fp
), User
, Group
);
846 fchmod(cupsFileNumber(fp
), ConfigFilePerm
);
849 * Write a small header to the file...
852 curtime
= time(NULL
);
853 curdate
= localtime(&curtime
);
854 strftime(temp
, sizeof(temp
) - 1, CUPS_STRFTIME_FORMAT
, curdate
);
856 cupsFilePuts(fp
, "# Printer configuration file for " CUPS_SVERSION
"\n");
857 cupsFilePrintf(fp
, "# Written by cupsd on %s\n", temp
);
860 * Write each local printer known to the system...
863 for (printer
= Printers
; printer
!= NULL
; printer
= printer
->next
)
866 * Skip remote destinations and printer classes...
869 if ((printer
->type
& CUPS_PRINTER_REMOTE
) ||
870 (printer
->type
& CUPS_PRINTER_CLASS
) ||
871 (printer
->type
& CUPS_PRINTER_IMPLICIT
))
875 * Write printers as needed...
878 if (printer
== DefaultPrinter
)
879 cupsFilePrintf(fp
, "<DefaultPrinter %s>\n", printer
->name
);
881 cupsFilePrintf(fp
, "<Printer %s>\n", printer
->name
);
884 cupsFilePrintf(fp
, "Info %s\n", printer
->info
);
886 if (printer
->location
)
887 cupsFilePrintf(fp
, "Location %s\n", printer
->location
);
889 if (printer
->device_uri
)
890 cupsFilePrintf(fp
, "DeviceURI %s\n", printer
->device_uri
);
892 if (printer
->state
== IPP_PRINTER_STOPPED
)
894 cupsFilePuts(fp
, "State Stopped\n");
895 cupsFilePrintf(fp
, "StateMessage %s\n", printer
->state_message
);
898 cupsFilePuts(fp
, "State Idle\n");
900 if (printer
->accepting
)
901 cupsFilePuts(fp
, "Accepting Yes\n");
903 cupsFilePuts(fp
, "Accepting No\n");
905 cupsFilePrintf(fp
, "JobSheets %s %s\n", printer
->job_sheets
[0],
906 printer
->job_sheets
[1]);
908 cupsFilePrintf(fp
, "QuotaPeriod %d\n", printer
->quota_period
);
909 cupsFilePrintf(fp
, "PageLimit %d\n", printer
->page_limit
);
910 cupsFilePrintf(fp
, "KLimit %d\n", printer
->k_limit
);
912 for (i
= 0; i
< printer
->num_users
; i
++)
913 cupsFilePrintf(fp
, "%sUser %s\n", printer
->deny_users
? "Deny" : "Allow",
916 cupsFilePuts(fp
, "</Printer>\n");
920 * Make IRIX desktop & printer status happy
923 write_irix_state(printer
);
932 * 'SetPrinterAttrs()' - Set printer attributes based upon the PPD file.
936 SetPrinterAttrs(printer_t
*p
) /* I - Printer to setup */
938 char uri
[HTTP_MAX_URI
]; /* URI for printer */
939 char method
[HTTP_MAX_URI
], /* Method portion of URI */
940 username
[HTTP_MAX_URI
], /* Username portion of URI */
941 host
[HTTP_MAX_URI
], /* Host portion of URI */
942 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
943 int port
; /* Port portion of URI */
944 int i
; /* Looping var */
945 char filename
[1024]; /* Name of PPD file */
946 int num_media
; /* Number of media options */
947 location_t
*auth
; /* Pointer to authentication element */
948 const char *auth_supported
; /* Authentication supported */
949 cups_ptype_t printer_type
; /* Printer type data */
950 ppd_file_t
*ppd
; /* PPD file data */
951 ppd_option_t
*input_slot
, /* InputSlot options */
952 *media_type
, /* MediaType options */
953 *page_size
, /* PageSize options */
954 *output_bin
, /* OutputBin options */
955 *media_quality
; /* EFMediaQualityMode options */
956 ppd_attr_t
*ppdattr
; /* PPD attribute */
957 ipp_attribute_t
*attr
; /* Attribute data */
958 ipp_value_t
*val
; /* Attribute value */
959 int nups
[] = /* number-up-supported values */
960 { 1, 2, 4, 6, 9, 16 };
961 ipp_orient_t orients
[4] = /* orientation-requested-supported values */
965 IPP_REVERSE_LANDSCAPE
,
968 const char *sides
[3] = /* sides-supported values */
974 const char *versions
[] = /* ipp-versions-supported values */
979 ipp_op_t ops
[] = /* operations-supported values */
986 IPP_GET_JOB_ATTRIBUTES
,
988 IPP_GET_PRINTER_ATTRIBUTES
,
994 IPP_SET_JOB_ATTRIBUTES
,
1000 CUPS_DELETE_PRINTER
,
1010 const char *charsets
[] = /* charset-supported values */
1040 const char *compressions
[] =
1047 #endif /* HAVE_LIBZ */
1050 ipp_finish_t finishings
[5];
1051 const char *multiple_document_handling
[] =
1053 "separate-documents-uncollated-copies",
1054 "separate-documents-collated-copies"
1058 DEBUG_printf(("SetPrinterAttrs: entering name = %s, type = %x\n", p
->name
,
1062 * Make sure that we have the common attributes defined...
1067 CommonData
= ippNew();
1069 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
1070 "pdl-override-supported", NULL
, "not-attempted");
1071 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
1072 "ipp-versions-supported", sizeof(versions
) / sizeof(versions
[0]),
1074 ippAddIntegers(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "operations-supported",
1075 sizeof(ops
) / sizeof(ops
[0]) + JobFiles
- 1, (int *)ops
);
1076 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
, "multiple-document-jobs-supported", 1);
1077 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
1078 "multiple-operation-time-out", 60);
1079 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
1080 "multiple-document-handling-supported",
1081 sizeof(multiple_document_handling
) /
1082 sizeof(multiple_document_handling
[0]), NULL
,
1083 multiple_document_handling
);
1084 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_CHARSET
, "charset-configured",
1085 NULL
, DefaultCharset
);
1086 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_CHARSET
, "charset-supported",
1087 sizeof(charsets
) / sizeof(charsets
[0]), NULL
, charsets
);
1088 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_LANGUAGE
,
1089 "natural-language-configured", NULL
, DefaultLanguage
);
1090 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_LANGUAGE
,
1091 "generated-natural-language-supported", NULL
, DefaultLanguage
);
1092 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_MIMETYPE
,
1093 "document-format-default", NULL
, "application/octet-stream");
1094 ippAddStrings(CommonData
, IPP_TAG_PRINTER
,
1095 (ipp_tag_t
)(IPP_TAG_MIMETYPE
| IPP_TAG_COPY
),
1096 "document-format-supported", NumMimeTypes
, NULL
, MimeTypes
);
1097 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
1098 "compression-supported",
1099 sizeof(compressions
) / sizeof(compressions
[0]),
1100 NULL
, compressions
);
1101 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
1102 "job-priority-supported", 100);
1103 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
1104 "job-priority-default", 50);
1105 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "copies-supported", 1, MaxCopies
);
1106 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
1107 "copies-default", 1);
1108 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
, "page-ranges-supported", 1);
1109 ippAddIntegers(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
1110 "number-up-supported", sizeof(nups
) / sizeof(nups
[0]), nups
);
1111 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
1112 "number-up-default", 1);
1113 ippAddIntegers(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
1114 "orientation-requested-supported", 4, (int *)orients
);
1115 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
1116 "orientation-requested-default", IPP_PORTRAIT
);
1121 * Setup the job-sheets-supported and job-sheets-default attributes...
1124 if (Classification
&& !ClassifyOverride
)
1125 attr
= ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
1126 "job-sheets-supported", NULL
, Classification
);
1128 attr
= ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
1129 "job-sheets-supported", NumBanners
+ 1, NULL
, NULL
);
1132 LogMessage(L_EMERG
, "SetPrinterAttrs: Unable to allocate memory for "
1133 "job-sheets-supported attribute: %s!",
1135 else if (!Classification
|| ClassifyOverride
)
1137 attr
->values
[0].string
.text
= strdup("none");
1139 for (i
= 0; i
< NumBanners
; i
++)
1140 attr
->values
[i
+ 1].string
.text
= strdup(Banners
[i
].name
);
1146 * Clear out old filters and add a filter from application/vnd.cups-raw to
1147 * printer/name to handle "raw" printing by users.
1150 DeletePrinterFilters(p
);
1151 AddPrinterFilter(p
, "application/vnd.cups-raw 0 -");
1154 * Figure out the authentication that is required for the printer.
1157 auth_supported
= "requesting-user-name";
1158 if (!(p
->type
& CUPS_PRINTER_REMOTE
))
1160 if (p
->type
& CUPS_PRINTER_CLASS
)
1161 snprintf(resource
, sizeof(resource
), "/classes/%s", p
->name
);
1163 snprintf(resource
, sizeof(resource
), "/printers/%s", p
->name
);
1165 if ((auth
= FindBest(resource
, HTTP_POST
)) != NULL
)
1167 if (auth
->type
== AUTH_BASIC
|| auth
->type
== AUTH_BASICDIGEST
)
1168 auth_supported
= "basic";
1169 else if (auth
->type
== AUTH_DIGEST
)
1170 auth_supported
= "digest";
1175 * Create the required IPP attributes for a printer...
1179 ippDelete(p
->attrs
);
1181 p
->attrs
= ippNew();
1183 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "printer-uri-supported",
1185 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
1186 "uri-authentication-supported", NULL
, auth_supported
);
1187 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
1188 "uri-security-supported", NULL
, "none");
1189 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
, "printer-name", NULL
,
1191 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-location",
1192 NULL
, p
->location
? p
->location
: "");
1193 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-info",
1194 NULL
, p
->info
? p
->info
: "");
1195 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "printer-more-info",
1201 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
1202 "requesting-user-name-denied", p
->num_users
, NULL
,
1205 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
1206 "requesting-user-name-allowed", p
->num_users
, NULL
,
1210 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
1211 "job-quota-period", p
->quota_period
);
1212 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
1213 "job-k-limit", p
->k_limit
);
1214 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
1215 "job-page-limit", p
->page_limit
);
1217 if (NumBanners
> 0 && !(p
->type
& CUPS_PRINTER_REMOTE
))
1220 * Setup the job-sheets-default attribute...
1223 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
1224 "job-sheets-default", 2, NULL
, NULL
);
1228 attr
->values
[0].string
.text
= strdup(Classification
?
1229 Classification
: p
->job_sheets
[0]);
1230 attr
->values
[1].string
.text
= strdup(Classification
?
1231 Classification
: p
->job_sheets
[1]);
1235 printer_type
= p
->type
;
1239 if (p
->type
& CUPS_PRINTER_REMOTE
)
1242 * Tell the client this is a remote printer of some type...
1245 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
1246 "printer-make-and-model", NULL
, p
->make_model
);
1253 * Assign additional attributes depending on whether this is a printer
1257 p
->type
&= ~CUPS_PRINTER_OPTIONS
;
1259 if (p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
))
1262 * Add class-specific attributes...
1265 if ((p
->type
& CUPS_PRINTER_IMPLICIT
) && p
->num_printers
> 0)
1266 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
1267 "printer-make-and-model", NULL
, p
->printers
[0]->make_model
);
1269 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
1270 "printer-make-and-model", NULL
, "Local Printer Class");
1272 if (p
->num_printers
> 0)
1275 * Add a list of member URIs and names...
1278 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
1279 "member-uris", p
->num_printers
, NULL
, NULL
);
1280 p
->type
|= CUPS_PRINTER_OPTIONS
;
1282 for (i
= 0; i
< p
->num_printers
; i
++)
1285 attr
->values
[i
].string
.text
= strdup(p
->printers
[i
]->uri
);
1287 p
->type
&= ~CUPS_PRINTER_OPTIONS
| p
->printers
[i
]->type
;
1290 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
1291 "member-names", p
->num_printers
, NULL
, NULL
);
1295 for (i
= 0; i
< p
->num_printers
; i
++)
1296 attr
->values
[i
].string
.text
= strdup(p
->printers
[i
]->name
);
1303 * Add printer-specific attributes... Start by sanitizing the device
1304 * URI so it doesn't have a username or password in it...
1308 strcpy(uri
, "file:/dev/null");
1309 else if (strstr(p
->device_uri
, "://") != NULL
)
1312 * http://..., ipp://..., etc.
1315 httpSeparate(p
->device_uri
, method
, username
, host
, &port
, resource
);
1317 snprintf(uri
, sizeof(uri
), "%s://%s:%d%s", method
, host
, port
,
1320 snprintf(uri
, sizeof(uri
), "%s://%s%s", method
, host
, resource
);
1325 * file:..., serial:..., etc.
1328 strlcpy(uri
, p
->device_uri
, sizeof(uri
));
1331 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "device-uri", NULL
,
1335 * Assign additional attributes from the PPD file (if any)...
1338 p
->type
|= CUPS_PRINTER_BW
;
1339 finishings
[0] = IPP_FINISHINGS_NONE
;
1342 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
1345 if ((ppd
= ppdOpenFile(filename
)) != NULL
)
1348 * Add make/model and other various attributes...
1351 if (ppd
->color_device
)
1352 p
->type
|= CUPS_PRINTER_COLOR
;
1353 if (ppd
->variable_sizes
)
1354 p
->type
|= CUPS_PRINTER_VARIABLE
;
1355 if (!ppd
->manual_copies
)
1356 p
->type
|= CUPS_PRINTER_COPIES
;
1357 if ((ppdattr
= ppdFindAttr(ppd
, "cupsFax", NULL
)) != NULL
)
1358 if (ppdattr
->value
&& !strcasecmp(ppdattr
->value
, "true"))
1359 p
->type
|= CUPS_PRINTER_FAX
;
1361 ippAddBoolean(p
->attrs
, IPP_TAG_PRINTER
, "color-supported",
1363 if (ppd
->throughput
)
1364 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
1365 "pages-per-minute", ppd
->throughput
);
1368 SetString(&p
->make_model
, ppd
->nickname
);
1369 else if (ppd
->modelname
)
1370 SetString(&p
->make_model
, ppd
->modelname
);
1372 SetString(&p
->make_model
, "Bad PPD File");
1374 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
1375 "printer-make-and-model", NULL
, p
->make_model
);
1378 * Add media options from the PPD file...
1381 if ((input_slot
= ppdFindOption(ppd
, "InputSlot")) != NULL
)
1382 num_media
= input_slot
->num_choices
;
1386 if ((media_type
= ppdFindOption(ppd
, "MediaType")) != NULL
)
1387 num_media
+= media_type
->num_choices
;
1389 if ((page_size
= ppdFindOption(ppd
, "PageSize")) != NULL
)
1390 num_media
+= page_size
->num_choices
;
1392 if ((media_quality
= ppdFindOption(ppd
, "EFMediaQualityMode")) != NULL
)
1393 num_media
+= media_quality
->num_choices
;
1397 LogMessage(L_CRIT
, "SetPrinterAttrs: The PPD file for printer %s "
1398 "contains no media options and is therefore "
1399 "invalid!", p
->name
);
1403 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
1404 "media-supported", num_media
, NULL
, NULL
);
1409 if (input_slot
!= NULL
)
1410 for (i
= 0; i
< input_slot
->num_choices
; i
++, val
++)
1411 val
->string
.text
= strdup(input_slot
->choices
[i
].choice
);
1413 if (media_type
!= NULL
)
1414 for (i
= 0; i
< media_type
->num_choices
; i
++, val
++)
1415 val
->string
.text
= strdup(media_type
->choices
[i
].choice
);
1417 if (media_quality
!= NULL
)
1418 for (i
= 0; i
< media_quality
->num_choices
; i
++, val
++)
1419 val
->string
.text
= strdup(media_quality
->choices
[i
].choice
);
1421 if (page_size
!= NULL
)
1423 for (i
= 0; i
< page_size
->num_choices
; i
++, val
++)
1424 val
->string
.text
= strdup(page_size
->choices
[i
].choice
);
1426 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
, "media-default",
1427 NULL
, page_size
->defchoice
);
1429 else if (input_slot
!= NULL
)
1430 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
, "media-default",
1431 NULL
, input_slot
->defchoice
);
1432 else if (media_type
!= NULL
)
1433 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
, "media-default",
1434 NULL
, media_type
->defchoice
);
1435 else if (media_quality
!= NULL
)
1436 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
, "media-default",
1437 NULL
, media_quality
->defchoice
);
1439 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
, "media-default",
1448 if ((output_bin
= ppdFindOption(ppd
, "OutputBin")) != NULL
)
1450 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
1451 "output-bin-supported", output_bin
->num_choices
,
1456 for (i
= 0, val
= attr
->values
;
1457 i
< output_bin
->num_choices
;
1459 val
->string
.text
= strdup(output_bin
->choices
[i
].choice
);
1467 if (ppdFindOption(ppd
, "Duplex") != NULL
)
1469 p
->type
|= CUPS_PRINTER_DUPLEX
;
1471 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
, "sides-supported",
1473 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
, "sides-default",
1477 if (ppdFindOption(ppd
, "Collate") != NULL
)
1478 p
->type
|= CUPS_PRINTER_COLLATE
;
1480 if (ppdFindOption(ppd
, "StapleLocation") != NULL
)
1482 p
->type
|= CUPS_PRINTER_STAPLE
;
1483 finishings
[num_finishings
++] = IPP_FINISHINGS_STAPLE
;
1486 if (ppdFindOption(ppd
, "BindEdge") != NULL
)
1488 p
->type
|= CUPS_PRINTER_BIND
;
1489 finishings
[num_finishings
++] = IPP_FINISHINGS_BIND
;
1492 for (i
= 0; i
< ppd
->num_sizes
; i
++)
1493 if (ppd
->sizes
[i
].length
> 1728)
1494 p
->type
|= CUPS_PRINTER_LARGE
;
1495 else if (ppd
->sizes
[i
].length
> 1008)
1496 p
->type
|= CUPS_PRINTER_MEDIUM
;
1498 p
->type
|= CUPS_PRINTER_SMALL
;
1501 * Add any filters in the PPD file...
1504 DEBUG_printf(("ppd->num_filters = %d\n", ppd
->num_filters
));
1505 for (i
= 0; i
< ppd
->num_filters
; i
++)
1507 DEBUG_printf(("ppd->filters[%d] = \"%s\"\n", i
, ppd
->filters
[i
]));
1508 AddPrinterFilter(p
, ppd
->filters
[i
]);
1511 if (ppd
->num_filters
== 0)
1512 AddPrinterFilter(p
, "application/vnd.cups-postscript 0 -");
1516 printer_type
= p
->type
;
1518 else if (access(filename
, 0) == 0)
1520 int pline
; /* PPD line number */
1521 ppd_status_t pstatus
; /* PPD load status */
1524 pstatus
= ppdLastError(&pline
);
1526 LogMessage(L_ERROR
, "PPD file for %s cannot be loaded!", p
->name
);
1528 if (pstatus
<= PPD_ALLOC_ERROR
)
1529 LogMessage(L_ERROR
, "%s", strerror(errno
));
1531 LogMessage(L_ERROR
, "%s on line %d.", ppdErrorString(pstatus
),
1534 LogMessage(L_INFO
, "Hint: Run \"cupstestppd %s\" and fix any errors.",
1537 AddPrinterFilter(p
, "application/vnd.cups-postscript 0 -");
1542 * If we have an interface script, add a filter entry for it...
1545 snprintf(filename
, sizeof(filename
), "%s/interfaces/%s", ServerRoot
,
1547 if (access(filename
, X_OK
) == 0)
1550 * Yes, we have a System V style interface script; use it!
1553 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
1554 "printer-make-and-model", NULL
, "Local System V Printer");
1556 snprintf(filename
, sizeof(filename
), "*/* 0 %s/interfaces/%s",
1557 ServerRoot
, p
->name
);
1558 AddPrinterFilter(p
, filename
);
1560 else if (p
->device_uri
&&
1561 strncmp(p
->device_uri
, "ipp://", 6) == 0 &&
1562 (strstr(p
->device_uri
, "/printers/") != NULL
||
1563 strstr(p
->device_uri
, "/classes/") != NULL
))
1566 * Tell the client this is really a hard-wired remote printer.
1569 printer_type
|= CUPS_PRINTER_REMOTE
;
1572 * Reset the printer-uri-supported attribute to point at the
1576 attr
= ippFindAttribute(p
->attrs
, "printer-uri-supported", IPP_TAG_URI
);
1577 free(attr
->values
[0].string
.text
);
1578 attr
->values
[0].string
.text
= strdup(p
->device_uri
);
1581 * Then set the make-and-model accordingly...
1584 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
1585 "printer-make-and-model", NULL
, "Remote Printer");
1588 * Print all files directly...
1596 * Otherwise we have neither - treat this as a "dumb" printer
1597 * with no PPD file...
1600 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
1601 "printer-make-and-model", NULL
, "Local Raw Printer");
1607 ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
1608 "finishings-supported", num_finishings
, (int *)finishings
);
1609 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
1610 "finishings-default", IPP_FINISHINGS_NONE
);
1615 * Add the CUPS-specific printer-type attribute...
1618 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-type",
1621 DEBUG_printf(("SetPrinterAttrs: leaving name = %s, type = %x\n", p
->name
,
1626 * Write the IRIX printer config and status files...
1629 write_irix_config(p
);
1630 write_irix_state(p
);
1636 * 'SetPrinterReasons()' - Set/update the reasons strings.
1640 SetPrinterReasons(printer_t
*p
, /* I - Printer */
1641 const char *s
) /* I - Reasons strings */
1643 int i
; /* Looping var */
1644 const char *sptr
; /* Pointer into reasons */
1645 char reason
[255], /* Reason string */
1646 *rptr
; /* Pointer into reason */
1649 if (s
[0] == '-' || s
[0] == '+')
1652 * Add/remove reasons...
1660 * Replace reasons...
1665 for (i
= 0; i
< p
->num_reasons
; i
++)
1666 free(p
->reasons
[i
]);
1672 * Loop through all of the reasons...
1678 * Skip leading whitespace and commas...
1681 while (isspace(*sptr
) || *sptr
== ',')
1684 for (rptr
= reason
; *sptr
&& !isspace(*sptr
) && *sptr
!= ','; sptr
++)
1685 if (rptr
< (reason
+ sizeof(reason
) - 1))
1699 for (i
= 0; i
< p
->num_reasons
; i
++)
1700 if (!strcasecmp(reason
, p
->reasons
[i
]))
1703 * Found a match, so remove it...
1707 free(p
->reasons
[i
]);
1709 if (i
< p
->num_reasons
)
1710 memmove(p
->reasons
+ i
, p
->reasons
+ i
+ 1,
1711 (p
->num_reasons
- i
) * sizeof(char *));
1716 else if (s
[0] == '+' &&
1717 p
->num_reasons
< (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
1723 for (i
= 0; i
< p
->num_reasons
; i
++)
1724 if (!strcasecmp(reason
, p
->reasons
[i
]))
1727 if (i
>= p
->num_reasons
)
1729 p
->reasons
[i
] = strdup(reason
);
1738 * 'SetPrinterState()' - Update the current state of a printer.
1742 SetPrinterState(printer_t
*p
, /* I - Printer to change */
1743 ipp_pstate_t s
, /* I - New state */
1744 int update
) /* I - Update printers.conf? */
1746 ipp_pstate_t old_state
; /* Old printer state */
1750 * Can't set status of remote printers...
1753 if (p
->type
& CUPS_PRINTER_REMOTE
)
1757 * Set the new state...
1760 old_state
= p
->state
;
1765 p
->state_time
= time(NULL
);
1769 write_irix_state(p
);
1773 AddPrinterHistory(p
);
1776 * Save the printer configuration if a printer goes from idle or processing
1777 * to stopped (or visa-versa)...
1780 if ((old_state
== IPP_PRINTER_STOPPED
) != (s
== IPP_PRINTER_STOPPED
) &&
1783 if (p
->type
& CUPS_PRINTER_CLASS
)
1792 * 'SortPrinters()' - Sort the printer list when a printer name is changed.
1798 printer_t
*current
, /* Current printer */
1799 *prev
, /* Previous printer */
1800 *next
; /* Next printer */
1801 int did_swap
; /* Non-zero if we did a swap */
1806 for (did_swap
= 0, current
= Printers
, prev
= NULL
; current
!= NULL
;)
1807 if (current
->next
== NULL
)
1809 else if (strcasecmp(current
->name
, current
->next
->name
) > 0)
1811 DEBUG_printf(("Swapping %s and %s...\n", current
->name
,
1812 current
->next
->name
));
1815 * Need to swap these two printers...
1821 Printers
= current
->next
;
1823 prev
->next
= current
->next
;
1826 * Yes, we can all get a headache from the next bunch of pointer
1830 next
= current
->next
;
1831 current
->next
= next
->next
;
1832 next
->next
= current
;
1838 current
= current
->next
;
1846 * 'StopPrinter()' - Stop a printer from printing any jobs...
1850 StopPrinter(printer_t
*p
, /* I - Printer to stop */
1851 int update
) /* I - Update printers.conf? */
1853 job_t
*job
; /* Active print job */
1857 * Set the printer state...
1860 SetPrinterState(p
, IPP_PRINTER_STOPPED
, update
);
1863 * See if we have a job printing on this printer...
1869 * Get pointer to job...
1872 job
= (job_t
*)p
->job
;
1878 StopJob(job
->id
, 0);
1881 * Reset the state to pending...
1884 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
1892 * 'ValidateDest()' - Validate a printer/class destination.
1895 const char * /* O - Printer or class name */
1896 ValidateDest(const char *hostname
, /* I - Host name */
1897 const char *resource
, /* I - Resource name */
1898 cups_ptype_t
*dtype
) /* O - Type (printer or class) */
1900 printer_t
*p
; /* Current printer */
1901 char localname
[1024], /* Localized hostname */
1902 *lptr
, /* Pointer into localized hostname */
1903 *sptr
; /* Pointer into server name */
1906 DEBUG_printf(("ValidateDest(\"%s\", \"%s\", %p)\n", hostname
, resource
, dtype
));
1909 * See if the resource is a class or printer...
1912 if (strncmp(resource
, "/classes/", 9) == 0)
1920 else if (strncmp(resource
, "/printers/", 10) == 0)
1931 * Bad resource name...
1938 * See if the printer or class name exists...
1941 if ((p
= FindPrinter(resource
)) == NULL
)
1942 p
= FindClass(resource
);
1944 if (p
== NULL
&& strchr(resource
, '@') == NULL
)
1948 *dtype
= p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
|
1949 CUPS_PRINTER_REMOTE
);
1954 * Change localhost to the server name...
1957 if (strcasecmp(hostname
, "localhost") == 0)
1958 hostname
= ServerName
;
1960 strlcpy(localname
, hostname
, sizeof(localname
));
1962 if (strcasecmp(hostname
, ServerName
) != 0)
1965 * Localize the hostname...
1968 lptr
= strchr(localname
, '.');
1969 sptr
= strchr(ServerName
, '.');
1971 if (sptr
!= NULL
&& lptr
!= NULL
)
1974 * Strip the common domain name components...
1977 while (lptr
!= NULL
)
1979 if (strcasecmp(lptr
, sptr
) == 0)
1985 lptr
= strchr(lptr
+ 1, '.');
1990 DEBUG_printf(("localized hostname is \"%s\"...\n", localname
));
1993 * Find a matching printer or class...
1996 for (p
= Printers
; p
!= NULL
; p
= p
->next
)
1997 if (strcasecmp(p
->hostname
, localname
) == 0 &&
1998 strcasecmp(p
->name
, resource
) == 0)
2000 *dtype
= p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
|
2001 CUPS_PRINTER_REMOTE
);
2010 * 'WritePrintcap()' - Write a pseudo-printcap file for older applications
2017 cups_file_t
*fp
; /* printcap file */
2018 printer_t
*p
; /* Current printer */
2023 * Update the IRIX printer state for the default printer; if
2024 * no printers remain, then the default printer file will be
2028 write_irix_state(DefaultPrinter
);
2032 * See if we have a printcap file; if not, don't bother writing it.
2039 * Open the printcap file...
2042 if ((fp
= cupsFileOpen(Printcap
, "w")) == NULL
)
2046 * Put a comment header at the top so that users will know where the
2047 * data has come from...
2050 cupsFilePuts(fp
, "# This file was automatically generated by cupsd(8) from the\n");
2051 cupsFilePrintf(fp
, "# %s/printers.conf file. All changes to this file\n",
2053 cupsFilePuts(fp
, "# will be lost.\n");
2056 * Write a new printcap with the current list of printers.
2059 switch (PrintcapFormat
)
2063 * Each printer is put in the file as:
2073 cupsFilePrintf(fp
, "%s|%s:rm=%s:rp=%s:\n", DefaultPrinter
->name
,
2074 DefaultPrinter
->info
, ServerName
, DefaultPrinter
->name
);
2076 for (p
= Printers
; p
!= NULL
; p
= p
->next
)
2077 if (p
!= DefaultPrinter
)
2078 cupsFilePrintf(fp
, "%s|%s:rm=%s:rp=%s:\n", p
->name
, p
->info
,
2079 ServerName
, p
->name
);
2082 case PRINTCAP_SOLARIS
:
2084 * Each printer is put in the file as:
2086 * _all:all=Printer1,Printer2,Printer3,...,PrinterN
2087 * _default:use=DefaultPrinter
2089 * :bsdaddr=ServerName,Printer1:\
2090 * :description=Description:
2092 * :bsdaddr=ServerName,Printer2:\
2093 * :description=Description:
2095 * :bsdaddr=ServerName,Printer3:\
2096 * :description=Description:
2099 * :bsdaddr=ServerName,PrinterN:\
2100 * :description=Description:
2103 cupsFilePuts(fp
, "_all:all=");
2104 for (p
= Printers
; p
!= NULL
; p
= p
->next
)
2105 cupsFilePrintf(fp
, "%s%c", p
->name
, p
->next
? ',' : '\n');
2108 cupsFilePrintf(fp
, "_default:use=%s\n", DefaultPrinter
->name
);
2110 for (p
= Printers
; p
!= NULL
; p
= p
->next
)
2111 cupsFilePrintf(fp
, "%s:\\\n"
2112 "\t:bsdaddr=%s,%s:\\\n"
2113 "\t:description=%s:\n",
2114 p
->name
, ServerName
, p
->name
, p
->info
? p
->info
: "");
2128 * 'write_irix_config()' - Update the config files used by the IRIX
2133 write_irix_config(printer_t
*p
) /* I - Printer to update */
2135 char filename
[1024]; /* Interface script filename */
2136 cups_file_t
*fp
; /* Interface script file */
2137 ipp_attribute_t
*attr
; /* Attribute value */
2141 * Add dummy interface and GUI scripts to fool SGI's "challenged" printing
2142 * tools. First the interface script that tells the tools what kind of
2143 * printer we have...
2146 snprintf(filename
, sizeof(filename
), "/var/spool/lp/interface/%s", p
->name
);
2148 if (p
->type
& CUPS_PRINTER_CLASS
)
2150 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
2152 cupsFilePuts(fp
, "#!/bin/sh\n");
2154 if ((attr
= ippFindAttribute(p
->attrs
, "printer-make-and-model",
2155 IPP_TAG_TEXT
)) != NULL
)
2156 cupsFilePrintf(fp
, "NAME=\"%s\"\n", attr
->values
[0].string
.text
);
2157 else if (p
->type
& CUPS_PRINTER_CLASS
)
2158 cupsFilePuts(fp
, "NAME=\"Printer Class\"\n");
2160 cupsFilePuts(fp
, "NAME=\"Remote Destination\"\n");
2162 if (p
->type
& CUPS_PRINTER_COLOR
)
2163 cupsFilePuts(fp
, "TYPE=ColorPostScript\n");
2165 cupsFilePuts(fp
, "TYPE=MonoPostScript\n");
2167 cupsFilePrintf(fp
, "HOSTNAME=%s\n", ServerName
);
2168 cupsFilePrintf(fp
, "HOSTPRINTER=%s\n", p
->name
);
2172 chmod(filename
, 0755);
2173 chown(filename
, User
, Group
);
2177 * Then the member file that tells which device file the queue is connected
2178 * to... Networked printers use "/dev/null" in this file, so that's what
2179 * we use (the actual device URI can confuse some apps...)
2182 snprintf(filename
, sizeof(filename
), "/var/spool/lp/member/%s", p
->name
);
2184 if (p
->type
& CUPS_PRINTER_CLASS
)
2186 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
2188 cupsFilePuts(fp
, "/dev/null\n");
2192 chmod(filename
, 0644);
2193 chown(filename
, User
, Group
);
2197 * The gui_interface file is a script or program that launches a GUI
2198 * option panel for the printer, using options specified on the
2199 * command-line in the third argument. The option panel must send
2200 * any printing options to stdout on a single line when the user
2201 * accepts them, or nothing if the user cancels the dialog.
2203 * The default options panel program is /usr/bin/glpoptions, from
2204 * the ESP Print Pro software. You can select another using the
2205 * PrintcapGUI option.
2208 snprintf(filename
, sizeof(filename
), "/var/spool/lp/gui_interface/ELF/%s.gui", p
->name
);
2210 if (p
->type
& CUPS_PRINTER_CLASS
)
2212 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
2214 cupsFilePuts(fp
, "#!/bin/sh\n");
2215 cupsFilePrintf(fp
, "%s -d %s -o \"$3\"\n", PrintcapGUI
, p
->name
);
2219 chmod(filename
, 0755);
2220 chown(filename
, User
, Group
);
2224 * The POD config file is needed by the printstatus command to show
2225 * the printer location and device.
2228 snprintf(filename
, sizeof(filename
), "/var/spool/lp/pod/%s.config", p
->name
);
2230 if (p
->type
& CUPS_PRINTER_CLASS
)
2232 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
2234 cupsFilePrintf(fp
, "Printer Class | %s\n",
2235 (p
->type
& CUPS_PRINTER_COLOR
) ? "ColorPostScript" : "MonoPostScript");
2236 cupsFilePrintf(fp
, "Printer Model | %s\n", p
->make_model
? p
->make_model
: "");
2237 cupsFilePrintf(fp
, "Location Code | %s\n", p
->location
? p
->location
: "");
2238 cupsFilePrintf(fp
, "Physical Location | %s\n", p
->info
? p
->info
: "");
2239 cupsFilePrintf(fp
, "Port Path | %s\n", p
->device_uri
? p
->device_uri
: "");
2240 cupsFilePrintf(fp
, "Config Path | /var/spool/lp/pod/%s.config\n", p
->name
);
2241 cupsFilePrintf(fp
, "Active Status Path | /var/spool/lp/pod/%s.status\n", p
->name
);
2242 cupsFilePuts(fp
, "Status Update Wait | 10 seconds\n");
2246 chmod(filename
, 0664);
2247 chown(filename
, User
, Group
);
2253 * 'write_irix_state()' - Update the status files used by IRIX printing
2258 write_irix_state(printer_t
*p
) /* I - Printer to update */
2260 char filename
[1024]; /* Interface script filename */
2261 cups_file_t
*fp
; /* Interface script file */
2262 int tag
; /* Status tag value */
2268 * The POD status file is needed for the printstatus window to
2269 * provide the current status of the printer.
2272 snprintf(filename
, sizeof(filename
), "/var/spool/lp/pod/%s.status", p
->name
);
2274 if (p
->type
& CUPS_PRINTER_CLASS
)
2276 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
2278 cupsFilePrintf(fp
, "Operational Status | %s\n",
2279 (p
->state
== IPP_PRINTER_IDLE
) ? "Idle" :
2280 (p
->state
== IPP_PRINTER_PROCESSING
) ? "Busy" :
2282 cupsFilePrintf(fp
, "Information | 01 00 00 | %s\n", CUPS_SVERSION
);
2283 cupsFilePrintf(fp
, "Information | 02 00 00 | Device URI: %s\n",
2284 p
->device_uri
? p
->device_uri
: "");
2285 cupsFilePrintf(fp
, "Information | 03 00 00 | %s jobs\n",
2286 p
->accepting
? "Accepting" : "Not accepting");
2287 cupsFilePrintf(fp
, "Information | 04 00 00 | %s\n", p
->state_message
);
2291 chmod(filename
, 0664);
2292 chown(filename
, User
, Group
);
2296 * The activeicons file is needed to provide desktop icons for printers:
2298 * [ quoted from /usr/lib/print/tagit ]
2300 * --- Type of printer tags (base values)
2302 * Dumb=66048 # 0x10200
2303 * DumbColor=66080 # 0x10220
2304 * Raster=66112 # 0x10240
2305 * ColorRaster=66144 # 0x10260
2306 * Plotter=66176 # 0x10280
2307 * PostScript=66208 # 0x102A0
2308 * ColorPostScript=66240 # 0x102C0
2309 * MonoPostScript=66272 # 0x102E0
2311 * --- Printer state modifiers for local printers
2316 * Unknown=3 # 0x3 (Faulted due to unknown reason)
2318 * --- Printer state modifiers for network printers
2322 * NetFaulted=10 # 0xA
2323 * NetUnknown=11 # 0xB (Faulted due to unknown reason)
2326 snprintf(filename
, sizeof(filename
), "/var/spool/lp/activeicons/%s", p
->name
);
2328 if (p
->type
& CUPS_PRINTER_CLASS
)
2330 else if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
2332 if (p
->type
& CUPS_PRINTER_COLOR
)
2337 if (p
->type
& CUPS_PRINTER_REMOTE
)
2340 if (p
->state
== IPP_PRINTER_PROCESSING
)
2343 else if (p
->state
== IPP_PRINTER_STOPPED
)
2346 cupsFilePuts(fp
, "#!/bin/sh\n");
2347 cupsFilePrintf(fp
, "#Tag %d\n", tag
);
2351 chmod(filename
, 0755);
2352 chown(filename
, User
, Group
);
2357 * The default file is needed by the printers window to show
2358 * the default printer.
2361 snprintf(filename
, sizeof(filename
), "/var/spool/lp/default");
2363 if (DefaultPrinter
!= NULL
)
2365 if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
2367 cupsFilePrintf(fp
, "%s\n", DefaultPrinter
->name
);
2371 chmod(filename
, 0644);
2372 chown(filename
, User
, Group
);
2382 * End of "$Id: printers.c,v 1.150 2003/04/25 15:23:22 mike Exp $".