bbd5538
diff -up cups-1.4rc1/cups/dest.c.cups-get-classes cups-1.4rc1/cups/dest.c
bbd5538
--- cups-1.4rc1/cups/dest.c.cups-get-classes	2009-05-13 22:39:17.000000000 +0100
bbd5538
+++ cups-1.4rc1/cups/dest.c	2009-07-28 22:17:40.285709944 +0100
bbd5538
@@ -1735,6 +1735,7 @@ cups_get_sdests(http_t      *http,	/* I 
bbd5538
   char		uri[1024];		/* printer-uri value */
bbd5538
   int		num_options;		/* Number of options */
bbd5538
   cups_option_t	*options;		/* Options */
bbd5538
+  int		get_classes;		/* Whether we need to fetch class */
bbd5538
 #ifdef __APPLE__
bbd5538
   char		media_default[41];	/* Default paper size */
bbd5538
 #endif /* __APPLE__ */
bbd5538
@@ -1791,6 +1792,8 @@ cups_get_sdests(http_t      *http,	/* I 
bbd5538
   *    printer-uri [for IPP_GET_PRINTER_ATTRIBUTES]
bbd5538
   */
bbd5538
 
bbd5538
+  get_classes = (op == CUPS_GET_PRINTERS);
bbd5538
+
bbd5538
   request = ippNewRequest(op);
bbd5538
 
bbd5538
   ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD,
bbd5538
@@ -1848,6 +1851,23 @@ cups_get_sdests(http_t      *http,	/* I 
bbd5538
 	    attr->value_tag != IPP_TAG_URI)
bbd5538
           continue;
bbd5538
 
bbd5538
+	if (get_classes &&
bbd5538
+
bbd5538
+	    /* Is this a class? */
bbd5538
+	    ((attr->value_tag == IPP_TAG_ENUM &&
bbd5538
+	      !strcmp(attr->name, "printer-type") &&
bbd5538
+	      (attr->values[0].integer & CUPS_PRINTER_CLASS)) ||
bbd5538
+
bbd5538
+	     /* Or, is this an attribute from CUPS 1.2 or later? */
bbd5538
+	     !strcmp(attr->name, "auth-info-required") ||
bbd5538
+	     !strncmp(attr->name, "marker-", 7) ||
bbd5538
+	     !strcmp(attr->name, "printer-commands") ||
bbd5538
+	     !strcmp(attr->name, "printer-is-shared")))
bbd5538
+	 /* We are talking to a recent enough CUPS server that
bbd5538
+	  * CUPS_GET_PRINTERS returns classes as well.
bbd5538
+	  */
bbd5538
+	  get_classes = 0;
bbd5538
+
bbd5538
         if (!strcmp(attr->name, "auth-info-required") ||
bbd5538
 	    !strcmp(attr->name, "device-uri") ||
bbd5538
 	    !strcmp(attr->name, "marker-change-time") ||
bbd5538
@@ -1939,6 +1959,28 @@ cups_get_sdests(http_t      *http,	/* I 
bbd5538
           continue;
bbd5538
       }
bbd5538
 
bbd5538
+     /*
bbd5538
+      * If we sent a CUPS_GET_CLASSES request, check whether
bbd5538
+      * CUPS_GET_PRINTERS already gave us this destination and exit
bbd5538
+      * early if so.
bbd5538
+      */
bbd5538
+
bbd5538
+      if (op == CUPS_GET_CLASSES)
bbd5538
+      {
bbd5538
+	int diff;
bbd5538
+	cups_find_dest (printer_name, NULL, num_dests, *dests, 0, &diff);
bbd5538
+	if (diff == 0)
bbd5538
+	{
bbd5538
+         /*
bbd5538
+	  * Found it.  The CUPS server already gave us the classes in
bbd5538
+	  * its CUPS_GET_PRINTERS response.
bbd5538
+	  */
bbd5538
+
bbd5538
+	  cupsFreeOptions(num_options, options);
bbd5538
+	  break;
bbd5538
+	}
bbd5538
+      }
bbd5538
+
bbd5538
       if ((dest = cups_add_dest(printer_name, NULL, &num_dests, dests)) != NULL)
bbd5538
       {
bbd5538
         dest->num_options = num_options;
bbd5538
@@ -1955,6 +1997,16 @@ cups_get_sdests(http_t      *http,	/* I 
bbd5538
   }
bbd5538
 
bbd5538
  /*
bbd5538
+  * If this is a CUPS_GET_PRINTERS request but we didn't see any
bbd5538
+  * classes we might be talking to an older CUPS server that requires
bbd5538
+  * CUPS_GET_CLASSES as well.
bbd5538
+  */
bbd5538
+
bbd5538
+  if (get_classes)
bbd5538
+    num_dests = cups_get_sdests (http, CUPS_GET_CLASSES, name,
bbd5538
+				 num_dests, dests);
bbd5538
+
bbd5538
+ /*
bbd5538
   * Return the count...
bbd5538
   */
bbd5538