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;
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>
109 wprintf("<TR><TD COLSPAN=2>"
110 "I don't know what to do with this.</TD></TR>"
116 p = icalcomponent_get_first_property(cal, ICAL_SUMMARY_PROPERTY);
118 wprintf("<TR><TD><B>Summary:</B></TD><TD>");
119 escputs((char *)icalproperty_get_comment(p));
120 wprintf("</TD></TR>\n");
123 p = icalcomponent_get_first_property(cal, ICAL_LOCATION_PROPERTY);
125 wprintf("<TR><TD><B>Location:</B></TD><TD>");
126 escputs((char *)icalproperty_get_comment(p));
127 wprintf("</TD></TR>\n");
131 * Only show start/end times if we're actually looking at the VEVENT
132 * component. Otherwise it shows bogus dates for things like timezone.
134 if (icalcomponent_isa(cal) == ICAL_VEVENT_COMPONENT) {
136 p = icalcomponent_get_first_property(cal,
137 ICAL_DTSTART_PROPERTY);
139 t = icalproperty_get_dtstart(p);
140 tt = icaltime_as_timet(t);
142 wprintf("<TR><TD><B>Starting date/time:</B></TD><TD>"
147 p = icalcomponent_get_first_property(cal, ICAL_DTEND_PROPERTY);
149 t = icalproperty_get_dtend(p);
150 tt = icaltime_as_timet(t);
152 wprintf("<TR><TD><B>Ending date/time:</B></TD><TD>"
159 p = icalcomponent_get_first_property(cal, ICAL_DESCRIPTION_PROPERTY);
161 wprintf("<TR><TD><B>Description:</B></TD><TD>");
162 escputs((char *)icalproperty_get_comment(p));
163 wprintf("</TD></TR>\n");
166 /* If the component has subcomponents, recurse through them. */
167 for (c = icalcomponent_get_first_component(cal, ICAL_ANY_COMPONENT);
169 c = icalcomponent_get_next_component(cal, ICAL_ANY_COMPONENT)) {
170 /* Recursively process subcomponent */
171 cal_process_object(c, recursion_level+1, msgnum, cal_partnum);
174 /* Trailing HTML for the display of this object */
175 if (recursion_level == 0) {
176 wprintf("<TR><TD COLSPAN=2>"
177 "<FORM METHOD=\"GET\" "
178 "ACTION=\"/respond_to_request\">\n"
179 "<INPUT TYPE=\"submit\" NAME=\"sc\" "
180 "VALUE=\"Accept\">\n"
182 "<INPUT TYPE=\"submit\" NAME=\"sc\" "
183 "VALUE=\"Decline\">\n"
184 "<INPUT TYPE=\"hidden\" NAME=\"msgnum\" "
186 "<INPUT TYPE=\"hidden\" NAME=\"cal_partnum\" "
189 "</TD></TR></TABLE></CENTER>\n",
197 * Deserialize a calendar object in a message so it can be processed.
198 * (This is the main entry point for these things)
200 void cal_process_attachment(char *part_source, long msgnum, char *cal_partnum) {
203 cal = icalcomponent_new_from_string(part_source);
206 wprintf("Error parsing calendar object: %s<BR>\n",
207 icalerror_strerror(icalerrno));
211 cal_process_object(cal, 0, msgnum, cal_partnum);
213 /* Free the memory we obtained from libical's constructor */
214 icalcomponent_free(cal);
221 * Respond to a meeting request
223 void respond_to_request(void) {
226 wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=007700><TR><TD>"
227 "<FONT SIZE=+1 COLOR=\"FFFFFF\""
228 "<B>Respond to meeting request</B>"
229 "</FONT></TD></TR></TABLE><BR>\n"
232 wprintf("msgnum = %s<BR>\n", bstr("msgnum"));
233 wprintf("cal_partnum = %s<BR>\n", bstr("cal_partnum"));
234 wprintf("sc = %s<BR>\n", bstr("sc"));
236 /* use OPNA command to foo this */
244 /*****************************************************************************/
249 * Display handlers for message reading
255 * If we're reading calendar items, just store them for now. We have to
256 * sort and re-output them later when we draw the calendar.
258 void display_individual_cal(icalcomponent *cal, long msgnum) {
262 WC->disp_cal = realloc(WC->disp_cal,
263 (sizeof(icalcomponent *) * WC->num_cal) );
264 WC->disp_cal[WC->num_cal - 1] = icalcomponent_new_clone(cal);
266 WC->cal_msgnum = realloc(WC->cal_msgnum,
267 (sizeof(long) * WC->num_cal) );
268 WC->cal_msgnum[WC->num_cal - 1] = msgnum;
274 * Display a task in the task list
276 void display_individual_task(icalcomponent *vtodo, long msgnum) {
279 p = icalcomponent_get_first_property(vtodo, ICAL_SUMMARY_PROPERTY);
280 wprintf("<LI><A HREF=\"/display_edit_task?msgnum=%ld\">", msgnum);
282 escputs((char *)icalproperty_get_comment(p));
289 * Display a task by itself (for editing)
291 void display_edit_individual_task(icalcomponent *supplied_vtodo, long msgnum) {
292 icalcomponent *vtodo;
294 struct icaltimetype t;
296 int created_new_vtodo = 0;
300 if (supplied_vtodo != NULL) {
301 vtodo = supplied_vtodo;
304 vtodo = icalcomponent_new(ICAL_VTODO_COMPONENT);
305 created_new_vtodo = 1;
309 wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=007700><TR><TD>"
310 "<FONT SIZE=+1 COLOR=\"FFFFFF\""
312 "</FONT></TD></TR></TABLE><BR>\n"
315 wprintf("<FORM METHOD=\"POST\" ACTION=\"/save_task\">\n");
316 wprintf("<INPUT TYPE=\"hidden\" NAME=\"msgnum\" VALUE=\"%ld\">\n",
320 "<INPUT TYPE=\"text\" NAME=\"summary\" "
321 "MAXLENGTH=\"64\" SIZE=\"64\" VALUE=\"");
322 p = icalcomponent_get_first_property(vtodo, ICAL_SUMMARY_PROPERTY);
324 escputs((char *)icalproperty_get_comment(p));
326 wprintf("\"><BR>\n");
328 wprintf("Start date: ");
329 p = icalcomponent_get_first_property(vtodo, ICAL_DTSTART_PROPERTY);
331 t = icalproperty_get_dtstart(p);
334 t = icaltime_from_timet(now, 0);
336 display_icaltimetype_as_webform(&t, "dtstart");
339 wprintf("Due date: ");
340 p = icalcomponent_get_first_property(vtodo, ICAL_DUE_PROPERTY);
342 t = icalproperty_get_due(p);
345 t = icaltime_from_timet(now, 0);
347 display_icaltimetype_as_webform(&t, "due");
350 wprintf("<CENTER><TEXTAREA NAME=\"description\" wrap=soft "
351 "ROWS=10 COLS=80 WIDTH=80>\n"
353 p = icalcomponent_get_first_property(vtodo, ICAL_DESCRIPTION_PROPERTY);
355 escputs((char *)icalproperty_get_comment(p));
357 wprintf("</TEXTAREA><BR>\n");
359 wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Save\">"
361 "<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Delete\">\n"
363 "<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">\n"
367 wprintf("</FORM>\n");
371 if (created_new_vtodo) {
372 icalcomponent_free(vtodo);
377 * Save an edited task
379 void save_individual_task(icalcomponent *supplied_vtodo, long msgnum) {
381 int delete_existing = 0;
383 icalcomponent *vtodo;
384 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;
394 if (!strcasecmp(bstr("sc"), "Save")) {
396 /* Replace values in the component with ones from the form */
398 while (prop = icalcomponent_get_first_property(vtodo,
399 ICAL_SUMMARY_PROPERTY), prop != NULL) {
400 icalcomponent_remove_property(vtodo, prop);
402 icalcomponent_add_property(vtodo,
403 icalproperty_new_summary(bstr("summary")));
405 while (prop = icalcomponent_get_first_property(vtodo,
406 ICAL_DESCRIPTION_PROPERTY), prop != NULL) {
407 icalcomponent_remove_property(vtodo, prop);
409 icalcomponent_add_property(vtodo,
410 icalproperty_new_description(bstr("description")));
412 while (prop = icalcomponent_get_first_property(vtodo,
413 ICAL_DTSTART_PROPERTY), prop != NULL) {
414 icalcomponent_remove_property(vtodo, prop);
416 icalcomponent_add_property(vtodo,
417 icalproperty_new_dtstart(
418 icaltime_from_webform("dtstart")
422 while (prop = icalcomponent_get_first_property(vtodo,
423 ICAL_DUE_PROPERTY), prop != NULL) {
424 icalcomponent_remove_property(vtodo, prop);
426 icalcomponent_add_property(vtodo,
427 icalproperty_new_due(
428 icaltime_from_webform("due")
432 /* Serialize it and save it to the message base */
433 serv_puts("ENT0 1|||4");
436 serv_puts("Content-type: text/calendar");
438 serv_puts(icalcomponent_as_ical_string(vtodo));
445 * If the user clicked 'Delete' then delete it, period.
447 if (!strcasecmp(bstr("sc"), "Delete")) {
451 if ( (delete_existing) && (msgnum > 0L) ) {
452 serv_printf("DELE %ld", atol(bstr("msgnum")));
456 if (created_new_vtodo) {
457 icalcomponent_free(vtodo);
460 /* Go back to the task list */
467 * Code common to all display handlers. Given a message number and a MIME
468 * type, we load the message and hunt for that MIME type. If found, we load
469 * the relevant part, deserialize it into a libical component, filter it for
470 * the requested object type, and feed it to the specified handler.
472 void display_using_handler(long msgnum,
474 icalcomponent_kind which_kind,
475 void (*callback)(icalcomponent *, long)
478 char mime_partnum[SIZ];
479 char mime_filename[SIZ];
480 char mime_content_type[SIZ];
481 char mime_disposition[SIZ];
483 char relevant_partnum[SIZ];
484 char *relevant_source = NULL;
485 icalcomponent *cal, *c;
487 sprintf(buf, "MSG0 %ld|1", msgnum); /* ask for headers only */
490 if (buf[0] != '1') return;
492 while (serv_gets(buf), strcmp(buf, "000")) {
493 if (!strncasecmp(buf, "part=", 5)) {
494 extract(mime_filename, &buf[5], 1);
495 extract(mime_partnum, &buf[5], 2);
496 extract(mime_disposition, &buf[5], 3);
497 extract(mime_content_type, &buf[5], 4);
498 mime_length = extract_int(&buf[5], 5);
500 if (!strcasecmp(mime_content_type, "text/calendar")) {
501 strcpy(relevant_partnum, mime_partnum);
507 if (strlen(relevant_partnum) > 0) {
508 relevant_source = load_mimepart(msgnum, relevant_partnum);
509 if (relevant_source != NULL) {
511 cal = icalcomponent_new_from_string(relevant_source);
514 /* Simple components of desired type */
515 if (icalcomponent_isa(cal) == which_kind) {
516 callback(cal, msgnum);
519 /* Subcomponents of desired type */
520 for (c = icalcomponent_get_first_component(cal,
523 c = icalcomponent_get_next_component(cal,
527 icalcomponent_free(cal);
529 free(relevant_source);
535 void display_calendar(long msgnum) {
536 display_using_handler(msgnum, "text/calendar",
537 ICAL_VEVENT_COMPONENT,
538 display_individual_cal);
541 void display_task(long msgnum) {
542 display_using_handler(msgnum, "text/calendar",
543 ICAL_VTODO_COMPONENT,
544 display_individual_task);
547 void display_edit_task(void) {
550 msgnum = atol(bstr("msgnum"));
553 display_using_handler(msgnum, "text/calendar",
554 ICAL_VTODO_COMPONENT,
555 display_edit_individual_task);
559 display_edit_individual_task(NULL, 0L);
563 void save_task(void) {
566 msgnum = atol(bstr("msgnum"));
568 display_using_handler(msgnum, "text/calendar",
569 ICAL_VTODO_COMPONENT,
570 save_individual_task);
573 save_individual_task(NULL, 0L);
577 void display_edit_event(void) {
580 msgnum = atol(bstr("msgnum"));
583 display_using_handler(msgnum, "text/calendar",
584 ICAL_VEVENT_COMPONENT,
585 display_edit_individual_event);
589 display_edit_individual_event(NULL, 0L);
593 void save_event(void) {
596 msgnum = atol(bstr("msgnum"));
599 display_using_handler(msgnum, "text/calendar",
600 ICAL_VEVENT_COMPONENT,
601 save_individual_event);
604 save_individual_event(NULL, 0L);
608 #endif /* HAVE_ICAL_H */