]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - scheduler/dirsvc.c
Merge changes from CUPS 1.5svn-r9641
[thirdparty/cups.git] / scheduler / dirsvc.c
index bc5b3a4669d3befaf152ab3c5e78152769a286a5..ad05fe4c3818266b42af443623e9c3afd9daf6d7 100644 (file)
@@ -1,56 +1,81 @@
 /*
- * "$Id: dirsvc.c 6205 2007-01-22 22:04:43Z mike $"
+ * "$Id: dirsvc.c 7933 2008-09-11 00:44:58Z mike $"
  *
- *   Directory services routines for the Common UNIX Printing System (CUPS).
+ *   Directory services routines for the CUPS scheduler.
  *
+ *   Copyright 2007-2011 by Apple Inc.
  *   Copyright 1997-2007 by Easy Software Products, all rights reserved.
  *
  *   These coded instructions, statements, and computer programs are the
- *   property of Easy Software Products and are protected by Federal
- *   copyright law.  Distribution and use rights are outlined in the file
- *   "LICENSE.txt" which should have been included with this file.  If this
- *   file is missing or damaged please contact Easy Software Products
- *   at:
- *
- *       Attn: CUPS Licensing Information
- *       Easy Software Products
- *       44141 Airport View Drive, Suite 204
- *       Hollywood, Maryland 20636 USA
- *
- *       Voice: (301) 373-9600
- *       EMail: cups-info@cups.org
- *         WWW: http://www.cups.org
+ *   property of Apple Inc. and are protected by Federal copyright
+ *   law.  Distribution and use rights are outlined in the file "LICENSE.txt"
+ *   which should have been included with this file.  If this file is
+ *   file is missing or damaged, see the license at "http://www.cups.org/".
  *
  * Contents:
  *
- *   cupsdLoadRemoteCache()        - Load the remote printer cache.
- *   cupsdSaveRemoteCache()        - Save the remote printer cache.
- *   cupsdSendBrowseDelete()       - Send a "browse delete" message for a
- *                                   printer.
- *   cupsdSendBrowseList()         - Send new browsing information as necessary.
- *   cupsdStartBrowsing()          - Start sending and receiving broadcast
- *                                   information.
- *   cupsdStartPolling()           - Start polling servers as needed.
- *   cupsdStopBrowsing()           - Stop sending and receiving broadcast
- *                                   information.
- *   cupsdStopPolling()            - Stop polling servers as needed.
- *   cupsdUpdateCUPSBrowse()       - Update the browse lists using the CUPS
- *                                   protocol.
- *   cupsdUpdateLDAPBrowse()       - Scan for new printers via LDAP...
- *   cupsdUpdatePolling()          - Read status messages from the poll daemons.
- *   cupsdUpdateSLPBrowse()        - Get browsing information via SLP.
- *   dequote()                     - Remote quotes from a string.
- *   process_browse_data()         - Process new browse data.
- *   process_implicit_classes()    - Create/update implicit classes as needed.
- *   send_cups_browse()            - Send new browsing information using the
- *                                   CUPS protocol.
- *   send_ldap_browse()            - Send LDAP printer registrations.
- *   send_slp_browse()             - Register the specified printer with SLP.
- *   slp_attr_callback()           - SLP attribute callback 
- *   slp_dereg_printer()           - SLPDereg() the specified printer
- *   slp_get_attr()                - Get an attribute from an SLP registration.
- *   slp_reg_callback()            - Empty SLPRegReport.
- *   slp_url_callback()            - SLP service url callback
+ *   cupsdDeregisterPrinter()   - Stop sending broadcast information for a local
+ *                                printer and remove any pending references to
+ *                                remote printers.
+ *   cupsdLoadRemoteCache()     - Load the remote printer cache.
+ *   cupsdRegisterPrinter()     - Start sending broadcast information for a
+ *                                printer or update the broadcast contents.
+ *   cupsdRestartPolling()      - Restart polling servers as needed.
+ *   cupsdSaveRemoteCache()     - Save the remote printer cache.
+ *   cupsdSendBrowseList()      - Send new browsing information as necessary.
+ *   ldap_rebind_proc()         - Callback function for LDAP rebind
+ *   ldap_connect()             - Start new LDAP connection
+ *   ldap_reconnect()           - Reconnect to LDAP Server
+ *   ldap_disconnect()          - Disconnect from LDAP Server
+ *   cupsdStartBrowsing()       - Start sending and receiving broadcast
+ *                                information.
+ *   cupsdStartPolling()        - Start polling servers as needed.
+ *   cupsdStopBrowsing()        - Stop sending and receiving broadcast
+ *                                information.
+ *   cupsdStopPolling()         - Stop polling servers as needed.
+ *   cupsdUpdateDNSSDName()     - Update the computer name we use for
+ *                                browsing...
+ *   cupsdUpdateLDAPBrowse()    - Scan for new printers via LDAP...
+ *   cupsdUpdateSLPBrowse()     - Get browsing information via SLP.
+ *   dequote()                  - Remote quotes from a string.
+ *   dnssdAddAlias()            - Add a DNS-SD alias name.
+ *   dnssdBuildTxtRecord()      - Build a TXT record from printer info.
+ *   dnssdComparePrinters()     - Compare the registered names of two printers.
+ *   dnssdDeregisterPrinter()   - Stop sending broadcast information for a
+ *                                printer.
+ *   dnssdPackTxtRecord()       - Pack an array of key/value pairs into the TXT
+ *                                record format.
+ *   dnssdRegisterCallback()    - DNSServiceRegister callback.
+ *   dnssdRegisterPrinter()     - Start sending broadcast information for a
+ *                                printer or update the broadcast contents.
+ *   dnssdStop()                - Stop all DNS-SD registrations.
+ *   dnssdUpdate()              - Handle DNS-SD queries.
+ *   get_auth_info_required()   - Get the auth-info-required value to advertise.
+ *   get_hostconfig()           - Get an /etc/hostconfig service setting.
+ *   is_local_queue()           - Determine whether the URI points at a local
+ *                                queue.
+ *   process_browse_data()      - Process new browse data.
+ *   process_implicit_classes() - Create/update implicit classes as needed.
+ *   send_cups_browse()         - Send new browsing information using the CUPS
+ *                                protocol.
+ *   ldap_search_rec()          - LDAP Search with reconnect
+ *   ldap_freeres()             - Free LDAPMessage
+ *   ldap_getval_char()         - Get first LDAP value and convert to string
+ *   send_ldap_ou()             - Send LDAP ou registrations.
+ *   send_ldap_browse()         - Send LDAP printer registrations.
+ *   ldap_dereg_printer()       - Delete printer from directory
+ *   ldap_dereg_ou()            - Remove the organizational unit.
+ *   send_slp_browse()          - Register the specified printer with SLP.
+ *   slp_attr_callback()        - SLP attribute callback
+ *   slp_dereg_printer()        - SLPDereg() the specified printer
+ *   slp_get_attr()             - Get an attribute from an SLP registration.
+ *   slp_reg_callback()         - Empty SLPRegReport.
+ *   slp_url_callback()         - SLP service url callback
+ *   update_cups_browse()       - Update the browse lists using the CUPS
+ *                                protocol.
+ *   update_lpd()               - Update the LPD configuration as needed.
+ *   update_polling()           - Read status messages from the poll daemons.
+ *   update_smb()               - Update the SMB configuration as needed.
  */
 
 /*
 #include "cupsd.h"
 #include <grp.h>
 
+#ifdef HAVE_DNSSD
+#  include <dns_sd.h>
+#  ifdef __APPLE__
+#    include <nameser.h>
+#    ifdef HAVE_COREFOUNDATION
+#      include <CoreFoundation/CoreFoundation.h>
+#    endif /* HAVE_COREFOUNDATION */
+#    ifdef HAVE_SYSTEMCONFIGURATION
+#      include <SystemConfiguration/SystemConfiguration.h>
+#    endif /* HAVE_SYSTEMCONFIGURATION */
+#  endif /* __APPLE__ */
+#endif /* HAVE_DNSSD */
+
 
 /*
  * Local functions...
  */
 
 static char    *dequote(char *d, const char *s, int dlen);
+static char    *get_auth_info_required(cupsd_printer_t *p, char *buffer,
+                                       size_t bufsize);
+#ifdef __APPLE__
+static int     get_hostconfig(const char *name);
+#endif /* __APPLE__ */
 static int     is_local_queue(const char *uri, char *host, int hostlen,
                               char *resource, int resourcelen);
 static void    process_browse_data(const char *uri, const char *host,
@@ -76,13 +119,68 @@ static void        process_browse_data(const char *uri, const char *host,
 static void    process_implicit_classes(void);
 static void    send_cups_browse(cupsd_printer_t *p);
 #ifdef HAVE_LDAP
+static LDAP    *ldap_connect(void);
+static LDAP    *ldap_reconnect(void);
+static void    ldap_disconnect(LDAP *ld);
+static int     ldap_search_rec(LDAP *ld, char *base, int scope,
+                                char *filter, char *attrs[],
+                                int attrsonly, LDAPMessage **res);
+static int     ldap_getval_firststring(LDAP *ld, LDAPMessage *entry,
+                                        char *attr, char *retval,
+                                        unsigned long maxsize);
+static void    ldap_freeres(LDAPMessage *entry);
+static void    send_ldap_ou(char *ou, char *basedn, char *descstring);
 static void    send_ldap_browse(cupsd_printer_t *p);
+static void    ldap_dereg_printer(cupsd_printer_t *p);
+static void    ldap_dereg_ou(char *ou, char *basedn);
+#  ifdef HAVE_LDAP_REBIND_PROC
+#    if defined(LDAP_API_FEATURE_X_OPENLDAP) && (LDAP_API_VERSION > 2000)
+static int     ldap_rebind_proc(LDAP *RebindLDAPHandle,
+                                 LDAP_CONST char *refsp,
+                                 ber_tag_t request,
+                                 ber_int_t msgid,
+                                 void *params);
+#    else
+static int     ldap_rebind_proc(LDAP *RebindLDAPHandle,
+                                 char **dnp,
+                                 char **passwdp,
+                                 int *authmethodp,
+                                 int freeit,
+                                 void *arg);
+#    endif /* defined(LDAP_API_FEATURE_X_OPENLDAP) && (LDAP_API_VERSION > 2000) */
+#  endif /* HAVE_LDAP_REBIND_PROC */
 #endif /* HAVE_LDAP */
 #ifdef HAVE_LIBSLP
 static void    send_slp_browse(cupsd_printer_t *p);
 #endif /* HAVE_LIBSLP */
+static void    update_cups_browse(void);
+static void    update_lpd(int onoff);
+static void    update_polling(void);
+static void    update_smb(int onoff);
+
+
+#ifdef HAVE_DNSSD
+#  ifdef HAVE_COREFOUNDATION
+static void    dnssdAddAlias(const void *key, const void *value,
+                             void *context);
+#  endif /* HAVE_COREFOUNDATION */
+static char    *dnssdBuildTxtRecord(int *txt_len, cupsd_printer_t *p,
+                                    int for_lpd);
+static int     dnssdComparePrinters(cupsd_printer_t *a, cupsd_printer_t *b);
+static void    dnssdDeregisterPrinter(cupsd_printer_t *p);
+static char    *dnssdPackTxtRecord(int *txt_len, char *keyvalue[][2],
+                                   int count);
+static void    dnssdRegisterCallback(DNSServiceRef sdRef,
+                                     DNSServiceFlags flags, 
+                                     DNSServiceErrorType errorCode,
+                                     const char *name, const char *regtype,
+                                     const char *domain, void *context);
+static void    dnssdRegisterPrinter(cupsd_printer_t *p);
+static void    dnssdStop(void);
+static void    dnssdUpdate(void);
+#endif /* HAVE_DNSSD */
 
-#ifdef HAVE_OPENLDAP
+#ifdef HAVE_LDAP
 static const char * const ldap_attrs[] =/* CUPS LDAP attributes */
                {
                  "printerDescription",
@@ -92,7 +190,7 @@ static const char * const ldap_attrs[] =/* CUPS LDAP attributes */
                  "printerURI",
                  NULL
                };
-#endif /* HAVE_OPENLDAP */
+#endif /* HAVE_LDAP */
 
 #ifdef HAVE_LIBSLP 
 /*
@@ -136,6 +234,62 @@ static SLPBoolean  slp_url_callback(SLPHandle hslp, const char *srvurl,
 #endif /* HAVE_LIBSLP */
 
 
+/*
+ * 'cupsdDeregisterPrinter()' - Stop sending broadcast information for a 
+ *                             local printer and remove any pending
+ *                              references to remote printers.
+ */
+
+void
+cupsdDeregisterPrinter(
+    cupsd_printer_t *p,                        /* I - Printer to register */
+    int             removeit)          /* I - Printer being permanently removed */
+{
+ /*
+  * Only deregister if browsing is enabled and it's a local printer...
+  */
+
+  cupsdLogMessage(CUPSD_LOG_DEBUG,
+                  "cupsdDeregisterPrinter(p=%p(%s), removeit=%d)", p, p->name,
+                 removeit);
+
+  if (!Browsing || !p->shared ||
+      (p->type & (CUPS_PRINTER_REMOTE | CUPS_PRINTER_IMPLICIT |
+                  CUPS_PRINTER_SCANNER)))
+    return;
+
+ /*
+  * Announce the deletion...
+  */
+
+  if ((BrowseLocalProtocols & BROWSE_CUPS) && BrowseSocket >= 0)
+  {
+    cups_ptype_t savedtype = p->type;  /* Saved printer type */
+
+    p->type |= CUPS_PRINTER_DELETE;
+
+    send_cups_browse(p);
+
+    p->type = savedtype;
+  }
+
+#ifdef HAVE_LIBSLP
+  if (BrowseLocalProtocols & BROWSE_SLP)
+    slp_dereg_printer(p);
+#endif /* HAVE_LIBSLP */
+
+#ifdef HAVE_LDAP
+  if (BrowseLocalProtocols & BROWSE_LDAP)
+    ldap_dereg_printer(p);
+#endif /* HAVE_LDAP */
+
+#ifdef HAVE_DNSSD
+  if (removeit && (BrowseLocalProtocols & BROWSE_DNSSD) && DNSSDRef)
+    dnssdDeregisterPrinter(p);
+#endif /* HAVE_DNSSD */
+}
+
+
 /*
  * 'cupsdLoadRemoteCache()' - Load the remote printer cache.
  */
@@ -143,9 +297,10 @@ static SLPBoolean  slp_url_callback(SLPHandle hslp, const char *srvurl,
 void
 cupsdLoadRemoteCache(void)
 {
+  int                  i;              /* Looping var */
   cups_file_t          *fp;            /* remote.cache file */
   int                  linenum;        /* Current line number */
-  char                 line[1024],     /* Line from file */
+  char                 line[4096],     /* Line from file */
                        *value,         /* Pointer to value */
                        *valueptr,      /* Pointer into value */
                        scheme[32],     /* Scheme portion of URI */
@@ -160,10 +315,10 @@ cupsdLoadRemoteCache(void)
 
 
  /*
-  * Don't load the cache if the CUPS remote protocol is disabled...
+  * Don't load the cache if the remote protocols are disabled...
   */
 
-  if (!Browsing || !(BrowseRemoteProtocols & BROWSE_CUPS))
+  if (!Browsing)
   {
     cupsdLogMessage(CUPSD_LOG_DEBUG,
                     "cupsdLoadRemoteCache: Not loading remote cache.");
@@ -225,7 +380,7 @@ cupsdLoadRemoteCache(void)
 
        p->accepting     = 1;
        p->state         = IPP_PRINTER_IDLE;
-       p->type          |= CUPS_PRINTER_REMOTE;
+       p->type          |= CUPS_PRINTER_REMOTE | CUPS_PRINTER_DISCOVERED;
        p->browse_time   = now;
        p->browse_expire = now + BrowseTimeout;
 
@@ -240,7 +395,7 @@ cupsdLoadRemoteCache(void)
       {
         cupsdLogMessage(CUPSD_LOG_ERROR,
                        "Syntax error on line %d of remote.cache.", linenum);
-        return;
+        break;
       }
     }
     else if (!strcasecmp(line, "<Class") ||
@@ -266,7 +421,7 @@ cupsdLoadRemoteCache(void)
 
        p->accepting     = 1;
        p->state         = IPP_PRINTER_IDLE;
-       p->type          |= CUPS_PRINTER_REMOTE;
+       p->type          |= CUPS_PRINTER_REMOTE | CUPS_PRINTER_DISCOVERED;
        p->browse_time   = now;
        p->browse_expire = now + BrowseTimeout;
 
@@ -281,7 +436,7 @@ cupsdLoadRemoteCache(void)
       {
         cupsdLogMessage(CUPSD_LOG_ERROR,
                        "Syntax error on line %d of remote.cache.", linenum);
-        return;
+        break;
       }
     }
     else if (!strcasecmp(line, "</Printer>") ||
@@ -298,17 +453,21 @@ cupsdLoadRemoteCache(void)
         p = NULL;
       }
       else
-      {
         cupsdLogMessage(CUPSD_LOG_ERROR,
                        "Syntax error on line %d of remote.cache.", linenum);
-        return;
-      }
     }
     else if (!p)
     {
       cupsdLogMessage(CUPSD_LOG_ERROR,
                       "Syntax error on line %d of remote.cache.", linenum);
-      return;
+    }
+    else if (!strcasecmp(line, "UUID"))
+    {
+      if (value && !strncmp(value, "urn:uuid:", 9))
+        cupsdSetString(&(p->uuid), value);
+      else
+        cupsdLogMessage(CUPSD_LOG_ERROR,
+                       "Bad UUID on line %d of remote.cache.", linenum);
     }
     else if (!strcasecmp(line, "Info"))
     {
@@ -335,14 +494,11 @@ cupsdLoadRemoteCache(void)
 
        cupsdSetString(&p->hostname, host);
        cupsdSetString(&p->uri, value);
-       cupsdSetString(&p->device_uri, value);
+       cupsdSetDeviceURI(p, value);
       }
       else
-      {
        cupsdLogMessage(CUPSD_LOG_ERROR,
                        "Syntax error on line %d of remote.cache.", linenum);
-       return;
-      }
     }
     else if (!strcasecmp(line, "Option") && value)
     {
@@ -363,6 +519,25 @@ cupsdLoadRemoteCache(void)
                                       &(p->options));
       }
     }
