]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - backend/dnssd.c
Fix build errors on Fedora.
[thirdparty/cups.git] / backend / dnssd.c
index 9cea92e037d2849655532afe16caa033699760c1..44084e3ed8b56b02b8d30a9f206f1ac1bfe1ffbf 100644 (file)
@@ -1,33 +1,17 @@
 /*
  * "$Id$"
  *
- *   DNS-SD discovery backend for CUPS.
+ * DNS-SD discovery backend for CUPS.
  *
- *   Copyright 2008-2012 by Apple Inc.
+ * Copyright 2008-2014 by Apple Inc.
  *
- *   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"
- *   "LICENSE" which should have been included with this file.  If this
- *   file is missing or damaged, see the license at "http://www.cups.org/".
+ * 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"
+ * "LICENSE" which should have been included with this file.  If this
+ * file is missing or damaged, see the license at "http://www.cups.org/".
  *
- *   This file is subject to the Apple OS-Developed Software exception.
- *
- * Contents:
- *
- *   main()                 - Browse for printers.
- *   browse_callback()      - Browse devices.
- *   browse_local_callback() - Browse local devices.
- *   client_callback()       - Avahi client callback function.
- *   compare_devices()      - Compare two devices.
- *   exec_backend()         - Execute the backend that corresponds to the
- *                            resolved service name.
- *   device_type()          - Get DNS-SD type enumeration from string.
- *   get_device()           - Create or update a device.
- *   query_callback()       - Process query data.
- *   find_device()          - Find a device from its name and domain.
- *   sigterm_handler()      - Handle termination signals.
- *   unquote()              - Unquote a name string.
+ * This file is subject to the Apple OS-Developed Software exception.
  */
 
 /*
@@ -77,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? */
@@ -137,7 +122,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,
@@ -513,9 +498,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 +537,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);
@@ -824,8 +821,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"))
@@ -1102,7 +1099,7 @@ query_callback(
     datanext = data + datalen;
 
     for (ptr = key; data < datanext && *data != '='; data ++)
-      *ptr++ = *data;
+      *ptr++ = (char)*data;
     *ptr = '\0';
 
     if (data < datanext && *data == '=')
@@ -1110,7 +1107,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",
@@ -1130,8 +1127,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") ||
@@ -1180,6 +1176,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)
@@ -1200,7 +1198,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",
@@ -1235,7 +1233,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;
       }
@@ -1244,8 +1242,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])