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 conflicts and buttons */
184 if (the_method == ICAL_METHOD_REQUEST) {
186 /* Check for conflicts */
187 serv_printf("ICAL conflicts|%ld|%s|", msgnum, cal_partnum);
190 while (serv_gets(buf), strcmp(buf, "000")) {
191 wprintf("<TR><TD><B><I>CONFLICT:</I></B></TD><TD>");
193 wprintf("</TD></TR>\n");
197 /* Display the Accept/Decline buttons */
198 wprintf("<TR><TD COLSPAN=2>"
199 "<FORM METHOD=\"GET\" "
200 "ACTION=\"/respond_to_request\">\n"
201 "<INPUT TYPE=\"submit\" NAME=\"sc\" "
202 "VALUE=\"Accept\">\n"
204 "<INPUT TYPE=\"submit\" NAME=\"sc\" "
205 "VALUE=\"Tentative\">\n"
207 "<INPUT TYPE=\"submit\" NAME=\"sc\" "
208 "VALUE=\"Decline\">\n"
209 "<INPUT TYPE=\"hidden\" NAME=\"msgnum\" "
211 "<INPUT TYPE=\"hidden\" NAME=\"cal_partnum\" "
220 /* Trailing HTML for the display of this object */
221 if (recursion_level == 0) {
223 wprintf("</TR></TABLE></CENTER>\n");
229 * Deserialize a calendar object in a message so it can be processed.
230 * (This is the main entry point for these things)
232 void cal_process_attachment(char *part_source, long msgnum, char *cal_partnum) {
235 cal = icalcomponent_new_from_string(part_source);
238 wprintf("Error parsing calendar object: %s<BR>\n",
239 icalerror_strerror(icalerrno));
243 cal_process_object(cal, 0, msgnum, cal_partnum);
245 /* Free the memory we obtained from libical's constructor */
246 icalcomponent_free(cal);
253 * Respond to a meeting request
255 void respond_to_request(void) {
260 wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=007700><TR><TD>"
261 "<FONT SIZE=+1 COLOR=\"FFFFFF\""
262 "<B>Respond to meeting request</B>"
263 "</FONT></TD></TR></TABLE><BR>\n"
266 serv_printf("ICAL respond|%s|%s|%s|",
280 /*****************************************************************************/
285 * Display handlers for message reading
291 * If we're reading calendar items, just store them for now. We have to
292 * sort and re-output them later when we draw the calendar.
294 void display_individual_cal(icalcomponent *cal, long msgnum) {
298 WC->disp_cal = realloc(WC->disp_cal,
299 (sizeof(icalcomponent *) * WC->num_cal) );
300 WC->disp_cal[WC->num_cal - 1] = icalcomponent_new_clone(cal);
302 WC->cal_msgnum = realloc(WC->cal_msgnum,
303 (sizeof(long) * WC->num_cal) );
304 WC->cal_msgnum[WC->num_cal - 1] = msgnum;
310 * Display a task in the task list
312 void display_individual_task(icalcomponent *vtodo, long msgnum) {
315 p = icalcomponent_get_first_property(vtodo, ICAL_SUMMARY_PROPERTY);
316 wprintf("<LI><A HREF=\"/display_edit_task?msgnum=%ld\">", msgnum);
318 escputs((char *)icalproperty_get_comment(p));
325 * Display a task by itself (for editing)
327 void display_edit_individual_task(icalcomponent *supplied_vtodo, long msgnum) {
328 icalcomponent *vtodo;
330 struct icaltimetype t;
332 int created_new_vtodo = 0;
336 if (supplied_vtodo != NULL) {
337 vtodo = supplied_vtodo;
340 vtodo = icalcomponent_new(ICAL_VTODO_COMPONENT);
341 created_new_vtodo = 1;
345 wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=007700><TR><TD>"
346 "<FONT SIZE=+1 COLOR=\"FFFFFF\""
348 "</FONT></TD></TR></TABLE><BR>\n"
351 wprintf("<FORM METHOD=\"POST\" ACTION=\"/save_task\">\n");
352 wprintf("<INPUT TYPE=\"hidden\" NAME=\"msgnum\" VALUE=\"%ld\">\n",
356 "<INPUT TYPE=\"text\" NAME=\"summary\" "
357 "MAXLENGTH=\"64\" SIZE=\"64\" VALUE=\"");
358 p = icalcomponent_get_first_property(vtodo, ICAL_SUMMARY_PROPERTY);
360 escputs((char *)icalproperty_get_comment(p));
362 wprintf("\"><BR>\n");
364 wprintf("Start date: ");
365 p = icalcomponent_get_first_property(vtodo, ICAL_DTSTART_PROPERTY);
367 t = icalproperty_get_dtstart(p);
370 t = icaltime_from_timet(now, 0);
372 display_icaltimetype_as_webform(&t, "dtstart");
375 wprintf("Due date: ");
376 p = icalcomponent_get_first_property(vtodo, ICAL_DUE_PROPERTY);
378 t = icalproperty_get_due(p);
381 t = icaltime_from_timet(now, 0);
383 display_icaltimetype_as_webform(&t, "due");
386 wprintf("<CENTER><TEXTAREA NAME=\"description\" wrap=soft "
387 "ROWS=10 COLS=80 WIDTH=80>\n"
389 p = icalcomponent_get_first_property(vtodo, ICAL_DESCRIPTION_PROPERTY);
391 escputs((char *)icalproperty_get_comment(p));
393 wprintf("</TEXTAREA><BR>\n");
395 wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Save\">"
397 "<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Delete\">\n"
399 "<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">\n"
403 wprintf("</FORM>\n");
407 if (created_new_vtodo) {
408 icalcomponent_free(vtodo);
413 * Save an edited task
415 void save_individual_task(icalcomponent *supplied_vtodo, long msgnum) {
417 int delete_existing = 0;
419 icalcomponent *vtodo;
420 int created_new_vtodo = 0;
422 if (supplied_vtodo != NULL) {
423 vtodo = supplied_vtodo;
426 vtodo = icalcomponent_new(ICAL_VTODO_COMPONENT);
427 created_new_vtodo = 1;
430 if (!strcasecmp(bstr("sc"), "Save")) {
432 /* Replace values in the component with ones from the form */
434 while (prop = icalcomponent_get_first_property(vtodo,
435 ICAL_SUMMARY_PROPERTY), prop != NULL) {
436 icalcomponent_remove_property(vtodo, prop);
438 icalcomponent_add_property(vtodo,
439 icalproperty_new_summary(bstr("summary")));
441 while (prop = icalcomponent_get_first_property(vtodo,
442 ICAL_DESCRIPTION_PROPERTY), prop != NULL) {
443 icalcomponent_remove_property(vtodo, prop);
445 icalcomponent_add_property(vtodo,
446 icalproperty_new_description(bstr("description")));
448 while (prop = icalcomponent_get_first_property(vtodo,
449 ICAL_DTSTART_PROPERTY), prop != NULL) {
450 icalcomponent_remove_property(vtodo, prop);
452 icalcomponent_add_property(vtodo,
453 icalproperty_new_dtstart(
454 icaltime_from_webform("dtstart")
458 while (prop = icalcomponent_get_first_property(vtodo,
459 ICAL_DUE_PROPERTY), prop != NULL) {
460 icalcomponent_remove_property(vtodo, prop);
462 icalcomponent_add_property(vtodo,
463 icalproperty_new_due(
464 icaltime_from_webform("due")
468 /* Serialize it and save it to the message base */
469 serv_puts("ENT0 1|||4");
472 serv_puts("Content-type: text/calendar");
474 serv_puts(icalcomponent_as_ical_string(vtodo));
481 * If the user clicked 'Delete' then delete it, period.
483 if (!strcasecmp(bstr("sc"), "Delete")) {
487 if ( (delete_existing) && (msgnum > 0L) ) {
488 serv_printf("DELE %ld", atol(bstr("msgnum")));
492 if (created_new_vtodo) {
493 icalcomponent_free(vtodo);
496 /* Go back to the task list */
503 * Code common to all display handlers. Given a message number and a MIME
504 * type, we load the message and hunt for that MIME type. If found, we load
505 * the relevant part, deserialize it into a libical component, filter it for
506 * the requested object type, and feed it to the specified handler.
508 void display_using_handler(long msgnum,
510 icalcomponent_kind which_kind,
511 void (*callback)(icalcomponent *, long)
514 char mime_partnum[SIZ];
515 char mime_filename[SIZ];
516 char mime_content_type[SIZ];
517 char mime_disposition[SIZ];
519 char relevant_partnum[SIZ];
520 char *relevant_source = NULL;
521 icalcomponent *cal, *c;
523 sprintf(buf, "MSG0 %ld|1", msgnum); /* ask for headers only */
526 if (buf[0] != '1') return;
528 while (serv_gets(buf), strcmp(buf, "000")) {
529 if (!strncasecmp(buf, "part=", 5)) {
530 extract(mime_filename, &buf[5], 1);
531 extract(mime_partnum, &buf[5], 2);
532 extract(mime_disposition, &buf[5], 3);
533 extract(mime_content_type, &buf[5], 4);
534 mime_length = extract_int(&buf[5], 5);
536 if (!strcasecmp(mime_content_type, "text/calendar")) {
537 strcpy(relevant_partnum, mime_partnum);
543 if (strlen(relevant_partnum) > 0) {
544 relevant_source = load_mimepart(msgnum, relevant_partnum);
545 if (relevant_source != NULL) {
547 cal = icalcomponent_new_from_string(relevant_source);
550 /* Simple components of desired type */
551 if (icalcomponent_isa(cal) == which_kind) {
552 callback(cal, msgnum);
555 /* Subcomponents of desired type */
556 for (c = icalcomponent_get_first_component(cal,
559 c = icalcomponent_get_next_component(cal,
563 icalcomponent_free(cal);
565 free(relevant_source);
571 void display_calendar(long msgnum) {
572 display_using_handler(msgnum, "text/calendar",
573 ICAL_VEVENT_COMPONENT,
574 display_individual_cal);
577 void display_task(long msgnum) {
578 display_using_handler(msgnum, "text/calendar",
579 ICAL_VTODO_COMPONENT,
580 display_individual_task);
583 void display_edit_task(void) {
586 msgnum = atol(bstr("msgnum"));
589 display_using_handler(msgnum, "text/calendar",
590 ICAL_VTODO_COMPONENT,
591 display_edit_individual_task);
595 display_edit_individual_task(NULL, 0L);
599 void save_task(void) {
602 msgnum = atol(bstr("msgnum"));
604 display_using_handler(msgnum, "text/calendar",
605 ICAL_VTODO_COMPONENT,
606 save_individual_task);
609 save_individual_task(NULL, 0L);
613 void display_edit_event(void) {
616 msgnum = atol(bstr("msgnum"));
619 display_using_handler(msgnum, "text/calendar",
620 ICAL_VEVENT_COMPONENT,
621 display_edit_individual_event);
625 display_edit_individual_event(NULL, 0L);
629 void save_event(void) {
632 msgnum = atol(bstr("msgnum"));
635 display_using_handler(msgnum, "text/calendar",
636 ICAL_VEVENT_COMPONENT,
637 save_individual_event);
640 save_individual_event(NULL, 0L);
644 #endif /* HAVE_ICAL_H */