Browse Source

adding stringpair_list opt_fields

PYADPT-55
Volker Birk 9 years ago
parent
commit
1c532252a1
  1. 4
      src/message.hh
  2. 5
      src/pEpmodule.cc
  3. 50
      src/str_attr.cc
  4. 4
      src/str_attr.hh

4
src/message.hh

@ -109,7 +109,9 @@ namespace pEp {
string comments() { return str_attr(_msg->comments); } string comments() { return str_attr(_msg->comments); }
void comments(string value) { str_attr(_msg->comments, value); } 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; PEP_enc_format enc_format;
}; };
} }

5
src/pEpmodule.cc

@ -130,6 +130,9 @@ BOOST_PYTHON_MODULE(pEp)
"keywords this message should be stored under") "keywords this message should be stored under")
.add_property("comments", (string(Message::*)()) &Message::comments, .add_property("comments", (string(Message::*)()) &Message::comments,
(void(Message::*)(string)) &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
src/str_attr.cc

@ -73,6 +73,56 @@ namespace pEp {
free_stringlist(sl); free_stringlist(sl);
sl = _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
src/str_attr.hh

@ -4,6 +4,7 @@
#include <pEp/pEpEngine.h> #include <pEp/pEpEngine.h>
#include <pEp/timestamp.h> #include <pEp/timestamp.h>
#include <pEp/stringlist.h> #include <pEp/stringlist.h>
#include <pEp/stringpair.h>
namespace pEp { namespace pEp {
namespace utility { namespace utility {
@ -18,6 +19,9 @@ namespace pEp {
list strlist_attr(stringlist_t *&sl); list strlist_attr(stringlist_t *&sl);
void strlist_attr(stringlist_t *&sl, list value); 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