rlescak / rpms / cups

Forked from rpms/cups 2 years ago
Clone
fecfdf6
diff -up cups-1.5.3/backend/dnssd.c.avahi-2-backend cups-1.5.3/backend/dnssd.c
fecfdf6
--- cups-1.5.3/backend/dnssd.c.avahi-2-backend	2012-05-15 16:53:18.164774446 +0200
fecfdf6
+++ cups-1.5.3/backend/dnssd.c	2012-05-15 17:09:07.684155704 +0200
9829b01
@@ -15,14 +15,21 @@
9829b01
  *
9829b01
  * Contents:
9829b01
  *
9829b01
+ *   next_txt_record()       - Get next TXT record from a cups_txt_records_t.
9829b01
+ *   parse_txt_record_pair() - Read key/value pair in cups_txt_records_t.
9829b01
  *   main()                  - Browse for printers.
9829b01
  *   browse_callback()       - Browse devices.
9829b01
  *   browse_local_callback() - Browse local devices.
9829b01
  *   compare_devices()       - Compare two devices.
9829b01
  *   exec_backend()          - Execute the backend that corresponds to the
9829b01
  *                             resolved service name.
9829b01
+ *   device_type()           - Get DNS-SD type enumeration from string.
9829b01
  *   get_device()            - Create or update a device.
9829b01
  *   query_callback()        - Process query data.
9829b01
+ *   avahi_client_callback() - Avahi client callback function.
9829b01
+ *   avahi_query_callback()  - Avahi query callback function.
9829b01
+ *   avahi_browse_callback() - Avahi browse callback function.
9829b01
+ *   find_device()           - Find a device from its name and domain.
9829b01
  *   sigterm_handler()       - Handle termination signals...
9829b01
  *   unquote()               - Unquote a name string.
9829b01
  */
9829b01
@@ -33,7 +40,18 @@
9829b01
 
9829b01
 #include "backend-private.h"
9829b01
 #include <cups/array.h>
9829b01
-#include <dns_sd.h>
9829b01
+#ifdef HAVE_DNSSD
9829b01
+#  include <dns_sd.h>
9829b01
+#endif /* HAVE_DNSSD */
9829b01
+#ifdef HAVE_AVAHI
9829b01
+#  include <avahi-client/client.h>
9829b01
+#  include <avahi-client/lookup.h>
9829b01
+#  include <avahi-common/simple-watch.h>
9829b01
+#  include <avahi-common/domain.h>
9829b01
+#  include <avahi-common/error.h>
9829b01
+#  include <avahi-common/malloc.h>
9829b01
+#define kDNSServiceMaxDomainName AVAHI_DOMAIN_NAME_MAX
9829b01
+#endif /* HAVE_AVAHI */
9829b01
 
9829b01
 
9829b01
 /*
9829b01
@@ -53,7 +71,12 @@ typedef enum
9829b01
 
9829b01
 typedef struct
9829b01
 {
9829b01
+#ifdef HAVE_DNSSD
9829b01
   DNSServiceRef	ref;			/* Service reference for resolve */
9829b01
+#endif /* HAVE_DNSSD */
9829b01
+#ifdef HAVE_AVAHI
9829b01
+  int		resolved;		/* Did we resolve the device? */
9829b01
+#endif /* HAVE_AVAHI */
9829b01
   char		*name,			/* Service name */
9829b01
 		*domain,		/* Domain name */
9829b01
 		*fullName,		/* Full name */
9829b01
@@ -65,6 +88,20 @@ typedef struct
9829b01
 		sent;			/* Did we list the device? */
9829b01
 } cups_device_t;
9829b01
 
9829b01
+typedef struct
9829b01
+{
9829b01
+  char key[256];
9829b01
+  char value[256];
9829b01
+
9829b01
+#ifdef HAVE_DNSSD
9829b01
+  const uint8_t *data;
9829b01
+  const uint8_t *datanext;
9829b01
+  const uint8_t *dataend;
9829b01
+#else /* HAVE_AVAHI */
9829b01
+  AvahiStringList *txt;
9829b01
+#endif /* HAVE_DNSSD */
9829b01
+} cups_txt_records_t;
9829b01
+
9829b01
 
9829b01
 /*
9829b01
  * Local globals...
9829b01
@@ -78,6 +115,7 @@ static int		job_canceled = 0;
9829b01
  * Local functions...
9829b01
  */
9829b01
 