+    else if (!strcasecmp(line, "Reason"))
+    {
+      if (value)
+      {
+        for (i = 0 ; i < p->num_reasons; i ++)
+         if (!strcmp(value, p->reasons[i]))
+           break;
+
+        if (i >= p->num_reasons &&
+           p->num_reasons < (int)(sizeof(p->reasons) / sizeof(p->reasons[0])))
+       {
+         p->reasons[p->num_reasons] = _cupsStrAlloc(value);
+         p->num_reasons ++;
+       }
+      }
+      else
+       cupsdLogMessage(CUPSD_LOG_ERROR,
+                       "Syntax error on line %d of remote.cache.", linenum);
+    }
     else if (!strcasecmp(line, "State"))
     {
      /*
@@ -372,13 +547,13 @@ cupsdLoadRemoteCache(void)
       if (value && !strcasecmp(value, "idle"))
         p->state = IPP_PRINTER_IDLE;
       else if (value && !strcasecmp(value, "stopped"))
+      {
         p->state = IPP_PRINTER_STOPPED;
+       cupsdSetPrinterReasons(p, "+paused");
+      }
       else
-      {
        cupsdLogMessage(CUPSD_LOG_ERROR,
                        "Syntax error on line %d of remote.cache.", linenum);
-       return;
-      }
     }
     else if (!strcasecmp(line, "StateMessage"))
     {
@@ -406,22 +581,16 @@ cupsdLoadRemoteCache(void)
                !strcasecmp(value, "false")))
         p->accepting = 0;
       else
-      {
        cupsdLogMessage(CUPSD_LOG_ERROR,
                        "Syntax error on line %d of remote.cache.", linenum);
-       return;
-      }
     }
     else if (!strcasecmp(line, "Type"))
     {
       if (value)
         p->type = atoi(value);
       else
-      {
        cupsdLogMessage(CUPSD_LOG_ERROR,
                        "Syntax error on line %d of remote.cache.", linenum);
-       return;
-      }
     }
     else if (!strcasecmp(line, "BrowseTime"))
     {
@@ -433,11 +602,8 @@ cupsdLoadRemoteCache(void)
           p->browse_expire = t;
       }
       else
-      {
        cupsdLogMessage(CUPSD_LOG_ERROR,
                        "Syntax error on line %d of remote.cache.", linenum);
-       return;
-      }
     }
     else if (!strcasecmp(line, "JobSheets"))
     {
@@ -462,45 +628,36 @@ cupsdLoadRemoteCache(void)
           for (value = valueptr; *valueptr && !isspace(*valueptr & 255); valueptr ++);
 
          if (*valueptr)
-            *valueptr++ = '\0';
+            *valueptr = '\0';
 
          cupsdSetString(&p->job_sheets[1], value);
        }
       }
       else
-      {
        cupsdLogMessage(CUPSD_LOG_ERROR,
                        "Syntax error on line %d of remote.cache.", linenum);
-       return;
-      }
     }
     else if (!strcasecmp(line, "AllowUser"))
     {
       if (value)
       {
         p->deny_users = 0;
-        cupsdAddPrinterUser(p, value);
+        cupsdAddString(&(p->users), value);
       }
       else
-      {
        cupsdLogMessage(CUPSD_LOG_ERROR,
                        "Syntax error on line %d of remote.cache.", linenum);
-       return;
-      }
     }
     else if (!strcasecmp(line, "DenyUser"))
     {
       if (value)
       {
         p->deny_users = 1;
-        cupsdAddPrinterUser(p, value);
+        cupsdAddString(&(p->users), value);
       }
       else
-      {
        cupsdLogMessage(CUPSD_LOG_ERROR,
                        "Syntax error on line %d of remote.cache.", linenum);
-       return;
-      }
     }
     else
     {
@@ -524,6 +681,34 @@ cupsdLoadRemoteCache(void)
 }
 
 
+/*
+ * 'cupsdRegisterPrinter()' - Start sending broadcast information for a
+ *                            printer or update the broadcast contents.
+ */
+
+void
+cupsdRegisterPrinter(cupsd_printer_t *p)/* I - Printer */
+{
+  cupsdLogMessage(CUPSD_LOG_DEBUG, "cupsdRegisterPrinter(p=%p(%s))", p,
+                  p->name);
+
+  if (!Browsing || !BrowseLocalProtocols ||
+      (p->type & (CUPS_PRINTER_REMOTE | CUPS_PRINTER_IMPLICIT |
+                  CUPS_PRINTER_SCANNER)))
+    return;
+
+#ifdef HAVE_LIBSLP
+/*  if (BrowseLocalProtocols & BROWSE_SLP)
+    slpRegisterPrinter(p); */
+#endif /* HAVE_LIBSLP */
+
+#ifdef HAVE_DNSSD
+  if ((BrowseLocalProtocols & BROWSE_DNSSD) && DNSSDRef)
+    dnssdRegisterPrinter(p);
+#endif /* HAVE_DNSSD */
+}
+
+
 /*
  * 'cupsdRestartPolling()' - Restart polling servers as needed.
  */
@@ -550,7 +735,9 @@ cupsdSaveRemoteCache(void)
 {
   int                  i;              /* Looping var */
   cups_file_t          *fp;            /* printers.conf file */
-  char                 temp[1024];     /* Temporary string */
+  char                 temp[1024],     /* Temporary string */
+                       value[2048],    /* Value string */
+                       *name;          /* Current user name */
   cupsd_printer_t      *printer;       /* Current printer class */
   time_t               curtime;        /* Current time */
   struct tm            *curdate;       /* Current date */
@@ -570,7 +757,7 @@ cupsdSaveRemoteCache(void)
     return;
   }
   else
-    cupsdLogMessage(CUPSD_LOG_INFO, "Saving remote.cache...");
+    cupsdLogMessage(CUPSD_LOG_DEBUG, "Saving remote.cache...");
 
  /*
   * Restrict access to the file...
@@ -602,7 +789,7 @@ cupsdSaveRemoteCache(void)
     * Skip local destinations...
     */
 
-    if (!(printer->type & CUPS_PRINTER_REMOTE))
+    if (!(printer->type & CUPS_PRINTER_DISCOVERED))
       continue;
 
    /*
@@ -619,46 +806,52 @@ cupsdSaveRemoteCache(void)
     else
       cupsFilePrintf(fp, "Printer %s>\n", printer->name);
 
-    cupsFilePrintf(fp, "Type %d\n", printer->type);
-
     cupsFilePrintf(fp, "BrowseTime %d\n", (int)printer->browse_expire);
 
-    if (printer->info)
-      cupsFilePrintf(fp, "Info %s\n", printer->info);
+    cupsFilePrintf(fp, "UUID %s\n", printer->uuid);
 
-    if (printer->make_model)
-      cupsFilePrintf(fp, "MakeModel %s\n", printer->make_model);
+    if (printer->info)
+      cupsFilePutConf(fp, "Info", printer->info);
 
     if (printer->location)
-      cupsFilePrintf(fp, "Location %s\n", printer->location);
+      cupsFilePutConf(fp, "Location", printer->location);
 
-    if (printer->device_uri)
-      cupsFilePrintf(fp, "DeviceURI %s\n", printer->device_uri);
+    if (printer->make_model)
+      cupsFilePutConf(fp, "MakeModel", printer->make_model);
+
+    cupsFilePutConf(fp, "DeviceURI", printer->device_uri);
 
     if (printer->state == IPP_PRINTER_STOPPED)
-    {
       cupsFilePuts(fp, "State Stopped\n");
-      cupsFilePrintf(fp, "StateMessage %s\n", printer->state_message);
-    }
     else
       cupsFilePuts(fp, "State Idle\n");
 
+    for (i = 0; i < printer->num_reasons; i ++)
+      cupsFilePutConf(fp, "Reason", printer->reasons[i]);
+
+    cupsFilePrintf(fp, "Type %d\n", printer->type);
+
     if (printer->accepting)
       cupsFilePuts(fp, "Accepting Yes\n");
     else
       cupsFilePuts(fp, "Accepting No\n");
 
-    cupsFilePrintf(fp, "JobSheets %s %s\n", printer->job_sheets[0],
-            printer->job_sheets[1]);
+    snprintf(value, sizeof(value), "%s %s", printer->job_sheets[0],
+             printer->job_sheets[1]);
+    cupsFilePutConf(fp, "JobSheets", value);
 
-    for (i = 0; i < printer->num_users; i ++)
-      cupsFilePrintf(fp, "%sUser %s\n", printer->deny_users ? "Deny" : "Allow",
-              printer->users[i]);
+    for (name = (char *)cupsArrayFirst(printer->users);
+        name;
+        name = (char *)cupsArrayNext(printer->users))
+      cupsFilePutConf(fp, printer->deny_users ? "DenyUser" : "AllowUser", name);
 
     for (i = printer->num_options, option = printer->options;
          i > 0;
         i --, option ++)
-      cupsFilePrintf(fp, "Option %s %s\n", option->name, option->value);
+    {
+      snprintf(value, sizeof(value), "%s %s", option->name, option->value);
+      cupsFilePutConf(fp, "Option", value);
+    }
 
     if (printer->type & CUPS_PRINTER_CLASS)
       cupsFilePuts(fp, "</Class>\n");
@@ -670,41 +863,6 @@ cupsdSaveRemoteCache(void)
 }
 
 
-/*
- * 'cupsdSendBrowseDelete()' - Send a "browse delete" message for a printer.
- */
-
-void
-cupsdSendBrowseDelete(
-    cupsd_printer_t *p)                        /* I - Printer to delete */
-{
- /*
-  * Only announce if browsing is enabled and this is a local queue...
-  */
-
-  if (!Browsing || !p->shared ||
-      (p->type & (CUPS_PRINTER_REMOTE | CUPS_PRINTER_IMPLICIT)))
-    return;
-
- /*
-  * First mark the printer for deletion...
-  */
-
-  p->type |= CUPS_PRINTER_DELETE;
-
- /*
-  * Announce the deletion...
-  */
-
-  if ((BrowseLocalProtocols & BROWSE_CUPS) && BrowseSocket >= 0)
-    send_cups_browse(p);
-#ifdef HAVE_LIBSLP
-  if ((BrowseLocalProtocols & BROWSE_SLP) && BrowseSLPHandle)
-    slp_dereg_printer(p);
-#endif /* HAVE_LIBSLP */
-}
-
-
 /*
  * 'cupsdSendBrowseList()' - Send new browsing information as necessary.
  */
@@ -718,7 +876,7 @@ cupsdSendBrowseList(void)
                        to;             /* Timeout time */
 
 
-  if (!Browsing || !BrowseLocalProtocols || !Printers)
+  if (!Browsing || !Printers)
     return;
 
  /*
@@ -732,7 +890,7 @@ cupsdSendBrowseList(void)
   * Figure out how many printers need an update...
   */
 
-  if (BrowseInterval > 0)
+  if (BrowseInterval > 0 && BrowseLocalProtocols)
   {
     int        max_count;                      /* Maximum number to update */
 
@@ -748,7 +906,8 @@ cupsdSendBrowseList(void)
     for (count = 0, p = (cupsd_printer_t *)cupsArrayFirst(Printers);
          count < max_count && p != NULL;
         p = (cupsd_printer_t *)cupsArrayNext(Printers))
-      if (!(p->type & (CUPS_PRINTER_REMOTE | CUPS_PRINTER_IMPLICIT)) &&
+      if (!(p->type & (CUPS_PRINTER_REMOTE | CUPS_PRINTER_IMPLICIT |
+                       CUPS_PRINTER_SCANNER)) &&
           p->shared && p->browse_time < ut)
         count ++;
 
@@ -774,7 +933,8 @@ cupsdSendBrowseList(void)
 
       if (!p)
         break;
-      else if ((p->type & (CUPS_PRINTER_REMOTE | CUPS_PRINTER_IMPLICIT)) ||
+      else if ((p->type & (CUPS_PRINTER_REMOTE | CUPS_PRINTER_IMPLICIT |
+                           CUPS_PRINTER_SCANNER)) ||
                !p->shared)
         continue;
       else if (p->browse_time < ut)
@@ -787,7 +947,7 @@ cupsdSendBrowseList(void)
 
        p->browse_time = time(NULL);
 
-       if (BrowseLocalProtocols & BROWSE_CUPS)
+       if ((BrowseLocalProtocols & BROWSE_CUPS) && BrowseSocket >= 0)
           send_cups_browse(p);
 
 #ifdef HAVE_LIBSLP
@@ -810,7 +970,7 @@ cupsdSendBrowseList(void)
   }
 
  /*
-  * Loop through all of the printers and send local updates as needed...
+  * Loop through all of the printers and timeout old printers as needed...
   */
 
   for (p = (cupsd_printer_t *)cupsArrayFirst(Printers);
@@ -821,2376 +981,4607 @@ cupsdSendBrowseList(void)
     * If this is a remote queue, see if it needs to be timed out...
     */
 
-    if (p->type & CUPS_PRINTER_REMOTE)
+    if ((p->type & CUPS_PRINTER_DISCOVERED) &&
+        !(p->type & CUPS_PRINTER_IMPLICIT) &&
+       p->browse_expire < to)
     {
-      if (p->browse_expire < to)
-      {
-       cupsdAddEvent(CUPSD_EVENT_PRINTER_DELETED, p, NULL,
-                      "%s \'%s\' deleted by directory services (timeout).",
-                     (p->type & CUPS_PRINTER_CLASS) ? "Class" : "Printer",
-                     p->name);
+      cupsdAddEvent(CUPSD_EVENT_PRINTER_DELETED, p, NULL,
+                   "%s \'%s\' deleted by directory services (timeout).",
+                   (p->type & CUPS_PRINTER_CLASS) ? "Class" : "Printer",
+                   p->name);
 
-        cupsdLogMessage(CUPSD_LOG_DEBUG,
-                       "Remote destination \"%s\" has timed out; "
-                       "deleting it...",
-                       p->name);
+      cupsdLogMessage(CUPSD_LOG_DEBUG,
+                     "Remote destination \"%s\" has timed out; "
+                     "deleting it...",
+                     p->name);
 
-        cupsArraySave(Printers);
-        cupsdDeletePrinter(p, 1);
-        cupsArrayRestore(Printers);
-      }
+      cupsArraySave(Printers);
+      cupsdDeletePrinter(p, 1);
+      cupsArrayRestore(Printers);
+      cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP | CUPSD_DIRTY_REMOTE);
     }
   }
 }
 
 
+#ifdef HAVE_LDAP_REBIND_PROC
+#  if defined(LDAP_API_FEATURE_X_OPENLDAP) && (LDAP_API_VERSION > 2000)
 /*
- * 'cupsdStartBrowsing()' - Start sending and receiving broadcast information.
+ * 'ldap_rebind_proc()' - Callback function for LDAP rebind
  */
 
-void
-cupsdStartBrowsing(void)
+static int                             /* O - Result code */
+ldap_rebind_proc(
+    LDAP            *RebindLDAPHandle, /* I - LDAP handle */
+    LDAP_CONST char *refsp,            /* I - ??? */
+    ber_tag_t       request,           /* I - ??? */
+    ber_int_t       msgid,             /* I - ??? */
+    void            *params)           /* I - ??? */
 {
-  int                  val;            /* Socket option value */
-  struct sockaddr_in   addr;           /* Broadcast address */
+  int          rc;                     /* Result code */
+#    if LDAP_API_VERSION > 3000
+  struct berval        bval;                   /* Bind value */
+#    endif /* LDAP_API_VERSION > 3000 */
 
+ /*
+  * Bind to new LDAP server...
+  */
 
-  BrowseNext = NULL;
+  cupsdLogMessage(CUPSD_LOG_DEBUG2, "ldap_rebind_proc: Rebind to %s", refsp);
 
-  if (!Browsing || !(BrowseLocalProtocols | BrowseRemoteProtocols))
-    return;
+#    if LDAP_API_VERSION > 3000
+  bval.bv_val = BrowseLDAPPassword;
+  bval.bv_len = (BrowseLDAPPassword == NULL) ? 0 : strlen(BrowseLDAPPassword);
 
-  if ((BrowseLocalProtocols | BrowseRemoteProtocols) & BROWSE_CUPS)
-  {
-    if (BrowseSocket < 0)
-    {
-     /*
-      * Create the broadcast socket...
-      */
+  rc = ldap_sasl_bind_s(RebindLDAPHandle, BrowseLDAPBindDN, LDAP_SASL_SIMPLE,
+                        &bval, NULL, NULL, NULL);
+#    else
+  rc = ldap_bind_s(RebindLDAPHandle, BrowseLDAPBindDN, BrowseLDAPPassword,
+                   LDAP_AUTH_SIMPLE);
+#    endif /* LDAP_API_VERSION > 3000 */
 
-      if ((BrowseSocket = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
-      {
-       cupsdLogMessage(CUPSD_LOG_ERROR,
-                       "cupsdStartBrowsing: Unable to create broadcast "
-                       "socket - %s.", strerror(errno));
-       BrowseLocalProtocols &= ~BROWSE_CUPS;
-       BrowseRemoteProtocols &= ~BROWSE_CUPS;
-       return;
-      }
+  return (rc);
+}
 
-     /*
-      * Bind the socket to browse port...
-      */
 
-      memset(&addr, 0, sizeof(addr));
-      addr.sin_addr.s_addr = htonl(INADDR_ANY);
-      addr.sin_family      = AF_INET;
-      addr.sin_port        = htons(BrowsePort);
+#  else /* defined(LDAP_API_FEATURE_X_OPENLDAP) && (LDAP_API_VERSION > 2000) */
+/*
+ * 'ldap_rebind_proc()' - Callback function for LDAP rebind
+ */
 
-      if (bind(BrowseSocket, (struct sockaddr *)&addr, sizeof(addr)))
-      {
-       cupsdLogMessage(CUPSD_LOG_ERROR,
-                       "cupsdStartBrowsing: Unable to bind broadcast "
-                       "socket - %s.", strerror(errno));
+static int                             /* O - Result code */
+ldap_rebind_proc(
+    LDAP *RebindLDAPHandle,            /* I - LDAP handle */
+    char **dnp,                                /* I - ??? */
+    char **passwdp,                    /* I - ??? */
+    int  *authmethodp,                 /* I - ??? */
+    int  freeit,                       /* I - ??? */
+    void *arg)                         /* I - ??? */
+{
+  switch (freeit)
+  {
+    case 1:
+       /*
+        * Free current values...
+        */
 
-#ifdef WIN32
-       closesocket(BrowseSocket);
-#else
-       close(BrowseSocket);
-#endif /* WIN32 */
+        cupsdLogMessage(CUPSD_LOG_DEBUG2, "ldap_rebind_proc: Free values...");
 
-       BrowseSocket = -1;
-       BrowseLocalProtocols &= ~BROWSE_CUPS;
-       BrowseRemoteProtocols &= ~BROWSE_CUPS;
-       return;
-      }
-    }
+        if (dnp && *dnp)
+          free(*dnp);
 
-   /*
-    * Set the "broadcast" flag...
-    */
+        if (passwdp && *passwdp)
+          free(*passwdp);
+        break;
 
-    val = 1;
-    if (setsockopt(BrowseSocket, SOL_SOCKET, SO_BROADCAST, &val, sizeof(val)))
-    {
-      cupsdLogMessage(CUPSD_LOG_ERROR,
-                      "cupsdStartBrowsing: Unable to set broadcast mode - %s.",
-                     strerror(errno));
+    case 0:
+       /*
+        * Return credentials for LDAP referal...
+        */
 
-#ifdef WIN32
-      closesocket(BrowseSocket);
-#else
-      close(BrowseSocket);
-#endif /* WIN32 */
+        cupsdLogMessage(CUPSD_LOG_DEBUG2,
+                        "ldap_rebind_proc: Return necessary values...");
 
-      BrowseSocket = -1;
-      BrowseLocalProtocols &= ~BROWSE_CUPS;
-      BrowseRemoteProtocols &= ~BROWSE_CUPS;
-      return;
-    }
+        *dnp         = strdup(BrowseLDAPBindDN);
+        *passwdp     = strdup(BrowseLDAPPassword);
+        *authmethodp = LDAP_AUTH_SIMPLE;
+        break;
 
-   /*
-    * Close the socket on exec...
-    */
+    default:
+       /*
+        * Should never happen...
+        */
 
-    fcntl(BrowseSocket, F_SETFD, fcntl(BrowseSocket, F_GETFD) | FD_CLOEXEC);
+        cupsdLogMessage(CUPSD_LOG_ERROR,
+                        "LDAP rebind has been called with wrong freeit value!");
+        break;
+  }
 
-   /*
-    * Finally, add the socket to the input selection set as needed...
-    */
+  return (LDAP_SUCCESS);
+}
+#  endif /* defined(LDAP_API_FEATURE_X_OPENLDAP) && (LDAP_API_VERSION > 2000) */
+#endif /* HAVE_LDAP_REBIND_PROC */
 
-    if (BrowseRemoteProtocols & BROWSE_CUPS)
-    {
-     /*
-      * We only listen if we want remote printers...
-      */
 
-      cupsdLogMessage(CUPSD_LOG_DEBUG2,
-                      "cupsdStartBrowsing: Adding fd %d to InputSet...",
-                      BrowseSocket);
+#ifdef HAVE_LDAP
+/*
+ * 'ldap_connect()' - Start new LDAP connection
+ */
 
-      FD_SET(BrowseSocket, InputSet);
-    }
-  }
-  else
-    BrowseSocket = -1;
+static LDAP *                          /* O - LDAP handle */
+ldap_connect(void)
+{
+  int          rc;                     /* LDAP API status */
+  int          version = 3;            /* LDAP version */
+  struct berval        bv = {0, ""};           /* SASL bind value */
+  LDAP         *TempBrowseLDAPHandle=NULL;
+                                       /* Temporary LDAP Handle */
+#  if defined(HAVE_LDAP_SSL) && defined (HAVE_MOZILLA_LDAP)
+  int          ldap_ssl = 0;           /* LDAP SSL indicator */
+  int          ssl_err = 0;            /* LDAP SSL error value */
+#  endif /* defined(HAVE_LDAP_SSL) && defined (HAVE_MOZILLA_LDAP) */
+
+
+#  ifdef HAVE_OPENLDAP
+#    ifdef HAVE_LDAP_SSL
+ /*
+  * Set the certificate file to use for encrypted LDAP sessions...
+  */
 
-#ifdef HAVE_LIBSLP
-  if ((BrowseLocalProtocols | BrowseRemoteProtocols) & BROWSE_SLP)
+  if (BrowseLDAPCACertFile)
   {
-   /* 
-    * Open SLP handle...
-    */
+    cupsdLogMessage(CUPSD_LOG_DEBUG,
+                   "ldap_connect: Setting CA certificate file \"%s\"",
+                    BrowseLDAPCACertFile);
 
-    if (SLPOpen("en", SLP_FALSE, &BrowseSLPHandle) != SLP_OK)
-    {
+    if ((rc = ldap_set_option(NULL, LDAP_OPT_X_TLS_CACERTFILE,
+                             (void *)BrowseLDAPCACertFile)) != LDAP_SUCCESS)
       cupsdLogMessage(CUPSD_LOG_ERROR,
-                      "Unable to open an SLP handle; disabling SLP browsing!");
-      BrowseLocalProtocols &= ~BROWSE_SLP;
-      BrowseRemoteProtocols &= ~BROWSE_SLP;
-    }
-
-    BrowseSLPRefresh = 0;
+                      "Unable to set CA certificate file for LDAP "
+                      "connections: %d - %s", rc, ldap_err2string(rc));
   }
-  else
-    BrowseSLPHandle = NULL;
-#endif /* HAVE_LIBSLP */
+#    endif /* HAVE_LDAP_SSL */
 
-#ifdef HAVE_OPENLDAP
-  if ((BrowseLocalProtocols | BrowseRemoteProtocols) & BROWSE_LDAP)
+ /*
+  * Initialize OPENLDAP connection...
+  * LDAP stuff currently only supports ldapi EXTERNAL SASL binds...
+  */
+
+  if (!BrowseLDAPServer || !strcasecmp(BrowseLDAPServer, "localhost")) 
+    rc = ldap_initialize(&TempBrowseLDAPHandle, "ldapi:///");
+  else 
+    rc = ldap_initialize(&TempBrowseLDAPHandle, BrowseLDAPServer);
+
+#  else /* HAVE_OPENLDAP */
+
+  int          ldap_port = 0;                  /* LDAP port */
+  char         ldap_protocol[11],              /* LDAP protocol */
+               ldap_host[255];                 /* LDAP host */
+
+ /*
+  * Split LDAP URI into its components...
+  */
+
+  if (!BrowseLDAPServer)
   {
-    if (!BrowseLDAPDN)
-    {
-      cupsdLogMessage(CUPSD_LOG_ERROR,
-                      "Need to set BrowseLDAPDN to use LDAP browsing!");
-      BrowseLocalProtocols &= ~BROWSE_LDAP;
-      BrowseRemoteProtocols &= ~BROWSE_LDAP;
-    }
+    cupsdLogMessage(CUPSD_LOG_ERROR, "BrowseLDAPServer not configured!");
+    cupsdLogMessage(CUPSD_LOG_ERROR, "Disabling LDAP browsing!");
+    BrowseLocalProtocols  &= ~BROWSE_LDAP;
+    BrowseRemoteProtocols &= ~BROWSE_LDAP;
+    return (NULL);
+  }
+
+  sscanf(BrowseLDAPServer, "%10[^:]://%254[^:/]:%d", ldap_protocol, ldap_host,
+         &ldap_port);
+
+  if (!strcmp(ldap_protocol, "ldap"))
+    ldap_ssl = 0;
+  else if (!strcmp(ldap_protocol, "ldaps"))
+    ldap_ssl = 1;
+  else
+  {
+    cupsdLogMessage(CUPSD_LOG_ERROR, "Unrecognized LDAP protocol (%s)!",
+                    ldap_protocol);
+    cupsdLogMessage(CUPSD_LOG_ERROR, "Disabling LDAP browsing!");
+    BrowseLocalProtocols &= ~BROWSE_LDAP;
+    BrowseRemoteProtocols &= ~BROWSE_LDAP;
+    return (NULL);
+  }
+
+  if (ldap_port == 0)
+  {
+    if (ldap_ssl)
+      ldap_port = LDAPS_PORT;
     else
-    {
-     /* 
-      * Open LDAP handle...
-      */
+      ldap_port = LDAP_PORT;
+  }
 
-      int              rc;             /* LDAP API status */
-      int              version = 3;    /* LDAP version */
-      struct berval    bv = {0, ""};   /* SASL bind value */
+  cupsdLogMessage(CUPSD_LOG_DEBUG, "ldap_connect: PROT:%s HOST:%s PORT:%d",
+                  ldap_protocol, ldap_host, ldap_port);
 
+ /*
+  * Initialize LDAP connection...
+  */
 
-     /*
-      * LDAP stuff currently only supports ldapi EXTERNAL SASL binds...
-      */
+  if (!ldap_ssl)
+  {
+    if ((TempBrowseLDAPHandle = ldap_init(ldap_host, ldap_port)) == NULL)
+      rc = LDAP_OPERATIONS_ERROR;
+    else
+      rc = LDAP_SUCCESS;
 
-      if (!BrowseLDAPServer || !strcasecmp(BrowseLDAPServer, "localhost")) 
-        rc = ldap_initialize(&BrowseLDAPHandle, "ldapi:///");
-      else     
-       rc = ldap_initialize(&BrowseLDAPHandle, BrowseLDAPServer);
+#    ifdef HAVE_LDAP_SSL
+  }
+  else
+  {
+   /*
+    * Initialize SSL LDAP connection...
+    */
 
+    if (BrowseLDAPCACertFile)
+    {
+      rc = ldapssl_client_init(BrowseLDAPCACertFile, (void *)NULL);
       if (rc != LDAP_SUCCESS)
       {
-       cupsdLogMessage(CUPSD_LOG_ERROR,
-                       "Unable to initialize LDAP; disabling LDAP browsing!");
-       BrowseLocalProtocols &= ~BROWSE_LDAP;
-       BrowseRemoteProtocols &= ~BROWSE_LDAP;
-      }
-      else if (ldap_set_option(BrowseLDAPHandle, LDAP_OPT_PROTOCOL_VERSION,
-                               (const void *)&version) != LDAP_SUCCESS)
-      {
-       ldap_unbind_ext(BrowseLDAPHandle, NULL, NULL);
-       BrowseLDAPHandle = NULL;
-       cupsdLogMessage(CUPSD_LOG_ERROR,
-                       "Unable to set LDAP protocol version; "
-                       "disabling LDAP browsing!");
-       BrowseLocalProtocols &= ~BROWSE_LDAP;
-       BrowseRemoteProtocols &= ~BROWSE_LDAP;
+        cupsdLogMessage(CUPSD_LOG_ERROR,
+                        "Failed to initialize LDAP SSL client!");
+        rc = LDAP_OPERATIONS_ERROR;
       }
       else
       {
-       if (!BrowseLDAPServer || !strcasecmp(BrowseLDAPServer, "localhost"))
-         rc = ldap_sasl_bind_s(BrowseLDAPHandle, NULL, "EXTERNAL", &bv, NULL,
-                               NULL, NULL);
-       else
-         rc = ldap_bind_s(BrowseLDAPHandle, BrowseLDAPBindDN,
-                          BrowseLDAPPassword, LDAP_AUTH_SIMPLE);
-
-       if (rc != LDAP_SUCCESS)
-       {
-         cupsdLogMessage(CUPSD_LOG_ERROR,
-                         "Unable to bind to LDAP server; "
-                         "disabling LDAP browsing!");
-         ldap_unbind_ext(BrowseLDAPHandle, NULL, NULL);
-         BrowseLocalProtocols &= ~BROWSE_LDAP;
-         BrowseRemoteProtocols &= ~BROWSE_LDAP;
-       }
+        if ((TempBrowseLDAPHandle = ldapssl_init(ldap_host, ldap_port,
+                                                 1)) == NULL)
+          rc = LDAP_OPERATIONS_ERROR;
+        else
+          rc = LDAP_SUCCESS;
       }
     }
+    else
+    {
+      cupsdLogMessage(CUPSD_LOG_ERROR,
+                      "LDAP SSL certificate file/database not configured!");
+      rc = LDAP_OPERATIONS_ERROR;
+    }
 
-    BrowseLDAPRefresh = 0;
+#    else /* HAVE_LDAP_SSL */
+
+   /*
+    * Return error, because client libraries doesn't support SSL
+    */
+
+    cupsdLogMessage(CUPSD_LOG_ERROR,
+                    "LDAP client libraries do not support SSL");
+    rc = LDAP_OPERATIONS_ERROR;
+
+#    endif /* HAVE_LDAP_SSL */
   }
-#endif /* HAVE_OPENLDAP */
-}
+#  endif /* HAVE_OPENLDAP */
 
+ /*
+  * Check return code from LDAP initialize...
+  */
 
-/*
- * 'cupsdStartPolling()' - Start polling servers as needed.
- */
+  if (rc != LDAP_SUCCESS)
+  {
+    cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to initialize LDAP!");
 
-void
-cupsdStartPolling(void)
-{
-  int                  i;              /* Looping var */
-  cupsd_dirsvc_poll_t  *pollp;         /* Current polling server */
-  char                 polld[1024];    /* Poll daemon path */
-  char                 sport[255];     /* Server port */
-  char                 bport[255];     /* Browser port */
-  char                 interval[255];  /* Poll interval */
-  int                  statusfds[2];   /* Status pipe */
-  char                 *argv[6];       /* Arguments */
-  char                 *envp[100];     /* Environment */
+    if (rc == LDAP_SERVER_DOWN || rc == LDAP_CONNECT_ERROR)
+      cupsdLogMessage(CUPSD_LOG_ERROR, "Temporarily disabling LDAP browsing...");
+    else
+    {
+      cupsdLogMessage(CUPSD_LOG_ERROR, "Disabling LDAP browsing!");
+
+      BrowseLocalProtocols  &= ~BROWSE_LDAP;
+      BrowseRemoteProtocols &= ~BROWSE_LDAP;
+    }
+
+    ldap_disconnect(TempBrowseLDAPHandle);
 
+    return (NULL);
+  }
 
  /*
-  * Don't do anything if we aren't polling...
+  * Upgrade LDAP version...
   */
 
-  if (NumPolled == 0 || BrowseSocket < 0)
+  if (ldap_set_option(TempBrowseLDAPHandle, LDAP_OPT_PROTOCOL_VERSION,
+                           (const void *)&version) != LDAP_SUCCESS)
   {
-    PollPipe         = -1;
-    PollStatusBuffer = NULL;
-    return;
+    cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to set LDAP protocol version %d!",
+                   version);
+    cupsdLogMessage(CUPSD_LOG_ERROR, "Disabling LDAP browsing!");
+
+    BrowseLocalProtocols  &= ~BROWSE_LDAP;
+    BrowseRemoteProtocols &= ~BROWSE_LDAP;
+    ldap_disconnect(TempBrowseLDAPHandle);
+
+    return (NULL);
   }
 
  /*
-  * Setup string arguments for polld, port and interval options.
+  * Register LDAP rebind procedure...
   */
 
-  snprintf(polld, sizeof(polld), "%s/daemon/cups-polld", ServerBin);
+#  ifdef HAVE_LDAP_REBIND_PROC
+#    if defined(LDAP_API_FEATURE_X_OPENLDAP) && (LDAP_API_VERSION > 2000)
 
-  sprintf(bport, "%d", BrowsePort);
+  rc = ldap_set_rebind_proc(TempBrowseLDAPHandle, &ldap_rebind_proc,
+                            (void *)NULL);
+  if (rc != LDAP_SUCCESS)
+    cupsdLogMessage(CUPSD_LOG_ERROR,
+                    "Setting LDAP rebind function failed with status %d: %s",
+                    rc, ldap_err2string(rc));
 
-  if (BrowseInterval)
-    sprintf(interval, "%d", BrowseInterval);
-  else
-    strcpy(interval, "30");
+#    else
 
-  argv[0] = "cups-polld";
-  argv[2] = sport;
-  argv[3] = interval;
-  argv[4] = bport;
-  argv[5] = NULL;
+  ldap_set_rebind_proc(TempBrowseLDAPHandle, &ldap_rebind_proc, (void *)NULL);
 
-  cupsdLoadEnv(envp, (int)(sizeof(envp) / sizeof(envp[0])));
+#    endif /* defined(LDAP_API_FEATURE_X_OPENLDAP) && (LDAP_API_VERSION > 2000) */
+#  endif /* HAVE_LDAP_REBIND_PROC */
 
  /*
-  * Create a pipe that receives the status messages from each
-  * polling daemon...
+  * Start LDAP bind...
   */
 
-  if (cupsdOpenPipe(statusfds))
-  {
-    cupsdLogMessage(CUPSD_LOG_ERROR,
-                    "Unable to create polling status pipes - %s.",
-                   strerror(errno));
-    PollPipe         = -1;
-    PollStatusBuffer = NULL;
-    return;
-  }
+#  if LDAP_API_VERSION > 3000
+  struct berval bval;
+  bval.bv_val = BrowseLDAPPassword;
+  bval.bv_len = (BrowseLDAPPassword == NULL) ? 0 : strlen(BrowseLDAPPassword);
 
-  PollPipe         = statusfds[0];
-  PollStatusBuffer = cupsdStatBufNew(PollPipe, "[Poll]");
+  if (!BrowseLDAPServer || !strcasecmp(BrowseLDAPServer, "localhost"))
+    rc = ldap_sasl_bind_s(TempBrowseLDAPHandle, NULL, "EXTERNAL", &bv, NULL,
+                          NULL, NULL);
+  else
+    rc = ldap_sasl_bind_s(TempBrowseLDAPHandle, BrowseLDAPBindDN, LDAP_SASL_SIMPLE, &bval, NULL, NULL, NULL);
 
- /*
-  * Run each polling daemon, redirecting stderr to the polling pipe...
-  */
+#  else
+    rc = ldap_bind_s(TempBrowseLDAPHandle, BrowseLDAPBindDN,
+                     BrowseLDAPPassword, LDAP_AUTH_SIMPLE);
+#  endif /* LDAP_API_VERSION > 3000 */
 
-  for (i = 0, pollp = Polled; i < NumPolled; i ++, pollp ++)
+  if (rc != LDAP_SUCCESS)
   {
-    sprintf(sport, "%d", pollp->port);
-
-    argv[1] = pollp->hostname;
+    cupsdLogMessage(CUPSD_LOG_ERROR, "LDAP bind failed with error %d: %s",
+                    rc, ldap_err2string(rc));
 
-    if (cupsdStartProcess(polld, argv, envp, -1, -1, statusfds[1], -1,
-                          0, &(pollp->pid)) < 0)
+#  if defined(HAVE_LDAP_SSL) && defined (HAVE_MOZILLA_LDAP)
+    if (ldap_ssl && (rc == LDAP_SERVER_DOWN || rc == LDAP_CONNECT_ERROR))
     {
-      cupsdLogMessage(CUPSD_LOG_ERROR,
-                      "cupsdStartPolling: Unable to fork polling daemon - %s",
-                      strerror(errno));
-      pollp->pid = 0;
-      break;
+      ssl_err = PORT_GetError();
+      if (ssl_err != 0)
+        cupsdLogMessage(CUPSD_LOG_ERROR, "LDAP SSL error %d: %s", ssl_err,
+                        ldapssl_err2string(ssl_err));
     }
-    else
-      cupsdLogMessage(CUPSD_LOG_DEBUG,
-                      "cupsdStartPolling: Started polling daemon for %s:%d, pid = %d",
-                      pollp->hostname, pollp->port, pollp->pid);
-  }
+#  endif /* defined(HAVE_LDAP_SSL) && defined (HAVE_MOZILLA_LDAP) */
 
-  close(statusfds[1]);
+    ldap_disconnect(TempBrowseLDAPHandle);
 
- /*
-  * Finally, add the pipe to the input selection set...
-  */
+    return (NULL);
+  }
 
-  cupsdLogMessage(CUPSD_LOG_DEBUG2,
-                  "cupsdStartPolling: Adding fd %d to InputSet...", PollPipe);
+  cupsdLogMessage(CUPSD_LOG_INFO, "LDAP connection established");
 
-  FD_SET(PollPipe, InputSet);
+  return (TempBrowseLDAPHandle);
 }
 
 
 /*
- * 'cupsdStopBrowsing()' - Stop sending and receiving broadcast information.
+ * 'ldap_reconnect()' - Reconnect to LDAP Server
  */
 
-void
-cupsdStopBrowsing(void)
+static LDAP *                          /* O - New LDAP handle */
+ldap_reconnect(void)
 {
-  if (!Browsing || !(BrowseLocalProtocols | BrowseRemoteProtocols))
-    return;
+  LDAP *TempBrowseLDAPHandle = NULL;   /* Temp Handle to LDAP server */
 
-  if (((BrowseLocalProtocols | BrowseRemoteProtocols) & BROWSE_CUPS) &&
-      BrowseSocket >= 0)
-  {
-   /*
-    * Close the socket and remove it from the input selection set.
-    */
 
-#ifdef WIN32
-    closesocket(BrowseSocket);
-#else
-    close(BrowseSocket);
-#endif /* WIN32 */
+ /*
+  * Get a new LDAP Handle and replace the global Handle
+  * if the new connection was successful.
+  */
 
-    cupsdLogMessage(CUPSD_LOG_DEBUG2,
-                   "cupsdStopBrowsing: Removing fd %d from InputSet...",
-                   BrowseSocket);
+  cupsdLogMessage(CUPSD_LOG_INFO, "Try LDAP reconnect...");
 
-    FD_CLR(BrowseSocket, InputSet);
-    BrowseSocket = -1;
-  }
+  TempBrowseLDAPHandle = ldap_connect();
 
-#ifdef HAVE_LIBSLP
-  if (((BrowseLocalProtocols | BrowseRemoteProtocols) & BROWSE_SLP) &&
-      BrowseSLPHandle)
+  if (TempBrowseLDAPHandle != NULL)
   {
-   /* 
-    * Close SLP handle...
-    */
+    if (BrowseLDAPHandle != NULL)
+      ldap_disconnect(BrowseLDAPHandle);
 
-    SLPClose(BrowseSLPHandle);
-    BrowseSLPHandle = NULL;
+    BrowseLDAPHandle = TempBrowseLDAPHandle;
   }
-#endif /* HAVE_LIBSLP */
 
-#ifdef HAVE_OPENLDAP
-  if (((BrowseLocalProtocols | BrowseRemoteProtocols) & BROWSE_LDAP) &&
-      BrowseLDAPHandle)
-  {
-    ldap_unbind(BrowseLDAPHandle);
-    BrowseLDAPHandle = NULL;
-  }
-#endif /* HAVE_OPENLDAP */
+  return (BrowseLDAPHandle);
 }
 
 
 /*
- * 'cupsdStopPolling()' - Stop polling servers as needed.
+ * 'ldap_disconnect()' - Disconnect from LDAP Server
  */
 
-void
-cupsdStopPolling(void)
+static void
+ldap_disconnect(LDAP *ld)              /* I - LDAP handle */
 {
-  int                  i;              /* Looping var */
-  cupsd_dirsvc_poll_t  *pollp;         /* Current polling server */
-
+  int  rc;                             /* Return code */
 
-  if (PollPipe >= 0)
-  {
-    cupsdStatBufDelete(PollStatusBuffer);
-    close(PollPipe);
 
-    cupsdLogMessage(CUPSD_LOG_DEBUG2,
-                    "cupsdStopPolling: removing fd %d from InputSet.", PollPipe);
-    FD_CLR(PollPipe, InputSet);
+ /*
+  * Close LDAP handle...
+  */
 
-    PollPipe         = -1;
-    PollStatusBuffer = NULL;
-  }
+#  if defined(HAVE_OPENLDAP) && LDAP_API_VERSION > 3000
+  rc = ldap_unbind_ext_s(ld, NULL, NULL);
+#  else
+  rc = ldap_unbind_s(ld);
+#  endif /* defined(HAVE_OPENLDAP) && LDAP_API_VERSION > 3000 */
 
-  for (i = 0, pollp = Polled; i < NumPolled; i ++, pollp ++)
-    if (pollp->pid)
-      cupsdEndProcess(pollp->pid, 0);
+  if (rc != LDAP_SUCCESS)
+    cupsdLogMessage(CUPSD_LOG_ERROR,
+                    "Unbind from LDAP server failed with status %d: %s",
+                    rc, ldap_err2string(rc));
 }
+#endif /* HAVE_LDAP */
 
 
 /*
- * 'cupsdUpdateCUPSBrowse()' - Update the browse lists using the CUPS protocol.
+ * 'cupsdStartBrowsing()' - Start sending and receiving broadcast information.
  */
 
 void
-cupsdUpdateCUPSBrowse(void)
+cupsdStartBrowsing(void)
 {
-  int          i;                      /* Looping var */
-  int          auth;                   /* Authorization status */
-  int          len;                    /* Length of name string */
-  int          bytes;                  /* Number of bytes left */
-  char         packet[1541],           /* Broadcast packet */
-               *pptr;                  /* Pointer into packet */
-  socklen_t    srclen;                 /* Length of source address */
-  http_addr_t  srcaddr;                /* Source address */
-  char         srcname[1024];          /* Source hostname */
-  unsigned     address[4];             /* Source address */
-  unsigned     type;                   /* Printer type */
-  unsigned     state;                  /* Printer state */
-  char         uri[HTTP_MAX_URI],      /* Printer URI */
-               host[HTTP_MAX_URI],     /* Host portion of URI */
-               resource[HTTP_MAX_URI], /* Resource portion of URI */
-               info[IPP_MAX_NAME],     /* Information string */
-               location[IPP_MAX_NAME], /* Location string */
-               make_model[IPP_MAX_NAME];/* Make and model string */
-  int          num_attrs;              /* Number of attributes */
-  cups_option_t        *attrs;                 /* Attributes */
+  int                  val;            /* Socket option value */
+  struct sockaddr_in   addr;           /* Broadcast address */
+  cupsd_printer_t      *p;             /* Current printer */
 
 
- /*
-  * Read a packet from the browse socket...
-  */
+  BrowseNext = NULL;
 
-  srclen = sizeof(srcaddr);
-  if ((bytes = recvfrom(BrowseSocket, packet, sizeof(packet) - 1, 0, 
-                        (struct sockaddr *)&srcaddr, &srclen)) < 0)
-  {
-   /*
-    * "Connection refused" is returned under Linux if the destination port
-    * or address is unreachable from a previous sendto(); check for the
-    * error here and ignore it for now...
-    */
+  if (!Browsing || !(BrowseLocalProtocols | BrowseRemoteProtocols))
+    return;
 
-    if (errno != ECONNREFUSED && errno != EAGAIN)
+  if ((BrowseLocalProtocols | BrowseRemoteProtocols) & BROWSE_CUPS)
+  {
+    if (BrowseSocket < 0)
     {
-      cupsdLogMessage(CUPSD_LOG_ERROR, "Browse recv failed - %s.",
-                      strerror(errno));
-      cupsdLogMessage(CUPSD_LOG_ERROR, "Browsing turned off.");
-
-      cupsdStopBrowsing();
-      Browsing = 0;
-    }
+     /*
+      * Create the broadcast socket...
+      */
 
-    return;
-  }
-
-  packet[bytes] = '\0';
+      if ((BrowseSocket = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
+      {
+       cupsdLogMessage(CUPSD_LOG_ERROR,
+                       "Unable to create broadcast socket - %s.",
+                       strerror(errno));
+       BrowseLocalProtocols &= ~BROWSE_CUPS;
+       BrowseRemoteProtocols &= ~BROWSE_CUPS;
 
- /*
-  * If we're about to sleep, ignore incoming browse packets.
-  */
+       if (FatalErrors & CUPSD_FATAL_BROWSE)
+         cupsdEndProcess(getpid(), 0);
+      }
+    }
 
-  if (Sleeping)
-    return;
+    if (BrowseSocket >= 0)
+    {
+     /*
+      * Bind the socket to browse port...
+      */
 
- /*
-  * Figure out where it came from...
-  */
+      memset(&addr, 0, sizeof(addr));
+      addr.sin_addr.s_addr = htonl(INADDR_ANY);
+      addr.sin_family      = AF_INET;
+      addr.sin_port        = htons(BrowsePort);
 
-#ifdef AF_INET6
-  if (srcaddr.addr.sa_family == AF_INET6)
-  {
-    address[0] = ntohl(srcaddr.ipv6.sin6_addr.s6_addr32[0]);
-    address[1] = ntohl(srcaddr.ipv6.sin6_addr.s6_addr32[1]);
-    address[2] = ntohl(srcaddr.ipv6.sin6_addr.s6_addr32[2]);
-    address[3] = ntohl(srcaddr.ipv6.sin6_addr.s6_addr32[3]);
-  }
-  else
-#endif /* AF_INET6 */
-  {
-    address[0] = 0;
-    address[1] = 0;
-    address[2] = 0;
-    address[3] = ntohl(srcaddr.ipv4.sin_addr.s_addr);
-  }
+      if (bind(BrowseSocket, (struct sockaddr *)&addr, sizeof(addr)))
+      {
+       cupsdLogMessage(CUPSD_LOG_ERROR,
+                       "Unable to bind broadcast socket - %s.",
+                       strerror(errno));
 
-  if (HostNameLookups)
-    httpAddrLookup(&srcaddr, srcname, sizeof(srcname));
-  else
-    httpAddrString(&srcaddr, srcname, sizeof(srcname));
+#ifdef WIN32
+       closesocket(BrowseSocket);
+#else
+       close(BrowseSocket);
+#endif /* WIN32 */
 
-  len = strlen(srcname);
+       BrowseSocket = -1;
+       BrowseLocalProtocols &= ~BROWSE_CUPS;
+       BrowseRemoteProtocols &= ~BROWSE_CUPS;
 
- /*
-  * Do ACL stuff...
-  */
+       if (FatalErrors & CUPSD_FATAL_BROWSE)
+         cupsdEndProcess(getpid(), 0);
+      }
+    }
 
-  if (BrowseACL)
-  {
-    if (httpAddrLocalhost(&srcaddr) || !strcasecmp(srcname, "localhost"))
+    if (BrowseSocket >= 0)
     {
      /*
-      * Access from localhost (127.0.0.1) is always allowed...
+      * Set the "broadcast" flag...
       */
 
-      auth = AUTH_ALLOW;
+      val = 1;
+      if (setsockopt(BrowseSocket, SOL_SOCKET, SO_BROADCAST, &val, sizeof(val)))
+      {
+       cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to set broadcast mode - %s.",
+                       strerror(errno));
+
+#ifdef WIN32
+       closesocket(BrowseSocket);
+#else
+       close(BrowseSocket);
+#endif /* WIN32 */
+
+       BrowseSocket = -1;
+       BrowseLocalProtocols &= ~BROWSE_CUPS;
+       BrowseRemoteProtocols &= ~BROWSE_CUPS;
+
+       if (FatalErrors & CUPSD_FATAL_BROWSE)
+         cupsdEndProcess(getpid(), 0);
+      }
     }
-    else
+
+    if (BrowseSocket >= 0)
     {
      /*
-      * Do authorization checks on the domain/address...
+      * Close the socket on exec...
       */
 
-      switch (BrowseACL->order_type)
-      {
-        default :
-           auth = AUTH_DENY;   /* anti-compiler-warning-code */
-           break;
-
-       case AUTH_ALLOW : /* Order Deny,Allow */
-            auth = AUTH_ALLOW;
-
-            if (cupsdCheckAuth(address, srcname, len,
-                         BrowseACL->num_deny, BrowseACL->deny))
-             auth = AUTH_DENY;
-
-            if (cupsdCheckAuth(address, srcname, len,
-                         BrowseACL->num_allow, BrowseACL->allow))
-             auth = AUTH_ALLOW;
-           break;
+      fcntl(BrowseSocket, F_SETFD, fcntl(BrowseSocket, F_GETFD) | FD_CLOEXEC);
 
-       case AUTH_DENY : /* Order Allow,Deny */
-            auth = AUTH_DENY;
+     /*
+      * Finally, add the socket to the input selection set as needed...
+      */
 
-            if (cupsdCheckAuth(address, srcname, len,
-                         BrowseACL->num_allow, BrowseACL->allow))
-             auth = AUTH_ALLOW;
+      if (BrowseRemoteProtocols & BROWSE_CUPS)
+      {
+       /*
+       * We only listen if we want remote printers...
+       */
 
-            if (cupsdCheckAuth(address, srcname, len,
-                         BrowseACL->num_deny, BrowseACL->deny))
-             auth = AUTH_DENY;
-           break;
+       cupsdAddSelect(BrowseSocket, (cupsd_selfunc_t)update_cups_browse,
+                      NULL, NULL);
       }
     }
   }
   else
-    auth = AUTH_ALLOW;
-
-  if (auth == AUTH_DENY)
-  {
-    cupsdLogMessage(CUPSD_LOG_DEBUG,
-                    "cupsdUpdateCUPSBrowse: Refused %d bytes from %s", bytes,
-                    srcname);
-    return;
-  }
-
-  cupsdLogMessage(CUPSD_LOG_DEBUG2,
-                  "cupsdUpdateCUPSBrowse: (%d bytes from %s) %s", bytes,
-                 srcname, packet);
-
- /*
-  * Parse packet...
-  */
+    BrowseSocket = -1;
 
-  if (sscanf(packet, "%x%x%1023s", &type, &state, uri) < 3)
+#ifdef HAVE_DNSSD
+  if ((BrowseLocalProtocols | BrowseRemoteProtocols) & BROWSE_DNSSD)
   {
-    cupsdLogMessage(CUPSD_LOG_WARN,
-                    "cupsdUpdateCUPSBrowse: Garbled browse packet - %s", packet);
-    return;
-  }
+    DNSServiceErrorType error;         /* Error from service creation */
+    cupsd_listener_t   *lis;           /* Current listening socket */
 
-  strcpy(location, "Location Unknown");
-  strcpy(info, "No Information Available");
-  make_model[0] = '\0';
-  num_attrs     = 0;
-  attrs         = NULL;
 
-  if ((pptr = strchr(packet, '\"')) != NULL)
-  {
    /*
-    * Have extended information; can't use sscanf for it because not all
-    * sscanf's allow empty strings with %[^\"]...
+    * First create a "master" connection for all registrations...
     */
 
-    for (i = 0, pptr ++;
-         i < (sizeof(location) - 1) && *pptr && *pptr != '\"';
-         i ++, pptr ++)
-      location[i] = *pptr;
-
-    if (i)
-      location[i] = '\0';
+    if ((error = DNSServiceCreateConnection(&DNSSDRef))
+           != kDNSServiceErr_NoError)
+    {
+      cupsdLogMessage(CUPSD_LOG_ERROR,
+                     "Unable to create master DNS-SD reference: %d", error);
 
-    if (*pptr == '\"')
-      pptr ++;
+      if (FatalErrors & CUPSD_FATAL_BROWSE)
+       cupsdEndProcess(getpid(), 0);
+    }
+    else
+    {
+     /*
+      * Add the master connection to the select list...
+      */
 
-    while (*pptr && isspace(*pptr & 255))
-      pptr ++;
+      int fd = DNSServiceRefSockFD(DNSSDRef);
 
-    if (*pptr == '\"')
-    {
-      for (i = 0, pptr ++;
-           i < (sizeof(info) - 1) && *pptr && *pptr != '\"';
-           i ++, pptr ++)
-       info[i] = *pptr;
+      fcntl(fd, F_SETFD, fcntl(fd, F_GETFD) | FD_CLOEXEC);
 
-      info[i] = '\0';
+      cupsdAddSelect(fd, (cupsd_selfunc_t)dnssdUpdate, NULL, NULL);
 
-      if (*pptr == '\"')
-       pptr ++;
+     /*
+      * Then get the port we use for registrations.  If we are not listening
+      * on any non-local ports, there is no sense sharing local printers via
+      * Bonjour...
+      */
 
-      while (*pptr && isspace(*pptr & 255))
-       pptr ++;
+      DNSSDPort = 0;
 
-      if (*pptr == '\"')
+      for (lis = (cupsd_listener_t *)cupsArrayFirst(Listeners);
+          lis;
+          lis = (cupsd_listener_t *)cupsArrayNext(Listeners))
       {
-       for (i = 0, pptr ++;
-             i < (sizeof(make_model) - 1) && *pptr && *pptr != '\"';
-             i ++, pptr ++)
-         make_model[i] = *pptr;
+       if (httpAddrLocalhost(&(lis->address)))
+         continue;
 
-       if (*pptr == '\"')
-         pptr ++;
+       if (lis->address.addr.sa_family == AF_INET)
+       {
+         DNSSDPort = ntohs(lis->address.ipv4.sin_port);
+         break;
+       }
+       else if (lis->address.addr.sa_family == AF_INET6)
+       {
+         DNSSDPort = ntohs(lis->address.ipv6.sin6_port);
+         break;
+       }
+      }
 
-       make_model[i] = '\0';
+     /*
+      * Create an array to track the printers we share...
+      */
 
-        if (*pptr)
-         num_attrs = cupsParseOptions(pptr, num_attrs, &attrs);
-      }
+      if (BrowseRemoteProtocols & BROWSE_DNSSD)
+        DNSSDPrinters = cupsArrayNew((cups_array_func_t)dnssdComparePrinters,
+                                    NULL);
+
+     /*
+      * Set the computer name and register the web interface...
+      */
+
+      cupsdUpdateDNSSDName();
     }
   }
+#endif /* HAVE_DNSSD */
 
-  DEBUG_puts(packet);
-  DEBUG_printf(("type=%x, state=%x, uri=\"%s\"\n"
-                "location=\"%s\", info=\"%s\", make_model=\"%s\"\n",
-               type, state, uri, location, info, make_model));
+#ifdef HAVE_LIBSLP
+  if ((BrowseLocalProtocols | BrowseRemoteProtocols) & BROWSE_SLP)
+  {
+   /* 
+    * Open SLP handle...
+    */
 
- /*
-  * Pull the URI apart to see if this is a local or remote printer...
-  */
+    if (SLPOpen("en", SLP_FALSE, &BrowseSLPHandle) != SLP_OK)
+    {
+      cupsdLogMessage(CUPSD_LOG_ERROR,
+                      "Unable to open an SLP handle; disabling SLP browsing!");
+      BrowseLocalProtocols &= ~BROWSE_SLP;
+      BrowseRemoteProtocols &= ~BROWSE_SLP;
+      BrowseSLPHandle = NULL;
 
-  if (is_local_queue(uri, host, sizeof(host), resource, sizeof(resource)))
+      if (FatalErrors & CUPSD_FATAL_BROWSE)
+       cupsdEndProcess(getpid(), 0);
+    }
+
+    BrowseSLPRefresh = 0;
+  }
+  else
+    BrowseSLPHandle = NULL;
+#endif /* HAVE_LIBSLP */
+
+#ifdef HAVE_LDAP
+  if ((BrowseLocalProtocols | BrowseRemoteProtocols) & BROWSE_LDAP)
   {
-    cupsFreeOptions(num_attrs, attrs);
-    return;
+    if (!BrowseLDAPDN)
+    {
+      cupsdLogMessage(CUPSD_LOG_ERROR,
+                      "Need to set BrowseLDAPDN to use LDAP browsing!");
+      BrowseLocalProtocols &= ~BROWSE_LDAP;
+      BrowseRemoteProtocols &= ~BROWSE_LDAP;
+
+      if (FatalErrors & CUPSD_FATAL_BROWSE)
+       cupsdEndProcess(getpid(), 0);
+    }
+    else
+    {
+     /*
+      * Open LDAP handle...
+      */
+
+      if ((BrowseLDAPHandle = ldap_connect()) == NULL &&
+          (FatalErrors & CUPSD_FATAL_BROWSE))
+       cupsdEndProcess(getpid(), 0);
+    }
+
+    BrowseLDAPRefresh = 0;
   }
+#endif /* HAVE_LDAP */
 
  /*
-  * Do relaying...
+  * Enable LPD and SMB printer sharing as needed through external programs...
   */
 
-  for (i = 0; i < NumRelays; i ++)
-    if (cupsdCheckAuth(address, srcname, len, 1, &(Relays[i].from)))
-      if (sendto(BrowseSocket, packet, bytes, 0,
-                 (struct sockaddr *)&(Relays[i].to),
-                httpAddrLength(&(Relays[i].to))) <= 0)
-      {
-       cupsdLogMessage(CUPSD_LOG_ERROR,
-                       "cupsdUpdateCUPSBrowse: sendto failed for relay %d - %s.",
-                       i + 1, strerror(errno));
-       cupsFreeOptions(num_attrs, attrs);
-       return;
-      }
+  if (BrowseLocalProtocols & BROWSE_LPD)
+    update_lpd(1);
+
+  if (BrowseLocalProtocols & BROWSE_SMB)
+    update_smb(1);
 
  /*
-  * Process the browse data...
+  * Register the individual printers
   */
 
-  process_browse_data(uri, host, resource, (cups_ptype_t)type,
-                      (ipp_pstate_t)state, location, info, make_model,
-                     num_attrs, attrs);
+  for (p = (cupsd_printer_t *)cupsArrayFirst(Printers);
+       p;
+       p = (cupsd_printer_t *)cupsArrayNext(Printers))
+    if (!(p->type & (CUPS_PRINTER_REMOTE | CUPS_PRINTER_IMPLICIT |
+                     CUPS_PRINTER_SCANNER)))
+      cupsdRegisterPrinter(p);
 }
 
 
-#ifdef HAVE_OPENLDAP
 /*
- * 'cupsdUpdateLDAPBrowse()' - Scan for new printers via LDAP...
+ * 'cupsdStartPolling()' - Start polling servers as needed.
  */
 
 void
-cupsdUpdateLDAPBrowse(void)
+cupsdStartPolling(void)
 {
-  char         uri[HTTP_MAX_URI],      /* Printer URI */
-               host[HTTP_MAX_URI],     /* Hostname */
-               resource[HTTP_MAX_URI], /* Resource path */
-               location[1024],         /* Printer location */
-               info[1024],             /* Printer information */
-               make_model[1024],       /* Printer make and model */
-               **value;                /* Holds the returned data from LDAP */
-  int          type;                   /* Printer type */
-  int          rc;                     /* LDAP status */
-  int          limit;                  /* Size limit */
-  LDAPMessage  *res,                   /* LDAP search results */
-                 *e;                   /* Current entry from search */
+  int                  i;              /* Looping var */
+  cupsd_dirsvc_poll_t  *pollp;         /* Current polling server */
+  char                 polld[1024];    /* Poll daemon path */
+  char                 sport[255];     /* Server port */
+  char                 bport[255];     /* Browser port */
+  char                 interval[255];  /* Poll interval */
+  int                  statusfds[2];   /* Status pipe */
+  char                 *argv[6];       /* Arguments */
+  char                 *envp[100];     /* Environment */
 
 
  /*
-  * Search for printers...
+  * Don't do anything if we aren't polling...
   */
 
-  cupsdLogMessage(CUPSD_LOG_DEBUG2, "UpdateLDAPBrowse: %s", ServerName);
+  if (NumPolled == 0 || BrowseSocket < 0)
+  {
+    PollPipe         = -1;
+    PollStatusBuffer = NULL;
+    return;
+  }
 
-  BrowseLDAPRefresh = time(NULL) + BrowseInterval;
+ /*
+  * Setup string arguments for polld, port and interval options.
+  */
 
-  rc = ldap_search_s(BrowseLDAPHandle, BrowseLDAPDN, LDAP_SCOPE_SUBTREE,
-                     "(objectclass=cupsPrinter)", (char **)ldap_attrs, 0, &res);
-  if (rc != LDAP_SUCCESS) 
+  snprintf(polld, sizeof(polld), "%s/daemon/cups-polld", ServerBin);
+
+  sprintf(bport, "%d", BrowsePort);
+
+  if (BrowseInterval)
+    sprintf(interval, "%d", BrowseInterval);
+  else
+    strcpy(interval, "30");
+
+  argv[0] = "cups-polld";
+  argv[2] = sport;
+  argv[3] = interval;
+  argv[4] = bport;
+  argv[5] = NULL;
+
+  cupsdLoadEnv(envp, (int)(sizeof(envp) / sizeof(envp[0])));
+
+ /*
+  * Create a pipe that receives the status messages from each
+  * polling daemon...
+  */
+
+  if (cupsdOpenPipe(statusfds))
   {
     cupsdLogMessage(CUPSD_LOG_ERROR,
-                    "LDAP search returned error %d: %s", rc,
-                   ldap_err2string(rc));
+                    "Unable to create polling status pipes - %s.",
+                   strerror(errno));
+    PollPipe         = -1;
+    PollStatusBuffer = NULL;
     return;
   }
 
-  limit = ldap_count_entries(BrowseLDAPHandle, res);
-  cupsdLogMessage(CUPSD_LOG_DEBUG2, "LDAP search returned %d entries", limit);
-  if (limit < 1)
-    return;
+  PollPipe         = statusfds[0];
+  PollStatusBuffer = cupsdStatBufNew(PollPipe, "[Poll]");
 
  /*
-  * Loop through the available printers...
+  * Run each polling daemon, redirecting stderr to the polling pipe...
   */
 
-  for (e = ldap_first_entry(BrowseLDAPHandle, res);
-       e;
-       e = ldap_next_entry(BrowseLDAPHandle, e))
+  for (i = 0, pollp = Polled; i < NumPolled; i ++, pollp ++)
   {
-   /*
-    * Get the required values from this entry...
-    */
+    sprintf(sport, "%d", pollp->port);
 
-    if ((value = ldap_get_values(BrowseLDAPHandle, e,
-                                 "printerDescription")) == NULL)
-      continue;
+    argv[1] = pollp->hostname;
 
-    strlcpy(info, *value, sizeof(info));
-    ldap_value_free(value);
+    if (cupsdStartProcess(polld, argv, envp, -1, -1, statusfds[1], -1, -1,
+                          0, DefaultProfile, NULL, &(pollp->pid)) < 0)
+    {
+      cupsdLogMessage(CUPSD_LOG_ERROR,
+                      "cupsdStartPolling: Unable to fork polling daemon - %s",
+                      strerror(errno));
+      pollp->pid = 0;
+      break;
+    }
+    else
+      cupsdLogMessage(CUPSD_LOG_DEBUG,
+                      "cupsdStartPolling: Started polling daemon for %s:%d, pid = %d",
+                      pollp->hostname, pollp->port, pollp->pid);
+  }
 
-    if ((value = ldap_get_values(BrowseLDAPHandle, e,
-                                 "printerLocation")) == NULL)
-      continue;
+  close(statusfds[1]);
 
-    strlcpy(location, *value, sizeof(location));
-    ldap_value_free(value);
+ /*
+  * Finally, add the pipe to the input selection set...
+  */
 
-    if ((value = ldap_get_values(BrowseLDAPHandle, e,
-                                 "printerMakeAndModel")) == NULL)
-      continue;
+  cupsdAddSelect(PollPipe, (cupsd_selfunc_t)update_polling, NULL, NULL);
+}
 
-    strlcpy(make_model, *value, sizeof(make_model));
-    ldap_value_free(value);
 
-    if ((value = ldap_get_values(BrowseLDAPHandle, e,
-                                 "printerType")) == NULL)
-      continue;
+/*
+ * 'cupsdStopBrowsing()' - Stop sending and receiving broadcast information.
+ */
 
-    type = atoi(*value);
-    ldap_value_free(value);
+void
+cupsdStopBrowsing(void)
+{
+  cupsd_printer_t      *p;             /* Current printer */
 
-    if ((value = ldap_get_values(BrowseLDAPHandle, e,
-                                 "printerURI")) == NULL)
-      continue;
 
-    strlcpy(uri, *value, sizeof(uri));
-    ldap_value_free(value);
+  if (!Browsing || !(BrowseLocalProtocols | BrowseRemoteProtocols))
+    return;
+
+ /*
+  * De-register the individual printers
+  */
+
+  for (p = (cupsd_printer_t *)cupsArrayFirst(Printers);
+       p;
+       p = (cupsd_printer_t *)cupsArrayNext(Printers))
+    if (!(p->type & (CUPS_PRINTER_REMOTE | CUPS_PRINTER_IMPLICIT |
+                     CUPS_PRINTER_SCANNER)))
+      cupsdDeregisterPrinter(p, 1);
+
+ /*
+  * Shut down browsing sockets...
+  */
 
+  if (((BrowseLocalProtocols | BrowseRemoteProtocols) & BROWSE_CUPS) &&
+      BrowseSocket >= 0)
+  {
    /*
-    * Process the entry as browse data...
+    * Close the socket and remove it from the input selection set.
     */
 
-    if (!is_local_queue(uri, host, sizeof(host), resource, sizeof(resource)))
-      process_browse_data(uri, host, resource, type, IPP_PRINTER_IDLE,
-                          location, info, make_model, 0, NULL);
+#ifdef WIN32
+    closesocket(BrowseSocket);
+#else
+    close(BrowseSocket);
+#endif /* WIN32 */
 
+    cupsdRemoveSelect(BrowseSocket);
+    BrowseSocket = -1;
+  }
+
+#ifdef HAVE_DNSSD
+  if ((BrowseLocalProtocols & BROWSE_DNSSD) && DNSSDRef)
+    dnssdStop();
+#endif /* HAVE_DNSSD */
+
+#ifdef HAVE_LIBSLP
+  if (((BrowseLocalProtocols | BrowseRemoteProtocols) & BROWSE_SLP) &&
+      BrowseSLPHandle)
+  {
+   /* 
+    * Close SLP handle...
+    */
+
+    SLPClose(BrowseSLPHandle);
+    BrowseSLPHandle = NULL;
+  }
+#endif /* HAVE_LIBSLP */
+
+#ifdef HAVE_LDAP
+  if (((BrowseLocalProtocols | BrowseRemoteProtocols) & BROWSE_LDAP) &&
+      BrowseLDAPHandle)
+  {
+    ldap_dereg_ou(ServerName, BrowseLDAPDN);
+    ldap_disconnect(BrowseLDAPHandle);
+    BrowseLDAPHandle = NULL;
   }
-}
 #endif /* HAVE_OPENLDAP */
 
+ /*
+  * Disable LPD and SMB printer sharing as needed through external programs...
+  */
+
+  if (BrowseLocalProtocols & BROWSE_LPD)
+    update_lpd(0);
+
+  if (BrowseLocalProtocols & BROWSE_SMB)
+    update_smb(0);
+}
+
 
 /*
- * 'cupsdUpdatePolling()' - Read status messages from the poll daemons.
+ * 'cupsdStopPolling()' - Stop polling servers as needed.
  */
 
 void
-cupsdUpdatePolling(void)
+cupsdStopPolling(void)
 {
-  char         *ptr,                   /* Pointer to end of line in buffer */
-               message[1024];          /* Pointer to message text */
-  int          loglevel;               /* Log level for message */
-
+  int                  i;              /* Looping var */
+  cupsd_dirsvc_poll_t  *pollp;         /* Current polling server */
 
-  while ((ptr = cupsdStatBufUpdate(PollStatusBuffer, &loglevel,
-                                   message, sizeof(message))) != NULL)
-    if (!strchr(PollStatusBuffer->buffer, '\n'))
-      break;
 
-  if (ptr == NULL && !PollStatusBuffer->bufused)
+  if (PollPipe >= 0)
   {
-   /*
-    * All polling processes have died; stop polling...
-    */
+    cupsdStatBufDelete(PollStatusBuffer);
+    close(PollPipe);
 
-    cupsdLogMessage(CUPSD_LOG_ERROR,
-                    "cupsdUpdatePolling: all polling processes have exited!");
-    cupsdStopPolling();
+    cupsdRemoveSelect(PollPipe);
+
+    PollPipe         = -1;
+    PollStatusBuffer = NULL;
   }
+
+  for (i = 0, pollp = Polled; i < NumPolled; i ++, pollp ++)
+    if (pollp->pid)
+      cupsdEndProcess(pollp->pid, 0);
 }
 
 
-#ifdef HAVE_LIBSLP 
+#ifdef HAVE_DNSSD
 /*
- * 'cupsdUpdateSLPBrowse()' - Get browsing information via SLP.
+ * 'cupsdUpdateDNSSDName()' - Update the computer name we use for browsing...
  */
 
 void
-cupsdUpdateSLPBrowse(void)
+cupsdUpdateDNSSDName(void)
 {
-  slpsrvurl_t  *s,                     /* Temporary list of service URLs */
-               *next;                  /* Next service in list */
-  cupsd_printer_t p;                   /* Printer information */
-  const char   *uri;                   /* Pointer to printer URI */
-  char         host[HTTP_MAX_URI],     /* Host portion of URI */
-               resource[HTTP_MAX_URI]; /* Resource portion of URI */
+  DNSServiceErrorType error;           /* Error from service creation */
+  char         webif[1024];            /* Web interface share name */
+#  ifdef HAVE_SYSTEMCONFIGURATION
+  SCDynamicStoreRef sc;                        /* Context for dynamic store */
+  CFDictionaryRef btmm;                        /* Back-to-My-Mac domains */
+  CFStringEncoding nameEncoding;       /* Encoding of computer name */
+  CFStringRef  nameRef;                /* Host name CFString */
+  char         nameBuffer[1024];       /* C-string buffer */
+#  endif /* HAVE_SYSTEMCONFIGURATION */
 
 
  /*
-  * Reset the refresh time...
-  */
-
-  BrowseSLPRefresh = time(NULL) + BrowseInterval;
-
- /* 
-  * Poll for remote printers using SLP...
+  * Only share the web interface and printers when non-local listening is
+  * enabled...
   */
 
-  s = NULL;
 
-  SLPFindSrvs(BrowseSLPHandle, SLP_CUPS_SRVTYPE, "", "",
-             slp_url_callback, &s);
+  if (!DNSSDPort)
+    return;
 
  /*
-  * Loop through the list of available printers...
+  * Get the computer name as a c-string...
   */
 
-  for (; s; s = next)
+#  ifdef HAVE_SYSTEMCONFIGURATION
+  sc = SCDynamicStoreCreate(kCFAllocatorDefault, CFSTR("cupsd"), NULL, NULL);
+
+  if (sc)
   {
    /*
-    * Save the "next" pointer...
+    * Get the computer name from the dynamic store...
     */
 
-    next = s->next;
+    cupsdClearString(&DNSSDComputerName);
 
-   /* 
-    * Load a cupsd_printer_t structure with the SLP service attributes...
-    */
+    if ((nameRef = SCDynamicStoreCopyComputerName(sc, &nameEncoding)) != NULL)
+    {
+      if (CFStringGetCString(nameRef, nameBuffer, sizeof(nameBuffer),
+                            kCFStringEncodingUTF8))
+      {
+        cupsdLogMessage(CUPSD_LOG_DEBUG,
+                       "Dynamic store computer name is \"%s\".", nameBuffer);
+       cupsdSetString(&DNSSDComputerName, nameBuffer);
+      }
 
-    SLPFindAttrs(BrowseSLPHandle, s->url, "", "", slp_attr_callback, &p);
+      CFRelease(nameRef);
+    }
+
+    if (!DNSSDComputerName)
+    {
+     /*
+      * Use the ServerName instead...
+      */
+
+      cupsdLogMessage(CUPSD_LOG_DEBUG,
+                      "Using ServerName \"%s\" as computer name.", ServerName);
+      cupsdSetString(&DNSSDComputerName, ServerName);
+    }
 
    /*
-    * Process this printer entry...
+    * Get the local hostname from the dynamic store...
     */
 
-    uri = s->url + SLP_CUPS_SRVLEN + 1;
+    cupsdClearString(&DNSSDHostName);
 
-    if (!strncmp(uri, "http://", 7) || !strncmp(uri, "ipp://", 6))
+    if ((nameRef = SCDynamicStoreCopyLocalHostName(sc)) != NULL)
+    {
+      if (CFStringGetCString(nameRef, nameBuffer, sizeof(nameBuffer),
+                            kCFStringEncodingUTF8))
+      {
+        cupsdLogMessage(CUPSD_LOG_DEBUG,
+                       "Dynamic store host name is \"%s\".", nameBuffer);
+       cupsdSetString(&DNSSDHostName, nameBuffer);
+      }
+
+      CFRelease(nameRef);
+    }
+
+    if (!DNSSDHostName)
     {
      /*
-      * Pull the URI apart to see if this is a local or remote printer...
+      * Use the ServerName instead...
       */
 
-      if (!is_local_queue(uri, host, sizeof(host), resource, sizeof(resource)))
-        process_browse_data(uri, host, resource, p.type, IPP_PRINTER_IDLE,
-                           p.location,  p.info, p.make_model, 0, NULL);
+      cupsdLogMessage(CUPSD_LOG_DEBUG,
+                      "Using ServerName \"%s\" as host name.", ServerName);
+      cupsdSetString(&DNSSDHostName, ServerName);
     }
 
    /*
-    * Free this listing...
+    * Get any Back-to-My-Mac domains and add them as aliases...
     */
 
-    cupsdClearString(&p.info);
-    cupsdClearString(&p.location);
-    cupsdClearString(&p.make_model);
-
-    free(s);
-  }       
-}
-#endif /* HAVE_LIBSLP */
+    cupsdFreeAliases(DNSSDAlias);
+    DNSSDAlias = NULL;
 
+    btmm = SCDynamicStoreCopyValue(sc, CFSTR("Setup:/Network/BackToMyMac"));
+    if (btmm && CFGetTypeID(btmm) == CFDictionaryGetTypeID())
+    {
+      cupsdLogMessage(CUPSD_LOG_DEBUG, "%d Back to My Mac aliases to add.",
+                     (int)CFDictionaryGetCount(btmm));
+      CFDictionaryApplyFunction(btmm, dnssdAddAlias, NULL);
+    }
+    else if (btmm)
+      cupsdLogMessage(CUPSD_LOG_ERROR,
+                     "Bad Back to My Mac data in dynamic store!");
+    else
+      cupsdLogMessage(CUPSD_LOG_DEBUG, "No Back to My Mac aliases to add.");
 
-/*
- * 'dequote()' - Remote quotes from a string.
- */
+    if (btmm)
+      CFRelease(btmm);
 
-static char *                          /* O - Dequoted string */
-dequote(char       *d,                 /* I - Destination string */
-        const char *s,                 /* I - Source string */
-       int        dlen)                /* I - Destination length */
-{
-  char *dptr;                          /* Pointer into destination */
+    CFRelease(sc);
+  }
+  else
+#  endif /* HAVE_SYSTEMCONFIGURATION */
+  {
+    cupsdSetString(&DNSSDComputerName, ServerName);
+    cupsdSetString(&DNSSDHostName, ServerName);
+  }
 
+ /*
+  * Then (re)register the web interface if enabled...
+  */
 
-  if (s)
+  if (BrowseWebIF)
   {
-    for (dptr = d, dlen --; *s && dlen > 0; s ++)
-      if (*s != '\"')
-      {
-       *dptr++ = *s;
-       dlen --;
-      }
-
-    *dptr = '\0';
+    if (DNSSDComputerName)
+      snprintf(webif, sizeof(webif), "CUPS @ %s", DNSSDComputerName);
+    else
+      strlcpy(webif, "CUPS Web Interface", sizeof(webif));
+
+    if (WebIFRef)
+      DNSServiceRefDeallocate(WebIFRef);
+
+    WebIFRef = DNSSDRef;
+    if ((error = DNSServiceRegister(&WebIFRef,
+                                   kDNSServiceFlagsShareConnection,
+                                   0, webif, "_http._tcp", NULL,
+                                   NULL, htons(DNSSDPort), 7,
+                                   "\006path=/", dnssdRegisterCallback,
+                                   NULL)) != kDNSServiceErr_NoError)
+      cupsdLogMessage(CUPSD_LOG_ERROR,
+                     "DNS-SD web interface registration failed: %d", error);
   }
-  else
-    *d = '\0';
-
-  return (d);
 }
