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;
87 /* Leading HTML for the display of this object */
88 if (recursion_level == 0) {
89 wprintf("<CENTER><TABLE border=0 cellpadding=5>\n");
92 /* Look for a method */
93 method = icalcomponent_get_first_property(cal, ICAL_METHOD_PROPERTY);
95 /* See what we need to do with this */
97 the_method = icalproperty_get_method(method);
99 case ICAL_METHOD_REQUEST:
100 wprintf("<TR><TD COLSPAN=2>\n"
102 "SRC=\"/static/vcalendar.gif\">"
104 "<B>Meeting invitation</B>
108 case ICAL_METHOD_PUBLISH:
109 wprintf("<TR><TD COLSPAN=2>\n"
111 "SRC=\"/static/vcalendar.gif\">"
113 "<B>Published event</B>
118 wprintf("<TR><TD COLSPAN=2>"
119 "I don't know what to do with this.</TD></TR>"
125 p = icalcomponent_get_first_property(cal, ICAL_SUMMARY_PROPERTY);
127 wprintf("<TR><TD><B>Summary:</B></TD><TD>");
128 escputs((char *)icalproperty_get_comment(p));
129 wprintf("</TD></TR>\n");
132 p = icalcomponent_get_first_property(cal, ICAL_LOCATION_PROPERTY);
134 wprintf("<TR><TD><B>Location:</B></TD><TD>");
135 escputs((char *)icalproperty_get_comment(p));
136 wprintf("</TD></TR>\n");
140 * Only show start/end times if we're actually looking at the VEVENT
141 * component. Otherwise it shows bogus dates for things like timezone.
143 if (icalcomponent_isa(cal) == ICAL_VEVENT_COMPONENT) {
145 p = icalcomponent_get_first_property(cal,
146 ICAL_DTSTART_PROPERTY);
148 t = icalproperty_get_dtstart(p);
149 tt = icaltime_as_timet(t);
151 wprintf("<TR><TD><B>Starting date/time:</B></TD><TD>"
156 p = icalcomponent_get_first_property(cal, ICAL_DTEND_PROPERTY);
158 t = icalproperty_get_dtend(p);
159 tt = icaltime_as_timet(t);
161 wprintf("<TR><TD><B>Ending date/time:</B></TD><TD>"
168 p = icalcomponent_get_first_property(cal, ICAL_DESCRIPTION_PROPERTY);
170 wprintf("<TR><TD><B>Description:</B></TD><TD>");
171 escputs((char *)icalproperty_get_comment(p));
172 wprintf("</TD></TR>\n");
175 /* If the component has subcomponents, recurse through them. */
176 for (c = icalcomponent_get_first_component(cal, ICAL_ANY_COMPONENT);
178 c = icalcomponent_get_next_component(cal, ICAL_ANY_COMPONENT)) {
179 /* Recursively process subcomponent */
180 cal_process_object(c, recursion_level+1, msgnum, cal_partnum);
183 /* If this is a REQUEST, display the Accept/Decline buttons */
184 if (the_method == ICAL_METHOD_REQUEST) {
185 wprintf("<TR><TD COLSPAN=2>"
186 "<FORM METHOD=\"GET\" "
187 "ACTION=\"/respond_to_request\">\n"
188 "<INPUT TYPE=\"submit\" NAME=\"sc\" "
189 "VALUE=\"Accept\">\n"
191 "<INPUT TYPE=\"submit\" NAME=\"sc\" "
192 "VALUE=\"Tentative\">\n"
194 "<INPUT TYPE=\"submit\" NAME=\"sc\" "
195 "VALUE=\"Decline\">\n"
196 "<INPUT TYPE=\"hidden\" NAME=\"msgnum\" "
198 "<INPUT TYPE=\"hidden\" NAME=\"cal_partnum\" "
206 /* Trailing HTML for the display of this object */
207 if (recursion_level == 0) {
208 wprintf("</TD></TR></TABLE></CENTER>\n");
214 * Deserialize a calendar object in a message so it can be processed.
215 * (This is the main entry point for these things)
217 void cal_process_attachment(char *part_source, long msgnum, char *cal_partnum) {
220 cal = icalcomponent_new_from_string(part_source);
223 wprintf("Error parsing calendar object: %s<BR>\n",
224 icalerror_strerror(icalerrno));
228 cal_process_object(cal, 0, msgnum, cal_partnum);
230 /* Free the memory we obtained from libical's constructor */
231 icalcomponent_free(cal);
238 * Respond to a meeting request
240 void respond_to_request(void) {
245 wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=007700><TR><TD>"
246 "<FONT SIZE=+1 COLOR=\"FFFFFF\""
247 "<B>Respond to meeting request</B>"
248 "</FONT></TD></TR></TABLE><BR>\n"
251 serv_printf("ICAL respond|%s|%s|%s|",
265 /*****************************************************************************/
270 * Display handlers for message reading
276 * If we're reading calendar items, just store them for now. We have to
277 * sort and re-output them later when we draw the calendar.
279 void display_individual_cal(icalcomponent *cal, long msgnum) {
283 WC->disp_cal = realloc(WC->disp_cal,
284 (sizeof(icalcomponent *) * WC->num_cal) );
285 WC->disp_cal[WC->num_cal - 1] = icalcomponent_new_clone(cal);
287 WC->cal_msgnum = realloc(WC->cal_msgnum,
288 (sizeof(long) * WC->num_cal) );
289 WC->cal_msgnum[WC->num_cal - 1] = msgnum;
295 * Display a task in the task list
297 void display_individual_task(icalcomponent *vtodo, long msgnum) {
300 p = icalcomponent_get_first_property(vtodo, ICAL_SUMMARY_PROPERTY);
301 wprintf("<LI><A HREF=\"/display_edit_task?msgnum=%ld\">", msgnum);
303 escputs((char *)icalproperty_get_comment(p));
310 * Display a task by itself (for editing)
312 void display_edit_individual_task(icalcomponent *supplied_vtodo, long msgnum) {
313 icalcomponent *vtodo;
315 struct icaltimetype t;
317 int created_new_vtodo = 0;
321 if (supplied_vtodo != NULL) {
322 vtodo = supplied_vtodo;
325 vtodo = icalcomponent_new(ICAL_VTODO_COMPONENT);
326 created_new_vtodo = 1;
330 wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=007700><TR><TD>"
331 "<FONT SIZE=+1 COLOR=\"FFFFFF\""
333 "</FONT></TD></TR></TABLE><BR>\n"
336 wprintf("<FORM METHOD=\"POST\" ACTION=\"/save_task\">\n");
337 wprintf("<INPUT TYPE=\"hidden\" NAME=\"msgnum\" VALUE=\"%ld\">\n",
341 "<INPUT TYPE=\"text\" NAME=\"summary\" "
342 "MAXLENGTH=\"64\" SIZE=\"64\" VALUE=\"");
343 p = icalcomponent_get_first_property(vtodo, ICAL_SUMMARY_PROPERTY);
345 escputs((char *)icalproperty_get_comment(p));
347 wprintf("\"><BR>\n");
349 wprintf("Start date: ");
350 p = icalcomponent_get_first_property(vtodo, ICAL_DTSTART_PROPERTY);
352 t = icalproperty_get_dtstart(p);
355 t = icaltime_from_timet(now, 0);
357 display_icaltimetype_as_webform(&t, "dtstart");
360 wprintf("Due date: ");
361 p = icalcomponent_get_first_property(vtodo, ICAL_DUE_PROPERTY);
363 t = icalproperty_get_due(p);
366 t = icaltime_from_timet(now, 0);
368 display_icaltimetype_as_webform(&t, "due");
371 wprintf("<CENTER><TEXTAREA NAME=\"description\" wrap=soft "
372 "ROWS=10 COLS=80 WIDTH=80>\n"
374 p = icalcomponent_get_first_property(vtodo, ICAL_DESCRIPTION_PROPERTY);
376 escputs((char *)icalproperty_get_comment(p));
378 wprintf("</TEXTAREA><BR>\n");
380 wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Save\">"
382 "<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Delete\">\n"
384 "<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">\n"
388 wprintf("</FORM>\n");
392 if (created_new_vtodo) {
393 icalcomponent_free(vtodo);
398 * Save an edited task
400 void save_individual_task(icalcomponent *supplied_vtodo, long msgnum) {
402 int delete_existing = 0;
404 icalcomponent *vtodo;
405 int created_new_vtodo = 0;
407 if (supplied_vtodo != NULL) {
408 vtodo = supplied_vtodo;
411 vtodo = icalcomponent_new(ICAL_VTODO_COMPONENT);
412 created_new_vtodo = 1;
415 if (!strcasecmp(bstr("sc"), "Save")) {
417 /* Replace values in the component with ones from the form */
419 while (prop = icalcomponent_get_first_property(vtodo,
420 ICAL_SUMMARY_PROPERTY), prop != NULL) {
421 icalcomponent_remove_property(vtodo, prop);
423 icalcomponent_add_property(vtodo,
424 icalproperty_new_summary(bstr("summary")));
426 while (prop = icalcomponent_get_first_property(vtodo,
427 ICAL_DESCRIPTION_PROPERTY), prop != NULL) {
428 icalcomponent_remove_property(vtodo, prop);
430 icalcomponent_add_property(vtodo,
431 icalproperty_new_description(bstr("description")));
433 while (prop = icalcomponent_get_first_property(vtodo,
434 ICAL_DTSTART_PROPERTY), prop != NULL) {
435 icalcomponent_remove_property(vtodo, prop);
437 icalcomponent_add_property(vtodo,
438 icalproperty_new_dtstart(
439 icaltime_from_webform("dtstart")
443 while (prop = icalcomponent_get_first_property(vtodo,
444 ICAL_DUE_PROPERTY), prop != NULL) {
445 icalcomponent_remove_property(vtodo, prop);
447 icalcomponent_add_property(vtodo,
448 icalproperty_new_due(
449 icaltime_from_webform("due")
453 /* Serialize it and save it to the message base */
454 serv_puts("ENT0 1|||4");
457 serv_puts("Content-type: text/calendar");
459 serv_puts(icalcomponent_as_ical_string(vtodo));
466 * If the user clicked 'Delete' then delete it, period.
468 if (!strcasecmp(bstr("sc"), "Delete")) {
472 if ( (delete_existing) && (msgnum > 0L) ) {
473 serv_printf("DELE %ld", atol(bstr("msgnum")));
477 if (created_new_vtodo) {
478 icalcomponent_free(vtodo);
481 /* Go back to the task list */
488 * Code common to all display handlers. Given a message number and a MIME
489 * type, we load the message and hunt for that MIME type. If found, we load
490 * the relevant part, deserialize it into a libical component, filter it for
491 * the requested object type, and feed it to the specified handler.
493 void display_using_handler(long msgnum,
495 icalcomponent_kind which_kind,
496 void (*callback)(icalcomponent *, long)
499 char mime_partnum[SIZ];
500 char mime_filename[SIZ];
501 char mime_content_type[SIZ];
502 char mime_disposition[SIZ];
504 char relevant_partnum[SIZ];
505 char *relevant_source = NULL;
506 icalcomponent *cal, *c;
508 sprintf(buf, "MSG0 %ld|1", msgnum); /* ask for headers only */
511 if (buf[0] != '1') return;
513 while (serv_gets(buf), strcmp(buf, "000")) {
514 if (!strncasecmp(buf, "part=", 5)) {
515 extract(mime_filename, &buf[5], 1);
516 extract(mime_partnum, &buf[5], 2);
517 extract(mime_disposition, &buf[5], 3);
518 extract(mime_content_type, &buf[5], 4);
519 mime_length = extract_int(&buf[5], 5);
521 if (!strcasecmp(mime_content_type, "text/calendar")) {
522 strcpy(relevant_partnum, mime_partnum);
528 if (strlen(relevant_partnum) > 0) {
529 relevant_source = load_mimepart(msgnum, relevant_partnum);
530 if (relevant_source != NULL) {
532 cal = icalcomponent_new_from_string(relevant_source);
535 /* Simple components of desired type */
536 if (icalcomponent_isa(cal) == which_kind) {
537 callback(cal, msgnum);
540 /* Subcomponents of desired type */
541 for (c = icalcomponent_get_first_component(cal,
544 c = icalcomponent_get_next_component(cal,
548 icalcomponent_free(cal);
550 free(relevant_source);
556 void display_calendar(long msgnum) {
557 display_using_handler(msgnum, "text/calendar",
558 ICAL_VEVENT_COMPONENT,
559 display_individual_cal);
562 void display_task(long msgnum) {
563 display_using_handler(msgnum, "text/calendar",
564 ICAL_VTODO_COMPONENT,
565 display_individual_task);
568 void display_edit_task(void) {
571 msgnum = atol(bstr("msgnum"));
574 display_using_handler(msgnum, "text/calendar",
575 ICAL_VTODO_COMPONENT,
576 display_edit_individual_task);
580 display_edit_individual_task(NULL, 0L);
584 void save_task(void) {
587 msgnum = atol(bstr("msgnum"));
589 display_using_handler(msgnum, "text/calendar",
590 ICAL_VTODO_COMPONENT,
591 save_individual_task);
594 save_individual_task(NULL, 0L);
598 void display_edit_event(void) {
601 msgnum = atol(bstr("msgnum"));
604 display_using_handler(msgnum, "text/calendar",
605 ICAL_VEVENT_COMPONENT,
606 display_edit_individual_event);
610 display_edit_individual_event(NULL, 0L);
614 void save_event(void) {
617 msgnum = atol(bstr("msgnum"));
620 display_using_handler(msgnum, "text/calendar",
621 ICAL_VEVENT_COMPONENT,
622 save_individual_event);
625 save_individual_event(NULL, 0L);
629 #endif /* HAVE_ICAL_H */