Blame SOURCES/cups-avahi-no-threaded.patch

3635cf
diff -up cups-2.2.5/scheduler/avahi.c.avahi-no-threaded cups-2.2.5/scheduler/avahi.c
3635cf
--- cups-2.2.5/scheduler/avahi.c.avahi-no-threaded	2017-10-17 19:03:00.760881016 +0200
3635cf
+++ cups-2.2.5/scheduler/avahi.c	2017-10-17 19:03:00.760881016 +0200
3635cf
@@ -0,0 +1,441 @@
3635cf
+/*
3635cf
+ * "$Id$"
3635cf
+ *
3635cf
+ *   Avahi poll implementation for the CUPS scheduler.
3635cf
+ *
3635cf
+ *   Copyright (C) 2010, 2011 Red Hat, Inc.
3635cf
+ *   Authors:
3635cf
+ *    Tim Waugh <twaugh@redhat.com>
3635cf
+ *
3635cf
+ *   Redistribution and use in source and binary forms, with or without
3635cf
+ *   modification, are permitted provided that the following conditions
3635cf
+ *   are met:
3635cf
+ *
3635cf
+ *   Redistributions of source code must retain the above copyright
3635cf
+ *   notice, this list of conditions and the following disclaimer.
3635cf
+ *
3635cf
+ *   Redistributions in binary form must reproduce the above copyright
3635cf
+ *   notice, this list of conditions and the following disclaimer in the
3635cf
+ *   documentation and/or other materials provided with the distribution.
3635cf
+ *
3635cf
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
3635cf
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
3635cf
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
3635cf
+ *   FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
3635cf
+ *   COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
3635cf
+ *   INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
3635cf
+ *   (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
3635cf
+ *   SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3635cf
+ *   HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
3635cf
+ *   STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
3635cf
+ *   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
3635cf
+ *   OF THE POSSIBILITY OF SUCH DAMAGE.
3635cf
+ *
3635cf
+ * Contents:
3635cf
+ *
3635cf
+ *   watch_read_cb         - Read callback for file descriptor
3635cf
+ *   watch_write_cb        - Write callback for file descriptor
3635cf
+ *   watched_fd_add_select() - Call cupsdAddSelect() as needed
3635cf
+ *   watch_new()           - Create a new file descriptor watch
3635cf
+ *   watch_free()          - Free a file descriptor watch
3635cf
+ *   watch_update()        - Update watched events for a file descriptor
3635cf
+ *   watch_get_events()    - Get events that happened for a file descriptor
3635cf
+ *   timeout_cb()          - Run a timed Avahi callback
3635cf
+ *   timeout_new()         - Set a wakeup time
3635cf
+ *   timeout_update()      - Update the expiration time for a timeout
3635cf
+ *   timeout_free()        - Free a timeout
3635cf
+ *   compare_watched_fds() - Compare watched file descriptors for array sorting
3635cf
+ *   avahi_cups_poll_new() - Create a new Avahi main loop object for CUPS
3635cf
+ *   avahi_cups_poll_free() - Free an Avahi main loop object for CUPS
3635cf
+ *   avahi_cups_poll_get() - Get the abstract poll API structure
3635cf
+ */
3635cf
+
3635cf
+#include <config.h>
3635cf
+
3635cf
+#ifdef HAVE_AVAHI /* Applies to entire file... */
3635cf
+
3635cf
+/*
3635cf
+ * Include necessary headers...
3635cf
+ */
3635cf
+
3635cf
+#include "cupsd.h"
3635cf
+
3635cf
+#if defined(HAVE_MALLOC_H) && defined(HAVE_MALLINFO)
3635cf
+#  include <malloc.h>
3635cf
+#endif /* HAVE_MALLOC_H && HAVE_MALLINFO */
3635cf
+
3635cf
+#ifdef HAVE_AVAHI
3635cf
+#  include <avahi-common/timeval.h>
3635cf
+#endif /* HAVE_AVAHI */
3635cf
+
3635cf
+
3635cf
+typedef struct
3635cf
+{
3635cf
+  AvahiCupsPoll *cups_poll;
3635cf
+
3635cf
+  int fd;
3635cf
+  AvahiWatchEvent occurred;
3635cf
+  cups_array_t *watches;
3635cf
+} cupsd_watched_fd_t;
3635cf
+
3635cf
+struct AvahiWatch
3635cf
+{
3635cf
+  cupsd_watched_fd_t *watched_fd;
3635cf
+
3635cf
+  AvahiWatchEvent events;
3635cf
+  AvahiWatchCallback callback;
3635cf
+  void *userdata;
3635cf
+};
3635cf
+
3635cf
+struct AvahiTimeout
3635cf
+{
3635cf
+  AvahiCupsPoll *cups_poll;
3635cf
+  AvahiTimeoutCallback callback;
3635cf
+  void *userdata;
3635cf
+  cupsd_timeout_t *cupsd_timeout;
3635cf
+};
3635cf
+
3635cf
+/*
3635cf
+ * Local functions...
3635cf
+ */
3635cf
+
3635cf
+static AvahiWatch *	watch_new(const AvahiPoll *api,
3635cf
+				  int fd,
3635cf
+				  AvahiWatchEvent events,
3635cf
+				  AvahiWatchCallback callback,
3635cf
+				  void *userdata);
3635cf
+static void		watch_free(AvahiWatch *watch);
3635cf
+static void		watch_update(AvahiWatch *watch,
3635cf
+				     AvahiWatchEvent events);
3635cf
+static AvahiWatchEvent	watch_get_events(AvahiWatch *watch);
3635cf
+
3635cf
+
3635cf
+/*
3635cf
+ * 'watch_read_cb' - Read callback for file descriptor
3635cf
+ */
3635cf
+
3635cf
+static void
3635cf
+watch_read_cb (void *userdata)
3635cf
+{
3635cf
+  AvahiWatch *watch;
3635cf
+  cupsd_watched_fd_t *watched_fd = userdata;
3635cf
+  watched_fd->occurred |= AVAHI_WATCH_IN;
3635cf
+  for (watch = (AvahiWatch *)cupsArrayFirst(watched_fd->watches);
3635cf
+       watch;
3635cf
+       watch = (AvahiWatch *)cupsArrayNext(watched_fd->watches))
3635cf
+  {
3635cf
+    if (watch->events & watched_fd->occurred)
3635cf
+    {
3635cf
+      (watch->callback) (watch, watched_fd->fd,
3635cf
+			 AVAHI_WATCH_IN, watch->userdata);
3635cf
+      watched_fd->occurred &= ~AVAHI_WATCH_IN;
3635cf
+      break;
3635cf
+    }
3635cf
+  }
3635cf
+}
3635cf
+
3635cf
+
3635cf
+/*
3635cf
+ * 'watch_write_cb' - Write callback for file descriptor
3635cf
+ */
3635cf
+
3635cf
+static void
3635cf
+watch_write_cb (void *userdata)
3635cf
+{
3635cf
+  AvahiWatch *watch;
3635cf
+  cupsd_watched_fd_t *watched_fd = userdata;
3635cf
+  watched_fd->occurred |= AVAHI_WATCH_OUT;
3635cf
+  for (watch = (AvahiWatch *)cupsArrayFirst(watched_fd->watches);
3635cf
+       watch;
3635cf
+       watch = (AvahiWatch *)cupsArrayNext(watched_fd->watches))
3635cf
+  {
3635cf
+    if (watch->events & watched_fd->occurred)
3635cf
+    {
3635cf
+      (watch->callback) (watch, watched_fd->fd,
3635cf
+			 AVAHI_WATCH_OUT, watch->userdata);
3635cf
+      watched_fd->occurred &= ~AVAHI_WATCH_OUT;
3635cf
+      break;
3635cf
+    }
3635cf
+  }
3635cf
+}
3635cf
+
3635cf
+
3635cf
+/*
3635cf
+ * 'watched_fd_add_select' - Call cupsdAddSelect() as needed
3635cf
+ */
3635cf
+
3635cf
+static int						/* O - Watches? */
3635cf
+watched_fd_add_select (cupsd_watched_fd_t *watched_fd)
3635cf
+{
3635cf
+  AvahiWatch *watch;
3635cf
+  cupsd_selfunc_t read_cb = NULL, write_cb = NULL;
3635cf
+  int any_watches = 0;
3635cf
+
3635cf
+  for (watch = (AvahiWatch *)cupsArrayFirst(watched_fd->watches);
3635cf
+       watch;
3635cf
+       watch = (AvahiWatch *)cupsArrayNext(watched_fd->watches))
3635cf
+  {
3635cf
+    any_watches = 1;
3635cf
+    if (watch->events & (AVAHI_WATCH_IN |
3635cf
+			     AVAHI_WATCH_ERR |
3635cf
+			     AVAHI_WATCH_HUP))
3635cf
+    {
3635cf
+      read_cb = (cupsd_selfunc_t)watch_read_cb;
3635cf
+      if (write_cb != NULL)
3635cf
+	break;
3635cf
+    }
3635cf
+
3635cf
+    if (watch->events & AVAHI_WATCH_OUT)
3635cf
+    {
3635cf
+      write_cb = (cupsd_selfunc_t)watch_write_cb;
3635cf
+      if (read_cb != NULL)
3635cf
+	break;
3635cf
+    }
3635cf
+  }
3635cf
+
3635cf
+  if (read_cb || write_cb)
3635cf
+    cupsdAddSelect (watched_fd->fd, read_cb, write_cb, watched_fd);
3635cf
+  else
3635cf
+    cupsdRemoveSelect (watched_fd->fd);
3635cf
+
3635cf
+  return (any_watches);
3635cf
+}
3635cf
+
3635cf
+/*
3635cf
+ * 'watch_new' - Create a new file descriptor watch
3635cf
+ */
3635cf
+
3635cf
+static AvahiWatch *
3635cf
+watch_new (const AvahiPoll *api,
3635cf
+	   int fd,
3635cf
+	   AvahiWatchEvent events,
3635cf
+	   AvahiWatchCallback callback,
3635cf
+	   void *userdata)
3635cf
+{
3635cf
+  cupsd_watched_fd_t key, *watched_fd;
3635cf
+  AvahiCupsPoll *cups_poll = api->userdata;
3635cf
+  AvahiWatch *watch = malloc(sizeof(AvahiWatch));
3635cf
+  if (watch == NULL)
3635cf
+    return (NULL);
3635cf
+
3635cf
+  watch->events = events;
3635cf
+  watch->callback = callback;
3635cf
+  watch->userdata = userdata;
3635cf
+
3635cf
+  key.fd = fd;
3635cf
+  watched_fd = cupsArrayFind (cups_poll->watched_fds, &key);
3635cf
+  if (watched_fd == NULL)
3635cf
+  {
3635cf
+    watched_fd = malloc(sizeof(cupsd_watched_fd_t));
3635cf
+    if (watched_fd == NULL)
3635cf
+    {
3635cf
+      free (watch);
3635cf
+      return (NULL);
3635cf
+    }
3635cf
+
3635cf
+    watched_fd->fd = fd;
3635cf
+    watched_fd->occurred = 0;
3635cf
+    watched_fd->cups_poll = cups_poll;
3635cf
+    watched_fd->watches = cupsArrayNew (NULL, NULL);
3635cf
+    cupsArrayAdd (cups_poll->watched_fds, watched_fd);
3635cf
+  }
3635cf
+
3635cf
+  watch->watched_fd = watched_fd;
3635cf
+  cupsArrayAdd(watched_fd->watches, watch);
3635cf
+  watched_fd_add_select (watched_fd);
3635cf
+  return (watch);
3635cf
+}
3635cf
+
3635cf
+
3635cf
+/*
3635cf
+ * 'watch_free' - Free a file descriptor watch
3635cf
+ */
3635cf
+
3635cf
+static void
3635cf
+watch_free (AvahiWatch *watch)
3635cf
+{
3635cf
+  cupsd_watched_fd_t *watched_fd = watch->watched_fd;
3635cf
+  AvahiCupsPoll *cups_poll = watched_fd->cups_poll;
3635cf
+
3635cf
+  cupsArrayRemove (watched_fd->watches, watch);
3635cf
+  free (watch);
3635cf
+
3635cf
+  if (!watched_fd_add_select (watched_fd))
3635cf
+  {
3635cf
+    /* No more watches */
3635cf
+    cupsArrayRemove (cups_poll->watched_fds, watched_fd);
3635cf
+    free (watched_fd);
3635cf
+  }
3635cf
+}
3635cf
+
3635cf
+
3635cf
+/*
3635cf
+ * 'watch_update' - Update watched events for a file descriptor
3635cf
+ */
3635cf
+
3635cf
+static void
3635cf
+watch_update (AvahiWatch *watch,
3635cf
+	      AvahiWatchEvent events)
3635cf
+{
3635cf
+  watch->events = events;
3635cf
+  watched_fd_add_select (watch->watched_fd);
3635cf
+}
3635cf
+
3635cf
+
3635cf
+/*
3635cf
+ * 'watch_get_events' - Get events that happened for a file descriptor
3635cf
+ */
3635cf
+
3635cf
+static AvahiWatchEvent
3635cf
+watch_get_events (AvahiWatch *watch)
3635cf
+{
3635cf
+  return (watch->watched_fd->occurred);
3635cf
+}
3635cf
+
3635cf
+
3635cf
+/*
3635cf
+ * 'timeout_cb()' - Run a timed Avahi callback
3635cf
+ */
3635cf
+
3635cf
+static void
3635cf
+timeout_cb (cupsd_timeout_t *cupsd_timeout, void *userdata)
3635cf
+{
3635cf
+  AvahiTimeout *timeout = userdata;
3635cf
+  (timeout->callback) (timeout, timeout->userdata);
3635cf
+}
3635cf
+
3635cf
+
3635cf
+/*
3635cf
+ * 'timeout_new' - Set a wakeup time
3635cf
+ */
3635cf
+
3635cf
+static AvahiTimeout *
3635cf
+timeout_new (const AvahiPoll *api,
3635cf
+	     const struct timeval *tv,
3635cf
+	     AvahiTimeoutCallback callback,
3635cf
+	     void *userdata)
3635cf
+{
3635cf
+  AvahiTimeout *timeout;
3635cf
+  AvahiCupsPoll *cups_poll = api->userdata;
3635cf
+
3635cf
+  timeout = malloc(sizeof(AvahiTimeout));
3635cf
+  if (timeout == NULL)
3635cf
+    return (NULL);
3635cf
+
3635cf
+  timeout->cups_poll = cups_poll;
3635cf
+  timeout->callback = callback;
3635cf
+  timeout->userdata = userdata;
3635cf
+  timeout->cupsd_timeout = cupsdAddTimeout (tv,
3635cf
+					    (cupsd_timeoutfunc_t)timeout_cb,
3635cf
+					    timeout);
3635cf
+  cupsArrayAdd (cups_poll->timeouts, timeout);
3635cf
+  return (timeout);
3635cf
+}
3635cf
+
3635cf
+
3635cf
+/*
3635cf
+ * 'timeout_update' - Update the expiration time for a timeout
3635cf
+ */
3635cf
+
3635cf
+static void
3635cf
+timeout_update (AvahiTimeout *timeout,
3635cf
+		const struct timeval *tv)
3635cf
+{
3635cf
+  cupsdUpdateTimeout (timeout->cupsd_timeout, tv);
3635cf
+}
3635cf
+
3635cf
+
3635cf
+/*
3635cf
+ * ' timeout_free' - Free a timeout
3635cf
+ */
3635cf
+
3635cf
+static void
3635cf
+timeout_free (AvahiTimeout *timeout)
3635cf
+{
3635cf
+  cupsArrayRemove (timeout->cups_poll->timeouts, timeout);
3635cf
+  cupsdRemoveTimeout (timeout->cupsd_timeout);
3635cf
+  free (timeout);
3635cf
+}
3635cf
+
3635cf
+
3635cf
+/*
3635cf
+ * 'compare_watched_fds' - Compare watched file descriptors for array sorting
3635cf
+ */
3635cf
+static int
3635cf
+compare_watched_fds(cupsd_watched_fd_t *p0,
3635cf
+		    cupsd_watched_fd_t *p1)
3635cf
+{
3635cf
+  /*
3635cf
+   * Compare by fd (no two elements have the same fd)
3635cf
+   */
3635cf
+
3635cf
+  if (p0->fd == p1->fd)
3635cf
+    return 0;
3635cf
+
3635cf
+  return (p0->fd < p1->fd ? -1 : 1);
3635cf
+}
3635cf
+
3635cf
+
3635cf
+/*
3635cf
+ * 'avahi_cups_poll_new' - Create a new Avahi main loop object for CUPS
3635cf
+ */
3635cf
+
3635cf
+AvahiCupsPoll *
3635cf
+avahi_cups_poll_new (void)
3635cf
+{
3635cf
+  AvahiCupsPoll *cups_poll = malloc(sizeof(AvahiCupsPoll));
3635cf
+  if (cups_poll == NULL)
3635cf
+    return (NULL);
3635cf
+
3635cf
+  cups_poll->watched_fds = cupsArrayNew ((cups_array_func_t)compare_watched_fds,
3635cf
+					 NULL);
3635cf
+  cups_poll->timeouts = cupsArrayNew (NULL, NULL);
3635cf
+
3635cf
+  cups_poll->api.userdata = cups_poll;
3635cf
+  cups_poll->api.watch_new = watch_new;
3635cf
+  cups_poll->api.watch_free = watch_free;
3635cf
+  cups_poll->api.watch_update = watch_update;
3635cf
+  cups_poll->api.watch_get_events = watch_get_events;
3635cf
+
3635cf
+  cups_poll->api.timeout_new = timeout_new;
3635cf
+  cups_poll->api.timeout_update = timeout_update;
3635cf
+  cups_poll->api.timeout_free = timeout_free;
3635cf
+
3635cf
+  return (cups_poll);
3635cf
+}
3635cf
+
3635cf
+
3635cf
+/*
3635cf
+ * 'avahi_cups_poll_free' - Free an Avahi main loop object for CUPS
3635cf
+ */
3635cf
+void
3635cf
+avahi_cups_poll_free (AvahiCupsPoll *cups_poll)
3635cf
+{
3635cf
+  cupsd_watched_fd_t *watched_fd;
3635cf
+
3635cf
+  for (watched_fd = (cupsd_watched_fd_t*)cupsArrayFirst(cups_poll->watched_fds);
3635cf
+       watched_fd;
3635cf
+       watched_fd = (cupsd_watched_fd_t*)cupsArrayNext(cups_poll->watched_fds))
3635cf
+    cupsArrayClear (watched_fd->watches);
3635cf
+
3635cf
+  cupsArrayClear (cups_poll->watched_fds);
3635cf
+  cupsArrayClear (cups_poll->timeouts);
3635cf
+}
3635cf
+
3635cf
+
3635cf
+/*
3635cf
+ * 'avahi_cups_poll_get' - Get the abstract poll API structure
3635cf
+ */
3635cf
+
3635cf
+const AvahiPoll *
3635cf
+avahi_cups_poll_get (AvahiCupsPoll *cups_poll)
3635cf
+{
3635cf
+  return (&cups_poll->api);
3635cf
+}
3635cf
+
3635cf
+
3635cf
+#endif /* HAVE_AVAHI ... from top of file */
3635cf
+
3635cf
+/*
3635cf
+ * End of "$Id$".
3635cf
+ */
3635cf
diff -up cups-2.2.5/scheduler/avahi.h.avahi-no-threaded cups-2.2.5/scheduler/avahi.h
3635cf
--- cups-2.2.5/scheduler/avahi.h.avahi-no-threaded	2017-10-17 19:03:00.760881016 +0200
3635cf
+++ cups-2.2.5/scheduler/avahi.h	2017-10-17 19:03:00.760881016 +0200
3635cf
@@ -0,0 +1,69 @@
3635cf
+/*
3635cf
+ * "$Id$"
3635cf
+ *
3635cf
+ *   Avahi poll implementation for the CUPS scheduler.
3635cf
+ *
3635cf
+ *   Copyright (C) 2010, 2011 Red Hat, Inc.
3635cf
+ *   Authors:
3635cf
+ *    Tim Waugh <twaugh@redhat.com>
3635cf
+ *
3635cf
+ *   Redistribution and use in source and binary forms, with or without
3635cf
+ *   modification, are permitted provided that the following conditions
3635cf
+ *   are met:
3635cf
+ *
3635cf
+ *   Redistributions of source code must retain the above copyright
3635cf
+ *   notice, this list of conditions and the following disclaimer.
3635cf
+ *
3635cf
+ *   Redistributions in binary form must reproduce the above copyright
3635cf
+ *   notice, this list of conditions and the following disclaimer in the
3635cf
+ *   documentation and/or other materials provided with the distribution.
3635cf
+ *
3635cf
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
3635cf
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
3635cf
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
3635cf
+ *   FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
3635cf
+ *   COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
3635cf
+ *   INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
3635cf
+ *   (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
3635cf
+ *   SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3635cf
+ *   HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
3635cf
+ *   STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
3635cf
+ *   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
3635cf
+ *   OF THE POSSIBILITY OF SUCH DAMAGE.
3635cf
+ */
3635cf
+
3635cf
+#include <config.h>
3635cf
+
3635cf
+#ifdef HAVE_AVAHI
3635cf
+#  include <avahi-client/client.h>
3635cf
+#  include <avahi-client/publish.h>
3635cf
+#endif /* HAVE_AVAHI */
3635cf
+
3635cf
+#ifdef HAVE_AUTHORIZATION_H
3635cf
+#  include <Security/Authorization.h>
3635cf
+#endif /* HAVE_AUTHORIZATION_H */
3635cf
+
3635cf
+
3635cf
+#ifdef HAVE_AVAHI
3635cf
+typedef struct
3635cf
+{
3635cf
+    AvahiPoll api;
3635cf
+    cups_array_t *watched_fds;
3635cf
+    cups_array_t *timeouts;
3635cf
+} AvahiCupsPoll;
3635cf
+#endif /* HAVE_AVAHI */
3635cf
+
3635cf
+/*
3635cf
+ * Prototypes...
3635cf
+ */
3635cf
+
3635cf
+#ifdef HAVE_AVAHI
3635cf
+extern AvahiCupsPoll *	avahi_cups_poll_new(void);
3635cf
+extern void		avahi_cups_poll_free(AvahiCupsPoll *cups_poll);
3635cf
+extern const AvahiPoll *avahi_cups_poll_get(AvahiCupsPoll *cups_poll);
3635cf
+#endif /* HAVE_AVAHI */
3635cf
+
3635cf
+
3635cf
+/*
3635cf
+ * End of "$Id$".
3635cf
+ */
3635cf
diff -up cups-2.2.5/scheduler/cupsd.h.avahi-no-threaded cups-2.2.5/scheduler/cupsd.h
3635cf
--- cups-2.2.5/scheduler/cupsd.h.avahi-no-threaded	2017-10-13 20:22:26.000000000 +0200
3635cf
+++ cups-2.2.5/scheduler/cupsd.h	2017-10-17 19:03:00.760881016 +0200
3635cf
@@ -118,6 +118,7 @@ extern const char *cups_hstrerror(int);
3635cf
 #include "colorman.h"
