Fixed up the retroshare message system.

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@331 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
drbob 2008-02-04 17:55:13 +00:00
parent 07a458367b
commit 8527a5e53f
17 changed files with 947 additions and 609 deletions

View file

@ -7,15 +7,16 @@ RS_TOP_DIR = ..
include $(RS_TOP_DIR)/scripts/config.mk
###############################################################
RSOBJ = p3face-file.o \
p3face-msgs.o \
RSOBJ = p3peers.o \
p3rank.o \
p3msgs.o \
p3face-file.o \
p3face-server.o \
p3face-config.o \
p3face-startup.o \
rstypes.o \
rsiface.o \
p3peers.o \
p3rank.o
p3face-msgs.o
# pqistrings.o \
# p3face-people.o

View file

@ -37,130 +37,6 @@ const int p3facemsgzone = 11453;
#include <sys/time.h>
#include <time.h>
#if 0
unsigned long getMsgId(RsMsgId &id)
{
unsigned long mid = 0;
mid = (id.data[0] << 24);
mid |= (id.data[1] << 16);
mid |= (id.data[2] << 8);
mid |= id.data[3];
return mid;
}
void setMsgId(RsMsgId &rsmid, unsigned int mid)
{
/* version that uses the uniqueMsgId stored in sid */
/* 16 Bytes XXX Must be equal! */
for(int i = 0; i < CHAN_SIGN_SIZE; i++)
rsmid.data[i] = 0;
rsmid.data[0] = (0xff & (mid >> 24));
rsmid.data[1] = (0xff & (mid >> 16));
rsmid.data[2] = (0xff & (mid >> 8));
rsmid.data[3] = (0xff & (mid >> 0));
return;
}
#endif
/****************************************/
/****************************************/
/* Message Items */
int RsServer::MessageSend(MessageInfo &info)
{
/* so we send this.... */
lockRsCore(); /* LOCK */
RsMsgItem *msg = new RsMsgItem();
/* id who it is to ???? handled lower */
msg -> PeerId("");
msg -> msgFlags = 0;
msg -> msgId = 0;
msg -> sendTime = time(NULL);
msg -> recvTime = 0;
msg -> subject = info.title;
msg -> message = info.msg;
std::list<PersonInfo>::iterator pit;
for(pit = info.msgto.begin(); pit != info.msgto.end(); pit++)
{
msg -> msgto.ids.push_back(pit->id);
}
for(pit = info.msgcc.begin(); pit != info.msgcc.end(); pit++)
{
msg -> msgcc.ids.push_back(pit->id);
}
for(pit = info.msgbcc.begin(); pit != info.msgbcc.end(); pit++)
{
msg -> msgbcc.ids.push_back(pit->id);
}
msg -> attachment.title = info.attach_title;
msg -> attachment.comment = info.attach_comment;
std::list<FileInfo>::iterator it;
for(it = info.files.begin(); it != info.files.end(); it++)
{
RsTlvFileItem mfi;
mfi.hash = it -> hash;
mfi.name = it -> fname;
mfi.filesize = it -> size;
msg -> attachment.items.push_back(mfi);
}
std::cerr << "RsServer::MessageSend()" << std::endl;
msg->print(std::cerr);
msgSrv -> sendMessage(msg);
unlockRsCore(); /* UNLOCK */
UpdateAllMsgs();
return 1;
}
/****************************************/
/****************************************/
int RsServer::MessageDelete(std::string mid)
{
lockRsCore(); /* LOCK */
std::cerr << "RsServer::MessageDelete() ";
std::cerr << "mid: " << mid << std::endl;
msgSrv -> removeMsgId(atoi(mid.c_str()));
unlockRsCore(); /* UNLOCK */
UpdateAllMsgs();
return 1;
}
int RsServer::MessageRead(std::string mid)
{
lockRsCore(); /* LOCK */
std::cerr << "RsServer::MessageRead() ";
std::cerr << "mid: " << mid << std::endl;
msgSrv -> markMsgIdRead(atoi(mid.c_str()));
unlockRsCore(); /* UNLOCK */
// (needed?) UpdateAllMsgs();
return 1;
}
/****************************************/
/****************************************/
int RsServer::ChannelCreateNew(ChannelInfo &info)
@ -177,105 +53,6 @@ int RsServer::ChannelSendMsg(ChannelInfo &info)
return 1;
}
/****************************************/
/****************************************/
int RsServer::ChatSend(ChatInfo &ci)
{
lockRsCore(); /* LOCK */
/* send a message to all for now */
if (ci.chatflags & RS_CHAT_PRIVATE)
{
chatSrv -> sendPrivateChat(ci.msg, ci.rsid);
}
else
{
/* global */
chatSrv -> sendChat(ci.msg);
}
unlockRsCore(); /* UNLOCK */
UpdateAllChat();
return 1;
}
int RsServer::UpdateAllChat()
{
RsIface &iface = getIface();
/* lock Mutexes */
lockRsCore(); /* LOCK */
iface.lockData(); /* LOCK */
/* get any messages and push them to iface */
// get the items from the list.
std::list<RsChatItem *> clist = chatSrv -> getChatQueue();
std::list<RsChatItem *>::iterator it;
for(it = clist.begin(); it != clist.end(); it++)
{
ChatInfo ci;
initRsChatInfo((*it), ci);
iface.mChatList.push_back(ci);
delete (*it);
}
iface.setChanged(RsIface::Chat);
/* unlock Mutexes */
iface.unlockData(); /* UNLOCK */
unlockRsCore(); /* UNLOCK */
return 1;
}
/****************************************/
/****************************************/
int RsServer::UpdateAllMsgs()
{
NotifyBase &cb = getNotify();
cb.notifyListPreChange(NOTIFY_LIST_MESSAGELIST, NOTIFY_TYPE_MOD);
RsIface &iface = getIface();
/* lock Mutexes */
lockRsCore(); /* LOCK */
iface.lockData(); /* LOCK */
/* do stuff */
std::list<RsMsgItem *> &msglist = msgSrv -> getMsgList();
std::list<RsMsgItem *> &msgOutlist = msgSrv -> getMsgOutList();
std::list<RsMsgItem *>::iterator mit;
std::list<MessageInfo> &msgs = iface.mMessageList;
msgs.clear();
for(mit = msglist.begin(); mit != msglist.end(); mit++)
{
MessageInfo mi;
initRsMI(*mit, mi);
msgs.push_back(mi);
}
for(mit = msgOutlist.begin(); mit != msgOutlist.end(); mit++)
{
MessageInfo mi;
initRsMI(*mit, mi);
msgs.push_back(mi);
}
iface.setChanged(RsIface::Message);
/* unlock Mutexes */
iface.unlockData(); /* UNLOCK */
unlockRsCore(); /* UNLOCK */
cb.notifyListChange(NOTIFY_LIST_MESSAGELIST, NOTIFY_TYPE_MOD);
return 1;
}
/****************************************/
/****************************************/
int RsServer::UpdateAllChannels()
@ -374,25 +151,6 @@ int RsServer::UpdateAllChannels()
* for intAddChannel / intAddChannelMsg.
*/
void RsServer::initRsChatInfo(RsChatItem *c, ChatInfo &i)
{
i.rsid = c -> PeerId();
i.name = mAuthMgr->getName(i.rsid);
i.msg = c -> message;
if (c -> chatFlags & RS_CHAT_FLAG_PRIVATE)
{
std::cerr << "RsServer::initRsChatInfo() Chat Private!!!";
i.chatflags = RS_CHAT_PRIVATE;
}
else
{
i.chatflags = RS_CHAT_PUBLIC;
std::cerr << "RsServer::initRsChatInfo() Chat Public!!!";
}
std::cerr << std::endl;
}
#ifdef PQI_USE_CHANNELS
int RsServer::intAddChannel(ChannelInfo &info)
@ -503,101 +261,13 @@ void RsServer::intCheckFileStatus(FileInfo &file)
}
void RsServer::initRsMI(RsMsgItem *msg, MessageInfo &mi)
{
mi.msgflags = 0;
/* translate flags, if we sent it... outgoing */
if ((msg->msgFlags & RS_MSG_FLAGS_OUTGOING)
|| (msg->PeerId() == mAuthMgr->OwnId()))
{
mi.msgflags |= RS_MSG_OUTGOING;
}
/* if it has a pending flag, then its in the outbox */
if (msg->msgFlags & RS_MSG_FLAGS_PENDING)
{
mi.msgflags |= RS_MSG_PENDING;
}
if (msg->msgFlags & RS_MSG_FLAGS_NEW)
{
mi.msgflags |= RS_MSG_NEW;
}
mi.id = msg->PeerId();
mi.srcname = mAuthMgr->getName(mi.id);
std::list<std::string>::iterator pit;
for(pit = msg->msgto.ids.begin();
pit != msg->msgto.ids.end(); pit++)
{
PersonInfo pi;
pi.id = (*pit);
pi.name = mAuthMgr->getName(pi.id);
mi.msgto.push_back(pi);
}
for(pit = msg->msgcc.ids.begin();
pit != msg->msgcc.ids.end(); pit++)
{
PersonInfo pi;
pi.id = (*pit);
pi.name = mAuthMgr->getName(pi.id);
mi.msgcc.push_back(pi);
}
for(pit = msg->msgbcc.ids.begin();
pit != msg->msgbcc.ids.end(); pit++)
{
PersonInfo pi;
pi.id = (*pit);
pi.name = mAuthMgr->getName(pi.id);
mi.msgbcc.push_back(pi);
}
mi.title = msg->subject;
mi.msg = msg->message;
mi.attach_title = msg->attachment.title;
mi.attach_comment = msg->attachment.comment;
mi.count = 0;
mi.size = 0;
std::list<RsTlvFileItem>::iterator it;
for(it = msg->attachment.items.begin();
it != msg->attachment.items.end(); it++)
{
FileInfo fi;
fi.fname = RsDirUtil::getTopDir(it->name);
fi.size = it->filesize;
fi.hash = it->hash;
fi.path = it->path;
mi.files.push_back(fi);
mi.count++;
mi.size += fi.size;
}
mi.ts = msg->sendTime;
mi.msgId = msg->msgId;
}
/* Flagging Persons / Channels / Files in or out of a set (CheckLists) */
int RsServer::ClearInChat()
{
lockRsCore(); /* LOCK */
#if 0
std::list<cert *>::iterator it;
std::list<cert *> &certs = sslr -> getCertList();
for(it = certs.begin(); it != certs.end(); it++)
{
(*it)->InChat(false);
}
sslr->IndicateCertsChanged();
#endif
mInChatList.clear();
unlockRsCore(); /* UNLOCK */
return 1;
@ -610,25 +280,26 @@ int RsServer::SetInChat(std::string id, bool in) /* friend : cha
/* so we send this.... */
lockRsCore(); /* LOCK */
#if 0
RsCertId rsid(id);
cert *c = intFindCert(rsid);
if (c)
std::cerr << "Set InChat(" << id << ") to " << (in ? "True" : "False") << std::endl;
std::list<std::string>::iterator it;
it = std::find(mInChatList.begin(), mInChatList.end(), id);
if (it == mInChatList.end())
{
c->InChat(in);
sslr->IndicateCertsChanged();
std::cerr << "Set InChat(" << id << ") to " << (in ? "True" : "False") << std::endl;
if (in)
{
mInChatList.push_back(id);
}
}
else
{
std::cerr << "FAILED TO Set InChat(" << id << ") to " << (in ? "True" : "False") << std::endl;
if (!in)
{
mInChatList.erase(it);
}
}
#endif
unlockRsCore(); /* UNLOCK */
//UpdateAllCerts();
return 1;
}
@ -637,16 +308,7 @@ int RsServer::ClearInMsg()
{
lockRsCore(); /* LOCK */
#if 0
std::list<cert *>::iterator it;
std::list<cert *> &certs = sslr -> getCertList();
for(it = certs.begin(); it != certs.end(); it++)
{
(*it)->InMessage(false);
}
sslr->IndicateCertsChanged();
#endif
mInMsgList.clear();
unlockRsCore(); /* UNLOCK */
@ -659,30 +321,59 @@ int RsServer::SetInMsg(std::string id, bool in) /* friend : msgs
/* so we send this.... */
lockRsCore(); /* LOCK */
#if 0
RsCertId rsid(id);
cert *c = intFindCert(rsid);
if (c)
std::cerr << "Set InMsg(" << id << ") to " << (in ? "True" : "False") << std::endl;
std::list<std::string>::iterator it;
it = std::find(mInMsgList.begin(), mInMsgList.end(), id);
if (it == mInMsgList.end())
{
c->InMessage(in);
sslr->IndicateCertsChanged();
std::cerr << "Set InMsg(" << id << ") to " << (in ? "True" : "False") << std::endl;
if (in)
{
mInMsgList.push_back(id);
}
}
else
{
std::cerr << "FAILED to Set InMsg(" << id << ") to " << (in ? "True" : "False") << std::endl;
if (!in)
{
mInMsgList.erase(it);
}
}
#endif
unlockRsCore(); /* UNLOCK */
return 1;
}
bool RsServer::IsInChat(std::string id) /* friend : chat msgs */
{
/* so we send this.... */
lockRsCore(); /* LOCK */
std::list<std::string>::iterator it;
it = std::find(mInChatList.begin(), mInChatList.end(), id);
bool inChat = (it != mInChatList.end());
unlockRsCore(); /* UNLOCK */
//UpdateAllCerts();
return 1;
return inChat;
}
bool RsServer::IsInMsg(std::string id) /* friend : msg recpts*/
{
/* so we send this.... */
lockRsCore(); /* LOCK */
std::list<std::string>::iterator it;
it = std::find(mInMsgList.begin(), mInMsgList.end(), id);
bool inMsg = (it != mInMsgList.end());
unlockRsCore(); /* UNLOCK */
return inMsg;
}
int RsServer::ClearInBroadcast()
{

View file

@ -175,11 +175,6 @@ void RsServer::run()
{
lastSec = (int) ts;
/* Chat needs to be quick too! */
//std::cerr << "RsServer::run() UpdateAllChat()" << std::endl;
UpdateAllChat();
// every five loops (> 5 secs)
if (loop % 5 == 0)
{
@ -199,8 +194,6 @@ void RsServer::run()
//std::cerr << "RsServer::run() UpdateAllTransfers()" << std::endl;
UpdateAllTransfers();
//std::cerr << "RsServer::run() UpdateAllMsgs()" << std::endl;
UpdateAllMsgs();
//std::cerr << "RsServer::run() UpdateAllChannels()" << std::endl;
UpdateAllChannels();

View file

@ -38,7 +38,6 @@
#include "upnp/upnphandler.h"
#include "dht/opendhtmgr.h"
// Removed temporarily...
#include "services/p3disc.h"
#include "services/p3msgservice.h"
#include "services/p3chatservice.h"
@ -56,6 +55,7 @@
#include "rsserver/p3face.h"
#include "rsserver/p3peers.h"
#include "rsserver/p3rank.h"
#include "rsserver/p3msgs.h"
#include "rsiface/rsgame.h"
/**************** PQI_USE_XPGP ******************/
@ -621,6 +621,7 @@ int RsServer::StartupRetroShare(RsInit *config)
/* setup the gui */
rsGameLauncher = gameLauncher;
rsRanks = new p3Rank(ranking);
rsMsgs = new p3Msgs(mAuthMgr, msgSrv, chatSrv);
/* put a welcome message in! */
if (config->firsttime_run)

View file

@ -36,12 +36,9 @@
#include "rsiface/rstypes.h"
#include "util/rsthreads.h"
class p3disc;
class p3MsgService;
class p3ChatService;
#include "services/p3chatservice.h"
#include "services/p3disc.h"
#include "services/p3msgservice.h"
#include "services/p3chatservice.h"
/* The Main Interface Class - for controlling the server */
@ -159,18 +156,10 @@ int UpdateRemotePeople();
/* p3face-msg Operations */
public:
/* Message Items */
virtual int MessageSend(MessageInfo &info);
virtual int MessageDelete(std::string mid);
virtual int MessageRead(std::string mid);
/* Channel Items */
virtual int ChannelCreateNew(ChannelInfo &info);
virtual int ChannelSendMsg(ChannelInfo &info);
/* Chat */
virtual int ChatSend(ChatInfo &ci);
/* Flagging Persons / Channels / Files in or out of a set (CheckLists) */
virtual int SetInChat(std::string id, bool in); /* friend : chat msgs */
virtual int SetInMsg(std::string id, bool in); /* friend : msg receipients */
@ -183,16 +172,17 @@ virtual int ClearInBroadcast();
virtual int ClearInSubscribe();
virtual int ClearInRecommend();
virtual bool IsInChat(std::string id); /* friend : chat msgs */
virtual bool IsInMsg(std::string id); /* friend : msg recpts*/
private:
std::list<std::string> mInChatList, mInMsgList;
/* Internal Update Iface Fns */
int UpdateAllChat();
int UpdateAllMsgs();
int UpdateAllChannels();
void initRsChatInfo(RsChatItem *c, ChatInfo &i);
#ifdef PQI_USE_CHANNELS
/* Internal Helper Fns */

View file

@ -0,0 +1,155 @@
/*
* "$Id: p3face-msgs.cc,v 1.7 2007-05-05 16:10:06 rmf24 Exp $"
*
* RetroShare C++ Interface.
*
* Copyright 2004-2006 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".
*
*/
#include "rsserver/p3face.h"
#include "util/rsdir.h"
#include <iostream>
#include <sstream>
#include "pqi/pqidebug.h"
const int p3facemsgzone = 11453;
#include <sys/time.h>
#include <time.h>
#include "rsserver/p3msgs.h"
/* external reference point */
RsMsgs *rsMsgs = NULL;
/****************************************/
/****************************************/
bool p3Msgs::getMessageSummaries(std::list<MsgInfoSummary> &msgList)
{
return mMsgSrv->getMessageSummaries(msgList);
}
bool p3Msgs::getMessage(std::string mid, MessageInfo &msg)
{
return mMsgSrv->getMessage(mid, msg);
}
/****************************************/
/****************************************/
/* Message Items */
bool p3Msgs::MessageSend(MessageInfo &info)
{
return mMsgSrv->MessageSend(info);
}
/****************************************/
/****************************************/
bool p3Msgs::MessageDelete(std::string mid)
{
std::cerr << "p3Msgs::MessageDelete() ";
std::cerr << "mid: " << mid << std::endl;
mMsgSrv -> removeMsgId(mid);
return 1;
}
bool p3Msgs::MessageRead(std::string mid)
{
std::cerr << "p3Msgs::MessageRead() ";
std::cerr << "mid: " << mid << std::endl;
mMsgSrv -> markMsgIdRead(mid);
return 1;
}
/****************************************/
/****************************************/
bool p3Msgs::ChatSend(ChatInfo &ci)
{
/* send a message to all for now */
if (ci.chatflags & RS_CHAT_PRIVATE)
{
mChatSrv -> sendPrivateChat(ci.msg, ci.rsid);
}
else
{
/* global */
mChatSrv -> sendChat(ci.msg);
}
return true;
}
bool p3Msgs::getNewChat(std::list<ChatInfo> &chats)
{
/* get any messages and push them to iface */
// get the items from the list.
std::list<RsChatItem *> clist = mChatSrv -> getChatQueue();
if (clist.size() < 1)
{
return false;
}
std::list<RsChatItem *>::iterator it;
for(it = clist.begin(); it != clist.end(); it++)
{
ChatInfo ci;
initRsChatInfo((*it), ci);
chats.push_back(ci);
delete (*it);
}
return true;
}
/**** HELPER FNS For Chat/Msg/Channel Lists ************
*
* The iface->Mutex is required to be locked
* for intAddChannel / intAddChannelMsg.
*/
void p3Msgs::initRsChatInfo(RsChatItem *c, ChatInfo &i)
{
i.rsid = c -> PeerId();
i.name = mAuthMgr->getName(i.rsid);
i.msg = c -> message;
if (c -> chatFlags & RS_CHAT_FLAG_PRIVATE)
{
std::cerr << "RsServer::initRsChatInfo() Chat Private!!!";
i.chatflags = RS_CHAT_PRIVATE;
}
else
{
i.chatflags = RS_CHAT_PUBLIC;
std::cerr << "RsServer::initRsChatInfo() Chat Public!!!";
}
std::cerr << std::endl;
}

View file

@ -0,0 +1,71 @@
#ifndef RS_P3MSG_INTERFACE_H
#define RS_P3MSG_INTERFACE_H
/*
* libretroshare/src/rsserver: p3msgs.h
*
* RetroShare C++ Interface.
*
* Copyright 2007-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".
*
*/
#include "rsiface/rsmsgs.h"
class p3AuthMgr;
class p3MsgService;
class p3ChatService;
class p3Msgs: public RsMsgs
{
public:
p3Msgs(p3AuthMgr *p3a, p3MsgService *p3m, p3ChatService *p3c)
:mAuthMgr(p3a), mMsgSrv(p3m), mChatSrv(p3c) { return; }
virtual ~p3Msgs() { return; }
/****************************************/
/* Message Items */
virtual bool getMessageSummaries(std::list<MsgInfoSummary> &msgList);
virtual bool getMessage(std::string mId, MessageInfo &msg);
virtual bool MessageSend(MessageInfo &info);
virtual bool MessageDelete(std::string mid);
virtual bool MessageRead(std::string mid);
/****************************************/
/* Chat */
virtual bool ChatSend(ChatInfo &ci);
virtual bool getNewChat(std::list<ChatInfo> &chats);
/****************************************/
private:
void initRsChatInfo(RsChatItem *c, ChatInfo &i);
p3AuthMgr *mAuthMgr;
p3MsgService *mMsgSrv;
p3ChatService *mChatSrv;
};
#endif

View file

@ -111,6 +111,7 @@ DirInfo *RsIface::getDirectoryMod(std::string uid, std::string path)
#if 0
const MessageInfo *RsIface::getMessage(std::string cid_in, std::string mid_in)
{
@ -172,6 +173,8 @@ const MessageInfo *RsIface::getChannelMsg(std::string chid_in, std::string mid_i
return NULL;
}
#endif
/* set to true */
bool RsIface::setChanged(DataFlags set)
{

View file

@ -89,6 +89,8 @@ std::ostream &print(std::ostream &out, const DirInfo &info, int indentLvl)
}
#if 0
std::ostream &operator<<(std::ostream &out, const MessageInfo &info)
{
out << "MessageInfo(TODO)";
@ -96,16 +98,18 @@ std::ostream &operator<<(std::ostream &out, const MessageInfo &info)
return out;
}
std::ostream &operator<<(std::ostream &out, const ChannelInfo &info)
std::ostream &operator<<(std::ostream &out, const ChatInfo &info)
{
out << "ChannelInfo(TODO)";
out << "ChatInfo(TODO)";
out << std::endl;
return out;
}
std::ostream &operator<<(std::ostream &out, const ChatInfo &info)
#endif
std::ostream &operator<<(std::ostream &out, const ChannelInfo &info)
{
out << "ChatInfo(TODO)";
out << "ChannelInfo(TODO)";
out << std::endl;
return out;
}