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 strcpy(v->id,
"para");
40 v->value_kind = vcardparameter_kind_value_kind(kind, &v->is_multivalued);
47 struct vcardparameter_impl *v = vcardparameter_new_impl(kind);
49 return (vcardparameter *)v;
54 if (!param || param->parent != 0) {
58 if (param->string != 0) {
60 }
else if (param->values != 0) {
61 if (param->value_kind == VCARD_TEXT_VALUE) {
62 vcardstrarray_free(param->values);
64 vcardenumarray_free(param->values);
66 }
else if (param->structured != 0) {
70 if (param->x_name != 0) {
74 memset(param, 0,
sizeof(vcardparameter));
83 struct vcardparameter_impl *clone;
85 icalerror_check_arg_rz((old != 0),
"param");
87 clone = vcardparameter_new_impl(old->kind);
93 memcpy(clone, old,
sizeof(
struct vcardparameter_impl));
95 if (old->string != 0) {
97 if (clone->string == 0) {
104 if (old->x_name != 0) {
106 if (clone->x_name == 0) {
113 if (old->values != 0) {
114 clone->values = old->value_kind == VCARD_TEXT_VALUE ? vcardstrarray_clone(old->values) : vcardenumarray_clone(old->values);
115 if (clone->values == 0) {
129 vcardparameter_kind kind;
130 vcardparameter *param;
132 icalerror_check_arg_rz(str != 0,
"str");
141 eq = strchr(cpy,
'=');
155 if (kind == VCARD_NO_PARAMETER) {
163 if (kind == VCARD_X_PARAMETER) {
165 }
else if (kind == VCARD_IANA_PARAMETER) {
194 size_t buf_size = 1024;
198 icalerror_check_arg_rz((param != 0),
"parameter");
207 if (param->kind == VCARD_X_PARAMETER) {
210 }
else if (param->kind == VCARD_IANA_PARAMETER) {
216 if (param->kind == VCARD_NO_PARAMETER ||
217 param->kind == VCARD_ANY_PARAMETER || kind_string == 0) {
229 if (param->string != 0) {
231 &buf_size, param->string);
232 }
else if (param->data != 0) {
236 if (param->value_kind == VCARD_INTEGER_VALUE) {
237#define VCARD_INTEGER_LENGTH 21
239 snprintf(intbuf, VCARD_INTEGER_LENGTH - 1,
"%d", param->data);
243 str = vcardparameter_enum_to_string(param->data);
248 }
else if (param->values != 0) {
250 const char *sep =
"";
252 for (i = 0; i < param->values->num_elements; i++) {
255 if (param->value_kind == VCARD_TEXT_VALUE) {
256 const char *str = vcardstrarray_element_at(param->values, i);
261 const vcardenumarray_element *elem =
262 vcardenumarray_element_at(param->values, i);
267 const char *str = vcardparameter_enum_to_string(elem->
val);
274 }
else if (vcardparameter_is_structured(param)) {
279 }
else if (vcardtime_is_valid_time(param->date)) {
280 const char *str = vcardtime_as_vcard_string(param->date, 0);
295 if (parameter == 0) {
296 return VCARD_NO_PARAMETER;
299 return parameter->kind;
304 const struct vcardparameter_impl *impl = (
struct vcardparameter_impl *)parameter;
306 if (parameter == 0) {
310 if (strcmp(impl->id,
"para") == 0) {
319 icalerror_check_arg_rv((param != 0),
"param");
320 icalerror_check_arg_rv((v != 0),
"v");
322 if (param->x_name != 0) {
328 if (param->x_name == 0) {
335 icalerror_check_arg_rz((param != 0),
"param");
337 return param->x_name;
342 icalerror_check_arg_rv((param != 0),
"param");
343 icalerror_check_arg_rv((v != 0),
"v");
345 if (param->string != 0) {
351 if (param->string == 0) {
358 icalerror_check_arg_rz((param != 0),
"param");
360 return param->string;
385 icalerror_check_arg_rv((param != 0),
"param");
387 param->parent = property;
392 icalerror_check_arg_rz((param != 0),
"param");
394 return param->parent;
399 vcardparameter_kind kind1;
400 vcardparameter_kind kind2;
404 icalerror_check_arg_rz((param1 != 0),
"param1");
405 icalerror_check_arg_rz((param2 != 0),
"param2");
410 if (kind1 != kind2) {
414 if (kind1 == VCARD_X_PARAMETER) {
417 if (strcasecmp(name1, name2) != 0) {
420 }
else if (kind1 == VCARD_IANA_PARAMETER) {
423 if (strcasecmp(name1, name2) != 0) {
430bool vcardparameter_is_multivalued(
const vcardparameter *param)
432 icalerror_check_arg_rz((param != 0),
"param");
434 return param->is_multivalued;
437bool vcardparameter_is_structured(
const vcardparameter *param)
439 icalerror_check_arg_rz((param != 0),
"param");
441 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.