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) {
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,
78 icalproperty *method = NULL;
79 icalproperty_method the_method;
81 struct icaltimetype t;
84 /* Look for a method */
85 method = icalcomponent_get_first_property(cal, ICAL_METHOD_PROPERTY);
87 /* See what we need to do with this */
89 the_method = icalproperty_get_method(method);
91 case ICAL_METHOD_REQUEST:
92 wprintf("<CENTER><IMG ALIGN=CENTER "
93 "SRC=\"/static/vcalendar.gif\">"
95 "<B>Meeting invitation</B></CENTER><BR>\n"
99 wprintf("I don't know what to do with this.<BR>\n");
104 p = icalcomponent_get_first_property(cal, ICAL_SUMMARY_PROPERTY);
106 wprintf("<B>Summary:</B> ");
107 escputs((char *)icalproperty_get_comment(p));
111 p = icalcomponent_get_first_property(cal, ICAL_LOCATION_PROPERTY);
113 wprintf("<B>Location:</B> ");
114 escputs((char *)icalproperty_get_comment(p));
118 p = icalcomponent_get_first_property(cal, ICAL_DTSTART_PROPERTY);
120 t = icalproperty_get_dtstart(p);
121 tt = icaltime_as_timet(t);
122 wprintf("<B>Starting date/time:</B> %s<BR>",
123 asctime(localtime(&tt))
127 p = icalcomponent_get_first_property(cal, ICAL_DTEND_PROPERTY);
129 t = icalproperty_get_dtstart(p);
130 tt = icaltime_as_timet(t);
131 wprintf("<B>Ending date/time:</B> %s<BR>",
132 asctime(localtime(&tt))
136 p = icalcomponent_get_first_property(cal, ICAL_DESCRIPTION_PROPERTY);
138 wprintf("<B>Description:</B> ");
139 escputs((char *)icalproperty_get_comment(p));
143 /* If the component has subcomponents, recurse through them. */
144 for (c = icalcomponent_get_first_component(cal, ICAL_ANY_COMPONENT);
146 c = icalcomponent_get_next_component(cal, ICAL_ANY_COMPONENT)) {
147 /* Recursively process subcomponent */
148 cal_process_object(c, recursion_level+1);
151 if (recursion_level == 0) {
152 wprintf("<CENTER><FORM METHOD=\"GET\" "
153 "ACTION=\"/respond_to_request\">\n"
154 "<INPUT TYPE=\"submit\" NAME=\"sc\" "
157 "<INPUT TYPE=\"submit\" NAME=\"sc\" "
166 * Deserialize a calendar object in a message so it can be processed.
167 * (This is the main entry point for these things)
169 void cal_process_attachment(char *part_source) {
172 cal = icalcomponent_new_from_string(part_source);
175 wprintf("Error parsing calendar object: %s<BR>\n",
176 icalerror_strerror(icalerrno));
180 cal_process_object(cal, 0);
182 /* Free the memory we obtained from libical's constructor */
183 icalcomponent_free(cal);
186 /*****************************************************************************/
191 * Display handlers for message reading
197 * If we're reading calendar items, just store them for now. We have to
198 * sort and re-output them later when we draw the calendar.
200 void display_individual_cal(icalcomponent *cal, long msgnum) {
204 WC->disp_cal = realloc(WC->disp_cal,
205 (sizeof(icalcomponent *) * WC->num_cal) );
206 WC->disp_cal[WC->num_cal - 1] = icalcomponent_new_clone(cal);
208 WC->cal_msgnum = realloc(WC->cal_msgnum,
209 (sizeof(long) * WC->num_cal) );
210 WC->cal_msgnum[WC->num_cal - 1] = msgnum;
216 * Display a task in the task list
218 void display_individual_task(icalcomponent *vtodo, long msgnum) {
221 p = icalcomponent_get_first_property(vtodo, ICAL_SUMMARY_PROPERTY);
222 wprintf("<LI><A HREF=\"/display_edit_task?msgnum=%ld\">", msgnum);
224 escputs((char *)icalproperty_get_comment(p));
231 * Display a task by itself (for editing)
233 void display_edit_individual_task(icalcomponent *supplied_vtodo, long msgnum) {
234 icalcomponent *vtodo;
236 struct icaltimetype t;
238 int created_new_vtodo = 0;
242 if (supplied_vtodo != NULL) {
243 vtodo = supplied_vtodo;
246 vtodo = icalcomponent_new(ICAL_VTODO_COMPONENT);
247 created_new_vtodo = 1;
251 wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=007700><TR><TD>"
252 "<FONT SIZE=+1 COLOR=\"FFFFFF\""
254 "</FONT></TD></TR></TABLE><BR>\n"
257 wprintf("<FORM METHOD=\"POST\" ACTION=\"/save_task\">\n");
258 wprintf("<INPUT TYPE=\"hidden\" NAME=\"msgnum\" VALUE=\"%ld\">\n",
262 "<INPUT TYPE=\"text\" NAME=\"summary\" "
263 "MAXLENGTH=\"64\" SIZE=\"64\" VALUE=\"");
264 p = icalcomponent_get_first_property(vtodo, ICAL_SUMMARY_PROPERTY);
266 escputs((char *)icalproperty_get_comment(p));
268 wprintf("\"><BR>\n");
270 wprintf("Start date: ");
271 p = icalcomponent_get_first_property(vtodo, ICAL_DTSTART_PROPERTY);
273 t = icalproperty_get_dtstart(p);
276 t = icaltime_from_timet(now, 0);
278 display_icaltimetype_as_webform(&t, "dtstart");
281 wprintf("Due date: ");
282 p = icalcomponent_get_first_property(vtodo, ICAL_DUE_PROPERTY);
284 t = icalproperty_get_due(p);
287 t = icaltime_from_timet(now, 0);
289 display_icaltimetype_as_webform(&t, "due");
292 wprintf("<CENTER><TEXTAREA NAME=\"description\" wrap=soft "
293 "ROWS=10 COLS=80 WIDTH=80>\n"
295 p = icalcomponent_get_first_property(vtodo, ICAL_DESCRIPTION_PROPERTY);
297 escputs((char *)icalproperty_get_comment(p));
299 wprintf("</TEXTAREA><BR>\n");
301 wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Save\">"
303 "<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Delete\">\n"
305 "<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">\n"
309 wprintf("</FORM>\n");
313 if (created_new_vtodo) {
314 icalcomponent_free(vtodo);
319 * Save an edited task
321 void save_individual_task(icalcomponent *supplied_vtodo, long msgnum) {
323 int delete_existing = 0;
325 icalcomponent *vtodo;
326 int created_new_vtodo = 0;
328 if (supplied_vtodo != NULL) {
329 vtodo = supplied_vtodo;
332 vtodo = icalcomponent_new(ICAL_VTODO_COMPONENT);
333 created_new_vtodo = 1;
336 if (!strcasecmp(bstr("sc"), "Save")) {
338 /* Replace values in the component with ones from the form */
340 while (prop = icalcomponent_get_first_property(vtodo,
341 ICAL_SUMMARY_PROPERTY), prop != NULL) {
342 icalcomponent_remove_property(vtodo, prop);
344 icalcomponent_add_property(vtodo,
345 icalproperty_new_summary(bstr("summary")));
347 while (prop = icalcomponent_get_first_property(vtodo,
348 ICAL_DESCRIPTION_PROPERTY), prop != NULL) {
349 icalcomponent_remove_property(vtodo, prop);
351 icalcomponent_add_property(vtodo,
352 icalproperty_new_description(bstr("description")));
354 while (prop = icalcomponent_get_first_property(vtodo,
355 ICAL_DTSTART_PROPERTY), prop != NULL) {
356 icalcomponent_remove_property(vtodo, prop);
358 icalcomponent_add_property(vtodo,
359 icalproperty_new_dtstart(
360 icaltime_from_webform("dtstart")
364 while (prop = icalcomponent_get_first_property(vtodo,
365 ICAL_DUE_PROPERTY), prop != NULL) {
366 icalcomponent_remove_property(vtodo, prop);
368 icalcomponent_add_property(vtodo,
369 icalproperty_new_due(
370 icaltime_from_webform("due")
374 /* Serialize it and save it to the message base */
375 serv_puts("ENT0 1|||4");
378 serv_puts("Content-type: text/calendar");
380 serv_puts(icalcomponent_as_ical_string(vtodo));
387 * If the user clicked 'Delete' then delete it, period.
389 if (!strcasecmp(bstr("sc"), "Delete")) {
393 if ( (delete_existing) && (msgnum > 0L) ) {
394 serv_printf("DELE %ld", atol(bstr("msgnum")));
398 if (created_new_vtodo) {
399 icalcomponent_free(vtodo);
402 /* Go back to the task list */
409 * Code common to all display handlers. Given a message number and a MIME
410 * type, we load the message and hunt for that MIME type. If found, we load
411 * the relevant part, deserialize it into a libical component, filter it for
412 * the requested object type, and feed it to the specified handler.
414 void display_using_handler(long msgnum,
416 icalcomponent_kind which_kind,
417 void (*callback)(icalcomponent *, long)
420 char mime_partnum[SIZ];
421 char mime_filename[SIZ];
422 char mime_content_type[SIZ];
423 char mime_disposition[SIZ];
425 char relevant_partnum[SIZ];
426 char *relevant_source = NULL;
427 icalcomponent *cal, *c;
429 sprintf(buf, "MSG0 %ld|1", msgnum); /* ask for headers only */
432 if (buf[0] != '1') return;
434 while (serv_gets(buf), strcmp(buf, "000")) {
435 if (!strncasecmp(buf, "part=", 5)) {
436 extract(mime_filename, &buf[5], 1);
437 extract(mime_partnum, &buf[5], 2);
438 extract(mime_disposition, &buf[5], 3);
439 extract(mime_content_type, &buf[5], 4);
440 mime_length = extract_int(&buf[5], 5);
442 if (!strcasecmp(mime_content_type, "text/calendar")) {
443 strcpy(relevant_partnum, mime_partnum);
449 if (strlen(relevant_partnum) > 0) {
450 relevant_source = load_mimepart(msgnum, relevant_partnum);
451 if (relevant_source != NULL) {
453 cal = icalcomponent_new_from_string(relevant_source);
456 /* Simple components of desired type */
457 if (icalcomponent_isa(cal) == which_kind) {
458 callback(cal, msgnum);
461 /* Subcomponents of desired type */
462 for (c = icalcomponent_get_first_component(cal,
465 c = icalcomponent_get_next_component(cal,
469 icalcomponent_free(cal);
471 free(relevant_source);
477 void display_calendar(long msgnum) {
478 display_using_handler(msgnum, "text/calendar",
479 ICAL_VEVENT_COMPONENT,
480 display_individual_cal);
483 void display_task(long msgnum) {
484 display_using_handler(msgnum, "text/calendar",
485 ICAL_VTODO_COMPONENT,
486 display_individual_task);
489 void display_edit_task(void) {
492 msgnum = atol(bstr("msgnum"));
495 display_using_handler(msgnum, "text/calendar",
496 ICAL_VTODO_COMPONENT,
497 display_edit_individual_task);
501 display_edit_individual_task(NULL, 0L);
505 void save_task(void) {
508 msgnum = atol(bstr("msgnum"));
510 display_using_handler(msgnum, "text/calendar",
511 ICAL_VTODO_COMPONENT,
512 save_individual_task);
515 save_individual_task(NULL, 0L);
519 void display_edit_event(void) {
522 msgnum = atol(bstr("msgnum"));
525 display_using_handler(msgnum, "text/calendar",
526 ICAL_VEVENT_COMPONENT,
527 display_edit_individual_event);
531 display_edit_individual_event(NULL, 0L);
535 void save_event(void) {
538 msgnum = atol(bstr("msgnum"));
541 display_using_handler(msgnum, "text/calendar",
542 ICAL_VEVENT_COMPONENT,
543 save_individual_event);
546 save_individual_event(NULL, 0L);
550 #endif /* HAVE_ICAL_H */