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 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542
|
/* sync_support.h -- Cyrus synchronization support functions
*
* Copyright (c) 1994-2008 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.
*
* Original version written by David Carter <dpc22@cam.ac.uk>
* Rewritten and integrated into Cyrus by Ken Murchison <ken@oceana.com>
*/
#ifndef INCLUDED_SYNC_SUPPORT_H
#define INCLUDED_SYNC_SUPPORT_H
#include "backend.h"
#include "dlist.h"
#include "prot.h"
#include "seen.h"
#include "mailbox.h"
#include "sync_log.h"
extern struct protocol_t imap_csync_protocol;
extern struct protocol_t csync_protocol;
#define SYNC_MSGID_LIST_HASH_SIZE (65536)
#define SYNC_MESSAGE_LIST_HASH_SIZE (65536)
#define SYNC_MESSAGE_LIST_MAX_OPEN_FILES (64)
const char *sync_get_config(const char *channel, const char *val);
int sync_get_durationconfig(const char *channel, const char *val, int defunit);
int sync_get_switchconfig(const char *channel, const char *val);
/* ====================================================================== */
int sync_parse_response(const char *name, struct protstream *in,
struct dlist **klp);
#define SYNC_PARSE_EAT_OKLINE (1)
#define SYNC_PARSE_NOEAT_OKLINE (0)
/* ====================================================================== */
struct sync_msgid {
struct sync_msgid *next;
struct sync_msgid *hash_next;
struct message_guid guid;
struct body *body;
size_t size;
char *fname;
unsigned int need_upload:1;
unsigned int is_archive:1;
};
struct sync_msgid_list {
struct sync_msgid *head;
struct sync_msgid *tail;
struct sync_msgid **hash;
int hash_size;
int count; /* Total number of messages in list */
int toupload; /* Number of messages needing upload in list */
};
struct sync_msgid_list *sync_msgid_list_create(int hash_size);
struct sync_msgid *sync_msgid_insert(struct sync_msgid_list *list,
const struct message_guid *guid);
void sync_msgid_remove(struct sync_msgid_list *l,
const struct message_guid *guid);
struct sync_msgid *sync_msgid_lookup(const struct sync_msgid_list *list,
const struct message_guid *guid);
void sync_msgid_list_free(struct sync_msgid_list **list);
struct sync_reserve {
struct sync_reserve *next;
char *part;
struct sync_msgid_list *list;
};
struct sync_reserve_list {
struct sync_reserve *head;
struct sync_reserve *tail;
int hash_size;
};
struct sync_reserve_list *sync_reserve_list_create(int hash_size);
struct sync_msgid_list *sync_reserve_partlist(struct sync_reserve_list *list,
const char *part);
void sync_reserve_list_free(struct sync_reserve_list **list);
/* ====================================================================== */
struct sync_folder {
struct sync_folder *next;
struct mailbox *mailbox;
char *uniqueid;
char *name;
uint32_t mbtype;
char *part;
char *acl;
uint32_t last_uid;
modseq_t highestmodseq;
uint32_t options;
uint32_t uidvalidity;
struct synccrcs synccrcs;
uint32_t recentuid;
time_t recenttime;
time_t pop3_last_login;
time_t pop3_show_after;
struct sync_annot_list *annots;
modseq_t xconvmodseq;
modseq_t raclmodseq;
modseq_t foldermodseq;
int ispartial;
struct quota quota;
int mark;
int reserve; /* Folder has been processed by reserve operation */
};
struct sync_folder_list {
struct sync_folder *head, *tail;
unsigned long count;
};
struct sync_folder_list *sync_folder_list_create(void);
struct sync_folder *sync_folder_list_add(struct sync_folder_list *l,
const char *uniqueid, const char *name,
uint32_t mbtype,
const char *part, const char *acl,
uint32_t options,
uint32_t uidvalidity,
uint32_t last_uid,
modseq_t highestmodseq,
struct synccrcs synccrcs,
uint32_t recentuid,
time_t recenttime,
time_t pop3_last_login,
time_t pop3_show_after,
struct sync_annot_list *annot,
modseq_t xconvmodseq,
modseq_t raclmodseq,
modseq_t foldermodseq,
int ispartial);
struct sync_folder *sync_folder_lookup(struct sync_folder_list *l,
const char *uniqueid);
void sync_folder_list_free(struct sync_folder_list **lp);
/* ====================================================================== */
struct sync_rename {
struct sync_rename *next;
char *uniqueid;
char *oldname;
char *newname;
char *part;
unsigned uidvalidity;
int done;
};
struct sync_rename_list {
struct sync_rename *head, *tail;
unsigned long count;
unsigned long done;
};
struct sync_rename_list *sync_rename_list_create(void);
struct sync_rename *sync_rename_list_add(struct sync_rename_list *l,
const char *id, const char *oldname,
const char *newname, const char *partition,
unsigned uidvalidity);
struct sync_rename *sync_rename_lookup(struct sync_rename_list *l,
const char *oldname);
void sync_rename_list_free(struct sync_rename_list **lp);
/* ====================================================================== */
struct sync_quota {
struct sync_quota *next;
char *root;
quota_t limits[QUOTA_NUMRESOURCES];
int done;
};
struct sync_quota_list {
struct sync_quota *head, *tail;
unsigned long count;
unsigned long done;
};
struct sync_quota_list *sync_quota_list_create(void);
struct sync_quota *sync_quota_list_add(struct sync_quota_list *l,
const char *root);
struct sync_quota *sync_quota_lookup(struct sync_quota_list *l,
const char *name);
void sync_quota_list_free(struct sync_quota_list **lp);
void sync_encode_quota_limits(struct dlist *kl, const quota_t limits[QUOTA_NUMRESOURCES]);
void sync_decode_quota_limits(/*const*/ struct dlist *kl, quota_t limits[QUOTA_NUMRESOURCES]);
/* ====================================================================== */
struct sync_name {
struct sync_name *next;
char *name;
int mark;
};
struct sync_name_list {
struct sync_name *head, *tail;
unsigned long count;
unsigned long marked;
};
struct sync_name_list *sync_name_list_create(void);
struct sync_name *sync_name_list_add(struct sync_name_list *l,
const char *name);
struct sync_name *sync_name_lookup(struct sync_name_list *l,
const char *name);
void sync_name_list_free(struct sync_name_list **lp);
/* ====================================================================== */
struct sync_seen {
struct sync_seen *next;
char *userid;
char *uniqueid;
struct seendata sd;
int mark;
};
struct sync_seen_list {
struct sync_seen *head, *tail;
unsigned long count;
};
struct sync_seen_list *sync_seen_list_create(void);
struct sync_seen *sync_seen_list_add(struct sync_seen_list *l,
const char *uniqueid,
time_t lastread, unsigned lastuid,
time_t lastchange, const char *seenuids);
struct sync_seen *sync_seen_list_lookup(struct sync_seen_list *l,
const char *uniqueid);
void sync_seen_list_free(struct sync_seen_list **lp);
/* ====================================================================== */
struct sync_sieve {
struct sync_sieve *next;
char *user;
char *name;
time_t last_update;
struct message_guid guid;
int active;
int mark;
};
struct sync_sieve_list {
struct sync_sieve *head;
struct sync_sieve *tail;
unsigned long count;
};
struct sync_sieve_list *sync_sieve_list_create(void);
void sync_sieve_list_free(struct sync_sieve_list **lp);
int sync_sieve_upload(const char *userid, const char *name,
time_t last_update, const char *content, size_t len);
int sync_sieve_activate(const char *userid, const char *bcname);
int sync_sieve_deactivate(const char *userid);
int sync_sieve_delete(const char *userid, const char *script);
/* ====================================================================== */
struct sync_annot {
struct sync_annot *next;
char *entry;
char *userid;
struct buf value;
int mark;
modseq_t modseq;
};
struct sync_annot_list {
struct sync_annot *head;
struct sync_annot *tail;
unsigned long count;
};
struct sync_annot_list *sync_annot_list_create(void);
void sync_annot_list_add(struct sync_annot_list *l,
const char *entry, const char *userid,
const struct buf *value,
modseq_t modseq);
void sync_annot_list_free(struct sync_annot_list **lp);
/* ====================================================================== */
struct sync_action {
struct sync_action *next;
int active;
char *name;
char *user;
};
struct sync_action_list {
struct sync_action *head, *tail;
unsigned long count;
};
struct sync_action_list *sync_action_list_create(void);
void sync_action_list_add(struct sync_action_list *l,
const char *name, const char *user);
void sync_action_list_free(struct sync_action_list **lp);
/* ====================================================================== */
void sync_send_response(struct dlist *kl, struct protstream *out);
void sync_send_apply(struct dlist *kl, struct protstream *out);
void sync_send_lookup(struct dlist *kl, struct protstream *out);
void sync_send_restart(struct protstream *out);
void sync_send_restore(struct dlist *kl, struct protstream *out);
struct dlist *sync_parseline(struct protstream *in);
/* ====================================================================== */
int addmbox_cb(const mbentry_t *mbentry, void *rock);
int parse_upload(struct dlist *kr, struct mailbox *mailbox,
struct index_record *record,
struct sync_annot_list **annotsp);
int sync_append_copyfile(struct mailbox *mailbox,
struct index_record *record,
const struct sync_annot_list *sal,
const struct sync_msgid_list *part_list);
/* ====================================================================== */
int read_annotations(const struct mailbox *,
const struct index_record *,
struct sync_annot_list **,
modseq_t since_modseq,
int flags);
/* ====================================================================== */
int sync_mailbox_version_check(struct mailbox **mailboxp);
/* ===================== client-side sync ============================= */
struct sync_client_state {
struct backend *backend;
struct protstream *clientin;
const char *servername;
const char *channel;
struct db *cachedb;
struct buf tagbuf;
unsigned flags;
};
#define SYNC_CLIENT_STATE_INITIALIZER { NULL, NULL, NULL, NULL, NULL, BUF_INITIALIZER, 0 }
/* ===================== server-side sync ============================= */
struct sync_state {
char *userid;
int userisadmin;
struct auth_state *authstate;
struct namespace *namespace;
struct protstream *pout;
unsigned flags;
};
int sync_get_message(struct dlist *kin, struct sync_state *sstate);
int sync_get_sieve(struct dlist *kin, struct sync_state *sstate);
int sync_get_annotation(struct dlist *kin, struct sync_state *sstate);
int sync_get_quota(struct dlist *kin, struct sync_state *sstate);
int sync_get_fullmailbox(struct dlist *kin, struct sync_state *sstate);
int sync_get_mailboxes(struct dlist *kin, struct sync_state *sstate);
int sync_get_meta(struct dlist *kin, struct sync_state *sstate);
int sync_get_user(struct dlist *kin, struct sync_state *sstate);
int sync_apply_reserve(struct dlist *kl,
struct sync_reserve_list *reserve_list,
struct sync_state *sstate);
int sync_apply_unquota(struct dlist *kin, struct sync_state *sstate);
int sync_apply_quota(struct dlist *kin, struct sync_state *sstate);
int sync_apply_mailbox(struct dlist *kin,
struct sync_reserve_list *reserve_list,
struct sync_state *sstate);
int sync_apply_unmailbox(struct dlist *kin, struct sync_state *sstate);
int sync_apply_rename(struct dlist *kin, struct sync_state *sstate);
int sync_apply_changesub(struct dlist *kin, struct sync_state *sstate);
int sync_apply_annotation(struct dlist *kin, struct sync_state *sstate);
int sync_apply_unannotation(struct dlist *kin, struct sync_state *sstate);
int sync_apply_sieve(struct dlist *kin, struct sync_state *sstate);
int sync_apply_unsieve(struct dlist *kin, struct sync_state *sstate);
int sync_apply_activate_sieve(struct dlist *kin, struct sync_state *sstate);
int sync_apply_unactivate_sieve(struct dlist *kin, struct sync_state *sstate);
int sync_apply_seen(struct dlist *kin, struct sync_state *sstate);
int sync_apply_unuser(struct dlist *kin, struct sync_state *sstate);
int sync_apply_expunge(struct dlist *kin, struct sync_state *sstate);
int sync_apply_message(struct dlist *kin,
struct sync_reserve_list *reserve_list,
struct sync_state *sstate);
const char *sync_apply(struct dlist *kin, struct sync_reserve_list *reserve_list, struct sync_state *state);
const char *sync_get(struct dlist *kin, struct sync_state *state);
const char *sync_restore(struct dlist *kin,
struct sync_reserve_list *reserve_list,
struct sync_state *state);
/* ===================== client-side sync ============================= */
#define SYNC_FLAG_VERBOSE (1<<0)
#define SYNC_FLAG_LOGGING (1<<1)
#define SYNC_FLAG_LOCALONLY (1<<2)
#define SYNC_FLAG_DELETE_REMOTE (1<<3)
#define SYNC_FLAG_NO_COPYBACK (1<<4)
#define SYNC_FLAG_BATCH (1<<5)
#define SYNC_FLAG_SIEVE_MAILBOX (1<<6)
#define SYNC_FLAG_NONBLOCK (1<<7)
int sync_do_seen(struct sync_client_state *sync_cs, const char *userid, char *uniqueid);
int sync_do_quota(struct sync_client_state *sync_cs, const char *root);
int sync_do_annotation(struct sync_client_state *sync_cs, const char *mboxname);
int sync_do_mailboxes(struct sync_client_state *sync_cs,
struct sync_name_list *mboxname_list,
const char *topart, int flags);
int sync_do_user(struct sync_client_state *sync_cs,
const char *userid, const char *topart);
int sync_do_meta(struct sync_client_state *sync_cs, const char *userid);
int sync_do_sub(struct sync_client_state *sync_cs,
const char *userid, const char *mboxname, int add);
int sync_response_parse(struct sync_client_state *sync_cs, const char *cmd,
struct sync_folder_list *folder_list,
struct sync_name_list *sub_list,
struct sync_sieve_list *sieve_list,
struct sync_seen_list *seen_list,
struct sync_quota_list *quota_list);
int sync_find_reserve_messages(struct mailbox *mailbox,
uint32_t fromuid, uint32_t touid,
struct sync_msgid_list *part_list);
int sync_reserve_partition(struct sync_client_state *sync_cs, char *partition,
struct sync_folder_list *replica_folders,
struct sync_msgid_list *part_list);
int sync_do_update_mailbox(struct sync_client_state *sync_cs,
struct sync_folder *local,
struct sync_folder *remote,
const char *topart,
struct sync_reserve_list *reserve_guids);
int sync_do_folder_delete(struct sync_client_state *sync_cs,
const char *mboxname);
int sync_do_user_quota(struct sync_client_state *sync_cs,
struct sync_name_list *master_quotaroots,
struct sync_quota_list *replica_quota);
int sync_do_user_sub(struct sync_client_state *sync_cs, const char *userid,
struct sync_name_list *replica_subs);
int sync_do_user_seen(struct sync_client_state *sync_cs, const char *userid,
struct sync_seen_list *replica_seen);
int sync_do_user_sieve(struct sync_client_state *sync_cs, const char *userid,
struct sync_sieve_list *replica_sieve);
int sync_do_restart(struct sync_client_state *sync_cs);
int sync_do_reader(struct sync_client_state *sync_cs, sync_log_reader_t *slr);
int sync_do_enable(struct sync_client_state *sync_cs, unsigned capa);
int sync_connect(struct sync_client_state *sync_cs);
void sync_disconnect(struct sync_client_state *sync_cs);
int sync_checkpoint(struct protstream *clientin);
/* ====================================================================== */
#endif /* INCLUDED_SYNC_SUPPORT_H */
|