+#endif /* HAVE_DNSSD */
 
 
+#ifdef HAVE_LDAP
 /*
- * 'is_local_queue()' - Determine whether the URI points at a local queue.
+ * 'cupsdUpdateLDAPBrowse()' - Scan for new printers via LDAP...
  */
 
-static int                             /* O - 1 = local, 0 = remote, -1 = bad URI */
-is_local_queue(const char *uri,                /* I - Printer URI */
-               char       *host,       /* O - Host string */
-              int        hostlen,      /* I - Length of host buffer */
-               char       *resource,   /* O - Resource string */
-              int        resourcelen)  /* I - Length of resource buffer */
+void
+cupsdUpdateLDAPBrowse(void)
 {
-  char         scheme[32],             /* Scheme portion of URI */
-               username[HTTP_MAX_URI]; /* Username portion of URI */
-  int          port;                   /* Port portion of URI */
-  cupsd_netif_t        *iface;                 /* Network interface */
+  char         uri[HTTP_MAX_URI],      /* Printer URI */
+               host[HTTP_MAX_URI],     /* Hostname */
+               resource[HTTP_MAX_URI], /* Resource path */
+               location[1024],         /* Printer location */
+               info[1024],             /* Printer information */
+               make_model[1024],       /* Printer make and model */
+               type_num[30];           /* Printer type number */
+  int          type;                   /* Printer type */
+  int          rc;                     /* LDAP status */
+  int          limit;                  /* Size limit */
+  LDAPMessage  *res,                   /* LDAP search results */
+                 *e;                   /* Current entry from search */
 
+  cupsdLogMessage(CUPSD_LOG_DEBUG2, "UpdateLDAPBrowse: %s", ServerName);
+
+  BrowseLDAPRefresh = time(NULL) + BrowseInterval;
 
  /*
-  * Pull the URI apart to see if this is a local or remote printer...
+  * Reconnect if LDAP Handle is invalid...
   */
 
-  if (httpSeparateURI(HTTP_URI_CODING_ALL, uri, scheme, sizeof(scheme),
-                      username, sizeof(username), host, hostlen, &port,
-                     resource, resourcelen) < HTTP_URI_OK)
-    return (-1);
-
-  DEBUG_printf(("host=\"%s\", ServerName=\"%s\"\n", host, ServerName));
+  if (! BrowseLDAPHandle)
+  {
+    ldap_reconnect();
+    return;
+  }
 
  /*
-  * Check for local server addresses...
+  * Search for cups printers in LDAP directory...
   */
 
-  if (!strcasecmp(host, ServerName) && port == LocalPort)
-    return (1);
-
-  cupsdNetIFUpdate();
-
-  for (iface = (cupsd_netif_t *)cupsArrayFirst(NetIFList);
-       iface;
-       iface = (cupsd_netif_t *)cupsArrayNext(NetIFList))
-    if (!strcasecmp(host, iface->hostname) && port == iface->port)
-      return (1);
+  rc = ldap_search_rec(BrowseLDAPHandle, BrowseLDAPDN, LDAP_SCOPE_SUBTREE,
+                       "(objectclass=cupsPrinter)", (char **)ldap_attrs, 0, &res);
 
  /*
-  * If we get here, the printer is remote...
+  * If ldap search was successfull then exit function
+  * and temporary disable LDAP updates...
   */
 
-  return (0);
-}
-
-
-/*
- * 'process_browse_data()' - Process new browse data.
- */
-
-static void
-process_browse_data(
-    const char    *uri,                        /* I - URI of printer/class */
-    const char    *host,               /* I - Hostname */
-    const char    *resource,           /* I - Resource path */
-    cups_ptype_t  type,                        /* I - Printer type */
-    ipp_pstate_t  state,               /* I - Printer state */
-    const char    *location,           /* I - Printer location */
-    const char    *info,               /* I - Printer information */
-    const char    *make_model,         /* I - Printer make and model */
-    int                  num_attrs,            /* I - Number of attributes */
-    cups_option_t *attrs)              /* I - Attributes */
-{
-  int          i;                      /* Looping var */
-  int          update;                 /* Update printer attributes? */
-  char         finaluri[HTTP_MAX_URI], /* Final URI for printer */
-               name[IPP_MAX_NAME],     /* Name of printer */
-               newname[IPP_MAX_NAME],  /* New name of printer */
-               *hptr,                  /* Pointer into hostname */
-               *sptr;                  /* Pointer into ServerName */
-  char         local_make_model[IPP_MAX_NAME];
-                                       /* Local make and model */
-  cupsd_printer_t *p;                  /* Printer information */
-  const char   *ipp_options,           /* ipp-options value */
-               *lease_duration;        /* lease-duration value */
-
+  if (rc != LDAP_SUCCESS) 
+  {
+    if (BrowseLDAPUpdate && ((rc == LDAP_SERVER_DOWN) || (rc == LDAP_CONNECT_ERROR)))
+    {
+      BrowseLDAPUpdate = FALSE;
+      cupsdLogMessage(CUPSD_LOG_INFO,
+                      "LDAP update temporary disabled");
+    }
+    return;
+  }
 
  /*
-  * Determine if the URI contains any illegal characters in it...
+  * If LDAP updates were disabled, we will reenable them...
   */
 
-  if (strncmp(uri, "ipp://", 6) || !host[0] ||
-      (strncmp(resource, "/printers/", 10) &&
-       strncmp(resource, "/classes/", 9)))
+  if (! BrowseLDAPUpdate)
   {
-    cupsdLogMessage(CUPSD_LOG_ERROR,
-                    "process_browse_data: Bad printer URI in browse data: %s",
-                    uri);
-    return;
+    BrowseLDAPUpdate = TRUE;
+    cupsdLogMessage(CUPSD_LOG_INFO,
+                    "LDAP update enabled");
   }
 
-  if (strchr(resource, '?') ||
-      (!strncmp(resource, "/printers/", 10) && strchr(resource + 10, '/')) ||
-      (!strncmp(resource, "/classes/", 9) && strchr(resource + 9, '/')))
+ /*
+  * Count LDAP entries and return if no entry exist...
+  */
+
+  limit = ldap_count_entries(BrowseLDAPHandle, res);
+  cupsdLogMessage(CUPSD_LOG_DEBUG2, "LDAP search returned %d entries", limit);
+  if (limit < 1)
   {
-    cupsdLogMessage(CUPSD_LOG_ERROR,
-                    "process_browse_data: Bad resource in browse data: %s",
-                    resource);
+    ldap_freeres(res);
     return;
   }
 
  /*
-  * OK, this isn't a local printer; add any remote options...
+  * Loop through the available printers...
   */
 
-  ipp_options = cupsGetOption("ipp-options", num_attrs, attrs);
-
-  if (BrowseRemoteOptions)
+  for (e = ldap_first_entry(BrowseLDAPHandle, res);
+       e;
+       e = ldap_next_entry(BrowseLDAPHandle, e))
   {
-    if (BrowseRemoteOptions[0] == '?')
-    {
-     /*
-      * Override server-supplied options...
-      */
+   /*
+    * Get the required values from this entry...
+    */
 
-      snprintf(finaluri, sizeof(finaluri), "%s%s", uri, BrowseRemoteOptions);
-    }
-    else if (ipp_options)
-    {
-     /*
-      * Combine the server and local options...
-      */
+    if (ldap_getval_firststring(BrowseLDAPHandle, e,
+                                "printerDescription", info, sizeof(info)) == -1)
+      continue;
 
-      snprintf(finaluri, sizeof(finaluri), "%s?%s+%s", uri, ipp_options,
-               BrowseRemoteOptions);
-    }
-    else
-    {
-     /*
-      * Just use the local options...
-      */
+    if (ldap_getval_firststring(BrowseLDAPHandle, e,
+                                "printerLocation", location, sizeof(location)) == -1)
+      continue;
 
-      snprintf(finaluri, sizeof(finaluri), "%s?%s", uri, BrowseRemoteOptions);
-    }
+    if (ldap_getval_firststring(BrowseLDAPHandle, e,
+                                "printerMakeAndModel", make_model, sizeof(make_model)) == -1)
+      continue;
+
+    if (ldap_getval_firststring(BrowseLDAPHandle, e,
+                                "printerType", type_num, sizeof(type_num)) == -1)
+      continue;
+
+    type = atoi(type_num);
+
+    if (ldap_getval_firststring(BrowseLDAPHandle, e,
+                                "printerURI", uri, sizeof(uri)) == -1)
+      continue;
 
-    uri = finaluri;
-  }
-  else if (ipp_options)
-  {
    /*
-    * Just use the server-supplied options...
+    * Process the entry as browse data...
     */
 
-    snprintf(finaluri, sizeof(finaluri), "%s?%s", uri, ipp_options);
-    uri = finaluri;
+    if (!is_local_queue(uri, host, sizeof(host), resource, sizeof(resource)))
+      process_browse_data(uri, host, resource, type, IPP_PRINTER_IDLE,
+                          location, info, make_model, 0, NULL);
+
   }
 
+  ldap_freeres(res);
+}
+#endif /* HAVE_LDAP */
+
+
+#ifdef HAVE_LIBSLP 
+/*
+ * 'cupsdUpdateSLPBrowse()' - Get browsing information via SLP.
+ */
+
+void
+cupsdUpdateSLPBrowse(void)
+{
+  slpsrvurl_t  *s,                     /* Temporary list of service URLs */
+               *next;                  /* Next service in list */
+  cupsd_printer_t p;                   /* Printer information */
+  const char   *uri;                   /* Pointer to printer URI */
+  char         host[HTTP_MAX_URI],     /* Host portion of URI */
+               resource[HTTP_MAX_URI]; /* Resource portion of URI */
+
+
  /*
-  * See if we already have it listed in the Printers list, and add it if not...
+  * Reset the refresh time...
   */
 
-  type   |= CUPS_PRINTER_REMOTE;
-  type   &= ~CUPS_PRINTER_IMPLICIT;
-  update = 0;
-  hptr   = strchr(host, '.');
-  sptr   = strchr(ServerName, '.');
+  BrowseSLPRefresh = time(NULL) + BrowseInterval;
 
-  if (!ServerNameIsIP && sptr != NULL && hptr != NULL)
-  {
-   /*
-    * Strip the common domain name components...
-    */
+ /* 
+  * Poll for remote printers using SLP...
+  */
 
-    while (hptr != NULL)
-    {
-      if (!strcasecmp(hptr, sptr))
-      {
-        *hptr = '\0';
-       break;
-      }
-      else
-        hptr = strchr(hptr + 1, '.');
-    }
-  }
+  s = NULL;
+
+  SLPFindSrvs(BrowseSLPHandle, SLP_CUPS_SRVTYPE, "", "",
+             slp_url_callback, &s);
 
-  if (type & CUPS_PRINTER_CLASS)
+ /*
+  * Loop through the list of available printers...
+  */
+
+  for (; s; s = next)
   {
    /*
-    * Remote destination is a class...
+    * Save the "next" pointer...
     */
 
-    if (!strncmp(resource, "/classes/", 9))
-      snprintf(name, sizeof(name), "%s@%s", resource + 9, host);
-    else
-      return;
+    next = s->next;
 
-    if (hptr && !*hptr)
-      *hptr = '.';                     /* Resource FQDN */
+   /* 
+    * Load a cupsd_printer_t structure with the SLP service attributes...
+    */
 
-    if ((p = cupsdFindClass(name)) == NULL && BrowseShortNames)
-    {
-      if ((p = cupsdFindClass(resource + 9)) != NULL)
-      {
-        if (p->hostname && strcasecmp(p->hostname, host))
-       {
-        /*
-         * Nope, this isn't the same host; if the hostname isn't the local host,
-         * add it to the other class and then find a class using the full host
-         * name...
-         */
-
-         if (p->type & CUPS_PRINTER_REMOTE)
-         {
-           cupsdLogMessage(CUPSD_LOG_DEBUG,
-                           "Renamed remote class \"%s\" to \"%s@%s\"...",
-                           p->name, p->name, p->hostname);
-           cupsdAddEvent(CUPSD_EVENT_PRINTER_DELETED, p, NULL,
-                         "Class \'%s\' deleted by directory services.",
-                         p->name);
-
-            snprintf(newname, sizeof(newname), "%s@%s", p->name, p->hostname);
-            cupsdRenamePrinter(p, newname);
-
-           cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED, p, NULL,
-                         "Class \'%s\' added by directory services.",
-                         p->name);
-         }
+    SLPFindAttrs(BrowseSLPHandle, s->url, "", "", slp_attr_callback, &p);
 
-          p = NULL;
-       }
-       else if (!p->hostname)
-       {
-        /*
-         * Hostname not set, so this must be a cached remote printer
-         * that was created for a pending print job...
-         */
+   /*
+    * Process this printer entry...
+    */
 
-          cupsdSetString(&p->hostname, host);
-         cupsdSetString(&p->uri, uri);
-         cupsdSetString(&p->device_uri, uri);
-          update = 1;
-        }
-      }
-      else
-      {
-       /*
-        * Use the short name for this shared class.
-       */
+    uri = s->url + SLP_CUPS_SRVLEN + 1;
 
-        strlcpy(name, resource + 9, sizeof(name));
-      }
-    }
-    else if (p && !p->hostname)
+    if (!strncmp(uri, "http://", 7) || !strncmp(uri, "ipp://", 6))
     {
      /*
-      * Hostname not set, so this must be a cached remote printer
-      * that was created for a pending print job...
+      * Pull the URI apart to see if this is a local or remote printer...
       */
 
-      cupsdSetString(&p->hostname, host);
-      cupsdSetString(&p->uri, uri);
-      cupsdSetString(&p->device_uri, uri);
-      update = 1;
+      if (!is_local_queue(uri, host, sizeof(host), resource, sizeof(resource)))
+        process_browse_data(uri, host, resource, p.type, IPP_PRINTER_IDLE,
+                           p.location,  p.info, p.make_model, 0, NULL);
     }
 
-    if (!p)
-    {
-     /*
-      * Class doesn't exist; add it...
-      */
-
-      p = cupsdAddClass(name);
-
-      cupsdLogMessage(CUPSD_LOG_DEBUG, "Added remote class \"%s\"...", name);
+   /*
+    * Free this listing...
+    */
 
-      cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED, p, NULL,
-                    "Class \'%s\' added by directory services.", name);
+    cupsdClearString(&p.info);
+    cupsdClearString(&p.location);
+    cupsdClearString(&p.make_model);
 
-     /*
-      * Force the URI to point to the real server...
-      */
+    free(s);
+  }       
+}
+#endif /* HAVE_LIBSLP */
 
