diff options
author | Ken Murchison <murch@fastmail.com> | 2020-11-08 09:04:48 -0500 |
---|---|---|
committer | Ken Murchison <murch@fastmail.com> | 2020-11-08 09:05:42 -0500 |
commit | e412005c3da06fb799b373643991e6dbb038307d (patch) | |
tree | 1ce537ef39f7a5f83277f0d85fb7dae79fc9cac6 | |
parent | faccb83ed4fb87b52b6ed4076fc2f4cce96b8a02 (diff) | |
download | libical-git-e412005c3da06fb799b373643991e6dbb038307d.tar.gz |
Added icalcomponent_[set|get]_x_name() and icalcomponent_get_component_name[_r]() - issue #433
-rw-r--r-- | ReleaseNotes.txt | 4 | ||||
-rw-r--r-- | src/libical/icalcomponent.c | 64 | ||||
-rw-r--r-- | src/libical/icalcomponent.h | 11 | ||||
-rw-r--r-- | src/libical/icalparser.c | 6 |
4 files changed, 84 insertions, 1 deletions
diff --git a/ReleaseNotes.txt b/ReleaseNotes.txt index 5f98714e..e2a7735e 100644 --- a/ReleaseNotes.txt +++ b/ReleaseNotes.txt @@ -18,6 +18,10 @@ Version 3.1.0 (NOT RELEASED YET): + icalvalue_clone + icalcluster_clone + icalrecur_iterator_prev + + icalcomponent_set_x_name + + icalcomponent_get_x_name + + icalcomponent_get_component_name + + icalcomponent_get_component_name_r * icaltzutil_get_zone_directory() can use the TZDIR environment to find system zoneinfo * Deprecated functions: + caldat (replaced by internal function icaldat_int()) diff --git a/src/libical/icalcomponent.c b/src/libical/icalcomponent.c index f6e8655c..deb2c402 100644 --- a/src/libical/icalcomponent.c +++ b/src/libical/icalcomponent.c @@ -330,6 +330,70 @@ int icalcomponent_isa_component(void *component) } } +void icalcomponent_set_x_name(icalcomponent *comp, const char *name) +{ + icalerror_check_arg_rv((name != 0), "name"); + icalerror_check_arg_rv((comp != 0), "comp"); + + if (comp->x_name != 0) { + free(comp->x_name); + } + + comp->x_name = icalmemory_strdup(name); + + if (comp->x_name == 0) { + icalerror_set_errno(ICAL_NEWFAILED_ERROR); + } +} + +const char *icalcomponent_get_x_name(icalcomponent *comp) +{ + icalerror_check_arg_rz((comp != 0), "comp"); + + return comp->x_name; +} + +const char *icalcomponent_get_component_name(const icalcomponent *comp) +{ + char *buf; + + buf = icalcomponent_get_component_name_r(comp); + icalmemory_add_tmp_buffer(buf); + return buf; +} + +char *icalcomponent_get_component_name_r(const icalcomponent *comp) +{ + const char *component_name = 0; + size_t buf_size = 256; + char *buf; + char *buf_ptr; + + icalerror_check_arg_rz((comp != 0), "comp"); + + buf = icalmemory_new_buffer(buf_size); + buf_ptr = buf; + + if (comp->kind == ICAL_X_COMPONENT && comp->x_name != 0) { + component_name = comp->x_name; + } else { + component_name = icalcomponent_kind_to_string(comp->kind); + } + + if (component_name == 0) { + icalerror_set_errno(ICAL_MALFORMEDDATA_ERROR); + icalmemory_free_buffer(buf); + return 0; + + } else { + /* _append_string will automatically grow the buffer if + component_name is longer than the initial buffer size */ + icalmemory_append_string(&buf, &buf_ptr, &buf_size, component_name); + } + + return buf; +} + void icalcomponent_add_property(icalcomponent *component, icalproperty *property) { icalerror_check_arg_rv((component != 0), "component"); diff --git a/src/libical/icalcomponent.h b/src/libical/icalcomponent.h index e3ece75e..8b68c5e7 100644 --- a/src/libical/icalcomponent.h +++ b/src/libical/icalcomponent.h @@ -77,6 +77,17 @@ LIBICAL_ICAL_EXPORT icalcomponent_kind icalcomponent_isa(const icalcomponent *co LIBICAL_ICAL_EXPORT int icalcomponent_isa_component(void *component); +/* Deal with X components */ + +LIBICAL_ICAL_EXPORT void icalcomponent_set_x_name(icalcomponent *comp, const char *name); +LIBICAL_ICAL_EXPORT const char *icalcomponent_get_x_name(icalcomponent *comp); + +/** Returns the name of the component -- the type name converted to a + * string, or the value of _get_x_name if the type is and X component + */ +LIBICAL_ICAL_EXPORT const char *icalcomponent_get_component_name(const icalcomponent *comp); +LIBICAL_ICAL_EXPORT char *icalcomponent_get_component_name_r(const icalcomponent *comp); + /** * @copydoc icalcomponent_clone() * @deprecated Use icalcomponent_clone() instead diff --git a/src/libical/icalparser.c b/src/libical/icalparser.c index 5f9e9ac2..4a8e2b3b 100644 --- a/src/libical/icalparser.c +++ b/src/libical/icalparser.c @@ -762,7 +762,11 @@ icalcomponent *icalparser_add_line(icalparser *parser, char *line) comp_kind = icalenum_string_to_component_kind(str); - c = icalcomponent_new(comp_kind); + if (comp_kind == ICAL_X_COMPONENT) { + c = icalcomponent_new_x(str); + } else { + c = icalcomponent_new(comp_kind); + } if (c == 0) { c = icalcomponent_new(ICAL_XLICINVALID_COMPONENT); |