3635cf
 #include "conf.h"
3635cf
 #include "banners.h"
3635cf
+#include "avahi.h"
3635cf
 #include "dirsvc.h"
3635cf
 #include "network.h"
3635cf
 #include "subscriptions.h"
3635cf
@@ -138,6 +139,15 @@ extern const char *cups_hstrerror(int);
3635cf
 
3635cf
 typedef void (*cupsd_selfunc_t)(void *data);
3635cf
 
3635cf
+#ifdef HAVE_AVAHI
3635cf
+/*
3635cf
+ * Timeout callback function type...
3635cf
+ */
3635cf
+
3635cf
+typedef struct _cupsd_timeout_s cupsd_timeout_t;
3635cf
+typedef void (*cupsd_timeoutfunc_t)(cupsd_timeout_t *timeout, void *data);
3635cf
+#endif /* HAVE_AVAHI */
3635cf
+
3635cf
 
3635cf
 /*
3635cf
  * Globals...
3635cf
@@ -162,6 +172,9 @@ VAR int			OnDemand	VALUE(0);
3635cf
 					/* Launched on demand */
3635cf
 #endif /* HAVE_ONDEMAND */
3635cf
 
3635cf
+#ifdef HAVE_AVAHI
3635cf
+VAR cups_array_t *Timeouts;		/* Timed callbacks for main loop */
3635cf
+#endif /* HAVE_AVAHI */
3635cf
 