-      p->type      = type & ~CUPS_PRINTER_REJECTING;
-      p->accepting = 1;
-      cupsdSetString(&p->uri, uri);
-      cupsdSetString(&p->device_uri, uri);
-      cupsdSetString(&p->hostname, host);
 
-      update = 1;
-    }
-  }
-  else
-  {
-   /*
-    * Remote destination is a printer...
-    */
+/*
+ * 'dequote()' - Remote quotes from a string.
+ */
 
-    if (!strncmp(resource, "/printers/", 10))
-      snprintf(name, sizeof(name), "%s@%s", resource + 10, host);
-    else
-      return;
+static char *                          /* O - Dequoted string */
+dequote(char       *d,                 /* I - Destination string */
+        const char *s,                 /* I - Source string */
+       int        dlen)                /* I - Destination length */
+{
+  char *dptr;                          /* Pointer into destination */
 
-    if (hptr && !*hptr)
-      *hptr = '.';                     /* Resource FQDN */
 
-    if ((p = cupsdFindPrinter(name)) == NULL && BrowseShortNames)
-    {
-      if ((p = cupsdFindPrinter(resource + 10)) != NULL)
+  if (s)
+  {
+    for (dptr = d, dlen --; *s && dlen > 0; s ++)
+      if (*s != '\"')
       {
-        if (p->hostname && strcasecmp(p->hostname, host))
-       {
-        /*
-         * Nope, this isn't the same host; if the hostname isn't the local host,
-         * add it to the other printer and then find a printer using the full host
-         * name...
-         */
+       *dptr++ = *s;
+       dlen --;
+      }
 
-         if (p->type & CUPS_PRINTER_REMOTE)
-         {
-           cupsdLogMessage(CUPSD_LOG_DEBUG,
-                           "Renamed remote printer \"%s\" to \"%s@%s\"...",
-                           p->name, p->name, p->hostname);
-           cupsdAddEvent(CUPSD_EVENT_PRINTER_DELETED, p, NULL,
-                         "Printer \'%s\' deleted by directory services.",
-                         p->name);
-
-            snprintf(newname, sizeof(newname), "%s@%s", p->name, p->hostname);
-            cupsdRenamePrinter(p, newname);
-
-           cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED, p, NULL,
-                         "Printer \'%s\' added by directory services.",
-                         p->name);
-         }
+    *dptr = '\0';
+  }
+  else
+    *d = '\0';
 
-          p = NULL;
-       }
-       else if (!p->hostname)
-       {
-        /*
-         * Hostname not set, so this must be a cached remote printer
-         * that was created for a pending print job...
-         */
+  return (d);
+}
 
-          cupsdSetString(&p->hostname, host);
-         cupsdSetString(&p->uri, uri);
-         cupsdSetString(&p->device_uri, uri);
-          update = 1;
-        }
-      }
-      else
-      {
-       /*
-        * Use the short name for this shared printer.
-       */
 
-        strlcpy(name, resource + 10, sizeof(name));
-      }
-    }
-    else if (p && !p->hostname)
-    {
-     /*
-      * Hostname not set, so this must be a cached remote printer
-      * that was created for a pending print job...
-      */
+#ifdef HAVE_DNSSD
+#  ifdef HAVE_COREFOUNDATION
+/*
+ * 'dnssdAddAlias()' - Add a DNS-SD alias name.
+ */
 
-      cupsdSetString(&p->hostname, host);
-      cupsdSetString(&p->uri, uri);
-      cupsdSetString(&p->device_uri, uri);
-      update = 1;
-    }
+static void
+dnssdAddAlias(const void *key,         /* I - Key */
+              const void *value,       /* I - Value (domain) */
+             void       *context)      /* I - Unused */
+{
+  char valueStr[1024],                 /* Domain string */
+       hostname[1024];                 /* Complete hostname */
 
-    if (!p)
-    {
-     /*
-      * Printer doesn't exist; add it...
-      */
 
-      p = cupsdAddPrinter(name);
+  (void)context;
 
-      cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED, p, NULL,
-                    "Printer \'%s\' added by directory services.", name);
+  if (CFGetTypeID((CFStringRef)value) == CFStringGetTypeID() &&
+      CFStringGetCString((CFStringRef)value, valueStr, sizeof(valueStr),
+                         kCFStringEncodingUTF8))
+  {
+    snprintf(hostname, sizeof(hostname), "%s.%s", DNSSDHostName, valueStr);
+    if (!DNSSDAlias)
+      DNSSDAlias = cupsArrayNew(NULL, NULL);
+
+    cupsdAddAlias(DNSSDAlias, hostname);
+    cupsdLogMessage(CUPSD_LOG_DEBUG, "Added Back to My Mac ServerAlias %s",
+                   hostname);
+  }
+  else
+    cupsdLogMessage(CUPSD_LOG_ERROR,
+                    "Bad Back to My Mac domain in dynamic store!");
+}
+#  endif /* HAVE_COREFOUNDATION */
 
-      cupsdLogMessage(CUPSD_LOG_DEBUG, "Added remote printer \"%s\"...", name);
 
-     /*
     * Force the URI to point to the real server...
     */
+/*
* 'dnssdBuildTxtRecord()' - Build a TXT record from printer info.
+ */
 
-      p->type      = type & ~CUPS_PRINTER_REJECTING;
-      p->accepting = 1;
-      cupsdSetString(&p->hostname, host);
-      cupsdSetString(&p->uri, uri);
-      cupsdSetString(&p->device_uri, uri);
+static char *                          /* O - TXT record */
+dnssdBuildTxtRecord(
+    int             *txt_len,          /* O - TXT record length */
+    cupsd_printer_t *p,                        /* I - Printer information */
+    int             for_lpd)           /* I - 1 = LPD, 0 = IPP */
+{
+  int          i;                      /* Looping var */
+  char         admin_hostname[256],    /* .local hostname for admin page */
+               adminurl_str[256],      /* URL for the admin page */
+               type_str[32],           /* Type to string buffer */
+               state_str[32],          /* State to string buffer */
+               rp_str[1024],           /* Queue name string buffer */
+               air_str[1024],          /* auth-info-required string buffer */
+               *keyvalue[32][2];       /* Table of key/value pairs */
 
-      update = 1;
-    }
-  }
 
  /*
-  * Update the state...
+  * Load up the key value pairs...
   */
 
-  p->state       = state;
-  p->browse_time = time(NULL);
+  i = 0;
 
-  if ((lease_duration = cupsGetOption("lease-duration", num_attrs,
-                                      attrs)) != NULL)
-  {
-   /*
-    * Grab the lease-duration for the browse data; anything less then 1
-    * second or more than 1 week gets the default BrowseTimeout...
-    */
+  keyvalue[i  ][0] = "txtvers";
+  keyvalue[i++][1] = "1";
 
-    i = atoi(lease_duration);
-    if (i < 1 || i > 604800)
-      i = BrowseTimeout;
+  keyvalue[i  ][0] = "qtotal";
+  keyvalue[i++][1] = "1";
 
-    p->browse_expire = p->browse_time + i;
-  }
+  keyvalue[i  ][0] = "rp";
+  keyvalue[i++][1] = rp_str;
+  if (for_lpd)
+    strlcpy(rp_str, p->name, sizeof(rp_str));
   else
-    p->browse_expire = p->browse_time + BrowseTimeout;
+    snprintf(rp_str, sizeof(rp_str), "%s/%s", 
+            (p->type & CUPS_PRINTER_CLASS) ? "classes" : "printers", p->name);
 
-  if (type & CUPS_PRINTER_REJECTING)
-  {
-    type &= ~CUPS_PRINTER_REJECTING;
+  keyvalue[i  ][0] = "ty";
+  keyvalue[i++][1] = p->make_model ? p->make_model : "Unknown";
 
-    if (p->accepting)
-    {
-      update       = 1;
-      p->accepting = 0;
-    }
-  }
-  else if (!p->accepting)
-  {
-    update       = 1;
-    p->accepting = 1;
-  }
+  snprintf(admin_hostname, sizeof(admin_hostname), "%s.local.", DNSSDHostName);
+  httpAssembleURIf(HTTP_URI_CODING_ALL, adminurl_str, sizeof(adminurl_str),
+                   "http", NULL, admin_hostname, DNSSDPort, "/%s/%s",
+                  (p->type & CUPS_PRINTER_CLASS) ? "classes" : "printers",
+                  p->name);
+  keyvalue[i  ][0] = "adminurl";
+  keyvalue[i++][1] = adminurl_str;
 
-  if (p->type != type)
-  {
-    p->type = type;
-    update  = 1;
-  }
+  keyvalue[i  ][0] = "note";
+  keyvalue[i++][1] = p->location ? p->location : "";
 
-  if (location && (!p->location || strcmp(p->location, location)))
-  {
-    cupsdSetString(&p->location, location);
-    update = 1;
-  }
+  keyvalue[i  ][0] = "priority";
+  keyvalue[i++][1] = for_lpd ? "100" : "0";
 
-  if (info && (!p->info || strcmp(p->info, info)))
-  {
-    cupsdSetString(&p->info, info);
-    update = 1;
-  }
+  keyvalue[i  ][0] = "product";
+  keyvalue[i++][1] = p->pc && p->pc->product ? p->pc->product : "Unknown";
 
-  if (!make_model || !make_model[0])
-  {
-    if (type & CUPS_PRINTER_CLASS)
-      snprintf(local_make_model, sizeof(local_make_model),
-               "Remote Class on %s", host);
-    else
-      snprintf(local_make_model, sizeof(local_make_model),
-               "Remote Printer on %s", host);
-  }
-  else
-    snprintf(local_make_model, sizeof(local_make_model),
-             "%s on %s", make_model, host);
+  keyvalue[i  ][0] = "pdl";
+  keyvalue[i++][1] = p->pdl ? p->pdl : "application/postscript";
 
-  if (!p->make_model || strcmp(p->make_model, local_make_model))
+  if (get_auth_info_required(p, air_str, sizeof(air_str)))
   {
-    cupsdSetString(&p->make_model, local_make_model);
-    update = 1;
+    keyvalue[i  ][0] = "air";
+    keyvalue[i++][1] = air_str;
   }
 
-  if (p->num_options)
-  {
-    if (!update && !(type & CUPS_PRINTER_DELETE))
-    {
-     /*
-      * See if we need to update the attributes...
-      */
+  keyvalue[i  ][0] = "UUID";
+  keyvalue[i++][1] = p->uuid + 9;
 
-      if (p->num_options != num_attrs)
-       update = 1;
-      else
-      {
-       for (i = 0; i < num_attrs; i ++)
-          if (strcmp(attrs[i].name, p->options[i].name) ||
-             (!attrs[i].value != !p->options[i].value) ||
-             (attrs[i].value && strcmp(attrs[i].value, p->options[i].value)))
-          {
-           update = 1;
-           break;
-          }
-      }
-    }
+#ifdef HAVE_SSL
+  keyvalue[i  ][0] = "TLS";
+  keyvalue[i++][1] = "1.2";
+#endif /* HAVE_SSL */
 
-   /*
-    * Free the old options...
-    */
+  keyvalue[i  ][0] = "Transparent";
+  keyvalue[i++][1] = "F";
 
-    cupsFreeOptions(p->num_options, p->options);
-  }
+  keyvalue[i  ][0] = "Binary";
+  keyvalue[i++][1] = "F";
 
-  p->num_options = num_attrs;
-  p->options     = attrs;
+  keyvalue[i  ][0] = "Fax";
+  keyvalue[i++][1] = (p->type & CUPS_PRINTER_FAX) ? "T" : "F";
 
-  if (type & CUPS_PRINTER_DELETE)
-  {
-    cupsdAddEvent(CUPSD_EVENT_PRINTER_DELETED, p, NULL,
-                  "%s \'%s\' deleted by directory services.",
-                 (type & CUPS_PRINTER_CLASS) ? "Class" : "Printer", p->name);
+  keyvalue[i  ][0] = "Color";
+  keyvalue[i++][1] = (p->type & CUPS_PRINTER_COLOR) ? "T" : "F";
 
-    cupsdExpireSubscriptions(p, NULL);
-    cupsdDeletePrinter(p, 1);
-    cupsdUpdateImplicitClasses();
-  }
-  else if (update)
-  {
-    cupsdSetPrinterAttrs(p);
-    cupsdUpdateImplicitClasses();
-  }
+  keyvalue[i  ][0] = "Duplex";
+  keyvalue[i++][1] = (p->type & CUPS_PRINTER_DUPLEX) ? "T" : "F";
 
- /*
-  * See if we have a default printer...  If not, make the first network
-  * default printer the default.
-  */
+  keyvalue[i  ][0] = "Staple";
+  keyvalue[i++][1] = (p->type & CUPS_PRINTER_STAPLE) ? "T" : "F";
 
-  if (DefaultPrinter == NULL && Printers != NULL && UseNetworkDefault)
-  {
-   /*
-    * Find the first network default printer and use it...
-    */
+  keyvalue[i  ][0] = "Copies";
+  keyvalue[i++][1] = (p->type & CUPS_PRINTER_COPIES) ? "T" : "F";
 
-    for (p = (cupsd_printer_t *)cupsArrayFirst(Printers);
-         p;
-        p = (cupsd_printer_t *)cupsArrayNext(Printers))
-      if (p->type & CUPS_PRINTER_DEFAULT)
-      {
-        DefaultPrinter = p;
-       break;
-      }
-  }
+  keyvalue[i  ][0] = "Collate";
+  keyvalue[i++][1] = (p->type & CUPS_PRINTER_COLLATE) ? "T" : "F";
 
- /*
-  * Do auto-classing if needed...
-  */
+  keyvalue[i  ][0] = "Punch";
+  keyvalue[i++][1] = (p->type & CUPS_PRINTER_PUNCH) ? "T" : "F";
 
-  process_implicit_classes();
+  keyvalue[i  ][0] = "Bind";
+  keyvalue[i++][1] = (p->type & CUPS_PRINTER_BIND) ? "T" : "F";
+
+  keyvalue[i  ][0] = "Sort";
+  keyvalue[i++][1] = (p->type & CUPS_PRINTER_SORT) ? "T" : "F";
+
+  keyvalue[i  ][0] = "Scan";
+  keyvalue[i++][1] = (p->type & CUPS_PRINTER_MFP) ? "T" : "F";
+
+  snprintf(type_str, sizeof(type_str), "0x%X", p->type | CUPS_PRINTER_REMOTE);
+  snprintf(state_str, sizeof(state_str), "%d", p->state);
+
+  keyvalue[i  ][0] = "printer-state";
+  keyvalue[i++][1] = state_str;
+
+  keyvalue[i  ][0] = "printer-type";
+  keyvalue[i++][1] = type_str;
 
  /*
-  * Update the printcap file...
+  * Then pack them into a proper txt record...
   */
 
