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);
153 wprintf("<TR><TD><B>Date:"
155 "%s %d, %d</TD></TR>",
161 tt = icaltime_as_timet(t);
163 wprintf("<TR><TD><B>Starting date/time:"
170 p = icalcomponent_get_first_property(cal, ICAL_DTEND_PROPERTY);
172 t = icalproperty_get_dtend(p);
173 tt = icaltime_as_timet(t);
175 wprintf("<TR><TD><B>Ending date/time:</B></TD><TD>"
182 p = icalcomponent_get_first_property(cal, ICAL_DESCRIPTION_PROPERTY);
184 wprintf("<TR><TD><B>Description:</B></TD><TD>");
185 escputs((char *)icalproperty_get_comment(p));
186 wprintf("</TD></TR>\n");
189 /* If the component has subcomponents, recurse through them. */
190 for (c = icalcomponent_get_first_component(cal, ICAL_ANY_COMPONENT);
192 c = icalcomponent_get_next_component(cal, ICAL_ANY_COMPONENT)) {
193 /* Recursively process subcomponent */
194 cal_process_object(c, recursion_level+1, msgnum, cal_partnum);
197 /* If this is a REQUEST, display conflicts and buttons */
198 if (the_method == ICAL_METHOD_REQUEST) {
200 /* Check for conflicts */
201 serv_printf("ICAL conflicts|%ld|%s|", msgnum, cal_partnum);
204 while (serv_gets(buf), strcmp(buf, "000")) {
205 extract(conflict_name, buf, 3);
206 is_update = extract_int(buf, 4);
207 wprintf("<TR><TD><B><I>%s</I></B></TD>"
218 "This is an update of" :
219 "This event would conflict with"
223 escputs(conflict_name);
224 wprintf(""</I> "
225 "which is already in your calendar."
230 /* Display the Accept/Decline buttons */
231 wprintf("<TR><TD COLSPAN=2>"
232 "<FORM METHOD=\"GET\" "
233 "ACTION=\"/respond_to_request\">\n"
234 "<INPUT TYPE=\"submit\" NAME=\"sc\" "
235 "VALUE=\"Accept\">\n"
237 "<INPUT TYPE=\"submit\" NAME=\"sc\" "
238 "VALUE=\"Tentative\">\n"
240 "<INPUT TYPE=\"submit\" NAME=\"sc\" "
241 "VALUE=\"Decline\">\n"
242 "<INPUT TYPE=\"hidden\" NAME=\"msgnum\" "
244 "<INPUT TYPE=\"hidden\" NAME=\"cal_partnum\" "
253 /* Trailing HTML for the display of this object */
254 if (recursion_level == 0) {
256 wprintf("</TR></TABLE></CENTER>\n");
262 * Deserialize a calendar object in a message so it can be processed.
263 * (This is the main entry point for these things)
265 void cal_process_attachment(char *part_source, long msgnum, char *cal_partnum) {
268 cal = icalcomponent_new_from_string(part_source);
271 wprintf("Error parsing calendar object: %s<BR>\n",
272 icalerror_strerror(icalerrno));
276 cal_process_object(cal, 0, msgnum, cal_partnum);
278 /* Free the memory we obtained from libical's constructor */
279 icalcomponent_free(cal);
286 * Respond to a meeting request
288 void respond_to_request(void) {
293 wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=007700><TR><TD>"
294 "<FONT SIZE=+1 COLOR=\"FFFFFF\""
295 "<B>Respond to meeting request</B>"
296 "</FONT></TD></TR></TABLE><BR>\n"
299 serv_printf("ICAL respond|%s|%s|%s|",
307 wprintf("<TABLE BORDER=0><TR><TD>"
308 "<IMG SRC=\"static/vcalendar.gif\" ALIGN=CENTER>"
311 if (!strcasecmp(bstr("sc"), "accept")) {
312 wprintf("You have accepted this meeting invitation. "
313 "It has been entered into your calendar, "
315 } else if (!strcasecmp(bstr("sc"), "tentative")) {
316 wprintf("You have tentatively accepted this meeting invitation. "
317 "It has been 'pencilled in' to your calendar, "
319 } else if (!strcasecmp(bstr("sc"), "decline")) {
320 wprintf("You have declined this meeting invitation. "
321 "It has <b>not</b> been entered into your calendar, "
324 wprintf("and a reply has been sent to the meeting organizer."
325 "</TD></TR></TABLE>\n"
328 wprintf("<IMG SRC=\"static/error.gif\" ALIGN=CENTER>"
332 wprintf("<A HREF=\"/dotskip?room=");
333 urlescputs(WC->wc_roomname);
334 wprintf("\">Return to messages</A><BR>\n");
342 /*****************************************************************************/
347 * Display handlers for message reading
353 * If we're reading calendar items, just store them for now. We have to
354 * sort and re-output them later when we draw the calendar.
356 void display_individual_cal(icalcomponent *cal, long msgnum) {
360 WC->disp_cal = realloc(WC->disp_cal,
361 (sizeof(icalcomponent *) * WC->num_cal) );
362 WC->disp_cal[WC->num_cal - 1] = icalcomponent_new_clone(cal);
364 WC->cal_msgnum = realloc(WC->cal_msgnum,
365 (sizeof(long) * WC->num_cal) );
366 WC->cal_msgnum[WC->num_cal - 1] = msgnum;
372 * Display a task in the task list
374 void display_individual_task(icalcomponent *vtodo, long msgnum) {
377 p = icalcomponent_get_first_property(vtodo, ICAL_SUMMARY_PROPERTY);
378 wprintf("<LI><A HREF=\"/display_edit_task?msgnum=%ld\">", msgnum);
380 escputs((char *)icalproperty_get_comment(p));
387 * Display a task by itself (for editing)
389 void display_edit_individual_task(icalcomponent *supplied_vtodo, long msgnum) {
390 icalcomponent *vtodo;
392 struct icaltimetype t;
394 int created_new_vtodo = 0;
398 if (supplied_vtodo != NULL) {
399 vtodo = supplied_vtodo;
402 vtodo = icalcomponent_new(ICAL_VTODO_COMPONENT);
403 created_new_vtodo = 1;
407 wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=007700><TR><TD>"
408 "<FONT SIZE=+1 COLOR=\"FFFFFF\""
410 "</FONT></TD></TR></TABLE><BR>\n"
413 wprintf("<FORM METHOD=\"POST\" ACTION=\"/save_task\">\n");
414 wprintf("<INPUT TYPE=\"hidden\" NAME=\"msgnum\" VALUE=\"%ld\">\n",
418 "<INPUT TYPE=\"text\" NAME=\"summary\" "
419 "MAXLENGTH=\"64\" SIZE=\"64\" VALUE=\"");
420 p = icalcomponent_get_first_property(vtodo, ICAL_SUMMARY_PROPERTY);
422 escputs((char *)icalproperty_get_comment(p));
424 wprintf("\"><BR>\n");
426 wprintf("Start date: ");
427 p = icalcomponent_get_first_property(vtodo, ICAL_DTSTART_PROPERTY);
429 t = icalproperty_get_dtstart(p);
432 t = icaltime_from_timet(now, 0);
434 display_icaltimetype_as_webform(&t, "dtstart");
437 wprintf("Due date: ");
438 p = icalcomponent_get_first_property(vtodo, ICAL_DUE_PROPERTY);
440 t = icalproperty_get_due(p);
443 t = icaltime_from_timet(now, 0);
445 display_icaltimetype_as_webform(&t, "due");
448 wprintf("<CENTER><TEXTAREA NAME=\"description\" wrap=soft "
449 "ROWS=10 COLS=80 WIDTH=80>\n"
451 p = icalcomponent_get_first_property(vtodo, ICAL_DESCRIPTION_PROPERTY);
453 escputs((char *)icalproperty_get_comment(p));
455 wprintf("</TEXTAREA><BR>\n");
457 wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Save\">"
459 "<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Delete\">\n"
461 "<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">\n"
465 wprintf("</FORM>\n");
469 if (created_new_vtodo) {
470 icalcomponent_free(vtodo);
475 * Save an edited task
477 void save_individual_task(icalcomponent *supplied_vtodo, long msgnum) {
479 int delete_existing = 0;
481 icalcomponent *vtodo;
482 int created_new_vtodo = 0;
484 if (supplied_vtodo != NULL) {
485 vtodo = supplied_vtodo;
488 vtodo = icalcomponent_new(ICAL_VTODO_COMPONENT);
489 created_new_vtodo = 1;
492 if (!strcasecmp(bstr("sc"), "Save")) {
494 /* Replace values in the component with ones from the form */
496 while (prop = icalcomponent_get_first_property(vtodo,
497 ICAL_SUMMARY_PROPERTY), prop != NULL) {
498 icalcomponent_remove_property(vtodo, prop);
499 icalproperty_free(prop);
501 icalcomponent_add_property(vtodo,
502 icalproperty_new_summary(bstr("summary")));
504 while (prop = icalcomponent_get_first_property(vtodo,
505 ICAL_DESCRIPTION_PROPERTY), prop != NULL) {
506 icalcomponent_remove_property(vtodo, prop);
507 icalproperty_free(prop);
509 icalcomponent_add_property(vtodo,
510 icalproperty_new_description(bstr("description")));
512 while (prop = icalcomponent_get_first_property(vtodo,
513 ICAL_DTSTART_PROPERTY), prop != NULL) {
514 icalcomponent_remove_property(vtodo, prop);
515 icalproperty_free(prop);
517 icalcomponent_add_property(vtodo,
518 icalproperty_new_dtstart(
519 icaltime_from_webform("dtstart")
523 while (prop = icalcomponent_get_first_property(vtodo,
524 ICAL_DUE_PROPERTY), prop != NULL) {
525 icalcomponent_remove_property(vtodo, prop);
526 icalproperty_free(prop);
528 icalcomponent_add_property(vtodo,
529 icalproperty_new_due(
530 icaltime_from_webform("due")
534 /* Serialize it and save it to the message base */
535 serv_puts("ENT0 1|||4");
538 serv_puts("Content-type: text/calendar");
540 serv_puts(icalcomponent_as_ical_string(vtodo));
543 /* Probably not necessary; the server will see the UID
544 * of the object and delete the old one anyway, but
552 * If the user clicked 'Delete' then explicitly delete the message.
554 if (!strcasecmp(bstr("sc"), "Delete")) {
558 if ( (delete_existing) && (msgnum > 0L) ) {
559 serv_printf("DELE %ld", atol(bstr("msgnum")));
563 if (created_new_vtodo) {
564 icalcomponent_free(vtodo);
567 /* Go back to the task list */
574 * Code common to all display handlers. Given a message number and a MIME
575 * type, we load the message and hunt for that MIME type. If found, we load
576 * the relevant part, deserialize it into a libical component, filter it for
577 * the requested object type, and feed it to the specified handler.
579 void display_using_handler(long msgnum,
581 icalcomponent_kind which_kind,
582 void (*callback)(icalcomponent *, long)
585 char mime_partnum[SIZ];
586 char mime_filename[SIZ];
587 char mime_content_type[SIZ];
588 char mime_disposition[SIZ];
590 char relevant_partnum[SIZ];
591 char *relevant_source = NULL;
592 icalcomponent *cal, *c;
594 sprintf(buf, "MSG0 %ld|1", msgnum); /* ask for headers only */
597 if (buf[0] != '1') return;
599 while (serv_gets(buf), strcmp(buf, "000")) {
600 if (!strncasecmp(buf, "part=", 5)) {
601 extract(mime_filename, &buf[5], 1);
602 extract(mime_partnum, &buf[5], 2);
603 extract(mime_disposition, &buf[5], 3);
604 extract(mime_content_type, &buf[5], 4);
605 mime_length = extract_int(&buf[5], 5);
607 if (!strcasecmp(mime_content_type, "text/calendar")) {
608 strcpy(relevant_partnum, mime_partnum);
614 if (strlen(relevant_partnum) > 0) {
615 relevant_source = load_mimepart(msgnum, relevant_partnum);
616 if (relevant_source != NULL) {
618 cal = icalcomponent_new_from_string(relevant_source);
621 /* Simple components of desired type */
622 if (icalcomponent_isa(cal) == which_kind) {
623 callback(cal, msgnum);
626 /* Subcomponents of desired type */
627 for (c = icalcomponent_get_first_component(cal,
630 c = icalcomponent_get_next_component(cal,
634 icalcomponent_free(cal);
636 free(relevant_source);
642 void display_calendar(long msgnum) {
643 display_using_handler(msgnum, "text/calendar",
644 ICAL_VEVENT_COMPONENT,
645 display_individual_cal);
648 void display_task(long msgnum) {
649 display_using_handler(msgnum, "text/calendar",
650 ICAL_VTODO_COMPONENT,
651 display_individual_task);
654 void display_edit_task(void) {
657 msgnum = atol(bstr("msgnum"));
660 display_using_handler(msgnum, "text/calendar",
661 ICAL_VTODO_COMPONENT,
662 display_edit_individual_task);
666 display_edit_individual_task(NULL, 0L);
670 void save_task(void) {
673 msgnum = atol(bstr("msgnum"));
675 display_using_handler(msgnum, "text/calendar",
676 ICAL_VTODO_COMPONENT,
677 save_individual_task);
680 save_individual_task(NULL, 0L);
684 void display_edit_event(void) {
687 msgnum = atol(bstr("msgnum"));
690 display_using_handler(msgnum, "text/calendar",
691 ICAL_VEVENT_COMPONENT,
692 display_edit_individual_event);
696 display_edit_individual_event(NULL, 0L);
700 void save_event(void) {
703 msgnum = atol(bstr("msgnum"));
706 display_using_handler(msgnum, "text/calendar",
707 ICAL_VEVENT_COMPONENT,
708 save_individual_event);
711 save_individual_event(NULL, 0L);
715 #endif /* HAVE_ICAL_H */