]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - cups/dest.c
Fix source file header text duplication text duplication.
[thirdparty/cups.git] / cups / dest.c
index 554903facef52d1fba2f98db862b888c54b5e089..b06a9ee154b445dba9337f74209576d1f6cf2d4e 100644 (file)
@@ -1,16 +1,14 @@
 /*
- * "$Id$"
- *
  * User-defined destination (and option) support for CUPS.
  *
- * Copyright 2007-2015 by Apple Inc.
+ * Copyright 2007-2016 by Apple Inc.
  * Copyright 1997-2007 by Easy Software Products.
  *
  * These coded instructions, statements, and computer programs are the
  * 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/".
+ * missing or damaged, see the license at "http://www.cups.org/".
  *
  * This file is subject to the Apple OS-Developed Software exception.
  */
  */
 
 #ifdef __APPLE__
-#  include <SystemConfiguration/SystemConfiguration.h>
+#  if !TARGET_OS_IOS
+#    include <SystemConfiguration/SystemConfiguration.h>
+#    define _CUPS_LOCATION_DEFAULTS 1
+#  endif /* !TARGET_OS_IOS */
 #  define kCUPSPrintingPrefs   CFSTR("org.cups.PrintingPrefs")
 #  define kDefaultPaperIDKey   CFSTR("DefaultPaperID")
 #  define kLastUsedPrintersKey CFSTR("LastUsedPrinters")
@@ -119,13 +120,17 @@ typedef struct _cups_dnssd_resolve_s      /* Data for resolving URI */
  * Local functions...
  */
 
-#ifdef __APPLE__
+#if _CUPS_LOCATION_DEFAULTS
 static CFArrayRef      appleCopyLocations(void);
 static CFStringRef     appleCopyNetwork(void);
-static char            *appleGetPaperSize(char *name, int namesize);
+#endif /* _CUPS_LOCATION_DEFAULTS */
+#ifdef __APPLE__
+static char            *appleGetPaperSize(char *name, size_t namesize);
+#endif /* __APPLE__ */
+#if _CUPS_LOCATION_DEFAULTS
 static CFStringRef     appleGetPrinter(CFArrayRef locations,
                                        CFStringRef network, CFIndex *locindex);
-#endif /* __APPLE__ */
+#endif /* _CUPS_LOCATION_DEFAULTS */
 static cups_dest_t     *cups_add_dest(const char *name, const char *instance,
                                       int *num_dests, cups_dest_t **dests);
 #ifdef __BLOCKS__
@@ -309,6 +314,7 @@ _cupsAppleCopyDefaultPaperID(void)
 CFStringRef                            /* O - Default printer name */
 _cupsAppleCopyDefaultPrinter(void)
 {
+#  if _CUPS_LOCATION_DEFAULTS
   CFStringRef  network;                /* Network location */
   CFArrayRef   locations;              /* Location array */
   CFStringRef  locprinter;             /* Current printer */
@@ -365,6 +371,10 @@ _cupsAppleCopyDefaultPrinter(void)
   CFRelease(locations);
 
   return (locprinter);
+
+#  else
+  return (NULL);
+#  endif /* _CUPS_LOCATION_DEFAULTS */
 }
 
 