-  cupsdWritePrintcap();
+  return (dnssdPackTxtRecord(txt_len, keyvalue, i));
 }
 
 
 /*
- * 'process_implicit_classes()' - Create/update implicit classes as needed.
+ * 'dnssdComparePrinters()' - Compare the registered names of two printers.
  */
 
-static void
-process_implicit_classes(void)
+static int                             /* O - Result of comparison */
+dnssdComparePrinters(cupsd_printer_t *a,/* I - First printer */
+                     cupsd_printer_t *b)/* I - Second printer */
 {
-  int          i;                      /* Looping var */
-  int          update;                 /* Update printer attributes? */
-  char         name[IPP_MAX_NAME],     /* Name of printer */
-               *hptr;                  /* Pointer into hostname */
-  cupsd_printer_t *p,                  /* Printer information */
-               *pclass,                /* Printer class */
-               *first;                 /* First printer in class */
-  int          offset,                 /* Offset of name */
-               len;                    /* Length of name */
+  return (strcasecmp(a->reg_name, b->reg_name));
+}
 
 
-  if (!ImplicitClasses || !Printers)
-    return;
+/*
+ * 'dnssdDeregisterPrinter()' - Stop sending broadcast information for a
+ *                              printer.
+ */
+
+static void
+dnssdDeregisterPrinter(
+    cupsd_printer_t *p)                        /* I - Printer */
+{
+  cupsdLogMessage(CUPSD_LOG_DEBUG2, "dnssdDeregisterPrinter(%s)", p->name);
 
  /*
-  * Loop through all available printers and create classes as needed...
+  * Closing the socket deregisters the service
   */
 
-  for (p = (cupsd_printer_t *)cupsArrayFirst(Printers), len = 0, offset = 0,
-           update = 0, pclass = NULL, first = NULL;
-       p != NULL;
-       p = (cupsd_printer_t *)cupsArrayNext(Printers))
+  if (p->ipp_ref)
+  {
+    DNSServiceRefDeallocate(p->ipp_ref);
+    p->ipp_ref = NULL;
+  }
+
+  if (p->ipp_txt)
   {
    /*
-    * Skip implicit classes...
+    * p->ipp_txt is malloc'd, not _cupsStrAlloc'd...
     */
 
-    if (p->type & CUPS_PRINTER_IMPLICIT)
-    {
-      len = 0;
-      continue;
-    }
+    free(p->ipp_txt);
+    p->ipp_txt = NULL;
+  }
+
+  if (p->printer_ref)
+  {
+    DNSServiceRefDeallocate(p->printer_ref);
+    p->printer_ref = NULL;
+  }
 
+  if (p->printer_txt)
+  {
    /*
-    * If len == 0, get the length of this printer name up to the "@"
-    * sign (if any).
+    * p->printer_txt is malloc'd, not _cupsStrAlloc'd...
     */
 
-    cupsArraySave(Printers);
-
-    if (len > 0 &&
-       !strncasecmp(p->name, name + offset, len) &&
-       (p->name[len] == '\0' || p->name[len] == '@'))
-    {
-     /*
-      * We have more than one printer with the same name; see if
-      * we have a class, and if this printer is a member...
-      */
-
-      if (pclass && strcasecmp(pclass->name, name))
-      {
-       if (update)
-         cupsdSetPrinterAttrs(pclass);
+    free(p->printer_txt);
+    p->printer_txt = NULL;
+  }
 
-       update = 0;
-       pclass = NULL;
-      }
+ /*
+  * Remove the printer from the array of DNS-SD printers, then clear the
+  * registered name...
+  */
 
-      if (!pclass && (pclass = cupsdFindDest(name)) == NULL)
-      {
-       /*
-       * Need to add the class...
-       */
+  cupsArrayRemove(DNSSDPrinters, p);
+  cupsdClearString(&p->reg_name);
+}
 
-       pclass = cupsdAddPrinter(name);
-       cupsArrayAdd(ImplicitPrinters, pclass);
 
-       pclass->type      |= CUPS_PRINTER_IMPLICIT;
-       pclass->accepting = 1;
-       pclass->state     = IPP_PRINTER_IDLE;
+/*
+ * 'dnssdPackTxtRecord()' - Pack an array of key/value pairs into the
+ *                          TXT record format.
+ */
 
-        cupsdSetString(&pclass->location, p->location);
-        cupsdSetString(&pclass->info, p->info);
+static char *                          /* O - TXT record */
+dnssdPackTxtRecord(int  *txt_len,      /* O - TXT record length */
+                  char *keyvalue[][2], /* I - Table of key value pairs */
+                  int  count)          /* I - Items in table */
+{
+  int  i;                              /* Looping var */
+  int  length;                         /* Length of TXT record */
+  int  length2;                                /* Length of value */
+  char *txtRecord;                     /* TXT record buffer */
+  char *cursor;                                /* Looping pointer */
 
-        update = 1;
 
-        cupsdLogMessage(CUPSD_LOG_DEBUG, "Added implicit class \"%s\"...",
-                       name);
-       cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED, p, NULL,
-                      "Implicit class \'%s\' added by directory services.",
-                     name);
-      }
+ /*
+  * Calculate the buffer size
+  */
 
-      if (first != NULL)
-      {
-        for (i = 0; i < pclass->num_printers; i ++)
-         if (pclass->printers[i] == first)
-           break;
+  if (count <= 0)
+    return (NULL);
 
-        if (i >= pclass->num_printers)
-       {
-         first->in_implicit_class = 1;
-         cupsdAddPrinterToClass(pclass, first);
-        }
+  for (length = i = 0; i < count; i++)
+    length += 1 + strlen(keyvalue[i][0]) + 
+             (keyvalue[i][1] ? 1 + strlen(keyvalue[i][1]) : 0);
 
-       first = NULL;
-      }
+ /*
+  * Allocate and fill it
+  */
 
-      for (i = 0; i < pclass->num_printers; i ++)
-       if (pclass->printers[i] == p)
-         break;
+  txtRecord = malloc(length);
+  if (txtRecord)
+  {
+    *txt_len = length;
 
-      if (i >= pclass->num_printers)
-      {
-       p->in_implicit_class = 1;
-       cupsdAddPrinterToClass(pclass, p);
-       update = 1;
-      }
-    }
-    else
+    for (cursor = txtRecord, i = 0; i < count; i++)
     {
      /*
-      * First time around; just get name length and mark it as first
-      * in the list...
+      * Drop in the p-string style length byte followed by the data
       */
 
-      if ((hptr = strchr(p->name, '@')) != NULL)
-       len = hptr - p->name;
-      else
-       len = strlen(p->name);
+      length  = strlen(keyvalue[i][0]);
+      length2 = keyvalue[i][1] ? 1 + strlen(keyvalue[i][1]) : 0;
 
-      strncpy(name, p->name, len);
-      name[len] = '\0';
-      offset    = 0;
+      *cursor++ = (unsigned char)(length + length2);
 
-      if ((first = (hptr ? cupsdFindDest(name) : p)) != NULL &&
-         !(first->type & CUPS_PRINTER_IMPLICIT))
+      memcpy(cursor, keyvalue[i][0], length);
+      cursor += length;
+
+      if (length2)
       {
-       /*
-       * Can't use same name as a local printer; add "Any" to the
-       * front of the name, unless we have explicitly disabled
-       * the "ImplicitAnyClasses"...
-       */
+        length2 --;
+       *cursor++ = '=';
+       memcpy(cursor, keyvalue[i][1], length2);
+       cursor += length2;
+      }
+    }
+  }
 
-        if (ImplicitAnyClasses && len < (sizeof(name) - 4))
-       {
-        /*
-         * Add "Any" to the class name...
-         */
+  return (txtRecord);
+}
 
-          strcpy(name, "Any");
-          strncpy(name + 3, p->name, len);
-         name[len + 3] = '\0';
-         offset        = 3;
-       }
-       else
-       {
-        /*
-         * Don't create an implicit class if we have a local printer
-         * with the same name...
-         */
 
-         len = 0;
-          cupsArrayRestore(Printers);
-         continue;
-       }
-      }
+/*
+ * 'dnssdRegisterCallback()' - DNSServiceRegister callback.
+ */
 
-      first = p;
-    }
+static void
+dnssdRegisterCallback(
+    DNSServiceRef      sdRef,          /* I - DNS Service reference */
+    DNSServiceFlags    flags,          /* I - Reserved for future use */
+    DNSServiceErrorType        errorCode,      /* I - Error code */
+    const char         *name,          /* I - Service name */
+    const char         *regtype,       /* I - Service type */
+    const char         *domain,        /* I - Domain. ".local" for now */
+    void               *context)       /* I - User-defined context */
+{
+  cupsd_printer_t *p = (cupsd_printer_t *)context;
+                                       /* Current printer */
 
-    cupsArrayRestore(Printers);
+
+  cupsdLogMessage(CUPSD_LOG_DEBUG2, "dnssdRegisterCallback(%s, %s) for %s (%s)",
+                  name, regtype, p ? p->name : "Web Interface",
+                 p ? (p->reg_name ? p->reg_name : "(null)") : "NA");
+
+  if (errorCode)
+  {
+    cupsdLogMessage(CUPSD_LOG_ERROR, 
+                   "DNSServiceRegister failed with error %d", (int)errorCode);
+    return;
   }
+  else if (p && (!p->reg_name || strcasecmp(name, p->reg_name)))
+  {
+    cupsdLogMessage(CUPSD_LOG_INFO, "Using service name \"%s\" for \"%s\"",
+                    name, p->name);
 
- /*
-  * Update the last printer class as needed...
-  */
+    cupsArrayRemove(DNSSDPrinters, p);
+    cupsdSetString(&p->reg_name, name);
+    cupsArrayAdd(DNSSDPrinters, p);
 
-  if (pclass && update)
-    cupsdSetPrinterAttrs(pclass);
+    LastEvent |= CUPSD_EVENT_PRINTER_MODIFIED;
+  }
 }
 
 
 /*
- * 'send_cups_browse()' - Send new browsing information using the CUPS
- *                           protocol.
+ * 'dnssdRegisterPrinter()' - Start sending broadcast information for a printer
+ *                           or update the broadcast contents.
  */
 
-static void
-send_cups_browse(cupsd_printer_t *p)   /* I - Printer to send */
+static void 
+dnssdRegisterPrinter(cupsd_printer_t *p)/* I - Printer */
 {
-  int                  i;              /* Looping var */
-  cups_ptype_t         type;           /* Printer type */
-  cupsd_dirsvc_addr_t  *b;             /* Browse address */
-  int                  bytes;          /* Length of packet */
-  char                 packet[1453],   /* Browse data packet */
-                       uri[1024],      /* Printer URI */
-                       location[1024], /* printer-location */
-                       info[1024],     /* printer-info */
-                       make_model[1024];
-                                       /* printer-make-and-model */
-  cupsd_netif_t                *iface;         /* Network interface */
+  DNSServiceErrorType  se;             /* dnssd errors */
+  char                 *ipp_txt,       /* IPP TXT record buffer */
+                       *printer_txt,   /* LPD TXT record buffer */
+                       name[1024],     /* Service name */
+                       *nameptr;       /* Pointer into name */
+  int                  ipp_len,        /* IPP TXT record length */
+                       printer_len,    /* LPD TXT record length */
+                       printer_port;   /* LPD port number */
+  const char           *regtype;       /* Registration type */
 
 
+  cupsdLogMessage(CUPSD_LOG_DEBUG2, "dnssdRegisterPrinter(%s) %s", p->name,
+                  !p->ipp_ref ? "new" : "update");
+
  /*
-  * Figure out the printer type value...
+  * If per-printer sharing was just disabled make sure we're not
+  * registered before returning.
   */
 
-  type = p->type | CUPS_PRINTER_REMOTE;
+  if (!p->shared)
+  {
+    dnssdDeregisterPrinter(p);
+    return;
+  }
 
-  if (!p->accepting)
-    type |= CUPS_PRINTER_REJECTING;
+ /*
+  * The registered name takes the form of "<printer-info> @ <computer name>"...
+  */
 
-  if (p == DefaultPrinter)
-    type |= CUPS_PRINTER_DEFAULT;
+  if (p->info && strlen(p->info) > 0)
+  {
+    if (DNSSDComputerName)
+      snprintf(name, sizeof(name), "%s @ %s", p->info, DNSSDComputerName);
+    else
+      strlcpy(name, p->info, sizeof(name));
+  }
+  else if (DNSSDComputerName)
+    snprintf(name, sizeof(name), "%s @ %s", p->name, DNSSDComputerName);
+  else
+    strlcpy(name, p->name, sizeof(name));
 
  /*
-  * Remove quotes from printer-info, printer-location, and
-  * printer-make-and-model attributes...
+  * If an existing printer was renamed, unregister it and start over...
   */
 
-  dequote(location, p->location, sizeof(location));
-  dequote(info, p->info, sizeof(info));
+  if (p->reg_name && strcmp(p->reg_name, name))
+    dnssdDeregisterPrinter(p);
 
-  if (p->make_model)
-    dequote(make_model, p->make_model, sizeof(make_model));
-  else if (p->type & CUPS_PRINTER_CLASS)
+  if (!p->reg_name)
   {
-    if (p->num_printers > 0 && p->printers[0]->make_model)
-      strlcpy(make_model, p->printers[0]->make_model, sizeof(make_model));
-    else
-      strlcpy(make_model, "Local Printer Class", sizeof(make_model));
+    cupsdSetString(&p->reg_name, name);
+    cupsArrayAdd(DNSSDPrinters, p);
   }
-  else if (p->raw)
-    strlcpy(make_model, "Local Raw Printer", sizeof(make_model));
-  else
-    strlcpy(make_model, "Local System V Printer", sizeof(make_model));
 
  /*
-  * Send a packet to each browse address...
+  * Register IPP and (optionally) LPD...
   */
 
-  for (i = NumBrowsers, b = Browsers; i > 0; i --, b ++)
-    if (b->iface[0])
+  ipp_len = 0;                         /* anti-compiler-warning-code */
+  ipp_txt = dnssdBuildTxtRecord(&ipp_len, p, 0);
+
+  if (p->ipp_ref &&
+      (ipp_len != p->ipp_len || memcmp(ipp_txt, p->ipp_txt, ipp_len)))
+  {
+   /*
+    * Update the existing registration...
+    */
+
+    /* A TTL of 0 means use record's original value (Radar 3176248) */
+    if ((se = DNSServiceUpdateRecord(p->ipp_ref, NULL, 0, ipp_len, ipp_txt,
+                                    0)) == kDNSServiceErr_NoError)
+    {
+      if (p->ipp_txt)
+       free(p->ipp_txt);
+
+      p->ipp_txt = ipp_txt;
+      p->ipp_len = ipp_len;
+      ipp_txt    = NULL;
+    }
+    else
     {
      /*
-      * Send the browse packet to one or more interfaces...
+      * Failed to update record, lets close this reference and move on...
       */
 
-      if (!strcmp(b->iface, "*"))
+      cupsdLogMessage(CUPSD_LOG_ERROR,
+                     "Unable to update IPP DNS-SD record for %s - %d", p->name,
+                     se);
+
+      DNSServiceRefDeallocate(p->ipp_ref);
+      p->ipp_ref = NULL;
+    }
+  }
+
+  if (!p->ipp_ref)
+  {
+   /*
+    * Initial registration.  Use the _fax-ipp regtype for fax queues...
+    */
+
+    regtype = (p->type & CUPS_PRINTER_FAX) ? "_fax-ipp._tcp" : DNSSDRegType;
+
+    cupsdLogMessage(CUPSD_LOG_DEBUG, 
+                   "Registering DNS-SD printer %s with name \"%s\" and "
+                   "type \"%s\"", p->name, name, regtype);
+
+   /*
+    * Register the queue, dropping characters as needed until we succeed...
+    */
+
+    nameptr = name + strlen(name);
+
+    do
+    {
+      p->ipp_ref = DNSSDRef;
+      if ((se = DNSServiceRegister(&p->ipp_ref, kDNSServiceFlagsShareConnection,
+                                   0, name, regtype, NULL, NULL,
+                                  htons(DNSSDPort), ipp_len, ipp_txt,
+                                  dnssdRegisterCallback,
+                                  p)) == kDNSServiceErr_BadParam)
       {
        /*
-        * Send to all local interfaces...
+        * Name is too long, drop trailing characters, taking into account
+       * UTF-8 encoding...
        */
 
-        cupsdNetIFUpdate();
+        nameptr --;
 
-       for (iface = (cupsd_netif_t *)cupsArrayFirst(NetIFList);
-            iface;
-            iface = (cupsd_netif_t *)cupsArrayNext(NetIFList))
-       {
-        /*
-         * Only send to local, IPv4 interfaces...
-         */
-
-         if (!iface->is_local || !iface->port ||
-             iface->address.addr.sa_family != AF_INET)
-           continue;
-
-         httpAssembleURIf(HTTP_URI_CODING_ALL, uri, sizeof(uri), "ipp", NULL,
-                          iface->hostname, iface->port,
-                          (p->type & CUPS_PRINTER_CLASS) ? "/classes/%s" :
-                                                           "/printers/%s",
-                          p->name);
-         snprintf(packet, sizeof(packet), "%x %x %s \"%s\" \"%s\" \"%s\" %s\n",
-                  type, p->state, uri, location, info, make_model,
-                  p->browse_attrs ? p->browse_attrs : "");
-
-         bytes = strlen(packet);
-
-         cupsdLogMessage(CUPSD_LOG_DEBUG2,
-                         "cupsdSendBrowseList: (%d bytes to \"%s\") %s", bytes,
-                         iface->name, packet);
-
-          iface->broadcast.ipv4.sin_port = htons(BrowsePort);
+        while (nameptr > name && (*nameptr & 0xc0) == 0x80)
+         nameptr --;
 
-         sendto(BrowseSocket, packet, bytes, 0,
-                (struct sockaddr *)&(iface->broadcast),
-                httpAddrLength(&(iface->broadcast)));
-        }
+        if (nameptr > name)
+          *nameptr = '\0';
       }
-      else if ((iface = cupsdNetIFFind(b->iface)) != NULL)
-      {
-       /*
-        * Send to the named interface using the IPv4 address...
-       */
+    }
+    while (se == kDNSServiceErr_BadParam && nameptr > name);
 
-        while (iface)
-         if (strcmp(b->iface, iface->name))
-         {
-           iface = NULL;
-           break;
-         }
-         else if (iface->address.addr.sa_family == AF_INET && iface->port)
-           break;
-         else
-            iface = (cupsd_netif_t *)cupsArrayNext(NetIFList);
+    if (se == kDNSServiceErr_NoError)
+    {
+      p->ipp_txt = ipp_txt;
+      p->ipp_len = ipp_len;
+      ipp_txt    = NULL;
+    }
+    else
+      cupsdLogMessage(CUPSD_LOG_WARN,
+                      "DNS-SD IPP registration of \"%s\" failed: %d",
+                     p->name, se);
+  }
 
-        if (iface)
-       {
-         httpAssembleURIf(HTTP_URI_CODING_ALL, uri, sizeof(uri), "ipp", NULL,
-                          iface->hostname, iface->port,
-                          (p->type & CUPS_PRINTER_CLASS) ? "/classes/%s%s" :
-                                                           "/printers/%s",
-                          p->name);
-         snprintf(packet, sizeof(packet), "%x %x %s \"%s\" \"%s\" \"%s\" %s\n",
-                  type, p->state, uri, location, info, make_model,
-                  p->browse_attrs ? p->browse_attrs : "");
+  if (ipp_txt)
+    free(ipp_txt);
 
-         bytes = strlen(packet);
+  if (BrowseLocalProtocols & BROWSE_LPD)
+  {
+    printer_len  = 0;                  /* anti-compiler-warning-code */
+    printer_port = 515;
+    printer_txt  = dnssdBuildTxtRecord(&printer_len, p, 1);
+  }
+  else
+  {
+    printer_len  = 0;
+    printer_port = 0;
+    printer_txt  = NULL;
+  }
 
-         cupsdLogMessage(CUPSD_LOG_DEBUG2,
-                         "cupsdSendBrowseList: (%d bytes to \"%s\") %s", bytes,
-                         iface->name, packet);
+  if (p->printer_ref &&
+      (printer_len != p->printer_len ||
+       memcmp(printer_txt, p->printer_txt, printer_len)))
+  {
+   /*
+    * Update the existing registration...
+    */
 
-          iface->broadcast.ipv4.sin_port = htons(BrowsePort);
+    /* A TTL of 0 means use record's original value (Radar 3176248) */
+    if ((se = DNSServiceUpdateRecord(p->printer_ref, NULL, 0, printer_len,
+                                    printer_txt,
+                                    0)) == kDNSServiceErr_NoError)
+    {
+      if (p->printer_txt)
+       free(p->printer_txt);
 
-         sendto(BrowseSocket, packet, bytes, 0,
-                (struct sockaddr *)&(iface->broadcast),
-                httpAddrLength(&(iface->broadcast)));
-        }
-      }
+      p->printer_txt = printer_txt;
+      p->printer_len = printer_len;
+      printer_txt    = NULL;
     }
     else
     {
      /*
-      * Send the browse packet to the indicated address using
-      * the default server name...
+      * Failed to update record, lets close this reference and move on...
       */
 
-      snprintf(packet, sizeof(packet), "%x %x %s \"%s\" \"%s\" \"%s\" %s\n",
-                      type, p->state, p->uri, location, info, make_model,
-              p->browse_attrs ? p->browse_attrs : "");
-
-      bytes = strlen(packet);
-      cupsdLogMessage(CUPSD_LOG_DEBUG2,
-                      "cupsdSendBrowseList: (%d bytes) %s", bytes, packet);
-
-      if (sendto(BrowseSocket, packet, bytes, 0,
-                (struct sockaddr *)&(b->to),
-                httpAddrLength(&(b->to))) <= 0)
-      {
-       /*
-        * Unable to send browse packet, so remove this address from the
-       * list...
-       */
-
-       cupsdLogMessage(CUPSD_LOG_ERROR,
-                       "cupsdSendBrowseList: sendto failed for browser "
-                       "%d - %s.",
-                       (int)(b - Browsers + 1), strerror(errno));
+      cupsdLogMessage(CUPSD_LOG_ERROR,
+                     "Unable to update LPD DNS-SD record for %s - %d",
+                     p->name, se);
 
-        if (i > 1)
-         memmove(b, b + 1, (i - 1) * sizeof(cupsd_dirsvc_addr_t));
+      DNSServiceRefDeallocate(p->printer_ref);
+      p->printer_ref = NULL;
+    }
+  }
+  
+  if (!p->printer_ref)
+  {
+   /*
+    * Initial registration...
+    */
 
-       b --;
-       NumBrowsers --;
-      }
+    cupsdLogMessage(CUPSD_LOG_DEBUG, 
+                   "Registering DNS-SD printer %s with name \"%s\" and "
+                   "type \"_printer._tcp\"", p->name, name);
+
+    p->printer_ref = DNSSDRef;
+    if ((se = DNSServiceRegister(&p->printer_ref,
+                                kDNSServiceFlagsShareConnection,
+                                0, name, "_printer._tcp", NULL, NULL,
+                                htons(printer_port), printer_len, printer_txt,
+                                dnssdRegisterCallback,
+                                p)) == kDNSServiceErr_NoError)
+    {
+      p->printer_txt = printer_txt;
+      p->printer_len = printer_len;
+      printer_txt    = NULL;
     }
+    else
+      cupsdLogMessage(CUPSD_LOG_WARN,
+                     "DNS-SD LPD registration of \"%s\" failed: %d",
+                     p->name, se);
+  }
+
+  if (printer_txt)
+    free(printer_txt);
 }
 
 
-#ifdef HAVE_OPENLDAP
 /*
- * 'send_ldap_browse()' - Send LDAP printer registrations.
+ * 'dnssdStop()' - Stop all DNS-SD registrations.
  */
 
 static void
