d4e17e5
diff -up cups-2.2.4/cups/cups.h.cupsenumdests2 cups-2.2.4/cups/cups.h
d4e17e5
--- cups-2.2.4/cups/cups.h.cupsenumdests2	2017-06-30 17:44:38.000000000 +0200
d4e17e5
+++ cups-2.2.4/cups/cups.h	2017-10-04 15:31:45.358029517 +0200
d4e17e5
@@ -527,11 +527,20 @@ extern int		cupsEnumDests(unsigned flags
d4e17e5
 				      cups_ptype_t type, cups_ptype_t mask,
d4e17e5
 				      cups_dest_cb_t cb, void *user_data)
d4e17e5
 				      _CUPS_API_1_6;
d4e17e5
+extern int		cupsEnumDests2(http_t *http, unsigned flags, int msec, int *cancel,
d4e17e5
+				      cups_ptype_t type, cups_ptype_t mask,
d4e17e5
+				      cups_dest_cb_t cb, void *user_data)
d4e17e5
+				      _CUPS_API_1_6;
d4e17e5
 #  ifdef __BLOCKS__
d4e17e5
 extern int		cupsEnumDestsBlock(unsigned flags, int msec,
d4e17e5
 					   int *cancel, cups_ptype_t type,
d4e17e5
 					   cups_ptype_t mask,
d4e17e5
 					   cups_dest_block_t block)
d4e17e5
+					   _CUPS_API_1_6;
d4e17e5
+extern int		cupsEnumDestsBlock2(http_t *http, unsigned flags, int msec,
d4e17e5
+					   int *cancel, cups_ptype_t type,
d4e17e5
+					   cups_ptype_t mask,
d4e17e5
+					   cups_dest_block_t block)
d4e17e5
 					   _CUPS_API_1_6;
d4e17e5
 #  endif /* __BLOCKS__ */
