Diffstat (limited to 'libical/src/libicalss/icalmessage.c') (more/less context) (show whitespace changes)
-rw-r--r-- | libical/src/libicalss/icalmessage.c | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/libical/src/libicalss/icalmessage.c b/libical/src/libicalss/icalmessage.c index d5c57c1..731a2c7 100644 --- a/libical/src/libicalss/icalmessage.c +++ b/libical/src/libicalss/icalmessage.c | |||
@@ -1,91 +1,91 @@ | |||
1 | /* -*- Mode: C -*- | 1 | /* -*- Mode: C -*- |
2 | ====================================================================== | 2 | ====================================================================== |
3 | FILE: icalmessage.c | 3 | FILE: icalmessage.c |
4 | CREATOR: ebusboom 07 Nov 2000 | 4 | CREATOR: ebusboom 07 Nov 2000 |
5 | 5 | ||
6 | $Id$ | 6 | $Id$ |
7 | $Locker$ | 7 | $Locker$ |
8 | 8 | ||
9 | (C) COPYRIGHT 2000, Eric Busboom, http://www.softwarestudio.org | 9 | (C) COPYRIGHT 2000, Eric Busboom, http://www.softwarestudio.org |
10 | 10 | ||
11 | This program is free software; you can redistribute it and/or modify | 11 | This program is free software; you can redistribute it and/or modify |
12 | it under the terms of either: | 12 | it under the terms of either: |
13 | 13 | ||
14 | The LGPL as published by the Free Software Foundation, version | 14 | The LGPL as published by the Free Software Foundation, version |
15 | 2.1, available at: http://www.fsf.org/copyleft/lesser.html | 15 | 2.1, available at: http://www.fsf.org/copyleft/lesser.html |
16 | 16 | ||
17 | Or: | 17 | Or: |
18 | 18 | ||
19 | The Mozilla Public License Version 1.0. You may obtain a copy of | 19 | The Mozilla Public License Version 1.0. You may obtain a copy of |
20 | the License at http://www.mozilla.org/MPL/ | 20 | the License at http://www.mozilla.org/MPL/ |
21 | 21 | ||
22 | 22 | ||
23 | ======================================================================*/ | 23 | ======================================================================*/ |
24 | 24 | ||
25 | #ifdef HAVE_CONFIG_H | 25 | #ifdef HAVE_CONFIG_H |
26 | #include "config.h" | 26 | #include "config.h" |
27 | #endif | 27 | #endif |
28 | 28 | ||
29 | #include "icalmessage.h" | 29 | #include "icalmessage.h" |
30 | #include "icalenums.h" | 30 | #include "icalenums.h" |
31 | #include <ctype.h> /* for tolower()*/ | 31 | #include <ctype.h> /* for tolower()*/ |
32 | #include <string.h> /* for strstr */ | 32 | #include <string.h> /* for strstr */ |
33 | #include <stdlib.h> /* for free(), malloc() */ | 33 | #include <stdlib.h> /* for free(), malloc() */ |
34 | icalcomponent* icalmessage_get_inner(icalcomponent* comp) | 34 | icalcomponent* icalmessage_get_inner(icalcomponent* comp) |
35 | { | 35 | { |
36 | if (icalcomponent_isa(comp) == ICAL_VCALENDAR_COMPONENT){ | 36 | if (icalcomponent_isa(comp) == ICAL_VCALENDAR_COMPONENT){ |
37 | return icalcomponent_get_first_real_component(comp); | 37 | return icalcomponent_get_first_real_component(comp); |
38 | } else { | 38 | } else { |
39 | return comp; | 39 | return comp; |
40 | } | 40 | } |
41 | } | 41 | } |
42 | 42 | ||
43 | char* lowercase(const char* str) | 43 | static char* lowercase(const char* str) |
44 | { | 44 | { |
45 | char* p = 0; | 45 | char* p = 0; |
46 | char* n = icalmemory_strdup(str); | 46 | char* n = icalmemory_strdup(str); |
47 | 47 | ||
48 | if(str ==0){ | 48 | if(str ==0){ |
49 | return 0; | 49 | return 0; |
50 | } | 50 | } |
51 | 51 | ||
52 | for(p = n; *p!=0; p++){ | 52 | for(p = n; *p!=0; p++){ |
53 | *p = tolower(*p); | 53 | *p = tolower(*p); |
54 | } | 54 | } |
55 | 55 | ||
56 | return n; | 56 | return n; |
57 | } | 57 | } |
58 | 58 | ||
59 | icalproperty* icalmessage_find_attendee(icalcomponent* comp, const char* user) | 59 | icalproperty* icalmessage_find_attendee(icalcomponent* comp, const char* user) |
60 | { | 60 | { |
61 | icalcomponent *inner = icalmessage_get_inner(comp); | 61 | icalcomponent *inner = icalmessage_get_inner(comp); |
62 | icalproperty *p,*attendee = 0; | 62 | icalproperty *p,*attendee = 0; |
63 | char* luser = lowercase(user); | 63 | char* luser = lowercase(user); |
64 | 64 | ||
65 | for(p = icalcomponent_get_first_property(inner, ICAL_ATTENDEE_PROPERTY); | 65 | for(p = icalcomponent_get_first_property(inner, ICAL_ATTENDEE_PROPERTY); |
66 | p != 0; | 66 | p != 0; |
67 | p = icalcomponent_get_next_property(inner, ICAL_ATTENDEE_PROPERTY) | 67 | p = icalcomponent_get_next_property(inner, ICAL_ATTENDEE_PROPERTY) |
68 | ){ | 68 | ){ |
69 | 69 | ||
70 | char* lattendee; | 70 | char* lattendee; |
71 | 71 | ||
72 | lattendee = lowercase(icalproperty_get_attendee(p)); | 72 | lattendee = lowercase(icalproperty_get_attendee(p)); |
73 | 73 | ||
74 | if (strstr(lattendee,user) != 0){ | 74 | if (strstr(lattendee,user) != 0){ |
75 | attendee = p; | 75 | attendee = p; |
76 | break; | 76 | break; |
77 | } | 77 | } |
78 | 78 | ||
79 | free(lattendee); | 79 | free(lattendee); |
80 | 80 | ||
81 | } | 81 | } |
82 | 82 | ||
83 | free(luser); | 83 | free(luser); |
84 | 84 | ||
85 | return attendee; | 85 | return attendee; |
86 | 86 | ||
87 | } | 87 | } |
88 | 88 | ||
89 | void icalmessage_copy_properties(icalcomponent* to, icalcomponent* from, | 89 | void icalmessage_copy_properties(icalcomponent* to, icalcomponent* from, |
90 | icalproperty_kind kind) | 90 | icalproperty_kind kind) |
91 | { | 91 | { |
@@ -113,173 +113,178 @@ void icalmessage_copy_properties(icalcomponent* to, icalcomponent* from, | |||
113 | icalcomponent *icalmessage_new_reply_base(icalcomponent* c, | 113 | icalcomponent *icalmessage_new_reply_base(icalcomponent* c, |
114 | const char* user, | 114 | const char* user, |
115 | const char* msg) | 115 | const char* msg) |
116 | { | 116 | { |
117 | icalproperty *attendee; | 117 | icalproperty *attendee; |
118 | char tmp[45]; | 118 | char tmp[45]; |
119 | 119 | ||
120 | icalcomponent *reply = icalcomponent_vanew( | 120 | icalcomponent *reply = icalcomponent_vanew( |
121 | ICAL_VCALENDAR_COMPONENT, | 121 | ICAL_VCALENDAR_COMPONENT, |
122 | icalproperty_new_method(ICAL_METHOD_REPLY), | 122 | icalproperty_new_method(ICAL_METHOD_REPLY), |
123 | icalcomponent_vanew( | 123 | icalcomponent_vanew( |
124 | ICAL_VEVENT_COMPONENT, | 124 | ICAL_VEVENT_COMPONENT, |
125 | icalproperty_new_dtstamp(icaltime_from_timet(time(0),0)), | 125 | icalproperty_new_dtstamp(icaltime_from_timet(time(0),0)), |
126 | 0), | 126 | 0), |
127 | 0); | 127 | 0); |
128 | 128 | ||
129 | icalcomponent *inner = icalmessage_get_inner(reply); | 129 | icalcomponent *inner = icalmessage_get_inner(reply); |
130 | 130 | ||
131 | icalerror_check_arg_rz(c,"c"); | 131 | icalerror_check_arg_rz(c,"c"); |
132 | 132 | ||
133 | icalmessage_copy_properties(reply,c,ICAL_UID_PROPERTY); | 133 | icalmessage_copy_properties(reply,c,ICAL_UID_PROPERTY); |
134 | icalmessage_copy_properties(reply,c,ICAL_ORGANIZER_PROPERTY); | 134 | icalmessage_copy_properties(reply,c,ICAL_ORGANIZER_PROPERTY); |
135 | icalmessage_copy_properties(reply,c,ICAL_RECURRENCEID_PROPERTY); | 135 | icalmessage_copy_properties(reply,c,ICAL_RECURRENCEID_PROPERTY); |
136 | icalmessage_copy_properties(reply,c,ICAL_SUMMARY_PROPERTY); | 136 | icalmessage_copy_properties(reply,c,ICAL_SUMMARY_PROPERTY); |
137 | icalmessage_copy_properties(reply,c,ICAL_SEQUENCE_PROPERTY); | 137 | icalmessage_copy_properties(reply,c,ICAL_SEQUENCE_PROPERTY); |
138 | 138 | ||
139 | icalcomponent_set_dtstamp(reply,icaltime_from_timet(time(0),0)); | 139 | icalcomponent_set_dtstamp(reply,icaltime_from_timet(time(0),0)); |
140 | 140 | ||
141 | if(msg != 0){ | 141 | if(msg != 0){ |
142 | icalcomponent_add_property(inner,icalproperty_new_comment(msg)); | 142 | icalcomponent_add_property(inner,icalproperty_new_comment(msg)); |
143 | } | 143 | } |
144 | 144 | ||
145 | /* Copy this user's attendee property */ | 145 | /* Copy this user's attendee property */ |
146 | 146 | ||
147 | attendee = icalmessage_find_attendee(c,user); | 147 | attendee = icalmessage_find_attendee(c,user); |
148 | 148 | ||
149 | if (attendee == 0){ | 149 | if (attendee == 0){ |
150 | icalerror_set_errno(ICAL_MALFORMEDDATA_ERROR); | 150 | icalerror_set_errno(ICAL_MALFORMEDDATA_ERROR); |
151 | icalcomponent_free(reply); | 151 | icalcomponent_free(reply); |
152 | return 0; | 152 | return 0; |
153 | } | 153 | } |
154 | 154 | ||
155 | icalcomponent_add_property(inner,icalproperty_new_clone(attendee)); | 155 | icalcomponent_add_property(inner,icalproperty_new_clone(attendee)); |
156 | 156 | ||
157 | /* Add PRODID and VERSION */ | 157 | /* Add PRODID and VERSION */ |
158 | 158 | ||
159 | icalcomponent_add_property(reply,icalproperty_new_version("2.0")); | 159 | icalcomponent_add_property(reply,icalproperty_new_version("2.0")); |
160 | 160 | ||
161 | #ifndef WIN32 | ||
161 | sprintf(tmp, | 162 | sprintf(tmp, |
162 | "-//SoftwareStudio//NONSGML %s %s //EN",PACKAGE,VERSION); | 163 | "-//SoftwareStudio//NONSGML %s %s //EN",PACKAGE,VERSION); |
164 | #else | ||
165 | sprintf(tmp, | ||
166 | "-//SoftwareStudio//NONSGML %s %s //EN",ICAL_PACKAGE,ICAL_VERSION); | ||
167 | #endif | ||
163 | icalcomponent_add_property(reply,icalproperty_new_prodid(tmp)); | 168 | icalcomponent_add_property(reply,icalproperty_new_prodid(tmp)); |
164 | 169 | ||
165 | return reply; | 170 | return reply; |
166 | 171 | ||
167 | } | 172 | } |
168 | 173 | ||
169 | icalcomponent* icalmessage_new_accept_reply(icalcomponent* c, | 174 | icalcomponent* icalmessage_new_accept_reply(icalcomponent* c, |
170 | const char* user, | 175 | const char* user, |
171 | const char* msg) | 176 | const char* msg) |
172 | { | 177 | { |
173 | 178 | ||
174 | icalcomponent *reply; | 179 | icalcomponent *reply; |
175 | icalproperty *attendee; | 180 | icalproperty *attendee; |
176 | icalcomponent *inner; | 181 | icalcomponent *inner; |
177 | 182 | ||
178 | icalerror_check_arg_rz(c,"c"); | 183 | icalerror_check_arg_rz(c,"c"); |
179 | 184 | ||
180 | reply = icalmessage_new_reply_base(c,user,msg); | 185 | reply = icalmessage_new_reply_base(c,user,msg); |
181 | 186 | ||
182 | if(reply == 0){ | 187 | if(reply == 0){ |
183 | return 0; | 188 | return 0; |
184 | } | 189 | } |
185 | 190 | ||
186 | inner = icalmessage_get_inner(reply); | 191 | inner = icalmessage_get_inner(reply); |
187 | 192 | ||
188 | attendee = icalcomponent_get_first_property(inner, | 193 | attendee = icalcomponent_get_first_property(inner, |
189 | ICAL_ATTENDEE_PROPERTY); | 194 | ICAL_ATTENDEE_PROPERTY); |
190 | 195 | ||
191 | icalproperty_set_parameter(attendee, | 196 | icalproperty_set_parameter(attendee, |
192 | icalparameter_new_partstat(ICAL_PARTSTAT_ACCEPTED)); | 197 | icalparameter_new_partstat(ICAL_PARTSTAT_ACCEPTED)); |
193 | 198 | ||
194 | return reply; | 199 | return reply; |
195 | } | 200 | } |
196 | 201 | ||
197 | icalcomponent* icalmessage_new_decline_reply(icalcomponent* c, | 202 | icalcomponent* icalmessage_new_decline_reply(icalcomponent* c, |
198 | const char* user, | 203 | const char* user, |
199 | const char* msg) | 204 | const char* msg) |
200 | { | 205 | { |
201 | icalcomponent *reply; | 206 | icalcomponent *reply; |
202 | icalproperty *attendee; | 207 | icalproperty *attendee; |
203 | icalcomponent *inner; | 208 | icalcomponent *inner; |
204 | 209 | ||
205 | icalerror_check_arg_rz(c,"c"); | 210 | icalerror_check_arg_rz(c,"c"); |
206 | 211 | ||
207 | reply = icalmessage_new_reply_base(c,user,msg); | 212 | reply = icalmessage_new_reply_base(c,user,msg); |
208 | inner = icalmessage_get_inner(reply); | 213 | inner = icalmessage_get_inner(reply); |
209 | if(reply == 0){ | 214 | if(reply == 0){ |
210 | return 0; | 215 | return 0; |
211 | } | 216 | } |
212 | 217 | ||
213 | attendee = icalcomponent_get_first_property(inner, | 218 | attendee = icalcomponent_get_first_property(inner, |
214 | ICAL_ATTENDEE_PROPERTY); | 219 | ICAL_ATTENDEE_PROPERTY); |
215 | 220 | ||
216 | icalproperty_set_parameter(attendee, | 221 | icalproperty_set_parameter(attendee, |
217 | icalparameter_new_partstat(ICAL_PARTSTAT_DECLINED)); | 222 | icalparameter_new_partstat(ICAL_PARTSTAT_DECLINED)); |
218 | 223 | ||
219 | return reply; | 224 | return reply; |
220 | } | 225 | } |
221 | 226 | ||
222 | /* New is modified version of old */ | 227 | /* New is modified version of old */ |
223 | icalcomponent* icalmessage_new_counterpropose_reply(icalcomponent* oldc, | 228 | icalcomponent* icalmessage_new_counterpropose_reply(icalcomponent* oldc, |
224 | icalcomponent* newc, | 229 | icalcomponent* newc, |
225 | const char* user, | 230 | const char* user, |
226 | const char* msg) | 231 | const char* msg) |
227 | { | 232 | { |
228 | icalcomponent *reply; | 233 | icalcomponent *reply; |
229 | 234 | ||
230 | icalerror_check_arg_rz(oldc,"oldc"); | 235 | icalerror_check_arg_rz(oldc,"oldc"); |
231 | icalerror_check_arg_rz(newc,"newc"); | 236 | icalerror_check_arg_rz(newc,"newc"); |
232 | 237 | ||
233 | reply = icalcomponent_new_clone(newc); | 238 | reply = icalmessage_new_reply_base(newc,user,msg); |
234 | 239 | ||
235 | icalcomponent_set_method(reply,ICAL_METHOD_COUNTER); | 240 | icalcomponent_set_method(reply,ICAL_METHOD_COUNTER); |
236 | 241 | ||
237 | return newc; | 242 | return reply; |
238 | 243 | ||
239 | } | 244 | } |
240 | 245 | ||
241 | 246 | ||
242 | icalcomponent* icalmessage_new_delegate_reply(icalcomponent* c, | 247 | icalcomponent* icalmessage_new_delegate_reply(icalcomponent* c, |
243 | const char* user, | 248 | const char* user, |
244 | const char* delegatee, | 249 | const char* delegatee, |
245 | const char* msg) | 250 | const char* msg) |
246 | { | 251 | { |
247 | 252 | ||
248 | icalcomponent *reply; | 253 | icalcomponent *reply; |
249 | icalproperty *attendee; | 254 | icalproperty *attendee; |
250 | icalcomponent *inner; | 255 | icalcomponent *inner; |
251 | 256 | ||
252 | icalerror_check_arg_rz(c,"c"); | 257 | icalerror_check_arg_rz(c,"c"); |
253 | 258 | ||
254 | reply = icalmessage_new_reply_base(c,user,msg); | 259 | reply = icalmessage_new_reply_base(c,user,msg); |
255 | inner = icalmessage_get_inner(reply); | 260 | inner = icalmessage_get_inner(reply); |
256 | if(reply == 0){ | 261 | if(reply == 0){ |
257 | return 0; | 262 | return 0; |
258 | } | 263 | } |
259 | 264 | ||
260 | attendee = icalcomponent_get_first_property(inner, | 265 | attendee = icalcomponent_get_first_property(inner, |
261 | ICAL_ATTENDEE_PROPERTY); | 266 | ICAL_ATTENDEE_PROPERTY); |
262 | 267 | ||
263 | icalproperty_set_parameter(attendee, | 268 | icalproperty_set_parameter(attendee, |
264 | icalparameter_new_partstat(ICAL_PARTSTAT_DELEGATED)); | 269 | icalparameter_new_partstat(ICAL_PARTSTAT_DELEGATED)); |
265 | 270 | ||
266 | icalproperty_set_parameter(attendee, | 271 | icalproperty_set_parameter(attendee, |
267 | icalparameter_new_delegatedto(delegatee)); | 272 | icalparameter_new_delegatedto(delegatee)); |
268 | 273 | ||
269 | return reply; | 274 | return reply; |
270 | 275 | ||
271 | } | 276 | } |
272 | 277 | ||
273 | icalcomponent* icalmessage_new_delegate_request(icalcomponent* c, | 278 | icalcomponent* icalmessage_new_delegate_request(icalcomponent* c, |
274 | const char* user, | 279 | const char* user, |
275 | const char* delegatee, | 280 | const char* delegatee, |
276 | const char* msg) | 281 | const char* msg) |
277 | { | 282 | { |
278 | 283 | ||
279 | icalcomponent *reply; | 284 | icalcomponent *reply; |
280 | icalproperty *attendee; | 285 | icalproperty *attendee; |
281 | icalcomponent *inner; | 286 | icalcomponent *inner; |
282 | 287 | ||
283 | icalerror_check_arg_rz(c,"c"); | 288 | icalerror_check_arg_rz(c,"c"); |
284 | 289 | ||
285 | reply = icalmessage_new_reply_base(c,user,msg); | 290 | reply = icalmessage_new_reply_base(c,user,msg); |