]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - scheduler/classes.c
Load cups into easysw/current.
[thirdparty/cups.git] / scheduler / classes.c
index 749a1bda01bdefd08c21d1df86791b7ef3878bdb..5b06ff7394e895ea384be9c047bc36bd553e9cfc 100644 (file)
@@ -1,25 +1,16 @@
 /*
- * "$Id: classes.c 5151 2006-02-22 22:43:17Z mike $"
+ * "$Id: classes.c 6649 2007-07-11 21:46:42Z mike $"
  *
  *   Printer class routines for the Common UNIX Printing System (CUPS).
  *
- *   Copyright 1997-2006 by Easy Software Products, all rights reserved.
+ *   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:
  *
@@ -265,6 +256,14 @@ cupsdFindAvailablePrinter(
     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
@@ -366,7 +365,21 @@ cupsdLoadAllClasses(void)
       {
         cupsdLogMessage(CUPSD_LOG_DEBUG, "Loading class %s...", value);
 
-        p = cupsdAddClass(value);
+       /*
+        * Since prior classes may have implicitly defined this class,
+       * see if it already exists...
+       */
+
+        if ((p = cupsdFindDest(value)) != NULL)
+       {
+         p->type = CUPS_PRINTER_CLASS;
+         cupsdSetStringf(&p->uri, "ipp://%s:%d/classes/%s", ServerName,
+                         LocalPort, value);
+         cupsdSetString(&p->error_policy, "retry-job");
+       }
+       else
+          p = cupsdAddClass(value);
+
        p->accepting = 1;
        p->state     = IPP_PRINTER_IDLE;
 
@@ -400,6 +413,13 @@ cupsdLoadAllClasses(void)
                       "Syntax error on line %d of classes.conf.", linenum);
       return;
     }
+    else if (!strcasecmp(line, "AuthInfoRequired"))
+    {
+      if (!cupsdSetAuthInfoRequired(p, value, NULL))
+       cupsdLogMessage(CUPSD_LOG_ERROR,
+                       "Bad AuthInfoRequired on line %d of classes.conf.",
+                       linenum);
+    }
     else if (!strcasecmp(line, "Info"))
     {
       if (value)
@@ -653,7 +673,20 @@ cupsdLoadAllClasses(void)
     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,
@@ -703,6 +736,7 @@ cupsdSaveAllClasses(void)
   time_t               curtime;        /* Current time */
   struct tm            *curdate;       /* Current date */
   cups_option_t                *option;        /* Current option */
+  const char           *ptr;           /* Pointer into info/location */
 
 
  /*
@@ -776,11 +810,49 @@ cupsdSaveAllClasses(void)
     else
       cupsFilePrintf(fp, "<Class %s>\n", pclass->name);
 
+    if (pclass->num_auth_info_required > 0)
+    {
+      cupsFilePrintf(fp, "AuthInfoRequired %s", pclass->auth_info_required[0]);
+      for (i = 1; i < pclass->num_auth_info_required; i ++)
+        cupsFilePrintf(fp, ",%s", pclass->auth_info_required[i]);
+      cupsFilePutChar(fp, '\n');
+    }
+
     if (pclass->info)
-      cupsFilePrintf(fp, "Info %s\n", pclass->info);
+    {
+      if ((ptr = strchr(pclass->info, '#')) != NULL)
+      {
+       /*
+        * Need to quote the first # in the info string...
+       */
+
+        cupsFilePuts(fp, "Info ");
+       cupsFileWrite(fp, pclass->info, ptr - pclass->info);
+       cupsFilePutChar(fp, '\\');
+       cupsFilePuts(fp, ptr);
+       cupsFilePutChar(fp, '\n');
+      }
+      else
+        cupsFilePrintf(fp, "Info %s\n", pclass->info);
+    }
 
     if (pclass->location)
-      cupsFilePrintf(fp, "Location %s\n", pclass->location);
+    {
+      if ((ptr = strchr(pclass->info, '#')) != NULL)
+      {
+       /*
+        * Need to quote the first # in the location string...
+       */
+
+        cupsFilePuts(fp, "Location ");
+       cupsFileWrite(fp, pclass->location, ptr - pclass->location);
+       cupsFilePutChar(fp, '\\');
+       cupsFilePuts(fp, ptr);
+       cupsFilePutChar(fp, '\n');
+      }
+      else
+        cupsFilePrintf(fp, "Location %s\n", pclass->location);
+    }
 
     if (pclass->state == IPP_PRINTER_STOPPED)
     {
@@ -864,5 +936,5 @@ cupsdUpdateImplicitClasses(void)
 
 
 /*
- * End of "$Id: classes.c 5151 2006-02-22 22:43:17Z mike $".
+ * End of "$Id: classes.c 6649 2007-07-11 21:46:42Z mike $".
  */