Libical API Documentation 4.0 STABLE VERSION [Visit the v3.0 documentation]
Loading...
Searching...
No Matches
icalcomponent.c
Go to the documentation of this file.
1/*======================================================================
2 FILE: icalcomponent.c
3 CREATOR: eric 28 April 1999
4
5 SPDX-FileCopyrightText: 2000, Eric Busboom <eric@civicknowledge.com>
6 SPDX-License-Identifier: LGPL-2.1-only OR MPL-2.0
7======================================================================*/
8
13
14#ifdef HAVE_CONFIG_H
15#include <config.h>
16#endif
17
18#include "icalcomponent.h"
19#include "icalerror_p.h"
20#include "icalerror.h"
21#include "icallimits.h"
22#include "icalmemory.h"
23#include "icalparser.h"
24#include "icalpvl_p.h"
25#include "icalrestriction.h"
26#include "icaltime_p.h"
27#include "icaltimezone.h"
28#include "icaltypes_p.h"
29
30#include <assert.h>
31#include <ctype.h>
32#include <stdlib.h>
33#include <limits.h>
34
35struct icalcomponent_impl {
36 icalstructuretype id;
38 char *x_name; /* also used for ICAL_IANA_COMPONENT */
39 icalpvl_list properties;
40 icalpvl_elem property_iterator;
41 icalpvl_list components;
42 icalpvl_elem component_iterator;
43 struct icalcomponent_impl *parent;
44
49 icalarray *timezones;
50 int timezones_sorted;
51};
52
53static void icalcomponent_add_children(icalcomponent *impl, va_list args);
54static icalcomponent *icalcomponent_new_impl(icalcomponent_kind kind);
55
56static bool icalcomponent_merge_vtimezone(icalcomponent *comp,
57 icalcomponent *vtimezone, icalstrarray *tzids_to_rename);
58static bool icalcomponent_handle_conflicting_vtimezones(icalcomponent *comp,
59 icalcomponent *vtimezone,
60 icalproperty *tzid_prop,
61 const char *tzid,
62 icalstrarray *tzids_to_rename);
63static size_t icalcomponent_get_tzid_prefix_len(const char *tzid);
64static void icalcomponent_rename_tzids(icalcomponent *comp, icalstrarray *rename_table);
65static void icalcomponent_rename_tzids_callback(icalparameter *param, void *data);
66static int icalcomponent_compare_vtimezones(icalcomponent *vtimezone1, icalcomponent *vtimezone2);
67static int icalcomponent_compare_timezone_fn(const void *elem1, const void *elem2);
68
69void icalcomponent_add_children(icalcomponent *impl, va_list args)
70{
71 void *vp;
72
73 while ((vp = va_arg(args, void *)) != 0) {
75
77 icalcomponent_add_component(impl, (icalcomponent *)vp);
78
79 } else if (icalproperty_isa_property(vp)) {
80 icalcomponent_add_property(impl, (icalproperty *)vp);
81 }
82 }
83}
84
85static icalcomponent *icalcomponent_new_impl(icalcomponent_kind kind)
86{
87 icalcomponent *comp;
88
89 if (!icalcomponent_kind_is_valid(kind)) {
90 return NULL;
91 }
92
93 if ((comp = (icalcomponent *)icalmemory_new_buffer(sizeof(icalcomponent))) == 0) {
95 return 0;
96 }
97
98 memset(comp, 0, sizeof(icalcomponent));
99
100 comp->id = ICAL_STRUCTURE_TYPE_COMPONENT;
101 comp->kind = kind;
102 comp->properties = icalpvl_newlist();
103 comp->components = icalpvl_newlist();
104 comp->timezones_sorted = 1;
105
106 return comp;
107}
108
110{
111 return icalcomponent_new_impl(kind);
112}
113
115{
116 /* See https://github.com/libical/libical/issues/585. Caller must pass NULL as final argument */
117
118 va_list args;
119
120 icalcomponent *impl = icalcomponent_new_impl(kind);
121
122 if (impl == 0) {
123 return 0;
124 }
125
126 va_start(args, kind);
127 icalcomponent_add_children(impl, args);
128 va_end(args);
129
130 return impl;
131}
132
133icalcomponent *icalcomponent_new_from_string(const char *str)
134{
135 return icalparser_parse_string(str);
136}
137
138icalcomponent *icalcomponent_clone(const icalcomponent *old)
139{
140 icalcomponent *clone;
141 const icalcomponent *c;
142 const icalproperty *p;
143 icalpvl_elem itr;
144
145 icalerror_check_arg_rz((old != 0), "component");
146
147 clone = icalcomponent_new_impl(old->kind);
148
149 if (clone == 0) {
150 return 0;
151 }
152
153 if (old->x_name) {
154 clone->x_name = icalmemory_strdup(old->x_name);
155 }
156
157 for (itr = icalpvl_head(old->properties); itr != 0; itr = icalpvl_next(itr)) {
158 p = (icalproperty *)icalpvl_data(itr);
160 }
161
162 for (itr = icalpvl_head(old->components); itr != 0; itr = icalpvl_next(itr)) {
163 c = (icalcomponent *)icalpvl_data(itr);
165 }
166
167 return clone;
168}
169
170icalcomponent *icalcomponent_new_x(const char *x_name)
171{
172 icalcomponent *comp = icalcomponent_new_impl(ICAL_X_COMPONENT);
173
174 if (!comp) {
175 return 0;
176 }
177 comp->x_name = icalmemory_strdup(x_name);
178 return comp;
179}
180
181icalcomponent *icalcomponent_new_iana(const char *iana_name)
182{
183 icalcomponent *comp = icalcomponent_new_impl(ICAL_IANA_COMPONENT);
184
185 if (!comp) {
186 return 0;
187 }
188 comp->x_name = icalmemory_strdup(iana_name);
189 return comp;
190}
191
192void icalcomponent_free(icalcomponent *c)
193{
194 icalcomponent *comp;
195
196 icalerror_check_arg_rv((c != 0), "component");
197
198 if (c->parent != 0) {
199 return;
200 }
201
202 if (c->properties != 0) {
203 icalproperty *prop;
204 while ((prop = icalpvl_pop(c->properties)) != 0) {
206 icalproperty_free(prop);
207 }
208 icalpvl_free(c->properties);
209 }
210
211 while ((comp = icalpvl_data(icalpvl_head(c->components))) != 0) {
213 icalcomponent_free(comp);
214 }
215
216 icalpvl_free(c->components);
217
218 icalmemory_free_buffer(c->x_name);
219
220 icaltimezone_array_free(c->timezones);
221 c->timezones = 0;
222
223 c->kind = ICAL_NO_COMPONENT;
224 c->properties = 0;
225 c->property_iterator = 0;
226 c->components = 0;
227 c->component_iterator = 0;
228 c->x_name = 0;
229 c->id = ICAL_STRUCTURE_TYPE_COMPONENT_EMPTY;
230 c->timezones = NULL;
231
233}
234
235char *icalcomponent_as_ical_string(const icalcomponent *component)
236{
237 char *buf;
238
239 buf = icalcomponent_as_ical_string_r(component);
240 if (buf) {
242 }
243 return buf;
244}
245
246char *icalcomponent_as_ical_string_r(const icalcomponent *component)
247{
248 char *buf;
249 size_t buf_size = 1024;
250 char *buf_ptr = 0;
251 icalpvl_elem itr;
252
253 /* RFC5545 explicitly says that the newline is *ALWAYS* a \r\n (CRLF)!!!! */
254 const char newline[] = "\r\n";
255
256 const icalcomponent *c;
257 icalproperty *p;
258 icalcomponent_kind kind = icalcomponent_isa(component);
259
260 const char *kind_string;
261
262 icalerror_check_arg_rz((component != 0), "component");
263 icalerror_check_arg_rz((kind != ICAL_NO_COMPONENT), "component kind is ICAL_NO_COMPONENT");
264
265 if (kind == ICAL_X_COMPONENT || kind == ICAL_IANA_COMPONENT) {
266 kind_string = component->x_name;
267 } else {
268 kind_string = icalcomponent_kind_to_string(kind);
269 }
270
271 icalerror_check_arg_rz((kind_string != 0), "Unknown kind of component");
272
273 buf = icalmemory_new_buffer(buf_size);
274 if (buf == NULL) {
275 return NULL;
276 }
277
278 buf_ptr = buf;
279
280 icalmemory_append_string(&buf, &buf_ptr, &buf_size, "BEGIN:");
281 icalmemory_append_string(&buf, &buf_ptr, &buf_size, kind_string);
282 icalmemory_append_string(&buf, &buf_ptr, &buf_size, newline);
283
284 for (itr = icalpvl_head(component->properties); itr != 0; itr = icalpvl_next(itr)) {
285 char *tmp_buf;
286
287 p = (icalproperty *)icalpvl_data(itr);
288
289 icalerror_assert((p != 0), "Got a null property");
291
292 icalmemory_append_string(&buf, &buf_ptr, &buf_size, tmp_buf);
293 icalmemory_free_buffer(tmp_buf);
294 }
295
296 for (itr = icalpvl_head(component->components); itr != 0; itr = icalpvl_next(itr)) {
297 char *tmp_buf;
298
299 c = (icalcomponent *)icalpvl_data(itr);
300
302 if (tmp_buf != NULL) {
303 icalmemory_append_string(&buf, &buf_ptr, &buf_size, tmp_buf);
304 icalmemory_free_buffer(tmp_buf);
305 }
306 }
307
308 icalmemory_append_string(&buf, &buf_ptr, &buf_size, "END:");
309 icalmemory_append_string(&buf, &buf_ptr, &buf_size, kind_string);
310 icalmemory_append_string(&buf, &buf_ptr, &buf_size, newline);
311
312 return buf;
313}
314
315bool icalcomponent_is_valid(const icalcomponent *component)
316{
317 if (component) {
318 if ((component->id == ICAL_STRUCTURE_TYPE_COMPONENT) && component->kind != ICAL_NO_COMPONENT) {
319 return true;
320 }
321 }
322 return false;
323}
324
325icalcomponent_kind icalcomponent_isa(const icalcomponent *component)
326{
327 icalerror_check_arg_rx((component != 0), "component", ICAL_NO_COMPONENT);
328
329 return component->kind;
330}
331
332bool icalcomponent_isa_component(const void *component)
333{
334 const icalcomponent *impl = component;
335
336 icalerror_check_arg_rz((component != 0), "component");
337
338 return (impl->id == ICAL_STRUCTURE_TYPE_COMPONENT);
339}
340
341void icalcomponent_set_x_name(icalcomponent *comp, const char *name)
342{
343 icalerror_check_arg_rv((name != 0), "name");
344 icalerror_check_arg_rv((comp != 0), "comp");
345
346 free(comp->x_name);
347 comp->x_name = icalmemory_strdup(name);
348
349 if (comp->x_name == 0) {
351 }
352}
353
354const char *icalcomponent_get_x_name(const icalcomponent *comp)
355{
356 icalerror_check_arg_rz((comp != 0), "comp");
357
358 return comp->x_name;
359}
360
361void icalcomponent_set_iana_name(icalcomponent *comp, const char *name)
362{
363 icalerror_check_arg_rv((name != 0), "name");
364 icalerror_check_arg_rv((comp != 0), "comp");
365 icalerror_check_arg_rv((comp->kind == ICAL_IANA_COMPONENT), "comp->kind");
366
367 icalmemory_free_buffer(comp->x_name);
368 comp->x_name = icalmemory_strdup(name);
369
370 if (comp->x_name == 0) {
372 }
373}
374
375const char *icalcomponent_get_iana_name(const icalcomponent *comp)
376{
377 icalerror_check_arg_rz((comp != 0), "comp");
378 icalerror_check_arg_rz((comp->kind == ICAL_IANA_COMPONENT), "comp->kind");
379
380 return comp->x_name;
381}
382
383const char *icalcomponent_get_component_name(const icalcomponent *comp)
384{
385 char *buf;
386
389 return buf;
390}
391
392char *icalcomponent_get_component_name_r(const icalcomponent *comp)
393{
394 const char *component_name = 0;
395 size_t buf_size = 256;
396 char *buf;
397 char *buf_ptr;
398
399 icalerror_check_arg_rz((comp != 0), "comp");
400
401 buf = icalmemory_new_buffer(buf_size);
402 buf_ptr = buf;
403
404 if ((comp->kind == ICAL_X_COMPONENT || comp->kind == ICAL_IANA_COMPONENT) &&
405 comp->x_name != 0) {
406 component_name = comp->x_name;
407 } else {
408 component_name = icalcomponent_kind_to_string(comp->kind);
409 }
410
411 if (component_name == 0) {
414 return 0;
415
416 } else {
417 /* _append_string will automatically grow the buffer if
418 component_name is longer than the initial buffer size */
419 icalmemory_append_string(&buf, &buf_ptr, &buf_size, component_name);
420 }
421
422 return buf;
423}
424
425void icalcomponent_add_property(icalcomponent *component, icalproperty *property)
426{
427 icalerror_check_arg_rv((component != 0), "component");
428 icalerror_check_arg_rv((property != 0), "property");
429
430 icalerror_assert((!icalproperty_get_parent(property)),
431 "The property has already been added to a component. "
432 "Remove the property with icalcomponent_remove_property "
433 "before calling icalcomponent_add_property");
434
435 icalproperty_set_parent(property, component);
436
437 icalpvl_push(component->properties, property);
438}
439
440void icalcomponent_remove_property(icalcomponent *component, icalproperty *property)
441{
442 icalpvl_elem itr, next_itr;
443
444 icalerror_check_arg_rv((component != 0), "component");
445 icalerror_check_arg_rv((property != 0), "property");
446
447 if (icalproperty_get_parent(property) == 0) {
448 return;
449 }
450
451 for (itr = icalpvl_head(component->properties); itr != 0; itr = next_itr) {
452 next_itr = icalpvl_next(itr);
453
454 if (icalpvl_data(itr) == (void *)property) {
455 if (component->property_iterator == itr) {
456 component->property_iterator = icalpvl_next(itr);
457 }
458
459 (void)icalpvl_remove(component->properties, itr);
460 icalproperty_set_parent(property, 0);
461 }
462 }
463}
464
466{
467 icalpvl_elem itr, next_itr;
468
469 icalerror_check_arg_rv((component != 0), "component");
470
471 for (itr = icalpvl_head(component->properties); itr != 0; itr = next_itr) {
472 next_itr = icalpvl_next(itr);
473
474 icalproperty *property = icalpvl_data(itr);
475 if (kind == ICAL_ANY_PROPERTY || icalproperty_isa(property) == kind) {
476 if (component->property_iterator == itr) {
477 component->property_iterator = icalpvl_next(itr);
478 }
479
480 (void)icalpvl_remove(component->properties, itr);
481 icalproperty_set_parent(property, 0);
482 icalproperty_free(property);
483 }
484 }
485}
486
487int icalcomponent_count_properties(icalcomponent *component, icalproperty_kind kind)
488{
489 int count = 0;
490 icalpvl_elem itr;
491
492 icalerror_check_arg_rz((component != 0), "component");
493
494 for (itr = icalpvl_head(component->properties); itr != 0; itr = icalpvl_next(itr)) {
495 if (kind == icalproperty_isa((icalproperty *)icalpvl_data(itr)) || kind == ICAL_ANY_PROPERTY) {
496 count++;
497 }
498 }
499
500 return count;
501}
502
503icalproperty *icalcomponent_get_current_property(icalcomponent *component)
504{
505 icalerror_check_arg_rz((component != 0), "component");
506
507 if (component->property_iterator == 0) {
508 return 0;
509 }
510
511 return (icalproperty *)icalpvl_data(component->property_iterator);
512}
513
514icalproperty *icalcomponent_get_first_property(icalcomponent *c, icalproperty_kind kind)
515{
516 icalerror_check_arg_rz((c != 0), "component");
517
518 for (c->property_iterator = icalpvl_head(c->properties);
519 c->property_iterator != 0; c->property_iterator = icalpvl_next(c->property_iterator)) {
520 icalproperty *p = (icalproperty *)icalpvl_data(c->property_iterator);
521
522 if (icalproperty_isa(p) == kind || kind == ICAL_ANY_PROPERTY) {
523 return p;
524 }
525 }
526 return 0;
527}
528
529icalproperty *icalcomponent_get_next_property(icalcomponent *c, icalproperty_kind kind)
530{
531 icalerror_check_arg_rz((c != 0), "component");
532
533 if (c->property_iterator == 0) {
534 return 0;
535 }
536
537 for (c->property_iterator = icalpvl_next(c->property_iterator);
538 c->property_iterator != 0; c->property_iterator = icalpvl_next(c->property_iterator)) {
539 icalproperty *p = (icalproperty *)icalpvl_data(c->property_iterator);
540
541 if (icalproperty_isa(p) == kind || kind == ICAL_ANY_PROPERTY) {
542 return p;
543 }
544 }
545
546 return 0;
547}
548
549void icalcomponent_add_component(icalcomponent *parent, icalcomponent *child)
550{
551 icalerror_check_arg_rv((parent != 0), "parent");
552 icalerror_check_arg_rv((child != 0), "child");
553
554 if (child->parent != 0) {
556 }
557
558 child->parent = parent;
559
560 /* Fix for Mozilla - bug 327602 */
561 if (child->kind != ICAL_VTIMEZONE_COMPONENT) {
562 icalpvl_push(parent->components, child);
563 } else {
564 /* VTIMEZONES should be first in the resulting VCALENDAR. */
565 icalpvl_unshift(parent->components, child);
566
567 /* Add the VTIMEZONE to our array. */
568 /* FIXME: Currently we are also creating this array when loading in
569 a builtin VTIMEZONE, when we don't need it. */
570 if (!parent->timezones) {
571 parent->timezones = icaltimezone_array_new();
572 }
573
574 if (parent->timezones) {
575 icaltimezone_array_append_from_vtimezone(parent->timezones, child);
576 }
577
578 /* Flag that we need to sort it before doing any binary searches. */
579 parent->timezones_sorted = 0;
580 }
581}
582
583void icalcomponent_remove_component(icalcomponent *parent, icalcomponent *child)
584{
585 icalpvl_elem itr, next_itr;
586
587 icalerror_check_arg_rv((parent != 0), "parent");
588 icalerror_check_arg_rv((child != 0), "child");
589
590 /* If the component is a VTIMEZONE, remove it from our array as well. */
591 if (child->kind == ICAL_VTIMEZONE_COMPONENT) {
592 icaltimezone *zone;
593 size_t i, num_elements;
594
595 num_elements = parent->timezones ? parent->timezones->num_elements : 0;
596 for (i = 0; i < num_elements; i++) {
597 zone = icalarray_element_at(parent->timezones, i);
598 if (icaltimezone_get_component(zone) == child) {
599 icaltimezone_free(zone, 0);
600 icalarray_remove_element_at(parent->timezones, i);
601 break;
602 }
603 }
604 }
605
606 for (itr = icalpvl_head(parent->components); itr != 0; itr = next_itr) {
607 next_itr = icalpvl_next(itr);
608
609 if (icalpvl_data(itr) == (void *)child) {
610 if (parent->component_iterator == itr) {
611 /* Don't let the current iterator become invalid */
612
613 /* HACK. The semantics for this are troubling. */
614 parent->component_iterator = icalpvl_next(parent->component_iterator);
615 }
616 (void)icalpvl_remove(parent->components, itr);
617 child->parent = 0;
618 break;
619 }
620 }
621}
622
623int icalcomponent_count_components(icalcomponent *component, icalcomponent_kind kind)
624{
625 int count = 0;
626 icalpvl_elem itr;
627
628 icalerror_check_arg_rz((component != 0), "component");
629
630 for (itr = icalpvl_head(component->components); itr != 0; itr = icalpvl_next(itr)) {
631 if (kind == icalcomponent_isa((icalcomponent *)icalpvl_data(itr)) ||
632 kind == ICAL_ANY_COMPONENT) {
633 count++;
634 }
635 }
636
637 return count;
638}
639
640icalcomponent *icalcomponent_get_current_component(icalcomponent *component)
641{
642 icalerror_check_arg_rz((component != 0), "component");
643
644 if (component->component_iterator == 0) {
645 return 0;
646 }
647
648 return (icalcomponent *)icalpvl_data(component->component_iterator);
649}
650
651icalcomponent *icalcomponent_get_first_component(icalcomponent *c, icalcomponent_kind kind)
652{
653 icalerror_check_arg_rz((c != 0), "component");
654
655 for (c->component_iterator = icalpvl_head(c->components);
656 c->component_iterator != 0; c->component_iterator = icalpvl_next(c->component_iterator)) {
657 icalcomponent *p = (icalcomponent *)icalpvl_data(c->component_iterator);
658
659 if (icalcomponent_isa(p) == kind || kind == ICAL_ANY_COMPONENT) {
660 return p;
661 }
662 }
663
664 return 0;
665}
666
667icalcomponent *icalcomponent_get_next_component(icalcomponent *c, icalcomponent_kind kind)
668{
669 icalerror_check_arg_rz((c != 0), "component");
670
671 if (c->component_iterator == 0) {
672 return 0;
673 }
674
675 for (c->component_iterator = icalpvl_next(c->component_iterator);
676 c->component_iterator != 0; c->component_iterator = icalpvl_next(c->component_iterator)) {
677 icalcomponent *p = (icalcomponent *)icalpvl_data(c->component_iterator);
678
679 if (icalcomponent_isa(p) == kind || kind == ICAL_ANY_COMPONENT) {
680 return p;
681 }
682 }
683
684 return 0;
685}
686
687icalcomponent *icalcomponent_get_first_real_component(const icalcomponent *c)
688{
689 icalcomponent *comp;
690 icalcomponent *cin = (icalcomponent *)c;
691
695
696 if (kind == ICAL_VEVENT_COMPONENT ||
697 kind == ICAL_VTODO_COMPONENT ||
698 kind == ICAL_VJOURNAL_COMPONENT ||
699 kind == ICAL_VFREEBUSY_COMPONENT ||
701 kind == ICAL_VPOLL_COMPONENT ||
702 kind == ICAL_VPATCH_COMPONENT ||
704 return comp;
705 }
706 }
707 return 0;
708}
709
710icaltime_span icalcomponent_get_span(icalcomponent *comp)
711{
712 const icalcomponent *inner;
714 icaltime_span span;
715 struct icaltimetype start, end;
716
717 span.start = 0;
718 span.end = 0;
719 span.is_busy = 1;
720
721 /* initial Error checking */
722 if (comp == NULL) {
723 return span;
724 }
725
726 /* FIXME this might go away */
727 kind = icalcomponent_isa(comp);
728 if (kind == ICAL_VCALENDAR_COMPONENT) {
730
731 /* Maybe there is a VTIMEZONE in there */
732 if (inner == 0) {
734 }
735
736 } else {
737 inner = comp;
738 }
739
740 if (inner == 0) {
742 /*icalerror_warn("icalcomponent_get_span: no component specified, \
743or empty VCALENDAR component"); */
744 return span;
745 }
746
747 kind = icalcomponent_isa(inner);
748
749 if (!(kind == ICAL_VEVENT_COMPONENT ||
750 kind == ICAL_VJOURNAL_COMPONENT ||
753 /*icalerror_warn("icalcomponent_get_span: no component specified, \
754or empty VCALENDAR component"); */
755 return span;
756 }
757
758 /* Get to work. starting with DTSTART */
759 start = icalcomponent_get_dtstart(comp);
760 if (icaltime_is_null_time(start)) {
761 return span;
762 }
764
765 /* The end time could be specified as either a DTEND, a DURATION, or be missing */
766 /* icalcomponent_get_dtend takes care of these cases. */
767 end = icalcomponent_get_dtend(comp);
768
770 if (icaltime_is_date(start)) {
771 /* Until the end of the day */
772 span.end -= 1;
773 }
774
775 return span;
776}
777
778bool icalproperty_recurrence_is_excluded(icalcomponent *comp,
779 struct icaltimetype *dtstart,
780 struct icaltimetype *recurtime)
781{
782 icalproperty *exdate, *exrule;
783 icalpvl_elem property_iterator;
784
785 if (comp == NULL || dtstart == NULL || recurtime == NULL || icaltime_is_null_time(*recurtime)) {
786 /* BAD DATA */
787 return true;
788 }
789
790 property_iterator = comp->property_iterator;
791
794 exdate != NULL; exdate = icalcomponent_get_next_property(comp, ICAL_EXDATE_PROPERTY)) {
795 struct icaltimetype exdatetime = icalproperty_get_datetime_with_component(exdate, comp);
796
797 if ((icaltime_is_date(exdatetime) &&
798 icaltime_compare_date_only(*recurtime, exdatetime) == 0) ||
799 (icaltime_compare(*recurtime, exdatetime) == 0)) {
801 comp->property_iterator = property_iterator;
802 return true;
803 }
804 }
805
808 exrule != NULL; exrule = icalcomponent_get_next_property(comp, ICAL_EXRULE_PROPERTY)) {
809 struct icalrecurrencetype *recur = icalproperty_get_exrule(exrule);
810 if (recur) {
811 icalrecur_iterator *exrule_itr = icalrecur_iterator_new(recur, *dtstart);
812 while (exrule_itr) {
813 int result;
814
815 struct icaltimetype exrule_time = icalrecur_iterator_next(exrule_itr);
816
817 if (icaltime_is_null_time(exrule_time)) {
818 break;
819 }
820
821 result = icaltime_compare(exrule_time, *recurtime);
822 if (result == 0) {
823 icalrecur_iterator_free(exrule_itr);
824 comp->property_iterator = property_iterator;
825 return true;
827 }
828 if (result == 1) {
829 break;
830 }
832 }
833
834 if (exrule_itr) {
835 icalrecur_iterator_free(exrule_itr);
836 }
837 }
838 }
839 comp->property_iterator = property_iterator;
840
841 return false; /* no matches */
842}
843
851static bool icalcomponent_is_busy(icalcomponent *comp)
852{
853 const icalproperty *transp;
854 enum icalproperty_status status;
855 bool ret = true;
856
859
860 /* Is this a busy time? Check the TRANSP property */
862
863 if (transp) {
864 icalvalue *transp_val = icalproperty_get_value(transp);
865
866 switch (icalvalue_get_transp(transp_val)) {
869 case ICAL_TRANSP_NONE:
870 ret = true;
871 break;
874 ret = false;
875 break;
876 default:
877 ret = false;
878 break;
879 }
880 }
881 status = icalcomponent_get_status(comp);
882 if (ret && status != ICAL_STATUS_NONE) {
883 switch (status) {
886 ret = false;
887 break;
888 default:
889 break;
890 }
891 }
892 return ret;
893}
894
895static struct icaltimetype icaltime_with_time(const struct icaltimetype t, int hour, int minutes, int seconds)
896{
897 struct icaltimetype ret = t;
898 ret.hour = hour;
899 ret.minute = minutes;
900 ret.second = seconds;
901 ret.is_date = 0;
902 return ret;
903}
904
905static struct icaltimetype icaltime_at_midnight(const struct icaltimetype t)
906{
907 return icaltime_with_time(t, 0, 0, 0);
908}
909
910static icaltime_span icaltime_span_from_time(const struct icaltimetype t, const struct icaldurationtype d)
911{
912 icaltime_span ret = {0};
913
914 ret.start =
917 ret.end =
921 return ret;
922}
923
924static icaltime_span icaltime_span_from_datetimeperiod(const struct icaldatetimeperiodtype p, const struct icaldurationtype d)
925{
926 struct icaltimetype start = p.time;
928
929 icaltime_span ret = {0};
930 if (icaltime_is_null_time(start)) {
931 start = p.period.start;
932
934 dur = p.period.duration;
935 } else {
936 ret.end =
938 p.period.end,
939 start.zone ? start.zone : icaltimezone_get_utc_timezone());
940 }
941 } else {
942 dur = d;
943 }
944
945 ret.start =
947 start,
948 start.zone ? start.zone : icaltimezone_get_utc_timezone());
949
952 icalduration_extend(start, dur),
953 start.zone ? start.zone : icaltimezone_get_utc_timezone());
954 }
955 return ret;
956}
957
958static int icaldatetimeperiod_start_compare(const void *a, const void *b)
959{
960 const struct icaldatetimeperiodtype *adtp = a, *bdtp = b;
961 const struct icaltimetype
962 at = (!icaltime_is_null_time(adtp->time) ? adtp->time : adtp->period.start),
963 bt = (!icaltime_is_null_time(bdtp->time) ? bdtp->time : bdtp->period.start);
964 return icaltime_compare(at, bt);
965}
966
967void icalcomponent_foreach_recurrence(icalcomponent *comp,
968 struct icaltimetype start,
969 struct icaltimetype end,
970 void (*callback)(icalcomponent *comp,
971 const struct icaltime_span *span,
972 void *data),
973 void *callback_data)
974{
975 struct icaltimetype dtstart, dtend, recur_time;
976 icaltime_span recurspan, basespan, limit_span,
977 rrule_span, rdate_span;
978 icaltime_t limit_start, limit_end, last_start;
979 struct icaldurationtype dtduration;
980 time_t end_timet = icaltime_as_timet_with_zone(
981 end, end.zone ? end.zone : icaltimezone_get_utc_timezone());
982 icalarray *rdates;
983 size_t rdate_idx = 0;
984
985 icalproperty *rrule, *rdate;
986 icalpvl_elem property_iterator; /* for saving the iterator */
987
988 if (comp == NULL || callback == NULL) {
989 return;
990 }
991
992 dtstart = icalcomponent_get_dtstart(comp);
993
994 if (icaltime_is_null_time(dtstart) &&
996 /* VTODO with no DTSTART - use DUE */
997 dtstart = icalcomponent_get_due(comp);
998 }
999 if (icaltime_is_null_time(dtstart)) {
1000 return;
1001 }
1002
1003 /* The end time could be specified as either a DTEND, a DURATION or be missing */
1004 /* icalcomponent_get_dtend takes care of these cases. */
1005 dtend = icalcomponent_get_dtend(comp);
1006 /* Our duration may similarly be derived from DTSTART and DTEND */
1007 dtduration = icalcomponent_get_duration(comp);
1008
1009 /* Now set up the base span for this item, corresponding to the
1010 base DTSTART and DTEND */
1011 basespan = icaltime_span_new(dtstart, dtend, true);
1012
1013 basespan.is_busy = (int)icalcomponent_is_busy(comp);
1014
1015 if (start.is_date) {
1016 /* We always treat start as date-time, because we do arithmetic calculations later
1017 on that wouldn't work on date-only. As date-only values shouldn't have a timezone set,
1018 we shouldn't have any issues with potential DST changes. */
1019 start = icaltime_at_midnight(start);
1020 }
1021
1022 /* Calculate the ceiling and floor values.. */
1023 limit_start = icaltime_as_timet_with_zone(start,
1025 if (!icaltime_is_null_time(end)) {
1026 if (end.is_date) {
1027 /* Same as with start, treat as date-time to allow for arithmetic operations. */
1028 end = icaltime_at_midnight(end);
1029 }
1030
1031 limit_end = icaltime_as_timet_with_zone(end,
1033 } else {
1034#if (SIZEOF_ICALTIME_T > 4)
1035 limit_end = (icaltime_t)LONG_MAX;
1036#else
1037 limit_end = (icaltime_t)INT_MAX;
1038#endif
1039 }
1040 limit_span.start = limit_start;
1041 limit_span.end = limit_end;
1042
1043 rrule_span.start = rdate_span.start =
1044 last_start = end_timet + 1;
1045
1046 /* Do the callback for the DTSTART entry, ONLY if there is no RRULE.
1047 Otherwise, the initial occurrence will be handled by the RRULE. */
1049 if ((rrule == NULL) &&
1050 !icalproperty_recurrence_is_excluded(comp, &dtstart, &dtstart)) {
1051 last_start = basespan.start;
1052 /* call callback action */
1053 if (icaltime_span_overlaps(&basespan, &limit_span)) {
1054 (*callback)(comp, &basespan, callback_data);
1055 }
1056 }
1057
1058 /* Now cycle through the rrule and rdate entries */
1059
1060 struct icaltimetype rrule_time = icaltime_null_time();
1061 icalrecur_iterator *rrule_itr = NULL;
1062 if (rrule != NULL) {
1063 struct icalrecurrencetype *recur = icalproperty_get_rrule(rrule);
1064 if (recur) {
1065 rrule_itr = icalrecur_iterator_new(recur, dtstart);
1066
1067 if (rrule_itr) {
1068 if (recur->count == 0) {
1069 icaltimetype mystart = start;
1070
1071 /* make sure we include any recurrence that ends in timespan */
1072 /* duration should be positive */
1073 dtduration.is_neg = 1;
1074 mystart = icalduration_extend(mystart, dtduration);
1075 dtduration.is_neg = 0;
1076
1077 icalrecur_iterator_set_start(rrule_itr, mystart);
1078 }
1079 rrule_time = icalrecur_iterator_next(rrule_itr);
1080 if (!icaltime_is_null_time(rrule_time)) {
1081 rrule_span = icaltime_span_from_time(rrule_time, dtduration);
1082 }
1083 }
1084 }
1085 }
1086
1087 struct icaldatetimeperiodtype rdate_period;
1088 rdates = icalarray_new(sizeof(struct icaldatetimeperiodtype), 16);
1089 if (!rdates) {
1091 } else {
1093 rdate != NULL;
1095 rdate_period = icalproperty_get_rdate(rdate);
1096 icalarray_append(rdates, &rdate_period);
1097 }
1098 if (rdates->num_elements > 0) {
1099 icalarray_sort(rdates, icaldatetimeperiod_start_compare);
1100 rdate_period = *((struct icaldatetimeperiodtype *)icalarray_element_at(rdates, rdate_idx));
1101 rdate_span = icaltime_span_from_datetimeperiod(rdate_period, dtduration);
1102 }
1103
1104 while (rdate_idx < rdates->num_elements || !icaltime_is_null_time(rrule_time)) {
1105 if (rdate_idx >= rdates->num_elements ||
1106 (!icaltime_is_null_time(rrule_time) &&
1107 rrule_span.start < rdate_span.start)) {
1108 /* use rrule time */
1109 recurspan = rrule_span;
1110 recur_time = rrule_time;
1111
1112 rrule_time = icalrecur_iterator_next(rrule_itr);
1113 if (!icaltime_is_null_time(rrule_time)) {
1114 rrule_span = icaltime_span_from_time(rrule_time, dtduration);
1115 }
1116 } else {
1117 /* use rdate time */
1118 recurspan = rdate_span;
1119 recur_time = rdate_period.time;
1120 if (icaltime_is_null_time(recur_time)) {
1121 recur_time = rdate_period.period.start;
1122 }
1123
1124 rdate_idx++;
1125 if (rdate_idx < rdates->num_elements) {
1126 rdate_period = *((struct icaldatetimeperiodtype *)icalarray_element_at(rdates, rdate_idx));
1127 rdate_span = icaltime_span_from_datetimeperiod(rdate_period, dtduration);
1128 }
1129 }
1130
1131 if (recurspan.start > end_timet) {
1132 break;
1133 }
1134
1135 if (last_start == recurspan.start) {
1136 continue;
1137 }
1138 last_start = recurspan.start;
1139
1140 /* save the iterator ICK! */
1141 property_iterator = comp->property_iterator;
1142
1144 &dtstart, &recur_time)) {
1145 /* call callback action */
1146 if (icaltime_span_overlaps(&recurspan, &limit_span)) {
1147 recurspan.is_busy = basespan.is_busy;
1148 (*callback)(comp, &recurspan, callback_data);
1149 }
1150 }
1151 comp->property_iterator = property_iterator;
1152 }
1153
1154 icalarray_free(rdates);
1155 }
1156
1157 if (rrule_itr != NULL) {
1158 icalrecur_iterator_free(rrule_itr);
1159 }
1160}
1161
1162bool icalcomponent_check_restrictions(icalcomponent *comp)
1163{
1164 icalerror_check_arg_rz(comp != 0, "comp");
1165 return icalrestriction_check(comp);
1166}
1167
1168int icalcomponent_count_errors(icalcomponent *component)
1169{
1170 int errors = 0;
1171 icalpvl_elem itr;
1172
1173 icalerror_check_arg_rz((component != 0), "component");
1174
1175 for (itr = icalpvl_head(component->properties); itr != 0; itr = icalpvl_next(itr)) {
1176 const icalproperty *p = (icalproperty *)icalpvl_data(itr);
1178 errors++;
1179 }
1180 }
1181
1182 for (itr = icalpvl_head(component->components); itr != 0; itr = icalpvl_next(itr)) {
1183 icalcomponent *c = (icalcomponent *)icalpvl_data(itr);
1184 errors += icalcomponent_count_errors(c);
1185 }
1186
1187 return errors;
1188}
1189
1190void icalcomponent_strip_errors(icalcomponent *component)
1191{
1192 icalpvl_elem itr, next_itr;
1193
1194 icalerror_check_arg_rv((component != 0), "component");
1195
1196 for (itr = icalpvl_head(component->properties); itr != 0; itr = next_itr) {
1197 icalproperty *p = (icalproperty *)icalpvl_data(itr);
1198 next_itr = icalpvl_next(itr);
1199
1201 icalcomponent_remove_property(component, p);
1203 }
1204 }
1205
1206 for (itr = icalpvl_head(component->components); itr != 0; itr = icalpvl_next(itr)) {
1207 icalcomponent *c = (icalcomponent *)icalpvl_data(itr);
1209 }
1210}
1211
1212/* Hack. This will change the state of the iterators */
1213void icalcomponent_convert_errors(icalcomponent *component)
1214{
1215 icalproperty *p, *next_p;
1216 icalcomponent *c;
1217
1218 for (p = icalcomponent_get_first_property(component, ICAL_ANY_PROPERTY); p != 0; p = next_p) {
1220
1222 struct icalreqstattype rst;
1223 icalparameter *param =
1225
1227 rst.desc = 0;
1228
1229 switch (icalparameter_get_xlicerrortype(param)) {
1232 break;
1233 }
1236 break;
1237 }
1240 break;
1241 }
1244 break;
1245 }
1248 break;
1249 }
1250
1251 default: {
1252 break;
1253 }
1254 }
1255 if (rst.code != ICAL_UNKNOWN_STATUS) {
1258
1259 icalcomponent_remove_property(component, p);
1261 }
1262 }
1263 }
1264
1266 c != 0; c = icalcomponent_get_next_component(component, ICAL_ANY_COMPONENT)) {
1268 }
1269}
1270
1272icalcomponent *icalcomponent_get_parent(const icalcomponent *component)
1273{
1274 return component->parent;
1275}
1276
1277void icalcomponent_set_parent(icalcomponent *component, icalcomponent *parent)
1278{
1279 component->parent = parent;
1280}
1282
1283static const icalcompiter icalcompiter_null = {ICAL_NO_COMPONENT, 0};
1284
1285static const icalpropiter icalpropiter_null = {ICAL_NO_PROPERTY, 0};
1286
1287struct icalcomponent_kind_map {
1288 icalcomponent_kind kind;
1289 char name[20];
1290};
1291
1292static const struct icalcomponent_kind_map component_map[] = {
1293 {ICAL_VEVENT_COMPONENT, "VEVENT"},
1294 {ICAL_VTODO_COMPONENT, "VTODO"},
1295 {ICAL_VJOURNAL_COMPONENT, "VJOURNAL"},
1296 {ICAL_VCALENDAR_COMPONENT, "VCALENDAR"},
1297 {ICAL_VAGENDA_COMPONENT, "VAGENDA"},
1298 {ICAL_VFREEBUSY_COMPONENT, "VFREEBUSY"},
1299 {ICAL_VTIMEZONE_COMPONENT, "VTIMEZONE"},
1300 {ICAL_VALARM_COMPONENT, "VALARM"},
1301 {ICAL_XSTANDARD_COMPONENT, "STANDARD"}, /*These are part of RFC5545 */
1302 {ICAL_XDAYLIGHT_COMPONENT, "DAYLIGHT"}, /*but are not really components */
1303 {ICAL_X_COMPONENT, "X"},
1304 {ICAL_VSCHEDULE_COMPONENT, "SCHEDULE"},
1305
1306 /* CAP components */
1307 {ICAL_VCAR_COMPONENT, "VCAR"},
1308 {ICAL_VCOMMAND_COMPONENT, "VCOMMAND"},
1309 {ICAL_VQUERY_COMPONENT, "VQUERY"},
1310 {ICAL_VREPLY_COMPONENT, "VREPLY"},
1311
1312 /* libical private components */
1313 {ICAL_XLICINVALID_COMPONENT, "X-LIC-UNKNOWN"},
1314 {ICAL_XLICMIMEPART_COMPONENT, "X-LIC-MIME-PART"},
1315 {ICAL_ANY_COMPONENT, "ANY"},
1316 {ICAL_XROOT_COMPONENT, "XROOT"},
1317
1318 /* Calendar Availability components */
1319 {ICAL_VAVAILABILITY_COMPONENT, "VAVAILABILITY"},
1320 {ICAL_XAVAILABLE_COMPONENT, "AVAILABLE"},
1321
1322 /* Consensus Scheduling components */
1323 {ICAL_VPOLL_COMPONENT, "VPOLL"},
1324 {ICAL_VVOTER_COMPONENT, "VVOTER"},
1325 {ICAL_XVOTE_COMPONENT, "VOTE"},
1326
1327 /* VPATCH components */
1328 {ICAL_VPATCH_COMPONENT, "VPATCH"},
1329 {ICAL_XPATCH_COMPONENT, "PATCH"},
1330
1331 /* Event Publishing components */
1332 {ICAL_PARTICIPANT_COMPONENT, "PARTICIPANT"},
1333 {ICAL_VLOCATION_COMPONENT, "VLOCATION"},
1334 {ICAL_VRESOURCE_COMPONENT, "VRESOURCE"},
1335
1336 /* IANA components (unknown but valid IANA token) */
1337 {ICAL_IANA_COMPONENT, "IANA"},
1338
1339 /* End of list */
1340 {ICAL_NO_COMPONENT, ""},
1341};
1342
1344{
1345 int i = 0;
1346
1347 do {
1348 if (component_map[i].kind == kind) {
1349 return true;
1350 }
1351 } while (component_map[i++].kind != ICAL_NO_COMPONENT);
1352
1353 return false;
1354}
1355
1357{
1358 int i;
1359
1360 for (i = 0; component_map[i].kind != ICAL_NO_COMPONENT; i++) {
1361 if (component_map[i].kind == kind) {
1362 return component_map[i].name;
1363 }
1364 }
1365
1366 return 0;
1367}
1368
1370{
1371 int i;
1372
1373 if (string == 0) {
1374 return ICAL_NO_COMPONENT;
1375 }
1376
1377 for (i = 0; component_map[i].kind != ICAL_NO_COMPONENT; i++) {
1378 // ignore IANA component kind, we'll fall back to using it later.
1379 if (component_map[i].kind == ICAL_IANA_COMPONENT) {
1380 continue;
1381 }
1382 if (strncasecmp(string, component_map[i].name, strlen(component_map[i].name)) == 0) {
1383 return component_map[i].kind;
1384 }
1385 }
1386
1387 if (strncasecmp(string, "X-", 2) == 0) {
1388 return ICAL_X_COMPONENT;
1389 }
1390
1391 return ICAL_IANA_COMPONENT;
1392}
1393
1394bool icalcompiter_is_valid(const icalcompiter *i)
1395{
1396 if (!i) {
1397 return false;
1398 }
1399 /* compare to icalcompiter_null */
1400 if (i->kind == ICAL_NO_COMPONENT && i->iter == 0) {
1401 return false;
1402 }
1403 return true;
1404}
1405
1406icalcompiter icalcomponent_begin_component(icalcomponent *component, icalcomponent_kind kind)
1407{
1408 icalcompiter itr;
1409 icalpvl_elem i;
1410
1411 itr.kind = kind;
1412 itr.iter = NULL;
1413
1414 icalerror_check_arg_re(component != 0, "component", icalcompiter_null);
1415
1416 for (i = icalpvl_head(component->components); i != 0; i = icalpvl_next(i)) {
1417 const icalcomponent *c = (icalcomponent *)icalpvl_data(i);
1418
1419 if (icalcomponent_isa(c) == kind || kind == ICAL_ANY_COMPONENT) {
1420 itr.iter = i;
1421
1422 return itr;
1423 }
1424 }
1425
1426 return icalcompiter_null;
1427}
1428
1429icalcompiter icalcomponent_end_component(icalcomponent *component, icalcomponent_kind kind)
1430{
1431 icalcompiter itr;
1432 icalpvl_elem i;
1433
1434 itr.kind = kind;
1435
1436 icalerror_check_arg_re(component != 0, "component", icalcompiter_null);
1437
1438 for (i = icalpvl_tail(component->components); i != 0; i = icalpvl_prior(i)) {
1439 const icalcomponent *c = (icalcomponent *)icalpvl_data(i);
1440
1441 if (icalcomponent_isa(c) == kind || kind == ICAL_ANY_COMPONENT) {
1442 itr.iter = icalpvl_next(i);
1443
1444 return itr;
1445 }
1446 }
1447
1448 return icalcompiter_null;
1449}
1450
1451icalcomponent *icalcompiter_next(icalcompiter *i)
1452{
1453 icalerror_check_arg_rz((i != 0), "i");
1454
1455 if (i->iter == 0) {
1456 return 0;
1457 }
1458
1459 for (i->iter = icalpvl_next(i->iter); i->iter != 0; i->iter = icalpvl_next(i->iter)) {
1460 const icalcomponent *c = (icalcomponent *)icalpvl_data(i->iter);
1461
1462 if (icalcomponent_isa(c) == i->kind || i->kind == ICAL_ANY_COMPONENT) {
1463 return icalcompiter_deref(i);
1464 }
1465 }
1466
1467 return 0;
1468}
1469
1470icalcomponent *icalcompiter_prior(icalcompiter *i)
1471{
1472 icalerror_check_arg_rz((i != 0), "i");
1473
1474 if (i->iter == 0) {
1475 return 0;
1476 }
1477
1478 for (i->iter = icalpvl_prior(i->iter); i->iter != 0; i->iter = icalpvl_prior(i->iter)) {
1479 const icalcomponent *c = (icalcomponent *)icalpvl_data(i->iter);
1480
1481 if (icalcomponent_isa(c) == i->kind || i->kind == ICAL_ANY_COMPONENT) {
1482 return icalcompiter_deref(i);
1483 }
1484 }
1485
1486 return 0;
1487}
1488
1489icalcomponent *icalcompiter_deref(icalcompiter *i)
1490{
1491 icalerror_check_arg_rz((i != 0), "i");
1492
1493 if (i->iter == 0) {
1494 return 0;
1495 }
1496
1497 return icalpvl_data(i->iter);
1498}
1499
1500icalpropiter icalcomponent_begin_property(icalcomponent *component, icalproperty_kind kind)
1501{
1502 icalerror_check_arg_re(component != 0, "component", icalpropiter_null);
1503
1504 icalpvl_elem i;
1505
1506 for (i = icalpvl_head(component->properties); i != 0; i = icalpvl_next(i)) {
1507 const icalproperty *p = (icalproperty *)icalpvl_data(i);
1508
1509 if (icalproperty_isa(p) == kind || kind == ICAL_ANY_PROPERTY) {
1510 icalpropiter itr = {kind, i};
1511 return itr;
1512 }
1513 }
1514
1515 return icalpropiter_null;
1516}
1517
1518bool icalpropiter_is_valid(const icalpropiter *i)
1519{
1520 if (!i) {
1521 return false;
1522 }
1523 /* compare to icalpropiter_null */
1524 if ((i->kind == ICAL_NO_PROPERTY) && (i->iter == 0)) {
1525 return false;
1526 }
1527 return true;
1528}
1529
1530icalproperty *icalpropiter_next(icalpropiter *i)
1531{
1532 icalerror_check_arg_rz((i != 0), "i");
1533
1534 if (i->iter == 0) {
1535 return 0;
1536 }
1537
1538 for (i->iter = icalpvl_next(i->iter); i->iter != 0; i->iter = icalpvl_next(i->iter)) {
1539 const icalproperty *p = (icalproperty *)icalpvl_data(i->iter);
1540
1541 if (icalproperty_isa(p) == i->kind || i->kind == ICAL_ANY_PROPERTY) {
1542 return icalpropiter_deref(i);
1543 }
1544 }
1545
1546 return 0;
1547}
1548
1549icalproperty *icalpropiter_deref(icalpropiter *i)
1550{
1551 icalerror_check_arg_rz((i != 0), "i");
1552
1553 if (i->iter == 0) {
1554 return 0;
1555 }
1556
1557 return icalpvl_data(i->iter);
1558}
1559
1560icalcomponent *icalcomponent_get_inner(icalcomponent *comp)
1561{
1564 } else {
1565 return comp;
1566 }
1567}
1568
1569void icalcomponent_set_method(icalcomponent *comp, icalproperty_method method)
1570{
1571 icalproperty *prop = icalcomponent_get_first_property(comp, ICAL_METHOD_PROPERTY);
1572
1573 if (prop == 0) {
1574 prop = icalproperty_new_method(method);
1575 icalcomponent_add_property(comp, prop);
1576 }
1577
1578 icalproperty_set_method(prop, method);
1579}
1580
1582{
1583 icalproperty *prop = icalcomponent_get_first_property(comp, ICAL_METHOD_PROPERTY);
1584
1585 if (prop == 0) {
1586 return ICAL_METHOD_NONE;
1587 }
1588
1589 return icalproperty_get_method(prop);
1590}
1591
1593#define ICALSETUPSET(p_kind) \
1594 icalcomponent *inner; \
1595 icalproperty *prop; \
1596 icalerror_check_arg_rv(comp != 0, "comp"); \
1597 inner = icalcomponent_get_inner(comp); \
1598 if (inner == 0) { \
1599 icalerror_set_errno(ICAL_MALFORMEDDATA_ERROR); \
1600 return; \
1601 } \
1602 prop = icalcomponent_get_first_property(inner, p_kind);
1604
1605void icalcomponent_set_dtstart(icalcomponent *comp, struct icaltimetype v)
1606{
1607 const char *tzid;
1608
1609 ICALSETUPSET(ICAL_DTSTART_PROPERTY);
1610
1611 if (prop == 0) {
1612 prop = icalproperty_new_dtstart(v);
1613 icalcomponent_add_property(inner, prop);
1614 } else {
1616 }
1617
1618 icalproperty_set_dtstart(prop, v);
1619
1620 if ((tzid = icaltime_get_tzid(v)) != NULL && !icaltime_is_utc(v)) {
1622 }
1623}
1624
1625struct icaltimetype icalcomponent_get_dtstart(icalcomponent *comp)
1626{
1627 icalcomponent *inner = icalcomponent_get_inner(comp);
1628 icalproperty *prop;
1629
1631 if (prop == 0) {
1632 return icaltime_null_time();
1633 }
1634
1636}
1637
1638struct icaltimetype icalcomponent_get_dtend(icalcomponent *comp)
1639{
1640 icalcomponent *inner = icalcomponent_get_inner(comp);
1641 const icalcomponent_kind kind = icalcomponent_isa(inner);
1642 icalproperty *end_prop, *dur_prop;
1643 struct icaltimetype ret;
1644
1645 switch (kind) {
1650 break;
1651 default:
1652 return icaltime_null_time();
1653 }
1654
1657
1658 if (end_prop != 0 && dur_prop == 0) {
1659 ret = icalproperty_get_datetime_with_component(end_prop, comp);
1660 } else if (end_prop == 0 && dur_prop != 0) {
1661 struct icaltimetype start = icalcomponent_get_dtstart(inner);
1662 struct icaldurationtype duration;
1663
1664 //extra check to prevent empty durations from crashing
1665 if (icalproperty_get_value(dur_prop)) {
1666 duration = icalproperty_get_duration(dur_prop);
1667 } else {
1668 duration = icaldurationtype_null_duration();
1669 }
1670
1671 ret = icalduration_extend(start, duration);
1672 } else if (end_prop == 0 && dur_prop == 0) {
1673 if (kind == ICAL_VEVENT_COMPONENT) {
1674 struct icaltimetype start = icalcomponent_get_dtstart(inner);
1675 if (icaltime_is_date(start)) {
1677 duration.days = 1;
1678 ret = icalduration_extend(start, duration);
1679 } else {
1680 ret = start;
1681 }
1682 } else {
1683 ret = icaltime_null_time();
1684 }
1685 } else {
1686 /* Error, both duration and dtend have been specified */
1688 ret = icaltime_null_time();
1689 }
1690
1691 return ret;
1692}
1693
1694void icalcomponent_set_dtend(icalcomponent *comp, struct icaltimetype v)
1695{
1696 const char *tzid;
1697
1698 ICALSETUPSET(ICAL_DTEND_PROPERTY);
1699
1702 return;
1703 }
1704
1705 if (prop == 0) {
1706 prop = icalproperty_new_dtend(v);
1707 icalcomponent_add_property(inner, prop);
1708 } else {
1710 }
1711
1712 icalproperty_set_dtend(prop, v);
1713
1714 if ((tzid = icaltime_get_tzid(v)) != NULL && !icaltime_is_utc(v)) {
1716 }
1717}
1718
1719void icalcomponent_set_duration(icalcomponent *comp, struct icaldurationtype v)
1720{
1721 ICALSETUPSET(ICAL_DURATION_PROPERTY);
1722
1725 return;
1726 }
1727
1728 if (prop == 0) {
1729 prop = icalproperty_new_duration(v);
1730 icalcomponent_add_property(inner, prop);
1731 } else {
1733 }
1734}
1735
1737{
1738 icalcomponent *inner = icalcomponent_get_inner(comp);
1739 const icalcomponent_kind kind = icalcomponent_isa(inner);
1740 icalproperty *end_prop, *dur_prop;
1741 struct icaldurationtype ret;
1742
1743 switch (kind) {
1748 break;
1751 break;
1752 default:
1753 /* The libical API is used incorrectly */
1755 }
1756
1758
1759 if (dur_prop != 0 && end_prop == 0) {
1760 ret = icalproperty_get_duration(dur_prop);
1761
1762 } else if (end_prop != 0 && dur_prop == 0) {
1763 /* Get exact duration */
1764 struct icaltimetype start = icalcomponent_get_dtstart(inner);
1765 struct icaltimetype end = icalproperty_get_datetime_with_component(end_prop, comp);
1766
1767 ret = icalduration_from_times(end, start);
1768 } else if (end_prop == 0 && dur_prop == 0) {
1769 struct icaltimetype start = icalcomponent_get_dtstart(inner);
1771 if (kind == ICAL_VEVENT_COMPONENT && icaltime_is_date(start)) {
1772 ret.days = 1;
1773 }
1774 } else {
1776 /* Error, both duration and dtend have been specified */
1778 }
1779 return ret;
1780}
1781
1782void icalcomponent_set_dtstamp(icalcomponent *comp, struct icaltimetype v)
1783{
1784 ICALSETUPSET(ICAL_DTSTAMP_PROPERTY);
1785
1786 if (prop == 0) {
1787 prop = icalproperty_new_dtstamp(v);
1788 icalcomponent_add_property(inner, prop);
1789 }
1790
1791 icalproperty_set_dtstamp(prop, v);
1792}
1793
1794struct icaltimetype icalcomponent_get_dtstamp(icalcomponent *comp)
1795{
1796 icalcomponent *inner = icalcomponent_get_inner(comp);
1797 icalproperty *prop = icalcomponent_get_first_property(inner, ICAL_DTSTAMP_PROPERTY);
1798
1799 if (prop == 0) {
1800 return icaltime_null_time();
1801 }
1802
1803 return icalproperty_get_dtstamp(prop);
1804}
1805
1806void icalcomponent_set_summary(icalcomponent *comp, const char *v)
1807{
1808 ICALSETUPSET(ICAL_SUMMARY_PROPERTY)
1809
1810 if (prop == 0) {
1811 prop = icalproperty_new_summary(v);
1812 icalcomponent_add_property(inner, prop);
1813 }
1814
1815 icalproperty_set_summary(prop, v);
1816}
1817
1818const char *icalcomponent_get_summary(icalcomponent *comp)
1819{
1820 icalcomponent *inner;
1821 icalproperty *prop;
1822
1823 icalerror_check_arg_rz(comp != 0, "comp");
1824
1825 inner = icalcomponent_get_inner(comp);
1826
1827 if (inner == 0) {
1829 return 0;
1830 }
1831
1833
1834 if (prop == 0) {
1835 return 0;
1836 }
1837
1838 return icalproperty_get_summary(prop);
1839}
1840
1841void icalcomponent_set_comment(icalcomponent *comp, const char *v)
1842{
1843 ICALSETUPSET(ICAL_COMMENT_PROPERTY);
1844
1845 if (prop == 0) {
1846 prop = icalproperty_new_comment(v);
1847 icalcomponent_add_property(inner, prop);
1848 }
1849
1850 icalproperty_set_comment(prop, v);
1851}
1852
1853const char *icalcomponent_get_comment(icalcomponent *comp)
1854{
1855 icalcomponent *inner;
1856 icalproperty *prop;
1857
1858 icalerror_check_arg_rz(comp != 0, "comp");
1859
1860 inner = icalcomponent_get_inner(comp);
1861
1862 if (inner == 0) {
1864 return 0;
1865 }
1866
1868
1869 if (prop == 0) {
1870 return 0;
1871 }
1872
1873 return icalproperty_get_comment(prop);
1874}
1875
1876void icalcomponent_set_uid(icalcomponent *comp, const char *v)
1877{
1878 ICALSETUPSET(ICAL_UID_PROPERTY);
1879
1880 if (prop == 0) {
1881 prop = icalproperty_new_uid(v);
1882 icalcomponent_add_property(inner, prop);
1883 }
1884
1885 icalproperty_set_uid(prop, v);
1886}
1887
1888const char *icalcomponent_get_uid(icalcomponent *comp)
1889{
1890 icalcomponent *inner;
1891 icalproperty *prop;
1892
1893 icalerror_check_arg_rz(comp != 0, "comp");
1894
1895 inner = icalcomponent_get_inner(comp);
1896
1897 if (inner == 0) {
1899 return 0;
1900 }
1901
1903
1904 if (prop == 0) {
1905 return 0;
1906 }
1907
1908 return icalproperty_get_uid(prop);
1909}
1910
1911void icalcomponent_set_recurrenceid(icalcomponent *comp, struct icaltimetype v)
1912{
1913 const char *tzid;
1914
1915 ICALSETUPSET(ICAL_RECURRENCEID_PROPERTY);
1916
1917 if (prop == 0) {
1919 icalcomponent_add_property(inner, prop);
1920 } else {
1922 }
1923
1925
1926 if ((tzid = icaltime_get_tzid(v)) != NULL && !icaltime_is_utc(v)) {
1928 }
1929}
1930
1932{
1933 icalcomponent *inner;
1934 icalproperty *prop;
1935
1936 if (comp == 0) {
1938 return icaltime_null_time();
1939 }
1940
1941 inner = icalcomponent_get_inner(comp);
1942
1943 if (inner == 0) {
1945 return icaltime_null_time();
1946 }
1947
1949
1950 if (prop == 0) {
1951 return icaltime_null_time();
1952 }
1953
1955}
1956
1957void icalcomponent_set_description(icalcomponent *comp, const char *v)
1958{
1959 ICALSETUPSET(ICAL_DESCRIPTION_PROPERTY);
1960
1961 if (prop == 0) {
1963 icalcomponent_add_property(inner, prop);
1964 }
1965
1967}
1968
1969const char *icalcomponent_get_description(icalcomponent *comp)
1970{
1971 icalcomponent *inner;
1972 icalproperty *prop;
1973
1974 icalerror_check_arg_rz(comp != 0, "comp");
1975
1976 inner = icalcomponent_get_inner(comp);
1977
1978 if (inner == 0) {
1980 return 0;
1981 }
1982
1984
1985 if (prop == 0) {
1986 return 0;
1987 }
1988
1989 return icalproperty_get_description(prop);
1990}
1991
1992void icalcomponent_set_location(icalcomponent *comp, const char *v)
1993{
1994 ICALSETUPSET(ICAL_LOCATION_PROPERTY)
1995
1996 if (prop == 0) {
1997 prop = icalproperty_new_location(v);
1998 icalcomponent_add_property(inner, prop);
1999 }
2000
2002}
2003
2004const char *icalcomponent_get_location(icalcomponent *comp)
2005{
2006 icalcomponent *inner;
2007 icalproperty *prop;
2008
2009 icalerror_check_arg_rz(comp != 0, "comp");
2010
2011 inner = icalcomponent_get_inner(comp);
2012
2013 if (inner == 0) {
2015 return 0;
2016 }
2017
2019
2020 if (prop == 0) {
2021 return 0;
2022 }
2023
2024 return icalproperty_get_location(prop);
2025}
2026
2027void icalcomponent_set_sequence(icalcomponent *comp, int v)
2028{
2029 ICALSETUPSET(ICAL_SEQUENCE_PROPERTY);
2030
2031 if (prop == 0) {
2032 prop = icalproperty_new_sequence(v);
2033 icalcomponent_add_property(inner, prop);
2034 }
2035
2037}
2038
2039int icalcomponent_get_sequence(icalcomponent *comp)
2040{
2041 icalcomponent *inner;
2042 icalproperty *prop;
2043
2044 icalerror_check_arg_rz(comp != 0, "comp");
2045
2046 inner = icalcomponent_get_inner(comp);
2047
2048 if (inner == 0) {
2050 return 0;
2051 }
2052
2054
2055 if (prop == 0) {
2056 return 0;
2057 }
2058
2059 return icalproperty_get_sequence(prop);
2060}
2061
2062void icalcomponent_set_status(icalcomponent *comp, enum icalproperty_status v)
2063{
2064 ICALSETUPSET(ICAL_STATUS_PROPERTY);
2065
2066 if (prop == 0) {
2067 prop = icalproperty_new_status(v);
2068 icalcomponent_add_property(inner, prop);
2069 }
2070
2071 icalproperty_set_status(prop, v);
2072}
2073
2075{
2076 icalcomponent *inner;
2077 icalproperty *prop;
2078
2079 icalerror_check_arg_rz(comp != 0, "comp");
2080
2081 inner = icalcomponent_get_inner(comp);
2082
2083 if (inner == 0) {
2085 return ICAL_STATUS_NONE;
2086 }
2087
2089
2090 if (prop == 0) {
2091 return ICAL_STATUS_NONE;
2092 }
2093
2094 return icalproperty_get_status(prop);
2095}
2096
2098{
2100}
2101
2102icalcomponent *icalcomponent_new_vevent(void)
2103{
2105}
2106
2107icalcomponent *icalcomponent_new_vtodo(void)
2108{
2110}
2111
2112icalcomponent *icalcomponent_new_vjournal(void)
2113{
2115}
2116
2117icalcomponent *icalcomponent_new_valarm(void)
2118{
2120}
2121
2123{
2125}
2126
2128{
2130}
2131
2133{
2135}
2136
2138{
2140}
2141
2142icalcomponent *icalcomponent_new_vagenda(void)
2143{
2145}
2146
2147icalcomponent *icalcomponent_new_vquery(void)
2148{
2150}
2151
2152icalcomponent *icalcomponent_new_vreply(void)
2153{
2155}
2156
2161
2163{
2165}
2166
2167icalcomponent *icalcomponent_new_vpoll(void)
2168{
2170}
2171
2172icalcomponent *icalcomponent_new_vvoter(void)
2173{
2175}
2176
2177icalcomponent *icalcomponent_new_xvote(void)
2178{
2180}
2181
2182icalcomponent *icalcomponent_new_vpatch(void)
2183{
2185}
2186
2187icalcomponent *icalcomponent_new_xpatch(void)
2188{
2190}
2191
2196
2198{
2200}
2201
2203{
2205}
2206
2207/*
2208 * Timezone stuff.
2209 */
2210
2211void icalcomponent_merge_component(icalcomponent *comp, icalcomponent *comp_to_merge)
2212{
2213 icalcomponent *subcomp, *next_subcomp;
2214 icalstrarray *tzids_to_rename;
2215
2216 /* Check that both components are VCALENDAR components. */
2217 icalassert(icalcomponent_isa(comp) == ICAL_VCALENDAR_COMPONENT);
2218 icalassert(icalcomponent_isa(comp_to_merge) == ICAL_VCALENDAR_COMPONENT);
2219
2220 /* Step through each subcomponent of comp_to_merge, looking for VTIMEZONEs.
2221 For each VTIMEZONE found, check if we need to add it to comp and if we
2222 need to rename it and all TZID references to it. */
2223 tzids_to_rename = icalstrarray_new(16);
2224 if (!tzids_to_rename) {
2225 return;
2226 }
2227
2229 while (subcomp) {
2230 next_subcomp = icalcomponent_get_next_component(comp_to_merge, ICAL_VTIMEZONE_COMPONENT);
2231 /* This will add the VTIMEZONE to comp, if necessary, and also update
2232 the array of TZIDs we need to rename. */
2233 if (!icalcomponent_merge_vtimezone(comp, subcomp, tzids_to_rename)) {
2234 break;
2235 }
2236 subcomp = next_subcomp;
2237 }
2238
2239 /* If we need to do any renaming of TZIDs, do it now. */
2240 if (icalstrarray_size(tzids_to_rename) != 0) {
2241 icalcomponent_rename_tzids(comp_to_merge, tzids_to_rename);
2242 }
2243 icalstrarray_free(tzids_to_rename);
2244 tzids_to_rename = 0;
2245 /* Now move all the components from comp_to_merge to comp, excluding
2246 VTIMEZONE components. */
2247 subcomp = icalcomponent_get_first_component(comp_to_merge, ICAL_ANY_COMPONENT);
2248 while (subcomp) {
2249 next_subcomp = icalcomponent_get_next_component(comp_to_merge, ICAL_ANY_COMPONENT);
2251 icalcomponent_remove_component(comp_to_merge, subcomp);
2252 icalcomponent_add_component(comp, subcomp);
2253 }
2254 subcomp = next_subcomp;
2255 }
2256
2257 /* Free comp_to_merge. We have moved most of the subcomponents over to
2258 comp now. */
2259 icalcomponent_free(comp_to_merge);
2260}
2261
2262static bool icalcomponent_merge_vtimezone(icalcomponent *comp,
2263 icalcomponent *vtimezone, icalstrarray *tzids_to_rename)
2264{
2265 icalproperty *tzid_prop;
2266 const char *tzid;
2267 char *tzid_copy;
2268 icaltimezone *existing_vtimezone;
2269
2270 /* Get the TZID of the VTIMEZONE. A VTIMEZONE without one is skipped. */
2272 if (!tzid_prop) {
2273 return true;
2274 }
2275
2276 tzid = icalproperty_get_tzid(tzid_prop);
2277 if (!tzid) {
2278 return true;
2279 }
2280
2281 /* See if there is already a VTIMEZONE in comp with the same TZID. */
2282 existing_vtimezone = icalcomponent_get_timezone(comp, tzid);
2283
2284 /* If there is no existing VTIMEZONE with the same TZID, we can just move
2285 the VTIMEZONE to comp and return. */
2286 if (!existing_vtimezone) {
2287 icalcomponent_remove_component(icalcomponent_get_parent(vtimezone), vtimezone);
2288 icalcomponent_add_component(comp, vtimezone);
2289 return true;
2290 }
2291
2292 /* If the TZID has a '/' prefix, then we don't have to worry about the
2293 clashing TZIDs, as they are supposed to be exactly the same VTIMEZONE. */
2294 if (tzid[0] == '/') {
2295 return true;
2296 }
2297
2298 /* Now we have two VTIMEZONEs with the same TZID (which isn't a globally
2299 unique one), so we compare the VTIMEZONE components to see if they are
2300 the same. If they are, we don't need to do anything. We make a copy of
2301 the tzid, since the parameter may get modified in these calls. */
2302 tzid_copy = icalmemory_strdup(tzid);
2303 if (!tzid_copy) {
2305 return false;
2306 }
2307
2308 const int match =
2309 icalcomponent_compare_vtimezones(icaltimezone_get_component(existing_vtimezone), vtimezone);
2310 bool merged = (match != -1);
2311 if (match == 0) {
2312 /* Now we have two different VTIMEZONEs with the same TZID. */
2313 merged = icalcomponent_handle_conflicting_vtimezones(comp, vtimezone, tzid_prop,
2314 tzid_copy, tzids_to_rename);
2315 }
2316 icalmemory_free_buffer(tzid_copy);
2317 return merged;
2318}
2319
2320static bool icalcomponent_handle_conflicting_vtimezones(icalcomponent *comp,
2321 icalcomponent *vtimezone,
2322 icalproperty *tzid_prop,
2323 const char *tzid,
2324 icalstrarray *tzids_to_rename)
2325{
2326 int max_suffix = 0;
2327 size_t i, num_elements, tzid_len;
2328 char *new_tzid, suffix_buf[32];
2329
2330 /* Find the length of the TZID without any trailing digits. */
2331 tzid_len = icalcomponent_get_tzid_prefix_len(tzid);
2332
2333 /* Step through each of the VTIMEZONEs in comp. We may already have the
2334 clashing VTIMEZONE in the calendar, but it may have been renamed
2335 (i.e. a unique number added on the end of the TZID, e.g. 'London2').
2336 So we compare the new VTIMEZONE with any VTIMEZONEs that have the
2337 same prefix (e.g. 'London'). If it matches any of those, we have to
2338 rename the TZIDs to that TZID, else we rename to a new TZID, using
2339 the biggest numeric suffix found + 1. */
2340 num_elements = comp->timezones ? comp->timezones->num_elements : 0;
2341 for (i = 0; i < num_elements; i++) {
2343 const char *existing_tzid;
2344 size_t existing_tzid_len;
2345
2346 zone = icalarray_element_at(comp->timezones, i);
2347 existing_tzid = icaltimezone_get_tzid(zone);
2348
2349 /* Find the length of the TZID without any trailing digits. */
2350 existing_tzid_len = icalcomponent_get_tzid_prefix_len(existing_tzid);
2351
2352 /* Check if we have the same prefix. */
2353 if (tzid_len == existing_tzid_len && strncmp(tzid, existing_tzid, tzid_len) == 0) {
2354 /* Compare the VTIMEZONEs. */
2355 const int match = icalcomponent_compare_vtimezones(icaltimezone_get_component(zone), vtimezone);
2356 if (match == -1) {
2357 return false;
2358 }
2359 if (match == 1) {
2360 /* The VTIMEZONEs match, so we can use the existing VTIMEZONE. But
2361 we have to rename TZIDs to this TZID. */
2362 icalstrarray_append(tzids_to_rename, tzid);
2363 icalstrarray_append(tzids_to_rename, existing_tzid);
2364 return true;
2365 }
2366
2367 /* Convert the suffix to an integer and remember the maximum numeric suffix found. */
2368 char *t_end;
2369 const char *t = existing_tzid + existing_tzid_len;
2370 const long suffix = strtol(t, &t_end, 10);
2371 if (t != t_end && suffix > max_suffix && suffix < INT_MAX) {
2372 max_suffix = (int)suffix;
2373 }
2374 }
2375 }
2376
2377 /* We didn't find a VTIMEZONE that matched, so we have to rename the TZID,
2378 using the maximum numerical suffix found + 1. */
2379 snprintf(suffix_buf, sizeof(suffix_buf), "%i", max_suffix + 1);
2380 const size_t len_new_tzid = tzid_len + strlen(suffix_buf) + 1;
2381 new_tzid = icalmemory_new_buffer(len_new_tzid);
2382 if (!new_tzid) {
2384 return false;
2385 }
2386 strncpy(new_tzid, tzid, tzid_len);
2387 new_tzid[tzid_len] = '\0';
2388 strncat(new_tzid, suffix_buf, len_new_tzid);
2389 new_tzid[len_new_tzid - 1] = '\0';
2390 icalstrarray_append(tzids_to_rename, tzid);
2391 icalstrarray_append(tzids_to_rename, new_tzid);
2392
2393 /* Add the VTIMEZONE to comp under its new TZID. */
2394 icalproperty_set_tzid(tzid_prop, new_tzid);
2395 icalcomponent_remove_component(icalcomponent_get_parent(vtimezone), vtimezone);
2396 icalcomponent_add_component(comp, vtimezone);
2397
2398 icalmemory_free_buffer(new_tzid);
2399 return true;
2400}
2401
2402/* Returns the length of the TZID, without any trailing digits. */
2403static size_t icalcomponent_get_tzid_prefix_len(const char *tzid)
2404{
2405 size_t len;
2406 const char *p;
2407
2408 len = strlen(tzid);
2409 p = tzid + len - 1;
2410 while (len > 0 && *p >= '0' && *p <= '9') {
2411 p--;
2412 len--;
2413 }
2414
2415 return len;
2416}
2417
2423static void icalcomponent_rename_tzids(icalcomponent *comp, icalstrarray *rename_table)
2424{
2425 icalcomponent_foreach_tzid(comp, icalcomponent_rename_tzids_callback, rename_table);
2426}
2427
2428static void icalcomponent_rename_tzids_callback(icalparameter *param, void *data)
2429{
2430 icalstrarray *rename_table = data;
2431 const char *tzid;
2432 size_t i;
2433
2434 tzid = icalparameter_get_tzid(param);
2435 if (!tzid) {
2436 return;
2437 }
2438
2439 /* Step through the rename table to see if the current TZID matches
2440 any of the ones we want to rename. */
2441 for (i = 0; i + 1 < icalstrarray_size(rename_table); i += 2) {
2442 const char *from = icalstrarray_element_at(rename_table, i);
2443 const char *to = icalstrarray_element_at(rename_table, i + 1);
2444 if (from && to && !strcmp(tzid, from)) {
2445 icalparameter_set_tzid(param, to);
2446 break;
2447 }
2448 }
2449}
2450
2451void icalcomponent_foreach_tzid(icalcomponent *comp,
2452 void (*callback)(icalparameter *param, void *data),
2453 void *callback_data)
2454{
2455 icalproperty *prop;
2456 icalcomponent *subcomp;
2457
2458 /* First look for any TZID parameters used in this component itself. */
2460 while (prop) {
2462
2463 /* These are the only properties that can have a TZID. Note that
2464 COMPLETED, CREATED, DTSTAMP & LASTMODIFIED must be in UTC. */
2465 if (kind == ICAL_DTSTART_PROPERTY ||
2466 kind == ICAL_DTEND_PROPERTY ||
2467 kind == ICAL_DUE_PROPERTY ||
2468 kind == ICAL_EXDATE_PROPERTY ||
2469 kind == ICAL_RDATE_PROPERTY) {
2471 if (param) {
2472 (*callback)(param, callback_data);
2473 }
2474 }
2475
2477 }
2478
2479 /* Now recursively check child components. */
2481 while (subcomp) {
2482 icalcomponent_foreach_tzid(subcomp, callback, callback_data);
2484 }
2485}
2486
2487icaltimezone *icalcomponent_get_timezone(icalcomponent *comp, const char *tzid)
2488{
2490 size_t lower, upper;
2491
2492 if (!comp->timezones) {
2493 return NULL;
2494 }
2495
2496 /* Sort the array if necessary (by the TZID string). */
2497 if (!comp->timezones_sorted) {
2498 icalarray_sort(comp->timezones, icalcomponent_compare_timezone_fn);
2499 comp->timezones_sorted = 1;
2500 }
2501
2502 /* Do a simple binary search. */
2503 lower = 0;
2504 upper = comp->timezones->num_elements;
2505
2506 while (lower < upper) {
2507 size_t middle = (lower + upper) >> 1;
2508 zone = icalarray_element_at(comp->timezones, middle);
2509 const char *zone_tzid = icaltimezone_get_tzid(zone);
2510 if (zone_tzid != NULL) {
2511 int cmp = strcmp(tzid, zone_tzid);
2512 if (cmp == 0) {
2513 return zone;
2514 } else if (cmp < 0) {
2515 upper = middle;
2516 } else {
2517 lower = middle + 1;
2518 }
2519 }
2520 }
2521
2522 return NULL;
2523}
2524
2528static int icalcomponent_compare_timezone_fn(const void *elem1, const void *elem2)
2529{
2530 bool zone1_is_valid = false, zone2_is_valid = false;
2531 const char *zone1_tzid = 0, *zone2_tzid = 0;
2532
2533 icaltimezone *zone1 = (icaltimezone *)elem1;
2534 icaltimezone *zone2 = (icaltimezone *)elem2;
2535
2536 if (zone1) {
2537 zone1_tzid = icaltimezone_get_tzid(zone1);
2538 if (zone1_tzid) {
2539 zone1_is_valid = true;
2540 }
2541 }
2542 if (zone2) {
2543 zone2_tzid = icaltimezone_get_tzid(zone2);
2544 if (zone2_tzid) {
2545 zone2_is_valid = true;
2546 }
2547 }
2548
2549 if (zone1_is_valid && !zone2_is_valid) {
2550 return 1;
2551 }
2552 if (!zone1_is_valid) {
2553 if (zone2_is_valid) {
2554 return -1;
2555 } else {
2556 return 0;
2557 }
2558 }
2559
2560 return strcmp(zone1_tzid, zone2_tzid);
2561}
2562
2567static int icalcomponent_compare_vtimezones(icalcomponent *vtimezone1, icalcomponent *vtimezone2)
2568{
2569 icalproperty *prop1, *prop2;
2570 const char *tzid1, *tzid2;
2571 char *tzid2_copy, *string1, *string2;
2572 int cmp;
2573
2574 /* Get the TZID property of the first VTIMEZONE. */
2576 if (!prop1) {
2577 return -1;
2578 }
2579
2580 tzid1 = icalproperty_get_tzid(prop1);
2581 if (!tzid1) {
2582 return -1;
2583 }
2584
2585 /* Get the TZID property of the second VTIMEZONE. */
2587 if (!prop2) {
2588 return -1;
2589 }
2590
2591 tzid2 = icalproperty_get_tzid(prop2);
2592 if (!tzid2) {
2593 return -1;
2594 }
2595
2596 /* Copy the second TZID, and set the property to the same as the first
2597 TZID, since we don't care if these match of not. */
2598 tzid2_copy = icalmemory_strdup(tzid2);
2599 if (!tzid2_copy) {
2601 return 0;
2602 }
2603
2604 icalproperty_set_tzid(prop2, tzid1);
2605
2606 /* Now convert both VTIMEZONEs to strings and compare them. */
2607 string1 = icalcomponent_as_ical_string_r(vtimezone1);
2608 if (!string1) {
2609 icalmemory_free_buffer(tzid2_copy);
2610 return -1;
2611 }
2612
2613 string2 = icalcomponent_as_ical_string_r(vtimezone2);
2614 if (!string2) {
2615 icalmemory_free_buffer(string1);
2616 icalmemory_free_buffer(tzid2_copy);
2617 return -1;
2618 }
2619
2620 cmp = strcmp(string1, string2);
2621
2622 icalmemory_free_buffer(string1);
2623 icalmemory_free_buffer(string2);
2624
2625 /* Now reset the second TZID. */
2626 icalproperty_set_tzid(prop2, tzid2_copy);
2627 icalmemory_free_buffer(tzid2_copy);
2628
2629 return (cmp == 0) ? 1 : 0;
2630}
2631
2632void icalcomponent_set_relcalid(icalcomponent *comp, const char *v)
2633{
2634 ICALSETUPSET(ICAL_RELCALID_PROPERTY);
2635
2636 if (prop == 0) {
2637 prop = icalproperty_new_relcalid(v);
2638 icalcomponent_add_property(inner, prop);
2639 }
2640
2642}
2643
2644const char *icalcomponent_get_relcalid(icalcomponent *comp)
2645{
2646 icalcomponent *inner;
2647 icalproperty *prop;
2648
2649 icalerror_check_arg_rz(comp != 0, "comp");
2650
2651 inner = icalcomponent_get_inner(comp);
2652
2653 if (inner == 0) {
2654 return 0;
2655 }
2656
2658
2659 if (prop == 0) {
2660 return 0;
2661 }
2662
2663 return icalproperty_get_relcalid(prop);
2664}
2665
2666struct icaltimetype icalcomponent_get_due(icalcomponent *comp)
2667{
2668 icalcomponent *inner = icalcomponent_get_inner(comp);
2669
2670 icalproperty *due_prop = icalcomponent_get_first_property(inner, ICAL_DUE_PROPERTY);
2671
2672 icalproperty *dur_prop = icalcomponent_get_first_property(inner, ICAL_DURATION_PROPERTY);
2673
2674 if (due_prop != 0) {
2675 return icalproperty_get_datetime_with_component(due_prop, comp);
2676 } else if (dur_prop != 0) {
2677 struct icaltimetype start = icalcomponent_get_dtstart(inner);
2678 struct icaldurationtype duration = icalproperty_get_duration(dur_prop);
2679
2680 struct icaltimetype due = icalduration_extend(start, duration);
2681
2682 return due;
2683 }
2684 return icaltime_null_time();
2685}
2686
2687void icalcomponent_set_due(icalcomponent *comp, struct icaltimetype v)
2688{
2689 const char *tzid;
2690
2691 icalcomponent *inner = icalcomponent_get_inner(comp);
2692
2693 icalproperty *due_prop = icalcomponent_get_first_property(inner, ICAL_DUE_PROPERTY);
2694
2695 icalproperty *dur_prop = icalcomponent_get_first_property(inner, ICAL_DURATION_PROPERTY);
2696
2697 if (due_prop == 0 && dur_prop == 0) {
2698 due_prop = icalproperty_new_due(v);
2699 icalcomponent_add_property(inner, due_prop);
2700 } else if (due_prop != 0) {
2701 icalproperty_set_due(due_prop, v);
2703 } else if (dur_prop != 0) {
2704 struct icaltimetype start = icalcomponent_get_dtstart(inner);
2705
2706 struct icaltimetype due = icalcomponent_get_due(inner);
2707
2708 struct icaldurationtype dur = icalduration_from_times(due, start);
2709
2710 icalproperty_set_duration(dur_prop, dur);
2711 }
2712
2713 if (due_prop && (tzid = icaltime_get_tzid(v)) != NULL && !icaltime_is_utc(v)) {
2715 }
2716}
2717
2718static int strcmpsafe(const char *a, const char *b)
2719{
2720 return strcmp((a == NULL ? "" : a),
2721 (b == NULL ? "" : b));
2722}
2723
2724static int prop_compare(void *a, void *b)
2725{
2726 const icalproperty *p1 = (icalproperty *)a;
2727 const icalproperty *p2 = (icalproperty *)b;
2730 int r = (int)k1 - (int)k2;
2731
2732 if (r == 0) {
2733 if (k1 == ICAL_X_PROPERTY) {
2734 r = strcmp(icalproperty_get_x_name(p1),
2736 }
2737
2738 if (r == 0) {
2739 r = strcmpsafe(icalproperty_get_value_as_string(p1),
2741 }
2742 }
2743
2744 return r;
2745}
2746
2747static inline int compare_nullptr(const void *a, const void *b)
2748{
2749 if (!a == !b) {
2750 return 0;
2751 }
2752
2753 // non-NULL sorts before NULL
2754 return a ? -1 : 1;
2755}
2756
2757static int comp_compare(void *a, void *b)
2758{
2759 icalcomponent *c1 = (icalcomponent *)a;
2760 icalcomponent *c2 = (icalcomponent *)b;
2763 int r = (int)k1 - (int)k2;
2764
2765 if (r == 0) {
2766 if ((k1 == ICAL_X_COMPONENT || k1 == ICAL_IANA_COMPONENT) &&
2767 (c1->x_name && c2->x_name)) {
2768 r = strcmp(c1->x_name, c2->x_name);
2769 }
2770
2771 if (r == 0) {
2772 const char *u1 = icalcomponent_get_uid(c1);
2773 const char *u2 = icalcomponent_get_uid(c2);
2774
2775 if (u1 && u2) {
2776 r = strcmp(u1, u2);
2777
2778 if (r == 0) {
2781 }
2782 } else {
2783 const icalproperty *p1, *p2;
2784
2785 switch (k1) {
2791 if (p1 && p2) {
2792 r = strcmp(icalproperty_get_value_as_string(p1),
2794 if (r == 0) {
2799 if (p1 && p2) {
2800 r = strcmp(icalproperty_get_value_as_string(p1),
2802 } else {
2803 r = compare_nullptr(p1, p2);
2804 }
2805 }
2806 } else {
2807 r = compare_nullptr(p1, p2);
2808 }
2809
2810 break;
2811
2817 if (p1 && p2) {
2818 r = strcmp(icalproperty_get_value_as_string(p1),
2820 } else {
2821 r = compare_nullptr(p1, p2);
2822 }
2823 break;
2824
2831
2832 if (p1 && p2) {
2833 r = strcmp(icalproperty_get_value_as_string(p1),
2835 } else {
2836 r = compare_nullptr(p1, p2);
2837 }
2838 break;
2839
2845
2846 if (p1 && p2) {
2847 r = strcmp(icalproperty_get_value_as_string(p1),
2849 } else {
2850 r = compare_nullptr(p1, p2);
2851 }
2852 break;
2853
2859
2860 if (p1 && p2) {
2861 r = strcmp(icalproperty_get_value_as_string(p1),
2863 } else {
2864 r = compare_nullptr(p1, p2);
2865 }
2866 break;
2867
2868 default:
2869 /* XXX Anything better? */
2872 break;
2873 }
2874 }
2875 }
2876 /* Always sort VTIMEZONEs first */
2877 } else if (k1 == ICAL_VTIMEZONE_COMPONENT) {
2878 return -1;
2879 } else if (k2 == ICAL_VTIMEZONE_COMPONENT) {
2880 return 1;
2881 }
2882
2883 return r;
2884}
2885
2886static bool string_contains_non_printing(const char *s)
2887{
2888 while (*s && isgraph((unsigned char)*s)) {
2889 ++s;
2890 }
2891 return *s != '\0';
2892}
2893void icalcomponent_normalize(icalcomponent *comp)
2894{
2895 icalproperty *prop;
2896 icalcomponent *sub;
2897 icalpvl_list sorted_props;
2898 icalpvl_list sorted_comps;
2899 size_t cnt = 0; //track properties
2900
2901 icalerror_check_arg(comp != 0, "comp");
2902 if (!comp) {
2903 return;
2904 }
2905
2906 sorted_props = icalpvl_newlist();
2907 sorted_comps = icalpvl_newlist();
2908
2909 /* oss-fuzz sets the cpu timeout at 60 seconds.
2910 * In order to meet that requirement we need to cap the number of properties.
2911 */
2912 const size_t max_properties = icallimit_get(ICAL_LIMIT_PROPERTIES);
2913 /* Normalize properties into sorted list */
2914 while ((++cnt < max_properties) && ((prop = icalpvl_pop(comp->properties)) != 0)) {
2915 int nparams, remove = 0;
2916
2918
2919 nparams = icalproperty_count_parameters(prop);
2920
2921 /* Remove un-parameterized properties having default values */
2922 if (nparams == 0) {
2923 switch (icalproperty_isa(prop)) {
2925 if (strcmp("GREGORIAN", icalproperty_get_calscale(prop)) == 0) {
2926 remove = 1;
2927 }
2928 break;
2929
2932 remove = 1;
2933 }
2934 break;
2935
2937 if (icalproperty_get_priority(prop) == 0) {
2938 remove = 1;
2939 }
2940 break;
2941
2944 remove = 1;
2945 }
2946 break;
2947
2949 if (icalproperty_get_repeat(prop) == 0) {
2950 remove = 1;
2951 }
2952 break;
2953
2955 if (icalproperty_get_sequence(prop) == 0) {
2956 remove = 1;
2957 }
2958 break;
2959
2960 case ICAL_UID_PROPERTY: {
2961 const char *uid = icalproperty_get_uid(prop);
2962 if (!uid || string_contains_non_printing(uid)) {
2963 remove = 1;
2964 }
2965 break;
2966 }
2967 default:
2968 break;
2969 }
2970 }
2971
2972 if (remove) {
2973 icalproperty_set_parent(prop, 0); // MUST NOT have a parent to free
2974 icalproperty_free(prop);
2975 } else {
2976 icalpvl_insert_ordered(sorted_props, prop_compare, prop);
2977 }
2978 }
2979
2980 /* Drain the remaining properties */
2981 if (cnt == max_properties) {
2982 while ((prop = icalpvl_pop(comp->properties)) != 0) {
2983 icalproperty_set_parent(prop, 0); // MUST NOT have a parent to free
2984 icalproperty_free(prop);
2985 }
2986 }
2987
2988 icalpvl_free(comp->properties);
2989 comp->properties = sorted_props;
2990
2991 /* Normalize sub-components into sorted list */
2992 while ((sub = icalpvl_pop(comp->components)) != 0) {
2994 icalpvl_insert_ordered(sorted_comps, comp_compare, sub);
2995 }
2996
2997 icalpvl_free(comp->components);
2998 comp->components = sorted_comps;
2999}
void * icalarray_element_at(icalarray *array, size_t position)
Access an array element.
Definition icalarray.c:135
void icalarray_free(icalarray *array)
Definition icalarray.c:104
void icalarray_sort(icalarray *array, int(*compare)(const void *, const void *))
Sorts the elements of an icalarray using the given comparison function.
Definition icalarray.c:182
void icalarray_append(icalarray *array, const void *element)
Appends an element to an array.
Definition icalarray.c:119
icalarray * icalarray_new(size_t element_size, size_t increment_size)
Definition icalarray.c:36
void icalarray_remove_element_at(icalarray *array, size_t position)
Removes a given element from an array.
Definition icalarray.c:148
void icalcomponent_remove_property_by_kind(icalcomponent *component, icalproperty_kind kind)
void icalcomponent_convert_errors(icalcomponent *component)
icalcomponent * icalcomponent_new_xstandard(void)
void icalcomponent_set_relcalid(icalcomponent *comp, const char *v)
bool icalcomponent_is_valid(const icalcomponent *component)
icalproperty * icalpropiter_deref(icalpropiter *i)
icalcomponent * icalcomponent_new_vagenda(void)
void icalcomponent_set_uid(icalcomponent *comp, const char *v)
icalcomponent_kind icalcomponent_string_to_kind(const char *string)
void icalcomponent_set_x_name(icalcomponent *comp, const char *name)
struct icaltimetype icalcomponent_get_dtend(icalcomponent *comp)
struct icaltimetype icalcomponent_get_dtstart(icalcomponent *comp)
icalcomponent * icalcomponent_new_vlocation(void)
icalproperty * icalcomponent_get_first_property(icalcomponent *c, icalproperty_kind kind)
bool icalcomponent_check_restrictions(icalcomponent *comp)
icalcomponent * icalcomponent_new_vpoll(void)
int icalcomponent_count_properties(icalcomponent *component, icalproperty_kind kind)
icalcomponent * icalcomponent_new_vavailability(void)
icalcomponent * icalcomponent_new_xpatch(void)
icalproperty_method icalcomponent_get_method(icalcomponent *comp)
bool icalcompiter_is_valid(const icalcompiter *i)
icalcomponent * icalcomponent_new_vreply(void)
void icalcomponent_set_recurrenceid(icalcomponent *comp, struct icaltimetype v)
icalcomponent * icalcomponent_new_xvote(void)
struct icaltimetype icalcomponent_get_recurrenceid(icalcomponent *comp)
icalcomponent * icalcompiter_next(icalcompiter *i)
void icalcomponent_set_location(icalcomponent *comp, const char *v)
const char * icalcomponent_get_description(icalcomponent *comp)
void icalcomponent_set_iana_name(icalcomponent *comp, const char *name)
icalcomponent * icalcomponent_get_next_component(icalcomponent *c, icalcomponent_kind kind)
icalcomponent * icalcomponent_get_first_component(icalcomponent *c, icalcomponent_kind kind)
void icalcomponent_set_dtstart(icalcomponent *comp, struct icaltimetype v)
void icalcomponent_set_dtstamp(icalcomponent *comp, struct icaltimetype v)
void icalcomponent_strip_errors(icalcomponent *component)
icalcomponent * icalcomponent_new_vcalendar(void)
void icalcomponent_normalize(icalcomponent *comp)
icalpropiter icalcomponent_begin_property(icalcomponent *component, icalproperty_kind kind)
icalcomponent * icalcomponent_get_current_component(icalcomponent *component)
void icalcomponent_remove_property(icalcomponent *component, icalproperty *property)
char * icalcomponent_as_ical_string(const icalcomponent *component)
const char * icalcomponent_kind_to_string(icalcomponent_kind kind)
enum icalproperty_status icalcomponent_get_status(icalcomponent *comp)
icalcomponent * icalcomponent_new_vjournal(void)
void icalcomponent_remove_component(icalcomponent *parent, icalcomponent *child)
icalcomponent * icalcomponent_new_vpatch(void)
icalcomponent * icalcomponent_new_vfreebusy(void)
icalproperty * icalpropiter_next(icalpropiter *i)
icalcomponent * icalcompiter_deref(icalcompiter *i)
icalcomponent * icalcomponent_vanew(icalcomponent_kind kind,...)
void icalcomponent_set_method(icalcomponent *comp, icalproperty_method method)
icalcomponent * icalcomponent_new(icalcomponent_kind kind)
void icalcomponent_set_summary(icalcomponent *comp, const char *v)
void icalcomponent_set_sequence(icalcomponent *comp, int v)
icalcomponent * icalcomponent_get_inner(icalcomponent *comp)
const char * icalcomponent_get_comment(icalcomponent *comp)
const char * icalcomponent_get_summary(icalcomponent *comp)
icaltime_span icalcomponent_get_span(icalcomponent *comp)
const char * icalcomponent_get_relcalid(icalcomponent *comp)
icalcomponent * icalcomponent_get_first_real_component(const icalcomponent *c)
icalcomponent * icalcomponent_new_vtimezone(void)
struct icaltimetype icalcomponent_get_due(icalcomponent *comp)
void icalcomponent_merge_component(icalcomponent *comp, icalcomponent *comp_to_merge)
bool icalpropiter_is_valid(const icalpropiter *i)
icalcomponent * icalcomponent_new_vresource(void)
bool icalproperty_recurrence_is_excluded(icalcomponent *comp, struct icaltimetype *dtstart, struct icaltimetype *recurtime)
Decides if a recurrence is acceptable.
const char * icalcomponent_get_x_name(const icalcomponent *comp)
int icalcomponent_count_errors(icalcomponent *component)
struct icaldurationtype icalcomponent_get_duration(icalcomponent *comp)
icalcomponent * icalcomponent_clone(const icalcomponent *old)
icalcomponent * icalcomponent_new_iana(const char *iana_name)
icalcomponent * icalcomponent_new_xavailable(void)
icalcomponent * icalcomponent_new_participant(void)
const char * icalcomponent_get_iana_name(const icalcomponent *comp)
icalproperty * icalcomponent_get_current_property(icalcomponent *component)
icaltimezone * icalcomponent_get_timezone(icalcomponent *comp, const char *tzid)
void icalcomponent_set_dtend(icalcomponent *comp, struct icaltimetype v)
const char * icalcomponent_get_uid(icalcomponent *comp)
int icalcomponent_get_sequence(icalcomponent *comp)
icalcompiter icalcomponent_end_component(icalcomponent *component, icalcomponent_kind kind)
const char * icalcomponent_get_component_name(const icalcomponent *comp)
icalcomponent * icalcomponent_new_xdaylight(void)
icalcomponent * icalcomponent_new_valarm(void)
icalcomponent * icalcomponent_new_x(const char *x_name)
void icalcomponent_add_property(icalcomponent *component, icalproperty *property)
void icalcomponent_set_duration(icalcomponent *comp, struct icaldurationtype v)
icalcompiter icalcomponent_begin_component(icalcomponent *component, icalcomponent_kind kind)
char * icalcomponent_as_ical_string_r(const icalcomponent *component)
icalcomponent_kind icalcomponent_isa(const icalcomponent *component)
icalcomponent * icalcompiter_prior(icalcompiter *i)
icalcomponent * icalcomponent_new_vtodo(void)
bool icalcomponent_kind_is_valid(const icalcomponent_kind kind)
char * icalcomponent_get_component_name_r(const icalcomponent *comp)
void icalcomponent_set_status(icalcomponent *comp, enum icalproperty_status v)
void icalcomponent_foreach_tzid(icalcomponent *comp, void(*callback)(icalparameter *param, void *data), void *callback_data)
const char * icalcomponent_get_location(icalcomponent *comp)
void icalcomponent_free(icalcomponent *c)
icalcomponent * icalcomponent_new_vevent(void)
void icalcomponent_set_due(icalcomponent *comp, struct icaltimetype v)
void icalcomponent_foreach_recurrence(icalcomponent *comp, struct icaltimetype start, struct icaltimetype end, void(*callback)(icalcomponent *comp, const struct icaltime_span *span, void *data), void *callback_data)
void icalcomponent_add_component(icalcomponent *parent, icalcomponent *child)
icalproperty * icalcomponent_get_next_property(icalcomponent *c, icalproperty_kind kind)
void icalcomponent_set_description(icalcomponent *comp, const char *v)
icalcomponent * icalcomponent_new_from_string(const char *str)
int icalcomponent_count_components(icalcomponent *component, icalcomponent_kind kind)
void icalcomponent_set_comment(icalcomponent *comp, const char *v)
icalcomponent * icalcomponent_new_vquery(void)
bool icalcomponent_isa_component(const void *component)
icalcomponent * icalcomponent_new_vvoter(void)
struct icaltimetype icalcomponent_get_dtstamp(icalcomponent *comp)
Defines the data structure for iCalendar components.
icalcomponent * icalproperty_get_parent(const icalproperty *property)
struct icaltimetype icalproperty_get_datetime_with_component(icalproperty *prop, icalcomponent *comp)
void icalproperty_set_parent(icalproperty *property, icalcomponent *component)
icalparameter_xlicerrortype icalparameter_get_xlicerrortype(const icalparameter *value)
@ ICAL_TZID_PARAMETER
@ ICAL_XLICERRORTYPE_PARAMETER
void icalparameter_set_tzid(icalparameter *value, const char *v)
const char * icalparameter_get_tzid(const icalparameter *value)
struct icalparameter_impl icalparameter
icalparameter * icalparameter_new_tzid(const char *v)
@ ICAL_XLICERRORTYPE_PROPERTYPARSEERROR
@ ICAL_XLICERRORTYPE_PARAMETERNAMEPARSEERROR
@ ICAL_XLICERRORTYPE_PARAMETERVALUEPARSEERROR
@ ICAL_XLICERRORTYPE_VALUEPARSEERROR
@ ICAL_XLICERRORTYPE_COMPONENTPARSEERROR
void icalproperty_set_dtstart(icalproperty *prop, struct icaltimetype v)
int icalproperty_get_repeat(const icalproperty *prop)
enum icalproperty_transp icalproperty_get_transp(const icalproperty *prop)
const char * icalproperty_get_uid(const icalproperty *prop)
int icalproperty_get_sequence(const icalproperty *prop)
icalproperty * icalproperty_new_comment(const char *v)
void icalproperty_set_tzid(icalproperty *prop, const char *v)
struct icaltimetype icalproperty_get_dtstamp(const icalproperty *prop)
icalproperty * icalproperty_new_description(const char *v)
icalproperty * icalproperty_new_dtend(struct icaltimetype v)
void icalproperty_set_due(icalproperty *prop, struct icaltimetype v)
icalproperty * icalproperty_new_dtstamp(struct icaltimetype v)
void icalproperty_set_uid(icalproperty *prop, const char *v)
const char * icalproperty_get_description(const icalproperty *prop)
icalproperty * icalproperty_new_sequence(int v)
void icalproperty_set_comment(icalproperty *prop, const char *v)
void icalproperty_set_sequence(icalproperty *prop, int v)
void icalproperty_set_dtend(icalproperty *prop, struct icaltimetype v)
const char * icalproperty_get_summary(const icalproperty *prop)
struct icalrecurrencetype * icalproperty_get_exrule(const icalproperty *prop)
icalproperty * icalproperty_new_method(enum icalproperty_method v)
struct icaldurationtype icalproperty_get_duration(const icalproperty *prop)
icalproperty * icalproperty_new_relcalid(const char *v)
void icalproperty_set_duration(icalproperty *prop, struct icaldurationtype v)
const char * icalproperty_get_comment(const icalproperty *prop)
void icalproperty_set_summary(icalproperty *prop, const char *v)
enum icalproperty_status icalproperty_get_status(const icalproperty *prop)
void icalproperty_set_location(icalproperty *prop, const char *v)
enum icalproperty_class icalproperty_get_class(const icalproperty *prop)
void icalproperty_set_recurrenceid(icalproperty *prop, struct icaltimetype v)
struct icalrecurrencetype * icalproperty_get_rrule(const icalproperty *prop)
icalproperty * icalproperty_new_uid(const char *v)
const char * icalproperty_get_tzid(const icalproperty *prop)
struct icaldatetimeperiodtype icalproperty_get_rdate(const icalproperty *prop)
void icalproperty_set_relcalid(icalproperty *prop, const char *v)
enum icalproperty_method icalproperty_get_method(const icalproperty *prop)
void icalproperty_set_method(icalproperty *prop, enum icalproperty_method v)
const char * icalproperty_get_calscale(const icalproperty *prop)
icalproperty * icalproperty_new_summary(const char *v)
icalproperty * icalproperty_new_location(const char *v)
void icalproperty_set_dtstamp(icalproperty *prop, struct icaltimetype v)
const char * icalproperty_get_xlicerror(const icalproperty *prop)
icalproperty * icalproperty_new_duration(struct icaldurationtype v)
icalproperty * icalproperty_new_requeststatus(struct icalreqstattype v)
icalproperty_kind
@ ICAL_CALSCALE_PROPERTY
@ ICAL_ANY_PROPERTY
@ ICAL_RELCALID_PROPERTY
@ ICAL_UID_PROPERTY
@ ICAL_RRULE_PROPERTY
@ ICAL_RDATE_PROPERTY
@ ICAL_DURATION_PROPERTY
@ ICAL_COMMENT_PROPERTY
@ ICAL_EXRULE_PROPERTY
@ ICAL_DESCRIPTION_PROPERTY
@ ICAL_TRANSP_PROPERTY
@ ICAL_XLICERROR_PROPERTY
@ ICAL_TZID_PROPERTY
@ ICAL_SUMMARY_PROPERTY
@ ICAL_SEQUENCE_PROPERTY
@ ICAL_RECURRENCEID_PROPERTY
@ ICAL_PRIORITY_PROPERTY
@ ICAL_EXDATE_PROPERTY
@ ICAL_METHOD_PROPERTY
@ ICAL_POLLITEMID_PROPERTY
@ ICAL_DUE_PROPERTY
@ ICAL_ACTION_PROPERTY
@ ICAL_VOTER_PROPERTY
@ ICAL_STATUS_PROPERTY
@ ICAL_DTSTAMP_PROPERTY
@ ICAL_LOCATION_PROPERTY
@ ICAL_DTEND_PROPERTY
@ ICAL_DTSTART_PROPERTY
@ ICAL_REPEAT_PROPERTY
@ ICAL_TRIGGER_PROPERTY
@ ICAL_X_PROPERTY
@ ICAL_CLASS_PROPERTY
@ ICAL_NO_PROPERTY
int icalproperty_get_priority(const icalproperty *prop)
void icalproperty_set_description(icalproperty *prop, const char *v)
icalproperty * icalproperty_new_dtstart(struct icaltimetype v)
const char * icalproperty_get_location(const icalproperty *prop)
void icalproperty_set_status(icalproperty *prop, enum icalproperty_status v)
icalproperty * icalproperty_new_due(struct icaltimetype v)
icalproperty * icalproperty_new_status(enum icalproperty_status v)
icalproperty * icalproperty_new_recurrenceid(struct icaltimetype v)
const char * icalproperty_get_relcalid(const icalproperty *prop)
icalproperty_status
@ ICAL_STATUS_TENTATIVE
@ ICAL_STATUS_CANCELLED
@ ICAL_STATUS_NONE
icalproperty_method
@ ICAL_METHOD_NONE
enum icalproperty_transp icalvalue_get_transp(const icalvalue *value)
@ ICAL_CLASS_PUBLIC
@ ICAL_TRANSP_TRANSPARENT
@ ICAL_TRANSP_OPAQUENOCONFLICT
@ ICAL_TRANSP_NONE
@ ICAL_TRANSP_OPAQUE
@ ICAL_TRANSP_TRANSPARENTNOCONFLICT
struct icalvalue_impl icalvalue
struct icaldurationtype icalduration_from_times(struct icaltimetype t1, struct icaltimetype t2)
Creates a duration from two icaltimetype endpoints.
struct icaltimetype icalduration_extend(struct icaltimetype t, struct icaldurationtype d)
Extends a time duration.
bool icaldurationtype_is_null_duration(struct icaldurationtype d)
Checks if a duration is a null duration.
struct icaldurationtype icaldurationtype_null_duration(void)
Creates a duration with zero length.
icalcomponent_kind
Definition icalenums.h:29
@ ICAL_X_COMPONENT
Definition icalenums.h:48
@ ICAL_XROOT_COMPONENT
Definition icalenums.h:32
@ ICAL_XDAYLIGHT_COMPONENT
Definition icalenums.h:47
@ ICAL_VREPLY_COMPONENT
Definition icalenums.h:51
@ ICAL_VLOCATION_COMPONENT
Definition icalenums.h:65
@ ICAL_XSTANDARD_COMPONENT
Definition icalenums.h:46
@ ICAL_NO_COMPONENT
Definition icalenums.h:30
@ ICAL_VFREEBUSY_COMPONENT
Definition icalenums.h:39
@ ICAL_VTODO_COMPONENT
Definition icalenums.h:35
@ ICAL_PARTICIPANT_COMPONENT
Definition icalenums.h:64
@ ICAL_VEVENT_COMPONENT
Definition icalenums.h:34
@ ICAL_VPATCH_COMPONENT
Definition icalenums.h:62
@ ICAL_VCALENDAR_COMPONENT
Definition icalenums.h:37
@ ICAL_VAVAILABILITY_COMPONENT
Definition icalenums.h:57
@ ICAL_IANA_COMPONENT
Definition icalenums.h:67
@ ICAL_VSCHEDULE_COMPONENT
Definition icalenums.h:49
@ ICAL_XVOTE_COMPONENT
Definition icalenums.h:61
@ ICAL_VAGENDA_COMPONENT
Definition icalenums.h:38
@ ICAL_ANY_COMPONENT
Definition icalenums.h:31
@ ICAL_VTIMEZONE_COMPONENT
Definition icalenums.h:45
@ ICAL_VJOURNAL_COMPONENT
Definition icalenums.h:36
@ ICAL_VVOTER_COMPONENT
Definition icalenums.h:60
@ ICAL_VCAR_COMPONENT
Definition icalenums.h:52
@ ICAL_VCOMMAND_COMPONENT
Definition icalenums.h:53
@ ICAL_VQUERY_COMPONENT
Definition icalenums.h:50
@ ICAL_XLICMIMEPART_COMPONENT
Definition icalenums.h:55
@ ICAL_XPATCH_COMPONENT
Definition icalenums.h:63
@ ICAL_VPOLL_COMPONENT
Definition icalenums.h:59
@ ICAL_XAVAILABLE_COMPONENT
Definition icalenums.h:58
@ ICAL_XLICINVALID_COMPONENT
Definition icalenums.h:54
@ ICAL_VRESOURCE_COMPONENT
Definition icalenums.h:66
@ ICAL_VALARM_COMPONENT
Definition icalenums.h:40
@ ICAL_3_2_INVPARAM_STATUS
Definition icalenums.h:95
@ ICAL_3_0_INVPROPNAME_STATUS
Definition icalenums.h:93
@ ICAL_3_1_INVPROPVAL_STATUS
Definition icalenums.h:94
@ ICAL_3_4_INVCOMP_STATUS
Definition icalenums.h:97
@ ICAL_3_3_INVPARAMVAL_STATUS
Definition icalenums.h:96
@ ICAL_UNKNOWN_STATUS
Definition icalenums.h:80
void icalerror_set_errno(icalerrorenum x)
Sets the icalerrno to a given error.
Definition icalerror.c:90
Error handling for libical.
@ ICAL_NEWFAILED_ERROR
Definition icalerror.h:50
@ ICAL_BADARG_ERROR
Definition icalerror.h:47
@ ICAL_ALLOCATION_ERROR
Definition icalerror.h:53
@ ICAL_MALFORMEDDATA_ERROR
Definition icalerror.h:59
@ ICAL_USAGE_ERROR
Definition icalerror.h:71
size_t icallimit_get(icallimits_kind kind)
Definition icallimits.c:29
Defines the interface for getting/setting internal library limits.
@ ICAL_LIMIT_PROPERTIES
Definition icallimits.h:30
void icalmemory_free_buffer(void *buf)
Releases a buffer.
Definition icalmemory.c:355
char * icalmemory_strdup(const char *s)
Creates a duplicate of a string.
Definition icalmemory.c:242
void icalmemory_append_string(char **buf, char **pos, size_t *buf_size, const char *string)
Appends a string to a buffer.
Definition icalmemory.c:365
void * icalmemory_new_buffer(size_t size)
Creates new buffer with the specified size.
Definition icalmemory.c:315
void icalmemory_add_tmp_buffer(void *buf)
Adds an externally allocated buffer to the ring.
Definition icalmemory.c:158
Common memory management routines.
icalcomponent * icalparser_parse_string(const char *str)
Parses a string and returns the parsed icalcomponent.
Line-oriented parsing.
icalvalue * icalproperty_get_value(const icalproperty *prop)
bool icalproperty_isa_property(void *property)
void icalproperty_free(icalproperty *p)
char * icalproperty_as_ical_string_r(icalproperty *prop)
icalproperty_kind icalproperty_isa(const icalproperty *p)
int icalproperty_count_parameters(const icalproperty *prop)
const char * icalproperty_get_value_as_string(const icalproperty *prop)
void icalproperty_remove_parameter_by_kind(icalproperty *prop, icalparameter_kind kind)
Removes all parameters with the specified kind.
icalparameter * icalproperty_get_first_parameter(icalproperty *p, icalparameter_kind kind)
void icalproperty_add_parameter(icalproperty *p, icalparameter *parameter)
void icalproperty_normalize(icalproperty *prop)
icalproperty * icalproperty_clone(const icalproperty *old)
const char * icalproperty_get_x_name(const icalproperty *prop)
void icalproperty_set_parameter(icalproperty *prop, icalparameter *parameter)
bool icalrecur_iterator_set_start(icalrecur_iterator *impl, struct icaltimetype start)
Definition icalrecur.c:4262
void icalrecur_iterator_free(icalrecur_iterator *impl)
Definition icalrecur.c:2525
icalrecur_iterator * icalrecur_iterator_new(struct icalrecurrencetype *rule, struct icaltimetype dtstart)
Definition icalrecur.c:2390
struct icaltimetype icalrecur_iterator_next(icalrecur_iterator *impl)
Definition icalrecur.c:3847
Functions to check if an icalcomponent meets the restrictions imposed by the standard.
bool icalrestriction_check(icalcomponent *comp)
Checks if a given VCALENDAR meets all the restrictions imposed by the standard.
const char * icalstrarray_element_at(icalstrarray *array, size_t position)
Accesses a string stored in the array.
void icalstrarray_append(icalstrarray *array, const char *elem)
Appends a string to the array.
void icalstrarray_free(icalstrarray *array)
Frees this array's memory and all its elements.
size_t icalstrarray_size(const icalstrarray *array)
Indicates the count of strings stored in the array.
#define icalstrarray_new(increment_size)
Creates a new icalstrarray object.
bool icaltime_is_date(const struct icaltimetype t)
Definition icaltime.c:634
const char * icaltime_get_tzid(const struct icaltimetype t)
Definition icaltime.c:888
bool icaltime_is_utc(const struct icaltimetype t)
Definition icaltime.c:639
int icaltime_compare_date_only(const struct icaltimetype a_in, const struct icaltimetype b_in)
Definition icaltime.c:722
bool icaltime_is_null_time(const struct icaltimetype t)
Definition icaltime.c:644
icaltime_t icaltime_as_timet_with_zone(const struct icaltimetype tt, const icaltimezone *zone)
Definition icaltime.c:297
int icaltime_compare(const struct icaltimetype a_in, const struct icaltimetype b_in)
Definition icaltime.c:653
struct icaltimetype icaltime_null_time(void)
Definition icaltime.c:584
icalcomponent * icaltimezone_get_component(icaltimezone *zone)
const char * icaltimezone_get_tzid(icaltimezone *zone)
icaltimezone * icaltimezone_get_utc_timezone(void)
void icaltimezone_free(icaltimezone *zone, int free_struct)
Frees all memory used for the icaltimezone.
Timezone handling routines.
struct _icaltimezone icaltimezone
struct icaltimetype time
Definition icaltypes.h:30
struct icalperiodtype period
Definition icaltypes.h:31
unsigned int days
struct icaldurationtype duration
Definition icalperiod.h:36
struct icaltimetype end
Definition icalperiod.h:34
struct icaltimetype start
Definition icalperiod.h:31
const char * desc
Definition icaltypes.h:112
const char * debug
Definition icaltypes.h:113
icalrequeststatus code
Definition icaltypes.h:111
const icaltimezone * zone
Definition icaltime.h:102