3635cf
 /*
3635cf
  * Prototypes...
3635cf
@@ -224,3 +237,15 @@ extern void		cupsdStopSelect(void);
3635cf
 /* server.c */
3635cf
 extern void		cupsdStartServer(void);
3635cf
 extern void		cupsdStopServer(void);
3635cf
+
3635cf
+#ifdef HAVE_AVAHI
3635cf
+extern void     cupsdInitTimeouts(void);
3635cf
+extern cupsd_timeout_t *cupsdAddTimeout (const struct timeval *tv,
3635cf
+					 cupsd_timeoutfunc_t cb,
3635cf
+					 void *data);
3635cf
+extern cupsd_timeout_t *cupsdNextTimeout (long *delay);
3635cf
+extern void     cupsdRunTimeout (cupsd_timeout_t *timeout);
3635cf
+extern void     cupsdUpdateTimeout (cupsd_timeout_t *timeout,
3635cf
+				    const struct timeval *tv);
3635cf
+extern void     cupsdRemoveTimeout (cupsd_timeout_t *timeout);
3635cf
+#endif /* HAVE_AVAHI */
3635cf
\ No newline at end of file
3635cf
diff -up cups-2.2.5/scheduler/dirsvc.c.avahi-no-threaded cups-2.2.5/scheduler/dirsvc.c
3635cf
--- cups-2.2.5/scheduler/dirsvc.c.avahi-no-threaded	2017-10-13 20:22:26.000000000 +0200
3635cf
+++ cups-2.2.5/scheduler/dirsvc.c	2017-10-17 19:05:35.938592292 +0200
3635cf
@@ -193,7 +193,7 @@ cupsdStartBrowsing(void)
3635cf
     cupsdUpdateDNSSDName();