d4e17e5
 extern ipp_status_t	cupsFinishDestDocument(http_t *http,
d4e17e5
diff -up cups-2.2.4/cups/dest.c.cupsenumdests2 cups-2.2.4/cups/dest.c
d4e17e5
--- cups-2.2.4/cups/dest.c.cupsenumdests2	2017-10-04 15:31:45.356029534 +0200
d4e17e5
+++ cups-2.2.4/cups/dest.c	2017-10-04 15:31:45.359029509 +0200
d4e17e5
@@ -1377,6 +1377,423 @@ cupsEnumDests(
d4e17e5
   return (1);
d4e17e5
 }
d4e17e5
 
d4e17e5
+/*
d4e17e5
+ * 'cupsEnumDests2()' - same as cupsEnumDests(), but for not default http connection
d4e17e5
+ */
d4e17e5
+
d4e17e5
+int					/* O - 1 on success, 0 on failure */
d4e17e5
+cupsEnumDests2(
d4e17e5
+  http_t         *http,			/* I - Connection to server */
d4e17e5
+  unsigned       flags,			/* I - Enumeration flags */
d4e17e5
+  int            msec,			/* I - Timeout in milliseconds, -1 for indefinite */
d4e17e5
+  int            *cancel,		/* I - Pointer to "cancel" variable */
d4e17e5
+  cups_ptype_t   type,			/* I - Printer type bits */
d4e17e5
+  cups_ptype_t   mask,			/* I - Mask for printer type bits */
d4e17e5
+  cups_dest_cb_t cb,			/* I - Callback function */
d4e17e5
+  void           *user_data)		/* I - User data */
d4e17e5
+{
d4e17e5
+  int			i,		/* Looping var */
d4e17e5
+			num_dests;	/* Number of destinations */
d4e17e5
+  cups_dest_t		*dests = NULL,	/* Destinations */
d4e17e5
+			*dest;		/* Current destination */
d4e17e5
+  const char		*defprinter;	/* Default printer */
d4e17e5
+  char			name[1024],	/* Copy of printer name */
d4e17e5
+			*instance,	/* Pointer to instance name */
d4e17e5
+			*user_default;	/* User default printer */
d4e17e5
+#if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
d4e17e5
+  int			count,		/* Number of queries started */
d4e17e5
+			completed,	/* Number of completed queries */
d4e17e5
+			remaining;	/* Remainder of timeout */
d4e17e5
+  struct timeval	curtime;	/* Current time */
d4e17e5
+  _cups_dnssd_data_t	data;		/* Data for callback */
d4e17e5
+  _cups_dnssd_device_t	*device;	/* Current device */
d4e17e5
+#  ifdef HAVE_DNSSD
d4e17e5
+  int			nfds,		/* Number of files responded */
d4e17e5
+			main_fd;	/* File descriptor for lookups */
d4e17e5
+  DNSServiceRef		ipp_ref = NULL,	/* IPP browser */
d4e17e5
+			local_ipp_ref = NULL; /* Local IPP browser */
d4e17e5
+#    ifdef HAVE_SSL
d4e17e5
+  DNSServiceRef		ipps_ref = NULL,/* IPPS browser */
d4e17e5
+			local_ipps_ref = NULL; /* Local IPPS browser */
d4e17e5
+#    endif /* HAVE_SSL */
d4e17e5
+#    ifdef HAVE_POLL
d4e17e5
+  struct pollfd		pfd;		/* Polling data */
d4e17e5
+#    else
d4e17e5
+  fd_set		input;		/* Input set for select() */
d4e17e5
+  struct timeval	timeout;	/* Timeout for select() */
d4e17e5
+#    endif /* HAVE_POLL */
d4e17e5
+#  else /* HAVE_AVAHI */
d4e17e5
+  int			error;		/* Error value */
d4e17e5
+  AvahiServiceBrowser	*ipp_ref = NULL;/* IPP browser */
d4e17e5
+#    ifdef HAVE_SSL
d4e17e5
+  AvahiServiceBrowser	*ipps_ref = NULL; /* IPPS browser */
d4e17e5
+#    endif /* HAVE_SSL */
d4e17e5
+#  endif /* HAVE_DNSSD */
d4e17e5
+#endif /* HAVE_DNSSD || HAVE_AVAHI */
d4e17e5
+
d4e17e5
+
d4e17e5
+ /*
d4e17e5
+  * Range check input...
d4e17e5
+  */
d4e17e5
+
d4e17e5
+  (void)flags;
d4e17e5
+
d4e17e5
+  if (!cb)
d4e17e5
+    return (0);
d4e17e5
+
d4e17e5
+ /*
d4e17e5
+  * Get ready to enumerate...
d4e17e5
+  */
d4e17e5
+
d4e17e5
+#if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
d4e17e5
+  memset(&data, 0, sizeof(data));
d4e17e5
+
d4e17e5
+  data.type      = type;
d4e17e5
+  data.mask      = mask;
d4e17e5
+  data.cb        = cb;
d4e17e5
+  data.user_data = user_data;
d4e17e5
+  data.devices   = cupsArrayNew3((cups_array_func_t)cups_dnssd_compare_devices, NULL, NULL, 0, NULL, (cups_afree_func_t)cups_dnssd_free_device);
d4e17e5
+#endif /* HAVE_DNSSD || HAVE_AVAHI */
d4e17e5
+
d4e17e5
+  if (!(mask & CUPS_PRINTER_DISCOVERED) || !(type & CUPS_PRINTER_DISCOVERED))
d4e17e5
+  {
d4e17e5
+   /*
d4e17e5
+    * Get the list of local printers and pass them to the callback function...
d4e17e5
+    */
d4e17e5
+
d4e17e5
+    num_dests = _cupsGetDests(http, IPP_OP_CUPS_GET_PRINTERS, NULL,
d4e17e5
+                              &dests, type, mask);
d4e17e5
+
d4e17e5
+    if ((user_default = _cupsUserDefault(name, sizeof(name))) != NULL)
d4e17e5
+      defprinter = name;
d4e17e5
+    else if ((defprinter = cupsGetDefault2(http)) != NULL)
d4e17e5
+    {
d4e17e5
+      strlcpy(name, defprinter, sizeof(name));
d4e17e5
+      defprinter = name;
d4e17e5
+    }
d4e17e5
+
d4e17e5
+    if (defprinter)
d4e17e5
+    {
d4e17e5
+     /*
d4e17e5
+      * Separate printer and instance name...
d4e17e5
+      */
d4e17e5
+
d4e17e5
+      if ((instance = strchr(name, '/')) != NULL)
d4e17e5
+        *instance++ = '\0';
d4e17e5
+
d4e17e5
+     /*
d4e17e5
+      * Lookup the printer and instance and make it the default...
d4e17e5
+      */
d4e17e5
+
d4e17e5
+      if ((dest = cupsGetDest(name, instance, num_dests, dests)) != NULL)
d4e17e5
+        dest->is_default = 1;
d4e17e5
+    }
d4e17e5
+
d4e17e5
+    for (i = num_dests, dest = dests;
d4e17e5
+         i > 0 && (!cancel || !*cancel);
d4e17e5
+         i --, dest ++)
d4e17e5
+    {
d4e17e5
+#if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
d4e17e5
+      const char *device_uri;		/* Device URI */
d4e17e5
+#endif /* HAVE_DNSSD || HAVE_AVAHI */
d4e17e5
+
d4e17e5
+      if (!(*cb)(user_data, i > 1 ? CUPS_DEST_FLAGS_MORE : CUPS_DEST_FLAGS_NONE,
d4e17e5
+                 dest))
d4e17e5
+        break;
d4e17e5
+
d4e17e5
+#if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
d4e17e5
+      if (!dest->instance && (device_uri = cupsGetOption("device-uri", dest->num_options, dest->options)) != NULL && !strncmp(device_uri, "dnssd://", 8))
d4e17e5
+      {
d4e17e5
+       /*
d4e17e5
+        * Add existing queue using service name, etc. so we don't list it again...
d4e17e5
+        */
d4e17e5
+
d4e17e5
+        char	scheme[32],		/* URI scheme */
d4e17e5
+                userpass[32],           /* Username:password */
d4e17e5
+                serviceName[256],       /* Service name (host field) */
d4e17e5
+                resource[256],          /* Resource (options) */
d4e17e5
+                *regtype,               /* Registration type */
d4e17e5
+                *replyDomain;           /* Registration domain */
d4e17e5
+        int	port;			/* Port number (not used) */
d4e17e5
+
d4e17e5
+        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)
d4e17e5
+        {
d4e17e5
+          if ((regtype = strstr(serviceName, "._ipp")) != NULL)
d4e17e5
+          {
d4e17e5
+            *regtype++ = '\0';
d4e17e5
+
d4e17e5
+            if ((replyDomain = strstr(regtype, "._tcp.")) != NULL)
d4e17e5
+            {
d4e17e5
+              replyDomain[5] = '\0';
d4e17e5
+              replyDomain += 6;
d4e17e5
+
d4e17e5
+              if ((device = cups_dnssd_get_device(&data, serviceName, regtype, replyDomain)) != NULL)
d4e17e5
+                device->state = _CUPS_DNSSD_ACTIVE;
d4e17e5
+            }
d4e17e5
+          }
d4e17e5
+        }
d4e17e5
+      }
d4e17e5
+#endif /* HAVE_DNSSD || HAVE_AVAHI */
d4e17e5
+    }
d4e17e5
+
d4e17e5
+    cupsFreeDests(num_dests, dests);
d4e17e5
+
d4e17e5
+    if (i > 0 || msec == 0)
d4e17e5
+      goto enum_finished;
d4e17e5
+  }
d4e17e5
+
d4e17e5
+ /*
d4e17e5
+  * Return early if the caller doesn't want to do discovery...
d4e17e5
+  */
d4e17e5
+
d4e17e5
+  if ((mask & CUPS_PRINTER_DISCOVERED) && !(type & CUPS_PRINTER_DISCOVERED))
d4e17e5
+    goto enum_finished;
d4e17e5
+
d4e17e5
+#if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
d4e17e5
+ /*
d4e17e5
+  * Get Bonjour-shared printers...
d4e17e5
+  */
d4e17e5
+
d4e17e5
+  gettimeofday(&curtime, NULL);
d4e17e5
+
d4e17e5
+#  ifdef HAVE_DNSSD
d4e17e5
+  if (DNSServiceCreateConnection(&data.main_ref) != kDNSServiceErr_NoError)
d4e17e5
+    return (0);
d4e17e5
+
d4e17e5
+  main_fd = DNSServiceRefSockFD(data.main_ref);
d4e17e5
+
d4e17e5
+  ipp_ref = data.main_ref;
d4e17e5
+  DNSServiceBrowse(&ipp_ref, kDNSServiceFlagsShareConnection, 0,
d4e17e5
+                   "_ipp._tcp", NULL,
d4e17e5
+                   (DNSServiceBrowseReply)cups_dnssd_browse_cb, &data);
d4e17e5
+
d4e17e5
+  local_ipp_ref = data.main_ref;
d4e17e5
+  DNSServiceBrowse(&local_ipp_ref, kDNSServiceFlagsShareConnection,
d4e17e5
+                   kDNSServiceInterfaceIndexLocalOnly,
d4e17e5
+                   "_ipp._tcp", NULL,
d4e17e5
+                   (DNSServiceBrowseReply)cups_dnssd_local_cb, &data);
d4e17e5
+
d4e17e5
+#    ifdef HAVE_SSL
d4e17e5
+  ipps_ref = data.main_ref;
d4e17e5
+  DNSServiceBrowse(&ipps_ref, kDNSServiceFlagsShareConnection, 0,
d4e17e5
+                   "_ipps._tcp", NULL,
d4e17e5
+                   (DNSServiceBrowseReply)cups_dnssd_browse_cb, &data);
d4e17e5
+
d4e17e5
+  local_ipps_ref = data.main_ref;
d4e17e5
+  DNSServiceBrowse(&local_ipps_ref, kDNSServiceFlagsShareConnection,
d4e17e5
+                   kDNSServiceInterfaceIndexLocalOnly,
d4e17e5
+                   "_ipps._tcp", NULL,
d4e17e5
+                   (DNSServiceBrowseReply)cups_dnssd_local_cb, &data);
d4e17e5
+#    endif /* HAVE_SSL */
d4e17e5
+
d4e17e5
+#  else /* HAVE_AVAHI */
d4e17e5
+  if ((data.simple_poll = avahi_simple_poll_new()) == NULL)
d4e17e5
+  {
d4e17e5
+    DEBUG_puts("cupsEnumDests2: Unable to create Avahi simple poll object.");
d4e17e5
+    return (1);
d4e17e5
+  }
d4e17e5
+
d4e17e5
+  avahi_simple_poll_set_func(data.simple_poll, cups_dnssd_poll_cb, &data);
d4e17e5
+
d4e17e5
+  data.client = avahi_client_new(avahi_simple_poll_get(data.simple_poll),
d4e17e5
+				 0, cups_dnssd_client_cb, &data,
d4e17e5
+				 &error);
d4e17e5
+  if (!data.client)
d4e17e5
+  {
d4e17e5
+    DEBUG_puts("cupsEnumDests2: Unable to create Avahi client.");
d4e17e5
+    avahi_simple_poll_free(data.simple_poll);
d4e17e5
+    return (1);
d4e17e5
+  }
d4e17e5
+
d4e17e5
+  data.browsers = 1;
d4e17e5
+  ipp_ref = avahi_service_browser_new(data.client, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, "_ipp._tcp", NULL, 0, cups_dnssd_browse_cb, &data);
d4e17e5
+
d4e17e5
+#    ifdef HAVE_SSL
d4e17e5
+  data.browsers ++;
d4e17e5
+  ipps_ref = avahi_service_browser_new(data.client, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, "_ipps._tcp", NULL, 0, cups_dnssd_browse_cb, &data);
d4e17e5
+#    endif /* HAVE_SSL */
d4e17e5
+#  endif /* HAVE_DNSSD */
d4e17e5
+
d4e17e5
+  if (msec < 0)
d4e17e5
+    remaining = INT_MAX;
d4e17e5
+  else
d4e17e5
+    remaining = msec;
d4e17e5
+
d4e17e5
+  while (remaining > 0 && (!cancel || !*cancel))
d4e17e5
+  {
d4e17e5
+   /*
d4e17e5
+    * Check for input...
d4e17e5
+    */
d4e17e5
+
d4e17e5
+    DEBUG_printf(("1cupsEnumDests2: remaining=%d", remaining));
d4e17e5
+
d4e17e5
+    cups_elapsed(&curtime);
d4e17e5
+
d4e17e5
+#  ifdef HAVE_DNSSD
d4e17e5
+#    ifdef HAVE_POLL
d4e17e5
+    pfd.fd     = main_fd;
d4e17e5
+    pfd.events = POLLIN;
d4e17e5
+
d4e17e5
+    nfds = poll(&pfd, 1, remaining > _CUPS_DNSSD_MAXTIME ? _CUPS_DNSSD_MAXTIME : remaining);
d4e17e5
+
d4e17e5
+#    else
d4e17e5
+    FD_ZERO(&input);
d4e17e5
+    FD_SET(main_fd, &input);
d4e17e5
+
d4e17e5
+    timeout.tv_sec  = 0;
d4e17e5
+    timeout.tv_usec = 1000 * (remaining > _CUPS_DNSSD_MAXTIME ? _CUPS_DNSSD_MAXTIME : remaining);
d4e17e5
+
d4e17e5
+    nfds = select(main_fd + 1, &input, NULL, NULL, &timeout);
d4e17e5
+#    endif /* HAVE_POLL */
d4e17e5
+
d4e17e5
+    if (nfds > 0)
d4e17e5
+      DNSServiceProcessResult(data.main_ref);
d4e17e5
+
d4e17e5
+#  else /* HAVE_AVAHI */
d4e17e5
+    data.got_data = 0;
d4e17e5
+
d4e17e5
+    if ((error = avahi_simple_poll_iterate(data.simple_poll, _CUPS_DNSSD_MAXTIME)) > 0)
d4e17e5
+    {
d4e17e5
+     /*
d4e17e5
+      * We've been told to exit the loop.  Perhaps the connection to
d4e17e5
+      * Avahi failed.
d4e17e5
+      */
d4e17e5
+
d4e17e5
+      break;
d4e17e5
+    }
d4e17e5
+
d4e17e5
+    DEBUG_printf(("1cupsEnumDests2: got_data=%d", data.got_data));
d4e17e5
+#  endif /* HAVE_DNSSD */
d4e17e5
+
d4e17e5
+    remaining -= cups_elapsed(&curtime);
d4e17e5
+
d4e17e5
+    for (device = (_cups_dnssd_device_t *)cupsArrayFirst(data.devices),
d4e17e5
+             count = 0, completed = 0;
d4e17e5
+         device;
d4e17e5
+         device = (_cups_dnssd_device_t *)cupsArrayNext(data.devices))
d4e17e5
+    {
d4e17e5
+      if (device->ref)
d4e17e5
+        count ++;
d4e17e5
+
d4e17e5
+      if (device->state == _CUPS_DNSSD_ACTIVE)
d4e17e5
+        completed ++;
d4e17e5
+
d4e17e5
+      if (!device->ref && device->state == _CUPS_DNSSD_NEW)
d4e17e5
+      {
d4e17e5
+	DEBUG_printf(("1cupsEnumDests2: Querying '%s'.", device->fullName));
d4e17e5
+
d4e17e5
+#  ifdef HAVE_DNSSD
d4e17e5
+        device->ref = data.main_ref;
d4e17e5
+
d4e17e5
+	if (DNSServiceQueryRecord(&(device->ref),
d4e17e5
+				  kDNSServiceFlagsShareConnection,
d4e17e5
+				  0, device->fullName,
d4e17e5
+				  kDNSServiceType_TXT,
d4e17e5
+				  kDNSServiceClass_IN,
d4e17e5
+				  (DNSServiceQueryRecordReply)cups_dnssd_query_cb,
d4e17e5
+				  &data) == kDNSServiceErr_NoError)
d4e17e5
+	{
d4e17e5
+	  count ++;
d4e17e5
+	}
d4e17e5
+	else
d4e17e5
+	{
d4e17e5
+	  device->ref   = 0;
d4e17e5
+	  device->state = _CUPS_DNSSD_ERROR;
d4e17e5
+
d4e17e5
+	  DEBUG_puts("1cupsEnumDests2: Query failed.");
d4e17e5
+	}
d4e17e5
+
d4e17e5
+#  else /* HAVE_AVAHI */
d4e17e5
+	if ((device->ref = avahi_record_browser_new(data.client, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, device->fullName, AVAHI_DNS_CLASS_IN, AVAHI_DNS_TYPE_TXT, 0, cups_dnssd_query_cb, &data)) != NULL)
d4e17e5
+        {
d4e17e5
+          DEBUG_printf(("1cupsEnumDests2: Query ref=%p", device->ref));
d4e17e5
+	  count ++;
d4e17e5
+	}
d4e17e5
+	else
d4e17e5
+	{
d4e17e5
+	  device->state = _CUPS_DNSSD_ERROR;
d4e17e5
+
d4e17e5
+	  DEBUG_printf(("1cupsEnumDests2: Query failed: %s", avahi_strerror(avahi_client_errno(data.client))));
d4e17e5
+	}
d4e17e5
+#  endif /* HAVE_DNSSD */
d4e17e5
+      }
d4e17e5
+      else if (device->ref && device->state == _CUPS_DNSSD_PENDING)
d4e17e5
+      {
d4e17e5
+        completed ++;
d4e17e5
+
d4e17e5
+        DEBUG_printf(("1cupsEnumDests2: Query for \"%s\" is complete.", device->fullName));
d4e17e5
+
d4e17e5
+        if ((device->type & mask) == type)
d4e17e5
+        {
d4e17e5
+	  DEBUG_printf(("1cupsEnumDests2: Add callback for \"%s\".", device->dest.name));
d4e17e5
+	  if (!(*cb)(user_data, CUPS_DEST_FLAGS_NONE, &device->dest))
d4e17e5
+	  {
d4e17e5
+	    remaining = -1;
d4e17e5
+	    break;
d4e17e5
+	  }
d4e17e5
+        }
d4e17e5
+
d4e17e5
+        device->state = _CUPS_DNSSD_ACTIVE;
d4e17e5
+      }
d4e17e5
+    }
d4e17e5
+
d4e17e5
+#  ifdef HAVE_AVAHI
d4e17e5
+    DEBUG_printf(("1cupsEnumDests2: remaining=%d, browsers=%d, completed=%d, count=%d, devices count=%d", remaining, data.browsers, completed, count, cupsArrayCount(data.devices)));
d4e17e5
+
d4e17e5
+    if (data.browsers == 0 && completed == cupsArrayCount(data.devices))
d4e17e5
+      break;
d4e17e5
+#  else
d4e17e5
+    DEBUG_printf(("1cupsEnumDests2: remaining=%d, completed=%d, count=%d, devices count=%d", remaining, completed, count, cupsArrayCount(data.devices)));
d4e17e5
+
d4e17e5
+    if (completed == cupsArrayCount(data.devices))
d4e17e5
+      break;
d4e17e5
+#  endif /* HAVE_AVAHI */
d4e17e5
+  }
d4e17e5
+#endif /* HAVE_DNSSD || HAVE_AVAHI */
d4e17e5
+
d4e17e5
+ /*
d4e17e5
+  * Return...
d4e17e5
+  */
d4e17e5
+
d4e17e5
+  enum_finished:
d4e17e5
+
d4e17e5
+#if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
d4e17e5
+  cupsArrayDelete(data.devices);
d4e17e5
+
d4e17e5
+#  ifdef HAVE_DNSSD
d4e17e5
+  if (ipp_ref)
d4e17e5
+    DNSServiceRefDeallocate(ipp_ref);
d4e17e5
+  if (local_ipp_ref)
d4e17e5
+    DNSServiceRefDeallocate(local_ipp_ref);
d4e17e5
+
d4e17e5
+#    ifdef HAVE_SSL
d4e17e5
+  if (ipps_ref)
d4e17e5
+    DNSServiceRefDeallocate(ipps_ref);
d4e17e5
+  if (local_ipps_ref)
d4e17e5
+    DNSServiceRefDeallocate(local_ipps_ref);
d4e17e5
+#    endif /* HAVE_SSL */
d4e17e5
+
d4e17e5
+  if (data.main_ref)
d4e17e5
+    DNSServiceRefDeallocate(data.main_ref);
d4e17e5
+
d4e17e5
+#  else /* HAVE_AVAHI */
d4e17e5
+  if (ipp_ref)
d4e17e5
+    avahi_service_browser_free(ipp_ref);
d4e17e5
+#    ifdef HAVE_SSL
d4e17e5
+  if (ipps_ref)
d4e17e5
+    avahi_service_browser_free(ipps_ref);
d4e17e5
+#    endif /* HAVE_SSL */
d4e17e5
+
d4e17e5
+  if (data.client)
d4e17e5
+    avahi_client_free(data.client);
d4e17e5
+  if (data.simple_poll)
d4e17e5
+    avahi_simple_poll_free(data.simple_poll);
d4e17e5
+#  endif /* HAVE_DNSSD */
d4e17e5
+#endif /* HAVE_DNSSD || HAVE_AVAHI */
d4e17e5
+
d4e17e5
+  return (1);
d4e17e5
+}
d4e17e5
+
d4e17e5
 
