2007-12-11 20:43:17 -05:00
|
|
|
/*
|
|
|
|
* libretroshare/src/services msgservice.h
|
|
|
|
*
|
|
|
|
* Services for RetroShare.
|
|
|
|
*
|
|
|
|
* Copyright 2004-2008 by Robert Fernie.
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License Version 2 as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
|
|
* USA.
|
|
|
|
*
|
|
|
|
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef MESSAGE_SERVICE_HEADER
|
|
|
|
#define MESSAGE_SERVICE_HEADER
|
|
|
|
|
|
|
|
#include <list>
|
|
|
|
#include <map>
|
|
|
|
#include <iostream>
|
|
|
|
|
2010-08-06 05:40:23 -04:00
|
|
|
#include "retroshare/rsmsgs.h"
|
2008-02-04 12:55:13 -05:00
|
|
|
|
2007-12-11 20:43:17 -05:00
|
|
|
#include "pqi/pqi.h"
|
|
|
|
#include "pqi/pqiindic.h"
|
2008-06-24 00:22:42 -04:00
|
|
|
|
2014-03-28 23:57:44 -04:00
|
|
|
#include "pqi/pqiservicemonitor.h"
|
2008-06-24 00:22:42 -04:00
|
|
|
#include "pqi/p3cfgmgr.h"
|
|
|
|
|
2007-12-11 20:43:17 -05:00
|
|
|
#include "services/p3service.h"
|
|
|
|
#include "serialiser/rsmsgitems.h"
|
2008-02-04 12:55:13 -05:00
|
|
|
#include "util/rsthreads.h"
|
2013-12-27 15:06:47 -05:00
|
|
|
|
|
|
|
#ifdef GROUTER
|
|
|
|
#include "grouter/p3grouter.h"
|
|
|
|
#include "grouter/grouterclientservice.h"
|
|
|
|
#endif
|
2013-04-29 16:44:48 -04:00
|
|
|
#include "turtle/p3turtle.h"
|
|
|
|
#include "turtle/turtleclientservice.h"
|
2007-12-11 20:43:17 -05:00
|
|
|
|
2011-07-09 14:39:34 -04:00
|
|
|
class p3LinkMgr;
|
2007-12-11 20:43:17 -05:00
|
|
|
|
2013-12-27 15:06:47 -05:00
|
|
|
// Temp tweak to test grouter
|
2014-03-28 23:57:44 -04:00
|
|
|
class p3MsgService: public p3Service, public p3Config, public pqiServiceMonitor, public RsTurtleClientService
|
2013-12-27 15:06:47 -05:00
|
|
|
#ifdef GROUTER
|
|
|
|
, public GRouterClientService
|
|
|
|
#endif
|
2007-12-11 20:43:17 -05:00
|
|
|
{
|
|
|
|
public:
|
2014-03-28 23:57:44 -04:00
|
|
|
p3MsgService(p3ServiceControl *sc);
|
2014-03-21 23:53:44 -04:00
|
|
|
virtual RsServiceInfo getServiceInfo();
|
2007-12-11 20:43:17 -05:00
|
|
|
|
2008-02-04 12:55:13 -05:00
|
|
|
/* External Interface */
|
|
|
|
bool getMessageSummaries(std::list<MsgInfoSummary> &msgList);
|
2010-11-02 17:11:11 -04:00
|
|
|
bool getMessage(const std::string &mid, MessageInfo &msg);
|
2010-05-28 10:42:54 -04:00
|
|
|
void getMessageCount(unsigned int *pnInbox, unsigned int *pnInboxNew, unsigned int *pnOutbox, unsigned int *pnDraftbox, unsigned int *pnSentbox, unsigned int *pnTrashbox);
|
2008-02-04 12:55:13 -05:00
|
|
|
|
2013-05-04 18:03:48 -04:00
|
|
|
bool decryptMessage(const std::string& mid) ;
|
2010-11-02 17:11:11 -04:00
|
|
|
bool removeMsgId(const std::string &mid);
|
|
|
|
bool markMsgIdRead(const std::string &mid, bool bUnreadByUser);
|
|
|
|
bool setMsgFlag(const std::string &mid, uint32_t flag, uint32_t mask);
|
|
|
|
bool getMsgParentId(const std::string &msgId, std::string &msgParentId);
|
|
|
|
// msgParentId == 0 --> remove
|
|
|
|
bool setMsgParentId(uint32_t msgId, uint32_t msgParentId);
|
2008-02-04 12:55:13 -05:00
|
|
|
|
|
|
|
bool MessageSend(MessageInfo &info);
|
2013-10-03 17:41:34 -04:00
|
|
|
bool SystemMessage(const std::string &title, const std::string &message, uint32_t systemFlag);
|
2010-11-02 17:11:11 -04:00
|
|
|
bool MessageToDraft(MessageInfo &info, const std::string &msgParentId);
|
|
|
|
bool MessageToTrash(const std::string &mid, bool bTrash);
|
2008-02-04 12:55:13 -05:00
|
|
|
|
2010-08-22 18:12:26 -04:00
|
|
|
bool getMessageTagTypes(MsgTagType& tags);
|
|
|
|
bool setMessageTagType(uint32_t tagId, std::string& text, uint32_t rgb_color);
|
|
|
|
bool removeMessageTagType(uint32_t tagId);
|
2010-08-19 17:47:26 -04:00
|
|
|
|
2010-11-02 17:11:11 -04:00
|
|
|
bool getMessageTag(const std::string &msgId, MsgTagInfo& info);
|
2010-08-22 18:12:26 -04:00
|
|
|
/* set == false && tagId == 0 --> remove all */
|
2010-11-02 17:11:11 -04:00
|
|
|
bool setMessageTag(const std::string &msgId, uint32_t tagId, bool set);
|
2010-08-22 18:12:26 -04:00
|
|
|
|
|
|
|
bool resetMessageStandardTagTypes(MsgTagType& tags);
|
2008-02-04 12:55:13 -05:00
|
|
|
|
2007-12-11 20:43:17 -05:00
|
|
|
void loadWelcomeMsg(); /* startup message */
|
|
|
|
|
2008-02-07 11:18:34 -05:00
|
|
|
//std::list<RsMsgItem *> &getMsgList();
|
|
|
|
//std::list<RsMsgItem *> &getMsgOutList();
|
2007-12-11 20:43:17 -05:00
|
|
|
|
|
|
|
int tick();
|
|
|
|
int status();
|
|
|
|
|
2010-09-20 18:11:09 -04:00
|
|
|
/*** Overloaded from p3Config ****/
|
|
|
|
virtual RsSerialiser *setupSerialiser();
|
2010-12-18 14:35:07 -05:00
|
|
|
virtual bool saveList(bool& cleanup, std::list<RsItem*>&);
|
|
|
|
virtual bool loadList(std::list<RsItem*>& load);
|
2010-09-20 18:11:09 -04:00
|
|
|
virtual void saveDone();
|
|
|
|
/*** Overloaded from p3Config ****/
|
2008-02-07 11:18:34 -05:00
|
|
|
|
|
|
|
/*** Overloaded from pqiMonitor ***/
|
2014-03-28 23:57:44 -04:00
|
|
|
virtual void statusChange(const std::list<pqiServicePeer> &plist);
|
2008-02-07 11:18:34 -05:00
|
|
|
int checkOutgoingMessages();
|
|
|
|
/*** Overloaded from pqiMonitor ***/
|
|
|
|
|
2013-04-29 16:44:48 -04:00
|
|
|
/*** overloaded from p3turtle ***/
|
|
|
|
|
2013-12-27 15:06:47 -05:00
|
|
|
#ifdef GROUTER
|
|
|
|
virtual void connectToGlobalRouter(p3GRouter *) ;
|
|
|
|
#endif
|
|
|
|
virtual void connectToTurtleRouter(p3turtle *) ;
|
2013-04-29 16:44:48 -04:00
|
|
|
|
|
|
|
struct DistantMessengingInvite
|
|
|
|
{
|
|
|
|
time_t time_of_validity ;
|
|
|
|
};
|
|
|
|
struct DistantMessengingContact
|
|
|
|
{
|
|
|
|
time_t last_hit_time ;
|
2014-03-17 16:56:06 -04:00
|
|
|
RsPeerId virtual_peer_id ;
|
2013-04-29 16:44:48 -04:00
|
|
|
uint32_t status ;
|
2013-08-31 17:10:04 -04:00
|
|
|
bool pending_messages ;
|
2013-04-29 16:44:48 -04:00
|
|
|
};
|
2014-03-17 16:56:06 -04:00
|
|
|
bool createDistantOfflineMessengingInvite(time_t time_of_validity,DistantMsgPeerId &peer_id) ;
|
2013-04-29 16:44:48 -04:00
|
|
|
bool getDistantOfflineMessengingInvites(std::vector<DistantOfflineMessengingInvite>& invites) ;
|
2013-07-31 12:34:34 -04:00
|
|
|
|
|
|
|
void enableDistantMessaging(bool b) ;
|
|
|
|
bool distantMessagingEnabled() ;
|
2014-03-17 16:56:06 -04:00
|
|
|
bool getDistantMessagePeerId(const RsPgpId& pgp_id,DistantMsgPeerId &peer_id) ;
|
2013-04-29 16:44:48 -04:00
|
|
|
|
2007-12-11 20:43:17 -05:00
|
|
|
private:
|
2014-03-17 16:56:06 -04:00
|
|
|
bool getDistantMessageHash(const RsPgpId& pgp_id,Sha1CheckSum &hash) ;
|
|
|
|
void sendPrivateMsgItem(const Sha1CheckSum& hash,RsMsgItem *) ;
|
|
|
|
|
2013-04-29 16:44:48 -04:00
|
|
|
// This maps contains the current invitations to respond to.
|
2014-03-17 16:56:06 -04:00
|
|
|
// The map is indexed by the hash
|
|
|
|
std::map<Sha1CheckSum,DistantMessengingInvite> _messenging_invites ;
|
2013-04-29 16:44:48 -04:00
|
|
|
|
|
|
|
// This contains the ongoing tunnel handling contacts.
|
2014-03-17 16:56:06 -04:00
|
|
|
// The map is indexed by the hash
|
|
|
|
std::map<Sha1CheckSum,DistantMessengingContact> _messenging_contacts ;
|
2013-04-29 16:44:48 -04:00
|
|
|
|
|
|
|
// Overloaded from RsTurtleClientService
|
|
|
|
|
2013-12-27 15:06:47 -05:00
|
|
|
#ifdef GROUTER
|
|
|
|
virtual void receiveGRouterData(RsGRouterGenericDataItem *item, const GRouterKeyId& key) ;
|
|
|
|
#endif
|
2014-03-17 16:56:06 -04:00
|
|
|
virtual bool handleTunnelRequest(const Sha1CheckSum& hash,const RsPeerId& peer_id) ;
|
|
|
|
// virtual void receiveTurtleData(RsTurtleGenericTunnelItem *item,const Sha1CheckSum& hash,const RsPeerId& virtual_peer_id,RsTurtleGenericTunnelItem::Direction direction) ;
|
2014-03-23 08:13:44 -04:00
|
|
|
void addVirtualPeer(const TurtleFileHash&, const TurtleVirtualPeerId&,RsTurtleGenericTunnelItem::Direction /* dir */) {}
|
2014-03-17 16:56:06 -04:00
|
|
|
void removeVirtualPeer(const TurtleFileHash&, const TurtleVirtualPeerId&) {}
|
2013-04-29 16:44:48 -04:00
|
|
|
|
|
|
|
// Utility functions
|
|
|
|
|
2014-03-17 16:56:06 -04:00
|
|
|
bool encryptMessage(const RsPgpId& pgp_id,RsMsgItem *msg) ;
|
|
|
|
bool locked_findHashForVirtualPeerId(const RsPeerId& pid,Sha1CheckSum& hash) ;
|
2013-05-03 17:02:44 -04:00
|
|
|
|
2013-04-29 16:44:48 -04:00
|
|
|
void manageDistantPeers() ;
|
2014-03-17 16:56:06 -04:00
|
|
|
void sendTurtleData(const Sha1CheckSum& hash,RsMsgItem *) ;
|
2013-12-27 15:06:47 -05:00
|
|
|
#ifdef GROUTER
|
2014-03-17 16:56:06 -04:00
|
|
|
void sendGRouterData(const Sha1CheckSum& hash,RsMsgItem *) ;
|
2013-12-27 15:06:47 -05:00
|
|
|
#endif
|
2013-04-29 16:44:48 -04:00
|
|
|
void handleIncomingItem(RsMsgItem *) ;
|
|
|
|
|
2013-12-27 15:06:47 -05:00
|
|
|
#ifdef GROUTER
|
|
|
|
p3GRouter *mGRouter ;
|
|
|
|
#endif
|
2013-04-29 16:44:48 -04:00
|
|
|
p3turtle *mTurtle ;
|
2007-12-11 20:43:17 -05:00
|
|
|
|
2008-02-04 16:40:34 -05:00
|
|
|
uint32_t getNewUniqueMsgId();
|
2008-02-04 12:55:13 -05:00
|
|
|
int sendMessage(RsMsgItem *item);
|
2011-09-09 15:37:38 -04:00
|
|
|
void checkSizeAndSendMessage(RsMsgItem *msg);
|
|
|
|
|
2007-12-11 20:43:17 -05:00
|
|
|
int incomingMsgs();
|
2012-05-01 05:18:55 -04:00
|
|
|
void processMsg(RsMsgItem *mi, bool incoming);
|
2011-09-09 15:37:38 -04:00
|
|
|
bool checkAndRebuildPartialMessage(RsMsgItem*) ;
|
2007-12-11 20:43:17 -05:00
|
|
|
|
2008-02-04 12:55:13 -05:00
|
|
|
void initRsMI(RsMsgItem *msg, MessageInfo &mi);
|
|
|
|
void initRsMIS(RsMsgItem *msg, MsgInfoSummary &mis);
|
2014-03-17 16:56:06 -04:00
|
|
|
RsMsgItem *initMIRsMsg(MessageInfo &info, const RsPeerId &to);
|
2008-02-04 12:55:13 -05:00
|
|
|
|
2010-08-22 18:12:26 -04:00
|
|
|
void initStandardTagTypes();
|
|
|
|
|
2014-03-28 23:57:44 -04:00
|
|
|
p3ServiceControl *mServiceCtrl;
|
2007-12-11 20:43:17 -05:00
|
|
|
|
2008-02-04 12:55:13 -05:00
|
|
|
/* Mutex Required for stuff below */
|
|
|
|
|
2008-02-04 16:40:34 -05:00
|
|
|
RsMutex mMsgMtx;
|
2013-04-29 16:44:48 -04:00
|
|
|
RsMsgSerialiser *_serialiser ;
|
2008-02-04 12:55:13 -05:00
|
|
|
|
2008-02-04 16:40:34 -05:00
|
|
|
/* stored list of messages */
|
|
|
|
std::map<uint32_t, RsMsgItem *> imsg;
|
|
|
|
/* ones that haven't made it out yet! */
|
|
|
|
std::map<uint32_t, RsMsgItem *> msgOutgoing;
|
2007-12-11 20:43:17 -05:00
|
|
|
|
2014-03-17 16:56:06 -04:00
|
|
|
std::map<RsPeerId, RsMsgItem *> _pendingPartialMessages ;
|
2011-09-09 15:37:38 -04:00
|
|
|
|
2010-08-19 17:47:26 -04:00
|
|
|
/* maps for tags types and msg tags */
|
|
|
|
|
|
|
|
std::map<uint32_t, RsMsgTagType*> mTags;
|
2010-08-22 18:12:26 -04:00
|
|
|
std::map<uint32_t, RsMsgTags*> mMsgTags;
|
2010-08-19 17:47:26 -04:00
|
|
|
|
2008-02-04 16:40:34 -05:00
|
|
|
uint32_t mMsgUniqueId;
|
2007-12-11 20:43:17 -05:00
|
|
|
|
2010-10-31 15:29:26 -04:00
|
|
|
// used delete msgSrcIds after config save
|
2011-05-21 12:26:00 -04:00
|
|
|
std::map<uint32_t, RsMsgSrcId*> mSrcIds;
|
2010-10-31 15:29:26 -04:00
|
|
|
|
2010-11-02 17:11:11 -04:00
|
|
|
// save the parent of the messages in draft for replied and forwarded
|
|
|
|
std::map<uint32_t, RsMsgParentId*> mParentId;
|
|
|
|
|
2008-02-04 12:55:13 -05:00
|
|
|
std::string config_dir;
|
2013-08-09 13:02:29 -04:00
|
|
|
|
|
|
|
bool mDistantMessagingEnabled ;
|
2007-12-11 20:43:17 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // MESSAGE_SERVICE_HEADER
|