Codebase list cyrus-imapd / debian/3.0.8-3 backup / backup.h
debian/3.0.8-3

Tree @debian/3.0.8-3 (Download .tar.gz)

backup.h @debian/3.0.8-3raw · history · blame

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
/* backup.h -- replication-based backup api
 *
 * Copyright (c) 1994-2015 Carnegie Mellon University.  All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution.
 *
 * 3. The name "Carnegie Mellon University" must not be used to
 *    endorse or promote products derived from this software without
 *    prior written permission. For permission or any legal
 *    details, please contact
 *      Carnegie Mellon University
 *      Center for Technology Transfer and Enterprise Creation
 *      4615 Forbes Avenue
 *      Suite 302
 *      Pittsburgh, PA  15213
 *      (412) 268-7393, fax: (412) 268-7395
 *      innovation@andrew.cmu.edu
 *
 * 4. Redistributions of any form whatsoever must retain the following
 *    acknowledgment:
 *    "This product includes software developed by Computing Services
 *     at Carnegie Mellon University (http://www.cmu.edu/computing/)."
 *
 * CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO
 * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
 * AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE
 * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
 * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 *
 */

#ifndef BACKUP_BACKUP_H
#define BACKUP_BACKUP_H

#include "imap/dlist.h"
#include "imap/mboxname.h"
#include "imap/sync_support.h"

#include "lib/gzuncat.h"

struct backup;

void backup_cleanup_staging_path(void);

/* opening the backups database */
#define FNAME_BACKUPDB "/backups.db"
int backupdb_open(struct db **backup_dbp, struct txn **tidp);


/* opening and closing backups */
enum backup_open_nonblock {
    BACKUP_OPEN_BLOCK = 0,
    BACKUP_OPEN_NONBLOCK = 1,
};

enum backup_open_create {
    BACKUP_OPEN_NOCREATE = 0,
    BACKUP_OPEN_CREATE = 1,
    BACKUP_OPEN_CREATE_EXCL = 2,
};

int backup_open(struct backup **backupp,
                const mbname_t *mbname,
                enum backup_open_nonblock nonblock,
                enum backup_open_create create);

int backup_get_paths(const mbname_t *mbname,
                     struct buf *data_fname, struct buf *index_fname,
                     enum backup_open_create create);

int backup_open_paths(struct backup **backupp,
                      const char *data_fname,
                      const char *index_fname,
                      enum backup_open_nonblock nonblock,
                      enum backup_open_create create);

int backup_close(struct backup **backupp); // also ends index/append ops
int backup_unlink(struct backup **backupp);


/* verifying backups */
enum {
    BACKUP_VERIFY_LAST_CHECKSUM = (1 << 0),
    BACKUP_VERIFY_ALL_CHECKSUMS = (1 << 1),
    BACKUP_VERIFY_MESSAGE_LINKS = (1 << 2),
    BACKUP_VERIFY_MAILBOX_LINKS = (1 << 3),
    BACKUP_VERIFY_MESSAGE_GUIDS = (1 << 4),
};
#define BACKUP_VERIFY_QUICK BACKUP_VERIFY_LAST_CHECKSUM
#define BACKUP_VERIFY_MESSAGES (BACKUP_VERIFY_MESSAGE_LINKS | BACKUP_VERIFY_MESSAGE_GUIDS)
#define BACKUP_VERIFY_FULL  ((unsigned) -1)
int backup_verify(struct backup *backup, unsigned level, int verbose, FILE *out);


/* accessing backup properties */
const char *backup_get_data_fname(const struct backup *backup);
const char *backup_get_index_fname(const struct backup *backup);
int backup_stat(const struct backup *backup,
                struct stat *data_statp,
                struct stat *index_statp);


/* reading backup chunk data */
struct backup_chunk {
    struct backup_chunk *next;
    int id;
    time_t ts_start;
    time_t ts_end;
    off_t offset;
    size_t length;
    char *file_sha1;
    char *data_sha1;
};

struct backup_chunk_list {
    struct backup_chunk *head;
    struct backup_chunk *tail;
    size_t count;
};

void backup_chunk_list_add(struct backup_chunk_list *list,
                           struct backup_chunk *chunk);
