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 #undef icalerror_warn
53 #define icalerror_warn(message) \
54 {syslog(LOG_WARNING, "icalerror: %s(), %s:%d: %s\n", __FUNCTION__, __FILE__, __LINE__, message);}
55 
56 #include "mailbox.h"
57 
58 #define PER_USER_CAL_DATA \
59     DAV_ANNOT_NS "<" XML_NS_CYRUS ">per-user-calendar-data"
60 
61 #ifndef HAVE_NEW_CLONE_API
62 /* Allow us to compile without #ifdef HAVE_NEW_CLONE_API everywhere */
63 #define icalcomponent_clone           icalcomponent_new_clone
64 #define icalproperty_clone            icalproperty_new_clone
65 #define icalparameter_clone           icalparameter_new_clone
66 #endif
67 
68 /* Initialize libical timezones. */
69 extern void ical_support_init(void);
70 
71 extern int cyrus_icalrestriction_check(icalcomponent *ical);
72 
73 extern const char *icalparameter_get_value_as_string(icalparameter *param);
74 extern struct icaldatetimeperiodtype
75 icalproperty_get_datetimeperiod(icalproperty *prop);
76 extern time_t icaltime_to_timet(icaltimetype t, const icaltimezone *floatingtz);
77 
78 /* If range is a NULL period, callback() is executed for ALL occurrences,
79    otherwise callback() is only executed for occurrences that overlap the range.
80    callback() returns true (1) while it wants more occurrences, 0 to finish.
81    If comp is a VCALENDAR then in addition to the main component, any embedded
82    component with RECURRENCE-ID is included in the occurrences.
83    If comp is a VEVENT or similar, only RRULE and RDATEs are considered. */
84 extern int icalcomponent_myforeach(icalcomponent *comp,
85                                    struct icalperiodtype range,
86                                    const icaltimezone *floatingtz,
87                                    int (*callback) (icalcomponent *comp,
88                                                     icaltimetype start,
89                                                     icaltimetype end,
90                                                     void *data),
91                                    void *callback_data);
92 
93 
94 extern icalcomponent *icalcomponent_new_stream(struct mailbox *mailbox,
95                                                const char *prodid,
96                                                const char *name,
97                                                const char *desc,
98                                                const char *color);
99 
100 extern icalcomponent *ical_string_as_icalcomponent(const struct buf *buf);
101 extern struct buf *my_icalcomponent_as_ical_string(icalcomponent* comp);
102 
103 extern icalcomponent *record_to_ical(struct mailbox *mailbox,
104                                      const struct index_record *record,
105                                      strarray_t *schedule_addresses);
106 
107 extern const char *get_icalcomponent_errstr(icalcomponent *ical);
108 
109 extern void icalcomponent_remove_invitee(icalcomponent *comp,
110                                          icalproperty *prop);
111 extern icalproperty *icalcomponent_get_first_invitee(icalcomponent *comp);
112 extern icalproperty *icalcomponent_get_next_invitee(icalcomponent *comp);
113 extern const char *icalproperty_get_invitee(icalproperty *prop);
114 
115 extern icaltimetype icalcomponent_get_recurrenceid_with_zone(icalcomponent *c);
116 
117 extern icalproperty *icalcomponent_get_x_property_by_name(icalcomponent *comp,
118                                                           const char *name);
119 
120 extern struct icalperiodtype icalcomponent_get_utc_timespan(icalcomponent *comp,
121                                                             icalcomponent_kind kind,
122                                                             icaltimezone *floating_tz);
123 
124 extern struct icalperiodtype icalrecurrenceset_get_utc_timespan(icalcomponent *ical,
125                                                                 icalcomponent_kind kind,
126                                                                 icaltimezone *floating_tz,
127                                                                 unsigned *is_recurring,
128                                                                 void (*comp_cb)(icalcomponent*,
129                                                                                 void*),
130                                                                 void *cb_rock);
131 
132 extern void icaltime_set_utc(struct icaltimetype *t, int set);
133 extern icaltimetype icaltime_convert_to_utc(const struct icaltimetype tt,
134                                             icaltimezone *floating_zone);
135 
136 extern int icalcomponent_apply_vpatch(icalcomponent *ical,
137                                       icalcomponent *vpatch,
138                                       int *num_changes, const char **errstr);
139 
140 /* Functions that should be declared in libical */
141 #define icaltimezone_set_zone_directory set_zone_directory
142 
143 #define icalcomponent_get_tzuntil_property(comp) \
144     icalcomponent_get_first_property(comp, ICAL_TZUNTIL_PROPERTY)
145 
146 #define icalcomponent_get_acknowledged_property(comp) \
147     icalcomponent_get_first_property(comp, ICAL_ACKNOWLEDGED_PROPERTY)
148 
149 #ifndef HAVE_RFC7986_COLOR
150 
151 /* Replacement for missing function in 3.0.0 <= libical < 3.0.5 */
152 
153 extern icalproperty *icalproperty_new_color(const char *v);
154 
155 #endif /* HAVE_RFC7986_COLOR */
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 /* Wrappers to fetch managed attachment parameters by kind */
168 
169 #define icalproperty_get_filename_parameter(prop) \
170     icalproperty_get_first_parameter(prop, ICAL_FILENAME_PARAMETER)
171 
172 #define icalproperty_get_managedid_parameter(prop) \
173     icalproperty_get_first_parameter(prop, ICAL_MANAGEDID_PARAMETER)
174 
175 #define icalproperty_get_size_parameter(prop) \
176     icalproperty_get_first_parameter(prop, ICAL_SIZE_PARAMETER)
177 
178 /* Wrappers to fetch scheduling parameters by kind */
179 
180 #define icalproperty_get_scheduleagent_parameter(prop) \
181     icalproperty_get_first_parameter(prop, ICAL_SCHEDULEAGENT_PARAMETER)
182 
183 #define icalproperty_get_scheduleforcesend_parameter(prop) \
184     icalproperty_get_first_parameter(prop, ICAL_SCHEDULEFORCESEND_PARAMETER)
185 
186 #define icalproperty_get_schedulestatus_parameter(prop) \
187     icalproperty_get_first_parameter(prop, ICAL_SCHEDULESTATUS_PARAMETER)
188 
189 #endif /* HAVE_ICAL */
190 
191 #endif /* ICAL_SUPPORT_H */
192