Merge pull request #1640 from G10h4ck/rsmsg_jsonapi

Provide usable API to send RS mails
This commit is contained in:
G10h4ck 2019-10-26 15:51:17 +02:00 committed by GitHub
commit d46e3eb2b7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 499 additions and 195 deletions

View File

@ -165,6 +165,8 @@ public:
virtual bool getKey(const RsGxsId &id, RsTlvPublicRSAKey& key) = 0; virtual bool getKey(const RsGxsId &id, RsTlvPublicRSAKey& key) = 0;
virtual bool getPrivateKey(const RsGxsId &id, RsTlvPrivateRSAKey& key) = 0; // For signing outgoing messages. virtual bool getPrivateKey(const RsGxsId &id, RsTlvPrivateRSAKey& key) = 0; // For signing outgoing messages.
virtual bool getIdDetails(const RsGxsId& id, RsIdentityDetails& details) = 0 ; // Proxy function so that we get p3Identity info from Gxs virtual bool getIdDetails(const RsGxsId& id, RsIdentityDetails& details) = 0 ; // Proxy function so that we get p3Identity info from Gxs
virtual ~RsGixs();
}; };
class GixsReputation class GixsReputation

View File

@ -66,6 +66,9 @@ enum class RsEventType : uint32_t
/// Emitted when a peer state changes, @see RsPeers /// Emitted when a peer state changes, @see RsPeers
PEER_STATE_CHANGED = 6, PEER_STATE_CHANGED = 6,
/// @see RsMailStatusEvent
MAIL_STATUS_CHANGE = 7,
MAX /// Used to detect invalid event type passed MAX /// Used to detect invalid event type passed
}; };

View File

@ -47,7 +47,7 @@ extern RsGxsChannels* rsGxsChannels;
struct RsGxsChannelGroup : RsSerializable struct RsGxsChannelGroup : RsSerializable
{ {
RsGxsChannelGroup() : mAutoDownload(false) {} RsGxsChannelGroup() : mAutoDownload(false) {}
RsGroupMetaData mMeta; RsGroupMetaData mMeta;
std::string mDescription; std::string mDescription;
@ -56,14 +56,17 @@ struct RsGxsChannelGroup : RsSerializable
bool mAutoDownload; bool mAutoDownload;
/// @see RsSerializable /// @see RsSerializable
virtual void serial_process( RsGenericSerializer::SerializeJob j, virtual void serial_process(
RsGenericSerializer::SerializeContext& ctx ) RsGenericSerializer::SerializeJob j,
RsGenericSerializer::SerializeContext& ctx ) override
{ {
RS_SERIAL_PROCESS(mMeta); RS_SERIAL_PROCESS(mMeta);
RS_SERIAL_PROCESS(mDescription); RS_SERIAL_PROCESS(mDescription);
RS_SERIAL_PROCESS(mImage); RS_SERIAL_PROCESS(mImage);
RS_SERIAL_PROCESS(mAutoDownload); RS_SERIAL_PROCESS(mAutoDownload);
} }
~RsGxsChannelGroup() override;
}; };
struct RsGxsChannelPost : RsSerializable struct RsGxsChannelPost : RsSerializable
@ -82,8 +85,9 @@ struct RsGxsChannelPost : RsSerializable
RsGxsImage mThumbnail; RsGxsImage mThumbnail;
/// @see RsSerializable /// @see RsSerializable
virtual void serial_process( RsGenericSerializer::SerializeJob j, virtual void serial_process(
RsGenericSerializer::SerializeContext& ctx ) RsGenericSerializer::SerializeJob j,
RsGenericSerializer::SerializeContext& ctx ) override
{ {
RS_SERIAL_PROCESS(mMeta); RS_SERIAL_PROCESS(mMeta);
RS_SERIAL_PROCESS(mOlderVersions); RS_SERIAL_PROCESS(mOlderVersions);
@ -94,6 +98,8 @@ struct RsGxsChannelPost : RsSerializable
RS_SERIAL_PROCESS(mSize); RS_SERIAL_PROCESS(mSize);
RS_SERIAL_PROCESS(mThumbnail); RS_SERIAL_PROCESS(mThumbnail);
} }
~RsGxsChannelPost() override;
}; };
@ -544,5 +550,5 @@ public:
virtual bool retrieveDistantGroup(const RsGxsGroupId& group_id,RsGxsChannelGroup& distant_group)=0; virtual bool retrieveDistantGroup(const RsGxsGroupId& group_id,RsGxsChannelGroup& distant_group)=0;
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
virtual ~RsGxsChannels(); ~RsGxsChannels() override;
}; };

View File

