8da250dad4b11c4983031742a83fb8f358044fe0Stéphane Graber#ifndef MAILBOX_LIST_NOTIFY_H
8da250dad4b11c4983031742a83fb8f358044fe0Stéphane Graber#define MAILBOX_LIST_NOTIFY_H
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn
8da250dad4b11c4983031742a83fb8f358044fe0Stéphane Graber#include "guid.h"
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallynstruct mailbox_list_notify;
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallynenum mailbox_list_notify_event {
8da250dad4b11c4983031742a83fb8f358044fe0Stéphane Graber MAILBOX_LIST_NOTIFY_CREATE = 0x01,
dc76ac7ab5295b8ad40ac57c51e03da4dbd28479Serge Hallyn MAILBOX_LIST_NOTIFY_DELETE = 0x02,
8da250dad4b11c4983031742a83fb8f358044fe0Stéphane Graber MAILBOX_LIST_NOTIFY_RENAME = 0x04,
8da250dad4b11c4983031742a83fb8f358044fe0Stéphane Graber MAILBOX_LIST_NOTIFY_SUBSCRIBE = 0x08,
8da250dad4b11c4983031742a83fb8f358044fe0Stéphane Graber MAILBOX_LIST_NOTIFY_UNSUBSCRIBE = 0x10,
8da250dad4b11c4983031742a83fb8f358044fe0Stéphane Graber
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn MAILBOX_LIST_NOTIFY_UIDVALIDITY = 0x20,
8da250dad4b11c4983031742a83fb8f358044fe0Stéphane Graber MAILBOX_LIST_NOTIFY_APPENDS = 0x40,
8da250dad4b11c4983031742a83fb8f358044fe0Stéphane Graber MAILBOX_LIST_NOTIFY_EXPUNGES = 0x80,
8da250dad4b11c4983031742a83fb8f358044fe0Stéphane Graber MAILBOX_LIST_NOTIFY_SEEN_CHANGES = 0x100,
8da250dad4b11c4983031742a83fb8f358044fe0Stéphane Graber MAILBOX_LIST_NOTIFY_MODSEQ_CHANGES = 0x200
8da250dad4b11c4983031742a83fb8f358044fe0Stéphane Graber#define MAILBOX_LIST_NOTIFY_STATUS \
8da250dad4b11c4983031742a83fb8f358044fe0Stéphane Graber (MAILBOX_LIST_NOTIFY_APPENDS | \
8da250dad4b11c4983031742a83fb8f358044fe0Stéphane Graber MAILBOX_LIST_NOTIFY_EXPUNGES | \
8da250dad4b11c4983031742a83fb8f358044fe0Stéphane Graber MAILBOX_LIST_NOTIFY_SEEN_CHANGES | \
dc76ac7ab5295b8ad40ac57c51e03da4dbd28479Serge Hallyn MAILBOX_LIST_NOTIFY_MODSEQ_CHANGES)
8da250dad4b11c4983031742a83fb8f358044fe0Stéphane Graber};
8da250dad4b11c4983031742a83fb8f358044fe0Stéphane Graber
8da250dad4b11c4983031742a83fb8f358044fe0Stéphane Graberstruct mailbox_list_notify {
8da250dad4b11c4983031742a83fb8f358044fe0Stéphane Graber struct mailbox_list *list;
8da250dad4b11c4983031742a83fb8f358044fe0Stéphane Graber enum mailbox_list_notify_event mask;
8da250dad4b11c4983031742a83fb8f358044fe0Stéphane Graber};
8da250dad4b11c4983031742a83fb8f358044fe0Stéphane Graber
8da250dad4b11c4983031742a83fb8f358044fe0Stéphane Graberstruct mailbox_list_notify_rec {
8da250dad4b11c4983031742a83fb8f358044fe0Stéphane Graber /* Each record can contain multiple events */
8da250dad4b11c4983031742a83fb8f358044fe0Stéphane Graber enum mailbox_list_notify_event events;
dc76ac7ab5295b8ad40ac57c51e03da4dbd28479Serge Hallyn
8da250dad4b11c4983031742a83fb8f358044fe0Stéphane Graber /* For all events: */
8da250dad4b11c4983031742a83fb8f358044fe0Stéphane Graber const char *storage_name, *vname;
8da250dad4b11c4983031742a83fb8f358044fe0Stéphane Graber /* For selectable mailboxes: */
8da250dad4b11c4983031742a83fb8f358044fe0Stéphane Graber guid_128_t guid;
8da250dad4b11c4983031742a83fb8f358044fe0Stéphane Graber
8da250dad4b11c4983031742a83fb8f358044fe0Stéphane Graber /* For rename: */
8da250dad4b11c4983031742a83fb8f358044fe0Stéphane Graber const char *old_vname;
8da250dad4b11c4983031742a83fb8f358044fe0Stéphane Graber};
8da250dad4b11c4983031742a83fb8f358044fe0Stéphane Graber
8da250dad4b11c4983031742a83fb8f358044fe0Stéphane Grabertypedef void mailbox_list_notify_callback_t(void *);
/* Monitor for specified changes in the mailbox list.
Returns 0 if ok, -1 if notifications aren't supported. */
int mailbox_list_notify_init(struct mailbox_list *list,
enum mailbox_list_notify_event mask,
struct mailbox_list_notify **notify_r);
void mailbox_list_notify_deinit(struct mailbox_list_notify **notify);
/* Get the next change. Returns 1 if record was returned, 0 if there are no
more changes currently or -1 if some error occurred */
int mailbox_list_notify_next(struct mailbox_list_notify *notify,
const struct mailbox_list_notify_rec **rec_r);
/* Call the specified callback when something changes. */
void mailbox_list_notify_wait(struct mailbox_list_notify *notify,
mailbox_list_notify_callback_t *callback, void *context);
#define mailbox_list_notify_wait(notify, callback, context) \
mailbox_list_notify_wait(notify + CALLBACK_TYPECHECK(callback, void (*)(typeof(context))), \
(mailbox_list_notify_callback_t*)callback, context);
/* Flush any delayed notifications now. */
void mailbox_list_notify_flush(struct mailbox_list_notify *notify);
#endif