From 5faebe885201d2662f78caca20371c71dfa9540a Mon Sep 17 00:00:00 2001 From: Volker Birk Date: Wed, 3 Aug 2016 23:59:10 +0200 Subject: [PATCH] constructors and destructor for Blob --- src/Identity.hh | 16 ++++++++-------- src/message.cc | 30 +++++++++++++++++++++++++++--- src/message.hh | 34 ++++++++++++++++++++++++++++------ 3 files changed, 63 insertions(+), 17 deletions(-) diff --git a/src/Identity.hh b/src/Identity.hh index 50f1ed1..5c15414 100644 --- a/src/Identity.hh +++ b/src/Identity.hh @@ -20,29 +20,29 @@ namespace pEp { void attach(pEp_identity *ident); pEp_identity *detach(); - void address(string value) { str_attr(_ident->address, value); } string address() { return str_attr(_ident->address); } + void address(string value) { str_attr(_ident->address, value); } - void fpr(string value) { str_attr(_ident->fpr, value); } string fpr() { return str_attr(_ident->fpr); } + void fpr(string value) { str_attr(_ident->fpr, value); } - void user_id(string value) { str_attr(_ident->user_id, value); } string user_id() { return str_attr(_ident->user_id); } + void user_id(string value) { str_attr(_ident->user_id, value); } - void username(string value) { str_attr(_ident->username, value); } string username() { return str_attr(_ident->username); } + void username(string value) { str_attr(_ident->username, value); } - void comm_type(PEP_comm_type value) { _ident->comm_type = value; }; PEP_comm_type comm_type() { return _ident->comm_type; } + void comm_type(PEP_comm_type value) { _ident->comm_type = value; }; - void lang(std::string value); std::string lang(); + void lang(std::string value); - void me(bool value) { _ident->me = value; } bool me() { return _ident->me; } + void me(bool value) { _ident->me = value; } - void flags(identity_flags_t flags) { _ident->flags = flags; } identity_flags_t flags() { return _ident->flags; } + void flags(identity_flags_t flags) { _ident->flags = flags; } }; } } diff --git a/src/message.cc b/src/message.cc index 8ef421f..a655d2f 100644 --- a/src/message.cc +++ b/src/message.cc @@ -1,11 +1,35 @@ #include "message.hh" +#include namespace pEp { namespace PythonAdapter { using namespace std; - Message::Message() - : _msg(new_message(NULL, NULL, NULL, NULL)) + Message::Blob::Blob(char *value, size_t size, string mime_type, + string filename) : _value(value), _size(size), + _mime_type(mime_type), _filename(filename) + { + + } + + Message::Blob::Blob(const Blob& second) + { + _size = second._size; + _value = (char *) malloc(_size); + if (!_value) + throw bad_alloc(); + memcpy(_value, second._value, _size); + _mime_type = second._mime_type; + _filename = second._filename; + } + + Message::Blob::~Blob() + { + free(_value); + } + + Message::Message(PEP_msg_direction dir) + : _msg(new_message(dir)) { if (!_msg) throw bad_alloc(); @@ -37,7 +61,7 @@ namespace pEp { message *Message::detach() { - message *new_one = new_message(NULL, NULL, NULL, NULL); + message *new_one = new_message(_msg->dir); if (!new_one) throw bad_alloc(); diff --git a/src/message.hh b/src/message.hh index ab37738..a6567c0 100644 --- a/src/message.hh +++ b/src/message.hh @@ -2,6 +2,7 @@ #include #include +#include #include "str_attr.hh" namespace pEp { @@ -9,10 +10,23 @@ namespace pEp { using namespace utility; class Message { + class Blob { + char *_value; + size_t _size; + string _mime_type; + string _filename; + + public: + Blob(char *value = NULL, size_t size = 0, string mime_type = "", + string filename = ""); + Blob(const Blob& second); + ~Blob(); + }; + message *_msg; public: - Message(); + Message(PEP_msg_direction dir = PEP_dir_outgoing); Message(const Message& second); Message(message *ident); ~Message(); @@ -20,12 +34,20 @@ namespace pEp { void attach(message *ident); message *detach(); - PEP_msg_direction dir; - char *id; - char *shortmsg; - char *longmsg; + PEP_msg_direction dir() { return _msg->dir; } + void dir(PEP_msg_direction value) { _msg->dir = value; } + + string id() { return str_attr(_msg->id); } + void id(string value) { str_attr(_msg->id, value); } + + string shortmsg() { return str_attr(_msg->shortmsg); } + void shortmsg(string value) { str_attr(_msg->shortmsg, value); } + + string longmsg() { return str_attr(_msg->longmsg); } + void longmsg(string value) { str_attr(_msg->longmsg, value); } - char *longmsg_formatted; + string longmsg_formatted() { return str_attr(_msg->longmsg_formatted); } + void longmsg_formatted(string value) { str_attr(_msg->longmsg_formatted, value); } bloblist_t *attachments; char *rawmsg_ref;