]> git.ipfire.org Git - thirdparty/cups.git/commitdiff
Revive CUPS_PRINTER_DISCOVERED for cupsEnumDests.
authorMichael Sweet <michael.r.sweet@gmail.com>
Wed, 31 May 2017 15:21:29 +0000 (11:21 -0400)
committerMichael Sweet <michael.r.sweet@gmail.com>
Wed, 31 May 2017 15:21:29 +0000 (11:21 -0400)
cups/cups.h
cups/cupspm.md
cups/dest.c
cups/util.c

index 22d4be3e14a7897665fe9e05fd9faf5c4fd86bbd..16bd98fec12ba1d7ae412236d5f0435e829f6077 100644 (file)
@@ -225,20 +225,19 @@ enum cups_ptype_e                 /* Printer type/capability bit
   CUPS_PRINTER_FAX = 0x40000,          /* Fax queue */
   CUPS_PRINTER_REJECTING = 0x80000,    /* Printer is rejecting jobs */
   CUPS_PRINTER_DELETE = 0x100000,      /* Delete printer
-                                        * @since CUPS 1.2/macOS 10.5@ */
+                                        * @deprecated@ @exclude all@ */
   CUPS_PRINTER_NOT_SHARED = 0x200000,  /* Printer is not shared
                                         * @since CUPS 1.2/macOS 10.5@ */
   CUPS_PRINTER_AUTHENTICATED = 0x400000,/* Printer requires authentication
                                         * @since CUPS 1.2/macOS 10.5@ */
   CUPS_PRINTER_COMMANDS = 0x800000,    /* Printer supports maintenance commands
                                         * @since CUPS 1.2/macOS 10.5@ */
-  CUPS_PRINTER_DISCOVERED = 0x1000000, /* Printer was automatically discovered
-                                        * and added @private@ */
+  CUPS_PRINTER_DISCOVERED = 0x1000000, /* Printer was discovered @since CUPS 1.2/macOS 10.5@ */
   CUPS_PRINTER_SCANNER = 0x2000000,    /* Scanner-only device
                                         * @since CUPS 1.4/macOS 10.6@ */
   CUPS_PRINTER_MFP = 0x4000000,                /* Printer with scanning capabilities
                                         * @since CUPS 1.4/macOS 10.6@ */
