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 edit_individual_task(icalcomponent *vtodo, long msgnum) {
312 if (!strcasecmp(bstr("sc"), "Save")) {
315 1. Replace property values with ones from the form
316 2. Serialize the task
317 3. Make a message out of it
318 4. Delete the existing message (msgnum)
319 5. Save the new message
324 if ( (!strcasecmp(bstr("sc"), "Save"))
325 || (!strcasecmp(bstr("sc"), "Delete")) ) {
326 serv_printf("DELE %ld", atol(bstr("msgnum")));
330 /* Go back to the task list */
337 * Code common to all display handlers. Given a message number and a MIME
338 * type, we load the message and hunt for that MIME type. If found, we load
339 * the relevant part, deserialize it into a libical component, filter it for
340 * the requested object type, and feed it to the specified handler.
342 void display_using_handler(long msgnum,
344 icalcomponent_kind which_kind,
345 void (*callback)(icalcomponent *, long)
348 char mime_partnum[SIZ];
349 char mime_filename[SIZ];
350 char mime_content_type[SIZ];
351 char mime_disposition[SIZ];
353 char relevant_partnum[SIZ];
354 char *relevant_source = NULL;
355 icalcomponent *cal, *c;
357 sprintf(buf, "MSG0 %ld|1", msgnum); /* ask for headers only */
360 if (buf[0] != '1') return;
362 while (serv_gets(buf), strcmp(buf, "000")) {
363 if (!strncasecmp(buf, "part=", 5)) {
364 extract(mime_filename, &buf[5], 1);
365 extract(mime_partnum, &buf[5], 2);
366 extract(mime_disposition, &buf[5], 3);
367 extract(mime_content_type, &buf[5], 4);
368 mime_length = extract_int(&buf[5], 5);
370 if (!strcasecmp(mime_content_type, "text/calendar")) {
371 strcpy(relevant_partnum, mime_partnum);
377 if (strlen(relevant_partnum) > 0) {
378 relevant_source = load_mimepart(msgnum, relevant_partnum);
379 if (relevant_source != NULL) {
381 /* Display the task */
382 cal = icalcomponent_new_from_string(relevant_source);
384 for (c = icalcomponent_get_first_component(cal,
387 c = icalcomponent_get_next_component(cal,
391 icalcomponent_free(cal);
393 free(relevant_source);
399 void display_calendar(long msgnum) {
400 display_using_handler(msgnum, "text/calendar",
402 display_individual_cal);
405 void display_task(long msgnum) {
406 display_using_handler(msgnum, "text/calendar",
407 ICAL_VTODO_COMPONENT,
408 display_individual_task);
411 void display_edit_task(void) {
414 msgnum = atol(bstr("msgnum"));
415 display_using_handler(msgnum, "text/calendar",
416 ICAL_VTODO_COMPONENT,
417 display_edit_individual_task);
420 void save_task(void) {
423 msgnum = atol(bstr("msgnum"));
424 display_using_handler(msgnum, "text/calendar",
425 ICAL_VTODO_COMPONENT,
426 edit_individual_task);
429 #endif /* HAVE_ICAL_H */