1 /* ical_support.h -- Helper functions for libical
2  *
3  * Copyright (c) 1994-2015 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 ICAL_SUPPORT_H
45 #define ICAL_SUPPORT_H
46 
47 #include <config.h>
48 
49 #ifdef HAVE_ICAL
50 
51 #include <libical/ical.h>
52 
53 #include "mailbox.h"
54 
55 extern const char *icalparameter_get_value_as_string(icalparameter *param);
56 extern struct icaldatetimeperiodtype
57 icalproperty_get_datetimeperiod(icalproperty *prop);
58 extern time_t icaltime_to_timet(icaltimetype t, const icaltimezone *floatingtz);
59 
60 /* If range is a NULL period, callback() is executed for ALL occurrences,
61    otherwise callback() is only executed for occurrences that overlap the range.
62    callback() returns true (1) while it wants more occurrences, 0 to finish */
63 extern int icalcomponent_myforeach(icalcomponent *comp,
64                                    struct icalperiodtype range,
65                                    const icaltimezone *floatingtz,
66                                    int (*callback) (icalcomponent *comp,
67                                                     icaltimetype start,
68                                                     icaltimetype end,
69                                                     void *data),
70                                    void *callback_data);
71 
72 
73 extern icalcomponent *ical_string_as_icalcomponent(const struct buf *buf);
74 extern struct buf *my_icalcomponent_as_ical_string(icalcomponent* comp);
75 
76 extern icalcomponent *record_to_ical(struct mailbox *mailbox,
77                                      const struct index_record *record,
78                                      char **schedule_userid);
79 
80 extern const char *get_icalcomponent_errstr(icalcomponent *ical);
81 
82 extern void icalcomponent_remove_invitee(icalcomponent *comp,
83                                          icalproperty *prop);
84 extern icalproperty *icalcomponent_get_first_invitee(icalcomponent *comp);
85 extern icalproperty *icalcomponent_get_next_invitee(icalcomponent *comp);
86 extern const char *icalproperty_get_invitee(icalproperty *prop);
87 
88 extern icaltimetype icalcomponent_get_recurrenceid_with_zone(icalcomponent *c);
89 
90 extern icalproperty *icalcomponent_get_x_property_by_name(icalcomponent *comp,
91                                                           const char *name);
92 
93 extern struct icalperiodtype icalcomponent_get_utc_timespan(icalcomponent *comp,
94                                                             icalcomponent_kind kind);
95 
96 extern struct icalperiodtype icalrecurrenceset_get_utc_timespan(icalcomponent *ical,
97                                                                 icalcomponent_kind kind,
98                                                                 unsigned *is_recurring,
99                                                                 void (*comp_cb)(icalcomponent*,
100                                                                                 void*),
101                                                                 void *cb_rock);
102 
103 extern void icaltime_set_utc(struct icaltimetype *t, int set);
104 
105 
106 /* Functions not declared in in libical < v2.0 */
107 
108 #if !HAVE_DECL_ICALPROPERTY_GET_PARENT
109 extern icalcomponent *icalproperty_get_parent(const icalproperty *property);
110 #endif
111 
112 #if !HAVE_DECL_ICALRECUR_FREQ_TO_STRING
113 extern const char *icalrecur_freq_to_string(icalrecurrencetype_frequency kind);
114 #endif
115 
116 #if !HAVE_DECL_ICALRECUR_WEEKDAY_TO_STRING
117 extern const char *icalrecur_weekday_to_string(icalrecurrencetype_weekday kind);
118 #endif
119 
120 
121 #ifdef HAVE_TZDIST_PROPS
122 
123 #define icalcomponent_get_tzuntil_property(comp) \
124     icalcomponent_get_first_property(comp, ICAL_TZUNTIL_PROPERTY)
125 
126 #else /* !HAVE_TZDIST_PROPS */
127 
128 /* Functions to replace those not available in libical < v2.0 */
129 
130 #define icalcomponent_get_tzuntil_property(comp) \
131     icalcomponent_get_x_property_by_name(comp, "TZUNTIL")
132 
133 extern icalproperty *icalproperty_new_tzidaliasof(const char *v);
134 extern icalproperty *icalproperty_new_tzuntil(struct icaltimetype v);
135 
136 #endif /* HAVE_TZDIST_PROPS */
137 
138 
139 #ifdef HAVE_VALARM_EXT_PROPS
140 
141 #define icalcomponent_get_acknowledged_property(comp) \
142     icalcomponent_get_first_property(comp, ICAL_ACKNOWLEDGED_PROPERTY)
143 
144 #else /* !HAVE_VALARM_EXT_PROPS */
145 
146 /* Functions to replace those not available in libical < v1.0 */
147 
148 #define icalcomponent_get_acknowledged_property(comp) \
149     icalcomponent_get_x_property_by_name(comp, "ACKNOWLEDGED")
150 
151 extern icalproperty *icalproperty_new_acknowledged(struct icaltimetype v);
152 extern struct icaltimetype icalproperty_get_acknowledged(const icalproperty *prop);
153 
154 #endif /* HAVE_VALARM_EXT_PROPS */
155 
156 
157 #ifndef HAVE_RSCALE
158 
159 /* Functions to replace those not available in libical < v1.0 */
160 
161 #define icalrecurrencetype_month_is_leap(month) 0
162 #define icalrecurrencetype_month_month(month) month
163 
164 #endif /* HAVE_RSCALE */
165 
166 
167 #ifdef HAVE_MANAGED_ATTACH_PARAMS
168 
169 /* Wrappers to fetch managed attachment parameters by kind */
170 
171 #define icalproperty_get_filename_parameter(prop) \
172     icalproperty_get_first_parameter(prop, ICAL_FILENAME_PARAMETER)
173 
174 #define icalproperty_get_managedid_parameter(prop) \
175     icalproperty_get_first_parameter(prop, ICAL_MANAGEDID_PARAMETER)
176 
177 #define icalproperty_get_size_parameter(prop) \
178     icalproperty_get_first_parameter(prop, ICAL_SIZE_PARAMETER)
179 
180 #elif defined(HAVE_IANA_PARAMS)
181 
182 /* Functions to replace those not available in libical < v2.0 */
183 
184 extern icalparameter* icalproperty_get_iana_parameter_by_name(icalproperty *prop,
185                                                               const char *name);
186 
187 extern icalparameter *icalparameter_new_filename(const char *fname);
188 
189 extern void icalparameter_set_filename(icalparameter *param, const char *fname);
190 
191 extern icalparameter *icalparameter_new_managedid(const char *id);
192 
193 extern const char *icalparameter_get_managedid(icalparameter *param);
194 
195 extern void icalparameter_set_managedid(icalparameter *param, const char *id);
196 
197 extern icalparameter *icalparameter_new_size(const char *sz);
198 
199 extern const char *icalparameter_get_size(icalparameter *param);
200 
201 extern void icalparameter_set_size(icalparameter *param, const char *sz);
202 
203 /* Wrappers to fetch managed attachment parameters by kind */
204 
205 #define icalproperty_get_filename_parameter(prop) \
206     icalproperty_get_iana_parameter_by_name(prop, "FILENAME")
207 
208 #define icalproperty_get_managedid_parameter(prop) \
209     icalproperty_get_iana_parameter_by_name(prop, "MANAGED-ID")
210 
211 #define icalproperty_get_size_parameter(prop) \
212     icalproperty_get_iana_parameter_by_name(prop, "SIZE")
213 
214 #else /* !HAVE_IANA_PARAMS */
215 
216 /* Dummy functions to allow compilation with libical < v0.48 */
217 
218 #define icalparameter_new_filename(fname) NULL
219 
220 #define icalparameter_set_filename(param, fname) (void) param
221 
222 #define icalparameter_new_managedid(id) NULL
223 
224 #define icalparameter_get_managedid(param) ""
225 
226 #define icalparameter_set_managedid(param, id) (void) param
227 
228 #define icalparameter_new_size(sz) NULL
229 
230 #define icalparameter_set_size(param, sz) (void) param
231 
232 #define icalproperty_get_filename_parameter(prop) NULL
233 
234 #define icalproperty_get_managedid_parameter(prop) NULL
235 
236 #define icalproperty_get_size_parameter(prop) NULL
237 
238 #endif /* HAVE_MANAGED_ATTACH_PARAMS */
239 
240 
241 #ifdef HAVE_SCHEDULING_PARAMS
242 
243 /* Wrappers to fetch scheduling parameters by kind */
244 
245 #define icalproperty_get_scheduleagent_parameter(prop) \
246     icalproperty_get_first_parameter(prop, ICAL_SCHEDULEAGENT_PARAMETER)
247 
248 #define icalproperty_get_scheduleforcesend_parameter(prop) \
249     icalproperty_get_first_parameter(prop, ICAL_SCHEDULEFORCESEND_PARAMETER)
250 
251 #define icalproperty_get_schedulestatus_parameter(prop) \
252     icalproperty_get_first_parameter(prop, ICAL_SCHEDULESTATUS_PARAMETER)
253 
254 #else /* !HAVE_SCHEDULING_PARAMS */
255 
256 typedef enum {
257     ICAL_SCHEDULEAGENT_X,
258     ICAL_SCHEDULEAGENT_SERVER,
259     ICAL_SCHEDULEAGENT_CLIENT,
260     ICAL_SCHEDULEAGENT_NONE
261 } icalparameter_scheduleagent;
262 
263 typedef enum {
264     ICAL_SCHEDULEFORCESEND_X,
265     ICAL_SCHEDULEFORCESEND_REQUEST,
266     ICAL_SCHEDULEFORCESEND_REPLY,
267     ICAL_SCHEDULEFORCESEND_NONE
268 } icalparameter_scheduleforcesend;
269 
270 
271 #ifdef HAVE_IANA_PARAMS
272 
273 /* Functions to replace those not available in libical < v1.0 */
274 
275 extern icalparameter_scheduleagent
276 icalparameter_get_scheduleagent(icalparameter *param);
277 
278 extern icalparameter_scheduleforcesend
279 icalparameter_get_scheduleforcesend(icalparameter *param);
280 
281 extern icalparameter *icalparameter_new_schedulestatus(const char *stat);
282 
283 /* Wrappers to fetch scheduling parameters by kind */
284 
285 #define icalproperty_get_scheduleagent_parameter(prop) \
286     icalproperty_get_iana_parameter_by_name(prop, "SCHEDULE-AGENT")
287 
288 #define icalproperty_get_scheduleforcesend_parameter(prop) \
289     icalproperty_get_iana_parameter_by_name(prop, "SCHEDULE-FORCE-SEND")
290 
291 #define icalproperty_get_schedulestatus_parameter(prop) \
292     icalproperty_get_iana_parameter_by_name(prop, "SCHEDULE-STATUS")
293 
294 #else /* !HAVE_IANA_PARAMS */
295 
296 /* Dummy functions to allow compilation with libical < v0.48 */
297 
298 #define icalparameter_get_scheduleagent(param) ICAL_SCHEDULEAGENT_NONE
299 
300 #define icalparameter_get_scheduleforcesend(param) ICAL_SCHEDULEFORCESEND_NONE
301 
302 #define icalparameter_new_schedulestatus(stat) ((void) stat, NULL)
303 
304 #define icalproperty_get_scheduleagent_parameter(prop) NULL
305 
306 #define icalproperty_get_scheduleforcesend_parameter(prop) NULL
307 
308 #define icalproperty_get_schedulestatus_parameter(prop) NULL
309 
310 #endif /* HAVE_IANA_PARAMS */
311 
312 #endif /* HAVE_SCHEDULING_PARAMS */
313 
314 #endif /* HAVE_ICAL */
315 
316 #endif /* ICAL_SUPPORT_H */
317