-  CUPS_PRINTER_3D = 0x8000000,         /* Printer with 3D capabilities @private@ */
+  CUPS_PRINTER_3D = 0x8000000,         /* Printer with 3D capabilities @exclude all@ @deprecated@ */
   CUPS_PRINTER_OPTIONS = 0x6fffc       /* ~(CLASS | REMOTE | IMPLICIT |
                                         * DEFAULT | FAX | REJECTING | DELETE |
                                         * NOT_SHARED | AUTHENTICATED |
@@ -340,11 +339,11 @@ extern ipp_t              *cupsDoRequest(http_t *http, ipp_t *request,
                                       const char *resource);
 extern http_encryption_t cupsEncryption(void);
 extern void            cupsFreeJobs(int num_jobs, cups_job_t *jobs);
-extern int             cupsGetClasses(char ***classes) _CUPS_DEPRECATED_MSG("Use cupsGetDests instead.");
+extern int             cupsGetClasses(char ***classes) _CUPS_DEPRECATED_MSG("Use cupsEnumDests instead.");
 extern const char      *cupsGetDefault(void);
 extern int             cupsGetJobs(cups_job_t **jobs, const char *name,
                                    int myjobs, int whichjobs);
-extern int             cupsGetPrinters(char ***printers) _CUPS_DEPRECATED_MSG("Use cupsGetDests instead.");
+extern int             cupsGetPrinters(char ***printers) _CUPS_DEPRECATED_MSG("Use cupsEnumDests instead.");
 extern ipp_status_t    cupsLastError(void);
 extern int             cupsPrintFile(const char *name, const char *filename,
                                      const char *title, int num_options,
index 12bfdbd34653d820e1136d719015ec6453d107f6..97f2049d6865d22c233259aebc59bfb9694f26e1 100644 (file)
@@ -153,15 +153,17 @@ the destinations based on categories and/or capabilities.  The destination's
 "printer-type" value is masked by the `mask` value and compared to the `type`
 value when filtering.  For example, to only enumerate destinations that are
 hosted on the local system, pass `CUPS_PRINTER_LOCAL` for the `type` argument
-and `CUPS_PRINTER_REMOTE` for the `mask` argument.  The following constants can
-be used for filtering:
+and `CUPS_PRINTER_DISCOVERED` for the `mask` argument.  The following constants
+can be used for filtering:
 
 - `CUPS_PRINTER_CLASS`: A collection of destinations.
 - `CUPS_PRINTER_FAX`: A facsimile device.
 - `CUPS_PRINTER_LOCAL`: A local printer or class.  This constant has the value 0
   (no bits set) and is only used for the `type` argument and is paired with the
-  `CUPS_PRINTER_REMOTE` constant passed in the `mask` argument.
-- `CUPS_PRINTER_REMOTE`: A remote printer or class.
+  `CUPS_PRINTER_REMOTE` or `CUPS_PRINTER_DISCOVERED` constant passed in the
+  `mask` argument.
+- `CUPS_PRINTER_REMOTE`: A remote (shared) printer or class.
+- `CUPS_PRINTER_DISCOVERED`: An available network printer or class.
 - `CUPS_PRINTER_BW`: Can do B&W printing.
 - `CUPS_PRINTER_COLOR`: Can do color printing.
 - `CUPS_PRINTER_DUPLEX`: Can do two-sided printing.
@@ -292,6 +294,8 @@ destination attributes:
 - "printer-state-reasons": Additional comma-delimited state keywords for the
   destination such as "media-tray-empty-error" and "toner-low-warning".
 - "printer-type": The `cups_ptype_t` value associated with the destination.
+- "printer-uri": The URI associated with the destination; if not set, this
+  destination was discovered but is not yet setup as a local printer.
 
 Use the `cupsGetOption` function to retrieve the value.  For example, the
 following code gets the make and model of a destination:
index e7eccf01ff1c3fede8acc1e0d9e47ef19b0761a5..9493244c7c4248be392a6ed442dea99c7a1d2a47 100644 (file)
@@ -928,10 +928,15 @@ _cupsCreateDest(const char *name, /* I - Printer name */
 /*
  * 'cupsEnumDests()' - Enumerate available destinations with a callback function.
  *
- * Destinations are enumerated from one or more sources. The callback function
- * receives the @code user_data@ pointer, destination name, instance, number of
- * options, and options which can be used as input to the @link cupsAddDest@
- * function.  The function must return 1 to continue enumeration or 0 to stop.
+ * Destinations are enumerated from one or more sources.  The callback function
+ * receives the @code user_data@ pointer and the destination pointer which can
+ * be used as input to the @link cupsCopyDest@ function.  The function must
+ * return 1 to continue enumeration or 0 to stop.
+ *
+ * The @code type@ and @code mask@ arguments allow the caller to filter the
+ * destinations that are enumerated.  Passing 0 for both will enumerate all
+ * printers.  The constant @code CUPS_PRINTER_DISCOVERED@ is used to filter on
+ * destinations that are available but have not yet been added locally.
  *
  * Enumeration happens on the current thread and does not return until all
  * destinations have been enumerated or the callback function returns 0.
@@ -998,37 +1003,9 @@ cupsEnumDests(
     return (0);
 
  /*
-  * Get the list of local printers and pass them to the callback function...
+  * Get ready to enumerate...
   */
 