void backup_chunk_list_empty(struct backup_chunk_list *list);
void backup_chunk_list_free(struct backup_chunk_list **chunk_listp);

struct backup_chunk_list *backup_get_chunks(struct backup *backup);
struct backup_chunk_list *backup_get_live_chunks(struct backup *backup,
                                                 time_t since);

struct backup_chunk *backup_get_chunk(struct backup *backup, int chunk_id);
struct backup_chunk *backup_get_latest_chunk(struct backup *backup);

void backup_chunk_free(struct backup_chunk **chunkp);

/* reading backup mailbox data */
struct backup_mailbox_message {
    struct backup_mailbox_message *next;
    int id;
    int mailbox_id;
    char *mailbox_uniqueid;
    int message_id;
    int last_chunk_id;
    int uid;
    modseq_t modseq;
    time_t last_updated;
    char *flags;
    time_t internaldate;
    struct message_guid guid;
    size_t size;
    char *annotations;
    time_t expunged;
};

struct backup_mailbox_message_list {
    struct backup_mailbox_message *head;
    struct backup_mailbox_message *tail;
    size_t count;
};

struct backup_mailbox {
    struct backup_mailbox *next;
    int id;
    int last_chunk_id;
    char *uniqueid;
    char *mboxname;
    char *mboxtype;
    uint32_t last_uid;
    modseq_t highestmodseq;
    uint32_t recentuid;
    time_t recenttime;
    time_t last_appenddate;
    time_t pop3_last_login;
    time_t pop3_show_after;
    uint32_t uidvalidity;
    char *partition;
    char *acl;
    char *options;
    uint32_t sync_crc;
    uint32_t sync_crc_annot;
    char *quotaroot;
    modseq_t xconvmodseq;
    char *annotations;
    time_t deleted;
    struct backup_mailbox_message_list *records;
};

struct backup_mailbox_list {
    struct backup_mailbox *head;
    struct backup_mailbox *tail;
    size_t count;
};

enum backup_mailbox_want_records {
    BACKUP_MAILBOX_NO_RECORDS = 0,
    BACKUP_MAILBOX_ALL_RECORDS = 1,
    BACKUP_MAILBOX_MATCH_RECORDS = 2,
};

int backup_get_mailbox_id(struct backup *backup, const char *uniqueid);

typedef int (*backup_mailbox_foreach_cb)(const struct backup_mailbox *mailbox,
                                         void *rock);
int backup_mailbox_foreach(struct backup *backup, int chunk_id,
                           enum backup_mailbox_want_records want_records,
                           backup_mailbox_foreach_cb cb, void *rock);

struct backup_mailbox_list *backup_get_mailboxes(
                                struct backup *backup,
                                int chunk_id,
                                enum backup_mailbox_want_records want_records);

struct backup_message;
struct backup_mailbox_list *backup_get_mailboxes_by_message(
                                struct backup *backup,
                                const struct backup_message *message,
                                enum backup_mailbox_want_records want_records);

struct backup_mailbox *backup_get_mailbox_by_uniqueid(
                                struct backup *backup,
                                const char *uniqueid,
                                enum backup_mailbox_want_records want_records);

struct backup_mailbox *backup_get_mailbox_by_name(
                                struct backup *backup,
                                const mbname_t *mbname,
                                enum backup_mailbox_want_records want_records);

struct dlist *backup_mailbox_to_dlist(const struct backup_mailbox *mailbox);

struct backup_mailbox *backup_mailbox_clone(const struct backup_mailbox *mailbox);

void backup_mailbox_free(struct backup_mailbox **mailboxp);

struct backup_mailbox_message_list *backup_get_mailbox_messages(struct backup *backup,
                                                                int chunk_id);

struct backup_mailbox_message *backup_get_mailbox_message(
                                    struct backup *backup,
                                    const char *uniqueid,
                                    const char *guid);

struct backup_mailbox_message *backup_mailbox_message_clone(
                                    const struct backup_mailbox_message *orig);

void backup_mailbox_message_free(struct backup_mailbox_message **mailbox_messagep);

void backup_mailbox_list_add(struct backup_mailbox_list *list,
                             struct backup_mailbox *mailbox);

struct backup_mailbox *backup_mailbox_list_remove(struct backup_mailbox_list *list,
                                                  struct backup_mailbox *mailbox);

