]> git.ipfire.org Git - thirdparty/cups.git/blob - scheduler/classes.c
Merge changes from CUPS 1.4svn-r8659
[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, RemotePort,
59 name);
60 cupsdSetString(&c->error_policy, "retry-current-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 int i; /* Looping var */
289 cups_file_t *fp; /* classes.conf file */
290 int linenum; /* Current line number */
291 char line[4096], /* Line from file */
292 *value, /* Pointer to value */
293 *valueptr; /* Pointer into value */
294 cupsd_printer_t *p, /* Current printer class */
295 *temp; /* Temporary pointer to printer */
296
297
298 /*
299 * Open the classes.conf file...
300 */
301
302 snprintf(line, sizeof(line), "%s/classes.conf", ServerRoot);
303 if ((fp = cupsFileOpen(line, "r")) == NULL)
304 {
305 if (errno != ENOENT)
306 cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to open %s - %s", line,
307 strerror(errno));
308 return;
309 }
310
311 /*
312 * Read class configurations until we hit EOF...
313 */
314
315 linenum = 0;
316 p = NULL;
317
318 while (cupsFileGetConf(fp, line, sizeof(line), &value, &linenum))
319 {
320 /*
321 * Decode the directive...
322 */
323
324 if (!strcasecmp(line, "<Class") ||
325 !strcasecmp(line, "<DefaultClass"))
326 {
327 /*
328 * <Class name> or <DefaultClass name>
329 */
330
331 if (p == NULL && value)
332 {
333 cupsdLogMessage(CUPSD_LOG_DEBUG, "Loading class %s...", value);
334
335 /*
336 * Since prior classes may have implicitly defined this class,
337 * see if it already exists...
338 */
339
340 if ((p = cupsdFindDest(value)) != NULL)
341 {
342 p->type = CUPS_PRINTER_CLASS;
343 cupsdSetStringf(&p->uri, "ipp://%s:%d/classes/%s", ServerName,
344 LocalPort, value);
345 cupsdSetString(&p->error_policy, "retry-job");
346 }
347 else
348 p = cupsdAddClass(value);
349
350 p->accepting = 1;
351 p->state = IPP_PRINTER_IDLE;
352
353 if (!strcasecmp(line, "<DefaultClass"))
354 DefaultPrinter = p;
355 }
356 else
357 cupsdLogMessage(CUPSD_LOG_ERROR,
358 "Syntax error on line %d of classes.conf.", linenum);
359 }
360 else if (!strcasecmp(line, "</Class>"))
361 {
362 if (p != NULL)
363 {
364 cupsdSetPrinterAttrs(p);
365 p = NULL;
366 }
367 else
368 cupsdLogMessage(CUPSD_LOG_ERROR,
369 "Syntax error on line %d of classes.conf.", linenum);
370 }
371 else if (!p)
372 {
373 cupsdLogMessage(CUPSD_LOG_ERROR,
374 "Syntax error on line %d of classes.conf.", linenum);
375 }
376 else if (!strcasecmp(line, "AuthInfoRequired"))
377 {
378 if (!cupsdSetAuthInfoRequired(p, value, NULL))
379 cupsdLogMessage(CUPSD_LOG_ERROR,
380 "Bad AuthInfoRequired on line %d of classes.conf.",
381 linenum);
382 }
383 else if (!strcasecmp(line, "Info"))
384 {
385 if (value)
386 cupsdSetString(&p->info, value);
387 }
388 else if (!strcasecmp(line, "Location"))
389 {
390 if (value)
391 cupsdSetString(&p->location, value);
392 }
393 else if (!strcasecmp(line, "Option") && value)
394 {
395 /*
396 * Option name value
397 */
398
399 for (valueptr = value; *valueptr && !isspace(*valueptr & 255); valueptr ++);
400
401 if (!*valueptr)
402 cupsdLogMessage(CUPSD_LOG_ERROR,
403 "Syntax error on line %d of classes.conf.", linenum);
404 else
405 {
406 for (; *valueptr && isspace(*valueptr & 255); *valueptr++ = '\0');
407
408 p->num_options = cupsAddOption(value, valueptr, p->num_options,
409 &(p->options));
410 }
411 }
412 else if (!strcasecmp(line, "Printer"))
413 {
414 if (!value)
415 {
416 cupsdLogMessage(CUPSD_LOG_ERROR,
417 "Syntax error on line %d of classes.conf.", linenum);
418 continue;
419 }
420 else if ((temp = cupsdFindPrinter(value)) == NULL)
421 {
422 cupsdLogMessage(CUPSD_LOG_WARN,
423 "Unknown printer %s on line %d of classes.conf.",
424 value, linenum);
425
426 /*
427 * Add the missing remote printer...
428 */
429
430 if ((temp = cupsdAddPrinter(value)) != NULL)
431 {
432 cupsdSetString(&temp->make_model, "Remote Printer on unknown");
433
434 temp->state = IPP_PRINTER_STOPPED;
435 temp->type |= CUPS_PRINTER_REMOTE;
436 temp->browse_time = 2147483647;
437
438 cupsdSetString(&temp->location, "Location Unknown");
439 cupsdSetString(&temp->info, "No Information Available");
440 temp->hostname[0] = '\0';
441
442 cupsdSetPrinterAttrs(temp);
443 }
444 }
445
446 if (temp)
447 cupsdAddPrinterToClass(p, temp);
448 }
449 else if (!strcasecmp(line, "State"))
450 {
451 /*
452 * Set the initial queue state...
453 */
454
455 if (!strcasecmp(value, "idle"))
456 p->state = IPP_PRINTER_IDLE;
457 else if (!strcasecmp(value, "stopped"))
458 {
459 p->state = IPP_PRINTER_STOPPED;
460
461 for (i = 0 ; i < p->num_reasons; i ++)
462 if (!strcmp("paused", p->reasons[i]))
463 break;
464
465 if (i >= p->num_reasons &&
466 p->num_reasons < (int)(sizeof(p->reasons) / sizeof(p->reasons[0])))
467 {
468 p->reasons[p->num_reasons] = _cupsStrAlloc("paused");
469 p->num_reasons ++;
470 }
471 }
472 else
473 cupsdLogMessage(CUPSD_LOG_ERROR,
474 "Syntax error on line %d of classes.conf.",
475 linenum);
476 }
477 else if (!strcasecmp(line, "StateMessage"))
478 {
479 /*
480 * Set the initial queue state message...
481 */
482
483 if (value)
484 strlcpy(p->state_message, value, sizeof(p->state_message));
485 }
486 else if (!strcasecmp(line, "StateTime"))
487 {
488 /*
489 * Set the state time...
490 */
491
492 if (value)
493 p->state_time = atoi(value);
494 }
495 else if (!strcasecmp(line, "Accepting"))
496 {
497 /*
498 * Set the initial accepting state...
499 */
500
501 if (value &&
502 (!strcasecmp(value, "yes") ||
503 !strcasecmp(value, "on") ||
504 !strcasecmp(value, "true")))
505 p->accepting = 1;
506 else if (value &&
507 (!strcasecmp(value, "no") ||
508 !strcasecmp(value, "off") ||
509 !strcasecmp(value, "false")))
510 p->accepting = 0;
511 else
512 cupsdLogMessage(CUPSD_LOG_ERROR,
513 "Syntax error on line %d of classes.conf.",
514 linenum);
515 }
516 else if (!strcasecmp(line, "Shared"))
517 {
518 /*
519 * Set the initial shared state...
520 */
521
522 if (value &&
523 (!strcasecmp(value, "yes") ||
524 !strcasecmp(value, "on") ||
525 !strcasecmp(value, "true")))
526 p->shared = 1;
527 else if (value &&
528 (!strcasecmp(value, "no") ||
529 !strcasecmp(value, "off") ||
530 !strcasecmp(value, "false")))
531 p->shared = 0;
532 else
533 cupsdLogMessage(CUPSD_LOG_ERROR,
534 "Syntax error on line %d of classes.conf.",
535 linenum);
536 }
537 else if (!strcasecmp(line, "JobSheets"))
538 {
539 /*
540 * Set the initial job sheets...
541 */
542
543 if (value)
544 {
545 for (valueptr = value;
546 *valueptr && !isspace(*valueptr & 255);
547 valueptr ++);
548
549 if (*valueptr)
550 *valueptr++ = '\0';
551
552 cupsdSetString(&p->job_sheets[0], value);
553
554 while (isspace(*valueptr & 255))
555 valueptr ++;
556
557 if (*valueptr)
558 {
559 for (value = valueptr;
560 *valueptr && !isspace(*valueptr & 255);
561 valueptr ++);
562
563 if (*valueptr)
564 *valueptr = '\0';
565
566 cupsdSetString(&p->job_sheets[1], value);
567 }
568 }
569 else
570 cupsdLogMessage(CUPSD_LOG_ERROR,
571 "Syntax error on line %d of classes.conf.", linenum);
572 }
573 else if (!strcasecmp(line, "AllowUser"))
574 {
575 if (value)
576 {
577 p->deny_users = 0;
578 cupsdAddPrinterUser(p, value);
579 }
580 else
581 cupsdLogMessage(CUPSD_LOG_ERROR,
582 "Syntax error on line %d of classes.conf.", linenum);
583 }
584 else if (!strcasecmp(line, "DenyUser"))
585 {
586 if (value)
587 {
588 p->deny_users = 1;
589 cupsdAddPrinterUser(p, value);
590 }
591 else
592 cupsdLogMessage(CUPSD_LOG_ERROR,
593 "Syntax error on line %d of classes.conf.", linenum);
594 }
595 else if (!strcasecmp(line, "QuotaPeriod"))
596 {
597 if (value)
598 p->quota_period = atoi(value);
599 else
600 cupsdLogMessage(CUPSD_LOG_ERROR,
601 "Syntax error on line %d of classes.conf.", linenum);
602 }
603 else if (!strcasecmp(line, "PageLimit"))
604 {
605 if (value)
606 p->page_limit = atoi(value);
607 else
608 cupsdLogMessage(CUPSD_LOG_ERROR,
609 "Syntax error on line %d of classes.conf.", linenum);
610 }
611 else if (!strcasecmp(line, "KLimit"))
612 {
613 if (value)
614 p->k_limit = atoi(value);
615 else
616 cupsdLogMessage(CUPSD_LOG_ERROR,
617 "Syntax error on line %d of classes.conf.", linenum);
618 }
619 else if (!strcasecmp(line, "OpPolicy"))
620 {
621 if (value)
622 {
623 cupsd_policy_t *pol; /* Policy */
624
625
626 if ((pol = cupsdFindPolicy(value)) != NULL)
627 {
628 cupsdSetString(&p->op_policy, value);
629 p->op_policy_ptr = pol;
630 }
631 else
632 cupsdLogMessage(CUPSD_LOG_ERROR,
633 "Bad policy \"%s\" on line %d of classes.conf",
634 value, linenum);
635 }
636 else
637 cupsdLogMessage(CUPSD_LOG_ERROR,
638 "Syntax error on line %d of classes.conf.", linenum);
639 }
640 else if (!strcasecmp(line, "ErrorPolicy"))
641 {
642 if (value)
643 {
644 if (strcmp(value, "retry-current-job") && strcmp(value, "retry-job"))
645 cupsdLogMessage(CUPSD_LOG_WARN,
646 "ErrorPolicy %s ignored on line %d of classes.conf",
647 value, linenum);
648 }
649 else
650 cupsdLogMessage(CUPSD_LOG_ERROR,
651 "Syntax error on line %d of classes.conf.", linenum);
652 }
653 else
654 {
655 /*
656 * Something else we don't understand...
657 */
658
659 cupsdLogMessage(CUPSD_LOG_ERROR,
660 "Unknown configuration directive %s on line %d of classes.conf.",
661 line, linenum);
662 }
663 }
664
665 cupsFileClose(fp);
666 }
667
668
669 /*
670 * 'cupsdSaveAllClasses()' - Save classes to the classes.conf file.
671 */
672
673 void
674 cupsdSaveAllClasses(void)
675 {
676 cups_file_t *fp; /* classes.conf file */
677 char temp[1024], /* Temporary string */
678 backup[1024], /* printers.conf.O file */
679 value[2048]; /* Value string */
680 cupsd_printer_t *pclass; /* Current printer class */
681 int i; /* Looping var */
682 time_t curtime; /* Current time */
683 struct tm *curdate; /* Current date */
684 cups_option_t *option; /* Current option */
685
686
687 /*
688 * Create the classes.conf file...
689 */
690
691 snprintf(temp, sizeof(temp), "%s/classes.conf", ServerRoot);
692 snprintf(backup, sizeof(backup), "%s/classes.conf.O", ServerRoot);
693
694 if (rename(temp, backup))
695 {
696 if (errno != ENOENT)
697 cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to backup classes.conf - %s",
698 strerror(errno));
699 }
700
701 if ((fp = cupsFileOpen(temp, "w")) == NULL)
702 {
703 cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to save classes.conf - %s",
704 strerror(errno));
705
706 if (rename(backup, temp))
707 cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to restore classes.conf - %s",
708 strerror(errno));
709 return;
710 }
711 else
712 cupsdLogMessage(CUPSD_LOG_INFO, "Saving classes.conf...");
713
714 /*
715 * Restrict access to the file...
716 */
717
718 fchown(cupsFileNumber(fp), RunUser, Group);
719 fchmod(cupsFileNumber(fp), 0600);
720
721 /*
722 * Write a small header to the file...
723 */
724
725 curtime = time(NULL);
726 curdate = localtime(&curtime);
727 strftime(temp, sizeof(temp) - 1, "%Y-%m-%d %H:%M", curdate);
728
729 cupsFilePuts(fp, "# Class configuration file for " CUPS_SVERSION "\n");
730 cupsFilePrintf(fp, "# Written by cupsd on %s\n", temp);
731
732 /*
733 * Write each local class known to the system...
734 */
735
736 for (pclass = (cupsd_printer_t *)cupsArrayFirst(Printers);
737 pclass;
738 pclass = (cupsd_printer_t *)cupsArrayNext(Printers))
739 {
740 /*
741 * Skip remote destinations and regular printers...
742 */
743
744 if ((pclass->type & CUPS_PRINTER_REMOTE) ||
745 (pclass->type & CUPS_PRINTER_IMPLICIT) ||
746 !(pclass->type & CUPS_PRINTER_CLASS))
747 continue;
748
749 /*
750 * Write printers as needed...
751 */
752
753 if (pclass == DefaultPrinter)
754 cupsFilePrintf(fp, "<DefaultClass %s>\n", pclass->name);
755 else
756 cupsFilePrintf(fp, "<Class %s>\n", pclass->name);
757
758 if (pclass->num_auth_info_required > 0)
759 {
760 switch (pclass->num_auth_info_required)
761 {
762 case 1 :
763 strlcpy(value, pclass->auth_info_required[0], sizeof(value));
764 break;
765
766 case 2 :
767 snprintf(value, sizeof(value), "%s,%s",
768 pclass->auth_info_required[0],
769 pclass->auth_info_required[1]);
770 break;
771
772 case 3 :
773 default :
774 snprintf(value, sizeof(value), "%s,%s,%s",
775 pclass->auth_info_required[0],
776 pclass->auth_info_required[1],
777 pclass->auth_info_required[2]);
778 break;
779 }
780
781 cupsFilePutConf(fp, "AuthInfoRequired", value);
782 }
783
784 if (pclass->info)
785 cupsFilePutConf(fp, "Info", pclass->info);
786
787 if (pclass->location)
788 cupsFilePutConf(fp, "Location", pclass->location);
789
790 if (pclass->state == IPP_PRINTER_STOPPED)
791 cupsFilePuts(fp, "State Stopped\n");
792 else
793 cupsFilePuts(fp, "State Idle\n");
794
795 cupsFilePrintf(fp, "StateTime %d\n", (int)pclass->state_time);
796
797 if (pclass->accepting)
798 cupsFilePuts(fp, "Accepting Yes\n");
799 else
800 cupsFilePuts(fp, "Accepting No\n");
801
802 if (pclass->shared)
803 cupsFilePuts(fp, "Shared Yes\n");
804 else
805 cupsFilePuts(fp, "Shared No\n");
806
807 snprintf(value, sizeof(value), "%s %s", pclass->job_sheets[0],
808 pclass->job_sheets[1]);
809 cupsFilePutConf(fp, "JobSheets", value);
810
811 for (i = 0; i < pclass->num_printers; i ++)
812 cupsFilePrintf(fp, "Printer %s\n", pclass->printers[i]->name);
813
814 cupsFilePrintf(fp, "QuotaPeriod %d\n", pclass->quota_period);
815 cupsFilePrintf(fp, "PageLimit %d\n", pclass->page_limit);
816 cupsFilePrintf(fp, "KLimit %d\n", pclass->k_limit);
817
818 for (i = 0; i < pclass->num_users; i ++)
819 cupsFilePutConf(fp, pclass->deny_users ? "DenyUser" : "AllowUser",
820 pclass->users[i]);
821
822 if (pclass->op_policy)
823 cupsFilePutConf(fp, "OpPolicy", pclass->op_policy);
824 if (pclass->error_policy)
825 cupsFilePutConf(fp, "ErrorPolicy", pclass->error_policy);
826
827 for (i = pclass->num_options, option = pclass->options;
828 i > 0;
829 i --, option ++)
830 {
831 snprintf(value, sizeof(value), "%s %s", option->name, option->value);
832 cupsFilePutConf(fp, "Option", value);
833 }
834
835 cupsFilePuts(fp, "</Class>\n");
836 }
837
838 cupsFileClose(fp);
839 }
840
841
842 /*
843 * 'cupsdUpdateImplicitClasses()' - Update the accepting state of implicit
844 * classes.
845 */
846
847 void
848 cupsdUpdateImplicitClasses(void)
849 {
850 int i; /* Looping var */
851 cupsd_printer_t *pclass; /* Current class */
852 int accepting; /* printer-is-accepting-jobs value */
853
854
855 for (pclass = (cupsd_printer_t *)cupsArrayFirst(ImplicitPrinters);
856 pclass;
857 pclass = (cupsd_printer_t *)cupsArrayNext(ImplicitPrinters))
858 {
859 /*
860 * Loop through the printers to come up with a composite state...
861 */
862
863 for (i = 0, accepting = 0; i < pclass->num_printers; i ++)
864 if ((accepting = pclass->printers[i]->accepting) != 0)
865 break;
866
867 pclass->accepting = accepting;
868 }
869 }
870
871
872 /*
873 * End of "$Id: classes.c 7724 2008-07-14 06:06:06Z mike $".
874 */