@ -338,7 +338,7 @@ struct RsIdentityDetails : RsSerializable
RS_SERIAL_PROCESS(mNickname); RS_SERIAL_PROCESS(mNickname);
RS_SERIAL_PROCESS(mFlags); RS_SERIAL_PROCESS(mFlags);
RS_SERIAL_PROCESS(mPgpId); RS_SERIAL_PROCESS(mPgpId);
//RS_SERIAL_PROCESS(mReputation); RS_SERIAL_PROCESS(mReputation);
RS_SERIAL_PROCESS(mAvatar); RS_SERIAL_PROCESS(mAvatar);
RS_SERIAL_PROCESS(mPublishTS); RS_SERIAL_PROCESS(mPublishTS);
RS_SERIAL_PROCESS(mLastUsageTS); RS_SERIAL_PROCESS(mLastUsageTS);
@ -352,7 +352,6 @@ struct RsIdentityDetails : RsSerializable
struct RsIdentity : RsGxsIfaceHelper struct RsIdentity : RsGxsIfaceHelper
{ {
explicit RsIdentity(RsGxsIface& gxs) : RsGxsIfaceHelper(gxs) {} explicit RsIdentity(RsGxsIface& gxs) : RsGxsIfaceHelper(gxs) {}
virtual ~RsIdentity() {}
/** /**
* @brief Create a new identity * @brief Create a new identity
@ -419,6 +418,14 @@ struct RsIdentity : RsGxsIfaceHelper
*/ */
virtual bool getOwnPseudonimousIds(std::vector<RsGxsId>& ids) = 0; virtual bool getOwnPseudonimousIds(std::vector<RsGxsId>& ids) = 0;
/**
* @brief Check if an id is known
* @jsonapi{development}
* @param[in] id Id to check
* @return true if the id is known, false otherwise
*/
virtual bool isKnownId(const RsGxsId& id) = 0;
/** /**
* @brief Check if an id is own * @brief Check if an id is own
* @jsonapi{development} * @jsonapi{development}
@ -568,4 +575,6 @@ struct RsIdentity : RsGxsIfaceHelper
RS_DEPRECATED_FOR("getIdentitiesSummaries getIdentitiesInfo") RS_DEPRECATED_FOR("getIdentitiesSummaries getIdentitiesInfo")
virtual bool getGroupData( const uint32_t& token, virtual bool getGroupData( const uint32_t& token,
std::vector<RsGxsIdGroup>& groups) = 0; std::vector<RsGxsIdGroup>& groups) = 0;
virtual ~RsIdentity();
}; };

View File

@ -3,7 +3,8 @@
* * * *
* libretroshare: retroshare core library * * libretroshare: retroshare core library *
* * * *
* Copyright 2007-2008 by Robert Fernie <retroshare@lunamutt.com> * * Copyright (C) 2007-2008 Robert Fernie <retroshare@lunamutt.com> *
* Copyright (C) 2016-2019 Gioacchino Mazzurco <gio@eigenlab.org> *
* * * *
* This program is free software: you can redistribute it and/or modify * * This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as * * it under the terms of the GNU Lesser General Public License as *
@ -19,8 +20,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * * along with this program. If not, see <https://www.gnu.org/licenses/>. *
* * * *
*******************************************************************************/ *******************************************************************************/
#ifndef RS_MSG_GUI_INTERFACE_H #pragma once
#define RS_MSG_GUI_INTERFACE_H
#include <list> #include <list>
#include <iostream> #include <iostream>
@ -28,8 +28,11 @@
#include <set> #include <set>
#include <assert.h> #include <assert.h>
#include "rstypes.h" #include "retroshare/rstypes.h"
#include "rsgxsifacetypes.h" #include "retroshare/rsgxsifacetypes.h"
#include "retroshare/rsevents.h"
#include "util/rsdeprecate.h"
#include "util/rsmemory.h"
/********************** For Messages and Channels *****************/ /********************** For Messages and Channels *****************/
@ -93,9 +96,31 @@ const ChatLobbyFlags RS_CHAT_LOBBY_FLAGS_PGP_SIGNED ( 0x00000010 ) ; // requi
typedef uint64_t ChatLobbyId ; typedef uint64_t ChatLobbyId ;
typedef uint64_t ChatLobbyMsgId ; typedef uint64_t ChatLobbyMsgId ;
typedef std::string ChatLobbyNickName ; typedef std::string ChatLobbyNickName ;
typedef std::string RsMailMessageId; // should be uint32_t !! typedef std::string RsMailMessageId; // TODO: rebase on t_RsGenericIdType
typedef uint64_t MessageId ;
/**
* Used to return a tracker id so the API user can keep track of sent mail
* status, it contains mail id, and recipient id
*/
struct RsMailIdRecipientIdPair : RsSerializable
{
RsMailIdRecipientIdPair(RsMailMessageId mailId, RsGxsId recipientId):
mMailId(mailId), mRecipientId(recipientId) {}
RsMailMessageId mMailId;
RsGxsId mRecipientId;
/// @see RsSerializable
void serial_process(
RsGenericSerializer::SerializeJob j,
RsGenericSerializer::SerializeContext &ctx ) override;
bool operator<(const RsMailIdRecipientIdPair& other) const;
bool operator==(const RsMailIdRecipientIdPair& other) const;
RsMailIdRecipientIdPair() = default;
~RsMailIdRecipientIdPair() override = default;
};
namespace Rs namespace Rs
{ {
@ -137,38 +162,9 @@ class MsgAddress
std::string _addr_string ; std::string _addr_string ;
}; };
class MessageInfo_v2
{
public:
//MessageInfo_v2() {}
unsigned int msgflags;
//RsMessageId msgId;
MsgAddress from ;
std::list<MsgAddress> rcpt ;
// Headers
//
std::string subject;
std::string msg;
rstime_t time_stamp ;
//std::list<MessageHeader> headers ;
std::string attach_title;
std::string attach_comment;
std::list<FileInfo> files;
int size; /* total of files */
int count; /* file count */
};
struct MessageInfo : RsSerializable struct MessageInfo : RsSerializable
{ {
MessageInfo(): msgflags(0), size(0), count(0), ts(0) {} MessageInfo(): msgflags(0), size(0), count(0), ts(0) {}
virtual ~MessageInfo() = default;
std::string msgId; std::string msgId;
@ -202,7 +198,10 @@ struct MessageInfo : RsSerializable
int ts; int ts;
// RsSerializable interface // RsSerializable interface
void serial_process(RsGenericSerializer::SerializeJob j, RsGenericSerializer::SerializeContext &ctx) { void serial_process(
RsGenericSerializer::SerializeJob j,
RsGenericSerializer::SerializeContext &ctx ) override
{
RS_SERIAL_PROCESS(msgId); RS_SERIAL_PROCESS(msgId);
RS_SERIAL_PROCESS(rspeerid_srcId); RS_SERIAL_PROCESS(rspeerid_srcId);
@ -230,26 +229,30 @@ struct MessageInfo : RsSerializable
RS_SERIAL_PROCESS(ts); RS_SERIAL_PROCESS(ts);
} }
~MessageInfo() override;
}; };
struct MsgInfoSummary : RsSerializable struct MsgInfoSummary : RsSerializable
{ {
MsgInfoSummary() : msgflags(0), count(0), ts(0) {} MsgInfoSummary() : msgflags(0), count(0), ts(0) {}
virtual ~MsgInfoSummary() = default;
RsMailMessageId msgId; RsMailMessageId msgId;
RsPeerId srcId; RsPeerId srcId;
uint32_t msgflags; uint32_t msgflags;
std::list<uint32_t> msgtags; // that leaves 25 bits for user-defined tags. std::list<uint32_t> msgtags; /// that leaves 25 bits for user-defined tags.
std::string title; std::string title;
int count; /* file count */ int count; /** file count */
rstime_t ts; rstime_t ts;
// RsSerializable interface /// @see RsSerializable
void serial_process(RsGenericSerializer::SerializeJob j, RsGenericSerializer::SerializeContext &ctx) { void serial_process(
RsGenericSerializer::SerializeJob j,
RsGenericSerializer::SerializeContext &ctx) override
{
RS_SERIAL_PROCESS(msgId); RS_SERIAL_PROCESS(msgId);
RS_SERIAL_PROCESS(srcId); RS_SERIAL_PROCESS(srcId);
@ -260,6 +263,8 @@ struct MsgInfoSummary : RsSerializable
RS_SERIAL_PROCESS(count); RS_SERIAL_PROCESS(count);
RS_SERIAL_PROCESS(ts); RS_SERIAL_PROCESS(ts);
} }
~MsgInfoSummary() override;
}; };
struct MsgTagInfo : RsSerializable struct MsgTagInfo : RsSerializable
@ -291,6 +296,22 @@ struct MsgTagType : RsSerializable
} //namespace Rs } //namespace Rs
} //namespace Msgs } //namespace Msgs
struct RsMailStatusEvent : RsEvent
{
RsMailStatusEvent() : RsEvent(RsEventType::MAIL_STATUS_CHANGE) {}
std::set<RsMailMessageId> mChangedMsgIds;
/// @see RsEvent
void serial_process( RsGenericSerializer::SerializeJob j,
RsGenericSerializer::SerializeContext& ctx) override
{
RsEvent::serial_process(j, ctx);
RS_SERIAL_PROCESS(mChangedMsgIds);
}
~RsMailStatusEvent() override;
};
#define RS_CHAT_PUBLIC 0x0001 #define RS_CHAT_PUBLIC 0x0001
#define RS_CHAT_PRIVATE 0x0002 #define RS_CHAT_PRIVATE 0x0002
@ -426,11 +447,10 @@ public:
} }
}; };
class VisibleChatLobbyRecord : RsSerializable struct VisibleChatLobbyRecord : RsSerializable
{ {
public: VisibleChatLobbyRecord():
VisibleChatLobbyRecord(): lobby_id(0), total_number_of_peers(0), last_report_time(0){} lobby_id(0), total_number_of_peers(0), last_report_time(0) {}
virtual ~VisibleChatLobbyRecord() = default;
ChatLobbyId lobby_id ; // unique id of the lobby ChatLobbyId lobby_id ; // unique id of the lobby
std::string lobby_name ; // name to use for this lobby std::string lobby_name ; // name to use for this lobby
@ -441,9 +461,11 @@ public:
rstime_t last_report_time ; // last time the lobby was reported. rstime_t last_report_time ; // last time the lobby was reported.
ChatLobbyFlags lobby_flags ; // see RS_CHAT_LOBBY_PRIVACY_LEVEL_PUBLIC / RS_CHAT_LOBBY_PRIVACY_LEVEL_PRIVATE ChatLobbyFlags lobby_flags ; // see RS_CHAT_LOBBY_PRIVACY_LEVEL_PUBLIC / RS_CHAT_LOBBY_PRIVACY_LEVEL_PRIVATE
// RsSerializable interface /// @see RsSerializable
public: void serial_process(
void serial_process(RsGenericSerializer::SerializeJob j, RsGenericSerializer::SerializeContext &ctx) { RsGenericSerializer::SerializeJob j,
RsGenericSerializer::SerializeContext &ctx) override
{
RS_SERIAL_PROCESS(lobby_id); RS_SERIAL_PROCESS(lobby_id);
RS_SERIAL_PROCESS(lobby_name); RS_SERIAL_PROCESS(lobby_name);
RS_SERIAL_PROCESS(lobby_topic); RS_SERIAL_PROCESS(lobby_topic);
@ -453,6 +475,8 @@ public:
RS_SERIAL_PROCESS(last_report_time); RS_SERIAL_PROCESS(last_report_time);
RS_SERIAL_PROCESS(lobby_flags); RS_SERIAL_PROCESS(lobby_flags);
} }
~VisibleChatLobbyRecord() override;
}; };
class ChatLobbyInfo : RsSerializable class ChatLobbyInfo : RsSerializable
@ -499,13 +523,6 @@ class RsMsgs
{ {
public: public:
RsMsgs() {}
virtual ~RsMsgs() = default;
/****************************************/
/* Message Items */
/****************************************/
/** /**
* @brief getMessageSummaries * @brief getMessageSummaries
* @jsonapi{development} * @jsonapi{development}
@ -523,6 +540,33 @@ public:
*/ */
virtual bool getMessage(const std::string &msgId, Rs::Msgs::MessageInfo &msg) = 0; virtual bool getMessage(const std::string &msgId, Rs::Msgs::MessageInfo &msg) = 0;
/**
* @brief sendMail
* @jsonapi{development}
* @param[in] from GXS id of the author
* @param[in] subject Mail subject
* @param[in] mailBody Mail body
* @param[in] to list of To: recipients
* @param[in] cc list of CC: recipients
* @param[in] bcc list of BCC: recipients
* @param[in] attachments list of suggested files
* @param[out] trackingIds storage for tracking ids for each sent mail
* @param[out] errorMsg error message if errors occurred, empty otherwise
* @return number of successfully sent mails
*/
virtual uint32_t sendMail(
const RsGxsId from,
const std::string& subject,
const std::string& mailBody,
const std::set<RsGxsId>& to = std::set<RsGxsId>(),
const std::set<RsGxsId>& cc = std::set<RsGxsId>(),
const std::set<RsGxsId>& bcc = std::set<RsGxsId>(),
const std::vector<FileInfo>& attachments = std::vector<FileInfo>(),
std::set<RsMailIdRecipientIdPair>& trackingIds =
RS_DEFAULT_STORAGE_PARAM(std::set<RsMailIdRecipientIdPair>),
std::string& errorMsg =
RS_DEFAULT_STORAGE_PARAM(std::string) ) = 0;
/** /**
* @brief getMessageCount * @brief getMessageCount
* @jsonapi{development} * @jsonapi{development}
@ -535,14 +579,6 @@ public:
*/ */
virtual void getMessageCount(uint32_t &nInbox, uint32_t &nInboxNew, uint32_t &nOutbox, uint32_t &nDraftbox, uint32_t &nSentbox, uint32_t &nTrashbox) = 0; virtual void getMessageCount(uint32_t &nInbox, uint32_t &nInboxNew, uint32_t &nOutbox, uint32_t &nDraftbox, uint32_t &nSentbox, uint32_t &nTrashbox) = 0;
/**
* @brief MessageSend
* @jsonapi{development}
* @param[in] info
* @return always true
*/
virtual bool MessageSend(Rs::Msgs::MessageInfo &info) = 0;
/** /**
* @brief SystemMessage * @brief SystemMessage
* @jsonapi{development} * @jsonapi{development}
@ -916,7 +952,14 @@ virtual bool initiateDistantChatConnexion(
virtual bool getDistantChatStatus(const DistantChatPeerId& pid,DistantChatPeerInfo& info)=0; virtual bool getDistantChatStatus(const DistantChatPeerId& pid,DistantChatPeerInfo& info)=0;
virtual bool closeDistantChatConnexion(const DistantChatPeerId& pid)=0; virtual bool closeDistantChatConnexion(const DistantChatPeerId& pid)=0;
/**
* @brief MessageSend
* @jsonapi{development}
* @param[in] info
* @return always true
*/
RS_DEPRECATED_FOR(sendMail)
virtual bool MessageSend(Rs::Msgs::MessageInfo &info) = 0;
virtual ~RsMsgs();
}; };
#endif