@@ -402,7 +412,10 @@ _cupsAppleSetDefaultPaperID(
 {
   CFPreferencesSetAppValue(kDefaultPaperIDKey, name, kCUPSPrintingPrefs);
   CFPreferencesAppSynchronize(kCUPSPrintingPrefs);
+
+#  ifdef HAVE_NOTIFY_POST
   notify_post("com.apple.printerPrefsChange");
+#  endif /* HAVE_NOTIFY_POST */
 }
 
 
@@ -414,6 +427,7 @@ void
 _cupsAppleSetDefaultPrinter(
     CFStringRef name)                  /* I - Default printer/class name */
 {
+#  if _CUPS_LOCATION_DEFAULTS
   CFStringRef          network;        /* Current network */
   CFArrayRef           locations;      /* Old locations array */
   CFIndex              locindex;       /* Index in locations array */
@@ -490,7 +504,10 @@ _cupsAppleSetDefaultPrinter(
       CFPreferencesSetAppValue(kLastUsedPrintersKey, newlocations,
                                kCUPSPrintingPrefs);
       CFPreferencesAppSynchronize(kCUPSPrintingPrefs);
+
+#  ifdef HAVE_NOTIFY_POST
       notify_post("com.apple.printerPrefsChange");
+#  endif /* HAVE_NOTIFY_POST */
     }
 
     if (newlocations)
@@ -504,6 +521,10 @@ _cupsAppleSetDefaultPrinter(
     CFRelease(locations);
 
   CFRelease(network);
+
+#  else
+  (void)name;
+#  endif /* _CUPS_LOCATION_DEFAULTS */
 }
 
 
@@ -519,7 +540,10 @@ _cupsAppleSetUseLastPrinter(
                           uselast ? kCFBooleanTrue : kCFBooleanFalse,
                           kCUPSPrintingPrefs);
   CFPreferencesAppSynchronize(kCUPSPrintingPrefs);
+
+#  ifdef HAVE_NOTIFY_POST
   notify_post("com.apple.printerPrefsChange");
+#  endif /* HAVE_NOTIFY_POST */
 }
 #endif /* __APPLE__ */
 
@@ -533,7 +557,7 @@ _cupsAppleSetUseLastPrinter(
  * to by "cancel" is non-zero, or the callback function (or block) returns 0,
  * The caller is responsible for calling httpClose() on the returned object.
  *
- * @since CUPS 1.6/OS X 10.8@
+ * @since CUPS 1.6/macOS 10.8@
  */
 
 http_t *                               /* O - Connection to server or @code NULL@ */
@@ -559,6 +583,8 @@ cupsConnectDest(
   http_t       *http;                  /* Connection to server */
 
 
+  DEBUG_printf(("cupsConnectDest(dest=%p, flags=0x%x, msec=%d, cancel=%p(%d), resource=\"%s\", resourcesize=" CUPS_LLFMT ", cb=%p, user_data=%p)", (void *)dest, flags, msec, (void *)cancel, cancel ? *cancel : -1, resource, CUPS_LLCAST resourcesize, (void *)cb, user_data));
+
  /*
   * Range check input...
   */
@@ -582,26 +608,39 @@ cupsConnectDest(
   * Grab the printer URI...
   */
 
-  if ((uri = cupsGetOption("printer-uri-supported", dest->num_options,
-                           dest->options)) == NULL)
+  if ((uri = cupsGetOption("printer-uri-supported", dest->num_options, dest->options)) == NULL)
   {
-    _cupsSetError(IPP_STATUS_ERROR_INTERNAL, strerror(ENOENT), 0);
+    if ((uri = cupsGetOption("resolved-device-uri", dest->num_options, dest->options)) == NULL)
+    {
+      if ((uri = cupsGetOption("device-uri", dest->num_options, dest->options)) != NULL)
+      {
+#if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
+        if (strstr(uri, "._tcp"))
+          uri = cups_dnssd_resolve(dest, uri, msec, cancel, cb, user_data);
+#endif /* HAVE_DNSSD || HAVE_AVAHI */
+      }
+    }
 
-    if (cb)
-      (*cb)(user_data, CUPS_DEST_FLAGS_UNCONNECTED | CUPS_DEST_FLAGS_ERROR,
-            dest);
+    if (uri)
+      uri = _cupsCreateDest(dest->name, cupsGetOption("printer-info", dest->num_options, dest->options), NULL, uri, tempresource, sizeof(tempresource));
 
-    return (NULL);
+    if (uri)
+    {
+      dest->num_options = cupsAddOption("printer-uri-supported", uri, dest->num_options, &dest->options);
+
+      uri = cupsGetOption("printer-uri-supported", dest->num_options, dest->options);
+    }
   }
 
-#if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
-  if (strstr(uri, "._tcp"))
+  if (!uri)
   {
-    if ((uri = cups_dnssd_resolve(dest, uri, msec, cancel, cb,
-                                  user_data)) == NULL)
-      return (NULL);
+    _cupsSetError(IPP_STATUS_ERROR_INTERNAL, strerror(ENOENT), 0);
+
+    if (cb)
+      (*cb)(user_data, CUPS_DEST_FLAGS_UNCONNECTED | CUPS_DEST_FLAGS_ERROR, dest);
+
+    return (NULL);
   }
-#endif /* HAVE_DNSSD || HAVE_AVAHI */
 
   if (httpSeparateURI(HTTP_URI_CODING_ALL, uri, scheme, sizeof(scheme),
                       userpass, sizeof(userpass), hostname, sizeof(hostname),
@@ -621,16 +660,14 @@ cupsConnectDest(
   */
 
   if (cb)
-    (*cb)(user_data, CUPS_DEST_FLAGS_UNCONNECTED | CUPS_DEST_FLAGS_RESOLVING,
-          dest);
+    (*cb)(user_data, CUPS_DEST_FLAGS_UNCONNECTED | CUPS_DEST_FLAGS_RESOLVING, dest);
 
   snprintf(portstr, sizeof(portstr), "%d", port);
 
   if ((addrlist = httpAddrGetList(hostname, AF_UNSPEC, portstr)) == NULL)
   {
     if (cb)
-      (*cb)(user_data, CUPS_DEST_FLAGS_UNCONNECTED | CUPS_DEST_FLAGS_ERROR,
-            dest);
+      (*cb)(user_data, CUPS_DEST_FLAGS_UNCONNECTED | CUPS_DEST_FLAGS_ERROR, dest);
 
     return (NULL);
   }
@@ -640,8 +677,7 @@ cupsConnectDest(
     httpAddrFreeList(addrlist);
 
     if (cb)
-      (*cb)(user_data, CUPS_DEST_FLAGS_UNCONNECTED | CUPS_DEST_FLAGS_CANCELED,
-            dest);
+      (*cb)(user_data, CUPS_DEST_FLAGS_UNCONNECTED | CUPS_DEST_FLAGS_CANCELED, dest);
 
     return (NULL);
   }
@@ -655,8 +691,7 @@ cupsConnectDest(
   else
     encryption = HTTP_ENCRYPTION_IF_REQUESTED;
 
-  http = httpConnect2(hostname, port, addrlist, AF_UNSPEC, encryption, 1, 0,
-                      NULL);
+  http = httpConnect2(hostname, port, addrlist, AF_UNSPEC, encryption, 1, 0, NULL);
   httpAddrFreeList(addrlist);
 
  /*
@@ -671,17 +706,14 @@ cupsConnectDest(
   else
   {
     if (cb)
-      (*cb)(user_data, CUPS_DEST_FLAGS_UNCONNECTED | CUPS_DEST_FLAGS_CONNECTING,
-            dest);
+      (*cb)(user_data, CUPS_DEST_FLAGS_UNCONNECTED | CUPS_DEST_FLAGS_CONNECTING, dest);
 
     if (!httpReconnect2(http, msec, cancel) && cb)
     {
       if (cancel && *cancel)
-       (*cb)(user_data,
-             CUPS_DEST_FLAGS_UNCONNECTED | CUPS_DEST_FLAGS_CONNECTING, dest);
+       (*cb)(user_data, CUPS_DEST_FLAGS_UNCONNECTED | CUPS_DEST_FLAGS_CONNECTING, dest);
       else
-       (*cb)(user_data, CUPS_DEST_FLAGS_UNCONNECTED | CUPS_DEST_FLAGS_ERROR,
-             dest);
+       (*cb)(user_data, CUPS_DEST_FLAGS_UNCONNECTED | CUPS_DEST_FLAGS_ERROR, dest);
     }
     else if (cb)
       (*cb)(user_data, CUPS_DEST_FLAGS_NONE, dest);
@@ -701,7 +733,7 @@ cupsConnectDest(
  * to by "cancel" is non-zero, or the callback function (or block) returns 0,
  * The caller is responsible for calling httpClose() on the returned object.
  *
- * @since CUPS 1.6/OS X 10.8@
+ * @since CUPS 1.6/macOS 10.8@
  */
 
 http_t *                               /* O - Connection to server or @code NULL@ */
@@ -727,7 +759,7 @@ cupsConnectDestBlock(
  * copy) - for use with the cupsEnumDests* functions. The caller is responsible
  * for calling cupsFreeDests() on the returned object(s).
  *
- * @since CUPS 1.6/OS X 10.8@
+ * @since CUPS 1.6/macOS 10.8@
  */
 
 int
@@ -795,6 +827,83 @@ cupsCopyDest(cups_dest_t *dest,
 }
 
 
+/*
+ * '_cupsCreateDest()' - Create a local (temporary) queue.
+ */
+
+char *                                 /* O - Printer URI or @code NULL@ on error */
+_cupsCreateDest(const char *name,      /* I - Printer name */
+                const char *info,      /* I - Printer description of @code NULL@ */
+               const char *device_id,  /* I - 1284 Device ID or @code NULL@ */
+               const char *device_uri, /* I - Device URI */
+               char       *uri,        /* I - Printer URI buffer */
+               size_t     urisize)     /* I - Size of URI buffer */
+{
+  http_t       *http;                  /* Connection to server */
+  ipp_t                *request,               /* CUPS-Create-Local-Printer request */
+               *response;              /* CUPS-Create-Local-Printer response */
+  ipp_attribute_t *attr;               /* printer-uri-supported attribute */
+  ipp_pstate_t state = IPP_PSTATE_STOPPED;
+                                       /* printer-state value */
+
+
+  if (!name || !device_uri || !uri || urisize < 32)
+    return (NULL);
+
+  if ((http = httpConnect2(cupsServer(), ippPort(), NULL, AF_UNSPEC, HTTP_ENCRYPTION_IF_REQUESTED, 1, 30000, NULL)) == NULL)
+    return (NULL);
+
+  request = ippNewRequest(IPP_OP_CUPS_CREATE_LOCAL_PRINTER);
+
+  ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL, "ipp://localhost/");
+  ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name", NULL, cupsUser());
+
+  ippAddString(request, IPP_TAG_PRINTER, IPP_TAG_URI, "device-uri", NULL, device_uri);
+  ippAddString(request, IPP_TAG_PRINTER, IPP_TAG_NAME, "printer-name", NULL, name);
+  if (info)
+    ippAddString(request, IPP_TAG_PRINTER, IPP_TAG_TEXT, "printer-info", NULL, info);
+  if (device_id)
+    ippAddString(request, IPP_TAG_PRINTER, IPP_TAG_TEXT, "printer-device-id", NULL, device_id);
+
+  response = cupsDoRequest(http, request, "/");
+
+  if ((attr = ippFindAttribute(response, "printer-uri-supported", IPP_TAG_URI)) != NULL)
+    strlcpy(uri, ippGetString(attr, 0, NULL), urisize);
+  else
+  {
+    ippDelete(response);
+    httpClose(http);
+    return (NULL);
+  }
+
+  if ((attr = ippFindAttribute(response, "printer-state", IPP_TAG_ENUM)) != NULL)
+    state = (ipp_pstate_t)ippGetInteger(attr, 0);
+
+  while (state == IPP_PSTATE_STOPPED && cupsLastError() == IPP_STATUS_OK)
+  {
+    sleep(1);
+    ippDelete(response);
+
+    request = ippNewRequest(IPP_OP_GET_PRINTER_ATTRIBUTES);
+
+    ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL, uri);
+    ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name", NULL, cupsUser());
+    ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD, "requested-attributes", NULL, "printer-state");
+
+    response = cupsDoRequest(http, request, "/");
+
+    if ((attr = ippFindAttribute(response, "printer-state", IPP_TAG_ENUM)) != NULL)
+      state = (ipp_pstate_t)ippGetInteger(attr, 0);
+  }
+
+  ippDelete(response);
+
+  httpClose(http);
+
+  return (uri);
+}
+
+
 /*
  * 'cupsEnumDests()' - Enumerate available destinations with a callback function.
  *
@@ -806,7 +915,7 @@ cupsCopyDest(cups_dest_t *dest,
  * Enumeration happens on the current thread and does not return until all
  * destinations have been enumerated or the callback function returns 0.
  *
- * @since CUPS 1.6/OS X 10.8@
+ * @since CUPS 1.6/macOS 10.8@
  */
 
 int                                    /* O - 1 on success, 0 on failure */
@@ -871,7 +980,7 @@ cupsEnumDests(
   */
 
   num_dests = _cupsGetDests(CUPS_HTTP_DEFAULT, IPP_OP_CUPS_GET_PRINTERS, NULL,
-                            &dests, type, mask);
+                            &dests, type, mask | CUPS_PRINTER_3D);
 
   if ((user_default = _cupsUserDefault(name, sizeof(name))) != NULL)
     defprinter = name;
@@ -1141,7 +1250,7 @@ cupsEnumDests(
  * Enumeration happens on the current thread and does not return until all
  * destinations have been enumerated or the block returns 0.
  *
- * @since CUPS 1.6/OS X 10.8@
+ * @since CUPS 1.6/macOS 10.8@
  */
 
 int                                    /* O - 1 on success, 0 on failure */
@@ -1311,7 +1420,7 @@ _cupsGetDestResource(
  *
  * "uri" is the "ipp" or "ipps" URI for the printer.
  *
- * @since CUPS 2.0/OS X 10.10@
+ * @since CUPS 2.0/macOS 10.10@
  */
 
 cups_dest_t *                          /* O - Destination or @code NULL@ */
@@ -1390,7 +1499,7 @@ cupsGetDestWithURI(const char *name,      /* I - Desired printer name or @code NULL@
   }
 
   dest->name        = _cupsStrAlloc(name);
-  dest->num_options = cupsAddOption("printer-uri-supported", uri, dest->num_options, &(dest->options));
+  dest->num_options = cupsAddOption("device-uri", uri, dest->num_options, &(dest->options));
   dest->num_options = cupsAddOption("printer-info", name, dest->num_options, &(dest->options));
 
   return (dest);
@@ -1415,7 +1524,7 @@ cupsGetDestWithURI(const char *name,      /* I - Desired printer name or @code NULL@
  * Free the memory used by the destination array using the @link cupsFreeDests@
  * function.
  *
- * Note: On OS X this function also gets the default paper from the system
+ * Note: On macOS this function also gets the default paper from the system
  * preferences (~/L/P/org.cups.PrintingPrefs.plist) and includes it in the
  * options array for each destination that supports it.
  */
@@ -1708,7 +1817,7 @@ cupsGetDests(cups_dest_t **dests) /* O - Destinations */
  * Use the @link cupsFreeDests@ function to free the destination list and
  * the @link cupsGetDest@ function to find a particular destination.
  *
- * @since CUPS 1.1.21/OS X 10.4@
+ * @since CUPS 1.1.21/macOS 10.4@
  */
 
 int                                    /* O - Number of destinations */
@@ -1743,7 +1852,7 @@ cupsGetDests2(http_t      *http,  /* I - Connection to server or @code CUPS_HTTP_
   */
 
   *dests    = (cups_dest_t *)0;
-  num_dests = _cupsGetDests(http, IPP_OP_CUPS_GET_PRINTERS, NULL, dests, 0, 0);
+  num_dests = _cupsGetDests(http, IPP_OP_CUPS_GET_PRINTERS, NULL, dests, 0, CUPS_PRINTER_3D);
 
   if (cupsLastError() >= IPP_STATUS_REDIRECTION_OTHER_SITE)
   {
@@ -1885,7 +1994,7 @@ cupsGetDests2(http_t      *http,  /* I - Connection to server or @code CUPS_HTTP_
  * The returned destination must be freed using @link cupsFreeDests@ with a
  * "num_dests" value of 1.
  *
- * @since CUPS 1.4/OS X 10.6@
+ * @since CUPS 1.4/macOS 10.6@
  */
 
 cups_dest_t *                          /* O - Destination or @code NULL@ */
@@ -1960,7 +2069,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, 0))
+  if (!_cupsGetDests(http, op, name, &dest, 0, CUPS_PRINTER_3D))
     return (NULL);
 
   if (instance)
@@ -1999,7 +2108,7 @@ cupsGetNamedDest(http_t     *http,        /* I - Connection to server or @code CUPS_HTT
  * @link cupsSetDests@ or @link cupsSetDests2@ functions to save the new
  * options for the user.
  *
- * @since CUPS 1.3/OS X 10.5@
+ * @since CUPS 1.3/macOS 10.5@
  */
 
 int                                    /* O  - New number of destinations */
@@ -2045,7 +2154,7 @@ cupsRemoveDest(const char  *name, /* I  - Destination name */
 /*
  * 'cupsSetDefaultDest()' - Set the default destination.
  *
- * @since CUPS 1.3/OS X 10.5@
+ * @since CUPS 1.3/macOS 10.5@
  */
 
 void
@@ -2100,7 +2209,7 @@ cupsSetDests(int         num_dests,       /* I - Number of destinations */
  * This function saves the destinations to /etc/cups/lpoptions when run
  * as root and ~/.cups/lpoptions when run as a normal user.
  *
- * @since CUPS 1.1.21/OS X 10.4@
+ * @since CUPS 1.1.21/macOS 10.4@
  */
 
 int                                    /* O - 0 on success, -1 on error */
@@ -2136,7 +2245,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, 0);
+  num_temps = _cupsGetDests(http, IPP_OP_CUPS_GET_PRINTERS, NULL, &temps, 0, CUPS_PRINTER_3D);
 
   if (cupsLastError() >= IPP_STATUS_REDIRECTION_OTHER_SITE)
   {
@@ -2326,7 +2435,7 @@ cupsSetDests2(http_t      *http,  /* I - Connection to server or @code CUPS_HTTP_
 
 #ifdef HAVE_NOTIFY_POST
  /*
-  * Send a notification so that MacOS X applications can know about the
+  * Send a notification so that macOS applications can know about the
   * change, too.
   */
 
@@ -2391,7 +2500,7 @@ _cupsUserDefault(char   *name,            /* I - Name buffer */
 }
 
 
-#ifdef __APPLE__
+#if _CUPS_LOCATION_DEFAULTS
 /*
  * 'appleCopyLocations()' - Copy the location history array.
  */
@@ -2484,15 +2593,17 @@ appleCopyNetwork(void)
 
   return (network);
 }
+#endif /* _CUPS_LOCATION_DEFAULTS */
 
 
+#ifdef __APPLE__
 /*
  * 'appleGetPaperSize()' - Get the default paper size.
  */
 
 static char *                          /* O - Default paper size */
-appleGetPaperSize(char *name,          /* I - Paper size name buffer */
-                  int  namesize)       /* I - Size of buffer */
+appleGetPaperSize(char   *name,                /* I - Paper size name buffer */
+                  size_t namesize)     /* I - Size of buffer */
 {
   CFStringRef  defaultPaperID;         /* Default paper ID */
   pwg_media_t  *pwgmedia;              /* PWG media size */
@@ -2501,8 +2612,7 @@ appleGetPaperSize(char *name,             /* I - Paper size name buffer */
   defaultPaperID = _cupsAppleCopyDefaultPaperID();
   if (!defaultPaperID ||
       CFGetTypeID(defaultPaperID) != CFStringGetTypeID() ||
-      !CFStringGetCString(defaultPaperID, name, namesize,
-                         kCFStringEncodingUTF8))
+      !CFStringGetCString(defaultPaperID, name, (CFIndex)namesize, kCFStringEncodingUTF8))
     name[0] = '\0';
   else if ((pwgmedia = pwgMediaForLegacy(name)) != NULL)
     strlcpy(name, pwgmedia->pwg, namesize);
@@ -2512,8 +2622,10 @@ appleGetPaperSize(char *name,            /* I - Paper size name buffer */
 
   return (name);
 }
+#endif /* __APPLE__ */
 
 
+#if _CUPS_LOCATION_DEFAULTS
 /*
  * 'appleGetPrinter()' - Get a printer from the history array.
  */
@@ -2551,7 +2663,7 @@ appleGetPrinter(CFArrayRef  locations,    /* I - Location array */
 
   return (NULL);
 }
-#endif /* __APPLE__ */
+#endif /* _CUPS_LOCATION_DEFAULTS */
 
 
 /*
@@ -2681,11 +2793,7 @@ cups_dnssd_browse_cb(
                                        /* Enumeration data */
 
 
-  DEBUG_printf(("5cups_dnssd_browse_cb(sdRef=%p, flags=%x, "
-               "interfaceIndex=%d, errorCode=%d, serviceName=\"%s\", "
-               "regtype=\"%s\", replyDomain=\"%s\", context=%p)",
-               sdRef, flags, interfaceIndex, errorCode, serviceName, regtype,
-               replyDomain, context));
+  DEBUG_printf(("5cups_dnssd_browse_cb(sdRef=%p, flags=%x, interfaceIndex=%d, errorCode=%d, serviceName=\"%s\", regtype=\"%s\", replyDomain=\"%s\", context=%p)", (void *)sdRef, flags, interfaceIndex, errorCode, serviceName, regtype, replyDomain, context));
 
  /*
   * Don't do anything on error...
@@ -2822,8 +2930,7 @@ cups_dnssd_free_device(
     _cups_dnssd_device_t *device,      /* I - Device */
     _cups_dnssd_data_t   *data)                /* I - Enumeration data */
 {
-  DEBUG_printf(("5cups_dnssd_free_device(device=%p(%s), data=%p)", device,
-                device->dest.name, data));
+  DEBUG_printf(("5cups_dnssd_free_device(device=%p(%s), data=%p)", (void *)device, device->dest.name, (void *)data));
 
 #  ifdef HAVE_DNSSD
   if (device->ref)
@@ -2861,9 +2968,7 @@ cups_dnssd_get_device(
                                        /* Full name for query */
 
 
-  DEBUG_printf(("5cups_dnssd_get_device(data=%p, serviceName=\"%s\", "
-                "regtype=\"%s\", replyDomain=\"%s\")", data, serviceName,
-                regtype, replyDomain));
+  DEBUG_printf(("5cups_dnssd_get_device(data=%p, serviceName=\"%s\", regtype=\"%s\", replyDomain=\"%s\")", (void *)data, serviceName, regtype, replyDomain));
 
  /*
   * See if this is an existing device...
@@ -2994,11 +3099,7 @@ cups_dnssd_local_cb(
   _cups_dnssd_device_t *device;        /* Device */
 
 
-  DEBUG_printf(("5cups_dnssd_local_cb(sdRef=%p, flags=%x, "
-               "interfaceIndex=%d, errorCode=%d, serviceName=\"%s\", "
-               "regtype=\"%s\", replyDomain=\"%s\", context=%p)",
-               sdRef, flags, interfaceIndex, errorCode, serviceName,
-               regtype, replyDomain, context));
+  DEBUG_printf(("5cups_dnssd_local_cb(sdRef=%p, flags=%x, interfaceIndex=%d, errorCode=%d, serviceName=\"%s\", regtype=\"%s\", replyDomain=\"%s\", context=%p)", (void *)sdRef, flags, interfaceIndex, errorCode, serviceName, regtype, replyDomain, context));
 
  /*
   * Only process "add" data...
@@ -3120,11 +3221,7 @@ cups_dnssd_query_cb(
 
 
 #  ifdef HAVE_DNSSD
-  DEBUG_printf(("5cups_dnssd_query_cb(sdRef=%p, flags=%x, "
-               "interfaceIndex=%d, errorCode=%d, fullName=\"%s\", "
-               "rrtype=%u, rrclass=%u, rdlen=%u, rdata=%p, ttl=%u, "
-               "context=%p)", sdRef, flags, interfaceIndex, errorCode,
-               fullName, rrtype, rrclass, rdlen, rdata, ttl, context));
+  DEBUG_printf(("5cups_dnssd_query_cb(sdRef=%p, flags=%x, interfaceIndex=%d, errorCode=%d, fullName=\"%s\", rrtype=%u, rrclass=%u, rdlen=%u, rdata=%p, ttl=%u, context=%p)", (void *)sdRef, flags, interfaceIndex, errorCode, fullName, rrtype, rrclass, rdlen, rdata, ttl, context));
 
  /*
   * Only process "add" data...
@@ -3270,22 +3367,28 @@ cups_dnssd_query_cb(
         */
 
         const char     *start, *next;  /* Pointer into value */
-        int            have_pdf = 0;   /* Have PDF? */
+        int            have_pdf = 0,   /* Have PDF? */
+                       have_raster = 0;/* Have raster format support? */
 
         for (start = value; start && *start; start = next)
         {
-          if (!_cups_strncasecmp(start, "application/pdf", 15) &&
-              (!start[15] || start[15] == ','))
+          if (!_cups_strncasecmp(start, "application/pdf", 15) && (!start[15] || start[15] == ','))
           {
             have_pdf = 1;
             break;
           }
+          else if ((!_cups_strncasecmp(start, "image/pwg-raster", 16) && (!start[16] || start[16] == ',')) ||
+                  (!_cups_strncasecmp(start, "image/urf", 9) && (!start[9] || start[9] == ',')))
+          {
+            have_raster = 1;
+            break;
+          }
 
           if ((next = strchr(start, ',')) != NULL)
             next ++;
         }
 
-        if (!have_pdf)
+        if (!have_pdf && !have_raster)
           device->state = _CUPS_DNSSD_INCOMPATIBLE;
       }
       else if (!_cups_strcasecmp(key, "printer-type"))
@@ -3351,31 +3454,21 @@ cups_dnssd_query_cb(
     * Save the printer-xxx values...
     */
 
-    device->dest.num_options = cupsAddOption("printer-info", name,
-                                            device->dest.num_options,
-                                            &device->dest.options);
+    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));
       strlcat(make_and_model, model, sizeof(make_and_model));
 
-      device->dest.num_options = cupsAddOption("printer-make-and-model",
-                                              make_and_model,
-                                              device->dest.num_options,
-                                              &device->dest.options);
+      device->dest.num_options = cupsAddOption("printer-make-and-model", make_and_model, device->dest.num_options, &device->dest.options);
     }
     else
-      device->dest.num_options = cupsAddOption("printer-make-and-model",
-                                              model,
-                                              device->dest.num_options,
-                                              &device->dest.options);
+      device->dest.num_options = cupsAddOption("printer-make-and-model", model, 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);
+    device->dest.num_options = cupsAddOption("printer-type", value, device->dest.num_options, &device->dest.options);
 
    /*
     * Save the URI...
@@ -3386,11 +3479,9 @@ cups_dnssd_query_cb(
                     !strcmp(device->regtype, "_ipps._tcp") ? "ipps" : "ipp",
                     NULL, uriname, 0, saw_printer_type ? "/cups" : "/");
 
-    DEBUG_printf(("6cups_dnssd_query: printer-uri-supported=\"%s\"", uri));
+    DEBUG_printf(("6cups_dnssd_query: device-uri=\"%s\"", uri));
 
-    device->dest.num_options = cupsAddOption("printer-uri-supported", uri,
-                                            device->dest.num_options,
-                                            &device->dest.options);
+    device->dest.num_options = cupsAddOption("device-uri", uri, device->dest.num_options, &device->dest.options);
   }
   else
     DEBUG_printf(("6cups_dnssd_query: Ignoring TXT record for '%s'.",
@@ -3436,18 +3527,14 @@ cups_dnssd_resolve(
     resolve.end_time.tv_sec += 75;
 
   if (cb)
-    (*cb)(user_data, CUPS_DEST_FLAGS_UNCONNECTED | CUPS_DEST_FLAGS_RESOLVING,
-         dest);
+    (*cb)(user_data, CUPS_DEST_FLAGS_UNCONNECTED | CUPS_DEST_FLAGS_RESOLVING, dest);
 
-  if ((uri = _httpResolveURI(uri, tempuri, sizeof(tempuri),
-                            _HTTP_RESOLVE_FQDN, cups_dnssd_resolve_cb,
-                            &resolve)) == NULL)
+  if ((uri = _httpResolveURI(uri, tempuri, sizeof(tempuri), _HTTP_RESOLVE_DEFAULT, cups_dnssd_resolve_cb, &resolve)) == NULL)
   {
     _cupsSetError(IPP_STATUS_ERROR_INTERNAL, _("Unable to resolve printer-uri."), 1);
 
     if (cb)
-      (*cb)(user_data, CUPS_DEST_FLAGS_UNCONNECTED | CUPS_DEST_FLAGS_ERROR,
-           dest);
+      (*cb)(user_data, CUPS_DEST_FLAGS_UNCONNECTED | CUPS_DEST_FLAGS_ERROR, dest);
 
     return (NULL);
   }
@@ -3456,11 +3543,9 @@ cups_dnssd_resolve(
   * Save the resolved URI...
   */
 
-  dest->num_options = cupsAddOption("printer-uri-supported", uri,
-                                   dest->num_options, &dest->options);
+  dest->num_options = cupsAddOption("resolved-device-uri", uri, dest->num_options, &dest->options);
 
-  return (cupsGetOption("printer-uri-supported", dest->num_options,
-                        dest->options));
+  return (cupsGetOption("resolved-device-uri", dest->num_options, dest->options));
 }
 
 
@@ -3480,8 +3565,11 @@ cups_dnssd_resolve_cb(void *context)     /* I - Resolve data */
   * If the cancel variable is set, return immediately.
   */
 
-  if (*resolve->cancel)
+  if (resolve->cancel && *(resolve->cancel))
+  {
+    DEBUG_puts("4cups_dnssd_resolve_cb: Canceled.");
     return (0);
+  }
 
  /*
   * Otherwise check the end time...
@@ -3489,9 +3577,11 @@ cups_dnssd_resolve_cb(void *context)     /* I - Resolve data */
 
   gettimeofday(&curtime, NULL);
 
-  return (curtime.tv_sec > resolve->end_time.tv_sec ||
+  DEBUG_printf(("4cups_dnssd_resolve_cb: curtime=%d.%06d, end_time=%d.%06d", (int)curtime.tv_sec, (int)curtime.tv_usec, (int)resolve->end_time.tv_sec, (int)resolve->end_time.tv_usec));
+
+  return (curtime.tv_sec < resolve->end_time.tv_sec ||
           (curtime.tv_sec == resolve->end_time.tv_sec &&
-           curtime.tv_usec > resolve->end_time.tv_usec));
+           curtime.tv_usec < resolve->end_time.tv_usec));
 }
 
 
@@ -3705,10 +3795,7 @@ cups_get_dests(
   int          linenum;                /* Current line number */
 
 
-  DEBUG_printf(("7cups_get_dests(filename=\"%s\", match_name=\"%s\", "
-                "match_inst=\"%s\", user_default_set=%d, num_dests=%d, "
-               "dests=%p)", filename, match_name, match_inst,
-               user_default_set, num_dests, dests));
+  DEBUG_printf(("7cups_get_dests(filename=\"%s\", match_name=\"%s\", match_inst=\"%s\", user_default_set=%d, num_dests=%d, dests=%p)", filename, match_name, match_inst, user_default_set, num_dests, (void *)dests));
 
  /*
   * Try to open the file...
@@ -3940,8 +4027,3 @@ cups_make_string(
 
   return (buffer);
 }
-
-
-/*
- * End of "$Id$".
- */