]> git.ipfire.org Git - thirdparty/cups.git/commitdiff
Add remaining printer-type bits, location (note), and info (name), and update
authormike <mike@7a7537e8-13f0-0310-91df-b6672ffda945>
Wed, 16 May 2012 22:33:31 +0000 (22:33 +0000)
committermike <mike@7a7537e8-13f0-0310-91df-b6672ffda945>
Wed, 16 May 2012 22:33:31 +0000 (22:33 +0000)
the test program to support filtering (STR #3066)

git-svn-id: svn+ssh://src.apple.com/svn/cups/cups.org/trunk@10470 7a7537e8-13f0-0310-91df-b6672ffda945

cups/dest.c
cups/testcups.c

index 3a8ba635d605ce83bab1025009ab002a289272a9..e53c1495de3747fe454d8c5f6f1b9d7ad8cfec5b 100644 (file)
@@ -139,6 +139,7 @@ typedef enum _cups_dnssd_state_e    /* Enumerated device state */
   _CUPS_DNSSD_PENDING,
   _CUPS_DNSSD_ACTIVE,
   _CUPS_DNSSD_LOCAL,
+  _CUPS_DNSSD_INCOMPATIBLE,
   _CUPS_DNSSD_ERROR
 } _cups_dnssd_state_t;
 
