+ * Utility function to fetch a VFREEBUSY type of thing for
+ * any specified user.
+ */
+icalcomponent *get_freebusy_for_user(char *who) {
+ char buf[SIZ];
+ char *serialized_fb = NULL;
+ icalcomponent *fb = NULL;
+
+ serv_printf("ICAL freebusy|%s", who);
+ serv_gets(buf);
+ if (buf[0] == '1') {
+ serialized_fb = read_server_text();
+ }
+
+ if (serialized_fb == NULL) {
+ return NULL;
+ }
+
+ fb = icalcomponent_new_from_string(serialized_fb);
+ free(serialized_fb);
+ if (fb == NULL) {
+ return NULL;
+ }
+
+ return fb;
+}
+
+
+
+/*
+ * Back end function for check_attendee_availability()
+ * This one checks an individual attendee against a supplied
+ * event start and end time. All these fields have already been
+ * broken out. The result is placed in 'annotation'.
+ */
+void check_individual_attendee(char *attendee_string,
+ struct icaltimetype event_start,
+ struct icaltimetype event_end,
+ char *annotation) {
+
+ icalcomponent *fbc = NULL;
+ icalcomponent *fb = NULL;
+ icalproperty *thisfb = NULL;
+
+ /* Set to 'unknown' right from the beginning. Unless we learn
+ * something else, that's what we'll go with.
+ */
+ strcpy(annotation, "availability unknown");
+
+ fbc = get_freebusy_for_user(attendee_string);
+ if (fbc == NULL) {
+ return;
+ }
+
+ /* Make sure we're looking at a VFREEBUSY by itself. What we're probably
+ * looking at initially is a VFREEBUSY encapsulated in a VCALENDAR.
+ */
+ if (icalcomponent_isa(fbc) == ICAL_VCALENDAR_COMPONENT) {
+ fb = icalcomponent_get_first_component(fbc, ICAL_VFREEBUSY_COMPONENT);
+ }
+ else if (icalcomponent_isa(fbc) == ICAL_VFREEBUSY_COMPONENT) {
+ fb = fbc;
+ }
+
+ /* Iterate through all FREEBUSY's looking for conflicts. */
+ if (fb != NULL) {
+
+ strcpy(annotation, "free");
+
+ for (thisfb = icalcomponent_get_first_property(fb, ICAL_FREEBUSY_PROPERTY);
+ thisfb != NULL;
+ thisfb = icalcomponent_get_next_property(fb, ICAL_FREEBUSY_PROPERTY) ) {
+
+ /* FIXME ... do the check */
+
+ }
+ }
+
+ icalcomponent_free(fbc);
+}
+
+
+
+/*
+ * Check the availability of all attendees for an event (when possible)
+ * and annotate accordingly.