View File

@ -72,7 +72,6 @@ struct RsReputationInfo : RsSerializable
mFriendsNegativeVotes(0), mFriendsNegativeVotes(0),
mFriendAverageScore(RS_REPUTATION_THRESHOLD_DEFAULT), mFriendAverageScore(RS_REPUTATION_THRESHOLD_DEFAULT),
mOverallReputationLevel(RsReputationLevel::NEUTRAL) {} mOverallReputationLevel(RsReputationLevel::NEUTRAL) {}
virtual ~RsReputationInfo() {}
RsOpinion mOwnOpinion; RsOpinion mOwnOpinion;
@ -94,6 +93,8 @@ struct RsReputationInfo : RsSerializable
RS_SERIAL_PROCESS(mFriendAverageScore); RS_SERIAL_PROCESS(mFriendAverageScore);
RS_SERIAL_PROCESS(mOverallReputationLevel); RS_SERIAL_PROCESS(mOverallReputationLevel);
} }
virtual ~RsReputationInfo();
}; };

View File

@ -399,11 +399,20 @@ struct FileChunksInfo : RsSerializable
CHUNK_STRATEGY_PROGRESSIVE CHUNK_STRATEGY_PROGRESSIVE
}; };
struct SliceInfo struct SliceInfo : RsSerializable
{ {
uint32_t start; uint32_t start;
uint32_t size; uint32_t size;
RsPeerId peer_id; RsPeerId peer_id;
/// @see RsSerializable
void serial_process(RsGenericSerializer::SerializeJob j,
RsGenericSerializer::SerializeContext& ctx) override
{
RS_SERIAL_PROCESS(start);
RS_SERIAL_PROCESS(size);
RS_SERIAL_PROCESS(peer_id);
}
}; };
uint64_t file_size; /// real size of the file uint64_t file_size; /// real size of the file
@ -432,7 +441,7 @@ struct FileChunksInfo : RsSerializable
RS_SERIAL_PROCESS(chunks); RS_SERIAL_PROCESS(chunks);
RS_SERIAL_PROCESS(compressed_peer_availability_maps); RS_SERIAL_PROCESS(compressed_peer_availability_maps);
RS_SERIAL_PROCESS(active_chunks); RS_SERIAL_PROCESS(active_chunks);
//RS_SERIAL_PROCESS(pending_slices); RS_SERIAL_PROCESS(pending_slices);
} }
}; };

View File

@ -3,7 +3,8 @@
* * * *
* libretroshare: retroshare core library * * libretroshare: retroshare core library *
* * * *
* Copyright 2004-2006 by Robert Fernie <retroshare@lunamutt.com> * * Copyright (C) 2004-2006 Robert Fernie <retroshare@lunamutt.com> *
* Copyright (C) 2016-2019 Gioacchino Mazzurco <gio@eigenlab.org> *
* * * *
* This program is free software: you can redistribute it and/or modify * * This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as * * it under the terms of the GNU Lesser General Public License as *
@ -20,6 +21,7 @@
* * * *
*******************************************************************************/ *******************************************************************************/
#include <iostream> #include <iostream>
#include <tuple>
#include "util/rsdir.h" #include "util/rsdir.h"
#include "util/rsdebug.h" #include "util/rsdebug.h"
@ -38,8 +40,7 @@
using namespace Rs::Msgs; using namespace Rs::Msgs;
/* external reference point */ /*extern*/ RsMsgs* rsMsgs = nullptr;
RsMsgs *rsMsgs = NULL;
/****************************************/ /****************************************/
/****************************************/ /****************************************/
@ -300,6 +301,22 @@ bool p3Msgs::MessageSend(MessageInfo &info)
return mMsgSrv->MessageSend(info); return mMsgSrv->MessageSend(info);
} }
uint32_t p3Msgs::sendMail(
const RsGxsId from,
const std::string& subject,
const std::string& body,
const std::set<RsGxsId>& to,
const std::set<RsGxsId>& cc,
const std::set<RsGxsId>& bcc,
const std::vector<FileInfo>& attachments,
std::set<RsMailIdRecipientIdPair>& trackingIds,
std::string& errorMsg )
{
return mMsgSrv->sendMail(
from, subject, body, to, cc, bcc, attachments,
trackingIds, errorMsg );
}
bool p3Msgs::SystemMessage(const std::string &title, const std::string &message, uint32_t systemFlag) bool p3Msgs::SystemMessage(const std::string &title, const std::string &message, uint32_t systemFlag)
{ {
return mMsgSrv->SystemMessage(title, message, systemFlag); return mMsgSrv->SystemMessage(title, message, systemFlag);
@ -541,3 +558,28 @@ uint32_t p3Msgs::getDistantChatPermissionFlags()
return mChatSrv->getDistantChatPermissionFlags() ; return mChatSrv->getDistantChatPermissionFlags() ;
} }
RsMsgs::~RsMsgs() = default;
RsMailStatusEvent::~RsMailStatusEvent() = default;
Rs::Msgs::MessageInfo::~MessageInfo() = default;
MsgInfoSummary::~MsgInfoSummary() = default;
VisibleChatLobbyRecord::~VisibleChatLobbyRecord() = default;
void RsMailIdRecipientIdPair::serial_process(
RsGenericSerializer::SerializeJob j,
RsGenericSerializer::SerializeContext& ctx )
{
RS_SERIAL_PROCESS(mMailId);
RS_SERIAL_PROCESS(mRecipientId);
}
bool RsMailIdRecipientIdPair::operator<(const RsMailIdRecipientIdPair& o) const
{
return std::tie( mMailId, mRecipientId) <
std::tie(o.mMailId, o.mRecipientId);
}
bool RsMailIdRecipientIdPair::operator==(const RsMailIdRecipientIdPair& o) const
{
return std::tie( mMailId, mRecipientId) ==
std::tie(o.mMailId, o.mRecipientId);
}

