4 * Functions which handle calendar objects and their processing/display.
14 #include <sys/types.h>
16 #include <sys/socket.h>
18 #include <netinet/in.h>
28 #include "webserver.h"
33 * Handler stubs for builds with no calendar library available
35 void cal_process_attachment(char *part_source, long msgnum, char *cal_partnum) {
37 wprintf("<I>This message contains calendaring/scheduling information,"
38 " but support for calendars is not available on this "
39 "particular system. Please ask your system administrator to "
40 "install a new version of the Citadel web service with "
41 "calendaring enabled.</I><BR>\n"
46 void display_calendar(long msgnum) {
48 "Cannot display calendar item. You are seeing this error "
49 "because your WebCit service has not been installed with "
50 "calendar support. Please contact your system administrator."
54 void display_task(long msgnum) {
56 "Cannot display to-do item. You are seeing this error "
57 "because your WebCit service has not been installed with "
58 "calendar support. Please contact your system administrator."
62 #else /* HAVE_ICAL_H */
65 /****** End of handler stubs. Everything below this line is real. ******/
71 * Process a calendar object
72 * ...at this point it's already been deserialized by cal_process_attachment()
74 void cal_process_object(icalcomponent *cal,
80 icalproperty *method = NULL;
81 icalproperty_method the_method = ICAL_METHOD_NONE;
83 struct icaltimetype t;
86 char conflict_name[SIZ];
89 /* Leading HTML for the display of this object */
90 if (recursion_level == 0) {
91 wprintf("<CENTER><TABLE border=0>\n");
94 /* Look for a method */
95 method = icalcomponent_get_first_property(cal, ICAL_METHOD_PROPERTY);
97 /* See what we need to do with this */
99 the_method = icalproperty_get_method(method);
101 case ICAL_METHOD_REQUEST:
102 wprintf("<TR><TD COLSPAN=2>\n"
104 "SRC=\"/static/vcalendar.gif\">"
106 "<B>Meeting invitation</B>
110 case ICAL_METHOD_PUBLISH:
111 wprintf("<TR><TD COLSPAN=2>\n"
113 "SRC=\"/static/vcalendar.gif\">"
115 "<B>Published event</B>
120 wprintf("<TR><TD COLSPAN=2>"
121 "I don't know what to do with this.</TD></TR>"
127 p = icalcomponent_get_first_property(cal, ICAL_SUMMARY_PROPERTY);
129 wprintf("<TR><TD><B>Summary:</B></TD><TD>");
130 escputs((char *)icalproperty_get_comment(p));
131 wprintf("</TD></TR>\n");
134 p = icalcomponent_get_first_property(cal, ICAL_LOCATION_PROPERTY);
136 wprintf("<TR><TD><B>Location:</B></TD><TD>");
137 escputs((char *)icalproperty_get_comment(p));
138 wprintf("</TD></TR>\n");
142 * Only show start/end times if we're actually looking at the VEVENT
143 * component. Otherwise it shows bogus dates for things like timezone.
145 if (icalcomponent_isa(cal) == ICAL_VEVENT_COMPONENT) {
147 p = icalcomponent_get_first_property(cal,
148 ICAL_DTSTART_PROPERTY);
150 t = icalproperty_get_dtstart(p);
151 tt = icaltime_as_timet(t);
153 wprintf("<TR><TD><B>Starting date/time:</B></TD><TD>"
158 p = icalcomponent_get_first_property(cal, ICAL_DTEND_PROPERTY);
160 t = icalproperty_get_dtend(p);
161 tt = icaltime_as_timet(t);
163 wprintf("<TR><TD><B>Ending date/time:</B></TD><TD>"
170 p = icalcomponent_get_first_property(cal, ICAL_DESCRIPTION_PROPERTY);
172 wprintf("<TR><TD><B>Description:</B></TD><TD>");
173 escputs((char *)icalproperty_get_comment(p));
174 wprintf("</TD></TR>\n");
177 /* If the component has subcomponents, recurse through them. */
178 for (c = icalcomponent_get_first_component(cal, ICAL_ANY_COMPONENT);
180 c = icalcomponent_get_next_component(cal, ICAL_ANY_COMPONENT)) {
181 /* Recursively process subcomponent */
182 cal_process_object(c, recursion_level+1, msgnum, cal_partnum);
185 /* If this is a REQUEST, display conflicts and buttons */
186 if (the_method == ICAL_METHOD_REQUEST) {
188 /* Check for conflicts */
189 serv_printf("ICAL conflicts|%ld|%s|", msgnum, cal_partnum);
192 while (serv_gets(buf), strcmp(buf, "000")) {
193 extract(conflict_name, buf, 3);
194 is_update = extract_int(buf, 4);
195 wprintf("<TR><TD><B><I>%s</I></B></TD>"
206 "This is an update of" :
207 "This event would conflict with"
211 escputs(conflict_name);
212 wprintf(""</I> "
213 "which is already in your calendar."
218 /* Display the Accept/Decline buttons */
219 wprintf("<TR><TD COLSPAN=2>"
220 "<FORM METHOD=\"GET\" "
221 "ACTION=\"/respond_to_request\">\n"
222 "<INPUT TYPE=\"submit\" NAME=\"sc\" "
223 "VALUE=\"Accept\">\n"
225 "<INPUT TYPE=\"submit\" NAME=\"sc\" "
226 "VALUE=\"Tentative\">\n"
228 "<INPUT TYPE=\"submit\" NAME=\"sc\" "
229 "VALUE=\"Decline\">\n"
230 "<INPUT TYPE=\"hidden\" NAME=\"msgnum\" "
232 "<INPUT TYPE=\"hidden\" NAME=\"cal_partnum\" "
241 /* Trailing HTML for the display of this object */
242 if (recursion_level == 0) {
244 wprintf("</TR></TABLE></CENTER>\n");
250 * Deserialize a calendar object in a message so it can be processed.
251 * (This is the main entry point for these things)
253 void cal_process_attachment(char *part_source, long msgnum, char *cal_partnum) {
256 cal = icalcomponent_new_from_string(part_source);
259 wprintf("Error parsing calendar object: %s<BR>\n",
260 icalerror_strerror(icalerrno));
264 cal_process_object(cal, 0, msgnum, cal_partnum);
266 /* Free the memory we obtained from libical's constructor */
267 icalcomponent_free(cal);
274 * Respond to a meeting request
276 void respond_to_request(void) {
281 wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=007700><TR><TD>"
282 "<FONT SIZE=+1 COLOR=\"FFFFFF\""
283 "<B>Respond to meeting request</B>"
284 "</FONT></TD></TR></TABLE><BR>\n"
287 serv_printf("ICAL respond|%s|%s|%s|",
295 wprintf("<TABLE BORDER=0><TR><TD>"
296 "<IMG SRC=\"static/vcalendar.gif\" ALIGN=CENTER>"
299 if (!strcasecmp(bstr("sc"), "accept")) {
300 wprintf("You have accepted this meeting invitation. "
301 "It has been entered into your calendar, "
303 } else if (!strcasecmp(bstr("sc"), "tentative")) {
304 wprintf("You have tentatively accepted this meeting invitation. "
305 "It has been 'pencilled in' to your calendar, "
307 } else if (!strcasecmp(bstr("sc"), "decline")) {
308 wprintf("You have declined this meeting invitation. "
309 "It has <b>not</b> been entered into your calendar, "
312 wprintf("and a reply has been sent to the meeting organizer."
313 "</TD></TR></TABLE>\n"
316 wprintf("<IMG SRC=\"static/error.gif\" ALIGN=CENTER>"
320 wprintf("<A HREF=\"/dotskip?room=");
321 urlescputs(WC->wc_roomname);
322 wprintf("\">Return to messages</A><BR>\n");
330 /*****************************************************************************/
335 * Display handlers for message reading
341 * If we're reading calendar items, just store them for now. We have to
342 * sort and re-output them later when we draw the calendar.
344 void display_individual_cal(icalcomponent *cal, long msgnum) {
348 WC->disp_cal = realloc(WC->disp_cal,
349 (sizeof(icalcomponent *) * WC->num_cal) );
350 WC->disp_cal[WC->num_cal - 1] = icalcomponent_new_clone(cal);
352 WC->cal_msgnum = realloc(WC->cal_msgnum,
353 (sizeof(long) * WC->num_cal) );
354 WC->cal_msgnum[WC->num_cal - 1] = msgnum;
360 * Display a task in the task list
362 void display_individual_task(icalcomponent *vtodo, long msgnum) {
365 p = icalcomponent_get_first_property(vtodo, ICAL_SUMMARY_PROPERTY);
366 wprintf("<LI><A HREF=\"/display_edit_task?msgnum=%ld\">", msgnum);
368 escputs((char *)icalproperty_get_comment(p));
375 * Display a task by itself (for editing)
377 void display_edit_individual_task(icalcomponent *supplied_vtodo, long msgnum) {
378 icalcomponent *vtodo;
380 struct icaltimetype t;
382 int created_new_vtodo = 0;
386 if (supplied_vtodo != NULL) {
387 vtodo = supplied_vtodo;
390 vtodo = icalcomponent_new(ICAL_VTODO_COMPONENT);
391 created_new_vtodo = 1;
395 wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=007700><TR><TD>"
396 "<FONT SIZE=+1 COLOR=\"FFFFFF\""
398 "</FONT></TD></TR></TABLE><BR>\n"
401 wprintf("<FORM METHOD=\"POST\" ACTION=\"/save_task\">\n");
402 wprintf("<INPUT TYPE=\"hidden\" NAME=\"msgnum\" VALUE=\"%ld\">\n",
406 "<INPUT TYPE=\"text\" NAME=\"summary\" "
407 "MAXLENGTH=\"64\" SIZE=\"64\" VALUE=\"");
408 p = icalcomponent_get_first_property(vtodo, ICAL_SUMMARY_PROPERTY);
410 escputs((char *)icalproperty_get_comment(p));
412 wprintf("\"><BR>\n");
414 wprintf("Start date: ");
415 p = icalcomponent_get_first_property(vtodo, ICAL_DTSTART_PROPERTY);
417 t = icalproperty_get_dtstart(p);
420 t = icaltime_from_timet(now, 0);
422 display_icaltimetype_as_webform(&t, "dtstart");
425 wprintf("Due date: ");
426 p = icalcomponent_get_first_property(vtodo, ICAL_DUE_PROPERTY);
428 t = icalproperty_get_due(p);
431 t = icaltime_from_timet(now, 0);
433 display_icaltimetype_as_webform(&t, "due");
436 wprintf("<CENTER><TEXTAREA NAME=\"description\" wrap=soft "
437 "ROWS=10 COLS=80 WIDTH=80>\n"
439 p = icalcomponent_get_first_property(vtodo, ICAL_DESCRIPTION_PROPERTY);
441 escputs((char *)icalproperty_get_comment(p));
443 wprintf("</TEXTAREA><BR>\n");
445 wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Save\">"
447 "<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Delete\">\n"
449 "<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">\n"
453 wprintf("</FORM>\n");
457 if (created_new_vtodo) {
458 icalcomponent_free(vtodo);
463 * Save an edited task
465 void save_individual_task(icalcomponent *supplied_vtodo, long msgnum) {
467 int delete_existing = 0;
469 icalcomponent *vtodo;
470 int created_new_vtodo = 0;
472 if (supplied_vtodo != NULL) {
473 vtodo = supplied_vtodo;
476 vtodo = icalcomponent_new(ICAL_VTODO_COMPONENT);
477 created_new_vtodo = 1;
480 if (!strcasecmp(bstr("sc"), "Save")) {
482 /* Replace values in the component with ones from the form */
484 while (prop = icalcomponent_get_first_property(vtodo,
485 ICAL_SUMMARY_PROPERTY), prop != NULL) {
486 icalcomponent_remove_property(vtodo, prop);
488 icalcomponent_add_property(vtodo,
489 icalproperty_new_summary(bstr("summary")));
491 while (prop = icalcomponent_get_first_property(vtodo,
492 ICAL_DESCRIPTION_PROPERTY), prop != NULL) {
493 icalcomponent_remove_property(vtodo, prop);
495 icalcomponent_add_property(vtodo,
496 icalproperty_new_description(bstr("description")));
498 while (prop = icalcomponent_get_first_property(vtodo,
499 ICAL_DTSTART_PROPERTY), prop != NULL) {
500 icalcomponent_remove_property(vtodo, prop);
502 icalcomponent_add_property(vtodo,
503 icalproperty_new_dtstart(
504 icaltime_from_webform("dtstart")
508 while (prop = icalcomponent_get_first_property(vtodo,
509 ICAL_DUE_PROPERTY), prop != NULL) {
510 icalcomponent_remove_property(vtodo, prop);
512 icalcomponent_add_property(vtodo,
513 icalproperty_new_due(
514 icaltime_from_webform("due")
518 /* Serialize it and save it to the message base */
519 serv_puts("ENT0 1|||4");
522 serv_puts("Content-type: text/calendar");
524 serv_puts(icalcomponent_as_ical_string(vtodo));
527 /* Probably not necessary; the server will see the UID
528 * of the object and delete the old one anyway, but
536 * If the user clicked 'Delete' then explicitly delete the message.
538 if (!strcasecmp(bstr("sc"), "Delete")) {
542 if ( (delete_existing) && (msgnum > 0L) ) {
543 serv_printf("DELE %ld", atol(bstr("msgnum")));
547 if (created_new_vtodo) {
548 icalcomponent_free(vtodo);
551 /* Go back to the task list */
558 * Code common to all display handlers. Given a message number and a MIME
559 * type, we load the message and hunt for that MIME type. If found, we load
560 * the relevant part, deserialize it into a libical component, filter it for
561 * the requested object type, and feed it to the specified handler.
563 void display_using_handler(long msgnum,
565 icalcomponent_kind which_kind,
566 void (*callback)(icalcomponent *, long)
569 char mime_partnum[SIZ];
570 char mime_filename[SIZ];
571 char mime_content_type[SIZ];
572 char mime_disposition[SIZ];
574 char relevant_partnum[SIZ];
575 char *relevant_source = NULL;
576 icalcomponent *cal, *c;
578 sprintf(buf, "MSG0 %ld|1", msgnum); /* ask for headers only */
581 if (buf[0] != '1') return;
583 while (serv_gets(buf), strcmp(buf, "000")) {
584 if (!strncasecmp(buf, "part=", 5)) {
585 extract(mime_filename, &buf[5], 1);
586 extract(mime_partnum, &buf[5], 2);
587 extract(mime_disposition, &buf[5], 3);
588 extract(mime_content_type, &buf[5], 4);
589 mime_length = extract_int(&buf[5], 5);
591 if (!strcasecmp(mime_content_type, "text/calendar")) {
592 strcpy(relevant_partnum, mime_partnum);
598 if (strlen(relevant_partnum) > 0) {
599 relevant_source = load_mimepart(msgnum, relevant_partnum);
600 if (relevant_source != NULL) {
602 cal = icalcomponent_new_from_string(relevant_source);
605 /* Simple components of desired type */
606 if (icalcomponent_isa(cal) == which_kind) {
607 callback(cal, msgnum);
610 /* Subcomponents of desired type */
611 for (c = icalcomponent_get_first_component(cal,
614 c = icalcomponent_get_next_component(cal,
618 icalcomponent_free(cal);
620 free(relevant_source);
626 void display_calendar(long msgnum) {
627 display_using_handler(msgnum, "text/calendar",
628 ICAL_VEVENT_COMPONENT,
629 display_individual_cal);
632 void display_task(long msgnum) {
633 display_using_handler(msgnum, "text/calendar",
634 ICAL_VTODO_COMPONENT,
635 display_individual_task);
638 void display_edit_task(void) {
641 msgnum = atol(bstr("msgnum"));
644 display_using_handler(msgnum, "text/calendar",
645 ICAL_VTODO_COMPONENT,
646 display_edit_individual_task);
650 display_edit_individual_task(NULL, 0L);
654 void save_task(void) {
657 msgnum = atol(bstr("msgnum"));
659 display_using_handler(msgnum, "text/calendar",
660 ICAL_VTODO_COMPONENT,
661 save_individual_task);
664 save_individual_task(NULL, 0L);
668 void display_edit_event(void) {
671 msgnum = atol(bstr("msgnum"));
674 display_using_handler(msgnum, "text/calendar",
675 ICAL_VEVENT_COMPONENT,
676 display_edit_individual_event);
680 display_edit_individual_event(NULL, 0L);
684 void save_event(void) {
687 msgnum = atol(bstr("msgnum"));
690 display_using_handler(msgnum, "text/calendar",
691 ICAL_VEVENT_COMPONENT,
692 save_individual_event);
695 save_individual_event(NULL, 0L);
699 #endif /* HAVE_ICAL_H */