Diffstat (limited to 'libical/src/libicalss/icalmessage.c') (more/less context) (show whitespace changes)
-rw-r--r-- | libical/src/libicalss/icalmessage.c | 373 |
1 files changed, 373 insertions, 0 deletions
diff --git a/libical/src/libicalss/icalmessage.c b/libical/src/libicalss/icalmessage.c new file mode 100644 index 0000000..d5c57c1 --- a/dev/null +++ b/libical/src/libicalss/icalmessage.c | |||
@@ -0,0 +1,373 @@ | |||
1 | /* -*- Mode: C -*- | ||
2 | ====================================================================== | ||
3 | FILE: icalmessage.c | ||
4 | CREATOR: ebusboom 07 Nov 2000 | ||
5 | |||
6 | $Id$ | ||
7 | $Locker$ | ||
8 | |||
9 | (C) COPYRIGHT 2000, Eric Busboom, http://www.softwarestudio.org | ||
10 | |||
11 | This program is free software; you can redistribute it and/or modify | ||
12 | it under the terms of either: | ||
13 | |||
14 | The LGPL as published by the Free Software Foundation, version | ||
15 | 2.1, available at: http://www.fsf.org/copyleft/lesser.html | ||
16 | |||
17 | Or: | ||
18 | |||
19 | The Mozilla Public License Version 1.0. You may obtain a copy of | ||
20 | the License at http://www.mozilla.org/MPL/ | ||
21 | |||
22 | |||
23 | ======================================================================*/ | ||
24 | |||
25 | #ifdef HAVE_CONFIG_H | ||
26 | #include "config.h" | ||
27 | #endif | ||
28 | |||
29 | #include "icalmessage.h" | ||
30 | #include "icalenums.h" | ||
31 | #include <ctype.h> /* for tolower()*/ | ||
32 | #include <string.h> /* for strstr */ | ||
33 | #include <stdlib.h> /* for free(), malloc() */ | ||
34 | icalcomponent* icalmessage_get_inner(icalcomponent* comp) | ||
35 | { | ||
36 | if (icalcomponent_isa(comp) == ICAL_VCALENDAR_COMPONENT){ | ||
37 | return icalcomponent_get_first_real_component(comp); | ||
38 | } else { | ||
39 | return comp; | ||
40 | } | ||
41 | } | ||
42 | |||
43 | char* lowercase(const char* str) | ||
44 | { | ||
45 | char* p = 0; | ||
46 | char* n = icalmemory_strdup(str); | ||
47 | |||
48 | if(str ==0){ | ||
49 | return 0; | ||
50 | } | ||
51 | |||
52 | for(p = n; *p!=0; p++){ | ||
53 | *p = tolower(*p); | ||
54 | } | ||
55 | |||
56 | return n; | ||
57 | } | ||
58 | |||
59 | icalproperty* icalmessage_find_attendee(icalcomponent* comp, const char* user) | ||
60 | { | ||
61 | icalcomponent *inner = icalmessage_get_inner(comp); | ||
62 | icalproperty *p,*attendee = 0; | ||
63 | char* luser = lowercase(user); | ||
64 | |||
65 | for(p = icalcomponent_get_first_property(inner, ICAL_ATTENDEE_PROPERTY); | ||
66 | p != 0; | ||
67 | p = icalcomponent_get_next_property(inner, ICAL_ATTENDEE_PROPERTY) | ||
68 | ){ | ||
69 | |||
70 | char* lattendee; | ||
71 | |||
72 | lattendee = lowercase(icalproperty_get_attendee(p)); | ||
73 | |||
74 | if (strstr(lattendee,user) != 0){ | ||
75 | attendee = p; | ||
76 | break; | ||
77 | } | ||
78 | |||
79 | free(lattendee); | ||
80 | |||
81 | } | ||
82 | |||
83 | free(luser); | ||
84 | |||
85 | return attendee; | ||
86 | |||
87 | } | ||
88 | |||
89 | void icalmessage_copy_properties(icalcomponent* to, icalcomponent* from, | ||
90 | icalproperty_kind kind) | ||
91 | { | ||
92 | icalcomponent *to_inner = icalmessage_get_inner(to); | ||
93 | icalcomponent *from_inner = icalmessage_get_inner(from); | ||
94 | |||
95 | if (to_inner == 0 && from_inner == 0){ | ||
96 | icalerror_set_errno(ICAL_MALFORMEDDATA_ERROR); | ||
97 | return; | ||
98 | } | ||
99 | |||
100 | if(!icalcomponent_get_first_property(from_inner,kind)){ | ||
101 | return; | ||
102 | } | ||
103 | |||
104 | icalcomponent_add_property(to_inner, | ||
105 | icalproperty_new_clone( | ||
106 | icalcomponent_get_first_property( | ||
107 | from_inner, | ||
108 | kind) | ||
109 | ) | ||
110 | ); | ||
111 | } | ||
112 | |||
113 | icalcomponent *icalmessage_new_reply_base(icalcomponent* c, | ||
114 | const char* user, | ||
115 | const char* msg) | ||
116 | { | ||
117 | icalproperty *attendee; | ||
118 | char tmp[45]; | ||
119 | |||
120 | icalcomponent *reply = icalcomponent_vanew( | ||
121 | ICAL_VCALENDAR_COMPONENT, | ||
122 | icalproperty_new_method(ICAL_METHOD_REPLY), | ||
123 | icalcomponent_vanew( | ||
124 | ICAL_VEVENT_COMPONENT, | ||
125 | icalproperty_new_dtstamp(icaltime_from_timet(time(0),0)), | ||
126 | 0), | ||
127 | 0); | ||
128 | |||
129 | icalcomponent *inner = icalmessage_get_inner(reply); | ||
130 | |||
131 | icalerror_check_arg_rz(c,"c"); | ||
132 | |||
133 | icalmessage_copy_properties(reply,c,ICAL_UID_PROPERTY); | ||
134 | icalmessage_copy_properties(reply,c,ICAL_ORGANIZER_PROPERTY); | ||
135 | icalmessage_copy_properties(reply,c,ICAL_RECURRENCEID_PROPERTY); | ||
136 | icalmessage_copy_properties(reply,c,ICAL_SUMMARY_PROPERTY); | ||
137 | icalmessage_copy_properties(reply,c,ICAL_SEQUENCE_PROPERTY); | ||
138 | |||
139 | icalcomponent_set_dtstamp(reply,icaltime_from_timet(time(0),0)); | ||
140 | |||
141 | if(msg != 0){ | ||
142 | icalcomponent_add_property(inner,icalproperty_new_comment(msg)); | ||
143 | } | ||
144 | |||
145 | /* Copy this user's attendee property */ | ||
146 | |||
147 | attendee = icalmessage_find_attendee(c,user); | ||
148 | |||
149 | if (attendee == 0){ | ||
150 | icalerror_set_errno(ICAL_MALFORMEDDATA_ERROR); | ||
151 | icalcomponent_free(reply); | ||
152 | return 0; | ||
153 | } | ||
154 | |||
155 | icalcomponent_add_property(inner,icalproperty_new_clone(attendee)); | ||
156 | |||
157 | /* Add PRODID and VERSION */ | ||
158 | |||
159 | icalcomponent_add_property(reply,icalproperty_new_version("2.0")); | ||
160 | |||
161 | sprintf(tmp, | ||
162 | "-//SoftwareStudio//NONSGML %s %s //EN",PACKAGE,VERSION); | ||
163 | icalcomponent_add_property(reply,icalproperty_new_prodid(tmp)); | ||
164 | |||
165 | return reply; | ||
166 | |||
167 | } | ||
168 | |||
169 | icalcomponent* icalmessage_new_accept_reply(icalcomponent* c, | ||
170 | const char* user, | ||
171 | const char* msg) | ||
172 | { | ||
173 | |||
174 | icalcomponent *reply; | ||
175 | icalproperty *attendee; | ||
176 | icalcomponent *inner; | ||
177 | |||
178 | icalerror_check_arg_rz(c,"c"); | ||
179 | |||
180 | reply = icalmessage_new_reply_base(c,user,msg); | ||
181 | |||
182 | if(reply == 0){ | ||
183 | return 0; | ||
184 | } | ||
185 | |||
186 | inner = icalmessage_get_inner(reply); | ||
187 | |||
188 | attendee = icalcomponent_get_first_property(inner, | ||
189 | ICAL_ATTENDEE_PROPERTY); | ||
190 | |||
191 | icalproperty_set_parameter(attendee, | ||
192 | icalparameter_new_partstat(ICAL_PARTSTAT_ACCEPTED)); | ||
193 | |||
194 | return reply; | ||
195 | } | ||
196 | |||
197 | icalcomponent* icalmessage_new_decline_reply(icalcomponent* c, | ||
198 | const char* user, | ||
199 | const char* msg) | ||
200 | { | ||
201 | icalcomponent *reply; | ||
202 | icalproperty *attendee; | ||
203 | icalcomponent *inner; | ||
204 | |||
205 | icalerror_check_arg_rz(c,"c"); | ||
206 | |||
207 | reply = icalmessage_new_reply_base(c,user,msg); | ||
208 | inner = icalmessage_get_inner(reply); | ||
209 | if(reply == 0){ | ||
210 | return 0; | ||
211 | } | ||
212 | |||
213 | attendee = icalcomponent_get_first_property(inner, | ||
214 | ICAL_ATTENDEE_PROPERTY); | ||
215 | |||
216 | icalproperty_set_parameter(attendee, | ||
217 | icalparameter_new_partstat(ICAL_PARTSTAT_DECLINED)); | ||
218 | |||
219 | return reply; | ||
220 | } | ||
221 | |||
222 | /* New is modified version of old */ | ||
223 | icalcomponent* icalmessage_new_counterpropose_reply(icalcomponent* oldc, | ||
224 | icalcomponent* newc, | ||
225 | const char* user, | ||
226 | const char* msg) | ||
227 | { | ||
228 | icalcomponent *reply; | ||
229 | |||
230 | icalerror_check_arg_rz(oldc,"oldc"); | ||
231 | icalerror_check_arg_rz(newc,"newc"); | ||
232 | |||
233 | reply = icalcomponent_new_clone(newc); | ||
234 | |||
235 | icalcomponent_set_method(reply,ICAL_METHOD_COUNTER); | ||
236 | |||
237 | return newc; | ||
238 | |||
239 | } | ||
240 | |||
241 | |||
242 | icalcomponent* icalmessage_new_delegate_reply(icalcomponent* c, | ||
243 | const char* user, | ||
244 | const char* delegatee, | ||
245 | const char* msg) | ||
246 | { | ||
247 | |||
248 | icalcomponent *reply; | ||
249 | icalproperty *attendee; | ||
250 | icalcomponent *inner; | ||
251 | |||
252 | icalerror_check_arg_rz(c,"c"); | ||
253 | |||
254 | reply = icalmessage_new_reply_base(c,user,msg); | ||
255 | inner = icalmessage_get_inner(reply); | ||
256 | if(reply == 0){ | ||
257 | return 0; | ||
258 | } | ||
259 | |||
260 | attendee = icalcomponent_get_first_property(inner, | ||
261 | ICAL_ATTENDEE_PROPERTY); | ||
262 | |||
263 | icalproperty_set_parameter(attendee, | ||
264 | icalparameter_new_partstat(ICAL_PARTSTAT_DELEGATED)); | ||
265 | |||
266 | icalproperty_set_parameter(attendee, | ||
267 | icalparameter_new_delegatedto(delegatee)); | ||
268 | |||
269 | return reply; | ||
270 | |||
271 | } | ||
272 | |||
273 | icalcomponent* icalmessage_new_delegate_request(icalcomponent* c, | ||
274 | const char* user, | ||
275 | const char* delegatee, | ||
276 | const char* msg) | ||
277 | { | ||
278 | |||
279 | icalcomponent *reply; | ||
280 | icalproperty *attendee; | ||
281 | icalcomponent *inner; | ||
282 | |||
283 | icalerror_check_arg_rz(c,"c"); | ||
284 | |||
285 | reply = icalmessage_new_reply_base(c,user,msg); | ||
286 | inner = icalmessage_get_inner(reply); | ||
287 | |||
288 | if(reply == 0){ | ||
289 | return 0; | ||
290 | } | ||
291 | |||
292 | icalcomponent_set_method(reply,ICAL_METHOD_REQUEST); | ||
293 | |||
294 | attendee = icalcomponent_get_first_property(inner, | ||
295 | ICAL_ATTENDEE_PROPERTY); | ||
296 | |||
297 | icalproperty_set_parameter(attendee, | ||
298 | icalparameter_new_partstat(ICAL_PARTSTAT_DELEGATED)); | ||
299 | |||
300 | icalproperty_set_parameter(attendee, | ||
301 | icalparameter_new_delegatedto(delegatee)); | ||
302 | |||
303 | icalcomponent_add_property( | ||
304 | inner, | ||
305 | icalproperty_vanew_attendee( | ||
306 | delegatee, | ||
307 | icalparameter_new_delegatedfrom( | ||
308 | icalproperty_get_attendee(attendee) | ||
309 | ), | ||
310 | 0 | ||
311 | ) | ||
312 | ); | ||
313 | |||
314 | |||
315 | return reply; | ||
316 | |||
317 | } | ||
318 | |||
319 | |||
320 | icalcomponent* icalmessage_new_cancel_event(icalcomponent* c, | ||
321 | const char* user, | ||
322 | const char* msg); | ||
323 | icalcomponent* icalmessage_new_cancel_instance(icalcomponent* c, | ||
324 | const char* user, | ||
325 | const char* msg); | ||
326 | icalcomponent* icalmessage_new_cancel_all(icalcomponent* c, | ||
327 | const char* user, | ||
328 | const char* msg); | ||
329 | |||
330 | |||
331 | |||
332 | icalcomponent* icalmessage_new_error_reply(icalcomponent* c, | ||
333 | const char* user, | ||
334 | const char* msg, | ||
335 | const char* debug, | ||
336 | icalrequeststatus code) | ||
337 | { | ||
338 | icalcomponent *reply; | ||
339 | icalcomponent *inner, *cinner; | ||
340 | struct icalreqstattype rs; | ||
341 | |||
342 | icalerror_check_arg_rz(c,"c"); | ||
343 | |||
344 | reply = icalmessage_new_reply_base(c,user,msg); | ||
345 | inner = icalmessage_get_inner(reply); | ||
346 | cinner = icalmessage_get_inner(c); | ||
347 | if(reply == 0){ | ||
348 | return 0; | ||
349 | } | ||
350 | |||
351 | if( code != ICAL_UNKNOWN_STATUS){ | ||
352 | rs.code = code; | ||
353 | rs.debug = debug; | ||
354 | |||
355 | icalcomponent_add_property(inner, | ||
356 | icalproperty_new_requeststatus(rs)); | ||
357 | } else { /* code == ICAL_UNKNOWN_STATUS */ | ||
358 | |||
359 | /* Copy all of the request status properties */ | ||
360 | icalproperty *p; | ||
361 | for(p = icalcomponent_get_first_property(cinner, | ||
362 | ICAL_REQUESTSTATUS_PROPERTY); | ||
363 | p != 0; | ||
364 | p = icalcomponent_get_next_property(cinner, | ||
365 | ICAL_REQUESTSTATUS_PROPERTY)){ | ||
366 | |||
367 | |||
368 | icalcomponent_add_property(inner,icalproperty_new_clone(p)); | ||
369 | } | ||
370 | } | ||
371 | |||
372 | return reply; | ||
373 | } | ||