]> git.ipfire.org Git - thirdparty/cups.git/commitdiff
<rdar://problem/14672918> Use UUID from dnssd URI to identify instance of printer
authormsweet <msweet@a1ca3aef-8c08-0410-bb20-df032aa958be>
Wed, 4 Sep 2013 20:35:42 +0000 (20:35 +0000)
committermsweet <msweet@a1ca3aef-8c08-0410-bb20-df032aa958be>
Wed, 4 Sep 2013 20:35:42 +0000 (20:35 +0000)
Report UUID (if any) and use it to find a matching printer.

git-svn-id: svn+ssh://src.apple.com/svn/cups/cups.org/trunk@11270 a1ca3aef-8c08-0410-bb20-df032aa958be

backend/dnssd.c
cups/http-support.c

index 9cea92e037d2849655532afe16caa033699760c1..1ac000f37f173794835c69fb671380fa3a6c071c 100644 (file)
@@ -77,7 +77,8 @@ typedef struct
                *domain,                /* Domain name */
                *fullName,              /* Full name */
                *make_and_model,        /* Make and model from TXT record */
-               *device_id;             /* 1284 device ID from TXT record */
+               *device_id,             /* 1284 device ID from TXT record */
+               *uuid;                  /* UUID from TXT record */
   cups_devtype_t type;                 /* Device registration type */
   int          priority,               /* Priority associated with type */
                cups_shared,            /* CUPS shared printer? */