View File

@ -3,7 +3,8 @@
* * * *
* libretroshare: retroshare core library * * libretroshare: retroshare core library *
* * * *
* Copyright 2007-2008 by Robert Fernie <retroshare@lunamutt.com> * * Copyright (C) 2007-2008 Robert Fernie <retroshare@lunamutt.com> *
* Copyright (C) 2016-2019 Gioacchino Mazzurco <gio@eigenlab.org> *
* * * *
* This program is free software: you can redistribute it and/or modify * * This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as * * it under the terms of the GNU Lesser General Public License as *
@ -19,8 +20,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * * along with this program. If not, see <https://www.gnu.org/licenses/>. *
* * * *
*******************************************************************************/ *******************************************************************************/
#ifndef RS_P3MSG_INTERFACE_H #pragma once
#define RS_P3MSG_INTERFACE_H
#include "retroshare/rsmsgs.h" #include "retroshare/rsmsgs.h"
#include "retroshare/rsgxsifacetypes.h" #include "retroshare/rsgxsifacetypes.h"
@ -38,11 +38,25 @@ class RsChatMsgItem;
*/ */
class p3Msgs: public RsMsgs class p3Msgs: public RsMsgs
{ {
public: public:
p3Msgs(p3MsgService *p3m, p3ChatService *p3c) p3Msgs(p3MsgService *p3m, p3ChatService *p3c) :
:mMsgSrv(p3m), mChatSrv(p3c) { return; } mMsgSrv(p3m), mChatSrv(p3c) {}
virtual ~p3Msgs() { return; } ~p3Msgs() override = default;
/// @see RsMsgs
uint32_t sendMail(
const RsGxsId from,
const std::string& subject,
const std::string& body,
const std::set<RsGxsId>& to = std::set<RsGxsId>(),
const std::set<RsGxsId>& cc = std::set<RsGxsId>(),
const std::set<RsGxsId>& bcc = std::set<RsGxsId>(),
const std::vector<FileInfo>& attachments = std::vector<FileInfo>(),
std::set<RsMailIdRecipientIdPair>& trackingIds =
RS_DEFAULT_STORAGE_PARAM(std::set<RsMailIdRecipientIdPair>),
std::string& errorMsg =
RS_DEFAULT_STORAGE_PARAM(std::string) ) override;
/****************************************/ /****************************************/
/* Message Items */ /* Message Items */
@ -54,6 +68,7 @@ class p3Msgs: public RsMsgs
virtual bool getMessage(const std::string &mId, Rs::Msgs::MessageInfo &msg); virtual bool getMessage(const std::string &mId, Rs::Msgs::MessageInfo &msg);
virtual void getMessageCount(uint32_t &nInbox, uint32_t &nInboxNew, uint32_t &nOutbox, uint32_t &nDraftbox, uint32_t &nSentbox, uint32_t &nTrashbox); virtual void getMessageCount(uint32_t &nInbox, uint32_t &nInboxNew, uint32_t &nOutbox, uint32_t &nDraftbox, uint32_t &nSentbox, uint32_t &nTrashbox);
RS_DEPRECATED_FOR(sendMail)
virtual bool MessageSend(Rs::Msgs::MessageInfo &info); virtual bool MessageSend(Rs::Msgs::MessageInfo &info);
virtual bool SystemMessage(const std::string &title, const std::string &message, uint32_t systemFlag); virtual bool SystemMessage(const std::string &title, const std::string &message, uint32_t systemFlag);
virtual bool MessageToDraft(Rs::Msgs::MessageInfo &info, const std::string &msgParentId); virtual bool MessageToDraft(Rs::Msgs::MessageInfo &info, const std::string &msgParentId);
@ -172,6 +187,3 @@ class p3Msgs: public RsMsgs
p3MsgService *mMsgSrv; p3MsgService *mMsgSrv;
p3ChatService *mChatSrv; p3ChatService *mChatSrv;
}; };
#endif

View File

@ -2466,4 +2466,6 @@ void p3GxsChannels::cleanTimedOutCallbacks()
} // RS_STACK_MUTEX(mDistantChannelsCallbacksMapMutex) } // RS_STACK_MUTEX(mDistantChannelsCallbacksMapMutex)
} }
RsGxsChannelGroup::~RsGxsChannelGroup() = default;
RsGxsChannelPost::~RsGxsChannelPost() = default;
RsGxsChannels::~RsGxsChannels() = default; RsGxsChannels::~RsGxsChannels() = default;

View File

