Browse Source

constructors and destructor for Blob

AllGroupDevicesShowHandshake
Volker Birk 6 years ago
parent
commit
5faebe8852
3 changed files with 63 additions and 17 deletions
  1. +8
    -8
      src/Identity.hh
  2. +27
    -3
      src/message.cc
  3. +28
    -6
      src/message.hh

+ 8
- 8
src/Identity.hh View File

@ -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; }
};
}
}


+ 27
- 3
src/message.cc View File

@ -1,11 +1,35 @@
#include "message.hh"
#include <stdlib.h>
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();


+ 28
- 6
src/message.hh View File

@ -2,6 +2,7 @@
#include <pEp/message.h>
#include <string>
#include <list>
#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;


Loading…
Cancel
Save