1 /* caldav_db.h -- abstract interface for per-user CalDAV database 2 * 3 * Copyright (c) 1994-2012 Carnegie Mellon University. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in 14 * the documentation and/or other materials provided with the 15 * distribution. 16 * 17 * 3. The name "Carnegie Mellon University" must not be used to 18 * endorse or promote products derived from this software without 19 * prior written permission. For permission or any legal 20 * details, please contact 21 * Carnegie Mellon University 22 * Center for Technology Transfer and Enterprise Creation 23 * 4615 Forbes Avenue 24 * Suite 302 25 * Pittsburgh, PA 15213 26 * (412) 268-7393, fax: (412) 268-7395 27 * innovation@andrew.cmu.edu 28 * 29 * 4. Redistributions of any form whatsoever must retain the following 30 * acknowledgment: 31 * "This product includes software developed by Computing Services 32 * at Carnegie Mellon University (http://www.cmu.edu/computing/)." 33 * 34 * CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO 35 * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 36 * AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE 37 * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 38 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN 39 * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING 40 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 41 * 42 */ 43 44 #ifndef CALDAV_DB_H 45 #define CALDAV_DB_H 46 47 #include <config.h> 48 49 extern time_t caldav_epoch; 50 extern time_t caldav_eternity; 51 52 #include <libical/ical.h> 53 54 #include "dav_db.h" 55 #include "ical_support.h" 56 57 /* Bitmask of calendar components */ 58 enum { 59 /* "Real" components - MUST remain in this order (values used in DAV DB) */ 60 CAL_COMP_VEVENT = (1<<0), 61 CAL_COMP_VTODO = (1<<1), 62 CAL_COMP_VJOURNAL = (1<<2), 63 CAL_COMP_VFREEBUSY = (1<<3), 64 CAL_COMP_VAVAILABILITY = (1<<4), 65 CAL_COMP_VPOLL = (1<<5), 66 /* Append additional "real" components here */ 67 68 /* Other components - values don't matter - prepend here */ 69 CAL_COMP_VALARM = (1<<13), 70 CAL_COMP_VTIMEZONE = (1<<14), 71 CAL_COMP_VCALENDAR = (1<<15) 72 }; 73 74 /* Returns NULL for unknown type */ 75 extern const char *caldav_comp_type_as_string(unsigned comp_type); 76 77 #define CAL_COMP_REAL 0xff /* All "real" components */ 78 79 struct caldav_db; 80 81 struct comp_flags { 82 unsigned recurring : 1; /* Has RRULE property */ 83 unsigned transp : 1; /* Is TRANSParent */ 84 unsigned status : 2; /* STATUS property value (see below) */ 85 unsigned tzbyref : 1; /* VTIMEZONEs by reference */ 86 unsigned mattach : 1; /* Has managed ATTACHment(s) */ 87 unsigned shared : 1; /* Is shared (per-user-data stripped) */ 88 }; 89 90 /* Status values */ 91 enum { 92 CAL_STATUS_BUSY = 0, 93 CAL_STATUS_CANCELED, 94 CAL_STATUS_TENTATIVE, 95 CAL_STATUS_UNAVAILABLE 96 }; 97 98 struct caldav_data { 99 struct dav_data dav; /* MUST be first so we can typecast */ 100 unsigned comp_type; 101 const char *ical_uid; 102 const char *organizer; 103 const char *dtstart; 104 const char *dtend; 105 struct comp_flags comp_flags; 106 const char *sched_tag; 107 int jmapversion; 108 const char *jmapdata; 109 }; 110 111 typedef int caldav_cb_t(void *rock, struct caldav_data *cdata); 112 113 /* prepare for caldav operations in this process */ 114 int caldav_init(void); 115 116 /* done with all caldav operations for this process */ 117 int caldav_done(void); 118 119 /* get a database handle corresponding to mailbox */ 120 struct caldav_db *caldav_open_mailbox(struct mailbox *mailbox); 121 struct caldav_db *caldav_open_userid(const char *userid); 122 123 /* close this handle */ 124 int caldav_close(struct caldav_db *caldavdb); 125 126 /* lookup an entry from 'caldavdb' by resource 127 (optionally inside a transaction for updates) */ 128 int caldav_lookup_resource(struct caldav_db *caldavdb, 129 const char *mailbox, const char *resource, 130 struct caldav_data **result, 131 int tombstones); 132 133 /* lookup an entry from 'caldavdb' by mailbox and IMAP uid 134 (optionally inside a transaction for updates) */ 135 int caldav_lookup_imapuid(struct caldav_db *caldavdb, 136 const char *mailbox, int uid, 137 struct caldav_data **result, 138 int tombstones); 139 140 /* lookup an entry from 'caldavdb' by iCal UID 141 (optionally inside a transaction for updates) */ 142 int caldav_lookup_uid(struct caldav_db *caldavdb, const char *ical_uid, 143 struct caldav_data **result); 144 145 /* process each entry for 'mailbox' in 'caldavdb' with cb() */ 146 int caldav_foreach(struct caldav_db *caldavdb, const char *mailbox, 147 caldav_cb_t *cb, void *rock); 148 149 enum caldav_sort { 150 CAL_SORT_NONE = 0, 151 CAL_SORT_UID, 152 CAL_SORT_START, 153 CAL_SORT_MAILBOX, 154 CAL_SORT_DESC = 0x80 /* bit-flag for descending sort */ 155 }; 156 157 /* process each entry for 'mailbox' in 'caldavdb' with cb() 158 * which last recurrence ends after 'after' and first 159 * recurrence starts before 'before'. The largest possible 160 * timerange spans from caldav_epoch to caldav_eternity. 161 * The callback is called in order of sort, or by an 162 * arbitrary order if no sort is specified. */ 163 int caldav_foreach_timerange(struct caldav_db *caldavdb, const char *mailbox, 164 time_t after, time_t before, 165 enum caldav_sort* sort, size_t nsort, 166 caldav_cb_t *cb, void *rock); 167 168 /* write an entry to 'caldavdb' */ 169 int caldav_write(struct caldav_db *caldavdb, struct caldav_data *cdata); 170 int caldav_writeentry(struct caldav_db *caldavdb, struct caldav_data *cdata, 171 icalcomponent *ical); 172 173 /* delete an entry from 'caldavdb' */ 174 int caldav_delete(struct caldav_db *caldavdb, unsigned rowid); 175 176 /* delete all entries for 'mailbox' from 'caldavdb' */ 177 int caldav_delmbox(struct caldav_db *caldavdb, const char *mailbox); 178 179 /* begin transaction */ 180 int caldav_begin(struct caldav_db *caldavdb); 181 182 /* commit transaction */ 183 int caldav_commit(struct caldav_db *caldavdb); 184 185 /* abort transaction */ 186 int caldav_abort(struct caldav_db *caldavdb); 187 188 char *caldav_mboxname(const char *userid, const char *name); 189 190 int caldav_get_events(struct caldav_db *caldavdb, const char *asuserid, 191 const char *mailbox, const char *ical_uid, 192 caldav_cb_t *cb, void *rock); 193 194 int caldav_write_jmapcache(struct caldav_db *caldavdb, int rowid, 195 const char *userid, int version, const char *data); 196 197 198 /* Process each entry for 'caldavdb' with a modseq higher than oldmodseq, 199 * in ascending order of modseq. 200 * If mailbox is not NULL, only process entries of this mailbox. 201 * If kind is non-negative, only process entries of this kind. 202 * If max_records is positive, only call cb for at most this entries. */ 203 int caldav_get_updates(struct caldav_db *caldavdb, 204 modseq_t oldmodseq, const char *mailbox, int kind, 205 int max_records, caldav_cb_t *cb, void *rock); 206 207 /* Update all the share ACLs */ 208 int caldav_update_shareacls(const char *userid); 209 210 #endif /* CALDAV_DB_H */ 211