]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - scheduler/dirsvc.c
Merge changes from CUPS 1.4svn-r8362.
[thirdparty/cups.git] / scheduler / dirsvc.c
index d876c5ac494281494c945c84f6a4d4c50bfd8d6f..f41fb451b820c9730c06ae2428b04f5d8bc6f656 100644 (file)
@@ -47,6 +47,7 @@
  *   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_hostconfig()           - Get an /etc/hostconfig service setting.
  *   is_local_queue()           - Determine whether the URI points at a local
@@ -166,6 +167,7 @@ static void dnssdRegisterCallback(DNSServiceRef sdRef,
                                      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 */
 
@@ -1816,29 +1818,7 @@ cupsdStopBrowsing(void)
 
 #ifdef HAVE_DNSSD
   if ((BrowseLocalProtocols & BROWSE_DNSSD) && DNSSDRef)
-  {
-    if (WebIFRef)
-    {
-      DNSServiceRefDeallocate(WebIFRef);
-      WebIFRef = NULL;
-    }
-
-    if (RemoteRef)
-    {
-      DNSServiceRefDeallocate(RemoteRef);
-      RemoteRef = NULL;
-    }
-
-    cupsdRemoveSelect(DNSServiceRefSockFD(DNSSDRef));
-
-    DNSServiceRefDeallocate(DNSSDRef);
-    DNSSDRef = NULL;
-
-    cupsArrayDelete(DNSSDPrinters);
-    DNSSDPrinters = NULL;
-
-    DNSSDPort = 0;
-  }
+    dnssdStop();
 #endif /* HAVE_DNSSD */
 
 #ifdef HAVE_LIBSLP
@@ -2811,6 +2791,53 @@ dnssdRegisterPrinter(cupsd_printer_t *p)/* I - Printer */
 }
 
 
+/*
+ * 'dnssdStop()' - Stop all DNS-SD registrations.
+ */
+
+static void
+dnssdStop(void)
+{
+  cupsd_printer_t      *p;             /* Current printer */
+
+
+ /*
+  * De-register the individual printers
+  */
+
+  for (p = (cupsd_printer_t *)cupsArrayFirst(Printers);
+       p;
+       p = (cupsd_printer_t *)cupsArrayNext(Printers))
+    dnssdDeregisterPrinter(p);
+
+ /*
+  * Shutdown the rest of the service refs...
+  */
+
+  if (WebIFRef)
+  {
+    DNSServiceRefDeallocate(WebIFRef);
+    WebIFRef = NULL;
+  }
+
+  if (RemoteRef)
+  {
+    DNSServiceRefDeallocate(RemoteRef);
+    RemoteRef = NULL;
+  }
+
+  cupsdRemoveSelect(DNSServiceRefSockFD(DNSSDRef));
+
+  DNSServiceRefDeallocate(DNSSDRef);
+  DNSSDRef = NULL;
+
+  cupsArrayDelete(DNSSDPrinters);
+  DNSSDPrinters = NULL;
+
+  DNSSDPort = 0;
+}
+
+
 /*
  * 'dnssdUpdate()' - Handle DNS-SD queries.
  */
@@ -2822,9 +2849,12 @@ dnssdUpdate(void)
 
 
   if ((sdErr = DNSServiceProcessResult(DNSSDRef)) != kDNSServiceErr_NoError)
+  {
     cupsdLogMessage(CUPSD_LOG_ERROR,
                     "DNS Service Discovery registration error %d!",
                    sdErr);
+    dnssdStop();
+  }
 }
 #endif /* HAVE_DNSSD */
 
@@ -3509,6 +3539,18 @@ process_implicit_classes(void)
       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;
@@ -5253,8 +5295,13 @@ update_polling(void)
 
   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)
   {