-send_ldap_browse(cupsd_printer_t *p)   /* I - Printer to register */
+dnssdStop(void)
 {
-  int          i;                      /* Looping var... */
-  LDAPMod      mods[7];                /* The 7 attributes we will be adding */
-  LDAPMod      *pmods[8];              /* Pointers to the 7 attributes + NULL */
-  LDAPMessage  *res;                   /* Search result token */
-  char         *cn_value[2],           /* Change records */
-               *uri[2],
-               *info[2],
-               *location[2],
-               *make_model[2],
-               *type[2],
-               typestring[255],        /* String to hold printer-type */
-               filter[256],            /* Search filter for possible UPDATEs */
-               dn[1024];               /* DN of the printer we are adding */
-  int          rc;                     /* LDAP status */
-  static const char * const objectClass_values[] =
-               {                       /* The 3 objectClass's we use in */
-                 "top",                /* our LDAP entries              */
-                 "device",
-                 "cupsPrinter",
-                 NULL
-               };
+  cupsd_printer_t      *p;             /* Current printer */
 
-  cupsdLogMessage(CUPSD_LOG_DEBUG2, "send_ldap_browse: %s\n", p->name);
 
  /*
-  * Everything in ldap is ** so we fudge around it...
+  * De-register the individual printers
   */
 
-  sprintf(typestring, "%u", p->type);
+  for (p = (cupsd_printer_t *)cupsArrayFirst(Printers);
+       p;
+       p = (cupsd_printer_t *)cupsArrayNext(Printers))
+    dnssdDeregisterPrinter(p);
 
-  cn_value[0]   = p->name;
-  cn_value[1]   = NULL;
-  info[0]       = p->info ? p->info : "Unknown";
-  info[1]       = NULL;
-  location[0]   = p->location ? p->location : "Unknown";
-  location[1]   = NULL;
-  make_model[0] = p->make_model ? p->make_model : "Unknown";
-  make_model[1] = NULL;
-  type[0]       = typestring;
-  type[1]       = NULL;
-  uri[0]        = p->uri;
-  uri[1]        = NULL;
+ /*
+  * Shutdown the rest of the service refs...
+  */
 
-  snprintf(filter, sizeof(filter),
-           "(&(objectclass=cupsPrinter)(printerURI=%s))", p->uri);
+  if (WebIFRef)
+  {
+    DNSServiceRefDeallocate(WebIFRef);
+    WebIFRef = NULL;
+  }
 
-  ldap_search_s(BrowseLDAPHandle, BrowseLDAPDN, LDAP_SCOPE_SUBTREE,
-                filter, (char **)ldap_attrs, 0, &res);
-  cupsdLogMessage(CUPSD_LOG_DEBUG2, "send_ldap_browse: Searching \"%s\"",
-                  filter);
+  if (RemoteRef)
+  {
+    DNSServiceRefDeallocate(RemoteRef);
+    RemoteRef = NULL;
+  }
 
-  mods[0].mod_type = "cn";
-  mods[0].mod_values = cn_value;
-  mods[1].mod_type = "printerDescription";
-  mods[1].mod_values = info;
-  mods[2].mod_type = "printerURI";
-  mods[2].mod_values = uri;
-  mods[3].mod_type = "printerLocation";
-  mods[3].mod_values = location;
-  mods[4].mod_type = "printerMakeAndModel";
-  mods[4].mod_values = make_model;
-  mods[5].mod_type = "printerType";
-  mods[5].mod_values = type;
-  mods[6].mod_type = "objectClass";
-  mods[6].mod_values = (char **)objectClass_values;
+  cupsdRemoveSelect(DNSServiceRefSockFD(DNSSDRef));
 
-  snprintf(dn, sizeof(dn), "cn=%s,ou=printers,%s", p->name, BrowseLDAPDN);
-  cupsdLogMessage(CUPSD_LOG_DEBUG2, "send_ldap_browse: dn=\"%s\"", dn);
+  DNSServiceRefDeallocate(DNSSDRef);
+  DNSSDRef = NULL;
 
-  if (ldap_count_entries(BrowseLDAPHandle, res) > 0)
-  {
-   /*
-    * Printer has already been registered, modify the current
-    * registration...
-    */
+  cupsArrayDelete(DNSSDPrinters);
+  DNSSDPrinters = NULL;
 
-    cupsdLogMessage(CUPSD_LOG_DEBUG2,
-                    "send_ldap_browse: Replacing entry...");
+  DNSSDPort = 0;
+}
 
-    for (i = 0; i < 7; i ++)
-    {
-      pmods[i]         = mods + i;
-      pmods[i]->mod_op = LDAP_MOD_REPLACE;
-    }
-    pmods[i] = NULL;
 
-    if ((rc = ldap_modify_s(BrowseLDAPHandle, dn, pmods)) != LDAP_SUCCESS)
-      cupsdLogMessage(CUPSD_LOG_ERROR,
-                      "LDAP modify for %s failed with status %d: %s",
-                      p->name, rc, ldap_err2string(rc));
-  }
-  else 
-  {
-   /*
-    * Printer has never been registered, add the current
-    * registration...
-    */
+/*
+ * 'dnssdUpdate()' - Handle DNS-SD queries.
+ */
 
-    cupsdLogMessage(CUPSD_LOG_DEBUG2,
-                    "send_ldap_browse: Adding entry...");
+static void
+dnssdUpdate(void)
+{
+  DNSServiceErrorType  sdErr;          /* Service discovery error */
 
-    for (i = 0; i < 7; i ++)
-    {
-      pmods[i]         = mods + i;
-      pmods[i]->mod_op = LDAP_MOD_ADD;
-    }
-    pmods[i] = NULL;
 
-    if ((rc = ldap_add_s(BrowseLDAPHandle, dn, pmods)) != LDAP_SUCCESS)
-      cupsdLogMessage(CUPSD_LOG_ERROR,
-                      "LDAP add for %s failed with status %d: %s",
-                      p->name, rc, ldap_err2string(rc));
+  if ((sdErr = DNSServiceProcessResult(DNSSDRef)) != kDNSServiceErr_NoError)
+  {
+    cupsdLogMessage(CUPSD_LOG_ERROR,
+                    "DNS Service Discovery registration error %d!",
+                   sdErr);
+    dnssdStop();
   }
 }
-#endif /* HAVE_OPENLDAP */
+#endif /* HAVE_DNSSD */
 
 
-#ifdef HAVE_LIBSLP
 /*
- * 'send_slp_browse()' - Register the specified printer with SLP.
+ * 'get_auth_info_required()' - Get the auth-info-required value to advertise.
  */
 
-static void
-send_slp_browse(cupsd_printer_t *p)    /* I - Printer to register */
+static char *                          /* O - String or NULL if none */
+get_auth_info_required(
+    cupsd_printer_t *p,                        /* I - Printer */
+    char            *buffer,           /* I - Value buffer */
+    size_t          bufsize)           /* I - Size of value buffer */
 {
-  char         srvurl[HTTP_MAX_URI],   /* Printer service URI */
-               attrs[8192],            /* Printer attributes */
-               finishings[1024],       /* Finishings to support */
-               make_model[IPP_MAX_NAME * 2],
-                                       /* Make and model, quoted */
-               location[IPP_MAX_NAME * 2],
-                                       /* Location, quoted */
-               info[IPP_MAX_NAME * 2], /* Info, quoted */
-               *src,                   /* Pointer to original string */
-               *dst;                   /* Pointer to destination string */
-  ipp_attribute_t *authentication;     /* uri-authentication-supported value */
-  SLPError     error;                  /* SLP error, if any */
+  cupsd_location_t *auth;              /* Pointer to authentication element */
+  char         resource[1024];         /* Printer/class resource path */
 
 
-  cupsdLogMessage(CUPSD_LOG_DEBUG, "send_slp_browse(%p = \"%s\")", p,
-                  p->name);
-
  /*
-  * Make the SLP service URL that conforms to the IANA 
-  * 'printer:' template.
+  * If auth-info-required is set for this printer, return that...
   */
 
-  snprintf(srvurl, sizeof(srvurl), SLP_CUPS_SRVTYPE ":%s", p->uri);
+  if (p->num_auth_info_required > 0 && strcmp(p->auth_info_required[0], "none"))
+  {
+    int                i;                      /* Looping var */
+    char       *bufptr;                /* Pointer into buffer */
 
-  cupsdLogMessage(CUPSD_LOG_DEBUG2, "Service URL = \"%s\"", srvurl);
+    for (i = 0, bufptr = buffer; i < p->num_auth_info_required; i ++)
+    {
+      if (bufptr >= (buffer + bufsize - 2))
+       break;
+
+      if (i)
+       *bufptr++ = ',';
+
+      strlcpy(bufptr, p->auth_info_required[i], bufsize - (bufptr - buffer));
+      bufptr += strlen(bufptr);
+    }
+
+    return (buffer);
+  }
 
  /*
-  * Figure out the finishings string...
+  * Figure out the authentication data requirements to advertise...
   */
 
-  if (p->type & CUPS_PRINTER_STAPLE)
-    strcpy(finishings, "staple");
+  if (p->type & CUPS_PRINTER_CLASS)
+    snprintf(resource, sizeof(resource), "/classes/%s", p->name);
   else
-    finishings[0] = '\0';
+    snprintf(resource, sizeof(resource), "/printers/%s", p->name);
 
-  if (p->type & CUPS_PRINTER_BIND)
-  {
-    if (finishings[0])
-      strlcat(finishings, ",bind", sizeof(finishings));
-    else
-      strcpy(finishings, "bind");
-  }
+  if ((auth = cupsdFindBest(resource, HTTP_POST)) == NULL ||
+      auth->type == CUPSD_AUTH_NONE)
+    auth = cupsdFindPolicyOp(p->op_policy_ptr, IPP_PRINT_JOB);
 
-  if (p->type & CUPS_PRINTER_PUNCH)
+  if (auth)
   {
-    if (finishings[0])
-      strlcat(finishings, ",punch", sizeof(finishings));
-    else
-      strcpy(finishings, "punch");
-  }
+    int        auth_type;                      /* Authentication type */
 
-  if (p->type & CUPS_PRINTER_COVER)
-  {
-    if (finishings[0])
-      strlcat(finishings, ",cover", sizeof(finishings));
-    else
-      strcpy(finishings, "cover");
-  }
+    if ((auth_type = auth->type) == CUPSD_AUTH_DEFAULT)
+      auth_type = DefaultAuthType;
 
-  if (p->type & CUPS_PRINTER_SORT)
-  {
-    if (finishings[0])
-      strlcat(finishings, ",sort", sizeof(finishings));
-    else
-      strcpy(finishings, "sort");
-  }
+    switch (auth_type)
+    {
+      case CUPSD_AUTH_NONE :
+          return (NULL);
 
-  if (!finishings[0])
+      case CUPSD_AUTH_NEGOTIATE :
+         strlcpy(buffer, "negotiate", bufsize);
+         break;
+
+      default :
+         strlcpy(buffer, "username,password", bufsize);
+         break;
+    }
+
+    return (buffer);
+  }
+
+  return ("none");
+}
+
+
+#ifdef __APPLE__
+/*
+ * 'get_hostconfig()' - Get an /etc/hostconfig service setting.
+ */
+
+static int                             /* O - 1 for YES or AUTOMATIC, 0 for NO */
+get_hostconfig(const char *name)       /* I - Name of service */
+{
+  cups_file_t  *fp;                    /* Hostconfig file */
+  char         line[1024],             /* Line from file */
+               *ptr;                   /* Pointer to value */
+  int          state = 1;              /* State of service */
+
+
+ /*
+  * Try opening the /etc/hostconfig file; if we can't open it, assume that
+  * the service is enabled/auto.
+  */
+
+  if ((fp = cupsFileOpen("/etc/hostconfig", "r")) != NULL)
+  {
+   /*
+    * Read lines from the file until we find the service...
+    */
+
+    while (cupsFileGets(fp, line, sizeof(line)))
+    {
+      if (line[0] == '#' || (ptr = strchr(line, '=')) == NULL)
+        continue;
+
+      *ptr++ = '\0';
+
+      if (!strcasecmp(line, name))
+      {
+       /*
+        * Found the service, see if it is set to "-NO-"...
+       */
+
+       if (!strncasecmp(ptr, "-NO-", 4))
+         state = 0;
+        break;
+      }
+    }
+
+    cupsFileClose(fp);
+  }
+
+  return (state);
+}
+#endif /* __APPLE__ */
+
+
+/*
+ * 'is_local_queue()' - Determine whether the URI points at a local queue.
+ */
+
+static int                             /* O - 1 = local, 0 = remote, -1 = bad URI */
+is_local_queue(const char *uri,                /* I - Printer URI */
+               char       *host,       /* O - Host string */
+              int        hostlen,      /* I - Length of host buffer */
+               char       *resource,   /* O - Resource string */
+              int        resourcelen)  /* I - Length of resource buffer */
+{
+  char         scheme[32],             /* Scheme portion of URI */
+               username[HTTP_MAX_URI]; /* Username portion of URI */
+  int          port;                   /* Port portion of URI */
+  cupsd_netif_t        *iface;                 /* Network interface */
+
+
+ /*
+  * Pull the URI apart to see if this is a local or remote printer...
+  */
+
+  if (httpSeparateURI(HTTP_URI_CODING_ALL, uri, scheme, sizeof(scheme),
+                      username, sizeof(username), host, hostlen, &port,
+                     resource, resourcelen) < HTTP_URI_OK)
+    return (-1);
+
+  DEBUG_printf(("host=\"%s\", ServerName=\"%s\"\n", host, ServerName));
+
+ /*
+  * Check for local server addresses...
+  */
+
+  if (!strcasecmp(host, ServerName) && port == LocalPort)
+    return (1);
+
+  cupsdNetIFUpdate();
+
+  for (iface = (cupsd_netif_t *)cupsArrayFirst(NetIFList);
+       iface;
+       iface = (cupsd_netif_t *)cupsArrayNext(NetIFList))
+    if (!strcasecmp(host, iface->hostname) && port == iface->port)
+      return (1);
+
+ /*
+  * If we get here, the printer is remote...
+  */
+
+  return (0);
+}
+
+
+/*
+ * 'process_browse_data()' - Process new browse data.
+ */
+
+static void
+process_browse_data(
+    const char    *uri,                        /* I - URI of printer/class */
+    const char    *host,               /* I - Hostname */
+    const char    *resource,           /* I - Resource path */
+    cups_ptype_t  type,                        /* I - Printer type */
+    ipp_pstate_t  state,               /* I - Printer state */
+    const char    *location,           /* I - Printer location */
+    const char    *info,               /* I - Printer information */
+    const char    *make_model,         /* I - Printer make and model */
+    int                  num_attrs,            /* I - Number of attributes */
+    cups_option_t *attrs)              /* I - Attributes */
+{
+  int          i;                      /* Looping var */
+  int          update;                 /* Update printer attributes? */
+  char         finaluri[HTTP_MAX_URI], /* Final URI for printer */
+               name[IPP_MAX_NAME],     /* Name of printer */
+               newname[IPP_MAX_NAME],  /* New name of printer */
+               *hptr,                  /* Pointer into hostname */
+               *sptr;                  /* Pointer into ServerName */
+  const char   *shortname;             /* Short queue name (queue) */
+  char         local_make_model[IPP_MAX_NAME];
+                                       /* Local make and model */
+  cupsd_printer_t *p;                  /* Printer information */
+  const char   *ipp_options,           /* ipp-options value */
+               *lease_duration,        /* lease-duration value */
+               *uuid;                  /* uuid value */
+  int          is_class;               /* Is this queue a class? */
+
+
+  cupsdLogMessage(CUPSD_LOG_DEBUG2,
+                  "process_browse_data(uri=\"%s\", host=\"%s\", "
+                 "resource=\"%s\", type=%x, state=%d, location=\"%s\", "
+                 "info=\"%s\", make_model=\"%s\", num_attrs=%d, attrs=%p)",
+                 uri, host, resource, type, state,
+                 location ? location : "(nil)", info ? info : "(nil)",
+                 make_model ? make_model : "(nil)", num_attrs, attrs);
+
+ /*
+  * Determine if the URI contains any illegal characters in it...
+  */
+
+  if (strncmp(uri, "ipp://", 6) || !host[0] ||
+      (strncmp(resource, "/printers/", 10) &&
+       strncmp(resource, "/classes/", 9)))
+  {
+    cupsdLogMessage(CUPSD_LOG_ERROR, "Bad printer URI in browse data: %s", uri);
+    return;
+  }
+
+  if (strchr(resource, '?') ||
+      (!strncmp(resource, "/printers/", 10) && strchr(resource + 10, '/')) ||
+      (!strncmp(resource, "/classes/", 9) && strchr(resource + 9, '/')))
+  {
+    cupsdLogMessage(CUPSD_LOG_ERROR, "Bad resource in browse data: %s",
+                    resource);
+    return;
+  }
+
+ /*
+  * OK, this isn't a local printer; add any remote options...
+  */
+
+  ipp_options = cupsGetOption("ipp-options", num_attrs, attrs);
+
+  if (BrowseRemoteOptions)
+  {
+    if (BrowseRemoteOptions[0] == '?')
+    {
+     /*
+      * Override server-supplied options...
+      */
+
+      snprintf(finaluri, sizeof(finaluri), "%s%s", uri, BrowseRemoteOptions);
+    }
+    else if (ipp_options)
+    {
+     /*
+      * Combine the server and local options...
+      */
+
+      snprintf(finaluri, sizeof(finaluri), "%s?%s+%s", uri, ipp_options,
+               BrowseRemoteOptions);
+    }
+    else
+    {
+     /*
+      * Just use the local options...
+      */
+
+      snprintf(finaluri, sizeof(finaluri), "%s?%s", uri, BrowseRemoteOptions);
+    }
+
+    uri = finaluri;
+  }
+  else if (ipp_options)
+  {
+   /*
+    * Just use the server-supplied options...
+    */
+
+    snprintf(finaluri, sizeof(finaluri), "%s?%s", uri, ipp_options);
+    uri = finaluri;
+  }
+
+ /*
+  * See if we already have it listed in the Printers list, and add it if not...
+  */
+
+  type     |= CUPS_PRINTER_REMOTE | CUPS_PRINTER_DISCOVERED;
+  type     &= ~CUPS_PRINTER_IMPLICIT;
+  update   = 0;
+  hptr     = strchr(host, '.');
+  sptr     = strchr(ServerName, '.');
+  is_class = type & CUPS_PRINTER_CLASS;
+  uuid     = cupsGetOption("uuid", num_attrs, attrs);
+
+  if (!ServerNameIsIP && sptr != NULL && hptr != NULL)
+  {
+   /*
+    * Strip the common domain name components...
+    */
+
+    while (hptr != NULL)
+    {
+      if (!strcasecmp(hptr, sptr))
+      {
+        *hptr = '\0';
+       break;
+      }
+      else
+        hptr = strchr(hptr + 1, '.');
+    }
+  }
+
+  if (is_class)
+  {
+   /*
+    * Remote destination is a class...
+    */
+
+    if (!strncmp(resource, "/classes/", 9))
+      snprintf(name, sizeof(name), "%s@%s", resource + 9, host);
+    else
+      return;
+
+    shortname = resource + 9;
+  }
+  else
+  {
+   /*
+    * Remote destination is a printer...
+    */
+
+    if (!strncmp(resource, "/printers/", 10))
+      snprintf(name, sizeof(name), "%s@%s", resource + 10, host);
+    else
+      return;
+
+    shortname = resource + 10;
+  }
+
+  if (hptr && !*hptr)
+    *hptr = '.';                       /* Resource FQDN */
+
+  if ((p = cupsdFindDest(name)) == NULL && BrowseShortNames)
+  {
+   /*
+    * Long name doesn't exist, try short name...
+    */
+
+    cupsdLogMessage(CUPSD_LOG_DEBUG, "process_browse_data: %s not found...",
+                    name);
+
+    if ((p = cupsdFindDest(shortname)) == NULL)
+    {
+     /*
+      * Short name doesn't exist, use it for this shared queue.
+      */
+
+      cupsdLogMessage(CUPSD_LOG_DEBUG2, "process_browse_data: %s not found...",
+                     shortname);
+      strlcpy(name, shortname, sizeof(name));
+    }
+    else
+    {
+     /*
+      * Short name exists...
+      */
+
+      cupsdLogMessage(CUPSD_LOG_DEBUG2,
+                      "process_browse_data: %s found, type=%x, hostname=%s...",
+                     shortname, p->type, p->hostname ? p->hostname : "(nil)");
+
+      if (p->type & CUPS_PRINTER_IMPLICIT)
+        p = NULL;                      /* Don't replace implicit classes */
+      else if (p->hostname && strcasecmp(p->hostname, host))
+      {
+       /*
+       * Short name exists but is for a different host.  If this is a remote
+       * queue, rename it and use the long name...
+       */
+
+       if (p->type & CUPS_PRINTER_REMOTE)
+       {
+         cupsdLogMessage(CUPSD_LOG_DEBUG,
+                         "Renamed remote %s \"%s\" to \"%s@%s\"...",
+                         is_class ? "class" : "printer", p->name, p->name,
+                         p->hostname);
+         cupsdAddEvent(CUPSD_EVENT_PRINTER_DELETED, p, NULL,
+                       "%s \'%s\' deleted by directory services.",
+                       is_class ? "Class" : "Printer", p->name);
+
+         snprintf(newname, sizeof(newname), "%s@%s", p->name, p->hostname);
+         cupsdRenamePrinter(p, newname);
+
+         cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED, p, NULL,
+                       "%s \'%s\' added by directory services.",
+                       is_class ? "Class" : "Printer", p->name);
+       }
+
+       /*
+        * Force creation with long name...
+       */
+
+       p = NULL;
+      }
+    }
+  }
+  else if (p)
+    cupsdLogMessage(CUPSD_LOG_DEBUG2,
+                   "process_browse_data: %s found, type=%x, hostname=%s...",
+                   name, p->type, p->hostname ? p->hostname : "(nil)");
+
+  if (!p)
+  {
+   /*
+    * Queue doesn't exist; add it...
+    */
+
+    if (is_class)
+      p = cupsdAddClass(name);
+    else
+      p = cupsdAddPrinter(name);
+
+    if (!p)
+      return;
+
+    cupsdClearString(&(p->hostname));
+
+    cupsdLogMessage(CUPSD_LOG_DEBUG, "Added remote %s \"%s\"...",
+                    is_class ? "class" : "printer", name);
+
+    cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED, p, NULL,
+                 "%s \'%s\' added by directory services.",
+                 is_class ? "Class" : "Printer", name);
+
+   /*
+    * Force the URI to point to the real server...
+    */
+
+    p->type      = type & ~CUPS_PRINTER_REJECTING;
+    p->accepting = 1;
+
+    cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP);
+  }
+
+  if (!p->hostname)
+  {
+   /*
+    * Hostname not set, so this must be a cached remote printer
+    * that was created for a pending print job...
+    */
+
+    cupsdSetString(&p->hostname, host);
+    cupsdSetString(&p->uri, uri);
+    cupsdSetString(&p->device_uri, uri);
+    update = 1;
+
+    cupsdMarkDirty(CUPSD_DIRTY_REMOTE);
+  }
+
+ /*
+  * Update the state...
+  */
+
+  p->state       = state;
+  p->browse_time = time(NULL);
+
+  if ((lease_duration = cupsGetOption("lease-duration", num_attrs,
+                                      attrs)) != NULL)
+  {
+   /*
+    * Grab the lease-duration for the browse data; anything less then 1
+    * second or more than 1 week gets the default BrowseTimeout...
+    */
+
+    i = atoi(lease_duration);
+    if (i < 1 || i > 604800)
+      i = BrowseTimeout;
+
+    p->browse_expire = p->browse_time + i;
+  }
+  else
+    p->browse_expire = p->browse_time + BrowseTimeout;
+
+  if (type & CUPS_PRINTER_REJECTING)
+  {
+    type &= ~CUPS_PRINTER_REJECTING;
+
+    if (p->accepting)
+    {
+      update       = 1;
+      p->accepting = 0;
+    }
+  }
+  else if (!p->accepting)
+  {
+    update       = 1;
+    p->accepting = 1;
+  }
+
+  if (p->type != type)
+  {
+    p->type = type;
+    update  = 1;
+  }
+
+  if (uuid && strcmp(p->uuid, uuid))
+  {
+    cupsdSetString(&p->uuid, uuid);
+    update = 1;
+  }
+
+  if (location && (!p->location || strcmp(p->location, location)))
+  {
+    cupsdSetString(&p->location, location);
+    update = 1;
+  }
+
+  if (info && (!p->info || strcmp(p->info, info)))
+  {
+    cupsdSetString(&p->info, info);
+    update = 1;
+
+    cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP | CUPSD_DIRTY_REMOTE);
+  }
+
+  if (!make_model || !make_model[0])
+  {
+    if (is_class)
+      snprintf(local_make_model, sizeof(local_make_model),
+               "Remote Class on %s", host);
+    else
+      snprintf(local_make_model, sizeof(local_make_model),
+               "Remote Printer on %s", host);
+  }
+  else
+    snprintf(local_make_model, sizeof(local_make_model),
+             "%s on %s", make_model, host);
+
+  if (!p->make_model || strcmp(p->make_model, local_make_model))
+  {
+    cupsdSetString(&p->make_model, local_make_model);
+    update = 1;
+  }
+
+  if (p->num_options)
+  {
+    if (!update && !(type & CUPS_PRINTER_DELETE))
+    {
+     /*
+      * See if we need to update the attributes...
+      */
+
+      if (p->num_options != num_attrs)
+       update = 1;
+      else
+      {
+       for (i = 0; i < num_attrs; i ++)
+          if (strcmp(attrs[i].name, p->options[i].name) ||
+             (!attrs[i].value != !p->options[i].value) ||
+             (attrs[i].value && strcmp(attrs[i].value, p->options[i].value)))
+          {
+           update = 1;
+           break;
+          }
+      }
+    }
+
+   /*
+    * Free the old options...
+    */
+
+    cupsFreeOptions(p->num_options, p->options);
+  }
+
+  p->num_options = num_attrs;
+  p->options     = attrs;
+
+  if (type & CUPS_PRINTER_DELETE)
+  {
+    cupsdAddEvent(CUPSD_EVENT_PRINTER_DELETED, p, NULL,
+                  "%s \'%s\' deleted by directory services.",
+                 is_class ? "Class" : "Printer", p->name);
+
+    cupsdExpireSubscriptions(p, NULL);
+    cupsdDeletePrinter(p, 1);
+    cupsdUpdateImplicitClasses();
+    cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP | CUPSD_DIRTY_REMOTE);
+  }
+  else if (update)
+  {
+    cupsdSetPrinterAttrs(p);
+    cupsdUpdateImplicitClasses();
+  }
+
+ /*
+  * See if we have a default printer...  If not, make the first network
+  * default printer the default.
+  */
+
+  if (DefaultPrinter == NULL && Printers != NULL && UseNetworkDefault)
+  {
+   /*
+    * Find the first network default printer and use it...
+    */
+
+    for (p = (cupsd_printer_t *)cupsArrayFirst(Printers);
+         p;
+        p = (cupsd_printer_t *)cupsArrayNext(Printers))
+      if (p->type & CUPS_PRINTER_DEFAULT)
+      {
+        DefaultPrinter = p;
+        cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP | CUPSD_DIRTY_REMOTE);
+       break;
+      }
+  }
+
+ /*
+  * Do auto-classing if needed...
+  */
+
+  process_implicit_classes();
+}
+
+
+/*
+ * 'process_implicit_classes()' - Create/update implicit classes as needed.
+ */
+
+static void
+process_implicit_classes(void)
+{
+  int          i;                      /* Looping var */
+  int          update;                 /* Update printer attributes? */
+  char         name[IPP_MAX_NAME],     /* Name of printer */
+               *hptr;                  /* Pointer into hostname */
+  cupsd_printer_t *p,                  /* Printer information */
+               *pclass,                /* Printer class */
+               *first;                 /* First printer in class */
+  int          offset,                 /* Offset of name */
+               len;                    /* Length of name */
+
+
+  if (!ImplicitClasses || !Printers)
+    return;
+
+ /*
+  * Loop through all available printers and create classes as needed...
+  */
+
+  for (p = (cupsd_printer_t *)cupsArrayFirst(Printers), len = 0, offset = 0,
+           update = 0, pclass = NULL, first = NULL;
+       p != NULL;
+       p = (cupsd_printer_t *)cupsArrayNext(Printers))
+  {
+   /*
+    * Skip implicit classes...
+    */
+
+    if (p->type & CUPS_PRINTER_IMPLICIT)
+    {
+      len = 0;
+      continue;
+    }
+
+   /*
+    * If len == 0, get the length of this printer name up to the "@"
+    * sign (if any).
+    */
+
+    cupsArraySave(Printers);
+
+    if (len > 0 &&
+       !strncasecmp(p->name, name + offset, len) &&
+       (p->name[len] == '\0' || p->name[len] == '@'))
+    {
+     /*
+      * We have more than one printer with the same name; see if
+      * we have a class, and if this printer is a member...
+      */
+
+      if (pclass && strcasecmp(pclass->name, name))
+      {
+       if (update)
+         cupsdSetPrinterAttrs(pclass);
+
+       update = 0;
+       pclass = NULL;
+      }
+
+      if (!pclass && (pclass = cupsdFindDest(name)) == NULL)
+      {
+       /*
+       * Need to add the class...
+       */
+
+       pclass = cupsdAddPrinter(name);
+       cupsArrayAdd(ImplicitPrinters, pclass);
+
+       pclass->type      |= CUPS_PRINTER_IMPLICIT;
+       pclass->accepting = 1;
+       pclass->state     = IPP_PRINTER_IDLE;
+
+        cupsdSetString(&pclass->location, p->location);
+        cupsdSetString(&pclass->info, p->info);
+
+        cupsdSetString(&pclass->job_sheets[0], p->job_sheets[0]);
+        cupsdSetString(&pclass->job_sheets[1], p->job_sheets[1]);
+
+        update = 1;
+
+       cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP | CUPSD_DIRTY_REMOTE);
+
+        cupsdLogMessage(CUPSD_LOG_DEBUG, "Added implicit class \"%s\"...",
+                       name);
+       cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED, p, NULL,
+                      "Implicit class \'%s\' added by directory services.",
+                     name);
+      }
+
+      if (first != NULL)
+      {
+        for (i = 0; i < pclass->num_printers; i ++)
+         if (pclass->printers[i] == first)
+           break;
+
+        if (i >= pclass->num_printers)
+       {
+         first->in_implicit_class = 1;
+         cupsdAddPrinterToClass(pclass, first);
+        }
+
+       first = NULL;
+      }
+
+      for (i = 0; i < pclass->num_printers; i ++)
+       if (pclass->printers[i] == p)
+         break;
+
+      if (i >= pclass->num_printers)
+      {
+       p->in_implicit_class = 1;
+       cupsdAddPrinterToClass(pclass, p);
+       update = 1;
+      }
+    }
+    else
+    {
+     /*
+      * First time around; just get name length and mark it as first
+      * in the list...
+      */
+
+      if ((hptr = strchr(p->name, '@')) != NULL)
+       len = hptr - p->name;
+      else
+       len = strlen(p->name);
+
+      if (len >= sizeof(name))
+      {
+       /*
+       * If the printer name length somehow is greater than we normally allow,
+       * skip this printer...
+       */
+
+       len = 0;
+       cupsArrayRestore(Printers);
+       continue;
+      }
+
+      strncpy(name, p->name, len);
+      name[len] = '\0';
+      offset    = 0;
+
+      if ((first = (hptr ? cupsdFindDest(name) : p)) != NULL &&
+         !(first->type & CUPS_PRINTER_IMPLICIT))
+      {
+       /*
+       * Can't use same name as a local printer; add "Any" to the
+       * front of the name, unless we have explicitly disabled
+       * the "ImplicitAnyClasses"...
+       */
+
+        if (ImplicitAnyClasses && len < (sizeof(name) - 4))
+       {
+        /*
+         * Add "Any" to the class name...
+         */
+
+          strcpy(name, "Any");
+          strncpy(name + 3, p->name, len);
+         name[len + 3] = '\0';
+         offset        = 3;
+       }
+       else
+       {
+        /*
+         * Don't create an implicit class if we have a local printer
+         * with the same name...
+         */
+
+         len = 0;
+          cupsArrayRestore(Printers);
+         continue;
+       }
+      }
+
+      first = p;
+    }
+
+    cupsArrayRestore(Printers);
+  }
+
+ /*
+  * Update the last printer class as needed...
+  */
+
+  if (pclass && update)
+    cupsdSetPrinterAttrs(pclass);
+}
+
+
+/*
+ * 'send_cups_browse()' - Send new browsing information using the CUPS
+ *                        protocol.
+ */
+
+static void
+send_cups_browse(cupsd_printer_t *p)   /* I - Printer to send */
+{
+  int                  i;              /* Looping var */
+  cups_ptype_t         type;           /* Printer type */
+  cupsd_dirsvc_addr_t  *b;             /* Browse address */
+  int                  bytes;          /* Length of packet */
+  char                 packet[1453],   /* Browse data packet */
+                       uri[1024],      /* Printer URI */
+                       location[1024], /* printer-location */
+                       info[1024],     /* printer-info */
+                       make_model[1024],
+                                       /* printer-make-and-model */
+                       air[1024];      /* auth-info-required */
+  cupsd_netif_t                *iface;         /* Network interface */
+
+
+ /*
+  * Figure out the printer type value...
+  */
+
+  type = p->type | CUPS_PRINTER_REMOTE;
+
+  if (!p->accepting)
+    type |= CUPS_PRINTER_REJECTING;
+
+  if (p == DefaultPrinter)
+    type |= CUPS_PRINTER_DEFAULT;
+
+ /*
+  * Remove quotes from printer-info, printer-location, and
+  * printer-make-and-model attributes...
+  */
+
+  dequote(location, p->location, sizeof(location));
+  dequote(info, p->info, sizeof(info));
+
+  if (p->make_model)
+    dequote(make_model, p->make_model, sizeof(make_model));
+  else if (p->type & CUPS_PRINTER_CLASS)
+  {
+    if (p->num_printers > 0 && p->printers[0]->make_model)
+      strlcpy(make_model, p->printers[0]->make_model, sizeof(make_model));
+    else
+      strlcpy(make_model, "Local Printer Class", sizeof(make_model));
+  }
+  else if (p->raw)
+    strlcpy(make_model, "Local Raw Printer", sizeof(make_model));
+  else
+    strlcpy(make_model, "Local System V Printer", sizeof(make_model));
+
+  if (get_auth_info_required(p, packet, sizeof(packet)))
+    snprintf(air, sizeof(air), " auth-info-required=%s", packet);
+  else
+    air[0] = '\0';
+
+ /*
+  * Send a packet to each browse address...
+  */
+
+  for (i = NumBrowsers, b = Browsers; i > 0; i --, b ++)
+    if (b->iface[0])
+    {
+     /*
+      * Send the browse packet to one or more interfaces...
+      */
+
+      if (!strcmp(b->iface, "*"))
+      {
+       /*
+        * Send to all local interfaces...
+       */
+
+        cupsdNetIFUpdate();
+
+       for (iface = (cupsd_netif_t *)cupsArrayFirst(NetIFList);
+            iface;
+            iface = (cupsd_netif_t *)cupsArrayNext(NetIFList))
+       {
+        /*
+         * Only send to local, IPv4 interfaces...
+         */
+
+         if (!iface->is_local || !iface->port ||
+             iface->address.addr.sa_family != AF_INET)
+           continue;
+
+         httpAssembleURIf(HTTP_URI_CODING_ALL, uri, sizeof(uri), "ipp", NULL,
+                          iface->hostname, iface->port,
+                          (p->type & CUPS_PRINTER_CLASS) ? "/classes/%s" :
+                                                           "/printers/%s",
+                          p->name);
+         snprintf(packet, sizeof(packet),
+                  "%x %x %s \"%s\" \"%s\" \"%s\" %s%s uuid=%s\n",
+                  type, p->state, uri, location, info, make_model,
+                  p->browse_attrs ? p->browse_attrs : "", air, p->uuid);
+
+         bytes = strlen(packet);
+
+         cupsdLogMessage(CUPSD_LOG_DEBUG2,
+                         "cupsdSendBrowseList: (%d bytes to \"%s\") %s", bytes,
+                         iface->name, packet);
+
+          iface->broadcast.ipv4.sin_port = htons(BrowsePort);
+
+         sendto(BrowseSocket, packet, bytes, 0,
+                (struct sockaddr *)&(iface->broadcast),
+                httpAddrLength(&(iface->broadcast)));
+        }
+      }
+      else if ((iface = cupsdNetIFFind(b->iface)) != NULL)
+      {
+       /*
+        * Send to the named interface using the IPv4 address...
+       */
+
+        while (iface)
+         if (strcmp(b->iface, iface->name))
+         {
+           iface = NULL;
+           break;
+         }
+         else if (iface->address.addr.sa_family == AF_INET && iface->port)
+           break;
+         else
+            iface = (cupsd_netif_t *)cupsArrayNext(NetIFList);
+
+        if (iface)
+       {
+         httpAssembleURIf(HTTP_URI_CODING_ALL, uri, sizeof(uri), "ipp", NULL,
+                          iface->hostname, iface->port,
+                          (p->type & CUPS_PRINTER_CLASS) ? "/classes/%s" :
+                                                           "/printers/%s",
+                          p->name);
+         snprintf(packet, sizeof(packet),
+                  "%x %x %s \"%s\" \"%s\" \"%s\" %s%s uuid=%s\n",
+                  type, p->state, uri, location, info, make_model,
+                  p->browse_attrs ? p->browse_attrs : "", air, p->uuid);
+
+         bytes = strlen(packet);
+
+         cupsdLogMessage(CUPSD_LOG_DEBUG2,
+                         "cupsdSendBrowseList: (%d bytes to \"%s\") %s", bytes,
+                         iface->name, packet);
+
+          iface->broadcast.ipv4.sin_port = htons(BrowsePort);
+
+         sendto(BrowseSocket, packet, bytes, 0,
+                (struct sockaddr *)&(iface->broadcast),
+                httpAddrLength(&(iface->broadcast)));
+        }
+      }
+    }
+    else
+    {
+     /*
+      * Send the browse packet to the indicated address using
+      * the default server name...
+      */
+
+      snprintf(packet, sizeof(packet),
+               "%x %x %s \"%s\" \"%s\" \"%s\" %s%s uuid=%s\n",
+                      type, p->state, p->uri, location, info, make_model,
+              p->browse_attrs ? p->browse_attrs : "", air, p->uuid);
+
+      bytes = strlen(packet);
+      cupsdLogMessage(CUPSD_LOG_DEBUG2,
+                      "cupsdSendBrowseList: (%d bytes) %s", bytes, packet);
+
+      if (sendto(BrowseSocket, packet, bytes, 0,
+                (struct sockaddr *)&(b->to),
+                httpAddrLength(&(b->to))) <= 0)
+      {
+       /*
+        * Unable to send browse packet, so remove this address from the
+       * list...
+       */
+
+       cupsdLogMessage(CUPSD_LOG_ERROR,
+                       "cupsdSendBrowseList: sendto failed for browser "
+                       "%d - %s.",
+                       (int)(b - Browsers + 1), strerror(errno));
+
+        if (i > 1)
+         memmove(b, b + 1, (i - 1) * sizeof(cupsd_dirsvc_addr_t));
+
+       b --;
+       NumBrowsers --;
+      }
+    }
+}
+
+
+#ifdef HAVE_LDAP
+/*
+ * 'ldap_search_rec()' - LDAP Search with reconnect
+ */
+
+static int                             /* O - Return code */
+ldap_search_rec(LDAP        *ld,       /* I - LDAP handler */
+                char        *base,     /* I - Base dn */
+                int         scope,     /* I - LDAP search scope */
+                char        *filter,   /* I - Filter string */
+                char        *attrs[],  /* I - Requested attributes */
+                int         attrsonly, /* I - Return only attributes? */
+                LDAPMessage **res)     /* I - LDAP handler */
+{
+  int  rc;                             /* Return code */
+  LDAP  *ldr;                          /* LDAP handler after reconnect */
+
+
+#  if defined(HAVE_OPENLDAP) && LDAP_API_VERSION > 3000
+  rc = ldap_search_ext_s(ld, base, scope, filter, attrs, attrsonly, NULL, NULL,
+                         NULL, LDAP_NO_LIMIT, res);
+#  else
+  rc = ldap_search_s(ld, base, scope, filter, attrs, attrsonly, res);
+#  endif /* defined(HAVE_OPENLDAP) && LDAP_API_VERSION > 3000 */
+
+ /*
+  * If we have a connection problem try again...
+  */
+
+  if (rc == LDAP_SERVER_DOWN || rc == LDAP_CONNECT_ERROR)
+  {
+    cupsdLogMessage(CUPSD_LOG_ERROR,
+                    "LDAP search failed with status %d: %s",
+                     rc, ldap_err2string(rc));
+    cupsdLogMessage(CUPSD_LOG_INFO,
+                    "We try the LDAP search once again after reconnecting to "
+                   "the server");
+    ldap_freeres(*res);
+    ldr = ldap_reconnect();
+
+#  if defined(HAVE_OPENLDAP) && LDAP_API_VERSION > 3000
+    rc = ldap_search_ext_s(ldr, base, scope, filter, attrs, attrsonly, NULL,
+                           NULL, NULL, LDAP_NO_LIMIT, res);
+#  else
+    rc = ldap_search_s(ldr, base, scope, filter, attrs, attrsonly, res);
+#  endif /* defined(HAVE_OPENLDAP) && LDAP_API_VERSION > 3000 */
+  }
+
+  if (rc == LDAP_NO_SUCH_OBJECT)
+    cupsdLogMessage(CUPSD_LOG_DEBUG,
+                    "ldap_search_rec: LDAP entry/object not found");
+  else if (rc != LDAP_SUCCESS)
+    cupsdLogMessage(CUPSD_LOG_ERROR,
+                    "ldap_search_rec: LDAP search failed with status %d: %s",
+                     rc, ldap_err2string(rc));
+
+  if (rc != LDAP_SUCCESS)
+    ldap_freeres(*res);
+
+  return (rc);
+}
+
+
+/*
+ * 'ldap_freeres()' - Free LDAPMessage
+ */
+
+static void
+ldap_freeres(LDAPMessage *entry)       /* I - LDAP handler */
+{
+  int  rc;                             /* Return value */
+
+
+  rc = ldap_msgfree(entry);
+  if (rc == -1)
+    cupsdLogMessage(CUPSD_LOG_WARN, "Can't free LDAPMessage!");
+  else if (rc == 0)
+    cupsdLogMessage(CUPSD_LOG_DEBUG2, "Freeing LDAPMessage was unnecessary");
+}
+
+
+/*
+ * 'ldap_getval_char()' - Get first LDAP value and convert to string
+ */
+
+static int                             /* O - Return code */
+ldap_getval_firststring(
+    LDAP          *ld,                 /* I - LDAP handler */
+    LDAPMessage   *entry,              /* I - LDAP message or search result */
+    char          *attr,               /* I - the wanted attribute  */
+    char          *retval,             /* O - String to return */
+    unsigned long maxsize)             /* I - Max string size */
+{
+  char                 *dn;            /* LDAP DN */
+  int                  rc = 0;         /* Return code */
+#  if defined(HAVE_OPENLDAP) && LDAP_API_VERSION > 3000
+  struct berval                **bval;         /* LDAP value array */
+  unsigned long                size;           /* String size */
+
+
+ /*
+  * Get value from LDAPMessage...
+  */
+
+  if ((bval = ldap_get_values_len(ld, entry, attr)) == NULL)
+  {
+    rc = -1;
+    dn = ldap_get_dn(ld, entry);
+    cupsdLogMessage(CUPSD_LOG_WARN,
+                    "Failed to get LDAP value %s for %s!",
+                    attr, dn);
+    ldap_memfree(dn);
+  }
+  else
+  {
+   /*
+    * Check size and copy value into our string...
+    */
+
+    size = maxsize;
+    if (size < (bval[0]->bv_len + 1))
+    {
+      rc = -1;
+      dn = ldap_get_dn(ld, entry);
+      cupsdLogMessage(CUPSD_LOG_WARN,
+                      "Attribute %s is too big! (dn: %s)",
+                      attr, dn);
+      ldap_memfree(dn);
+    }
+    else
+      size = bval[0]->bv_len + 1;
+
+    strlcpy(retval, bval[0]->bv_val, size);
+    ldap_value_free_len(bval);
+  }
+#  else
+  char **value;                        /* LDAP value */
+
+ /*
+  * Get value from LDAPMessage...
+  */
+
+  if ((value = (char **)ldap_get_values(ld, entry, attr)) == NULL)
+  {
+    rc = -1;
+    dn = ldap_get_dn(ld, entry);
+    cupsdLogMessage(CUPSD_LOG_WARN, "Failed to get LDAP value %s for %s!",
+                    attr, dn);
+    ldap_memfree(dn);
+  }
+  else
+  {
+    strlcpy(retval, *value, maxsize);
+    ldap_value_free(value);
+  }
+#  endif /* defined(HAVE_OPENLDAP) && LDAP_API_VERSION > 3000 */
+
+  return (rc);
+}
+
+
+/*
+ * 'send_ldap_ou()' - Send LDAP ou registrations.
+ */
+
+static void
+send_ldap_ou(char *ou,                 /* I - Servername/ou to register */
+             char *basedn,             /* I - Our base dn */
+             char *descstring)         /* I - Description for ou */
+{
+  int           i;                      /* Looping var... */
+  LDAPMod       mods[3];                /* The 3 attributes we will be adding */
+  LDAPMod       *pmods[4];              /* Pointers to the 3 attributes + NULL */
+  LDAPMessage   *res,                   /* Search result token */
+               *e;                     /* Current entry from search */
+  int           rc;                     /* LDAP status */
+  int           rcmod;                  /* LDAP status for modifications */
+  char          dn[1024],               /* DN of the organizational unit we are adding */
+                *desc[2],               /* Change records */
+                *ou_value[2];
+  char         old_desc[1024];         /* Old description */
+  static const char * const objectClass_values[] =
+               {                       /* The 2 objectClass's we use in */
+                 "top",                /* our LDAP entries              */
+                 "organizationalUnit",
+                 NULL
+               };
+  static const char * const ou_attrs[] =/* CUPS LDAP attributes */
+               {
+                 "description",
+                 NULL
+               };
+
+
+  cupsdLogMessage(CUPSD_LOG_DEBUG2, "send_ldap_ou: %s", ou);
+
+ /*
+  * Reconnect if LDAP Handle is invalid...
+  */
+
+  if (!BrowseLDAPHandle)
+  {
+    cupsdLogMessage(CUPSD_LOG_DEBUG2,
+                    "send_ldap_ou: LDAP Handle is invalid. Try reconnecting...");
+    ldap_reconnect();
+    return;
+  }
+
+ /*
+  * Prepare ldap search...
+  */
+
+  snprintf(dn, sizeof(dn), "ou=%s, %s", ou, basedn);
+  cupsdLogMessage(CUPSD_LOG_DEBUG2, "send_ldap_ou: dn=\"%s\"", dn);
+
+  ou_value[0] = ou;
+  ou_value[1] = NULL;
+  desc[0]     = descstring;
+  desc[1]     = NULL;
+  
+  mods[0].mod_type   = "ou";
+  mods[0].mod_values = ou_value;
+  mods[1].mod_type   = "description";
+  mods[1].mod_values = desc;
+  mods[2].mod_type   = "objectClass";
+  mods[2].mod_values = (char **)objectClass_values;
+
+  rc = ldap_search_rec(BrowseLDAPHandle, dn, LDAP_SCOPE_BASE, NULL,
+                       (char **)ou_attrs, 0, &res);
+
+ /*
+  * If ldap search was not successfull then exit function...
+  */
+
+  if (rc != LDAP_SUCCESS && rc != LDAP_NO_SUCH_OBJECT)
+    return;
+
+ /*
+  * Check if we need to insert or update the LDAP entry...
+  */
+
+  if (ldap_count_entries(BrowseLDAPHandle, res) > 0 &&
+      rc != LDAP_NO_SUCH_OBJECT)
+  {
+   /*
+    * Printserver has already been registered, check if
+    * modification is required...
+    */
+
+    e = ldap_first_entry(BrowseLDAPHandle, res);
+
+   /*
+    * Get the required values from this entry...
+    */
+
+    if (ldap_getval_firststring(BrowseLDAPHandle, e, "description", old_desc,
+                                sizeof(old_desc)) == -1)
+      old_desc[0] = '\0';
+
+   /*
+    * Check if modification is required...
+    */
+
+    if ( strcmp(desc[0], old_desc) == 0 )
+    {
+     /*
+      * LDAP entry for the printer exists.
+      * Printer has already been registered,
+      * no modifications required...
+      */
+      cupsdLogMessage(CUPSD_LOG_DEBUG2,
+                      "send_ldap_ou: No updates required for %s", ou);
+    }
+    else
+    {
+
+      cupsdLogMessage(CUPSD_LOG_DEBUG2,
+                      "send_ldap_ou: Replace entry for %s", ou);
+
+      for (i = 0; i < 3; i ++)
+      {
+        pmods[i]         = mods + i;
+        pmods[i]->mod_op = LDAP_MOD_REPLACE;
+      }
+      pmods[i] = NULL;
+
+#  if defined(HAVE_OPENLDAP) && LDAP_API_VERSION > 3000
+      if ((rcmod = ldap_modify_ext_s(BrowseLDAPHandle, dn, pmods, NULL,
+                                     NULL)) != LDAP_SUCCESS)
+#  else
+      if ((rcmod = ldap_modify_s(BrowseLDAPHandle, dn, pmods)) != LDAP_SUCCESS)
+#  endif /* defined(HAVE_OPENLDAP) && LDAP_API_VERSION > 3000 */
+      {
+        cupsdLogMessage(CUPSD_LOG_ERROR,
+                        "LDAP modify for %s failed with status %d: %s",
+                        ou, rcmod, ldap_err2string(rcmod));
+        if (rcmod == LDAP_SERVER_DOWN)
+          ldap_reconnect();
+      }
+    }
+  }
+  else
+  {
+   /*
+    * Printserver has never been registered,
+    * add registration...
+    */
+
+    cupsdLogMessage(CUPSD_LOG_DEBUG2,
+                    "send_ldap_ou: Add entry for %s", ou);
+
+    for (i = 0; i < 3; i ++)
+    {
+      pmods[i]         = mods + i;
+      pmods[i]->mod_op = LDAP_MOD_ADD;
+    }
+    pmods[i] = NULL;
+
+#  if defined(HAVE_OPENLDAP) && LDAP_API_VERSION > 3000
+    if ((rcmod = ldap_add_ext_s(BrowseLDAPHandle, dn, pmods, NULL,
+                                NULL)) != LDAP_SUCCESS)
+#  else
+    if ((rcmod = ldap_add_s(BrowseLDAPHandle, dn, pmods)) != LDAP_SUCCESS)
+#  endif /* defined(HAVE_OPENLDAP) && LDAP_API_VERSION > 3000 */
+    {
+      cupsdLogMessage(CUPSD_LOG_ERROR,
+                      "LDAP add for %s failed with status %d: %s",
+                      ou, rcmod, ldap_err2string(rcmod));
+      if (rcmod == LDAP_SERVER_DOWN)
+        ldap_reconnect();
+    }
+  }
+
+  if (rc == LDAP_SUCCESS)
+    ldap_freeres(res);
+}
+
+
+/*
+ * 'send_ldap_browse()' - Send LDAP printer registrations.
+ */
+
+static void
+send_ldap_browse(cupsd_printer_t *p)   /* I - Printer to register */
+{
+  int          i;                      /* Looping var... */
+  LDAPMod      mods[7];                /* The 7 attributes we will be adding */
+  LDAPMod      *pmods[8];              /* Pointers to the 7 attributes + NULL */
+  LDAPMessage  *res,                   /* Search result token */
+               *e;                     /* Current entry from search */
+  char         *cn_value[2],           /* Change records */
+               *uri[2],
+               *info[2],
+               *location[2],
+               *make_model[2],
+               *type[2],
+               typestring[255],        /* String to hold printer-type */
+               dn[1024];               /* DN of the printer we are adding */
+  int          rc;                     /* LDAP status */
+  int          rcmod;                  /* LDAP status for modifications */
+  char         old_uri[HTTP_MAX_URI],  /* Printer URI */
+               old_location[1024],     /* Printer location */
+               old_info[1024],         /* Printer information */
+               old_make_model[1024],   /* Printer make and model */
+               old_type_string[30];    /* Temporary type number */
+  int          old_type;               /* Printer type */
+  static const char * const objectClass_values[] =
+               {                       /* The 3 objectClass's we use in */
+                 "top",                /* our LDAP entries              */
+                 "device",
+                 "cupsPrinter",
+                 NULL
+               };
+
+
+  cupsdLogMessage(CUPSD_LOG_DEBUG2, "send_ldap_browse: %s", p->name);
+
+ /*
+  * Exit function if LDAP updates has been disabled...
+  */
+
+  if (!BrowseLDAPUpdate)
+  {
+    cupsdLogMessage(CUPSD_LOG_DEBUG2,
+                    "send_ldap_browse: Updates temporary disabled; "
+                   "skipping...");
+    return;
+  }
+
+ /*
+  * Reconnect if LDAP Handle is invalid...
+  */
+
+  if (!BrowseLDAPHandle)
+  {
+    cupsdLogMessage(CUPSD_LOG_DEBUG2,
+                    "send_ldap_browse: LDAP Handle is invalid. Try "
+                   "reconnecting...");
+    ldap_reconnect();
+    return;
+  }
+
+ /*
+  * Everything in ldap is ** so we fudge around it...
+  */
+
+  sprintf(typestring, "%u", p->type);
+
+  cn_value[0]   = p->name;
+  cn_value[1]   = NULL;
+  info[0]       = p->info ? p->info : "Unknown";
+  info[1]       = NULL;
+  location[0]   = p->location ? p->location : "Unknown";
+  location[1]   = NULL;
+  make_model[0] = p->make_model ? p->make_model : "Unknown";
+  make_model[1] = NULL;
+  type[0]       = typestring;
+  type[1]       = NULL;
+  uri[0]        = p->uri;
+  uri[1]        = NULL;
+
+ /*
+  * Get ldap entry for printer ...
+  */
+
+  snprintf(dn, sizeof(dn), "cn=%s, ou=%s, %s", p->name, ServerName,
+           BrowseLDAPDN);
+  cupsdLogMessage(CUPSD_LOG_DEBUG2, "send_ldap_browse: dn=\"%s\"", dn);
+
+  rc = ldap_search_rec(BrowseLDAPHandle, dn, LDAP_SCOPE_BASE, NULL,
+                       (char **)ldap_attrs, 0, &res);
+
+ /*
+  * If ldap search was not successfull then exit function
+  * and temporary disable LDAP updates...
+  */
+
+  if (rc != LDAP_SUCCESS && rc != LDAP_NO_SUCH_OBJECT)
+  {
+    if (BrowseLDAPUpdate &&
+        (rc == LDAP_SERVER_DOWN || rc == LDAP_CONNECT_ERROR))
+    {
+      BrowseLDAPUpdate = FALSE;
+      cupsdLogMessage(CUPSD_LOG_INFO,
+                      "LDAP update temporary disabled");
+    }
+
+    return;
+  }
+
+ /*
+  * Fill modification array...
+  */
+
+  mods[0].mod_type   = "cn";
+  mods[0].mod_values = cn_value;
+  mods[1].mod_type   = "printerDescription";
+  mods[1].mod_values = info;
+  mods[2].mod_type   = "printerURI";
+  mods[2].mod_values = uri;
+  mods[3].mod_type   = "printerLocation";
+  mods[3].mod_values = location;
+  mods[4].mod_type   = "printerMakeAndModel";
+  mods[4].mod_values = make_model;
+  mods[5].mod_type   = "printerType";
+  mods[5].mod_values = type;
+  mods[6].mod_type   = "objectClass";
+  mods[6].mod_values = (char **)objectClass_values;
+
+ /*
+  * Check if we need to insert or update the LDAP entry...
+  */
+
+  if (ldap_count_entries(BrowseLDAPHandle, res) > 0 &&
+      rc != LDAP_NO_SUCH_OBJECT)
+  {
+   /*
+    * Printer has already been registered, check if
+    * modification is required...
+    */
+
+    e = ldap_first_entry(BrowseLDAPHandle, res);
+
+   /*
+    * Get the required values from this entry...
+    */
+
+    if (ldap_getval_firststring(BrowseLDAPHandle, e, "printerDescription",
+                                old_info, sizeof(old_info)) == -1)
+      old_info[0] = '\0';
+
+    if (ldap_getval_firststring(BrowseLDAPHandle, e, "printerLocation",
+                                old_location, sizeof(old_location)) == -1)
+      old_info[0] = '\0';
+
+    if (ldap_getval_firststring(BrowseLDAPHandle, e, "printerMakeAndModel",
+                                old_make_model, sizeof(old_make_model)) == -1)
+      old_info[0] = '\0';
+
+    if (ldap_getval_firststring(BrowseLDAPHandle, e, "printerType",
+                                old_type_string, sizeof(old_type_string)) == -1)
+      old_info[0] = '\0';
+
+    old_type = atoi(old_type_string);
+
+    if (ldap_getval_firststring(BrowseLDAPHandle, e, "printerURI", old_uri,
+                                sizeof(old_uri)) == -1)
+      old_info[0] = '\0';
+
+   /*
+    * Check if modification is required...
+    */
+
+    if (!strcmp(info[0], old_info) && !strcmp(uri[0], old_uri) &&
+        !strcmp(location[0], old_location) &&
+       !strcmp(make_model[0], old_make_model) && p->type == old_type)
+    {
+     /*
+      * LDAP entry for the printer exists. Printer has already been registered,
+      * no modifications required...
+      */
+
+      cupsdLogMessage(CUPSD_LOG_DEBUG2,
+                       "send_ldap_browse: No updates required for %s", p->name);
+    }
+    else
+    {
+     /*
+      * LDAP entry for the printer exists.  Printer has already been registered,
+      * modify the current registration...
+      */
+
+      cupsdLogMessage(CUPSD_LOG_DEBUG2,
+                      "send_ldap_browse: Replace entry for %s", p->name);
+
+      for (i = 0; i < 7; i ++)
+      {
+        pmods[i]         = mods + i;
+        pmods[i]->mod_op = LDAP_MOD_REPLACE;
+      }
+      pmods[i] = NULL;
+
+#  if defined(HAVE_OPENLDAP) && LDAP_API_VERSION > 3000
+      if ((rcmod = ldap_modify_ext_s(BrowseLDAPHandle, dn, pmods, NULL,
+                                     NULL)) != LDAP_SUCCESS)
+#  else
+      if ((rcmod = ldap_modify_s(BrowseLDAPHandle, dn, pmods)) != LDAP_SUCCESS)
+#  endif /* defined(HAVE_OPENLDAP) && LDAP_API_VERSION > 3000 */
+      {
+        cupsdLogMessage(CUPSD_LOG_ERROR,
+                        "LDAP modify for %s failed with status %d: %s",
+                        p->name, rcmod, ldap_err2string(rcmod));
+        if (rcmod == LDAP_SERVER_DOWN)
+          ldap_reconnect();
+      }
+    }
+  }
+  else 
+  {
+   /*
+    * No LDAP entry exists for the printer.  Printer has never been registered,
+    * add the current registration...
+    */
+
+    send_ldap_ou(ServerName, BrowseLDAPDN, "CUPS Server");
+
+    cupsdLogMessage(CUPSD_LOG_DEBUG2,
+                    "send_ldap_browse: Add entry for %s", p->name);
+
+    for (i = 0; i < 7; i ++)
+    {
+      pmods[i]         = mods + i;
+      pmods[i]->mod_op = LDAP_MOD_ADD;
+    }
+    pmods[i] = NULL;
+
+#  if defined(HAVE_OPENLDAP) && LDAP_API_VERSION > 3000
+    if ((rcmod = ldap_add_ext_s(BrowseLDAPHandle, dn, pmods, NULL,
+                                NULL)) != LDAP_SUCCESS)
+#  else
+    if ((rcmod = ldap_add_s(BrowseLDAPHandle, dn, pmods)) != LDAP_SUCCESS)
+#  endif /* defined(HAVE_OPENLDAP) && LDAP_API_VERSION > 3000 */
+    {
+      cupsdLogMessage(CUPSD_LOG_ERROR,
+                      "LDAP add for %s failed with status %d: %s",
+                      p->name, rcmod, ldap_err2string(rcmod));
+      if (rcmod == LDAP_SERVER_DOWN)
+        ldap_reconnect();
+    }
+  }
+
+  if (rc == LDAP_SUCCESS)
+    ldap_freeres(res);
+}
+
+
+/*
+ * 'ldap_dereg_printer()' - Delete printer from directory
+ */
+
+static void
+ldap_dereg_printer(cupsd_printer_t *p) /* I - Printer to deregister */
+{
+  char         dn[1024];               /* DN of the printer */
+  int          rc;                     /* LDAP status */
+
+
+  cupsdLogMessage(CUPSD_LOG_DEBUG2, "ldap_dereg_printer: Remove entry for %s",
+                  p->name);
+
+ /*
+  * Reconnect if LDAP Handle is invalid...
+  */
+
+  if (!BrowseLDAPHandle)
+  {
+    ldap_reconnect();
+    return;
+  }
+
+ /*
+  * Get dn for printer and delete LDAP entry...
+  */
+
+  snprintf(dn, sizeof(dn), "cn=%s, ou=%s, %s", p->name, ServerName,
+           BrowseLDAPDN);
+  cupsdLogMessage(CUPSD_LOG_DEBUG2, "ldap_dereg_printer: dn=\"%s\"", dn);
+
+#  if defined(HAVE_OPENLDAP) && LDAP_API_VERSION > 3000
+  if ((rc = ldap_delete_ext_s(BrowseLDAPHandle, dn, NULL,
+                              NULL)) != LDAP_SUCCESS)
+#  else
+  if ((rc = ldap_delete_s(BrowseLDAPHandle, dn)) != LDAP_SUCCESS)
+#  endif /* defined(HAVE_OPENLDAP) && LDAP_API_VERSION > 3000 */
+  {
+    cupsdLogMessage(CUPSD_LOG_WARN,
+                    "LDAP delete for %s failed with status %d: %s",
+                    p->name, rc, ldap_err2string(rc));
+
+   /*
+    * If we had a connection problem (connection timed out, etc.)
+    * we should reconnect and try again to delete the entry...
+    */
+
+    if (rc == LDAP_SERVER_DOWN || rc == LDAP_CONNECT_ERROR)
+    {
+      cupsdLogMessage(CUPSD_LOG_INFO,
+                      "Retry deleting LDAP entry for %s after a reconnect...", p->name);
+      ldap_reconnect();
+
+#  if defined(HAVE_OPENLDAP) && LDAP_API_VERSION > 3000
+      if ((rc = ldap_delete_ext_s(BrowseLDAPHandle, dn, NULL,
+                                  NULL)) != LDAP_SUCCESS)
+#  else
+      if ((rc = ldap_delete_s(BrowseLDAPHandle, dn)) != LDAP_SUCCESS)
+#  endif /* defined(HAVE_OPENLDAP) && LDAP_API_VERSION > 3000 */
+        cupsdLogMessage(CUPSD_LOG_WARN,
+                        "LDAP delete for %s failed with status %d: %s",
+                        p->name, rc, ldap_err2string(rc));
+    }
+  }
+}
+
+
+/*
+ * 'ldap_dereg_ou()' - Remove the organizational unit.
+ */
+
+static void
+ldap_dereg_ou(char *ou,                        /* I - Organizational unit (servername) */
+              char *basedn)            /* I - Dase dn */
+{
+  char         dn[1024];               /* DN of the printer */
+  int          rc;                     /* LDAP status */
+
+
+  cupsdLogMessage(CUPSD_LOG_DEBUG2, "ldap_dereg_ou: Remove entry for %s", ou);
+
+ /*
+  * Reconnect if LDAP Handle is invalid...
+  */
+
+  if (!BrowseLDAPHandle)
+  {
+    ldap_reconnect();
+    return;
+  }
+
+ /*
+  * Get dn for printer and delete LDAP entry...
+  */
+
+  snprintf(dn, sizeof(dn), "ou=%s, %s", ou, basedn);
+  cupsdLogMessage(CUPSD_LOG_DEBUG2, "ldap_dereg_ou: dn=\"%s\"", dn);
+
+#  if defined(HAVE_OPENLDAP) && LDAP_API_VERSION > 3000
+  if ((rc = ldap_delete_ext_s(BrowseLDAPHandle, dn, NULL,
+                              NULL)) != LDAP_SUCCESS)
+#  else
+  if ((rc = ldap_delete_s(BrowseLDAPHandle, dn)) != LDAP_SUCCESS)
+#  endif /* defined(HAVE_OPENLDAP) && LDAP_API_VERSION > 3000 */
+  {
+    cupsdLogMessage(CUPSD_LOG_WARN,
+                    "LDAP delete for %s failed with status %d: %s",
+                    ou, rc, ldap_err2string(rc));
+
+   /*
+    * If we had a connection problem (connection timed out, etc.)
+    * we should reconnect and try again to delete the entry...
+    */
+
+    if (rc == LDAP_SERVER_DOWN || rc == LDAP_CONNECT_ERROR)
+    {
+      cupsdLogMessage(CUPSD_LOG_INFO,
+                      "Retry deleting LDAP entry for %s after a reconnect...", ou);
+      ldap_reconnect();
+#  if defined(HAVE_OPENLDAP) && LDAP_API_VERSION > 3000
+      if ((rc = ldap_delete_ext_s(BrowseLDAPHandle, dn, NULL,
+                                  NULL)) != LDAP_SUCCESS)
+#  else
+      if ((rc = ldap_delete_s(BrowseLDAPHandle, dn)) != LDAP_SUCCESS)
+#  endif /* defined(HAVE_OPENLDAP) && LDAP_API_VERSION > 3000 */
+        cupsdLogMessage(CUPSD_LOG_WARN,
+                        "LDAP delete for %s failed with status %d: %s",
+                        ou, rc, ldap_err2string(rc));
+    }
+  }
+}
+#endif /* HAVE_LDAP */
+
+
+#ifdef HAVE_LIBSLP
+/*
+ * 'send_slp_browse()' - Register the specified printer with SLP.
+ */
+
+static void
+send_slp_browse(cupsd_printer_t *p)    /* I - Printer to register */
+{
+  char         srvurl[HTTP_MAX_URI],   /* Printer service URI */
+               attrs[8192],            /* Printer attributes */
+               finishings[1024],       /* Finishings to support */
+               make_model[IPP_MAX_NAME * 2],
+                                       /* Make and model, quoted */
+               location[IPP_MAX_NAME * 2],
+                                       /* Location, quoted */
+               info[IPP_MAX_NAME * 2], /* Info, quoted */
+               *src,                   /* Pointer to original string */
+               *dst;                   /* Pointer to destination string */
+  ipp_attribute_t *authentication;     /* uri-authentication-supported value */
+  SLPError     error;                  /* SLP error, if any */
+
+
+  cupsdLogMessage(CUPSD_LOG_DEBUG, "send_slp_browse(%p = \"%s\")", p,
+                  p->name);
+
+ /*
+  * Make the SLP service URL that conforms to the IANA 
+  * 'printer:' template.
+  */
+
+  snprintf(srvurl, sizeof(srvurl), SLP_CUPS_SRVTYPE ":%s", p->uri);
+
+  cupsdLogMessage(CUPSD_LOG_DEBUG2, "Service URL = \"%s\"", srvurl);
+
+ /*
+  * Figure out the finishings string...
+  */
+
+  if (p->type & CUPS_PRINTER_STAPLE)
+    strcpy(finishings, "staple");
+  else
+    finishings[0] = '\0';
+
+  if (p->type & CUPS_PRINTER_BIND)
+  {
+    if (finishings[0])
+      strlcat(finishings, ",bind", sizeof(finishings));
+    else
+      strcpy(finishings, "bind");
+  }
+
+  if (p->type & CUPS_PRINTER_PUNCH)
+  {
+    if (finishings[0])
+      strlcat(finishings, ",punch", sizeof(finishings));
+    else
+      strcpy(finishings, "punch");
+  }
+
+  if (p->type & CUPS_PRINTER_COVER)
+  {
+    if (finishings[0])
+      strlcat(finishings, ",cover", sizeof(finishings));
+    else
+      strcpy(finishings, "cover");
+  }
+
+  if (p->type & CUPS_PRINTER_SORT)
+  {
+    if (finishings[0])
+      strlcat(finishings, ",sort", sizeof(finishings));
+    else
+      strcpy(finishings, "sort");
+  }
+
+  if (!finishings[0])
     strcpy(finishings, "none");
 
  /*
-  * Quote any commas in the make and model, location, and info strings...
+  * Quote any commas in the make and model, location, and info strings...
+  */
+
+  for (src = p->make_model, dst = make_model;
+       src && *src && dst < (make_model + sizeof(make_model) - 2);)
+  {
+    if (*src == ',' || *src == '\\' || *src == ')')
+      *dst++ = '\\';
+
+    *dst++ = *src++;
+  }
+
+  *dst = '\0';
+
+  if (!make_model[0])
+    strcpy(make_model, "Unknown");
+
+  for (src = p->location, dst = location;
+       src && *src && dst < (location + sizeof(location) - 2);)
+  {
+    if (*src == ',' || *src == '\\' || *src == ')')
+      *dst++ = '\\';
+
+    *dst++ = *src++;
+  }
+
+  *dst = '\0';
+
+  if (!location[0])
+    strcpy(location, "Unknown");
+
+  for (src = p->info, dst = info;
+       src && *src && dst < (info + sizeof(info) - 2);)
+  {
+    if (*src == ',' || *src == '\\' || *src == ')')
+      *dst++ = '\\';
+
+    *dst++ = *src++;
+  }
+
+  *dst = '\0';
+
+  if (!info[0])
+    strcpy(info, "Unknown");
+
+ /*
+  * Get the authentication value...
+  */
+
+  authentication = ippFindAttribute(p->attrs, "uri-authentication-supported",
+                                    IPP_TAG_KEYWORD);
+
+ /*
+  * Make the SLP attribute string list that conforms to
+  * the IANA 'printer:' template.
+  */
+
+  snprintf(attrs, sizeof(attrs),
+           "(printer-uri-supported=%s),"
+           "(uri-authentication-supported=%s>),"
+#ifdef HAVE_SSL
+           "(uri-security-supported=tls>),"
+#else
+           "(uri-security-supported=none>),"
+#endif /* HAVE_SSL */
+           "(printer-name=%s),"
+           "(printer-location=%s),"
+           "(printer-info=%s),"
+           "(printer-more-info=%s),"
+           "(printer-make-and-model=%s),"
+          "(printer-type=%d),"
+          "(charset-supported=utf-8),"
+          "(natural-language-configured=%s),"
+          "(natural-language-supported=de,en,es,fr,it),"
+           "(color-supported=%s),"
+           "(finishings-supported=%s),"
+           "(sides-supported=one-sided%s),"
+          "(multiple-document-jobs-supported=true)"
+          "(ipp-versions-supported=1.0,1.1)",
+          p->uri, authentication->values[0].string.text, p->name, location,
+          info, p->uri, make_model, p->type, DefaultLanguage,
+           p->type & CUPS_PRINTER_COLOR ? "true" : "false",
+           finishings,
+           p->type & CUPS_PRINTER_DUPLEX ?
+              ",two-sided-long-edge,two-sided-short-edge" : "");
+
+  cupsdLogMessage(CUPSD_LOG_DEBUG2, "Attributes = \"%s\"", attrs);
+
+ /*
+  * Register the printer with the SLP server...
+  */
+
+  error = SLPReg(BrowseSLPHandle, srvurl, BrowseTimeout,
+                SLP_CUPS_SRVTYPE, attrs, SLP_TRUE, slp_reg_callback, 0);
+
+  if (error != SLP_OK)
+    cupsdLogMessage(CUPSD_LOG_ERROR, "SLPReg of \"%s\" failed with status %d!", p->name,
+                    error);
+}
+
+
+/*
+ * 'slp_attr_callback()' - SLP attribute callback 
+ */
+
+static SLPBoolean                      /* O - SLP_TRUE for success */
+slp_attr_callback(
+    SLPHandle  hslp,                   /* I - SLP handle */
+    const char *attrlist,              /* I - Attribute list */
+    SLPError   errcode,                        /* I - Parsing status for this attr */
+    void       *cookie)                        /* I - Current printer */
+{
+  char                 *tmp = 0;       /* Temporary string */
+  cupsd_printer_t      *p = (cupsd_printer_t*)cookie;
+                                       /* Current printer */
+
+
+  (void)hslp;                          /* anti-compiler-warning-code */
+
+ /*
+  * Bail if there was an error
+  */
+
+  if (errcode != SLP_OK)
+    return (SLP_TRUE);
+
+ /*
+  * Parse the attrlist to obtain things needed to build CUPS browse packet
+  */
+
+  memset(p, 0, sizeof(cupsd_printer_t));
+
+  if (slp_get_attr(attrlist, "(printer-location=", &(p->location)))
+    return (SLP_FALSE);
+  if (slp_get_attr(attrlist, "(printer-info=", &(p->info)))
+    return (SLP_FALSE);
+  if (slp_get_attr(attrlist, "(printer-make-and-model=", &(p->make_model)))
+    return (SLP_FALSE);
+  if (!slp_get_attr(attrlist, "(printer-type=", &tmp))
+    p->type = atoi(tmp);
+  else
+    p->type = CUPS_PRINTER_REMOTE;
+
+  cupsdClearString(&tmp);
+
+  return (SLP_TRUE);
+}
+
+
+/*
+ * 'slp_dereg_printer()' - SLPDereg() the specified printer
+ */
+
+static void 
+slp_dereg_printer(cupsd_printer_t *p)  /* I - Printer */
+{
+  char srvurl[HTTP_MAX_URI];           /* Printer service URI */
+
+
+  cupsdLogMessage(CUPSD_LOG_DEBUG, "slp_dereg_printer: printer=\"%s\"", p->name);
+
+  if (!(p->type & CUPS_PRINTER_REMOTE))
+  {
+   /*
+    * Make the SLP service URL that conforms to the IANA 
+    * 'printer:' template.
+    */
+
+    snprintf(srvurl, sizeof(srvurl), SLP_CUPS_SRVTYPE ":%s", p->uri);
+
+   /*
+    * Deregister the printer...
+    */
+
+    SLPDereg(BrowseSLPHandle, srvurl, slp_reg_callback, 0);
+  }
+}
+
+
+/*
+ * 'slp_get_attr()' - Get an attribute from an SLP registration.
+ */
+
+static int                             /* O - 0 on success */
+slp_get_attr(const char *attrlist,     /* I - Attribute list string */
+             const char *tag,          /* I - Name of attribute */
+             char       **valbuf)      /* O - Value */
+{
+  char *ptr1,                          /* Pointer into string */
+       *ptr2;                          /* ... */
+
+
+  cupsdClearString(valbuf);
+
+  if ((ptr1 = strstr(attrlist, tag)) != NULL)
+  {
+    ptr1 += strlen(tag);
+
+    if ((ptr2 = strchr(ptr1,')')) != NULL)
+    {
+     /*
+      * Copy the value...
+      */
+
+      *valbuf = calloc(ptr2 - ptr1 + 1, 1);
+      strncpy(*valbuf, ptr1, ptr2 - ptr1);
+
+     /*
+      * Dequote the value...
+      */
+
+      for (ptr1 = *valbuf; *ptr1; ptr1 ++)
+       if (*ptr1 == '\\' && ptr1[1])
+         _cups_strcpy(ptr1, ptr1 + 1);
+
+      return (0);
+    }
+  }
+
+  return (-1);
+}
+
+
+/*
+ * 'slp_reg_callback()' - Empty SLPRegReport.
+ */
+
+static void
+slp_reg_callback(SLPHandle hslp,       /* I - SLP handle */
+                 SLPError  errcode,    /* I - Error code, if any */
+                void      *cookie)     /* I - App data */
+{
+  (void)hslp;
+  (void)errcode;
+  (void)cookie;
+
+  return;
+}
+
+
+/*
+ * 'slp_url_callback()' - SLP service url callback
+ */
+
+static SLPBoolean                      /* O - TRUE = OK, FALSE = error */
+slp_url_callback(
+    SLPHandle      hslp,               /* I - SLP handle */
+    const char     *srvurl,            /* I - URL of service */
+    unsigned short lifetime,           /* I - Life of service */
+    SLPError       errcode,            /* I - Existing error code */
+    void           *cookie)            /* I - Pointer to service list */
+{
+  slpsrvurl_t  *s,                     /* New service entry */
+               **head;                 /* Pointer to head of entry */
+
+
+ /*
+  * Let the compiler know we won't be using these vars...
   */
 
-  for (src = p->make_model, dst = make_model;
-       src && *src && dst < (make_model + sizeof(make_model) - 2);)
-  {
-    if (*src == ',' || *src == '\\' || *src == ')')
-      *dst++ = '\\';
+  (void)hslp;
+  (void)lifetime;
 
-    *dst++ = *src++;
-  }
+ /*
+  * Bail if there was an error
+  */
 
-  *dst = '\0';
+  if (errcode != SLP_OK)
+    return (SLP_TRUE);
 
-  if (!make_model[0])
-    strcpy(make_model, "Unknown");
+ /*
+  * Grab the head of the list...
+  */
 
-  for (src = p->location, dst = location;
-       src && *src && dst < (location + sizeof(location) - 2);)
+  head = (slpsrvurl_t**)cookie;
+
+ /*
+  * Allocate a *temporary* slpsrvurl_t to hold this entry.
+  */
+
+  if ((s = (slpsrvurl_t *)calloc(1, sizeof(slpsrvurl_t))) == NULL)
+    return (SLP_FALSE);
+
+ /*
+  * Copy the SLP service URL...
+  */
+
+  strlcpy(s->url, srvurl, sizeof(s->url));
+
+ /* 
+  * Link the SLP service URL into the head of the list
+  */
+
+  if (*head)
+    s->next = *head;
+
+  *head = s;
+
+  return (SLP_TRUE);
+}
+#endif /* HAVE_LIBSLP */
+
+
+/*
+ * 'update_cups_browse()' - Update the browse lists using the CUPS protocol.
+ */
+
+static void
+update_cups_browse(void)
+{
+  int          i;                      /* Looping var */
+  int          auth;                   /* Authorization status */
+  int          len;                    /* Length of name string */
+  int          bytes;                  /* Number of bytes left */
+  char         packet[1541],           /* Broadcast packet */
+               *pptr;                  /* Pointer into packet */
+  socklen_t    srclen;                 /* Length of source address */
+  http_addr_t  srcaddr;                /* Source address */
+  char         srcname[1024];          /* Source hostname */
+  unsigned     address[4];             /* Source address */
+  unsigned     type;                   /* Printer type */
+  unsigned     state;                  /* Printer state */
+  char         uri[HTTP_MAX_URI],      /* Printer URI */
+               host[HTTP_MAX_URI],     /* Host portion of URI */
+               resource[HTTP_MAX_URI], /* Resource portion of URI */
+               info[IPP_MAX_NAME],     /* Information string */
+               location[IPP_MAX_NAME], /* Location string */
+               make_model[IPP_MAX_NAME];/* Make and model string */
+  int          num_attrs;              /* Number of attributes */
+  cups_option_t        *attrs;                 /* Attributes */
+
+
+ /*
+  * Read a packet from the browse socket...
+  */
+
+  srclen = sizeof(srcaddr);
+  if ((bytes = recvfrom(BrowseSocket, packet, sizeof(packet) - 1, 0, 
+                        (struct sockaddr *)&srcaddr, &srclen)) < 0)
   {
-    if (*src == ',' || *src == '\\' || *src == ')')
-      *dst++ = '\\';
+   /*
+    * "Connection refused" is returned under Linux if the destination port
+    * or address is unreachable from a previous sendto(); check for the
+    * error here and ignore it for now...
+    */
 
-    *dst++ = *src++;
+    if (errno != ECONNREFUSED && errno != EAGAIN)
+    {
+      cupsdLogMessage(CUPSD_LOG_ERROR, "Browse recv failed - %s.",
+                      strerror(errno));
+      cupsdLogMessage(CUPSD_LOG_ERROR, "CUPS browsing turned off.");
+
+#ifdef WIN32
+      closesocket(BrowseSocket);
+#else
+      close(BrowseSocket);
+#endif /* WIN32 */
+
+      cupsdRemoveSelect(BrowseSocket);
+      BrowseSocket = -1;
+
+      BrowseLocalProtocols  &= ~BROWSE_CUPS;
+      BrowseRemoteProtocols &= ~BROWSE_CUPS;
+    }
+
+    return;
   }
 
-  *dst = '\0';
+  packet[bytes] = '\0';
 
-  if (!location[0])
-    strcpy(location, "Unknown");
+ /*
+  * If we're about to sleep, ignore incoming browse packets.
+  */
 
-  for (src = p->info, dst = info;
-       src && *src && dst < (info + sizeof(info) - 2);)
-  {
-    if (*src == ',' || *src == '\\' || *src == ')')
-      *dst++ = '\\';
+  if (Sleeping)
+    return;
 
-    *dst++ = *src++;
+ /*
+  * Figure out where it came from...
+  */
+
+#ifdef AF_INET6
+  if (srcaddr.addr.sa_family == AF_INET6)
+  {
+    address[0] = ntohl(srcaddr.ipv6.sin6_addr.s6_addr32[0]);
+    address[1] = ntohl(srcaddr.ipv6.sin6_addr.s6_addr32[1]);
+    address[2] = ntohl(srcaddr.ipv6.sin6_addr.s6_addr32[2]);
+    address[3] = ntohl(srcaddr.ipv6.sin6_addr.s6_addr32[3]);
+  }
+  else
+#endif /* AF_INET6 */
+  {
+    address[0] = 0;
+    address[1] = 0;
+    address[2] = 0;
+    address[3] = ntohl(srcaddr.ipv4.sin_addr.s_addr);
   }
 
-  *dst = '\0';
+  if (HostNameLookups)
+    httpAddrLookup(&srcaddr, srcname, sizeof(srcname));
+  else
+    httpAddrString(&srcaddr, srcname, sizeof(srcname));
 
-  if (!info[0])
-    strcpy(info, "Unknown");
+  len = strlen(srcname);
 
  /*
-  * Get the authentication value...
+  * Do ACL stuff...
   */
 
-  authentication = ippFindAttribute(p->attrs, "uri-authentication-supported",
-                                    IPP_TAG_KEYWORD);
+  if (BrowseACL)
+  {
+    if (httpAddrLocalhost(&srcaddr) || !strcasecmp(srcname, "localhost"))
+    {
+     /*
+      * Access from localhost (127.0.0.1) is always allowed...
+      */
+
+      auth = CUPSD_AUTH_ALLOW;
+    }
+    else
+    {
+     /*
+      * Do authorization checks on the domain/address...
+      */
+
+      switch (BrowseACL->order_type)
+      {
+        default :
+           auth = CUPSD_AUTH_DENY;     /* anti-compiler-warning-code */
+           break;
+
+       case CUPSD_AUTH_ALLOW : /* Order Deny,Allow */
+            auth = CUPSD_AUTH_ALLOW;
+
+            if (cupsdCheckAuth(address, srcname, len, BrowseACL->deny))
+             auth = CUPSD_AUTH_DENY;
+
+            if (cupsdCheckAuth(address, srcname, len, BrowseACL->allow))
+             auth = CUPSD_AUTH_ALLOW;
+           break;
+
+       case CUPSD_AUTH_DENY : /* Order Allow,Deny */
+            auth = CUPSD_AUTH_DENY;
+
+            if (cupsdCheckAuth(address, srcname, len, BrowseACL->allow))
+             auth = CUPSD_AUTH_ALLOW;
+
+            if (cupsdCheckAuth(address, srcname, len, BrowseACL->deny))
+             auth = CUPSD_AUTH_DENY;
+           break;
+      }
+    }
+  }
+  else
+    auth = CUPSD_AUTH_ALLOW;
+
+  if (auth == CUPSD_AUTH_DENY)
+  {
+    cupsdLogMessage(CUPSD_LOG_DEBUG,
+                    "update_cups_browse: Refused %d bytes from %s", bytes,
+                    srcname);
+    return;
+  }
+
+  cupsdLogMessage(CUPSD_LOG_DEBUG2,
+                  "update_cups_browse: (%d bytes from %s) %s", bytes,
+                 srcname, packet);
 
  /*
-  * Make the SLP attribute string list that conforms to
-  * the IANA 'printer:' template.
+  * Parse packet...
   */
 
-  snprintf(attrs, sizeof(attrs),
-           "(printer-uri-supported=%s),"
-           "(uri-authentication-supported=%s>),"
-#ifdef HAVE_SSL
-           "(uri-security-supported=tls>),"
-#else
-           "(uri-security-supported=none>),"
-#endif /* HAVE_SSL */
-           "(printer-name=%s),"
-           "(printer-location=%s),"
-           "(printer-info=%s),"
-           "(printer-more-info=%s),"
-           "(printer-make-and-model=%s),"
-          "(printer-type=%d),"
-          "(charset-supported=utf-8),"
-          "(natural-language-configured=%s),"
-          "(natural-language-supported=de,en,es,fr,it),"
-           "(color-supported=%s),"
-           "(finishings-supported=%s),"
-           "(sides-supported=one-sided%s),"
-          "(multiple-document-jobs-supported=true)"
-          "(ipp-versions-supported=1.0,1.1)",
-          p->uri, authentication->values[0].string.text, p->name, location,
-          info, p->uri, make_model, p->type, DefaultLanguage,
-           p->type & CUPS_PRINTER_COLOR ? "true" : "false",
-           finishings,
-           p->type & CUPS_PRINTER_DUPLEX ?
-              ",two-sided-long-edge,two-sided-short-edge" : "");
+  if (sscanf(packet, "%x%x%1023s", &type, &state, uri) < 3)
+  {
+    cupsdLogMessage(CUPSD_LOG_WARN,
+                    "update_cups_browse: Garbled browse packet - %s", packet);
+    return;
+  }
+
+  strcpy(location, "Location Unknown");
+  strcpy(info, "No Information Available");
+  make_model[0] = '\0';
+  num_attrs     = 0;
+  attrs         = NULL;
+
+  if ((pptr = strchr(packet, '\"')) != NULL)
+  {
+   /*
+    * Have extended information; can't use sscanf for it because not all
+    * sscanf's allow empty strings with %[^\"]...
+    */
+
+    for (i = 0, pptr ++;
+         i < (sizeof(location) - 1) && *pptr && *pptr != '\"';
+         i ++, pptr ++)
+      location[i] = *pptr;
+
+    if (i)
+      location[i] = '\0';
+
+    if (*pptr == '\"')
+      pptr ++;
 
-  cupsdLogMessage(CUPSD_LOG_DEBUG2, "Attributes = \"%s\"", attrs);
+    while (*pptr && isspace(*pptr & 255))
+      pptr ++;
 
- /*
-  * Register the printer with the SLP server...
-  */
+    if (*pptr == '\"')
+    {
+      for (i = 0, pptr ++;
+           i < (sizeof(info) - 1) && *pptr && *pptr != '\"';
+           i ++, pptr ++)
+       info[i] = *pptr;
 
-  error = SLPReg(BrowseSLPHandle, srvurl, BrowseTimeout,
-                SLP_CUPS_SRVTYPE, attrs, SLP_TRUE, slp_reg_callback, 0);
+      info[i] = '\0';
 
-  if (error != SLP_OK)
-    cupsdLogMessage(CUPSD_LOG_ERROR, "SLPReg of \"%s\" failed with status %d!", p->name,
-                    error);
-}
+      if (*pptr == '\"')
+       pptr ++;
 
+      while (*pptr && isspace(*pptr & 255))
+       pptr ++;
 
-/*
- * 'slp_attr_callback()' - SLP attribute callback 
- */
+      if (*pptr == '\"')
+      {
+       for (i = 0, pptr ++;
+             i < (sizeof(make_model) - 1) && *pptr && *pptr != '\"';
+             i ++, pptr ++)
+         make_model[i] = *pptr;
 
-static SLPBoolean                      /* O - SLP_TRUE for success */
-slp_attr_callback(
-    SLPHandle  hslp,                   /* I - SLP handle */
-    const char *attrlist,              /* I - Attribute list */
-    SLPError   errcode,                        /* I - Parsing status for this attr */
-    void       *cookie)                        /* I - Current printer */
-{
-  char                 *tmp = 0;       /* Temporary string */
-  cupsd_printer_t      *p = (cupsd_printer_t*)cookie;
-                                       /* Current printer */
+       if (*pptr == '\"')
+         pptr ++;
 
+       make_model[i] = '\0';
 
-  (void)hslp;                          /* anti-compiler-warning-code */
+        if (*pptr)
+         num_attrs = cupsParseOptions(pptr, num_attrs, &attrs);
+      }
+    }
+  }
+
+  DEBUG_puts(packet);
+  DEBUG_printf(("type=%x, state=%x, uri=\"%s\"\n"
+                "location=\"%s\", info=\"%s\", make_model=\"%s\"\n",
+               type, state, uri, location, info, make_model));
 
  /*
-  * Bail if there was an error
+  * Pull the URI apart to see if this is a local or remote printer...
   */
 
-  if (errcode != SLP_OK)
-    return (SLP_TRUE);
+  if (is_local_queue(uri, host, sizeof(host), resource, sizeof(resource)))
+  {
+    cupsFreeOptions(num_attrs, attrs);
+    return;
+  }
 
  /*
-  * Parse the attrlist to obtain things needed to build CUPS browse packet
+  * Do relaying...
   */
 
-  memset(p, 0, sizeof(cupsd_printer_t));
-
-  if (slp_get_attr(attrlist, "(printer-location=", &(p->location)))
-    return (SLP_FALSE);
-  if (slp_get_attr(attrlist, "(printer-info=", &(p->info)))
-    return (SLP_FALSE);
-  if (slp_get_attr(attrlist, "(printer-make-and-model=", &(p->make_model)))
-    return (SLP_FALSE);
-  if (!slp_get_attr(attrlist, "(printer-type=", &tmp))
-    p->type = atoi(tmp);
-  else
-    p->type = CUPS_PRINTER_REMOTE;
+  for (i = 0; i < NumRelays; i ++)
+    if (cupsdCheckAuth(address, srcname, len, Relays[i].from))
+      if (sendto(BrowseSocket, packet, bytes, 0,
+                 (struct sockaddr *)&(Relays[i].to),
+                httpAddrLength(&(Relays[i].to))) <= 0)
+      {
+       cupsdLogMessage(CUPSD_LOG_ERROR,
+                       "update_cups_browse: sendto failed for relay %d - %s.",
+                       i + 1, strerror(errno));
+       cupsFreeOptions(num_attrs, attrs);
+       return;
+      }
 
-  cupsdClearString(&tmp);
+ /*
+  * Process the browse data...
+  */
 
-  return (SLP_TRUE);
+  process_browse_data(uri, host, resource, (cups_ptype_t)type,
+                      (ipp_pstate_t)state, location, info, make_model,
+                     num_attrs, attrs);
 }
 
 
 /*
- * 'slp_dereg_printer()' - SLPDereg() the specified printer
+ * 'update_lpd()' - Update the LPD configuration as needed.
  */
 
-static void 
-slp_dereg_printer(cupsd_printer_t *p)  /* I - Printer */
+static void
+update_lpd(int onoff)                  /* - 1 = turn on, 0 = turn off */
 {
-  char srvurl[HTTP_MAX_URI];           /* Printer service URI */
+  if (!LPDConfigFile)
+    return;
 
+#ifdef __APPLE__
+ /*
+  * Allow /etc/hostconfig CUPS_LPD service setting to override cupsd.conf
+  * setting for backwards-compatibility.
+  */
 
-  cupsdLogMessage(CUPSD_LOG_DEBUG, "slp_dereg_printer: printer=\"%s\"", p->name);
+  if (onoff && !get_hostconfig("CUPS_LPD"))
+    onoff = 0;
+#endif /* __APPLE__ */
 
-  if (!(p->type & CUPS_PRINTER_REMOTE))
+  if (!strncmp(LPDConfigFile, "xinetd:///", 10))
   {
    /*
-    * Make the SLP service URL that conforms to the IANA 
-    * 'printer:' template.
+    * Enable/disable LPD via the xinetd.d config file for cups-lpd...
     */
 
-    snprintf(srvurl, sizeof(srvurl), SLP_CUPS_SRVTYPE ":%s", p->uri);
-
-   /*
-    * Deregister the printer...
-    */
+    char       newfile[1024];          /* New cups-lpd.N file */
+    cups_file_t        *ofp,                   /* Original file pointer */
+               *nfp;                   /* New file pointer */
+    char       line[1024];             /* Line from file */
 
-    SLPDereg(BrowseSLPHandle, srvurl, slp_reg_callback, 0);
-  }
-}
 
+    snprintf(newfile, sizeof(newfile), "%s.N", LPDConfigFile + 9);
 
-/*
- * 'slp_get_attr()' - Get an attribute from an SLP registration.
- */
+    if ((ofp = cupsFileOpen(LPDConfigFile + 9, "r")) == NULL)
+    {
+      cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to open \"%s\" - %s",
+                      LPDConfigFile + 9, strerror(errno));
+      return;
+    }
 