@@ -513,9 +514,15 @@ main(int  argc,                            /* I - Number of command-line args */
           {
            unquote(uriName, best->fullName, sizeof(uriName));
 
-           httpAssembleURI(HTTP_URI_CODING_ALL, device_uri, sizeof(device_uri),
-                           "dnssd", NULL, uriName, 0,
-                           best->cups_shared ? "/cups" : "/");
+            if (best->uuid)
+             httpAssembleURIf(HTTP_URI_CODING_ALL, device_uri,
+                              sizeof(device_uri), "dnssd", NULL, uriName, 0,
+                              best->cups_shared ? "/cups?uuid=%s" : "/?uuid=%s",
+                              best->uuid);
+           else
+             httpAssembleURI(HTTP_URI_CODING_ALL, device_uri,
+                             sizeof(device_uri), "dnssd", NULL, uriName, 0,
+                             best->cups_shared ? "/cups" : "/");
 
            cupsBackendReport("network", device_uri, best->make_and_model,
                              best->name, best->device_id, NULL);
@@ -546,9 +553,15 @@ main(int  argc,                            /* I - Number of command-line args */
       {
        unquote(uriName, best->fullName, sizeof(uriName));
 
-       httpAssembleURI(HTTP_URI_CODING_ALL, device_uri, sizeof(device_uri),
-                       "dnssd", NULL, uriName, 0,
-                       best->cups_shared ? "/cups" : "/");
+       if (best->uuid)
+         httpAssembleURIf(HTTP_URI_CODING_ALL, device_uri,
+                          sizeof(device_uri), "dnssd", NULL, uriName, 0,
+                          best->cups_shared ? "/cups?uuid=%s" : "/?uuid=%s",
+                          best->uuid);
+       else
+         httpAssembleURI(HTTP_URI_CODING_ALL, device_uri,
+                         sizeof(device_uri), "dnssd", NULL, uriName, 0,
+                         best->cups_shared ? "/cups" : "/");
 
        cupsBackendReport("network", device_uri, best->make_and_model,
                          best->name, best->device_id, NULL);
@@ -1180,6 +1193,8 @@ query_callback(
       if (device->type == CUPS_DEVICE_PRINTER)
        device->sent = 1;
     }
+    else if (!_cups_strcasecmp(key, "UUID"))
+      device->uuid = strdup(value);
   }
 
   if (device->device_id)
index bec39d0f4dd7b48bb017bddac3f4340e6b2b798a..a0496a4ab22d5ec23c07a699504d775464aaed82 100644 (file)
@@ -86,6 +86,7 @@ typedef struct _http_uribuf_s         /* URI buffer */
   size_t               bufsize;        /* Size of buffer */
   int                  options;        /* Options passed to _httpResolveURI */
   const char           *resource;      /* Resource from URI */
+  const char           *uuid;          /* UUID from URI */
 } _http_uribuf_t;
 
 
@@ -1556,7 +1557,9 @@ _httpResolveURI(
   {
 #if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
     char               *regtype,       /* Pointer to type in hostname */
-                       *domain;        /* Pointer to domain in hostname */
+                       *domain,        /* Pointer to domain in hostname */
+                       *uuid,          /* Pointer to UUID in URI */
+                       *uuidend;       /* Pointer to end of UUID in URI */
     _http_uribuf_t     uribuf;         /* URI buffer */
     int                        offline = 0;    /* offline-report state set? */
 #  ifdef HAVE_DNSSD
@@ -1613,12 +1616,21 @@ _httpResolveURI(
     if (domain)
       *domain++ = '\0';
 
+    if ((uuid = strstr(resource, "?uuid=")) != NULL)
+    {
+      *uuid = '\0';
+      uuid  += 6;
+      if ((uuidend = strchr(uuid, '&')) != NULL)
+        *uuidend = '\0';
+    }
+
+    resolved_uri[0] = '\0';
+
     uribuf.buffer   = resolved_uri;
     uribuf.bufsize  = resolved_size;
     uribuf.options  = options;
     uribuf.resource = resource;
-
-    resolved_uri[0] = '\0';
+    uribuf.uuid     = uuid;
 
     DEBUG_printf(("6_httpResolveURI: Resolving hostname=\"%s\", regtype=\"%s\", "
                   "domain=\"%s\"\n", hostname, regtype, domain));
@@ -1737,7 +1749,8 @@ _httpResolveURI(
          }
          else
          {
-           if (DNSServiceProcessResult(ref) == kDNSServiceErr_NoError)
+           if (DNSServiceProcessResult(ref) == kDNSServiceErr_NoError &&
+               resolved_uri[0])
            {
              uri = resolved_uri;
              break;
@@ -2050,6 +2063,34 @@ http_resolve_cb(
                interfaceIndex, errorCode, fullName, hostTarget, port, txtLen,
                txtRecord, context));
 
+ /*
+  * If we have a UUID, compare it...
+  */
+
+  if (uribuf->uuid &&
+      (value = TXTRecordGetValuePtr(txtLen, txtRecord, "UUID",
+                                    &valueLen)) != NULL)
+  {
+    char       uuid[256];              /* UUID value */
+
+    memcpy(uuid, value, valueLen);
+    uuid[valueLen] = '\0';
+
+    if (_cups_strcasecmp(uuid, uribuf->uuid))
+    {
+      if (uribuf->options & _HTTP_RESOLVE_STDERR)
+      {
+       _cupsLangPrintFilter(stderr, "INFO", _("Still looking for printer."));
+       fprintf(stderr, "DEBUG: Found UUID %s, looking for %s.", uuid,
+               uribuf->uuid);
+      }
+
+      DEBUG_printf(("7http_resolve_cb: Found UUID %s, looking for %s.", uuid,
+                    uribuf->uuid));
+      return;
+    }
+  }
+
  /*
   * Figure out the scheme from the full name...
   */
@@ -2254,6 +2295,34 @@ http_resolve_cb(
     return;
   }
 
+ /*
+  * If we have a UUID, compare it...
+  */
+
+  if (uribuf->uuid && (pair = avahi_string_list_find(txt, "UUID")) != NULL)
+  {
+    char       uuid[256];              /* UUID value */
+
+    avahi_string_list_get_pair(pair, NULL, &value, &valueLen);
+
+    memcpy(uuid, value, valueLen);
+    uuid[valueLen] = '\0';
+
+    if (_cups_strcasecmp(uuid, uribuf->uuid))
+    {
+      if (uribuf->options & _HTTP_RESOLVE_STDERR)
+      {
+       _cupsLangPrintFilter(stderr, "INFO", _("Still looking for printer."));
+       fprintf(stderr, "DEBUG: Found UUID %s, looking for %s.", uuid,
+               uribuf->uuid);
+      }
+
+      DEBUG_printf(("7http_resolve_cb: Found UUID %s, looking for %s.", uuid,
+                    uribuf->uuid));
+      return;
+    }
+  }
+
  /*
   * Figure out the scheme from the full name...
   */
@@ -2291,7 +2360,8 @@ http_resolve_cb(
   */
 
   if ((uribuf->options & _HTTP_RESOLVE_FAXOUT) &&
-      (!strcmp(scheme, "ipp") || !strcmp(scheme, "ipps")))
+      (!strcmp(scheme, "ipp") || !strcmp(scheme, "ipps")) &&
+      !avahi_string_list_find(txt, "printer-type"))
   {
     reskey     = "rfo";
     resdefault = "/ipp/faxout";