]> git.ipfire.org Git - thirdparty/cups.git/blob - scheduler/classes.c
Merge changes from CUPS 1.4svn-r8227.
[thirdparty/cups.git] / scheduler / classes.c
1 /*
2 * "$Id: classes.c 7724 2008-07-14 06:06:06Z mike $"
3 *
4 * Printer class routines for the Common UNIX Printing System (CUPS).
5 *
6 * Copyright 2007-2009 by Apple Inc.
7 * Copyright 1997-2007 by Easy Software Products, all rights reserved.
8 *
9 * These coded instructions, statements, and computer programs are the
10 * property of Apple Inc. and are protected by Federal copyright
11 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
12 * which should have been included with this file. If this file is
13 * file is missing or damaged, see the license at "http://www.cups.org/".
14 *
15 * Contents:
16 *
17 * cupsdAddClass() - Add a class to the system.
18 * cupsdAddPrinterToClass() - Add a printer to a class...
19 * cupsdDeletePrinterFromClass() - Delete a printer from a class.
20 * cupsdDeletePrinterFromClasses() - Delete a printer from all classes.
21 * cupsdFindAvailablePrinter() - Find an available printer in a class.
22 * cupsdFindClass() - Find the named class.
23 * cupsdLoadAllClasses() - Load classes from the classes.conf file.
24 * cupsdSaveAllClasses() - Save classes to the classes.conf file.
25 * cupsdUpdateImplicitClasses() - Update the accepting state of implicit
26 * classes.
27 */
28
29 /*
30 * Include necessary headers...
31 */
32
33 #include "cupsd.h"
34
35
36 /*
37 * 'cupsdAddClass()' - Add a class to the system.
38 */
39
40 cupsd_printer_t * /* O - New class */
41 cupsdAddClass(const char *name) /* I - Name of class */
42 {
43 cupsd_printer_t *c; /* New class */
44
45
46 /*
47 * Add the printer and set the type to "class"...
48 */
49
50 if ((c = cupsdAddPrinter(name)) != NULL)
51 {
52 /*
53 * Change from a printer to a class...
54 */
55
56 c->type = CUPS_PRINTER_CLASS;
57
58 cupsdSetStringf(&c->uri, "ipp://%s:%d/classes/%s", ServerName, LocalPort,
59 name);
60 cupsdSetString(&c->error_policy, "retry-job");
61 }
62
63 return (c);
64 }
65
66
67 /*
68 * 'cupsdAddPrinterToClass()' - Add a printer to a class...
69 */
70
71 void
72 cupsdAddPrinterToClass(
73 cupsd_printer_t *c, /* I - Class to add to */
74 cupsd_printer_t *p) /* I - Printer to add */
75 {
76 int i; /* Looping var */
77 cupsd_printer_t **temp; /* Pointer to printer array */
78
79
80 /*
81 * See if this printer is already a member of the class...
82 */
83
84 for (i = 0; i < c->num_printers; i ++)
85 if (c->printers[i] == p)
86 return;
87
88 /*
89 * Allocate memory as needed...
90 */
91
92 if (c->num_printers == 0)
93 temp = malloc(sizeof(cupsd_printer_t *));
94 else
95 temp = realloc(c->printers, sizeof(cupsd_printer_t *) * (c->num_printers + 1));
96
97 if (temp == NULL)
98 {
99 cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to add printer %s to class %s!",
100 p->name, c->name);
101 return;
102 }
103
104 /*
105 * Add the printer to the end of the array and update the number of printers.
106 */
107
108 c->printers = temp;
109 temp += c->num_printers;
110 c->num_printers ++;
111
112 *temp = p;
113 }
114
115
116 /*
117 * 'cupsdDeletePrinterFromClass()' - Delete a printer from a class.
118 */
119
120 void
121 cupsdDeletePrinterFromClass(
122 cupsd_printer_t *c, /* I - Class to delete from */
123 cupsd_printer_t *p) /* I - Printer to delete */
124 {
125 int i; /* Looping var */
126
127
128 /*
129 * See if the printer is in the class...
130 */
131
132 for (i = 0; i < c->num_printers; i ++)
133 if (p == c->printers[i])
134 break;
135
136 /*
137 * If it is, remove it from the list...
138 */
139
140 if (i < c->num_printers)
141 {
142 /*
143 * Yes, remove the printer...
144 */
145
146 c->num_printers --;
147 if (i < c->num_printers)
148 memmove(c->printers + i, c->printers + i + 1,
149 (c->num_printers - i) * sizeof(cupsd_printer_t *));
150 }
151 else
152 return;
153
154 /*
155 * Update the IPP attributes (have to do this for member-names)...
156 */
157
158 cupsdSetPrinterAttrs(c);
159 }
160
161
162 /*
163 * 'cupsdDeletePrinterFromClasses()' - Delete a printer from all classes.
164 */
165
166 void
167 cupsdDeletePrinterFromClasses(
168 cupsd_printer_t *p) /* I - Printer to delete */
169 {
170 cupsd_printer_t *c; /* Pointer to current class */
171
172
173 /*
174 * Loop through the printer/class list and remove the printer
175 * from each class listed...
176 */
177
178 for (c = (cupsd_printer_t *)cupsArrayFirst(Printers);
179 c;
180 c = (cupsd_printer_t *)cupsArrayNext(Printers))
181 if (c->type & (CUPS_PRINTER_CLASS | CUPS_PRINTER_IMPLICIT))
182 cupsdDeletePrinterFromClass(c, p);
183
184 /*
185 * Then clean out any empty implicit classes...
186 */
187
188 for (c = (cupsd_printer_t *)cupsArrayFirst(ImplicitPrinters);
189 c;
190 c = (cupsd_printer_t *)cupsArrayNext(ImplicitPrinters))
191 if (c->num_printers == 0)
192 {
193 cupsdLogMessage(CUPSD_LOG_DEBUG, "Deleting implicit class \"%s\"...",
194 c->name);
195 cupsdDeletePrinter(c, 0);
196 }
197 }
198
199
200 /*
201 * 'cupsdFindAvailablePrinter()' - Find an available printer in a class.
202 */
203
204 cupsd_printer_t * /* O - Available printer or NULL */
205 cupsdFindAvailablePrinter(
206 const char *name) /* I - Class to check */
207 {
208 int i; /* Looping var */
209 cupsd_printer_t *c; /* Printer class */
210
211
212 /*
213 * Find the class...
214 */
215
216 if ((c = cupsdFindClass(name)) == NULL)
217 {
218 cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to find class \"%s\"!", name);
219 return (NULL);
220 }
221
222 if (c->num_printers == 0)
223 return (NULL);
224
225 /*
226 * Make sure that the last printer is also a valid index into the printer
227 * array. If not, reset the last printer to 0...
228 */
229
230 if (c->last_printer >= c->num_printers)
231 c->last_printer = 0;
232
233 /*
234 * Loop through the printers in the class and return the first idle
235 * printer... We keep track of the last printer that we used so that
236 * a "round robin" type of scheduling is realized (otherwise the first
237 * server might be saturated with print jobs...)
238 *
239 * Thanks to Joel Fredrikson for helping us get this right!
240 */
241
242 for (i = c->last_printer + 1; ; i ++)
243 {
244 if (i >= c->num_printers)
245 i = 0;
246
247 if (c->printers[i]->accepting &&
248 (c->printers[i]->state == IPP_PRINTER_IDLE ||
249 ((c->printers[i]->type & CUPS_PRINTER_REMOTE) && !c->printers[i]->job)))
250 {
251 c->last_printer = i;
252 return (c->printers[i]);
253 }
254
255 if (i == c->last_printer)
256 break;
257 }
258
259 return (NULL);
260 }
261
262
263 /*
264 * 'cupsdFindClass()' - Find the named class.
265 */
266
267 cupsd_printer_t * /* O - Matching class or NULL */
268 cupsdFindClass(const char *name) /* I - Name of class */
269 {
270 cupsd_printer_t *c; /* Current class/printer */
271
272
273 if ((c = cupsdFindDest(name)) != NULL &&
274 (c->type & (CUPS_PRINTER_CLASS | CUPS_PRINTER_IMPLICIT)))
275 return (c);
276 else
277 return (NULL);
278 }
279
280
281 /*
282 * 'cupsdLoadAllClasses()' - Load classes from the classes.conf file.
283 */
284
285 void
286 cupsdLoadAllClasses(void)
287 {
288 cups_file_t *fp; /* classes.conf file */
289 int linenum; /* Current line number */
290 char line[1024], /* Line from file */
291 *value, /* Pointer to value */
292 *valueptr; /* Pointer into value */
293 cupsd_printer_t *p, /* Current printer class */
294 *temp; /* Temporary pointer to printer */
295
296
297 /*
298 * Open the classes.conf file...
299 */
300
301 snprintf(line, sizeof(line), "%s/classes.conf", ServerRoot);
302 if ((fp = cupsFileOpen(line, "r")) == NULL)
303 {
304 if (errno != ENOENT)
305 cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to open %s - %s", line,
306 strerror(errno));
307 return;
308 }
309
310 /*
311 * Read class configurations until we hit EOF...
312 */
313
314 linenum = 0;
315 p = NULL;
316
317 while (cupsFileGetConf(fp, line, sizeof(line), &value, &linenum))
318 {
319 /*
320 * Decode the directive...
321 */
322
323 if (!strcasecmp(line, "<Class") ||
324 !strcasecmp(line, "<DefaultClass"))
325 {
326 /*
327 * <Class name> or <DefaultClass name>
328 */
329
330 if (p == NULL && value)
331 {
332 cupsdLogMessage(CUPSD_LOG_DEBUG, "Loading class %s...", value);
333
334 /*
335 * Since prior classes may have implicitly defined this class,
336 * see if it already exists...
337 */
338
339 if ((p = cupsdFindDest(value)) != NULL)
340 {
341 p->type = CUPS_PRINTER_CLASS;
342 cupsdSetStringf(&p->uri, "ipp://%s:%d/classes/%s", ServerName,
343 LocalPort, value);
344 cupsdSetString(&p->error_policy, "retry-job");
345 }
346 else
347 p = cupsdAddClass(value);
348
349 p->accepting = 1;
350 p->state = IPP_PRINTER_IDLE;
351
352 if (!strcasecmp(line, "<DefaultClass"))
353 DefaultPrinter = p;
354 }
355 else
356 cupsdLogMessage(CUPSD_LOG_ERROR,
357 "Syntax error on line %d of classes.conf.", linenum);
358 }
359 else if (!strcasecmp(line, "</Class>"))
360 {
361 if (p != NULL)
362 {
363 cupsdSetPrinterAttrs(p);
364 p = NULL;
365 }
366 else
367 cupsdLogMessage(CUPSD_LOG_ERROR,
368 "Syntax error on line %d of classes.conf.", linenum);
369 }
370 else if (!p)
371 {
372 cupsdLogMessage(CUPSD_LOG_ERROR,
373 "Syntax error on line %d of classes.conf.", linenum);
374 }
375 else if (!strcasecmp(line, "AuthInfoRequired"))
376 {
377 if (!cupsdSetAuthInfoRequired(p, value, NULL))
378 cupsdLogMessage(CUPSD_LOG_ERROR,
379 "Bad AuthInfoRequired on line %d of classes.conf.",
380 linenum);
381 }
382 else if (!strcasecmp(line, "Info"))
383 {
384 if (value)
385 cupsdSetString(&p->info, value);
386 }
387 else if (!strcasecmp(line, "Location"))
388 {
389 if (value)
390 cupsdSetString(&p->location, value);
391 }
392 else if (!strcasecmp(line, "Option") && value)
393 {
394 /*
395 * Option name value
396 */
397
398 for (valueptr = value; *valueptr && !isspace(*valueptr & 255); valueptr ++);
399
400 if (!*valueptr)
401 cupsdLogMessage(CUPSD_LOG_ERROR,
402 "Syntax error on line %d of classes.conf.", linenum);
403 else
404 {
405 for (; *valueptr && isspace(*valueptr & 255); *valueptr++ = '\0');
406
407 p->num_options = cupsAddOption(value, valueptr, p->num_options,
408 &(p->options));
409 }
410 }
411 else if (!strcasecmp(line, "Printer"))
412 {
413 if (!value)
414 {
415 cupsdLogMessage(CUPSD_LOG_ERROR,
416 "Syntax error on line %d of classes.conf.", linenum);
417 continue;
418 }
419 else if ((temp = cupsdFindPrinter(value)) == NULL)
420 {
421 cupsdLogMessage(CUPSD_LOG_WARN,
422 "Unknown printer %s on line %d of classes.conf.",
423 value, linenum);
424
425 /*
426 * Add the missing remote printer...
427 */
428
429 if ((temp = cupsdAddPrinter(value)) != NULL)
430 {
431 cupsdSetString(&temp->make_model, "Remote Printer on unknown");
432
433 temp->state = IPP_PRINTER_STOPPED;
434 temp->type |= CUPS_PRINTER_REMOTE;
435 temp->browse_time = 2147483647;
436
437 cupsdSetString(&temp->location, "Location Unknown");
438 cupsdSetString(&temp->info, "No Information Available");
439 temp->hostname[0] = '\0';
440
441 cupsdSetPrinterAttrs(temp);
442 }
443 }
444
445 if (temp)
446 cupsdAddPrinterToClass(p, temp);
447 }
448 else if (!strcasecmp(line, "State"))
449 {
450 /*
451 * Set the initial queue state...
452 */
453
454 if (!strcasecmp(value, "idle"))
455 p->state = IPP_PRINTER_IDLE;
456 else if (!strcasecmp(value, "stopped"))
457 p->state = IPP_PRINTER_STOPPED;
458 else
459 cupsdLogMessage(CUPSD_LOG_ERROR,
460 "Syntax error on line %d of classes.conf.",
461 linenum);
462 }
463 else if (!strcasecmp(line, "StateMessage"))
464 {
465 /*
466 * Set the initial queue state message...
467 */
468
469 if (value)
470 strlcpy(p->state_message, value, sizeof(p->state_message));
471 }
472 else if (!strcasecmp(line, "StateTime"))
473 {
474 /*
475 * Set the state time...
476 */
477
478 if (value)
479 p->state_time = atoi(value);
480 }
481 else if (!strcasecmp(line, "Accepting"))
482 {
483 /*
484 * Set the initial accepting state...
485 */
486
487 if (value &&
488 (!strcasecmp(value, "yes") ||
489 !strcasecmp(value, "on") ||
490 !strcasecmp(value, "true")))
491 p->accepting = 1;
492 else if (value &&
493 (!strcasecmp(value, "no") ||
494 !strcasecmp(value, "off") ||
495 !strcasecmp(value, "false")))
496 p->accepting = 0;
497 else
498 cupsdLogMessage(CUPSD_LOG_ERROR,
499 "Syntax error on line %d of classes.conf.",
500 linenum);
501 }
502 else if (!strcasecmp(line, "Shared"))
503 {
504 /*
505 * Set the initial shared state...
506 */
507
508 if (value &&
509 (!strcasecmp(value, "yes") ||
510 !strcasecmp(value, "on") ||
511 !strcasecmp(value, "true")))
512 p->shared = 1;
513 else if (value &&
514 (!strcasecmp(value, "no") ||
515 !strcasecmp(value, "off") ||
516 !strcasecmp(value, "false")))
517 p->shared = 0;
518 else
519 cupsdLogMessage(CUPSD_LOG_ERROR,
520 "Syntax error on line %d of classes.conf.",
521 linenum);
522 }
523 else if (!strcasecmp(line, "JobSheets"))
524 {
525 /*
526 * Set the initial job sheets...
527 */
528
529 if (value)
530 {
531 for (valueptr = value;
532 *valueptr && !isspace(*valueptr & 255);
533 valueptr ++);
534
535 if (*valueptr)
536 *valueptr++ = '\0';
537
538 cupsdSetString(&p->job_sheets[0], value);
539
540 while (isspace(*valueptr & 255))
541 valueptr ++;
542
543 if (*valueptr)
544 {
545 for (value = valueptr;
546 *valueptr && !isspace(*valueptr & 255);
547 valueptr ++);
548
549 if (*valueptr)
550 *valueptr = '\0';
551
552 cupsdSetString(&p->job_sheets[1], value);
553 }
554 }
555 else
556 cupsdLogMessage(CUPSD_LOG_ERROR,
557 "Syntax error on line %d of classes.conf.", linenum);
558 }
559 else if (!strcasecmp(line, "AllowUser"))
560 {
561 if (value)
562 {
563 p->deny_users = 0;
564 cupsdAddPrinterUser(p, value);
565 }
566 else
567 cupsdLogMessage(CUPSD_LOG_ERROR,
568 "Syntax error on line %d of classes.conf.", linenum);
569 }
570 else if (!strcasecmp(line, "DenyUser"))
571 {
572 if (value)
573 {
574 p->deny_users = 1;
575 cupsdAddPrinterUser(p, value);
576 }
577 else
578 cupsdLogMessage(CUPSD_LOG_ERROR,
579 "Syntax error on line %d of classes.conf.", linenum);
580 }
581 else if (!strcasecmp(line, "QuotaPeriod"))
582 {
583 if (value)
584 p->quota_period = atoi(value);
585 else
586 cupsdLogMessage(CUPSD_LOG_ERROR,
587 "Syntax error on line %d of classes.conf.", linenum);
588 }
589 else if (!strcasecmp(line, "PageLimit"))
590 {
591 if (value)
592 p->page_limit = atoi(value);
593 else
594 cupsdLogMessage(CUPSD_LOG_ERROR,
595 "Syntax error on line %d of classes.conf.", linenum);
596 }
597 else if (!strcasecmp(line, "KLimit"))
598 {
599 if (value)
600 p->k_limit = atoi(value);
601 else
602 cupsdLogMessage(CUPSD_LOG_ERROR,
603 "Syntax error on line %d of classes.conf.", linenum);
604 }
605 else if (!strcasecmp(line, "OpPolicy"))
606 {
607 if (value)
608 {
609 cupsd_policy_t *pol; /* Policy */
610
611
612 if ((pol = cupsdFindPolicy(value)) != NULL)
613 {
614 cupsdSetString(&p->op_policy, value);
615 p->op_policy_ptr = pol;
616 }
617 else
618 cupsdLogMessage(CUPSD_LOG_ERROR,
619 "Bad policy \"%s\" on line %d of classes.conf",
620 value, linenum);
621 }
622 else
623 cupsdLogMessage(CUPSD_LOG_ERROR,
624 "Syntax error on line %d of classes.conf.", linenum);
625 }
626 else if (!strcasecmp(line, "ErrorPolicy"))
627 {
628 if (value)
629 cupsdSetString(&p->error_policy, value);
630 else
631 cupsdLogMessage(CUPSD_LOG_ERROR,
632 "Syntax error on line %d of classes.conf.", linenum);
633 }
634 else
635 {
636 /*
637 * Something else we don't understand...
638 */
639
640 cupsdLogMessage(CUPSD_LOG_ERROR,
641 "Unknown configuration directive %s on line %d of classes.conf.",
642 line, linenum);
643 }
644 }
645
646 cupsFileClose(fp);
647 }
648
649
650 /*
651 * 'cupsdSaveAllClasses()' - Save classes to the classes.conf file.
652 */
653
654 void
655 cupsdSaveAllClasses(void)
656 {
657 cups_file_t *fp; /* classes.conf file */
658 char temp[1024], /* Temporary string */
659 backup[1024], /* printers.conf.O file */
660 value[2048]; /* Value string */
661 cupsd_printer_t *pclass; /* Current printer class */
662 int i; /* Looping var */
663 time_t curtime; /* Current time */
664 struct tm *curdate; /* Current date */
665 cups_option_t *option; /* Current option */
666
667
668 /*
669 * Create the classes.conf file...
670 */
671
672 snprintf(temp, sizeof(temp), "%s/classes.conf", ServerRoot);
673 snprintf(backup, sizeof(backup), "%s/classes.conf.O", ServerRoot);
674
675 if (rename(temp, backup))
676 {
677 if (errno != ENOENT)
678 cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to backup classes.conf - %s",
679 strerror(errno));
680 }
681
682 if ((fp = cupsFileOpen(temp, "w")) == NULL)
683 {
684 cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to save classes.conf - %s",
685 strerror(errno));
686
687 if (rename(backup, temp))
688 cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to restore classes.conf - %s",
689 strerror(errno));
690 return;
691 }
692 else
693 cupsdLogMessage(CUPSD_LOG_INFO, "Saving classes.conf...");
694
695 /*
696 * Restrict access to the file...
697 */
698
699 fchown(cupsFileNumber(fp), RunUser, Group);
700 fchmod(cupsFileNumber(fp), 0600);
701
702 /*
703 * Write a small header to the file...
704 */
705
706 curtime = time(NULL);
707 curdate = localtime(&curtime);
708 strftime(temp, sizeof(temp) - 1, "%Y-%m-%d %H:%M", curdate);
709
710 cupsFilePuts(fp, "# Class configuration file for " CUPS_SVERSION "\n");
711 cupsFilePrintf(fp, "# Written by cupsd on %s\n", temp);
712
713 /*
714 * Write each local class known to the system...
715 */
716
717 for (pclass = (cupsd_printer_t *)cupsArrayFirst(Printers);
718 pclass;
719 pclass = (cupsd_printer_t *)cupsArrayNext(Printers))
720 {
721 /*
722 * Skip remote destinations and regular printers...
723 */
724
725 if ((pclass->type & CUPS_PRINTER_REMOTE) ||
726 (pclass->type & CUPS_PRINTER_IMPLICIT) ||
727 !(pclass->type & CUPS_PRINTER_CLASS))
728 continue;
729
730 /*
731 * Write printers as needed...
732 */
733
734 if (pclass == DefaultPrinter)
735 cupsFilePrintf(fp, "<DefaultClass %s>\n", pclass->name);
736 else
737 cupsFilePrintf(fp, "<Class %s>\n", pclass->name);
738
739 if (pclass->num_auth_info_required > 0)
740 {
741 switch (pclass->num_auth_info_required)
742 {
743 case 1 :
744 strlcpy(value, pclass->auth_info_required[0], sizeof(value));
745 break;
746
747 case 2 :
748 snprintf(value, sizeof(value), "%s,%s",
749 pclass->auth_info_required[0],
750 pclass->auth_info_required[1]);
751 break;
752
753 case 3 :
754 default :
755 snprintf(value, sizeof(value), "%s,%s,%s",
756 pclass->auth_info_required[0],
757 pclass->auth_info_required[1],
758 pclass->auth_info_required[2]);
759 break;
760 }
761
762 cupsFilePutConf(fp, "AuthInfoRequired", value);
763 }
764
765 if (pclass->info)
766 cupsFilePutConf(fp, "Info", pclass->info);
767
768 if (pclass->location)
769 cupsFilePutConf(fp, "Location", pclass->location);
770
771 if (pclass->state == IPP_PRINTER_STOPPED)
772 cupsFilePuts(fp, "State Stopped\n");
773 else
774 cupsFilePuts(fp, "State Idle\n");
775
776 cupsFilePrintf(fp, "StateTime %d\n", (int)pclass->state_time);
777
778 if (pclass->accepting)
779 cupsFilePuts(fp, "Accepting Yes\n");
780 else
781 cupsFilePuts(fp, "Accepting No\n");
782
783 if (pclass->shared)
784 cupsFilePuts(fp, "Shared Yes\n");
785 else
786 cupsFilePuts(fp, "Shared No\n");
787
788 snprintf(value, sizeof(value), "%s %s", pclass->job_sheets[0],
789 pclass->job_sheets[1]);
790 cupsFilePutConf(fp, "JobSheets", value);
791
792 cupsFilePrintf(fp, "QuotaPeriod %d\n", pclass->quota_period);
793 cupsFilePrintf(fp, "PageLimit %d\n", pclass->page_limit);
794 cupsFilePrintf(fp, "KLimit %d\n", pclass->k_limit);
795
796 for (i = 0; i < pclass->num_users; i ++)
797 cupsFilePutConf(fp, pclass->deny_users ? "DenyUser" : "AllowUser",
798 pclass->users[i]);
799
800 if (pclass->op_policy)
801 cupsFilePutConf(fp, "OpPolicy", pclass->op_policy);
802 if (pclass->error_policy)
803 cupsFilePutConf(fp, "ErrorPolicy", pclass->error_policy);
804
805 for (i = pclass->num_options, option = pclass->options;
806 i > 0;
807 i --, option ++)
808 {
809 snprintf(value, sizeof(value), "%s %s", option->name, option->value);
810 cupsFilePutConf(fp, "Option", value);
811 }
812
813 cupsFilePuts(fp, "</Class>\n");
814 }
815
816 cupsFileClose(fp);
817 }
818
819
820 /*
821 * 'cupsdUpdateImplicitClasses()' - Update the accepting state of implicit
822 * classes.
823 */
824
825 void
826 cupsdUpdateImplicitClasses(void)
827 {
828 int i; /* Looping var */
829 cupsd_printer_t *pclass; /* Current class */
830 int accepting; /* printer-is-accepting-jobs value */
831
832
833 for (pclass = (cupsd_printer_t *)cupsArrayFirst(ImplicitPrinters);
834 pclass;
835 pclass = (cupsd_printer_t *)cupsArrayNext(ImplicitPrinters))
836 {
837 /*
838 * Loop through the printers to come up with a composite state...
839 */
840
841 for (i = 0, accepting = 0; i < pclass->num_printers; i ++)
842 if ((accepting = pclass->printers[i]->accepting) != 0)
843 break;
844
845 pclass->accepting = accepting;
846 }
847 }
848
849
850 /*
851 * End of "$Id: classes.c 7724 2008-07-14 06:06:06Z mike $".
852 */