19#include "vcardparameterimpl.h"
20#include "icalerror_p.h"
26LIBICAL_VCARD_EXPORT
struct vcardparameter_impl *vcardparameter_new_impl(vcardparameter_kind kind)
28 struct vcardparameter_impl *v;
30 if ((v = (
struct vcardparameter_impl *)
icalmemory_new_buffer(
sizeof(
struct vcardparameter_impl))) == 0) {
35 memset(v, 0,
sizeof(
struct vcardparameter_impl));
37 v->id = ICAL_STRUCTURE_TYPE_PARAMETER;
39 v->value_kind = vcardparameter_kind_value_kind(kind, &v->is_multivalued);
46 struct vcardparameter_impl *v = vcardparameter_new_impl(kind);
48 return (vcardparameter *)v;
53 if (!param || param->parent != 0) {
57 if (param->string != 0) {
59 }
else if (param->values != 0) {
60 if (param->value_kind == VCARD_TEXT_VALUE) {
61 vcardstrarray_free(param->values);
63 vcardenumarray_free(param->values);
65 }
else if (param->structured != 0) {
69 if (param->x_name != 0) {
73 memset(param, 0,
sizeof(vcardparameter));
76 param->id = ICAL_STRUCTURE_TYPE_PARAMETER_EMPTY;
82 struct vcardparameter_impl *clone;
84 icalerror_check_arg_rz((old != 0),
"param");
86 clone = vcardparameter_new_impl(old->kind);
92 memcpy(clone, old,
sizeof(
struct vcardparameter_impl));
94 if (old->string != 0) {
96 if (clone->string == 0) {
103 if (old->x_name != 0) {
105 if (clone->x_name == 0) {
112 if (old->values != 0) {
113 clone->values = old->value_kind == VCARD_TEXT_VALUE ? vcardstrarray_clone(old->values) : vcardenumarray_clone(old->values);
114 if (clone->values == 0) {
128 vcardparameter_kind kind;
129 vcardparameter *param;
131 icalerror_check_arg_rz(str != 0,
"str");
140 eq = strchr(cpy,
'=');
154 if (kind == VCARD_NO_PARAMETER) {
162 if (kind == VCARD_X_PARAMETER) {
164 }
else if (kind == VCARD_IANA_PARAMETER) {
193 size_t buf_size = 1024;
197 icalerror_check_arg_rz((param != 0),
"parameter");
206 if (param->kind == VCARD_X_PARAMETER) {
209 }
else if (param->kind == VCARD_IANA_PARAMETER) {
215 if (param->kind == VCARD_NO_PARAMETER ||
216 param->kind == VCARD_ANY_PARAMETER || kind_string == 0) {
228 if (param->string != 0) {
230 &buf_size, param->string);
231 }
else if (param->data != 0) {
235 if (param->value_kind == VCARD_INTEGER_VALUE) {
236#define VCARD_INTEGER_LENGTH 21
238 snprintf(intbuf, VCARD_INTEGER_LENGTH - 1,
"%d", param->data);
242 str = vcardparameter_enum_to_string(param->data);
247 }
else if (param->values != 0) {
249 const char *sep =
"";
251 for (i = 0; i < param->values->num_elements; i++) {
254 if (param->value_kind == VCARD_TEXT_VALUE) {
255 const char *str = vcardstrarray_element_at(param->values, i);
260 const vcardenumarray_element *elem =
261 vcardenumarray_element_at(param->values, i);
266 const char *str = vcardparameter_enum_to_string(elem->
val);
273 }
else if (vcardparameter_is_structured(param)) {
278 }
else if (vcardtime_is_valid_time(param->date)) {
279 const char *str = vcardtime_as_vcard_string(param->date, 0);
294 if (parameter == 0) {
295 return VCARD_NO_PARAMETER;
298 return parameter->kind;
303 const struct vcardparameter_impl *impl = (
struct vcardparameter_impl *)parameter;
305 if (parameter == 0) {
309 return (impl->id == ICAL_STRUCTURE_TYPE_PARAMETER);
314 icalerror_check_arg_rv((param != 0),
"param");
315 icalerror_check_arg_rv((v != 0),
"v");
317 if (param->x_name != 0) {
323 if (param->x_name == 0) {
330 icalerror_check_arg_rz((param != 0),
"param");
332 return param->x_name;
337 icalerror_check_arg_rv((param != 0),
"param");
338 icalerror_check_arg_rv((v != 0),
"v");
340 if (param->string != 0) {
346 if (param->string == 0) {
353 icalerror_check_arg_rz((param != 0),
"param");
355 return param->string;
380 icalerror_check_arg_rv((param != 0),
"param");
382 param->parent = property;
387 icalerror_check_arg_rz((param != 0),
"param");
389 return param->parent;
394 vcardparameter_kind kind1;
395 vcardparameter_kind kind2;
399 icalerror_check_arg_rz((param1 != 0),
"param1");
400 icalerror_check_arg_rz((param2 != 0),
"param2");
405 if (kind1 != kind2) {
409 if (kind1 == VCARD_X_PARAMETER) {
412 if (strcasecmp(name1, name2) != 0) {
415 }
else if (kind1 == VCARD_IANA_PARAMETER) {
418 if (strcasecmp(name1, name2) != 0) {
425bool vcardparameter_is_multivalued(
const vcardparameter *param)
427 icalerror_check_arg_rz((param != 0),
"param");
429 return param->is_multivalued;
432bool vcardparameter_is_structured(
const vcardparameter *param)
434 icalerror_check_arg_rz((param != 0),
"param");
436 return (param->value_kind == VCARD_STRUCTURED_VALUE);
void icalerror_set_errno(icalerrorenum x)
Sets the icalerrno to a given error.
@ ICAL_MALFORMEDDATA_ERROR
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_append_encoded_string(char **buf, char **pos, size_t *buf_size, const char *string)
void icalmemory_add_tmp_buffer(void *buf)
Adds an externally allocated buffer to the ring.
void * icalmemory_tmp_buffer(size_t size)
Creates a new temporary buffer on the ring and returns it.
Common memory management routines.
vcardparameter * vcardparameter_new_from_string(const char *str)
Creates new vcardparameter object from string.
bool vcardparameter_has_same_name(const vcardparameter *param1, const vcardparameter *param2)
Determines if two parameters have the same name.
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.
const char * vcardparameter_get_iana_value(const vcardparameter *param)
Returns the IANA value of param.
void vcardparameter_free(vcardparameter *param)
Frees an vcardparameter object.
void vcardparameter_set_iana_value(vcardparameter *param, const char *v)
Sets the IANA value of param to v.
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)
vcardproperty * vcardparameter_get_parent(const vcardparameter *param)
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.
void vcardparameter_set_xvalue(vcardparameter *param, const char *v)
Sets the X-value of param to v.
const char * vcardparameter_get_xvalue(const vcardparameter *param)
Returns the X-value of param.
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.
Defines the data structure representing vCard parameters.
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.
void vcardstructured_unref(vcardstructuredtype *st)
Decrements the reference count of the vcardstructuredtype.
char * vcardstructured_as_vcard_string_r(const vcardstructuredtype *st, bool is_param)
Formats a vcardstructuredtype as a vCard property or parameter value.