$darkmode
Libical API Documentation 4.0 STABLE VERSION Visit the v3.0 documentation
vcardcomponent.h
Go to the documentation of this file.
1 /*======================================================================
2  FILE: vcardcomponent.h
3  CREATOR: Ken Murchison 24 Aug 2022 <murch@fastmailteam.com>
4 
5  SPDX-FileCopyrightText: 2022, Fastmail Pty. Ltd. (https://fastmail.com)
6  SPDX-License-Identifier: LGPL-2.1-only OR MPL-2.0
7  ======================================================================*/
8 
14 #ifndef VCARDCOMPONENT_H
15 #define VCARDCOMPONENT_H
16 
17 #include "libical_sentinel.h"
18 #include "libical_vcard_export.h"
19 #include "vcardproperty.h"
20 
21 #include <stdbool.h>
22 
23 typedef enum vcardcomponent_kind
24 {
25  VCARD_NO_COMPONENT,
26  VCARD_ANY_COMPONENT, /* Used to select all components */
27  VCARD_XROOT_COMPONENT, /* Used as container for multiple vCards */
28  VCARD_VCARD_COMPONENT,
29  VCARD_NUM_COMPONENT_TYPES /* MUST be last (unless we can put NO_COMP last) */
30 } vcardcomponent_kind;
31 
32 typedef struct vcardcomponent_impl vcardcomponent;
33 
36 LIBICAL_VCARD_EXPORT vcardcomponent *vcardcomponent_new(vcardcomponent_kind kind);
37 
43 LIBICAL_VCARD_EXPORT vcardcomponent *vcardcomponent_clone(const vcardcomponent *old);
44 
47 LIBICAL_VCARD_EXPORT vcardcomponent *vcardcomponent_new_from_string(const char *str);
48 
51 LIBICAL_VCARD_EXPORT LIBICAL_SENTINEL vcardcomponent *vcardcomponent_vanew(vcardcomponent_kind kind, ...);
52 
53 /*** @brief Destructor
54  */
55 LIBICAL_VCARD_EXPORT void vcardcomponent_free(vcardcomponent *comp);
56 
57 LIBICAL_VCARD_EXPORT char *vcardcomponent_as_vcard_string(vcardcomponent *comp);
58 
59 LIBICAL_VCARD_EXPORT char *vcardcomponent_as_vcard_string_r(vcardcomponent *comp);
60 
61 LIBICAL_VCARD_EXPORT bool vcardcomponent_is_valid(const vcardcomponent *comp);
62 
63 LIBICAL_VCARD_EXPORT vcardcomponent_kind vcardcomponent_isa(const vcardcomponent *comp);
64 
65 LIBICAL_VCARD_EXPORT bool vcardcomponent_isa_component(const void *comp);
66 
67 /***** Working with Properties *****/
68 
69 LIBICAL_VCARD_EXPORT void vcardcomponent_add_property(vcardcomponent *comp,
70  vcardproperty *property);
71 
72 LIBICAL_VCARD_EXPORT void vcardcomponent_remove_property(vcardcomponent *comp,
73  vcardproperty *property);
74 
75 LIBICAL_VCARD_EXPORT int vcardcomponent_count_properties(vcardcomponent *comp,
76  vcardproperty_kind kind,
77  int ignore_alts);
78 
79 /***** Working with Components *****/
80 
81 LIBICAL_VCARD_EXPORT void vcardcomponent_add_component(vcardcomponent *parent, vcardcomponent *child);
82 
83 LIBICAL_VCARD_EXPORT void vcardcomponent_remove_component(vcardcomponent *parent,
84  vcardcomponent *child);
85 
86 LIBICAL_VCARD_EXPORT int vcardcomponent_count_components(vcardcomponent *comp,
87  vcardcomponent_kind kind);
88 
89 /* Kind conversion routines */
90 
91 LIBICAL_VCARD_EXPORT bool vcardcomponent_kind_is_valid(const vcardcomponent_kind kind);
92 
93 LIBICAL_VCARD_EXPORT vcardcomponent_kind vcardcomponent_string_to_kind(const char *string);
94 
95 LIBICAL_VCARD_EXPORT const char *vcardcomponent_kind_to_string(vcardcomponent_kind kind);
96 
97 /* Iteration Routines. There are two forms of iterators, internal and
98 external. The internal ones came first, and are almost completely
99 sufficient, but they fail badly when you want to construct a loop that
100 removes components from the container.*/
101 
102 /* Iterate through components */
103 LIBICAL_VCARD_EXPORT vcardcomponent *vcardcomponent_get_current_component(vcardcomponent *comp);
104 
105 LIBICAL_VCARD_EXPORT vcardcomponent *vcardcomponent_get_first_component(vcardcomponent *comp,
106  vcardcomponent_kind kind);
107 LIBICAL_VCARD_EXPORT vcardcomponent *vcardcomponent_get_next_component(vcardcomponent *comp,
108  vcardcomponent_kind kind);
109 
114 LIBICAL_VCARD_EXPORT void vcardproperty_set_parent(vcardproperty *property,
115  vcardcomponent *comp);
116 
120 LIBICAL_VCARD_EXPORT vcardcomponent *vcardproperty_get_parent(const vcardproperty *property);
121 
122 /* Iterate through the properties */
123 LIBICAL_VCARD_EXPORT vcardproperty *vcardcomponent_get_current_property(vcardcomponent *comp);
124 
125 LIBICAL_VCARD_EXPORT vcardproperty *vcardcomponent_get_first_property(vcardcomponent *comp,
126  vcardproperty_kind kind);
127 LIBICAL_VCARD_EXPORT vcardproperty *vcardcomponent_get_next_property(vcardcomponent *comp,
128  vcardproperty_kind kind);
129 
130 /***** Working with embedded error properties *****/
131 
132 /* Check the component against itip rules and insert error properties*/
133 /* Working with embedded error properties */
134 LIBICAL_VCARD_EXPORT int vcardcomponent_check_restrictions(vcardcomponent *comp);
135 
141 LIBICAL_VCARD_EXPORT int vcardcomponent_count_errors(vcardcomponent *comp);
142 
144 LIBICAL_VCARD_EXPORT void vcardcomponent_strip_errors(vcardcomponent *comp);
145 
150 LIBICAL_VCARD_EXPORT void vcardcomponent_normalize(vcardcomponent *comp);
151 
152 LIBICAL_VCARD_EXPORT void vcardcomponent_transform(vcardcomponent *impl,
153  vcardproperty_version version);
154 
155 /******************** Convenience routines **********************/
156 
157 LIBICAL_VCARD_EXPORT enum vcardproperty_version vcardcomponent_get_version(vcardcomponent *comp);
158 LIBICAL_VCARD_EXPORT const char *vcardcomponent_get_uid(vcardcomponent *comp);
159 LIBICAL_VCARD_EXPORT const char *vcardcomponent_get_fn(vcardcomponent *comp);
160 
161 #endif /* !VCARDCOMPONENT_H */
vcardcomponent * vcardcomponent_clone(const vcardcomponent *old)
Deeply clones an vcard. Returns a pointer to the memory for the newly cloned vcard.
vcardcomponent * vcardcomponent_new(vcardcomponent_kind kind)
Constructor.
void vcardcomponent_normalize(vcardcomponent *comp)
Normalizes (reorders and sorts the properties) the specified vcard comp.
void vcardcomponent_strip_errors(vcardcomponent *comp)
Removes all X-LIC-ERROR properties.
LIBICAL_SENTINEL vcardcomponent * vcardcomponent_vanew(vcardcomponent_kind kind,...)
Constructor.
Defines the data structure representing vCard properties.
int vcardcomponent_count_errors(vcardcomponent *comp)
Returns the number of errors encountered parsing the data.
void vcardproperty_set_parent(vcardproperty *property, vcardcomponent *comp)
Sets the parent vcard for the specified vcardproperty property.
vcardcomponent * vcardproperty_get_parent(const vcardproperty *property)
Returns the parent vcard for the specified property.
vcardcomponent * vcardcomponent_new_from_string(const char *str)
Constructor.