Diffstat (limited to 'libical/src/libical/icalvalue.c') (more/less context) (show whitespace changes)
-rw-r--r-- | libical/src/libical/icalvalue.c | 484 |
1 files changed, 289 insertions, 195 deletions
diff --git a/libical/src/libical/icalvalue.c b/libical/src/libical/icalvalue.c index eb5476e..4c67136 100644 --- a/libical/src/libical/icalvalue.c +++ b/libical/src/libical/icalvalue.c | |||
@@ -1,7 +1,8 @@ | |||
1 | /* -*- Mode: C -*- */ | 1 | /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | /* vi:set ts=4 sts=4 sw=4 expandtab : */ | ||
2 | /*====================================================================== | 3 | /*====================================================================== |
3 | FILE: icalvalue.c | 4 | FILE: icalvalue.c |
4 | CREATOR: eric 02 May 1999 | 5 | CREATOR: eric 02 May 1999 |
5 | 6 | ||
6 | $Id$ | 7 | $Id$ |
7 | 8 | ||
@@ -43,30 +44,35 @@ | |||
43 | #include <stddef.h> /* For offsetof() macro */ | 44 | #include <stddef.h> /* For offsetof() macro */ |
44 | #include <errno.h> | 45 | #include <errno.h> |
45 | #include <time.h> /* for mktime */ | 46 | #include <time.h> /* for mktime */ |
46 | #include <stdlib.h> /* for atoi and atof */ | 47 | #include <stdlib.h> /* for atoi and atof */ |
47 | #include <limits.h> /* for SHRT_MAX */ | 48 | #include <limits.h> /* for SHRT_MAX */ |
48 | 49 | ||
49 | int snprintf(char *str, size_t n, char const *fmt, ...); | 50 | #ifdef WIN32 |
51 | #define snprintf _snprintf | ||
52 | #define strcasecmp stricmp | ||
53 | #endif | ||
50 | 54 | ||
51 | #if _MAC_OS_ | 55 | #if _MAC_OS_ |
52 | #include "icalmemory_strdup.h" | 56 | #include "icalmemory_strdup.h" |
53 | #endif | 57 | #endif |
54 | 58 | ||
55 | #define TMP_BUF_SIZE 1024 | 59 | #define TMP_BUF_SIZE 1024 |
56 | 60 | ||
57 | void print_datetime_to_string(char* str, struct icaltimetype *data); | 61 | void print_datetime_to_string(char* str, const struct icaltimetype *data); |
58 | void print_date_to_string(char* str, struct icaltimetype *data); | 62 | void print_date_to_string(char* str, const struct icaltimetype *data); |
59 | void print_time_to_string(char* str, struct icaltimetype *data); | 63 | void print_time_to_string(char* str, const struct icaltimetype *data); |
60 | void print_recur_to_string(char* str, struct icaltimetype *data); | ||
61 | 64 | ||
62 | 65 | ||
63 | struct icalvalue_impl* icalvalue_new_impl(icalvalue_kind kind){ | 66 | struct icalvalue_impl* icalvalue_new_impl(icalvalue_kind kind){ |
64 | 67 | ||
65 | struct icalvalue_impl* v; | 68 | struct icalvalue_impl* v; |
66 | 69 | ||
70 | if (!icalvalue_kind_is_valid(kind)) | ||
71 | return NULL; | ||
72 | |||
67 | if ( ( v = (struct icalvalue_impl*) | 73 | if ( ( v = (struct icalvalue_impl*) |
68 | malloc(sizeof(struct icalvalue_impl))) == 0) { | 74 | malloc(sizeof(struct icalvalue_impl))) == 0) { |
69 | icalerror_set_errno(ICAL_NEWFAILED_ERROR); | 75 | icalerror_set_errno(ICAL_NEWFAILED_ERROR); |
70 | return 0; | 76 | return 0; |
71 | } | 77 | } |
72 | 78 | ||
@@ -87,38 +93,40 @@ struct icalvalue_impl* icalvalue_new_impl(icalvalue_kind kind){ | |||
87 | icalvalue* | 93 | icalvalue* |
88 | icalvalue_new (icalvalue_kind kind) | 94 | icalvalue_new (icalvalue_kind kind) |
89 | { | 95 | { |
90 | return (icalvalue*)icalvalue_new_impl(kind); | 96 | return (icalvalue*)icalvalue_new_impl(kind); |
91 | } | 97 | } |
92 | 98 | ||
93 | icalvalue* icalvalue_new_clone(icalvalue* value){ | 99 | icalvalue* icalvalue_new_clone(const icalvalue* old) { |
94 | |||
95 | struct icalvalue_impl* new; | 100 | struct icalvalue_impl* new; |
96 | struct icalvalue_impl* old = (struct icalvalue_impl*)value; | ||
97 | 101 | ||
98 | new = icalvalue_new_impl(old->kind); | 102 | new = icalvalue_new_impl(old->kind); |
99 | 103 | ||
100 | if (new == 0){ | 104 | if (new == 0){ |
101 | return 0; | 105 | return 0; |
102 | } | 106 | } |
103 | 107 | ||
104 | |||
105 | strcpy(new->id, old->id); | 108 | strcpy(new->id, old->id); |
106 | new->kind = old->kind; | 109 | new->kind = old->kind; |
107 | new->size = old->size; | 110 | new->size = old->size; |
108 | 111 | ||
109 | switch (new->kind){ | 112 | switch (new->kind){ |
110 | |||
111 | /* The contents of the attach value may or may not be owned by the | ||
112 | * library. */ | ||
113 | case ICAL_ATTACH_VALUE: | 113 | case ICAL_ATTACH_VALUE: |
114 | case ICAL_BINARY_VALUE: | 114 | case ICAL_BINARY_VALUE: |
115 | { | 115 | { |
116 | /* HACK ugh. I don't feel like impleenting this */ | 116 | /* Hmm. We just ref the attach value, which may not be the right |
117 | } | 117 | * thing to do. We cannot quite copy the data, anyways, since we |
118 | * don't know how long it is. | ||
119 | */ | ||
120 | new->data.v_attach = old->data.v_attach; | ||
121 | if (new->data.v_attach) | ||
122 | icalattach_ref (new->data.v_attach); | ||
118 | 123 | ||
124 | break; | ||
125 | } | ||
126 | case ICAL_QUERY_VALUE: | ||
119 | case ICAL_STRING_VALUE: | 127 | case ICAL_STRING_VALUE: |
120 | case ICAL_TEXT_VALUE: | 128 | case ICAL_TEXT_VALUE: |
121 | case ICAL_CALADDRESS_VALUE: | 129 | case ICAL_CALADDRESS_VALUE: |
122 | case ICAL_URI_VALUE: | 130 | case ICAL_URI_VALUE: |
123 | { | 131 | { |
124 | if (old->data.v_string != 0) { | 132 | if (old->data.v_string != 0) { |
@@ -143,25 +151,38 @@ icalvalue* icalvalue_new_clone(icalvalue* value){ | |||
143 | memcpy(new->data.v_recur, old->data.v_recur, | 151 | memcpy(new->data.v_recur, old->data.v_recur, |
144 | sizeof(struct icalrecurrencetype)); | 152 | sizeof(struct icalrecurrencetype)); |
145 | } | 153 | } |
146 | break; | 154 | break; |
147 | } | 155 | } |
148 | 156 | ||
157 | case ICAL_X_VALUE: | ||
158 | { | ||
159 | if (old->x_value != 0) { | ||
160 | new->x_value=icalmemory_strdup(old->x_value); | ||
161 | |||
162 | if (new->x_value == 0) { | ||
163 | return 0; | ||
164 | } | ||
165 | } | ||
166 | |||
167 | break; | ||
168 | } | ||
169 | |||
149 | default: | 170 | default: |
150 | { | 171 | { |
151 | /* all of the other types are stored as values, not | 172 | /* all of the other types are stored as values, not |
152 | pointers, so we can just copy the whole structure. */ | 173 | pointers, so we can just copy the whole structure. */ |
153 | 174 | ||
154 | new->data = old->data; | 175 | new->data = old->data; |
155 | } | 176 | } |
156 | } | 177 | } |
157 | 178 | ||
158 | return new; | 179 | return new; |
159 | } | 180 | } |
160 | 181 | ||
161 | char* icalmemory_strdup_and_dequote(const char* str) | 182 | static char* icalmemory_strdup_and_dequote(const char* str) |
162 | { | 183 | { |
163 | const char* p; | 184 | const char* p; |
164 | char* out = (char*)malloc(sizeof(char) * strlen(str) +1); | 185 | char* out = (char*)malloc(sizeof(char) * strlen(str) +1); |
165 | char* pout; | 186 | char* pout; |
166 | 187 | ||
167 | if (out == 0){ | 188 | if (out == 0){ |
@@ -180,24 +201,45 @@ char* icalmemory_strdup_and_dequote(const char* str) | |||
180 | { | 201 | { |
181 | *pout = '\0'; | 202 | *pout = '\0'; |
182 | break; | 203 | break; |
183 | 204 | ||
184 | } | 205 | } |
185 | case 'n': | 206 | case 'n': |
207 | case 'N': | ||
186 | { | 208 | { |
187 | *pout = '\n'; | 209 | *pout = '\n'; |
188 | break; | 210 | break; |
189 | } | 211 | } |
190 | case 'N': | 212 | case 't': |
213 | case 'T': | ||
191 | { | 214 | { |
192 | *pout = '\n'; | 215 | *pout = '\t'; |
216 | break; | ||
217 | } | ||
218 | case 'r': | ||
219 | case 'R': | ||
220 | { | ||
221 | *pout = '\r'; | ||
222 | break; | ||
223 | } | ||
224 | case 'b': | ||
225 | case 'B': | ||
226 | { | ||
227 | *pout = '\b'; | ||
228 | break; | ||
229 | } | ||
230 | case 'f': | ||
231 | case 'F': | ||
232 | { | ||
233 | *pout = '\f'; | ||
193 | break; | 234 | break; |
194 | } | 235 | } |
195 | case '\\': | ||
196 | case ',': | ||
197 | case ';': | 236 | case ';': |
237 | case ',': | ||
238 | case '"': | ||
239 | case '\\': | ||
198 | { | 240 | { |
199 | *pout = *p; | 241 | *pout = *p; |
200 | break; | 242 | break; |
201 | } | 243 | } |
202 | default: | 244 | default: |
203 | { | 245 | { |
@@ -214,15 +256,22 @@ char* icalmemory_strdup_and_dequote(const char* str) | |||
214 | 256 | ||
215 | *pout = '\0'; | 257 | *pout = '\0'; |
216 | 258 | ||
217 | return out; | 259 | return out; |
218 | } | 260 | } |
219 | 261 | ||
262 | /* | ||
263 | * FIXME | ||
264 | * | ||
265 | * This is a bad API, as it forces callers to specify their own X type. | ||
266 | * This function should take care of this by itself. | ||
267 | */ | ||
268 | static | ||
220 | icalvalue* icalvalue_new_enum(icalvalue_kind kind, int x_type, const char* str) | 269 | icalvalue* icalvalue_new_enum(icalvalue_kind kind, int x_type, const char* str) |
221 | { | 270 | { |
222 | int e = icalproperty_string_to_enum(str); | 271 | int e = icalproperty_kind_and_string_to_enum(kind, str); |
223 | struct icalvalue_impl *value; | 272 | struct icalvalue_impl *value; |
224 | 273 | ||
225 | if(e != 0 && icalproperty_enum_belongs_to_property( | 274 | if(e != 0 && icalproperty_enum_belongs_to_property( |
226 | icalproperty_value_kind_to_kind(kind),e)) { | 275 | icalproperty_value_kind_to_kind(kind),e)) { |
227 | 276 | ||
228 | value = icalvalue_new_impl(kind); | 277 | value = icalvalue_new_impl(kind); |
@@ -239,113 +288,123 @@ icalvalue* icalvalue_new_enum(icalvalue_kind kind, int x_type, const char* str) | |||
239 | 288 | ||
240 | 289 | ||
241 | icalvalue* icalvalue_new_from_string_with_error(icalvalue_kind kind,const char* str,icalproperty** error) | 290 | icalvalue* icalvalue_new_from_string_with_error(icalvalue_kind kind,const char* str,icalproperty** error) |
242 | { | 291 | { |
243 | 292 | ||
244 | struct icalvalue_impl *value = 0; | 293 | struct icalvalue_impl *value = 0; |
245 | struct icalattachtype *attach = 0; | ||
246 | 294 | ||
247 | icalerror_check_arg_rz(str!=0,"str"); | 295 | icalerror_check_arg_rz(str!=0,"str"); |
248 | 296 | ||
249 | if (error != 0){ | 297 | if (error != 0){ |
250 | *error = 0; | 298 | *error = 0; |
251 | } | 299 | } |
252 | 300 | ||
253 | switch (kind){ | 301 | switch (kind){ |
254 | 302 | ||
255 | case ICAL_ATTACH_VALUE: | 303 | case ICAL_ATTACH_VALUE: |
256 | attach = icalattachtype_new(); | 304 | { |
305 | icalattach *attach; | ||
306 | |||
307 | attach = icalattach_new_from_url (str); | ||
308 | if (!attach) | ||
309 | break; | ||
310 | |||
257 | value = icalvalue_new_attach( attach ); | 311 | value = icalvalue_new_attach( attach ); |
258 | icalattachtype_free( attach ); | 312 | icalattach_unref (attach); |
259 | icalattachtype_set_url( value->data.v_attach, str ); | ||
260 | break; | 313 | break; |
314 | } | ||
315 | |||
261 | case ICAL_BINARY_VALUE: | 316 | case ICAL_BINARY_VALUE: |
262 | case ICAL_BOOLEAN_VALUE: | 317 | case ICAL_BOOLEAN_VALUE: |
263 | { | 318 | { |
264 | /* HACK */ | 319 | /* HACK */ |
265 | value = 0; | 320 | value = 0; |
266 | 321 | ||
267 | if (error != 0){ | 322 | if (error != 0){ |
268 | char temp[TMP_BUF_SIZE]; | 323 | char temp[TMP_BUF_SIZE]; |
269 | sprintf(temp,"%s Values are not implemented", | 324 | sprintf(temp,"%s Values are not implemented", |
270 | icalparameter_kind_to_string(kind)); | 325 | icalvalue_kind_to_string(kind)); |
271 | *error = icalproperty_vanew_xlicerror( | 326 | *error = icalproperty_vanew_xlicerror( |
272 | temp, | 327 | temp, |
273 | icalparameter_new_xlicerrortype( | 328 | icalparameter_new_xlicerrortype( |
274 | ICAL_XLICERRORTYPE_VALUEPARSEERROR), | 329 | ICAL_XLICERRORTYPE_VALUEPARSEERROR), |
275 | 0); | 330 | 0); |
276 | } | 331 | } |
277 | break; | 332 | break; |
278 | } | 333 | } |
279 | 334 | ||
280 | 335 | ||
281 | case ICAL_TRANSP_VALUE: | 336 | case ICAL_TRANSP_VALUE: |
282 | value = icalvalue_new_enum(kind, ICAL_TRANSP_X,str); | 337 | value = icalvalue_new_enum(kind, (int)ICAL_TRANSP_X,str); |
283 | break; | 338 | break; |
284 | case ICAL_METHOD_VALUE: | 339 | case ICAL_METHOD_VALUE: |
285 | value = icalvalue_new_enum(kind, ICAL_METHOD_X,str); | 340 | value = icalvalue_new_enum(kind, (int)ICAL_METHOD_X,str); |
286 | break; | 341 | break; |
287 | case ICAL_STATUS_VALUE: | 342 | case ICAL_STATUS_VALUE: |
288 | value = icalvalue_new_enum(kind, ICAL_STATUS_X,str); | 343 | value = icalvalue_new_enum(kind, (int)ICAL_STATUS_X,str); |
289 | break; | 344 | break; |
290 | case ICAL_ACTION_VALUE: | 345 | case ICAL_ACTION_VALUE: |
291 | value = icalvalue_new_enum(kind, ICAL_ACTION_X,str); | 346 | value = icalvalue_new_enum(kind, (int)ICAL_ACTION_X,str); |
347 | break; | ||
348 | |||
349 | case ICAL_QUERY_VALUE: | ||
350 | value = icalvalue_new_query(str); | ||
292 | break; | 351 | break; |
352 | |||
293 | case ICAL_CLASS_VALUE: | 353 | case ICAL_CLASS_VALUE: |
294 | value = icalvalue_new_enum(kind, ICAL_CLASS_X,str); | 354 | value = icalvalue_new_enum(kind, (int)ICAL_CLASS_X,str); |
295 | break; | 355 | break; |
296 | 356 | ||
297 | 357 | ||
298 | case ICAL_INTEGER_VALUE: | 358 | case ICAL_INTEGER_VALUE: |
299 | { | ||
300 | value = icalvalue_new_integer(atoi(str)); | 359 | value = icalvalue_new_integer(atoi(str)); |
301 | break; | 360 | break; |
302 | } | ||
303 | 361 | ||
304 | case ICAL_FLOAT_VALUE: | 362 | case ICAL_FLOAT_VALUE: |
305 | { | ||
306 | value = icalvalue_new_float((float )atof(str)); | 363 | value = icalvalue_new_float((float )atof(str)); |
307 | break; | 364 | break; |
308 | } | ||
309 | 365 | ||
310 | case ICAL_UTCOFFSET_VALUE: | 366 | case ICAL_UTCOFFSET_VALUE: |
311 | { | 367 | { |
312 | value = icalparser_parse_value(kind,str,(icalcomponent*)0); | 368 | int t,utcoffset, hours, minutes, seconds; |
369 | /* treat the UTCOFSET string a a decimal number, disassemble its digits | ||
370 | and reconstruct it as sections */ | ||
371 | t = strtol(str,0,10); | ||
372 | /* add phantom seconds field */ | ||
373 | if(abs(t)<9999){t *= 100; } | ||
374 | hours = (t/10000); | ||
375 | minutes = (t-hours*10000)/100; | ||
376 | seconds = (t-hours*10000-minutes*100); | ||
377 | utcoffset = hours*3600+minutes*60+seconds; | ||
378 | |||
379 | value = icalvalue_new_utcoffset(utcoffset); | ||
380 | |||
313 | break; | 381 | break; |
314 | } | 382 | } |
315 | 383 | ||
316 | case ICAL_TEXT_VALUE: | 384 | case ICAL_TEXT_VALUE: |
317 | { | 385 | { |
318 | char* dequoted_str = icalmemory_strdup_and_dequote(str); | 386 | char* dequoted_str = icalmemory_strdup_and_dequote(str); |
319 | value = icalvalue_new_text(dequoted_str); | 387 | value = icalvalue_new_text(dequoted_str); |
320 | free(dequoted_str); | 388 | free(dequoted_str); |
321 | break; | 389 | break; |
322 | } | 390 | } |
323 | 391 | ||
324 | |||
325 | case ICAL_STRING_VALUE: | 392 | case ICAL_STRING_VALUE: |
326 | { | ||
327 | value = icalvalue_new_string(str); | 393 | value = icalvalue_new_string(str); |
328 | break; | 394 | break; |
329 | } | ||
330 | 395 | ||
331 | case ICAL_CALADDRESS_VALUE: | 396 | case ICAL_CALADDRESS_VALUE: |
332 | { | ||
333 | value = icalvalue_new_caladdress(str); | 397 | value = icalvalue_new_caladdress(str); |
334 | break; | 398 | break; |
335 | } | ||
336 | 399 | ||
337 | case ICAL_URI_VALUE: | 400 | case ICAL_URI_VALUE: |
338 | { | ||
339 | value = icalvalue_new_uri(str); | 401 | value = icalvalue_new_uri(str); |
340 | break; | 402 | break; |
341 | } | ||
342 | |||
343 | 403 | ||
344 | case ICAL_GEO_VALUE: | 404 | case ICAL_GEO_VALUE: |
345 | { | ||
346 | value = 0; | 405 | value = 0; |
347 | /* HACK */ | 406 | /* HACK */ |
348 | 407 | ||
349 | if (error != 0){ | 408 | if (error != 0){ |
350 | char temp[TMP_BUF_SIZE]; | 409 | char temp[TMP_BUF_SIZE]; |
351 | sprintf(temp,"GEO Values are not implemented"); | 410 | sprintf(temp,"GEO Values are not implemented"); |
@@ -356,13 +415,12 @@ icalvalue* icalvalue_new_from_string_with_error(icalvalue_kind kind,const char* | |||
356 | 0); | 415 | 0); |
357 | } | 416 | } |
358 | 417 | ||
359 | /*icalerror_warn("Parsing GEO properties is unimplmeneted");*/ | 418 | /*icalerror_warn("Parsing GEO properties is unimplmeneted");*/ |
360 | 419 | ||
361 | break; | 420 | break; |
362 | } | ||
363 | 421 | ||
364 | case ICAL_RECUR_VALUE: | 422 | case ICAL_RECUR_VALUE: |
365 | { | 423 | { |
366 | struct icalrecurrencetype rt; | 424 | struct icalrecurrencetype rt; |
367 | rt = icalrecurrencetype_from_string(str); | 425 | rt = icalrecurrencetype_from_string(str); |
368 | if(rt.freq != ICAL_NO_RECURRENCE){ | 426 | if(rt.freq != ICAL_NO_RECURRENCE){ |
@@ -388,30 +446,31 @@ icalvalue* icalvalue_new_from_string_with_error(icalvalue_kind kind,const char* | |||
388 | 446 | ||
389 | case ICAL_DATETIMEPERIOD_VALUE: | 447 | case ICAL_DATETIMEPERIOD_VALUE: |
390 | { | 448 | { |
391 | struct icaltimetype tt; | 449 | struct icaltimetype tt; |
392 | struct icalperiodtype p; | 450 | struct icalperiodtype p; |
393 | tt = icaltime_from_string(str); | 451 | tt = icaltime_from_string(str); |
394 | p = icalperiodtype_from_string(str); | ||
395 | 452 | ||
396 | if(!icaltime_is_null_time(tt)){ | 453 | if(!icaltime_is_null_time(tt)){ |
397 | value = icalvalue_new_datetime(tt); | 454 | value = icalvalue_new_datetime(tt); |
398 | } else if (!icalperiodtype_is_null_period(p)){ | 455 | break; |
456 | } | ||
457 | |||
458 | p = icalperiodtype_from_string(str); | ||
459 | if (!icalperiodtype_is_null_period(p)){ | ||
399 | value = icalvalue_new_period(p); | 460 | value = icalvalue_new_period(p); |
400 | } | 461 | } |
401 | 462 | ||
402 | break; | 463 | break; |
403 | } | 464 | } |
404 | 465 | ||
405 | case ICAL_DURATION_VALUE: | 466 | case ICAL_DURATION_VALUE: |
406 | { | 467 | { |
407 | struct icaldurationtype dur = icaldurationtype_from_string(str); | 468 | struct icaldurationtype dur = icaldurationtype_from_string(str); |
408 | 469 | ||
409 | if(icaldurationtype_is_null_duration(dur)){ | 470 | if (!icaldurationtype_is_bad_duration(dur)) { /* failed to parse */ |
410 | value = 0; | ||
411 | } else { | ||
412 | value = icalvalue_new_duration(dur); | 471 | value = icalvalue_new_duration(dur); |
413 | } | 472 | } |
414 | 473 | ||
415 | break; | 474 | break; |
416 | } | 475 | } |
417 | 476 | ||
@@ -426,13 +485,13 @@ icalvalue* icalvalue_new_from_string_with_error(icalvalue_kind kind,const char* | |||
426 | break; | 485 | break; |
427 | } | 486 | } |
428 | 487 | ||
429 | case ICAL_TRIGGER_VALUE: | 488 | case ICAL_TRIGGER_VALUE: |
430 | { | 489 | { |
431 | struct icaltriggertype tr = icaltriggertype_from_string(str); | 490 | struct icaltriggertype tr = icaltriggertype_from_string(str); |
432 | if (!icaltriggertype_is_null_trigger(tr)){ | 491 | if (!icaltriggertype_is_bad_trigger(tr)) { |
433 | value = icalvalue_new_trigger(tr); | 492 | value = icalvalue_new_trigger(tr); |
434 | } | 493 | } |
435 | break; | 494 | break; |
436 | } | 495 | } |
437 | 496 | ||
438 | case ICAL_REQUESTSTATUS_VALUE: | 497 | case ICAL_REQUESTSTATUS_VALUE: |
@@ -441,15 +500,23 @@ icalvalue* icalvalue_new_from_string_with_error(icalvalue_kind kind,const char* | |||
441 | if(rst.code != ICAL_UNKNOWN_STATUS){ | 500 | if(rst.code != ICAL_UNKNOWN_STATUS){ |
442 | value = icalvalue_new_requeststatus(rst); | 501 | value = icalvalue_new_requeststatus(rst); |
443 | } | 502 | } |
444 | break; | 503 | break; |
445 | 504 | ||
446 | } | 505 | } |
447 | default: | 506 | |
507 | case ICAL_X_VALUE: | ||
448 | { | 508 | { |
509 | char* dequoted_str = icalmemory_strdup_and_dequote(str); | ||
510 | value = icalvalue_new_x(dequoted_str); | ||
511 | free(dequoted_str); | ||
512 | } | ||
513 | break; | ||
449 | 514 | ||
515 | default: | ||
516 | { | ||
450 | if (error != 0 ){ | 517 | if (error != 0 ){ |
451 | char temp[TMP_BUF_SIZE]; | 518 | char temp[TMP_BUF_SIZE]; |
452 | 519 | ||
453 | snprintf(temp,TMP_BUF_SIZE,"Unknown type for \'%s\'",str); | 520 | snprintf(temp,TMP_BUF_SIZE,"Unknown type for \'%s\'",str); |
454 | 521 | ||
455 | *error = icalproperty_vanew_xlicerror( | 522 | *error = icalproperty_vanew_xlicerror( |
@@ -481,23 +548,21 @@ icalvalue* icalvalue_new_from_string_with_error(icalvalue_kind kind,const char* | |||
481 | return value; | 548 | return value; |
482 | 549 | ||
483 | } | 550 | } |
484 | 551 | ||
485 | icalvalue* icalvalue_new_from_string(icalvalue_kind kind,const char* str) | 552 | icalvalue* icalvalue_new_from_string(icalvalue_kind kind,const char* str) |
486 | { | 553 | { |
487 | return icalvalue_new_from_string_with_error(kind,str,(icalproperty*)0); | 554 | return icalvalue_new_from_string_with_error(kind,str,(icalproperty**)0); |
488 | } | 555 | } |
489 | 556 | ||
490 | 557 | ||
491 | 558 | ||
492 | void | 559 | void |
493 | icalvalue_free (icalvalue* value) | 560 | icalvalue_free (icalvalue* v) |
494 | { | 561 | { |
495 | struct icalvalue_impl* v = (struct icalvalue_impl*)value; | 562 | icalerror_check_arg_rv((v != 0),"value"); |
496 | |||
497 | icalerror_check_arg_rv((value != 0),"value"); | ||
498 | 563 | ||
499 | #ifdef ICAL_FREE_ON_LIST_IS_ERROR | 564 | #ifdef ICAL_FREE_ON_LIST_IS_ERROR |
500 | icalerror_assert( (v->parent ==0),"This value is still attached to a property"); | 565 | icalerror_assert( (v->parent ==0),"This value is still attached to a property"); |
501 | 566 | ||
502 | #else | 567 | #else |
503 | if(v->parent !=0){ | 568 | if(v->parent !=0){ |
@@ -507,21 +572,25 @@ icalvalue_free (icalvalue* value) | |||
507 | 572 | ||
508 | if(v->x_value != 0){ | 573 | if(v->x_value != 0){ |
509 | free(v->x_value); | 574 | free(v->x_value); |
510 | } | 575 | } |
511 | 576 | ||
512 | switch (v->kind){ | 577 | switch (v->kind){ |
513 | case ICAL_ATTACH_VALUE: | 578 | case ICAL_BINARY_VALUE: |
514 | icalattachtype_free( v->data.v_attach ); | 579 | case ICAL_ATTACH_VALUE: { |
580 | if (v->data.v_attach) { | ||
581 | icalattach_unref (v->data.v_attach); | ||
582 | v->data.v_attach = NULL; | ||
583 | } | ||
584 | |||
515 | break; | 585 | break; |
516 | case ICAL_BINARY_VALUE: { | ||
517 | /* HACK ugh. This will be tough to implement */ | ||
518 | } | 586 | } |
519 | case ICAL_TEXT_VALUE: | 587 | case ICAL_TEXT_VALUE: |
520 | case ICAL_CALADDRESS_VALUE: | 588 | case ICAL_CALADDRESS_VALUE: |
521 | case ICAL_URI_VALUE: | 589 | case ICAL_URI_VALUE: |
590 | case ICAL_QUERY_VALUE: | ||
522 | { | 591 | { |
523 | if (v->data.v_string != 0) { | 592 | if (v->data.v_string != 0) { |
524 | free((void*)v->data.v_string); | 593 | free((void*)v->data.v_string); |
525 | v->data.v_string = 0; | 594 | v->data.v_string = 0; |
526 | } | 595 | } |
527 | break; | 596 | break; |
@@ -547,24 +616,22 @@ icalvalue_free (icalvalue* value) | |||
547 | memset(&(v->data),0,sizeof(v->data)); | 616 | memset(&(v->data),0,sizeof(v->data)); |
548 | v->id[0] = 'X'; | 617 | v->id[0] = 'X'; |
549 | free(v); | 618 | free(v); |
550 | } | 619 | } |
551 | 620 | ||
552 | int | 621 | int |
553 | icalvalue_is_valid (icalvalue* value) | 622 | icalvalue_is_valid (const icalvalue* value) |
554 | { | 623 | { |
555 | /*struct icalvalue_impl* v = (struct icalvalue_impl*)value;*/ | ||
556 | |||
557 | if(value == 0){ | 624 | if(value == 0){ |
558 | return 0; | 625 | return 0; |
559 | } | 626 | } |
560 | 627 | ||
561 | return 1; | 628 | return 1; |
562 | } | 629 | } |
563 | 630 | ||
564 | char* icalvalue_binary_as_ical_string(icalvalue* value) { | 631 | static char* icalvalue_binary_as_ical_string(const icalvalue* value) { |
565 | 632 | ||
566 | const char* data; | 633 | const char* data; |
567 | char* str; | 634 | char* str; |
568 | icalerror_check_arg_rz( (value!=0),"value"); | 635 | icalerror_check_arg_rz( (value!=0),"value"); |
569 | 636 | ||
570 | data = icalvalue_get_binary(value); | 637 | data = icalvalue_get_binary(value); |
@@ -572,47 +639,29 @@ char* icalvalue_binary_as_ical_string(icalvalue* value) { | |||
572 | str = (char*)icalmemory_tmp_buffer(60); | 639 | str = (char*)icalmemory_tmp_buffer(60); |
573 | sprintf(str,"icalvalue_binary_as_ical_string is not implemented yet"); | 640 | sprintf(str,"icalvalue_binary_as_ical_string is not implemented yet"); |
574 | 641 | ||
575 | return str; | 642 | return str; |
576 | } | 643 | } |
577 | 644 | ||
578 | #ifndef _WIN32 | 645 | |
579 | #define MAX_INT_DIGITS 12 /* Enough for 2^32 + sign*/ | 646 | #define MAX_INT_DIGITS 12 /* Enough for 2^32 + sign*/ |
580 | char* icalvalue_int_as_ical_string(icalvalue* value) { | ||
581 | 647 | ||
648 | static char* icalvalue_int_as_ical_string(const icalvalue* value) { | ||
582 | int data; | 649 | int data; |
583 | char* str = (char*)icalmemory_tmp_buffer(MAX_INT_DIGITS); | 650 | char* str = (char*)icalmemory_tmp_buffer(MAX_INT_DIGITS); |
584 | 651 | ||
585 | icalerror_check_arg_rz( (value!=0),"value"); | 652 | icalerror_check_arg_rz( (value!=0),"value"); |
586 | 653 | ||
587 | data = icalvalue_get_integer(value); | 654 | data = icalvalue_get_integer(value); |
588 | 655 | ||
589 | snprintf(str,MAX_INT_DIGITS,"%d",data); | 656 | snprintf(str,MAX_INT_DIGITS,"%d",data); |
590 | 657 | ||
591 | return str; | 658 | return str; |
592 | } | 659 | } |
593 | #else | ||
594 | // snprintf not working on wintendo | ||
595 | |||
596 | #define MAX_INT_DIGITS 32 /* Enough for 2^32 + sign*/ | ||
597 | char* icalvalue_int_as_ical_string(icalvalue* value) { | ||
598 | |||
599 | int data; | ||
600 | char* str = (char*)icalmemory_tmp_buffer(MAX_INT_DIGITS); | ||
601 | |||
602 | icalerror_check_arg_rz( (value!=0),"value"); | ||
603 | |||
604 | data = icalvalue_get_integer(value); | ||
605 | |||
606 | sprintf(str,"%d",data); | ||
607 | |||
608 | return str; | ||
609 | } | ||
610 | 660 | ||
611 | #endif | 661 | static char* icalvalue_utcoffset_as_ical_string(const icalvalue* value) |
612 | char* icalvalue_utcoffset_as_ical_string(icalvalue* value) | ||
613 | { | 662 | { |
614 | int data,h,m,s; | 663 | int data,h,m,s; |
615 | char sign; | 664 | char sign; |
616 | char* str = (char*)icalmemory_tmp_buffer(9); | 665 | char* str = (char*)icalmemory_tmp_buffer(9); |
617 | 666 | ||
618 | icalerror_check_arg_rz( (value!=0),"value"); | 667 | icalerror_check_arg_rz( (value!=0),"value"); |
@@ -626,115 +675,101 @@ char* icalvalue_utcoffset_as_ical_string(icalvalue* value) | |||
626 | } | 675 | } |
627 | 676 | ||
628 | h = data/3600; | 677 | h = data/3600; |
629 | m = (data - (h*3600))/ 60; | 678 | m = (data - (h*3600))/ 60; |
630 | s = (data - (h*3600) - (m*60)); | 679 | s = (data - (h*3600) - (m*60)); |
631 | 680 | ||
681 | if (s > 0) | ||
632 | sprintf(str,"%c%02d%02d%02d",sign,abs(h),abs(m),abs(s)); | 682 | sprintf(str,"%c%02d%02d%02d",sign,abs(h),abs(m),abs(s)); |
683 | else | ||
684 | sprintf(str,"%c%02d%02d",sign,abs(h),abs(m)); | ||
633 | 685 | ||
634 | return str; | 686 | return str; |
635 | } | 687 | } |
636 | 688 | ||
637 | char* icalvalue_string_as_ical_string(icalvalue* value) { | 689 | static char* icalvalue_string_as_ical_string(const icalvalue* value) { |
638 | 690 | ||
639 | const char* data; | 691 | const char* data; |
640 | char* str = 0; | 692 | char* str = 0; |
641 | icalerror_check_arg_rz( (value!=0),"value"); | 693 | icalerror_check_arg_rz( (value!=0),"value"); |
642 | 694 | data = value->data.v_string; | |
643 | data = ((struct icalvalue_impl*)value)->data.v_string; | ||
644 | 695 | ||
645 | str = (char*)icalmemory_tmp_buffer(strlen(data)+1); | 696 | str = (char*)icalmemory_tmp_buffer(strlen(data)+1); |
646 | 697 | ||
647 | strcpy(str,data); | 698 | strcpy(str,data); |
648 | 699 | ||
649 | return str; | 700 | return str; |
650 | } | 701 | } |
651 | 702 | ||
652 | 703 | ||
653 | char* icalvalue_recur_as_ical_string(icalvalue* value) | 704 | static char* icalvalue_recur_as_ical_string(const icalvalue* value) |
654 | { | 705 | { |
655 | struct icalvalue_impl *impl = (struct icalvalue_impl*)value; | 706 | struct icalrecurrencetype *recur = value->data.v_recur; |
656 | struct icalrecurrencetype *recur = impl->data.v_recur; | ||
657 | 707 | ||
658 | return icalrecurrencetype_as_string(recur); | 708 | return icalrecurrencetype_as_string(recur); |
659 | } | 709 | } |
660 | 710 | ||
661 | char* icalvalue_text_as_ical_string(icalvalue* value) { | 711 | /* @todo This is not RFC2445 compliant. |
712 | * The RFC only allows: | ||
713 | * TSAFE-CHAR = %x20-21 / %x23-2B / %x2D-39 / %x3C-5B / %x5D-7E / NON-US-ASCII | ||
714 | * As such, \t\r\b\f are not allowed, not even escaped | ||
715 | */ | ||
662 | 716 | ||
717 | static char* icalvalue_text_as_ical_string(const icalvalue* value) { | ||
663 | char *str; | 718 | char *str; |
664 | char *str_p; | 719 | char *str_p; |
665 | char *rtrn; | 720 | char *rtrn; |
666 | const char *p; | 721 | const char *p; |
667 | size_t buf_sz; | 722 | size_t buf_sz; |
668 | int line_length; | ||
669 | |||
670 | line_length = 0; | ||
671 | 723 | ||
672 | buf_sz = strlen(((struct icalvalue_impl*)value)->data.v_string)+1; | 724 | buf_sz = strlen(value->data.v_string)+1; |
673 | 725 | ||
674 | str_p = str = (char*)icalmemory_new_buffer(buf_sz); | 726 | str_p = str = (char*)icalmemory_new_buffer(buf_sz); |
675 | 727 | ||
676 | if (str_p == 0){ | 728 | if (str_p == 0){ |
677 | return 0; | 729 | return 0; |
678 | } | 730 | } |
679 | 731 | ||
680 | for(p=((struct icalvalue_impl*)value)->data.v_string; *p!=0; p++){ | 732 | for(p=value->data.v_string; *p!=0; p++){ |
681 | 733 | ||
682 | switch(*p){ | 734 | switch(*p){ |
683 | case '\n': { | 735 | case '\n': { |
684 | icalmemory_append_string(&str,&str_p,&buf_sz,"\\n"); | 736 | icalmemory_append_string(&str,&str_p,&buf_sz,"\\n"); |
685 | line_length+=3; | ||
686 | break; | 737 | break; |
687 | } | 738 | } |
688 | 739 | ||
689 | case '\t': { | 740 | case '\t': { |
690 | icalmemory_append_string(&str,&str_p,&buf_sz,"\\t"); | 741 | icalmemory_append_string(&str,&str_p,&buf_sz,"\\t"); |
691 | line_length+=3; | ||
692 | break; | 742 | break; |
693 | } | 743 | } |
694 | case '\r': { | 744 | case '\r': { |
695 | icalmemory_append_string(&str,&str_p,&buf_sz,"\\r"); | 745 | icalmemory_append_string(&str,&str_p,&buf_sz,"\\r"); |
696 | line_length+=3; | ||
697 | break; | 746 | break; |
698 | } | 747 | } |
699 | case '\b': { | 748 | case '\b': { |
700 | icalmemory_append_string(&str,&str_p,&buf_sz,"\\b"); | 749 | icalmemory_append_string(&str,&str_p,&buf_sz,"\\b"); |
701 | line_length+=3; | ||
702 | break; | 750 | break; |
703 | } | 751 | } |
704 | case '\f': { | 752 | case '\f': { |
705 | icalmemory_append_string(&str,&str_p,&buf_sz,"\\f"); | 753 | icalmemory_append_string(&str,&str_p,&buf_sz,"\\f"); |
706 | line_length+=3; | ||
707 | break; | 754 | break; |
708 | } | 755 | } |
709 | 756 | ||
710 | case ';': | 757 | case ';': |
711 | case ',':{ | 758 | case ',': |
759 | case '"': | ||
760 | case '\\':{ | ||
712 | icalmemory_append_char(&str,&str_p,&buf_sz,'\\'); | 761 | icalmemory_append_char(&str,&str_p,&buf_sz,'\\'); |
713 | icalmemory_append_char(&str,&str_p,&buf_sz,*p); | 762 | icalmemory_append_char(&str,&str_p,&buf_sz,*p); |
714 | line_length+=3; | ||
715 | break; | 763 | break; |
716 | } | 764 | } |
717 | 765 | ||
718 | default: { | 766 | default: { |
719 | icalmemory_append_char(&str,&str_p,&buf_sz,*p); | 767 | icalmemory_append_char(&str,&str_p,&buf_sz,*p); |
720 | line_length++; | ||
721 | } | ||
722 | } | 768 | } |
723 | |||
724 | if (line_length > 65 && *p == ' '){ | ||
725 | icalmemory_append_string(&str,&str_p,&buf_sz,"\n "); | ||
726 | line_length=0; | ||
727 | } | 769 | } |
728 | |||
729 | |||
730 | if (line_length > 75){ | ||
731 | icalmemory_append_string(&str,&str_p,&buf_sz,"\n "); | ||
732 | line_length=0; | ||
733 | } | ||
734 | |||
735 | } | 770 | } |
736 | 771 | ||
737 | /* Assume the last character is not a '\0' and add one. We could | 772 | /* Assume the last character is not a '\0' and add one. We could |
738 | check *str_p != 0, but that would be an uninitialized memory | 773 | check *str_p != 0, but that would be an uninitialized memory |
739 | read. */ | 774 | read. */ |
740 | 775 | ||
@@ -746,73 +781,68 @@ char* icalvalue_text_as_ical_string(icalvalue* value) { | |||
746 | icalmemory_free_buffer(str); | 781 | icalmemory_free_buffer(str); |
747 | 782 | ||
748 | return rtrn; | 783 | return rtrn; |
749 | } | 784 | } |
750 | 785 | ||
751 | 786 | ||
752 | char* icalvalue_attach_as_ical_string(icalvalue* value) { | 787 | static char* |
753 | 788 | icalvalue_attach_as_ical_string(const icalvalue* value) | |
754 | struct icalattachtype *a; | 789 | { |
790 | icalattach *a; | ||
755 | char * str; | 791 | char * str; |
756 | 792 | ||
757 | icalerror_check_arg_rz( (value!=0),"value"); | 793 | icalerror_check_arg_rz( (value!=0),"value"); |
758 | 794 | ||
759 | a = icalvalue_get_attach(value); | 795 | a = icalvalue_get_attach(value); |
760 | 796 | ||
761 | if (a->binary != 0) { | 797 | if (icalattach_get_is_url (a)) { |
762 | return icalvalue_binary_as_ical_string(value); | 798 | const char *url; |
763 | } else if (a->base64 != 0) { | 799 | |
764 | str = (char*)icalmemory_tmp_buffer(strlen(a->base64)+1); | 800 | url = icalattach_get_url (a); |
765 | strcpy(str,a->base64); | 801 | str = icalmemory_tmp_buffer (strlen (url) + 1); |
802 | strcpy (str, url); | ||
766 | return str; | 803 | return str; |
767 | } else if (a->url != 0){ | 804 | } else |
768 | icalvalue *v = icalvalue_new_text( a->url ); | 805 | return icalvalue_binary_as_ical_string (value); |
769 | char *icalstring = icalvalue_string_as_ical_string(v); | ||
770 | icalvalue_free( v ); | ||
771 | return icalstring; | ||
772 | } else { | ||
773 | icalerror_set_errno(ICAL_MALFORMEDDATA_ERROR); | ||
774 | return 0; | ||
775 | } | ||
776 | } | 806 | } |
777 | 807 | ||
778 | 808 | ||
779 | char* icalvalue_duration_as_ical_string(icalvalue* value) { | 809 | static char* icalvalue_duration_as_ical_string(const icalvalue* value) { |
780 | 810 | ||
781 | struct icaldurationtype data; | 811 | struct icaldurationtype data; |
782 | 812 | ||
783 | icalerror_check_arg_rz( (value!=0),"value"); | 813 | icalerror_check_arg_rz( (value!=0),"value"); |
784 | data = icalvalue_get_duration(value); | 814 | data = icalvalue_get_duration(value); |
785 | 815 | ||
786 | return icaldurationtype_as_ical_string(data); | 816 | return icaldurationtype_as_ical_string(data); |
787 | } | 817 | } |
788 | 818 | ||
789 | void print_time_to_string(char* str, struct icaltimetype *data) | 819 | void print_time_to_string(char* str, const struct icaltimetype *data) |
790 | { | 820 | { |
791 | char temp[20]; | 821 | char temp[20]; |
792 | 822 | ||
793 | if (data->is_utc == 1){ | 823 | if (icaltime_is_utc(*data)){ |
794 | sprintf(temp,"%02d%02d%02dZ",data->hour,data->minute,data->second); | 824 | sprintf(temp,"%02d%02d%02dZ",data->hour,data->minute,data->second); |
795 | } else { | 825 | } else { |
796 | sprintf(temp,"%02d%02d%02d",data->hour,data->minute,data->second); | 826 | sprintf(temp,"%02d%02d%02d",data->hour,data->minute,data->second); |
797 | } | 827 | } |
798 | 828 | ||
799 | strcat(str,temp); | 829 | strcat(str,temp); |
800 | } | 830 | } |
801 | 831 | ||
802 | 832 | ||
803 | void print_date_to_string(char* str, struct icaltimetype *data) | 833 | void print_date_to_string(char* str, const struct icaltimetype *data) |
804 | { | 834 | { |
805 | char temp[20]; | 835 | char temp[20]; |
806 | 836 | ||
807 | sprintf(temp,"%04d%02d%02d",data->year,data->month,data->day); | 837 | sprintf(temp,"%04d%02d%02d",data->year,data->month,data->day); |
808 | 838 | ||
809 | strcat(str,temp); | 839 | strcat(str,temp); |
810 | } | 840 | } |
811 | 841 | ||
812 | char* icalvalue_date_as_ical_string(icalvalue* value) { | 842 | static char* icalvalue_date_as_ical_string(const icalvalue* value) { |
813 | 843 | ||
814 | struct icaltimetype data; | 844 | struct icaltimetype data; |
815 | char* str; | 845 | char* str; |
816 | icalerror_check_arg_rz( (value!=0),"value"); | 846 | icalerror_check_arg_rz( (value!=0),"value"); |
817 | data = icalvalue_get_date(value); | 847 | data = icalvalue_get_date(value); |
818 | 848 | ||
@@ -821,21 +851,20 @@ char* icalvalue_date_as_ical_string(icalvalue* value) { | |||
821 | str[0] = 0; | 851 | str[0] = 0; |
822 | print_date_to_string(str,&data); | 852 | print_date_to_string(str,&data); |
823 | 853 | ||
824 | return str; | 854 | return str; |
825 | } | 855 | } |
826 | 856 | ||
827 | void print_datetime_to_string(char* str, struct icaltimetype *data) | 857 | void print_datetime_to_string(char* str, const struct icaltimetype *data) |
828 | { | 858 | { |
829 | print_date_to_string(str,data); | 859 | print_date_to_string(str,data); |
830 | strcat(str,"T"); | 860 | strcat(str,"T"); |
831 | print_time_to_string(str,data); | 861 | print_time_to_string(str,data); |
832 | |||
833 | } | 862 | } |
834 | 863 | ||
835 | const char* icalvalue_datetime_as_ical_string(icalvalue* value) { | 864 | static const char* icalvalue_datetime_as_ical_string(const icalvalue* value) { |
836 | 865 | ||
837 | struct icaltimetype data; | 866 | struct icaltimetype data; |
838 | char* str; | 867 | char* str; |
839 | icalvalue_kind kind = icalvalue_isa(value); | 868 | icalvalue_kind kind = icalvalue_isa(value); |
840 | 869 | ||
841 | icalerror_check_arg_rz( (value!=0),"value"); | 870 | icalerror_check_arg_rz( (value!=0),"value"); |
@@ -856,13 +885,13 @@ const char* icalvalue_datetime_as_ical_string(icalvalue* value) { | |||
856 | print_datetime_to_string(str,&data); | 885 | print_datetime_to_string(str,&data); |
857 | 886 | ||
858 | return str; | 887 | return str; |
859 | 888 | ||
860 | } | 889 | } |
861 | 890 | ||
862 | char* icalvalue_float_as_ical_string(icalvalue* value) { | 891 | static char* icalvalue_float_as_ical_string(const icalvalue* value) { |
863 | 892 | ||
864 | float data; | 893 | float data; |
865 | char* str; | 894 | char* str; |
866 | icalerror_check_arg_rz( (value!=0),"value"); | 895 | icalerror_check_arg_rz( (value!=0),"value"); |
867 | data = icalvalue_get_float(value); | 896 | data = icalvalue_get_float(value); |
868 | 897 | ||
@@ -870,13 +899,13 @@ char* icalvalue_float_as_ical_string(icalvalue* value) { | |||
870 | 899 | ||
871 | sprintf(str,"%f",data); | 900 | sprintf(str,"%f",data); |
872 | 901 | ||
873 | return str; | 902 | return str; |
874 | } | 903 | } |
875 | 904 | ||
876 | char* icalvalue_geo_as_ical_string(icalvalue* value) { | 905 | static char* icalvalue_geo_as_ical_string(const icalvalue* value) { |
877 | 906 | ||
878 | struct icalgeotype data; | 907 | struct icalgeotype data; |
879 | char* str; | 908 | char* str; |
880 | icalerror_check_arg_rz( (value!=0),"value"); | 909 | icalerror_check_arg_rz( (value!=0),"value"); |
881 | 910 | ||
882 | data = icalvalue_get_geo(value); | 911 | data = icalvalue_get_geo(value); |
@@ -885,34 +914,34 @@ char* icalvalue_geo_as_ical_string(icalvalue* value) { | |||
885 | 914 | ||
886 | sprintf(str,"%f;%f",data.lat,data.lon); | 915 | sprintf(str,"%f;%f",data.lat,data.lon); |
887 | 916 | ||
888 | return str; | 917 | return str; |
889 | } | 918 | } |
890 | 919 | ||
891 | const char* icalvalue_datetimeperiod_as_ical_string(icalvalue* value) { | 920 | static const char* icalvalue_datetimeperiod_as_ical_string(const icalvalue* value) { |
892 | struct icaldatetimeperiodtype dtp = icalvalue_get_datetimeperiod(value); | 921 | struct icaldatetimeperiodtype dtp = icalvalue_get_datetimeperiod(value); |
893 | 922 | ||
894 | icalerror_check_arg_rz( (value!=0),"value"); | 923 | icalerror_check_arg_rz( (value!=0),"value"); |
895 | 924 | ||
896 | if(!icaltime_is_null_time(dtp.time)){ | 925 | if(!icaltime_is_null_time(dtp.time)){ |
897 | return icaltime_as_ical_string(dtp.time); | 926 | return icaltime_as_ical_string(dtp.time); |
898 | } else { | 927 | } else { |
899 | return icalperiodtype_as_ical_string(dtp.period); | 928 | return icalperiodtype_as_ical_string(dtp.period); |
900 | } | 929 | } |
901 | } | 930 | } |
902 | 931 | ||
903 | const char* icalvalue_period_as_ical_string(icalvalue* value) { | 932 | static const char* icalvalue_period_as_ical_string(const icalvalue* value) { |
904 | struct icalperiodtype data; | 933 | struct icalperiodtype data; |
905 | icalerror_check_arg_rz( (value!=0),"value"); | 934 | icalerror_check_arg_rz( (value!=0),"value"); |
906 | data = icalvalue_get_period(value); | 935 | data = icalvalue_get_period(value); |
907 | 936 | ||
908 | return icalperiodtype_as_ical_string(data); | 937 | return icalperiodtype_as_ical_string(data); |
909 | 938 | ||
910 | } | 939 | } |
911 | 940 | ||
912 | char* icalvalue_trigger_as_ical_string(icalvalue* value) { | 941 | static const char* icalvalue_trigger_as_ical_string(const icalvalue* value) { |
913 | 942 | ||
914 | struct icaltriggertype data; | 943 | struct icaltriggertype data; |
915 | 944 | ||
916 | icalerror_check_arg_rz( (value!=0),"value"); | 945 | icalerror_check_arg_rz( (value!=0),"value"); |
917 | data = icalvalue_get_trigger(value); | 946 | data = icalvalue_get_trigger(value); |
918 | 947 | ||
@@ -922,23 +951,19 @@ char* icalvalue_trigger_as_ical_string(icalvalue* value) { | |||
922 | return icaldurationtype_as_ical_string(data.duration); | 951 | return icaldurationtype_as_ical_string(data.duration); |
923 | } | 952 | } |
924 | 953 | ||
925 | } | 954 | } |
926 | 955 | ||
927 | const char* | 956 | const char* |
928 | icalvalue_as_ical_string (icalvalue* value) | 957 | icalvalue_as_ical_string(const icalvalue* value) |
929 | { | 958 | { |
930 | struct icalvalue_impl* v = (struct icalvalue_impl*)value; | ||
931 | |||
932 | v=v; | ||
933 | |||
934 | if(value == 0){ | 959 | if(value == 0){ |
935 | return 0; | 960 | return 0; |
936 | } | 961 | } |
937 | 962 | ||
938 | switch (v->kind){ | 963 | switch (value->kind){ |
939 | 964 | ||
940 | case ICAL_ATTACH_VALUE: | 965 | case ICAL_ATTACH_VALUE: |
941 | return icalvalue_attach_as_ical_string(value); | 966 | return icalvalue_attach_as_ical_string(value); |
942 | 967 | ||
943 | case ICAL_BINARY_VALUE: | 968 | case ICAL_BINARY_VALUE: |
944 | return icalvalue_binary_as_ical_string(value); | 969 | return icalvalue_binary_as_ical_string(value); |
@@ -950,12 +975,15 @@ icalvalue_as_ical_string (icalvalue* value) | |||
950 | case ICAL_UTCOFFSET_VALUE: | 975 | case ICAL_UTCOFFSET_VALUE: |
951 | return icalvalue_utcoffset_as_ical_string(value); | 976 | return icalvalue_utcoffset_as_ical_string(value); |
952 | 977 | ||
953 | case ICAL_TEXT_VALUE: | 978 | case ICAL_TEXT_VALUE: |
954 | return icalvalue_text_as_ical_string(value); | 979 | return icalvalue_text_as_ical_string(value); |
955 | 980 | ||
981 | case ICAL_QUERY_VALUE: | ||
982 | return icalvalue_string_as_ical_string(value); | ||
983 | |||
956 | case ICAL_STRING_VALUE: | 984 | case ICAL_STRING_VALUE: |
957 | case ICAL_URI_VALUE: | 985 | case ICAL_URI_VALUE: |
958 | case ICAL_CALADDRESS_VALUE: | 986 | case ICAL_CALADDRESS_VALUE: |
959 | return icalvalue_string_as_ical_string(value); | 987 | return icalvalue_string_as_ical_string(value); |
960 | 988 | ||
961 | case ICAL_DATE_VALUE: | 989 | case ICAL_DATE_VALUE: |
@@ -980,47 +1008,48 @@ icalvalue_as_ical_string (icalvalue* value) | |||
980 | return icalvalue_recur_as_ical_string(value); | 1008 | return icalvalue_recur_as_ical_string(value); |
981 | 1009 | ||
982 | case ICAL_TRIGGER_VALUE: | 1010 | case ICAL_TRIGGER_VALUE: |
983 | return icalvalue_trigger_as_ical_string(value); | 1011 | return icalvalue_trigger_as_ical_string(value); |
984 | 1012 | ||
985 | case ICAL_REQUESTSTATUS_VALUE: | 1013 | case ICAL_REQUESTSTATUS_VALUE: |
986 | return icalreqstattype_as_string(v->data.v_requeststatus); | 1014 | return icalreqstattype_as_string(value->data.v_requeststatus); |
987 | 1015 | ||
988 | case ICAL_ACTION_VALUE: | 1016 | case ICAL_ACTION_VALUE: |
989 | case ICAL_METHOD_VALUE: | 1017 | case ICAL_METHOD_VALUE: |
990 | case ICAL_STATUS_VALUE: | 1018 | case ICAL_STATUS_VALUE: |
991 | case ICAL_TRANSP_VALUE: | 1019 | case ICAL_TRANSP_VALUE: |
992 | case ICAL_CLASS_VALUE: | 1020 | case ICAL_CLASS_VALUE: |
993 | if(v->x_value !=0){ | 1021 | if(value->x_value !=0){ |
994 | return icalmemory_tmp_copy(v->x_value); | 1022 | return icalmemory_tmp_copy(value->x_value); |
995 | } | 1023 | } |
996 | 1024 | ||
997 | return icalproperty_enum_to_string(v->data.v_enum); | 1025 | return icalproperty_enum_to_string(value->data.v_enum); |
998 | 1026 | ||
999 | case ICAL_X_VALUE: | 1027 | case ICAL_X_VALUE: |
1000 | return icalmemory_tmp_copy(v->x_value); | 1028 | if (value->x_value != 0) |
1029 | return icalmemory_tmp_copy(value->x_value); | ||
1030 | |||
1031 | /* FALLTHRU */ | ||
1001 | 1032 | ||
1002 | case ICAL_NO_VALUE: | 1033 | case ICAL_NO_VALUE: |
1003 | default: | 1034 | default: |
1004 | { | 1035 | { |
1005 | return 0; | 1036 | return 0; |
1006 | } | 1037 | } |
1007 | } | 1038 | } |
1008 | } | 1039 | } |
1009 | 1040 | ||
1010 | 1041 | ||
1011 | icalvalue_kind | 1042 | icalvalue_kind |
1012 | icalvalue_isa (icalvalue* value) | 1043 | icalvalue_isa (const icalvalue* value) |
1013 | { | 1044 | { |
1014 | struct icalvalue_impl* v = (struct icalvalue_impl*)value; | ||
1015 | |||
1016 | if(value == 0){ | 1045 | if(value == 0){ |
1017 | return ICAL_NO_VALUE; | 1046 | return ICAL_NO_VALUE; |
1018 | } | 1047 | } |
1019 | 1048 | ||
1020 | return v->kind; | 1049 | return value->kind; |
1021 | } | 1050 | } |
1022 | 1051 | ||
1023 | 1052 | ||
1024 | int | 1053 | int |
1025 | icalvalue_isa_value (void* value) | 1054 | icalvalue_isa_value (void* value) |
1026 | { | 1055 | { |
@@ -1033,29 +1062,32 @@ icalvalue_isa_value (void* value) | |||
1033 | } else { | 1062 | } else { |
1034 | return 0; | 1063 | return 0; |
1035 | } | 1064 | } |
1036 | } | 1065 | } |
1037 | 1066 | ||
1038 | 1067 | ||
1039 | int icalvalue_is_time(icalvalue* a) { | 1068 | static int icalvalue_is_time(const icalvalue* a) { |
1040 | icalvalue_kind kind = icalvalue_isa(a); | 1069 | icalvalue_kind kind = icalvalue_isa(a); |
1041 | 1070 | ||
1042 | if(kind == ICAL_DATETIME_VALUE || | 1071 | if(kind == ICAL_DATETIME_VALUE || |
1043 | kind == ICAL_DATE_VALUE ){ | 1072 | kind == ICAL_DATE_VALUE ){ |
1044 | return 1; | 1073 | return 1; |
1045 | } | 1074 | } |
1046 | 1075 | ||
1047 | return 0; | 1076 | return 0; |
1048 | 1077 | ||
1049 | } | 1078 | } |
1050 | 1079 | ||
1080 | /* | ||
1081 | * In case of error, this function returns 0. This is partly bogus, as 0 is | ||
1082 | * not part of the returned enum. | ||
1083 | * FIXME We should probably add an error value to the enum. | ||
1084 | */ | ||
1051 | icalparameter_xliccomparetype | 1085 | icalparameter_xliccomparetype |
1052 | icalvalue_compare(icalvalue* a, icalvalue *b) | 1086 | icalvalue_compare(const icalvalue* a, const icalvalue *b) |
1053 | { | 1087 | { |
1054 | struct icalvalue_impl *impla = (struct icalvalue_impl *)a; | ||
1055 | struct icalvalue_impl *implb = (struct icalvalue_impl *)b; | ||
1056 | 1088 | ||
1057 | icalerror_check_arg_rz( (a!=0), "a"); | 1089 | icalerror_check_arg_rz( (a!=0), "a"); |
1058 | icalerror_check_arg_rz( (b!=0), "b"); | 1090 | icalerror_check_arg_rz( (b!=0), "b"); |
1059 | 1091 | ||
1060 | /* Not the same type; they can only be unequal */ | 1092 | /* Not the same type; they can only be unequal */ |
1061 | if( ! (icalvalue_is_time(a) && icalvalue_is_time(b)) && | 1093 | if( ! (icalvalue_is_time(a) && icalvalue_is_time(b)) && |
@@ -1063,54 +1095,76 @@ icalvalue_compare(icalvalue* a, icalvalue *b) | |||
1063 | return ICAL_XLICCOMPARETYPE_NOTEQUAL; | 1095 | return ICAL_XLICCOMPARETYPE_NOTEQUAL; |
1064 | } | 1096 | } |
1065 | 1097 | ||
1066 | switch (icalvalue_isa(a)){ | 1098 | switch (icalvalue_isa(a)){ |
1067 | 1099 | ||
1068 | case ICAL_ATTACH_VALUE: | 1100 | case ICAL_ATTACH_VALUE: |
1101 | { | ||
1102 | if (icalattach_get_is_url(a->data.v_attach) && | ||
1103 | icalattach_get_is_url(b->data.v_attach)) { | ||
1104 | if (strcasecmp(icalattach_get_url(a->data.v_attach), | ||
1105 | icalattach_get_url(b->data.v_attach)) == 0) | ||
1106 | return ICAL_XLICCOMPARETYPE_EQUAL; | ||
1107 | else | ||
1108 | return ICAL_XLICCOMPARETYPE_NOTEQUAL; | ||
1109 | } | ||
1110 | else { | ||
1111 | if (a->data.v_attach == b->data.v_attach) | ||
1112 | return ICAL_XLICCOMPARETYPE_EQUAL; | ||
1113 | else | ||
1114 | return ICAL_XLICCOMPARETYPE_NOTEQUAL; | ||
1115 | } | ||
1116 | } | ||
1069 | case ICAL_BINARY_VALUE: | 1117 | case ICAL_BINARY_VALUE: |
1118 | { | ||
1119 | if (a->data.v_attach == b->data.v_attach) | ||
1120 | return ICAL_XLICCOMPARETYPE_EQUAL; | ||
1121 | else | ||
1122 | return ICAL_XLICCOMPARETYPE_NOTEQUAL; | ||
1123 | } | ||
1070 | 1124 | ||
1071 | case ICAL_BOOLEAN_VALUE: | 1125 | case ICAL_BOOLEAN_VALUE: |
1072 | { | 1126 | { |
1073 | if (icalvalue_get_boolean(a) == icalvalue_get_boolean(b)){ | 1127 | if (icalvalue_get_boolean(a) == icalvalue_get_boolean(b)){ |
1074 | return ICAL_XLICCOMPARETYPE_EQUAL; | 1128 | return ICAL_XLICCOMPARETYPE_EQUAL; |
1075 | } else { | 1129 | } else { |
1076 | return ICAL_XLICCOMPARETYPE_NOTEQUAL; | 1130 | return ICAL_XLICCOMPARETYPE_NOTEQUAL; |
1077 | } | 1131 | } |
1078 | } | 1132 | } |
1079 | 1133 | ||
1080 | case ICAL_FLOAT_VALUE: | 1134 | case ICAL_FLOAT_VALUE: |
1081 | { | 1135 | { |
1082 | if (impla->data.v_float > implb->data.v_float){ | 1136 | if (a->data.v_float > b->data.v_float){ |
1083 | return ICAL_XLICCOMPARETYPE_GREATER; | 1137 | return ICAL_XLICCOMPARETYPE_GREATER; |
1084 | } else if (impla->data.v_float < implb->data.v_float){ | 1138 | } else if (a->data.v_float < b->data.v_float){ |
1085 | return ICAL_XLICCOMPARETYPE_LESS; | 1139 | return ICAL_XLICCOMPARETYPE_LESS; |
1086 | } else { | 1140 | } else { |
1087 | return ICAL_XLICCOMPARETYPE_EQUAL; | 1141 | return ICAL_XLICCOMPARETYPE_EQUAL; |
1088 | } | 1142 | } |
1089 | } | 1143 | } |
1090 | 1144 | ||
1091 | case ICAL_INTEGER_VALUE: | 1145 | case ICAL_INTEGER_VALUE: |
1092 | case ICAL_UTCOFFSET_VALUE: | 1146 | case ICAL_UTCOFFSET_VALUE: |
1093 | { | 1147 | { |
1094 | if (impla->data.v_int > implb->data.v_int){ | 1148 | if (a->data.v_int > b->data.v_int){ |
1095 | return ICAL_XLICCOMPARETYPE_GREATER; | 1149 | return ICAL_XLICCOMPARETYPE_GREATER; |
1096 | } else if (impla->data.v_int < implb->data.v_int){ | 1150 | } else if (a->data.v_int < b->data.v_int){ |
1097 | return ICAL_XLICCOMPARETYPE_LESS; | 1151 | return ICAL_XLICCOMPARETYPE_LESS; |
1098 | } else { | 1152 | } else { |
1099 | return ICAL_XLICCOMPARETYPE_EQUAL; | 1153 | return ICAL_XLICCOMPARETYPE_EQUAL; |
1100 | } | 1154 | } |
1101 | } | 1155 | } |
1102 | 1156 | ||
1103 | case ICAL_DURATION_VALUE: | 1157 | case ICAL_DURATION_VALUE: |
1104 | { | 1158 | { |
1105 | int a = icaldurationtype_as_int(impla->data.v_duration); | 1159 | int dur_a = icaldurationtype_as_int(a->data.v_duration); |
1106 | int b = icaldurationtype_as_int(implb->data.v_duration); | 1160 | int dur_b = icaldurationtype_as_int(b->data.v_duration); |
1107 | 1161 | ||
1108 | if (a > b){ | 1162 | if (dur_a > dur_b){ |
1109 | return ICAL_XLICCOMPARETYPE_GREATER; | 1163 | return ICAL_XLICCOMPARETYPE_GREATER; |
1110 | } else if (a < b){ | 1164 | } else if (dur_a < dur_b){ |
1111 | return ICAL_XLICCOMPARETYPE_LESS; | 1165 | return ICAL_XLICCOMPARETYPE_LESS; |
1112 | } else { | 1166 | } else { |
1113 | return ICAL_XLICCOMPARETYPE_EQUAL; | 1167 | return ICAL_XLICCOMPARETYPE_EQUAL; |
1114 | } | 1168 | } |
1115 | } | 1169 | } |
1116 | 1170 | ||
@@ -1119,12 +1173,14 @@ icalvalue_compare(icalvalue* a, icalvalue *b) | |||
1119 | case ICAL_URI_VALUE: | 1173 | case ICAL_URI_VALUE: |
1120 | case ICAL_CALADDRESS_VALUE: | 1174 | case ICAL_CALADDRESS_VALUE: |
1121 | case ICAL_TRIGGER_VALUE: | 1175 | case ICAL_TRIGGER_VALUE: |
1122 | case ICAL_DATE_VALUE: | 1176 | case ICAL_DATE_VALUE: |
1123 | case ICAL_DATETIME_VALUE: | 1177 | case ICAL_DATETIME_VALUE: |
1124 | case ICAL_DATETIMEPERIOD_VALUE: | 1178 | case ICAL_DATETIMEPERIOD_VALUE: |
1179 | case ICAL_QUERY_VALUE: | ||
1180 | case ICAL_RECUR_VALUE: | ||
1125 | { | 1181 | { |
1126 | int r; | 1182 | int r; |
1127 | 1183 | ||
1128 | r = strcmp(icalvalue_as_ical_string(a), | 1184 | r = strcmp(icalvalue_as_ical_string(a), |
1129 | icalvalue_as_ical_string(b)); | 1185 | icalvalue_as_ical_string(b)); |
1130 | 1186 | ||
@@ -1156,60 +1212,98 @@ icalvalue_compare(icalvalue* a, icalvalue *b) | |||
1156 | } else { | 1212 | } else { |
1157 | return ICAL_XLICCOMPARETYPE_NOTEQUAL; | 1213 | return ICAL_XLICCOMPARETYPE_NOTEQUAL; |
1158 | } | 1214 | } |
1159 | 1215 | ||
1160 | } | 1216 | } |
1161 | 1217 | ||
1218 | case ICAL_TRANSP_VALUE: | ||
1219 | { | ||
1220 | if (icalvalue_get_transp(a) == icalvalue_get_transp(b)){ | ||
1221 | return ICAL_XLICCOMPARETYPE_EQUAL; | ||
1222 | } else { | ||
1223 | return ICAL_XLICCOMPARETYPE_NOTEQUAL; | ||
1224 | } | ||
1225 | } | ||
1226 | |||
1227 | case ICAL_ACTION_VALUE: | ||
1228 | { | ||
1229 | if (icalvalue_get_action(a) == icalvalue_get_action(b)){ | ||
1230 | return ICAL_XLICCOMPARETYPE_EQUAL; | ||
1231 | } else { | ||
1232 | return ICAL_XLICCOMPARETYPE_NOTEQUAL; | ||
1233 | } | ||
1234 | } | ||
1235 | |||
1162 | case ICAL_PERIOD_VALUE: | 1236 | case ICAL_PERIOD_VALUE: |
1163 | case ICAL_GEO_VALUE: | 1237 | case ICAL_GEO_VALUE: |
1164 | case ICAL_RECUR_VALUE: | ||
1165 | case ICAL_NO_VALUE: | 1238 | case ICAL_NO_VALUE: |
1166 | default: | 1239 | default: |
1167 | { | 1240 | { |
1168 | icalerror_warn("Comparison not implemented for value type"); | 1241 | icalerror_warn("Comparison not implemented for value type"); |
1169 | return ICAL_XLICCOMPARETYPE_REGEX+1; /* HACK */ | 1242 | return 0; |
1170 | } | 1243 | } |
1171 | } | 1244 | } |
1172 | 1245 | ||
1173 | } | 1246 | } |
1174 | 1247 | ||
1175 | /* Examine the value and possiby chage the kind to agree with the value */ | 1248 | /** Examine the value and possibly change the kind to agree with the |
1249 | * value | ||
1250 | */ | ||
1251 | |||
1176 | void icalvalue_reset_kind(icalvalue* value) | 1252 | void icalvalue_reset_kind(icalvalue* value) |
1177 | { | 1253 | { |
1178 | struct icalvalue_impl* impl = (struct icalvalue_impl*)value; | 1254 | if( (value->kind==ICAL_DATETIME_VALUE || value->kind==ICAL_DATE_VALUE )&& |
1179 | 1255 | !icaltime_is_null_time(value->data.v_time) ) { | |
1180 | if( (impl->kind==ICAL_DATETIME_VALUE || impl->kind==ICAL_DATE_VALUE )&& | ||
1181 | !icaltime_is_null_time(impl->data.v_time) ) { | ||
1182 | 1256 | ||
1183 | if( impl->data.v_time.is_date == 1){ | 1257 | if(icaltime_is_date(value->data.v_time)){ |
1184 | impl->kind = ICAL_DATE_VALUE; | 1258 | value->kind = ICAL_DATE_VALUE; |
1185 | } else { | 1259 | } else { |
1186 | impl->kind = ICAL_DATETIME_VALUE; | 1260 | value->kind = ICAL_DATETIME_VALUE; |
1187 | } | 1261 | } |
1188 | } | 1262 | } |
1189 | 1263 | ||
1190 | } | 1264 | } |
1191 | 1265 | ||
1192 | void icalvalue_set_parent(icalvalue* value, | 1266 | void icalvalue_set_parent(icalvalue* value, |
1193 | icalproperty* property) | 1267 | icalproperty* property) |
1194 | { | 1268 | { |
1195 | struct icalvalue_impl* v = (struct icalvalue_impl*)value; | 1269 | value->parent = property; |
1196 | |||
1197 | v->parent = property; | ||
1198 | |||
1199 | } | 1270 | } |
1200 | 1271 | ||
1201 | icalproperty* icalvalue_get_parent(icalvalue* value) | 1272 | icalproperty* icalvalue_get_parent(icalvalue* value) |
1202 | { | 1273 | { |
1203 | struct icalvalue_impl* v = (struct icalvalue_impl*)value; | 1274 | return value->parent; |
1275 | } | ||
1276 | |||
1277 | |||
1278 | int icalvalue_encode_ical_string(const char *szText, char *szEncText, int nMaxBufferLen) | ||
1279 | { | ||
1280 | char *ptr; | ||
1281 | icalvalue *value = 0; | ||
1282 | |||
1283 | if ((szText == 0) || (szEncText == 0)) | ||
1284 | return 0; | ||
1204 | 1285 | ||
1286 | value = icalvalue_new_from_string(ICAL_STRING_VALUE, szText); | ||
1205 | 1287 | ||
1206 | return v->parent; | 1288 | if (value == 0) |
1289 | return 0; | ||
1290 | |||
1291 | ptr = icalvalue_text_as_ical_string(value); | ||
1292 | if (ptr == 0) | ||
1293 | return 0; | ||
1294 | |||
1295 | if ((int)strlen(ptr) >= nMaxBufferLen) | ||
1296 | { | ||
1297 | icalvalue_free (value); | ||
1298 | return 0; | ||
1207 | } | 1299 | } |
1208 | 1300 | ||
1301 | strcpy(szEncText, ptr); | ||
1209 | 1302 | ||
1303 | icalvalue_free ((icalvalue*)value); | ||
1304 | |||
1305 | return 1; | ||
1306 | } | ||
1210 | 1307 | ||
1211 | /* The remaining interfaces are 'new', 'set' and 'get' for each of the value | 1308 | /* The remaining interfaces are 'new', 'set' and 'get' for each of the value |
1212 | types */ | 1309 | types */ |
1213 | |||
1214 | |||
1215 | /* Everything below this line is machine generated. Do not edit. */ | ||