Addition of new channels service.

* Addition of channels serialiser.
 * New channels interface.
 * Added Channels to startup code.
 * New CFG Id for serialiser.
 * Cleanup of old channels stuff from interfaces.
 * Cleanup of messages as well.
 * Changed file size to uint64_t



git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@620 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
drbob 2008-06-24 04:22:42 +00:00
parent d8def217fa
commit b9ccbd54e8
18 changed files with 964 additions and 310 deletions

View File

@ -70,6 +70,8 @@ const uint32_t CONFIG_TYPE_QBLOG = 0x0012;
const uint32_t CONFIG_TYPE_FORUMS = 0x0013;
const uint32_t CONFIG_TYPE_CHANNELS = 0x0014;
/* CACHE ID Must be at the END so that other configurations
* are loaded First (Cache Config --> Cache Loading)
*/

View File

@ -0,0 +1,120 @@
#ifndef RS_CHANNEL_GUI_INTERFACE_H
#define RS_CHANNEL_GUI_INTERFACE_H
/*
* libretroshare/src/rsiface: rschannels.h
*
* RetroShare C++ Interface.
*
* Copyright 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 <list>
#include <iostream>
#include <string>
#include "rsiface/rstypes.h"
#include "rsiface/rsdistrib.h" /* For FLAGS */
class ChannelInfo
{
public:
ChannelInfo() {}
std::string channelId;
std::wstring channelName;
std::wstring channelDesc;
uint32_t channelFlags;
uint32_t pop;
time_t lastPost;
};
class ChannelMsgInfo
{
public:
ChannelMsgInfo() {}
std::string channelId;
std::string msgId;
unsigned int msgflags;
std::wstring subject;
std::wstring msg;
time_t ts;
std::list<FileInfo> files;
uint32_t count;
uint64_t size;
};
class ChannelMsgSummary
{
public:
ChannelMsgSummary() {}
std::string channelId;
std::string msgId;
uint32_t msgflags;
std::wstring subject;
std::wstring msg;
uint32_t count; /* file count */
time_t ts;
};
std::ostream &operator<<(std::ostream &out, const ChannelInfo &info);
std::ostream &operator<<(std::ostream &out, const ChannelMsgSummary &info);
std::ostream &operator<<(std::ostream &out, const ChannelMsgInfo &info);
class RsChannels;
extern RsChannels *rsChannels;
class RsChannels
{
public:
RsChannels() { return; }
virtual ~RsChannels() { return; }
/****************************************/
virtual bool channelsChanged(std::list<std::string> &chanIds) = 0;
virtual std::string createChannel(std::wstring chanName, std::wstring chanDesc, uint32_t chanFlags) = 0;
virtual bool getChannelInfo(std::string cId, ChannelInfo &ci) = 0;
virtual bool getChannelList(std::list<ChannelInfo> &chanList) = 0;
virtual bool getChannelMsgList(std::string cId, std::list<ChannelMsgSummary> &msgs) = 0;
virtual bool getChannelMessage(std::string cId, std::string mId, ChannelMsgInfo &msg) = 0;
virtual bool ChannelMessageSend(ChannelMsgInfo &info) = 0;
virtual bool channelSubscribe(std::string cId, bool subscribe) = 0;
/****************************************/
};
#endif

View File

@ -100,21 +100,6 @@ virtual void unlockData() = 0;
const PersonInfo *getPerson(std::string id);
const DirInfo *getDirectory(std::string id, std::string path);
const std::map<RsChanId, ChannelInfo> &getChannels()
{ return mChannelMap; }
const std::map<RsChanId, ChannelInfo> &getOurChannels()
{ return mChannelOwnMap; }
//const MessageInfo *getChannelMsg(std::string chId, std::string mId);
//std::list<ChatInfo> getChatNew()
// {
// std::list<ChatInfo> newList = mChatList;
// mChatList.clear();
// return newList;
// }
const std::list<FileInfo> &getRecommendList()
{ return mRecommendList; }
@ -160,10 +145,6 @@ void fillLists(); /* create some dummy data to display */
std::list<PersonInfo> mRemoteDirList;
std::list<PersonInfo> mLocalDirList;
std::list<FileTransferInfo> mTransferList;
//std::list<MessageInfo> mMessageList;
std::map<RsChanId, ChannelInfo> mChannelMap;
std::map<RsChanId, ChannelInfo> mChannelOwnMap;
//std::list<ChatInfo> mChatList;
std::list<FileInfo> mRecommendList;
bool mChanged[NumOfFlags];
@ -218,20 +199,6 @@ virtual int FileCancel(std::string fname, std::string hash, uint32_t size) = 0;
virtual int FileClearCompleted() = 0;
virtual int FileSetBandwidthTotals(float outkB, float inkB) = 0;
/****************************************/
/* Message Items */
//virtual int MessageSend(MessageInfo &info) = 0;
//virtual int MessageDelete(std::string mid) = 0;
//virtual int MessageRead(std::string mid) = 0;
/* Channel Items */
virtual int ChannelCreateNew(ChannelInfo &info) = 0;
virtual int ChannelSendMsg(ChannelInfo &info) = 0;
/****************************************/
/* Chat */
//virtual int ChatSend(ChatInfo &ci) = 0;
/****************************************/
/* Flagging Persons / Channels / Files in or out of a set (CheckLists) */

