00001
00002
00003
00010
00011
00012 #include "webcit.h"
00013 #include "webserver.h"
00014
00016 #ifdef WEBCIT_WITH_CALENDAR_SERVICE
00017
00018
00019
00026 icalcomponent *get_freebusy_for_user(char *who) {
00027 char buf[SIZ];
00028 char *serialized_fb = NULL;
00029 icalcomponent *fb = NULL;
00030
00031 serv_printf("ICAL freebusy|%s", who);
00032 serv_getln(buf, sizeof buf);
00033 if (buf[0] == '1') {
00034 serialized_fb = read_server_text();
00035 }
00036
00037 if (serialized_fb == NULL) {
00038 return NULL;
00039 }
00040
00041 fb = icalcomponent_new_from_string(serialized_fb);
00042 free(serialized_fb);
00043 if (fb == NULL) {
00044 return NULL;
00045 }
00046
00047 return(fb);
00048 }
00049
00050
00051
00052
00064 int ical_ctdl_is_overlap(
00065 struct icaltimetype t1start,
00066 struct icaltimetype t1end,
00067 struct icaltimetype t2start,
00068 struct icaltimetype t2end
00069 ) {
00070
00071 if (icaltime_is_null_time(t1start)) return(0);
00072 if (icaltime_is_null_time(t2start)) return(0);
00073
00075 if (t1start.is_date) {
00076 if (!icaltime_compare_date_only(t1start, t2start)) {
00077 return(1);
00078 }
00079 if (!icaltime_is_null_time(t2end)) {
00080 if (!icaltime_compare_date_only(t1start, t2end)) {
00081 return(1);
00082 }
00083 }
00084 }
00085
00086 if (t2start.is_date) {
00087 if (!icaltime_compare_date_only(t2start, t1start)) {
00088 return(1);
00089 }
00090 if (!icaltime_is_null_time(t1end)) {
00091 if (!icaltime_compare_date_only(t2start, t1end)) {
00092 return(1);
00093 }
00094 }
00095 }
00096
00100 if (icaltime_is_null_time(t1end)) return(0);
00101 if (icaltime_is_null_time(t2end)) return(0);
00102
00104 if (icaltime_compare(t1end, t2start) <= 0) return(0);
00105
00107 if (icaltime_compare(t2end, t1start) <= 0) return(0);
00108
00110 return(1);
00111 }
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126 void check_individual_attendee(char *attendee_string,
00127 struct icaltimetype event_start,
00128 struct icaltimetype event_end,
00129 char *annotation) {
00130
00131 icalcomponent *fbc = NULL;
00132 icalcomponent *fb = NULL;
00133 icalproperty *thisfb = NULL;
00134 struct icalperiodtype period;
00135
00140 strcpy(annotation, _("availability unknown"));
00141
00142 fbc = get_freebusy_for_user(attendee_string);
00143 if (fbc == NULL) {
00144 return;
00145 }
00146
00151 if (icalcomponent_isa(fbc) == ICAL_VCALENDAR_COMPONENT) {
00152 fb = icalcomponent_get_first_component(fbc, ICAL_VFREEBUSY_COMPONENT);
00153 }
00154 else if (icalcomponent_isa(fbc) == ICAL_VFREEBUSY_COMPONENT) {
00155 fb = fbc;
00156 }
00157
00159 if (fb != NULL) {
00160
00161 strcpy(annotation, _("free"));
00162
00163 for (thisfb = icalcomponent_get_first_property(fb, ICAL_FREEBUSY_PROPERTY);
00164 thisfb != NULL;
00165 thisfb = icalcomponent_get_next_property(fb, ICAL_FREEBUSY_PROPERTY) ) {
00166
00168 period = icalproperty_get_freebusy(thisfb);
00169 if (ical_ctdl_is_overlap(period.start, period.end,
00170 event_start, event_end)) {
00171 strcpy(annotation, _("BUSY"));
00172 }
00173
00174 }
00175 }
00176
00177 icalcomponent_free(fbc);
00178 }
00179
00180
00181
00182
00189 void check_attendee_availability(icalcomponent *vevent) {
00190 icalproperty *attendee = NULL;
00191 icalproperty *dtstart_p = NULL;
00192 icalproperty *dtend_p = NULL;
00193 struct icaltimetype dtstart_t;
00194 struct icaltimetype dtend_t;
00195 char attendee_string[SIZ];
00196 char annotated_attendee_string[SIZ];
00197 char annotation[SIZ];
00198
00199 if (vevent == NULL) {
00200 return;
00201 }
00202
00211 if (icalcomponent_isa(vevent) == ICAL_VCALENDAR_COMPONENT) {
00212 check_attendee_availability(
00213 icalcomponent_get_first_component(
00214 vevent, ICAL_VEVENT_COMPONENT
00215 )
00216 );
00217 return;
00218 }
00219
00220 ical_dezonify(vevent);
00225 dtstart_p = icalcomponent_get_first_property(vevent, ICAL_DTSTART_PROPERTY);
00226 if (dtstart_p != NULL) dtstart_t = icalproperty_get_dtstart(dtstart_p);
00227
00228 dtend_p = icalcomponent_get_first_property(vevent, ICAL_DTEND_PROPERTY);
00229 if (dtend_p != NULL) dtend_t = icalproperty_get_dtend(dtend_p);
00230
00234 for (attendee = icalcomponent_get_first_property(vevent, ICAL_ATTENDEE_PROPERTY);
00235 attendee != NULL;
00236 attendee = icalcomponent_get_next_property(vevent, ICAL_ATTENDEE_PROPERTY)) {
00237
00238 strcpy(attendee_string, icalproperty_get_attendee(attendee));
00239 if (!strncasecmp(attendee_string, "MAILTO:", 7)) {
00240
00242 strcpy(attendee_string, &attendee_string[7]);
00243 striplt(attendee_string);
00244
00245 check_individual_attendee(attendee_string,
00246 dtstart_t, dtend_t,
00247 annotation);
00248
00250 snprintf(annotated_attendee_string, sizeof annotated_attendee_string,
00251 "MAILTO:%s (%s)", attendee_string, annotation);
00252 icalproperty_set_attendee(attendee, annotated_attendee_string);
00253
00254 }
00255 }
00256
00257 }
00258
00259
00260 #endif
00261