1
#! /bin/sh /usr/share/dpatch/dpatch-run
2
## 23-configurable_idled.dpatch by Ondřej Surý <ondrej@sury.org>
4
## All lines beginning with `## DP:' are a description of the patch.
5
## DP: Adds imapd.conf option to select IDLE method at runtime
8
diff -urNad cyrus-imapd-2.2.13/configure.in /tmp/dpep.7DrWs1/cyrus-imapd-2.2.13/configure.in
9
--- cyrus-imapd-2.2.13/configure.in 2006-08-23 18:13:47.000000000 +0200
10
+++ /tmp/dpep.7DrWs1/cyrus-imapd-2.2.13/configure.in 2006-08-23 18:13:56.178920138 +0200
12
METHOD is [poll], idled or no],
13
WITH_IDLE="${withval}",WITH_IDLE="poll")
15
-if test "$WITH_IDLE" = "idled"; then
16
- IMAP_PROGS="$IMAP_PROGS idled"
20
dnl see if we're compiling with NNTP support
21
diff -urNad cyrus-imapd-2.2.13/imap/Makefile.in /tmp/dpep.7DrWs1/cyrus-imapd-2.2.13/imap/Makefile.in
22
--- cyrus-imapd-2.2.13/imap/Makefile.in 2006-08-23 18:13:47.000000000 +0200
23
+++ /tmp/dpep.7DrWs1/cyrus-imapd-2.2.13/imap/Makefile.in 2006-08-23 18:13:56.178920138 +0200
25
# 'local' (legacy flat file).
28
-# IMAP IDLE mechanism
29
-IDLE=idle_@WITH_IDLE@.o
32
top_srcdir = @top_srcdir@
35
convert_code.o duplicate.o saslclient.o saslserver.o signals.o \
36
annotate.o search_engines.o squat.o squat_internal.o mbdump.o \
37
imapparse.o telemetry.o user.o notify.o protocol.o quota_db.o \
39
+ idle.o idle_no.o idle_poll.o idle_idled.o \
42
IMAPDOBJS=pushstats.o backend.o imapd.o index.o tls.o version.o
45
SERVICE=../master/service.o
46
SERVICETHREAD=../master/service-thread.o
48
-PROGS = imapd lmtpd pop3d \
49
+PROGS = imapd lmtpd pop3d idled \
50
fud smmapd reconstruct quota mbpath ipurge \
51
cyrdump chk_cyrus cvt_cyrusdb deliver ctl_mboxlist \
52
ctl_deliver ctl_cyrusdb squatter mbexamine cyr_expire arbitron \
53
diff -urNad cyrus-imapd-2.2.13/imap/global.c /tmp/dpep.7DrWs1/cyrus-imapd-2.2.13/imap/global.c
54
--- cyrus-imapd-2.2.13/imap/global.c 2006-08-23 18:13:47.000000000 +0200
55
+++ /tmp/dpep.7DrWs1/cyrus-imapd-2.2.13/imap/global.c 2006-08-23 18:28:28.243411698 +0200
57
#include "prot.h" /* for PROT_BUFSIZE */
65
/* syslog prefix tag */
66
static char syslog_prefix[20];
68
+struct idle_backend *config_idle=NULL;
70
/* Called before a cyrus application starts (but after command line parameters
72
int cyrus_init(const char *alt_config, const char *ident, unsigned flags)
75
cyrusdb_fromname(config_getstring(IMAPOPT_PTSCACHE_DB));
77
+ /* lookup idle backend */
79
+ idle_fromname(config_getstring(IMAPOPT_IDLEMETHOD));
81
/* configure libcyrus as needed */
82
libcyrus_config_setstring(CYRUSOPT_CONFIG_DIR, config_dir);
83
libcyrus_config_setswitch(CYRUSOPT_AUTH_UNIX_GROUP_ENABLE,
84
diff -urNad cyrus-imapd-2.2.13/imap/global.h /tmp/dpep.7DrWs1/cyrus-imapd-2.2.13/imap/global.h
85
--- cyrus-imapd-2.2.13/imap/global.h 2006-08-21 23:32:39.000000000 +0200
86
+++ /tmp/dpep.7DrWs1/cyrus-imapd-2.2.13/imap/global.h 2006-08-23 18:13:56.179920040 +0200
88
extern struct cyrusdb_backend *config_tlscache_db;
89
extern struct cyrusdb_backend *config_ptscache_db;
91
+extern struct idle_backend *config_idle;
93
#endif /* INCLUDED_GLOBAL_H */
94
diff -urNad cyrus-imapd-2.2.13/imap/idle.c /tmp/dpep.7DrWs1/cyrus-imapd-2.2.13/imap/idle.c
95
--- cyrus-imapd-2.2.13/imap/idle.c 1970-01-01 01:00:00.000000000 +0100
96
+++ /tmp/dpep.7DrWs1/cyrus-imapd-2.2.13/imap/idle.c 2006-08-23 18:13:56.179920040 +0200
99
+ * Copyright (c) 1998-2003 Carnegie Mellon University. All rights reserved.
101
+ * Redistribution and use in source and binary forms, with or without
102
+ * modification, are permitted provided that the following conditions
105
+ * 1. Redistributions of source code must retain the above copyright
106
+ * notice, this list of conditions and the following disclaimer.
108
+ * 2. Redistributions in binary form must reproduce the above copyright
109
+ * notice, this list of conditions and the following disclaimer in
110
+ * the documentation and/or other materials provided with the
113
+ * 3. The name "Carnegie Mellon University" must not be used to
114
+ * endorse or promote products derived from this software without
115
+ * prior written permission. For permission or any other legal
116
+ * details, please contact
117
+ * Office of Technology Transfer
118
+ * Carnegie Mellon University
119
+ * 5000 Forbes Avenue
120
+ * Pittsburgh, PA 15213-3890
121
+ * (412) 268-4387, fax: (412) 268-7395
122
+ * tech-transfer@andrew.cmu.edu
124
+ * 4. Redistributions of any form whatsoever must retain the following
126
+ * "This product includes software developed by Computing Services
127
+ * at Carnegie Mellon University (http://www.cmu.edu/computing/)."
129
+ * CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO
130
+ * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
131
+ * AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE
132
+ * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
133
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
134
+ * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
135
+ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
138
+/* $Id: idle.c,v 1.10 2006/01/04 02:06:23 ondrej Exp $ */
145
+#include <sys/socket.h>
146
+#include <netinet/in.h>
147
+#include <arpa/inet.h>
150
+#include <sys/types.h>
151
+#include <sys/stat.h>
154
+#include "makedepend/def.h"
157
+#include "exitcodes.h"
159
+struct idle_backend *idle_backends[] = {
165
+struct idle_backend *idle_fromname(const char *name)
168
+ struct idle_backend *idle = NULL;
170
+ for (i = 0; idle_backends[i]; i++) {
171
+ if (!strcmp(idle_backends[i]->name, name)) {
172
+ idle = idle_backends[i];
178
+ snprintf(errbuf, sizeof(errbuf),
179
+ "idle backend %s not supported", name);
180
+ fatal(errbuf, EC_CONFIG);
185
diff -urNad cyrus-imapd-2.2.13/imap/idle.h /tmp/dpep.7DrWs1/cyrus-imapd-2.2.13/imap/idle.h
186
--- cyrus-imapd-2.2.13/imap/idle.h 2006-08-21 23:32:39.000000000 +0200
187
+++ /tmp/dpep.7DrWs1/cyrus-imapd-2.2.13/imap/idle.h 2006-08-23 18:13:56.180919942 +0200
193
-extern const char *idle_method_desc;
200
typedef void idle_updateproc_t(idle_flags_t flags);
202
+struct idle_backend {
205
-/* Is IDLE enabled? Can also do initial setup, if necessary */
206
-int idle_enabled(void);
207
+ /* Is IDLE enabled? Can also do initial setup, if necessary */
208
+ int (*enabled)(void);
211
- * 'proc' is a pointer to a function which reports mailbox updates and/or
212
- * ALERTs to the client.
214
-int idle_init(idle_updateproc_t *proc);
216
+ * 'proc' is a pointer to a function which reports mailbox updates and/or
217
+ * ALERTs to the client.
219
+ int (*init)(idle_updateproc_t *proc);
221
-/* Start IDLEing on 'mailbox'. */
222
-void idle_start(struct mailbox *mailbox);
223
+ /* Start IDLEing on 'mailbox'. */
224
+ void (*start)(struct mailbox *mailbox);
226
-/* Cleanup when IDLE is completed. */
227
-void idle_done(struct mailbox *mailbox);
228
+ /* Cleanup when IDLE is completed. */
229
+ void (*done)(struct mailbox *mailbox);
232
+/* Defines to simulate old behaviour */
233
+/* see struct definition above to see what they do */
235
+#define idle_enabled() (config_idle?config_idle->enabled():0)
236
+#define idle_init(proc) (config_idle?config_idle->init(proc):0)
237
+#define idle_start(mbox) (config_idle?config_idle->start(mbox):0)
238
+#define idle_done(mbox) (config_idle?config_idle->done(mbox):0)
239
+#define idle_method_desc (config_idle?config_idle->name:NULL)
241
+extern struct idle_backend *idle_backends[];
243
+/* Note that some of these may be undefined symbols
244
+ * if imapd was not built with support for them */
245
+extern struct idle_backend id_bk_no;
246
+extern struct idle_backend id_bk_poll;
247
+extern struct idle_backend id_bk_idled;
250
+struct idle_backend *idle_fromname(const char *name);
253
diff -urNad cyrus-imapd-2.2.13/imap/idle_idled.c /tmp/dpep.7DrWs1/cyrus-imapd-2.2.13/imap/idle_idled.c
254
--- cyrus-imapd-2.2.13/imap/idle_idled.c 2006-08-23 18:13:47.000000000 +0200
255
+++ /tmp/dpep.7DrWs1/cyrus-imapd-2.2.13/imap/idle_idled.c 2006-08-23 18:13:56.180919942 +0200
260
-const char *idle_method_desc = "idled";
262
/* function to report mailbox updates to the client */
263
static idle_updateproc_t *idle_update = NULL;
266
static int idle_remote_len = 0;
268
/* Forward declarations */
269
-int idle_send_msg(int msg, struct mailbox *mailbox);
270
-void idle_notify(struct mailbox *mailbox);
271
+static int idle_send_msg(int msg, struct mailbox *mailbox);
272
+static void idle_notify(struct mailbox *mailbox);
276
* Create connection to idled for sending notifications
278
-int idle_enabled(void)
279
+static int idle_idled_enabled(void)
287
-int idle_init(idle_updateproc_t *proc)
288
+/* forward declaration */
289
+static void idle_idled_done(struct mailbox *mailbox);
291
+static int idle_idled_init(idle_updateproc_t *proc)
293
struct sigaction action;
295
@@ -177,14 +178,14 @@
296
syslog(LOG_ERR, "sigaction: %m");
298
/* Cancel receiving signals */
300
+ idle_idled_done(NULL);
307
-void idle_start(struct mailbox *mailbox)
308
+static void idle_idled_start(struct mailbox *mailbox)
316
-void idle_done(struct mailbox *mailbox)
317
+static void idle_idled_done(struct mailbox *mailbox)
319
/* Tell idled that we're done idling */
320
idle_send_msg(IDLE_DONE, mailbox);
323
* Send a message to idled
325
-int idle_send_msg(int msg, struct mailbox *mailbox)
326
+static int idle_send_msg(int msg, struct mailbox *mailbox)
328
idle_data_t idledata;
330
@@ -235,10 +236,21 @@
332
* Notify imapidled of a mailbox change
334
-void idle_notify(struct mailbox *mailbox)
335
+static void idle_notify(struct mailbox *mailbox)
337
/* We should try to determine if we need to send this
338
* (ie, is an imapd is IDLE on 'mailbox'?).
340
idle_send_msg(IDLE_NOTIFY, mailbox);
343
+struct idle_backend id_bk_idled =
345
+ "idled", /* name */
347
+ &idle_idled_enabled,
353
diff -urNad cyrus-imapd-2.2.13/imap/idle_no.c /tmp/dpep.7DrWs1/cyrus-imapd-2.2.13/imap/idle_no.c
354
--- cyrus-imapd-2.2.13/imap/idle_no.c 2006-08-21 23:32:39.000000000 +0200
355
+++ /tmp/dpep.7DrWs1/cyrus-imapd-2.2.13/imap/idle_no.c 2006-08-23 18:13:56.181919844 +0200
361
-const char *idle_method_desc = (char *)0;
363
-int idle_enabled(void)
364
+static int idle_no_enabled(void)
369
-int idle_init(idle_updateproc_t *proc)
370
+static int idle_no_init(idle_updateproc_t *proc)
375
-void idle_start(struct mailbox *mailbox)
376
+static void idle_no_start(struct mailbox *mailbox __attribute__((unused)))
380
-void idle_done(struct mailbox *mailbox)
381
+static void idle_no_done(struct mailbox *mailbox __attribute__((unused)))
385
+struct idle_backend id_bk_no =
395
diff -urNad cyrus-imapd-2.2.13/imap/idle_poll.c /tmp/dpep.7DrWs1/cyrus-imapd-2.2.13/imap/idle_poll.c
396
--- cyrus-imapd-2.2.13/imap/idle_poll.c 2006-08-21 23:32:39.000000000 +0200
397
+++ /tmp/dpep.7DrWs1/cyrus-imapd-2.2.13/imap/idle_poll.c 2006-08-23 18:13:56.181919844 +0200
402
-const char *idle_method_desc = "poll";
404
/* function to report mailbox updates to the client */
405
static idle_updateproc_t *idle_update = NULL;
407
/* how often to poll the mailbox */
408
static time_t idle_period = -1;
410
-int idle_enabled(void)
411
+static int idle_poll_enabled(void)
413
/* get polling period */
414
if (idle_period == -1) {
419
-int idle_init(idle_updateproc_t *proc)
420
+/* forward declaration */
421
+static void idle_poll_done(struct mailbox *mailbox __attribute__((unused)));
423
+static int idle_poll_init(idle_updateproc_t *proc)
425
struct sigaction action;
428
syslog(LOG_ERR, "sigaction: %m");
430
/* Cancel receiving signals */
432
+ idle_poll_done(NULL);
439
-void idle_start(struct mailbox *mailbox __attribute__((unused)))
440
+static void idle_poll_start(struct mailbox *mailbox __attribute__((unused)))
445
-void idle_done(struct mailbox *mailbox __attribute__((unused)))
446
+static void idle_poll_done(struct mailbox *mailbox __attribute__((unused)))
448
/* Remove the polling function */
449
signal(SIGALRM, SIG_IGN);
454
+struct idle_backend id_bk_poll =
458
+ &idle_poll_enabled,
464
diff -urNad cyrus-imapd-2.2.13/imap/version.c /tmp/dpep.7DrWs1/cyrus-imapd-2.2.13/imap/version.c
465
--- cyrus-imapd-2.2.13/imap/version.c 2006-08-21 23:32:39.000000000 +0200
466
+++ /tmp/dpep.7DrWs1/cyrus-imapd-2.2.13/imap/version.c 2006-08-23 18:13:56.181919844 +0200
470
#include "nonblock.h"
475
diff -urNad cyrus-imapd-2.2.13/lib/Makefile.in /tmp/dpep.7DrWs1/cyrus-imapd-2.2.13/lib/Makefile.in
476
--- cyrus-imapd-2.2.13/lib/Makefile.in 2006-08-23 18:13:47.000000000 +0200
477
+++ /tmp/dpep.7DrWs1/cyrus-imapd-2.2.13/lib/Makefile.in 2006-08-23 18:13:56.182919747 +0200
484
BUILTSOURCES = imapopts.h imapopts.c
486
LIBCYR_HDRS = $(srcdir)/acl.h $(srcdir)/assert.h $(srcdir)/auth.h \
488
$(RANLIB) libcyrus_min.a
490
imapopts.c: imapoptions $(srcdir)/../tools/config2header
491
- $(srcdir)/../tools/config2header CC=$(CC) $(srcdir)/imapopts.c $(srcdir)/imapopts.h < $(srcdir)/imapoptions
492
+ sed -e "s/%IDLE%/$(IDLE)/g" < $(srcdir)/imapoptions | $(srcdir)/../tools/config2header CC=$(CC) $(srcdir)/imapopts.c $(srcdir)/imapopts.h
494
imapopts.h: imapopts.c
496
diff -urNad cyrus-imapd-2.2.13/lib/imapoptions /tmp/dpep.7DrWs1/cyrus-imapd-2.2.13/lib/imapoptions
497
--- cyrus-imapd-2.2.13/lib/imapoptions 2006-08-23 18:13:47.000000000 +0200
498
+++ /tmp/dpep.7DrWs1/cyrus-imapd-2.2.13/lib/imapoptions 2006-08-23 18:13:56.182919747 +0200
500
/* The password to use for authentication to the backend server hostname
501
(where hostname is the short hostname of the server) - Cyrus Murder */
503
+{ "idlemethod", "%IDLE%", STRINGLIST("no", "poll", "idled") }
504
+/* The idle backend to use for IDLE command. */
506
{ "idlesocket", "{configdirectory}/socket/idle", STRING }
507
/* Unix domain socket that idled listens on. */