-
Notifications
You must be signed in to change notification settings - Fork 1
/
mcal.h
executable file
·439 lines (353 loc) · 12.4 KB
/
mcal.h
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
/*
* $Id: mcal.h,v 1.10 2001/01/09 03:26:48 markie Exp $
* Libmcal - Modular Calendar Access Library
* Copyright (C) 1999 Mark Musone and Andrew Skalski
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
* Contact Information:
*
* Mark Musone
*
* Andrew Skalski
*
*/
#ifndef _MCAL_H
#define _MCAL_H
#include <stdarg.h>
#include "bool.h"
#include "datetime.h"
#include "cal_misc.h"
/* default folder, if none is specified */
#define DEFAULT_FOLDER "INBOX"
/* default protocol if none is specified */
#define DEFAULT_PROTO "icap"
/* calendar library version */
#define CALVER "0.6"
/* calendar library date */
#define MCALVER 20000121
/* structs */
#define CALDRIVER struct cal_driver
#define CALSTREAM struct cal_stream
#define CALADDR struct cal_addr
#define CALEVENT struct cal_event
#define CALATTR struct cal_attr
/* calendar options */
enum {
CAL_LOGIN = 1, /* cal_open() - relogin */
};
/* recurrence options */
typedef enum {
RECUR_NONE, /* event does not recur */
RECUR_DAILY, /* daily */
RECUR_WEEKLY, /* weekly on a set of weekdays */
RECUR_MONTHLY_MDAY, /* monthly on a specific date */
RECUR_MONTHLY_WDAY, /* monthly on the nth fooday */
RECUR_YEARLY, /* yearly */
/* new recur types go here */
NUM_RECUR_TYPES
} recur_t;
/* weekday mask type */
enum {
M_SUNDAY = 0x1,
M_MONDAY = 0x2,
M_TUESDAY = 0x4,
M_WEDNESDAY = 0x8,
M_THURSDAY = 0x10,
M_FRIDAY = 0x20,
M_SATURDAY = 0x40,
M_WEEKDAYS = 0x3e,
M_WEEKEND = 0x41,
M_ALLDAYS = 0x7f,
};
/* recurrence data union */
typedef union recurdata
{
/* only recur type that is not fully specified using only the
* start-date field is weekly, since a set of weekdays must be
* supplied.
*/
long weekly_wday;
} recurdata_t;
/* driver specific linked list data */
CALATTR {
char *name; /* name */
char *value; /* value */
CALATTR **prev; /* previous in list */
CALATTR *next; /* next in list */
};
/* event structure */
CALEVENT {
unsigned long id; /* ID number */
bool public; /* public flag */
datetime_t start; /* start of event */
datetime_t end; /* end of event */
char *category; /* event category */
char *title; /* event title */
char *description; /* event description */
/* minutes before event that alarm is to sound (0 means no alarm) */
long alarm;
/* recurrence info */
recur_t recur_type; /* recurrence type */
long recur_interval; /* recurrence interval */
datetime_t recur_enddate; /* last recurrence */
recurdata_t recur_data; /* type-specific data */
CALATTR *attrlist; /* attribute list */
};
/* calendar address structure */
CALADDR {
const char *host; /* network host */
const char *proto; /* network protocol */
const char *user; /* folder owner */
const char *folder; /* folder name */
char *buf; /* dynamic buffer */
size_t bufsize; /* buffer size */
};
/* calendar stream struct */
CALSTREAM {
const CALDRIVER *driver; /* stream driver */
CALADDR *addr; /* folder address */
bool dead; /* dead stream? */
weekday_t startofweek; /* first day of week */
void *data; /* driver-specific data */
};
/* calendar driver structure */
CALDRIVER {
/* return true if <addr> is valid for this driver */
bool (*valid)( const CALADDR *addr);
/* open a calendar stream to the given <addr>.
* if <stream> is non-NULL, attempt to re-use it;
* otherwise allocate a new stream and open it.
* do not allocate if stream re-use is not possible.
* return NULL on error.
*/
CALSTREAM* (*open)( CALSTREAM *stream,
const CALADDR *addr,
long options);
/* close <stream>, release its resources, and return NULL.
* in the future, it may be possible to keep the stream
* open (but the folder is closed and user is logged out)
* for persistent connections. this must be specified
* as an option flag.
*/
CALSTREAM* (*close)( CALSTREAM *stream,
long options);
/* return true if the stream is still alive */
bool (*ping)( CALSTREAM *stream);
/* return true if calendar created ok */
bool (*create)( CALSTREAM *stream,
const char *calendar);
/* search the current folder for events between <start> and
* <end> (inclusive.) if either lacks a date or is NULL, that
* bound will not be checked. if both lack a date or are NULL,
* then all events in the folder will be returned. event id's
* are returned by the cc_searched() callback. returns false
* on error.
*/
bool (*search_range)( CALSTREAM *stream,
const datetime_t *start,
const datetime_t *end);
/* search the current folder for active alarms. the alarms
* are checked against the specified <when> date/time.
* alarms are considered active if <when> is after {alarm}
* minutes before event start, and before the event end,
* inclusively. returns false on error.
*/
bool (*search_alarm)( CALSTREAM *stream,
const datetime_t *when);
/* fetch the event matching <id>. if the event is found, it
* is allocated and a pointer to it is stored in (*event).
* otherwise NULL is stored in (*event). returns false on error.
*/
bool (*fetch)( CALSTREAM *stream,
unsigned long id,
CALEVENT **event);
/* appends <event> to the folder specified by <addr>. if
* successful, the ID of the new event is stored in (*id).
* returns true on success.
*/
bool (*append)( CALSTREAM *stream,
const CALADDR *addr,
unsigned long *id,
const CALEVENT *event);
/* removes the event specified by <id> from the folder. returns
* false on error.
*/
bool (*remove)( CALSTREAM *stream,
unsigned long id);
/* cancels the alarm for the event specified by <id>. returns
* false on error.
*/
bool (*snooze)( CALSTREAM *stream,
unsigned long id);
bool (*store)( CALSTREAM *stream,
const CALEVENT *event);
/* Delete an entire calendar */
bool (*delete)( CALSTREAM *stream, char *calendar);
bool (*rename)( CALSTREAM *stream,char *src,char *dest);
};
/** calendar client callbacks **/
/* Called when a stream driver requires a username/password. It is
* only called during cal_open().
*/
void cc_login(const char **username, const char **password);
/* Called whenever an ID is returned by the cal_search family of
* routines.
*/
void cc_searched(unsigned long id);
/* normal system logging */
void cc_vlog(const char *fmt, va_list ap);
/* debug logging */
void cc_vdlog(const char *fmt, va_list ap);
/** logging wrapper functions **/
void cc_log(const char *fmt, ...); /* normal system logging */
void cc_dlog(const char *fmt, ...); /* debug logging */
/** calendar client functions **/
/* Parses a calendar address and returns a CALADDR structure, which must
* be disposed of with caladdr_free(). returns NULL on error.
*/
CALADDR* caladdr_parse(const char *address);
/* Duplicates the CALADDR struct (must later be disposed
* of with caladdr_free())
*/
CALADDR* caladdr_dup(const CALADDR *addr);
/* Constructs a string representing a CALADDR (must be freed())
* returns NULL on error
*/
char* caladdr_out(const CALADDR *addr);
/* Disposes of a CALADDR structure, returns NULL for convenience. */
CALADDR* caladdr_free(CALADDR *addr);
/* Allocates a new CALEVENT. */
CALEVENT* calevent_new(void);
/* Disposes of a CALEVENT, returns NULL for convenience. */
CALEVENT* calevent_free(CALEVENT *event);
/* Check the validity of an event's fields. */
bool calevent_valid(const CALEVENT *event);
/* Routines to set and fetch event attributes. */
const char* calevent_getattr(const CALEVENT *event, const char *name);
bool calevent_setattr(CALEVENT *event, const char *name,
const char *value);
/* Routines to alter event recurrence. */
bool calevent_recur_none(CALEVENT *event);
bool calevent_recur_daily(CALEVENT *event, datetime_t *enddate,
long interval);
bool calevent_recur_weekly(CALEVENT *event, datetime_t *enddate,
long interval, long weekdays);
bool calevent_recur_monthly_mday(CALEVENT *event,
datetime_t *enddate, long interval);
bool calevent_recur_monthly_wday(CALEVENT *event,
datetime_t *enddate, long interval);
bool calevent_recur_yearly(CALEVENT *event,
datetime_t *enddate, long interval);
/* Routines to evaluate event recurrence. */
/* fills in <next> with the next date the event occurs. if <next> has
* a date value, it is filled with the next date the event occurs, on or
* after the supplied date. Returns empty date field if event does not
* occur or something is invalid.
*/
void calevent_next_recurrence( const CALEVENT *event,
datetime_t *next,
weekday_t startofweek);
/* moves <clamp> ahead to the first day in <mask> after <clamp>, using
* <weekstart> as the first day of the week. returns false if none
* was found.
*/
bool first_day_not_before( int mask, weekday_t *clamp,
weekday_t weekstart);
/* Creates a new calendar
*/
bool cal_create(CALSTREAM *stream,const char *calendar);
/* Returns true if the address is valid for any of the calendar drivers */
bool cal_valid(const char *address);
/* Opens a stream (recycles <stream> if not NULL) and returns it. returns
* NULL on error.
*/
CALSTREAM* cal_open(CALSTREAM *stream, const char *address, long options);
/* Same as cal_open() but takes a parsed CALADDR structure instead of a
* string folder name
*/
CALSTREAM* cal_open_addr( CALSTREAM *stream, const CALADDR *addr,
long options);
/* Closes the stream and returns a new handle. This will be normally
* be NULL, but certain options may allow for persistent connections,
* in which case the folder will be closed and user logged out, but the
* stream left open for further use.
*/
CALSTREAM* cal_close(CALSTREAM *stream, long options);
/* Returns true if the stream is still alive. */
bool cal_ping(CALSTREAM *stream);
/* Searches the current folder for events between <start> and <end>,
* inclusively. If either <start> or <end> lacks a date or is NULL,
* it will be ignored.
*/
bool cal_search_range( CALSTREAM *stream,
const datetime_t *start,
const datetime_t *end);
/* Searches the current folder for active alarms, using <when> as the
* reference time. <when> must contain both date and time components.
*/
bool cal_search_alarm(CALSTREAM *stream, const datetime_t *when);
/* Fetches the event with id of <id> from the folder. Returns false on
* error. (*event) points to the event (which must be freed) or to NULL
* if it was not found.
*/
bool cal_fetch( CALSTREAM *stream,
unsigned long id,
CALEVENT **event);
/* Appends an event to <folder>. Returns false on error. If successful,
* the ID of the new event is stored in (*id)
*/
bool cal_append( CALSTREAM *stream,
const char *folder,
unsigned long *id,
const CALEVENT *event);
/* Same as cal_append(), but uses a parsed CALADDR instead of a folder
* string.
*/
bool cal_append_addr(CALSTREAM *stream,
const CALADDR *addr,
unsigned long *id,
const CALEVENT *event);
/* Save changes to an already existing event. If the event doesn't yet
* exist (it has uid 0) then cal_append is called. Returns the saved uid
* on success, and false on failure.
*/
bool cal_store( CALSTREAM *stream,
CALEVENT *event);
/* Removes the event with id of <id> from the folder. Returns false on
* error.
*/
bool cal_remove( CALSTREAM *stream,
unsigned long id);
/* Cancels the alarm for event with id of <id>. Returns false on error. */
bool cal_snooze( CALSTREAM *stream,
unsigned long id);
/* delete an entire calendar */
bool cal_delete( CALSTREAM *stream,
char *calendar);
/* rename a calendar */
bool cal_rename( CALSTREAM *stream,
char *src,char *dest);
/* private functions */
/* Searches for a driver for the given calendar address. Returns NULL
* if none is found.
*/
const CALDRIVER* cal_getdriver(const CALADDR *addr);
#include "icalroutines.h"
#endif