View File

@ -75,8 +75,8 @@ static const int kRsFiStatusDone = 2;
std::string hash;
std::string ext;
int size;
int avail; /* how much we have */
uint64_t size;
uint64_t avail; /* how much we have */
int status;
bool inRecommend;
@ -138,26 +138,6 @@ class FileTransferInfo: public FileInfo
int downloadStatus; /* 0 = Err, 1 = Ok, 2 = Done */
};
class ChannelInfo: public BaseInfo
{
public:
ChannelInfo() :publisher(false) {}
RsChanId chanId;
bool publisher;
std::string chanName;
//std::list<MessageInfo> msglist;
/* details */
int mode;
float rank;
bool inBroadcast;
bool inSubscribe;
int size; /* total of msgs */
int count; /* msg count */
};
/* matched to the uPnP states */
#define UPNP_STATE_UNINITIALISED 0
#define UPNP_STATE_UNAVAILABILE 1
@ -230,7 +210,6 @@ class SearchRequest
};
std::ostream &operator<<(std::ostream &out, const ChannelInfo &info);
std::ostream &operator<<(std::ostream &out, const PersonInfo &info);
std::ostream &print(std::ostream &out, const DirInfo &info, int indentLvl);

View File

@ -37,221 +37,6 @@ const int p3facemsgzone = 11453;
#include <sys/time.h>
#include <time.h>
/****************************************/
/****************************************/
int RsServer::ChannelCreateNew(ChannelInfo &info)
{
UpdateAllChannels();
return 1;
}
/****************************************/
/****************************************/
int RsServer::ChannelSendMsg(ChannelInfo &info)
{
UpdateAllChannels();
return 1;
}
/****************************************/
/****************************************/
int RsServer::UpdateAllChannels()
{
#ifdef PQI_USE_CHANNELS
std::list<pqichannel *> chanlist;
std::list<pqichannel *>::iterator cit;
NotifyBase &cb = getNotify();
cb.notifyListPreChange(NOTIFY_LIST_CHANNELLIST, NOTIFY_TYPE_MOD);
RsIface &iface = getIface();
/* lock Mutexes */
lockRsCore(); /* LOCK */
iface.lockData(); /* LOCK */
std::map<RsChanId, ChannelInfo> &chs = iface.mChannelMap;
server->getAvailableChannels(chanlist);
/* empty the old list */
chs.clear();
for(cit = chanlist.begin(); cit != chanlist.end(); ++cit)
{
ChannelInfo ci;
initRsCI(*cit, ci);
intAddChannel(ci);
{
std::ostringstream out;
out << "fltkserver::UpdateAllChannels() Added: ";
out << ci;
pqioutput(PQL_DEBUG_BASIC, p3facemsgzone, out.str());
}
/* then add msgs */
std::list<chanMsgSummary> summarylist;
std::list<chanMsgSummary>::iterator mit;
channelSign sign = (*cit)->getSign();
server->getChannelMsgList(sign, summarylist);
for(mit = summarylist.begin(); mit != summarylist.end(); mit++)
{
channelMsg *cm = NULL;
cm = server->getChannelMsg(sign, mit->mh);
MessageInfo msg;
initRsCMI(*cit, cm, msg);
// the files....
PQChanItem::FileList::const_iterator it;
for(it = cm->msg->files.begin(); it != cm->msg->files.end(); ++it)
{
FileInfo file;
/* add to the message */
//ChanFileDisItem *cfdi = new ChanFileDisItem(it->name, it->size);
initRsCMFI(*cit, &(*mit), &(*it), file);
msg.files.push_back(file);
msg.size += file.size;
msg.count++;
} // files loop.
ci.size += msg.size;
ci.count += ci.count;
/* add the Msg? */
intAddChannelMsg(ci.chanId, msg);
} // msg loop
} // channel loop.
/* Notify of Changes */
iface.setChanged(RsIface::Channel);
/* release Mutexes */
iface.unlockData(); /* UNLOCK */
unlockRsCore(); /* UNLOCK */
cb.notifyListChange(NOTIFY_LIST_CHANNELLIST, NOTIFY_TYPE_MOD);
#endif
return 1;
}
/**** HELPER FNS For Chat/Msg/Channel Lists ************
*
* The iface->Mutex is required to be locked
* for intAddChannel / intAddChannelMsg.
*/
#ifdef PQI_USE_CHANNELS
int RsServer::intAddChannel(ChannelInfo &info)
{
RsIface &iface = getIface();
std::map<RsChanId, ChannelInfo> &chs = iface.mChannelMap;
chs[info.chanId] = info;
return 1;
}
int RsServer::intAddChannelMsg(RsChanId id, MessageInfo &msg)
{
RsIface &iface = getIface();
std::map<RsChanId, ChannelInfo> &chs = iface.mChannelMap;
std::map<RsChanId, ChannelInfo>::iterator it = chs.find(id);
if (it != chs.end())
{
/* add the message */
/*
std::map<MsgId, MessageInfo> &msgs =
it -> second.msglist;
msgs[MsgId] = msg;
*/
std::list<MessageInfo> &msgs =
it -> second.msglist;
msgs.push_back(msg);
}
return 1;
}
RsChanId RsServer::signToChanId(const channelSign &cs) const
{
/* hackish here */
RsChanId id;
int i;
for(i = 0; i < CHAN_SIGN_SIZE; i++) /* 16 Bytes XXX Must be equal! */
id.data[i] = cs.sign[i];
return id;
}
void RsServer::initRsCI(pqichannel *in, ChannelInfo &out)
{
out.chanId = signToChanId(in -> getSign());
out.mode = in -> getMode();
out.rank = in -> getRanking();
out.chanName = in -> getName();
out.count = in -> getMsgCount();
/*
out.size = in -> getMsgSize();
*/
}
void RsServer::initRsCMI(pqichannel *chan, channelMsg *cm, MessageInfo &msg)
{
msg.title = cm->msg->title;
msg.msg = cm->msg->msg;
int i;
MsgHash h = getMsgHash(cm->msg); /* call from p3channel.h */
/* Copy MsgId over */
for(i = 0; i < CHAN_SIGN_SIZE; i++) /* 16 Bytes XXX Must be equal! */
msg.msgId.data[i] = h.sign[i];
/* init size to zero */
msg.size = 0;
msg.count = 0;
}
void RsServer::initRsCMFI(pqichannel *chan, chanMsgSummary *msg,
const PQChanItem::FileItem *cfdi,
FileInfo &file)
{
file.searchId = 0;
file.path = "";
file.fname = cfdi -> name;
file.hash = cfdi -> hash;
file.ext = "";
file.size = cfdi -> size;
file.inRecommend = false;
/* check the status */
file.status = FileInfo::kRsFiStatusNone;
/* cfdi -> status; */
if (file.status > FileInfo::kRsFiStatusNone)
{
intCheckFileStatus(file);
}
else
{
file.avail = 0;
file.rank = 0;
}
}
#endif
void RsServer::intCheckFileStatus(FileInfo &file)
{

View File

@ -192,9 +192,6 @@ void RsServer::run()
//std::cerr << "RsServer::run() UpdateAllTransfers()" << std::endl;
UpdateAllTransfers();
//std::cerr << "RsServer::run() UpdateAllChannels()" << std::endl;
UpdateAllChannels();
//std::cerr << "RsServer::run() ";
//std::cerr << "UpdateRemotePeople()"<<std::endl;
//UpdateRemotePeople();

View File

@ -49,6 +49,7 @@
#include "services/p3ranking.h"
#include "services/p3photoservice.h"
#include "services/p3forums.h"
#include "services/p3channels.h"
#include "services/p3status.h"
#include "services/p3Qblog.h"
@ -613,6 +614,14 @@ int RsServer::StartupRetroShare(RsInit *config)
mCacheStrapper -> addCachePair(cp4);
pqih -> addService(mForums); /* This must be also ticked as a service */
p3Channels *mChannels = new p3Channels(RS_SERVICE_TYPE_CHANNEL,
mCacheStrapper, mCacheTransfer,
localcachedir, remotecachedir, localcachedir);
CachePair cp5(mChannels, mChannels, CacheId(RS_SERVICE_TYPE_CHANNEL, 0));
mCacheStrapper -> addCachePair(cp5);
pqih -> addService(mChannels); /* This must be also ticked as a service */
#else
mQblog = NULL;
//mForums = NULL;
@ -641,6 +650,7 @@ int RsServer::StartupRetroShare(RsInit *config)
mConfigMgr->addConfiguration("ranklink.cfg", mRanking);
#ifndef RS_RELEASE
mConfigMgr->addConfiguration("forums.cfg", mForums);
mConfigMgr->addConfiguration("channels.cfg", mChannels);
#endif
/**************************************************************************/
@ -770,6 +780,7 @@ int RsServer::StartupRetroShare(RsInit *config)
rsGameLauncher = gameLauncher;
rsPhoto = new p3Photo(photoService);
rsForums = mForums;
rsChannels = mChannels;
rsStatus = new p3Status();
rsQblog = new p3Blog(mQblog);
@ -777,6 +788,7 @@ int RsServer::StartupRetroShare(RsInit *config)
rsGameLauncher = NULL;
rsPhoto = NULL;
rsForums = NULL;
rsChannels = NULL;
rsStatus = NULL;
rsQblog = NULL;
#endif

View File

@ -162,10 +162,6 @@ int UpdateRemotePeople();
/* p3face-msg Operations */
public:
/* Channel Items */
virtual int ChannelCreateNew(ChannelInfo &info);
virtual int ChannelSendMsg(ChannelInfo &info);
/* 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 */
@ -186,26 +182,6 @@ virtual bool IsInMsg(std::string id); /* friend : msg recpts*/
std::list<std::string> mInChatList, mInMsgList;
/* Internal Update Iface Fns */
int UpdateAllChannels();
#ifdef PQI_USE_CHANNELS
/* Internal Helper Fns */
RsChanId signToChanId(const channelSign &cs) const;
int intAddChannel(ChannelInfo &info);
int intAddChannelMsg(RsChanId id, MessageInfo &msg);
void initRsCI(pqichannel *in, ChannelInfo &out);
void initRsCMI(pqichannel *chan, channelMsg *cm, MessageInfo &msg);
void initRsCMFI(pqichannel *chan, chanMsgSummary *msg,
const PQChanItem::FileItem *cfdi, FileInfo &file);
#endif
void intCheckFileStatus(FileInfo &file);
void initRsMI(RsMsgItem *msg, MessageInfo &mi);

View File

@ -25,8 +25,6 @@
*/
#include "rsserver/p3face.h"
#include "util/rsdir.h"
#include <iostream>
#include <sstream>
@ -37,8 +35,13 @@ const int p3facemsgzone = 11453;
#include <sys/time.h>
#include <time.h>
#include "rsiface/rstypes.h"
#include "util/rsdir.h"
#include "rsserver/p3msgs.h"
#include "services/p3msgservice.h"
#include "services/p3chatservice.h"
/* external reference point */
RsMsgs *rsMsgs = NULL;

View File

@ -32,6 +32,8 @@ class p3AuthMgr;
class p3MsgService;
class p3ChatService;
class RsChatItem;
class p3Msgs: public RsMsgs
{
public:

View File

@ -107,15 +107,6 @@ std::ostream &operator<<(std::ostream &out, const ChatInfo &info)
#endif
std::ostream &operator<<(std::ostream &out, const ChannelInfo &info)
{
out << "ChannelInfo(TODO)";
out << std::endl;
return out;
}
int DirInfo::merge(const DirInfo &udir)
{
/* add in the data from the udir */

View File

@ -18,6 +18,7 @@ RSOBJ += rsphotoitems.o # RsItems
RSOBJ += rsgameitems.o # RsItems
RSOBJ += rsdistribitems.o # RsItems
RSOBJ += rsforumitems.o # RsItems
RSOBJ += rschannelitems.o # RsItems
RSOBJ += rsqblogitems.o # RsItems
RSOBJ += rsstatusitems.o # RsItems

View File

@ -0,0 +1,214 @@
/*
* libretroshare/src/serialiser: rschannelitems.cc
*
* RetroShare Serialiser.
*
* Copyright 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 "serialiser/rschannelitems.h"
#include "serialiser/rsbaseserial.h"
#include "serialiser/rstlvbase.h"
#define RSSERIAL_DEBUG 1
#include <iostream>
/*************************************************************************/
void RsChannelMsg::clear()
{
RsDistribMsg::clear();
subject.clear();
message.clear();
attachment.TlvClear();
}
std::ostream &RsChannelMsg::print(std::ostream &out, uint16_t indent)
{
printRsItemBase(out, "RsChannelMsg", indent);
uint16_t int_Indent = indent + 2;
RsDistribMsg::print(out, int_Indent);
printIndent(out, int_Indent);
std::string cnv_subject(subject.begin(), subject.end());
out << "subject: " << cnv_subject << std::endl;
printIndent(out, int_Indent);
std::string cnv_message(message.begin(), message.end());
out << "message: " << cnv_message << std::endl;
printIndent(out, int_Indent);
out << "Attachment: " << std::endl;
attachment.print(out, int_Indent);
printRsItemEnd(out, "RsChannelMsg", indent);
return out;
}
/*************************************************************************/
/*************************************************************************/
uint32_t RsChannelSerialiser::sizeMsg(RsChannelMsg *item)
{
uint32_t s = 8; /* header */
/* RsDistribMsg stuff */
s += GetTlvStringSize(item->grpId);
s += 4; /* timestamp */
/* RsChannelMsg stuff */
s += GetTlvWideStringSize(item->subject);
s += GetTlvWideStringSize(item->message);
s += item->attachment.TlvSize();
return s;
}
/* serialise the data to the buffer */
bool RsChannelSerialiser::serialiseMsg(RsChannelMsg *item, void *data, uint32_t *pktsize)
{
uint32_t tlvsize = sizeMsg(item);
uint32_t offset = 0;
if (*pktsize < tlvsize)
return false; /* not enough space */
*pktsize = tlvsize;
bool ok = true;
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
std::cerr << "RsChannelSerialiser::serialiseMsg() Header: " << ok << std::endl;
std::cerr << "RsChannelSerialiser::serialiseMsg() Size: " << tlvsize << std::endl;
/* skip the header */
offset += 8;
/* RsDistribMsg first */
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_GROUPID, item->grpId);
std::cerr << "RsChannelSerialiser::serialiseMsg() grpId: " << ok << std::endl;
ok &= setRawUInt32(data, tlvsize, &offset, item->timestamp);
std::cerr << "RsChannelSerialiser::serialiseMsg() timestamp: " << ok << std::endl;
/* RsChannelMsg */
ok &= SetTlvWideString(data, tlvsize, &offset, TLV_TYPE_WSTR_SUBJECT, item->subject);
std::cerr << "RsChannelSerialiser::serialiseMsg() Title: " << ok << std::endl;
ok &= SetTlvWideString(data, tlvsize, &offset, TLV_TYPE_WSTR_MSG, item->message);
std::cerr << "RsChannelSerialiser::serialiseMsg() Msg: " << ok << std::endl;
ok &= item->attachment.SetTlv(data, tlvsize, &offset);
std::cerr << "RsChannelSerialiser::serialiseMsg() Attachment: " << ok << std::endl;
if (offset != tlvsize)
{
ok = false;
std::cerr << "RsChannelSerialiser::serialiseMsg() Size Error! " << std::endl;
}
return ok;
}
RsChannelMsg *RsChannelSerialiser::deserialiseMsg(void *data, uint32_t *pktsize)
{
/* get the type and size */
uint32_t rstype = getRsItemId(data);
uint32_t rssize = getRsItemSize(data);
uint32_t offset = 0;
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
(RS_SERVICE_TYPE_CHANNEL != getRsItemService(rstype)) ||
(RS_PKT_SUBTYPE_CHANNEL_MSG != getRsItemSubType(rstype)))
{
return NULL; /* wrong type */
}
if (*pktsize < rssize) /* check size */
return NULL; /* not enough data */
/* set the packet length */
*pktsize = rssize;
bool ok = true;
/* ready to load */
RsChannelMsg *item = new RsChannelMsg();
item->clear();
/* skip the header */
offset += 8;
/* RsDistribMsg first */
ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_GROUPID, item->grpId);
ok &= getRawUInt32(data, rssize, &offset, &(item->timestamp));
/* RsChannelMsg */
ok &= GetTlvWideString(data, rssize, &offset, TLV_TYPE_WSTR_SUBJECT, item->subject);
ok &= GetTlvWideString(data, rssize, &offset, TLV_TYPE_WSTR_MSG, item->message);
ok &= item->attachment.GetTlv(data, rssize, &offset);
if (offset != rssize)
{
/* error */
delete item;
return NULL;
}
if (!ok)
{
delete item;
return NULL;
}
return item;
}
uint32_t RsChannelSerialiser::size(RsItem *item)
{
return sizeMsg((RsChannelMsg *) item);
}
bool RsChannelSerialiser::serialise(RsItem *item, void *data, uint32_t *pktsize)
{
return serialiseMsg((RsChannelMsg *) item, data, pktsize);
}
RsItem *RsChannelSerialiser::deserialise(void *data, uint32_t *pktsize)
{
return deserialiseMsg(data, pktsize);
}
/*************************************************************************/