@ -810,9 +810,15 @@ bool p3IdService::getOwnIds(std::list<RsGxsId> &ownIds,bool signed_only)
return true ; return true ;
} }
bool p3IdService::isKnownId(const RsGxsId& id)
{
RS_STACK_MUTEX(mIdMtx);
return mKeyCache.is_cached(id) ||
std::find(mOwnIds.begin(), mOwnIds.end(),id) != mOwnIds.end();
}
bool p3IdService::identityToBase64( const RsGxsId& id, bool p3IdService::identityToBase64( const RsGxsId& id,
std::string& base64String ) std::string& base64String )
{ return serialiseIdentityToMemory(id, base64String); } { return serialiseIdentityToMemory(id, base64String); }
bool p3IdService::serialiseIdentityToMemory( const RsGxsId& id, bool p3IdService::serialiseIdentityToMemory( const RsGxsId& id,
@ -4788,3 +4794,7 @@ RsIdentityUsage::RsIdentityUsage(
RsIdentityUsage::RsIdentityUsage() : RsIdentityUsage::RsIdentityUsage() :
mServiceId(RsServiceType::NONE), mUsageCode(UNKNOWN_USAGE), mAdditionalId(0) mServiceId(RsServiceType::NONE), mUsageCode(UNKNOWN_USAGE), mAdditionalId(0)
{} {}
RsIdentity::~RsIdentity() = default;
RsReputationInfo::~RsReputationInfo() = default;
RsGixs::~RsGixs() = default;

View File

@ -293,12 +293,12 @@ public:
/// @see RsIdentity /// @see RsIdentity
bool getOwnPseudonimousIds(std::vector<RsGxsId>& ids) override; bool getOwnPseudonimousIds(std::vector<RsGxsId>& ids) override;
virtual bool getOwnIds(std::list<RsGxsId> &ownIds, bool signed_only = false); bool getOwnIds(
std::list<RsGxsId> &ownIds, bool signed_only = false ) override;
//virtual bool getPublicKey(const RsGxsId &id, RsTlvSecurityKey &key) ; bool isKnownId(const RsGxsId& id) override;
//virtual void networkRequestPublicKey(const RsGxsId& key_id,const std::list<RsPeerId>& peer_ids) ;
virtual bool isOwnId(const RsGxsId& key_id) ; bool isOwnId(const RsGxsId& key_id) override;
virtual bool signData( const uint8_t* data, virtual bool signData( const uint8_t* data,
uint32_t data_size, uint32_t data_size,
@ -619,7 +619,7 @@ private:
bool ownIdsAreLoaded() { RS_STACK_MUTEX(mIdMtx); return mOwnIdsLoaded; } bool ownIdsAreLoaded() { RS_STACK_MUTEX(mIdMtx); return mOwnIdsLoaded; }
bool mAutoAddFriendsIdentitiesAsContacts; bool mAutoAddFriendsIdentitiesAsContacts;
uint32_t mMaxKeepKeysBanned ; uint32_t mMaxKeepKeysBanned;
RS_SET_CONTEXT_DEBUG_LEVEL(1) RS_SET_CONTEXT_DEBUG_LEVEL(1)
}; };

View File

@ -3,7 +3,8 @@
* * * *
* libretroshare: retroshare core library * * libretroshare: retroshare core library *
* * * *
* Copyright 2004-2008 Robert Fernie <retroshare@lunamutt.com> * * Copyright (C) 2004-2008 Robert Fernie <retroshare@lunamutt.com> *
* Copyright (C) 2016-2019 Gioacchino Mazzurco <gio@eigenlab.org> *
* * * *
* This program is free software: you can redistribute it and/or modify * * This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as * * it under the terms of the GNU Lesser General Public License as *
@ -55,19 +56,10 @@
#include <map> #include <map>
#include <sstream> #include <sstream>
//#define MSG_DEBUG 1
//#define DEBUG_DISTANT_MSG
//#define DISABLE_DISTANT_MESSAGES
//#define DEBUG_DISTANT_MSG
typedef unsigned int uint;
using namespace Rs::Msgs; using namespace Rs::Msgs;
static struct RsLog::logInfo msgservicezoneInfo = {RsLog::Default, "msgservice"}; /// keep msg hashes for 2 months to avoid re-sent msgs
#define msgservicezone &msgservicezoneInfo static constexpr uint32_t RS_MSG_DISTANT_MESSAGE_HASH_KEEP_TIME = 2*30*86400;
static const uint32_t RS_MSG_DISTANT_MESSAGE_HASH_KEEP_TIME = 2*30*86400 ; // keep msg hashes for 2 months to avoid re-sent msgs
/* Another little hack ..... unique message Ids /* Another little hack ..... unique message Ids
* will be handled in this class..... * will be handled in this class.....
@ -128,11 +120,8 @@ uint32_t p3MsgService::getNewUniqueMsgId()
return mMsgUniqueId++; return mMsgUniqueId++;
} }
int p3MsgService::tick() int p3MsgService::tick()
{ {
pqioutput(PQL_DEBUG_BASIC, msgservicezone,
"p3MsgService::tick()");
/* don't worry about increasing tick rate! /* don't worry about increasing tick rate!
* (handled by p3service) * (handled by p3service)
*/ */
@ -158,7 +147,7 @@ void p3MsgService::cleanListOfReceivedMessageHashes()
{ {
RS_STACK_MUTEX(recentlyReceivedMutex); RS_STACK_MUTEX(recentlyReceivedMutex);
rstime_t now = time(NULL); rstime_t now = time(nullptr);
for( auto it = mRecentlyReceivedMessageHashes.begin(); for( auto it = mRecentlyReceivedMessageHashes.begin();
it != mRecentlyReceivedMessageHashes.end(); ) it != mRecentlyReceivedMessageHashes.end(); )
@ -173,21 +162,13 @@ void p3MsgService::cleanListOfReceivedMessageHashes()
else ++it; else ++it;
} }
int p3MsgService::status()
{
pqioutput(PQL_DEBUG_BASIC, msgservicezone,
"p3MsgService::status()");
return 1;
}
void p3MsgService::processIncomingMsg(RsMsgItem *mi) void p3MsgService::processIncomingMsg(RsMsgItem *mi)
{ {
mi -> recvTime = time(NULL); mi -> recvTime = static_cast<uint32_t>(time(nullptr));
mi -> msgId = getNewUniqueMsgId(); mi -> msgId = getNewUniqueMsgId();
{ {
RsStackMutex stack(mMsgMtx); /*** STACK LOCKED MTX ***/ RS_STACK_MUTEX(mMsgMtx);
/* from a peer */ /* from a peer */
@ -226,6 +207,13 @@ void p3MsgService::processIncomingMsg(RsMsgItem *mi)
} }
RsServer::notify()->notifyListChange(NOTIFY_LIST_MESSAGELIST,NOTIFY_TYPE_ADD); RsServer::notify()->notifyListChange(NOTIFY_LIST_MESSAGELIST,NOTIFY_TYPE_ADD);
if(rsEvents)
{
std::shared_ptr<RsMailStatusEvent> pEvent(new RsMailStatusEvent());
pEvent->mChangedMsgIds.insert(std::to_string(mi->msgId));
rsEvents->postEvent(pEvent);
}
} }
bool p3MsgService::checkAndRebuildPartialMessage(RsMsgItem *ci) bool p3MsgService::checkAndRebuildPartialMessage(RsMsgItem *ci)
@ -289,7 +277,8 @@ void p3MsgService::handleIncomingItem(RsMsgItem *mi)
{ {
bool changed = false ; bool changed = false ;
if(checkAndRebuildPartialMessage(mi)) // only returns true when a msg is complete. // only returns true when a msg is complete.
if(checkAndRebuildPartialMessage(mi))
{ {
processIncomingMsg(mi); processIncomingMsg(mi);
changed = true ; changed = true ;
@ -356,6 +345,9 @@ int p3MsgService::checkOutgoingMessages()
bool changed = false; bool changed = false;
std::list<RsMsgItem*> output_queue; std::list<RsMsgItem*> output_queue;
using Evt_t = RsMailStatusEvent;
std::shared_ptr<Evt_t> pEvent(new Evt_t());
{ {
RS_STACK_MUTEX(mMsgMtx); /********** STACK LOCKED MTX ******/ RS_STACK_MUTEX(mMsgMtx); /********** STACK LOCKED MTX ******/
@ -386,12 +378,12 @@ int p3MsgService::checkOutgoingMessages()
if(should_send) if(should_send)
{ {
/* send msg */ Dbg3() << __PRETTY_FUNCTION__ << " Sending out message"
pqioutput( PQL_DEBUG_BASIC, msgservicezone, << std::endl;
"p3MsgService::checkOutGoingMessages() Sending out message");
/* remove the pending flag */ /* remove the pending flag */
output_queue.push_back(mit->second) ; output_queue.push_back(mit->second);
pEvent->mChangedMsgIds.insert(std::to_string(mit->first));
/* When the message is a distant msg, dont remove it yet from /* When the message is a distant msg, dont remove it yet from
* the list. Only mark it as being sent, so that we don't send * the list. Only mark it as being sent, so that we don't send
@ -414,8 +406,8 @@ int p3MsgService::checkOutgoingMessages()
} }
else else
{ {
pqioutput( PQL_DEBUG_BASIC, msgservicezone, Dbg3() << __PRETTY_FUNCTION__ << " Delaying until available..."
"p3MsgService::checkOutGoingMessages() Delaying until available..."); << std::endl;
} }
} }
@ -446,6 +438,9 @@ int p3MsgService::checkOutgoingMessages()
if(changed) if(changed)
RsServer::notify()->notifyListChange(NOTIFY_LIST_MESSAGELIST,NOTIFY_TYPE_MOD); RsServer::notify()->notifyListChange(NOTIFY_LIST_MESSAGELIST,NOTIFY_TYPE_MOD);
if(rsEvents && !pEvent->mChangedMsgIds.empty())
rsEvents->postEvent(pEvent);
return 0; return 0;
} }
@ -911,6 +906,8 @@ bool p3MsgService::removeMsgId(const std::string &mid)
} }
bool changed = false; bool changed = false;
using Evt_t = RsMailStatusEvent;
std::shared_ptr<Evt_t> pEvent(new Evt_t());
{ {
RsStackMutex stack(mMsgMtx); /********** STACK LOCKED MTX ******/ RsStackMutex stack(mMsgMtx); /********** STACK LOCKED MTX ******/
@ -922,6 +919,7 @@ bool p3MsgService::removeMsgId(const std::string &mid)
RsMsgItem *mi = mit->second; RsMsgItem *mi = mit->second;
imsg.erase(mit); imsg.erase(mit);
delete mi; delete mi;
pEvent->mChangedMsgIds.insert(mid);
} }
mit = msgOutgoing.find(msgId); mit = msgOutgoing.find(msgId);
@ -931,6 +929,7 @@ bool p3MsgService::removeMsgId(const std::string &mid)
RsMsgItem *mi = mit->second; RsMsgItem *mi = mit->second;
msgOutgoing.erase(mit); msgOutgoing.erase(mit);
delete mi; delete mi;
pEvent->mChangedMsgIds.insert(mid);
} }
std::map<uint32_t, RsMsgSrcId*>::iterator srcIt = mSrcIds.find(msgId); std::map<uint32_t, RsMsgSrcId*>::iterator srcIt = mSrcIds.find(msgId);
@ -938,6 +937,7 @@ bool p3MsgService::removeMsgId(const std::string &mid)
changed = true; changed = true;
delete (srcIt->second); delete (srcIt->second);
mSrcIds.erase(srcIt); mSrcIds.erase(srcIt);
pEvent->mChangedMsgIds.insert(mid);
} }
} }
@ -950,6 +950,9 @@ bool p3MsgService::removeMsgId(const std::string &mid)
RsServer::notify()->notifyListChange(NOTIFY_LIST_MESSAGELIST,NOTIFY_TYPE_MOD); RsServer::notify()->notifyListChange(NOTIFY_LIST_MESSAGELIST,NOTIFY_TYPE_MOD);
} }
if(rsEvents && !pEvent->mChangedMsgIds.empty())
rsEvents->postEvent(pEvent);
return changed; return changed;
} }
@ -1095,12 +1098,14 @@ bool p3MsgService::setMsgParentId(uint32_t msgId, uint32_t msgParentId)
/****************************************/ /****************************************/
/****************************************/ /****************************************/
/* Message Items */ /* Message Items */
uint32_t p3MsgService::sendMessage(RsMsgItem *item) // no from field because it's implicitly our own PeerId // no from field because it's implicitly our own PeerId
uint32_t p3MsgService::sendMessage(RsMsgItem* item)
{ {
if(!item) if(!item)
return 0 ; {
RsErr() << __PRETTY_FUNCTION__ << " item can't be null" << std::endl;
pqioutput(PQL_DEBUG_BASIC, msgservicezone, "p3MsgService::sendMessage()"); return 0;
}
item->msgId = getNewUniqueMsgId(); /* grabs Mtx as well */ item->msgId = getNewUniqueMsgId(); /* grabs Mtx as well */
item->msgFlags |= (RS_MSG_FLAGS_OUTGOING | RS_MSG_FLAGS_PENDING); /* add pending flag */ item->msgFlags |= (RS_MSG_FLAGS_OUTGOING | RS_MSG_FLAGS_PENDING); /* add pending flag */
@ -1131,7 +1136,12 @@ uint32_t p3MsgService::sendMessage(RsMsgItem *item) // no from field because
uint32_t p3MsgService::sendDistantMessage(RsMsgItem *item, const RsGxsId& from) uint32_t p3MsgService::sendDistantMessage(RsMsgItem *item, const RsGxsId& from)
{ {
if(!item) return 0; if(!item)
{
RsErr() << __PRETTY_FUNCTION__ << " item can't be null" << std::endl;
print_stacktrace();
return 0;
}
item->msgId = getNewUniqueMsgId(); /* grabs Mtx as well */ item->msgId = getNewUniqueMsgId(); /* grabs Mtx as well */
item->msgFlags |= ( RS_MSG_FLAGS_DISTANT | RS_MSG_FLAGS_OUTGOING | item->msgFlags |= ( RS_MSG_FLAGS_DISTANT | RS_MSG_FLAGS_OUTGOING |
@ -1178,8 +1188,6 @@ bool p3MsgService::MessageSend(MessageInfo &info)
if (msg) if (msg)
{ {
std::list<RsPgpId>::iterator it ;
if (msg->msgFlags & RS_MSG_FLAGS_SIGNED) if (msg->msgFlags & RS_MSG_FLAGS_SIGNED)
msg->msgFlags |= RS_MSG_FLAGS_SIGNATURE_CHECKS; // this is always true, since we are sending the message msg->msgFlags |= RS_MSG_FLAGS_SIGNATURE_CHECKS; // this is always true, since we are sending the message
@ -1192,14 +1200,125 @@ bool p3MsgService::MessageSend(MessageInfo &info)
imsg[msg->msgId] = msg; imsg[msg->msgId] = msg;
RsServer::notify()->notifyListChange(NOTIFY_LIST_MESSAGELIST,NOTIFY_TYPE_ADD); RsServer::notify()->notifyListChange(NOTIFY_LIST_MESSAGELIST,NOTIFY_TYPE_ADD);
//
// // return new message id
// rs_sprintf(info.msgId, "%lu", msg->msgId);
} }
return true; return true;
} }
uint32_t p3MsgService::sendMail(
const RsGxsId from,
const std::string& subject,
const std::string& body,
const std::set<RsGxsId>& to,
const std::set<RsGxsId>& cc,
const std::set<RsGxsId>& bcc,
const std::vector<FileInfo>& attachments,
std::set<RsMailIdRecipientIdPair>& trackingIds,
std::string& errorMsg )
{
errorMsg.clear();
const std::string fname = __PRETTY_FUNCTION__;
auto pCheck = [&](bool test, const std::string& errMsg)
{
if(!test)
{
errorMsg = errMsg;
RsErr() << fname << " " << errMsg << std::endl;
}
return test;
};
if(!pCheck(!from.isNull(), "from can't be null")) return false;
if(!pCheck( rsIdentity->isOwnId(from),
"from must be own identity") ) return false;
if(!pCheck(!(to.empty() && cc.empty() && bcc.empty()),
"You must specify at least one recipient" )) return false;
auto dstCheck =
[&](const std::set<RsGxsId>& dstSet, const std::string& setName)
{
for(const RsGxsId& dst: dstSet)
{
if(dst.isNull())
{
errorMsg = setName + " contains a null recipient";
RsErr() << fname << " " << errorMsg << std::endl;
return false;
}
if(!rsIdentity->isKnownId(dst))
{
rsIdentity->requestIdentity(dst);
errorMsg = setName + " contains an unknown recipient: " +
dst.toStdString();
RsErr() << fname << " " << errorMsg << std::endl;
return false;
}
}
return true;
};
if(!dstCheck(to, "to")) return false;
if(!dstCheck(cc, "cc")) return false;
if(!dstCheck(bcc, "bcc")) return false;
MessageInfo msgInfo;
msgInfo.rsgxsid_srcId = from;
msgInfo.title = subject;
msgInfo.msg = body;
msgInfo.rsgxsid_msgto = to;
msgInfo.rsgxsid_msgcc = cc;
msgInfo.rsgxsid_msgbcc = bcc;
std::copy( attachments.begin(), attachments.end(),
std::back_inserter(msgInfo.files) );
uint32_t ret = 0;
using Evt_t = RsMailStatusEvent;
std::shared_ptr<Evt_t> pEvent(new Evt_t());
auto pSend = [&](const std::set<RsGxsId>& sDest)
{
for(const RsGxsId& dst : sDest)
{
RsMsgItem* msgItem = initMIRsMsg(msgInfo, dst);
if(!msgItem)
{
errorMsg += " initMIRsMsg from: " + from.toStdString()
+ " dst: " + dst.toStdString() + " subject: " + subject
+ " returned nullptr!\n";
RsErr() << fname << errorMsg;
continue;
}
uint32_t msgId = sendDistantMessage(msgItem, from);
// ensure we don't use that ptr again without noticing
msgItem = nullptr;
if(!msgId)
{
errorMsg += " sendDistantMessage from: " + from.toStdString()
+ " dst: " + dst.toStdString() + " subject: " + subject
+ " returned 0!\n";
RsErr() << fname << errorMsg;
continue;
}
const RsMailMessageId mailId = std::to_string(msgId);
pEvent->mChangedMsgIds.insert(mailId);
trackingIds.insert(RsMailIdRecipientIdPair(mailId, dst));
++ret;
}
};
pSend(to);
pSend(cc);
pSend(bcc);
if(rsEvents) rsEvents->postEvent(pEvent);
return ret;
}
bool p3MsgService::SystemMessage(const std::string &title, const std::string &message, uint32_t systemFlag) bool p3MsgService::SystemMessage(const std::string &title, const std::string &message, uint32_t systemFlag)
{ {
if ((systemFlag & RS_MSG_SYSTEM) == 0) { if ((systemFlag & RS_MSG_SYSTEM) == 0) {
@ -1890,20 +2009,21 @@ void p3MsgService::notifyDataStatus( const GRouterMsgPropagationId& id,
{ {
RS_STACK_MUTEX(mMsgMtx); RS_STACK_MUTEX(mMsgMtx);
std::cerr << "(WW) p3MsgService::notifyDataStatus: Global router tells "
<< "us that item ID " << id
<< " could not be delivered on time.";
auto it = _ongoing_messages.find(id); auto it = _ongoing_messages.find(id);
if(it == _ongoing_messages.end()) if(it == _ongoing_messages.end())
{ {
std::cerr << " (EE) cannot find pending message to acknowledge. " RsErr() << __PRETTY_FUNCTION__
<< "Weird. grouter id = " << id << std::endl; << " cannot find pending message to acknowledge. "
<< "Weird. grouter id: " << id << std::endl;
return; return;
} }
uint32_t msg_id = it->second; uint32_t msg_id = it->second;
std::cerr << " message id = " << msg_id << std::endl;
RsWarn() << __PRETTY_FUNCTION__ << " Global router tells "
<< "us that item ID " << id
<< " could not be delivered on time. Message id: "
<< msg_id << std::endl;
/* this is needed because it's not saved in config, but we should /* this is needed because it's not saved in config, but we should
* probably include it in _ongoing_messages */ * probably include it in _ongoing_messages */
@ -1912,10 +2032,10 @@ void p3MsgService::notifyDataStatus( const GRouterMsgPropagationId& id,
std::map<uint32_t,RsMsgItem*>::iterator mit = msgOutgoing.find(msg_id); std::map<uint32_t,RsMsgItem*>::iterator mit = msgOutgoing.find(msg_id);
if(mit == msgOutgoing.end()) if(mit == msgOutgoing.end())
{ {
std::cerr << " (II) message has been notified as not delivered, " RsInfo() << __PRETTY_FUNCTION__
<< "but it's not in outgoing list. Probably it has been " << " message has been notified as not delivered, "
<< "delivered successfully by other means." << "but it's not in outgoing list. Probably it has been "
<< std::endl; << "delivered successfully by other means." << std::endl;
} }
else else
{ {
@ -1925,6 +2045,7 @@ void p3MsgService::notifyDataStatus( const GRouterMsgPropagationId& id,
// clear the routed flag so that the message is requested again // clear the routed flag so that the message is requested again
mit->second->msgFlags &= ~RS_MSG_FLAGS_ROUTED; mit->second->msgFlags &= ~RS_MSG_FLAGS_ROUTED;
} }
return; return;
} }
@ -1954,17 +2075,31 @@ void p3MsgService::notifyDataStatus( const GRouterMsgPropagationId& id,
return; return;
} }
#if 0
delete it2->second; delete it2->second;
msgOutgoing.erase(it2); msgOutgoing.erase(it2);
#else
// Do not delete it move to sent folder instead!
it2->second->msgFlags &= ~RS_MSG_FLAGS_PENDING;
imsg[msg_id] = it2->second;
msgOutgoing.erase(it2);
#endif
RsServer::notify()->notifyListChange( NOTIFY_LIST_MESSAGELIST, RsServer::notify()->notifyListChange( NOTIFY_LIST_MESSAGELIST,
NOTIFY_TYPE_ADD ); NOTIFY_TYPE_ADD );
IndicateConfigChanged(); IndicateConfigChanged();
using Evt_t = RsMailStatusEvent;
std::shared_ptr<Evt_t> pEvent(new Evt_t());
pEvent->mChangedMsgIds.insert(std::to_string(msg_id));
if(rsEvents) rsEvents->postEvent(pEvent);
return; return;
} }
std::cerr << "p3MsgService: unhandled data status info from global router"
<< " for msg ID " << id << ": this is a bug." << std::endl; RsErr() << __PRETTY_FUNCTION__
<< " unhandled data status info from global router"
<< " for msg ID " << id << ": this is a bug." << std::endl;
} }
bool p3MsgService::acceptDataFromPeer(const RsGxsId& to_gxs_id) bool p3MsgService::acceptDataFromPeer(const RsGxsId& to_gxs_id)
@ -1997,8 +2132,8 @@ bool p3MsgService::receiveGxsTransMail( const RsGxsId& authorId,
const RsGxsId& recipientId, const RsGxsId& recipientId,
const uint8_t* data, uint32_t dataSize ) const uint8_t* data, uint32_t dataSize )
{ {
std::cout << __PRETTY_FUNCTION__ << " " << authorId << ", " << recipientId Dbg2() << __PRETTY_FUNCTION__ << " " << authorId << ", " << recipientId
<< ",, " << dataSize << std::endl; << ",, " << dataSize << std::endl;
Sha1CheckSum hash = RsDirUtil::sha1sum(data, dataSize); Sha1CheckSum hash = RsDirUtil::sha1sum(data, dataSize);
@ -2007,29 +2142,31 @@ bool p3MsgService::receiveGxsTransMail( const RsGxsId& authorId,
if( mRecentlyReceivedMessageHashes.find(hash) != if( mRecentlyReceivedMessageHashes.find(hash) !=
mRecentlyReceivedMessageHashes.end() ) mRecentlyReceivedMessageHashes.end() )
{ {
std::cerr << __PRETTY_FUNCTION__ << " (II) receiving " RsInfo() << __PRETTY_FUNCTION__ << " (II) receiving "
<< "message of hash " << hash << " more than once. " << "message of hash " << hash << " more than once. "
<< "Probably it has arrived before by other means." << "Probably it has arrived before by other means."
<< std::endl; << std::endl;
return true; return true;
} }
mRecentlyReceivedMessageHashes[hash] = time(NULL); mRecentlyReceivedMessageHashes[hash] =
static_cast<uint32_t>(time(nullptr));
} }
IndicateConfigChanged(); IndicateConfigChanged();
RsItem *item = _serialiser->deserialise(const_cast<uint8_t*>(data), &dataSize); RsItem *item = _serialiser->deserialise(
const_cast<uint8_t*>(data), &dataSize );
RsMsgItem *msg_item = dynamic_cast<RsMsgItem*>(item); RsMsgItem *msg_item = dynamic_cast<RsMsgItem*>(item);
if(msg_item) if(msg_item)
{ {
std::cerr << __PRETTY_FUNCTION__ << " Encrypted item correctly " Dbg3() << __PRETTY_FUNCTION__ << " Encrypted item correctly "
<< "deserialised. Passing on to incoming list." << "deserialised. Passing on to incoming list."
<< std::endl; << std::endl;
msg_item->msgFlags |= RS_MSG_FLAGS_DISTANT; msg_item->msgFlags |= RS_MSG_FLAGS_DISTANT;
/* we expect complete msgs - remove partial flag just in case /* we expect complete msgs - remove partial flag just in case
* someone has funny ideas */ * someone has funny ideas */
msg_item->msgFlags &= ~RS_MSG_FLAGS_PARTIAL; msg_item->msgFlags &= ~RS_MSG_FLAGS_PARTIAL;
// hack to pass on GXS id. // hack to pass on GXS id.
@ -2038,8 +2175,8 @@ bool p3MsgService::receiveGxsTransMail( const RsGxsId& authorId,
} }
else else
{ {
std::cerr << __PRETTY_FUNCTION__ << " Item could not be " RsWarn() << __PRETTY_FUNCTION__ << " Item could not be "
<< "deserialised. Format error??" << std::endl; << "deserialised. Format error?" << std::endl;
return false; return false;
} }
@ -2049,8 +2186,11 @@ bool p3MsgService::receiveGxsTransMail( const RsGxsId& authorId,
bool p3MsgService::notifyGxsTransSendStatus( RsGxsTransId mailId, bool p3MsgService::notifyGxsTransSendStatus( RsGxsTransId mailId,
GxsTransSendStatus status ) GxsTransSendStatus status )
{ {
std::cout << __PRETTY_FUNCTION__ << " " << mailId << ", " Dbg2() << __PRETTY_FUNCTION__ << " " << mailId << ", "
<< static_cast<uint>(status) << std::endl; << static_cast<uint32_t>(status) << std::endl;
using Evt_t = RsMailStatusEvent;
std::shared_ptr<Evt_t> pEvent(new Evt_t());
if( status == GxsTransSendStatus::RECEIPT_RECEIVED ) if( status == GxsTransSendStatus::RECEIPT_RECEIVED )
{ {
@ -2062,11 +2202,10 @@ bool p3MsgService::notifyGxsTransSendStatus( RsGxsTransId mailId,
auto it = gxsOngoingMessages.find(mailId); auto it = gxsOngoingMessages.find(mailId);
if(it == gxsOngoingMessages.end()) if(it == gxsOngoingMessages.end())
{ {
std::cerr << __PRETTY_FUNCTION__<< " " RsErr() << __PRETTY_FUNCTION__<< " " << mailId << ", "
<< mailId << static_cast<uint32_t>(status)
<< ", " << static_cast<uint>(status) << " cannot find pending message to acknowledge!"
<< " (EE) cannot find pending message to acknowledge!" << std::endl;
<< std::endl;
return false; return false;
} }
@ -2081,26 +2220,32 @@ bool p3MsgService::notifyGxsTransSendStatus( RsGxsTransId mailId,
auto it2 = msgOutgoing.find(msg_id); auto it2 = msgOutgoing.find(msg_id);
if(it2 == msgOutgoing.end()) if(it2 == msgOutgoing.end())
{ {
std::cerr << __PRETTY_FUNCTION__ << " " << mailId RsInfo() << __PRETTY_FUNCTION__ << " " << mailId
<< ", " << static_cast<uint>(status) << " (II) " << ", " << static_cast<uint32_t>(status)
<< "received receipt for message that is not in " << " received receipt for message that is not in "
<< "outgoing list, probably it has been acknoweldged " << "outgoing list, probably it has been acknoweldged "
<< "before by other means." << std::endl; << "before by other means." << std::endl;
return true; }
else
{
#if 0
delete it2->second;
msgOutgoing.erase(it2);
#else
// Do not delete it move to sent folder instead!
it2->second->msgFlags &= ~RS_MSG_FLAGS_PENDING;
imsg[msg_id] = it2->second;
msgOutgoing.erase(it2);
#endif
pEvent->mChangedMsgIds.insert(std::to_string(msg_id));
} }
delete it2->second;
msgOutgoing.erase(it2);
} }
RsServer::notify()->notifyListChange( NOTIFY_LIST_MESSAGELIST, RsServer::notify()->notifyListChange( NOTIFY_LIST_MESSAGELIST,
NOTIFY_TYPE_ADD ); NOTIFY_TYPE_ADD );
IndicateConfigChanged(); IndicateConfigChanged();
return true;
} }
else if( status >= GxsTransSendStatus::FAILED_RECEIPT_SIGNATURE )
if( status >= GxsTransSendStatus::FAILED_RECEIPT_SIGNATURE )
{ {
uint32_t msg_id; uint32_t msg_id;
@ -2132,17 +2277,22 @@ bool p3MsgService::notifyGxsTransSendStatus( RsGxsTransId mailId,
std::cerr << " message has been notified as not delivered, " std::cerr << " message has been notified as not delivered, "
<< "but it not on outgoing list." << "but it not on outgoing list."
<< std::endl; << std::endl;
return true;
} }
std::cerr << " reseting the ROUTED flag so that the message is " else
<< "requested again" << std::endl; {
std::cerr << " reseting the ROUTED flag so that the message is "
<< "requested again" << std::endl;
// clear the routed flag so that the message is requested again
mit->second->msgFlags &= ~RS_MSG_FLAGS_ROUTED;
// clear the routed flag so that the message is requested again pEvent->mChangedMsgIds.insert(std::to_string(msg_id));
mit->second->msgFlags &= ~RS_MSG_FLAGS_ROUTED; }
return true;
} }
} }
if(rsEvents && !pEvent->mChangedMsgIds.empty())
rsEvents->postEvent(pEvent);
return true; return true;
} }

View File

@ -37,7 +37,7 @@
#include "services/p3service.h" #include "services/p3service.h"
#include "rsitems/rsmsgitems.h" #include "rsitems/rsmsgitems.h"
#include "util/rsthreads.h" #include "util/rsthreads.h"
#include "util/rsdebug.h"
#include "retroshare/rsgxsifacetypes.h" #include "retroshare/rsgxsifacetypes.h"
#include "grouter/p3grouter.h" #include "grouter/p3grouter.h"
@ -59,6 +59,19 @@ public:
virtual RsServiceInfo getServiceInfo(); virtual RsServiceInfo getServiceInfo();
/// @see RsMsgs::sendMail
uint32_t sendMail(const RsGxsId from,
const std::string& subject,
const std::string& body,
const std::set<RsGxsId>& to = std::set<RsGxsId>(),
const std::set<RsGxsId>& cc = std::set<RsGxsId>(),
const std::set<RsGxsId>& bcc = std::set<RsGxsId>(),
const std::vector<FileInfo>& attachments = std::vector<FileInfo>(),
std::set<RsMailIdRecipientIdPair>& trackingIds =
RS_DEFAULT_STORAGE_PARAM(std::set<RsMailIdRecipientIdPair>),
std::string& errorMsg =
RS_DEFAULT_STORAGE_PARAM(std::string) );
/* External Interface */ /* External Interface */
bool getMessageSummaries(std::list<Rs::Msgs::MsgInfoSummary> &msgList); bool getMessageSummaries(std::list<Rs::Msgs::MsgInfoSummary> &msgList);
bool getMessage(const std::string &mid, Rs::Msgs::MessageInfo &msg); bool getMessage(const std::string &mid, Rs::Msgs::MessageInfo &msg);
@ -72,6 +85,7 @@ public:
// msgParentId == 0 --> remove // msgParentId == 0 --> remove
bool setMsgParentId(uint32_t msgId, uint32_t msgParentId); bool setMsgParentId(uint32_t msgId, uint32_t msgParentId);
RS_DEPRECATED_FOR(sendMail)
bool MessageSend(Rs::Msgs::MessageInfo &info); bool MessageSend(Rs::Msgs::MessageInfo &info);
bool SystemMessage(const std::string &title, const std::string &message, uint32_t systemFlag); bool SystemMessage(const std::string &title, const std::string &message, uint32_t systemFlag);
bool MessageToDraft(Rs::Msgs::MessageInfo &info, const std::string &msgParentId); bool MessageToDraft(Rs::Msgs::MessageInfo &info, const std::string &msgParentId);
@ -94,7 +108,6 @@ public:
//std::list<RsMsgItem *> &getMsgOutList(); //std::list<RsMsgItem *> &getMsgOutList();
int tick(); int tick();
int status();
/*** Overloaded from p3Config ****/ /*** Overloaded from p3Config ****/
virtual RsSerialiser *setupSerialiser(); virtual RsSerialiser *setupSerialiser();
@ -227,6 +240,8 @@ private:
bool mShouldEnableDistantMessaging ; bool mShouldEnableDistantMessaging ;
p3GxsTrans& mGxsTransServ; p3GxsTrans& mGxsTransServ;
RS_SET_CONTEXT_DEBUG_LEVEL(3)
}; };
#endif // MESSAGE_SERVICE_HEADER #endif // MESSAGE_SERVICE_HEADER