-  num_dests = _cupsGetDests(CUPS_HTTP_DEFAULT, IPP_OP_CUPS_GET_PRINTERS, NULL,
-                            &dests, type, mask | CUPS_PRINTER_3D);
-
-  if ((user_default = _cupsUserDefault(name, sizeof(name))) != NULL)
-    defprinter = name;
-  else if ((defprinter = cupsGetDefault2(CUPS_HTTP_DEFAULT)) != NULL)
-  {
-    strlcpy(name, defprinter, sizeof(name));
-    defprinter = name;
-  }
-
-  if (defprinter)
-  {
-   /*
-    * Separate printer and instance name...
-    */
-
-    if ((instance = strchr(name, '/')) != NULL)
-      *instance++ = '\0';
-
-   /*
-    * Lookup the printer and instance and make it the default...
-    */
-
-    if ((dest = cupsGetDest(name, instance, num_dests, dests)) != NULL)
-      dest->is_default = 1;
-  }
-
 #if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
   data.type      = type;
   data.mask      = mask;
@@ -1037,64 +1014,100 @@ cupsEnumDests(
   data.devices   = cupsArrayNew3((cups_array_func_t)cups_dnssd_compare_devices, NULL, NULL, 0, NULL, (cups_afree_func_t)cups_dnssd_free_device);
 #endif /* HAVE_DNSSD || HAVE_AVAHI */
 
-  for (i = num_dests, dest = dests;
-       i > 0 && (!cancel || !*cancel);
-       i --, dest ++)
+  if (!(mask & CUPS_PRINTER_DISCOVERED) || !(type & CUPS_PRINTER_DISCOVERED))
   {
-#if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
-    const char *device_uri;            /* Device URI */
-#endif /* HAVE_DNSSD || HAVE_AVAHI */
+   /*
+    * Get the list of local printers and pass them to the callback function...
+    */
 
-    if (!(*cb)(user_data, i > 1 ? CUPS_DEST_FLAGS_MORE : CUPS_DEST_FLAGS_NONE,
-               dest))
-      break;
+    num_dests = _cupsGetDests(CUPS_HTTP_DEFAULT, IPP_OP_CUPS_GET_PRINTERS, NULL,
+                              &dests, type, mask);
 
-#if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
-    if (!dest->instance && (device_uri = cupsGetOption("device-uri", dest->num_options, dest->options)) != NULL && !strncmp(device_uri, "dnssd://", 8))
+    if ((user_default = _cupsUserDefault(name, sizeof(name))) != NULL)
+      defprinter = name;
+    else if ((defprinter = cupsGetDefault2(CUPS_HTTP_DEFAULT)) != NULL)
+    {
+      strlcpy(name, defprinter, sizeof(name));
+      defprinter = name;
+    }
+
+    if (defprinter)
     {
      /*
-      * Add existing queue using service name, etc. so we don't list it again...
+      * Separate printer and instance name...
       */
 
-      char     scheme[32],             /* URI scheme */
-               userpass[32],           /* Username:password */
-               serviceName[256],       /* Service name (host field) */
-               resource[256],          /* Resource (options) */
-               *regtype,               /* Registration type */
-               *replyDomain;           /* Registration domain */
-      int      port;                   /* Port number (not used) */
-
-      if (httpSeparateURI(HTTP_URI_CODING_ALL, device_uri, scheme, sizeof(scheme), userpass, sizeof(userpass), serviceName, sizeof(serviceName), &port, resource, sizeof(resource)) >= HTTP_URI_STATUS_OK)
-      {
-        if ((regtype = strstr(serviceName, "._ipp")) != NULL)
-       {
-         *regtype++ = '\0';
+      if ((instance = strchr(name, '/')) != NULL)
+        *instance++ = '\0';
 
-         if ((replyDomain = strstr(regtype, "._tcp.")) != NULL)
-         {
-           replyDomain[5] = '\0';
-           replyDomain += 6;
+     /*
+      * Lookup the printer and instance and make it the default...
+      */
 
-           if ((device = cups_dnssd_get_device(&data, serviceName, regtype, replyDomain)) != NULL)
-             device->state = _CUPS_DNSSD_ACTIVE;
-         }
-        }
-      }
+      if ((dest = cupsGetDest(name, instance, num_dests, dests)) != NULL)
+        dest->is_default = 1;
     }
+
+    for (i = num_dests, dest = dests;
+         i > 0 && (!cancel || !*cancel);
+         i --, dest ++)
+    {
+#if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
+      const char *device_uri;          /* Device URI */
 #endif /* HAVE_DNSSD || HAVE_AVAHI */
-  }
 
-  cupsFreeDests(num_dests, dests);
+      if (!(*cb)(user_data, i > 1 ? CUPS_DEST_FLAGS_MORE : CUPS_DEST_FLAGS_NONE,
+                 dest))
+        break;
 
-  if (i > 0 || msec == 0)
-  {
 #if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
-    cupsArrayDelete(data.devices);
+      if (!dest->instance && (device_uri = cupsGetOption("device-uri", dest->num_options, dest->options)) != NULL && !strncmp(device_uri, "dnssd://", 8))
+      {
+       /*
+        * Add existing queue using service name, etc. so we don't list it again...
+        */
+
+        char   scheme[32],             /* URI scheme */
+                  userpass[32],                /* Username:password */
+                  serviceName[256],    /* Service name (host field) */
+                  resource[256],               /* Resource (options) */
+                  *regtype,            /* Registration type */
+                  *replyDomain;                /* Registration domain */
+        int    port;                   /* Port number (not used) */
+
+        if (httpSeparateURI(HTTP_URI_CODING_ALL, device_uri, scheme, sizeof(scheme), userpass, sizeof(userpass), serviceName, sizeof(serviceName), &port, resource, sizeof(resource)) >= HTTP_URI_STATUS_OK)
+        {
+          if ((regtype = strstr(serviceName, "._ipp")) != NULL)
+          {
+            *regtype++ = '\0';
+
+            if ((replyDomain = strstr(regtype, "._tcp.")) != NULL)
+            {
+              replyDomain[5] = '\0';
+              replyDomain += 6;
+
+              if ((device = cups_dnssd_get_device(&data, serviceName, regtype, replyDomain)) != NULL)
+                device->state = _CUPS_DNSSD_ACTIVE;
+            }
+          }
+        }
+      }
 #endif /* HAVE_DNSSD || HAVE_AVAHI */
+    }
 
-    return (1);
+    cupsFreeDests(num_dests, dests);
+
+    if (i > 0 || msec == 0)
+      goto enum_finished;
   }
 
+ /*
+  * Return early if the caller doesn't want to do discovery...
+  */
+
+  if ((mask & CUPS_PRINTER_DISCOVERED) && !(type & CUPS_PRINTER_DISCOVERED))
+    goto enum_finished;
+
 #if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
  /*
   * Get Bonjour-shared printers...
@@ -1294,8 +1307,6 @@ cupsEnumDests(
 #  endif /* HAVE_AVAHI */
   }
 
