4 * Check attendee availability for scheduling a meeting.
14 #include <sys/types.h>
16 #include <sys/socket.h>
18 #include <netinet/in.h>
28 #include "webserver.h"
31 #ifdef WEBCIT_WITH_CALENDAR_SERVICE
36 * Utility function to fetch a VFREEBUSY type of thing for
39 icalcomponent *get_freebusy_for_user(char *who) {
41 char *serialized_fb = NULL;
42 icalcomponent *fb = NULL;
44 serv_printf("ICAL freebusy|%s", who);
47 serialized_fb = read_server_text();
50 if (serialized_fb == NULL) {
54 fb = icalcomponent_new_from_string(serialized_fb);
66 * Back end function for check_attendee_availability()
67 * This one checks an individual attendee against a supplied
68 * event start and end time. All these fields have already been
69 * broken out. The result is placed in 'annotation'.
71 void check_individual_attendee(char *attendee_string,
72 struct icaltimetype event_start,
73 struct icaltimetype event_end,
76 icalcomponent *fbc = NULL;
77 icalcomponent *fb = NULL;
78 icalproperty *thisfb = NULL;
80 /* Set to 'unknown' right from the beginning. Unless we learn
81 * something else, that's what we'll go with.
83 strcpy(annotation, "availability unknown");
85 fbc = get_freebusy_for_user(attendee_string);
90 /* Make sure we're looking at a VFREEBUSY by itself. What we're probably
91 * looking at initially is a VFREEBUSY encapsulated in a VCALENDAR.
93 if (icalcomponent_isa(fbc) == ICAL_VCALENDAR_COMPONENT) {
94 fb = icalcomponent_get_first_component(fbc, ICAL_VFREEBUSY_COMPONENT);
96 else if (icalcomponent_isa(fbc) == ICAL_VFREEBUSY_COMPONENT) {
100 /* Iterate through all FREEBUSY's looking for conflicts. */
103 strcpy(annotation, "free");
105 for (thisfb = icalcomponent_get_first_property(fb, ICAL_FREEBUSY_PROPERTY);
107 thisfb = icalcomponent_get_next_property(fb, ICAL_FREEBUSY_PROPERTY) ) {
109 /* FIXME ... do the check */
114 icalcomponent_free(fbc);
120 * Check the availability of all attendees for an event (when possible)
121 * and annotate accordingly.
123 void check_attendee_availability(icalcomponent *vevent) {
124 icalproperty *attendee = NULL;
125 icalproperty *dtstart_p = NULL;
126 icalproperty *dtend_p = NULL;
127 struct icaltimetype dtstart_t;
128 struct icaltimetype dtend_t;
129 char attendee_string[SIZ];
130 char annotated_attendee_string[SIZ];
131 char annotation[SIZ];
133 if (vevent == NULL) {
137 /* If we're looking at a fully encapsulated VCALENDAR
138 * rather than a VEVENT component, attempt to use the first
139 * relevant VEVENT subcomponent. If there is none, the
140 * NULL returned by icalcomponent_get_first_component() will
141 * tell the next iteration of this function to create a
144 if (icalcomponent_isa(vevent) == ICAL_VCALENDAR_COMPONENT) {
145 check_attendee_availability(
146 icalcomponent_get_first_component(
147 vevent, ICAL_VEVENT_COMPONENT
154 * Learn the start and end times.
156 dtstart_p = icalcomponent_get_first_property(vevent, ICAL_DTSTART_PROPERTY);
157 if (dtstart_p != NULL) dtstart_t = icalproperty_get_dtstart(dtstart_p);
159 dtend_p = icalcomponent_get_first_property(vevent, ICAL_DTEND_PROPERTY);
160 if (dtend_p != NULL) dtend_t = icalproperty_get_dtend(dtend_p);
163 * Iterate through attendees.
165 for (attendee = icalcomponent_get_first_property(vevent, ICAL_ATTENDEE_PROPERTY);
167 attendee = icalcomponent_get_next_property(vevent, ICAL_ATTENDEE_PROPERTY)) {
169 strcpy(attendee_string, icalproperty_get_attendee(attendee));
170 if (!strncasecmp(attendee_string, "MAILTO:", 7)) {
172 /* screen name or email address */
173 strcpy(attendee_string, &attendee_string[7]);
174 striplt(attendee_string);
176 check_individual_attendee(attendee_string,
180 /* Replace the attendee name with an annotated one. */
181 snprintf(annotated_attendee_string, sizeof annotated_attendee_string,
182 "MAILTO:%s (%s)", attendee_string, annotation);
183 icalproperty_set_attendee(attendee, annotated_attendee_string);
191 #endif /* WEBCIT_WITH_CALENDAR_SERVICE */