3635cf
 
3635cf
 #  else /* HAVE_AVAHI */
3635cf
-    if ((DNSSDMaster = avahi_threaded_poll_new()) == NULL)
3635cf
+    if ((DNSSDMaster = avahi_cups_poll_new()) == NULL)
3635cf
     {
3635cf
       cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to create DNS-SD thread.");
3635cf
 
3635cf
@@ -204,7 +204,7 @@ cupsdStartBrowsing(void)
3635cf
     {
3635cf
       int error;			/* Error code, if any */
3635cf
 
3635cf
-      DNSSDClient = avahi_client_new(avahi_threaded_poll_get(DNSSDMaster), AVAHI_CLIENT_NO_FAIL, dnssdClientCallback, NULL, &error);
3635cf
+      DNSSDClient = avahi_client_new(avahi_cups_poll_get(DNSSDMaster), AVAHI_CLIENT_NO_FAIL, dnssdClientCallback, NULL, &error);
3635cf
 
3635cf
       if (DNSSDClient == NULL)
3635cf
       {
3635cf
@@ -215,11 +215,9 @@ cupsdStartBrowsing(void)
3635cf
         if (FatalErrors & CUPSD_FATAL_BROWSE)
3635cf
 	  cupsdEndProcess(getpid(), 0);
3635cf
 
3635cf
-        avahi_threaded_poll_free(DNSSDMaster);
3635cf
+        avahi_cups_poll_free(DNSSDMaster);
3635cf
         DNSSDMaster = NULL;
3635cf
       }
3635cf
-      else
3635cf
-	avahi_threaded_poll_start(DNSSDMaster);
3635cf
     }
3635cf
 #  endif /* HAVE_DNSSD */
3635cf
   }
