]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - scheduler/classes.c
Merge changes from CUPS 1.4svn-r7874.
[thirdparty/cups.git] / scheduler / classes.c
index 63a818bfd5dabc11c48881ff1b6e7aaada954370..da828ce7497638f8d632ee247f855d54f2648beb 100644 (file)
@@ -1,25 +1,16 @@
 /*
- * "$Id: classes.c 6318 2007-03-06 04:36:55Z mike $"
+ * "$Id: classes.c 7608 2008-05-21 01:37:21Z mike $"
  *
  *   Printer class routines for the Common UNIX Printing System (CUPS).
  *
+ *   Copyright 2007 by Apple Inc.
  *   Copyright 1997-2007 by Easy Software Products, all rights reserved.
  *
  *   These coded instructions, statements, and computer programs are the
- *   property of Easy Software Products and are protected by Federal
- *   copyright law.  Distribution and use rights are outlined in the file
- *   "LICENSE.txt" which should have been included with this file.  If this
- *   file is missing or damaged please contact Easy Software Products
- *   at:
- *
- *       Attn: CUPS Licensing Information
- *       Easy Software Products
- *       44141 Airport View Drive, Suite 204
- *       Hollywood, Maryland 20636 USA
- *
- *       Voice: (301) 373-9600
- *       EMail: cups-info@cups.org
- *         WWW: http://www.cups.org
+ *   property of Apple Inc. and are protected by Federal copyright
+ *   law.  Distribution and use rights are outlined in the file "LICENSE.txt"
+ *   which should have been included with this file.  If this file is
+ *   file is missing or damaged, see the license at "http://www.cups.org/".
  *
  * Contents:
  *
@@ -219,7 +210,8 @@ cupsdDeletePrinterFromClasses(
        c = (cupsd_printer_t *)cupsArrayNext(ImplicitPrinters))
     if (c->num_printers == 0)
     {
-      cupsArrayRemove(ImplicitPrinters, c);
+      cupsdLogMessage(CUPSD_LOG_DEBUG, "Deleting implicit class \"%s\"...",
+                      c->name);
       cupsdDeletePrinter(c, 0);
     }
 }
@@ -265,6 +257,17 @@ cupsdFindAvailablePrinter(
     return (NULL);
   }
 
+  if (c->num_printers == 0)
+    return (NULL);
+
+ /*
+  * Make sure that the last printer is also a valid index into the printer
+  * array.  If not, reset the last printer to 0...
+  */
+
+  if (c->last_printer >= c->num_printers)
+    c->last_printer = 0;
+
  /*
   * Loop through the printers in the class and return the first idle
   * printer...  We keep track of the last printer that we used so that
@@ -391,7 +394,7 @@ cupsdLoadAllClasses(void)
       {
         cupsdLogMessage(CUPSD_LOG_ERROR,
                        "Syntax error on line %d of classes.conf.", linenum);
-        return;
+        break;
       }
     }
     else if (!strcasecmp(line, "</Class>"))
@@ -405,14 +408,14 @@ cupsdLoadAllClasses(void)
       {
         cupsdLogMessage(CUPSD_LOG_ERROR,
                        "Syntax error on line %d of classes.conf.", linenum);
-        return;
+        break;
       }
     }
     else if (!p)
     {
       cupsdLogMessage(CUPSD_LOG_ERROR,
                       "Syntax error on line %d of classes.conf.", linenum);
-      return;
+      break;
     }
     else if (!strcasecmp(line, "AuthInfoRequired"))
     {
@@ -456,7 +459,7 @@ cupsdLoadAllClasses(void)
       {
        cupsdLogMessage(CUPSD_LOG_ERROR,
                        "Syntax error on line %d of classes.conf.", linenum);
-       return;
+       break;
       }
       else if ((temp = cupsdFindPrinter(value)) == NULL)
       {
@@ -502,7 +505,7 @@ cupsdLoadAllClasses(void)
        cupsdLogMessage(CUPSD_LOG_ERROR,
                        "Syntax error on line %d of classes.conf.",
                        linenum);
-       return;
+       break;
       }
     }
     else if (!strcasecmp(line, "StateMessage"))
@@ -544,7 +547,7 @@ cupsdLoadAllClasses(void)
        cupsdLogMessage(CUPSD_LOG_ERROR,
                        "Syntax error on line %d of classes.conf.",
                        linenum);
-       return;
+       break;
       }
     }
     else if (!strcasecmp(line, "Shared"))
@@ -566,9 +569,9 @@ cupsdLoadAllClasses(void)
       else
       {
        cupsdLogMessage(CUPSD_LOG_ERROR,
-                       "Syntax error on line %d of printers.conf.",
+                       "Syntax error on line %d of classes.conf.",
                        linenum);
-       return;
+       break;
       }
     }
     else if (!strcasecmp(line, "JobSheets"))
@@ -598,7 +601,7 @@ cupsdLoadAllClasses(void)
               valueptr ++);
 
          if (*valueptr)
-            *valueptr++ = '\0';
+            *valueptr = '\0';
 
          cupsdSetString(&p->job_sheets[1], value);
        }
@@ -607,7 +610,7 @@ cupsdLoadAllClasses(void)
       {
        cupsdLogMessage(CUPSD_LOG_ERROR,
                        "Syntax error on line %d of classes.conf.", linenum);
-       return;
+       break;
       }
     }
     else if (!strcasecmp(line, "AllowUser"))
@@ -621,7 +624,7 @@ cupsdLoadAllClasses(void)
       {
        cupsdLogMessage(CUPSD_LOG_ERROR,
                        "Syntax error on line %d of classes.conf.", linenum);
-       return;
+       break;
       }
     }
     else if (!strcasecmp(line, "DenyUser"))
@@ -635,7 +638,7 @@ cupsdLoadAllClasses(void)
       {
        cupsdLogMessage(CUPSD_LOG_ERROR,
                        "Syntax error on line %d of classes.conf.", linenum);
-       return;
+       break;
       }
     }
     else if (!strcasecmp(line, "QuotaPeriod"))
@@ -646,7 +649,7 @@ cupsdLoadAllClasses(void)
       {
        cupsdLogMessage(CUPSD_LOG_ERROR,
                        "Syntax error on line %d of classes.conf.", linenum);
-       return;
+       break;
       }
     }
     else if (!strcasecmp(line, "PageLimit"))
@@ -657,7 +660,7 @@ cupsdLoadAllClasses(void)
       {
        cupsdLogMessage(CUPSD_LOG_ERROR,
                        "Syntax error on line %d of classes.conf.", linenum);
-       return;
+       break;
       }
     }
     else if (!strcasecmp(line, "KLimit"))
@@ -668,18 +671,31 @@ cupsdLoadAllClasses(void)
       {
        cupsdLogMessage(CUPSD_LOG_ERROR,
                        "Syntax error on line %d of classes.conf.", linenum);
-       return;
+       break;
       }
     }
     else if (!strcasecmp(line, "OpPolicy"))
     {
       if (value)
-        cupsdSetString(&p->op_policy, value);
+      {
+        cupsd_policy_t *pol;           /* Policy */
+
+
+        if ((pol = cupsdFindPolicy(value)) != NULL)
+       {
+          cupsdSetString(&p->op_policy, value);
+         p->op_policy_ptr = pol;
+       }
+       else
+         cupsdLogMessage(CUPSD_LOG_ERROR,
+                         "Bad policy \"%s\" on line %d of classes.conf",
+                         value, linenum);
+      }
       else
       {
        cupsdLogMessage(CUPSD_LOG_ERROR,
                        "Syntax error on line %d of classes.conf.", linenum);
-       return;
+       break;
       }
     }
     else if (!strcasecmp(line, "ErrorPolicy"))