View File

@ -0,0 +1,91 @@
#ifndef RS_CHANNEL_ITEMS_H
#define RS_CHANNEL_ITEMS_H
/*
* libretroshare/src/serialiser: rschannelitems.h
*
* RetroShare Serialiser.
*
* 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 <map>
#include "serialiser/rsserviceids.h"
#include "serialiser/rsserial.h"
#include "serialiser/rstlvtypes.h"
#include "serialiser/rstlvkeys.h"
#include "serialiser/rsdistribitems.h"
const uint8_t RS_PKT_SUBTYPE_CHANNEL_MSG = 0x01;
/**************************************************************************/
class RsChannelMsg: public RsDistribMsg
{
public:
RsChannelMsg()
:RsDistribMsg(RS_SERVICE_TYPE_CHANNEL, RS_PKT_SUBTYPE_CHANNEL_MSG) { return; }
virtual ~RsChannelMsg() { return; }
virtual void clear();
virtual std::ostream& print(std::ostream &out, uint16_t indent = 0);
/*
* RsDistribMsg has:
* grpId, timestamp.
* Not Used: parentId, threadId
*/
std::wstring subject;
std::wstring message;
RsTlvFileSet attachment;
};
class RsChannelSerialiser: public RsSerialType
{
public:
RsChannelSerialiser()
:RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_CHANNEL)
{ return; }
virtual ~RsChannelSerialiser()
{ return; }
virtual uint32_t size(RsItem *);
virtual bool serialise (RsItem *item, void *data, uint32_t *size);
virtual RsItem * deserialise(void *data, uint32_t *size);
private:
/* For RS_PKT_SUBTYPE_CHANNEL_MSG */
virtual uint32_t sizeMsg(RsChannelMsg *);
virtual bool serialiseMsg(RsChannelMsg *item, void *data, uint32_t *size);
virtual RsChannelMsg *deserialiseMsg(void *data, uint32_t *size);
};
/**************************************************************************/
#endif /* RS_CHANNEL_ITEMS_H */