d4e17e5
 #  ifdef __BLOCKS__
d4e17e5
 /*
d4e17e5
@@ -1413,6 +1830,24 @@ cupsEnumDestsBlock(
d4e17e5
   return (cupsEnumDests(flags, timeout, cancel, type, mask,
d4e17e5
                         (cups_dest_cb_t)cups_block_cb, (void *)block));
d4e17e5
 }
d4e17e5
+
d4e17e5
+/*
d4e17e5
+ * 'cupsEnumDestsBlock2()' - same as cupsEnumDestsBlock(), only with non default http connection 
d4e17e5
+ */
d4e17e5
+
d4e17e5
+int					/* O - 1 on success, 0 on failure */
d4e17e5
+cupsEnumDestsBlock2(
d4e17e5
+    http_t            *http,		/* I - Connection to server@ */
d4e17e5
+    unsigned          flags,		/* I - Enumeration flags */
d4e17e5
+    int               timeout,		/* I - Timeout in milliseconds, 0 for indefinite */
d4e17e5
+    int               *cancel,		/* I - Pointer to "cancel" variable */
d4e17e5
+    cups_ptype_t      type,		/* I - Printer type bits */
d4e17e5
+    cups_ptype_t      mask,		/* I - Mask for printer type bits */
d4e17e5
+    cups_dest_block_t block)		/* I - Block */
d4e17e5
+{
d4e17e5
+  return (cupsEnumDests2(http, flags, timeout, cancel, type, mask,
d4e17e5
+                        (cups_dest_cb_t)cups_block_cb, (void *)block));
d4e17e5
+}
d4e17e5
 #  endif /* __BLOCKS__ */
