Browse Source

swapContent

ENGINE-781
Volker Birk 5 years ago
parent
commit
d526591460
  1. 83
      message_cache.cc

83
message_cache.cc

@ -241,6 +241,21 @@ namespace pEp {
} }
} }
static void swapContent(::message*& part, ::message*& full)
{
free(part->longmsg);
part->longmsg = full->longmsg;
full->longmsg = nullptr;
free(part->longmsg_formatted);
part->longmsg_formatted = full->longmsg_formatted;
full->longmsg_formatted = nullptr;
free_bloblist(part->attachments);
part->attachments = full->attachments;
full->attachments = nullptr;
}
DYNAMIC_API PEP_STATUS MessageCache::decrypt_message( DYNAMIC_API PEP_STATUS MessageCache::decrypt_message(
PEP_SESSION session, PEP_SESSION session,
message *src, message *src,
@ -259,17 +274,7 @@ namespace pEp {
_msg = message_cache._cache.at(src->id).src; _msg = message_cache._cache.at(src->id).src;
} }
free(src->longmsg); swapContent(src, _msg);
src->longmsg = _msg->longmsg;
_msg->longmsg = nullptr;
free(src->longmsg_formatted);
src->longmsg_formatted = _msg->longmsg_formatted;
_msg->longmsg_formatted = nullptr;
free_bloblist(src->attachments);
src->attachments = _msg->attachments;
_msg->attachments = nullptr;
// if attachments got reordered correct // if attachments got reordered correct
correctAttachmentsOrder(src->attachments); correctAttachmentsOrder(src->attachments);
@ -278,14 +283,7 @@ namespace pEp {
PEP_STATUS status = ::decrypt_message(session, src, &_dst, keylist, PEP_STATUS status = ::decrypt_message(session, src, &_dst, keylist,
rating, flags); rating, flags);
_msg->longmsg = src->longmsg; swapContent(_msg, src);
src->longmsg = nullptr;
_msg->longmsg_formatted = src->longmsg_formatted;
src->longmsg_formatted = nullptr;
_msg->attachments = src->attachments;
src->attachments = nullptr;
*dst = empty_message_copy(_dst); *dst = empty_message_copy(_dst);
@ -316,36 +314,14 @@ namespace pEp {
::message *_src = _cache.at(std::string(msg->id)).src; ::message *_src = _cache.at(std::string(msg->id)).src;
::free_message(_cache.at(msg->id).dst); ::free_message(_cache.at(msg->id).dst);
free(_msg->longmsg); swapContent(_msg, _src);
_msg->longmsg = _src->longmsg;
_src->longmsg = nullptr;
free(_msg->longmsg_formatted);
_msg->longmsg_formatted = _src->longmsg_formatted;
_src->longmsg_formatted = nullptr;
free_bloblist(_msg->attachments);
_msg->attachments = _src->attachments;
_src->attachments = nullptr;
free_message(_src); free_message(_src);
} }
else /* msg_dst */ { else /* msg_dst */ {
::message *_dst = _cache.at(std::string(msg->id)).dst; ::message *_dst = _cache.at(std::string(msg->id)).dst;
::free_message(_cache.at(msg->id).src); ::free_message(_cache.at(msg->id).src);
free(_msg->longmsg); swapContent(_msg, _dst);
_msg->longmsg = _dst->longmsg;
_dst->longmsg = nullptr;
free(_msg->longmsg_formatted);
_msg->longmsg_formatted = _dst->longmsg_formatted;
_dst->longmsg_formatted = nullptr;
free_bloblist(_msg->attachments);
_msg->attachments = _dst->attachments;
_dst->attachments = nullptr;
free_message(_dst); free_message(_dst);
} }
@ -397,30 +373,13 @@ namespace pEp {
_msg = message_cache._cache.at(src->id).src; _msg = message_cache._cache.at(src->id).src;
} }
free(src->longmsg); swapContent(src, _msg);
src->longmsg = _msg->longmsg;
_msg->longmsg = nullptr;
free(src->longmsg_formatted);
src->longmsg_formatted = _msg->longmsg_formatted;
_msg->longmsg_formatted = nullptr;
free_bloblist(src->attachments);
src->attachments = _msg->attachments;
_msg->attachments = nullptr;
::message *_dst = nullptr; ::message *_dst = nullptr;
PEP_STATUS status = ::encrypt_message(session, src, extra, &_dst, PEP_STATUS status = ::encrypt_message(session, src, extra, &_dst,
enc_format, flags); enc_format, flags);
_msg->longmsg = src->longmsg; swapContent(_msg, src);
src->longmsg = nullptr;
_msg->longmsg_formatted = src->longmsg_formatted;
src->longmsg_formatted = nullptr;
_msg->attachments = src->attachments;
src->attachments = nullptr;
*dst = empty_message_copy(_dst); *dst = empty_message_copy(_dst);

Loading…
Cancel
Save