]> git.pld-linux.org Git - packages/cups.git/blob - cups-avahi-no-threaded.patch
Release 4 (by relup.sh)
[packages/cups.git] / cups-avahi-no-threaded.patch
1 diff -urNp -x '*.orig' cups-2.3.3.org/scheduler/Makefile cups-2.3.3/scheduler/Makefile
2 --- cups-2.3.3.org/scheduler/Makefile   2020-04-27 20:04:29.000000000 +0200
3 +++ cups-2.3.3/scheduler/Makefile       2021-04-20 22:45:53.873155054 +0200
4 @@ -12,6 +12,7 @@ include ../Makedefs
5  
6  CUPSDOBJS =    \
7                 auth.o \
8 +               avahi.o \
9                 banners.o \
10                 cert.o \
11                 classes.o \
12 @@ -35,7 +36,8 @@ CUPSDOBJS =   \
13                 server.o \
14                 statbuf.o \
15                 subscriptions.o \
16 -               sysman.o
17 +               sysman.o \
18 +               timeout.o
19  LIBOBJS =      \
20                 filter.o \
21                 mime.o \
22 diff -urNp -x '*.orig' cups-2.3.3.org/scheduler/avahi.c cups-2.3.3/scheduler/avahi.c
23 --- cups-2.3.3.org/scheduler/avahi.c    1970-01-01 01:00:00.000000000 +0100
24 +++ cups-2.3.3/scheduler/avahi.c        2021-04-20 22:45:53.873155054 +0200
25 @@ -0,0 +1,441 @@
26 +/*
27 + * "$Id$"
28 + *
29 + *   Avahi poll implementation for the CUPS scheduler.
30 + *
31 + *   Copyright (C) 2010, 2011 Red Hat, Inc.
32 + *   Authors:
33 + *    Tim Waugh <twaugh@redhat.com>
34 + *
35 + *   Redistribution and use in source and binary forms, with or without
36 + *   modification, are permitted provided that the following conditions
37 + *   are met:
38 + *
39 + *   Redistributions of source code must retain the above copyright
40 + *   notice, this list of conditions and the following disclaimer.
41 + *
42 + *   Redistributions in binary form must reproduce the above copyright
43 + *   notice, this list of conditions and the following disclaimer in the
44 + *   documentation and/or other materials provided with the distribution.
45 + *
46 + *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
47 + *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
48 + *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
49 + *   FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
50 + *   COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
51 + *   INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
52 + *   (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
53 + *   SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
54 + *   HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
55 + *   STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
56 + *   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
57 + *   OF THE POSSIBILITY OF SUCH DAMAGE.
58 + *
59 + * Contents:
60 + *
61 + *   watch_read_cb         - Read callback for file descriptor
62 + *   watch_write_cb        - Write callback for file descriptor
63 + *   watched_fd_add_select() - Call cupsdAddSelect() as needed
64 + *   watch_new()           - Create a new file descriptor watch
65 + *   watch_free()          - Free a file descriptor watch
66 + *   watch_update()        - Update watched events for a file descriptor
67 + *   watch_get_events()    - Get events that happened for a file descriptor
68 + *   timeout_cb()          - Run a timed Avahi callback
69 + *   timeout_new()         - Set a wakeup time
70 + *   timeout_update()      - Update the expiration time for a timeout
71 + *   timeout_free()        - Free a timeout
72 + *   compare_watched_fds() - Compare watched file descriptors for array sorting
73 + *   avahi_cups_poll_new() - Create a new Avahi main loop object for CUPS
74 + *   avahi_cups_poll_free() - Free an Avahi main loop object for CUPS
75 + *   avahi_cups_poll_get() - Get the abstract poll API structure
76 + */
77 +
78 +#include <config.h>
79 +
80 +#ifdef HAVE_AVAHI /* Applies to entire file... */
81 +
82 +/*
83 + * Include necessary headers...
84 + */
85 +
86 +#include "cupsd.h"
87 +
88 +#if defined(HAVE_MALLOC_H) && defined(HAVE_MALLINFO)
89 +#  include <malloc.h>
90 +#endif /* HAVE_MALLOC_H && HAVE_MALLINFO */
91 +
92 +#ifdef HAVE_AVAHI
93 +#  include <avahi-common/timeval.h>
94 +#endif /* HAVE_AVAHI */
95 +
96 +
97 +typedef struct
98 +{
99 +  AvahiCupsPoll *cups_poll;
100 +
101 +  int fd;
102 +  AvahiWatchEvent occurred;
103 +  cups_array_t *watches;
104 +} cupsd_watched_fd_t;
105 +
106 +struct AvahiWatch
107 +{
108 +  cupsd_watched_fd_t *watched_fd;
109 +
110 +  AvahiWatchEvent events;
111 +  AvahiWatchCallback callback;
112 +  void *userdata;
113 +};
114 +
115 +struct AvahiTimeout
116 +{
117 +  AvahiCupsPoll *cups_poll;
118 +  AvahiTimeoutCallback callback;
119 +  void *userdata;
120 +  cupsd_timeout_t *cupsd_timeout;
121 +};
122 +
123 +/*
124 + * Local functions...
125 + */
126 +
127 +static AvahiWatch *    watch_new(const AvahiPoll *api,
128 +                                 int fd,
129 +                                 AvahiWatchEvent events,
130 +                                 AvahiWatchCallback callback,
131 +                                 void *userdata);
132 +static void            watch_free(AvahiWatch *watch);
133 +static void            watch_update(AvahiWatch *watch,
134 +                                    AvahiWatchEvent events);
135 +static AvahiWatchEvent watch_get_events(AvahiWatch *watch);
136 +
137 +
138 +/*
139 + * 'watch_read_cb' - Read callback for file descriptor
140 + */
141 +
142 +static void
143 +watch_read_cb (void *userdata)
144 +{
145 +  AvahiWatch *watch;
146 +  cupsd_watched_fd_t *watched_fd = userdata;
147 +  watched_fd->occurred |= AVAHI_WATCH_IN;
148 +  for (watch = (AvahiWatch *)cupsArrayFirst(watched_fd->watches);
149 +       watch;
150 +       watch = (AvahiWatch *)cupsArrayNext(watched_fd->watches))
151 +  {
152 +    if (watch->events & watched_fd->occurred)
153 +    {
154 +      (watch->callback) (watch, watched_fd->fd,
155 +                        AVAHI_WATCH_IN, watch->userdata);
156 +      watched_fd->occurred &= ~AVAHI_WATCH_IN;
157 +      break;
158 +    }
159 +  }
160 +}
161 +
162 +
163 +/*
164 + * 'watch_write_cb' - Write callback for file descriptor
165 + */
166 +
167 +static void
168 +watch_write_cb (void *userdata)
169 +{
170 +  AvahiWatch *watch;
171 +  cupsd_watched_fd_t *watched_fd = userdata;
172 +  watched_fd->occurred |= AVAHI_WATCH_OUT;
173 +  for (watch = (AvahiWatch *)cupsArrayFirst(watched_fd->watches);
174 +       watch;
175 +       watch = (AvahiWatch *)cupsArrayNext(watched_fd->watches))
176 +  {
177 +    if (watch->events & watched_fd->occurred)
178 +    {
179 +      (watch->callback) (watch, watched_fd->fd,
180 +                        AVAHI_WATCH_OUT, watch->userdata);
181 +      watched_fd->occurred &= ~AVAHI_WATCH_OUT;
182 +      break;
183 +    }
184 +  }
185 +}
186 +
187 +
188 +/*
189 + * 'watched_fd_add_select' - Call cupsdAddSelect() as needed
190 + */
191 +
192 +static int                                             /* O - Watches? */
193 +watched_fd_add_select (cupsd_watched_fd_t *watched_fd)
194 +{
195 +  AvahiWatch *watch;
196 +  cupsd_selfunc_t read_cb = NULL, write_cb = NULL;
197 +  int any_watches = 0;
198 +
199 +  for (watch = (AvahiWatch *)cupsArrayFirst(watched_fd->watches);
200 +       watch;
201 +       watch = (AvahiWatch *)cupsArrayNext(watched_fd->watches))
202 +  {
203 +    any_watches = 1;
204 +    if (watch->events & (AVAHI_WATCH_IN |
205 +                            AVAHI_WATCH_ERR |
206 +                            AVAHI_WATCH_HUP))
207 +    {
208 +      read_cb = (cupsd_selfunc_t)watch_read_cb;
209 +      if (write_cb != NULL)
210 +       break;
211 +    }
212 +
213 +    if (watch->events & AVAHI_WATCH_OUT)
214 +    {
215 +      write_cb = (cupsd_selfunc_t)watch_write_cb;
216 +      if (read_cb != NULL)
217 +       break;
218 +    }
219 +  }
220 +
221 +  if (read_cb || write_cb)
222 +    cupsdAddSelect (watched_fd->fd, read_cb, write_cb, watched_fd);
223 +  else
224 +    cupsdRemoveSelect (watched_fd->fd);
225 +
226 +  return (any_watches);
227 +}
228 +
229 +/*
230 + * 'watch_new' - Create a new file descriptor watch
231 + */
232 +
233 +static AvahiWatch *
234 +watch_new (const AvahiPoll *api,
235 +          int fd,
236 +          AvahiWatchEvent events,
237 +          AvahiWatchCallback callback,
238 +          void *userdata)
239 +{
240 +  cupsd_watched_fd_t key, *watched_fd;
241 +  AvahiCupsPoll *cups_poll = api->userdata;
242 +  AvahiWatch *watch = malloc(sizeof(AvahiWatch));
243 +  if (watch == NULL)
244 +    return (NULL);
245 +
246 +  watch->events = events;
247 +  watch->callback = callback;
248 +  watch->userdata = userdata;
249 +
250 +  key.fd = fd;
251 +  watched_fd = cupsArrayFind (cups_poll->watched_fds, &key);
252 +  if (watched_fd == NULL)
253 +  {
254 +    watched_fd = malloc(sizeof(cupsd_watched_fd_t));
255 +    if (watched_fd == NULL)
256 +    {
257 +      free (watch);
258 +      return (NULL);
259 +    }
260 +
261 +    watched_fd->fd = fd;
262 +    watched_fd->occurred = 0;
263 +    watched_fd->cups_poll = cups_poll;
264 +    watched_fd->watches = cupsArrayNew (NULL, NULL);
265 +    cupsArrayAdd (cups_poll->watched_fds, watched_fd);
266 +  }
267 +
268 +  watch->watched_fd = watched_fd;
269 +  cupsArrayAdd(watched_fd->watches, watch);
270 +  watched_fd_add_select (watched_fd);
271 +  return (watch);
272 +}
273 +
274 +
275 +/*
276 + * 'watch_free' - Free a file descriptor watch
277 + */
278 +
279 +static void
280 +watch_free (AvahiWatch *watch)
281 +{
282 +  cupsd_watched_fd_t *watched_fd = watch->watched_fd;
283 +  AvahiCupsPoll *cups_poll = watched_fd->cups_poll;
284 +
285 +  cupsArrayRemove (watched_fd->watches, watch);
286 +  free (watch);
287 +
288 +  if (!watched_fd_add_select (watched_fd))
289 +  {
290 +    /* No more watches */
291 +    cupsArrayRemove (cups_poll->watched_fds, watched_fd);
292 +    free (watched_fd);
293 +  }
294 +}
295 +
296 +
297 +/*
298 + * 'watch_update' - Update watched events for a file descriptor
299 + */
300 +
301 +static void
302 +watch_update (AvahiWatch *watch,
303 +             AvahiWatchEvent events)
304 +{
305 +  watch->events = events;
306 +  watched_fd_add_select (watch->watched_fd);
307 +}
308 +
309 +
310 +/*
311 + * 'watch_get_events' - Get events that happened for a file descriptor
312 + */
313 +
314 +static AvahiWatchEvent
315 +watch_get_events (AvahiWatch *watch)
316 +{
317 +  return (watch->watched_fd->occurred);
318 +}
319 +
320 +
321 +/*
322 + * 'timeout_cb()' - Run a timed Avahi callback
323 + */
324 +
325 +static void
326 +timeout_cb (cupsd_timeout_t *cupsd_timeout, void *userdata)
327 +{
328 +  AvahiTimeout *timeout = userdata;
329 +  (timeout->callback) (timeout, timeout->userdata);
330 +}
331 +
332 +
333 +/*
334 + * 'timeout_new' - Set a wakeup time
335 + */
336 +
337 +static AvahiTimeout *
338 +timeout_new (const AvahiPoll *api,
339 +            const struct timeval *tv,
340 +            AvahiTimeoutCallback callback,
341 +            void *userdata)
342 +{
343 +  AvahiTimeout *timeout;
344 +  AvahiCupsPoll *cups_poll = api->userdata;
345 +
346 +  timeout = malloc(sizeof(AvahiTimeout));
347 +  if (timeout == NULL)
348 +    return (NULL);
349 +
350 +  timeout->cups_poll = cups_poll;
351 +  timeout->callback = callback;
352 +  timeout->userdata = userdata;
353 +  timeout->cupsd_timeout = cupsdAddTimeout (tv,
354 +                                           (cupsd_timeoutfunc_t)timeout_cb,
355 +                                           timeout);
356 +  cupsArrayAdd (cups_poll->timeouts, timeout);
357 +  return (timeout);
358 +}
359 +
360 +
361 +/*
362 + * 'timeout_update' - Update the expiration time for a timeout
363 + */
364 +
365 +static void
366 +timeout_update (AvahiTimeout *timeout,
367 +               const struct timeval *tv)
368 +{
369 +  cupsdUpdateTimeout (timeout->cupsd_timeout, tv);
370 +}
371 +
372 +
373 +/*
374 + * ' timeout_free' - Free a timeout
375 + */
376 +
377 +static void
378 +timeout_free (AvahiTimeout *timeout)
379 +{
380 +  cupsArrayRemove (timeout->cups_poll->timeouts, timeout);
381 +  cupsdRemoveTimeout (timeout->cupsd_timeout);
382 +  free (timeout);
383 +}
384 +
385 +
386 +/*
387 + * 'compare_watched_fds' - Compare watched file descriptors for array sorting
388 + */
389 +static int
390 +compare_watched_fds(cupsd_watched_fd_t *p0,
391 +                   cupsd_watched_fd_t *p1)
392 +{
393 +  /*
394 +   * Compare by fd (no two elements have the same fd)
395 +   */
396 +
397 +  if (p0->fd == p1->fd)
398 +    return 0;
399 +
400 +  return (p0->fd < p1->fd ? -1 : 1);
401 +}
402 +
403 +
404 +/*
405 + * 'avahi_cups_poll_new' - Create a new Avahi main loop object for CUPS
406 + */
407 +
408 +AvahiCupsPoll *
409 +avahi_cups_poll_new (void)
410 +{
411 +  AvahiCupsPoll *cups_poll = malloc(sizeof(AvahiCupsPoll));
412 +  if (cups_poll == NULL)
413 +    return (NULL);
414 +
415 +  cups_poll->watched_fds = cupsArrayNew ((cups_array_func_t)compare_watched_fds,
416 +                                        NULL);
417 +  cups_poll->timeouts = cupsArrayNew (NULL, NULL);
418 +
419 +  cups_poll->api.userdata = cups_poll;
420 +  cups_poll->api.watch_new = watch_new;
421 +  cups_poll->api.watch_free = watch_free;
422 +  cups_poll->api.watch_update = watch_update;
423 +  cups_poll->api.watch_get_events = watch_get_events;
424 +
425 +  cups_poll->api.timeout_new = timeout_new;
426 +  cups_poll->api.timeout_update = timeout_update;
427 +  cups_poll->api.timeout_free = timeout_free;
428 +
429 +  return (cups_poll);
430 +}
431 +
432 +
433 +/*
434 + * 'avahi_cups_poll_free' - Free an Avahi main loop object for CUPS
435 + */
436 +void
437 +avahi_cups_poll_free (AvahiCupsPoll *cups_poll)
438 +{
439 +  cupsd_watched_fd_t *watched_fd;
440 +
441 +  for (watched_fd = (cupsd_watched_fd_t*)cupsArrayFirst(cups_poll->watched_fds);
442 +       watched_fd;
443 +       watched_fd = (cupsd_watched_fd_t*)cupsArrayNext(cups_poll->watched_fds))
444 +    cupsArrayClear (watched_fd->watches);
445 +
446 +  cupsArrayClear (cups_poll->watched_fds);
447 +  cupsArrayClear (cups_poll->timeouts);
448 +}
449 +
450 +
451 +/*
452 + * 'avahi_cups_poll_get' - Get the abstract poll API structure
453 + */
454 +
455 +const AvahiPoll *
456 +avahi_cups_poll_get (AvahiCupsPoll *cups_poll)
457 +{
458 +  return (&cups_poll->api);
459 +}
460 +
461 +
462 +#endif /* HAVE_AVAHI ... from top of file */
463 +
464 +/*
465 + * End of "$Id$".
466 + */
467 diff -urNp -x '*.orig' cups-2.3.3.org/scheduler/avahi.h cups-2.3.3/scheduler/avahi.h
468 --- cups-2.3.3.org/scheduler/avahi.h    1970-01-01 01:00:00.000000000 +0100
469 +++ cups-2.3.3/scheduler/avahi.h        2021-04-20 22:45:53.873155054 +0200
470 @@ -0,0 +1,69 @@
471 +/*
472 + * "$Id$"
473 + *
474 + *   Avahi poll implementation for the CUPS scheduler.
475 + *
476 + *   Copyright (C) 2010, 2011 Red Hat, Inc.
477 + *   Authors:
478 + *    Tim Waugh <twaugh@redhat.com>
479 + *
480 + *   Redistribution and use in source and binary forms, with or without
481 + *   modification, are permitted provided that the following conditions
482 + *   are met:
483 + *
484 + *   Redistributions of source code must retain the above copyright
485 + *   notice, this list of conditions and the following disclaimer.
486 + *
487 + *   Redistributions in binary form must reproduce the above copyright
488 + *   notice, this list of conditions and the following disclaimer in the
489 + *   documentation and/or other materials provided with the distribution.
490 + *
491 + *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
492 + *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
493 + *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
494 + *   FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
495 + *   COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
496 + *   INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
497 + *   (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
498 + *   SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
499 + *   HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
500 + *   STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
501 + *   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
502 + *   OF THE POSSIBILITY OF SUCH DAMAGE.
503 + */
504 +
505 +#include <config.h>
506 +
507 +#ifdef HAVE_AVAHI
508 +#  include <avahi-client/client.h>
509 +#  include <avahi-client/publish.h>
510 +#endif /* HAVE_AVAHI */
511 +
512 +#ifdef HAVE_AUTHORIZATION_H
513 +#  include <Security/Authorization.h>
514 +#endif /* HAVE_AUTHORIZATION_H */
515 +
516 +
517 +#ifdef HAVE_AVAHI
518 +typedef struct
519 +{
520 +    AvahiPoll api;
521 +    cups_array_t *watched_fds;
522 +    cups_array_t *timeouts;
523 +} AvahiCupsPoll;
524 +#endif /* HAVE_AVAHI */
525 +
526 +/*
527 + * Prototypes...
528 + */
529 +
530 +#ifdef HAVE_AVAHI
531 +extern AvahiCupsPoll * avahi_cups_poll_new(void);
532 +extern void            avahi_cups_poll_free(AvahiCupsPoll *cups_poll);
533 +extern const AvahiPoll *avahi_cups_poll_get(AvahiCupsPoll *cups_poll);
534 +#endif /* HAVE_AVAHI */
535 +
536 +
537 +/*
538 + * End of "$Id$".
539 + */
540 diff -urNp -x '*.orig' cups-2.3.3.org/scheduler/cupsd.h cups-2.3.3/scheduler/cupsd.h
541 --- cups-2.3.3.org/scheduler/cupsd.h    2020-04-27 20:04:29.000000000 +0200
542 +++ cups-2.3.3/scheduler/cupsd.h        2021-04-20 22:45:53.873155054 +0200
543 @@ -115,6 +115,7 @@ extern const char *cups_hstrerror(int);
544  #include "colorman.h"
545  #include "conf.h"
546  #include "banners.h"
547 +#include "avahi.h"
548  #include "dirsvc.h"
549  #include "network.h"
550  #include "subscriptions.h"
551 @@ -135,6 +136,15 @@ extern const char *cups_hstrerror(int);
552  
553  typedef void (*cupsd_selfunc_t)(void *data);
554  
555 +#ifdef HAVE_AVAHI
556 +/*
557 + * Timeout callback function type...
558 + */
559 +
560 +typedef struct _cupsd_timeout_s cupsd_timeout_t;
561 +typedef void (*cupsd_timeoutfunc_t)(cupsd_timeout_t *timeout, void *data);
562 +#endif /* HAVE_AVAHI */
563 +
564  
565  /*
566   * Globals...
567 @@ -159,6 +169,9 @@ VAR int                     OnDemand        VALUE(0);
568                                         /* Launched on demand */
569  #endif /* HAVE_ONDEMAND */
570  
571 +#ifdef HAVE_AVAHI
572 +VAR cups_array_t *Timeouts;            /* Timed callbacks for main loop */
573 +#endif /* HAVE_AVAHI */
574  
575  /*
576   * Prototypes...
577 @@ -220,3 +233,15 @@ extern void                cupsdStopSelect(void);
578  /* server.c */
579  extern void            cupsdStartServer(void);
580  extern void            cupsdStopServer(void);
581 +
582 +#ifdef HAVE_AVAHI
583 +extern void     cupsdInitTimeouts(void);
584 +extern cupsd_timeout_t *cupsdAddTimeout (const struct timeval *tv,
585 +                                        cupsd_timeoutfunc_t cb,
586 +                                        void *data);
587 +extern cupsd_timeout_t *cupsdNextTimeout (long *delay);
588 +extern void     cupsdRunTimeout (cupsd_timeout_t *timeout);
589 +extern void     cupsdUpdateTimeout (cupsd_timeout_t *timeout,
590 +                                   const struct timeval *tv);
591 +extern void     cupsdRemoveTimeout (cupsd_timeout_t *timeout);
592 +#endif /* HAVE_AVAHI */
593 \ No newline at end of file
594 diff -urNp -x '*.orig' cups-2.3.3.org/scheduler/dirsvc.c cups-2.3.3/scheduler/dirsvc.c
595 --- cups-2.3.3.org/scheduler/dirsvc.c   2020-04-27 20:04:29.000000000 +0200
596 +++ cups-2.3.3/scheduler/dirsvc.c       2021-04-20 22:45:53.873155054 +0200
597 @@ -190,7 +190,7 @@ cupsdStartBrowsing(void)
598      cupsdUpdateDNSSDName();
599  
600  #  else /* HAVE_AVAHI */
601 -    if ((DNSSDMaster = avahi_threaded_poll_new()) == NULL)
602 +    if ((DNSSDMaster = avahi_cups_poll_new()) == NULL)
603      {
604        cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to create DNS-SD thread.");
605  
606 @@ -201,7 +201,7 @@ cupsdStartBrowsing(void)
607      {
608        int error;                       /* Error code, if any */
609  
610 -      DNSSDClient = avahi_client_new(avahi_threaded_poll_get(DNSSDMaster), AVAHI_CLIENT_NO_FAIL, dnssdClientCallback, NULL, &error);
611 +      DNSSDClient = avahi_client_new(avahi_cups_poll_get(DNSSDMaster), AVAHI_CLIENT_NO_FAIL, dnssdClientCallback, NULL, &error);
612  
613        if (DNSSDClient == NULL)
614        {
615 @@ -212,11 +212,9 @@ cupsdStartBrowsing(void)
616          if (FatalErrors & CUPSD_FATAL_BROWSE)
617           cupsdEndProcess(getpid(), 0);
618  
619 -        avahi_threaded_poll_free(DNSSDMaster);
620 +        avahi_cups_poll_free(DNSSDMaster);
621          DNSSDMaster = NULL;
622        }
623 -      else
624 -       avahi_threaded_poll_start(DNSSDMaster);
625      }
626  #  endif /* HAVE_DNSSD */
627    }
628 @@ -632,7 +630,7 @@ dnssdClientCallback(
629           * Renew Avahi client...
630           */
631  
632 -         DNSSDClient = avahi_client_new(avahi_threaded_poll_get(DNSSDMaster), AVAHI_CLIENT_NO_FAIL, dnssdClientCallback, NULL, &error);
633 +         DNSSDClient = avahi_client_new(avahi_cups_poll_get(DNSSDMaster), AVAHI_CLIENT_NO_FAIL, dnssdClientCallback, NULL, &error);
634  
635           if (!DNSSDClient)
636           {
637 @@ -698,17 +696,11 @@ dnssdDeregisterInstance(
638    *srv = NULL;
639  
640  #  else /* HAVE_AVAHI */
641 -  if (!from_callback)
642 -    avahi_threaded_poll_lock(DNSSDMaster);
643 -
644    if (*srv)
645    {
646      avahi_entry_group_free(*srv);
647      *srv = NULL;
648    }
649 -
650 -  if (!from_callback)
651 -    avahi_threaded_poll_unlock(DNSSDMaster);
652  #  endif /* HAVE_DNSSD */
653  }
654  
655 @@ -1027,16 +1019,10 @@ dnssdRegisterInstance(
656    (void)commit;
657  
658  #  else /* HAVE_AVAHI */
659 -  if (!from_callback)
660 -    avahi_threaded_poll_lock(DNSSDMaster);
661 -
662    if (!*srv)
663      *srv = avahi_entry_group_new(DNSSDClient, dnssdRegisterCallback, NULL);
664    if (!*srv)
665    {
666 -    if (!from_callback)
667 -      avahi_threaded_poll_unlock(DNSSDMaster);
668 -
669      cupsdLogMessage(CUPSD_LOG_WARN, "DNS-SD registration of \"%s\" failed: %s",
670                      name, dnssdErrorString(avahi_client_errno(DNSSDClient)));
671      return (0);
672 @@ -1151,9 +1137,6 @@ dnssdRegisterInstance(
673        cupsdLogMessage(CUPSD_LOG_DEBUG, "DNS-SD commit of \"%s\" failed.",
674                        name);
675    }
676 -
677 -  if (!from_callback)
678 -    avahi_threaded_poll_unlock(DNSSDMaster);
679  #  endif /* HAVE_DNSSD */
680  
681    if (error)
682 @@ -1324,9 +1307,6 @@ dnssdStop(void)
683    DNSSDMaster = NULL;
684  
685  #  else /* HAVE_AVAHI */
686 -  if (DNSSDMaster)
687 -    avahi_threaded_poll_stop(DNSSDMaster);
688 -
689    if (DNSSDClient)
690    {
691      avahi_client_free(DNSSDClient);
692 @@ -1335,7 +1315,7 @@ dnssdStop(void)
693  
694    if (DNSSDMaster)
695    {
696 -    avahi_threaded_poll_free(DNSSDMaster);
697 +    avahi_cups_poll_free(DNSSDMaster);
698      DNSSDMaster = NULL;
699    }
700  #  endif /* HAVE_DNSSD */
701 diff -urNp -x '*.orig' cups-2.3.3.org/scheduler/dirsvc.h cups-2.3.3/scheduler/dirsvc.h
702 --- cups-2.3.3.org/scheduler/dirsvc.h   2020-04-27 20:04:29.000000000 +0200
703 +++ cups-2.3.3/scheduler/dirsvc.h       2021-04-20 22:45:53.873155054 +0200
704 @@ -45,7 +45,7 @@ VAR cups_array_t      *DNSSDPrinters  VALUE(NU
705  VAR DNSServiceRef      DNSSDMaster     VALUE(NULL);
706                                         /* Master DNS-SD service reference */
707  #  else /* HAVE_AVAHI */
708 -VAR AvahiThreadedPoll  *DNSSDMaster    VALUE(NULL);
709 +VAR AvahiCupsPoll      *DNSSDMaster    VALUE(NULL);
710                                         /* Master polling interface for Avahi */
711  VAR AvahiClient                *DNSSDClient    VALUE(NULL);
712                                         /* Client information */
713 diff -urNp -x '*.orig' cups-2.3.3.org/scheduler/main.c cups-2.3.3/scheduler/main.c
714 --- cups-2.3.3.org/scheduler/main.c     2021-04-20 22:45:53.709821838 +0200
715 +++ cups-2.3.3/scheduler/main.c 2021-04-20 22:45:53.873155054 +0200
716 @@ -132,7 +132,10 @@ main(int  argc,                            /* I - Number of comm
717    int                  service_idle_exit = 0;
718                                         /* Idle exit on select timeout? */
719  #endif /* HAVE_ONDEMAND */
720 -
721 +#ifdef HAVE_AVAHI
722 +  cupsd_timeout_t      *tmo;           /* Next scheduled timed callback */
723 +  long                 tmo_delay;      /* Time before it must be called */
724 +#endif /* HAVE_AVAHI */
725  
726  #ifdef HAVE_GETEUID
727   /*
728 @@ -600,6 +603,14 @@ main(int  argc,                            /* I - Number of comm
729  
730    httpInitialize();
731  
732 +#ifdef HAVE_AVAHI
733 + /*
734 +  * Initialize timed callback structures.
735 +  */
736 +
737 +  cupsdInitTimeouts();
738 +#endif /* HAVE_AVAHI */
739 +
740    cupsdStartServer();
741  
742   /*
743 @@ -934,6 +945,16 @@ main(int  argc,                            /* I - Number of comm
744      }
745  #endif /* __APPLE__ */
746  
747 +#ifdef HAVE_AVAHI
748 +   /*
749 +    * If a timed callback is due, run it.
750 +    */
751 +
752 +    tmo = cupsdNextTimeout (&tmo_delay);
753 +    if (tmo && tmo_delay == 0)
754 +      cupsdRunTimeout (tmo);
755 +#endif /* HAVE_AVAHI */
756 +
757  #ifndef __APPLE__
758     /*
759      * Update the network interfaces once a minute...
760 @@ -1643,6 +1664,10 @@ select_timeout(int fds)                  /* I - Number
761    cupsd_client_t       *con;           /* Client information */
762    cupsd_job_t          *job;           /* Job information */
763    const char           *why;           /* Debugging aid */
764 +#ifdef HAVE_AVAHI
765 +  cupsd_timeout_t      *tmo;           /* Timed callback */
766 +  long                 tmo_delay;      /* Seconds before calling it */
767 +#endif /* HAVE_AVAHI */
768  
769  
770    cupsdLogMessage(CUPSD_LOG_DEBUG2, "select_timeout: JobHistoryUpdate=%ld",
771 @@ -1688,6 +1713,19 @@ select_timeout(int fds)                  /* I - Number
772    }
773  #endif /* __APPLE__ */
774  
775 +#ifdef HAVE_AVAHI
776 + /*
777 +  * See if there are any scheduled timed callbacks to run.
778 +  */
779 +
780 +  if ((tmo = cupsdNextTimeout(&tmo_delay)) != NULL &&
781 +      (now + tmo_delay) < timeout)
782 +  {
783 +    timeout = tmo_delay;
784 +    why = "run a timed callback";
785 +  }
786 +#endif /* HAVE_AVAHI */
787 +
788   /*
789    * Check whether we are accepting new connections...
790    */
791 diff -urNp -x '*.orig' cups-2.3.3.org/scheduler/timeout.c cups-2.3.3/scheduler/timeout.c
792 --- cups-2.3.3.org/scheduler/timeout.c  1970-01-01 01:00:00.000000000 +0100
793 +++ cups-2.3.3/scheduler/timeout.c      2021-04-20 22:45:53.873155054 +0200
794 @@ -0,0 +1,235 @@
795 +/*
796 + * "$Id$"
797 + *
798 + *   Timeout functions for the Common UNIX Printing System (CUPS).
799 + *
800 + *   Copyright (C) 2010, 2011 Red Hat, Inc.
801 + *   Authors:
802 + *     Tim Waugh <twaugh@redhat.com>
803 + *
804 + *   Redistribution and use in source and binary forms, with or without
805 + *   modification, are permitted provided that the following conditions
806 + *   are met:
807 + *
808 + *   Redistributions of source code must retain the above copyright
809 + *   notice, this list of conditions and the following disclaimer.
810 + *
811 + *   Redistributions in binary form must reproduce the above copyright
812 + *   notice, this list of conditions and the following disclaimer in the
813 + *   documentation and/or other materials provided with the distribution.
814 + *
815 + *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
816 + *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
817 + *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
818 + *   FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
819 + *   COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
820 + *   INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
821 + *   (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
822 + *   SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
823 + *   HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
824 + *   STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
825 + *   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
826 + *   OF THE POSSIBILITY OF SUCH DAMAGE.
827 + *
828 + * Contents:
829 + *
830 + *   cupsdInitTimeouts()  - Initialise timeout structure.
831 + *   cupsdAddTimeout()    - Add a timed callback.
832 + *   cupsdNextTimeout()   - Find the next enabled timed callback.
833 + *   cupsdUpdateTimeout() - Adjust the time of a timed callback or disable it.
834 + *   cupsdRemoveTimeout() - Discard a timed callback.
835 + *   compare_timeouts()   - Compare timed callbacks for array sorting.
836 + */
837 +
838 +#include <config.h>
839 +
840 +#ifdef HAVE_AVAHI /* Applies to entire file... */
841 +
842 +/*
843 + * Include necessary headers...
844 + */
845 +
846 +#include "cupsd.h"
847 +
848 +#if defined(HAVE_MALLOC_H) && defined(HAVE_MALLINFO)
849 +#  include <malloc.h>
850 +#endif /* HAVE_MALLOC_H && HAVE_MALLINFO */
851 +
852 +#ifdef HAVE_AVAHI
853 +#  include <avahi-common/timeval.h>
854 +#endif /* HAVE_AVAHI */
855 +
856 +
857 +struct _cupsd_timeout_s
858 +{
859 +  struct timeval when;
860 +  int enabled;
861 +  cupsd_timeoutfunc_t callback;
862 +  void *data;
863 +};
864 +
865 +/*
866 + * Local functions...
867 + */
868 +
869 +/*
870 + * 'compare_timeouts()' - Compare timed callbacks for array sorting.
871 + */
872 +
873 +static int
874 +compare_addrs (void *p0, void *p1)
875 +{
876 +  if (p0 == p1)
877 +    return (0);
878 +  if (p0 < p1)
879 +    return (-1);
880 +  return (1);
881 +}
882 +
883 +static int
884 +compare_timeouts (cupsd_timeout_t *p0, cupsd_timeout_t *p1)
885 +{
886 +  int addrsdiff = compare_addrs (p0, p1);
887 +  int tvdiff;
888 +
889 +  if (addrsdiff == 0)
890 +    return (0);
891 +
892 +  if (!p0->enabled || !p1->enabled)
893 +  {
894 +    if (!p0->enabled && !p1->enabled)
895 +      return (addrsdiff);
896 +
897 +    return (p0->enabled ? -1 : 1);
898 +  }
899 +
900 +  tvdiff = avahi_timeval_compare (&p0->when, &p1->when);
901 +  if (tvdiff != 0)
902 +    return (tvdiff);
903 +
904 +  return (addrsdiff);
905 +}
906 +
907 +
908 +/*
909 + * 'cupsdInitTimeouts()' - Initialise timeout structures.
910 + */
911 +
912 +void
913 +cupsdInitTimeouts(void)
914 +{
915 +  Timeouts = cupsArrayNew ((cups_array_func_t)compare_timeouts, NULL);
916 +}
917 +
918 +
919 +/*
920 + * 'cupsdAddTimeout()' - Add a timed callback.
921 + */
922 +
923 +cupsd_timeout_t *                              /* O - Timeout handle */
924 +cupsdAddTimeout(const struct timeval *tv,      /* I - Absolute time */
925 +               cupsd_timeoutfunc_t cb,         /* I - Callback function */
926 +               void *data)                     /* I - User data */
927 +{
928 +  cupsd_timeout_t *timeout;
929 +
930 +  timeout = malloc (sizeof(cupsd_timeout_t));
931 +  if (timeout != NULL)
932 +  {
933 +    timeout->enabled = (tv != NULL);
934 +    if (tv)
935 +    {
936 +      timeout->when.tv_sec = tv->tv_sec;
937 +      timeout->when.tv_usec = tv->tv_usec;
938 +    }
939 +
940 +    timeout->callback = cb;
941 +    timeout->data = data;
942 +    cupsArrayAdd (Timeouts, timeout);
943 +  }
944 +
945 +  return timeout;
946 +}
947 +
948 +
949 +/*
950 + * 'cupsdNextTimeout()' - Find the next enabled timed callback.
951 + */
952 +
953 +cupsd_timeout_t *              /* O - Next enabled timeout or NULL */
954 +cupsdNextTimeout(long *delay)  /* O - Seconds before scheduled */
955 +{
956 +  cupsd_timeout_t *first = cupsArrayFirst (Timeouts);
957 +  struct timeval curtime;
958 +
959 +  if (first && !first->enabled)
960 +    first = NULL;
961 +
962 +  if (first && delay)
963 +  {
964 +    gettimeofday (&curtime, NULL);
965 +    if (avahi_timeval_compare (&curtime, &first->when) > 0)
966 +    {
967 +      *delay = 0;
968 +    } else {
969 +      *delay = 1 + first->when.tv_sec - curtime.tv_sec;
970 +      if (first->when.tv_usec < curtime.tv_usec)
971 +       (*delay)--;
972 +    }
973 +  }
974 +
975 +  return (first);
976 +}
977 +
978 +
979 +/*
980 + * 'cupsdRunTimeout()' - Run a timed callback.
981 + */
982 +
983 +void
984 +cupsdRunTimeout(cupsd_timeout_t *timeout)      /* I - Timeout */
985 +{
986 +  if (!timeout)
987 +    return;
988 +  timeout->enabled = 0;
989 +  if (!timeout->callback)
990 +    return;
991 +  timeout->callback (timeout, timeout->data);
992 +}
993 +
994 +/*
995 + * 'cupsdUpdateTimeout()' - Adjust the time of a timed callback or disable it.
996 + */
997 +
998 +void
999 +cupsdUpdateTimeout(cupsd_timeout_t *timeout,   /* I - Timeout */
1000 +                  const struct timeval *tv)    /* I - Absolute time or NULL */
1001 +{
1002 +  cupsArrayRemove (Timeouts, timeout);
1003 +  timeout->enabled = (tv != NULL);
1004 +  if (tv)
1005 +  {
1006 +    timeout->when.tv_sec = tv->tv_sec;
1007 +    timeout->when.tv_usec = tv->tv_usec;
1008 +  }
1009 +  cupsArrayAdd (Timeouts, timeout);
1010 +}
1011 +
1012 +
1013 +/*
1014 + * 'cupsdRemoveTimeout()' - Discard a timed callback.
1015 + */
1016 +
1017 +void
1018 +cupsdRemoveTimeout(cupsd_timeout_t *timeout)   /* I - Timeout */
1019 +{
1020 +  cupsArrayRemove (Timeouts, timeout);
1021 +  free (timeout);
1022 +}
1023 +
1024 +
1025 +#endif /* HAVE_AVAHI ... from top of file */
1026 +
1027 +/*
1028 + * End of "$Id$".
1029 + */
This page took 0.687464 seconds and 3 git commands to generate.