From 0527e7acc343a742141481f623a2c4dffe371444 Mon Sep 17 00:00:00 2001 From: Volker Birk Date: Thu, 4 Aug 2016 00:10:26 +0200 Subject: [PATCH] Blob::attach() and Blob::detach() --- src/message.cc | 32 ++++++++++++++++++++++++++++++++ src/message.hh | 2 ++ 2 files changed, 34 insertions(+) diff --git a/src/message.cc b/src/message.cc index a655d2f..1d72441 100644 --- a/src/message.cc +++ b/src/message.cc @@ -28,6 +28,38 @@ namespace pEp { free(_value); } + void Message::Blob::attach(bloblist_t *blob) + { + free(_value); + _size = blob->size; + _value = blob->value; + blob->size = 0; + blob->value = NULL; + if (blob->mime_type) { + _mime_type = blob->mime_type; + free(blob->mime_type); + blob->mime_type = NULL; + } + if (blob->filename) { + _filename = blob->filename; + free(blob->filename); + blob->filename = NULL; + } + } + + bloblist_t * Message::Blob::detach() + { + bloblist_t *bl = new_bloblist(_value, _size, _mime_type.c_str(), + _filename.c_str()); + if (!bl) + throw bad_alloc(); + _size = 0; + _value = NULL; + _mime_type = ""; + _filename = ""; + return bl; + } + Message::Message(PEP_msg_direction dir) : _msg(new_message(dir)) { diff --git a/src/message.hh b/src/message.hh index a6567c0..a13e300 100644 --- a/src/message.hh +++ b/src/message.hh @@ -21,6 +21,8 @@ namespace pEp { string filename = ""); Blob(const Blob& second); ~Blob(); + void attach(bloblist_t *blob); + bloblist_t *detach(); }; message *_msg;