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];
88 /* Leading HTML for the display of this object */
89 if (recursion_level == 0) {
90 wprintf("<CENTER><TABLE border=0>\n");
93 /* Look for a method */
94 method = icalcomponent_get_first_property(cal, ICAL_METHOD_PROPERTY);
96 /* See what we need to do with this */
98 the_method = icalproperty_get_method(method);
100 case ICAL_METHOD_REQUEST:
101 wprintf("<TR><TD COLSPAN=2>\n"
103 "SRC=\"/static/vcalendar.gif\">"
105 "<B>Meeting invitation</B>
109 case ICAL_METHOD_PUBLISH:
110 wprintf("<TR><TD COLSPAN=2>\n"
112 "SRC=\"/static/vcalendar.gif\">"
114 "<B>Published event</B>
119 wprintf("<TR><TD COLSPAN=2>"
120 "I don't know what to do with this.</TD></TR>"
126 p = icalcomponent_get_first_property(cal, ICAL_SUMMARY_PROPERTY);
128 wprintf("<TR><TD><B>Summary:</B></TD><TD>");
129 escputs((char *)icalproperty_get_comment(p));
130 wprintf("</TD></TR>\n");
133 p = icalcomponent_get_first_property(cal, ICAL_LOCATION_PROPERTY);
135 wprintf("<TR><TD><B>Location:</B></TD><TD>");
136 escputs((char *)icalproperty_get_comment(p));
137 wprintf("</TD></TR>\n");
141 * Only show start/end times if we're actually looking at the VEVENT
142 * component. Otherwise it shows bogus dates for things like timezone.
144 if (icalcomponent_isa(cal) == ICAL_VEVENT_COMPONENT) {
146 p = icalcomponent_get_first_property(cal,
147 ICAL_DTSTART_PROPERTY);
149 t = icalproperty_get_dtstart(p);
150 tt = icaltime_as_timet(t);
152 wprintf("<TR><TD><B>Starting date/time:</B></TD><TD>"
157 p = icalcomponent_get_first_property(cal, ICAL_DTEND_PROPERTY);
159 t = icalproperty_get_dtend(p);
160 tt = icaltime_as_timet(t);
162 wprintf("<TR><TD><B>Ending date/time:</B></TD><TD>"
169 p = icalcomponent_get_first_property(cal, ICAL_DESCRIPTION_PROPERTY);
171 wprintf("<TR><TD><B>Description:</B></TD><TD>");
172 escputs((char *)icalproperty_get_comment(p));
173 wprintf("</TD></TR>\n");
176 /* If the component has subcomponents, recurse through them. */
177 for (c = icalcomponent_get_first_component(cal, ICAL_ANY_COMPONENT);
179 c = icalcomponent_get_next_component(cal, ICAL_ANY_COMPONENT)) {
180 /* Recursively process subcomponent */
181 cal_process_object(c, recursion_level+1, msgnum, cal_partnum);
184 /* If this is a REQUEST, display conflicts and buttons */
185 if (the_method == ICAL_METHOD_REQUEST) {
187 /* Check for conflicts */
188 serv_printf("ICAL conflicts|%ld|%s|", msgnum, cal_partnum);
191 while (serv_gets(buf), strcmp(buf, "000")) {
192 extract(conflict_name, buf, 3);
193 wprintf("<TR><TD><B><I>CONFLICT:</I></B></TD>"
195 "This event would conflict with "
198 escputs(conflict_name);
199 wprintf(""</I> "
200 "which is already in your calendar."
205 /* Display the Accept/Decline buttons */
206 wprintf("<TR><TD COLSPAN=2>"
207 "<FORM METHOD=\"GET\" "
208 "ACTION=\"/respond_to_request\">\n"
209 "<INPUT TYPE=\"submit\" NAME=\"sc\" "
210 "VALUE=\"Accept\">\n"
212 "<INPUT TYPE=\"submit\" NAME=\"sc\" "
213 "VALUE=\"Tentative\">\n"
215 "<INPUT TYPE=\"submit\" NAME=\"sc\" "
216 "VALUE=\"Decline\">\n"
217 "<INPUT TYPE=\"hidden\" NAME=\"msgnum\" "
219 "<INPUT TYPE=\"hidden\" NAME=\"cal_partnum\" "
228 /* Trailing HTML for the display of this object */
229 if (recursion_level == 0) {
231 wprintf("</TR></TABLE></CENTER>\n");
237 * Deserialize a calendar object in a message so it can be processed.
238 * (This is the main entry point for these things)
240 void cal_process_attachment(char *part_source, long msgnum, char *cal_partnum) {
243 cal = icalcomponent_new_from_string(part_source);
246 wprintf("Error parsing calendar object: %s<BR>\n",
247 icalerror_strerror(icalerrno));
251 cal_process_object(cal, 0, msgnum, cal_partnum);
253 /* Free the memory we obtained from libical's constructor */
254 icalcomponent_free(cal);
261 * Respond to a meeting request
263 void respond_to_request(void) {
268 wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=007700><TR><TD>"
269 "<FONT SIZE=+1 COLOR=\"FFFFFF\""
270 "<B>Respond to meeting request</B>"
271 "</FONT></TD></TR></TABLE><BR>\n"
274 serv_printf("ICAL respond|%s|%s|%s|",
288 /*****************************************************************************/
293 * Display handlers for message reading
299 * If we're reading calendar items, just store them for now. We have to
300 * sort and re-output them later when we draw the calendar.
302 void display_individual_cal(icalcomponent *cal, long msgnum) {
306 WC->disp_cal = realloc(WC->disp_cal,
307 (sizeof(icalcomponent *) * WC->num_cal) );
308 WC->disp_cal[WC->num_cal - 1] = icalcomponent_new_clone(cal);
310 WC->cal_msgnum = realloc(WC->cal_msgnum,
311 (sizeof(long) * WC->num_cal) );
312 WC->cal_msgnum[WC->num_cal - 1] = msgnum;
318 * Display a task in the task list
320 void display_individual_task(icalcomponent *vtodo, long msgnum) {
323 p = icalcomponent_get_first_property(vtodo, ICAL_SUMMARY_PROPERTY);
324 wprintf("<LI><A HREF=\"/display_edit_task?msgnum=%ld\">", msgnum);
326 escputs((char *)icalproperty_get_comment(p));
333 * Display a task by itself (for editing)
335 void display_edit_individual_task(icalcomponent *supplied_vtodo, long msgnum) {
336 icalcomponent *vtodo;
338 struct icaltimetype t;
340 int created_new_vtodo = 0;
344 if (supplied_vtodo != NULL) {
345 vtodo = supplied_vtodo;
348 vtodo = icalcomponent_new(ICAL_VTODO_COMPONENT);
349 created_new_vtodo = 1;
353 wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=007700><TR><TD>"
354 "<FONT SIZE=+1 COLOR=\"FFFFFF\""
356 "</FONT></TD></TR></TABLE><BR>\n"
359 wprintf("<FORM METHOD=\"POST\" ACTION=\"/save_task\">\n");
360 wprintf("<INPUT TYPE=\"hidden\" NAME=\"msgnum\" VALUE=\"%ld\">\n",
364 "<INPUT TYPE=\"text\" NAME=\"summary\" "
365 "MAXLENGTH=\"64\" SIZE=\"64\" VALUE=\"");
366 p = icalcomponent_get_first_property(vtodo, ICAL_SUMMARY_PROPERTY);
368 escputs((char *)icalproperty_get_comment(p));
370 wprintf("\"><BR>\n");
372 wprintf("Start date: ");
373 p = icalcomponent_get_first_property(vtodo, ICAL_DTSTART_PROPERTY);
375 t = icalproperty_get_dtstart(p);
378 t = icaltime_from_timet(now, 0);
380 display_icaltimetype_as_webform(&t, "dtstart");
383 wprintf("Due date: ");
384 p = icalcomponent_get_first_property(vtodo, ICAL_DUE_PROPERTY);
386 t = icalproperty_get_due(p);
389 t = icaltime_from_timet(now, 0);
391 display_icaltimetype_as_webform(&t, "due");
394 wprintf("<CENTER><TEXTAREA NAME=\"description\" wrap=soft "
395 "ROWS=10 COLS=80 WIDTH=80>\n"
397 p = icalcomponent_get_first_property(vtodo, ICAL_DESCRIPTION_PROPERTY);
399 escputs((char *)icalproperty_get_comment(p));
401 wprintf("</TEXTAREA><BR>\n");
403 wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Save\">"
405 "<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Delete\">\n"
407 "<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">\n"
411 wprintf("</FORM>\n");
415 if (created_new_vtodo) {
416 icalcomponent_free(vtodo);
421 * Save an edited task
423 void save_individual_task(icalcomponent *supplied_vtodo, long msgnum) {
425 int delete_existing = 0;
427 icalcomponent *vtodo;
428 int created_new_vtodo = 0;
430 if (supplied_vtodo != NULL) {
431 vtodo = supplied_vtodo;
434 vtodo = icalcomponent_new(ICAL_VTODO_COMPONENT);
435 created_new_vtodo = 1;
438 if (!strcasecmp(bstr("sc"), "Save")) {
440 /* Replace values in the component with ones from the form */
442 while (prop = icalcomponent_get_first_property(vtodo,
443 ICAL_SUMMARY_PROPERTY), prop != NULL) {
444 icalcomponent_remove_property(vtodo, prop);
446 icalcomponent_add_property(vtodo,
447 icalproperty_new_summary(bstr("summary")));
449 while (prop = icalcomponent_get_first_property(vtodo,
450 ICAL_DESCRIPTION_PROPERTY), prop != NULL) {
451 icalcomponent_remove_property(vtodo, prop);
453 icalcomponent_add_property(vtodo,
454 icalproperty_new_description(bstr("description")));
456 while (prop = icalcomponent_get_first_property(vtodo,
457 ICAL_DTSTART_PROPERTY), prop != NULL) {
458 icalcomponent_remove_property(vtodo, prop);
460 icalcomponent_add_property(vtodo,
461 icalproperty_new_dtstart(
462 icaltime_from_webform("dtstart")
466 while (prop = icalcomponent_get_first_property(vtodo,
467 ICAL_DUE_PROPERTY), prop != NULL) {
468 icalcomponent_remove_property(vtodo, prop);
470 icalcomponent_add_property(vtodo,
471 icalproperty_new_due(
472 icaltime_from_webform("due")
476 /* Serialize it and save it to the message base */
477 serv_puts("ENT0 1|||4");
480 serv_puts("Content-type: text/calendar");
482 serv_puts(icalcomponent_as_ical_string(vtodo));
485 /* Probably not necessary; the server will see the UID
486 * of the object and delete the old one anyway, but
494 * If the user clicked 'Delete' then explicitly delete the message.
496 if (!strcasecmp(bstr("sc"), "Delete")) {
500 if ( (delete_existing) && (msgnum > 0L) ) {
501 serv_printf("DELE %ld", atol(bstr("msgnum")));
505 if (created_new_vtodo) {
506 icalcomponent_free(vtodo);
509 /* Go back to the task list */
516 * Code common to all display handlers. Given a message number and a MIME
517 * type, we load the message and hunt for that MIME type. If found, we load
518 * the relevant part, deserialize it into a libical component, filter it for
519 * the requested object type, and feed it to the specified handler.
521 void display_using_handler(long msgnum,
523 icalcomponent_kind which_kind,
524 void (*callback)(icalcomponent *, long)
527 char mime_partnum[SIZ];
528 char mime_filename[SIZ];
529 char mime_content_type[SIZ];
530 char mime_disposition[SIZ];
532 char relevant_partnum[SIZ];
533 char *relevant_source = NULL;
534 icalcomponent *cal, *c;
536 sprintf(buf, "MSG0 %ld|1", msgnum); /* ask for headers only */
539 if (buf[0] != '1') return;
541 while (serv_gets(buf), strcmp(buf, "000")) {
542 if (!strncasecmp(buf, "part=", 5)) {
543 extract(mime_filename, &buf[5], 1);
544 extract(mime_partnum, &buf[5], 2);
545 extract(mime_disposition, &buf[5], 3);
546 extract(mime_content_type, &buf[5], 4);
547 mime_length = extract_int(&buf[5], 5);
549 if (!strcasecmp(mime_content_type, "text/calendar")) {
550 strcpy(relevant_partnum, mime_partnum);
556 if (strlen(relevant_partnum) > 0) {
557 relevant_source = load_mimepart(msgnum, relevant_partnum);
558 if (relevant_source != NULL) {
560 cal = icalcomponent_new_from_string(relevant_source);
563 /* Simple components of desired type */
564 if (icalcomponent_isa(cal) == which_kind) {
565 callback(cal, msgnum);
568 /* Subcomponents of desired type */
569 for (c = icalcomponent_get_first_component(cal,
572 c = icalcomponent_get_next_component(cal,
576 icalcomponent_free(cal);
578 free(relevant_source);
584 void display_calendar(long msgnum) {
585 display_using_handler(msgnum, "text/calendar",
586 ICAL_VEVENT_COMPONENT,
587 display_individual_cal);
590 void display_task(long msgnum) {
591 display_using_handler(msgnum, "text/calendar",
592 ICAL_VTODO_COMPONENT,
593 display_individual_task);
596 void display_edit_task(void) {
599 msgnum = atol(bstr("msgnum"));
602 display_using_handler(msgnum, "text/calendar",
603 ICAL_VTODO_COMPONENT,
604 display_edit_individual_task);
608 display_edit_individual_task(NULL, 0L);
612 void save_task(void) {
615 msgnum = atol(bstr("msgnum"));
617 display_using_handler(msgnum, "text/calendar",
618 ICAL_VTODO_COMPONENT,
619 save_individual_task);
622 save_individual_task(NULL, 0L);
626 void display_edit_event(void) {
629 msgnum = atol(bstr("msgnum"));
632 display_using_handler(msgnum, "text/calendar",
633 ICAL_VEVENT_COMPONENT,
634 display_edit_individual_event);
638 display_edit_individual_event(NULL, 0L);
642 void save_event(void) {
645 msgnum = atol(bstr("msgnum"));
648 display_using_handler(msgnum, "text/calendar",
649 ICAL_VEVENT_COMPONENT,
650 save_individual_event);
653 save_individual_event(NULL, 0L);
657 #endif /* HAVE_ICAL_H */