mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-12-15 10:54:22 -05:00
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@2181 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
572d2c198d
commit
7fc84d7ceb
150
libretroshare/src/rsiface/rsblogs.h
Normal file
150
libretroshare/src/rsiface/rsblogs.h
Normal file
@ -0,0 +1,150 @@
|
||||
#ifndef RS_BLOG_GUI_INTERFACE_H
|
||||
#define RS_BLOG_GUI_INTERFACE_H
|
||||
|
||||
/*
|
||||
* libretroshare/src/rsiface: rsblogs.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 BlogInfo
|
||||
{
|
||||
public:
|
||||
BlogInfo() {}
|
||||
std::string blogId;
|
||||
std::wstring blogName;
|
||||
std::wstring blogDesc;
|
||||
|
||||
uint32_t blogFlags;
|
||||
uint32_t pop;
|
||||
|
||||
time_t lastPost;
|
||||
};
|
||||
|
||||
class BlogMsgInfo
|
||||
{
|
||||
public:
|
||||
BlogMsgInfo() {}
|
||||
std::string blogId;
|
||||
std::string msgId;
|
||||
/// this has a value if replying to another msg
|
||||
std::string msgIdReply;
|
||||
|
||||
unsigned int msgflags;
|
||||
|
||||
std::wstring subject;
|
||||
std::wstring msg;
|
||||
time_t ts;
|
||||
|
||||
std::list<FileInfo> files;
|
||||
uint32_t count;
|
||||
uint64_t size;
|
||||
};
|
||||
|
||||
|
||||
class BlogMsgSummary
|
||||
{
|
||||
public:
|
||||
BlogMsgSummary() {}
|
||||
std::string blogId;
|
||||
std::string msgId;
|
||||
|
||||
uint32_t msgflags;
|
||||
|
||||
std::wstring subject;
|
||||
std::wstring msg;
|
||||
std::string msgIdReply;
|
||||
uint32_t count; /* file count */
|
||||
time_t ts;
|
||||
|
||||
};
|
||||
|
||||
std::ostream &operator<<(std::ostream &out, const BlogInfo &info);
|
||||
std::ostream &operator<<(std::ostream &out, const BlogMsgSummary &info);
|
||||
std::ostream &operator<<(std::ostream &out, const BlogMsgInfo &info);
|
||||
|
||||
class RsBlogs;
|
||||
extern RsBlogs *rsBlogs;
|
||||
|
||||
class RsBlogs
|
||||
{
|
||||
public:
|
||||
|
||||
RsBlogs() { return; }
|
||||
virtual ~RsBlogs() { return; }
|
||||
|
||||
/****************************************/
|
||||
|
||||
/*!
|
||||
* Checks if the group a blod id belongs to has changed
|
||||
*/
|
||||
virtual bool blogsChanged(std::list<std::string> &blogIds) = 0;
|
||||
|
||||
|
||||
virtual std::string createBlog(std::wstring blogName, std::wstring blogDesc, uint32_t blogFlags) = 0;
|
||||
|
||||
virtual bool getBlogInfo(std::string cId, BlogInfo &ci) = 0;
|
||||
virtual bool getBlogList(std::list<BlogInfo> &chanList) = 0;
|
||||
virtual bool getBlogMsgList(std::string cId, std::list<BlogMsgSummary> &msgs) = 0;
|
||||
|
||||
/*!
|
||||
* Retrieves a specific blog Msg based on group Id and message Id
|
||||
*/
|
||||
virtual bool getBlogMessage(std::string cId, std::string mId, BlogMsgInfo &msg) = 0;
|
||||
|
||||
/*!
|
||||
* Can send blog message to user
|
||||
* @param info the message
|
||||
*/
|
||||
virtual bool BlogMessageSend(BlogMsgInfo &info) = 0;
|
||||
|
||||
/*!
|
||||
* Allows user to subscribe to a blog via group ID
|
||||
* @param cId group id
|
||||
* @param subscribe determine subscription based on value
|
||||
*/
|
||||
virtual bool blogSubscribe(std::string cId, bool subscribe) = 0;
|
||||
|
||||
/*!
|
||||
* Commenting on other user's blogs, ensure field info has a valid info.msgIdReply has valid msg id, this
|
||||
* points to which message the blog reply is replying to
|
||||
*/
|
||||
virtual bool BlogMessageReply(BlogMsgInfo &info) = 0;
|
||||
|
||||
/*!
|
||||
*
|
||||
*/
|
||||
virtual bool isReply(BlogMsgInfo &info) = 0;
|
||||
/****************************************/
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif
|
228
libretroshare/src/serialiser/rsblogitems.cc
Normal file
228
libretroshare/src/serialiser/rsblogitems.cc
Normal file
@ -0,0 +1,228 @@
|
||||
|
||||
/*
|
||||
* libretroshare/src/serialiser: rsblogitems.cc
|
||||
*
|
||||
* RetroShare Serialiser.
|
||||
*
|
||||
* Copyright 2010 by Cyril, Chris Parker .
|
||||
*
|
||||
* 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/rsblogitems.h"
|
||||
|
||||
#include "serialiser/rsbaseserial.h"
|
||||
#include "serialiser/rstlvbase.h"
|
||||
|
||||
#define RSSERIAL_DEBUG 1
|
||||
#include <iostream>
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
void RsBlogMsg::clear()
|
||||
{
|
||||
RsDistribMsg::clear();
|
||||
|
||||
subject.clear();
|
||||
message.clear();
|
||||
mIdReply.clear();
|
||||
|
||||
attachment.TlvClear();
|
||||
}
|
||||
|
||||
std::ostream &RsBlogMsg::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 << "mIdReply:" << mIdReply << std::endl;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
|
||||
out << "Attachment: " << std::endl;
|
||||
attachment.print(out, int_Indent);
|
||||
|
||||
printRsItemEnd(out, "RsBlogMsg", indent);
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
/*************************************************************************/
|
||||
/*************************************************************************/
|
||||
|
||||
uint32_t RsBlogSerialiser::sizeMsg(RsBlogMsg *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 += GetTlvStringSize(item->mIdReply);
|
||||
|
||||
s += item->attachment.TlvSize();
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
/* serialise the data to the buffer */
|
||||
bool RsBlogSerialiser::serialiseMsg(RsBlogMsg *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;
|
||||
|
||||
/* RsBlogMsg */
|
||||
ok &= SetTlvWideString(data, tlvsize, &offset, TLV_TYPE_WSTR_SUBJECT, item->subject);
|
||||
std::cerr << "RsBlogSerialiser::serialiseMsg() subject: " << ok << std::endl;
|
||||
ok &= SetTlvWideString(data, tlvsize, &offset, TLV_TYPE_WSTR_MSG, item->message);
|
||||
std::cerr << "RsBlogSerialiser::serialiseMsg() msg: " << ok << std::endl;
|
||||
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_MSG, item->mIdReply);
|
||||
std::cerr << "RsBlogSerialiser::serialiseMsg() mIdReply: " << 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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
RsBlogMsg *RsBlogSerialiser::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_QBLOG != getRsItemService(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_BLOG_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 */
|
||||
RsBlogMsg *item = new RsBlogMsg();
|
||||
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));
|
||||
|
||||
/* RsBlogMsg */
|
||||
|
||||
ok &= GetTlvWideString(data, rssize, &offset, TLV_TYPE_WSTR_SUBJECT, item->subject);
|
||||
ok &= GetTlvWideString(data, rssize, &offset, TLV_TYPE_WSTR_MSG, item->message);
|
||||
ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_MSGID, item->mIdReply);
|
||||
|
||||
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 RsBlogSerialiser::size(RsItem *item)
|
||||
{
|
||||
return sizeMsg((RsBlogMsg *) item);
|
||||
}
|
||||
|
||||
bool RsBlogSerialiser::serialise(RsItem *item, void *data, uint32_t *pktsize)
|
||||
{
|
||||
return serialiseMsg((RsBlogMsg *) item, data, pktsize);
|
||||
}
|
||||
|
||||
RsItem *RsBlogSerialiser::deserialise(void *data, uint32_t *pktsize)
|
||||
{
|
||||
return deserialiseMsg(data, pktsize);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*************************************************************************/
|
||||
|
93
libretroshare/src/serialiser/rsblogitems.h
Normal file
93
libretroshare/src/serialiser/rsblogitems.h
Normal file
@ -0,0 +1,93 @@
|
||||
#ifndef RS_BLOG_ITEMS_H
|
||||
#define RS_BLOG_ITEMS_H
|
||||
|
||||
/*
|
||||
* libretroshare/src/serialiser: rsblogitems.h
|
||||
*
|
||||
* RetroShare Serialiser.
|
||||
*
|
||||
* Copyright 2007-2008 by Cyril, Chris Parker.
|
||||
*
|
||||
* 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_BLOG_MSG = 0x01;
|
||||
|
||||
/**************************************************************************/
|
||||
|
||||
class RsBlogMsg: public RsDistribMsg
|
||||
{
|
||||
public:
|
||||
RsBlogMsg()
|
||||
:RsDistribMsg(RS_SERVICE_TYPE_QBLOG, RS_PKT_SUBTYPE_BLOG_MSG) { return; }
|
||||
virtual ~RsBlogMsg() { 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;
|
||||
/// message id to which the reply applies to
|
||||
std::string mIdReply;
|
||||
|
||||
RsTlvFileSet attachment;
|
||||
|
||||
};
|
||||
|
||||
class RsBlogSerialiser: public RsSerialType
|
||||
{
|
||||
public:
|
||||
RsBlogSerialiser()
|
||||
:RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_CHANNEL)
|
||||
{ return; }
|
||||
virtual ~RsBlogSerialiser()
|
||||
{ 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(RsBlogMsg *);
|
||||
virtual bool serialiseMsg(RsBlogMsg *item, void *data, uint32_t *size);
|
||||
virtual RsBlogMsg *deserialiseMsg(void *data, uint32_t *size);
|
||||
|
||||
};
|
||||
|
||||
/**************************************************************************/
|
||||
|
||||
#endif /* RS_BLOG_ITEMS_H */
|
||||
|
||||
|
503
libretroshare/src/services/p3blogs.cc
Normal file
503
libretroshare/src/services/p3blogs.cc
Normal file
@ -0,0 +1,503 @@
|
||||
/*
|
||||
* libretroshare/src/services: p3Blogs.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/p3blogs.h"
|
||||
#include "util/rsdir.h"
|
||||
|
||||
std::ostream &operator<<(std::ostream &out, const BlogInfo &info)
|
||||
{
|
||||
std::string name(info.blogName.begin(), info.blogName.end());
|
||||
std::string desc(info.blogDesc.begin(), info.blogDesc.end());
|
||||
|
||||
out << "BlogInfo:";
|
||||
out << std::endl;
|
||||
out << "BlogId: " << info.blogId << std::endl;
|
||||
out << "BlogName: " << name << std::endl;
|
||||
out << "BlogDesc: " << desc << std::endl;
|
||||
out << "BlogFlags: " << info.blogFlags << std::endl;
|
||||
out << "Pop: " << info.pop << std::endl;
|
||||
out << "LastPost: " << info.lastPost << std::endl;
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
std::ostream &operator<<(std::ostream &out, const BlogMsgSummary &info)
|
||||
{
|
||||
out << "BlogMsgSummary:";
|
||||
out << std::endl;
|
||||
out << "BlogId: " << info.blogId << std::endl;
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
std::ostream &operator<<(std::ostream &out, const BlogMsgInfo &info)
|
||||
{
|
||||
out << "BlogMsgInfo:";
|
||||
out << std::endl;
|
||||
out << "BlogId: " << info.blogId << std::endl;
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
RsBlogs *rsBlogs = NULL;
|
||||
|
||||
|
||||
/* Blogs will be initially stored for 1 year
|
||||
* remember 2^16 = 64K max units in store period.
|
||||
* PUBPERIOD * 2^16 = max STORE PERIOD */
|
||||
#define BLOG_STOREPERIOD (90*24*3600) /* 30 * 24 * 3600 - secs in a year */
|
||||
#define BLOG_PUBPERIOD 600 /* 10 minutes ... (max = 455 days) */
|
||||
|
||||
p3Blogs::p3Blogs(uint16_t type, CacheStrapper *cs,
|
||||
CacheTransfer *cft, RsFiles *files,
|
||||
std::string srcdir, std::string storedir, std::string blogDir)
|
||||
:p3GroupDistrib(type, cs, cft, srcdir, storedir,
|
||||
CONFIG_TYPE_QBLOG, BLOG_STOREPERIOD, BLOG_PUBPERIOD),
|
||||
mRsFiles(files),
|
||||
mBlogsDir(blogDir)
|
||||
{
|
||||
//loadDummyData();
|
||||
|
||||
/* create chanDir */
|
||||
if (!RsDirUtil::checkCreateDirectory(mBlogsDir))
|
||||
{
|
||||
std::cerr << "p3Blogs() Failed to create Channels Directory: ";
|
||||
std::cerr << mBlogsDir;
|
||||
std::cerr << std::endl;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
p3Blogs::~p3Blogs()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/****************************************/
|
||||
|
||||
bool p3Blogs::blogsChanged(std::list<std::string> &blogIds)
|
||||
{
|
||||
return groupsChanged(blogIds);
|
||||
}
|
||||
|
||||
|
||||
bool p3Blogs::getBlogInfo(std::string cId, BlogInfo &ci)
|
||||
{
|
||||
RsStackMutex stack(distribMtx); /***** STACK LOCKED MUTEX *****/
|
||||
|
||||
/* extract details */
|
||||
GroupInfo *gi = locked_getGroupInfo(cId);
|
||||
|
||||
if (!gi)
|
||||
return false;
|
||||
|
||||
ci.blogId = gi->grpId;
|
||||
ci.blogName = gi->grpName;
|
||||
ci.blogDesc = gi->grpDesc;
|
||||
|
||||
ci.blogFlags = gi->flags;
|
||||
|
||||
ci.pop = gi->sources.size();
|
||||
ci.lastPost = gi->lastPost;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool p3Blogs::getBlogList(std::list<BlogInfo> &blogList)
|
||||
{
|
||||
std::list<std::string> grpIds;
|
||||
std::list<std::string>::iterator it;
|
||||
|
||||
getAllGroupList(grpIds);
|
||||
|
||||
for(it = grpIds.begin(); it != grpIds.end(); it++)
|
||||
{
|
||||
BlogInfo ci;
|
||||
if (getBlogInfo(*it, ci))
|
||||
{
|
||||
blogList.push_back(ci);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool p3Blogs::getBlogMsgList(std::string cId, std::list<BlogMsgSummary> &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);
|
||||
RsBlogMsg *cmsg = dynamic_cast<RsBlogMsg *>(msg);
|
||||
if (!cmsg)
|
||||
continue;
|
||||
|
||||
BlogMsgSummary tis;
|
||||
|
||||
tis.blogId = 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();
|
||||
tis.msgIdReply = cmsg->mIdReply;
|
||||
|
||||
msgs.push_back(tis);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool p3Blogs::getBlogMessage(std::string fId, std::string mId, BlogMsgInfo &info)
|
||||
{
|
||||
std::list<std::string> msgIds;
|
||||
std::list<std::string>::iterator it;
|
||||
|
||||
RsStackMutex stack(distribMtx); /***** STACK LOCKED MUTEX *****/
|
||||
|
||||
RsDistribMsg *msg = locked_getGroupMsg(fId, mId);
|
||||
RsBlogMsg *cmsg = dynamic_cast<RsBlogMsg *>(msg);
|
||||
if (!cmsg)
|
||||
return false;
|
||||
|
||||
|
||||
info.blogId = 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;
|
||||
info.msgIdReply = cmsg->mIdReply;
|
||||
|
||||
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 p3Blogs::BlogMessageSend(BlogMsgInfo &info)
|
||||
{
|
||||
|
||||
RsBlogMsg *cmsg = new RsBlogMsg();
|
||||
cmsg->grpId = info.blogId;
|
||||
cmsg->mIdReply = info.msgIdReply;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
bool p3Blogs::BlogMessageReply(BlogMsgInfo& reply){
|
||||
|
||||
if(reply.msgIdReply.empty())
|
||||
return false;
|
||||
|
||||
return BlogMessageSend(reply);
|
||||
}
|
||||
|
||||
bool p3Blogs::isReply(BlogMsgInfo& info){
|
||||
|
||||
// if replies list is empty then this is not a reply to a blog
|
||||
return !info.msgIdReply.empty();
|
||||
}
|
||||
|
||||
std::string p3Blogs::createBlog(std::wstring blogName, std::wstring blogDesc, uint32_t blogFlags)
|
||||
{
|
||||
std::string id = createGroup(blogName, blogDesc, blogFlags);
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
RsSerialType *p3Blogs::createSerialiser()
|
||||
{
|
||||
return new RsBlogSerialiser();
|
||||
}
|
||||
|
||||
bool p3Blogs::locked_checkDistribMsg(RsDistribMsg *msg)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
RsDistribGrp *p3Blogs::locked_createPublicDistribGrp(GroupInfo &info)
|
||||
{
|
||||
RsDistribGrp *grp = NULL; //new RsChannelGrp();
|
||||
|
||||
return grp;
|
||||
}
|
||||
|
||||
RsDistribGrp *p3Blogs::locked_createPrivateDistribGrp(GroupInfo &info)
|
||||
{
|
||||
RsDistribGrp *grp = NULL; //new RsChannelGrp();
|
||||
|
||||
return grp;
|
||||
}
|
||||
|
||||
|
||||
bool p3Blogs::blogSubscribe(std::string cId, bool subscribe)
|
||||
{
|
||||
std::cerr << "p3Blogs::channelSubscribe() ";
|
||||
std::cerr << cId;
|
||||
std::cerr << std::endl;
|
||||
|
||||
return subscribeToGroup(cId, subscribe);
|
||||
}
|
||||
|
||||
|
||||
/***************************************************************************************/
|
||||
/****************** Event Feedback (Overloaded form p3distrib) *************************/
|
||||
/***************************************************************************************/
|
||||
/* only download in the first week of channel
|
||||
* older stuff can be manually downloaded.
|
||||
*/
|
||||
|
||||
const uint32_t DOWNLOAD_PERIOD = 7 * 24 * 3600;
|
||||
|
||||
/* This is called when we receive a msg, and also recalled
|
||||
* on a subscription to a channel..
|
||||
*/
|
||||
|
||||
bool p3Blogs::locked_eventDuplicateMsg(GroupInfo *grp, RsDistribMsg *msg, std::string id)
|
||||
{
|
||||
std::string grpId = msg->grpId;
|
||||
std::string msgId = msg->msgId;
|
||||
std::string nullId;
|
||||
|
||||
|
||||
std::cerr << "p3Blogs::locked_eventDuplicateMsg() ";
|
||||
std::cerr << " grpId: " << grpId << " msgId: " << msgId;
|
||||
std::cerr << " peerId: " << id;
|
||||
std::cerr << std::endl;
|
||||
|
||||
|
||||
RsBlogMsg *chanMsg = dynamic_cast<RsBlogMsg *>(msg);
|
||||
if (!chanMsg)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/* request the files
|
||||
* NB: This will result in duplicates.
|
||||
* it is upto ftserver/ftcontroller/ftextralist
|
||||
* */
|
||||
|
||||
//bool download = (grp->flags & (RS_DISTRIB_ADMIN |
|
||||
// RS_DISTRIB_PUBLISH | RS_DISTRIB_SUBSCRIBED))
|
||||
bool download = (grp->flags & RS_DISTRIB_SUBSCRIBED);
|
||||
|
||||
/* check subscribed */
|
||||
if (!download)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/* check age */
|
||||
time_t age = time(NULL) - msg->timestamp;
|
||||
|
||||
if (age > DOWNLOAD_PERIOD)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/* Iterate through files */
|
||||
std::list<RsTlvFileItem>::iterator fit;
|
||||
for(fit = chanMsg->attachment.items.begin();
|
||||
fit != chanMsg->attachment.items.end(); fit++)
|
||||
{
|
||||
std::string fname = fit->name;
|
||||
std::string hash = fit->hash;
|
||||
uint64_t size = fit->filesize;
|
||||
std::string blogname = grpId;
|
||||
std::string localpath = mBlogsDir + "/" + blogname;
|
||||
uint32_t flags = RS_FILE_HINTS_EXTRA;
|
||||
std::list<std::string> srcIds;
|
||||
|
||||
srcIds.push_back(id);
|
||||
|
||||
/* download it ... and flag for ExtraList
|
||||
* don't do pre-search check as FileRequest does it better
|
||||
*
|
||||
* FileRequest will ignore request if file is already indexed.
|
||||
*/
|
||||
|
||||
std::cerr << "p3Blogs::locked_eventDuplicateMsg() ";
|
||||
std::cerr << " Downloading: " << fname;
|
||||
std::cerr << " to: " << localpath;
|
||||
std::cerr << " from: " << id;
|
||||
std::cerr << std::endl;
|
||||
|
||||
mRsFiles->FileRequest(fname, hash, size,
|
||||
localpath, flags, srcIds);
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#include "pqi/pqinotify.h"
|
||||
|
||||
bool p3Blogs::locked_eventNewMsg(GroupInfo *grp, RsDistribMsg *msg, std::string id)
|
||||
{
|
||||
std::string grpId = msg->grpId;
|
||||
std::string msgId = msg->msgId;
|
||||
std::string nullId;
|
||||
|
||||
std::cerr << "p3Blogs::locked_eventNewMsg() ";
|
||||
std::cerr << " grpId: " << grpId;
|
||||
std::cerr << " msgId: " << msgId;
|
||||
std::cerr << " peerId: " << id;
|
||||
std::cerr << std::endl;
|
||||
|
||||
getPqiNotify()->AddFeedItem(RS_FEED_ITEM_BLOG_MSG, grpId, msgId, nullId);
|
||||
|
||||
/* request the files
|
||||
* NB: This could result in duplicates.
|
||||
* which must be handled by ft side.
|
||||
*
|
||||
* this is exactly what DuplicateMsg does.
|
||||
* */
|
||||
return locked_eventDuplicateMsg(grp, msg, id);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void p3Blogs::locked_notifyGroupChanged(GroupInfo &grp, uint32_t flags)
|
||||
{
|
||||
std::string grpId = grp.grpId;
|
||||
std::string msgId;
|
||||
std::string nullId;
|
||||
|
||||
std::cerr << "p3Blogs::locked_notifyGroupChanged() ";
|
||||
std::cerr << grpId;
|
||||
std::cerr << " flags:" << flags;
|
||||
std::cerr << std::endl;
|
||||
|
||||
switch(flags)
|
||||
{
|
||||
case GRP_NEW_UPDATE:
|
||||
std::cerr << "p3Blogs::locked_notifyGroupChanged() NEW UPDATE";
|
||||
std::cerr << std::endl;
|
||||
getPqiNotify()->AddFeedItem(RS_FEED_ITEM_BLOG_NEW, grpId, msgId, nullId);
|
||||
break;
|
||||
case GRP_UPDATE:
|
||||
std::cerr << "p3Blogs::locked_notifyGroupChanged() UPDATE";
|
||||
std::cerr << std::endl;
|
||||
getPqiNotify()->AddFeedItem(RS_FEED_ITEM_BLOG_UPDATE, grpId, msgId, nullId);
|
||||
break;
|
||||
case GRP_LOAD_KEY:
|
||||
std::cerr << "p3Blogs::locked_notifyGroupChanged() LOAD_KEY";
|
||||
std::cerr << std::endl;
|
||||
break;
|
||||
case GRP_NEW_MSG:
|
||||
std::cerr << "p3Blogs::locked_notifyGroupChanged() NEW MSG";
|
||||
std::cerr << std::endl;
|
||||
break;
|
||||
case GRP_SUBSCRIBED:
|
||||
std::cerr << "p3Blogs::locked_notifyGroupChanged() SUBSCRIBED";
|
||||
std::cerr << std::endl;
|
||||
{
|
||||
std::string blogdir = mBlogsDir + "/" + grpId;
|
||||
|
||||
std::cerr << "p3Blogs::locked_notifyGroupChanged() ";
|
||||
std::cerr << " creating directory: " << blogdir;
|
||||
std::cerr << std::endl;
|
||||
|
||||
/* create chanDir */
|
||||
if (!RsDirUtil::checkCreateDirectory(blogdir))
|
||||
{
|
||||
std::cerr << "p3Blogs::locked_notifyGroupChanged() ";
|
||||
std::cerr << "Failed to create Blogs Directory: ";
|
||||
std::cerr << blogdir;
|
||||
std::cerr << std::endl;
|
||||
}
|
||||
|
||||
/* check if downloads need to be started? */
|
||||
}
|
||||
|
||||
break;
|
||||
case GRP_UNSUBSCRIBED:
|
||||
std::cerr << "p3Blogs::locked_notifyGroupChanged() UNSUBSCRIBED";
|
||||
std::cerr << std::endl;
|
||||
|
||||
/* won't stop downloads... */
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
std::cerr << "p3Blogs::locked_notifyGroupChanged() Unknown DEFAULT";
|
||||
std::cerr << std::endl;
|
||||
break;
|
||||
}
|
||||
|
||||
return p3GroupDistrib::locked_notifyGroupChanged(grp, flags);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/****************************************/
|
||||
|
||||
|
||||
|
96
libretroshare/src/services/p3blogs.h
Normal file
96
libretroshare/src/services/p3blogs.h
Normal file
@ -0,0 +1,96 @@
|
||||
#ifndef RS_P3_BLOGS_INTERFACE_H
|
||||
#define RS_P3_BLOGS_INTERFACE_H
|
||||
|
||||
/*
|
||||
* libretroshare/src/services: p3blogs.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/rsblogs.h"
|
||||
#include "rsiface/rsfiles.h"
|
||||
#include "services/p3distrib.h"
|
||||
|
||||
#include "serialiser/rstlvtypes.h"
|
||||
#include "serialiser/rsblogitems.h"
|
||||
|
||||
|
||||
class p3Blogs: public p3GroupDistrib, public RsBlogs
|
||||
{
|
||||
public:
|
||||
|
||||
p3Blogs(uint16_t type, CacheStrapper *cs, CacheTransfer *cft, RsFiles *files,
|
||||
std::string srcdir, std::string storedir, std::string blogsdir);
|
||||
virtual ~p3Blogs();
|
||||
|
||||
/****************************************/
|
||||
/********* rsBlogs Interface ***********/
|
||||
|
||||
virtual bool blogsChanged(std::list<std::string> &blogIds);
|
||||
|
||||
virtual std::string createBlog(std::wstring blogName, std::wstring blogDesc, uint32_t blogFlags);
|
||||
|
||||
virtual bool getBlogInfo(std::string cId, BlogInfo &ci);
|
||||
virtual bool getBlogList(std::list<BlogInfo> &chanList);
|
||||
virtual bool getBlogMsgList(std::string cId, std::list<BlogMsgSummary> &msgs);
|
||||
virtual bool getBlogMessage(std::string cId, std::string mId, BlogMsgInfo &msg);
|
||||
|
||||
virtual bool BlogMessageSend(BlogMsgInfo &info);
|
||||
|
||||
|
||||
virtual bool blogSubscribe(std::string cId, bool subscribe);
|
||||
|
||||
virtual bool BlogMessageReply(BlogMsgInfo &info);
|
||||
|
||||
virtual bool isReply(BlogMsgInfo& info);
|
||||
|
||||
/***************************************************************************************/
|
||||
/****************** Event Feedback (Overloaded form p3distrib) *************************/
|
||||
/***************************************************************************************/
|
||||
|
||||
protected:
|
||||
virtual void locked_notifyGroupChanged(GroupInfo &info, uint32_t flags);
|
||||
virtual bool locked_eventNewMsg(GroupInfo *, RsDistribMsg *, std::string);
|
||||
virtual bool locked_eventDuplicateMsg(GroupInfo *, RsDistribMsg *, std::string);
|
||||
|
||||
|
||||
/****************************************/
|
||||
/********* Overloaded Functions *********/
|
||||
|
||||
virtual RsSerialType *createSerialiser();
|
||||
|
||||
virtual bool locked_checkDistribMsg(RsDistribMsg *msg);
|
||||
virtual RsDistribGrp *locked_createPublicDistribGrp(GroupInfo &info);
|
||||
virtual RsDistribGrp *locked_createPrivateDistribGrp(GroupInfo &info);
|
||||
|
||||
|
||||
/****************************************/
|
||||
|
||||
private:
|
||||
|
||||
RsFiles *mRsFiles;
|
||||
std::string mBlogsDir;
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user