-static int                             /* O - 0 on success */
-slp_get_attr(const char *attrlist,     /* I - Attribute list string */
-             const char *tag,          /* I - Name of attribute */
-             char       **valbuf)      /* O - Value */
-{
-  char *ptr1,                          /* Pointer into string */
-       *ptr2;                          /* ... */
+    if ((nfp = cupsFileOpen(newfile, "w")) == NULL)
+    {
+      cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to create \"%s\" - %s",
+                      newfile, strerror(errno));
+      cupsFileClose(ofp);
+      return;
+    }
 
+   /*
+    * Copy all of the lines from the cups-lpd file...
+    */
 
-  cupsdClearString(valbuf);
+    while (cupsFileGets(ofp, line, sizeof(line)))
+    {
+      if (line[0] == '{')
+      {
+        cupsFilePrintf(nfp, "%s\n", line);
+        snprintf(line, sizeof(line), "\tdisable = %s",
+                onoff ? "no" : "yes");
+      }
+      else if (!strstr(line, "disable ="))
+        cupsFilePrintf(nfp, "%s\n", line);
+    }
 
-  if ((ptr1 = strstr(attrlist, tag)) != NULL)
+    cupsFileClose(nfp);
+    cupsFileClose(ofp);
+    rename(newfile, LPDConfigFile + 9);
+  }
+#ifdef __APPLE__
+  else if (!strncmp(LPDConfigFile, "launchd:///", 11))
   {
-    ptr1 += strlen(tag);
-
-    if ((ptr2 = strchr(ptr1,')')) != NULL)
-    {
-     /*
-      * Copy the value...
-      */
+   /*
+    * Enable/disable LPD via the launchctl command...
+    */
 
-      *valbuf = calloc(ptr2 - ptr1 + 1, 1);
-      strncpy(*valbuf, ptr1, ptr2 - ptr1);
+    char       *argv[5],               /* Arguments for command */
+               *envp[MAX_ENV];         /* Environment for command */
+    int                pid;                    /* Process ID */
 
-     /*
-      * Dequote the value...
-      */
 
-      for (ptr1 = *valbuf; *ptr1; ptr1 ++)
-       if (*ptr1 == '\\' && ptr1[1])
-         _cups_strcpy(ptr1, ptr1 + 1);
+    cupsdLoadEnv(envp, (int)(sizeof(envp) / sizeof(envp[0])));
+    argv[0] = (char *)"launchctl";
+    argv[1] = (char *)(onoff ? "load" : "unload");
+    argv[2] = (char *)"-w";
+    argv[3] = LPDConfigFile + 10;
+    argv[4] = NULL;
 
-      return (0);
-    }
+    cupsdStartProcess("/bin/launchctl", argv, envp, -1, -1, -1, -1, -1, 1,
+                      NULL, NULL, &pid);
   }