9829b01
+#ifdef HAVE_DNSSD
9829b01
 static void		browse_callback(DNSServiceRef sdRef,
9829b01
 			                DNSServiceFlags flags,
9829b01
 				        uint32_t interfaceIndex,
fecfdf6
@@ -95,13 +133,6 @@ static void		browse_local_callback(DNSSe
9829b01
 					      const char *replyDomain,
fecfdf6
 					      void *context)
fecfdf6
 					      __attribute__((nonnull(1,5,6,7,8)));
9829b01
-static int		compare_devices(cups_device_t *a, cups_device_t *b);
9829b01
-static void		exec_backend(char **argv);
9829b01
-static cups_device_t	*get_device(cups_array_t *devices,
9829b01
-			            const char *serviceName,
9829b01
-			            const char *regtype,
fecfdf6
-				    const char *replyDomain)
fecfdf6
-				    __attribute__((nonnull(1,2,3,4)));
9829b01
 static void		query_callback(DNSServiceRef sdRef,
9829b01
 			               DNSServiceFlags flags,
9829b01
 				       uint32_t interfaceIndex,
fecfdf6
@@ -111,10 +142,119 @@ static void		query_callback(DNSServiceRe
9829b01
 				       const void *rdata, uint32_t ttl,
fecfdf6
 				       void *context)
fecfdf6
 				       __attribute__((nonnull(1,5,9,11)));
9829b01
+#endif /* HAVE_DNSSD */
9829b01
+#ifdef HAVE_AVAHI
9829b01
+static void		avahi_client_callback (AvahiClient *client,
9829b01
+					       AvahiClientState state,
9829b01
+					       void *context);
9829b01
+static void		avahi_browse_callback (AvahiServiceBrowser *browser,
9829b01
+					       AvahiIfIndex interface,
9829b01
+					       AvahiProtocol protocol,
9829b01
+					       AvahiBrowserEvent event,
9829b01
+					       const char *serviceName,
9829b01
+					       const char *regtype,
9829b01
+					       const char *replyDomain,
9829b01
+					       AvahiLookupResultFlags flags,
9829b01
+					       void *context);
9829b01
+#endif /* HAVE_AVAHI */
9829b01
+static cups_device_t *	find_device (cups_array_t *devices,
9829b01
+				     cups_txt_records_t *txt,
9829b01
+				     cups_device_t *dkey);
9829b01
+static int		compare_devices(cups_device_t *a, cups_device_t *b);
9829b01
+static void		exec_backend(char **argv);
9829b01
+static cups_device_t	*get_device(cups_array_t *devices,
9829b01
+			            const char *serviceName,
9829b01
+			            const char *regtype,
fecfdf6
+				    const char *replyDomain)
fecfdf6
+				    __attribute__((nonnull(1,2,3,4)));
9829b01
 static void		sigterm_handler(int sig);
fecfdf6
 static void		unquote(char *dst, const char *src, size_t dstsize)
fecfdf6
 			    __attribute__((nonnull(1,2)));
9829b01
 
9829b01
+#ifdef HAVE_AVAHI
9829b01
+static AvahiSimplePoll *simple_poll = NULL;
9829b01
+static int avahi_got_callback;
9829b01
+#endif /* HAVE_AVAHI */
9829b01
+
9829b01
+
9829b01
+/*
9829b01
+ * 'next_txt_record()' - Get next TXT record from a cups_txt_records_t.
9829b01
+ */
9829b01
+
9829b01
+static cups_txt_records_t *
9829b01
+next_txt_record (cups_txt_records_t *txt)
9829b01
+{
9829b01
+#ifdef HAVE_DNSSD
9829b01
+  txt->data = txt->datanext;
9829b01
+#else /* HAVE_AVAHI */
9829b01
+  txt->txt = avahi_string_list_get_next (txt->txt);
9829b01
+  if (txt->txt == NULL)
9829b01
+    return NULL;
9829b01
+#endif /* HAVE_DNSSD */
9829b01
+
9829b01
+  return txt;
9829b01
+}
9829b01
+
9829b01
+
9829b01
+/*
9829b01
+ * 'parse_txt_record_pair()' - Read key/value pair in cups_txt_records_t.
9829b01
+ */
9829b01
+
9829b01
+static int
9829b01
+parse_txt_record_pair (cups_txt_records_t *txt)
9829b01
+{
9829b01
+#ifdef HAVE_DNSSD
9829b01
+  uint8_t	datalen;
9829b01
+  uint8_t	*data = txt->data;
9829b01
+  char		*ptr;
9829b01
+
9829b01
+ /*
9829b01
+  * Read a key/value pair starting with an 8-bit length.  Since the
9829b01
+  * length is 8 bits and the size of the key/value buffers is 256, we
9829b01
+  * don't need to check for overflow...
9829b01
+  */
9829b01
+
9829b01
+  datalen = *data++;
0d86476
+  if (!datalen || (data + datalen) > txt->dataend)
9829b01
+    return NULL;
9829b01
+  txt->datanext = data + datalen;
9829b01
+
9829b01
+  for (ptr = txt->key; data < txt->datanext && *data != '='; data ++)
9829b01
+    *ptr++ = *data;
9829b01
+  *ptr = '\0';
9829b01
+
9829b01
+  if (data < txt->datanext && *data == '=')
9829b01
+  {
9829b01
+    data++;
9829b01
+
9829b01
+    if (data < datanext)
9829b01
+      memcpy (txt->value, data, txt->datanext - data);
9829b01
+    value[txt->datanext - data] = '\0';
9829b01
+  }
9829b01
+  else
9829b01
+    return 1;
9829b01
+#else /* HAVE_AVAHI */
9829b01
+  char *key, *value;
9829b01
+  size_t len;
9829b01
+  avahi_string_list_get_pair (txt->txt, &key, &value, &len;;
9829b01
+  if (len > sizeof (txt->value) - 1)
9829b01
+    len = sizeof (txt->value) - 1;
9829b01
+
9829b01
+  memcpy (txt->value, value, len);
9829b01
+  txt->value[len] = '\0';
9829b01
+  len = strlen (key);
9829b01
+  if (len > sizeof (txt->key) - 1)
9829b01
+    len = sizeof (txt->key) - 1;
9829b01
+
9829b01
+  memcpy (txt->key, key, len);
9829b01
+  txt->key[len] = '\0';
9829b01
+  avahi_free (key);
9829b01
+  avahi_free (value);
9829b01
+#endif /* HAVE_AVAHI */
9829b01
+
9829b01
+  return 0;
9829b01
+}
9829b01
+
9829b01
 
9829b01
 /*
9829b01
  * 'main()' - Browse for printers.
fecfdf6
@@ -125,6 +265,13 @@ main(int  argc,				/* I - Number of comm
9829b01
      char *argv[])			/* I - Command-line arguments */
9829b01
 {
9829b01
   const char	*name;			/* Backend name */
9829b01
+  cups_array_t	*devices;		/* Device array */
9829b01
+  cups_device_t	*device;		/* Current device */
9829b01
+  char		uriName[1024];		/* Unquoted fullName for URI */
9829b01
+#ifdef HAVE_DNSSD
9829b01
+  int		fd;			/* Main file descriptor */
9829b01
+  fd_set	input;			/* Input set for select() */
9829b01
+  struct timeval timeout;		/* Timeout for select() */
9829b01
   DNSServiceRef	main_ref,		/* Main service reference */
9829b01
 		fax_ipp_ref,		/* IPP fax service reference */
9829b01
 		ipp_ref,		/* IPP service reference */
fecfdf6
@@ -138,12 +285,11 @@ main(int  argc,				/* I - Number of comm
9829b01
 		pdl_datastream_ref,	/* AppSocket service reference */
9829b01
 		printer_ref,		/* LPD service reference */
9829b01
 		riousbprint_ref;	/* Remote IO service reference */
9829b01
-  int		fd;			/* Main file descriptor */
9829b01
-  fd_set	input;			/* Input set for select() */
9829b01
-  struct timeval timeout;		/* Timeout for select() */
9829b01
-  cups_array_t	*devices;		/* Device array */
9829b01
-  cups_device_t	*device;		/* Current device */
9829b01
-  char		uriName[1024];		/* Unquoted fullName for URI */
9829b01
+#endif /* HAVE_DNSSD */
9829b01
+#ifdef HAVE_AVAHI
9829b01
+  AvahiClient	*client;
9829b01
+  int		error;
9829b01
+#endif /* HAVE_AVAHI */
9829b01
 #if defined(HAVE_SIGACTION) && !defined(HAVE_SIGSET)
9829b01
   struct sigaction action;		/* Actions for POSIX signals */
9829b01
 #endif /* HAVE_SIGACTION && !HAVE_SIGSET */
fecfdf6
@@ -203,6 +349,49 @@ main(int  argc,				/* I - Number of comm
9829b01
   * Browse for different kinds of printers...
9829b01
   */
9829b01
 
9829b01
+#ifdef HAVE_AVAHI
9829b01
+  if ((simple_poll = avahi_simple_poll_new ()) == NULL)
9829b01
+  {
9829b01
+    perror ("ERROR: Unable to create avahi simple poll object");
9829b01
+    return (1);
9829b01
+  }
9829b01
+
9829b01
+  client = avahi_client_new (avahi_simple_poll_get (simple_poll),
9829b01
+			     0, avahi_client_callback, NULL, &error);
9829b01
+  if (!client)
9829b01
+  {
9829b01
+    perror ("DEBUG: Unable to create avahi client");
9829b01
+    return (0);
9829b01
+  }
9829b01
+
9829b01
+  avahi_service_browser_new (client, AVAHI_IF_UNSPEC,
9829b01
+			     AVAHI_PROTO_UNSPEC,
9829b01
+			     "_fax-ipp._tcp", NULL, 0,
9829b01
+			     avahi_browse_callback, devices);
9829b01
+  avahi_service_browser_new (client, AVAHI_IF_UNSPEC,
9829b01
+			     AVAHI_PROTO_UNSPEC,
9829b01
+			     "_ipp._tcp", NULL, 0,
9829b01
+			     avahi_browse_callback, devices);
9829b01
+  avahi_service_browser_new (client, AVAHI_IF_UNSPEC,
9829b01
+			     AVAHI_PROTO_UNSPEC,
9829b01
+			     "_ipp-tls._tcp", NULL, 0,
9829b01
+			     avahi_browse_callback, devices);
9829b01
+  avahi_service_browser_new (client, AVAHI_IF_UNSPEC,
9829b01
+			     AVAHI_PROTO_UNSPEC,
9829b01
+			     "_pdl-datastream._tcp",
9829b01
+			     NULL, 0,
9829b01
+			     avahi_browse_callback,
9829b01
+			     devices);
9829b01
+  avahi_service_browser_new (client, AVAHI_IF_UNSPEC,
9829b01
+			     AVAHI_PROTO_UNSPEC,
9829b01
+			     "_printer._tcp", NULL, 0,
9829b01
+			     avahi_browse_callback, devices);
9829b01
+  avahi_service_browser_new (client, AVAHI_IF_UNSPEC,
9829b01
+			     AVAHI_PROTO_UNSPEC,
9829b01
+			     "_riousbprint._tcp", NULL, 0,
9829b01
+			     avahi_browse_callback, devices);
9829b01
+#endif /* HAVE_AVAHI */
9829b01
+#ifdef HAVE_DNSSD
9829b01
   if (DNSServiceCreateConnection(&main_ref) != kDNSServiceErr_NoError)
9829b01
   {
9829b01
     perror("ERROR: Unable to create service connection");
fecfdf6
@@ -263,6 +452,7 @@ main(int  argc,				/* I - Number of comm
9829b01
   riousbprint_ref = main_ref;
9829b01
   DNSServiceBrowse(&riousbprint_ref, kDNSServiceFlagsShareConnection, 0,
9829b01
                    "_riousbprint._tcp", NULL, browse_callback, devices);
9829b01
+#endif /* HAVE_DNSSD */
9829b01
 
9829b01
  /*
9829b01
   * Loop until we are killed...
fecfdf6
@@ -270,6 +460,9 @@ main(int  argc,				/* I - Number of comm
9829b01
 
9829b01
   while (!job_canceled)
9829b01
   {
9829b01
+    int announce = 0;
9829b01
+
9829b01
+#ifdef HAVE_DNSSD
9829b01
     FD_ZERO(&input);
9829b01
     FD_SET(fd, &input);
9829b01
 
fecfdf6
@@ -289,11 +482,35 @@ main(int  argc,				/* I - Number of comm
9829b01
     }
9829b01
     else
9829b01
     {
9829b01
+      announce = 1;
9829b01
+    }
9829b01
+#else /* HAVE_AVAHI */
9829b01
+    int r;
9829b01
+    avahi_got_callback = 0;
9829b01
+    r = avahi_simple_poll_iterate (simple_poll, 1);
9829b01
+    if (r != 0 && r != EINTR)
9829b01
+    {
9829b01
+     /*
9829b01
+      * We've been told to exit the loop.  Perhaps the connection to
9829b01
+      * avahi failed.
9829b01
+      */
9829b01
+
9829b01
+      break;
9829b01
+    }
9829b01
+
9829b01
+    if (avahi_got_callback)
9829b01
+      announce = 1;
9829b01
+#endif /* HAVE_DNSSD */
9829b01
+
9829b01
+    if (announce)
9829b01
+    {
9829b01
      /*
9829b01
       * Announce any devices we've found...
9829b01
       */
9829b01
 
9829b01
+#ifdef HAVE_DNSSD
9829b01
       DNSServiceErrorType status;	/* DNS query status */
9829b01
+#endif /* HAVE_DNSSD */
9829b01
       cups_device_t *best;		/* Best matching device */
9829b01
       char	device_uri[1024];	/* Device URI */
9829b01
       int	count;			/* Number of queries */
fecfdf6
@@ -307,6 +524,7 @@ main(int  argc,				/* I - Number of comm
9829b01
         if (device->sent)
9829b01
 	  sent ++;
9829b01
 
9829b01
+#ifdef HAVE_DNSSD
9829b01
         if (device->ref)
9829b01
 	  count ++;
9829b01
 
fecfdf6
@@ -338,14 +556,23 @@ main(int  argc,				/* I - Number of comm
9829b01
 	      count ++;
9829b01
           }
9829b01
 	}
9829b01
-	else if (!device->sent)
9829b01
+	else
9829b01
+#endif /* HAVE_DNSSD */
9829b01
+#ifdef HAVE_AVAHI
9829b01
+	if (!device->resolved)
9829b01
+	  continue;
9829b01
+        else
9829b01
+#endif /* HAVE_AVAHI */
9829b01
+	if (!device->sent)
9829b01
 	{
9829b01
+#ifdef HAVE_DNSSD
9829b01
 	 /*
9829b01
 	  * Got the TXT records, now report the device...
9829b01
 	  */
9829b01
 
9829b01
 	  DNSServiceRefDeallocate(device->ref);
9829b01
 	  device->ref = 0;
9829b01
+#endif /* HAVE_DNSSD */
9829b01
 
9829b01
           if (!best)
9829b01
 	    best = device;
fecfdf6
@@ -406,6 +633,7 @@ main(int  argc,				/* I - Number of comm
9829b01
 }
9829b01
 
9829b01
 
9829b01
+#ifdef HAVE_DNSSD
9829b01
 /*
9829b01
  * 'browse_callback()' - Browse devices.
9829b01
  */
fecfdf6
@@ -494,6 +722,7 @@ browse_local_callback(
9829b01
 	  device->fullName);
9829b01
   device->sent = 1;
9829b01
 }
9829b01
+#endif /* HAVE_DNSSD */
9829b01
 
9829b01
 
9829b01
 /*
fecfdf6
@@ -574,6 +803,41 @@ exec_backend(char **argv)		/* I - Comman
9829b01
 
9829b01
 
9829b01
 /*
9829b01
+ * 'device_type()' - Get DNS-SD type enumeration from string.
9829b01
+ */
9829b01
+
9829b01
+static int
9829b01
+device_type (const char *regtype)
9829b01
+{
9829b01
+#ifdef HAVE_AVAHI
9829b01
+  if (!strcmp(regtype, "_ipp._tcp"))
9829b01
+    return (CUPS_DEVICE_IPP);
9829b01
+  else if (!strcmp(regtype, "_ipps._tcp") ||
9829b01
+	   !strcmp(regtype, "_ipp-tls._tcp"))
9829b01
+    return (CUPS_DEVICE_IPPS);
9829b01
+  else if (!strcmp(regtype, "_fax-ipp._tcp"))
9829b01
+    return (CUPS_DEVICE_FAX_IPP);
9829b01
+  else if (!strcmp(regtype, "_printer._tcp"))
9829b01
+    return (CUPS_DEVICE_PDL_DATASTREAM);
9829b01
+#else
9829b01
+  if (!strcmp(regtype, "_ipp._tcp."))
9829b01
+    return (CUPS_DEVICE_IPP);
9829b01
+  else if (!strcmp(regtype, "_ipps._tcp.") ||
9829b01
+	   !strcmp(regtype, "_ipp-tls._tcp."))
9829b01
+    return (CUPS_DEVICE_IPPS);
9829b01
+  else if (!strcmp(regtype, "_fax-ipp._tcp."))
9829b01
+    return (CUPS_DEVICE_FAX_IPP);
9829b01
+  else if (!strcmp(regtype, "_printer._tcp."))
9829b01
+    return (CUPS_DEVICE_PRINTER);
9829b01
+  else if (!strcmp(regtype, "_pdl-datastream._tcp."))
9829b01
+    return (CUPS_DEVICE_PDL_DATASTREAM);
9829b01
+#endif /* HAVE_AVAHI */
9829b01
+
9829b01
+  return (CUPS_DEVICE_RIOUSBPRINT);
9829b01
+}
9829b01
+
9829b01
+
9829b01
+/*
9829b01
  * 'get_device()' - Create or update a device.
9829b01
  */
9829b01
 
fecfdf6
@@ -594,20 +858,7 @@ get_device(cups_array_t *devices,	/* I -
9829b01
   */
9829b01
 
9829b01
   key.name = (char *)serviceName;
9829b01
-
9829b01
-  if (!strcmp(regtype, "_ipp._tcp."))
9829b01
-    key.type = CUPS_DEVICE_IPP;
9829b01
-  else if (!strcmp(regtype, "_ipps._tcp.") ||
9829b01
-	   !strcmp(regtype, "_ipp-tls._tcp."))
9829b01
-    key.type = CUPS_DEVICE_IPPS;
9829b01
-  else if (!strcmp(regtype, "_fax-ipp._tcp."))
9829b01
-    key.type = CUPS_DEVICE_FAX_IPP;
9829b01
-  else if (!strcmp(regtype, "_printer._tcp."))
9829b01
-    key.type = CUPS_DEVICE_PRINTER;
9829b01
-  else if (!strcmp(regtype, "_pdl-datastream._tcp."))
9829b01
-    key.type = CUPS_DEVICE_PDL_DATASTREAM;
9829b01
-  else
9829b01
-    key.type = CUPS_DEVICE_RIOUSBPRINT;
9829b01
+  key.type = device_type (regtype);
9829b01
 
9829b01
   for (device = cupsArrayFind(devices, &key);
9829b01
        device;
fecfdf6
@@ -627,8 +878,14 @@ get_device(cups_array_t *devices,	/* I -
9829b01
         free(device->domain);
9829b01
 	device->domain = strdup(replyDomain);
9829b01
 
9829b01
+#ifdef HAVE_DNSSD
9829b01
 	DNSServiceConstructFullName(fullName, device->name, regtype,
9829b01
 	                            replyDomain);
9829b01
+#else /* HAVE_AVAHI */
9829b01
+	avahi_service_name_join (fullName, kDNSServiceMaxDomainName,
9829b01
+				 serviceName, regtype, replyDomain);
9829b01
+#endif /* HAVE_DNSSD */
9829b01
+
9829b01
 	free(device->fullName);
9829b01
 	device->fullName = strdup(fullName);
9829b01
       }
fecfdf6
@@ -648,6 +905,9 @@ get_device(cups_array_t *devices,	/* I -
9829b01
   device->domain   = strdup(replyDomain);
9829b01
   device->type     = key.type;
9829b01
   device->priority = 50;
9829b01
+#ifdef HAVE_AVAHI
9829b01
+  device->resolved = 0;
9829b01
+#endif /* HAVE_AVAHI */
9829b01
 
9829b01
   cupsArrayAdd(devices, device);
9829b01
 
fecfdf6
@@ -655,13 +915,20 @@ get_device(cups_array_t *devices,	/* I -
9829b01
   * Set the "full name" of this service, which is used for queries...
9829b01
   */
9829b01
 
9829b01
+#ifdef HAVE_DNSSD
9829b01
   DNSServiceConstructFullName(fullName, serviceName, regtype, replyDomain);
9829b01
+#else /* HAVE_AVAHI */
9829b01
+  avahi_service_name_join (fullName, kDNSServiceMaxDomainName,
9829b01
+			   serviceName, regtype, replyDomain);
9829b01
+#endif /* HAVE_DNSSD */
9829b01
+
9829b01
   device->fullName = strdup(fullName);
9829b01
 
9829b01
   return (device);
9829b01
 }
9829b01
 
9829b01
 
9829b01
+#ifdef HAVE_DNSSD
9829b01
 /*
9829b01
  * 'query_callback()' - Process query data.
9829b01
  */
fecfdf6
@@ -685,7 +952,7 @@ query_callback(
9829b01
 		*ptr;			/* Pointer into string */
9829b01
   cups_device_t	dkey,			/* Search key */
9829b01
 		*device;		/* Device */
9829b01
-
9829b01
+  cups_txt_records_t txt;
9829b01
 
9829b01
   fprintf(stderr, "DEBUG2: query_callback(sdRef=%p, flags=%x, "
9829b01
                   "interfaceIndex=%d, errorCode=%d, fullName=\"%s\", "
fecfdf6
@@ -719,94 +986,233 @@ query_callback(
9829b01
   if ((ptr = strstr(name, "._")) != NULL)
9829b01
     *ptr = '\0';
9829b01
 
9829b01
-  if (strstr(fullName, "_ipp._tcp."))
9829b01
-    dkey.type = CUPS_DEVICE_IPP;
9829b01
-  else if (strstr(fullName, "_ipps._tcp.") ||
9829b01
-           strstr(fullName, "_ipp-tls._tcp."))
9829b01
-    dkey.type = CUPS_DEVICE_IPPS;
9829b01
-  else if (strstr(fullName, "_fax-ipp._tcp."))
9829b01
-    dkey.type = CUPS_DEVICE_FAX_IPP;
9829b01
-  else if (strstr(fullName, "_printer._tcp."))
9829b01
-    dkey.type = CUPS_DEVICE_PRINTER;
9829b01
-  else if (strstr(fullName, "_pdl-datastream._tcp."))
9829b01
-    dkey.type = CUPS_DEVICE_PDL_DATASTREAM;
9829b01
+  dkey.type = device_type (fullName);
9829b01
+
9829b01
+  txt.data = rdata;
9829b01
+  txt.dataend = rdata + rdlen;
9829b01
+  device = find_device ((cups_array_t *) context, &txt, &dkey);
9829b01
+  if (!device)
9829b01
+    fprintf(stderr, "DEBUG: Ignoring TXT record for \"%s\"...\n", fullName);
9829b01
+}
9829b01
+#endif /* HAVE_DNSSD */
9829b01
+
9829b01
+
9829b01
+#ifdef HAVE_AVAHI
9829b01
+/*
9829b01
+ * 'avahi_client_callback()' - Avahi client callback function.
9829b01
+ */
9829b01
+
9829b01
+static void
9829b01
+avahi_client_callback(AvahiClient *client,
9829b01
+		      AvahiClientState state,
9829b01
+		      void *context)
9829b01
+{
9829b01
+ /*
9829b01
+  * If the connection drops, quit.
9829b01
+  */
9829b01
+
9829b01
+  if (state == AVAHI_CLIENT_FAILURE)
9829b01
+  {
9829b01
+    fprintf (stderr, "ERROR: Avahi connection failed\n");
9829b01
+    avahi_simple_poll_quit (simple_poll);
9829b01
+  }
9829b01
+}
9829b01
+
9829b01
+
9829b01
+/*
9829b01
+ * 'avahi_query_callback()' - Avahi query callback function.
9829b01
+ */
9829b01
+
9829b01
+static void
9829b01
+avahi_query_callback(AvahiServiceResolver *resolver,
9829b01
+		     AvahiIfIndex interface,
9829b01
+		     AvahiProtocol protocol,
9829b01
+		     AvahiResolverEvent event,
9829b01
+		     const char *name,
9829b01
+		     const char *type,
9829b01
+		     const char *domain,
9829b01
+		     const char *host_name,
9829b01
+		     const AvahiAddress *address,
9829b01
+		     uint16_t port,
9829b01
+		     AvahiStringList *txt,
9829b01
+		     AvahiLookupResultFlags flags,
9829b01
+		     void *context)
9829b01
+{
9829b01
+  AvahiClient		*client;
9829b01
+  cups_device_t		key,
9829b01
+			*device;
9829b01
+  char			uqname[1024],
9829b01
+			*ptr;
9829b01
+  cups_txt_records_t	txtr;
9829b01
+
9829b01
+  client = avahi_service_resolver_get_client (resolver);
9829b01
+  if (event != AVAHI_RESOLVER_FOUND)
9829b01
+  {
9829b01
+    if (event == AVAHI_RESOLVER_FAILURE)
9829b01
+    {
9829b01
+      fprintf (stderr, "ERROR: %s\n",
9829b01
+	       avahi_strerror (avahi_client_errno (client)));
9829b01
+    }
9829b01
+
9829b01
+    avahi_service_resolver_free (resolver);
9829b01
+    return;
9829b01
+  }
9829b01
+
9829b01
+ /*
9829b01
+  * Set search key for device.
9829b01
+  */
9829b01
+
9829b01
+  key.name = uqname;
9829b01
+  unquote (uqname, name, sizeof (uqname));
9829b01
+  if ((ptr = strstr(name, "._")) != NULL)
9829b01
+    *ptr = '\0';
9829b01
+
9829b01
+  key.domain = (char *) domain;
9829b01
+  key.type = device_type (type);
9829b01
+
9829b01
+ /*
9829b01
+  * Find the device and the the TXT information.
9829b01
+  */
9829b01
+
9829b01
+  txtr.txt = txt;
9829b01
+  device = find_device ((cups_array_t *) context, &txtr, &key);
9829b01
+  if (device)
9829b01
+  {
9829b01
+   /*
9829b01
+    * Let the main loop know to announce the device.
9829b01
+    */
9829b01
+
9829b01
+    device->resolved = 1;
9829b01
+    avahi_got_callback = 1;
9829b01
+  }
9829b01
   else
9829b01
-    dkey.type = CUPS_DEVICE_RIOUSBPRINT;
9829b01
+    fprintf (stderr, "DEBUG: Ignoring TXT record for \"%s\"...\n", name);
fecfdf6
 
fecfdf6
-  for (device = cupsArrayFind(devices, &dkey);
9829b01
+  avahi_service_resolver_free (resolver);
9829b01
+}
9829b01
+
9829b01
+
9829b01
+/*
9829b01
+ * 'avahi_browse_callback()' - Avahi browse callback function.
9829b01
+ */
9829b01
+
9829b01
+static void
9829b01
+avahi_browse_callback(AvahiServiceBrowser *browser,
9829b01
+		      AvahiIfIndex interface,
9829b01
+		      AvahiProtocol protocol,
9829b01
+		      AvahiBrowserEvent event,
9829b01
+		      const char *name,
9829b01
+		      const char *type,
9829b01
+		      const char *domain,
9829b01
+		      AvahiLookupResultFlags flags,
9829b01
+		      void *context)
9829b01
+{
9829b01
+  AvahiClient *client = avahi_service_browser_get_client (browser);
9829b01
+
9829b01
+  switch (event)
9829b01
+  {
9829b01
+  case AVAHI_BROWSER_FAILURE:
9829b01
+    fprintf (stderr, "ERROR: %s\n",
9829b01
+	     avahi_strerror (avahi_client_errno (client)));
9829b01
+    avahi_simple_poll_quit (simple_poll);
9829b01
+    return;
9829b01
+
9829b01
+  case AVAHI_BROWSER_NEW:
9829b01
+   /*
9829b01
+    * This object is new on the network.
9829b01
+    */
9829b01
+
9829b01
+    if (flags & AVAHI_LOOKUP_RESULT_LOCAL)
9829b01
+    {
9829b01
+     /*
9829b01
+      * This comes from the local machine so ignore it.
9829b01
+      */
9829b01
+
9829b01
+      fprintf (stderr, "DEBUG: ignoring local service %s\n", name);
9829b01
+    }
9829b01
+    else
9829b01
+    {
9829b01
+     /*
9829b01
+      * Create a device entry for it if it doesn't yet exist.
9829b01
+      */
9829b01
+
9829b01
+      get_device ((cups_array_t *)context, name, type, domain);
9829b01
+
9829b01
+     /*
9829b01
+      * Now look for a TXT entry.
9829b01
+      */
9829b01
+
9829b01
+      if (avahi_service_resolver_new (client, interface, protocol,
9829b01
+				      name, type, domain,
9829b01
+				      AVAHI_PROTO_UNSPEC, 0,
9829b01
+				      avahi_query_callback, context) == NULL)
9829b01
+      {
9829b01
+	fprintf (stderr, "ERROR: failed to resolve service %s: %s\n",
9829b01
+		 name, avahi_strerror (avahi_client_errno (client)));
9829b01
+      }
9829b01
+    }
9829b01
+
9829b01
+    break;
9829b01
+
9829b01
+  case AVAHI_BROWSER_REMOVE:
9829b01
+  case AVAHI_BROWSER_ALL_FOR_NOW:
9829b01
+  case AVAHI_BROWSER_CACHE_EXHAUSTED:
9829b01
+    break;
9829b01
+  }
9829b01
+}
9829b01
+#endif /* HAVE_AVAHI */
9829b01
+
fecfdf6
+
9829b01
+/*
9829b01
+ * 'find_device()' - Find a device from its name and domain.
9829b01
+ */
9829b01
+
9829b01
+static cups_device_t *
9829b01
+find_device (cups_array_t *devices,
9829b01
+	     cups_txt_records_t *txt,
9829b01
+	     cups_device_t *dkey)
9829b01
+{
9829b01
+  cups_device_t	*device;
9829b01
+  char		*ptr;
9829b01
+
9829b01
+  for (device = cupsArrayFind(devices, dkey);
9829b01
        device;
9829b01
        device = cupsArrayNext(devices))
9829b01
   {
9829b01
-    if (_cups_strcasecmp(device->name, dkey.name) ||
9829b01
-        _cups_strcasecmp(device->domain, dkey.domain))
9829b01
+    if (_cups_strcasecmp(device->name, dkey->name) ||
9829b01
+        _cups_strcasecmp(device->domain, dkey->domain))
9829b01
     {
9829b01
       device = NULL;
9829b01
       break;
9829b01
     }
9829b01
-    else if (device->type == dkey.type)
9829b01
+    else if (device->type == dkey->type)
9829b01
     {
9829b01
      /*
9829b01
       * Found it, pull out the priority and make and model from the TXT
9829b01
       * record and save it...
9829b01
       */
9829b01
 
9829b01
-      const uint8_t	*data,		/* Pointer into data */
9829b01
-			*datanext,	/* Next key/value pair */
9829b01
-			*dataend;	/* End of entire TXT record */
9829b01
-      uint8_t		datalen;	/* Length of current key/value pair */
9829b01
-      char		key[256],	/* Key string */
9829b01
-			value[256],	/* Value string */
9829b01
-			make_and_model[512],
9829b01
+      char		make_and_model[512],
9829b01
 				      	/* Manufacturer and model */
9829b01
 			model[256],	/* Model */
9829b01
-			device_id[2048];/* 1284 device ID */
9829b01
-
9829b01
+			device_id[2048]; /* 1284 device ID */
9829b01
 
9829b01
       device_id[0]      = '\0';
9829b01
       make_and_model[0] = '\0';
9829b01
 
9829b01
       strcpy(model, "Unknown");
9829b01
 
9829b01
-      for (data = rdata, dataend = data + rdlen;
9829b01
-           data < dataend;
9829b01
-           data = datanext)
9829b01
+      for (;;)
9829b01
       {
9829b01
-       /*
9829b01
-        * Read a key/value pair starting with an 8-bit length.  Since the
9829b01
-	* length is 8 bits and the size of the key/value buffers is 256, we
9829b01
-	* don't need to check for overflow...
9829b01
-	*/
9829b01
-
9829b01
-        datalen = *data++;
9829b01
-
9495754
-        if (!datalen || (data + datalen) > dataend)
9829b01
-	  break;
9829b01
-
9829b01
-        datanext = data + datalen;
9829b01
-
9829b01
-        for (ptr = key; data < datanext && *data != '='; data ++)
9829b01
-	  *ptr++ = *data;
9829b01
-	*ptr = '\0';
9829b01
+	char *key;
9829b01
+	char *value;
9829b01
 
9829b01
-	if (data < datanext && *data == '=')
9829b01
-	{
9829b01
-	  data ++;
9829b01
-
9829b01
-	  if (data < datanext)
9829b01
-	    memcpy(value, data, datanext - data);
9829b01
-	  value[datanext - data] = '\0';
9829b01
+	if (parse_txt_record_pair (txt))
9829b01
+	  goto next;
9829b01
 
9829b01
-	  fprintf(stderr, "DEBUG2: query_callback: \"%s=%s\".\n",
9829b01
-	          key, value);
9829b01
-	}
9829b01
-	else
9829b01
-	{
9829b01
-	  fprintf(stderr, "DEBUG2: query_callback: \"%s\" with no value.\n",
9829b01
-	          key);
9829b01
-	  continue;
9829b01
-	}
9829b01
-
9829b01
-        if (!_cups_strncasecmp(key, "usb_", 4))
9829b01
+	key = txt->key;
9829b01
+	value = txt->value;
9829b01
+        if (!strncasecmp(key, "usb_", 4))
9829b01
 	{
9829b01
 	 /*
9829b01
 	  * Add USB device ID information...
fecfdf6
@@ -861,6 +1267,10 @@ query_callback(
9829b01
 	  if (device->type == CUPS_DEVICE_PRINTER)
9829b01
 	    device->sent = 1;
9829b01
 	}
9829b01
+
9829b01
+      next:
9829b01
+	if (next_txt_record (txt) == NULL)
9829b01
+	  break;
9829b01
       }
9829b01
 
9829b01
       if (device->device_id)
fecfdf6
@@ -917,11 +1327,9 @@ query_callback(
9829b01
     }
9829b01
   }
9829b01
 
9829b01
-  if (!device)
9829b01
-    fprintf(stderr, "DEBUG: Ignoring TXT record for \"%s\"...\n", fullName);
9829b01
+  return device;
9829b01
 }
9829b01
 
9829b01
-
9829b01
 /*
9829b01
  * 'sigterm_handler()' - Handle termination signals...
9829b01
  */
fecfdf6
diff -up cups-1.5.3/cups/http-support.c.avahi-2-backend cups-1.5.3/cups/http-support.c
fecfdf6
--- cups-1.5.3/cups/http-support.c.avahi-2-backend	2012-02-15 02:06:12.000000000 +0100
fecfdf6
+++ cups-1.5.3/cups/http-support.c	2012-05-15 17:04:51.045944634 +0200
9829b01
@@ -43,6 +43,10 @@
9829b01
  *   http_copy_decode()   - Copy and decode a URI.
9829b01
  *   http_copy_encode()   - Copy and encode a URI.
9829b01
  *   http_resolve_cb()    - Build a device URI for the given service name.
9829b01
+ *   avahi_resolve_uri_client_cb()
9829b01
+ *                        - Avahi client callback for resolving URI.
9829b01
+ *   avahi_resolve_uri_resolver_cb()
9829b01
+ *                        - Avahi resolver callback for resolving URI.
9829b01
  */
9829b01
 
9829b01
 /*
9829b01
@@ -60,6 +64,11 @@
9829b01
 #    include <sys/select.h>
9829b01
 #  endif /* WIN32 */
9829b01
 #endif /* HAVE_DNSSD */
9829b01
+#ifdef HAVE_AVAHI
9829b01
+#  include <avahi-client/client.h>
9829b01
+#  include <avahi-client/lookup.h>
9829b01
+#  include <avahi-common/simple-watch.h>
9829b01
+#endif /* HAVE_AVAHI */
9829b01
 
9829b01
 
9829b01
 /*
9829b01
@@ -127,6 +136,24 @@ static void DNSSD_API	http_resolve_cb(DN
9829b01
 					void *context);
9829b01
 #endif /* HAVE_DNSSD */
9829b01
 
9829b01
+#ifdef HAVE_AVAHI
9829b01
+static void	avahi_resolve_uri_client_cb(AvahiClient *client,
9829b01
+					    AvahiClientState state,
9829b01
+					    void *simple_poll);
9829b01
+static void	avahi_resolve_uri_resolver_cb(AvahiServiceResolver *resolver,
9829b01
+					      AvahiIfIndex interface,
9829b01
+					      AvahiProtocol protocol,
9829b01
+					      AvahiResolverEvent event,
9829b01
+					      const char *name,
9829b01
+					      const char *type,
9829b01
+					      const char *domain,
9829b01
+					      const char *host_name,
9829b01
+					      const AvahiAddress *address,
9829b01
+					      uint16_t port,
9829b01
+					      AvahiStringList *txt,
9829b01
+					      AvahiLookupResultFlags flags,
9829b01
+					      void *context);
9829b01
+#endif /* HAVE_AVAHI */
9829b01
 
9829b01
 /*
9829b01
  * 'httpAssembleURI()' - Assemble a uniform resource identifier from its
fecfdf6
@@ -1434,6 +1461,9 @@ _httpResolveURI(
9829b01
 
9829b01
   if (strstr(hostname, "._tcp"))
9829b01
   {
9829b01
+#if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
9829b01
+    char		*regtype,	/* Pointer to type in hostname */
9829b01
+			*domain;	/* Pointer to domain in hostname */
9829b01
 #ifdef HAVE_DNSSD
9829b01
 #  ifdef WIN32
9829b01
 #    pragma comment(lib, "dnssd.lib")
fecfdf6
@@ -1452,6 +1482,17 @@ _httpResolveURI(
9829b01
     fd_set		input_set;	/* Input set for select() */
9829b01
     struct timeval	stimeout;	/* Timeout value for select() */
9829b01
 #endif /* HAVE_POLL */
9829b01
+#else /* HAVE_AVAHI */
9829b01
+    AvahiSimplePoll	*simple_poll;
9829b01
+    AvahiClient		*client;
9829b01
+    int			error;
9829b01
+    struct
9829b01
+    {
9829b01
+      AvahiSimplePoll	*poll;
9829b01
+      _http_uribuf_t	uribuf;
9829b01
+    } user_data;
9829b01
+#endif /* HAVE_DNSSD */
9829b01
+
9829b01
 
9829b01
     if (options & _HTTP_RESOLVE_STDERR)
9829b01
       fprintf(stderr, "DEBUG: Resolving \"%s\"...\n", hostname);
fecfdf6
@@ -1488,9 +1529,16 @@ _httpResolveURI(
9829b01
     if (domain)
9829b01
       *domain++ = '\0';
9829b01
 
9829b01
+#ifdef HAVE_DNSSD
9829b01
     uribuf.buffer   = resolved_uri;
9829b01
     uribuf.bufsize  = resolved_size;
9829b01
     uribuf.options  = options;
9829b01
+#else
9829b01
+    user_data.uribuf.buffer = resolved_uri;
9829b01
+    user_data.uribuf.bufsize = resolved_size;
9829b01
+    user_data.uribuf.options = options;
9829b01
+#endif
9829b01
+
9829b01
     resolved_uri[0] = '\0';
9829b01
 
9829b01
     DEBUG_printf(("6_httpResolveURI: Resolving hostname=\"%s\", regtype=\"%s\", "
fecfdf6
@@ -1504,6 +1552,7 @@ _httpResolveURI(
9829b01
 
9829b01
     uri = NULL;
9829b01
 
9829b01
+#ifdef HAVE_DNSSD
9829b01
     if (DNSServiceCreateConnection(&ref) == kDNSServiceErr_NoError)
9829b01
     {
9829b01
       localref = ref;
fecfdf6
@@ -1611,6 +1660,36 @@ _httpResolveURI(
9829b01
 
9829b01
       DNSServiceRefDeallocate(ref);
9829b01
     }
9829b01
+#else /* HAVE_AVAHI */
9829b01
+    if ((simple_poll = avahi_simple_poll_new ()) != NULL)
9829b01
+    {
9829b01
+      if ((client = avahi_client_new (avahi_simple_poll_get (simple_poll),
9829b01
+				      0, avahi_resolve_uri_client_cb,
9829b01
+				      &simple_poll, &error)) != NULL)
9829b01
+      {
9829b01
+	user_data.poll = simple_poll;
9829b01
+	if (avahi_service_resolver_new (client, AVAHI_IF_UNSPEC,
9829b01
+					AVAHI_PROTO_UNSPEC, hostname,
9829b01
+					regtype, domain, AVAHI_PROTO_UNSPEC, 0,
9829b01
+					avahi_resolve_uri_resolver_cb,
9829b01
+					&user_data) != NULL)
9829b01
+	{
9829b01
+	  avahi_simple_poll_loop (simple_poll);
9829b01
+
9829b01
+	 /*
9829b01
+	  * Collect the result.
9829b01
+	  */
9829b01
+
9829b01
+	  if (resolved_uri[0])
9829b01
+	    uri = resolved_uri;
9829b01
+	}
9829b01
+
9829b01
+	avahi_client_free (client);
9829b01
+      }
9829b01
+
9829b01
+      avahi_simple_poll_free (simple_poll);
9829b01
+    }
9829b01
+#endif /* HAVE_DNSSD */
9829b01
 
9829b01
     if (options & _HTTP_RESOLVE_STDERR)
9829b01
     {
fecfdf6
@@ -1622,13 +1701,13 @@ _httpResolveURI(
9829b01
       fputs("STATE: -connecting-to-device,offline-report\n", stderr);
9829b01
     }
9829b01
 
9829b01
-#else
9829b01
+#else /* HAVE_DNSSD || HAVE_AVAHI */
9829b01
    /*
9829b01
     * No DNS-SD support...
9829b01
     */
9829b01
 
9829b01
     uri = NULL;
9829b01
-#endif /* HAVE_DNSSD */
9829b01
+#endif /* HAVE_DNSSD || HAVE_AVAHI */
9829b01
 
9829b01
     if ((options & _HTTP_RESOLVE_STDERR) && !uri)
9829b01
       _cupsLangPrintFilter(stderr, "ERROR", _("Unable to find printer."));
fecfdf6
@@ -1916,6 +1995,115 @@ http_resolve_cb(
fecfdf6
 }
9829b01
 #endif /* HAVE_DNSSD */
9829b01
 
9829b01
+#ifdef HAVE_AVAHI
9829b01
+/*
9829b01
+ * 'avahi_resolve_uri_client_cb()' - Avahi client callback for resolving URI.
9829b01
+ */
9829b01
+
9829b01
+static void
9829b01
+avahi_resolve_uri_client_cb (AvahiClient *client,
9829b01
+			     AvahiClientState state,
9829b01
+			     void *simple_poll)
9829b01
+{
9829b01
+  DEBUG_printf(("avahi_resolve_uri_client_callback(client=%p, state=%d, "
9829b01
+		"simple_poll=%p)\n", client, state, simple_poll));
9829b01
+
9829b01
+  /*
9829b01
+   * If the connection drops, quit.
9829b01
+   */
9829b01
+
9829b01
+  if (state == AVAHI_CLIENT_FAILURE)
9829b01
+    avahi_simple_poll_quit (simple_poll);
9829b01
+}
9829b01
+
9829b01
+
9829b01
+/*
9829b01
+ * 'avahi_resolve_uri_resolver_cb()' - Avahi resolver callback for resolving
9829b01
+ *                                     URI.
9829b01
+ */
9829b01
+
9829b01
+static void
9829b01
+avahi_resolve_uri_resolver_cb (AvahiServiceResolver *resolver,
9829b01
+			       AvahiIfIndex interface,
9829b01
+			       AvahiProtocol protocol,
9829b01
+			       AvahiResolverEvent event,
9829b01
+			       const char *name,
9829b01
+			       const char *type,
9829b01
+			       const char *domain,
9829b01
+			       const char *host_name,
9829b01
+			       const AvahiAddress *address,
9829b01
+			       uint16_t port,
9829b01
+			       AvahiStringList *txt,
9829b01
+			       AvahiLookupResultFlags flags,
9829b01
+			       void *context)
9829b01
+{
9829b01
+  const char		*scheme;	/* URI scheme */
9829b01
+  char			rp[256];	/* Remote printer */
9829b01
+  AvahiStringList	*pair;
9829b01
+  char			*value;
9829b01
+  size_t		valueLen = 0;
9829b01
+  char			addr[AVAHI_ADDRESS_STR_MAX];
9829b01
+  struct
9829b01
+  {
9829b01
+    AvahiSimplePoll	*poll;
9829b01
+    _http_uribuf_t	uribuf;
9829b01
+  }		*poll_uribuf = context;
9829b01
+
9829b01
+  DEBUG_printf(("avahi_resolve_uri_resolver_callback(resolver=%p, "
9829b01
+		"interface=%d, protocol=%d, event=%d, name=\"%s\", "
9829b01
+		"type=\"%s\", domain=\"%s\", host_name=\"%s\", address=%p, "
9829b01
+		"port=%d, txt=%p, flags=%d, context=%p)\n",
9829b01
+		resolver, interface, protocol, event, name, type, domain,
9829b01
+		host_name, address, port, txt, flags, context));
9829b01
+
9829b01
+  if (event != AVAHI_RESOLVER_FOUND)
9829b01
+  {
9829b01
+    avahi_service_resolver_free (resolver);
9829b01
+    avahi_simple_poll_quit (poll_uribuf->poll);
9829b01
+    return;
9829b01
+  }
9829b01
+
9829b01
+ /*
9829b01
+  * Figure out the scheme from the full name...
9829b01
+  */
9829b01
+
9829b01
+  if (strstr(type, "_ipp."))
9829b01
+    scheme = "ipp";
9829b01
+  else if (strstr(type, "_printer."))
9829b01
+    scheme = "lpd";
9829b01
+  else if (strstr(type, "_pdl-datastream."))
9829b01
+    scheme = "socket";
9829b01
+  else
9829b01
+    scheme = "riousbprint";
9829b01
+
9829b01
+ /*
9829b01
+  * Extract the "remote printer key from the TXT record...
9829b01
+  */
9829b01
+
9829b01
+  if ((pair = avahi_string_list_find (txt, "rp")) != NULL)
9829b01
+  {
9829b01
+    avahi_string_list_get_pair (pair, NULL, &value, &valueLen);
9829b01
+    rp[0] = '/';
9829b01
+    memcpy (rp + 1, value, valueLen);
9829b01
+    rp[valueLen + 1] = '\0';
9829b01
+  }
9829b01
+  else
9829b01
+    rp[0] = '\0';
9829b01
+
9829b01
+ /*
9829b01
+  * Assemble the final device URI...
9829b01
+  */
9829b01
+
9829b01
+  avahi_address_snprint (addr, AVAHI_ADDRESS_STR_MAX, address);
9829b01
+  httpAssembleURI(HTTP_URI_CODING_ALL, poll_uribuf->uribuf.buffer,
9829b01
+		  poll_uribuf->uribuf.bufsize, scheme, NULL,
9829b01
+		  addr, port, rp);
9829b01
+  DEBUG_printf(("avahi_resolve_uri_resolver_callback: Resolved URI is \"%s\"\n",
9829b01
+		poll_uribuf->uribuf.buffer));
9829b01
+  avahi_simple_poll_quit (poll_uribuf->poll);
9829b01
+}
9829b01
+#endif /* HAVE_AVAHI */
9829b01
+
fecfdf6
 
9829b01
 /*
fecfdf6
  * End of "$Id: http-support.c 10284 2012-02-15 01:06:12Z mike $".