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) {
100 if (old->x_name != 0) {
103 if (clone->x_name == 0) {
110 for (p = icalpvl_head(old->parameters); p != 0; p = icalpvl_next(p)) {
119 icalpvl_push(clone->parameters, param);
127 size_t buf_size = 1024;
131 vcardcomponent *comp;
134 icalerror_check_arg_rz((
str != 0),
"str");
175 icalerror_check_arg_rv((p != 0),
"prop");
177 if (p->parent != 0) {
186 while ((param = icalpvl_pop(p->parameters)) != 0) {
190 icalpvl_free(p->parameters);
192 if (p->x_name != 0) {
202 p->parameter_iterator = 0;
205 p->id = ICAL_STRUCTURE_TYPE_PROPERTY_EMPTY;
212static const size_t MAX_LINE_LEN = 75;
214static char *get_next_line_start(
char *line_start,
size_t chars_left)
220 if (chars_left < MAX_LINE_LEN) {
221 return line_start + chars_left;
227 pos = line_start + MAX_LINE_LEN - 2;
228 while (pos > line_start) {
229 if (*pos ==
';' || *pos ==
':' || *pos ==
' ') {
238 pos = line_start + MAX_LINE_LEN - 1;
239 while (pos > line_start) {
241 if ((*pos & 128) == 0) {
246 if ((*pos & 192) == 192) {
256 return line_start + MAX_LINE_LEN - 1;
265static char *fold_property_line(
char *text)
267 size_t buf_size, len;
269 char *buf, *buf_ptr, *line_start, *next_line_start;
281 chars_left = (ssize_t)len;
284 if (chars_left <= 0) {
289 next_line_start = get_next_line_start(line_start, (
size_t)chars_left);
300 char ch = *next_line_start;
301 *next_line_start =
'\0';
303 *next_line_start = ch;
306 chars_left -= (next_line_start - line_start);
307 line_start = next_line_start;
318static const char *vcardproperty_get_value_kind(vcardproperty *prop,
321 const char *kind_string = NULL;
411 !vcardproperty_value_kind_is_default(prop->kind,
kind)) {
438 const char *property_name = 0;
439 size_t buf_size = 1024;
444 const char *kind_string = 0;
446 icalerror_check_arg_rz((prop != 0),
"prop");
454 property_name = prop->x_name;
459 if (property_name == 0) {
460 icalerror_warn(
"Got a property of an unknown kind.");
465 if (prop->group != 0) {
473 kind_string = vcardproperty_get_value_kind(prop, value);
474 if (kind_string != 0) {
486 if (kind_string == 0) {
487 icalerror_warn(
"Got a parameter of unknown kind for the following property");
489 icalerror_warn((property_name) ? property_name :
"(NULL)");
522 out_buf = fold_property_line(buf);
540 const vcardproperty *impl = (vcardproperty *)property;
542 icalerror_check_arg_rz((property != 0),
"property");
543 return (impl->id == ICAL_STRUCTURE_TYPE_PROPERTY);
548 icalerror_check_arg_rv((p != 0),
"prop");
549 icalerror_check_arg_rv((parameter != 0),
"parameter");
551 icalpvl_push(p->parameters, parameter);
558 icalerror_check_arg_rv((prop != 0),
"prop");
559 icalerror_check_arg_rv((parameter != 0),
"parameter");
574 const char *name,
const char *value)
579 icalerror_check_arg_rv((prop != 0),
"prop");
580 icalerror_check_arg_rv((name != 0),
"name");
581 icalerror_check_arg_rv((value != 0),
"value");
624 icalerror_check_arg_rz((prop != 0),
"prop");
625 icalerror_check_arg_rz((name != 0),
"name");
655 t = strchr(
str,
'=');
668 pvql = strchr(pv,
'"');
678 pvqr = strrchr(
str,
'"');
693 icalerror_check_arg_rv((prop != 0),
"prop");
695 for (p = icalpvl_head(prop->parameters); p != 0; p = icalpvl_next(p)) {
699 (void)icalpvl_remove(prop->parameters, p);
710 icalerror_check_arg_rv((prop != 0),
"prop");
712 for (p = icalpvl_head(prop->parameters); p != 0; p = icalpvl_next(p)) {
714 const char *kind_string;
728 if (0 == strcmp(kind_string, name)) {
729 (void)icalpvl_remove(prop->parameters, p);
740 icalerror_check_arg_rv((prop != 0),
"prop");
741 icalerror_check_arg_rv((parameter != 0),
"parameter");
743 for (p = icalpvl_head(prop->parameters); p != 0; p = icalpvl_next(p)) {
746 if (parameter == p_param) {
747 (void)icalpvl_remove(prop->parameters, p);
757 return icalpvl_count(prop->parameters);
766 icalerror_check_arg_rz((p != 0),
"prop");
768 p->parameter_iterator = icalpvl_head(p->parameters);
770 if (p->parameter_iterator == 0) {
774 for (p->parameter_iterator = icalpvl_head(p->parameters);
775 p->parameter_iterator != 0; p->parameter_iterator = icalpvl_next(p->parameter_iterator)) {
788 icalerror_check_arg_rz((p != 0),
"prop");
790 if (p->parameter_iterator == 0) {
794 for (p->parameter_iterator = icalpvl_next(p->parameter_iterator);
795 p->parameter_iterator != 0; p->parameter_iterator = icalpvl_next(p->parameter_iterator)) {
810 icalerror_check_arg_rv((p != 0),
"prop");
811 icalerror_check_arg_rv((value != 0),
"value");
842 icalerror_check_arg_rv((prop != 0),
"prop");
843 icalerror_check_arg_rv((
str != 0),
"str");
844 icalerror_check_arg_rv((type != 0),
"type");
846 if (strcmp(type,
"NO") == 0) {
880 icalerror_check_arg_rz((prop != 0),
"prop");
898 icalerror_check_arg_rz((prop != 0),
"prop");
907 icalerror_check_arg_rv((name != 0),
"name");
908 icalerror_check_arg_rv((prop != 0),
"prop");
910 if (prop->x_name != 0) {
916 if (prop->x_name == 0) {
923 icalerror_check_arg_rz((prop != 0),
"prop");
930 icalerror_check_arg_rv((group != 0),
"group");
931 icalerror_check_arg_rv((prop != 0),
"prop");
933 if (prop->group != 0) {
939 if (prop->group == 0) {
946 icalerror_check_arg_rz((prop != 0),
"prop");
962 const char *property_name = 0;
963 size_t buf_size = 256;
967 icalerror_check_arg_rz((prop != 0),
"prop");
973 property_name = prop->x_name;
978 if (property_name == 0) {
994 icalerror_check_arg_rv((property != 0),
"property");
996 property->parent = comp;
1001 icalerror_check_arg_rz((property != 0),
"property");
1003 return property->parent;
1006static int param_compare(
void *a,
void *b)
1015 icalpvl_list sorted_params = icalpvl_newlist();
1019 while ((param = icalpvl_pop(prop->parameters)) != 0) {
1026 switch (prop_kind) {
1101 icalpvl_insert_ordered(sorted_params, param_compare, param);
1105 icalpvl_free(prop->parameters);
1106 prop->parameters = sorted_params;
1108 switch (prop_kind) {
enum icalrequeststatus 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.
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)
vcardcomponent * vcardproperty_get_parent(const vcardproperty *property)
Returns the parent vcard for the specified property.
vcardvalue * vcardproperty_get_value(const vcardproperty *prop)
void vcardproperty_add_type_parameter(vcardproperty *prop, vcardenumarray_element *type)
void vcardproperty_set_parent(vcardproperty *property, vcardcomponent *comp)
Sets the parent vcard for the specified vcardproperty property.
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)