]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - backend/dnssd.c
Import CUPS v2.0.3
[thirdparty/cups.git] / backend / dnssd.c
index 742f9124c1a12903a483f996889c5cc13cf5918f..83f450959d8732f44cc8bf119c2e4be7ac3d9468 100644 (file)
@@ -1,9 +1,9 @@
 /*
- * "$Id: dnssd.c 11971 2014-07-01 14:38:29Z msweet $"
+ * "$Id: dnssd.c 12660 2015-05-22 19:09:57Z msweet $"
  *
  * DNS-SD discovery backend for CUPS.
  *
- * Copyright 2008-2014 by Apple Inc.
+ * Copyright 2008-2015 by Apple Inc.
  *
  * These coded instructions, statements, and computer programs are the
  * property of Apple Inc. and are protected by Federal copyright
@@ -61,7 +61,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? */
@@ -122,7 +123,7 @@ static void         client_callback(AvahiClient *client,
 #endif /* HAVE_AVAHI */
 
 static int             compare_devices(cups_device_t *a, cups_device_t *b);
-static void            exec_backend(char **argv);
+static void            exec_backend(char **argv) __attribute__((noreturn));
 static cups_device_t   *get_device(cups_array_t *devices,
                                    const char *serviceName,
                                    const char *regtype,
@@ -317,7 +318,7 @@ main(int  argc,                             /* I - Number of command-line args */
   if ((simple_poll = avahi_simple_poll_new()) == NULL)
   {
     fputs("DEBUG: Unable to create Avahi simple poll object.\n", stderr);
-    return (1);
+    return (0);
   }
 
   avahi_simple_poll_set_func(simple_poll, poll_callback, NULL);
@@ -327,7 +328,7 @@ main(int  argc,                             /* I - Number of command-line args */
   if (!client)
   {
     fputs("DEBUG: Unable to create Avahi client.\n", stderr);
-    return (1);
+    return (0);
   }
 
   browsers = 6;
@@ -499,9 +500,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);
@@ -532,9 +539,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);
@@ -817,8 +830,8 @@ exec_backend(char **argv)           /* I - Command-line arguments */
  * 'device_type()' - Get DNS-SD type enumeration from string.
  */
 
-static int
-device_type(const char *regtype)
+static cups_devtype_t                  /* O - Device type */
+device_type(const char *regtype)       /* I - Service registration type */
 {
 #ifdef HAVE_AVAHI
   if (!strcmp(regtype, "_ipp._tcp"))
@@ -909,9 +922,10 @@ get_device(cups_array_t *devices,  /* I - Device array */
   */
 
 #ifdef HAVE_DNSSD
-  fprintf(stderr, "DEBUG: Found \"%s.%s%s\"...\n", serviceName, regtype, replyDomain);
+  DNSServiceConstructFullName(fullName, serviceName, regtype, replyDomain);
 #else /* HAVE_AVAHI */
-  fprintf(stderr, "DEBUG: Found \"%s.%s.%s\"...\n", serviceName, regtype, replyDomain);
+  avahi_service_name_join(fullName, kDNSServiceMaxDomainName,
+                          serviceName, regtype, replyDomain);
 #endif /* HAVE_DNSSD */
 
   device           = calloc(sizeof(cups_device_t), 1);
@@ -1098,7 +1112,7 @@ query_callback(
     datanext = data + datalen;
 
     for (ptr = key; data < datanext && *data != '='; data ++)
-      *ptr++ = *data;
+      *ptr++ = (char)*data;
     *ptr = '\0';
 
     if (data < datanext && *data == '=')
@@ -1106,7 +1120,7 @@ query_callback(
       data ++;
 
       if (data < datanext)
-       memcpy(value, data, datanext - data);
+       memcpy(value, data, (size_t)(datanext - data));
       value[datanext - data] = '\0';
 
       fprintf(stderr, "DEBUG2: query_callback: \"%s=%s\".\n",
@@ -1126,8 +1140,7 @@ query_callback(
       */
 
       ptr = device_id + strlen(device_id);
-      snprintf(ptr, sizeof(device_id) - (ptr - device_id), "%s:%s;",
-              key + 4, value);
+      snprintf(ptr, sizeof(device_id) - (size_t)(ptr - device_id), "%s:%s;", key + 4, value);
     }
 
     if (!_cups_strcasecmp(key, "usb_MFG") || !_cups_strcasecmp(key, "usb_MANU") ||
@@ -1176,6 +1189,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)
@@ -1196,7 +1211,7 @@ query_callback(
       * Assume the first word is the make...
       */
 
-      memcpy(make_and_model, model, ptr - model);
+      memcpy(make_and_model, model, (size_t)(ptr - model));
       make_and_model[ptr - model] = '\0';
 
       snprintf(device_id, sizeof(device_id), "MFG:%s;MDL:%s",
@@ -1231,7 +1246,7 @@ query_callback(
       while (isalnum(*ptr & 255) || *ptr == '-' || *ptr == '.')
       {
         if (isalnum(*ptr & 255) && valptr < (value + sizeof(value) - 1))
-          *valptr++ = toupper(*ptr++ & 255);
+          *valptr++ = (char)toupper(*ptr++ & 255);
         else
           break;
       }
@@ -1240,8 +1255,7 @@ query_callback(
     }
 
     ptr = device_id + strlen(device_id);
-    snprintf(ptr, sizeof(device_id) - (ptr - device_id), "CMD:%s;",
-            value + 1);
+    snprintf(ptr, sizeof(device_id) - (size_t)(ptr - device_id), "CMD:%s;", value + 1);
   }
 
   if (device_id[0])
@@ -1316,5 +1330,5 @@ unquote(char       *dst,          /* I - Destination buffer */
 
 
 /*
- * End of "$Id: dnssd.c 11971 2014-07-01 14:38:29Z msweet $".
+ * End of "$Id: dnssd.c 12660 2015-05-22 19:09:57Z msweet $".
  */