11 * \brief verify users avaiability
12 * Utility function to fetch a VFREEBUSY type of thing for
14 * \param who string of the user to search
16 icalcomponent *get_freebusy_for_user(char *who) {
18 char *serialized_fb = NULL;
19 icalcomponent *fb = NULL;
21 serv_printf("ICAL freebusy|%s", who);
22 serv_getln(buf, sizeof buf);
24 serialized_fb = read_server_text();
27 if (serialized_fb == NULL) {
31 fb = icalcomponent_new_from_string(serialized_fb);
42 * \brief Check if dates are overlapping
43 * Check to see if two events overlap.
44 * (This function is used in both Citadel and WebCit. If you change it in
45 * one place, change it in the other. Better yet, put it in a library.)
46 * \param t1start date one start
47 * \param t1end date one end
48 * \param t2start date one start
49 * \param t2end date two end
50 * \returns nonzero if they do.
52 int ical_ctdl_is_overlap(
53 struct icaltimetype t1start,
54 struct icaltimetype t1end,
55 struct icaltimetype t2start,
56 struct icaltimetype t2end
59 if (icaltime_is_null_time(t1start)) return(0);
60 if (icaltime_is_null_time(t2start)) return(0);
62 /** First, check for all-day events */
63 if (t1start.is_date) {
64 if (!icaltime_compare_date_only(t1start, t2start)) {
67 if (!icaltime_is_null_time(t2end)) {
68 if (!icaltime_compare_date_only(t1start, t2end)) {
74 if (t2start.is_date) {
75 if (!icaltime_compare_date_only(t2start, t1start)) {
78 if (!icaltime_is_null_time(t1end)) {
79 if (!icaltime_compare_date_only(t2start, t1end)) {
85 /* lprintf (9, "Comparing t1start %d:%d t1end %d:%d t2start %d:%d t2end %d:%d \n",
86 t1start.hour, t1start.minute, t1end.hour, t1end.minute,
87 t2start.hour, t2start.minute, t2end.hour, t2end.minute);
90 /** Now check for overlaps using date *and* time. */
92 /** First, bail out if either event 1 or event 2 is missing end time. */
93 if (icaltime_is_null_time(t1end)) return(0);
94 if (icaltime_is_null_time(t2end)) return(0);
96 /** If event 1 ends before event 2 starts, we're in the clear. */
97 if (icaltime_compare(t1end, t2start) <= 0) return(0);
98 // lprintf(9, "first passed\n");
100 /** If event 2 ends before event 1 starts, we're also ok. */
101 if (icaltime_compare(t2end, t1start) <= 0) return(0);
102 // lprintf(9, "second passed\n");
104 /** Otherwise, they overlap. */
111 * \brief dig availability on citserver
112 * Back end function for check_attendee_availability()
113 * This one checks an individual attendee against a supplied
114 * event start and end time. All these fields have already been
116 * \param attendee_string name of the attendee
117 * \param event_start starttime of the event to check
118 * \param event_end endtime of the event to check
119 * \return The result is placed in 'annotation'.
121 void check_individual_attendee(char *attendee_string,
122 struct icaltimetype event_start,
123 struct icaltimetype event_end,
126 icalcomponent *fbc = NULL;
127 icalcomponent *fb = NULL;
128 icalproperty *thisfb = NULL;
129 struct icalperiodtype period;
132 * Set to 'unknown' right from the beginning. Unless we learn
133 * something else, that's what we'll go with.
135 strcpy(annotation, _("availability unknown"));
137 fbc = get_freebusy_for_user(attendee_string);
143 * Make sure we're looking at a VFREEBUSY by itself. What we're probably
144 * looking at initially is a VFREEBUSY encapsulated in a VCALENDAR.
146 if (icalcomponent_isa(fbc) == ICAL_VCALENDAR_COMPONENT) {
147 fb = icalcomponent_get_first_component(fbc, ICAL_VFREEBUSY_COMPONENT);
149 else if (icalcomponent_isa(fbc) == ICAL_VFREEBUSY_COMPONENT) {
153 /** Iterate through all FREEBUSY's looking for conflicts. */
156 strcpy(annotation, _("free"));
158 for (thisfb = icalcomponent_get_first_property(fb, ICAL_FREEBUSY_PROPERTY);
160 thisfb = icalcomponent_get_next_property(fb, ICAL_FREEBUSY_PROPERTY) ) {
163 period = icalproperty_get_freebusy(thisfb);
164 if (ical_ctdl_is_overlap(period.start, period.end,
165 event_start, event_end)) {
166 strcpy(annotation, _("BUSY"));
172 icalcomponent_free(fbc);
179 * \brief check attendees availability
180 * Check the availability of all attendees for an event (when possible)
181 * and annotate accordingly.
182 * \param vevent the event which should be compared with attendees calendar
184 void check_attendee_availability(icalcomponent *vevent) {
185 icalproperty *attendee = NULL;
186 icalproperty *dtstart_p = NULL;
187 icalproperty *dtend_p = NULL;
188 struct icaltimetype dtstart_t;
189 struct icaltimetype dtend_t;
190 char attendee_string[SIZ];
191 char annotated_attendee_string[SIZ];
192 char annotation[SIZ];
194 if (vevent == NULL) {
199 * If we're looking at a fully encapsulated VCALENDAR
200 * rather than a VEVENT component, attempt to use the first
201 * relevant VEVENT subcomponent. If there is none, the
202 * NULL returned by icalcomponent_get_first_component() will
203 * tell the next iteration of this function to create a
206 if (icalcomponent_isa(vevent) == ICAL_VCALENDAR_COMPONENT) {
207 check_attendee_availability(
208 icalcomponent_get_first_component(
209 vevent, ICAL_VEVENT_COMPONENT
215 ical_dezonify(vevent); /**< Convert everything to UTC */
218 * Learn the start and end times.
220 dtstart_p = icalcomponent_get_first_property(vevent, ICAL_DTSTART_PROPERTY);
221 if (dtstart_p != NULL) dtstart_t = icalproperty_get_dtstart(dtstart_p);
223 dtend_p = icalcomponent_get_first_property(vevent, ICAL_DTEND_PROPERTY);
224 if (dtend_p != NULL) dtend_t = icalproperty_get_dtend(dtend_p);
227 * Iterate through attendees.
229 for (attendee = icalcomponent_get_first_property(vevent, ICAL_ATTENDEE_PROPERTY);
231 attendee = icalcomponent_get_next_property(vevent, ICAL_ATTENDEE_PROPERTY)) {
233 strcpy(attendee_string, icalproperty_get_attendee(attendee));
234 if (!strncasecmp(attendee_string, "MAILTO:", 7)) {
236 /** screen name or email address */
237 strcpy(attendee_string, &attendee_string[7]);
238 striplt(attendee_string);
240 check_individual_attendee(attendee_string,
244 /** Replace the attendee name with an annotated one. */
245 snprintf(annotated_attendee_string, sizeof annotated_attendee_string,
246 "MAILTO:%s (%s)", attendee_string, annotation);
247 icalproperty_set_attendee(attendee, annotated_attendee_string);