-
-  return (-1);
+#endif /* __APPLE__ */
+  else
+    cupsdLogMessage(CUPSD_LOG_INFO, "Unknown LPDConfigFile scheme!");
 }
 
 
 /*
- * 'slp_reg_callback()' - Empty SLPRegReport.
+ * 'update_polling()' - Read status messages from the poll daemons.
  */
 
 static void
-slp_reg_callback(SLPHandle hslp,       /* I - SLP handle */
-                 SLPError  errcode,    /* I - Error code, if any */
-                void      *cookie)     /* I - App data */
+update_polling(void)
 {
-  (void)hslp;
-  (void)errcode;
-  (void)cookie;
+  char         *ptr,                   /* Pointer to end of line in buffer */
+               message[1024];          /* Pointer to message text */
+  int          loglevel;               /* Log level for message */
 
-  return;
+
+  while ((ptr = cupsdStatBufUpdate(PollStatusBuffer, &loglevel,
+                                   message, sizeof(message))) != NULL)
+  {
+    if (loglevel == CUPSD_LOG_INFO)
+      cupsdLogMessage(CUPSD_LOG_INFO, "%s", message);
+
+    if (!strchr(PollStatusBuffer->buffer, '\n'))
+      break;
+  }
+
+  if (ptr == NULL && !PollStatusBuffer->bufused)
+  {
+   /*
+    * All polling processes have died; stop polling...
+    */
+
+    cupsdLogMessage(CUPSD_LOG_ERROR,
+                    "update_polling: all polling processes have exited!");
+    cupsdStopPolling();
+  }
 }
 
 
 /*
- * 'slp_url_callback()' - SLP service url callback
+ * 'update_smb()' - Update the SMB configuration as needed.
  */
 
-static SLPBoolean                      /* O - TRUE = OK, FALSE = error */
-slp_url_callback(
-    SLPHandle      hslp,               /* I - SLP handle */
-    const char     *srvurl,            /* I - URL of service */
-    unsigned short lifetime,           /* I - Life of service */
-    SLPError       errcode,            /* I - Existing error code */
-    void           *cookie)            /* I - Pointer to service list */
+static void
+update_smb(int onoff)                  /* I - 1 = turn on, 0 = turn off */
 {
-  slpsrvurl_t  *s,                     /* New service entry */
-               **head;                 /* Pointer to head of entry */
-
-
- /*
-  * Let the compiler know we won't be using these vars...
-  */
-
-  (void)hslp;
-  (void)lifetime;
+  if (!SMBConfigFile)
+    return;
 
- /*
-  * Bail if there was an error
-  */
+  if (!strncmp(SMBConfigFile, "samba:///", 9))
+  {
+   /*
+    * Enable/disable SMB via the specified smb.conf config file...
+    */
 
-  if (errcode != SLP_OK)
-    return (SLP_TRUE);
+    char       newfile[1024];          /* New smb.conf.N file */
+    cups_file_t        *ofp,                   /* Original file pointer */
+               *nfp;                   /* New file pointer */
+    char       line[1024];             /* Line from file */
+    int                in_printers;            /* In [printers] section? */
 
- /*
-  * Grab the head of the list...
-  */
 
-  head = (slpsrvurl_t**)cookie;
+    snprintf(newfile, sizeof(newfile), "%s.N", SMBConfigFile + 8);
 
- /*
-  * Allocate a *temporary* slpsrvurl_t to hold this entry.
-  */
+    if ((ofp = cupsFileOpen(SMBConfigFile + 8, "r")) == NULL)
+    {
+      cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to open \"%s\" - %s",
+                      SMBConfigFile + 8, strerror(errno));
+      return;
+    }
 
-  if ((s = (slpsrvurl_t *)calloc(1, sizeof(slpsrvurl_t))) == NULL)
-    return (SLP_FALSE);
+    if ((nfp = cupsFileOpen(newfile, "w")) == NULL)
+    {
+      cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to create \"%s\" - %s",
+                      newfile, strerror(errno));
+      cupsFileClose(ofp);
+      return;
+    }
 
- /*
-  * Copy the SLP service URL...
-  */
  /*
+    * Copy all of the lines from the smb.conf file...
+    */
 
-  strlcpy(s->url, srvurl, sizeof(s->url));
+    in_printers = 0;
 
- /* 
-  * Link the SLP service URL into the head of the list
-  */
+    while (cupsFileGets(ofp, line, sizeof(line)))
+    {
+      if (in_printers && strstr(line, "printable ="))
+        snprintf(line, sizeof(line), "    printable = %s",
+                onoff ? "yes" : "no");
 
-  if (*head)
-    s->next = *head;
+      cupsFilePrintf(nfp, "%s\n", line);
 
-  *head = s;
+      if (line[0] == '[')
+        in_printers = !strcmp(line, "[printers]");
+    }
 
-  return (SLP_TRUE);
+    cupsFileClose(nfp);
+    cupsFileClose(ofp);
+    rename(newfile, SMBConfigFile + 8);
+  }
+  else
+    cupsdLogMessage(CUPSD_LOG_INFO, "Unknown SMBConfigFile scheme!");
 }
-#endif /* HAVE_LIBSLP */
 
 
 /*
- * End of "$Id: dirsvc.c 6205 2007-01-22 22:04:43Z mike $".
+ * End of "$Id: dirsvc.c 7933 2008-09-11 00:44:58Z mike $".
  */