diff --git a/src/str_attr.cc b/src/str_attr.cc index f4cfc68..083c87a 100644 --- a/src/str_attr.cc +++ b/src/str_attr.cc @@ -37,6 +37,42 @@ namespace pEp { free_timestamp(ts); ts = new_timestamp(value); } + + list strlist(stringlist_t *&sl) + { + list result; + + for (stringlist_t *_sl = sl; _sl && _sl->value; _sl = _sl->next) { + string s(_sl->value); + result.append(object(s)); + } + + return result; + } + + void strlist(stringlist_t *&sl, list value) + { + stringlist_t *_sl = new_stringlist(NULL); + if (!_sl) + throw bad_alloc(); + + stringlist_t *_s = _sl; + for (int i=0; i extract_string(value[i]); + if (!extract_string.check()) { + free_stringlist(_sl); + } + string s = extract_string(); + _s = stringlist_add(_s, s.c_str()); + if (!_s) { + free_stringlist(_sl); + throw bad_alloc(); + } + } + + free_stringlist(sl); + sl = _sl; + } } } diff --git a/src/str_attr.hh b/src/str_attr.hh index a2fdd0c..49caea9 100644 --- a/src/str_attr.hh +++ b/src/str_attr.hh @@ -3,6 +3,7 @@ #include #include #include +#include namespace pEp { namespace utility { @@ -14,6 +15,9 @@ namespace pEp { time_t timestamp_attr(timestamp *&ts); void timestamp_attr(timestamp *&ts, time_t value); + + list strlist(stringlist_t *&sl); + void strlist(stringlist_t *&sl, list value); } }