You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
724 lines
15 KiB
C++
724 lines
15 KiB
C++
4 years ago
|
#include "pEp-types.hh"
|
||
|
#include "pEp-utils.hh"
|
||
|
#include "pEp-utils-json.hh"
|
||
![]()
5 years ago
|
#include "json-adapter.hh"
|
||
7 years ago
|
|
||
5 years ago
|
#include <pEp/pEp_string.h>
|
||
5 years ago
|
#include <pEp/status_to_string.hh> // from libpEpAdapter
|
||
5 years ago
|
|
||
7 years ago
|
#include <iostream> // Just to print debug stuff to std::cerr
|
||
7 years ago
|
#include "base64.hh"
|
||
7 years ago
|
|
||
5 years ago
|
|
||
|
using pEp::utility::from_json_object;
|
||
|
using pEp::utility::to_json_object;
|
||
|
|
||
7 years ago
|
namespace
|
||
|
{
|
||
7 years ago
|
std::string base64_from_json_object(const js::Object& obj, const std::string& key)
|
||
|
{
|
||
|
const std::string b64String = from_json_object<std::string, js::str_type> (obj, key);
|
||
|
return base64_decode(b64String);
|
||
|
}
|
||
![]()
7 years ago
|
|
||
|
void to_base64_json_object(js::Object& obj, const std::string& key, char *value, size_t size)
|
||
7 years ago
|
{
|
||
|
if(value != nullptr && size>0)
|
||
|
{
|
||
|
const std::string raw_string(value, value+size);
|
||
|
obj.emplace_back( key, js::Value( base64_encode( raw_string ) ) );
|
||
|
}
|
||
|
}
|
||
6 years ago
|
|
||
|
} // end of anonymous namespace
|
||
7 years ago
|
|
||
|
|
||
7 years ago
|
template<>
|
||
5 years ago
|
In<PEP_SESSION, ParamFlag::NoInput>::~In()
|
||
7 years ago
|
{
|
||
|
// no automatic release!
|
||
|
}
|
||
|
|
||
|
|
||
7 years ago
|
template<>
|
||
|
In<const timestamp*>::~In()
|
||
|
{
|
||
|
free_timestamp(const_cast<timestamp*>(value)); // FIXME: is that const_cast okay?
|
||
|
}
|
||
|
|
||
|
|
||
7 years ago
|
template<>
|
||
|
In<message*>::~In()
|
||
|
{
|
||
|
free_message(value);
|
||
|
}
|
||
|
|
||
|
template<>
|
||
5 years ago
|
In<stringlist_t*, ParamFlag::Default>::~In()
|
||
7 years ago
|
{
|
||
|
free_stringlist(value);
|
||
|
}
|
||
|
|
||
5 years ago
|
template<>
|
||
5 years ago
|
In<stringlist_t*, ParamFlag::DontOwn>::~In()
|
||
5 years ago
|
{
|
||
|
}
|
||
|
|
||
7 years ago
|
|
||
|
template<>
|
||
|
In<pEp_identity*>::~In()
|
||
|
{
|
||
|
free_identity(value);
|
||
|
}
|
||
|
|
||
7 years ago
|
template<>
|
||
|
In<const pEp_identity*>::~In()
|
||
|
{
|
||
|
free_identity(const_cast<pEp_identity*>(value));
|
||
|
}
|
||
|
|
||
7 years ago
|
template<>
|
||
|
Out<pEp_identity*>::~Out()
|
||
|
{
|
||
5 years ago
|
free_identity(value);
|
||
7 years ago
|
}
|
||
|
|
||
7 years ago
|
template<>
|
||
|
Out<identity_list*>::~Out()
|
||
|
{
|
||
5 years ago
|
free_identity_list(value);
|
||
7 years ago
|
}
|
||
|
|
||
4 years ago
|
template<>
|
||
|
In<const identity_list*>::~In()
|
||
|
{
|
||
|
free_identity_list(const_cast<identity_list*>(value));
|
||
|
}
|
||
|
|
||
7 years ago
|
|
||
7 years ago
|
template<>
|
||
|
In<PEP_enc_format>::~In()
|
||
|
{
|
||
|
// nothing to do here. :-)
|
||
|
}
|
||
|
|
||
7 years ago
|
|
||
6 years ago
|
template<>
|
||
|
In<PEP_rating>::~In()
|
||
|
{
|
||
|
// nothing to do here. :-)
|
||
|
}
|
||
|
|
||
|
|
||
7 years ago
|
template<>
|
||
|
In<sync_handshake_signal>::~In()
|
||
|
{
|
||
|
// nothing to do here. :-)
|
||
|
}
|
||
|
|
||
|
|
||
7 years ago
|
template<>
|
||
|
In<sync_handshake_result>::~In()
|
||
|
{
|
||
|
// nothing to do here. :-)
|
||
|
}
|
||
|
|
||
|
|
||
7 years ago
|
|
||
|
template<>
|
||
5 years ago
|
Out<stringlist_t*, ParamFlag::Default>::~Out()
|
||
7 years ago
|
{
|
||
5 years ago
|
free_stringlist(value);
|
||
7 years ago
|
}
|
||
|
|
||
5 years ago
|
template<>
|
||
|
Out<stringlist_t*, ParamFlag::DontOwn>::~Out()
|
||
|
{
|
||
|
// don't call free_stringlist()!
|
||
|
}
|
||
|
|
||
7 years ago
|
template<>
|
||
|
Out<stringpair_list_t*>::~Out()
|
||
|
{
|
||
5 years ago
|
free_stringpair_list(value);
|
||
7 years ago
|
}
|
||
|
|
||
7 years ago
|
|
||
|
template<>
|
||
|
Out<_message*>::~Out()
|
||
|
{
|
||
5 years ago
|
free_message(value);
|
||
7 years ago
|
}
|
||
|
|
||
|
|
||
|
template<>
|
||
7 years ago
|
Out<PEP_rating>::~Out()
|
||
7 years ago
|
{
|
||
|
}
|
||
|
|
||
|
|
||
7 years ago
|
template<>
|
||
|
Out<PEP_comm_type>::~Out()
|
||
|
{
|
||
|
}
|
||
|
|
||
|
|
||
5 years ago
|
template<>
|
||
|
Out<PEP_STATUS>::~Out()
|
||
|
{
|
||
|
}
|
||
|
|
||
|
|
||
5 years ago
|
// used for strings that shall be _owned_ by the pEpEngine only!
|
||
|
template<>
|
||
|
char* from_json<char*>(const js::Value& v)
|
||
|
{
|
||
5 years ago
|
if(v.is_null())
|
||
|
{
|
||
|
return nullptr;
|
||
|
}
|
||
|
|
||
5 years ago
|
const std::string& ss = v.get_str();
|
||
5 years ago
|
char* s = new_string(ss.c_str(), ss.size() );
|
||
5 years ago
|
return s;
|
||
|
}
|
||
|
|
||
|
|
||
7 years ago
|
template<>
|
||
|
message* from_json<message*>(const js::Value& v)
|
||
|
{
|
||
5 years ago
|
if(v.is_null())
|
||
|
{
|
||
|
return nullptr;
|
||
|
}
|
||
|
|
||
7 years ago
|
const js::Object& o = v.get_obj();
|
||
5 years ago
|
|
||
5 years ago
|
auto msg = pEp::utility::make_c_ptr(new_message(PEP_dir_incoming), &free_message );
|
||
5 years ago
|
|
||
7 years ago
|
// fetch values from v and put them into msg
|
||
7 years ago
|
msg->dir = from_json_object<PEP_msg_direction, js::int_type>(o, "dir");
|
||
7 years ago
|
msg->id = from_json_object<char*, js::str_type>(o, "id");
|
||
7 years ago
|
msg->shortmsg = from_json_object<char*, js::str_type>(o, "shortmsg");
|
||
|
msg->longmsg = from_json_object<char*, js::str_type>(o, "longmsg");
|
||
|
msg->longmsg_formatted = from_json_object<char*, js::str_type>(o, "longmsg_formatted");
|
||
7 years ago
|
|
||
|
msg->attachments = from_json_object<bloblist_t*, js::array_type>(o, "attachments");
|
||
|
|
||
|
msg->sent = from_json_object<timestamp*, js::int_type>(o, "sent");
|
||
|
msg->recv = from_json_object<timestamp*, js::int_type>(o, "recv");
|
||
|
|
||
6 years ago
|
msg->from = from_json_object<pEp_identity* , js::obj_type> (o, "from");
|
||
7 years ago
|
msg->to = from_json_object<identity_list*, js::array_type>(o, "to");
|
||
6 years ago
|
msg->recv_by = from_json_object<pEp_identity* , js::obj_type> (o, "recv_by");
|
||
7 years ago
|
msg->cc = from_json_object<identity_list*, js::array_type>(o, "cc");
|
||
|
msg->bcc = from_json_object<identity_list*, js::array_type>(o, "bcc");
|
||
|
msg->reply_to = from_json_object<identity_list*, js::array_type>(o, "reply_to");
|
||
|
msg->in_reply_to = from_json_object<stringlist_t*, js::array_type>(o, "in_reply_to");
|
||
7 years ago
|
|
||
|
// TODO: refering_msg_ref
|
||
|
msg->references = from_json_object<stringlist_t*, js::array_type>(o, "references");
|
||
|
// TODO: refered_by
|
||
|
|
||
|
msg->keywords = from_json_object<stringlist_t*, js::int_type>(o, "keywords");
|
||
|
msg->comments = from_json_object<char*, js::str_type>(o, "comments");
|
||
|
msg->opt_fields = from_json_object<stringpair_list_t*, js::array_type>(o, "opt_fields");
|
||
|
msg->enc_format = from_json_object<PEP_enc_format, js::int_type>(o, "enc_format");
|
||
7 years ago
|
|
||
5 years ago
|
return msg.release();
|
||
7 years ago
|
}
|
||
|
|
||
|
|
||
|
template<>
|
||
|
pEp_identity* from_json<pEp_identity*>(const js::Value& v)
|
||
|
{
|
||
5 years ago
|
if(v.is_null())
|
||
|
{
|
||
|
return nullptr;
|
||
|
}
|
||
|
|
||
7 years ago
|
const js::Object& o = v.get_obj();
|
||
|
|
||
5 years ago
|
auto address = pEp::utility::make_c_ptr(from_json_object<char*, js::str_type>(o, "address") , &free_string );
|
||
|
auto fingerprint = pEp::utility::make_c_ptr(from_json_object<char*, js::str_type>(o, "fpr") , &free_string );
|
||
|
auto user_id = pEp::utility::make_c_ptr(from_json_object<char*, js::str_type>(o, "user_id") , &free_string );
|
||
|
auto username = pEp::utility::make_c_ptr(from_json_object<char*, js::str_type>(o, "username") , &free_string );
|
||
|
auto lang = pEp::utility::make_c_ptr(from_json_object<char*, js::str_type>(o, "lang") , &free_string );
|
||
7 years ago
|
|
||
5 years ago
|
auto ident = pEp::utility::make_c_ptr( new_identity
|
||
7 years ago
|
(
|
||
5 years ago
|
address.get(),
|
||
|
fingerprint.get(),
|
||
|
user_id.get(),
|
||
|
username.get()
|
||
|
), &free_identity );
|
||
7 years ago
|
|
||
7 years ago
|
ident->comm_type = from_json_object<PEP_comm_type, js::int_type>(o, "comm_type");
|
||
5 years ago
|
if(lang && lang.get()[0] && lang.get()[1])
|
||
7 years ago
|
{
|
||
5 years ago
|
strncpy(ident->lang, lang.get(), 3);
|
||
7 years ago
|
}
|
||
7 years ago
|
ident->flags = from_json_object<unsigned, js::int_type>(o, "flags");
|
||
7 years ago
|
|
||
5 years ago
|
return ident.release();
|
||
7 years ago
|
}
|
||
|
|
||
7 years ago
|
template<>
|
||
|
const pEp_identity* from_json<const pEp_identity*>(const js::Value& v)
|
||
|
{
|
||
6 years ago
|
return from_json<pEp_identity*>(v);
|
||
7 years ago
|
}
|
||
|
|
||
7 years ago
|
|
||
|
template<>
|
||
7 years ago
|
js::Value to_json<message const*>(message const* const& msg)
|
||
7 years ago
|
{
|
||
|
if(msg == nullptr)
|
||
|
{
|
||
5 years ago
|
return js::Value();
|
||
7 years ago
|
}
|
||
|
|
||
|
js::Object o;
|
||
7 years ago
|
to_json_object(o, "dir" , msg->dir);
|
||
|
to_json_object(o, "id" , msg->id);
|
||
7 years ago
|
to_json_object(o, "shortmsg", msg->shortmsg);
|
||
|
to_json_object(o, "longmsg" , msg->longmsg);
|
||
|
to_json_object(o, "longmsg_formatted" , msg->longmsg_formatted);
|
||
7 years ago
|
to_json_object(o, "attachments", msg->attachments);
|
||
|
to_json_object(o, "sent" , msg->sent);
|
||
|
to_json_object(o, "recv" , msg->recv);
|
||
|
|
||
7 years ago
|
to_json_object(o, "from" , msg->from);
|
||
7 years ago
|
to_json_object(o, "to" , msg->to);
|
||
7 years ago
|
to_json_object(o, "recv_by" , msg->recv_by);
|
||
|
|
||
7 years ago
|
to_json_object(o, "cc" , msg->cc);
|
||
|
to_json_object(o, "bcc" , msg->bcc);
|
||
|
to_json_object(o, "reply_to", msg->reply_to);
|
||
7 years ago
|
to_json_object(o, "in_reply_to" , msg->in_reply_to);
|
||
|
|
||
7 years ago
|
// TODO: refering_msg_ref
|
||
|
to_json_object(o, "references", msg->references);
|
||
|
// TODO: refered_by
|
||
|
|
||
|
to_json_object(o, "keywords", msg->keywords);
|
||
|
to_json_object(o, "comments", msg->comments);
|
||
|
to_json_object(o, "opt_fields", msg->opt_fields);
|
||
|
to_json_object(o, "enc_format", msg->enc_format);
|
||
7 years ago
|
|
||
7 years ago
|
return js::Value( std::move(o) );
|
||
7 years ago
|
}
|
||
|
|
||
7 years ago
|
template<>
|
||
|
js::Value to_json<message*>(message* const& msg)
|
||
|
{
|
||
|
return to_json( const_cast<const message*>(msg) );
|
||
|
}
|
||
|
|
||
7 years ago
|
|
||
|
template<>
|
||
|
stringlist_t* from_json<stringlist_t*>(const js::Value& v)
|
||
|
{
|
||
5 years ago
|
if(v.is_null())
|
||
|
{
|
||
|
return nullptr;
|
||
|
}
|
||
|
|
||
7 years ago
|
const js::Array& a = v.get_array();
|
||
5 years ago
|
auto sl = pEp::utility::make_c_ptr(new_stringlist( nullptr ), &free_stringlist );
|
||
5 years ago
|
|
||
7 years ago
|
for(const js::Value& v : a )
|
||
|
{
|
||
5 years ago
|
const std::string& s = v.get_str();
|
||
|
stringlist_add(sl.get(), s.c_str() );
|
||
7 years ago
|
}
|
||
5 years ago
|
|
||
5 years ago
|
return sl.release();
|
||
7 years ago
|
}
|
||
|
|
||
6 years ago
|
template<>
|
||
|
const stringlist_t* from_json<const stringlist_t*>(const js::Value& v)
|
||
|
{
|
||
|
return const_cast<const stringlist_t*>( from_json<stringlist_t*>(v) );
|
||
|
}
|
||
|
|
||
7 years ago
|
|
||
|
template<>
|
||
|
identity_list* from_json<identity_list*>(const js::Value& v)
|
||
|
{
|
||
5 years ago
|
if(v.is_null())
|
||
|
{
|
||
|
return nullptr;
|
||
|
}
|
||
|
|
||
7 years ago
|
const js::Array& a = v.get_array();
|
||
5 years ago
|
auto il = pEp::utility::make_c_ptr(new_identity_list( nullptr ), &free_identity_list);
|
||
5 years ago
|
|
||
7 years ago
|
for(const js::Value& v : a )
|
||
|
{
|
||
|
pEp_identity* id = from_json<pEp_identity*>(v);
|
||
5 years ago
|
identity_list_add(il.get(), id );
|
||
7 years ago
|
}
|
||
5 years ago
|
|
||
5 years ago
|
return il.release();
|
||
7 years ago
|
}
|
||
|
|
||
4 years ago
|
template<>
|
||
|
const identity_list* from_json<const identity_list*>(const js::Value& v)
|
||
|
{
|
||
|
return from_json<identity_list*>(v);
|
||
|
}
|
||
7 years ago
|
|
||
7 years ago
|
template<>
|
||
|
_bloblist_t* from_json<_bloblist_t*>(const js::Value& v)
|
||
|
{
|
||
5 years ago
|
if(v.is_null())
|
||
|
{
|
||
|
return nullptr;
|
||
|
}
|
||
|
|
||
7 years ago
|
const js::Array& a = v.get_array();
|
||
|
if(a.empty())
|
||
|
return nullptr;
|
||
|
|
||
|
auto element = a.begin();
|
||
![]()
7 years ago
|
_bloblist_t* bl = NULL;
|
||
6 years ago
|
|
||
|
for(; element!=a.end(); ++element)
|
||
7 years ago
|
{
|
||
|
const auto oelem = element->get_obj();
|
||
5 years ago
|
|
||
|
// FIXME: change base64 decoder that it decodes into output array directly to avoid copying.
|
||
6 years ago
|
std::string v = base64_from_json_object(oelem, "value");
|
||
|
size_t vs = v.size();
|
||
5 years ago
|
char* vc = new_string(nullptr, vs + 1);
|
||
6 years ago
|
if(vc == NULL)
|
||
|
throw std::runtime_error("Out of memory while allocating blob");
|
||
|
|
||
![]()
7 years ago
|
memcpy(vc, v.c_str(), vs + 1 );
|
||
6 years ago
|
|
||
5 years ago
|
// must use unique_ptr<char> instead of std::string to handle NULL values differently from empty strings:
|
||
|
auto mime_type = pEp::utility::make_c_ptr( from_json_object<char*, js::str_type>(oelem, "mime_type"), &free_string );
|
||
|
auto filename = pEp::utility::make_c_ptr( from_json_object<char*, js::str_type>(oelem, "filename") , &free_string );
|
||
|
|
||
|
bl = bloblist_add(bl, vc, vs, mime_type.get(), filename.get());
|
||
6 years ago
|
|
||
|
if(bl == NULL)
|
||
5 years ago
|
throw std::runtime_error("Couldn't add blob to bloblist");
|
||
7 years ago
|
}
|
||
6 years ago
|
|
||
7 years ago
|
return bl;
|
||
|
}
|
||
|
|
||
|
|
||
7 years ago
|
template<>
|
||
|
js::Value to_json<_bloblist_t*>(_bloblist_t* const& bl)
|
||
|
{
|
||
|
_bloblist_t* b = bl;
|
||
|
js::Array a;
|
||
|
|
||
|
while(b)
|
||
|
{
|
||
|
js::Object o;
|
||
6 years ago
|
if(b->value)
|
||
|
{
|
||
|
to_base64_json_object(o, "value", b->value, b->size);
|
||
|
}
|
||
7 years ago
|
o.emplace_back( "size", boost::uint64_t(b->size) );
|
||
7 years ago
|
|
||
|
if(b->mime_type)
|
||
6 years ago
|
{
|
||
7 years ago
|
o.emplace_back( "mime_type", b->mime_type );
|
||
6 years ago
|
}
|
||
7 years ago
|
|
||
|
if(b->filename)
|
||
6 years ago
|
{
|
||
7 years ago
|
o.emplace_back( "filename", b->filename );
|
||
6 years ago
|
}
|
||
7 years ago
|
|
||
|
a.push_back( std::move(o) );
|
||
|
b = b->next;
|
||
|
}
|
||
|
|
||
|
return js::Value( std::move(a) );
|
||
|
}
|
||
|
|
||
6 years ago
|
|
||
7 years ago
|
template<>
|
||
|
stringpair_t* from_json<stringpair_t*>(const js::Value& v)
|
||
|
{
|
||
5 years ago
|
if(v.is_null())
|
||
|
{
|
||
|
return nullptr;
|
||
|
}
|
||
|
|
||
7 years ago
|
const js::Object& o = v.get_obj();
|
||
|
char* key = from_json_object<char*, js::str_type>(o, "key");
|
||
|
char* val = from_json_object<char*, js::str_type>(o, "value");
|
||
|
stringpair_t* sp = new_stringpair( key, val );
|
||
|
free(val);
|
||
|
free(key);
|
||
|
return sp;
|
||
|
}
|
||
|
|
||
|
|
||
7 years ago
|
|
||
7 years ago
|
template<>
|
||
|
stringpair_list_t* from_json<stringpair_list_t*>(const js::Value& v)
|
||
|
{
|
||
5 years ago
|
if(v.is_null())
|
||
|
{
|
||
|
return nullptr;
|
||
|
}
|
||
|
|
||
7 years ago
|
const js::Array& a = v.get_array();
|
||
|
if(a.empty())
|
||
|
return nullptr;
|
||
|
|
||
|
auto element = a.begin();
|
||
|
stringpair_list_t* spl = new_stringpair_list( from_json<stringpair_t*>(*element) );
|
||
7 years ago
|
|
||
|
++element;
|
||
|
|
||
7 years ago
|
for(; element!=a.end(); ++element)
|
||
|
{
|
||
|
spl = stringpair_list_add(spl, from_json<stringpair_t*>(*element) );
|
||
|
}
|
||
|
|
||
|
return spl;
|
||
|
}
|
||
|
|
||
|
|
||
7 years ago
|
template<>
|
||
|
js::Value to_json<stringpair_list_t*>(stringpair_list_t* const& osl)
|
||
|
{
|
||
|
stringpair_list_t* spl = osl;
|
||
|
js::Array a;
|
||
|
|
||
|
while(spl)
|
||
|
{
|
||
6 years ago
|
if(spl->value)
|
||
|
{
|
||
|
js::Object o;
|
||
|
o.emplace_back( "key", spl->value->key );
|
||
|
o.emplace_back( "value", spl->value->value );
|
||
|
a.push_back( std::move(o) );
|
||
|
}
|
||
7 years ago
|
spl = spl->next;
|
||
|
}
|
||
|
|
||
7 years ago
|
return js::Value( std::move(a) );
|
||
7 years ago
|
}
|
||
|
|
||
|
|
||
7 years ago
|
template<>
|
||
|
tm* from_json<tm*>(const js::Value& v)
|
||
|
{
|
||
|
return new_timestamp( v.get_int64() );
|
||
|
}
|
||
|
|
||
7 years ago
|
template<>
|
||
|
const tm* from_json<const tm*>(const js::Value& v)
|
||
|
{
|
||
|
return new_timestamp( v.get_int64() );
|
||
|
}
|
||
|
|
||
|
|
||
7 years ago
|
template<>
|
||
6 years ago
|
js::Value to_json<const stringlist_t*>(const stringlist_t* const& osl)
|
||
7 years ago
|
{
|
||
6 years ago
|
const stringlist_t* sl = osl;
|
||
7 years ago
|
js::Array a;
|
||
|
|
||
|
while(sl)
|
||
|
{
|
||
6 years ago
|
if(sl->value)
|
||
|
{
|
||
|
std::string value = sl->value;
|
||
|
a.push_back( std::move(value) );
|
||
|
}
|
||
7 years ago
|
sl = sl->next;
|
||
|
}
|
||
|
|
||
7 years ago
|
return js::Value( std::move(a) );
|
||
7 years ago
|
}
|
||
|
|
||
6 years ago
|
template<>
|
||
|
js::Value to_json<stringlist_t*>(stringlist_t* const& osl)
|
||
|
{
|
||
|
return to_json<const stringlist_t*>(osl);
|
||
|
}
|
||
7 years ago
|
|
||
|
template<>
|
||
7 years ago
|
js::Value to_json<const pEp_identity*>(const pEp_identity* const& id)
|
||
7 years ago
|
{
|
||
|
if(id == nullptr)
|
||
|
{
|
||
5 years ago
|
return js::Value();
|
||
7 years ago
|
}
|
||
|
|
||
|
js::Object o;
|
||
|
|
||
6 years ago
|
to_json_object(o, "address" , id->address);
|
||
|
to_json_object(o, "fpr" , id->fpr);
|
||
|
to_json_object(o, "user_id" , id->user_id);
|
||
7 years ago
|
to_json_object(o, "username", id->username);
|
||
6 years ago
|
|
||
|
o.emplace_back( "comm_type" , js::Value( int( id->comm_type) ));
|
||
7 years ago
|
|
||
7 years ago
|
if(id->lang[0] && id->lang[1])
|
||
7 years ago
|
o.emplace_back( "lang", js::Value( std::string( id->lang, id->lang+2) ));
|
||
|
|
||
7 years ago
|
return js::Value( std::move(o) );
|
||
7 years ago
|
}
|
||
|
|
||
7 years ago
|
template<>
|
||
|
js::Value to_json<pEp_identity*>(pEp_identity* const& id)
|
||
|
{
|
||
|
return to_json( const_cast<const pEp_identity*>(id) );
|
||
|
}
|
||
|
|
||
7 years ago
|
|
||
|
template<>
|
||
|
js::Value to_json<identity_list*>(identity_list* const& idl)
|
||
|
{
|
||
|
identity_list* il = idl;
|
||
|
js::Array a;
|
||
|
|
||
|
while(il)
|
||
|
{
|
||
|
const js::Value value = to_json<pEp_identity*>(il->ident);
|
||
|
a.push_back(value);
|
||
|
il = il->next;
|
||
|
}
|
||
|
|
||
7 years ago
|
return js::Value( std::move(a) );
|
||
7 years ago
|
}
|
||
|
|
||
|
|
||
|
template<>
|
||
7 years ago
|
js::Value to_json<PEP_rating>(const PEP_rating& rating)
|
||
7 years ago
|
{
|
||
|
js::Object o;
|
||
6 years ago
|
o.emplace_back( "rating", int(rating) );
|
||
7 years ago
|
return o;
|
||
|
}
|
||
|
|
||
|
|
||
6 years ago
|
template<>
|
||
|
PEP_rating from_json<PEP_rating>(const js::Value& v)
|
||
|
{
|
||
|
const js::Object& o = v.get_obj();
|
||
|
return from_json_object<PEP_rating, js::int_type>(o, "rating");
|
||
|
}
|
||
|
|
||
|
|
||
7 years ago
|
template<>
|
||
|
js::Value to_json<PEP_STATUS>(const PEP_STATUS& status)
|
||
|
{
|
||
|
js::Object o;
|
||
|
o.emplace_back( "status", int(status) );
|
||
5 years ago
|
o.emplace_back( "hex", ::pEp::status_to_string(status) );
|
||
7 years ago
|
return o;
|
||
|
}
|
||
|
|
||
|
|
||
|
template<>
|
||
|
PEP_enc_format from_json<PEP_enc_format>(const js::Value& v)
|
||
|
{
|
||
|
return PEP_enc_format(v.get_int());
|
||
|
}
|
||
|
|
||
7 years ago
|
template<>
|
||
|
js::Value to_json<PEP_enc_format>(const PEP_enc_format& v)
|
||
|
{
|
||
|
return js::Value( int(v) );
|
||
|
}
|
||
|
|
||
7 years ago
|
|
||
7 years ago
|
template<>
|
||
|
PEP_msg_direction from_json<PEP_msg_direction>(const js::Value& v)
|
||
|
{
|
||
|
return PEP_msg_direction(v.get_int());
|
||
|
}
|
||
|
|
||
|
|
||
7 years ago
|
template<>
|
||
|
js::Value to_json<PEP_msg_direction>(const PEP_msg_direction& v)
|
||
|
{
|
||
|
return js::Value( int(v) );
|
||
|
}
|
||
|
|
||
7 years ago
|
template<>
|
||
|
js::Value to_json<sync_handshake_signal>(const sync_handshake_signal& s)
|
||
|
{
|
||
|
js::Object o;
|
||
|
o.emplace_back( "sync_handshake_signal", int(s) );
|
||
|
return o;
|
||
|
}
|
||
|
|
||
7 years ago
|
template<>
|
||
|
PEP_comm_type from_json<PEP_comm_type>(const js::Value& v)
|
||
|
{
|
||
|
return PEP_comm_type(v.get_int());
|
||
|
}
|
||
|
|
||
7 years ago
|
template<>
|
||
|
sync_handshake_result from_json<sync_handshake_result>(const js::Value& v)
|
||
|
{
|
||
|
return sync_handshake_result(v.get_int());
|
||
|
}
|
||
|
|
||
7 years ago
|
template<>
|
||
|
js::Value to_json<PEP_comm_type>(const PEP_comm_type& v)
|
||
|
{
|
||
|
return js::Value( int(v) );
|
||
|
}
|
||
|
|
||
7 years ago
|
|
||
7 years ago
|
template<>
|
||
|
js::Value Type2String<PEP_SESSION>::get() { return "Session"; }
|
||
|
|
||
|
template<>
|
||
|
js::Value Type2String<_message*>::get() { return "Message"; }
|
||
|
|
||
7 years ago
|
template<>
|
||
|
js::Value Type2String<const timestamp*>::get() { return "Timestamp"; }
|
||
|
|
||
7 years ago
|
template<>
|
||
|
js::Value Type2String<pEp_identity*>::get() { return "Identity"; }
|
||
7 years ago
|
template<>
|
||
|
js::Value Type2String<const pEp_identity*>::get() { return "Identity"; }
|
||
7 years ago
|
|
||
7 years ago
|
template<>
|
||
|
js::Value Type2String<identity_list*>::get() { return "IdentityList"; }
|
||
4 years ago
|
template<>
|
||
|
js::Value Type2String<const identity_list*>::get() { return "IdentityList"; }
|
||
7 years ago
|
|
||
7 years ago
|
template<>
|
||
|
js::Value Type2String<_stringlist_t*>::get() { return "StringList"; }
|
||
|
|
||
7 years ago
|
template<>
|
||
|
js::Value Type2String<stringpair_list_t*>::get() { return "StringPairList"; }
|
||
|
|
||
7 years ago
|
template<>
|
||
7 years ago
|
js::Value Type2String<_PEP_rating>::get() { return "PEP_rating"; }
|
||
7 years ago
|
|
||
|
template<>
|
||
|
js::Value Type2String<_PEP_enc_format>::get() { return "PEP_enc_format"; }
|
||
|
|
||
7 years ago
|
template<>
|
||
|
js::Value Type2String<sync_handshake_result>::get() { return "PEP_sync_handshake_result"; }
|
||
|
|
||
7 years ago
|
template<>
|
||
|
js::Value Type2String<_PEP_comm_type>::get() { return "PEP_comm_type"; }
|
||
|
|
||
7 years ago
|
template<>
|
||
|
js::Value Type2String<PEP_STATUS>::get() { return "PEP_STATUS"; }
|
||
|
|
||
6 years ago
|
template<>
|
||
|
js::Value Type2String<Language>::get() { return "Language"; }
|
||
![]()
5 years ago
|
|
||
|
template<>
|
||
|
js::Value Type2String<JsonAdapter *>::get() { return "JsonAdapter"; }
|