dd27f80
diff -up cups-1.4.0/backend/dnssd.c.avahi cups-1.4.0/backend/dnssd.c
dd27f80
--- cups-1.4.0/backend/dnssd.c.avahi	2009-08-07 23:27:12.000000000 +0100
081f3eb
+++ cups-1.4.0/backend/dnssd.c	2009-09-04 14:57:04.730388833 +0100
111438e
@@ -22,6 +22,7 @@
a1088d0
  *   exec_backend()          - Execute the backend that corresponds to the
a1088d0
  *                             resolved service name.
b85fafd
  *   get_device()            - Create or update a device.
111438e
+*    find_device()
111438e
  *   query_callback()        - Process query data.
111438e
  *   sigterm_handler()       - Handle termination signals...
b85fafd
  *   unquote()               - Unquote a name string.
111438e
@@ -33,7 +34,18 @@
b85fafd
 
b85fafd
 #include "backend-private.h"
b85fafd
 #include <cups/array.h>
b85fafd
-#include <dns_sd.h>
111438e
+#ifdef HAVE_DNSSD
111438e
+#  include <dns_sd.h>
111438e
+#endif /* HAVE_DNSSD */
b85fafd
+#ifdef HAVE_AVAHI
111438e
+#  include <avahi-client/client.h>
111438e
+#  include <avahi-client/lookup.h>
111438e
+#  include <avahi-common/simple-watch.h>
111438e
+#  include <avahi-common/domain.h>
111438e
+#  include <avahi-common/error.h>
111438e
+#  include <avahi-common/malloc.h>
b85fafd
+#define kDNSServiceMaxDomainName AVAHI_DOMAIN_NAME_MAX
111438e
+#endif /* HAVE_AVAHI */
b85fafd
 
b85fafd
 
b85fafd
 /*
081f3eb
@@ -52,7 +64,12 @@ typedef enum
b85fafd
 
b85fafd
 typedef struct
b85fafd
 {
b85fafd
+#ifdef HAVE_DNSSD
b85fafd
   DNSServiceRef	ref;			/* Service reference for resolve */
b85fafd
+#endif /* HAVE_DNSSD */
081f3eb
+#ifdef HAVE_AVAHI
081f3eb
+  int		resolved;		/* Did we resolve the device? */
081f3eb
+#endif /* HAVE_AVAHI */
b85fafd
   char		*name,			/* Service name */
b85fafd
 		*domain,		/* Domain name */
b85fafd
 		*fullName,		/* Full name */
081f3eb
@@ -64,6 +81,20 @@ typedef struct
111438e
 		sent;			/* Did we list the device? */
111438e
 } cups_device_t;
111438e
 
111438e
+typedef struct
111438e
+{
111438e
+  char key[256];
111438e
+  char value[256];
111438e
+
111438e
+#ifdef HAVE_DNSSD
111438e
+  const uint8_t *data;
111438e
+  const uint8_t *datanext;
111438e
+  const uint8_t *dataend;
111438e
+#else /* HAVE_AVAHI */
111438e
+  AvahiStringList *txt;
111438e
+#endif /* HAVE_DNSSD */
111438e
+} cups_txt_records_t;
111438e
+
111438e
 
111438e
 /*
111438e
  * Local globals...
081f3eb
@@ -77,6 +108,7 @@ static int		job_canceled = 0;
b85fafd
  * Local functions...
b85fafd
  */
b85fafd
 
