Diffstat (limited to 'libical/src/libical/icalvalue.c') (more/less context) (ignore whitespace changes)
-rw-r--r-- | libical/src/libical/icalvalue.c | 518 |
1 files changed, 306 insertions, 212 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,4 +1,5 @@ | |||
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 |
@@ -46,7 +47,10 @@ | |||
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" |
@@ -54,16 +58,18 @@ int snprintf(char *str, size_t n, char const *fmt, ...); | |||
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); |
@@ -90,10 +96,8 @@ icalvalue_new (icalvalue_kind kind) | |||
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 | ||
@@ -101,21 +105,25 @@ icalvalue* icalvalue_new_clone(icalvalue* value){ | |||
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: |
@@ -146,6 +154,19 @@ icalvalue* icalvalue_new_clone(icalvalue* value){ | |||
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 |
@@ -158,7 +179,7 @@ icalvalue* icalvalue_new_clone(icalvalue* value){ | |||
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); |
@@ -183,18 +204,39 @@ char* icalmemory_strdup_and_dequote(const char* str) | |||
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; |
@@ -217,9 +259,16 @@ char* icalmemory_strdup_and_dequote(const char* str) | |||
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( |
@@ -242,7 +291,6 @@ icalvalue* icalvalue_new_from_string_with_error(icalvalue_kind kind,const char* | |||
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 | ||
@@ -253,12 +301,19 @@ icalvalue* icalvalue_new_from_string_with_error(icalvalue_kind kind,const char* | |||
253 | switch (kind){ | 301 | switch (kind){ |
254 | 302 | ||
255 | case ICAL_ATTACH_VALUE: | 303 | case ICAL_ATTACH_VALUE: |
256 | attach = icalattachtype_new(); | 304 | { |
257 | value = icalvalue_new_attach( attach ); | 305 | icalattach *attach; |
258 | icalattachtype_free( attach ); | 306 | |
259 | icalattachtype_set_url( value->data.v_attach, str ); | 307 | attach = icalattach_new_from_url (str); |
260 | break; | 308 | if (!attach) |
261 | case ICAL_BINARY_VALUE: | 309 | break; |
310 | |||
311 | value = icalvalue_new_attach (attach); | ||
312 | icalattach_unref (attach); | ||
313 | break; | ||
314 | } | ||
315 | |||
316 | case ICAL_BINARY_VALUE: | ||
262 | case ICAL_BOOLEAN_VALUE: | 317 | case ICAL_BOOLEAN_VALUE: |
263 | { | 318 | { |
264 | /* HACK */ | 319 | /* HACK */ |
@@ -267,7 +322,7 @@ icalvalue* icalvalue_new_from_string_with_error(icalvalue_kind kind,const char* | |||
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( |
@@ -279,37 +334,50 @@ icalvalue* icalvalue_new_from_string_with_error(icalvalue_kind kind,const char* | |||
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); |
292 | break; | 347 | break; |
348 | |||
349 | case ICAL_QUERY_VALUE: | ||
350 | value = icalvalue_new_query(str); | ||
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 | { | 363 | value = icalvalue_new_float((float)atof(str)); |
306 | value = icalvalue_new_float((float )atof(str)); | ||
307 | break; | 364 | break; |
308 | } | 365 | |
309 | |||
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 | ||
@@ -321,28 +389,19 @@ icalvalue* icalvalue_new_from_string_with_error(icalvalue_kind kind,const char* | |||
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 | ||
@@ -350,16 +409,15 @@ icalvalue* icalvalue_new_from_string_with_error(icalvalue_kind kind,const char* | |||
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"); |
352 | *error = icalproperty_vanew_xlicerror( | 411 | *error = icalproperty_vanew_xlicerror( |
353 | temp, | 412 | temp, |
354 | icalparameter_new_xlicerrortype( | 413 | icalparameter_new_xlicerrortype( |
355 | ICAL_XLICERRORTYPE_VALUEPARSEERROR), | 414 | ICAL_XLICERRORTYPE_VALUEPARSEERROR), |
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 | { |
@@ -391,14 +449,17 @@ icalvalue* icalvalue_new_from_string_with_error(icalvalue_kind kind,const char* | |||
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); | 452 | |
395 | |||
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 | ||
@@ -406,9 +467,7 @@ icalvalue* icalvalue_new_from_string_with_error(icalvalue_kind kind,const char* | |||
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 | ||
@@ -429,7 +488,7 @@ icalvalue* icalvalue_new_from_string_with_error(icalvalue_kind kind,const char* | |||
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; |
@@ -444,9 +503,17 @@ icalvalue* icalvalue_new_from_string_with_error(icalvalue_kind kind,const char* | |||
444 | break; | 503 | break; |
445 | 504 | ||
446 | } | 505 | } |
506 | |||
507 | case ICAL_X_VALUE: | ||
508 | { | ||
509 | char* dequoted_str = icalmemory_strdup_and_dequote(str); | ||
510 | value = icalvalue_new_x(dequoted_str); | ||
511 | free(dequoted_str); | ||
512 | } | ||
513 | break; | ||
514 | |||
447 | default: | 515 | default: |
448 | { | 516 | { |
449 | |||
450 | if (error != 0 ){ | 517 | if (error != 0 ){ |
451 | char temp[TMP_BUF_SIZE]; | 518 | char temp[TMP_BUF_SIZE]; |
452 | 519 | ||
@@ -484,17 +551,15 @@ icalvalue* icalvalue_new_from_string_with_error(icalvalue_kind kind,const char* | |||
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"); |
@@ -510,15 +575,19 @@ icalvalue_free (icalvalue* 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); |
@@ -550,10 +619,8 @@ icalvalue_free (icalvalue* value) | |||
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 | } |
@@ -561,7 +628,7 @@ icalvalue_is_valid (icalvalue* value) | |||
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; |
@@ -575,10 +642,10 @@ char* icalvalue_binary_as_ical_string(icalvalue* value) { | |||
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 | ||
@@ -590,26 +657,8 @@ char* icalvalue_int_as_ical_string(icalvalue* value) { | |||
590 | 657 | ||
591 | return str; | 658 | return str; |
592 | } | 659 | } |
593 | #else | ||
594 | // snprintf not working on wintendo | ||
595 | 660 | ||
596 | #define MAX_INT_DIGITS 32 /* Enough for 2^32 + sign*/ | 661 | static char* icalvalue_utcoffset_as_ical_string(const icalvalue* value) |
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 | |||
611 | #endif | ||
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; |
@@ -629,18 +678,20 @@ char* icalvalue_utcoffset_as_ical_string(icalvalue* value) | |||
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 | ||
632 | sprintf(str,"%c%02d%02d%02d",sign,abs(h),abs(m),abs(s)); | 681 | if (s > 0) |
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 | ||
@@ -650,26 +701,27 @@ char* icalvalue_string_as_ical_string(icalvalue* value) { | |||
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 | ||
@@ -677,61 +729,44 @@ char* icalvalue_text_as_ical_string(icalvalue* value) { | |||
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 | } | 768 | } |
722 | } | 769 | } |
723 | |||
724 | if (line_length > 65 && *p == ' '){ | ||
725 | icalmemory_append_string(&str,&str_p,&buf_sz,"\n "); | ||
726 | line_length=0; | ||
727 | } | ||
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 |
@@ -749,34 +784,29 @@ char* icalvalue_text_as_ical_string(icalvalue* value) { | |||
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 | ||
@@ -786,11 +816,11 @@ char* icalvalue_duration_as_ical_string(icalvalue* value) { | |||
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); |
@@ -800,7 +830,7 @@ void print_time_to_string(char* str, struct icaltimetype *data) | |||
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 | ||
@@ -809,7 +839,7 @@ void print_date_to_string(char* str, struct icaltimetype *data) | |||
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; |
@@ -824,15 +854,14 @@ char* icalvalue_date_as_ical_string(icalvalue* value) { | |||
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; |
@@ -859,7 +888,7 @@ const char* icalvalue_datetime_as_ical_string(icalvalue* value) { | |||
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; |
@@ -873,7 +902,7 @@ char* icalvalue_float_as_ical_string(icalvalue* value) { | |||
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; |
@@ -888,7 +917,7 @@ char* icalvalue_geo_as_ical_string(icalvalue* value) { | |||
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"); |
@@ -900,7 +929,7 @@ const char* icalvalue_datetimeperiod_as_ical_string(icalvalue* value) { | |||
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); |
@@ -909,7 +938,7 @@ const char* icalvalue_period_as_ical_string(icalvalue* value) { | |||
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 | ||
@@ -925,17 +954,13 @@ char* icalvalue_trigger_as_ical_string(icalvalue* value) { | |||
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); |
@@ -953,6 +978,9 @@ icalvalue_as_ical_string (icalvalue* value) | |||
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: |
@@ -983,21 +1011,24 @@ icalvalue_as_ical_string (icalvalue* 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: |
@@ -1009,15 +1040,13 @@ icalvalue_as_ical_string (icalvalue* value) | |||
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 | ||
@@ -1036,7 +1065,7 @@ icalvalue_isa_value (void* value) | |||
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 || |
@@ -1048,11 +1077,14 @@ int icalvalue_is_time(icalvalue* a) { | |||
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"); |
@@ -1066,7 +1098,29 @@ icalvalue_compare(icalvalue* a, icalvalue *b) | |||
1066 | switch (icalvalue_isa(a)){ | 1098 | switch (icalvalue_isa(a)){ |
1067 | 1099 | ||
1068 | case ICAL_ATTACH_VALUE: | 1100 | case ICAL_ATTACH_VALUE: |
1069 | case ICAL_BINARY_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 | } | ||
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 | { |
@@ -1079,9 +1133,9 @@ icalvalue_compare(icalvalue* a, icalvalue *b) | |||
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; |
@@ -1091,9 +1145,9 @@ icalvalue_compare(icalvalue* a, icalvalue *b) | |||
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; |
@@ -1102,12 +1156,12 @@ icalvalue_compare(icalvalue* a, icalvalue *b) | |||
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; |
@@ -1122,6 +1176,8 @@ icalvalue_compare(icalvalue* a, icalvalue *b) | |||
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 | ||
@@ -1159,31 +1215,49 @@ icalvalue_compare(icalvalue* a, icalvalue *b) | |||
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 | ||
@@ -1192,24 +1266,44 @@ void icalvalue_reset_kind(icalvalue* value) | |||
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 | } | ||
1204 | 1276 | ||
1205 | 1277 | ||
1206 | return v->parent; | 1278 | int icalvalue_encode_ical_string(const char *szText, char *szEncText, int nMaxBufferLen) |
1207 | } | 1279 | { |
1280 | char *ptr; | ||
1281 | icalvalue *value = 0; | ||
1282 | |||
1283 | if ((szText == 0) || (szEncText == 0)) | ||
1284 | return 0; | ||
1285 | |||
1286 | value = icalvalue_new_from_string(ICAL_STRING_VALUE, szText); | ||
1287 | |||
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; | ||
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. */ | ||