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];
343 if (sscanf(result,
"%lf", &dtest) != 1) {
352 vcardproperty **error)
354 struct vcardvalue_impl *value = 0;
356 icalerror_check_arg_rz(
str != 0,
"str");
364 if (!strcmp(
str,
"TRUE")) {
366 }
else if (!strcmp(
str,
"FALSE")) {
368 }
else if (error != 0) {
372 snprintf(temp,
sizeof(temp),
373 "Could not parse %s as a %s property",
395 const int v = strtol(
str, &s_end, 10);
404 const float v = strtof(
str, &s_end);
412#pragma GCC diagnostic push
413#pragma GCC diagnostic ignored "-Wformat-nonliteral"
417 unsigned hour, min = 0;
418 int nchar = 0, len = (int)strlen(
str);
424 fmt =
"%1[+-]%02u:%02u%n";
426 fmt =
"%1[+-]%02u%02u%n";
429 if (3 != sscanf(
str, fmt, sign, &hour, &min, &nchar)) {
432 }
else if (2 != sscanf(
str,
"%1[+-]%02u%n", sign, &hour, &nchar)) {
436#pragma GCC diagnostic pop
438 if (len && (len == nchar)) {
439 int utcoffset = (int)(hour * 3600 + min * 60);
442 utcoffset = -utcoffset;
445 }
else if (error != 0) {
449 snprintf(temp,
sizeof(temp),
450 "Could not parse %s as a %s property",
485 goto geo_parsing_error;
488 while (cur && isspace((
int)*cur)) {
493 if (!cur || *cur !=
';') {
494 goto geo_parsing_error;
500 while (cur && isspace((
int)*cur)) {
505 goto geo_parsing_error;
513 snprintf(temp,
sizeof(temp),
514 "Could not parse %s as a %s value",
536 value->data.v_time = tt;
560 "vcardvalue_new_from_string got an unknown value type (%s) for \'%s\'",
562 icalerror_warn(temp);
567 if (error != 0 && *error == 0 && value == 0) {
583 return vcardvalue_new_from_string_with_error(
kind,
str, (vcardproperty **)0);
588 icalerror_check_arg_rv((v != 0),
"value");
590 if (v->parent != 0) {
594 if (v->x_value != 0) {
602 if (v->data.v_string != 0) {
604 v->data.v_string = 0;
610 if (v->data.v_textlist != 0) {
613 v->data.v_textlist = 0;
619 v->data.v_structured = 0;
624 v->data.v_geo.coords.lat[0] =
'\0';
625 v->data.v_geo.coords.lon[0] =
'\0';
637 memset(&(v->data), 0,
sizeof(v->data));
638 v->id = ICAL_STRUCTURE_TYPE_VALUE_EMPTY;
651static char *vcardvalue_boolean_as_vcard_string_r(
const vcardvalue *value)
656 icalerror_check_arg_rz((value != 0),
"value");
661 strncpy(
str, data ?
"TRUE" :
"FALSE", 6);
666#define MAX_INT_DIGITS 12
668static char *vcardvalue_int_as_vcard_string_r(
const vcardvalue *value)
673 icalerror_check_arg_rz((value != 0),
"value");
683static char *vcardvalue_utcoffset_as_vcard_string_r(
const vcardvalue *value,
692 icalerror_check_arg_rz((value != 0),
"value");
697 if (abs(data) == data) {
704 m = (data - (h * 3600)) / 60;
705 s = (data - (h * 3600) - (m * 60));
710#pragma GCC diagnostic push
711#pragma GCC diagnostic ignored "-Wformat-nonliteral"
714 fmt =
"%c%02d%02d%02d";
716 fmt =
"%c%02d:%02d:%02d";
728 snprintf(
str, size, fmt, sign, h, m, s);
729#pragma GCC diagnostic pop
733static char *vcardvalue_text_as_vcard_string_r(
const vcardvalue *value)
739 return vcardmemory_strdup_and_quote(&
str, &str_p, &buf_sz,
740 value->data.v_string,
false);
743static char *vcardvalue_string_as_vcard_string_r(
const vcardvalue *value)
748 icalerror_check_arg_rz((value != 0),
"value");
749 data = value->data.v_string;
751 const size_t len_data = strlen(data) + 1;
754 strncpy(
str, data, len_data);
755 str[len_data - 1] =
'\0';
760static void _vcardstrarray_as_vcard_string_r(
char **
str,
char **str_p,
size_t *buf_sz,
765 (void)vcardmemory_strdup_and_quote(
str, str_p, buf_sz,
"", is_param);
777 (void)vcardmemory_strdup_and_quote(
str, str_p, buf_sz,
785 char *buf_ptr = NULL;
788 _vcardstrarray_as_vcard_string_r(&buf, &buf_ptr, &buf_size,
814 _vcardstrarray_as_vcard_string_r(&buf, &buf_ptr, &buf_size,
815 array,
',', is_param);
824static char *vcardvalue_textlist_as_vcard_string_r(
const vcardvalue *value,
827 icalerror_check_arg_rz((value != 0),
"value");
832static char *vcardvalue_structured_as_vcard_string_r(
const vcardvalue *value)
834 icalerror_check_arg_rz((value != 0),
"value");
839static char *vcardvalue_float_as_vcard_string_r(
const vcardvalue *value)
845 icalerror_check_arg_rz((value != 0),
"value");
852 (void)setlocale(LC_NUMERIC,
"C");
856 snprintf(
str, 40,
"%f", data);
859 (void)setlocale(LC_NUMERIC, old_locale);
865static char *vcardvalue_geo_as_vcard_string_r(
const vcardvalue *value)
867 icalerror_check_arg_rz((value != 0),
"value");
870 snprintf(
str, max_len,
"%s;%s",
871 value->data.v_geo.coords.lat, value->data.v_geo.coords.lon);
872 str[max_len - 1] =
'\0';
908 switch (value->kind) {
910 return vcardvalue_boolean_as_vcard_string_r(value);
913 return vcardvalue_int_as_vcard_string_r(value);
916 return vcardvalue_utcoffset_as_vcard_string_r(value, version);
919 return vcardvalue_text_as_vcard_string_r(value);
922 return vcardvalue_textlist_as_vcard_string_r(value,
923 is_structured ?
';' :
',');
926 return vcardvalue_structured_as_vcard_string_r(value);
929 return vcardvalue_geo_as_vcard_string_r(value);
933 return vcardvalue_string_as_vcard_string_r(value);
956 return vcardvalue_float_as_vcard_string_r(value);
961 if (value->x_value != 0) {
968 if (value->x_value != 0) {
993 const struct vcardvalue_impl *impl = (
struct vcardvalue_impl *)value;
995 icalerror_check_arg_rz((value != 0),
"value");
997 return (impl->id == ICAL_STRUCTURE_TYPE_VALUE);
1009 switch (value->kind) {
1033 icalerror_check_arg_rv((value != 0),
"value");
1035 value->parent = property;
1040 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)