-  cupsArrayDelete(data.devices);
-
 #  ifdef HAVE_DNSSD
   DNSServiceRefDeallocate(ipp_ref);
   DNSServiceRefDeallocate(local_ipp_ref);
@@ -1318,6 +1329,16 @@ cupsEnumDests(
 #  endif /* HAVE_DNSSD */
 #endif /* HAVE_DNSSD || HAVE_DNSSD */
 
+ /*
+  * Return...
+  */
+
+  enum_finished:
+
+#if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
+  cupsArrayDelete(data.devices);
+#endif /* HAVE_DNSSD || HAVE_AVAHI */
+
   return (1);
 }
 
@@ -1326,11 +1347,16 @@ cupsEnumDests(
 /*
  * 'cupsEnumDestsBlock()' - Enumerate available destinations with a block.
  *
- * Destinations are enumerated from one or more sources. The block receives the
- * destination name, instance, number of options, and options which can be used
- * as input to the @link cupsAddDest@ function.  The block must return 1 to
+ * Destinations are enumerated from one or more sources.  The block receives the
+ * @code user_data@ pointer and the destination pointer which can be used as
+ * input to the @link cupsCopyDest@ function.  The block must return 1 to
  * continue enumeration or 0 to stop.
  *
+ * The @code type@ and @code mask@ arguments allow the caller to filter the
+ * destinations that are enumerated.  Passing 0 for both will enumerate all
+ * printers.  The constant @code CUPS_PRINTER_DISCOVERED@ is used to filter on
+ * destinations that are available but have not yet been added locally.
+ *
  * Enumeration happens on the current thread and does not return until all
  * destinations have been enumerated or the block returns 0.
  *
@@ -1980,7 +2006,7 @@ cupsGetDests2(http_t      *http,  /* I - Connection to server or @code CUPS_HTTP_
   data.num_dests = 0;
   data.dests     = NULL;
 
-  cupsEnumDests(0, 1000, NULL, 0, CUPS_PRINTER_3D, (cups_dest_cb_t)cups_get_cb, &data);
+  cupsEnumDests(0, 1000, NULL, 0, 0, (cups_dest_cb_t)cups_get_cb, &data);
 
   if (cupsLastError() >= IPP_STATUS_REDIRECTION_OTHER_SITE)
   {
@@ -2204,7 +2230,7 @@ cupsGetNamedDest(http_t     *http,        /* I - Connection to server or @code CUPS_HTT
   * Get the printer's attributes...
   */
 
-  if (!_cupsGetDests(http, op, name, &dest, 0, CUPS_PRINTER_3D))
+  if (!_cupsGetDests(http, op, name, &dest, 0, 0))
   {
     if (name)
     {
@@ -2215,7 +2241,7 @@ cupsGetNamedDest(http_t     *http,        /* I - Connection to server or @code CUPS_HTT
       data.name = name;
       data.dest = NULL;
 
-      cupsEnumDests(0, 1000, NULL, 0, CUPS_PRINTER_3D, (cups_dest_cb_t)cups_name_cb, &data);
+      cupsEnumDests(0, 1000, NULL, 0, 0, (cups_dest_cb_t)cups_name_cb, &data);
 
       if (!data.dest)
         return (NULL);
@@ -2401,7 +2427,7 @@ cupsSetDests2(http_t      *http,  /* I - Connection to server or @code CUPS_HTTP_
   * Get the server destinations...
   */
 
-  num_temps = _cupsGetDests(http, IPP_OP_CUPS_GET_PRINTERS, NULL, &temps, 0, CUPS_PRINTER_3D);
+  num_temps = _cupsGetDests(http, IPP_OP_CUPS_GET_PRINTERS, NULL, &temps, 0, 0);
 
   if (cupsLastError() >= IPP_STATUS_REDIRECTION_OTHER_SITE)
   {
@@ -3453,7 +3479,7 @@ 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;
+    cups_ptype_t       type = CUPS_PRINTER_DISCOVERED | CUPS_PRINTER_BW;
                                        /* Printer type */
     int                        saw_printer_type = 0;
                                        /* Did we see a printer-type key? */
@@ -3572,7 +3598,7 @@ cups_dnssd_query_cb(
         */
 
        saw_printer_type = 1;
-        type             = (cups_ptype_t)strtol(value, NULL, 0);
+        type             = (cups_ptype_t)strtol(value, NULL, 0) | CUPS_PRINTER_DISCOVERED;
       }
       else if (!saw_printer_type)
       {
index d30380b6e696390a37154e8018b5cdc2420a73c1..28ebbd0b0b2b8433a7d9104a11e3acc886f9379c 100644 (file)
@@ -195,7 +195,7 @@ cupsCreateJob(
   data.name = name;
   data.dest = NULL;
 
-  cupsEnumDests(0, 1000, NULL, 0, CUPS_PRINTER_3D, (cups_dest_cb_t)cups_create_cb, &data);
+  cupsEnumDests(0, 1000, NULL, 0, 0, (cups_dest_cb_t)cups_create_cb, &data);
 
   if (!data.dest)
   {