]> code.citadel.org Git - citadel.git/blob - webcit/calendar.c
* Just a bunch of glue code to iterate through the various types of ical
[citadel.git] / webcit / calendar.c
1 /*
2  * $Id$
3  *
4  * Functions which handle calendar objects and their processing/display.
5  *
6  */
7
8 #include <ctype.h>
9 #include <stdlib.h>
10 #include <unistd.h>
11 #include <stdio.h>
12 #include <fcntl.h>
13 #include <signal.h>
14 #include <sys/types.h>
15 #include <sys/wait.h>
16 #include <sys/socket.h>
17 #include <limits.h>
18 #include <netinet/in.h>
19 #include <netdb.h>
20 #include <string.h>
21 #include <pwd.h>
22 #include <errno.h>
23 #include <stdarg.h>
24 #include <pthread.h>
25 #include <signal.h>
26 #include "webcit.h"
27 #include "webserver.h"
28
29 #ifdef HAVE_ICAL_H
30 #include <ical.h>
31 #endif
32
33
34 #ifndef HAVE_ICAL_H
35
36 /*
37  * Handler stub for builds with no calendar library available
38  */
39 void cal_process_attachment(char *part_source) {
40
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"
46         );
47
48 }
49
50 #else /* HAVE_ICAL_H */
51
52
53
54 /*
55  * Process a single calendar component.
56  * It won't be a compound component at this point because those have
57  * already been broken down by cal_process_object().
58  */
59 void cal_process_subcomponent(icalcomponent *cal) {
60         wprintf("cal_process_subcomponent() called<BR>\n");
61         wprintf("cal_process_subcomponent() exiting<BR>\n");
62 }
63
64
65
66
67
68 /*
69  * Process a calendar object
70  * ...at this point it's already been deserialized by cal_process_attachment()
71  */
72 void cal_process_object(icalcomponent *cal) {
73         icalcomponent *c;
74         int num_subcomponents = 0;
75
76         wprintf("cal_process_object() called<BR>\n");
77
78         /* Iterate through all subcomponents */
79         wprintf("Iterating through all sub-components<BR>\n");
80         for (c = icalcomponent_get_first_component(cal, ICAL_ANY_COMPONENT);
81             (c != 0);
82             c = icalcomponent_get_next_component(cal, ICAL_ANY_COMPONENT)) {
83                 cal_process_subcomponent(c);
84                 ++num_subcomponents;
85         }
86
87         /* Iterate through all subcomponents */
88         wprintf("Iterating through VEVENTs<BR>\n");
89         for (c = icalcomponent_get_first_component(cal, ICAL_VEVENT_COMPONENT);
90             (c != 0);
91             c = icalcomponent_get_next_component(cal, ICAL_VEVENT_COMPONENT)) {
92                 cal_process_subcomponent(c);
93                 --num_subcomponents;
94         }
95
96         /* Iterate through all subcomponents */
97         wprintf("Iterating through VTODOs<BR>\n");
98         for (c = icalcomponent_get_first_component(cal, ICAL_VTODO_COMPONENT);
99             (c != 0);
100             c = icalcomponent_get_next_component(cal, ICAL_VTODO_COMPONENT)) {
101                 cal_process_subcomponent(c);
102                 --num_subcomponents;
103         }
104
105         /* Iterate through all subcomponents */
106         wprintf("Iterating through VJOURNALs<BR>\n");
107         for (c = icalcomponent_get_first_component(cal, ICAL_VJOURNAL_COMPONENT);
108             (c != 0);
109             c = icalcomponent_get_next_component(cal, ICAL_VJOURNAL_COMPONENT)) {
110                 cal_process_subcomponent(c);
111                 --num_subcomponents;
112         }
113
114         /* Iterate through all subcomponents */
115         wprintf("Iterating through VCALENDARs<BR>\n");
116         for (c = icalcomponent_get_first_component(cal, ICAL_VCALENDAR_COMPONENT);
117             (c != 0);
118             c = icalcomponent_get_next_component(cal, ICAL_VCALENDAR_COMPONENT)) {
119                 cal_process_subcomponent(c);
120                 --num_subcomponents;
121         }
122
123         /* Iterate through all subcomponents */
124         wprintf("Iterating through VFREEBUSYs<BR>\n");
125         for (c = icalcomponent_get_first_component(cal, ICAL_VFREEBUSY_COMPONENT);
126             (c != 0);
127             c = icalcomponent_get_next_component(cal, ICAL_VFREEBUSY_COMPONENT)) {
128                 cal_process_subcomponent(c);
129                 --num_subcomponents;
130         }
131
132         /* Iterate through all subcomponents */
133         wprintf("Iterating through VALARMs<BR>\n");
134         for (c = icalcomponent_get_first_component(cal, ICAL_VALARM_COMPONENT);
135             (c != 0);
136             c = icalcomponent_get_next_component(cal, ICAL_VALARM_COMPONENT)) {
137                 cal_process_subcomponent(c);
138                 --num_subcomponents;
139         }
140
141         /* Iterate through all subcomponents */
142         wprintf("Iterating through VTIMEZONEs<BR>\n");
143         for (c = icalcomponent_get_first_component(cal, ICAL_VTIMEZONE_COMPONENT);
144             (c != 0);
145             c = icalcomponent_get_next_component(cal, ICAL_VTIMEZONE_COMPONENT)) {
146                 cal_process_subcomponent(c);
147                 --num_subcomponents;
148         }
149
150         /* Iterate through all subcomponents */
151         wprintf("Iterating through VSCHEDULEs<BR>\n");
152         for (c = icalcomponent_get_first_component(cal, ICAL_VSCHEDULE_COMPONENT);
153             (c != 0);
154             c = icalcomponent_get_next_component(cal, ICAL_VSCHEDULE_COMPONENT)) {
155                 cal_process_subcomponent(c);
156                 --num_subcomponents;
157         }
158
159         /* Iterate through all subcomponents */
160         wprintf("Iterating through VQUERYs<BR>\n");
161         for (c = icalcomponent_get_first_component(cal, ICAL_VQUERY_COMPONENT);
162             (c != 0);
163             c = icalcomponent_get_next_component(cal, ICAL_VQUERY_COMPONENT)) {
164                 cal_process_subcomponent(c);
165                 --num_subcomponents;
166         }
167
168         /* Iterate through all subcomponents */
169         wprintf("Iterating through VCARs<BR>\n");
170         for (c = icalcomponent_get_first_component(cal, ICAL_VCAR_COMPONENT);
171             (c != 0);
172             c = icalcomponent_get_next_component(cal, ICAL_VCAR_COMPONENT)) {
173                 cal_process_subcomponent(c);
174                 --num_subcomponents;
175         }
176
177         /* Iterate through all subcomponents */
178         wprintf("Iterating through VCOMMANDs<BR>\n");
179         for (c = icalcomponent_get_first_component(cal, ICAL_VCOMMAND_COMPONENT);
180             (c != 0);
181             c = icalcomponent_get_next_component(cal, ICAL_VCOMMAND_COMPONENT)) {
182                 cal_process_subcomponent(c);
183                 --num_subcomponents;
184         }
185
186         if (num_subcomponents != 0) {
187                 wprintf("Warning: %d subcomponents unhandled<BR>\n",
188                         num_subcomponents);
189         }
190
191         wprintf("cal_process_object() exiting<BR>\n");
192 }
193
194
195 /*
196  * Deserialize a calendar object in a message so it can be processed.
197  * (This is the main entry point for these things)
198  */
199 void cal_process_attachment(char *part_source) {
200         icalcomponent *cal;
201
202         wprintf("Processing calendar attachment<BR>\n");
203         cal = icalcomponent_new_from_string(part_source);
204
205         if (cal == NULL) {
206                 wprintf("Error parsing calendar object: %s<BR>\n",
207                         icalerror_strerror(icalerrno));
208                 return;
209         }
210
211         cal_process_object(cal);
212
213         /* Free the memory we obtained from libical's constructor */
214         icalcomponent_free(cal);
215 }
216
217 #endif /* HAVE_ICAL_H */