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|",
301 /*****************************************************************************/
306 * Display handlers for message reading
312 * If we're reading calendar items, just store them for now. We have to
313 * sort and re-output them later when we draw the calendar.
315 void display_individual_cal(icalcomponent *cal, long msgnum) {
319 WC->disp_cal = realloc(WC->disp_cal,
320 (sizeof(icalcomponent *) * WC->num_cal) );
321 WC->disp_cal[WC->num_cal - 1] = icalcomponent_new_clone(cal);
323 WC->cal_msgnum = realloc(WC->cal_msgnum,
324 (sizeof(long) * WC->num_cal) );
325 WC->cal_msgnum[WC->num_cal - 1] = msgnum;
331 * Display a task in the task list
333 void display_individual_task(icalcomponent *vtodo, long msgnum) {
336 p = icalcomponent_get_first_property(vtodo, ICAL_SUMMARY_PROPERTY);
337 wprintf("<LI><A HREF=\"/display_edit_task?msgnum=%ld\">", msgnum);
339 escputs((char *)icalproperty_get_comment(p));
346 * Display a task by itself (for editing)
348 void display_edit_individual_task(icalcomponent *supplied_vtodo, long msgnum) {
349 icalcomponent *vtodo;
351 struct icaltimetype t;
353 int created_new_vtodo = 0;
357 if (supplied_vtodo != NULL) {
358 vtodo = supplied_vtodo;
361 vtodo = icalcomponent_new(ICAL_VTODO_COMPONENT);
362 created_new_vtodo = 1;
366 wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=007700><TR><TD>"
367 "<FONT SIZE=+1 COLOR=\"FFFFFF\""
369 "</FONT></TD></TR></TABLE><BR>\n"
372 wprintf("<FORM METHOD=\"POST\" ACTION=\"/save_task\">\n");
373 wprintf("<INPUT TYPE=\"hidden\" NAME=\"msgnum\" VALUE=\"%ld\">\n",
377 "<INPUT TYPE=\"text\" NAME=\"summary\" "
378 "MAXLENGTH=\"64\" SIZE=\"64\" VALUE=\"");
379 p = icalcomponent_get_first_property(vtodo, ICAL_SUMMARY_PROPERTY);
381 escputs((char *)icalproperty_get_comment(p));
383 wprintf("\"><BR>\n");
385 wprintf("Start date: ");
386 p = icalcomponent_get_first_property(vtodo, ICAL_DTSTART_PROPERTY);
388 t = icalproperty_get_dtstart(p);
391 t = icaltime_from_timet(now, 0);
393 display_icaltimetype_as_webform(&t, "dtstart");
396 wprintf("Due date: ");
397 p = icalcomponent_get_first_property(vtodo, ICAL_DUE_PROPERTY);
399 t = icalproperty_get_due(p);
402 t = icaltime_from_timet(now, 0);
404 display_icaltimetype_as_webform(&t, "due");
407 wprintf("<CENTER><TEXTAREA NAME=\"description\" wrap=soft "
408 "ROWS=10 COLS=80 WIDTH=80>\n"
410 p = icalcomponent_get_first_property(vtodo, ICAL_DESCRIPTION_PROPERTY);
412 escputs((char *)icalproperty_get_comment(p));
414 wprintf("</TEXTAREA><BR>\n");
416 wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Save\">"
418 "<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Delete\">\n"
420 "<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">\n"
424 wprintf("</FORM>\n");
428 if (created_new_vtodo) {
429 icalcomponent_free(vtodo);
434 * Save an edited task
436 void save_individual_task(icalcomponent *supplied_vtodo, long msgnum) {
438 int delete_existing = 0;
440 icalcomponent *vtodo;
441 int created_new_vtodo = 0;
443 if (supplied_vtodo != NULL) {
444 vtodo = supplied_vtodo;
447 vtodo = icalcomponent_new(ICAL_VTODO_COMPONENT);
448 created_new_vtodo = 1;
451 if (!strcasecmp(bstr("sc"), "Save")) {
453 /* Replace values in the component with ones from the form */
455 while (prop = icalcomponent_get_first_property(vtodo,
456 ICAL_SUMMARY_PROPERTY), prop != NULL) {
457 icalcomponent_remove_property(vtodo, prop);
459 icalcomponent_add_property(vtodo,
460 icalproperty_new_summary(bstr("summary")));
462 while (prop = icalcomponent_get_first_property(vtodo,
463 ICAL_DESCRIPTION_PROPERTY), prop != NULL) {
464 icalcomponent_remove_property(vtodo, prop);
466 icalcomponent_add_property(vtodo,
467 icalproperty_new_description(bstr("description")));
469 while (prop = icalcomponent_get_first_property(vtodo,
470 ICAL_DTSTART_PROPERTY), prop != NULL) {
471 icalcomponent_remove_property(vtodo, prop);
473 icalcomponent_add_property(vtodo,
474 icalproperty_new_dtstart(
475 icaltime_from_webform("dtstart")
479 while (prop = icalcomponent_get_first_property(vtodo,
480 ICAL_DUE_PROPERTY), prop != NULL) {
481 icalcomponent_remove_property(vtodo, prop);
483 icalcomponent_add_property(vtodo,
484 icalproperty_new_due(
485 icaltime_from_webform("due")
489 /* Serialize it and save it to the message base */
490 serv_puts("ENT0 1|||4");
493 serv_puts("Content-type: text/calendar");
495 serv_puts(icalcomponent_as_ical_string(vtodo));
498 /* Probably not necessary; the server will see the UID
499 * of the object and delete the old one anyway, but
507 * If the user clicked 'Delete' then explicitly delete the message.
509 if (!strcasecmp(bstr("sc"), "Delete")) {
513 if ( (delete_existing) && (msgnum > 0L) ) {
514 serv_printf("DELE %ld", atol(bstr("msgnum")));
518 if (created_new_vtodo) {
519 icalcomponent_free(vtodo);
522 /* Go back to the task list */
529 * Code common to all display handlers. Given a message number and a MIME
530 * type, we load the message and hunt for that MIME type. If found, we load
531 * the relevant part, deserialize it into a libical component, filter it for
532 * the requested object type, and feed it to the specified handler.
534 void display_using_handler(long msgnum,
536 icalcomponent_kind which_kind,
537 void (*callback)(icalcomponent *, long)
540 char mime_partnum[SIZ];
541 char mime_filename[SIZ];
542 char mime_content_type[SIZ];
543 char mime_disposition[SIZ];
545 char relevant_partnum[SIZ];
546 char *relevant_source = NULL;
547 icalcomponent *cal, *c;
549 sprintf(buf, "MSG0 %ld|1", msgnum); /* ask for headers only */
552 if (buf[0] != '1') return;
554 while (serv_gets(buf), strcmp(buf, "000")) {
555 if (!strncasecmp(buf, "part=", 5)) {
556 extract(mime_filename, &buf[5], 1);
557 extract(mime_partnum, &buf[5], 2);
558 extract(mime_disposition, &buf[5], 3);
559 extract(mime_content_type, &buf[5], 4);
560 mime_length = extract_int(&buf[5], 5);
562 if (!strcasecmp(mime_content_type, "text/calendar")) {
563 strcpy(relevant_partnum, mime_partnum);
569 if (strlen(relevant_partnum) > 0) {
570 relevant_source = load_mimepart(msgnum, relevant_partnum);
571 if (relevant_source != NULL) {
573 cal = icalcomponent_new_from_string(relevant_source);
576 /* Simple components of desired type */
577 if (icalcomponent_isa(cal) == which_kind) {
578 callback(cal, msgnum);
581 /* Subcomponents of desired type */
582 for (c = icalcomponent_get_first_component(cal,
585 c = icalcomponent_get_next_component(cal,
589 icalcomponent_free(cal);
591 free(relevant_source);
597 void display_calendar(long msgnum) {
598 display_using_handler(msgnum, "text/calendar",
599 ICAL_VEVENT_COMPONENT,
600 display_individual_cal);
603 void display_task(long msgnum) {
604 display_using_handler(msgnum, "text/calendar",
605 ICAL_VTODO_COMPONENT,
606 display_individual_task);
609 void display_edit_task(void) {
612 msgnum = atol(bstr("msgnum"));
615 display_using_handler(msgnum, "text/calendar",
616 ICAL_VTODO_COMPONENT,
617 display_edit_individual_task);
621 display_edit_individual_task(NULL, 0L);
625 void save_task(void) {
628 msgnum = atol(bstr("msgnum"));
630 display_using_handler(msgnum, "text/calendar",
631 ICAL_VTODO_COMPONENT,
632 save_individual_task);
635 save_individual_task(NULL, 0L);
639 void display_edit_event(void) {
642 msgnum = atol(bstr("msgnum"));
645 display_using_handler(msgnum, "text/calendar",
646 ICAL_VEVENT_COMPONENT,
647 display_edit_individual_event);
651 display_edit_individual_event(NULL, 0L);
655 void save_event(void) {
658 msgnum = atol(bstr("msgnum"));
661 display_using_handler(msgnum, "text/calendar",
662 ICAL_VEVENT_COMPONENT,
663 save_individual_event);
666 save_individual_event(NULL, 0L);
670 #endif /* HAVE_ICAL_H */