@@ -690,7 +706,7 @@ cupsdLoadAllClasses(void)
       {
        cupsdLogMessage(CUPSD_LOG_ERROR,
                        "Syntax error on line %d of classes.conf.", linenum);
-       return;
+       break;
       }
     }
     else
@@ -865,8 +881,25 @@ cupsdSaveAllClasses(void)
     cupsFilePrintf(fp, "JobSheets %s %s\n", pclass->job_sheets[0],
                    pclass->job_sheets[1]);
 
-    for (i = 0; i < pclass->num_printers; i ++)
-      cupsFilePrintf(fp, "Printer %s\n", pclass->printers[i]->name);
+    for (i = 0; i < pclass->num_users; i ++)
+    {
+      if ((ptr = strchr(pclass->users[i], '#')) != NULL)
+      {
+       /*
+        * Need to quote the first # in the user string...
+       */
+
+        cupsFilePrintf(fp, "%sUser ", pclass->deny_users ? "Deny" : "Allow");
+       cupsFileWrite(fp, pclass->users[i], ptr - pclass->users[i]);
+       cupsFilePutChar(fp, '\\');
+       cupsFilePuts(fp, ptr);
+       cupsFilePutChar(fp, '\n');
+      }
+      else
+        cupsFilePrintf(fp, "%sUser %s\n",
+                      pclass->deny_users ? "Deny" : "Allow",
+                       pclass->users[i]);
+    }
 
     cupsFilePrintf(fp, "QuotaPeriod %d\n", pclass->quota_period);
     cupsFilePrintf(fp, "PageLimit %d\n", pclass->page_limit);
@@ -924,5 +957,5 @@ cupsdUpdateImplicitClasses(void)
 
 
 /*
- * End of "$Id: classes.c 6318 2007-03-06 04:36:55Z mike $".
+ * End of "$Id: classes.c 7608 2008-05-21 01:37:21Z mike $".
  */