View File

@ -13,7 +13,8 @@ RSOBJ = p3service.o p3chatservice.o p3msgservice.o \
p3distrib.o \
p3status.o \
p3Qblog.o \
p3forums.o
p3forums.o \
p3channels.o
# dummy forums interface.
# p3forums-dummy.o \

View File

@ -0,0 +1,423 @@
/*
* libretroshare/src/services: p3channels.cc
*
* RetroShare C++ Interface.
*
* Copyright 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 "services/p3channels.h"
#include "util/rsdir.h"
std::ostream &operator<<(std::ostream &out, const ChannelInfo &info)
{
std::string name(info.channelName.begin(), info.channelName.end());
std::string desc(info.channelDesc.begin(), info.channelDesc.end());
out << "ChannelInfo:";
out << std::endl;
out << "ChannelId: " << info.channelId << std::endl;
out << "ChannelName: " << name << std::endl;
out << "ChannelDesc: " << desc << std::endl;
out << "ChannelFlags: " << info.channelFlags << std::endl;
out << "Pop: " << info.pop << std::endl;
out << "LastPost: " << info.lastPost << std::endl;
return out;
}
std::ostream &operator<<(std::ostream &out, const ChannelMsgSummary &info)
{
out << "ChannelMsgSummary:";
out << std::endl;
out << "ChannelId: " << info.channelId << std::endl;
return out;
}
std::ostream &operator<<(std::ostream &out, const ChannelMsgInfo &info)
{
out << "ChannelMsgInfo:";
out << std::endl;
out << "ChannelId: " << info.channelId << std::endl;
return out;
}
RsChannels *rsChannels = NULL;
#define CHANNEL_STOREPERIOD 10000
#define CHANNEL_PUBPERIOD 600
p3Channels::p3Channels(uint16_t type, CacheStrapper *cs, CacheTransfer *cft,
std::string srcdir, std::string storedir, std::string chanDir)
:p3GroupDistrib(type, cs, cft, srcdir, storedir,
CONFIG_TYPE_CHANNELS, CHANNEL_STOREPERIOD, CHANNEL_PUBPERIOD),
mChannelsDir(chanDir)
{
//loadDummyData();
return;
}
p3Channels::~p3Channels()
{
return;
}
/****************************************/
bool p3Channels::channelsChanged(std::list<std::string> &chanIds)
{
return groupsChanged(chanIds);
}
bool p3Channels::getChannelInfo(std::string cId, ChannelInfo &ci)
{
RsStackMutex stack(distribMtx); /***** STACK LOCKED MUTEX *****/
/* extract details */
GroupInfo *gi = locked_getGroupInfo(cId);
if (!gi)
return false;
ci.channelId = gi->grpId;
ci.channelName = gi->grpName;
ci.channelDesc = gi->grpDesc;
ci.channelFlags = gi->flags;
ci.pop = gi->sources.size();
ci.lastPost = gi->lastPost;
return true;
}
bool p3Channels::getChannelList(std::list<ChannelInfo> &channelList)
{
std::list<std::string> grpIds;
std::list<std::string>::iterator it;
getAllGroupList(grpIds);
for(it = grpIds.begin(); it != grpIds.end(); it++)
{
ChannelInfo ci;
if (getChannelInfo(*it, ci))
{
channelList.push_back(ci);
}
}
return true;
}
bool p3Channels::getChannelMsgList(std::string cId, std::list<ChannelMsgSummary> &msgs)
{
std::list<std::string> msgIds;
std::list<std::string>::iterator it;
getAllMsgList(cId, msgIds);
RsStackMutex stack(distribMtx); /***** STACK LOCKED MUTEX *****/
for(it = msgIds.begin(); it != msgIds.end(); it++)
{
/* get details */
RsDistribMsg *msg = locked_getGroupMsg(cId, *it);
RsChannelMsg *cmsg = dynamic_cast<RsChannelMsg *>(msg);
if (!cmsg)
continue;
ChannelMsgSummary tis;
tis.channelId = msg->grpId;
tis.msgId = msg->msgId;
tis.ts = msg->timestamp;
/* the rest must be gotten from the derived Msg */
tis.subject = cmsg->subject;
tis.msg = cmsg->message;
tis.count = cmsg->attachment.items.size();
msgs.push_back(tis);
}
return true;
}
bool p3Channels::getChannelMessage(std::string fId, std::string mId, ChannelMsgInfo &info)
{
std::list<std::string> msgIds;
std::list<std::string>::iterator it;
RsStackMutex stack(distribMtx); /***** STACK LOCKED MUTEX *****/
RsDistribMsg *msg = locked_getGroupMsg(fId, mId);
RsChannelMsg *cmsg = dynamic_cast<RsChannelMsg *>(msg);
if (!cmsg)
return false;
info.channelId = msg->grpId;
info.msgId = msg->msgId;
info.ts = msg->timestamp;
/* the rest must be gotten from the derived Msg */
info.subject = cmsg->subject;
info.msg = cmsg->message;
std::list<RsTlvFileItem>::iterator fit;
for(fit = cmsg->attachment.items.begin();
fit != cmsg->attachment.items.end(); fit++)
{
FileInfo fi;
fi.fname = RsDirUtil::getTopDir(fit->name);
fi.size = fit->filesize;
fi.hash = fit->hash;
fi.path = fit->path;
info.files.push_back(fi);
info.count++;
info.size += fi.size;
}
return true;
}
bool p3Channels::ChannelMessageSend(ChannelMsgInfo &info)
{
RsChannelMsg *cmsg = new RsChannelMsg();
cmsg->grpId = info.channelId;
cmsg->subject = info.subject;
cmsg->message = info.msg;
cmsg->timestamp = time(NULL);
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;
cmsg -> attachment.items.push_back(mfi);
}
std::string msgId = publishMsg(cmsg, true);
return true;
}
std::string p3Channels::createChannel(std::wstring channelName, std::wstring channelDesc, uint32_t channelFlags)
{
std::string id = createGroup(channelName, channelDesc, channelFlags);
return id;
}
RsSerialType *p3Channels::createSerialiser()
{
return new RsChannelSerialiser();
}
bool p3Channels::locked_checkDistribMsg(RsDistribMsg *msg)
{
return true;
}
RsDistribGrp *p3Channels::locked_createPublicDistribGrp(GroupInfo &info)
{
RsDistribGrp *grp = NULL; //new RsChannelGrp();
return grp;
}
RsDistribGrp *p3Channels::locked_createPrivateDistribGrp(GroupInfo &info)
{
RsDistribGrp *grp = NULL; //new RsChannelGrp();
return grp;
}
bool p3Channels::channelSubscribe(std::string cId, bool subscribe)
{
return subscribeToGroup(cId, subscribe);
}
/***************************************************************************************/
/****************** Event Feedback (Overloaded form p3distrib) *************************/
/***************************************************************************************/
#include "pqi/pqinotify.h"
bool p3Channels::locked_eventUpdateGroup(GroupInfo *info, bool isNew)
{
std::string grpId = info->grpId;
std::string msgId;
std::string nullId;
if (isNew)
{
getPqiNotify()->AddFeedItem(RS_FEED_ITEM_CHAN_NEW, grpId, msgId, nullId);
}
else
{
getPqiNotify()->AddFeedItem(RS_FEED_ITEM_CHAN_UPDATE, grpId, msgId, nullId);
}
return true;
}
bool p3Channels::locked_eventNewMsg(RsDistribMsg *msg)
{
std::string grpId = msg->grpId;
std::string msgId = msg->msgId;
std::string nullId;
getPqiNotify()->AddFeedItem(RS_FEED_ITEM_CHAN_MSG, grpId, msgId, nullId);
return true;
}
/****************************************/
#if 0
void p3Channels::loadDummyData()
{
ChannelInfo fi;
std::string channelId;
std::string msgId;
time_t now = time(NULL);
fi.channelId = "FID1234";
fi.channelName = L"Channel 1";
fi.channelDesc = L"Channel 1";
fi.channelFlags = RS_DISTRIB_ADMIN;
fi.pop = 2;
fi.lastPost = now - 123;
channelId = createChannel(fi.channelName, fi.channelDesc, fi.channelFlags);
fi.channelId = "FID2345";
fi.channelName = L"Channel 2";
fi.channelDesc = L"Channel 2";
fi.channelFlags = RS_DISTRIB_SUBSCRIBED;
fi.pop = 3;
fi.lastPost = now - 1234;
channelId = createChannel(fi.channelName, fi.channelDesc, fi.channelFlags);
msgId = createChannelMsg(channelId, "", L"WELCOME TO Channel1", L"Hello!");
msgId = createChannelMsg(channelId, msgId, L"Love this channel", L"Hello2!");
return;
/* ignore this */
fi.channelId = "FID3456";
fi.channelName = L"Channel 3";
fi.channelDesc = L"Channel 3";
fi.channelFlags = 0;
fi.pop = 3;
fi.lastPost = now - 1234;
channelId = createChannel(fi.channelName, fi.channelDesc, fi.channelFlags);
fi.channelId = "FID4567";
fi.channelName = L"Channel 4";
fi.channelDesc = L"Channel 4";
fi.channelFlags = 0;
fi.pop = 5;
fi.lastPost = now - 1234;
channelId = createChannel(fi.channelName, fi.channelDesc, fi.channelFlags);
fi.channelId = "FID5678";
fi.channelName = L"Channel 5";
fi.channelDesc = L"Channel 5";
fi.channelFlags = 0;
fi.pop = 1;
fi.lastPost = now - 1234;
channelId = createChannel(fi.channelName, fi.channelDesc, fi.channelFlags);
fi.channelId = "FID6789";
fi.channelName = L"Channel 6";
fi.channelDesc = L"Channel 6";
fi.channelFlags = 0;
fi.pop = 2;
fi.lastPost = now - 1234;
channelId = createChannel(fi.channelName, fi.channelDesc, fi.channelFlags);
fi.channelId = "FID7890";
fi.channelName = L"Channel 7";
fi.channelDesc = L"Channel 7";
fi.channelFlags = 0;
fi.pop = 4;
fi.lastPost = now - 1234;
channelId = createChannel(fi.channelName, fi.channelDesc, fi.channelFlags);
fi.channelId = "FID8901";
fi.channelName = L"Channel 8";
fi.channelDesc = L"Channel 8";
fi.channelFlags = 0;
fi.pop = 3;
fi.lastPost = now - 1234;
channelId = createChannel(fi.channelName, fi.channelDesc, fi.channelFlags);
fi.channelId = "FID9012";
fi.channelName = L"Channel 9";
fi.channelDesc = L"Channel 9";
fi.channelFlags = 0;
fi.pop = 2;
fi.lastPost = now - 1234;
channelId = createChannel(fi.channelName, fi.channelDesc, fi.channelFlags);
fi.channelId = "FID9123";
fi.channelName = L"Channel 10";
fi.channelDesc = L"Channel 10";
fi.channelFlags = 0;
fi.pop = 1;
fi.lastPost = now - 1234;
channelId = createChannel(fi.channelName, fi.channelDesc, fi.channelFlags);
mChannelsChanged = true;
}
#endif