111438e
+#ifdef HAVE_DNSSD
b85fafd
 static void		browse_callback(DNSServiceRef sdRef,
b85fafd
 			                DNSServiceFlags flags,
b85fafd
 				        uint32_t interfaceIndex,
081f3eb
@@ -92,12 +124,6 @@ static void		browse_local_callback(DNSSe
b85fafd
 					      const char *regtype,
b85fafd
 					      const char *replyDomain,
b85fafd
 					      void *context);
b85fafd
-static int		compare_devices(cups_device_t *a, cups_device_t *b);
b85fafd
-static void		exec_backend(char **argv);
b85fafd
-static cups_device_t	*get_device(cups_array_t *devices,
b85fafd
-			            const char *serviceName,
b85fafd
-			            const char *regtype,
b85fafd
-				    const char *replyDomain);
b85fafd
 static void		query_callback(DNSServiceRef sdRef,
b85fafd
 			               DNSServiceFlags flags,
b85fafd
 				       uint32_t interfaceIndex,
081f3eb
@@ -106,9 +132,111 @@ static void		query_callback(DNSServiceRe
b85fafd
 				       uint16_t rrclass, uint16_t rdlen,
b85fafd
 				       const void *rdata, uint32_t ttl,
b85fafd
 				       void *context);
111438e
+#endif /* HAVE_DNSSD */
111438e
+#ifdef HAVE_AVAHI
111438e
+static void		avahi_client_callback (AvahiClient *client,
111438e
+					       AvahiClientState state,
111438e
+					       void *context);
111438e
+static void		avahi_browse_callback (AvahiServiceBrowser *browser,
111438e
+					       AvahiIfIndex interface,
111438e
+					       AvahiProtocol protocol,
111438e
+					       AvahiBrowserEvent event,
111438e
+					       const char *serviceName,
111438e
+					       const char *regtype,
111438e
+					       const char *replyDomain,
111438e
+					       AvahiLookupResultFlags flags,
111438e
+					       void *context);
111438e
+#endif /* HAVE_AVAHI */
b85fafd
+
111438e
+static cups_device_t *	find_device (cups_array_t *devices,
111438e
+				     cups_txt_records_t *txt,
111438e
+				     cups_device_t *dkey);
b85fafd
+static int		compare_devices(cups_device_t *a, cups_device_t *b);
b85fafd
+static void		exec_backend(char **argv);
b85fafd
+static cups_device_t	*get_device(cups_array_t *devices,
b85fafd
+			            const char *serviceName,
b85fafd
+			            const char *regtype,
b85fafd
+				    const char *replyDomain);
111438e
 static void		sigterm_handler(int sig);
b85fafd
 static void		unquote(char *dst, const char *src, size_t dstsize);
111438e
 
b85fafd
+#ifdef HAVE_AVAHI
b85fafd
+static AvahiSimplePoll *simple_poll = NULL;
b85fafd
+static int avahi_got_callback;
b85fafd
+#endif /* HAVE_AVAHI */
111438e
+
111438e
+
111438e
+/*
111438e
+ * cups_txt_records_t access functions
111438e
+ */
111438e
+static cups_txt_records_t *
111438e
+next_txt_record (cups_txt_records_t *txt)
111438e
+{
111438e
+#ifdef HAVE_DNSSD
111438e
+  txt->data = txt->datanext;
111438e
+#else /* HAVE_AVAHI */
111438e
+  txt->txt = avahi_string_list_get_next (txt->txt);
111438e
+  if (txt->txt == NULL)
111438e
+    return NULL;
111438e
+#endif /* HAVE_DNSSD */
111438e
+
111438e
+  return txt;
111438e
+}
111438e
+
111438e
+static int
111438e
+parse_txt_record_pair (cups_txt_records_t *txt)
111438e
+{
111438e
+#ifdef HAVE_DNSSD
111438e
+  uint8_t	datalen;
111438e
+  uint8_t	*data = txt->data;
111438e
+  char		*ptr;
111438e
+
111438e
+ /*
111438e
+  * Read a key/value pair starting with an 8-bit length.  Since the
111438e
+  * length is 8 bits and the size of the key/value buffers is 256, we
111438e
+  * don't need to check for overflow...
111438e
+  */
111438e
+
111438e
+  datalen = *data++;
111438e
+  if (!datalen || (data + datalen) >= txt->dataend)
111438e
+    return NULL;
111438e
+  txt->datanext = data + datalen;
111438e
+
111438e
+  for (ptr = txt->key; data < txt->datanext && *data != '='; data ++)
111438e
+    *ptr++ = *data;
111438e
+  *ptr = '\0';
111438e
+
111438e
+  if (data < txt->datanext && *data == '=')
111438e
+  {
111438e
+    data++;
111438e
+
111438e
+    if (data < datanext)
111438e
+      memcpy (txt->value, data, txt->datanext - data);
111438e
+    value[txt->datanext - data] = '\0';
111438e
+  }
111438e
+  else
111438e
+    return 1;
111438e
+#else /* HAVE_AVAHI */
111438e
+  char *key, *value;
111438e
+  size_t len;
111438e
+  avahi_string_list_get_pair (txt->txt, &key, &value, &len;;
111438e
+  if (len > sizeof (txt->value) - 1)
111438e
+    len = sizeof (txt->value) - 1;
111438e
+
111438e
+  memcpy (txt->value, value, len);
111438e
+  txt->value[len] = '\0';
111438e
+  len = strlen (key);
111438e
+  if (len > sizeof (txt->key) - 1)
111438e
+    len = sizeof (txt->key) - 1;
111438e
+
111438e
+  memcpy (txt->key, key, len);
111438e
+  txt->key[len] = '\0';
111438e
+  avahi_free (key);
111438e
+  avahi_free (value);
111438e
+#endif /* HAVE_AVAHI */
111438e
+
111438e
+  return 0;
111438e
+}
b85fafd
 
b85fafd
 /*
111438e
  * 'main()' - Browse for printers.
081f3eb
@@ -119,6 +247,13 @@ main(int  argc,				/* I - Number of comm
b85fafd
      char *argv[])			/* I - Command-line arguments */
b85fafd
 {
b85fafd
   const char	*name;			/* Backend name */
b85fafd
+  cups_array_t	*devices;		/* Device array */
b85fafd
+  cups_device_t	*device;		/* Current device */
b85fafd
+  char		uriName[1024];		/* Unquoted fullName for URI */
111438e
+#ifdef HAVE_DNSSD
111438e
+  int		fd;			/* Main file descriptor */
111438e
+  fd_set	input;			/* Input set for select() */
111438e
+  struct timeval timeout;		/* Timeout for select() */
b85fafd
   DNSServiceRef	main_ref,		/* Main service reference */
b85fafd
 		fax_ipp_ref,		/* IPP fax service reference */
b85fafd
 		ipp_ref,		/* IPP service reference */
081f3eb
@@ -130,12 +265,11 @@ main(int  argc,				/* I - Number of comm
b85fafd
 		pdl_datastream_ref,	/* AppSocket service reference */
b85fafd
 		printer_ref,		/* LPD service reference */
b85fafd
 		riousbprint_ref;	/* Remote IO service reference */
b85fafd
-  int		fd;			/* Main file descriptor */
b85fafd
-  fd_set	input;			/* Input set for select() */
b85fafd
-  struct timeval timeout;		/* Timeout for select() */
b85fafd
-  cups_array_t	*devices;		/* Device array */
b85fafd
-  cups_device_t	*device;		/* Current device */
a1088d0
-  char		uriName[1024];		/* Unquoted fullName for URI */
111438e
+#endif /* HAVE_DNSSD */
111438e
+#ifdef HAVE_AVAHI
111438e
+  AvahiClient	*client;
111438e
+  int		error;
111438e
+#endif /* HAVE_AVAHI */
111438e
 #if defined(HAVE_SIGACTION) && !defined(HAVE_SIGSET)
111438e
   struct sigaction action;		/* Actions for POSIX signals */
111438e
 #endif /* HAVE_SIGACTION && !HAVE_SIGSET */
081f3eb
@@ -194,6 +328,49 @@ main(int  argc,				/* I - Number of comm
b85fafd
   * Browse for different kinds of printers...
b85fafd
   */
b85fafd
 
b85fafd
+#ifdef HAVE_AVAHI
b85fafd
+  if ((simple_poll = avahi_simple_poll_new ()) == NULL)
b85fafd
+  {
b85fafd
+    perror ("ERROR: Unable to create avahi simple poll object");
b85fafd
+    return (1);
b85fafd
+  }
b85fafd
+
b85fafd
+  client = avahi_client_new (avahi_simple_poll_get (simple_poll),
b85fafd
+			     0, avahi_client_callback, NULL, &error);
b85fafd
+  if (!client)
b85fafd
+  {
b85fafd
+    perror ("ERROR: Unable to create avahi client");
b85fafd
+    return (1);
b85fafd
+  }
b85fafd
+
b85fafd
+  avahi_service_browser_new (client, AVAHI_IF_UNSPEC,
b85fafd
+			     AVAHI_PROTO_UNSPEC,
b85fafd
+			     "_fax-ipp._tcp", NULL, 0,
b85fafd
+			     avahi_browse_callback, devices);
b85fafd
+  avahi_service_browser_new (client, AVAHI_IF_UNSPEC,
b85fafd
+			     AVAHI_PROTO_UNSPEC,
b85fafd
+			     "_ipp._tcp", NULL, 0,
b85fafd
+			     avahi_browse_callback, devices);
b85fafd
+  avahi_service_browser_new (client, AVAHI_IF_UNSPEC,
b85fafd
+			     AVAHI_PROTO_UNSPEC,
b85fafd
+			     "_ipp-tls._tcp", NULL, 0,
b85fafd
+			     avahi_browse_callback, devices);
b85fafd
+  avahi_service_browser_new (client, AVAHI_IF_UNSPEC,
b85fafd
+			     AVAHI_PROTO_UNSPEC,
b85fafd
+			     "_pdl-datastream._tcp",
b85fafd
+			     NULL, 0,
b85fafd
+			     avahi_browse_callback,
b85fafd
+			     devices);
b85fafd
+  avahi_service_browser_new (client, AVAHI_IF_UNSPEC,
b85fafd
+			     AVAHI_PROTO_UNSPEC,
b85fafd
+			     "_printer._tcp", NULL, 0,
b85fafd
+			     avahi_browse_callback, devices);
b85fafd
+  avahi_service_browser_new (client, AVAHI_IF_UNSPEC,
b85fafd
+			     AVAHI_PROTO_UNSPEC,
b85fafd
+			     "_riousbprint._tcp", NULL, 0,
b85fafd
+			     avahi_browse_callback, devices);
111438e
+#endif /* HAVE_AVAHI */
111438e
+#ifdef HAVE_DNSSD
b85fafd
   if (DNSServiceCreateConnection(&main_ref) != kDNSServiceErr_NoError)
b85fafd
   {
b85fafd
     perror("ERROR: Unable to create service connection");
081f3eb
@@ -245,6 +422,7 @@ main(int  argc,				/* I - Number of comm
b85fafd
   riousbprint_ref = main_ref;
b85fafd
   DNSServiceBrowse(&riousbprint_ref, kDNSServiceFlagsShareConnection, 0,
b85fafd
                    "_riousbprint._tcp", NULL, browse_callback, devices);
111438e
+#endif /* HAVE_DNSSD */
b85fafd
 
b85fafd
  /*
b85fafd
   * Loop until we are killed...
081f3eb
@@ -252,6 +430,9 @@ main(int  argc,				/* I - Number of comm
b85fafd
 
111438e
   while (!job_canceled)
b85fafd
   {
b85fafd
+    int announce = 0;
b85fafd
+
111438e
+#ifdef HAVE_DNSSD
111438e
     FD_ZERO(&input);
111438e
     FD_SET(fd, &input);
111438e
 
081f3eb
@@ -271,11 +452,35 @@ main(int  argc,				/* I - Number of comm
111438e
     }
111438e
     else
111438e
     {
111438e
+      announce = 1;
111438e
+    }
111438e
+#else /* HAVE_AVAHI */
b85fafd
+    int r;
b85fafd
+    avahi_got_callback = 0;
b85fafd
+    r = avahi_simple_poll_iterate (simple_poll, 1);
b85fafd
+    if (r != 0 && r != EINTR)
b85fafd
+    {
b85fafd
+     /*
b85fafd
+      * We've been told to exit the loop.  Perhaps the connection to
b85fafd
+      * avahi failed.
b85fafd
+      */
b85fafd
+
b85fafd
+      break;
b85fafd
+    }
b85fafd
+
b85fafd
+    if (avahi_got_callback)
b85fafd
+      announce = 1;
111438e
+#endif /* HAVE_DNSSD */
b85fafd
+
b85fafd
+    if (announce)
b85fafd
+    {
b85fafd
      /*
b85fafd
       * Announce any devices we've found...
b85fafd
       */
b85fafd
 
111438e
+#ifdef HAVE_DNSSD
b85fafd
       DNSServiceErrorType status;	/* DNS query status */
111438e
+#endif /* HAVE_DNSSD */
b85fafd
       cups_device_t *best;		/* Best matching device */
b85fafd
       char	device_uri[1024];	/* Device URI */
b85fafd
       int	count;			/* Number of queries */
081f3eb
@@ -285,6 +490,7 @@ main(int  argc,				/* I - Number of comm
b85fafd
                best = NULL, count = 0;
b85fafd
            device;
b85fafd
 	   device = (cups_device_t *)cupsArrayNext(devices))
111438e
+#ifdef HAVE_DNSSD
b85fafd
         if (!device->ref && !device->sent)
b85fafd
 	{
b85fafd
 	 /*
081f3eb
@@ -313,14 +519,23 @@ main(int  argc,				/* I - Number of comm
b85fafd
 	      count ++;
b85fafd
           }
b85fafd
 	}
b85fafd
-	else if (!device->sent)
b85fafd
+	else
111438e
+#endif /* HAVE_DNSSD */
081f3eb
+#ifdef HAVE_AVAHI
081f3eb
+	if (!device->resolved)
081f3eb
+	  continue;
081f3eb
+        else
081f3eb
+#endif /* HAVE_AVAHI */
b85fafd
+	if (!device->sent)
b85fafd
 	{
111438e
+#ifdef HAVE_DNSSD
b85fafd
 	 /*
b85fafd
 	  * Got the TXT records, now report the device...
b85fafd
 	  */
b85fafd
 
b85fafd
 	  DNSServiceRefDeallocate(device->ref);
b85fafd
 	  device->ref = 0;
111438e
+#endif /* HAVE_DNSSD */
b85fafd
 
b85fafd
           if (!best)
b85fafd
 	    best = device;
081f3eb
@@ -372,6 +587,7 @@ main(int  argc,				/* I - Number of comm
111438e
  * 'browse_callback()' - Browse devices.
111438e
  */
111438e
 
111438e
+#ifdef HAVE_DNSSD
111438e
 static void
111438e
 browse_callback(
111438e
     DNSServiceRef       sdRef,		/* I - Service reference */
081f3eb
@@ -405,12 +621,14 @@ browse_callback(
111438e
 
111438e
   get_device((cups_array_t *)context, serviceName, regtype, replyDomain);
111438e
 }
111438e
+#endif /* HAVE_DNSSD */
111438e
 
111438e
 
111438e
 /*
111438e
  * 'browse_local_callback()' - Browse local devices.
111438e
  */
111438e
 
111438e
+#ifdef HAVE_DNSSD
111438e
 static void
111438e
 browse_local_callback(
111438e
     DNSServiceRef       sdRef,		/* I - Service reference */
081f3eb
@@ -456,6 +674,7 @@ browse_local_callback(
111438e
 	  device->fullName);
111438e
   device->sent = 1;
b85fafd
 }
111438e
+#endif /* HAVE_DNSSD */
b85fafd
 
b85fafd
 
111438e
 /*
081f3eb
@@ -528,6 +747,32 @@ exec_backend(char **argv)		/* I - Comman
111438e
   exit(CUPS_BACKEND_STOP);
111438e
 }
111438e
 
111438e
+static int
111438e
+device_type (const char *regtype)
111438e
+{
111438e
+#ifdef HAVE_AVAHI
111438e
+  if (!strcmp(regtype, "_ipp._tcp") ||
111438e
+      !strcmp(regtype, "_ipp-tls._tcp"))
111438e
+    return (CUPS_DEVICE_IPP);
111438e
+  else if (!strcmp(regtype, "_fax-ipp._tcp"))
111438e
+    return (CUPS_DEVICE_FAX_IPP);
111438e
+  else if (!strcmp(regtype, "_printer._tcp"))
111438e
+    return (CUPS_DEVICE_PDL_DATASTREAM);
111438e
+#else
111438e
+  if (!strcmp(regtype, "_ipp._tcp.") ||
111438e
+      !strcmp(regtype, "_ipp-tls._tcp."))
111438e
+    return (CUPS_DEVICE_IPP);
111438e
+  else if (!strcmp(regtype, "_fax-ipp._tcp."))
111438e
+    return (CUPS_DEVICE_FAX_IPP);
111438e
+  else if (!strcmp(regtype, "_printer._tcp."))
111438e
+    return (CUPS_DEVICE_PRINTER);
111438e
+  else if (!strcmp(regtype, "_pdl-datastream._tcp."))
111438e
+    return (CUPS_DEVICE_PDL_DATASTREAM);
111438e
+#endif /* HAVE_AVAHI */
111438e
+
111438e
+  return (CUPS_DEVICE_RIOUSBPRINT);
111438e
+}
111438e
+
111438e
 
111438e
 /*
111438e
  * 'get_device()' - Create or update a device.
081f3eb
@@ -550,18 +795,7 @@ get_device(cups_array_t *devices,	/* I -
111438e
   */
111438e
 
111438e
   key.name = (char *)serviceName;
111438e
-
111438e
-  if (!strcmp(regtype, "_ipp._tcp.") ||
111438e
-      !strcmp(regtype, "_ipp-tls._tcp."))
111438e
-    key.type = CUPS_DEVICE_IPP;
111438e
-  else if (!strcmp(regtype, "_fax-ipp._tcp."))
111438e
-    key.type = CUPS_DEVICE_FAX_IPP;
111438e
-  else if (!strcmp(regtype, "_printer._tcp."))
111438e
-    key.type = CUPS_DEVICE_PRINTER;
111438e
-  else if (!strcmp(regtype, "_pdl-datastream._tcp."))
111438e
-    key.type = CUPS_DEVICE_PDL_DATASTREAM;
111438e
-  else
111438e
-    key.type = CUPS_DEVICE_RIOUSBPRINT;
111438e
+  key.type = device_type (regtype);
111438e
 
111438e
   for (device = cupsArrayFind(devices, &key);
111438e
        device;
081f3eb
@@ -581,8 +815,14 @@ get_device(cups_array_t *devices,	/* I -
111438e
         free(device->domain);
111438e
 	device->domain = strdup(replyDomain);
111438e
 
111438e
+#ifdef HAVE_DNSSD
111438e
 	DNSServiceConstructFullName(fullName, device->name, regtype,
111438e
 	                            replyDomain);
111438e
+#else /* HAVE_AVAHI */
111438e
+	avahi_service_name_join (fullName, kDNSServiceMaxDomainName,
111438e
+				 serviceName, regtype, replyDomain);
111438e
+#endif /* HAVE_DNSSD */
111438e
+
111438e
 	free(device->fullName);
111438e
 	device->fullName = strdup(fullName);
111438e
       }
081f3eb
@@ -602,6 +842,9 @@ get_device(cups_array_t *devices,	/* I -
081f3eb
   device->domain   = strdup(replyDomain);
081f3eb
   device->type     = key.type;
081f3eb
   device->priority = 50;
081f3eb
+#ifdef HAVE_AVAHI
081f3eb
+  device->resolved = 0;
081f3eb
+#endif /* HAVE_AVAHI */
081f3eb
 
081f3eb
   cupsArrayAdd(devices, device);
081f3eb
 
081f3eb
@@ -609,7 +852,13 @@ get_device(cups_array_t *devices,	/* I -
111438e
   * Set the "full name" of this service, which is used for queries...
111438e
   */
111438e
 
111438e
+#ifdef HAVE_DNSSD
111438e
   DNSServiceConstructFullName(fullName, serviceName, regtype, replyDomain);
111438e
+#else /* HAVE_AVAHI */
111438e
+  avahi_service_name_join (fullName, kDNSServiceMaxDomainName,
111438e
+			   serviceName, regtype, replyDomain);
111438e
+#endif /* HAVE_DNSSD */
111438e
+
111438e
   device->fullName = strdup(fullName);
111438e
 
111438e
   return (device);
081f3eb
@@ -620,6 +869,7 @@ get_device(cups_array_t *devices,	/* I -
111438e
  * 'query_callback()' - Process query data.
111438e
  */
111438e
 
111438e
+#ifdef HAVE_DNSSD
111438e
 static void
111438e
 query_callback(
111438e
     DNSServiceRef       sdRef,		/* I - Service reference */
081f3eb
@@ -639,7 +889,7 @@ query_callback(
111438e
 		*ptr;			/* Pointer into string */
111438e
   cups_device_t	dkey,			/* Search key */
111438e
 		*device;		/* Device */
111438e
-
111438e
+  cups_txt_records_t txt;
111438e
 
111438e
   fprintf(stderr, "DEBUG2: query_callback(sdRef=%p, flags=%x, "
111438e
                   "interfaceIndex=%d, errorCode=%d, fullName=\"%s\", "
081f3eb
@@ -673,84 +923,212 @@ query_callback(
111438e
   if ((ptr = strstr(name, "._")) != NULL)
111438e
     *ptr = '\0';
111438e
 
111438e
-  if (strstr(fullName, "_ipp._tcp.") ||
111438e
-      strstr(fullName, "_ipp-tls._tcp."))
111438e
-    dkey.type = CUPS_DEVICE_IPP;
111438e
-  else if (strstr(fullName, "_fax-ipp._tcp."))
111438e
-    dkey.type = CUPS_DEVICE_FAX_IPP;
111438e
-  else if (strstr(fullName, "_printer._tcp."))
111438e
-    dkey.type = CUPS_DEVICE_PRINTER;
111438e
-  else if (strstr(fullName, "_pdl-datastream._tcp."))
111438e
-    dkey.type = CUPS_DEVICE_PDL_DATASTREAM;
111438e
+  dkey.type = device_type (fullName);
111438e
+
111438e
+  txt.data = rdata;
111438e
+  txt.dataend = rdata + rdlen;
111438e
+  device = find_device ((cups_array_t *) context, &txt, &dkey);
111438e
+  if (!device)
111438e
+    fprintf(stderr, "DEBUG: Ignoring TXT record for \"%s\"...\n", fullName);
111438e
+}
111438e
+#endif /* HAVE_DNSSD */
111438e
+
b85fafd
+#ifdef HAVE_AVAHI
b85fafd
+static void
111438e
+avahi_client_callback(AvahiClient *client,
111438e
+		      AvahiClientState state,
111438e
+		      void *context)
b85fafd
+{
b85fafd
+ /*
b85fafd
+  * If the connection drops, quit.
b85fafd
+  */
b85fafd
+
b85fafd
+  if (state == AVAHI_CLIENT_FAILURE)
b85fafd
+  {
b85fafd
+    fprintf (stderr, "ERROR: Avahi connection failed\n");
b85fafd
+    avahi_simple_poll_quit (simple_poll);
b85fafd
+  }
b85fafd
+}
b85fafd
+
b85fafd
+static void
111438e
+avahi_query_callback(AvahiServiceResolver *resolver,
111438e
+		     AvahiIfIndex interface,
111438e
+		     AvahiProtocol protocol,
111438e
+		     AvahiResolverEvent event,
111438e
+		     const char *name,
111438e
+		     const char *type,
111438e
+		     const char *domain,
111438e
+		     const char *host_name,
111438e
+		     const AvahiAddress *address,
111438e
+		     uint16_t port,
111438e
+		     AvahiStringList *txt,
111438e
+		     AvahiLookupResultFlags flags,
111438e
+		     void *context)
b85fafd
+{
b85fafd
+  AvahiClient		*client;
b85fafd
+  cups_device_t		key,
b85fafd
+			*device;
b85fafd
+  char			uqname[1024],
b85fafd
+			*ptr;
111438e
+  cups_txt_records_t	txtr;
b85fafd
+
b85fafd
+  client = avahi_service_resolver_get_client (resolver);
b85fafd
+  if (event != AVAHI_RESOLVER_FOUND)
b85fafd
+  {
b85fafd
+    if (event == AVAHI_RESOLVER_FAILURE)
b85fafd
+    {
b85fafd
+      fprintf (stderr, "ERROR: %s\n",
b85fafd
+	       avahi_strerror (avahi_client_errno (client)));
b85fafd
+    }
b85fafd
+
b85fafd
+    avahi_service_resolver_free (resolver);
b85fafd
+    return;
b85fafd
+  }
b85fafd
+
b85fafd
+ /*
b85fafd
+  * Set search key for device.
b85fafd
+  */
b85fafd
+
b85fafd
+  key.name = uqname;
b85fafd
+  unquote (uqname, name, sizeof (uqname));
b85fafd
+  if ((ptr = strstr(name, "._")) != NULL)
b85fafd
+    *ptr = '\0';
b85fafd
+
b85fafd
+  key.domain = (char *) domain;
b85fafd
+  key.type = device_type (type);
b85fafd
+
b85fafd
+ /*
b85fafd
+  * Find the device and the the TXT information.
b85fafd
+  */
b85fafd
+
111438e
+  txtr.txt = txt;
111438e
+  device = find_device ((cups_array_t *) context, &txtr, &key);
b85fafd
+  if (device)
b85fafd
+  {
b85fafd
+   /*
b85fafd
+    * Let the main loop know to announce the device.
b85fafd
+    */
b85fafd
+
081f3eb
+    device->resolved = 1;
b85fafd
+    avahi_got_callback = 1;
b85fafd
+  }
111438e
   else
111438e
-    dkey.type = CUPS_DEVICE_RIOUSBPRINT;
b85fafd
+    fprintf (stderr, "DEBUG: Ignoring TXT record for \"%s\"...\n", name);
081f3eb
+
b85fafd
+  avahi_service_resolver_free (resolver);
b85fafd
+}
b85fafd
+
b85fafd
+static void
111438e
+avahi_browse_callback(AvahiServiceBrowser *browser,
111438e
+		      AvahiIfIndex interface,
111438e
+		      AvahiProtocol protocol,
111438e
+		      AvahiBrowserEvent event,
111438e
+		      const char *name,
111438e
+		      const char *type,
111438e
+		      const char *domain,
111438e
+		      AvahiLookupResultFlags flags,
111438e
+		      void *context)
b85fafd
+{
b85fafd
+  AvahiClient *client = avahi_service_browser_get_client (browser);
b85fafd
+
b85fafd
+  switch (event)
b85fafd
+  {
b85fafd
+  case AVAHI_BROWSER_FAILURE:
b85fafd
+    fprintf (stderr, "ERROR: %s\n",
b85fafd
+	     avahi_strerror (avahi_client_errno (client)));
b85fafd
+    avahi_simple_poll_quit (simple_poll);
b85fafd
+    return;
b85fafd
+
b85fafd
+  case AVAHI_BROWSER_NEW:
b85fafd
+   /*
b85fafd
+    * This object is new on the network.
b85fafd
+    */
b85fafd
+
b85fafd
+    if (flags & AVAHI_LOOKUP_RESULT_LOCAL)
b85fafd
+    {
b85fafd
+     /*
b85fafd
+      * This comes from the local machine so ignore it.
b85fafd
+      */
b85fafd
+
b85fafd
+      fprintf (stderr, "DEBUG: ignoring local service %s\n", name);
b85fafd
+    }
b85fafd
+    else
b85fafd
+    {
b85fafd
+     /*
b85fafd
+      * Create a device entry for it if it doesn't yet exist.
b85fafd
+      */
b85fafd
+
b85fafd
+      get_device ((cups_array_t *)context, name, type, domain);
b85fafd
+
b85fafd
+     /*
b85fafd
+      * Now look for a TXT entry.
b85fafd
+      */
b85fafd
+
b85fafd
+      if (avahi_service_resolver_new (client, interface, protocol,
b85fafd
+				      name, type, domain,
b85fafd
+				      AVAHI_PROTO_UNSPEC, 0,
b85fafd
+				      avahi_query_callback, context) == NULL)
b85fafd
+      {
b85fafd
+	fprintf (stderr, "ERROR: failed to resolve service %s: %s\n",
b85fafd
+		 name, avahi_strerror (avahi_client_errno (client)));
b85fafd
+      }
b85fafd
+    }
b85fafd
+
b85fafd
+    break;
081f3eb
 
081f3eb
-  for (device = cupsArrayFind(devices, &dkey);
b85fafd
+  case AVAHI_BROWSER_REMOVE:
b85fafd
+  case AVAHI_BROWSER_ALL_FOR_NOW:
b85fafd
+  case AVAHI_BROWSER_CACHE_EXHAUSTED:
b85fafd
+    break;
b85fafd
+  }  
b85fafd
+}
111438e
+#endif /* HAVE_AVAHI */
b85fafd
+
b85fafd
+static cups_device_t *
b85fafd
+find_device (cups_array_t *devices,
111438e
+	     cups_txt_records_t *txt,
111438e
+	     cups_device_t *dkey)
b85fafd
+{
111438e
+  cups_device_t	*device;
111438e
+  char		*ptr;
b85fafd
+
111438e
+  for (device = cupsArrayFind(devices, dkey);
b85fafd
        device;
b85fafd
        device = cupsArrayNext(devices))
b85fafd
   {
111438e
-    if (strcasecmp(device->name, dkey.name) ||
111438e
-        strcasecmp(device->domain, dkey.domain))
111438e
+    if (strcasecmp(device->name, dkey->name) ||
111438e
+        strcasecmp(device->domain, dkey->domain))
b85fafd
     {
b85fafd
       device = NULL;
b85fafd
       break;
b85fafd
     }
111438e
-    else if (device->type == dkey.type)
111438e
+    else if (device->type == dkey->type)
b85fafd
     {
b85fafd
      /*
b85fafd
       * Found it, pull out the priority and make and model from the TXT
b85fafd
       * record and save it...
b85fafd
       */
b85fafd
 
111438e
-      const uint8_t	*data,		/* Pointer into data */
111438e
-			*datanext,	/* Next key/value pair */
111438e
-			*dataend;	/* End of entire TXT record */
111438e
-      uint8_t		datalen;	/* Length of current key/value pair */
111438e
-      char		key[256],	/* Key string */
111438e
-			value[256],	/* Value string */
111438e
-			make_and_model[512],
111438e
+      char		make_and_model[512],
111438e
 				      	/* Manufacturer and model */
111438e
 			model[256],	/* Model */
111438e
-			device_id[2048];/* 1284 device ID */
b85fafd
-
111438e
+			device_id[2048]; /* 1284 device ID */
b85fafd
 
111438e
       device_id[0]      = '\0';
111438e
       make_and_model[0] = '\0';
b85fafd
 
111438e
       strcpy(model, "Unknown");
b85fafd
 
111438e
-      for (data = rdata, dataend = data + rdlen;
111438e
-           data < dataend;
111438e
-           data = datanext)
111438e
+      for (;;)
b85fafd
       {
111438e
-       /*
111438e
-        * Read a key/value pair starting with an 8-bit length.  Since the
111438e
-	* length is 8 bits and the size of the key/value buffers is 256, we
111438e
-	* don't need to check for overflow...
111438e
-	*/
111438e
-
111438e
-        datalen = *data++;
111438e
-
111438e
-        if (!datalen || (data + datalen) >= dataend)
111438e
-	  break;
111438e
-
111438e
-        datanext = data + datalen;
111438e
+	char *key;
111438e
+	char *value;
b85fafd
 
111438e
-        for (ptr = key; data < datanext && *data != '='; data ++)
111438e
-	  *ptr++ = *data;
111438e
-	*ptr = '\0';
b85fafd
-
111438e
-	if (data < datanext && *data == '=')
111438e
-	{
111438e
-	  data ++;
111438e
-
111438e
-	  if (data < datanext)
111438e
-	    memcpy(value, data, datanext - data);
111438e
-	  value[datanext - data] = '\0';
111438e
-	}
111438e
-	else
111438e
-	  continue;
111438e
+	if (parse_txt_record_pair (txt))
111438e
+	  goto next;
111438e
 
111438e
+	key = txt->key;
111438e
+	value = txt->value;
111438e
         if (!strncasecmp(key, "usb_", 4))
b85fafd
 	{
b85fafd
 	 /*
081f3eb
@@ -805,6 +1183,10 @@ query_callback(
111438e
 	  if (device->type == CUPS_DEVICE_PRINTER)
111438e
 	    device->sent = 1;
b85fafd
 	}
111438e
+
111438e
+      next:
111438e
+	if (next_txt_record (txt) == NULL)
111438e
+	  break;
111438e
       }
b85fafd
 
111438e
       if (device->device_id)
081f3eb
@@ -854,11 +1236,9 @@ query_callback(
b85fafd
     }
b85fafd
   }
b85fafd
 
b85fafd
-  if (!device)
b85fafd
-    fprintf(stderr, "DEBUG: Ignoring TXT record for \"%s\"...\n", fullName);
b85fafd
+  return device;
b85fafd
 }
b85fafd
 
111438e
-
b85fafd
 /*
111438e
  * 'sigterm_handler()' - Handle termination signals...
b85fafd
  */
dd27f80
diff -up cups-1.4.0/config.h.in.avahi cups-1.4.0/config.h.in
dd27f80
--- cups-1.4.0/config.h.in.avahi	2009-06-10 16:51:21.000000000 +0100
081f3eb
+++ cups-1.4.0/config.h.in	2009-09-04 14:57:04.733388405 +0100
dd27f80
@@ -336,6 +336,13 @@
b85fafd
 
b85fafd
 
b85fafd
 /*
b85fafd
+ * Do we have Avahi for DNS Service Discovery?
b85fafd
+ */
b85fafd
+
b85fafd
+#undef HAVE_AVAHI
b85fafd
+
b85fafd
+
b85fafd
+/*
b85fafd
  * Do we have <sys/ioctl.h>?
b85fafd
  */
b85fafd
 
dd27f80
diff -up cups-1.4.0/config-scripts/cups-dnssd.m4.avahi cups-1.4.0/config-scripts/cups-dnssd.m4
dd27f80
--- cups-1.4.0/config-scripts/cups-dnssd.m4.avahi	2009-02-10 17:05:35.000000000 +0000
081f3eb
+++ cups-1.4.0/config-scripts/cups-dnssd.m4	2009-09-04 14:57:04.731388902 +0100
b85fafd
@@ -27,6 +27,21 @@ AC_ARG_WITH(dnssd-includes, [  --with-dn
b85fafd
 DNSSDLIBS=""
b85fafd
 DNSSD_BACKEND=""
b85fafd
 
b85fafd
+AC_ARG_ENABLE(avahi, [  --enable-avahi          turn on DNS Service Discovery support, default=no],
b85fafd
+	      [if test x$enable_avahi = xyes; then
b85fafd
+		       AC_MSG_CHECKING(for Avahi)
b85fafd
+		       if $PKGCONFIG --exists avahi-client; then
b85fafd
+			       AC_MSG_RESULT(yes)
b85fafd
+			       CFLAGS="$CFLAGS `$PKGCONFIG --cflags avahi-client`"
b85fafd
+			       DNSSDLIBS="`$PKGCONFIG --libs avahi-client`"
b85fafd
+			       DNSSD_BACKEND="dnssd"
b85fafd
+			       AC_DEFINE(HAVE_AVAHI)
b85fafd
+			       enable_dnssd=no
b85fafd
+		       else
b85fafd
+			       AC_MSG_RESULT(no)
b85fafd
+		       fi
b85fafd
+	       fi])
b85fafd
+
b85fafd
 if test x$enable_dnssd != xno; then
b85fafd
 	AC_CHECK_HEADER(dns_sd.h, [
b85fafd
 		case "$uname" in
dd27f80
diff -up cups-1.4.0/cups/http-support.c.avahi cups-1.4.0/cups/http-support.c
dd27f80
--- cups-1.4.0/cups/http-support.c.avahi	2009-06-12 01:21:58.000000000 +0100
081f3eb
+++ cups-1.4.0/cups/http-support.c	2009-09-04 14:57:04.736398674 +0100
dd27f80
@@ -55,6 +55,11 @@
b85fafd
 #  include <dns_sd.h>
111438e
 #  include <poll.h>
b85fafd
 #endif /* HAVE_DNSSD */
b85fafd
+#ifdef HAVE_AVAHI
111438e
+#  include <avahi-client/client.h>
111438e
+#  include <avahi-client/lookup.h>
111438e
+#  include <avahi-common/simple-watch.h>
b85fafd
+#endif /* HAVE_AVAHI */
b85fafd
 
b85fafd
 
b85fafd
 /*
dd27f80
@@ -121,6 +126,24 @@ static void		resolve_callback(DNSService
b85fafd
 					 void *context);
b85fafd
 #endif /* HAVE_DNSSD */
b85fafd
 
b85fafd
+#ifdef HAVE_AVAHI
111438e
+static void	avahi_resolve_uri_client_cb(AvahiClient *client,
111438e
+					    AvahiClientState state,
111438e
+					    void *simple_poll);
111438e
+static void	avahi_resolve_uri_resolver_cb(AvahiServiceResolver *resolver,
111438e
+					      AvahiIfIndex interface,
111438e
+					      AvahiProtocol protocol,
111438e
+					      AvahiResolverEvent event,
111438e
+					      const char *name,
111438e
+					      const char *type,
111438e
+					      const char *domain,
111438e
+					      const char *host_name,
111438e
+					      const AvahiAddress *address,
111438e
+					      uint16_t port,
111438e
+					      AvahiStringList *txt,
111438e
+					      AvahiLookupResultFlags flags,
111438e
+					      void *context);
b85fafd
+#endif /* HAVE_AVAHI */
b85fafd
 
b85fafd
 /*
b85fafd
  * 'httpAssembleURI()' - Assemble a uniform resource identifier from its
dd27f80
@@ -1349,15 +1372,26 @@ _httpResolveURI(
b85fafd
 
b85fafd
   if (strstr(hostname, "._tcp"))
b85fafd
   {
b85fafd
+#if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
111438e
+    char		*regtype,	/* Pointer to type in hostname */
111438e
+			*domain;	/* Pointer to domain in hostname */
b85fafd
 #ifdef HAVE_DNSSD
111438e
     DNSServiceRef	ref,		/* DNS-SD master service reference */
111438e
 			domainref,	/* DNS-SD service reference for domain */
111438e
 			localref;	/* DNS-SD service reference for .local */
111438e
     int			domainsent = 0;	/* Send the domain resolve? */
111438e
-    char		*regtype,	/* Pointer to type in hostname */
111438e
-			*domain;	/* Pointer to domain in hostname */
111438e
     _http_uribuf_t	uribuf;		/* URI buffer */
111438e
     struct pollfd	polldata;	/* Polling data */
111438e
+#else /* HAVE_AVAHI */
b85fafd
+    AvahiSimplePoll	*simple_poll;
b85fafd
+    AvahiClient		*client;
b85fafd
+    int			error;
111438e
+    struct
b85fafd
+    {
b85fafd
+      AvahiSimplePoll	*poll;
b85fafd
+      _http_uribuf_t	uribuf;
111438e
+    } user_data;
b85fafd
+#endif /* HAVE_DNSSD */
b85fafd
 
111438e
 
111438e
     if (logit)
dd27f80
@@ -1395,8 +1429,13 @@ _httpResolveURI(
b85fafd
     if (domain)
b85fafd
       *domain++ = '\0';
b85fafd
 
b85fafd
+#ifdef HAVE_DNSSD
b85fafd
     uribuf.buffer  = resolved_uri;
b85fafd
     uribuf.bufsize = resolved_size;
b85fafd
+#else
b85fafd
+    user_data.uribuf.buffer = resolved_uri;
b85fafd
+    user_data.uribuf.bufsize = resolved_size;
b85fafd
+#endif
b85fafd
 
b85fafd
     resolved_uri[0] = '\0';
b85fafd
 
111438e
@@ -1411,6 +1450,7 @@ _httpResolveURI(
111438e
 
111438e
     uri = NULL;
b85fafd
 
b85fafd
+#ifdef HAVE_DNSSD
111438e
     if (DNSServiceCreateConnection(&ref) == kDNSServiceErr_NoError)
111438e
     {
111438e
       localref = ref;
dd27f80
@@ -1486,6 +1526,36 @@ _httpResolveURI(
111438e
 
111438e
       DNSServiceRefDeallocate(ref);
a1088d0
     }
111438e
+#else /* HAVE_AVAHI */
b85fafd
+    if ((simple_poll = avahi_simple_poll_new ()) != NULL)
b85fafd
+    {
b85fafd
+      if ((client = avahi_client_new (avahi_simple_poll_get (simple_poll),
111438e
+				      0, avahi_resolve_uri_client_cb,
b85fafd
+				      &simple_poll, &error)) != NULL)
b85fafd
+      {
b85fafd
+	user_data.poll = simple_poll;
b85fafd
+	if (avahi_service_resolver_new (client, AVAHI_IF_UNSPEC,
b85fafd
+					AVAHI_PROTO_UNSPEC, hostname,
b85fafd
+					regtype, domain, AVAHI_PROTO_UNSPEC, 0,
111438e
+					avahi_resolve_uri_resolver_cb,
b85fafd
+					&user_data) != NULL)
b85fafd
+	{
b85fafd
+	  avahi_simple_poll_loop (simple_poll);
b85fafd
+
b85fafd
+	 /*
b85fafd
+	  * Collect the result.
b85fafd
+	  */
b85fafd
+
b85fafd
+	  if (resolved_uri[0])
b85fafd
+	    uri = resolved_uri;
b85fafd
+	}
b85fafd
+
b85fafd
+	avahi_client_free (client);
b85fafd
+      }
b85fafd
+
b85fafd
+      avahi_simple_poll_free (simple_poll);
b85fafd
+    }
111438e
+#endif /* HAVE_DNSSD */
a1088d0
 
a1088d0
     if (logit)
111438e
     {
dd27f80
@@ -1497,13 +1567,13 @@ _httpResolveURI(
b85fafd
       fputs("STATE: -connecting-to-device\n", stderr);
111438e
     }
b85fafd
 
b85fafd
-#else
b85fafd
+#else /* HAVE_DNSSD || HAVE_AVAHI */
a1088d0
    /*
a1088d0
     * No DNS-SD support...
a1088d0
     */
a1088d0
 
b85fafd
     uri = NULL;
b85fafd
-#endif /* HAVE_DNSSD */
b85fafd
+#endif /* HAVE_DNSSD || HAVE_AVAHI */
b85fafd
 
a1088d0
     if (logit && !uri)
b85fafd
       _cupsLangPuts(stderr, _("Unable to find printer!\n"));
dd27f80
@@ -1708,6 +1778,105 @@ resolve_callback(
b85fafd
 }
b85fafd
 #endif /* HAVE_DNSSD */
b85fafd
 
b85fafd
+#ifdef HAVE_AVAHI
b85fafd
+static void
111438e
+avahi_resolve_uri_client_cb (AvahiClient *client,
111438e
+			     AvahiClientState state,
111438e
+			     void *simple_poll)
b85fafd
+{
b85fafd
+  DEBUG_printf(("avahi_resolve_uri_client_callback(client=%p, state=%d, "
b85fafd
+		"simple_poll=%p)\n", client, state, simple_poll));
b85fafd
+
b85fafd
+  /*
b85fafd
+   * If the connection drops, quit.
b85fafd
+   */
b85fafd
+
b85fafd
+  if (state == AVAHI_CLIENT_FAILURE)
b85fafd
+    avahi_simple_poll_quit (simple_poll);
b85fafd
+}
b85fafd
+
b85fafd
+static void
111438e
+avahi_resolve_uri_resolver_cb (AvahiServiceResolver *resolver,
111438e
+			       AvahiIfIndex interface,
111438e
+			       AvahiProtocol protocol,
111438e
+			       AvahiResolverEvent event,
111438e
+			       const char *name,
111438e
+			       const char *type,
111438e
+			       const char *domain,
111438e
+			       const char *host_name,
111438e
+			       const AvahiAddress *address,
111438e
+			       uint16_t port,
111438e
+			       AvahiStringList *txt,
111438e
+			       AvahiLookupResultFlags flags,
111438e
+			       void *context)
b85fafd
+{
b85fafd
+  const char		*scheme;	/* URI scheme */
b85fafd
+  char			rp[256];	/* Remote printer */
b85fafd
+  AvahiStringList	*pair;
b85fafd
+  char			*value;
b85fafd
+  size_t		valueLen = 0;
b85fafd
+  char			addr[AVAHI_ADDRESS_STR_MAX];
b85fafd
+  struct
b85fafd
+  {
b85fafd
+    AvahiSimplePoll	*poll;
b85fafd
+    _http_uribuf_t	uribuf;
b85fafd
+  }		*poll_uribuf = context;
b85fafd
+
b85fafd
+  DEBUG_printf(("avahi_resolve_uri_resolver_callback(resolver=%p, "
b85fafd
+		"interface=%d, protocol=%d, event=%d, name=\"%s\", "
b85fafd
+		"type=\"%s\", domain=\"%s\", host_name=\"%s\", address=%p, "
b85fafd
+		"port=%d, txt=%p, flags=%d, context=%p)\n",
b85fafd
+		resolver, interface, protocol, event, name, type, domain,
b85fafd
+		host_name, address, port, txt, flags, context));
b85fafd
+
b85fafd
+  if (event != AVAHI_RESOLVER_FOUND)
b85fafd
+  {
b85fafd
+    avahi_service_resolver_free (resolver);
b85fafd
+    avahi_simple_poll_quit (poll_uribuf->poll);
b85fafd
+    return;
b85fafd
+  }
b85fafd
+
b85fafd
+ /*
b85fafd
+  * Figure out the scheme from the full name...
b85fafd
+  */
b85fafd
+
b85fafd
+  if (strstr(type, "_ipp."))
b85fafd
+    scheme = "ipp";
b85fafd
+  else if (strstr(type, "_printer."))
b85fafd
+    scheme = "lpd";
b85fafd
+  else if (strstr(type, "_pdl-datastream."))
b85fafd
+    scheme = "socket";
b85fafd
+  else
b85fafd
+    scheme = "riousbprint";
b85fafd
+
b85fafd
+ /*
b85fafd
+  * Extract the "remote printer key from the TXT record...
b85fafd
+  */
b85fafd
+
b85fafd
+  if ((pair = avahi_string_list_find (txt, "rp")) != NULL)
b85fafd
+  {
b85fafd
+    avahi_string_list_get_pair (pair, NULL, &value, &valueLen);
b85fafd
+    rp[0] = '/';
b85fafd
+    memcpy (rp + 1, value, valueLen);
b85fafd
+    rp[valueLen + 1] = '\0';
b85fafd
+  }
b85fafd
+  else
b85fafd
+    rp[0] = '\0';
b85fafd
+
b85fafd
+ /*
b85fafd
+  * Assemble the final device URI...
b85fafd
+  */
b85fafd
+
b85fafd
+  avahi_address_snprint (addr, AVAHI_ADDRESS_STR_MAX, address);
b85fafd
+  httpAssembleURI(HTTP_URI_CODING_ALL, poll_uribuf->uribuf.buffer,
b85fafd
+		  poll_uribuf->uribuf.bufsize, scheme, NULL,
b85fafd
+		  addr, port, rp);
b85fafd
+  DEBUG_printf(("avahi_resolve_uri_resolver_callback: Resolved URI is \"%s\"\n",
b85fafd
+		poll_uribuf->uribuf.buffer));
b85fafd
+  avahi_simple_poll_quit (poll_uribuf->poll);
b85fafd
+}
b85fafd
+#endif /* HAVE_AVAHI */
b85fafd
+
b85fafd
 
b85fafd
 /*
dd27f80
  * End of "$Id: http-support.c 8705 2009-06-12 00:21:58Z mike $".