Browse Source

adding stringpair_list opt_fields

AllGroupDevicesShowHandshake
Volker Birk 6 years ago
parent
commit
1c532252a1
4 changed files with 61 additions and 2 deletions
  1. +3
    -1
      src/message.hh
  2. +4
    -1
      src/pEpmodule.cc
  3. +50
    -0
      src/str_attr.cc
  4. +4
    -0
      src/str_attr.hh

+ 3
- 1
src/message.hh View File

@ -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;
};
}


+ 4
- 1
src/pEpmodule.cc View File

@ -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");
}

+ 50
- 0
src/str_attr.cc View File

@ -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<len(value); i++) {
extract< string > 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;
}
}
}

+ 4
- 0
src/str_attr.hh View File

@ -4,6 +4,7 @@
#include <pEp/pEpEngine.h>
#include <pEp/timestamp.h>
#include <pEp/stringlist.h>
#include <pEp/stringpair.h>
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);
}
}

Loading…
Cancel
Save