18#include "vcardproperty_p.h"
22#include "icalerror_p.h"
26#include "icaltypes_p.h"
30struct vcardproperty_impl {
35 icalpvl_list parameters;
36 icalpvl_elem parameter_iterator;
38 vcardcomponent *parent;
54 memset(prop, 0,
sizeof(vcardproperty));
56 prop->id = ICAL_STRUCTURE_TYPE_PROPERTY;
58 prop->parameters = icalpvl_newlist();
67 while ((vp = va_arg(args,
void *)) != 0) {
92 icalerror_check_arg_rz((old != 0),
"old");
94 icalerror_check_arg_rz((clone != 0),
"clone");
96 if (old->value != 0) {
99 if (clone->value == 0) {
108 if (old->x_name != 0) {
111 if (clone->x_name == 0) {
118 if (old->group != 0) {
121 if (clone->group == 0) {
128 for (p = icalpvl_head(old->parameters); p != 0; p = icalpvl_next(p)) {
137 icalpvl_push(clone->parameters, param);
145 size_t buf_size = 1024;
149 vcardcomponent *comp;
152 icalerror_check_arg_rz((str != 0),
"str");
193 icalerror_check_arg_rv((p != 0),
"prop");
195 if (p->parent != 0) {
204 while ((param = icalpvl_pop(p->parameters)) != 0) {
208 icalpvl_free(p->parameters);
210 if (p->x_name != 0) {
220 p->parameter_iterator = 0;
223 p->id = ICAL_STRUCTURE_TYPE_PROPERTY_EMPTY;
230static const size_t MAX_LINE_LEN = 75;
232static char *get_next_line_start(
char *line_start,
size_t chars_left)
238 if (chars_left < MAX_LINE_LEN) {
239 return line_start + chars_left;
245 pos = line_start + MAX_LINE_LEN - 2;
246 while (pos > line_start) {
247 if (*pos ==
';' || *pos ==
':' || *pos ==
' ') {
256 pos = line_start + MAX_LINE_LEN - 1;
257 while (pos > line_start) {
259 if ((*pos & 128) == 0) {
264 if ((*pos & 192) == 192) {
274 return line_start + MAX_LINE_LEN - 1;
283static char *fold_property_line(
char *text)
285 size_t buf_size, len;
287 char *buf, *buf_ptr, *line_start, *next_line_start;
299 chars_left = (ssize_t)len;
302 if (chars_left <= 0) {
307 next_line_start = get_next_line_start(line_start, (
size_t)chars_left);
318 char ch = *next_line_start;
319 *next_line_start =
'\0';
321 *next_line_start = ch;
324 chars_left -= (next_line_start - line_start);
325 line_start = next_line_start;
336static const char *vcardproperty_get_value_kind(vcardproperty *prop,
339 const char *kind_string = NULL;
432 !vcardproperty_value_kind_is_default(prop->kind, kind)) {
459 const char *property_name = 0;
460 size_t buf_size = 1024;
465 const char *kind_string = 0;
467 icalerror_check_arg_rz((prop != 0),
"prop");
475 property_name = prop->x_name;
480 if (property_name == 0) {
481 icalerror_warn(
"Got a property of an unknown kind.");
486 if (prop->group != 0) {
494 kind_string = vcardproperty_get_value_kind(prop, value);
495 if (kind_string != 0) {
507 if (kind_string == 0) {
508 icalerror_warn(
"Got a parameter of unknown kind for the following property");
510 icalerror_warn((property_name) ? property_name :
"(NULL)");
543 out_buf = fold_property_line(buf);
561 const vcardproperty *impl = (vcardproperty *)property;
563 icalerror_check_arg_rz((property != 0),
"property");
564 return (impl->id == ICAL_STRUCTURE_TYPE_PROPERTY);
569 icalerror_check_arg_rv((p != 0),
"prop");
570 icalerror_check_arg_rv((parameter != 0),
"parameter");
572 icalpvl_push(p->parameters, parameter);
579 icalerror_check_arg_rv((prop != 0),
"prop");
580 icalerror_check_arg_rv((parameter != 0),
"parameter");
595 const char *name,
const char *value)
600 icalerror_check_arg_rv((prop != 0),
"prop");
601 icalerror_check_arg_rv((name != 0),
"name");
602 icalerror_check_arg_rv((value != 0),
"value");
645 icalerror_check_arg_rz((prop != 0),
"prop");
646 icalerror_check_arg_rz((name != 0),
"name");
676 t = strchr(str,
'=');
689 pvql = strchr(pv,
'"');
699 pvqr = strrchr(str,
'"');
714 icalerror_check_arg_rv((prop != 0),
"prop");
716 for (p = icalpvl_head(prop->parameters); p != 0; p = icalpvl_next(p)) {
720 (void)icalpvl_remove(prop->parameters, p);
731 icalerror_check_arg_rv((prop != 0),
"prop");
733 for (p = icalpvl_head(prop->parameters); p != 0; p = icalpvl_next(p)) {
735 const char *kind_string;
749 if (0 == strcmp(kind_string, name)) {
750 (void)icalpvl_remove(prop->parameters, p);
761 icalerror_check_arg_rv((prop != 0),
"prop");
762 icalerror_check_arg_rv((parameter != 0),
"parameter");
764 for (p = icalpvl_head(prop->parameters); p != 0; p = icalpvl_next(p)) {
767 if (parameter == p_param) {
768 (void)icalpvl_remove(prop->parameters, p);
778 return icalpvl_count(prop->parameters);
787 icalerror_check_arg_rz((p != 0),
"prop");
789 p->parameter_iterator = icalpvl_head(p->parameters);
791 if (p->parameter_iterator == 0) {
795 for (p->parameter_iterator = icalpvl_head(p->parameters);
796 p->parameter_iterator != 0; p->parameter_iterator = icalpvl_next(p->parameter_iterator)) {
809 icalerror_check_arg_rz((p != 0),
"prop");
811 if (p->parameter_iterator == 0) {
815 for (p->parameter_iterator = icalpvl_next(p->parameter_iterator);
816 p->parameter_iterator != 0; p->parameter_iterator = icalpvl_next(p->parameter_iterator)) {
831 icalerror_check_arg_rv((p != 0),
"prop");
832 icalerror_check_arg_rv((value != 0),
"value");
863 icalerror_check_arg_rv((prop != 0),
"prop");
864 icalerror_check_arg_rv((str != 0),
"str");
865 icalerror_check_arg_rv((type != 0),
"type");
867 if (strcmp(type,
"NO") == 0) {
901 icalerror_check_arg_rz((prop != 0),
"prop");
919 icalerror_check_arg_rz((prop != 0),
"prop");
928 icalerror_check_arg_rv((name != 0),
"name");
929 icalerror_check_arg_rv((prop != 0),
"prop");
931 if (prop->x_name != 0) {
937 if (prop->x_name == 0) {
944 icalerror_check_arg_rz((prop != 0),
"prop");
951 icalerror_check_arg_rv((group != 0),
"group");
952 icalerror_check_arg_rv((prop != 0),
"prop");
954 if (prop->group != 0) {
960 if (prop->group == 0) {
967 icalerror_check_arg_rz((prop != 0),
"prop");
983 const char *property_name = 0;
984 size_t buf_size = 256;
988 icalerror_check_arg_rz((prop != 0),
"prop");
994 property_name = prop->x_name;
999 if (property_name == 0) {
1015 icalerror_check_arg_rv((property != 0),
"property");
1017 property->parent = comp;
1022 icalerror_check_arg_rz((property != 0),
"property");
1024 return property->parent;
1027static int param_compare(
void *a,
void *b)
1036 icalpvl_list sorted_params = icalpvl_newlist();
1040 while ((param = icalpvl_pop(prop->parameters)) != 0) {
1047 switch (prop_kind) {
1122 icalpvl_insert_ordered(sorted_params, param_compare, param);
1126 icalpvl_free(prop->parameters);
1127 prop->parameters = sorted_params;
1129 switch (prop_kind) {
void icalerror_set_errno(icalerrorenum x)
Sets the icalerrno to a given error.
void icalerror_clear_errno(void)
Resets icalerrno to ICAL_NO_ERROR.
@ ICAL_MALFORMEDDATA_ERROR
#define icalerrno
Access the current icalerrno value.
void icalmemory_free_buffer(void *buf)
Releases a buffer.
char * icalmemory_strdup(const char *s)
Creates a duplicate of a string.
void icalmemory_append_string(char **buf, char **pos, size_t *buf_size, const char *string)
Appends a string to a buffer.
void * icalmemory_new_buffer(size_t size)
Creates new buffer with the specified size.
void icalmemory_add_tmp_buffer(void *buf)
Adds an externally allocated buffer to the ring.
Common memory management routines.
bool icalproperty_get_allow_empty_properties(void)
Defines the data structure representing iCalendar properties.
void vcardcomponent_remove_property(vcardcomponent *comp, vcardproperty *property)
enum vcardproperty_version vcardcomponent_get_version(vcardcomponent *comp)
int vcardcomponent_count_errors(vcardcomponent *comp)
Returns the number of errors encountered parsing the data.
void vcardcomponent_free(vcardcomponent *c)
vcardproperty * vcardcomponent_get_first_property(vcardcomponent *c, vcardproperty_kind kind)
Defines the data structure representing vCard components.
vcardcomponent * vcardproperty_get_parent(const vcardproperty *property)
Returns the parent vcard for the specified property.
void vcardproperty_set_parent(vcardproperty *property, vcardcomponent *comp)
Sets the parent vcard for the specified vcardproperty property.
void vcardparameter_set_type(vcardparameter *value, vcardenumarray *v)
vcardstrarray * vcardparameter_get_pid(const vcardparameter *value)
struct vcardparameter_impl vcardparameter
vcardenumarray * vcardparameter_get_type(const vcardparameter *value)
vcardparameter_value vcardparameter_get_value(const vcardparameter *value)
int vcardparameter_get_pref(const vcardparameter *value)
vcardstrarray * vcardparameter_get_sortas(const vcardparameter *value)
vcardparameter_calscale vcardparameter_get_calscale(const vcardparameter *value)
@ VCARD_VALUE_DATEANDORTIME
@ VCARD_ENCODING_PARAMETER
@ VCARD_CALSCALE_PARAMETER
@ VCARD_CALSCALE_GREGORIAN
vcardstrarray * vcardproperty_get_categories(const vcardproperty *prop)
@ VCARD_CATEGORIES_PROPERTY
@ VCARD_DEATHPLACE_PROPERTY
@ VCARD_DEATHDATE_PROPERTY
@ VCARD_NICKNAME_PROPERTY
@ VCARD_ANNIVERSARY_PROPERTY
@ VCARD_BIRTHPLACE_PROPERTY
vcardstrarray * vcardproperty_get_nickname(const vcardproperty *prop)
struct vcardvalue_impl vcardvalue
@ VCARD_DATEANDORTIME_VALUE
#define vcardenumarray_add(array, add)
icalenumarray_element vcardenumarray_element
#define vcardenumarray_sort(array)
#define vcardenumarray_new(increment_size)
icalenumarray vcardenumarray
#define vcardenumarray_find(array, needle)
char * vcardparameter_as_vcard_string(vcardparameter *param)
Converts vcardparameter into a string representation.
void vcardparameter_set_xname(vcardparameter *param, const char *v)
Sets the X-name of param to v.
void vcardparameter_free(vcardparameter *param)
Frees an vcardparameter object.
const char * vcardparameter_get_iana_name(const vcardparameter *param)
Returns the IANA name of param.
void vcardparameter_set_parent(vcardparameter *param, vcardproperty *property)
bool vcardparameter_isa_parameter(void *parameter)
vcardparameter_kind vcardparameter_isa(const vcardparameter *parameter)
void vcardparameter_set_iana_name(vcardparameter *param, const char *v)
Sets the IANA name of param to v.
vcardparameter * vcardparameter_clone(const vcardparameter *old)
Creates new vcardparameter as a clone of the given one.
const char * vcardparameter_get_xname(const vcardparameter *param)
Returns the X-name of param.
vcardparameter * vcardparameter_new(vcardparameter_kind kind)
Creates new vcardparameter object.
char * vcardparameter_as_vcard_string_r(vcardparameter *param)
Converts vcardparameter into an string representation according to RFC5445/RFC6868.
const char * vcardparameter_kind_to_string(vcardparameter_kind kind)
Returns a string representing the given vcardparameter_kind.
vcardparameter * vcardparameter_new_from_value_string(vcardparameter_kind kind, const char *value)
Creates new vcardparameter of a given kind with a given value.
vcardparameter_kind vcardparameter_string_to_kind(const char *string)
Returns the vcardparameter_kind for a given string.
vcardcomponent * vcardparser_parse_string(const char *str)
Line-oriented parsing vCard format.
vcardproperty * vcardproperty_new(vcardproperty_kind kind)
void vcardproperty_set_parameter_from_string(vcardproperty *prop, const char *name, const char *value)
const char * vcardproperty_get_property_name(const vcardproperty *prop)
void vcardproperty_set_group(vcardproperty *prop, const char *group)
vcardproperty * vcardproperty_new_from_string(const char *str)
void vcardproperty_set_x_name(vcardproperty *prop, const char *name)
void vcardproperty_free(vcardproperty *p)
void vcardproperty_add_parameters(vcardproperty *prop, va_list args)
void vcardproperty_set_value_from_string(vcardproperty *prop, const char *str, const char *type)
const char * vcardproperty_as_vcard_string(vcardproperty *prop)
void vcardproperty_set_value(vcardproperty *p, vcardvalue *value)
void vcardproperty_normalize(vcardproperty *prop)
const char * vcardproperty_get_value_as_string(const vcardproperty *prop)
void vcardproperty_remove_parameter_by_name(vcardproperty *prop, const char *name)
Removes all parameters with the specified name.
void vcardproperty_remove_parameter_by_ref(vcardproperty *prop, vcardparameter *parameter)
Removes the specified parameter reference from the property.
char * vcardproperty_get_value_as_string_r(const vcardproperty *prop)
const char * vcardproperty_get_x_name(const vcardproperty *prop)
struct vcardproperty_impl * vcardproperty_new_impl(vcardproperty_kind kind)
int vcardproperty_count_parameters(const vcardproperty *prop)
bool vcardproperty_isa_property(void *property)
vcardparameter * vcardproperty_get_first_parameter(vcardproperty *p, vcardparameter_kind kind)
vcardvalue * vcardproperty_get_value(const vcardproperty *prop)
void vcardproperty_add_type_parameter(vcardproperty *prop, vcardenumarray_element *type)
const char * vcardproperty_get_group(const vcardproperty *prop)
vcardproperty * vcardproperty_clone(const vcardproperty *old)
Deeply clones an vcardproperty.
char * vcardproperty_get_parameter_as_string_r(vcardproperty *prop, const char *name)
void vcardproperty_remove_parameter_by_kind(vcardproperty *prop, vcardparameter_kind kind)
Removes all parameters with the specified kind.
char * vcardproperty_get_property_name_r(const vcardproperty *prop)
void vcardproperty_add_parameter(vcardproperty *p, vcardparameter *parameter)
char * vcardproperty_as_vcard_string_r(vcardproperty *prop)
void vcardproperty_set_parameter(vcardproperty *prop, vcardparameter *parameter)
vcardproperty_kind vcardproperty_isa(const vcardproperty *p)
vcardparameter * vcardproperty_get_next_parameter(vcardproperty *p, vcardparameter_kind kind)
const char * vcardproperty_get_parameter_as_string(vcardproperty *prop, const char *name)
bool vcardproperty_kind_is_valid(const vcardproperty_kind kind)
vcardvalue_kind vcardproperty_kind_to_value_kind(vcardproperty_kind kind)
void vcardvalue_set_parent(vcardvalue *value, vcardproperty *property)
vcardvalue_kind vcardparameter_value_to_value_kind(vcardparameter_value value)
const char * vcardproperty_kind_to_string(vcardproperty_kind kind)
#define vcardstrarray_sort(array)
vcardvalue * vcardvalue_new_from_string(vcardvalue_kind kind, const char *str)
bool vcardvalue_isa_value(void *value)
vcardvalue_kind vcardvalue_isa(const vcardvalue *value)
char * vcardvalue_as_vcard_string_r(const vcardvalue *value)
vcardvalue * vcardvalue_clone(const vcardvalue *old)
void vcardvalue_free(vcardvalue *v)
Defines the data structure representing vCard values.
vcardvalue_kind vcardvalue_string_to_kind(const char *str)
const char * vcardvalue_kind_to_string(const vcardvalue_kind kind)