Magellan Linux

Annotation of /trunk/cups/patches/cups-1.5.2-avahi-3-timeouts.patch

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1642 - (hide annotations) (download)
Thu Feb 16 08:44:18 2012 UTC (12 years, 3 months ago) by niro
File size: 9900 byte(s)
-added redhat/fedora avahi patches
1 niro 1642 diff -up cups-1.5.0/scheduler/cupsd.h.avahi-3-timeouts cups-1.5.0/scheduler/cupsd.h
2     --- cups-1.5.0/scheduler/cupsd.h.avahi-3-timeouts 2011-05-11 23:17:34.000000000 +0100
3     +++ cups-1.5.0/scheduler/cupsd.h 2011-10-07 13:20:41.522867324 +0100
4     @@ -140,6 +140,15 @@ extern const char *cups_hstrerror(int);
5    
6     typedef void (*cupsd_selfunc_t)(void *data);
7    
8     +#ifdef HAVE_AVAHI
9     +/*
10     + * Timeout callback function type...
11     + */
12     +
13     +typedef struct _cupsd_timeout_s cupsd_timeout_t;
14     +typedef void (*cupsd_timeoutfunc_t)(cupsd_timeout_t *timeout, void *data);
15     +#endif /* HAVE_AVAHI */
16     +
17    
18     /*
19     * Globals...
20     @@ -173,6 +182,11 @@ VAR int Launchd VALUE(0);
21     /* Running from launchd */
22     #endif /* HAVE_LAUNCH_H */
23    
24     +#ifdef HAVE_AVAHI
25     +VAR cups_array_t *Timeouts; /* Timed callbacks for main loop */
26     +#endif /* HAVE_AVAHI */
27     +
28     +
29    
30     /*
31     * Prototypes...
32     @@ -242,6 +256,20 @@ extern void cupsdStopSelect(void);
33     extern void cupsdStartServer(void);
34     extern void cupsdStopServer(void);
35    
36     +#ifdef HAVE_AVAHI
37     +extern void cupsdInitTimeouts(void);
38     +extern cupsd_timeout_t *cupsdAddTimeout (const struct timeval *tv,
39     + cupsd_timeoutfunc_t cb,
40     + void *data);
41     +extern cupsd_timeout_t *cupsdNextTimeout (long *delay);
42     +extern void cupsdRunTimeout (cupsd_timeout_t *timeout);
43     +extern void cupsdUpdateTimeout (cupsd_timeout_t *timeout,
44     + const struct timeval *tv);
45     +extern void cupsdRemoveTimeout (cupsd_timeout_t *timeout);
46     +#endif /* HAVE_AVAHI */
47     +
48     +extern int cupsdRemoveFile(const char *filename);
49     +
50    
51     /*
52     * End of "$Id: cupsd.h 9766 2011-05-11 22:17:34Z mike $".
53     diff -up cups-1.5.0/scheduler/main.c.avahi-3-timeouts cups-1.5.0/scheduler/main.c
54     --- cups-1.5.0/scheduler/main.c.avahi-3-timeouts 2011-10-07 13:20:36.875954675 +0100
55     +++ cups-1.5.0/scheduler/main.c 2011-10-07 13:20:41.524867282 +0100
56     @@ -146,6 +146,10 @@ main(int argc, /* I - Number of comm
57     int launchd_idle_exit;
58     /* Idle exit on select timeout? */
59     #endif /* HAVE_LAUNCHD */
60     +#ifdef HAVE_AVAHI
61     + cupsd_timeout_t *tmo; /* Next scheduled timed callback */
62     + long tmo_delay; /* Time before it must be called */
63     +#endif /* HAVE_AVAHI */
64    
65    
66     #ifdef HAVE_GETEUID
67     @@ -535,6 +539,14 @@ main(int argc, /* I - Number of comm
68    
69     httpInitialize();
70    
71     +#ifdef HAVE_AVAHI
72     + /*
73     + * Initialize timed callback structures.
74     + */
75     +
76     + cupsdInitTimeouts();
77     +#endif /* HAVE_AVAHI */
78     +
79     cupsdStartServer();
80    
81     /*
82     @@ -874,6 +886,16 @@ main(int argc, /* I - Number of comm
83     }
84     #endif /* __APPLE__ */
85    
86     +#ifdef HAVE_AVAHI
87     + /*
88     + * If a timed callback is due, run it.
89     + */
90     +
91     + tmo = cupsdNextTimeout (&tmo_delay);
92     + if (tmo && tmo_delay == 0)
93     + cupsdRunTimeout (tmo);
94     +#endif /* HAVE_AVAHI */
95     +
96     #ifndef __APPLE__
97     /*
98     * Update the network interfaces once a minute...
99     @@ -1787,6 +1809,10 @@ select_timeout(int fds) /* I - Number
100     cupsd_job_t *job; /* Job information */
101     cupsd_subscription_t *sub; /* Subscription information */
102     const char *why; /* Debugging aid */
103     +#ifdef HAVE_AVAHI
104     + cupsd_timeout_t *tmo; /* Timed callback */
105     + long tmo_delay; /* Seconds before calling it */
106     +#endif /* HAVE_AVAHI */
107    
108    
109     /*
110     @@ -1829,6 +1855,19 @@ select_timeout(int fds) /* I - Number
111     }
112     #endif /* __APPLE__ */
113    
114     +#ifdef HAVE_AVAHI
115     + /*
116     + * See if there are any scheduled timed callbacks to run.
117     + */
118     +
119     + tmo = cupsdNextTimeout (&tmo_delay);
120     + if (tmo)
121     + {
122     + timeout = tmo_delay;
123     + why = "run a timed callback";
124     + }
125     +#endif /* HAVE_AVAHI */
126     +
127     /*
128     * Check whether we are accepting new connections...
129     */
130     diff -up cups-1.5.0/scheduler/Makefile.avahi-3-timeouts cups-1.5.0/scheduler/Makefile
131     --- cups-1.5.0/scheduler/Makefile.avahi-3-timeouts 2011-10-07 13:20:36.955953170 +0100
132     +++ cups-1.5.0/scheduler/Makefile 2011-10-07 13:20:41.521867343 +0100
133     @@ -39,7 +39,8 @@ CUPSDOBJS = \
134     server.o \
135     statbuf.o \
136     subscriptions.o \
137     - sysman.o
138     + sysman.o \
139     + timeout.o
140     LIBOBJS = \
141     filter.o \
142     mime.o \
143     diff -up cups-1.5.0/scheduler/timeout.c.avahi-3-timeouts cups-1.5.0/scheduler/timeout.c
144     --- cups-1.5.0/scheduler/timeout.c.avahi-3-timeouts 2011-10-07 13:20:41.525867259 +0100
145     +++ cups-1.5.0/scheduler/timeout.c 2011-10-07 13:20:41.525867259 +0100
146     @@ -0,0 +1,235 @@
147     +/*
148     + * "$Id$"
149     + *
150     + * Timeout functions for the Common UNIX Printing System (CUPS).
151     + *
152     + * Copyright (C) 2010, 2011 Red Hat, Inc.
153     + * Authors:
154     + * Tim Waugh <twaugh@redhat.com>
155     + *
156     + * Redistribution and use in source and binary forms, with or without
157     + * modification, are permitted provided that the following conditions
158     + * are met:
159     + *
160     + * Redistributions of source code must retain the above copyright
161     + * notice, this list of conditions and the following disclaimer.
162     + *
163     + * Redistributions in binary form must reproduce the above copyright
164     + * notice, this list of conditions and the following disclaimer in the
165     + * documentation and/or other materials provided with the distribution.
166     + *
167     + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
168     + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
169     + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
170     + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
171     + * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
172     + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
173     + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
174     + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
175     + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
176     + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
177     + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
178     + * OF THE POSSIBILITY OF SUCH DAMAGE.
179     + *
180     + * Contents:
181     + *
182     + * cupsdInitTimeouts() - Initialise timeout structure.
183     + * cupsdAddTimeout() - Add a timed callback.
184     + * cupsdNextTimeout() - Find the next enabled timed callback.
185     + * cupsdUpdateTimeout() - Adjust the time of a timed callback or disable it.
186     + * cupsdRemoveTimeout() - Discard a timed callback.
187     + * compare_timeouts() - Compare timed callbacks for array sorting.
188     + */
189     +
190     +#include <config.h>
191     +
192     +#ifdef HAVE_AVAHI /* Applies to entire file... */
193     +
194     +/*
195     + * Include necessary headers...
196     + */
197     +
198     +#include "cupsd.h"
199     +
200     +#if defined(HAVE_MALLOC_H) && defined(HAVE_MALLINFO)
201     +# include <malloc.h>
202     +#endif /* HAVE_MALLOC_H && HAVE_MALLINFO */
203     +
204     +#ifdef HAVE_AVAHI
205     +# include <avahi-common/timeval.h>
206     +#endif /* HAVE_AVAHI */
207     +
208     +
209     +struct _cupsd_timeout_s
210     +{
211     + struct timeval when;
212     + int enabled;
213     + cupsd_timeoutfunc_t callback;
214     + void *data;
215     +};
216     +
217     +/*
218     + * Local functions...
219     + */
220     +
221     +/*
222     + * 'compare_timeouts()' - Compare timed callbacks for array sorting.
223     + */
224     +
225     +static int
226     +compare_addrs (void *p0, void *p1)
227     +{
228     + if (p0 == p1)
229     + return (0);
230     + if (p0 < p1)
231     + return (-1);
232     + return (1);
233     +}
234     +
235     +static int
236     +compare_timeouts (cupsd_timeout_t *p0, cupsd_timeout_t *p1)
237     +{
238     + int addrsdiff = compare_addrs (p0, p1);
239     + int tvdiff;
240     +
241     + if (addrsdiff == 0)
242     + return (0);
243     +
244     + if (!p0->enabled || !p1->enabled)
245     + {
246     + if (!p0->enabled && !p1->enabled)
247     + return (addrsdiff);
248     +
249     + return (p0->enabled ? -1 : 1);
250     + }
251     +
252     + tvdiff = avahi_timeval_compare (&p0->when, &p1->when);
253     + if (tvdiff != 0)
254     + return (tvdiff);
255     +
256     + return (addrsdiff);
257     +}
258     +
259     +
260     +/*
261     + * 'cupsdInitTimeouts()' - Initialise timeout structures.
262     + */
263     +
264     +void
265     +cupsdInitTimeouts(void)
266     +{
267     + Timeouts = cupsArrayNew ((cups_array_func_t)compare_timeouts, NULL);
268     +}
269     +
270     +
271     +/*
272     + * 'cupsdAddTimeout()' - Add a timed callback.
273     + */
274     +
275     +cupsd_timeout_t * /* O - Timeout handle */
276     +cupsdAddTimeout(const struct timeval *tv, /* I - Absolute time */
277     + cupsd_timeoutfunc_t cb, /* I - Callback function */
278     + void *data) /* I - User data */
279     +{
280     + cupsd_timeout_t *timeout;
281     +
282     + timeout = malloc (sizeof(cupsd_timeout_t));
283     + if (timeout != NULL)
284     + {
285     + timeout->enabled = (tv != NULL);
286     + if (tv)
287     + {
288     + timeout->when.tv_sec = tv->tv_sec;
289     + timeout->when.tv_usec = tv->tv_usec;
290     + }
291     +
292     + timeout->callback = cb;
293     + timeout->data = data;
294     + cupsArrayAdd (Timeouts, timeout);
295     + }
296     +
297     + return timeout;
298     +}
299     +
300     +
301     +/*
302     + * 'cupsdNextTimeout()' - Find the next enabled timed callback.
303     + */
304     +
305     +cupsd_timeout_t * /* O - Next enabled timeout or NULL */
306     +cupsdNextTimeout(long *delay) /* O - Seconds before scheduled */
307     +{
308     + cupsd_timeout_t *first = cupsArrayFirst (Timeouts);
309     + struct timeval curtime;
310     +
311     + if (first && !first->enabled)
312     + first = NULL;
313     +
314     + if (first && delay)
315     + {
316     + gettimeofday (&curtime, NULL);
317     + if (avahi_timeval_compare (&curtime, &first->when) > 0)
318     + {
319     + *delay = 0;
320     + } else {
321     + *delay = 1 + first->when.tv_sec - curtime.tv_sec;
322     + if (first->when.tv_usec < curtime.tv_usec)
323     + (*delay)--;
324     + }
325     + }
326     +
327     + return (first);
328     +}
329     +
330     +
331     +/*
332     + * 'cupsdRunTimeout()' - Run a timed callback.
333     + */
334     +
335     +void
336     +cupsdRunTimeout(cupsd_timeout_t *timeout) /* I - Timeout */
337     +{
338     + if (!timeout)
339     + return;
340     + timeout->enabled = 0;
341     + if (!timeout->callback)
342     + return;
343     + timeout->callback (timeout, timeout->data);
344     +}
345     +
346     +/*
347     + * 'cupsdUpdateTimeout()' - Adjust the time of a timed callback or disable it.
348     + */
349     +
350     +void
351     +cupsdUpdateTimeout(cupsd_timeout_t *timeout, /* I - Timeout */
352     + const struct timeval *tv) /* I - Absolute time or NULL */
353     +{
354     + cupsArrayRemove (Timeouts, timeout);
355     + timeout->enabled = (tv != NULL);
356     + if (tv)
357     + {
358     + timeout->when.tv_sec = tv->tv_sec;
359     + timeout->when.tv_usec = tv->tv_usec;
360     + }
361     + cupsArrayAdd (Timeouts, timeout);
362     +}
363     +
364     +
365     +/*
366     + * 'cupsdRemoveTimeout()' - Discard a timed callback.
367     + */
368     +
369     +void
370     +cupsdRemoveTimeout(cupsd_timeout_t *timeout) /* I - Timeout */
371     +{
372     + cupsArrayRemove (Timeouts, timeout);
373     + free (timeout);
374     +}
375     +
376     +
377     +#endif /* HAVE_AVAHI ... from top of file */
378     +
379     +/*
380     + * End of "$Id$".
381     + */