3635cf
@@ -635,7 +633,7 @@ dnssdClientCallback(
3635cf
 	  * Renew Avahi client...
3635cf
 	  */
3635cf
 
3635cf
-	  DNSSDClient = avahi_client_new(avahi_threaded_poll_get(DNSSDMaster), AVAHI_CLIENT_NO_FAIL, dnssdClientCallback, NULL, &error);
3635cf
+	  DNSSDClient = avahi_client_new(avahi_cups_poll_get(DNSSDMaster), AVAHI_CLIENT_NO_FAIL, dnssdClientCallback, NULL, &error);
3635cf
 
3635cf
 	  if (!DNSSDClient)
3635cf
 	  {
3635cf
@@ -701,13 +699,7 @@ dnssdDeregisterInstance(
3635cf
 #  else /* HAVE_AVAHI */
3635cf
   if (*srv)
3635cf
   {
3635cf
-    if (!from_callback)
3635cf
-      avahi_threaded_poll_lock(DNSSDMaster);
3635cf
-
3635cf
     avahi_entry_group_free(*srv);
3635cf
-
3635cf
-    if (!from_callback)
3635cf
-      avahi_threaded_poll_unlock(DNSSDMaster);
3635cf
   }
3635cf
 #  endif /* HAVE_DNSSD */
3635cf
 
3635cf
@@ -1029,16 +1021,10 @@ dnssdRegisterInstance(
3635cf
   (void)commit;
3635cf
 
3635cf
 #  else /* HAVE_AVAHI */
3635cf
-  if (!from_callback)
3635cf
-    avahi_threaded_poll_lock(DNSSDMaster);
3635cf
-
3635cf
   if (!*srv)
3635cf
     *srv = avahi_entry_group_new(DNSSDClient, dnssdRegisterCallback, NULL);
3635cf
   if (!*srv)
3635cf
   {
3635cf
-    if (!from_callback)
3635cf
-      avahi_threaded_poll_unlock(DNSSDMaster);
3635cf
-
3635cf
     cupsdLogMessage(CUPSD_LOG_WARN, "DNS-SD registration of \"%s\" failed: %s",
3635cf
                     name, dnssdErrorString(avahi_client_errno(DNSSDClient)));
3635cf
     return (0);
3635cf
@@ -1153,9 +1139,6 @@ dnssdRegisterInstance(
3635cf
       cupsdLogMessage(CUPSD_LOG_DEBUG, "DNS-SD commit of \"%s\" failed.",
3635cf
                       name);
3635cf
   }
3635cf
-
3635cf
-  if (!from_callback)
3635cf
-    avahi_threaded_poll_unlock(DNSSDMaster);
3635cf
 #  endif /* HAVE_DNSSD */
3635cf
 
3635cf
   if (error)
3635cf
@@ -1326,9 +1309,6 @@ dnssdStop(void)
3635cf
   DNSSDMaster = NULL;
3635cf
 
3635cf
 #  else /* HAVE_AVAHI */
3635cf
-  if (DNSSDMaster)
3635cf
-    avahi_threaded_poll_stop(DNSSDMaster);
3635cf
-
3635cf
   if (DNSSDClient)
3635cf
   {
3635cf
     avahi_client_free(DNSSDClient);
3635cf
@@ -1337,7 +1317,7 @@ dnssdStop(void)
3635cf
 
3635cf
   if (DNSSDMaster)
3635cf
   {
3635cf
-    avahi_threaded_poll_free(DNSSDMaster);
3635cf
+    avahi_cups_poll_free(DNSSDMaster);
3635cf
     DNSSDMaster = NULL;
3635cf
   }
3635cf
 #  endif /* HAVE_DNSSD */
3635cf
diff -up cups-2.2.5/scheduler/dirsvc.h.avahi-no-threaded cups-2.2.5/scheduler/dirsvc.h
3635cf
--- cups-2.2.5/scheduler/dirsvc.h.avahi-no-threaded	2017-10-13 20:22:26.000000000 +0200
3635cf
+++ cups-2.2.5/scheduler/dirsvc.h	2017-10-17 19:03:00.761881007 +0200
3635cf
@@ -49,7 +49,7 @@ VAR cups_array_t	*DNSSDPrinters	VALUE(NU
3635cf
 VAR DNSServiceRef	DNSSDMaster	VALUE(NULL);
3635cf
 					/* Master DNS-SD service reference */
3635cf
 #  else /* HAVE_AVAHI */
3635cf
-VAR AvahiThreadedPoll	*DNSSDMaster	VALUE(NULL);
3635cf
+VAR AvahiCupsPoll	*DNSSDMaster	VALUE(NULL);
3635cf
 					/* Master polling interface for Avahi */
3635cf
 VAR AvahiClient		*DNSSDClient	VALUE(NULL);
3635cf
 					/* Client information */
3635cf
diff -up cups-2.2.5/scheduler/main.c.avahi-no-threaded cups-2.2.5/scheduler/main.c
3635cf
--- cups-2.2.5/scheduler/main.c.avahi-no-threaded	2017-10-17 19:03:00.753881074 +0200
3635cf
+++ cups-2.2.5/scheduler/main.c	2017-10-17 19:03:00.761881007 +0200
3635cf
@@ -131,7 +131,10 @@ main(int  argc,				/* I - Number of comm
3635cf
   int			service_idle_exit;
3635cf
 					/* Idle exit on select timeout? */
3635cf
 #endif /* HAVE_ONDEMAND */
3635cf
-
3635cf
+#ifdef HAVE_AVAHI
3635cf
+  cupsd_timeout_t	*tmo;		/* Next scheduled timed callback */
3635cf
+  long			tmo_delay;	/* Time before it must be called */
3635cf
+#endif /* HAVE_AVAHI */
3635cf
 
3635cf
 #ifdef HAVE_GETEUID
3635cf
  /*
3635cf
@@ -610,6 +613,14 @@ main(int  argc,				/* I - Number of comm
3635cf
 
3635cf
   httpInitialize();
3635cf
 
3635cf
+#ifdef HAVE_AVAHI
3635cf
+ /*
3635cf
+  * Initialize timed callback structures.
3635cf
+  */
3635cf
+
3635cf
+  cupsdInitTimeouts();
3635cf
+#endif /* HAVE_AVAHI */
3635cf
+
3635cf
   cupsdStartServer();
3635cf
 
3635cf
  /*
3635cf
@@ -928,6 +939,16 @@ main(int  argc,				/* I - Number of comm
3635cf
     }
3635cf
 #endif /* __APPLE__ */
3635cf
 
3635cf
+#ifdef HAVE_AVAHI
3635cf
+   /*
3635cf
+    * If a timed callback is due, run it.
3635cf
+    */
3635cf
+
3635cf
+    tmo = cupsdNextTimeout (&tmo_delay);
3635cf
+    if (tmo && tmo_delay == 0)
3635cf
+      cupsdRunTimeout (tmo);
3635cf
+#endif /* HAVE_AVAHI */
3635cf
+
3635cf
 #ifndef __APPLE__
3635cf
    /*
3635cf
     * Update the network interfaces once a minute...
3635cf
@@ -1632,6 +1653,10 @@ select_timeout(int fds)			/* I - Number
3635cf
   cupsd_job_t		*job;		/* Job information */
3635cf
   cupsd_printer_t       *printer;       /* Printer information */
3635cf
   const char		*why;		/* Debugging aid */
3635cf
+#ifdef HAVE_AVAHI
3635cf
+  cupsd_timeout_t	*tmo;		/* Timed callback */
3635cf
+  long			tmo_delay;	/* Seconds before calling it */
3635cf
+#endif /* HAVE_AVAHI */
3635cf
 
3635cf
 
3635cf
   cupsdLogMessage(CUPSD_LOG_DEBUG2, "select_timeout: JobHistoryUpdate=%ld",
3635cf
@@ -1677,6 +1702,19 @@ select_timeout(int fds)			/* I - Number
3635cf
   }
3635cf
 #endif /* __APPLE__ */
3635cf
 
3635cf
+#ifdef HAVE_AVAHI
3635cf
+ /*
3635cf
+  * See if there are any scheduled timed callbacks to run.
3635cf
+  */
3635cf
+
3635cf
+  if ((tmo = cupsdNextTimeout(&tmo_delay)) != NULL &&
3635cf
+      (now + tmo_delay) < timeout)
3635cf
+  {
3635cf
+    timeout = tmo_delay;
3635cf
+    why = "run a timed callback";
3635cf
+  }
3635cf
+#endif /* HAVE_AVAHI */
3635cf
+
3635cf
  /*
3635cf
   * Check whether we are accepting new connections...
3635cf
   */
3635cf
diff -up cups-2.2.5/scheduler/Makefile.avahi-no-threaded cups-2.2.5/scheduler/Makefile
3635cf
--- cups-2.2.5/scheduler/Makefile.avahi-no-threaded	2017-10-13 20:22:26.000000000 +0200
3635cf
+++ cups-2.2.5/scheduler/Makefile	2017-10-17 19:03:00.762880999 +0200
3635cf
@@ -15,6 +15,7 @@ include ../Makedefs
3635cf
 
3635cf
 CUPSDOBJS =	\
3635cf
 		auth.o \
3635cf
+		avahi.o \
3635cf
 		banners.o \
3635cf
 		cert.o \
3635cf
 		classes.o \
3635cf
@@ -38,7 +39,8 @@ CUPSDOBJS =	\
3635cf
 		server.o \
3635cf
 		statbuf.o \
3635cf
 		subscriptions.o \
3635cf
-		sysman.o
3635cf
+		sysman.o \
3635cf
+		timeout.o
3635cf
 LIBOBJS =	\
3635cf
 		filter.o \
3635cf
 		mime.o \
3635cf
diff -up cups-2.2.5/scheduler/timeout.c.avahi-no-threaded cups-2.2.5/scheduler/timeout.c
3635cf
--- cups-2.2.5/scheduler/timeout.c.avahi-no-threaded	2017-10-17 19:03:00.762880999 +0200
3635cf
+++ cups-2.2.5/scheduler/timeout.c	2017-10-17 19:03:00.762880999 +0200
3635cf
@@ -0,0 +1,235 @@
3635cf
+/*
3635cf
+ * "$Id$"
3635cf
+ *
3635cf
+ *   Timeout functions for the Common UNIX Printing System (CUPS).
3635cf
+ *
3635cf
+ *   Copyright (C) 2010, 2011 Red Hat, Inc.
3635cf
+ *   Authors:
3635cf
+ *     Tim Waugh <twaugh@redhat.com>
3635cf
+ *
3635cf
+ *   Redistribution and use in source and binary forms, with or without
3635cf
+ *   modification, are permitted provided that the following conditions
3635cf
+ *   are met:
3635cf
+ *
3635cf
+ *   Redistributions of source code must retain the above copyright
3635cf
+ *   notice, this list of conditions and the following disclaimer.
3635cf
+ *
3635cf
+ *   Redistributions in binary form must reproduce the above copyright
3635cf
+ *   notice, this list of conditions and the following disclaimer in the
3635cf
+ *   documentation and/or other materials provided with the distribution.
3635cf
+ *
3635cf
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
3635cf
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
3635cf
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
3635cf
+ *   FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
3635cf
+ *   COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
3635cf
+ *   INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
3635cf
+ *   (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
3635cf
+ *   SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3635cf
+ *   HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
3635cf
+ *   STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
3635cf
+ *   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
3635cf
+ *   OF THE POSSIBILITY OF SUCH DAMAGE.
3635cf
+ *
3635cf
+ * Contents:
3635cf
+ *
3635cf
+ *   cupsdInitTimeouts()  - Initialise timeout structure.
3635cf
+ *   cupsdAddTimeout()    - Add a timed callback.
3635cf
+ *   cupsdNextTimeout()   - Find the next enabled timed callback.
3635cf
+ *   cupsdUpdateTimeout() - Adjust the time of a timed callback or disable it.
3635cf
+ *   cupsdRemoveTimeout() - Discard a timed callback.
3635cf
+ *   compare_timeouts()   - Compare timed callbacks for array sorting.
3635cf
+ */
3635cf
+
3635cf
+#include <config.h>
3635cf
+
3635cf
+#ifdef HAVE_AVAHI /* Applies to entire file... */
3635cf
+
3635cf
+/*
3635cf
+ * Include necessary headers...
3635cf
+ */
3635cf
+
3635cf
+#include "cupsd.h"
3635cf
+
3635cf
+#if defined(HAVE_MALLOC_H) && defined(HAVE_MALLINFO)
3635cf
+#  include <malloc.h>
3635cf
+#endif /* HAVE_MALLOC_H && HAVE_MALLINFO */
3635cf
+
3635cf
+#ifdef HAVE_AVAHI
3635cf
+#  include <avahi-common/timeval.h>
3635cf
+#endif /* HAVE_AVAHI */
3635cf
+
3635cf
+
3635cf
+struct _cupsd_timeout_s
3635cf
+{
3635cf
+  struct timeval when;
3635cf
+  int enabled;
3635cf
+  cupsd_timeoutfunc_t callback;
3635cf
+  void *data;
3635cf
+};
3635cf
+
3635cf
+/*
3635cf
+ * Local functions...
3635cf
+ */
3635cf
+
3635cf
+/*
3635cf
+ * 'compare_timeouts()' - Compare timed callbacks for array sorting.
3635cf
+ */
3635cf
+
3635cf
+static int
3635cf
+compare_addrs (void *p0, void *p1)
3635cf
+{
3635cf
+  if (p0 == p1)
3635cf
+    return (0);
3635cf
+  if (p0 < p1)
3635cf
+    return (-1);
3635cf
+  return (1);
3635cf
+}
3635cf
+
3635cf
+static int
3635cf
+compare_timeouts (cupsd_timeout_t *p0, cupsd_timeout_t *p1)
3635cf
+{
3635cf
+  int addrsdiff = compare_addrs (p0, p1);
3635cf
+  int tvdiff;
3635cf
+
3635cf
+  if (addrsdiff == 0)
3635cf
+    return (0);
3635cf
+
3635cf
+  if (!p0->enabled || !p1->enabled)
3635cf
+  {
3635cf
+    if (!p0->enabled && !p1->enabled)
3635cf
+      return (addrsdiff);
3635cf
+
3635cf
+    return (p0->enabled ? -1 : 1);
3635cf
+  }
3635cf
+
3635cf
+  tvdiff = avahi_timeval_compare (&p0->when, &p1->when);
3635cf
+  if (tvdiff != 0)
3635cf
+    return (tvdiff);
3635cf
+
3635cf
+  return (addrsdiff);
3635cf
+}
3635cf
+
3635cf
+
3635cf
+/*
3635cf
+ * 'cupsdInitTimeouts()' - Initialise timeout structures.
3635cf
+ */
3635cf
+
3635cf
+void
3635cf
+cupsdInitTimeouts(void)
3635cf
+{
3635cf
+  Timeouts = cupsArrayNew ((cups_array_func_t)compare_timeouts, NULL);
3635cf
+}
3635cf
+
3635cf
+
3635cf
+/*
3635cf
+ * 'cupsdAddTimeout()' - Add a timed callback.
3635cf
+ */
3635cf
+
3635cf
+cupsd_timeout_t *				/* O - Timeout handle */
3635cf
+cupsdAddTimeout(const struct timeval *tv,	/* I - Absolute time */
3635cf
+		cupsd_timeoutfunc_t cb,		/* I - Callback function */
3635cf
+		void *data)			/* I - User data */
3635cf
+{
3635cf
+  cupsd_timeout_t *timeout;
3635cf
+
3635cf
+  timeout = malloc (sizeof(cupsd_timeout_t));
3635cf
+  if (timeout != NULL)
3635cf
+  {
3635cf
+    timeout->enabled = (tv != NULL);
3635cf
+    if (tv)
3635cf
+    {
3635cf
+      timeout->when.tv_sec = tv->tv_sec;
3635cf
+      timeout->when.tv_usec = tv->tv_usec;
3635cf
+    }
3635cf
+
3635cf
+    timeout->callback = cb;
3635cf
+    timeout->data = data;
3635cf
+    cupsArrayAdd (Timeouts, timeout);
3635cf
+  }
3635cf
+
3635cf
+  return timeout;
3635cf
+}
3635cf
+
3635cf
+
3635cf
+/*
3635cf
+ * 'cupsdNextTimeout()' - Find the next enabled timed callback.
3635cf
+ */
3635cf
+
3635cf
+cupsd_timeout_t *		/* O - Next enabled timeout or NULL */
3635cf
+cupsdNextTimeout(long *delay)	/* O - Seconds before scheduled */
3635cf
+{
3635cf
+  cupsd_timeout_t *first = cupsArrayFirst (Timeouts);
3635cf
+  struct timeval curtime;
3635cf
+
3635cf
+  if (first && !first->enabled)
3635cf
+    first = NULL;
3635cf
+
3635cf
+  if (first && delay)
3635cf
+  {
3635cf
+    gettimeofday (&curtime, NULL);
3635cf
+    if (avahi_timeval_compare (&curtime, &first->when) > 0)
3635cf
+    {
3635cf
+      *delay = 0;
3635cf
+    } else {
3635cf
+      *delay = 1 + first->when.tv_sec - curtime.tv_sec;
3635cf
+      if (first->when.tv_usec < curtime.tv_usec)
3635cf
+	(*delay)--;
3635cf
+    }
3635cf
+  }
3635cf
+
3635cf
+  return (first);
3635cf
+}
3635cf
+
3635cf
+
3635cf
+/*
3635cf
+ * 'cupsdRunTimeout()' - Run a timed callback.
3635cf
+ */
3635cf
+
3635cf
+void
3635cf
+cupsdRunTimeout(cupsd_timeout_t *timeout)	/* I - Timeout */
3635cf
+{
3635cf
+  if (!timeout)
3635cf
+    return;
3635cf
+  timeout->enabled = 0;
3635cf
+  if (!timeout->callback)
3635cf
+    return;
3635cf
+  timeout->callback (timeout, timeout->data);
3635cf
+}
3635cf
+
3635cf
+/*
3635cf
+ * 'cupsdUpdateTimeout()' - Adjust the time of a timed callback or disable it.
3635cf
+ */
3635cf
+
3635cf
+void
3635cf
+cupsdUpdateTimeout(cupsd_timeout_t *timeout,	/* I - Timeout */
3635cf
+		   const struct timeval *tv)	/* I - Absolute time or NULL */
3635cf
+{
3635cf
+  cupsArrayRemove (Timeouts, timeout);
3635cf
+  timeout->enabled = (tv != NULL);
3635cf
+  if (tv)
3635cf
+  {
3635cf
+    timeout->when.tv_sec = tv->tv_sec;
3635cf
+    timeout->when.tv_usec = tv->tv_usec;
3635cf
+  }
3635cf
+  cupsArrayAdd (Timeouts, timeout);
3635cf
+}
3635cf
+
3635cf
+
3635cf
+/*
3635cf
+ * 'cupsdRemoveTimeout()' - Discard a timed callback.
3635cf
+ */
3635cf
+
3635cf
+void
3635cf
+cupsdRemoveTimeout(cupsd_timeout_t *timeout)	/* I - Timeout */
3635cf
+{
3635cf
+  cupsArrayRemove (Timeouts, timeout);
3635cf
+  free (timeout);
3635cf
+}
3635cf
+
3635cf
+
3635cf
+#endif /* HAVE_AVAHI ... from top of file */
3635cf
+
3635cf
+/*
3635cf
+ * End of "$Id$".
3635cf
+ */