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>
27 #include "webserver.h"
37 * Handler stubs for builds with no calendar library available
39 void cal_process_attachment(char *part_source) {
41 wprintf("<I>This message contains calendaring/scheduling information,"
42 " but support for calendars is not available on this "
43 "particular system. Please ask your system administrator to "
44 "install a new version of the Citadel web service with "
45 "calendaring enabled.</I><BR>\n"
50 void display_calendar(long msgnum) {
51 wprintf("<i>Cannot display calendar item</i><br>\n");
54 void display_task(long msgnum) {
55 wprintf("<i>Cannot display item from task list</i><br>\n");
58 #else /* HAVE_ICAL_H */
61 /****** End of handler stubs. Everything below this line is real. ******/
65 * Process a single calendar component.
66 * It won't be a compound component at this point because those have
67 * already been broken down by cal_process_object().
69 void cal_process_subcomponent(icalcomponent *cal) {
70 wprintf("cal_process_subcomponent() called<BR>\n");
71 wprintf("cal_process_subcomponent() exiting<BR>\n");
79 * Process a calendar object
80 * ...at this point it's already been deserialized by cal_process_attachment()
82 void cal_process_object(icalcomponent *cal) {
84 int num_subcomponents = 0;
86 wprintf("cal_process_object() called<BR>\n");
88 /* Iterate through all subcomponents */
89 wprintf("Iterating through all sub-components<BR>\n");
90 for (c = icalcomponent_get_first_component(cal, ICAL_ANY_COMPONENT);
92 c = icalcomponent_get_next_component(cal, ICAL_ANY_COMPONENT)) {
93 cal_process_subcomponent(c);
97 /* Iterate through all subcomponents */
98 wprintf("Iterating through VEVENTs<BR>\n");
99 for (c = icalcomponent_get_first_component(cal, ICAL_VEVENT_COMPONENT);
101 c = icalcomponent_get_next_component(cal, ICAL_VEVENT_COMPONENT)) {
102 cal_process_subcomponent(c);
106 /* Iterate through all subcomponents */
107 wprintf("Iterating through VTODOs<BR>\n");
108 for (c = icalcomponent_get_first_component(cal, ICAL_VTODO_COMPONENT);
110 c = icalcomponent_get_next_component(cal, ICAL_VTODO_COMPONENT)) {
111 cal_process_subcomponent(c);
115 /* Iterate through all subcomponents */
116 wprintf("Iterating through VJOURNALs<BR>\n");
117 for (c = icalcomponent_get_first_component(cal, ICAL_VJOURNAL_COMPONENT);
119 c = icalcomponent_get_next_component(cal, ICAL_VJOURNAL_COMPONENT)) {
120 cal_process_subcomponent(c);
124 /* Iterate through all subcomponents */
125 wprintf("Iterating through VCALENDARs<BR>\n");
126 for (c = icalcomponent_get_first_component(cal, ICAL_VCALENDAR_COMPONENT);
128 c = icalcomponent_get_next_component(cal, ICAL_VCALENDAR_COMPONENT)) {
129 cal_process_subcomponent(c);
133 /* Iterate through all subcomponents */
134 wprintf("Iterating through VFREEBUSYs<BR>\n");
135 for (c = icalcomponent_get_first_component(cal, ICAL_VFREEBUSY_COMPONENT);
137 c = icalcomponent_get_next_component(cal, ICAL_VFREEBUSY_COMPONENT)) {
138 cal_process_subcomponent(c);
142 /* Iterate through all subcomponents */
143 wprintf("Iterating through VALARMs<BR>\n");
144 for (c = icalcomponent_get_first_component(cal, ICAL_VALARM_COMPONENT);
146 c = icalcomponent_get_next_component(cal, ICAL_VALARM_COMPONENT)) {
147 cal_process_subcomponent(c);
151 /* Iterate through all subcomponents */
152 wprintf("Iterating through VTIMEZONEs<BR>\n");
153 for (c = icalcomponent_get_first_component(cal, ICAL_VTIMEZONE_COMPONENT);
155 c = icalcomponent_get_next_component(cal, ICAL_VTIMEZONE_COMPONENT)) {
156 cal_process_subcomponent(c);
160 /* Iterate through all subcomponents */
161 wprintf("Iterating through VSCHEDULEs<BR>\n");
162 for (c = icalcomponent_get_first_component(cal, ICAL_VSCHEDULE_COMPONENT);
164 c = icalcomponent_get_next_component(cal, ICAL_VSCHEDULE_COMPONENT)) {
165 cal_process_subcomponent(c);
169 /* Iterate through all subcomponents */
170 wprintf("Iterating through VQUERYs<BR>\n");
171 for (c = icalcomponent_get_first_component(cal, ICAL_VQUERY_COMPONENT);
173 c = icalcomponent_get_next_component(cal, ICAL_VQUERY_COMPONENT)) {
174 cal_process_subcomponent(c);
178 /* Iterate through all subcomponents */
179 wprintf("Iterating through VCARs<BR>\n");
180 for (c = icalcomponent_get_first_component(cal, ICAL_VCAR_COMPONENT);
182 c = icalcomponent_get_next_component(cal, ICAL_VCAR_COMPONENT)) {
183 cal_process_subcomponent(c);
187 /* Iterate through all subcomponents */
188 wprintf("Iterating through VCOMMANDs<BR>\n");
189 for (c = icalcomponent_get_first_component(cal, ICAL_VCOMMAND_COMPONENT);
191 c = icalcomponent_get_next_component(cal, ICAL_VCOMMAND_COMPONENT)) {
192 cal_process_subcomponent(c);
196 if (num_subcomponents != 0) {
197 wprintf("Warning: %d subcomponents unhandled<BR>\n",
201 wprintf("cal_process_object() exiting<BR>\n");
206 * Deserialize a calendar object in a message so it can be processed.
207 * (This is the main entry point for these things)
209 void cal_process_attachment(char *part_source) {
212 wprintf("Processing calendar attachment<BR>\n");
213 cal = icalcomponent_new_from_string(part_source);
216 wprintf("Error parsing calendar object: %s<BR>\n",
217 icalerror_strerror(icalerrno));
221 cal_process_object(cal);
223 /* Free the memory we obtained from libical's constructor */
224 icalcomponent_free(cal);
227 /*****************************************************************************/
234 * Display handlers for message reading
236 void display_individual_cal(icalcomponent *cal, long msgnum) {
237 wprintf("display_individual_cal() called<BR>\n");
243 * Display a task in the task list
245 void display_individual_task(icalcomponent *vtodo, long msgnum) {
248 p = icalcomponent_get_first_property(vtodo, ICAL_SUMMARY_PROPERTY);
249 wprintf("<LI><A HREF=\"/display_edit_task?msgnum=%ld\">", msgnum);
250 if (p != NULL) escputs((char *)icalproperty_get_comment(p));
252 icalproperty_free(p);
257 * Display a task by itself (for editing)
259 void display_edit_individual_task(icalcomponent *vtodo, long msgnum) {
263 wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=007700><TR><TD>"
264 "<FONT SIZE=+1 COLOR=\"FFFFFF\""
266 "</FONT></TD></TR></TABLE><BR>\n"
269 wprintf("<FORM METHOD=\"POST\" ACTION=\"/save_task\">\n");
270 wprintf("<INPUT TYPE=\"hidden\" NAME=\"msgnum\" VALUE=\"%ld\">\n",
274 "<INPUT TYPE=\"text\" NAME=\"summary\" "
275 "MAXLENGTH=\"64\" SIZE=\"64\" VALUE=\"");
276 p = icalcomponent_get_first_property(vtodo, ICAL_SUMMARY_PROPERTY);
277 if (p != NULL) escputs((char *)icalproperty_get_comment(p));
278 icalproperty_free(p);
279 wprintf("\"><BR>\n");
281 wprintf("Start date: FIXME <BR>\n");
283 wprintf("Due date: FIXME <BR>\n");
285 wprintf("<CENTER><TEXTAREA NAME=\"msgtext\" wrap=soft "
286 "ROWS=10 COLS=80 WIDTH=80>\n"
288 p = icalcomponent_get_first_property(vtodo, ICAL_DESCRIPTION_PROPERTY);
289 if (p != NULL) escputs((char *)icalproperty_get_comment(p));
290 icalproperty_free(p);
291 wprintf("</TEXTAREA><BR>\n");
293 wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Save\">"
295 "<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Delete\">\n"
297 "<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">\n"
301 wprintf("</FORM>\n");
307 * Save an edited task
309 void save_individual_task(icalcomponent *vtodo, long msgnum) {
311 int delete_existing = 0;
313 if (!strcasecmp(bstr("sc"), "Save")) {
315 /* Replace values in the component with ones from the form */
316 /* FIXME ... do this */
318 /* Serialize it and save it to the message base */
319 serv_puts("ENT0 1|||4");
322 serv_puts("Content-type: text/calendar");
324 serv_puts(icalcomponent_as_ical_string(vtodo));
326 /* delete_existing = 1; */
331 * If the user clicked 'Delete' then delete it, period.
333 if (!strcasecmp(bstr("sc"), "Delete")) {
337 if (delete_existing) {
338 serv_printf("DELE %ld", atol(bstr("msgnum")));
342 /* Go back to the task list */
349 * Code common to all display handlers. Given a message number and a MIME
350 * type, we load the message and hunt for that MIME type. If found, we load
351 * the relevant part, deserialize it into a libical component, filter it for
352 * the requested object type, and feed it to the specified handler.
354 void display_using_handler(long msgnum,
356 icalcomponent_kind which_kind,
357 void (*callback)(icalcomponent *, long)
360 char mime_partnum[SIZ];
361 char mime_filename[SIZ];
362 char mime_content_type[SIZ];
363 char mime_disposition[SIZ];
365 char relevant_partnum[SIZ];
366 char *relevant_source = NULL;
367 icalcomponent *cal, *c;
369 sprintf(buf, "MSG0 %ld|1", msgnum); /* ask for headers only */
372 if (buf[0] != '1') return;
374 while (serv_gets(buf), strcmp(buf, "000")) {
375 if (!strncasecmp(buf, "part=", 5)) {
376 extract(mime_filename, &buf[5], 1);
377 extract(mime_partnum, &buf[5], 2);
378 extract(mime_disposition, &buf[5], 3);
379 extract(mime_content_type, &buf[5], 4);
380 mime_length = extract_int(&buf[5], 5);
382 if (!strcasecmp(mime_content_type, "text/calendar")) {
383 strcpy(relevant_partnum, mime_partnum);
389 if (strlen(relevant_partnum) > 0) {
390 relevant_source = load_mimepart(msgnum, relevant_partnum);
391 if (relevant_source != NULL) {
393 /* Display the task */
394 cal = icalcomponent_new_from_string(relevant_source);
396 for (c = icalcomponent_get_first_component(cal,
399 c = icalcomponent_get_next_component(cal,
403 icalcomponent_free(cal);
405 free(relevant_source);
411 void display_calendar(long msgnum) {
412 display_using_handler(msgnum, "text/calendar",
414 display_individual_cal);
417 void display_task(long msgnum) {
418 display_using_handler(msgnum, "text/calendar",
419 ICAL_VTODO_COMPONENT,
420 display_individual_task);
423 void display_edit_task(void) {
426 msgnum = atol(bstr("msgnum"));
427 display_using_handler(msgnum, "text/calendar",
428 ICAL_VTODO_COMPONENT,
429 display_edit_individual_task);
432 void save_task(void) {
435 msgnum = atol(bstr("msgnum"));
436 display_using_handler(msgnum, "text/calendar",
437 ICAL_VTODO_COMPONENT,
438 save_individual_task);
441 #endif /* HAVE_ICAL_H */