mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-02 14:16:16 -04:00
Added the first version of the FeedReader plugin.
Added a new method to RsPlugInInterfaces to stop the plugins at shutdown of RetroShare. git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-gxs-b1@5372 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
ebc8fa3212
commit
09b5d7a8c6
42 changed files with 7004 additions and 7 deletions
1710
plugins/FeedReader/services/p3FeedReader.cc
Normal file
1710
plugins/FeedReader/services/p3FeedReader.cc
Normal file
File diff suppressed because it is too large
Load diff
113
plugins/FeedReader/services/p3FeedReader.h
Normal file
113
plugins/FeedReader/services/p3FeedReader.h
Normal file
|
@ -0,0 +1,113 @@
|
|||
/****************************************************************
|
||||
* RetroShare GUI is distributed under the following license:
|
||||
*
|
||||
* Copyright (C) 2012 by Thunder
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
****************************************************************/
|
||||
|
||||
#ifndef P3_FEEDREADER
|
||||
#define P3_FEEDREADER
|
||||
|
||||
#include "retroshare/rsplugin.h"
|
||||
#include "plugins/rspqiservice.h"
|
||||
#include "interface/rsFeedReader.h"
|
||||
#include "p3FeedReaderThread.h"
|
||||
|
||||
class RsFeedReaderFeed;
|
||||
|
||||
//TODO: get new id's
|
||||
const uint8_t RS_PKT_TYPE_FEEDREADER_CONFIG = 0xf0;
|
||||
const uint32_t CONFIG_TYPE_FEEDREADER = 0x0001;
|
||||
|
||||
class p3FeedReader : public RsPQIService, public RsFeedReader
|
||||
{
|
||||
public:
|
||||
p3FeedReader(RsPluginHandler *pgHandler);
|
||||
|
||||
/****************** FeedReader Interface *************/
|
||||
virtual void stop();
|
||||
virtual void setNotify(RsFeedReaderNotify *notify);
|
||||
|
||||
virtual uint32_t getStandardStorageTime();
|
||||
virtual void setStandardStorageTime(uint32_t storageTime);
|
||||
virtual uint32_t getStandardUpdateInterval();
|
||||
virtual void setStandardUpdateInterval(uint32_t updateInterval);
|
||||
virtual bool getStandardProxy(std::string &proxyAddress, uint16_t &proxyPort);
|
||||
virtual void setStandardProxy(bool useProxy, const std::string &proxyAddress, uint16_t proxyPort);
|
||||
|
||||
virtual RsFeedAddResult addFolder(const std::string parentId, const std::string &name, std::string &feedId);
|
||||
virtual RsFeedAddResult setFolder(const std::string &feedId, const std::string &name);
|
||||
virtual RsFeedAddResult addFeed(const FeedInfo &feedInfo, std::string &feedId);
|
||||
virtual RsFeedAddResult setFeed(const std::string &feedId, const FeedInfo &feedInfo);
|
||||
virtual bool removeFeed(const std::string &feedId);
|
||||
virtual void getFeedList(const std::string &parentId, std::list<FeedInfo> &feedInfos);
|
||||
virtual bool getFeedInfo(const std::string &feedId, FeedInfo &feedInfo);
|
||||
virtual bool getMsgInfo(const std::string &feedId, const std::string &msgId, FeedMsgInfo &msgInfo);
|
||||
virtual bool removeMsg(const std::string &feedId, const std::string &msgId);
|
||||
virtual bool removeMsgs(const std::string &feedId, const std::list<std::string> &msgIds);
|
||||
virtual bool getMessageCount(const std::string &feedId, uint32_t *msgCount, uint32_t *newCount, uint32_t *unreadCount);
|
||||
virtual bool getFeedMsgList(const std::string &feedId, std::list<FeedMsgInfo> &msgInfos);
|
||||
virtual bool processFeed(const std::string &feedId);
|
||||
virtual bool setMessageRead(const std::string &feedId, const std::string &msgId, bool read);
|
||||
|
||||
/****************** p3Service STUFF ******************/
|
||||
virtual int tick();
|
||||
|
||||
/****************** internal STUFF *******************/
|
||||
bool getFeedToDownload(RsFeedReaderFeed &feed);
|
||||
void onDownloadSuccess(const std::string &feedId, const std::string &content, std::string &icon);
|
||||
void onDownloadError(const std::string &feedId, p3FeedReaderThread::DownloadResult result, const std::string &error);
|
||||
void onProcessSuccess(const std::string &feedId, std::list<RsFeedReaderMsg*> &msgs);
|
||||
void onProcessError(const std::string &feedId, p3FeedReaderThread::ProcessResult result);
|
||||
|
||||
bool getFeedToProcess(RsFeedReaderFeed &feed);
|
||||
|
||||
void setFeedInfo(const std::string &feedId, const std::string &name, const std::string &description);
|
||||
|
||||
protected:
|
||||
/****************** p3Config STUFF *******************/
|
||||
virtual RsSerialiser *setupSerialiser();
|
||||
virtual bool saveList(bool &cleanup, std::list<RsItem *>&);
|
||||
virtual bool loadList(std::list<RsItem *>& load);
|
||||
virtual void saveDone();
|
||||
|
||||
private:
|
||||
void cleanFeeds();
|
||||
void deleteAllMsgs_locked(RsFeedReaderFeed *fi);
|
||||
|
||||
std::list<p3FeedReaderThread*> mThreads;
|
||||
uint32_t mNextFeedId;
|
||||
uint32_t mNextMsgId;
|
||||
time_t mLastClean;
|
||||
RsFeedReaderNotify *mNotify;
|
||||
|
||||
RsMutex mFeedReaderMtx;
|
||||
uint32_t mStandardUpdateInterval;
|
||||
uint32_t mStandardStorageTime;
|
||||
bool mStandardUseProxy;
|
||||
std::string mStandardProxyAddress;
|
||||
uint16_t mStandardProxyPort;
|
||||
std::map<std::string, RsFeedReaderFeed*> mFeeds;
|
||||
|
||||
RsMutex mDownloadMutex;
|
||||
std::list<std::string> mDownloadFeeds;
|
||||
|
||||
RsMutex mProcessMutex;
|
||||
std::list<std::string> mProcessFeeds;
|
||||
};
|
||||
|
||||
#endif
|
1024
plugins/FeedReader/services/p3FeedReaderThread.cc
Normal file
1024
plugins/FeedReader/services/p3FeedReaderThread.cc
Normal file
File diff suppressed because it is too large
Load diff
71
plugins/FeedReader/services/p3FeedReaderThread.h
Normal file
71
plugins/FeedReader/services/p3FeedReaderThread.h
Normal file
|
@ -0,0 +1,71 @@
|
|||
/****************************************************************
|
||||
* RetroShare GUI is distributed under the following license:
|
||||
*
|
||||
* Copyright (C) 2012 by Thunder
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
****************************************************************/
|
||||
|
||||
#ifndef P3_FEEDREADERTHREAD
|
||||
#define P3_FEEDREADERTHREAD
|
||||
|
||||
#include "util/rsthreads.h"
|
||||
#include <list>
|
||||
|
||||
class p3FeedReader;
|
||||
class RsFeedReaderFeed;
|
||||
class RsFeedReaderMsg;
|
||||
|
||||
class p3FeedReaderThread : public RsThread
|
||||
{
|
||||
public:
|
||||
enum Type
|
||||
{
|
||||
DOWNLOAD,
|
||||
PROCESS
|
||||
};
|
||||
enum DownloadResult
|
||||
{
|
||||
DOWNLOAD_SUCCESS,
|
||||
DOWNLOAD_ERROR_INIT,
|
||||
DOWNLOAD_ERROR,
|
||||
DOWNLOAD_UNKNOWN_CONTENT_TYPE,
|
||||
DOWNLOAD_NOT_FOUND,
|
||||
DOWNLOAD_UNKOWN_RESPONSE_CODE,
|
||||
DOWNLOAD_INTERNAL_ERROR
|
||||
};
|
||||
enum ProcessResult
|
||||
{
|
||||
PROCESS_SUCCESS,
|
||||
PROCESS_ERROR_INIT,
|
||||
PROCESS_UNKNOWN_FORMAT
|
||||
};
|
||||
|
||||
public:
|
||||
p3FeedReaderThread(p3FeedReader *feedReader, Type type);
|
||||
|
||||
private:
|
||||
virtual void run();
|
||||
|
||||
DownloadResult download(const RsFeedReaderFeed &feed, std::string &content, std::string &icon, std::string &error);
|
||||
ProcessResult process(const RsFeedReaderFeed &feed, std::list<RsFeedReaderMsg*> &entries, std::string &error);
|
||||
|
||||
p3FeedReader *mFeedReader;
|
||||
Type mType;
|
||||
/*xmlCharEncodingHandlerPtr*/ void *mCharEncodingHandler;
|
||||
};
|
||||
|
||||
#endif
|
388
plugins/FeedReader/services/rsFeedReaderItems.cc
Normal file
388
plugins/FeedReader/services/rsFeedReaderItems.cc
Normal file
|
@ -0,0 +1,388 @@
|
|||
/****************************************************************
|
||||
* RetroShare GUI is distributed under the following license:
|
||||
*
|
||||
* Copyright (C) 2012 by Thunder
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
****************************************************************/
|
||||
|
||||
#include "serialiser/rsbaseserial.h"
|
||||
#include "serialiser/rstlvbase.h"
|
||||
#include "rsFeedReaderItems.h"
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
RsFeedReaderFeed::RsFeedReaderFeed() : RsItem(RS_PKT_VERSION1, RS_PKT_CLASS_CONFIG, RS_PKT_TYPE_FEEDREADER_CONFIG, RS_PKT_SUBTYPE_FEEDREADER_FEED)
|
||||
{
|
||||
clear();
|
||||
}
|
||||
|
||||
void RsFeedReaderFeed::clear()
|
||||
{
|
||||
feedId.clear();
|
||||
parentId.clear();
|
||||
name.clear();
|
||||
url.clear();
|
||||
user.clear();
|
||||
password.clear();
|
||||
proxyAddress.clear();
|
||||
proxyPort = 0;
|
||||
updateInterval = 0;
|
||||
lastUpdate = 0;
|
||||
storageTime = 0;
|
||||
flag = 0;
|
||||
forumId.clear();
|
||||
description.clear();
|
||||
icon.clear();
|
||||
errorState = RS_FEED_ERRORSTATE_OK;
|
||||
errorString.clear();
|
||||
|
||||
workstate = WAITING;
|
||||
content.clear();
|
||||
}
|
||||
|
||||
std::ostream &RsFeedReaderFeed::print(std::ostream &out, uint16_t /*indent*/)
|
||||
{
|
||||
return out;
|
||||
}
|
||||
|
||||
uint32_t RsFeedReaderSerialiser::sizeFeed(RsFeedReaderFeed *item)
|
||||
{
|
||||
uint32_t s = 8; /* header */
|
||||
s += GetTlvStringSize(item->feedId);
|
||||
s += GetTlvStringSize(item->parentId);
|
||||
s += GetTlvStringSize(item->url);
|
||||
s += GetTlvStringSize(item->name);
|
||||
s += GetTlvStringSize(item->description);
|
||||
s += GetTlvStringSize(item->icon);
|
||||
s += GetTlvStringSize(item->user);
|
||||
s += GetTlvStringSize(item->password);
|
||||
s += GetTlvStringSize(item->proxyAddress);
|
||||
s += sizeof(uint16_t); /* proxyPort */
|
||||
s += sizeof(uint32_t); /* updateInterval */
|
||||
s += sizeof(time_t); /* lastscan */
|
||||
s += sizeof(uint32_t); /* storageTime */
|
||||
s += sizeof(uint32_t); /* flag */
|
||||
s += GetTlvStringSize(item->forumId);
|
||||
s += sizeof(uint32_t); /* errorstate */
|
||||
s += GetTlvStringSize(item->errorString);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
/* serialise the data to the buffer */
|
||||
bool RsFeedReaderSerialiser::serialiseFeed(RsFeedReaderFeed *item, void *data, uint32_t *pktsize)
|
||||
{
|
||||
uint32_t tlvsize = sizeFeed(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);
|
||||
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
/* add values */
|
||||
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_GENID, item->feedId);
|
||||
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_VALUE, item->parentId);
|
||||
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_LINK, item->url);
|
||||
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_NAME, item->name);
|
||||
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_COMMENT, item->description);
|
||||
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_VALUE, item->icon);
|
||||
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_VALUE, item->user);
|
||||
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_VALUE, item->password);
|
||||
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_VALUE, item->proxyAddress);
|
||||
ok &= setRawUInt16(data, tlvsize, &offset, item->proxyPort);
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, item->updateInterval);
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, item->lastUpdate);
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, item->storageTime);
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, item->flag);
|
||||
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_VALUE, item->forumId);
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, item->errorState);
|
||||
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_VALUE, item->errorString);
|
||||
|
||||
if (offset != tlvsize)
|
||||
{
|
||||
ok = false;
|
||||
std::cerr << "RsFeedReaderSerialiser::serialiseFeed() Size Error! " << std::endl;
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
RsFeedReaderFeed *RsFeedReaderSerialiser::deserialiseFeed(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_VERSION1 != getRsItemVersion(rstype)) ||
|
||||
(RS_PKT_CLASS_CONFIG != getRsItemClass(rstype)) ||
|
||||
(RS_PKT_TYPE_FEEDREADER_CONFIG != getRsItemType(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_FEEDREADER_FEED != 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 */
|
||||
RsFeedReaderFeed *item = new RsFeedReaderFeed();
|
||||
item->clear();
|
||||
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
/* get values */
|
||||
ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_GENID, item->feedId);
|
||||
ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_VALUE, item->parentId);
|
||||
ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_LINK, item->url);
|
||||
ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_NAME, item->name);
|
||||
ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_COMMENT, item->description);
|
||||
ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_VALUE, item->icon);
|
||||
ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_VALUE, item->user);
|
||||
ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_VALUE, item->password);
|
||||
ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_VALUE, item->proxyAddress);
|
||||
ok &= getRawUInt16(data, rssize, &offset, &(item->proxyPort));
|
||||
ok &= getRawUInt32(data, rssize, &offset, &(item->updateInterval));
|
||||
ok &= getRawUInt32(data, rssize, &offset, (uint32_t*) &(item->lastUpdate));
|
||||
ok &= getRawUInt32(data, rssize, &offset, &(item->storageTime));
|
||||
ok &= getRawUInt32(data, rssize, &offset, &(item->flag));
|
||||
ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_VALUE, item->forumId);
|
||||
ok &= getRawUInt32(data, rssize, &offset, &(item->errorState));
|
||||
ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_VALUE, item->errorString);
|
||||
|
||||
if (offset != rssize)
|
||||
{
|
||||
/* error */
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
RsFeedReaderMsg::RsFeedReaderMsg() : RsItem(RS_PKT_VERSION1, RS_PKT_CLASS_CONFIG, RS_PKT_TYPE_FEEDREADER_CONFIG, RS_PKT_SUBTYPE_FEEDREADER_MSG)
|
||||
{
|
||||
clear();
|
||||
}
|
||||
|
||||
void RsFeedReaderMsg::clear()
|
||||
{
|
||||
msgId.clear();
|
||||
feedId.clear();
|
||||
title.clear();
|
||||
link.clear();
|
||||
author.clear();
|
||||
description.clear();
|
||||
pubDate = 0;
|
||||
flag = 0;
|
||||
}
|
||||
|
||||
std::ostream &RsFeedReaderMsg::print(std::ostream &out, uint16_t /*indent*/)
|
||||
{
|
||||
return out;
|
||||
}
|
||||
|
||||
uint32_t RsFeedReaderSerialiser::sizeMsg(RsFeedReaderMsg *item)
|
||||
{
|
||||
uint32_t s = 8; /* header */
|
||||
s += GetTlvStringSize(item->msgId);
|
||||
s += GetTlvStringSize(item->feedId);
|
||||
s += GetTlvStringSize(item->title);
|
||||
s += GetTlvStringSize(item->link);
|
||||
s += GetTlvStringSize(item->author);
|
||||
s += GetTlvStringSize(item->description);
|
||||
s += sizeof(time_t); /* pubDate */
|
||||
s += sizeof(uint32_t); /* flag */
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
/* serialise the data to the buffer */
|
||||
bool RsFeedReaderSerialiser::serialiseMsg(RsFeedReaderMsg *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);
|
||||
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
/* add values */
|
||||
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_GENID, item->msgId);
|
||||
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_VALUE, item->feedId);
|
||||
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_NAME, item->title);
|
||||
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_LINK, item->link);
|
||||
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_VALUE, item->author);
|
||||
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_COMMENT, item->description);
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, item->pubDate);
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, item->flag);
|
||||
|
||||
if (offset != tlvsize)
|
||||
{
|
||||
ok = false;
|
||||
std::cerr << "RsFeedReaderSerialiser::serialiseMsg() Size Error! " << std::endl;
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
RsFeedReaderMsg *RsFeedReaderSerialiser::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_VERSION1 != getRsItemVersion(rstype)) ||
|
||||
(RS_PKT_CLASS_CONFIG != getRsItemClass(rstype)) ||
|
||||
(RS_PKT_TYPE_FEEDREADER_CONFIG != getRsItemType(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_FEEDREADER_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 */
|
||||
RsFeedReaderMsg *item = new RsFeedReaderMsg();
|
||||
item->clear();
|
||||
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
/* get values */
|
||||
ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_GENID, item->msgId);
|
||||
ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_VALUE, item->feedId);
|
||||
ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_NAME, item->title);
|
||||
ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_LINK, item->link);
|
||||
ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_VALUE, item->author);
|
||||
ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_COMMENT, item->description);
|
||||
ok &= getRawUInt32(data, rssize, &offset, (uint32_t*) &(item->pubDate));
|
||||
ok &= getRawUInt32(data, rssize, &offset, &(item->flag));
|
||||
|
||||
if (offset != rssize)
|
||||
{
|
||||
/* error */
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
uint32_t RsFeedReaderSerialiser::size(RsItem *item)
|
||||
{
|
||||
RsFeedReaderFeed *fi;
|
||||
RsFeedReaderMsg *ei;
|
||||
|
||||
if (NULL != (fi = dynamic_cast<RsFeedReaderFeed*>(item)))
|
||||
{
|
||||
return sizeFeed((RsFeedReaderFeed*) item);
|
||||
}
|
||||
if (NULL != (ei = dynamic_cast<RsFeedReaderMsg*>(item)))
|
||||
{
|
||||
return sizeMsg((RsFeedReaderMsg*) item);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool RsFeedReaderSerialiser::serialise(RsItem *item, void *data, uint32_t *pktsize)
|
||||
{
|
||||
RsFeedReaderFeed *fi;
|
||||
RsFeedReaderMsg *ei;
|
||||
|
||||
if (NULL != (fi = dynamic_cast<RsFeedReaderFeed*>(item)))
|
||||
{
|
||||
return serialiseFeed((RsFeedReaderFeed*) item, data, pktsize);
|
||||
}
|
||||
if (NULL != (ei = dynamic_cast<RsFeedReaderMsg*>(item)))
|
||||
{
|
||||
return serialiseMsg((RsFeedReaderMsg*) item, data, pktsize);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
RsItem *RsFeedReaderSerialiser::deserialise(void *data, uint32_t *pktsize)
|
||||
{
|
||||
/* get the type and size */
|
||||
uint32_t rstype = getRsItemId(data);
|
||||
|
||||
if ((RS_PKT_VERSION1 != getRsItemVersion(rstype)) ||
|
||||
(RS_PKT_CLASS_CONFIG != getRsItemClass(rstype)) ||
|
||||
(RS_PKT_TYPE_FEEDREADER_CONFIG != getRsItemType(rstype)))
|
||||
{
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
|
||||
switch (getRsItemSubType(rstype))
|
||||
{
|
||||
case RS_PKT_SUBTYPE_FEEDREADER_FEED:
|
||||
return deserialiseFeed(data, pktsize);
|
||||
case RS_PKT_SUBTYPE_FEEDREADER_MSG:
|
||||
return deserialiseMsg(data, pktsize);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
149
plugins/FeedReader/services/rsFeedReaderItems.h
Normal file
149
plugins/FeedReader/services/rsFeedReaderItems.h
Normal file
|
@ -0,0 +1,149 @@
|
|||
/****************************************************************
|
||||
* RetroShare GUI is distributed under the following license:
|
||||
*
|
||||
* Copyright (C) 2012 by Thunder
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
****************************************************************/
|
||||
|
||||
#ifndef RS_FEEDREADER_ITEMS_H
|
||||
#define RS_FEEDREADER_ITEMS_H
|
||||
|
||||
#include "serialiser/rsserial.h"
|
||||
#include "serialiser/rstlvtypes.h"
|
||||
|
||||
#include "p3FeedReader.h"
|
||||
|
||||
const uint8_t RS_PKT_SUBTYPE_FEEDREADER_FEED = 0x02;
|
||||
const uint8_t RS_PKT_SUBTYPE_FEEDREADER_MSG = 0x03;
|
||||
|
||||
/**************************************************************************/
|
||||
|
||||
#define RS_FEED_ERRORSTATE_OK 0
|
||||
#define RS_FEED_ERRORSTATE_DOWNLOAD_INTERNAL_ERROR 1
|
||||
#define RS_FEED_ERRORSTATE_DOWNLOAD_ERROR 2
|
||||
#define RS_FEED_ERRORSTATE_DOWNLOAD_UNKNOWN_CONTENT_TYPE 3
|
||||
#define RS_FEED_ERRORSTATE_DOWNLOAD_NOT_FOUND 4
|
||||
#define RS_FEED_ERRORSTATE_DOWNLOAD_UNKOWN_RESPONSE_CODE 5
|
||||
|
||||
#define RS_FEED_ERRORSTATE_PROCESS_INTERNAL_ERROR 50
|
||||
|
||||
#define RS_FEED_ERRORSTATE_FORUM_CREATE 100
|
||||
#define RS_FEED_ERRORSTATE_FORUM_NOT_FOUND 101
|
||||
#define RS_FEED_ERRORSTATE_FORUM_NO_ADMIN 102
|
||||
#define RS_FEED_ERRORSTATE_FORUM_NO_ANONYMOUS_FORUM 103
|
||||
|
||||
#define RS_FEED_FLAG_FOLDER 0x001
|
||||
#define RS_FEED_FLAG_INFO_FROM_FEED 0x002
|
||||
#define RS_FEED_FLAG_STANDARD_STORAGE_TIME 0x004
|
||||
#define RS_FEED_FLAG_STANDARD_UPDATE_INTERVAL 0x008
|
||||
#define RS_FEED_FLAG_STANDARD_PROXY 0x010
|
||||
#define RS_FEED_FLAG_AUTHENTICATION 0x020
|
||||
#define RS_FEED_FLAG_DEACTIVATED 0x040
|
||||
#define RS_FEED_FLAG_FORUM 0x080
|
||||
#define RS_FEED_FLAG_UPDATE_FORUM_INFO 0x100
|
||||
|
||||
class RsFeedReaderFeed : public RsItem
|
||||
{
|
||||
public:
|
||||
enum WorkState {
|
||||
WAITING,
|
||||
WAITING_TO_DOWNLOAD,
|
||||
DOWNLOADING,
|
||||
WAITING_TO_PROCESS,
|
||||
PROCESSING
|
||||
};
|
||||
|
||||
public:
|
||||
RsFeedReaderFeed();
|
||||
virtual ~RsFeedReaderFeed() {}
|
||||
|
||||
virtual void clear();
|
||||
virtual std::ostream& print(std::ostream &out, uint16_t indent = 0);
|
||||
|
||||
std::string feedId;
|
||||
std::string parentId;
|
||||
std::string name;
|
||||
std::string url;
|
||||
std::string user;
|
||||
std::string password;
|
||||
std::string proxyAddress;
|
||||
uint16_t proxyPort;
|
||||
uint32_t updateInterval;
|
||||
time_t lastUpdate;
|
||||
uint32_t flag; // RS_FEED_FLAG_...
|
||||
std::string forumId;
|
||||
uint32_t storageTime;
|
||||
std::string description;
|
||||
std::string icon;
|
||||
uint32_t errorState;
|
||||
std::string errorString;
|
||||
|
||||
/* Not Serialised */
|
||||
WorkState workstate;
|
||||
std::string content;
|
||||
|
||||
std::map<std::string, RsFeedReaderMsg*> mMsgs;
|
||||
};
|
||||
|
||||
#define RS_FEEDMSG_FLAG_DELETED 1
|
||||
#define RS_FEEDMSG_FLAG_NEW 2
|
||||
#define RS_FEEDMSG_FLAG_READ 4
|
||||
|
||||
class RsFeedReaderMsg : public RsItem
|
||||
{
|
||||
public:
|
||||
RsFeedReaderMsg();
|
||||
virtual ~RsFeedReaderMsg() {}
|
||||
|
||||
virtual void clear();
|
||||
virtual std::ostream& print(std::ostream &out, uint16_t indent = 0);
|
||||
|
||||
std::string msgId;
|
||||
std::string feedId;
|
||||
std::string title;
|
||||
std::string link;
|
||||
std::string author;
|
||||
std::string description;
|
||||
time_t pubDate;
|
||||
uint32_t flag; // RS_FEEDMSG_FLAG_...
|
||||
};
|
||||
|
||||
class RsFeedReaderSerialiser: public RsSerialType
|
||||
{
|
||||
public:
|
||||
RsFeedReaderSerialiser() : RsSerialType(RS_PKT_VERSION1, RS_PKT_CLASS_CONFIG, RS_PKT_TYPE_FEEDREADER_CONFIG) {}
|
||||
virtual ~RsFeedReaderSerialiser() {}
|
||||
|
||||
virtual uint32_t size(RsItem *item);
|
||||
virtual bool serialise(RsItem *item, void *data, uint32_t *size);
|
||||
virtual RsItem *deserialise(void *data, uint32_t *size);
|
||||
|
||||
private:
|
||||
/* For RS_PKT_SUBTYPE_FEEDREADER_FEED */
|
||||
virtual uint32_t sizeFeed(RsFeedReaderFeed *item);
|
||||
virtual bool serialiseFeed(RsFeedReaderFeed *item, void *data, uint32_t *size);
|
||||
virtual RsFeedReaderFeed *deserialiseFeed(void *data, uint32_t *size);
|
||||
|
||||
/* For RS_PKT_SUBTYPE_FEEDREADER_MSG */
|
||||
virtual uint32_t sizeMsg(RsFeedReaderMsg *item);
|
||||
virtual bool serialiseMsg(RsFeedReaderMsg *item, void *data, uint32_t *size);
|
||||
virtual RsFeedReaderMsg *deserialiseMsg(void *data, uint32_t *size);
|
||||
};
|
||||
|
||||
/**************************************************************************/
|
||||
|
||||
#endif
|
Loading…
Add table
Add a link
Reference in a new issue