diff --git a/src/message.hh b/src/message.hh index 214528c..0b9d530 100644 --- a/src/message.hh +++ b/src/message.hh @@ -109,7 +109,9 @@ namespace pEp { string comments() { return str_attr(_msg->comments); } void comments(string value) { str_attr(_msg->comments, value); } - stringpair_list_t *opt_fields; + dict opt_fields() { return strdict_attr(_msg->opt_fields); } + void opt_fields(dict value) { return strdict_attr(_msg->opt_fields, value); } + PEP_enc_format enc_format; }; } diff --git a/src/pEpmodule.cc b/src/pEpmodule.cc index cb7bb93..54e9f56 100644 --- a/src/pEpmodule.cc +++ b/src/pEpmodule.cc @@ -130,6 +130,9 @@ BOOST_PYTHON_MODULE(pEp) "keywords this message should be stored under") .add_property("comments", (string(Message::*)()) &Message::comments, (void(Message::*)(string)) &Message::comments, - "comments added to message"); + "comments added to message") + .add_property("opt_fields", (dict(Message::*)()) &Message::opt_fields, + (void(Message::*)(dict)) &Message::opt_fields, + "opt_fields of message"); } diff --git a/src/str_attr.cc b/src/str_attr.cc index 96d6bf2..71722d4 100644 --- a/src/str_attr.cc +++ b/src/str_attr.cc @@ -73,6 +73,56 @@ namespace pEp { free_stringlist(sl); sl = _sl; } + + dict strdict_attr(stringpair_list_t *&spl) + { + dict result; + + for (stringpair_list_t *_spl = spl; _spl && _spl->value; _spl = + _spl->next) { + stringpair_t *p = _spl->value; + if (p->key && p->value) { + string key(p->key); + string value(p->value); + + result[key] = value; + } + } + + return result; + } + + void strdict_attr(stringpair_list_t *&spl, dict value) + { + stringpair_list_t *_spl = new_stringpair_list(NULL); + if (!_spl) + throw bad_alloc(); + + stringpair_list_t *_s = _spl; + for (int i=0; i extract_key(value.keys()[i]); + extract< string > extract_value(value.values()[i]); + + if (!(extract_key.check() && extract_value.check())) + free_stringpair_list(_spl); + + string key = extract_key(); + string value = extract_value(); + stringpair_t *pair = new_stringpair(key.c_str(), value.c_str()); + if (!pair) { + free_stringpair_list(_spl); + throw bad_alloc(); + } + _s = stringpair_list_add(_s, pair); + if (!_s) { + free_stringpair_list(_spl); + throw bad_alloc(); + } + } + + free_stringpair_list(spl); + spl = _spl; + } } } diff --git a/src/str_attr.hh b/src/str_attr.hh index 68580ac..3f48da0 100644 --- a/src/str_attr.hh +++ b/src/str_attr.hh @@ -4,6 +4,7 @@ #include #include #include +#include namespace pEp { namespace utility { @@ -18,6 +19,9 @@ namespace pEp { list strlist_attr(stringlist_t *&sl); void strlist_attr(stringlist_t *&sl, list value); + + dict strdict_attr(stringpair_list_t *&spl); + void strdict_attr(stringpair_list_t *&spl, dict value); } }