]> git.ipfire.org Git - thirdparty/cups.git/blob - scheduler/printers.c
Fix emptying of printers.conf when reconfiguring the scheduler (STR #47)
[thirdparty/cups.git] / scheduler / printers.c
1 /*
2 * "$Id: printers.c,v 1.150 2003/04/25 15:23:22 mike Exp $"
3 *
4 * Printer routines for the Common UNIX Printing System (CUPS).
5 *
6 * Copyright 1997-2003 by Easy Software Products, all rights reserved.
7 *
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
13 * at:
14 *
15 * Attn: CUPS Licensing Information
16 * Easy Software Products
17 * 44141 Airport View Drive, Suite 204
18 * Hollywood, Maryland 20636-3111 USA
19 *
20 * Voice: (301) 373-9603
21 * EMail: cups-info@cups.org
22 * WWW: http://www.cups.org
23 *
24 * Contents:
25 *
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
41 * changed.
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
47 * desktop tools.
48 * write_irix_state() - Update the status files used by IRIX printing
49 * desktop tools.
50 */
51
52 /*
53 * Include necessary headers...
54 */
55
56 #include "cupsd.h"
57
58
59 /*
60 * Local functions...
61 */
62
63 #ifdef __sgi
64 static void write_irix_config(printer_t *p);
65 static void write_irix_state(printer_t *p);
66 #endif /* __sgi */
67
68
69 /*
70 * 'AddPrinter()' - Add a printer to the system.
71 */
72
73 printer_t * /* O - New printer */
74 AddPrinter(const char *name) /* I - Name of printer */
75 {
76 printer_t *p, /* New printer */
77 *current, /* Current printer in list */
78 *prev; /* Previous printer in list */
79
80
81 /*
82 * Range check input...
83 */
84
85 LogMessage(L_DEBUG2, "AddPrinter(\"%s\")", name ? name : "(null)");
86
87 if (name == NULL)
88 return (NULL);
89
90 /*
91 * Create a new printer entity...
92 */
93
94 if ((p = calloc(1, sizeof(printer_t))) == NULL)
95 {
96 LogMessage(L_ERROR, "Unable to allocate memory for printer - %s",
97 strerror(errno));
98 return (NULL);
99 }
100
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");
107
108 p->state = IPP_PRINTER_STOPPED;
109 p->accepting = 0;
110 p->filetype = mimeAddType(MimeDatabase, "printer", name);
111
112 SetString(&p->job_sheets[0], "none");
113 SetString(&p->job_sheets[1], "none");
114
115 if (MaxPrinterHistory)
116 p->history = calloc(MaxPrinterHistory, sizeof(ipp_t *));
117
118 /*
119 * Insert the printer in the printer list alphabetically...
120 */
121
122 for (prev = NULL, current = Printers;
123 current != NULL;
124 prev = current, current = current->next)
125 if (strcasecmp(p->name, current->name) < 0)
126 break;
127
128 /*
129 * Insert this printer before the current one...
130 */
131
132 if (prev == NULL)
133 Printers = p;
134 else
135 prev->next = p;
136
137 p->next = current;
138
139 /*
140 * Write a new /etc/printcap or /var/spool/lp/pstatus file.
141 */
142
143 WritePrintcap();
144
145 return (p);
146 }
147
148
149 /*
150 * 'AddPrinterFilter()' - Add a MIME filter for a printer.
151 */
152
153 void
154 AddPrinterFilter(printer_t *p, /* I - Printer to add to */
155 const char *filter) /* I - Filter to add */
156 {
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 */
163
164
165 /*
166 * Range check input...
167 */
168
169 if (p == NULL || p->filetype == NULL || filter == NULL)
170 return;
171
172 /*
173 * Parse the filter string; it should be in the following format:
174 *
175 * super/type cost program
176 */
177
178 if (sscanf(filter, "%15[^/]/%31s%d%1023s", super, type, &cost, program) != 4)
179 {
180 LogMessage(L_ERROR, "AddPrinterFilter: Invalid filter string \"%s\"!",
181 filter);
182 return;
183 }
184
185 /*
186 * Add the filter to the MIME database, supporting wildcards as needed...
187 */
188
189 for (temptype = MimeDatabase->types, i = MimeDatabase->num_types;
190 i > 0;
191 i --, temptype ++)
192 if (((super[0] == '*' && strcasecmp((*temptype)->super, "printer") != 0) ||
193 strcasecmp((*temptype)->super, super) == 0) &&
194 (type[0] == '*' || strcasecmp((*temptype)->type, type) == 0))
195 {
196 LogMessage(L_DEBUG2, "Adding filter %s/%s %s/%s %d %s",
197 (*temptype)->super, (*temptype)->type,
198 p->filetype->super, p->filetype->type,
199 cost, program);
200 mimeAddFilter(MimeDatabase, *temptype, p->filetype, cost, program);
201 }
202 }
203
204
205 /*
206 * 'AddPrinterHistory()' - Add the current printer state to the history.
207 */
208
209 void
210 AddPrinterHistory(printer_t *p) /* I - Printer */
211 {
212 ipp_t *history; /* History collection */
213
214
215 /*
216 * Stop early if we aren't keeping history data...
217 */
218
219 if (MaxPrinterHistory <= 0)
220 return;
221
222 /*
223 * Retire old history data as needed...
224 */
225
226 p->sequence_number ++;
227
228 if (p->num_history >= MaxPrinterHistory)
229 {
230 p->num_history --;
231 ippDelete(p->history[0]);
232 memmove(p->history, p->history + 1, p->num_history * sizeof(ipp_t *));
233 }
234
235 /*
236 * Create a collection containing the current printer-state, printer-up-time,
237 * printer-state-message, and printer-state-reasons attributes.
238 */
239
240 history = ippNew();
241 ippAddInteger(history, IPP_TAG_PRINTER, IPP_TAG_ENUM, "printer-state",
242 p->state);
243 ippAddBoolean(history, IPP_TAG_PRINTER, "printer-is-accepting-jobs",
244 p->accepting);
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");
251 else
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);
259
260 p->history[p->num_history] = history;
261 p->num_history ++;
262 }
263
264
265 /*
266 * 'AddPrinterUser()' - Add a user to the ACL.
267 */
268
269 void
270 AddPrinterUser(printer_t *p, /* I - Printer */
271 const char *username) /* I - User */
272 {
273 const char **temp; /* Temporary array pointer */
274
275
276 if (!p || !username)
277 return;
278
279 if (p->num_users == 0)
280 temp = malloc(sizeof(char **));
281 else
282 temp = realloc(p->users, sizeof(char **) * (p->num_users + 1));
283
284 if (!temp)
285 return;
286
287 p->users = temp;
288 temp += p->num_users;
289
290 if ((*temp = strdup(username)) != NULL)
291 p->num_users ++;
292 }
293
294
295 /*
296 * 'DeleteAllPrinters()' - Delete all printers from the system.
297 */
298
299 void
300 DeleteAllPrinters(void)
301 {
302 printer_t *p, /* Pointer to current printer/class */
303 *next; /* Pointer to next printer in list */
304
305
306 for (p = Printers; p != NULL; p = next)
307 {
308 next = p->next;
309
310 if (!(p->type & CUPS_PRINTER_CLASS))
311 DeletePrinter(p);
312 }
313
314 if (CommonData)
315 {
316 ippDelete(CommonData);
317 CommonData = NULL;
318 }
319 }
320
321
322 /*
323 * 'DeletePrinter()' - Delete a printer from the system.
324 */
325
326 void
327 DeletePrinter(printer_t *p) /* I - Printer to delete */
328 {
329 int i; /* Looping var */
330 printer_t *current, /* Current printer in list */
331 *prev; /* Previous printer in list */
332 #ifdef __sgi
333 char filename[1024]; /* Interface script filename */
334 #endif /* __sgi */
335
336
337 DEBUG_printf(("DeletePrinter(%08x): p->name = \"%s\"...\n", p, p->name));
338
339 /*
340 * Range check input...
341 */
342
343 if (p == NULL)
344 return;
345
346 /*
347 * Remove the printer from the list...
348 */
349
350 for (prev = NULL, current = Printers;
351 current != NULL;
352 prev = current, current = current->next)
353 if (p == current)
354 break;
355
356 if (current == NULL)
357 {
358 LogMessage(L_ERROR, "Tried to delete a non-existent printer %s!\n",
359 p->name);
360 return;
361 }
362
363 if (prev == NULL)
364 Printers = p->next;
365 else
366 prev->next = p->next;
367
368 /*
369 * Stop printing on this printer...
370 */
371
372 StopPrinter(p, 1);
373
374 /*
375 * Remove the dummy interface/icon/option files under IRIX...
376 */
377
378 #ifdef __sgi
379 snprintf(filename, sizeof(filename), "/var/spool/lp/interface/%s", p->name);
380 unlink(filename);
381
382 snprintf(filename, sizeof(filename), "/var/spool/lp/gui_interface/ELF/%s.gui",
383 p->name);
384 unlink(filename);
385
386 snprintf(filename, sizeof(filename), "/var/spool/lp/activeicons/%s", p->name);
387 unlink(filename);
388
389 snprintf(filename, sizeof(filename), "/var/spool/lp/pod/%s.config", p->name);
390 unlink(filename);
391
392 snprintf(filename, sizeof(filename), "/var/spool/lp/pod/%s.status", p->name);
393 unlink(filename);
394
395 snprintf(filename, sizeof(filename), "/var/spool/lp/member/%s", p->name);
396 unlink(filename);
397 #endif /* __sgi */
398
399 /*
400 * If p is the default printer, assign the next one...
401 */
402
403 if (p == DefaultPrinter)
404 {
405 DefaultPrinter = Printers;
406
407 WritePrintcap();
408 }
409
410 /*
411 * Remove this printer from any classes...
412 */
413
414 if (!(p->type & (CUPS_PRINTER_CLASS | CUPS_PRINTER_IMPLICIT)))
415 DeletePrinterFromClasses(p);
416
417 /*
418 * Free all memory used by the printer...
419 */
420
421 if (p->printers != NULL)
422 free(p->printers);
423
424 if (MaxPrinterHistory)
425 {
426 for (i = 0; i < p->num_history; i ++)
427 ippDelete(p->history[i]);
428
429 free(p->history);
430 }
431
432 for (i = 0; i < p->num_reasons; i ++)
433 free(p->reasons[i]);
434
435 ippDelete(p->attrs);
436
437 DeletePrinterFilters(p);
438
439 FreePrinterUsers(p);
440 FreeQuotas(p);
441
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);
451
452 free(p);
453
454 /*
455 * Write a new /etc/printcap file...
456 */
457
458 WritePrintcap();
459 }
460
461
462 /*
463 * 'DeletePrinterFilters()' - Delete all MIME filters for a printer.
464 */
465
466 void
467 DeletePrinterFilters(printer_t *p) /* I - Printer to remove from */
468 {
469 int i; /* Looping var */
470 mime_filter_t *filter; /* MIME filter looping var */
471
472
473 /*
474 * Range check input...
475 */
476
477 if (p == NULL)
478 return;
479
480 /*
481 * Remove all filters from the MIME database that have a destination
482 * type == printer...
483 */
484
485 for (filter = MimeDatabase->filters, i = MimeDatabase->num_filters;
486 i > 0;
487 i --, filter ++)
488 if (filter->dst == p->filetype)
489 {
490 /*
491 * Delete the current filter...
492 */
493
494 MimeDatabase->num_filters --;
495
496 if (i > 1)
497 memcpy(filter, filter + 1, sizeof(mime_filter_t) * (i - 1));
498
499 filter --;
500 }
501 }
502
503
504 /*
505 * 'FindDest()' - Find a destination in the list.
506 */
507
508 printer_t * /* O - Destination in list */
509 FindDest(const char *name) /* I - Name of printer or class to find */
510 {
511 printer_t *p; /* Current destination */
512 int diff; /* Difference */
513
514
515 for (p = Printers; p != NULL; p = p->next)
516 if ((diff = strcasecmp(name, p->name)) == 0)/* name == p->name */
517 return (p);
518 else if (diff < 0) /* name < p->name */
519 return (NULL);
520
521 return (NULL);
522 }
523
524
525 /*
526 * 'FindPrinter()' - Find a printer in the list.
527 */
528
529 printer_t * /* O - Printer in list */
530 FindPrinter(const char *name) /* I - Name of printer to find */
531 {
532 printer_t *p; /* Current printer */
533 int diff; /* Difference */
534
535
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 */
539 return (p);
540 else if (diff < 0) /* name < p->name */
541 return (NULL);
542
543 return (NULL);
544 }
545
546
547 /*
548 * 'FreePrinterUsers()' - Free allow/deny users.
549 */
550
551 void
552 FreePrinterUsers(printer_t *p) /* I - Printer */
553 {
554 int i; /* Looping var */
555
556
557 if (!p || !p->num_users)
558 return;
559
560 for (i = 0; i < p->num_users; i ++)
561 free((void *)p->users[i]);
562
563 free(p->users);
564
565 p->num_users = 0;
566 p->users = NULL;
567 }
568
569
570 /*
571 * 'LoadAllPrinters()' - Load printers from the printers.conf file.
572 */
573
574 void
575 LoadAllPrinters(void)
576 {
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 */
586
587
588 /*
589 * Open the printers.conf file...
590 */
591
592 snprintf(line, sizeof(line), "%s/printers.conf", ServerRoot);
593 if ((fp = cupsFileOpen(line, "r")) == NULL)
594 {
595 LogMessage(L_ERROR, "LoadAllPrinters: Unable to open %s - %s", line,
596 strerror(errno));
597 return;
598 }
599
600 /*
601 * Read printer configurations until we hit EOF...
602 */
603
604 linenum = 0;
605 p = NULL;
606
607 while (cupsFileGets(fp, line, sizeof(line)) != NULL)
608 {
609 linenum ++;
610
611 /*
612 * Skip comment lines...
613 */
614
615 if (line[0] == '#')
616 continue;
617
618 /*
619 * Strip trailing whitespace, if any...
620 */
621
622 len = strlen(line);
623
624 while (len > 0 && isspace(line[len - 1]))
625 {
626 len --;
627 line[len] = '\0';
628 }
629
630 /*
631 * Extract the name from the beginning of the line...
632 */
633
634 for (value = line; isspace(*value); value ++);
635
636 for (nameptr = name; *value != '\0' && !isspace(*value) &&
637 nameptr < (name + sizeof(name) - 1);)
638 *nameptr++ = *value++;
639 *nameptr = '\0';
640
641 while (isspace(*value))
642 value ++;
643
644 if (name[0] == '\0')
645 continue;
646
647 /*
648 * Decode the directive...
649 */
650
651 if (strcmp(name, "<Printer") == 0 ||
652 strcmp(name, "<DefaultPrinter") == 0)
653 {
654 /*
655 * <Printer name> or <DefaultPrinter name>
656 */
657
658 if (line[len - 1] == '>' && p == NULL)
659 {
660 /*
661 * Add the printer and a base file type...
662 */
663
664 line[len - 1] = '\0';
665
666 LogMessage(L_DEBUG, "LoadAllPrinters: Loading printer %s...", value);
667
668 p = AddPrinter(value);
669 p->accepting = 1;
670 p->state = IPP_PRINTER_IDLE;
671
672 /*
673 * Set the default printer as needed...
674 */
675
676 if (strcmp(name, "<DefaultPrinter") == 0)
677 DefaultPrinter = p;
678 }
679 else
680 {
681 LogMessage(L_ERROR, "Syntax error on line %d of printers.conf.",
682 linenum);
683 return;
684 }
685 }
686 else if (strcmp(name, "</Printer>") == 0)
687 {
688 if (p != NULL)
689 {
690 SetPrinterAttrs(p);
691 AddPrinterHistory(p);
692 p = NULL;
693 }
694 else
695 {
696 LogMessage(L_ERROR, "Syntax error on line %d of printers.conf.",
697 linenum);
698 return;
699 }
700 }
701 else if (p == NULL)
702 {
703 LogMessage(L_ERROR, "Syntax error on line %d of printers.conf.",
704 linenum);
705 return;
706 }
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)
714 {
715 /*
716 * Set the initial queue state...
717 */
718
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;
723 }
724 else if (strcmp(name, "StateMessage") == 0)
725 {
726 /*
727 * Set the initial queue state message...
728 */
729
730 while (isspace(*value))
731 value ++;
732
733 strlcpy(p->state_message, value, sizeof(p->state_message));
734 }
735 else if (strcmp(name, "Accepting") == 0)
736 {
737 /*
738 * Set the initial accepting state...
739 */
740
741 if (strcasecmp(value, "yes") == 0)
742 p->accepting = 1;
743 else
744 p->accepting = 0;
745 }
746 else if (strcmp(name, "JobSheets") == 0)
747 {
748 /*
749 * Set the initial job sheets...
750 */
751
752 for (valueptr = value; *valueptr && !isspace(*valueptr); valueptr ++);
753
754 if (*valueptr)
755 *valueptr++ = '\0';
756
757 SetString(&p->job_sheets[0], value);
758
759 while (isspace(*valueptr))
760 valueptr ++;
761
762 if (*valueptr)
763 {
764 for (value = valueptr; *valueptr && !isspace(*valueptr); valueptr ++);
765
766 if (*valueptr)
767 *valueptr++ = '\0';
768
769 SetString(&p->job_sheets[1], value);
770 }
771 }
772 else if (strcmp(name, "AllowUser") == 0)
773 {
774 p->deny_users = 0;
775 AddPrinterUser(p, value);
776 }
777 else if (strcmp(name, "DenyUser") == 0)
778 {
779 p->deny_users = 1;
780 AddPrinterUser(p, value);
781 }
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);
788 else
789 {
790 /*
791 * Something else we don't understand...
792 */
793
794 LogMessage(L_ERROR, "Unknown configuration directive %s on line %d of printers.conf.",
795 name, linenum);
796 }
797 }
798
799 cupsFileClose(fp);
800 }
801
802
803 /*
804 * 'SaveAllPrinters()' - Save all printer definitions to the printers.conf
805 * file.
806 */
807
808 void
809 SaveAllPrinters(void)
810 {
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 */
818
819
820 /*
821 * Create the printers.conf file...
822 */
823
824 snprintf(temp, sizeof(temp), "%s/printers.conf", ServerRoot);
825 snprintf(backup, sizeof(backup), "%s/printers.conf.O", ServerRoot);
826
827 if (rename(temp, backup))
828 LogMessage(L_ERROR, "Unable to backup printers.conf - %s", strerror(errno));
829
830 if ((fp = cupsFileOpen(temp, "w")) == NULL)
831 {
832 LogMessage(L_ERROR, "Unable to save printers.conf - %s", strerror(errno));
833
834 if (rename(backup, temp))
835 LogMessage(L_ERROR, "Unable to restore printers.conf - %s", strerror(errno));
836 return;
837 }
838 else
839 LogMessage(L_INFO, "Saving printers.conf...");
840
841 /*
842 * Restrict access to the file...
843 */
844
845 fchown(cupsFileNumber(fp), User, Group);
846 fchmod(cupsFileNumber(fp), ConfigFilePerm);
847
848 /*
849 * Write a small header to the file...
850 */
851
852 curtime = time(NULL);
853 curdate = localtime(&curtime);
854 strftime(temp, sizeof(temp) - 1, CUPS_STRFTIME_FORMAT, curdate);
855
856 cupsFilePuts(fp, "# Printer configuration file for " CUPS_SVERSION "\n");
857 cupsFilePrintf(fp, "# Written by cupsd on %s\n", temp);
858
859 /*
860 * Write each local printer known to the system...
861 */
862
863 for (printer = Printers; printer != NULL; printer = printer->next)
864 {
865 /*
866 * Skip remote destinations and printer classes...
867 */
868
869 if ((printer->type & CUPS_PRINTER_REMOTE) ||
870 (printer->type & CUPS_PRINTER_CLASS) ||
871 (printer->type & CUPS_PRINTER_IMPLICIT))
872 continue;
873
874 /*
875 * Write printers as needed...
876 */
877
878 if (printer == DefaultPrinter)
879 cupsFilePrintf(fp, "<DefaultPrinter %s>\n", printer->name);
880 else
881 cupsFilePrintf(fp, "<Printer %s>\n", printer->name);
882
883 if (printer->info)
884 cupsFilePrintf(fp, "Info %s\n", printer->info);
885
886 if (printer->location)
887 cupsFilePrintf(fp, "Location %s\n", printer->location);
888
889 if (printer->device_uri)
890 cupsFilePrintf(fp, "DeviceURI %s\n", printer->device_uri);
891
892 if (printer->state == IPP_PRINTER_STOPPED)
893 {
894 cupsFilePuts(fp, "State Stopped\n");
895 cupsFilePrintf(fp, "StateMessage %s\n", printer->state_message);
896 }
897 else
898 cupsFilePuts(fp, "State Idle\n");
899
900 if (printer->accepting)
901 cupsFilePuts(fp, "Accepting Yes\n");
902 else
903 cupsFilePuts(fp, "Accepting No\n");
904
905 cupsFilePrintf(fp, "JobSheets %s %s\n", printer->job_sheets[0],
906 printer->job_sheets[1]);
907
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);
911
912 for (i = 0; i < printer->num_users; i ++)
913 cupsFilePrintf(fp, "%sUser %s\n", printer->deny_users ? "Deny" : "Allow",
914 printer->users[i]);
915
916 cupsFilePuts(fp, "</Printer>\n");
917
918 #ifdef __sgi
919 /*
920 * Make IRIX desktop & printer status happy
921 */
922
923 write_irix_state(printer);
924 #endif /* __sgi */
925 }
926
927 cupsFileClose(fp);
928 }
929
930
931 /*
932 * 'SetPrinterAttrs()' - Set printer attributes based upon the PPD file.
933 */
934
935 void
936 SetPrinterAttrs(printer_t *p) /* I - Printer to setup */
937 {
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 */
962 {
963 IPP_PORTRAIT,
964 IPP_LANDSCAPE,
965 IPP_REVERSE_LANDSCAPE,
966 IPP_REVERSE_PORTRAIT
967 };
968 const char *sides[3] = /* sides-supported values */
969 {
970 "one",
971 "two-long-edge",
972 "two-short-edge"
973 };
974 const char *versions[] = /* ipp-versions-supported values */
975 {
976 "1.0",
977 "1.1"
978 };
979 ipp_op_t ops[] = /* operations-supported values */
980 {
981 IPP_PRINT_JOB,
982 IPP_VALIDATE_JOB,
983 IPP_CREATE_JOB,
984 IPP_SEND_DOCUMENT,
985 IPP_CANCEL_JOB,
986 IPP_GET_JOB_ATTRIBUTES,
987 IPP_GET_JOBS,
988 IPP_GET_PRINTER_ATTRIBUTES,
989 IPP_HOLD_JOB,
990 IPP_RELEASE_JOB,
991 IPP_PAUSE_PRINTER,
992 IPP_RESUME_PRINTER,
993 IPP_PURGE_JOBS,
994 IPP_SET_JOB_ATTRIBUTES,
995 IPP_ENABLE_PRINTER,
996 IPP_DISABLE_PRINTER,
997 CUPS_GET_DEFAULT,
998 CUPS_GET_PRINTERS,
999 CUPS_ADD_PRINTER,
1000 CUPS_DELETE_PRINTER,
1001 CUPS_GET_CLASSES,
1002 CUPS_ADD_CLASS,
1003 CUPS_DELETE_CLASS,
1004 CUPS_ACCEPT_JOBS,
1005 CUPS_REJECT_JOBS,
1006 CUPS_GET_DEVICES,
1007 CUPS_GET_PPDS,
1008 IPP_RESTART_JOB
1009 };
1010 const char *charsets[] = /* charset-supported values */
1011 {
1012 "us-ascii",
1013 "iso-8859-1",
1014 "iso-8859-2",
1015 "iso-8859-3",
1016 "iso-8859-4",
1017 "iso-8859-5",
1018 "iso-8859-6",
1019 "iso-8859-7",
1020 "iso-8859-8",
1021 "iso-8859-9",
1022 "iso-8859-10",
1023 "iso-8859-13",
1024 "iso-8859-14",
1025 "iso-8859-15",
1026 "utf-8",
1027 "windows-874",
1028 "windows-1250",
1029 "windows-1251",
1030 "windows-1252",
1031 "windows-1253",
1032 "windows-1254",
1033 "windows-1255",
1034 "windows-1256",
1035 "windows-1257",
1036 "windows-1258",
1037 "koi8-r",
1038 "koi8-u",
1039 };
1040 const char *compressions[] =
1041 {
1042 #ifdef HAVE_LIBZ
1043 "none",
1044 "gzip"
1045 #else
1046 "none"
1047 #endif /* HAVE_LIBZ */
1048 };
1049 int num_finishings;
1050 ipp_finish_t finishings[5];
1051 const char *multiple_document_handling[] =
1052 {
1053 "separate-documents-uncollated-copies",
1054 "separate-documents-collated-copies"
1055 };
1056
1057
1058 DEBUG_printf(("SetPrinterAttrs: entering name = %s, type = %x\n", p->name,
1059 p->type));
1060
1061 /*
1062 * Make sure that we have the common attributes defined...
1063 */
1064
1065 if (!CommonData)
1066 {
1067 CommonData = ippNew();
1068
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]),
1073 NULL, versions);
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);
1117
1118 if (NumBanners > 0)
1119 {
1120 /*
1121 * Setup the job-sheets-supported and job-sheets-default attributes...
1122 */
1123
1124 if (Classification && !ClassifyOverride)
1125 attr = ippAddString(CommonData, IPP_TAG_PRINTER, IPP_TAG_NAME,
1126 "job-sheets-supported", NULL, Classification);
1127 else
1128 attr = ippAddStrings(CommonData, IPP_TAG_PRINTER, IPP_TAG_NAME,
1129 "job-sheets-supported", NumBanners + 1, NULL, NULL);
1130
1131 if (attr == NULL)
1132 LogMessage(L_EMERG, "SetPrinterAttrs: Unable to allocate memory for "
1133 "job-sheets-supported attribute: %s!",
1134 strerror(errno));
1135 else if (!Classification || ClassifyOverride)
1136 {
1137 attr->values[0].string.text = strdup("none");
1138
1139 for (i = 0; i < NumBanners; i ++)
1140 attr->values[i + 1].string.text = strdup(Banners[i].name);
1141 }
1142 }
1143 }
1144
1145 /*
1146 * Clear out old filters and add a filter from application/vnd.cups-raw to
1147 * printer/name to handle "raw" printing by users.
1148 */
1149
1150 DeletePrinterFilters(p);
1151 AddPrinterFilter(p, "application/vnd.cups-raw 0 -");
1152
1153 /*
1154 * Figure out the authentication that is required for the printer.
1155 */
1156
1157 auth_supported = "requesting-user-name";
1158 if (!(p->type & CUPS_PRINTER_REMOTE))
1159 {
1160 if (p->type & CUPS_PRINTER_CLASS)
1161 snprintf(resource, sizeof(resource), "/classes/%s", p->name);
1162 else
1163 snprintf(resource, sizeof(resource), "/printers/%s", p->name);
1164
1165 if ((auth = FindBest(resource, HTTP_POST)) != NULL)
1166 {
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";
1171 }
1172 }
1173
1174 /*
1175 * Create the required IPP attributes for a printer...
1176 */
1177
1178 if (p->attrs)
1179 ippDelete(p->attrs);
1180
1181 p->attrs = ippNew();
1182
1183 ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_URI, "printer-uri-supported",
1184 NULL, p->uri);
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,
1190 p->name);
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",
1196 NULL, p->uri);
1197
1198 if (p->num_users)
1199 {
1200 if (p->deny_users)
1201 ippAddStrings(p->attrs, IPP_TAG_PRINTER, IPP_TAG_NAME,
1202 "requesting-user-name-denied", p->num_users, NULL,
1203 p->users);
1204 else
1205 ippAddStrings(p->attrs, IPP_TAG_PRINTER, IPP_TAG_NAME,
1206 "requesting-user-name-allowed", p->num_users, NULL,
1207 p->users);
1208 }
1209
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);
1216
1217 if (NumBanners > 0 && !(p->type & CUPS_PRINTER_REMOTE))
1218 {
1219 /*
1220 * Setup the job-sheets-default attribute...
1221 */
1222
1223 attr = ippAddStrings(p->attrs, IPP_TAG_PRINTER, IPP_TAG_NAME,
1224 "job-sheets-default", 2, NULL, NULL);
1225
1226 if (attr != NULL)
1227 {
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]);
1232 }
1233 }
1234
1235 printer_type = p->type;
1236
1237 p->raw = 0;
1238
1239 if (p->type & CUPS_PRINTER_REMOTE)
1240 {
1241 /*
1242 * Tell the client this is a remote printer of some type...
1243 */
1244
1245 ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_TEXT,
1246 "printer-make-and-model", NULL, p->make_model);
1247
1248 p->raw = 1;
1249 }
1250 else
1251 {
1252 /*
1253 * Assign additional attributes depending on whether this is a printer
1254 * or class...
1255 */
1256
1257 p->type &= ~CUPS_PRINTER_OPTIONS;
1258
1259 if (p->type & (CUPS_PRINTER_CLASS | CUPS_PRINTER_IMPLICIT))
1260 {
1261 /*
1262 * Add class-specific attributes...
1263 */
1264
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);
1268 else
1269 ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_TEXT,
1270 "printer-make-and-model", NULL, "Local Printer Class");
1271
1272 if (p->num_printers > 0)
1273 {
1274 /*
1275 * Add a list of member URIs and names...
1276 */
1277
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;
1281
1282 for (i = 0; i < p->num_printers; i ++)
1283 {
1284 if (attr != NULL)
1285 attr->values[i].string.text = strdup(p->printers[i]->uri);
1286
1287 p->type &= ~CUPS_PRINTER_OPTIONS | p->printers[i]->type;
1288 }
1289
1290 attr = ippAddStrings(p->attrs, IPP_TAG_PRINTER, IPP_TAG_NAME,
1291 "member-names", p->num_printers, NULL, NULL);
1292
1293 if (attr != NULL)
1294 {
1295 for (i = 0; i < p->num_printers; i ++)
1296 attr->values[i].string.text = strdup(p->printers[i]->name);
1297 }
1298 }
1299 }
1300 else
1301 {
1302 /*
1303 * Add printer-specific attributes... Start by sanitizing the device
1304 * URI so it doesn't have a username or password in it...
1305 */
1306
1307 if (!p->device_uri)
1308 strcpy(uri, "file:/dev/null");
1309 else if (strstr(p->device_uri, "://") != NULL)
1310 {
1311 /*
1312 * http://..., ipp://..., etc.
1313 */
1314
1315 httpSeparate(p->device_uri, method, username, host, &port, resource);
1316 if (port)
1317 snprintf(uri, sizeof(uri), "%s://%s:%d%s", method, host, port,
1318 resource);
1319 else
1320 snprintf(uri, sizeof(uri), "%s://%s%s", method, host, resource);
1321 }
1322 else
1323 {
1324 /*
1325 * file:..., serial:..., etc.
1326 */
1327
1328 strlcpy(uri, p->device_uri, sizeof(uri));
1329 }
1330
1331 ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_URI, "device-uri", NULL,
1332 uri);
1333
1334 /*
1335 * Assign additional attributes from the PPD file (if any)...
1336 */
1337
1338 p->type |= CUPS_PRINTER_BW;
1339 finishings[0] = IPP_FINISHINGS_NONE;
1340 num_finishings = 1;
1341
1342 snprintf(filename, sizeof(filename), "%s/ppd/%s.ppd", ServerRoot,
1343 p->name);
1344
1345 if ((ppd = ppdOpenFile(filename)) != NULL)
1346 {
1347 /*
1348 * Add make/model and other various attributes...
1349 */
1350
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;
1360
1361 ippAddBoolean(p->attrs, IPP_TAG_PRINTER, "color-supported",
1362 ppd->color_device);
1363 if (ppd->throughput)
1364 ippAddInteger(p->attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
1365 "pages-per-minute", ppd->throughput);
1366
1367 if (ppd->nickname)
1368 SetString(&p->make_model, ppd->nickname);
1369 else if (ppd->modelname)
1370 SetString(&p->make_model, ppd->modelname);
1371 else
1372 SetString(&p->make_model, "Bad PPD File");
1373
1374 ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_TEXT,
1375 "printer-make-and-model", NULL, p->make_model);
1376
1377 /*
1378 * Add media options from the PPD file...
1379 */
1380
1381 if ((input_slot = ppdFindOption(ppd, "InputSlot")) != NULL)
1382 num_media = input_slot->num_choices;
1383 else
1384 num_media = 0;
1385
1386 if ((media_type = ppdFindOption(ppd, "MediaType")) != NULL)
1387 num_media += media_type->num_choices;
1388
1389 if ((page_size = ppdFindOption(ppd, "PageSize")) != NULL)
1390 num_media += page_size->num_choices;
1391
1392 if ((media_quality = ppdFindOption(ppd, "EFMediaQualityMode")) != NULL)
1393 num_media += media_quality->num_choices;
1394
1395 if (num_media == 0)
1396 {
1397 LogMessage(L_CRIT, "SetPrinterAttrs: The PPD file for printer %s "
1398 "contains no media options and is therefore "
1399 "invalid!", p->name);
1400 }
1401 else
1402 {
1403 attr = ippAddStrings(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
1404 "media-supported", num_media, NULL, NULL);
1405 if (attr != NULL)
1406 {
1407 val = attr->values;
1408
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);
1412
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);
1416
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);
1420
1421 if (page_size != NULL)
1422 {
1423 for (i = 0; i < page_size->num_choices; i ++, val ++)
1424 val->string.text = strdup(page_size->choices[i].choice);
1425
1426 ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, "media-default",
1427 NULL, page_size->defchoice);
1428 }
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);
1438 else
1439 ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, "media-default",
1440 NULL, "none");
1441 }
1442 }
1443
1444 /*
1445 * Output bin...
1446 */
1447
1448 if ((output_bin = ppdFindOption(ppd, "OutputBin")) != NULL)
1449 {
1450 attr = ippAddStrings(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
1451 "output-bin-supported", output_bin->num_choices,
1452 NULL, NULL);
1453
1454 if (attr != NULL)
1455 {
1456 for (i = 0, val = attr->values;
1457 i < output_bin->num_choices;
1458 i ++, val ++)
1459 val->string.text = strdup(output_bin->choices[i].choice);
1460 }
1461 }
1462
1463 /*
1464 * Duplexing, etc...
1465 */
1466
1467 if (ppdFindOption(ppd, "Duplex") != NULL)
1468 {
1469 p->type |= CUPS_PRINTER_DUPLEX;
1470
1471 ippAddStrings(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, "sides-supported",
1472 3, NULL, sides);
1473 ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, "sides-default",
1474 NULL, "one");
1475 }
1476
1477 if (ppdFindOption(ppd, "Collate") != NULL)
1478 p->type |= CUPS_PRINTER_COLLATE;
1479
1480 if (ppdFindOption(ppd, "StapleLocation") != NULL)
1481 {
1482 p->type |= CUPS_PRINTER_STAPLE;
1483 finishings[num_finishings++] = IPP_FINISHINGS_STAPLE;
1484 }
1485
1486 if (ppdFindOption(ppd, "BindEdge") != NULL)
1487 {
1488 p->type |= CUPS_PRINTER_BIND;
1489 finishings[num_finishings++] = IPP_FINISHINGS_BIND;
1490 }
1491
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;
1497 else
1498 p->type |= CUPS_PRINTER_SMALL;
1499
1500 /*
1501 * Add any filters in the PPD file...
1502 */
1503
1504 DEBUG_printf(("ppd->num_filters = %d\n", ppd->num_filters));
1505 for (i = 0; i < ppd->num_filters; i ++)
1506 {
1507 DEBUG_printf(("ppd->filters[%d] = \"%s\"\n", i, ppd->filters[i]));
1508 AddPrinterFilter(p, ppd->filters[i]);
1509 }
1510
1511 if (ppd->num_filters == 0)
1512 AddPrinterFilter(p, "application/vnd.cups-postscript 0 -");
1513
1514 ppdClose(ppd);
1515
1516 printer_type = p->type;
1517 }
1518 else if (access(filename, 0) == 0)
1519 {
1520 int pline; /* PPD line number */
1521 ppd_status_t pstatus; /* PPD load status */
1522
1523
1524 pstatus = ppdLastError(&pline);
1525
1526 LogMessage(L_ERROR, "PPD file for %s cannot be loaded!", p->name);
1527
1528 if (pstatus <= PPD_ALLOC_ERROR)
1529 LogMessage(L_ERROR, "%s", strerror(errno));
1530 else
1531 LogMessage(L_ERROR, "%s on line %d.", ppdErrorString(pstatus),
1532 pline);
1533
1534 LogMessage(L_INFO, "Hint: Run \"cupstestppd %s\" and fix any errors.",
1535 filename);
1536
1537 AddPrinterFilter(p, "application/vnd.cups-postscript 0 -");
1538 }
1539 else
1540 {
1541 /*
1542 * If we have an interface script, add a filter entry for it...
1543 */
1544
1545 snprintf(filename, sizeof(filename), "%s/interfaces/%s", ServerRoot,
1546 p->name);
1547 if (access(filename, X_OK) == 0)
1548 {
1549 /*
1550 * Yes, we have a System V style interface script; use it!
1551 */
1552
1553 ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_TEXT,
1554 "printer-make-and-model", NULL, "Local System V Printer");
1555
1556 snprintf(filename, sizeof(filename), "*/* 0 %s/interfaces/%s",
1557 ServerRoot, p->name);
1558 AddPrinterFilter(p, filename);
1559 }
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))
1564 {
1565 /*
1566 * Tell the client this is really a hard-wired remote printer.
1567 */
1568
1569 printer_type |= CUPS_PRINTER_REMOTE;
1570
1571 /*
1572 * Reset the printer-uri-supported attribute to point at the
1573 * remote printer...
1574 */
1575
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);
1579
1580 /*
1581 * Then set the make-and-model accordingly...
1582 */
1583
1584 ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_TEXT,
1585 "printer-make-and-model", NULL, "Remote Printer");
1586
1587 /*
1588 * Print all files directly...
1589 */
1590
1591 p->raw = 1;
1592 }
1593 else
1594 {
1595 /*
1596 * Otherwise we have neither - treat this as a "dumb" printer
1597 * with no PPD file...
1598 */
1599
1600 ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_TEXT,
1601 "printer-make-and-model", NULL, "Local Raw Printer");
1602
1603 p->raw = 1;
1604 }
1605 }
1606
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);
1611 }
1612 }
1613
1614 /*
1615 * Add the CUPS-specific printer-type attribute...
1616 */
1617
1618 ippAddInteger(p->attrs, IPP_TAG_PRINTER, IPP_TAG_ENUM, "printer-type",
1619 printer_type);
1620
1621 DEBUG_printf(("SetPrinterAttrs: leaving name = %s, type = %x\n", p->name,
1622 p->type));
1623
1624 #ifdef __sgi
1625 /*
1626 * Write the IRIX printer config and status files...
1627 */
1628
1629 write_irix_config(p);
1630 write_irix_state(p);
1631 #endif /* __sgi */
1632 }
1633
1634
1635 /*
1636 * 'SetPrinterReasons()' - Set/update the reasons strings.
1637 */
1638
1639 void
1640 SetPrinterReasons(printer_t *p, /* I - Printer */
1641 const char *s) /* I - Reasons strings */
1642 {
1643 int i; /* Looping var */
1644 const char *sptr; /* Pointer into reasons */
1645 char reason[255], /* Reason string */
1646 *rptr; /* Pointer into reason */
1647
1648
1649 if (s[0] == '-' || s[0] == '+')
1650 {
1651 /*
1652 * Add/remove reasons...
1653 */
1654
1655 sptr = s + 1;
1656 }
1657 else
1658 {
1659 /*
1660 * Replace reasons...
1661 */
1662
1663 sptr = s;
1664
1665 for (i = 0; i < p->num_reasons; i ++)
1666 free(p->reasons[i]);
1667
1668 p->num_reasons = 0;
1669 }
1670
1671 /*
1672 * Loop through all of the reasons...
1673 */
1674
1675 while (*sptr)
1676 {
1677 /*
1678 * Skip leading whitespace and commas...
1679 */
1680
1681 while (isspace(*sptr) || *sptr == ',')
1682 sptr ++;
1683
1684 for (rptr = reason; *sptr && !isspace(*sptr) && *sptr != ','; sptr ++)
1685 if (rptr < (reason + sizeof(reason) - 1))
1686 *rptr++ = *sptr;
1687
1688 if (rptr == reason)
1689 break;
1690
1691 *rptr = '\0';
1692
1693 if (s[0] == '-')
1694 {
1695 /*
1696 * Remove reason...
1697 */
1698
1699 for (i = 0; i < p->num_reasons; i ++)
1700 if (!strcasecmp(reason, p->reasons[i]))
1701 {
1702 /*
1703 * Found a match, so remove it...
1704 */
1705
1706 p->num_reasons --;
1707 free(p->reasons[i]);
1708
1709 if (i < p->num_reasons)
1710 memmove(p->reasons + i, p->reasons + i + 1,
1711 (p->num_reasons - i) * sizeof(char *));
1712
1713 i --;
1714 }
1715 }
1716 else if (s[0] == '+' &&
1717 p->num_reasons < (int)(sizeof(p->reasons) / sizeof(p->reasons[0])))
1718 {
1719 /*
1720 * Add reason...
1721 */
1722
1723 for (i = 0; i < p->num_reasons; i ++)
1724 if (!strcasecmp(reason, p->reasons[i]))
1725 break;
1726
1727 if (i >= p->num_reasons)
1728 {
1729 p->reasons[i] = strdup(reason);
1730 p->num_reasons ++;
1731 }
1732 }
1733 }
1734 }
1735
1736
1737 /*
1738 * 'SetPrinterState()' - Update the current state of a printer.
1739 */
1740
1741 void
1742 SetPrinterState(printer_t *p, /* I - Printer to change */
1743 ipp_pstate_t s, /* I - New state */
1744 int update) /* I - Update printers.conf? */
1745 {
1746 ipp_pstate_t old_state; /* Old printer state */
1747
1748
1749 /*
1750 * Can't set status of remote printers...
1751 */
1752
1753 if (p->type & CUPS_PRINTER_REMOTE)
1754 return;
1755
1756 /*
1757 * Set the new state...
1758 */
1759
1760 old_state = p->state;
1761 p->state = s;
1762
1763 if (old_state != s)
1764 {
1765 p->state_time = time(NULL);
1766 p->browse_time = 0;
1767
1768 #ifdef __sgi
1769 write_irix_state(p);
1770 #endif /* __sgi */
1771 }
1772
1773 AddPrinterHistory(p);
1774
1775 /*
1776 * Save the printer configuration if a printer goes from idle or processing
1777 * to stopped (or visa-versa)...
1778 */
1779
1780 if ((old_state == IPP_PRINTER_STOPPED) != (s == IPP_PRINTER_STOPPED) &&
1781 update)
1782 {
1783 if (p->type & CUPS_PRINTER_CLASS)
1784 SaveAllClasses();
1785 else
1786 SaveAllPrinters();
1787 }
1788 }
1789
1790
1791 /*
1792 * 'SortPrinters()' - Sort the printer list when a printer name is changed.
1793 */
1794
1795 void
1796 SortPrinters(void)
1797 {
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 */
1802
1803
1804 do
1805 {
1806 for (did_swap = 0, current = Printers, prev = NULL; current != NULL;)
1807 if (current->next == NULL)
1808 break;
1809 else if (strcasecmp(current->name, current->next->name) > 0)
1810 {
1811 DEBUG_printf(("Swapping %s and %s...\n", current->name,
1812 current->next->name));
1813
1814 /*
1815 * Need to swap these two printers...
1816 */
1817
1818 did_swap = 1;
1819
1820 if (prev == NULL)
1821 Printers = current->next;
1822 else
1823 prev->next = current->next;
1824
1825 /*
1826 * Yes, we can all get a headache from the next bunch of pointer
1827 * swapping...
1828 */
1829
1830 next = current->next;
1831 current->next = next->next;
1832 next->next = current;
1833 prev = next;
1834 }
1835 else
1836 {
1837 prev = current;
1838 current = current->next;
1839 }
1840 }
1841 while (did_swap);
1842 }
1843
1844
1845 /*
1846 * 'StopPrinter()' - Stop a printer from printing any jobs...
1847 */
1848
1849 void
1850 StopPrinter(printer_t *p, /* I - Printer to stop */
1851 int update) /* I - Update printers.conf? */
1852 {
1853 job_t *job; /* Active print job */
1854
1855
1856 /*
1857 * Set the printer state...
1858 */
1859
1860 SetPrinterState(p, IPP_PRINTER_STOPPED, update);
1861
1862 /*
1863 * See if we have a job printing on this printer...
1864 */
1865
1866 if (p->job)
1867 {
1868 /*
1869 * Get pointer to job...
1870 */
1871
1872 job = (job_t *)p->job;
1873
1874 /*
1875 * Stop it...
1876 */
1877
1878 StopJob(job->id, 0);
1879
1880 /*
1881 * Reset the state to pending...
1882 */
1883
1884 job->state->values[0].integer = IPP_JOB_PENDING;
1885
1886 SaveJob(job->id);
1887 }
1888 }
1889
1890
1891 /*
1892 * 'ValidateDest()' - Validate a printer/class destination.
1893 */
1894
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) */
1899 {
1900 printer_t *p; /* Current printer */
1901 char localname[1024], /* Localized hostname */
1902 *lptr, /* Pointer into localized hostname */
1903 *sptr; /* Pointer into server name */
1904
1905
1906 DEBUG_printf(("ValidateDest(\"%s\", \"%s\", %p)\n", hostname, resource, dtype));
1907
1908 /*
1909 * See if the resource is a class or printer...
1910 */
1911
1912 if (strncmp(resource, "/classes/", 9) == 0)
1913 {
1914 /*
1915 * Class...
1916 */
1917
1918 resource += 9;
1919 }
1920 else if (strncmp(resource, "/printers/", 10) == 0)
1921 {
1922 /*
1923 * Printer...
1924 */
1925
1926 resource += 10;
1927 }
1928 else
1929 {
1930 /*
1931 * Bad resource name...
1932 */
1933
1934 return (NULL);
1935 }
1936
1937 /*
1938 * See if the printer or class name exists...
1939 */
1940
1941 if ((p = FindPrinter(resource)) == NULL)
1942 p = FindClass(resource);
1943
1944 if (p == NULL && strchr(resource, '@') == NULL)
1945 return (NULL);
1946 else if (p != NULL)
1947 {
1948 *dtype = p->type & (CUPS_PRINTER_CLASS | CUPS_PRINTER_IMPLICIT |
1949 CUPS_PRINTER_REMOTE);
1950 return (p->name);
1951 }
1952
1953 /*
1954 * Change localhost to the server name...
1955 */
1956
1957 if (strcasecmp(hostname, "localhost") == 0)
1958 hostname = ServerName;
1959
1960 strlcpy(localname, hostname, sizeof(localname));
1961
1962 if (strcasecmp(hostname, ServerName) != 0)
1963 {
1964 /*
1965 * Localize the hostname...
1966 */
1967
1968 lptr = strchr(localname, '.');
1969 sptr = strchr(ServerName, '.');
1970
1971 if (sptr != NULL && lptr != NULL)
1972 {
1973 /*
1974 * Strip the common domain name components...
1975 */
1976
1977 while (lptr != NULL)
1978 {
1979 if (strcasecmp(lptr, sptr) == 0)
1980 {
1981 *lptr = '\0';
1982 break;
1983 }
1984 else
1985 lptr = strchr(lptr + 1, '.');
1986 }
1987 }
1988 }
1989
1990 DEBUG_printf(("localized hostname is \"%s\"...\n", localname));
1991
1992 /*
1993 * Find a matching printer or class...
1994 */
1995
1996 for (p = Printers; p != NULL; p = p->next)
1997 if (strcasecmp(p->hostname, localname) == 0 &&
1998 strcasecmp(p->name, resource) == 0)
1999 {
2000 *dtype = p->type & (CUPS_PRINTER_CLASS | CUPS_PRINTER_IMPLICIT |
2001 CUPS_PRINTER_REMOTE);
2002 return (p->name);
2003 }
2004
2005 return (NULL);
2006 }
2007
2008
2009 /*
2010 * 'WritePrintcap()' - Write a pseudo-printcap file for older applications
2011 * that need it...
2012 */
2013
2014 void
2015 WritePrintcap(void)
2016 {
2017 cups_file_t *fp; /* printcap file */
2018 printer_t *p; /* Current printer */
2019
2020
2021 #ifdef __sgi
2022 /*
2023 * Update the IRIX printer state for the default printer; if
2024 * no printers remain, then the default printer file will be
2025 * removed...
2026 */
2027
2028 write_irix_state(DefaultPrinter);
2029 #endif /* __sgi */
2030
2031 /*
2032 * See if we have a printcap file; if not, don't bother writing it.
2033 */
2034
2035 if (!Printcap[0])
2036 return;
2037
2038 /*
2039 * Open the printcap file...
2040 */
2041
2042 if ((fp = cupsFileOpen(Printcap, "w")) == NULL)
2043 return;
2044
2045 /*
2046 * Put a comment header at the top so that users will know where the
2047 * data has come from...
2048 */
2049
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",
2052 ServerRoot);
2053 cupsFilePuts(fp, "# will be lost.\n");
2054
2055 /*
2056 * Write a new printcap with the current list of printers.
2057 */
2058
2059 switch (PrintcapFormat)
2060 {
2061 case PRINTCAP_BSD:
2062 /*
2063 * Each printer is put in the file as:
2064 *
2065 * Printer1:
2066 * Printer2:
2067 * Printer3:
2068 * ...
2069 * PrinterN:
2070 */
2071
2072 if (DefaultPrinter)
2073 cupsFilePrintf(fp, "%s|%s:rm=%s:rp=%s:\n", DefaultPrinter->name,
2074 DefaultPrinter->info, ServerName, DefaultPrinter->name);
2075
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);
2080 break;
2081
2082 case PRINTCAP_SOLARIS:
2083 /*
2084 * Each printer is put in the file as:
2085 *
2086 * _all:all=Printer1,Printer2,Printer3,...,PrinterN
2087 * _default:use=DefaultPrinter
2088 * Printer1:\
2089 * :bsdaddr=ServerName,Printer1:\
2090 * :description=Description:
2091 * Printer2:
2092 * :bsdaddr=ServerName,Printer2:\
2093 * :description=Description:
2094 * Printer3:
2095 * :bsdaddr=ServerName,Printer3:\
2096 * :description=Description:
2097 * ...
2098 * PrinterN:
2099 * :bsdaddr=ServerName,PrinterN:\
2100 * :description=Description:
2101 */
2102
2103 cupsFilePuts(fp, "_all:all=");
2104 for (p = Printers; p != NULL; p = p->next)
2105 cupsFilePrintf(fp, "%s%c", p->name, p->next ? ',' : '\n');
2106
2107 if (DefaultPrinter)
2108 cupsFilePrintf(fp, "_default:use=%s\n", DefaultPrinter->name);
2109
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 : "");
2115 break;
2116 }
2117
2118 /*
2119 * Close the file...
2120 */
2121
2122 cupsFileClose(fp);
2123 }
2124
2125
2126 #ifdef __sgi
2127 /*
2128 * 'write_irix_config()' - Update the config files used by the IRIX
2129 * desktop tools.
2130 */
2131
2132 static void
2133 write_irix_config(printer_t *p) /* I - Printer to update */
2134 {
2135 char filename[1024]; /* Interface script filename */
2136 cups_file_t *fp; /* Interface script file */
2137 ipp_attribute_t *attr; /* Attribute value */
2138
2139
2140 /*
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...
2144 */
2145
2146 snprintf(filename, sizeof(filename), "/var/spool/lp/interface/%s", p->name);
2147
2148 if (p->type & CUPS_PRINTER_CLASS)
2149 unlink(filename);
2150 else if ((fp = cupsFileOpen(filename, "w")) != NULL)
2151 {
2152 cupsFilePuts(fp, "#!/bin/sh\n");
2153
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");
2159 else
2160 cupsFilePuts(fp, "NAME=\"Remote Destination\"\n");
2161
2162 if (p->type & CUPS_PRINTER_COLOR)
2163 cupsFilePuts(fp, "TYPE=ColorPostScript\n");
2164 else
2165 cupsFilePuts(fp, "TYPE=MonoPostScript\n");
2166
2167 cupsFilePrintf(fp, "HOSTNAME=%s\n", ServerName);
2168 cupsFilePrintf(fp, "HOSTPRINTER=%s\n", p->name);
2169
2170 cupsFileClose(fp);
2171
2172 chmod(filename, 0755);
2173 chown(filename, User, Group);
2174 }
2175
2176 /*
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...)
2180 */
2181
2182 snprintf(filename, sizeof(filename), "/var/spool/lp/member/%s", p->name);
2183
2184 if (p->type & CUPS_PRINTER_CLASS)
2185 unlink(filename);
2186 else if ((fp = cupsFileOpen(filename, "w")) != NULL)
2187 {
2188 cupsFilePuts(fp, "/dev/null\n");
2189
2190 cupsFileClose(fp);
2191
2192 chmod(filename, 0644);
2193 chown(filename, User, Group);
2194 }
2195
2196 /*
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.
2202 *
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.
2206 */
2207
2208 snprintf(filename, sizeof(filename), "/var/spool/lp/gui_interface/ELF/%s.gui", p->name);
2209
2210 if (p->type & CUPS_PRINTER_CLASS)
2211 unlink(filename);
2212 else if ((fp = cupsFileOpen(filename, "w")) != NULL)
2213 {
2214 cupsFilePuts(fp, "#!/bin/sh\n");
2215 cupsFilePrintf(fp, "%s -d %s -o \"$3\"\n", PrintcapGUI, p->name);
2216
2217 cupsFileClose(fp);
2218
2219 chmod(filename, 0755);
2220 chown(filename, User, Group);
2221 }
2222
2223 /*
2224 * The POD config file is needed by the printstatus command to show
2225 * the printer location and device.
2226 */
2227
2228 snprintf(filename, sizeof(filename), "/var/spool/lp/pod/%s.config", p->name);
2229
2230 if (p->type & CUPS_PRINTER_CLASS)
2231 unlink(filename);
2232 else if ((fp = cupsFileOpen(filename, "w")) != NULL)
2233 {
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");
2243
2244 cupsFileClose(fp);
2245
2246 chmod(filename, 0664);
2247 chown(filename, User, Group);
2248 }
2249 }
2250
2251
2252 /*
2253 * 'write_irix_state()' - Update the status files used by IRIX printing
2254 * desktop tools.
2255 */
2256
2257 static void
2258 write_irix_state(printer_t *p) /* I - Printer to update */
2259 {
2260 char filename[1024]; /* Interface script filename */
2261 cups_file_t *fp; /* Interface script file */
2262 int tag; /* Status tag value */
2263
2264
2265 if (p)
2266 {
2267 /*
2268 * The POD status file is needed for the printstatus window to
2269 * provide the current status of the printer.
2270 */
2271
2272 snprintf(filename, sizeof(filename), "/var/spool/lp/pod/%s.status", p->name);
2273
2274 if (p->type & CUPS_PRINTER_CLASS)
2275 unlink(filename);
2276 else if ((fp = cupsFileOpen(filename, "w")) != NULL)
2277 {
2278 cupsFilePrintf(fp, "Operational Status | %s\n",
2279 (p->state == IPP_PRINTER_IDLE) ? "Idle" :
2280 (p->state == IPP_PRINTER_PROCESSING) ? "Busy" :
2281 "Faulted");
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);
2288
2289 cupsFileClose(fp);
2290
2291 chmod(filename, 0664);
2292 chown(filename, User, Group);
2293 }
2294
2295 /*
2296 * The activeicons file is needed to provide desktop icons for printers:
2297 *
2298 * [ quoted from /usr/lib/print/tagit ]
2299 *
2300 * --- Type of printer tags (base values)
2301 *
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
2310 *
2311 * --- Printer state modifiers for local printers
2312 *
2313 * Idle=0 # 0x0
2314 * Busy=1 # 0x1
2315 * Faulted=2 # 0x2
2316 * Unknown=3 # 0x3 (Faulted due to unknown reason)
2317 *
2318 * --- Printer state modifiers for network printers
2319 *
2320 * NetIdle=8 # 0x8
2321 * NetBusy=9 # 0x9
2322 * NetFaulted=10 # 0xA
2323 * NetUnknown=11 # 0xB (Faulted due to unknown reason)
2324 */
2325
2326 snprintf(filename, sizeof(filename), "/var/spool/lp/activeicons/%s", p->name);
2327
2328 if (p->type & CUPS_PRINTER_CLASS)
2329 unlink(filename);
2330 else if ((fp = cupsFileOpen(filename, "w")) != NULL)
2331 {
2332 if (p->type & CUPS_PRINTER_COLOR)
2333 tag = 66240;
2334 else
2335 tag = 66272;
2336
2337 if (p->type & CUPS_PRINTER_REMOTE)
2338 tag |= 8;
2339
2340 if (p->state == IPP_PRINTER_PROCESSING)
2341 tag |= 1;
2342
2343 else if (p->state == IPP_PRINTER_STOPPED)
2344 tag |= 2;
2345
2346 cupsFilePuts(fp, "#!/bin/sh\n");
2347 cupsFilePrintf(fp, "#Tag %d\n", tag);
2348
2349 cupsFileClose(fp);
2350
2351 chmod(filename, 0755);
2352 chown(filename, User, Group);
2353 }
2354 }
2355
2356 /*
2357 * The default file is needed by the printers window to show
2358 * the default printer.
2359 */
2360
2361 snprintf(filename, sizeof(filename), "/var/spool/lp/default");
2362
2363 if (DefaultPrinter != NULL)
2364 {
2365 if ((fp = cupsFileOpen(filename, "w")) != NULL)
2366 {
2367 cupsFilePrintf(fp, "%s\n", DefaultPrinter->name);
2368
2369 cupsFileClose(fp);
2370
2371 chmod(filename, 0644);
2372 chown(filename, User, Group);
2373 }
2374 }
2375 else
2376 unlink(filename);
2377 }
2378 #endif /* __sgi */
2379
2380
2381 /*
2382 * End of "$Id: printers.c,v 1.150 2003/04/25 15:23:22 mike Exp $".
2383 */