@@ -964,25 +965,25 @@ cupsEnumDests(
 
   ipp_ref = data.main_ref;
   DNSServiceBrowse(&ipp_ref, kDNSServiceFlagsShareConnection, 0,
-                   "_ipp._tcp,_cups", NULL,
+                   "_ipp._tcp", NULL,
                    (DNSServiceBrowseReply)cups_dnssd_browse_cb, &data);
 
   local_ipp_ref = data.main_ref;
   DNSServiceBrowse(&local_ipp_ref, kDNSServiceFlagsShareConnection,
                    kDNSServiceInterfaceIndexLocalOnly,
-                   "_ipp._tcp,_cups", NULL,
+                   "_ipp._tcp", NULL,
                    (DNSServiceBrowseReply)cups_dnssd_local_cb, &data);
 
 #    ifdef HAVE_SSL
   ipps_ref = data.main_ref;
   DNSServiceBrowse(&ipps_ref, kDNSServiceFlagsShareConnection, 0,
-                   "_ipps._tcp,_cups", NULL,
+                   "_ipps._tcp", NULL,
                    (DNSServiceBrowseReply)cups_dnssd_browse_cb, &data);
 
   local_ipps_ref = data.main_ref;
   DNSServiceBrowse(&local_ipps_ref, kDNSServiceFlagsShareConnection,
                    kDNSServiceInterfaceIndexLocalOnly,
-                   "_ipps._tcp,_cups", NULL,
+                   "_ipps._tcp", NULL,
                    (DNSServiceBrowseReply)cups_dnssd_local_cb, &data);
 #    endif /* HAVE_SSL */
 
@@ -1122,11 +1123,14 @@ cupsEnumDests(
       }
       else if (device->ref && device->state == _CUPS_DNSSD_PENDING)
       {
-       if (!(*cb)(user_data, CUPS_DEST_FLAGS_NONE, &device->dest))
-       {
-         remaining = -1;
-         break;
-       }
+        if ((device->type & mask) == type)
+        {
+         if (!(*cb)(user_data, CUPS_DEST_FLAGS_NONE, &device->dest))
+         {
+           remaining = -1;
+           break;
+         }
+        }
 
         device->state = _CUPS_DNSSD_ACTIVE;
       }
@@ -3134,6 +3138,10 @@ cups_dnssd_query_cb(
                        model[256],     /* Model */
                        uriname[1024],  /* Name for URI */
                        uri[1024];      /* Printer URI */
+    cups_ptype_t       type = CUPS_PRINTER_REMOTE | CUPS_PRINTER_BW;
+                                       /* Printer type */
+    int                        saw_printer_type = 0;
+                                       /* Did we see a printer-type key? */
 
     device->state     = _CUPS_DNSSD_PENDING;
     make_and_model[0] = '\0';
@@ -3207,18 +3215,102 @@ cups_dnssd_query_cb(
        if ((ptr = strchr(model, ',')) != NULL)
          *ptr = '\0';
       }
+      else if (!_cups_strcasecmp(key, "note"))
+        device->dest.num_options = cupsAddOption("printer-location", value,
+                                                device->dest.num_options,
+                                                &device->dest.options);
+      else if (!_cups_strcasecmp(key, "pdl"))
+      {
+       /*
+        * Look for PDF-capable printers; only PDF-capable printers are shown.
+        */
+
+        const char     *start, *next;  /* Pointer into value */
+        int            have_pdf = 0;   /* Have PDF? */
+
+        for (start = value; start && *start; start = next)
+        {
+          if (!_cups_strncasecmp(start, "application/pdf", 15) &&
+              (!start[15] || start[15] == ','))
+          {
+            have_pdf = 1;
+            break;
+          }
+
+          if ((next = strchr(start, ',')) != NULL)
+            next ++;
+        }
+
+        if (!have_pdf)
+          device->state = _CUPS_DNSSD_INCOMPATIBLE;
+      }
       else if (!_cups_strcasecmp(key, "printer-type"))
       {
-        device->dest.num_options = cupsAddOption("printer-type", value,
-                                                 device->dest.num_options,
-                                                 &device->dest.options);
+       /*
+        * Value is either NNNN or 0xXXXX
+        */
+
+       saw_printer_type = 1;
+        type             = strtol(value, NULL, 0);
+      }
+      else if (!saw_printer_type)
+      {
+       if (!_cups_strcasecmp(key, "air") &&
+                !_cups_strcasecmp(value, "t"))
+         type |= CUPS_PRINTER_AUTHENTICATED;
+       else if (!_cups_strcasecmp(key, "bind") &&
+                !_cups_strcasecmp(value, "t"))
+         type |= CUPS_PRINTER_BIND;
+       else if (!_cups_strcasecmp(key, "collate") &&
+                !_cups_strcasecmp(value, "t"))
+         type |= CUPS_PRINTER_COLLATE;
+       else if (!_cups_strcasecmp(key, "color") &&
+                !_cups_strcasecmp(value, "t"))
+         type |= CUPS_PRINTER_COLOR;
+       else if (!_cups_strcasecmp(key, "copies") &&
+                !_cups_strcasecmp(value, "t"))
+         type |= CUPS_PRINTER_COPIES;
+       else if (!_cups_strcasecmp(key, "duplex") &&
+                !_cups_strcasecmp(value, "t"))
+         type |= CUPS_PRINTER_DUPLEX;
+       else if (!_cups_strcasecmp(key, "fax") &&
+                !_cups_strcasecmp(value, "t"))
+         type |= CUPS_PRINTER_MFP;
+       else if (!_cups_strcasecmp(key, "papercustom") &&
+                !_cups_strcasecmp(value, "t"))
+         type |= CUPS_PRINTER_VARIABLE;
+       else if (!_cups_strcasecmp(key, "papermax"))
+       {
+         if (!_cups_strcasecmp(value, "legal-a4"))
+           type |= CUPS_PRINTER_SMALL;
+         else if (!_cups_strcasecmp(value, "isoc-a2"))
+           type |= CUPS_PRINTER_MEDIUM;
+         else if (!_cups_strcasecmp(value, ">isoc-a2"))
+           type |= CUPS_PRINTER_LARGE;
+       }
+       else if (!_cups_strcasecmp(key, "punch") &&
+                !_cups_strcasecmp(value, "t"))
+         type |= CUPS_PRINTER_PUNCH;
+       else if (!_cups_strcasecmp(key, "scan") &&
+                !_cups_strcasecmp(value, "t"))
+         type |= CUPS_PRINTER_MFP;
+       else if (!_cups_strcasecmp(key, "sort") &&
+                !_cups_strcasecmp(value, "t"))
+         type |= CUPS_PRINTER_SORT;
+       else if (!_cups_strcasecmp(key, "staple") &&
+                !_cups_strcasecmp(value, "t"))
+         type |= CUPS_PRINTER_STAPLE;
       }
     }
 
    /*
-    * Save the make-and-model...
+    * Save the printer-xxx values...
     */
 
+    device->dest.num_options = cupsAddOption("printer-info", name,
+                                            device->dest.num_options,
+                                            &device->dest.options);
+
     if (make_and_model[0])
     {
       strlcat(make_and_model, " ", sizeof(make_and_model));
@@ -3235,6 +3327,12 @@ cups_dnssd_query_cb(
                                               device->dest.num_options,
                                               &device->dest.options);
 
+    device->type = type;
+    snprintf(value, sizeof(value), "%u", type);
+    device->dest.num_options = cupsAddOption("printer-type", value,
+                                            device->dest.num_options,
+                                            &device->dest.options);
+
    /*
     * Save the URI...
     */
@@ -3242,7 +3340,7 @@ cups_dnssd_query_cb(
     cups_dnssd_unquote(uriname, device->fullName, sizeof(uriname));
     httpAssembleURI(HTTP_URI_CODING_ALL, uri, sizeof(uri),
                     !strcmp(device->regtype, "_ipps._tcp") ? "ipps" : "ipp",
-                    NULL, uriname, 0, "/cups");
+                    NULL, uriname, 0, saw_printer_type ? "/cups" : "/");
 
     DEBUG_printf(("6cups_dnssd_query: printer-uri-supported=\"%s\"", uri));
 
index 5ae3f57973d614c96ac7071377d627d6fb79ab7d..18bb39cc4af0521f67949162709046fa27d98f7e 100644 (file)
@@ -63,14 +63,102 @@ main(int  argc,                            /* I - Number of command-line arguments */
   {
     if (!strcmp(argv[1], "enum"))
     {
-      int      msec;                   /* Timeout in milliseconds */
-
-      if (argc >= 3)
-        msec = atoi(argv[2]) * 1000;
-      else
-        msec = 0;
-
-      cupsEnumDests(CUPS_DEST_FLAGS_NONE, msec, NULL, 0, 0, enum_cb, NULL);
+      cups_ptype_t     mask = CUPS_PRINTER_LOCAL,
+                                       /* Printer type mask */
+                       type = CUPS_PRINTER_LOCAL;
+                                       /* Printer type */
+      int              msec = 0;       /* Timeout in milliseconds */
+
+
+      for (i = 2; i < argc; i ++)
+        if (isdigit(argv[i][0] & 255) || argv[i][0] == '.')
+          msec = (int)(atof(argv[i]) * 1000);
+        else if (!_cups_strcasecmp(argv[i], "bw"))
+        {
+          mask |= CUPS_PRINTER_BW;
+          type |= CUPS_PRINTER_BW;
+        }
+        else if (!_cups_strcasecmp(argv[i], "color"))
+        {
+          mask |= CUPS_PRINTER_COLOR;
+          type |= CUPS_PRINTER_COLOR;
+        }
+        else if (!_cups_strcasecmp(argv[i], "mono"))
+        {
+          mask |= CUPS_PRINTER_COLOR;
+        }
+        else if (!_cups_strcasecmp(argv[i], "duplex"))
+        {
+          mask |= CUPS_PRINTER_DUPLEX;
+          type |= CUPS_PRINTER_DUPLEX;
+        }
+        else if (!_cups_strcasecmp(argv[i], "simplex"))
+        {
+          mask |= CUPS_PRINTER_DUPLEX;
+        }
+        else if (!_cups_strcasecmp(argv[i], "staple"))
+        {
+          mask |= CUPS_PRINTER_STAPLE;
+          type |= CUPS_PRINTER_STAPLE;
+        }
+        else if (!_cups_strcasecmp(argv[i], "copies"))
+        {
+          mask |= CUPS_PRINTER_COPIES;
+          type |= CUPS_PRINTER_COPIES;
+        }
+        else if (!_cups_strcasecmp(argv[i], "collate"))
+        {
+          mask |= CUPS_PRINTER_COLLATE;
+          type |= CUPS_PRINTER_COLLATE;
+        }
+        else if (!_cups_strcasecmp(argv[i], "punch"))
+        {
+          mask |= CUPS_PRINTER_PUNCH;
+          type |= CUPS_PRINTER_PUNCH;
+        }
+        else if (!_cups_strcasecmp(argv[i], "cover"))
+        {
+          mask |= CUPS_PRINTER_COVER;
+          type |= CUPS_PRINTER_COVER;
+        }
+        else if (!_cups_strcasecmp(argv[i], "bind"))
+        {
+          mask |= CUPS_PRINTER_BIND;
+          type |= CUPS_PRINTER_BIND;
+        }
+        else if (!_cups_strcasecmp(argv[i], "sort"))
+        {
+          mask |= CUPS_PRINTER_SORT;
+          type |= CUPS_PRINTER_SORT;
+        }
+        else if (!_cups_strcasecmp(argv[i], "mfp"))
+        {
+          mask |= CUPS_PRINTER_MFP;
+          type |= CUPS_PRINTER_MFP;
+        }
+        else if (!_cups_strcasecmp(argv[i], "printer"))
+        {
+          mask |= CUPS_PRINTER_MFP;
+        }
+        else if (!_cups_strcasecmp(argv[i], "large"))
+        {
+          mask |= CUPS_PRINTER_LARGE;
+          type |= CUPS_PRINTER_LARGE;
+        }
+        else if (!_cups_strcasecmp(argv[i], "medium"))
+        {
+          mask |= CUPS_PRINTER_MEDIUM;
+          type |= CUPS_PRINTER_MEDIUM;
+        }
+        else if (!_cups_strcasecmp(argv[i], "small"))
+        {
+          mask |= CUPS_PRINTER_SMALL;
+          type |= CUPS_PRINTER_SMALL;
+        }
+        else
+          fprintf(stderr, "Unknown argument \"%s\" ignored...\n", argv[i]);
+
+      cupsEnumDests(CUPS_DEST_FLAGS_NONE, msec, NULL, type, mask, enum_cb, NULL);
     }
     else if (!strcmp(argv[1], "password"))
     {
@@ -417,14 +505,19 @@ enum_cb(void        *user_data,           /* I - User data (unused) */
         unsigned    flags,             /* I - Destination flags */
         cups_dest_t *dest)             /* I - Destination */
 {
+  int          i;                      /* Looping var */
+  cups_option_t        *option;                /* Current option */
+
+
   if (flags & CUPS_DEST_FLAGS_REMOVED)
-    printf("Removed '%s' (%s).\n", dest->name,
-           cupsGetOption("printer-uri-supported", dest->num_options,
-                         dest->options));
+    printf("Removed '%s':\n", dest->name);
   else
-    printf("Added '%s' (%s).\n", dest->name,
-           cupsGetOption("printer-uri-supported", dest->num_options,
-                         dest->options));
+    printf("Added '%s':\n", dest->name);
+
+  for (i = dest->num_options, option = dest->options; i > 0; i --, option ++)
+    printf("    %s=\"%s\"\n", option->name, option->value);
+
+  putchar('\n');
 
   return (1);
 }