struct backup_mailbox_message *backup_mailbox_message_list_remove(
    struct backup_mailbox_message_list *list,
    struct backup_mailbox_message *mailbox_message);

void backup_mailbox_list_empty(struct backup_mailbox_list *list);
void backup_mailbox_message_list_empty(struct backup_mailbox_message_list *list);


/* reading backup message data */
struct backup_message {
    int id;
    struct message_guid *guid;
    char *partition;
    int chunk_id;
    off_t offset;
    size_t length;
};

int backup_get_message_id(struct backup *backup, const char *guid);
// FIXME do i even need these?
struct backup_message *backup_get_message(struct backup *backup,
                                          const struct message_guid *guid);
char *backup_get_message_content(struct backup *backup,
                                 const struct backup_message *message);
void backup_message_free(struct backup_message **message);

typedef int (*backup_message_foreach_cb)(const struct backup_message *message,
                                         void *rock);
int backup_message_foreach(struct backup *backup,
                           int chunk_id, const time_t *sincep,
                           backup_message_foreach_cb cb, void *rock);


/* reading backup seen data */
struct backup_seen {
    int id;
    int last_chunk_id;
    char *uniqueid;
    time_t lastread;
    uint32_t lastuid;
    time_t lastchange;
    char *seenuids;
};

void backup_seen_free(struct backup_seen **seen);

typedef int (*backup_seen_foreach_cb)(const struct backup_seen *seen,
                                      void *rock);
int backup_seen_foreach(struct backup *backup,
                        int chunk_id,
                        backup_seen_foreach_cb cb,
                        void *rock);


/* reading backup subscription data */
struct backup_subscription {
    int id;
    int last_chunk_id;
    char *mboxname;
    time_t unsubscribed;
};

void backup_subscription_free(struct backup_subscription **sub);

typedef int (*backup_subscription_foreach_cb)(const struct backup_subscription *sub,
                                              void *rock);
int backup_subscription_foreach(struct backup *backup,
                                int chunk_id,
                                backup_subscription_foreach_cb cb,
                                void *rock);


/* reading backup sieve data */
struct backup_sieve {
    int id;
    int chunk_id;
    time_t last_update;
    char *filename;
    struct message_guid guid;
    off_t offset;
    time_t deleted;
};

void backup_sieve_free(struct backup_sieve **sieve);

typedef int (*backup_sieve_foreach_cb)(const struct backup_sieve *sieve,
                                       void *rock);
int backup_sieve_foreach(struct backup *backup,
                         int chunk_id,
                         backup_sieve_foreach_cb cb,
                         void *rock);


/* writing backup data */
enum backup_append_flush {
    BACKUP_APPEND_NOFLUSH = 0,
    BACKUP_APPEND_FLUSH = 1,
};

int backup_append_start(struct backup *backup,
                        const time_t *tsp,
                        enum backup_append_flush flush);
int backup_append(struct backup *backup,
                  struct dlist *dlist,
                  const time_t *tsp,
                  enum backup_append_flush flush);
int backup_append_end(struct backup *backup,
                      const time_t *tsp);
int backup_append_abort(struct backup *backup);


/* reading backup data */
typedef int (*backup_read_data_cb)(const struct buf *buf, void *rock);

int backup_read_chunk_data(struct backup *backup,
                           const struct backup_chunk *chunk,
                           backup_read_data_cb proc, void *rock);
int backup_read_message_data(struct backup *backup,
                             const struct backup_message *message,
                             backup_read_data_cb proc, void *rock);

typedef struct sync_msgid *(*sync_msgid_lookup_func)(
    const struct sync_msgid_list *list,
    const struct message_guid *guid);

int backup_prepare_message_upload(struct backup *backup,
                                  const char *partition,
                                  struct sync_msgid_list *msgid_list,
                                  sync_msgid_lookup_func msgid_lookup,
                                  struct dlist **uploadp);
/* miscellaneous */
int backup_reindex(const char *name,
                   enum backup_open_nonblock nonblock,
                   int verbose, FILE *out);
int backup_rename(const mbname_t *old_mbname, const mbname_t *new_mbname);
int backup_compact(const char *name,
                   enum backup_open_nonblock nonblock,
                   int force, int verbose, FILE *out);

#endif