d4e17e5
 
d4e17e5
 
d4e17e5
@@ -2057,7 +2492,13 @@ cupsGetDests2(http_t      *http,	/* I -
d4e17e5
   data.num_dests = 0;
d4e17e5
   data.dests     = NULL;
d4e17e5
 
d4e17e5
-  cupsEnumDests(0, 1000, NULL, 0, 0, (cups_dest_cb_t)cups_get_cb, &data);
d4e17e5
+  if (!http)
d4e17e5
+    http = CUPS_HTTP_DEFAULT;
d4e17e5
+
d4e17e5
+  if (http == CUPS_HTTP_DEFAULT)
d4e17e5
+    cupsEnumDests(0, 1000, NULL, 0, 0, (cups_dest_cb_t)cups_get_cb, &data);
d4e17e5
+  else
d4e17e5
+    cupsEnumDests2(http, 0, 1000, NULL, 0, 0, (cups_dest_cb_t)cups_get_cb, &data);
d4e17e5
 
d4e17e5
  /*
d4e17e5
   * Make a copy of the "real" queues for a later sanity check...
d4e17e5
diff -up cups-2.2.4/cups/util.c.cupsenumdests2 cups-2.2.4/cups/util.c
d4e17e5
--- cups-2.2.4/cups/util.c.cupsenumdests2	2017-06-30 17:44:38.000000000 +0200
d4e17e5
+++ cups-2.2.4/cups/util.c	2017-10-04 15:36:08.453828842 +0200
d4e17e5
@@ -197,7 +197,13 @@ cupsCreateJob(
d4e17e5
   data.name = name;
d4e17e5
   data.dest = NULL;
d4e17e5
 
d4e17e5
-  cupsEnumDests(0, 1000, NULL, 0, 0, (cups_dest_cb_t)cups_create_cb, &data);
d4e17e5
+  if (!http)
d4e17e5
+    http = CUPS_HTTP_DEFAULT;
d4e17e5
+
d4e17e5
+  if (http == CUPS_HTTP_DEFAULT)
d4e17e5
+    cupsEnumDests(0, 1000, NULL, 0, 0, (cups_dest_cb_t)cups_create_cb, &data);
d4e17e5
+  else
d4e17e5
+    cupsEnumDests2(http, 0, 1000, NULL, 0, 0, (cups_dest_cb_t)cups_create_cb, &data);
d4e17e5
 
d4e17e5
   if (!data.dest)
d4e17e5
   {