19#include "vcardvalueimpl.h"
23#include "icalerror_p.h"
30#define TMP_BUF_SIZE 1024
34 struct vcardvalue_impl *v;
45 v->id = ICAL_STRUCTURE_TYPE_VALUE;
50 memset(&(v->data), 0,
sizeof(v->data));
62 struct vcardvalue_impl *clone;
71 clone->kind = old->kind;
72 clone->size = old->size;
74 switch (clone->kind) {
78 if (old->data.v_string != 0) {
81 if (clone->data.v_string == 0) {
90 if (old->x_value != 0) {
93 if (clone->x_value == 0) {
104 if (old->data.v_structured != 0) {
105 clone->data.v_structured =
114 clone->data = old->data;
137 for (p = *
str; *p != 0; p++) {
182 }
else if (sep && strchr(sep, *p)) {
208static char *vcardmemory_strdup_and_quote(
char **
str,
char **str_p,
size_t *buf_sz,
209 const char *unquoted_str,
bool is_param)
214 *buf_sz = strlen(unquoted_str) + 1;
224 for (p = unquoted_str; *p != 0; p++) {
269 struct vcardvalue_impl *value;
273 value->data.v_enum = e;
277 value->data.v_enum = x_type;
290static bool simple_str_to_doublestr(
const char *from,
char *result,
int result_len,
char **to)
292 const char *start = NULL;
293 char *end = NULL, *cur = (
char *)from;
295 struct lconv *loc_data = localeconv();
300 if (!from || !result) {
305 while (*cur && isspace((
int)*cur)) {
314 while (*cur && (isdigit((
int)*cur) || *cur ==
'.' || *cur ==
'+' || *cur ==
'-')) {
318 len = (int)(ptrdiff_t)(end - start);
319 if (len + 1 >= result_len) {
321 len = result_len - 1;
328 for (i = 0; i < len; ++i) {
329 if (start[i] ==
'.' &&
330 loc_data && loc_data->decimal_point && loc_data->decimal_point[0] && loc_data->decimal_point[0] !=
'.') {
332 result[i] = loc_data->decimal_point[0];
334 result[i] = start[i];
342 if (sscanf(result,
"%lf", &dtest) != 1) {
350 vcardproperty **error)
352 struct vcardvalue_impl *value = 0;
354 icalerror_check_arg_rz(
str != 0,
"str");
362 if (!strcmp(
str,
"TRUE")) {
364 }
else if (!strcmp(
str,
"FALSE")) {
366 }
else if (error != 0) {
370 snprintf(temp,
sizeof(temp),
371 "Could not parse %s as a %s property",
400#pragma GCC diagnostic push
401#pragma GCC diagnostic ignored "-Wformat-nonliteral"
404 unsigned hour, min = 0;
405 int nchar = 0, len = (int)strlen(
str);
411 fmt =
"%1[+-]%02u:%02u%n";
413 fmt =
"%1[+-]%02u%02u%n";
416 if (3 != sscanf(
str, fmt, sign, &hour, &min, &nchar)) {
419 }
else if (2 != sscanf(
str,
"%1[+-]%02u%n", sign, &hour, &nchar)) {
422#pragma GCC diagnostic pop
424 if (len && (len == nchar)) {
425 int utcoffset = (int)(hour * 3600 + min * 60);
428 utcoffset = -utcoffset;
431 }
else if (error != 0) {
435 snprintf(temp,
sizeof(temp),
436 "Could not parse %s as a %s property",
471 goto geo_parsing_error;
474 while (cur && isspace((
int)*cur)) {
479 if (!cur || *cur !=
';') {
480 goto geo_parsing_error;
486 while (cur && isspace((
int)*cur)) {
491 goto geo_parsing_error;
499 snprintf(temp,
sizeof(temp),
500 "Could not parse %s as a %s value",
522 value->data.v_time = tt;
546 "vcardvalue_new_from_string got an unknown value type (%s) for \'%s\'",
548 icalerror_warn(temp);
553 if (error != 0 && *error == 0 && value == 0) {
569 return vcardvalue_new_from_string_with_error(
kind,
str, (vcardproperty **)0);
574 icalerror_check_arg_rv((v != 0),
"value");
576 if (v->parent != 0) {
580 if (v->x_value != 0) {
588 if (v->data.v_string != 0) {
590 v->data.v_string = 0;
596 if (v->data.v_textlist != 0) {
599 v->data.v_textlist = 0;
605 v->data.v_structured = 0;
610 v->data.v_geo.coords.lat[0] =
'\0';
611 v->data.v_geo.coords.lon[0] =
'\0';
623 memset(&(v->data), 0,
sizeof(v->data));
624 v->id = ICAL_STRUCTURE_TYPE_VALUE_EMPTY;
637static char *vcardvalue_boolean_as_vcard_string_r(
const vcardvalue *value)
642 icalerror_check_arg_rz((value != 0),
"value");
647 strncpy(
str, data ?
"TRUE" :
"FALSE", 6);
652#define MAX_INT_DIGITS 12
654static char *vcardvalue_int_as_vcard_string_r(
const vcardvalue *value)
659 icalerror_check_arg_rz((value != 0),
"value");
669static char *vcardvalue_utcoffset_as_vcard_string_r(
const vcardvalue *value,
678 icalerror_check_arg_rz((value != 0),
"value");
683 if (abs(data) == data) {
690 m = (data - (h * 3600)) / 60;
691 s = (data - (h * 3600) - (m * 60));
696#pragma GCC diagnostic push
697#pragma GCC diagnostic ignored "-Wformat-nonliteral"
700 fmt =
"%c%02d%02d%02d";
702 fmt =
"%c%02d:%02d:%02d";
714 snprintf(
str, size, fmt, sign, h, m, s);
715#pragma GCC diagnostic pop
719static char *vcardvalue_text_as_vcard_string_r(
const vcardvalue *value)
725 return vcardmemory_strdup_and_quote(&
str, &str_p, &buf_sz,
726 value->data.v_string, 0);
729static char *vcardvalue_string_as_vcard_string_r(
const vcardvalue *value)
734 icalerror_check_arg_rz((value != 0),
"value");
735 data = value->data.v_string;
737 const size_t len_data = strlen(data) + 1;
740 strncpy(
str, data, len_data);
741 str[len_data - 1] =
'\0';
746static void _vcardstrarray_as_vcard_string_r(
char **
str,
char **str_p,
size_t *buf_sz,
751 (void)vcardmemory_strdup_and_quote(
str, str_p, buf_sz,
"", is_param);
763 (void)vcardmemory_strdup_and_quote(
str, str_p, buf_sz,
771 char *buf_ptr = NULL;
774 _vcardstrarray_as_vcard_string_r(&buf, &buf_ptr, &buf_size,
800 _vcardstrarray_as_vcard_string_r(&buf, &buf_ptr, &buf_size,
801 array,
',', is_param);
810static char *vcardvalue_textlist_as_vcard_string_r(
const vcardvalue *value,
813 icalerror_check_arg_rz((value != 0),
"value");
818static char *vcardvalue_structured_as_vcard_string_r(
const vcardvalue *value)
820 icalerror_check_arg_rz((value != 0),
"value");
825static char *vcardvalue_float_as_vcard_string_r(
const vcardvalue *value)
831 icalerror_check_arg_rz((value != 0),
"value");
838 (void)setlocale(LC_NUMERIC,
"C");
842 snprintf(
str, 40,
"%f", data);
845 (void)setlocale(LC_NUMERIC, old_locale);
851static char *vcardvalue_geo_as_vcard_string_r(
const vcardvalue *value)
853 icalerror_check_arg_rz((value != 0),
"value");
856 snprintf(
str, max_len,
"%s;%s",
857 value->data.v_geo.coords.lat, value->data.v_geo.coords.lon);
858 str[max_len - 1] =
'\0';
894 switch (value->kind) {
896 return vcardvalue_boolean_as_vcard_string_r(value);
899 return vcardvalue_int_as_vcard_string_r(value);
902 return vcardvalue_utcoffset_as_vcard_string_r(value, version);
905 return vcardvalue_text_as_vcard_string_r(value);
908 return vcardvalue_textlist_as_vcard_string_r(value,
909 is_structured ?
';' :
',');
912 return vcardvalue_structured_as_vcard_string_r(value);
915 return vcardvalue_geo_as_vcard_string_r(value);
919 return vcardvalue_string_as_vcard_string_r(value);
942 return vcardvalue_float_as_vcard_string_r(value);
947 if (value->x_value != 0) {
954 if (value->x_value != 0) {
979 const struct vcardvalue_impl *impl = (
struct vcardvalue_impl *)value;
981 icalerror_check_arg_rz((value != 0),
"value");
983 return (impl->id == ICAL_STRUCTURE_TYPE_VALUE);
995 switch (value->kind) {
1019 icalerror_check_arg_rv((value != 0),
"value");
1021 value->parent = property;
1026 return value->parent;
enum icalrequeststatus kind
void icalerror_set_errno(icalerrorenum x)
Sets the icalerrno to a given 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_char(char **buf, char **pos, size_t *buf_size, char ch)
Appends a character to a buffer.
void icalmemory_add_tmp_buffer(void *buf)
Adds an externally allocated buffer to the ring.
Common memory management routines.
struct vcardgeotype::@162201204342263205067330224176321027032342016274 coords
enum vcardproperty_version vcardcomponent_get_version(vcardcomponent *comp)
Defines the data structure representing vCard components.
vcardcomponent * vcardproperty_get_parent(const vcardproperty *property)
Returns the parent vcard for the specified property.
struct vcardparameter_impl vcardparameter
vcardparameter * vcardparameter_new_xlicerrortype(vcardparameter_xlicerrortype v)
@ VCARD_XLICERRORTYPE_VALUEPARSEERROR
vcardproperty * vcardproperty_vanew_xlicerror(const char *v,...)
vcardvalue * vcardvalue_new_textlist(vcardstrarray *v)
struct vcardvalue_impl vcardvalue
vcardvalue * vcardvalue_new_geo(vcardgeotype v)
int vcardvalue_get_utcoffset(const vcardvalue *value)
vcardvalue * vcardvalue_new_integer(int v)
vcardvalue * vcardvalue_new_x(const char *v)
vcardvalue * vcardvalue_new_languagetag(const char *v)
int vcardvalue_get_integer(const vcardvalue *value)
void vcardvalue_set_x(vcardvalue *value, const char *v)
vcardvalue * vcardvalue_new_float(float v)
vcardvalue * vcardvalue_new_uri(const char *v)
float vcardvalue_get_float(const vcardvalue *value)
vcardvalue * vcardvalue_new_structured(vcardstructuredtype *v)
@ VCARD_DATEANDORTIME_VALUE
@ VCARD_LANGUAGETAG_VALUE
vcardvalue * vcardvalue_new_text(const char *v)
vcardvalue * vcardvalue_new_utcoffset(int v)
vcardvalue * vcardvalue_new_boolean(int v)
vcardproperty_kind vcardproperty_isa(const vcardproperty *p)
Defines the data structure representing vCard properties.
vcardproperty_kind vcardproperty_value_kind_to_kind(vcardvalue_kind kind)
char * vcardproperty_enum_to_string_r(int e)
int vcardproperty_kind_and_string_to_enum(const int kind, const char *str)
bool vcardproperty_enum_belongs_to_property(vcardproperty_kind kind, int e)
bool vcardproperty_is_structured(vcardproperty_kind pkind)
#define vcardstrarray_size(array)
#define vcardstrarray_free(array)
#define vcardstrarray_element_at(array, position)
icalstrarray vcardstrarray
vcardstrarray * vcardstructured_field_at(const vcardstructuredtype *st, size_t position)
Returns the field at the given position in a vcardstructuredtype.
vcardstructuredtype * vcardstructured_new_from_string(const char *str)
Creates a new instance of vcardstructuredtype from a string.
vcardstructuredtype * vcardstructured_clone(const vcardstructuredtype *st)
Clones a vcardstructuredtype.
void vcardstructured_unref(vcardstructuredtype *st)
Decrements the reference count of the vcardstructuredtype.
size_t vcardstructured_num_fields(const vcardstructuredtype *st)
Returns the number of fields in a vcardstructuredtype.
struct vcardstructuredtype_impl vcardstructuredtype
Represents a decoded, structured text value.
vcardstrarray * vcardtextlist_new_from_string(const char *str, char sep)
Defines functions for creating vCard text lists.
bool vcardtime_is_timestamp(const vcardtimetype t)
bool vcardtime_is_date(const vcardtimetype t)
vcardtimetype vcardtime_from_string(const char *str, int is_bare_time)
bool vcardtime_is_null_datetime(const vcardtimetype t)
bool vcardtime_is_time(const vcardtimetype t)
char * vcardtime_as_vcard_string_r(const vcardtimetype t, unsigned flags)
#define VCARDTIME_BARE_TIME
vcardvalue * vcardvalue_new_from_string(vcardvalue_kind kind, const char *str)
const char * vcardvalue_as_vcard_string(const vcardvalue *value)
bool vcardvalue_isa_value(void *value)
vcardproperty * vcardvalue_get_parent(const vcardvalue *value)
char * vcardvalue_strdup_and_dequote_text(const char **str, const char *sep)
struct vcardvalue_impl * vcardvalue_new_impl(vcardvalue_kind kind)
vcardvalue_kind vcardvalue_isa(const vcardvalue *value)
char * vcardvalue_as_vcard_string_r(const vcardvalue *value)
void vcardvalue_set_parent(vcardvalue *value, vcardproperty *property)
vcardvalue * vcardvalue_clone(const vcardvalue *old)
void vcardvalue_reset_kind(vcardvalue *value)
bool vcardvalue_is_valid(const vcardvalue *value)
char * vcardstrarray_as_vcard_string_r(const vcardstrarray *array, const char sep)
vcardvalue * vcardvalue_new(vcardvalue_kind kind)
char * vcardstructured_as_vcard_string_r(const vcardstructuredtype *st, bool is_param)
Formats a vcardstructuredtype as a vCard property or parameter value.
void vcardvalue_free(vcardvalue *v)
Defines the data structure representing vCard values.
const char * vcardvalue_kind_to_string(const vcardvalue_kind kind)
bool vcardvalue_kind_is_valid(const vcardvalue_kind kind)