View File

@ -0,0 +1,86 @@
#ifndef RS_P3_CHANNELS_INTERFACE_H
#define RS_P3_CHANNELS_INTERFACE_H
/*
* libretroshare/src/services: p3channels.h
*
* RetroShare C++ Interface.
*
* Copyright 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/rschannels.h"
#include "services/p3distrib.h"
#include "serialiser/rstlvtypes.h"
#include "serialiser/rschannelitems.h"
class p3Channels: public p3GroupDistrib, public RsChannels
{
public:
p3Channels(uint16_t type, CacheStrapper *cs, CacheTransfer *cft,
std::string srcdir, std::string storedir, std::string channelsdir);
virtual ~p3Channels();
/****************************************/
/********* rsChannels Interface ***********/
virtual bool channelsChanged(std::list<std::string> &chanIds);
virtual std::string createChannel(std::wstring chanName, std::wstring chanDesc, uint32_t chanFlags);
virtual bool getChannelInfo(std::string cId, ChannelInfo &ci);
virtual bool getChannelList(std::list<ChannelInfo> &chanList);
virtual bool getChannelMsgList(std::string cId, std::list<ChannelMsgSummary> &msgs);
virtual bool getChannelMessage(std::string cId, std::string mId, ChannelMsgInfo &msg);
virtual bool ChannelMessageSend(ChannelMsgInfo &info);
virtual bool channelSubscribe(std::string cId, bool subscribe);
/***************************************************************************************/
/****************** Event Feedback (Overloaded form p3distrib) *************************/
/***************************************************************************************/
virtual bool locked_eventUpdateGroup(GroupInfo *, bool isNew);
virtual bool locked_eventNewMsg(RsDistribMsg *);
/****************************************/
/********* Overloaded Functions *********/
virtual RsSerialType *createSerialiser();
virtual bool locked_checkDistribMsg(RsDistribMsg *msg);
virtual RsDistribGrp *locked_createPublicDistribGrp(GroupInfo &info);
virtual RsDistribGrp *locked_createPrivateDistribGrp(GroupInfo &info);
/****************************************/
private:
std::string mChannelsDir;
};
#endif

View File

@ -35,6 +35,10 @@
#include "pqi/pqi.h"
#include "pqi/pqiindic.h"
#include "pqi/pqimonitor.h"
#include "pqi/p3cfgmgr.h"
#include "services/p3service.h"
#include "serialiser/rsmsgitems.h"
#include "util/rsthreads.h"