* Cleaned up lots of old VEG services.

- left the code for p3gxsserviceVEG and p3postedVEG, until p3posted is finished.
 * Converted p3wireVEG => p3wire
 * cleaned up rsinit.cc and libretroshare.pro



git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-gxs-b1@5901 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
drbob 2012-11-26 22:53:44 +00:00
parent 6a063ff32d
commit 78bc0a4567
22 changed files with 859 additions and 5315 deletions

View File

@ -137,16 +137,15 @@ PUBLIC_HEADERS = retroshare/rsblogs.h \
retroshare/rstypes.h \
retroshare/rsdht.h \
retroshare/rsdsdv.h \
retroshare/rsconfig.h \
retroshare/rsphotoV2.h
retroshare/rsconfig.h
HEADERS += plugins/pluginmanager.h \
plugins/dlfcn_win32.h \
serialiser/rspluginitems.h
HEADERS += $$PUBLIC_HEADERS
# public headers to be...
HEADERS += retroshare/rsgame.h \
retroshare/rsphoto.h
HEADERS += retroshare/rsgame.h
# ################################ Linux ##########################################
linux-* {
@ -610,16 +609,12 @@ HEADERS += retroshare/rsgame.h \
gxs/rsgxsdataaccess.h \
retroshare/rsgxsservice.h \
serialiser/rsgxsitems.h \
serialiser/rsphotov2items.h \
util/retrodb.h \
util/contentvalue.h \
gxs/gxscoreserver.h \
gxs/gxssecurity.h \
gxs/rsgxsifaceimpl.h \
gxs/gxstokenqueue.h \
services/p3posted.h \
retroshare/rsposted.h \
serialiser/rsposteditems.h
SOURCES += serialiser/rsnxsitems.cc \
@ -628,17 +623,13 @@ HEADERS += retroshare/rsgame.h \
gxs/rsgxsnetservice.cc \
gxs/rsgxsdata.cc \
serialiser/rsgxsitems.cc \
services/p3photoserviceV2.cc \
gxs/rsgxsdataaccess.cc \
serialiser/rsphotov2items.cc \
util/retrodb.cc \
util/contentvalue.cc \
gxs/gxscoreserver.cc \
gxs/gxssecurity.cc \
gxs/rsgxsifaceimpl.cc \
gxs/gxstokenqueue.cc \
services/p3posted.cc \
serialiser/rsposteditems.cc
# Identity Service
HEADERS += retroshare/rsidentity.h \
@ -665,26 +656,34 @@ HEADERS += retroshare/rsgame.h \
SOURCES += services/p3wiki.cc \
serialiser/rswikiitems.cc \
# Wiki Service
HEADERS += retroshare/rswire.h \
services/p3wire.h \
serialiser/rswireitems.h
SOURCES += services/p3wire.cc \
serialiser/rswireitems.cc \
# Posted Service
HEADERS += services/p3posted.h \
retroshare/rsposted.h \
serialiser/rsposteditems.h
SOURCES += services/p3posted.cc \
serialiser/rsposteditems.cc
#Photo Service
HEADERS += services/p3photoservice.h \
retroshare/rsphoto.h \
serialiser/rsphotoitems.h \
SOURCES += services/p3photoservice.cc \
serialiser/rsphotoitems.cc \
}
newservices {
HEADERS += services/p3photoserviceV2.h \
retroshare/rsphotoVEG.h \
services/p3gxsserviceVEG.h \
services/p3wikiserviceVEG.h \
retroshare/rswikiVEG.h \
retroshare/rswireVEG.h \
services/p3wireVEG.h \
retroshare/rsforumsVEG.h \
services/p3forumsVEG.h
# Do I need this?
#serialiser/rsphotoitemsVEG.h \
# source code for p3gxsserviceVEG / p3postedVEG will be maintained
# until they are finished - for reference... but it wont compile.
SOURCES += services/p3gxsserviceVEG.cc \
services/p3wikiserviceVEG.cc \
services/p3wireVEG.cc \
services/p3forumsVEG.cc
# Do I need this?
# serialiser/rsphotoitemsVEG.cc \
}

View File

@ -1,106 +0,0 @@
#ifndef RETROSHARE_FORUMV2_GUI_INTERFACE_H
#define RETROSHARE_FORUMV2_GUI_INTERFACE_H
/*
* libretroshare/src/retroshare: rsforumv2.h
*
* RetroShare C++ Interface.
*
* Copyright 2012-2012 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.1 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 <inttypes.h>
#include <string>
#include <list>
#include <retroshare/rsidentityVEG.h>
/* The Main Interface Class - for information about your Peers */
class RsForumsVEG;
extern RsForumsVEG *rsForumsVEG;
class RsForumV2Group
{
public:
// All the MetaData is Stored here:
RsGroupMetaData mMeta;
// THESE ARE IN THE META DATA.
//std::string mGroupId;
//std::string mName;
std::string mDescription;
// THESE ARE CURRENTLY UNUSED.
//std::string mCategory;
//std::string mHashTags;
};
class RsForumV2Msg
{
public:
// All the MetaData is Stored here:
RsMsgMetaData mMeta;
// THESE ARE IN THE META DATA.
//std::string mGroupId;
//std::string mMsgId;
//std::string mOrigMsgId;
//std::string mThreadId;
//std::string mParentId;
//std::string mName; (aka. Title)
std::string mMsg; // all the text is stored here.
// THESE ARE CURRENTLY UNUSED.
//std::string mHashTags;
};
class RsForumsVEG: public RsTokenServiceVEG
{
public:
RsForumsVEG() { return; }
virtual ~RsForumsVEG() { return; }
/* Specific Service Data */
virtual bool getGroupData(const uint32_t &token, RsForumV2Group &group) = 0;
virtual bool getMsgData(const uint32_t &token, RsForumV2Msg &msg) = 0;
// ONES THAT WE ARE NOT IMPLEMENTING. (YET!)
//virtual bool getMessageStatus(const std::string& fId, const std::string& mId, uint32_t& status) = 0;
// THINK WE CAN GENERALISE THIS TO: a list function, and you can just count the list entries...
// requestGroupList(groupId, UNREAD, ...)
//virtual bool getMessageCount(const std::string &groupId, unsigned int &newCount, unsigned int &unreadCount) = 0;
/* details are updated in group - to choose GroupID */
virtual bool createGroup(uint32_t &token, RsForumV2Group &group, bool isNew) = 0;
virtual bool createMsg(uint32_t &token, RsForumV2Msg &msg, bool isNew) = 0;
};
#endif

View File

@ -1,534 +0,0 @@
#ifndef RETROSHARE_IDENTITY_GUI_VEG_INTERFACE_H
#define RETROSHARE_IDENTITY_GUI_VEG_INTERFACE_H
/*
* libretroshare/src/retroshare: rsidentity.h
*
* RetroShare C++ Interface.
*
* Copyright 2012-2012 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 <inttypes.h>
#include <string>
#include <list>
// FLAGS WILL BE REUSED FROM RSDISTRIB -> FOR NOW.
#include <retroshare/rsdistrib.h>
/********** Generic Token Request Interface ***********************
* This is packaged here, as most TokenServices will require ID Services too.
* The requests can be generic, but the reponses are service specific (dependent on data types).
*/
// This bit will be filled out over time.
#define RS_TOKREQOPT_MSG_VERSIONS 0x0001 // MSGRELATED: Returns All MsgIds with OrigMsgId = MsgId.
#define RS_TOKREQOPT_MSG_ORIGMSG 0x0002 // MSGLIST: All Unique OrigMsgIds in a Group.
#define RS_TOKREQOPT_MSG_LATEST 0x0004 // MSGLIST: All Latest MsgIds in Group. MSGRELATED: Latest MsgIds for Input Msgs.
#define RS_TOKREQOPT_MSG_THREAD 0x0010 // MSGRELATED: All Msgs in Thread. MSGLIST: All Unique Thread Ids in Group.
#define RS_TOKREQOPT_MSG_PARENT 0x0020 // MSGRELATED: All Children Msgs.
#define RS_TOKREQOPT_MSG_AUTHOR 0x0040 // MSGLIST: Messages from this AuthorId
// Status Filtering... should it be a different Option Field.
#define RS_TOKREQOPT_GROUP_UPDATED 0x0100 // GROUPLIST: Groups that have been updated.
#define RS_TOKREQOPT_MSG_UPDATED 0x0200 // MSGLIST: Msg that have been updated from specified groups.
#define RS_TOKREQOPT_MSG_UPDATED 0x0200 // MSGLIST: Msg that have been updated from specified groups.
// Read Status.
#define RS_TOKREQOPT_READ 0x0001
#define RS_TOKREQOPT_UNREAD 0x0002
#define RS_TOKREQ_ANSTYPE_LIST 0x0001
#define RS_TOKREQ_ANSTYPE_SUMMARY 0x0002
#define RS_TOKREQ_ANSTYPE_DATA 0x0003
class RsTokReqOptionsVEG
{
public:
RsTokReqOptionsVEG()
{
mOptions = 0;
mStatusFilter = 0; mStatusMask = 0;
mFlagsFilter = 0; mFlagsMask = 0;
mSubscribeFilter = 0;
mBefore = 0; mAfter = 0;
}
uint32_t mOptions;
// Request specific matches with Group / Message Status.
// Should be usable with any Options... applied afterwards.
uint32_t mStatusFilter;
uint32_t mStatusMask;
// MsgFlags or GroupsFlags, depends on Request.
uint32_t mFlagsFilter;
uint32_t mFlagsMask;
uint32_t mSubscribeFilter; // Only for Groups.
// Time range... again applied after Options.
time_t mBefore;
time_t mAfter;
};
/*********************************************************
* Documentation for Groups Definitions.
*
* A Group is defined by:
* - TWO RSA Keys. (Admin Key & Publish Key)
* - Publish TS: Used to select the latest definition.
*
* - Operating Mode:
* - Circle (Public, External, Private).
* - Publish Mode: Encrypted / All-Signed / Only ThreadHead / None Required.
* - AuthorId: GPG Required / Any Required / Only if no Publish Signature.
*
* - Description:
* - Name & Description.
* - Optional AuthorId.
*
* Most of this information is contained inside the GroupMetaData.
* except for Actual Admin / Publish Keys, which are maintained internally.
*
*******
* - Group Definition must be signed by Admin Key, otherwise invalid.
* - Circle Definition controls distribution of Group and Messages, see section on this for more details.
* - Public parts of Keys are distributed with Definition.
* - Private parts can be distributed to select people via alternative channels.
* - A Message Requires at least one signature: publish or Author. This signature will be used as MsgId.
*
* Groups will operate in the following modes:
* 1) Public Forum: PublishMode = None Required, AuthorId: Required.
* 2) Closed Forum: PublishMode = All-Signed, AuthorId: Required.
* 3) Private Forum: PublishMode = Encrypted, AuthorId: Required.
*
* 4) Anon Channel: PublishMode = All-Signed, AuthorId: None.
* 5) Anon Channel with Comments: PublishMode = Only ThreadHead, AuthorId: If No Publish Signature.
* 6) Private Channel: PublishMode = Encrypted.
*
* 7) Personal Photos - with comments: PublishMode = Only ThreadHead, AuthorId: Required.
* 8) Personal Photos - no comments: PublishMode = All-Signed, AuthorId: Required.
*
* 9 ) Public Wiki: PublishMode = None Required, AuthorId: Required.
* 10) Closed Wiki: PublishMode = All-Signed, AuthorId: Required.
* 11) Private Wiki: PublishMode = Encrypted, AuthorId: Required.
*
* 12) Twitter: PublishMode = Only ThreadHead, AuthorId: Required.
*
* 13) Posted: PublishMode = None Required, AuthorId: Required.
*
*
******
*
* Additionally to this information. The MetaData also contains several fields which can
* be used to store local information for the benefit of the service.
*
* In Particular: MsgStatus & GroupStatus inform the service if the user has read the message or if anything has changed.
*
***/
// Control of Publish Signatures.
#define RSGXS_GROUP_SIGN_PUBLISH_MASK 0x000000ff
#define RSGXS_GROUP_SIGN_PUBLISH_ENCRYPTED 0x00000001
#define RSGXS_GROUP_SIGN_PUBLISH_ALLSIGNED 0x00000002
#define RSGXS_GROUP_SIGN_PUBLISH_THREADHEAD 0x00000004
#define RSGXS_GROUP_SIGN_PUBLISH_NONEREQ 0x00000008
// Author Signature.
#define RSGXS_GROUP_SIGN_AUTHOR_MASK 0x0000ff00
#define RSGXS_GROUP_SIGN_AUTHOR_GPG 0x00000100
#define RSGXS_GROUP_SIGN_AUTHOR_REQUIRED 0x00000200
#define RSGXS_GROUP_SIGN_AUTHOR_IFNOPUBSIGN 0x00000400
#define RSGXS_GROUP_SIGN_AUTHOR_NONE 0x00000800
// NB: That one signature is required...
// so some combinations are not possible. e.g.
// SIGN_PUBLISH_NONEREQ && SIGN_AUTHOR_NONE is not allowed.
// SIGN_PUBLISH_THREADHEAD && SIGN_AUTHOR_NONE is also invalid.
#define RSGXS_GROUP_SIGN_RESERVED_MASK 0xffff0000
// STATUS FLAGS: There is space here for Service specific flags - if they so desire.
//
// Msgs: UNREAD_BY_USER & PROCESSED are useful.
// Groups: NEW_MESSAGES & GROUP_UPDATED.
#define RSGXS_MSG_STATUS_MASK 0x0000000f
#define RSGXS_MSG_STATUS_READ 0x00000001 // New or Not New
#define RSGXS_MSG_STATUS_UNREAD_BY_USER 0x00000002
#define RSGXS_MSG_STATUS_UNPROCESSED 0x00000004 // By the Service.
#define RSGXS_MSG_STATUS_SERVICE_MASK 0xffff0000
#define RSGXS_GROUP_STATUS_MASK 0x0000000f
#define RSGXS_GROUP_STATUS_UPDATED 0x00000001
#define RSGXS_GROUP_STATUS_NEWGROUP 0x00000002
#define RSGXS_GROUP_STATUS_NEWMSG 0x00000004
#define RSGXS_GROUP_STATUS_SERVICE_MASK 0xffff0000
// Subscription Flags. (LOCAL)
#define RSGXS_GROUP_SUBSCRIBE_MASK 0x0000000f
#define RSGXS_GROUP_SUBSCRIBE_ADMIN 0x00000001
#define RSGXS_GROUP_SUBSCRIBE_PUBLISH 0x00000002
#define RSGXS_GROUP_SUBSCRIBE_SUBSCRIBED 0x00000004
#define RSGXS_GROUP_SUBSCRIBE_MONITOR 0x00000008
// Some MACROS for EASE OF USE. (USED BY FORUMSV2 At the moment.
// MOVED TO REAL GXS STUFF
//#define IS_MSG_UNREAD(status) ((status & RSGXS_MSG_STATUS_READ) == 0 || (status & RSGXS_MSG_STATUS_UNREAD_BY_USER))
//#define IS_GROUP_ADMIN(subscribeFlags) (subscribeFlags & RSGXS_GROUP_SUBSCRIBE_ADMIN)
//#define IS_GROUP_SUBSCRIBED(subscribeFlags) (subscribeFlags & (RSGXS_GROUP_SUBSCRIBE_ADMIN | RSGXS_GROUP_SUBSCRIBE_SUBSCRIBED))
#define RSGXS_MAX_SERVICE_STRING 200 // Sensible limit for dbase usage.
#include "serialiser/rsgxsitems.h"
//class RsGroupMetaData
//{
// public:
//
// RsGroupMetaData()
// {
// mGroupFlags = 0;
// mSignFlags = 0;
// mSubscribeFlags = 0;
//
// mPop = 0;
// mMsgCount = 0;
// mLastPost = 0;
// mGroupStatus = 0;
//
// //mPublishTs = 0;
// }
//
// std::string mGroupId;
// std::string mGroupName;
// uint32_t mGroupFlags; // Service Specific Options ????
// uint32_t mSignFlags; // Combination of RSGXS_GROUP_SIGN_PUBLISH_MASK & RSGXS_GROUP_SIGN_AUTHOR_MASK.
//
// time_t mPublishTs; // Mandatory.
// std::string mAuthorId; // Optional.
//
// // BELOW HERE IS LOCAL DATA, THAT IS NOT FROM MSG.
//
// uint32_t mSubscribeFlags;
//
// uint32_t mPop; // HOW DO WE DO THIS NOW.
// uint32_t mMsgCount; // ???
// time_t mLastPost; // ???
//
// uint32_t mGroupStatus;
//
// std::string mServiceString; // Service Specific Free-Form extra storage.
//};
//
//
//
//
//class RsMsgMetaData
//{
// public:
//
// RsMsgMetaData()
// {
// mPublishTs = 0;
// mMsgFlags = 0;
// mMsgStatus = 0;
// mChildTs = 0;
// }
//
// std::string mGroupId;
// std::string mMsgId;
//
// std::string mThreadId;
// std::string mParentId;
// std::string mOrigMsgId;
//
// std::string mAuthorId;
//
// std::string mMsgName;
// time_t mPublishTs;
//
// uint32_t mMsgFlags; // Whats this for? (Optional Service Specific - e.g. flag MsgType)
//
// // BELOW HERE IS LOCAL DATA, THAT IS NOT FROM MSG.
// // normally READ / UNREAD flags. LOCAL Data.
// uint32_t mMsgStatus;
// time_t mChildTs;
//
// std::string mServiceString; // Service Specific Free-Form extra storage.
//
//};
//std::ostream &operator<<(std::ostream &out, const RsGroupMetaData &meta);
//std::ostream &operator<<(std::ostream &out, const RsMsgMetaData &meta);
class RsTokenServiceVEG
{
public:
RsTokenServiceVEG() { return; }
virtual ~RsTokenServiceVEG() { return; }
/* changed? */
virtual bool updated() = 0;
/* Data Requests */
virtual bool requestGroupInfo( uint32_t &token, uint32_t ansType, const RsTokReqOptionsVEG &opts, const std::list<std::string> &groupIds) = 0;
virtual bool requestMsgInfo( uint32_t &token, uint32_t ansType, const RsTokReqOptionsVEG &opts, const std::list<std::string> &groupIds) = 0;
virtual bool requestMsgRelatedInfo(uint32_t &token, uint32_t ansType, const RsTokReqOptionsVEG &opts, const std::list<std::string> &msgIds) = 0;
/* Generic Lists */
virtual bool getGroupList( const uint32_t &token, std::list<std::string> &groupIds) = 0;
virtual bool getMsgList( const uint32_t &token, std::list<std::string> &msgIds) = 0;
/* Generic Summary */
virtual bool getGroupSummary( const uint32_t &token, std::list<RsGroupMetaData> &groupInfo) = 0;
virtual bool getMsgSummary( const uint32_t &token, std::list<RsMsgMetaData> &msgInfo) = 0;
/* Actual Data -> specific to Interface */
/* Poll */
virtual uint32_t requestStatus(const uint32_t token) = 0;
/* Cancel Request */
virtual bool cancelRequest(const uint32_t &token) = 0;
//////////////////////////////////////////////////////////////////////////////
/* Functions from Forums -> need to be implemented generically */
// Groups Changed is now part of requestGroupInfo request.
//virtual bool groupsChanged(std::list<std::string> &groupIds) = 0;
// Message/Group Status - is retrived via requests...
// These operations could have a token, but for the moment we are going to assume
// they are async and always succeed - (or fail silently).
virtual bool setMessageStatus(const std::string &msgId, const uint32_t status, const uint32_t statusMask) = 0;
virtual bool setGroupStatus(const std::string &grpId, const uint32_t status, const uint32_t statusMask) = 0;
virtual bool setGroupSubscribeFlags(const std::string &groupId, uint32_t subscribeFlags, uint32_t subscribeMask) = 0;
virtual bool setMessageServiceString(const std::string &msgId, const std::string &str) = 0;
virtual bool setGroupServiceString(const std::string &grpId, const std::string &str) = 0;
// (FUTURE WORK).
virtual bool groupRestoreKeys(const std::string &groupId) = 0;
virtual bool groupShareKeys(const std::string &groupId, std::list<std::string>& peers) = 0;
};
/* The Main Interface Class - for information about your Peers */
class RsIdentityVEG;
extern RsIdentityVEG *rsIdentityVEG;
#define RSID_TYPE_MASK 0xff00
#define RSID_RELATION_MASK 0x00ff
#define RSID_TYPE_REALID 0x0100
#define RSID_TYPE_PSEUDONYM 0x0200
#define RSID_RELATION_YOURSELF 0x0001
#define RSID_RELATION_FRIEND 0x0002
#define RSID_RELATION_FOF 0x0004
#define RSID_RELATION_OTHER 0x0008
#define RSID_RELATION_UNKNOWN 0x0010
std::string rsIdTypeToString(uint32_t idtype);
class RsIdGroup
{
public:
RsGroupMetaData mMeta;
// In GroupMetaData.
//std::string mNickname; (mGroupName)
//std::string mKeyId; (mGroupId)
uint32_t mIdType;
std::string mGpgIdHash; // SHA(KeyId + Gpg Fingerprint) -> can only be IDed if GPG known.
// NOTE: These cannot be transmitted as part of underlying messages....
// Must use ServiceString.
bool mGpgIdKnown; // if GpgIdHash has been identified.
std::string mGpgId; // if known.
std::string mGpgName; // if known.
std::string mGpgEmail; // if known.
};
class RsIdMsg
{
public:
RsMsgMetaData mMeta;
// In MsgMetaData.
//std::string mKeyId; (mGroupId)
//std::string mPeerId; (mAuthorId) ???
int mOpinion;
double mReputation;
//int mRating;
//int mPeersRating;
//std::string mComment;
};
std::ostream &operator<<(std::ostream &out, const RsIdGroup &meta);
std::ostream &operator<<(std::ostream &out, const RsIdMsg &meta);
#if 0
class RsIdReputation
{
public:
std::string mKeyId;
int mYourRating;
int mPeersRating;
int mFofRating;
int mTotalRating;
std::string mComment;
};
class RsIdOpinion
{
public:
std::string mKeyId;
std::string mPeerId;
int mRating;
int mPeersRating;
std::string mComment;
};
#endif
class RsIdentityVEG: public RsTokenServiceVEG
{
public:
RsIdentityVEG() { return; }
virtual ~RsIdentityVEG() { return; }
/* INCLUDES INTERFACE FROM RS TOKEN SERVICE */
//////////////////////////////////////////////////////////////////////////////
/* Specific Service Data */
virtual bool getGroupData(const uint32_t &token, RsIdGroup &group) = 0;
virtual bool getMsgData(const uint32_t &token, RsIdMsg &msg) = 0;
virtual bool createGroup(uint32_t &token, RsIdGroup &group, bool isNew) = 0;
virtual bool createMsg(uint32_t &token, RsIdMsg &msg, bool isNew) = 0;
/* In the Identity System - You don't access the Messages Directly.
* as they represent idividuals opinions....
* This is reflected in the TokenService calls returning false.
*
* Below is the additional interface to look at reputation.
*/
/* So we will want to cache much of the identity stuff, so that we have quick access to the results.
* The following bits of data will not use the request/response interface, and should be available immediately.
*
* ID => Nickname, knownGPG, reputation.
*
* This will require quite a bit of data...
* 20 Bytes + 50 + 1 + 4 Bytes? (< 100 Bytes).
* x 10,000 IDs. => ~1 MB of cache (Good).
* x 100,000 IDs. => ~10 MB of cache (Good).
* x 1,000,000 IDs. => ~100 MB of cache (Too Big).
*
* We also need to store quick access to your OwnIds.
*/
//virtual uint32_t getIdDetails(const std::string &id, std::string &nickname, bool &isGpgKnown,
// uint32_t &ownOpinion, float &reputation);
//virtual uint32_t getOwnIds(std::list<std::string> &ownIds);
//virtual bool setOpinion(const std::string &id, uint32_t opinion);
virtual void generateDummyData() = 0;
#if 0
/* Data Requests */
virtual bool requestIdentityList(uint32_t &token) = 0;
virtual bool requestIdentities(uint32_t &token, const std::list<std::string> &ids) = 0;
virtual bool requestIdReputations(uint32_t &token, const std::list<std::string> &ids) = 0;
virtual bool requestIdPeerOpinion(uint32_t &token, const std::string &aboutId, const std::string &peerId) = 0;
//virtual bool requestIdGpgDetails(uint32_t &token, const std::list<std::string> &ids) = 0;
/* Poll */
virtual uint32_t requestStatus(const uint32_t token) = 0;
/* Retrieve Data */
virtual bool getIdentityList(const uint32_t token, std::list<std::string> &ids) = 0;
virtual bool getIdentity(const uint32_t token, RsIdData &data) = 0;
virtual bool getIdReputation(const uint32_t token, RsIdReputation &reputation) = 0;
virtual bool getIdPeerOpinion(const uint32_t token, RsIdOpinion &opinion) = 0;
/* Updates */
virtual bool updateIdentity(RsIdData &data) = 0;
virtual bool updateOpinion(RsIdOpinion &opinion) = 0;
#endif
};
#endif

View File

@ -1,106 +0,0 @@
#ifndef RETROSHARE_WIKI_VEG_GUI_INTERFACE_H
#define RETROSHARE_WIKI_VEG_GUI_INTERFACE_H
/*
* libretroshare/src/retroshare: rswiki.h
*
* RetroShare C++ Interface.
*
* Copyright 2012-2012 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 <inttypes.h>
#include <string>
#include <list>
#include <retroshare/rsidentityVEG.h>
/* The Main Interface Class - for information about your Peers */
class RsWikiVEG;
extern RsWikiVEG *rsWikiVEG;
class RsWikiGroupShare
{
public:
uint32_t mShareType;
std::string mShareGroupId;
std::string mPublishKey;
uint32_t mCommentMode;
uint32_t mResizeMode;
};
class RsWikiGroup
{
public:
RsGroupMetaData mMeta;
//std::string mGroupId;
//std::string mName;
std::string mDescription;
std::string mCategory;
std::string mHashTags;
RsWikiGroupShare mShareOptions;
};
class RsWikiPage
{
public:
RsMsgMetaData mMeta;
// IN META DATA.
//std::string mGroupId;
//std::string mOrigPageId;
//std::string mPageId;
//std::string mName;
// WE SHOULD SWITCH TO USING THREAD/PARENT IDS HERE....
std::string mPrevId;
std::string mPage; // all the text is stored here.
std::string mHashTags;
};
class RsWikiVEG: public RsTokenServiceVEG
{
public:
RsWikiVEG() { return; }
virtual ~RsWikiVEG() { return; }
/* Specific Service Data */
virtual bool getGroupData(const uint32_t &token, RsWikiGroup &group) = 0;
virtual bool getMsgData(const uint32_t &token, RsWikiPage &page) = 0;
virtual bool createGroup(uint32_t &token, RsWikiGroup &group, bool isNew) = 0;
virtual bool createPage(uint32_t &token, RsWikiPage &page, bool isNew) = 0;
};
#endif

View File

@ -30,38 +30,20 @@
#include <string>
#include <list>
#include <retroshare/rsidentityVEG.h>
#include "gxs/rstokenservice.h"
#include "gxs/rsgxsifaceimpl.h"
/* The Main Interface Class - for information about your Peers */
class RsWireVEG;
extern RsWireVEG *rsWireVEG;
class RsWireGroupShare
{
public:
uint32_t mShareType;
std::string mShareGroupId;
std::string mPublishKey;
uint32_t mCommentMode;
uint32_t mResizeMode;
};
class RsWire;
extern RsWire *rsWire;
class RsWireGroup
{
public:
RsGroupMetaData mMeta;
//std::string mGroupId;
//std::string mName;
std::string mDescription;
std::string mCategory;
std::string mHashTags;
RsWireGroupShare mShareOptions;
};
@ -102,46 +84,40 @@ class RsWirePulse
RsMsgMetaData mMeta;
//std::string mGroupId;
//std::string mOrigPageId;
//std::string mPrevId;
//std::string mPageId;
//std::string mName;
std::string mPulseText; // all the text is stored here.
std::string mHashTags;
std::string mPulse; // all the text is stored here.
// These will be added at some point.
// std::string mInReplyPulse;
std::string mInReplyPulse;
// uint32_t mPulseFlags;
uint32_t mPulseFlags;
// std::list<std::string> mMentions;
// std::list<std::string> mHashTags;
// std::list<std::string> mUrls;
std::list<std::string> mMentions;
std::list<std::string> mHashTags;
std::list<std::string> mUrls;
RsWirePlace mPlace;
// RsWirePlace mPlace;
};
std::ostream &operator<<(std::ostream &out, const RsWireGroup &group);
std::ostream &operator<<(std::ostream &out, const RsWirePulse &pulse);
class RsWireVEG: public RsTokenServiceVEG
class RsWire: public RsGxsIfaceImpl
{
public:
RsWireVEG() { return; }
virtual ~RsWireVEG() { return; }
RsWire(RsGenExchange *gxs): RsGxsIfaceImpl(gxs) { return; }
virtual ~RsWire() { return; }
/* Specific Service Data */
virtual bool getGroupData(const uint32_t &token, RsWireGroup &group) = 0;
virtual bool getMsgData(const uint32_t &token, RsWirePulse &pulse) = 0;
virtual bool getGroupData(const uint32_t &token, std::vector<RsWireGroup> &groups) = 0;
virtual bool getPulseData(const uint32_t &token, std::vector<RsWirePulse> &pulses) = 0;
/* Create Stuff */
virtual bool createGroup(uint32_t &token, RsWireGroup &group, bool isNew) = 0;
virtual bool createPulse(uint32_t &token, RsWirePulse &pulse, bool isNew) = 0;
virtual bool createGroup(uint32_t &token, RsWireGroup &group) = 0;
virtual bool createPulse(uint32_t &token, RsWirePulse &pulse) = 0;
};
#endif

View File

@ -1829,12 +1829,7 @@ RsTurtle *rsTurtle = NULL ;
#include "services/p3posted.h"
#include "services/p3photoservice.h"
#include "services/p3gxsforums.h"
// Not too many to convert now!
#include "services/p3wikiserviceVEG.h"
#include "services/p3wireVEG.h"
//#include "services/p3idserviceVEG.h"
//#include "services/p3forumsVEG.h"
#include "services/p3wire.h"
#endif
#ifndef PQI_DISABLE_TUNNEL
@ -2284,7 +2279,8 @@ int RsServer::StartupRetroShare()
// empty and matches an exist directory location
// the given ssl user id then this directory is cleaned
// and deleted
std::string priorGxsDir = "./" + mLinkMgr->getOwnId() + "/", currGxsDir = RsInitConfig::configDir + "/GXS_phase1";
std::string priorGxsDir = "./" + mLinkMgr->getOwnId() + "/";
std::string currGxsDir = RsInitConfig::configDir + "/GXS_phase1";
bool cleanUpGxsDir = false;
if(!priorGxsDir.empty())
@ -2298,21 +2294,6 @@ int RsServer::StartupRetroShare()
else
rmdir(priorGxsDir.c_str());
RsDirUtil::checkCreateDirectory(currGxsDir);
// Testing New Cache Services.
//p3WikiServiceVEG *mWikis = new p3WikiServiceVEG(RS_SERVICE_GXSV1_TYPE_WIKI);
//pqih -> addService(mWikis);
// Testing New Cache Services.
p3WireVEG *mWire = new p3WireVEG(RS_SERVICE_GXSV1_TYPE_WIRE);
pqih -> addService(mWire);
// Testing New Cache Services.
//p3ForumsVEG *mForumsV2 = new p3ForumsVEG(RS_SERVICE_GXSV1_TYPE_FORUMS);
//pqih -> addService(mForumsV2);
// TODO: temporary to store GXS service data, remove
RsDirUtil::checkCreateDirectory(currGxsDir);
@ -2339,7 +2320,6 @@ int RsServer::StartupRetroShare()
/**** Photo service ****/
// create photo authentication policy
uint32_t photoAuthenPolicy = 0;
uint8_t flag = 0;
@ -2404,6 +2384,23 @@ int RsServer::StartupRetroShare()
RsGxsNetService* wiki_ns = new RsGxsNetService(
RS_SERVICE_GXSV1_TYPE_WIKI, wiki_ds, nxsMgr, mWiki);
/**** Wire GXS service ****/
p3Wire *mWire = NULL;
RsGeneralDataService* wire_ds = new RsDataService(currGxsDir + "/", "wire_db",
RS_SERVICE_GXSV1_TYPE_WIRE);
wire_ds->resetDataStore(); //TODO: remove, new service data per RS session, for testing
mWire = new p3Wire(wire_ds, NULL);
// create GXS photo service
RsGxsNetService* wire_ns = new RsGxsNetService(
RS_SERVICE_GXSV1_TYPE_WIRE, wire_ds, nxsMgr, mWire);
/**** Forum GXS service ****/
p3GxsForums *mGxsForums = NULL;
@ -2425,19 +2422,13 @@ int RsServer::StartupRetroShare()
#ifdef ENABLE_GXS_CORE
/*** start up GXS core runner ***/
// GxsCoreServer* mGxsCore = new GxsCoreServer();
//mGxsCore->addService(mGxsIdService);
#if ENABLE_OTHER_GXS_SERVICES
createThread(*mGxsIdService);
createThread(*mPhoto);
createThread(*mPosted);
createThread(*mWiki);
createThread(*mWire);
createThread(*mGxsForums);
//
// mGxsCore->addService(mPhoto);
// mGxsCore->addService(mPosted);
// mGxsCore->addService(mWiki);
#endif
// cores ready start up GXS net servers
@ -2446,6 +2437,7 @@ int RsServer::StartupRetroShare()
createThread(*photo_ns);
createThread(*posted_ns);
createThread(*wiki_ns);
createThread(*wire_ns);
createThread(*gxsforums_ns);
#endif
@ -2458,8 +2450,6 @@ int RsServer::StartupRetroShare()
pqih->addService(gxsforums_ns);
#endif
// start up gxs core server
//createThread(*mGxsCore);
#endif
@ -2728,10 +2718,9 @@ int RsServer::StartupRetroShare()
rsPosted = mPosted;
rsPhoto = mPhoto;
rsGxsForums = mGxsForums;
rsWire = mWire;
#endif
rsWireVEG = mWire;
//rsForumsVEG = mForumsV2;
#endif // ENABLE_GXS_SERVICES
@ -2748,7 +2737,6 @@ int RsServer::StartupRetroShare()
rsGameLauncher = NULL;
#endif
/* put a welcome message in! */
if (RsInitConfig::firsttime_run)
{

View File

@ -198,7 +198,7 @@ bool RsGxsWikiSerialiser::serialiseGxsWikiCollectionItem(RsGxsWikiCollectionItem
#ifdef GXSID_DEBUG
if (!ok)
{
std::cerr << "RsGxsWikiSerialiser::serialiseGxsIdcollectionItem() NOK" << std::endl;
std::cerr << "RsGxsWikiSerialiser::serialiseGxsWikiCollectionItem() NOK" << std::endl;
}
#endif
@ -354,7 +354,7 @@ bool RsGxsWikiSerialiser::serialiseGxsWikiSnapshotItem(RsGxsWikiSnapshotItem *it
#ifdef GXSID_DEBUG
if (!ok)
{
std::cerr << "RsGxsWikiSerialiser::serialiseGxsIdgroupItem() NOK" << std::endl;
std::cerr << "RsGxsWikiSerialiser::serialiseGxsWikiSnapshotItem() NOK" << std::endl;
}
#endif
@ -502,7 +502,7 @@ bool RsGxsWikiSerialiser::serialiseGxsWikiCommentItem(RsGxsWikiCommentItem *item
#ifdef GXSID_DEBUG
if (!ok)
{
std::cerr << "RsGxsWikiSerialiser::serialiseGxsIdgroupItem() NOK" << std::endl;
std::cerr << "RsGxsWikiSerialiser::serialiseGxsWikiCommentItem() NOK" << std::endl;
}
#endif

View File

@ -7,7 +7,7 @@
*
* 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.
* License Version 2.1 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

View File

@ -0,0 +1,408 @@
/*
* libretroshare/src/serialiser: rswikiitems.cc
*
* RetroShare C++ Interface.
*
* Copyright 2012-2012 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.1 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 <iostream>
#include "rswireitems.h"
#include "serialiser/rstlvbase.h"
#include "serialiser/rsbaseserial.h"
#define WIRE_DEBUG 1
uint32_t RsGxsWireSerialiser::size(RsItem *item)
{
RsGxsWireGroupItem* grp_item = NULL;
RsGxsWirePulseItem* snap_item = NULL;
if((grp_item = dynamic_cast<RsGxsWireGroupItem*>(item)) != NULL)
{
return sizeGxsWireGroupItem(grp_item);
}
else if((snap_item = dynamic_cast<RsGxsWirePulseItem*>(item)) != NULL)
{
return sizeGxsWirePulseItem(snap_item);
}
return NULL;
}
bool RsGxsWireSerialiser::serialise(RsItem *item, void *data, uint32_t *size)
{
RsGxsWireGroupItem* grp_item = NULL;
RsGxsWirePulseItem* snap_item = NULL;
if((grp_item = dynamic_cast<RsGxsWireGroupItem*>(item)) != NULL)
{
return serialiseGxsWireGroupItem(grp_item, data, size);
}
else if((snap_item = dynamic_cast<RsGxsWirePulseItem*>(item)) != NULL)
{
return serialiseGxsWirePulseItem(snap_item, data, size);
}
return false;
}
RsItem* RsGxsWireSerialiser::deserialise(void* data, uint32_t* size)
{
#ifdef WIRE_DEBUG
std::cerr << "RsGxsWireSerialiser::deserialise()" << std::endl;
#endif
/* get the type and size */
uint32_t rstype = getRsItemId(data);
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
(RS_SERVICE_GXSV1_TYPE_WIRE != getRsItemService(rstype)))
{
return NULL; /* wrong type */
}
switch(getRsItemSubType(rstype))
{
case RS_PKT_SUBTYPE_WIRE_GROUP_ITEM:
return deserialiseGxsWireGroupItem(data, size);
break;
case RS_PKT_SUBTYPE_WIRE_PULSE_ITEM:
return deserialiseGxsWirePulseItem(data, size);
break;
default:
#ifdef WIRE_DEBUG
std::cerr << "RsGxsWireSerialiser::deserialise(): unknown subtype";
std::cerr << std::endl;
#endif
break;
}
return NULL;
}
/*****************************************************************************************/
/*****************************************************************************************/
/*****************************************************************************************/
void RsGxsWireGroupItem::clear()
{
group.mDescription.clear();
}
std::ostream& RsGxsWireGroupItem::print(std::ostream& out, uint16_t indent)
{
printRsItemBase(out, "RsGxsWireGroupItem", indent);
uint16_t int_Indent = indent + 2;
printIndent(out, int_Indent);
out << "Description: " << group.mDescription << std::endl;
printRsItemEnd(out ,"RsGxsWireGroupItem", indent);
return out;
}
uint32_t RsGxsWireSerialiser::sizeGxsWireGroupItem(RsGxsWireGroupItem *item)
{
const RsWireGroup& group = item->group;
uint32_t s = 8; // header
s += GetTlvStringSize(group.mDescription);
return s;
}
bool RsGxsWireSerialiser::serialiseGxsWireGroupItem(RsGxsWireGroupItem *item, void *data, uint32_t *size)
{
#ifdef WIRE_DEBUG
std::cerr << "RsGxsWireSerialiser::serialiseGxsWireGroupItem()" << std::endl;
#endif
uint32_t tlvsize = sizeGxsWireGroupItem(item);
uint32_t offset = 0;
if(*size < tlvsize)
{
#ifdef WIRE_DEBUG
std::cerr << "RsGxsWireSerialiser::serialiseGxsWireGroupItem()" << std::endl;
#endif
return false;
}
*size = tlvsize;
bool ok = true;
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
/* skip the header */
offset += 8;
/* GxsWireGroupItem */
ok &= SetTlvString(data, tlvsize, &offset, 1, item->group.mDescription);
if(offset != tlvsize)
{
#ifdef WIRE_DEBUG
std::cerr << "RsGxsWireSerialiser::serialiseGxsWireGroupItem() FAIL Size Error! " << std::endl;
#endif
ok = false;
}
#ifdef WIRE_DEBUG
if (!ok)
{
std::cerr << "RsGxsWireSerialiser::serialiseGxsWireGroupItem() NOK" << std::endl;
}
#endif
return ok;
}
RsGxsWireGroupItem* RsGxsWireSerialiser::deserialiseGxsWireGroupItem(void *data, uint32_t *size)
{
#ifdef WIRE_DEBUG
std::cerr << "RsGxsWireSerialiser::deserialiseGxsWireGroupItem()" << std::endl;
#endif
/* 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_GXSV1_TYPE_WIRE != getRsItemService(rstype)) ||
(RS_PKT_SUBTYPE_WIRE_GROUP_ITEM != getRsItemSubType(rstype)))
{
#ifdef WIRE_DEBUG
std::cerr << "RsGxsWireSerialiser::deserialiseGxsWireGroupItem() FAIL wrong type" << std::endl;
#endif
return NULL; /* wrong type */
}
if (*size < rssize) /* check size */
{
#ifdef WIRE_DEBUG
std::cerr << "RsGxsWireSerialiser::deserialiseGxsWireGroupItem() FAIL wrong size" << std::endl;
#endif
return NULL; /* not enough data */
}
/* set the packet length */
*size = rssize;
bool ok = true;
RsGxsWireGroupItem* item = new RsGxsWireGroupItem();
/* skip the header */
offset += 8;
ok &= GetTlvString(data, rssize, &offset, 1, item->group.mDescription);
if (offset != rssize)
{
#ifdef WIRE_DEBUG
std::cerr << "RsGxsWireSerialiser::deserialiseGxsWireGroupItem() FAIL size mismatch" << std::endl;
#endif
/* error */
delete item;
return NULL;
}
if (!ok)
{
#ifdef WIRE_DEBUG
std::cerr << "RsGxsWireSerialiser::deserialiseGxsWireGroupItem() NOK" << std::endl;
#endif
delete item;
return NULL;
}
return item;
}
/*****************************************************************************************/
/*****************************************************************************************/
/*****************************************************************************************/
void RsGxsWirePulseItem::clear()
{
pulse.mPulseText.clear();
pulse.mHashTags.clear();
}
std::ostream& RsGxsWirePulseItem::print(std::ostream& out, uint16_t indent)
{
printRsItemBase(out, "RsGxsWirePulseItem", indent);
uint16_t int_Indent = indent + 2;
printIndent(out, int_Indent);
out << "Page: " << pulse.mPulseText << std::endl;
printIndent(out, int_Indent);
out << "HashTags: " << pulse.mHashTags << std::endl;
printRsItemEnd(out ,"RsGxsWirePulseItem", indent);
return out;
}
uint32_t RsGxsWireSerialiser::sizeGxsWirePulseItem(RsGxsWirePulseItem *item)
{
const RsWirePulse& pulse = item->pulse;
uint32_t s = 8; // header
s += GetTlvStringSize(pulse.mPulseText);
s += GetTlvStringSize(pulse.mHashTags);
return s;
}
bool RsGxsWireSerialiser::serialiseGxsWirePulseItem(RsGxsWirePulseItem *item, void *data, uint32_t *size)
{
#ifdef WIRE_DEBUG
std::cerr << "RsGxsWireSerialiser::serialiseGxsWirePulseItem()" << std::endl;
#endif
uint32_t tlvsize = sizeGxsWirePulseItem(item);
uint32_t offset = 0;
if(*size < tlvsize)
{
#ifdef WIRE_DEBUG
std::cerr << "RsGxsWireSerialiser::serialiseGxsWirePulseItem()" << std::endl;
#endif
return false;
}
*size = tlvsize;
bool ok = true;
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
/* skip the header */
offset += 8;
/* GxsWirePulseItem */
ok &= SetTlvString(data, tlvsize, &offset, 1, item->pulse.mPulseText);
ok &= SetTlvString(data, tlvsize, &offset, 1, item->pulse.mHashTags);
if(offset != tlvsize)
{
#ifdef WIRE_DEBUG
std::cerr << "RsGxsWireSerialiser::serialiseGxsWirePulseItem() FAIL Size Error! " << std::endl;
#endif
ok = false;
}
#ifdef WIRE_DEBUG
if (!ok)
{
std::cerr << "RsGxsWireSerialiser::serialiseGxsWirePulseItem() NOK" << std::endl;
}
#endif
return ok;
}
RsGxsWirePulseItem* RsGxsWireSerialiser::deserialiseGxsWirePulseItem(void *data, uint32_t *size)
{
#ifdef WIRE_DEBUG
std::cerr << "RsGxsWireSerialiser::deserialiseGxsWirePulseItem()" << std::endl;
#endif
/* 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_GXSV1_TYPE_WIRE != getRsItemService(rstype)) ||
(RS_PKT_SUBTYPE_WIRE_PULSE_ITEM != getRsItemSubType(rstype)))
{
#ifdef WIRE_DEBUG
std::cerr << "RsGxsWireSerialiser::deserialiseGxsWirePulseItem() FAIL wrong type" << std::endl;
#endif
return NULL; /* wrong type */
}
if (*size < rssize) /* check size */
{
#ifdef WIRE_DEBUG
std::cerr << "RsGxsWireSerialiser::deserialiseGxsWirePulseItem() FAIL wrong size" << std::endl;
#endif
return NULL; /* not enough data */
}
/* set the packet length */
*size = rssize;
bool ok = true;
RsGxsWirePulseItem* item = new RsGxsWirePulseItem();
/* skip the header */
offset += 8;
ok &= GetTlvString(data, rssize, &offset, 1, item->pulse.mPulseText);
ok &= GetTlvString(data, rssize, &offset, 1, item->pulse.mHashTags);
if (offset != rssize)
{
#ifdef WIRE_DEBUG
std::cerr << "RsGxsWireSerialiser::deserialiseGxsWirePulseItem() FAIL size mismatch" << std::endl;
#endif
/* error */
delete item;
return NULL;
}
if (!ok)
{
#ifdef WIRE_DEBUG
std::cerr << "RsGxsWireSerialiser::deserialiseGxsWirePulseItem() NOK" << std::endl;
#endif
delete item;
return NULL;
}
return item;
}
/*****************************************************************************************/
/*****************************************************************************************/
/*****************************************************************************************/

View File

@ -0,0 +1,93 @@
/*
* libretroshare/src/serialiser: rswireitems.h
*
* RetroShare C++ Interface.
*
* Copyright 2012-2012 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.1 as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA.
*
* Please report all bugs and problems to "retroshare@lunamutt.com".
*
*/
#ifndef RS_WIRE_ITEMS_H
#define RS_WIRE_ITEMS_H
#include <map>
#include "serialiser/rsserviceids.h"
#include "serialiser/rsserial.h"
#include "serialiser/rstlvtypes.h"
#include "rsgxsitems.h"
#include "retroshare/rswire.h"
const uint8_t RS_PKT_SUBTYPE_WIRE_GROUP_ITEM = 0x02;
const uint8_t RS_PKT_SUBTYPE_WIRE_PULSE_ITEM = 0x03;
class RsGxsWireGroupItem : public RsGxsGrpItem
{
public:
RsGxsWireGroupItem(): RsGxsGrpItem(RS_SERVICE_GXSV1_TYPE_WIRE,
RS_PKT_SUBTYPE_WIRE_GROUP_ITEM) { return;}
virtual ~RsGxsWireGroupItem() { return;}
void clear();
std::ostream &print(std::ostream &out, uint16_t indent = 0);
RsWireGroup group;
};
class RsGxsWirePulseItem : public RsGxsMsgItem
{
public:
RsGxsWirePulseItem(): RsGxsMsgItem(RS_SERVICE_GXSV1_TYPE_WIRE,
RS_PKT_SUBTYPE_WIRE_PULSE_ITEM) {return; }
virtual ~RsGxsWirePulseItem() { return;}
void clear();
std::ostream &print(std::ostream &out, uint16_t indent = 0);
RsWirePulse pulse;
};
class RsGxsWireSerialiser : public RsSerialType
{
public:
RsGxsWireSerialiser()
:RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_GXSV1_TYPE_WIRE)
{ return; }
virtual ~RsGxsWireSerialiser() { return; }
uint32_t size(RsItem *item);
bool serialise (RsItem *item, void *data, uint32_t *size);
RsItem * deserialise(void *data, uint32_t *size);
private:
uint32_t sizeGxsWireGroupItem(RsGxsWireGroupItem *item);
bool serialiseGxsWireGroupItem (RsGxsWireGroupItem *item, void *data, uint32_t *size);
RsGxsWireGroupItem * deserialiseGxsWireGroupItem(void *data, uint32_t *size);
uint32_t sizeGxsWirePulseItem(RsGxsWirePulseItem *item);
bool serialiseGxsWirePulseItem (RsGxsWirePulseItem *item, void *data, uint32_t *size);
RsGxsWirePulseItem * deserialiseGxsWirePulseItem(void *data, uint32_t *size);
};
#endif /* RS_WIKI_ITEMS_H */

View File

@ -1,805 +0,0 @@
/*
* libretroshare/src/services p3forumsv2.cc
*
* ForumsV2 interface for RetroShare.
*
* Copyright 2012-2012 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.1 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/p3forumsVEG.h"
#include "util/rsrandom.h"
#include <stdio.h>
/****
* #define FORUMV2_DEBUG 1
****/
RsForumsVEG *rsForumsVEG = NULL;
/********************************************************************************/
/******************* Startup / Tick ******************************************/
/********************************************************************************/
p3ForumsVEG::p3ForumsVEG(uint16_t type)
:p3GxsDataServiceVEG(type, new ForumDataProxy()), mForumMtx("p3ForumsV2"), mUpdated(true)
{
{
RsStackMutex stack(mForumMtx); /********** STACK LOCKED MTX ******/
mForumProxy = (ForumDataProxy *) mProxy;
}
generateDummyData();
return;
}
int p3ForumsVEG::tick()
{
//std::cerr << "p3ForumsVEG::tick()";
//std::cerr << std::endl;
fakeprocessrequests();
return 0;
}
bool p3ForumsVEG::updated()
{
RsStackMutex stack(mForumMtx); /********** STACK LOCKED MTX ******/
if (mUpdated)
{
mUpdated = false;
return true;
}
return false;
}
/* Data Requests */
bool p3ForumsVEG::requestGroupInfo( uint32_t &token, uint32_t ansType, const RsTokReqOptionsVEG &opts, const std::list<std::string> &groupIds)
{
generateToken(token);
std::cerr << "p3ForumsVEG::requestGroupInfo() gets Token: " << token << std::endl;
storeRequest(token, ansType, opts, GXS_REQUEST_TYPE_GROUPS, groupIds);
return true;
}
bool p3ForumsVEG::requestMsgInfo( uint32_t &token, uint32_t ansType, const RsTokReqOptionsVEG &opts, const std::list<std::string> &groupIds)
{
generateToken(token);
std::cerr << "p3ForumsVEG::requestMsgInfo() gets Token: " << token << std::endl;
storeRequest(token, ansType, opts, GXS_REQUEST_TYPE_MSGS, groupIds);
return true;
}
bool p3ForumsVEG::requestMsgRelatedInfo(uint32_t &token, uint32_t ansType, const RsTokReqOptionsVEG &opts, const std::list<std::string> &msgIds)
{
generateToken(token);
std::cerr << "p3ForumsVEG::requestMsgRelatedInfo() gets Token: " << token << std::endl;
storeRequest(token, ansType, opts, GXS_REQUEST_TYPE_MSGRELATED, msgIds);
return true;
}
/* Generic Lists */
bool p3ForumsVEG::getGroupList( const uint32_t &token, std::list<std::string> &groupIds)
{
uint32_t status;
uint32_t reqtype;
uint32_t anstype;
time_t ts;
checkRequestStatus(token, status, reqtype, anstype, ts);
if (anstype != RS_TOKREQ_ANSTYPE_LIST)
{
std::cerr << "p3ForumsVEG::getGroupList() ERROR AnsType Wrong" << std::endl;
return false;
}
if (reqtype != GXS_REQUEST_TYPE_GROUPS)
{
std::cerr << "p3ForumsVEG::getGroupList() ERROR ReqType Wrong" << std::endl;
return false;
}
if (status != GXS_REQUEST_STATUS_COMPLETE)
{
std::cerr << "p3ForumsVEG::getGroupList() ERROR Status Incomplete" << std::endl;
return false;
}
bool ans = loadRequestOutList(token, groupIds);
updateRequestStatus(token, GXS_REQUEST_STATUS_DONE);
return ans;
}
bool p3ForumsVEG::getMsgList( const uint32_t &token, std::list<std::string> &msgIds)
{
uint32_t status;
uint32_t reqtype;
uint32_t anstype;
time_t ts;
checkRequestStatus(token, status, reqtype, anstype, ts);
if (anstype != RS_TOKREQ_ANSTYPE_LIST)
{
std::cerr << "p3ForumsVEG::getMsgList() ERROR AnsType Wrong" << std::endl;
return false;
}
if ((reqtype != GXS_REQUEST_TYPE_MSGS) && (reqtype != GXS_REQUEST_TYPE_MSGRELATED))
{
std::cerr << "p3ForumsVEG::getMsgList() ERROR ReqType Wrong" << std::endl;
return false;
}
if (status != GXS_REQUEST_STATUS_COMPLETE)
{
std::cerr << "p3ForumsVEG::getMsgList() ERROR Status Incomplete" << std::endl;
return false;
}
bool ans = loadRequestOutList(token, msgIds);
updateRequestStatus(token, GXS_REQUEST_STATUS_DONE);
return ans;
}
/* Generic Summary */
bool p3ForumsVEG::getGroupSummary( const uint32_t &token, std::list<RsGroupMetaData> &groupInfo)
{
uint32_t status;
uint32_t reqtype;
uint32_t anstype;
time_t ts;
checkRequestStatus(token, status, reqtype, anstype, ts);
if (anstype != RS_TOKREQ_ANSTYPE_SUMMARY)
{
std::cerr << "p3ForumsVEG::getGroupSummary() ERROR AnsType Wrong" << std::endl;
return false;
}
if (reqtype != GXS_REQUEST_TYPE_GROUPS)
{
std::cerr << "p3ForumsVEG::getGroupSummary() ERROR ReqType Wrong" << std::endl;
return false;
}
if (status != GXS_REQUEST_STATUS_COMPLETE)
{
std::cerr << "p3ForumsVEG::getGroupSummary() ERROR Status Incomplete" << std::endl;
return false;
}
std::list<std::string> groupIds;
bool ans = loadRequestOutList(token, groupIds);
updateRequestStatus(token, GXS_REQUEST_STATUS_DONE);
/* convert to RsGroupMetaData */
mProxy->getGroupSummary(groupIds, groupInfo);
return ans;
}
bool p3ForumsVEG::getMsgSummary( const uint32_t &token, std::list<RsMsgMetaData> &msgInfo)
{
uint32_t status;
uint32_t reqtype;
uint32_t anstype;
time_t ts;
checkRequestStatus(token, status, reqtype, anstype, ts);
if (anstype != RS_TOKREQ_ANSTYPE_SUMMARY)
{
std::cerr << "p3ForumsVEG::getMsgSummary() ERROR AnsType Wrong" << std::endl;
return false;
}
if ((reqtype != GXS_REQUEST_TYPE_MSGS) && (reqtype != GXS_REQUEST_TYPE_MSGRELATED))
{
std::cerr << "p3ForumsVEG::getMsgSummary() ERROR ReqType Wrong" << std::endl;
return false;
}
if (status != GXS_REQUEST_STATUS_COMPLETE)
{
std::cerr << "p3ForumsVEG::getMsgSummary() ERROR Status Incomplete" << std::endl;
return false;
}
std::list<std::string> msgIds;
bool ans = loadRequestOutList(token, msgIds);
updateRequestStatus(token, GXS_REQUEST_STATUS_DONE);
/* convert to RsMsgMetaData */
mProxy->getMsgSummary(msgIds, msgInfo);
return ans;
}
/* Specific Service Data */
bool p3ForumsVEG::getGroupData(const uint32_t &token, RsForumV2Group &group)
{
uint32_t status;
uint32_t reqtype;
uint32_t anstype;
time_t ts;
checkRequestStatus(token, status, reqtype, anstype, ts);
if (anstype != RS_TOKREQ_ANSTYPE_DATA)
{
std::cerr << "p3ForumsVEG::getGroupData() ERROR AnsType Wrong" << std::endl;
return false;
}
if (reqtype != GXS_REQUEST_TYPE_GROUPS)
{
std::cerr << "p3ForumsVEG::getGroupData() ERROR ReqType Wrong" << std::endl;
return false;
}
if (status != GXS_REQUEST_STATUS_COMPLETE)
{
std::cerr << "p3ForumsVEG::getGroupData() ERROR Status Incomplete" << std::endl;
return false;
}
std::string id;
if (!popRequestOutList(token, id))
{
/* finished */
updateRequestStatus(token, GXS_REQUEST_STATUS_DONE);
return false;
}
/* convert to RsForumAlbum */
bool ans = mForumProxy->getForumGroup(id, group);
return ans;
}
bool p3ForumsVEG::getMsgData(const uint32_t &token, RsForumV2Msg &msg)
{
uint32_t status;
uint32_t reqtype;
uint32_t anstype;
time_t ts;
checkRequestStatus(token, status, reqtype, anstype, ts);
if (anstype != RS_TOKREQ_ANSTYPE_DATA)
{
std::cerr << "p3ForumsVEG::getMsgData() ERROR AnsType Wrong" << std::endl;
return false;
}
if ((reqtype != GXS_REQUEST_TYPE_MSGS) && (reqtype != GXS_REQUEST_TYPE_MSGRELATED))
{
std::cerr << "p3ForumsVEG::getMsgData() ERROR ReqType Wrong" << std::endl;
return false;
}
if (status != GXS_REQUEST_STATUS_COMPLETE)
{
std::cerr << "p3ForumsVEG::getMsgData() ERROR Status Incomplete" << std::endl;
return false;
}
std::string id;
if (!popRequestOutList(token, id))
{
/* finished */
updateRequestStatus(token, GXS_REQUEST_STATUS_DONE);
return false;
}
/* convert to RsForumAlbum */
bool ans = mForumProxy->getForumMsg(id, msg);
return ans;
}
/* Poll */
uint32_t p3ForumsVEG::requestStatus(const uint32_t token)
{
uint32_t status;
uint32_t reqtype;
uint32_t anstype;
time_t ts;
checkRequestStatus(token, status, reqtype, anstype, ts);
return status;
}
/* Cancel Request */
bool p3ForumsVEG::cancelRequest(const uint32_t &token)
{
return clearRequest(token);
}
//////////////////////////////////////////////////////////////////////////////
bool p3ForumsVEG::setMessageStatus(const std::string &msgId, const uint32_t status, const uint32_t statusMask)
{
return mForumProxy->setMessageStatus(msgId, status, statusMask);
}
bool p3ForumsVEG::setGroupStatus(const std::string &groupId, const uint32_t status, const uint32_t statusMask)
{
return mForumProxy->setGroupStatus(groupId, status, statusMask);
}
bool p3ForumsVEG::setGroupSubscribeFlags(const std::string &groupId, uint32_t subscribeFlags, uint32_t subscribeMask)
{
return mForumProxy->setGroupSubscribeFlags(groupId, subscribeFlags, subscribeMask);
}
bool p3ForumsVEG::setMessageServiceString(const std::string &msgId, const std::string &str)
{
return mForumProxy->setMessageServiceString(msgId, str);
}
bool p3ForumsVEG::setGroupServiceString(const std::string &grpId, const std::string &str)
{
return mForumProxy->setGroupServiceString(grpId, str);
}
bool p3ForumsVEG::groupRestoreKeys(const std::string &groupId)
{
return false;
}
bool p3ForumsVEG::groupShareKeys(const std::string &groupId, std::list<std::string>& peers)
{
return false;
}
/********************************************************************************************/
std::string p3ForumsVEG::genRandomId()
{
std::string randomId;
for(int i = 0; i < 20; i++)
{
randomId += (char) ('a' + (RSRandom::random_u32() % 26));
}
return randomId;
}
bool p3ForumsVEG::createGroup(uint32_t &token, RsForumV2Group &group, bool isNew)
{
if (group.mMeta.mGroupId.empty())
{
/* new photo */
/* generate a temp id */
group.mMeta.mGroupId = genRandomId();
}
else
{
std::cerr << "p3ForumsVEG::createGroup() Group with existing Id... dropping";
std::cerr << std::endl;
return false;
}
{
RsStackMutex stack(mForumMtx); /********** STACK LOCKED MTX ******/
mUpdated = true;
mForumProxy->addForumGroup(group);
}
// Fake a request to return the GroupMetaData.
generateToken(token);
uint32_t ansType = RS_TOKREQ_ANSTYPE_SUMMARY;
RsTokReqOptionsVEG opts; // NULL is good.
std::list<std::string> groupIds;
groupIds.push_back(group.mMeta.mGroupId); // It will just return this one.
std::cerr << "p3ForumsVEG::createGroup() Generating Request Token: " << token << std::endl;
storeRequest(token, ansType, opts, GXS_REQUEST_TYPE_GROUPS, groupIds);
return true;
}
bool p3ForumsVEG::createMsg(uint32_t &token, RsForumV2Msg &msg, bool isNew)
{
if (msg.mMeta.mGroupId.empty())
{
/* new photo */
std::cerr << "p3ForumsVEG::createForumMsg() Missing MsgID";
std::cerr << std::endl;
return false;
}
/* check if its a mod or new msg */
if (msg.mMeta.mOrigMsgId.empty())
{
std::cerr << "p3ForumsVEG::createForumMsg() New Msg";
std::cerr << std::endl;
/* new msg, generate a new OrigMsgId */
msg.mMeta.mOrigMsgId = genRandomId();
msg.mMeta.mMsgId = msg.mMeta.mOrigMsgId;
}
else
{
std::cerr << "p3ForumsVEG::createForumMsg() Modified Msg";
std::cerr << std::endl;
/* mod msg, keep orig msg id, generate a new MsgId */
msg.mMeta.mMsgId = genRandomId();
}
std::cerr << "p3ForumsVEG::createForumMsg() GroupId: " << msg.mMeta.mGroupId;
std::cerr << std::endl;
std::cerr << "p3ForumsVEG::createForumMsg() MsgId: " << msg.mMeta.mMsgId;
std::cerr << std::endl;
std::cerr << "p3ForumsVEG::createForumMsg() OrigMsgId: " << msg.mMeta.mOrigMsgId;
std::cerr << std::endl;
{
RsStackMutex stack(mForumMtx); /********** STACK LOCKED MTX ******/
mUpdated = true;
mForumProxy->addForumMsg(msg);
}
// Fake a request to return the MsgMetaData.
generateToken(token);
uint32_t ansType = RS_TOKREQ_ANSTYPE_SUMMARY;
RsTokReqOptionsVEG opts; // NULL is good.
std::list<std::string> msgIds;
msgIds.push_back(msg.mMeta.mMsgId); // It will just return this one.
std::cerr << "p3ForumsVEG::createMsg() Generating Request Token: " << token << std::endl;
storeRequest(token, ansType, opts, GXS_REQUEST_TYPE_MSGRELATED, msgIds);
return true;
}
/********************************************************************************************/
bool ForumDataProxy::getForumGroup(const std::string &id, RsForumV2Group &group)
{
void *groupData = NULL;
RsGroupMetaData meta;
if (getGroupData(id, groupData) && getGroupSummary(id, meta))
{
RsForumV2Group *pG = (RsForumV2Group *) groupData;
group = *pG;
// update definitive version of the metadata.
group.mMeta = meta;
std::cerr << "ForumDataProxy::getForumGroup() Id: " << id;
std::cerr << " MetaData: " << meta << " DataPointer: " << groupData;
std::cerr << std::endl;
return true;
}
std::cerr << "ForumDataProxy::getForumGroup() FAILED Id: " << id;
std::cerr << std::endl;
return false;
}
bool ForumDataProxy::getForumMsg(const std::string &id, RsForumV2Msg &page)
{
void *msgData = NULL;
RsMsgMetaData meta;
if (getMsgData(id, msgData) && getMsgSummary(id, meta))
{
RsForumV2Msg *pP = (RsForumV2Msg *) msgData;
// Shallow copy of thumbnail.
page = *pP;
// update definitive version of the metadata.
page.mMeta = meta;
std::cerr << "ForumDataProxy::getForumMsg() Id: " << id;
std::cerr << " MetaData: " << meta << " DataPointer: " << msgData;
std::cerr << std::endl;
return true;
}
std::cerr << "ForumDataProxy::getForumMsg() FAILED Id: " << id;
std::cerr << std::endl;
return false;
}
bool ForumDataProxy::addForumGroup(const RsForumV2Group &group)
{
// Make duplicate.
RsForumV2Group *pG = new RsForumV2Group();
*pG = group;
std::cerr << "ForumDataProxy::addForumGroup()";
std::cerr << " MetaData: " << pG->mMeta << " DataPointer: " << pG;
std::cerr << std::endl;
return createGroup(pG);
}
bool ForumDataProxy::addForumMsg(const RsForumV2Msg &msg)
{
// Make duplicate.
RsForumV2Msg *pM = new RsForumV2Msg();
*pM = msg;
std::cerr << "ForumDataProxy::addForumMsg()";
std::cerr << " MetaData: " << pM->mMeta << " DataPointer: " << pM;
std::cerr << std::endl;
return createMsg(pM);
}
/* These Functions must be overloaded to complete the service */
bool ForumDataProxy::convertGroupToMetaData(void *groupData, RsGroupMetaData &meta)
{
RsForumV2Group *group = (RsForumV2Group *) groupData;
meta = group->mMeta;
return true;
}
bool ForumDataProxy::convertMsgToMetaData(void *msgData, RsMsgMetaData &meta)
{
RsForumV2Msg *page = (RsForumV2Msg *) msgData;
meta = page->mMeta;
return true;
}
/********************************************************************************************/
bool p3ForumsVEG::generateDummyData()
{
/* so we want to generate 100's of forums */
#define MAX_FORUMS 10 //100
#define MAX_THREADS 10 //1000
#define MAX_MSGS 100 //10000
std::list<RsForumV2Group> mGroups;
std::list<RsForumV2Group>::iterator git;
std::list<RsForumV2Msg> mMsgs;
std::list<RsForumV2Msg>::iterator mit;
#define DUMMY_NAME_MAX_LEN 10000
char name[DUMMY_NAME_MAX_LEN];
int i, j;
time_t now = time(NULL);
for(i = 0; i < MAX_FORUMS; i++)
{
/* generate a new forum */
RsForumV2Group forum;
/* generate a temp id */
forum.mMeta.mGroupId = genRandomId();
snprintf(name, DUMMY_NAME_MAX_LEN, "TestForum_%d", i+1);
forum.mMeta.mGroupId = genRandomId();
forum.mMeta.mGroupName = name;
forum.mMeta.mPublishTs = now - (RSRandom::random_f32() * 100000);
/* key fields to fill in:
* GroupId.
* Name.
* Flags.
* Pop.
*/
/* use probability to decide which are subscribed / own / popularity.
*/
float rnd = RSRandom::random_f32();
if (rnd < 0.1)
{
forum.mMeta.mSubscribeFlags = RSGXS_GROUP_SUBSCRIBE_ADMIN;
}
else if (rnd < 0.3)
{
forum.mMeta.mSubscribeFlags = RSGXS_GROUP_SUBSCRIBE_SUBSCRIBED;
}
else
{
forum.mMeta.mSubscribeFlags = 0;
}
forum.mMeta.mPop = (int) (RSRandom::random_f32() * 10.0);
mGroups.push_back(forum);
//std::cerr << "p3ForumsVEG::generateDummyData() Generated Forum: " << forum.mMeta;
//std::cerr << std::endl;
}
for(i = 0; i < MAX_THREADS; i++)
{
/* generate a base thread */
/* rotate the Forum Groups Around, then pick one.
*/
int rnd = (int) (RSRandom::random_f32() * 10.0);
for(j = 0; j < rnd; j++)
{
RsForumV2Group head = mGroups.front();
mGroups.pop_front();
mGroups.push_back(head);
}
RsForumV2Group forum = mGroups.front();
/* now create a new thread */
RsForumV2Msg msg;
/* fill in key data
* GroupId
* MsgId
* OrigMsgId
* ThreadId
* ParentId
* PublishTS (take Forum TS + a bit ).
*
* ChildTS ????
*/
snprintf(name, DUMMY_NAME_MAX_LEN, "%s => ThreadMsg_%d", forum.mMeta.mGroupName.c_str(), i+1);
msg.mMeta.mMsgName = name;
msg.mMeta.mGroupId = forum.mMeta.mGroupId;
msg.mMeta.mMsgId = genRandomId();
msg.mMeta.mOrigMsgId = msg.mMeta.mMsgId;
msg.mMeta.mThreadId = msg.mMeta.mMsgId;
msg.mMeta.mParentId = "";
msg.mMeta.mPublishTs = forum.mMeta.mPublishTs + (RSRandom::random_f32() * 10000);
if (msg.mMeta.mPublishTs > now)
msg.mMeta.mPublishTs = now - 1;
mMsgs.push_back(msg);
//std::cerr << "p3ForumsVEG::generateDummyData() Generated Thread: " << msg.mMeta;
//std::cerr << std::endl;
}
for(i = 0; i < MAX_MSGS; i++)
{
/* generate a base thread */
/* rotate the Forum Groups Around, then pick one.
*/
int rnd = (int) (RSRandom::random_f32() * 10.0);
for(j = 0; j < rnd; j++)
{
RsForumV2Msg head = mMsgs.front();
mMsgs.pop_front();
mMsgs.push_back(head);
}
RsForumV2Msg parent = mMsgs.front();
/* now create a new child msg */
RsForumV2Msg msg;
/* fill in key data
* GroupId
* MsgId
* OrigMsgId
* ThreadId
* ParentId
* PublishTS (take Forum TS + a bit ).
*
* ChildTS ????
*/
snprintf(name, DUMMY_NAME_MAX_LEN, "%s => Msg_%d", parent.mMeta.mMsgName.c_str(), i+1);
msg.mMeta.mMsgName = name;
msg.mMsg = name;
msg.mMeta.mGroupId = parent.mMeta.mGroupId;
msg.mMeta.mMsgId = genRandomId();
msg.mMeta.mOrigMsgId = msg.mMeta.mMsgId;
msg.mMeta.mThreadId = parent.mMeta.mThreadId;
msg.mMeta.mParentId = parent.mMeta.mOrigMsgId;
msg.mMeta.mPublishTs = parent.mMeta.mPublishTs + (RSRandom::random_f32() * 10000);
if (msg.mMeta.mPublishTs > now)
msg.mMeta.mPublishTs = now - 1;
mMsgs.push_back(msg);
//std::cerr << "p3ForumsVEG::generateDummyData() Generated Child Msg: " << msg.mMeta;
//std::cerr << std::endl;
}
mUpdated = true;
/* Then - at the end, we push them all into the Proxy */
for(git = mGroups.begin(); git != mGroups.end(); git++)
{
/* pushback */
mForumProxy->addForumGroup(*git);
}
for(mit = mMsgs.begin(); mit != mMsgs.end(); mit++)
{
/* pushback */
mForumProxy->addForumMsg(*mit);
}
return true;
}

View File

@ -1,126 +0,0 @@
/*
* libretroshare/src/services: p3forumsv2.h
*
* Wiki interface for RetroShare.
*
* Copyright 2012-2012 by Robert Fernie.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License Version 2 as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA.
*
* Please report all bugs and problems to "retroshare@lunamutt.com".
*
*/
#ifndef P3_FORUMSV2_SERVICE_HEADER
#define P3_FORUMSV2_SERVICE_HEADER
#include "services/p3gxsserviceVEG.h"
#include "retroshare/rsforumsVEG.h"
#include <map>
#include <string>
/*
*
*/
class ForumDataProxy: public GxsDataProxyVEG
{
public:
bool getForumGroup(const std::string &id, RsForumV2Group &group);
bool getForumMsg(const std::string &id, RsForumV2Msg &msg);
bool addForumGroup(const RsForumV2Group &group);
bool addForumMsg(const RsForumV2Msg &msg);
/* These Functions must be overloaded to complete the service */
virtual bool convertGroupToMetaData(void *groupData, RsGroupMetaData &meta);
virtual bool convertMsgToMetaData(void *msgData, RsMsgMetaData &meta);
};
class p3ForumsVEG: public p3GxsDataServiceVEG, public RsForumsVEG
{
public:
p3ForumsVEG(uint16_t type);
virtual int tick();
public:
virtual bool updated();
/* Data Requests */
virtual bool requestGroupInfo( uint32_t &token, uint32_t ansType, const RsTokReqOptionsVEG &opts, const std::list<std::string> &groupIds);
virtual bool requestMsgInfo( uint32_t &token, uint32_t ansType, const RsTokReqOptionsVEG &opts, const std::list<std::string> &groupIds);
virtual bool requestMsgRelatedInfo(uint32_t &token, uint32_t ansType, const RsTokReqOptionsVEG &opts, const std::list<std::string> &msgIds);
/* Generic Lists */
virtual bool getGroupList( const uint32_t &token, std::list<std::string> &groupIds);
virtual bool getMsgList( const uint32_t &token, std::list<std::string> &msgIds);
/* Generic Summary */
virtual bool getGroupSummary( const uint32_t &token, std::list<RsGroupMetaData> &groupInfo);
virtual bool getMsgSummary( const uint32_t &token, std::list<RsMsgMetaData> &msgInfo);
/* Actual Data -> specific to Interface */
/* Specific Service Data */
virtual bool getGroupData(const uint32_t &token, RsForumV2Group &group);
virtual bool getMsgData(const uint32_t &token, RsForumV2Msg &msg);
/* Poll */
virtual uint32_t requestStatus(const uint32_t token);
/* Cancel Request */
virtual bool cancelRequest(const uint32_t &token);
//////////////////////////////////////////////////////////////////////////////
virtual bool setMessageStatus(const std::string &msgId, const uint32_t status, const uint32_t statusMask);
virtual bool setGroupStatus(const std::string &groupId, const uint32_t status, const uint32_t statusMask);
virtual bool setGroupSubscribeFlags(const std::string &groupId, uint32_t subscribeFlags, uint32_t subscribeMask);
virtual bool setMessageServiceString(const std::string &msgId, const std::string &str);
virtual bool setGroupServiceString(const std::string &grpId, const std::string &str);
virtual bool groupRestoreKeys(const std::string &groupId);
virtual bool groupShareKeys(const std::string &groupId, std::list<std::string>& peers);
virtual bool createGroup(uint32_t &token, RsForumV2Group &group, bool isNew);
virtual bool createMsg(uint32_t &token, RsForumV2Msg &msg, bool isNew);
private:
std::string genRandomId();
bool generateDummyData();
ForumDataProxy *mForumProxy;
RsMutex mForumMtx;
/***** below here is locked *****/
bool mUpdated;
};
#endif

File diff suppressed because it is too large Load Diff

View File

@ -1,186 +0,0 @@
/*
* libretroshare/src/services: p3idservice.h
*
* Identity interface for RetroShare.
*
* Copyright 2012-2012 by Robert Fernie.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License Version 2 as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA.
*
* Please report all bugs and problems to "retroshare@lunamutt.com".
*
*/
#ifndef P3_IDENTITY_SERVICE_VEG_HEADER
#define P3_IDENTITY_SERVICE_VEG_HEADER
#include "services/p3service.h"
#include "services/p3gxsserviceVEG.h"
#include "retroshare/rsidentityVEG.h"
#include <map>
#include <string>
/*
* Identity Service
*
*/
class IdDataProxy: public GxsDataProxyVEG
{
public:
bool getGroup(const std::string &id, RsIdGroup &group);
bool getMsg(const std::string &id, RsIdMsg &msg);
bool addGroup(const RsIdGroup &group);
bool addMsg(const RsIdMsg &msg);
/* These Functions must be overloaded to complete the service */
virtual bool convertGroupToMetaData(void *groupData, RsGroupMetaData &meta);
virtual bool convertMsgToMetaData(void *msgData, RsMsgMetaData &meta);
};
// INTERNAL DATA TYPES...
// Describes data stored in GroupServiceString.
class IdRepCumulScore
{
public:
uint32_t count;
uint32_t nullcount;
double sum;
double sumsq;
// derived parameters:
};
class IdGroupServiceStrData
{
public:
IdGroupServiceStrData() { pgpIdKnown = false; }
bool pgpIdKnown;
std::string pgpId;
uint32_t ownScore;
IdRepCumulScore opinion;
IdRepCumulScore reputation;
};
#define ID_LOCAL_STATUS_FULL_CALC_FLAG 0x00010000
#define ID_LOCAL_STATUS_INC_CALC_FLAG 0x00020000
class p3IdServiceVEG: public p3GxsDataServiceVEG, public RsIdentityVEG
{
public:
p3IdServiceVEG(uint16_t type);
virtual int tick();
public:
/* changed? */
virtual bool updated();
/* From RsTokenService */
/* Data Requests */
virtual bool requestGroupInfo( uint32_t &token, uint32_t ansType, const RsTokReqOptionsVEG &opts, const std::list<std::string> &groupIds);
virtual bool requestMsgInfo( uint32_t &token, uint32_t ansType, const RsTokReqOptionsVEG &opts, const std::list<std::string> &groupIds);
virtual bool requestMsgRelatedInfo(uint32_t &token, uint32_t ansType, const RsTokReqOptionsVEG &opts, const std::list<std::string> &msgIds);
/* Generic Lists */
virtual bool getGroupList( const uint32_t &token, std::list<std::string> &groupIds);
virtual bool getMsgList( const uint32_t &token, std::list<std::string> &msgIds);
/* Generic Summary */
virtual bool getGroupSummary( const uint32_t &token, std::list<RsGroupMetaData> &groupInfo);
virtual bool getMsgSummary( const uint32_t &token, std::list<RsMsgMetaData> &msgInfo);
/* Actual Data -> specific to Interface */
virtual bool getGroupData(const uint32_t &token, RsIdGroup &group);
virtual bool getMsgData(const uint32_t &token, RsIdMsg &msg);
/* Poll */
virtual uint32_t requestStatus(const uint32_t token);
/* Cancel Request */
virtual bool cancelRequest(const uint32_t &token);
//////////////////////////////////////////////////////////////////////////////
virtual bool setMessageStatus(const std::string &msgId, const uint32_t status, const uint32_t statusMask);
virtual bool setGroupStatus(const std::string &groupId, const uint32_t status, const uint32_t statusMask);
virtual bool setGroupSubscribeFlags(const std::string &groupId, uint32_t subscribeFlags, uint32_t subscribeMask);
virtual bool setMessageServiceString(const std::string &msgId, const std::string &str);
virtual bool setGroupServiceString(const std::string &grpId, const std::string &str);
virtual bool groupRestoreKeys(const std::string &groupId);
virtual bool groupShareKeys(const std::string &groupId, std::list<std::string>& peers);
virtual bool createGroup(uint32_t &token, RsIdGroup &group, bool isNew);
virtual bool createMsg(uint32_t &token, RsIdMsg &msg, bool isNew);
private:
virtual void generateDummyData();
std::string genRandomId();
int background_tick();
bool background_checkTokenRequest();
bool background_requestGroups();
bool background_requestNewMessages();
bool background_processNewMessages();
bool background_FullCalcRequest();
bool background_processFullCalc();
bool background_cleanup();
bool encodeIdGroupCache(std::string &str, const IdGroupServiceStrData &data);
bool extractIdGroupCache(std::string &str, IdGroupServiceStrData &data);
IdDataProxy *mIdProxy;
RsMutex mIdMtx;
/***** below here is locked *****/
bool mLastBgCheck;
bool mBgProcessing;
uint32_t mBgToken;
uint32_t mBgPhase;
std::map<std::string, RsGroupMetaData> mBgGroupMap;
std::list<std::string> mBgFullCalcGroups;
bool mUpdated;
#if 0
std::map<std::string, RsIdData> mIds;
std::map<std::string, std::map<std::string, RsIdOpinion> > mOpinions;
std::map<std::string, RsIdReputation> mReputations; // this is created locally.
#endif
};
#endif

View File

@ -7,7 +7,7 @@
*
* 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.
* License Version 2.1 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

View File

@ -7,7 +7,7 @@
*
* 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.
* License Version 2.1 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

View File

@ -1,595 +0,0 @@
/*
* libretroshare/src/services p3wikiservice.cc
*
* Wiki interface for RetroShare.
*
* Copyright 2012-2012 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/p3wikiserviceVEG.h"
#include "util/rsrandom.h"
/****
* #define WIKI_DEBUG 1
****/
RsWikiVEG *rsWikiVEG = NULL;
/********************************************************************************/
/******************* Startup / Tick ******************************************/
/********************************************************************************/
p3WikiServiceVEG::p3WikiServiceVEG(uint16_t type)
:p3GxsDataServiceVEG(type, new WikiDataProxy()), mWikiMtx("p3WikiService"), mUpdated(true)
{
RsStackMutex stack(mWikiMtx); /********** STACK LOCKED MTX ******/
mWikiProxy = (WikiDataProxy *) mProxy;
return;
}
int p3WikiServiceVEG::tick()
{
//std::cerr << "p3WikiServiceVEG::tick()";
//std::cerr << std::endl;
fakeprocessrequests();
return 0;
}
bool p3WikiServiceVEG::updated()
{
RsStackMutex stack(mWikiMtx); /********** STACK LOCKED MTX ******/
if (mUpdated)
{
mUpdated = false;
return true;
}
return false;
}
/* Data Requests */
bool p3WikiServiceVEG::requestGroupInfo( uint32_t &token, uint32_t ansType, const RsTokReqOptionsVEG &opts, const std::list<std::string> &groupIds)
{
generateToken(token);
std::cerr << "p3WikiServiceVEG::requestGroupInfo() gets Token: " << token << std::endl;
storeRequest(token, ansType, opts, GXS_REQUEST_TYPE_GROUPS, groupIds);
return true;
}
bool p3WikiServiceVEG::requestMsgInfo( uint32_t &token, uint32_t ansType, const RsTokReqOptionsVEG &opts, const std::list<std::string> &groupIds)
{
generateToken(token);
std::cerr << "p3WikiServiceVEG::requestMsgInfo() gets Token: " << token << std::endl;
storeRequest(token, ansType, opts, GXS_REQUEST_TYPE_MSGS, groupIds);
return true;
}
bool p3WikiServiceVEG::requestMsgRelatedInfo(uint32_t &token, uint32_t ansType, const RsTokReqOptionsVEG &opts, const std::list<std::string> &msgIds)
{
generateToken(token);
std::cerr << "p3WikiServiceVEG::requestMsgRelatedInfo() gets Token: " << token << std::endl;
storeRequest(token, ansType, opts, GXS_REQUEST_TYPE_MSGRELATED, msgIds);
return true;
}
/* Generic Lists */
bool p3WikiServiceVEG::getGroupList( const uint32_t &token, std::list<std::string> &groupIds)
{
uint32_t status;
uint32_t reqtype;
uint32_t anstype;
time_t ts;
checkRequestStatus(token, status, reqtype, anstype, ts);
if (anstype != RS_TOKREQ_ANSTYPE_LIST)
{
std::cerr << "p3WikiServiceVEG::getGroupList() ERROR AnsType Wrong" << std::endl;
return false;
}
if (reqtype != GXS_REQUEST_TYPE_GROUPS)
{
std::cerr << "p3WikiServiceVEG::getGroupList() ERROR ReqType Wrong" << std::endl;
return false;
}
if (status != GXS_REQUEST_STATUS_COMPLETE)
{
std::cerr << "p3WikiServiceVEG::getGroupList() ERROR Status Incomplete" << std::endl;
return false;
}
bool ans = loadRequestOutList(token, groupIds);
updateRequestStatus(token, GXS_REQUEST_STATUS_DONE);
return ans;
}
bool p3WikiServiceVEG::getMsgList( const uint32_t &token, std::list<std::string> &msgIds)
{
uint32_t status;
uint32_t reqtype;
uint32_t anstype;
time_t ts;
checkRequestStatus(token, status, reqtype, anstype, ts);
if (anstype != RS_TOKREQ_ANSTYPE_LIST)
{
std::cerr << "p3WikiServiceVEG::getMsgList() ERROR AnsType Wrong" << std::endl;
return false;
}
if ((reqtype != GXS_REQUEST_TYPE_MSGS) && (reqtype != GXS_REQUEST_TYPE_MSGRELATED))
{
std::cerr << "p3WikiServiceVEG::getMsgList() ERROR ReqType Wrong" << std::endl;
return false;
}
if (status != GXS_REQUEST_STATUS_COMPLETE)
{
std::cerr << "p3WikiServiceVEG::getMsgList() ERROR Status Incomplete" << std::endl;
return false;
}
bool ans = loadRequestOutList(token, msgIds);
updateRequestStatus(token, GXS_REQUEST_STATUS_DONE);
return ans;
}
/* Generic Summary */
bool p3WikiServiceVEG::getGroupSummary( const uint32_t &token, std::list<RsGroupMetaData> &groupInfo)
{
uint32_t status;
uint32_t reqtype;
uint32_t anstype;
time_t ts;
checkRequestStatus(token, status, reqtype, anstype, ts);
if (anstype != RS_TOKREQ_ANSTYPE_SUMMARY)
{
std::cerr << "p3WikiServiceVEG::getGroupSummary() ERROR AnsType Wrong" << std::endl;
return false;
}
if (reqtype != GXS_REQUEST_TYPE_GROUPS)
{
std::cerr << "p3WikiServiceVEG::getGroupSummary() ERROR ReqType Wrong" << std::endl;
return false;
}
if (status != GXS_REQUEST_STATUS_COMPLETE)
{
std::cerr << "p3WikiServiceVEG::getGroupSummary() ERROR Status Incomplete" << std::endl;
return false;
}
std::list<std::string> groupIds;
bool ans = loadRequestOutList(token, groupIds);
updateRequestStatus(token, GXS_REQUEST_STATUS_DONE);
/* convert to RsGroupMetaData */
mProxy->getGroupSummary(groupIds, groupInfo);
return ans;
}
bool p3WikiServiceVEG::getMsgSummary( const uint32_t &token, std::list<RsMsgMetaData> &msgInfo)
{
uint32_t status;
uint32_t reqtype;
uint32_t anstype;
time_t ts;
checkRequestStatus(token, status, reqtype, anstype, ts);
if (anstype != RS_TOKREQ_ANSTYPE_SUMMARY)
{
std::cerr << "p3WikiServiceVEG::getMsgSummary() ERROR AnsType Wrong" << std::endl;
return false;
}
if ((reqtype != GXS_REQUEST_TYPE_MSGS) && (reqtype != GXS_REQUEST_TYPE_MSGRELATED))
{
std::cerr << "p3WikiServiceVEG::getMsgSummary() ERROR ReqType Wrong" << std::endl;
return false;
}
if (status != GXS_REQUEST_STATUS_COMPLETE)
{
std::cerr << "p3WikiServiceVEG::getMsgSummary() ERROR Status Incomplete" << std::endl;
return false;
}
std::list<std::string> msgIds;
bool ans = loadRequestOutList(token, msgIds);
updateRequestStatus(token, GXS_REQUEST_STATUS_DONE);
/* convert to RsMsgMetaData */
mProxy->getMsgSummary(msgIds, msgInfo);
return ans;
}
/* Specific Service Data */
bool p3WikiServiceVEG::getGroupData(const uint32_t &token, RsWikiGroup &group)
{
uint32_t status;
uint32_t reqtype;
uint32_t anstype;
time_t ts;
checkRequestStatus(token, status, reqtype, anstype, ts);
if (anstype != RS_TOKREQ_ANSTYPE_DATA)
{
std::cerr << "p3WikiServiceVEG::getGroupData() ERROR AnsType Wrong" << std::endl;
return false;
}
if (reqtype != GXS_REQUEST_TYPE_GROUPS)
{
std::cerr << "p3WikiServiceVEG::getGroupData() ERROR ReqType Wrong" << std::endl;
return false;
}
if (status != GXS_REQUEST_STATUS_COMPLETE)
{
std::cerr << "p3WikiServiceVEG::getGroupData() ERROR Status Incomplete" << std::endl;
return false;
}
std::string id;
if (!popRequestOutList(token, id))
{
/* finished */
updateRequestStatus(token, GXS_REQUEST_STATUS_DONE);
return false;
}
/* convert to RsWikiAlbum */
bool ans = mWikiProxy->getGroup(id, group);
return ans;
}
bool p3WikiServiceVEG::getMsgData(const uint32_t &token, RsWikiPage &page)
{
uint32_t status;
uint32_t reqtype;
uint32_t anstype;
time_t ts;
checkRequestStatus(token, status, reqtype, anstype, ts);
if (anstype != RS_TOKREQ_ANSTYPE_DATA)
{
std::cerr << "p3WikiServiceVEG::getMsgData() ERROR AnsType Wrong" << std::endl;
return false;
}
if ((reqtype != GXS_REQUEST_TYPE_MSGS) && (reqtype != GXS_REQUEST_TYPE_MSGRELATED))
{
std::cerr << "p3WikiServiceVEG::getMsgData() ERROR ReqType Wrong" << std::endl;
return false;
}
if (status != GXS_REQUEST_STATUS_COMPLETE)
{
std::cerr << "p3WikiServiceVEG::getMsgData() ERROR Status Incomplete" << std::endl;
return false;
}
std::string id;
if (!popRequestOutList(token, id))
{
/* finished */
updateRequestStatus(token, GXS_REQUEST_STATUS_DONE);
return false;
}
/* convert to RsWikiAlbum */
bool ans = mWikiProxy->getPage(id, page);
return ans;
}
/* Poll */
uint32_t p3WikiServiceVEG::requestStatus(const uint32_t token)
{
uint32_t status;
uint32_t reqtype;
uint32_t anstype;
time_t ts;
checkRequestStatus(token, status, reqtype, anstype, ts);
return status;
}
/* Cancel Request */
bool p3WikiServiceVEG::cancelRequest(const uint32_t &token)
{
return clearRequest(token);
}
//////////////////////////////////////////////////////////////////////////////
bool p3WikiServiceVEG::setMessageStatus(const std::string &msgId, const uint32_t status, const uint32_t statusMask)
{
return mWikiProxy->setMessageStatus(msgId, status, statusMask);
}
bool p3WikiServiceVEG::setGroupStatus(const std::string &groupId, const uint32_t status, const uint32_t statusMask)
{
return mWikiProxy->setGroupStatus(groupId, status, statusMask);
}
bool p3WikiServiceVEG::setGroupSubscribeFlags(const std::string &groupId, uint32_t subscribeFlags, uint32_t subscribeMask)
{
return mWikiProxy->setGroupSubscribeFlags(groupId, subscribeFlags, subscribeMask);
}
bool p3WikiServiceVEG::setMessageServiceString(const std::string &msgId, const std::string &str)
{
return mWikiProxy->setMessageServiceString(msgId, str);
}
bool p3WikiServiceVEG::setGroupServiceString(const std::string &grpId, const std::string &str)
{
return mWikiProxy->setGroupServiceString(grpId, str);
}
bool p3WikiServiceVEG::groupRestoreKeys(const std::string &groupId)
{
return false;
}
bool p3WikiServiceVEG::groupShareKeys(const std::string &groupId, std::list<std::string>& peers)
{
return false;
}
/********************************************************************************************/
std::string p3WikiServiceVEG::genRandomId()
{
std::string randomId;
for(int i = 0; i < 20; i++)
{
randomId += (char) ('a' + (RSRandom::random_u32() % 26));
}
return randomId;
}
bool p3WikiServiceVEG::createGroup(uint32_t &token, RsWikiGroup &group, bool isNew)
{
if (group.mMeta.mGroupId.empty())
{
/* new photo */
/* generate a temp id */
group.mMeta.mGroupId = genRandomId();
}
else
{
std::cerr << "p3WikiServiceVEG::createGroup() Group with existing Id... dropping";
std::cerr << std::endl;
return false;
}
{
RsStackMutex stack(mWikiMtx); /********** STACK LOCKED MTX ******/
mUpdated = true;
mWikiProxy->addGroup(group);
}
// Fake a request to return the GroupMetaData.
generateToken(token);
uint32_t ansType = RS_TOKREQ_ANSTYPE_SUMMARY;
RsTokReqOptionsVEG opts; // NULL is good.
std::list<std::string> groupIds;
groupIds.push_back(group.mMeta.mGroupId); // It will just return this one.
std::cerr << "p3WikiServiceVEG::createGroup() Generating Request Token: " << token << std::endl;
storeRequest(token, ansType, opts, GXS_REQUEST_TYPE_GROUPS, groupIds);
return true;
}
bool p3WikiServiceVEG::createPage(uint32_t &token, RsWikiPage &page, bool isNew)
{
if (page.mMeta.mGroupId.empty())
{
/* new photo */
std::cerr << "p3WikiServiceVEG::createPage() Missing PageID";
std::cerr << std::endl;
return false;
}
/* check if its a mod or new page */
if (page.mMeta.mOrigMsgId.empty())
{
std::cerr << "p3WikiServiceVEG::createPage() New Page";
std::cerr << std::endl;
/* new page, generate a new OrigPageId */
page.mMeta.mOrigMsgId = genRandomId();
page.mMeta.mMsgId = page.mMeta.mOrigMsgId;
}
else
{
std::cerr << "p3WikiServiceVEG::createPage() Modified Page";
std::cerr << std::endl;
/* mod page, keep orig page id, generate a new PageId */
page.mMeta.mMsgId = genRandomId();
}
std::cerr << "p3WikiServiceVEG::createPage() GroupId: " << page.mMeta.mGroupId;
std::cerr << std::endl;
std::cerr << "p3WikiServiceVEG::createPage() PageId: " << page.mMeta.mMsgId;
std::cerr << std::endl;
std::cerr << "p3WikiServiceVEG::createPage() OrigPageId: " << page.mMeta.mOrigMsgId;
std::cerr << std::endl;
{
RsStackMutex stack(mWikiMtx); /********** STACK LOCKED MTX ******/
mUpdated = true;
mWikiProxy->addPage(page);
}
// Fake a request to return the MsgMetaData.
generateToken(token);
uint32_t ansType = RS_TOKREQ_ANSTYPE_SUMMARY;
RsTokReqOptionsVEG opts; // NULL is good.
std::list<std::string> msgIds;
msgIds.push_back(page.mMeta.mMsgId); // It will just return this one.
std::cerr << "p3WikiServiceVEG::createPage() Generating Request Token: " << token << std::endl;
storeRequest(token, ansType, opts, GXS_REQUEST_TYPE_MSGRELATED, msgIds);
return true;
}
/********************************************************************************************/
bool WikiDataProxy::getGroup(const std::string &id, RsWikiGroup &group)
{
void *groupData = NULL;
RsGroupMetaData meta;
if (getGroupData(id, groupData) && getGroupSummary(id, meta))
{
RsWikiGroup *pG = (RsWikiGroup *) groupData;
group = *pG;
// update definitive version of the metadata.
group.mMeta = meta;
std::cerr << "WikiDataProxy::getGroup() Id: " << id;
std::cerr << " MetaData: " << meta << " DataPointer: " << groupData;
std::cerr << std::endl;
return true;
}
std::cerr << "WikiDataProxy::getGroup() FAILED Id: " << id;
std::cerr << std::endl;
return false;
}
bool WikiDataProxy::getPage(const std::string &id, RsWikiPage &page)
{
void *msgData = NULL;
RsMsgMetaData meta;
if (getMsgData(id, msgData) && getMsgSummary(id, meta))
{
RsWikiPage *pP = (RsWikiPage *) msgData;
// Shallow copy of thumbnail.
page = *pP;
// update definitive version of the metadata.
page.mMeta = meta;
std::cerr << "WikiDataProxy::getPage() Id: " << id;
std::cerr << " MetaData: " << meta << " DataPointer: " << msgData;
std::cerr << std::endl;
return true;
}
std::cerr << "WikiDataProxy::getPage() FAILED Id: " << id;
std::cerr << std::endl;
return false;
}
bool WikiDataProxy::addGroup(const RsWikiGroup &group)
{
// Make duplicate.
RsWikiGroup *pG = new RsWikiGroup();
*pG = group;
std::cerr << "WikiDataProxy::addGroup()";
std::cerr << " MetaData: " << pG->mMeta << " DataPointer: " << pG;
std::cerr << std::endl;
return createGroup(pG);
}
bool WikiDataProxy::addPage(const RsWikiPage &page)
{
// Make duplicate.
RsWikiPage *pP = new RsWikiPage();
*pP = page;
std::cerr << "WikiDataProxy::addPage()";
std::cerr << " MetaData: " << pP->mMeta << " DataPointer: " << pP;
std::cerr << std::endl;
return createMsg(pP);
}
/* These Functions must be overloaded to complete the service */
bool WikiDataProxy::convertGroupToMetaData(void *groupData, RsGroupMetaData &meta)
{
RsWikiGroup *group = (RsWikiGroup *) groupData;
meta = group->mMeta;
return true;
}
bool WikiDataProxy::convertMsgToMetaData(void *msgData, RsMsgMetaData &meta)
{
RsWikiPage *page = (RsWikiPage *) msgData;
meta = page->mMeta;
return true;
}

View File

@ -1,129 +0,0 @@
/*
* libretroshare/src/services: p3wikiservice.h
*
* Wiki interface for RetroShare.
*
* Copyright 2012-2012 by Robert Fernie.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License Version 2 as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA.
*
* Please report all bugs and problems to "retroshare@lunamutt.com".
*
*/
#ifndef P3_WIKI_SERVICE_VEG_HEADER
#define P3_WIKI_SERVICE_VEG_HEADER
#include "services/p3gxsserviceVEG.h"
#include "retroshare/rswikiVEG.h"
#include <map>
#include <string>
/*
* Wiki Service
*
* This is an example service for the new cache system.
* For the moment, it will only hold data passed to it from the GUI.
* and spew that back when asked....
*
* We are doing it like this - so we can check the required interface functionality.
*
* Expect it won't take long before it'll be properly linked into the backend!
*
* This will be transformed into a Plugin Service, once the basics have been worked out.
*
*/
class WikiDataProxy: public GxsDataProxyVEG
{
public:
bool getGroup(const std::string &id, RsWikiGroup &group);
bool getPage(const std::string &id, RsWikiPage &wiki);
bool addGroup(const RsWikiGroup &group);
bool addPage(const RsWikiPage &page);
/* These Functions must be overloaded to complete the service */
virtual bool convertGroupToMetaData(void *groupData, RsGroupMetaData &meta);
virtual bool convertMsgToMetaData(void *msgData, RsMsgMetaData &meta);
};
class p3WikiServiceVEG: public p3GxsDataServiceVEG, public RsWikiVEG
{
public:
p3WikiServiceVEG(uint16_t type);
virtual int tick();
public:
virtual bool updated();
/* Data Requests */
virtual bool requestGroupInfo( uint32_t &token, uint32_t ansType, const RsTokReqOptionsVEG &opts, const std::list<std::string> &groupIds);
virtual bool requestMsgInfo( uint32_t &token, uint32_t ansType, const RsTokReqOptionsVEG &opts, const std::list<std::string> &groupIds);
virtual bool requestMsgRelatedInfo(uint32_t &token, uint32_t ansType, const RsTokReqOptionsVEG &opts, const std::list<std::string> &msgIds);
/* Generic Lists */
virtual bool getGroupList( const uint32_t &token, std::list<std::string> &groupIds);
virtual bool getMsgList( const uint32_t &token, std::list<std::string> &msgIds);
/* Generic Summary */
virtual bool getGroupSummary( const uint32_t &token, std::list<RsGroupMetaData> &groupInfo);
virtual bool getMsgSummary( const uint32_t &token, std::list<RsMsgMetaData> &msgInfo);
/* Actual Data -> specific to Interface */
/* Specific Service Data */
virtual bool getGroupData(const uint32_t &token, RsWikiGroup &group);
virtual bool getMsgData(const uint32_t &token, RsWikiPage &page);
/* Poll */
virtual uint32_t requestStatus(const uint32_t token);
/* Cancel Request */
virtual bool cancelRequest(const uint32_t &token);
//////////////////////////////////////////////////////////////////////////////
virtual bool setMessageStatus(const std::string &msgId, const uint32_t status, const uint32_t statusMask);
virtual bool setGroupStatus(const std::string &groupId, const uint32_t status, const uint32_t statusMask);
virtual bool setGroupSubscribeFlags(const std::string &groupId, uint32_t subscribeFlags, uint32_t subscribeMask);
virtual bool setMessageServiceString(const std::string &msgId, const std::string &str);
virtual bool setGroupServiceString(const std::string &grpId, const std::string &str);
virtual bool groupRestoreKeys(const std::string &groupId);
virtual bool groupShareKeys(const std::string &groupId, std::list<std::string>& peers);
virtual bool createGroup(uint32_t &token, RsWikiGroup &group, bool isNew);
virtual bool createPage(uint32_t &token, RsWikiPage &page, bool isNew);
private:
std::string genRandomId();
WikiDataProxy *mWikiProxy;
RsMutex mWikiMtx;
bool mUpdated;
};
#endif

View File

@ -0,0 +1,207 @@
/*
* libretroshare/src/services p3wire.cc
*
* Wire interface for RetroShare.
*
* Copyright 2012-2012 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.1 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/p3wire.h"
#include "serialiser/rswireitems.h"
#include "util/rsrandom.h"
/****
* #define WIRE_DEBUG 1
****/
RsWire *rsWire = NULL;
p3Wire::p3Wire(RsGeneralDataService* gds, RsNetworkExchangeService* nes)
:RsGenExchange(gds, nes, new RsGxsWireSerialiser(), RS_SERVICE_GXSV1_TYPE_WIRE), RsWire(this), mWireMtx("WireMtx")
{
}
void p3Wire::service_tick()
{
return;
}
void p3Wire::notifyChanges(std::vector<RsGxsNotify*>& changes)
{
std::cerr << "p3Wire::notifyChanges() New stuff";
std::cerr << std::endl;
receiveChanges(changes);
}
/* Specific Service Data */
bool p3Wire::getGroupData(const uint32_t &token, std::vector<RsWireGroup> &groups)
{
std::cerr << "p3Wire::getGroupData()";
std::cerr << std::endl;
std::vector<RsGxsGrpItem*> grpData;
bool ok = RsGenExchange::getGroupData(token, grpData);
if(ok)
{
std::vector<RsGxsGrpItem*>::iterator vit = grpData.begin();
for(; vit != grpData.end(); vit++)
{
RsGxsWireGroupItem* item = dynamic_cast<RsGxsWireGroupItem*>(*vit);
if (item)
{
RsWireGroup group = item->group;
group.mMeta = item->meta;
delete item;
groups.push_back(group);
std::cerr << "p3Wire::getGroupData() Adding WireGroup to Vector: ";
std::cerr << std::endl;
std::cerr << group;
std::cerr << std::endl;
}
else
{
std::cerr << "Not a WireGroupItem, deleting!" << std::endl;
delete *vit;
}
}
}
return ok;
}
bool p3Wire::getPulseData(const uint32_t &token, std::vector<RsWirePulse> &pulses)
{
GxsMsgDataMap msgData;
bool ok = RsGenExchange::getMsgData(token, msgData);
if(ok)
{
GxsMsgDataMap::iterator mit = msgData.begin();
for(; mit != msgData.end(); mit++)
{
RsGxsGroupId grpId = mit->first;
std::vector<RsGxsMsgItem*>& msgItems = mit->second;
std::vector<RsGxsMsgItem*>::iterator vit = msgItems.begin();
for(; vit != msgItems.end(); vit++)
{
RsGxsWirePulseItem* item = dynamic_cast<RsGxsWirePulseItem*>(*vit);
if(item)
{
RsWirePulse pulse = item->pulse;
pulse.mMeta = item->meta;
pulses.push_back(pulse);
delete item;
}
else
{
std::cerr << "Not a WikiPulse Item, deleting!" << std::endl;
delete *vit;
}
}
}
}
return ok;
}
bool p3Wire::createGroup(uint32_t &token, RsWireGroup &group)
{
RsGxsWireGroupItem* groupItem = new RsGxsWireGroupItem();
groupItem->group = group;
groupItem->meta = group.mMeta;
std::cerr << "p3Wire::createGroup(): ";
std::cerr << std::endl;
std::cerr << group;
std::cerr << std::endl;
std::cerr << "p3Wire::createGroup() pushing to RsGenExchange";
std::cerr << std::endl;
RsGenExchange::publishGroup(token, groupItem);
return true;
}
bool p3Wire::createPulse(uint32_t &token, RsWirePulse &pulse)
{
std::cerr << "p3Wire::createPulse(): " << pulse;
std::cerr << std::endl;
RsGxsWirePulseItem* pulseItem = new RsGxsWirePulseItem();
pulseItem->pulse = pulse;
pulseItem->meta = pulse.mMeta;
RsGenExchange::publishMsg(token, pulseItem);
return true;
}
std::ostream &operator<<(std::ostream &out, const RsWireGroup &group)
{
out << "RsWireGroup [ ";
out << " Name: " << group.mMeta.mGroupName;
out << " Desc: " << group.mDescription;
//out << " Category: " << group.mCategory;
out << " ]";
return out;
}
std::ostream &operator<<(std::ostream &out, const RsWirePulse &pulse)
{
out << "RsWirePulse [ ";
out << "Title: " << pulse.mMeta.mMsgName;
out << "PulseText: " << pulse.mPulseText;
out << "]";
return out;
}
/***** FOR TESTING *****/
std::string p3Wire::genRandomId()
{
std::string randomId;
for(int i = 0; i < 20; i++)
{
randomId += (char) ('a' + (RSRandom::random_u32() % 26));
}
return randomId;
}
void p3Wire::generateDummyData()
{
}

View File

@ -0,0 +1,71 @@
/*
* libretroshare/src/services: p3wire.h
*
* Wiki interface for RetroShare.
*
* Copyright 2012-2012 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.1 as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA.
*
* Please report all bugs and problems to "retroshare@lunamutt.com".
*
*/
#ifndef P3_WIRE_SERVICE_HEADER
#define P3_WIRE_SERVICE_HEADER
#include "retroshare/rswire.h"
#include "gxs/rsgenexchange.h"
#include <map>
#include <string>
/*
* Wiki Service
*
*
*/
class p3Wire: public RsGenExchange, public RsWire
{
public:
p3Wire(RsGeneralDataService* gds, RsNetworkExchangeService* nes);
protected:
virtual void notifyChanges(std::vector<RsGxsNotify*>& changes) ;
public:
virtual void service_tick();
/* Specific Service Data */
virtual bool getGroupData(const uint32_t &token, std::vector<RsWireGroup> &groups);
virtual bool getPulseData(const uint32_t &token, std::vector<RsWirePulse> &pulses);
virtual bool createGroup(uint32_t &token, RsWireGroup &group);
virtual bool createPulse(uint32_t &token, RsWirePulse &pulse);
private:
virtual void generateDummyData();
std::string genRandomId();
RsMutex mWireMtx;
};
#endif

View File

@ -1,939 +0,0 @@
/*
* libretroshare/src/services p3wire.cc
*
* Wire interface for RetroShare.
*
* Copyright 2012-2012 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.1 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/p3wireVEG.h"
#include "util/rsrandom.h"
/****
* #define WIKI_DEBUG 1
****/
RsWireVEG *rsWireVEG = NULL;
/********************************************************************************/
/******************* Startup / Tick ******************************************/
/********************************************************************************/
p3WireVEG::p3WireVEG(uint16_t type)
:p3GxsDataServiceVEG(type, new WireDataProxy()), mWireMtx("p3Wire"), mUpdated(true)
{
RsStackMutex stack(mWireMtx); /********** STACK LOCKED MTX ******/
mWireProxy = (WireDataProxy *) mProxy;
return;
}
int p3WireVEG::tick()
{
//std::cerr << "p3WireVEG::tick()";
//std::cerr << std::endl;
fakeprocessrequests();
return 0;
}
bool p3WireVEG::updated()
{
RsStackMutex stack(mWireMtx); /********** STACK LOCKED MTX ******/
if (mUpdated)
{
mUpdated = false;
return true;
}
return false;
}
/* Data Requests */
bool p3WireVEG::requestGroupInfo( uint32_t &token, uint32_t ansType, const RsTokReqOptionsVEG &opts, const std::list<std::string> &groupIds)
{
generateToken(token);
std::cerr << "p3WireVEG::requestGroupInfo() gets Token: " << token << std::endl;
storeRequest(token, ansType, opts, GXS_REQUEST_TYPE_GROUPS, groupIds);
return true;
}
bool p3WireVEG::requestMsgInfo( uint32_t &token, uint32_t ansType, const RsTokReqOptionsVEG &opts, const std::list<std::string> &groupIds)
{
generateToken(token);
std::cerr << "p3WireVEG::requestMsgInfo() gets Token: " << token << std::endl;
storeRequest(token, ansType, opts, GXS_REQUEST_TYPE_MSGS, groupIds);
return true;
}
bool p3WireVEG::requestMsgRelatedInfo(uint32_t &token, uint32_t ansType, const RsTokReqOptionsVEG &opts, const std::list<std::string> &msgIds)
{
generateToken(token);
std::cerr << "p3WireVEG::requestMsgRelatedInfo() gets Token: " << token << std::endl;
storeRequest(token, ansType, opts, GXS_REQUEST_TYPE_MSGRELATED, msgIds);
return true;
}
/* Generic Lists */
bool p3WireVEG::getGroupList( const uint32_t &token, std::list<std::string> &groupIds)
{
uint32_t status;
uint32_t reqtype;
uint32_t anstype;
time_t ts;
checkRequestStatus(token, status, reqtype, anstype, ts);
if (anstype != RS_TOKREQ_ANSTYPE_LIST)
{
std::cerr << "p3WireVEG::getGroupList() ERROR AnsType Wrong" << std::endl;
return false;
}
if (reqtype != GXS_REQUEST_TYPE_GROUPS)
{
std::cerr << "p3WireVEG::getGroupList() ERROR ReqType Wrong" << std::endl;
return false;
}
if (status != GXS_REQUEST_STATUS_COMPLETE)
{
std::cerr << "p3WireVEG::getGroupList() ERROR Status Incomplete" << std::endl;
return false;
}
bool ans = loadRequestOutList(token, groupIds);
updateRequestStatus(token, GXS_REQUEST_STATUS_DONE);
return ans;
}
bool p3WireVEG::getMsgList( const uint32_t &token, std::list<std::string> &msgIds)
{
uint32_t status;
uint32_t reqtype;
uint32_t anstype;
time_t ts;
checkRequestStatus(token, status, reqtype, anstype, ts);
if (anstype != RS_TOKREQ_ANSTYPE_LIST)
{
std::cerr << "p3WireVEG::getMsgList() ERROR AnsType Wrong" << std::endl;
return false;
}
if ((reqtype != GXS_REQUEST_TYPE_MSGS) && (reqtype != GXS_REQUEST_TYPE_MSGRELATED))
{
std::cerr << "p3WireVEG::getMsgList() ERROR ReqType Wrong" << std::endl;
return false;
}
if (status != GXS_REQUEST_STATUS_COMPLETE)
{
std::cerr << "p3WireVEG::getMsgList() ERROR Status Incomplete" << std::endl;
return false;
}
bool ans = loadRequestOutList(token, msgIds);
updateRequestStatus(token, GXS_REQUEST_STATUS_DONE);
return ans;
}
/* Generic Summary */
bool p3WireVEG::getGroupSummary( const uint32_t &token, std::list<RsGroupMetaData> &groupInfo)
{
uint32_t status;
uint32_t reqtype;
uint32_t anstype;
time_t ts;
checkRequestStatus(token, status, reqtype, anstype, ts);
if (anstype != RS_TOKREQ_ANSTYPE_SUMMARY)
{
std::cerr << "p3WireVEG::getGroupSummary() ERROR AnsType Wrong" << std::endl;
return false;
}
if (reqtype != GXS_REQUEST_TYPE_GROUPS)
{
std::cerr << "p3WireVEG::getGroupSummary() ERROR ReqType Wrong" << std::endl;
return false;
}
if (status != GXS_REQUEST_STATUS_COMPLETE)
{
std::cerr << "p3WireVEG::getGroupSummary() ERROR Status Incomplete" << std::endl;
return false;
}
std::list<std::string> groupIds;
bool ans = loadRequestOutList(token, groupIds);
updateRequestStatus(token, GXS_REQUEST_STATUS_DONE);
/* convert to RsGroupMetaData */
mProxy->getGroupSummary(groupIds, groupInfo);
return ans;
}
bool p3WireVEG::getMsgSummary( const uint32_t &token, std::list<RsMsgMetaData> &msgInfo)
{
uint32_t status;
uint32_t reqtype;
uint32_t anstype;
time_t ts;
checkRequestStatus(token, status, reqtype, anstype, ts);
if (anstype != RS_TOKREQ_ANSTYPE_SUMMARY)
{
std::cerr << "p3WireVEG::getMsgSummary() ERROR AnsType Wrong" << std::endl;
return false;
}
if ((reqtype != GXS_REQUEST_TYPE_MSGS) && (reqtype != GXS_REQUEST_TYPE_MSGRELATED))
{
std::cerr << "p3WireVEG::getMsgSummary() ERROR ReqType Wrong" << std::endl;
return false;
}
if (status != GXS_REQUEST_STATUS_COMPLETE)
{
std::cerr << "p3WireVEG::getMsgSummary() ERROR Status Incomplete" << std::endl;
return false;
}
std::list<std::string> msgIds;
bool ans = loadRequestOutList(token, msgIds);
updateRequestStatus(token, GXS_REQUEST_STATUS_DONE);
/* convert to RsMsgMetaData */
mProxy->getMsgSummary(msgIds, msgInfo);
return ans;
}
/* Specific Service Data */
bool p3WireVEG::getGroupData(const uint32_t &token, RsWireGroup &group)
{
uint32_t status;
uint32_t reqtype;
uint32_t anstype;
time_t ts;
checkRequestStatus(token, status, reqtype, anstype, ts);
if (anstype != RS_TOKREQ_ANSTYPE_DATA)
{
std::cerr << "p3WireVEG::getGroupData() ERROR AnsType Wrong" << std::endl;
return false;
}
if (reqtype != GXS_REQUEST_TYPE_GROUPS)
{
std::cerr << "p3WireVEG::getGroupData() ERROR ReqType Wrong" << std::endl;
return false;
}
if (status != GXS_REQUEST_STATUS_COMPLETE)
{
std::cerr << "p3WireVEG::getGroupData() ERROR Status Incomplete" << std::endl;
return false;
}
std::string id;
if (!popRequestOutList(token, id))
{
/* finished */
updateRequestStatus(token, GXS_REQUEST_STATUS_DONE);
return false;
}
/* convert to RsWireGroup */
bool ans = mWireProxy->getGroup(id, group);
return ans;
}
bool p3WireVEG::getMsgData(const uint32_t &token, RsWirePulse &pulse)
{
uint32_t status;
uint32_t reqtype;
uint32_t anstype;
time_t ts;
checkRequestStatus(token, status, reqtype, anstype, ts);
if (anstype != RS_TOKREQ_ANSTYPE_DATA)
{
std::cerr << "p3WireVEG::getMsgData() ERROR AnsType Wrong" << std::endl;
return false;
}
if ((reqtype != GXS_REQUEST_TYPE_MSGS) && (reqtype != GXS_REQUEST_TYPE_MSGRELATED))
{
std::cerr << "p3WireVEG::getMsgData() ERROR ReqType Wrong" << std::endl;
return false;
}
if (status != GXS_REQUEST_STATUS_COMPLETE)
{
std::cerr << "p3WireVEG::getMsgData() ERROR Status Incomplete" << std::endl;
return false;
}
std::string id;
if (!popRequestOutList(token, id))
{
/* finished */
updateRequestStatus(token, GXS_REQUEST_STATUS_DONE);
return false;
}
/* convert to RsWirePulse */
bool ans = mWireProxy->getPulse(id, pulse);
return ans;
}
/* Poll */
uint32_t p3WireVEG::requestStatus(const uint32_t token)
{
uint32_t status;
uint32_t reqtype;
uint32_t anstype;
time_t ts;
checkRequestStatus(token, status, reqtype, anstype, ts);
return status;
}
/* Cancel Request */
bool p3WireVEG::cancelRequest(const uint32_t &token)
{
return clearRequest(token);
}
//////////////////////////////////////////////////////////////////////////////
bool p3WireVEG::setMessageStatus(const std::string &msgId, const uint32_t status, const uint32_t statusMask)
{
return mWireProxy->setMessageStatus(msgId, status, statusMask);
}
bool p3WireVEG::setGroupStatus(const std::string &groupId, const uint32_t status, const uint32_t statusMask)
{
return mWireProxy->setGroupStatus(groupId, status, statusMask);
}
bool p3WireVEG::setGroupSubscribeFlags(const std::string &groupId, uint32_t subscribeFlags, uint32_t subscribeMask)
{
return mWireProxy->setGroupSubscribeFlags(groupId, subscribeFlags, subscribeMask);
}
bool p3WireVEG::setMessageServiceString(const std::string &msgId, const std::string &str)
{
return mWireProxy->setMessageServiceString(msgId, str);
}
bool p3WireVEG::setGroupServiceString(const std::string &grpId, const std::string &str)
{
return mWireProxy->setGroupServiceString(grpId, str);
}
bool p3WireVEG::groupRestoreKeys(const std::string &groupId)
{
return false;
}
bool p3WireVEG::groupShareKeys(const std::string &groupId, std::list<std::string>& peers)
{
return false;
}
/********************************************************************************************/
std::string p3WireVEG::genRandomId()
{
std::string randomId;
for(int i = 0; i < 20; i++)
{
randomId += (char) ('a' + (RSRandom::random_u32() % 26));
}
return randomId;
}
bool p3WireVEG::createGroup(uint32_t &token, RsWireGroup &group, bool isNew)
{
if (group.mMeta.mGroupId.empty())
{
/* new photo */
/* generate a temp id */
group.mMeta.mGroupId = genRandomId();
}
else
{
std::cerr << "p3WireVEG::createGroup() Group with existing Id... dropping";
std::cerr << std::endl;
return false;
}
{
RsStackMutex stack(mWireMtx); /********** STACK LOCKED MTX ******/
mUpdated = true;
mWireProxy->addGroup(group);
}
// Fake a request to return the GroupMetaData.
generateToken(token);
uint32_t ansType = RS_TOKREQ_ANSTYPE_SUMMARY;
RsTokReqOptionsVEG opts; // NULL is good.
std::list<std::string> groupIds;
groupIds.push_back(group.mMeta.mGroupId); // It will just return this one.
std::cerr << "p3Wiree::createGroup() Generating Request Token: " << token << std::endl;
storeRequest(token, ansType, opts, GXS_REQUEST_TYPE_GROUPS, groupIds);
return true;
}
bool p3WireVEG::createPulse(uint32_t &token, RsWirePulse &pulse, bool isNew)
{
if (pulse.mMeta.mGroupId.empty())
{
/* new photo */
std::cerr << "p3WireVEG::createPulse() Missing PulseID";
std::cerr << std::endl;
return false;
}
/* check if its a mod or new pulse */
if (pulse.mMeta.mOrigMsgId.empty())
{
std::cerr << "p3WireVEG::createPulse() New Pulse";
std::cerr << std::endl;
/* new pulse, generate a new OrigPulseId */
pulse.mMeta.mOrigMsgId = genRandomId();
pulse.mMeta.mMsgId = pulse.mMeta.mOrigMsgId;
}
else
{
std::cerr << "p3WireVEG::createPulse() Modified Pulse";
std::cerr << std::endl;
/* mod pulse, keep orig pulse id, generate a new PulseId */
pulse.mMeta.mMsgId = genRandomId();
}
std::cerr << "p3WireVEG::createPulse() GroupId: " << pulse.mMeta.mGroupId;
std::cerr << std::endl;
std::cerr << "p3WireVEG::createPulse() PulseId: " << pulse.mMeta.mMsgId;
std::cerr << std::endl;
std::cerr << "p3WireVEG::createPulse() OrigPulseId: " << pulse.mMeta.mOrigMsgId;
std::cerr << std::endl;
{
RsStackMutex stack(mWireMtx); /********** STACK LOCKED MTX ******/
mUpdated = true;
mWireProxy->addPulse(pulse);
}
// Fake a request to return the MsgMetaData.
generateToken(token);
uint32_t ansType = RS_TOKREQ_ANSTYPE_SUMMARY;
RsTokReqOptionsVEG opts; // NULL is good.
std::list<std::string> msgIds;
msgIds.push_back(pulse.mMeta.mMsgId); // It will just return this one.
std::cerr << "p3WireVEG::createPulse() Generating Request Token: " << token << std::endl;
storeRequest(token, ansType, opts, GXS_REQUEST_TYPE_MSGRELATED, msgIds);
return true;
}
/********************************************************************************************/
bool WireDataProxy::getGroup(const std::string &id, RsWireGroup &group)
{
void *groupData = NULL;
RsGroupMetaData meta;
if (getGroupData(id, groupData) && getGroupSummary(id, meta))
{
RsWireGroup *pG = (RsWireGroup *) groupData;
group = *pG;
// update definitive version of the metadata.
group.mMeta = meta;
std::cerr << "WireDataProxy::getGroup() Id: " << id;
std::cerr << " MetaData: " << meta << " DataPointer: " << groupData;
std::cerr << std::endl;
return true;
}
std::cerr << "WireDataProxy::getGroup() FAILED Id: " << id;
std::cerr << std::endl;
return false;
}
bool WireDataProxy::getPulse(const std::string &id, RsWirePulse &pulse)
{
void *msgData = NULL;
RsMsgMetaData meta;
if (getMsgData(id, msgData) && getMsgSummary(id, meta))
{
RsWirePulse *pP = (RsWirePulse *) msgData;
// Shallow copy of thumbnail.
pulse = *pP;
// update definitive version of the metadata.
pulse.mMeta = meta;
std::cerr << "WireDataProxy::getPulse() Id: " << id;
std::cerr << " MetaData: " << meta << " DataPointer: " << msgData;
std::cerr << std::endl;
return true;
}
std::cerr << "WireDataProxy::getPulse() FAILED Id: " << id;
std::cerr << std::endl;
return false;
}
bool WireDataProxy::addGroup(const RsWireGroup &group)
{
// Make duplicate.
RsWireGroup *pG = new RsWireGroup();
*pG = group;
std::cerr << "WireDataProxy::addGroup()";
std::cerr << " MetaData: " << pG->mMeta << " DataPointer: " << pG;
std::cerr << std::endl;
return createGroup(pG);
}
bool WireDataProxy::addPulse(const RsWirePulse &pulse)
{
// Make duplicate.
RsWirePulse *pP = new RsWirePulse();
*pP = pulse;
std::cerr << "WireDataProxy::addPulse()";
std::cerr << " MetaData: " << pP->mMeta << " DataPointer: " << pP;
std::cerr << std::endl;
return createMsg(pP);
}
/* These Functions must be overloaded to complete the service */
bool WireDataProxy::convertGroupToMetaData(void *groupData, RsGroupMetaData &meta)
{
RsWireGroup *group = (RsWireGroup *) groupData;
meta = group->mMeta;
return true;
}
bool WireDataProxy::convertMsgToMetaData(void *msgData, RsMsgMetaData &meta)
{
RsWirePulse *page = (RsWirePulse *) msgData;
meta = page->mMeta;
return true;
}
/***********************************************************************/
/***********************************************************************/
/***********************************************************************/
/***********************************************************************/
#if 0
bool p3WireVEG::generateDummyData()
{
#define MAX_GROUPS 100
#define MAX_POSTS 1000
#define MAX_BASE_COMMENTS 1000 //10000
#define MAX_COMMENTS 4000 //10000
#define MAX_VOTES 10000 //10000
std::list<RsWireGroup> mGroups;
std::list<RsWireGroup>::iterator git;
std::list<RsWirePulse> mPosts;
std::list<RsWirePulse>::iterator pit;
std::list<RsPostedVote> mVotes;
std::list<RsPostedVote>::iterator vit;
std::list<RsPostedComment> mComments;
std::list<RsPostedComment>::iterator cit;
#define DUMMY_NAME_MAX_LEN 10000
char name[DUMMY_NAME_MAX_LEN];
int i, j;
time_t now = time(NULL);
for(i = 0; i < MAX_GROUPS; i++)
{
/* generate a new forum */
RsPostedGroup group;
snprintf(name, DUMMY_NAME_MAX_LEN, "TestTopic_%d", i+1);
group.mMeta.mGroupId = genRandomId();
group.mMeta.mGroupName = name;
group.mMeta.mPublishTs = now - (RSRandom::random_f32() * 100000);
/* key fields to fill in:
* GroupId.
* Name.
* Flags.
* Pop.
*/
/* use probability to decide which are subscribed / own / popularity.
*/
float rnd = RSRandom::random_f32();
if (rnd < 0.1)
{
group.mMeta.mSubscribeFlags = RSGXS_GROUP_SUBSCRIBE_ADMIN | RSGXS_GROUP_SUBSCRIBE_SUBSCRIBED;
}
else if (rnd < 0.3)
{
group.mMeta.mSubscribeFlags = RSGXS_GROUP_SUBSCRIBE_SUBSCRIBED;
}
else
{
group.mMeta.mSubscribeFlags = 0;
}
group.mMeta.mPop = (int) (RSRandom::random_f32() * 10.0);
mGroups.push_back(group);
}
for(i = 0; i < MAX_POSTS; i++)
{
/* generate a base thread */
/* rotate the Forum Groups Around, then pick one.
*/
int rnd = (int) (RSRandom::random_f32() * 10.0);
for(j = 0; j < rnd; j++)
{
RsPostedGroup head = mGroups.front();
mGroups.pop_front();
mGroups.push_back(head);
}
RsPostedGroup group = mGroups.front();
/* now create a new thread */
RsPostedPost post;
snprintf(name, DUMMY_NAME_MAX_LEN, "%s => Post_%d", group.mMeta.mGroupName.c_str(), i+1);
post.mMeta.mMsgName = name;
post.mMeta.mGroupId = group.mMeta.mGroupId;
post.mMeta.mMsgId = genRandomId();
post.mMeta.mOrigMsgId = post.mMeta.mMsgId;
post.mMeta.mThreadId = post.mMeta.mMsgId;
post.mMeta.mParentId = "";
post.mMeta.mPublishTs = group.mMeta.mPublishTs + (RSRandom::random_f32() * 10000);
if (post.mMeta.mPublishTs > now)
post.mMeta.mPublishTs = now - 1;
mPosts.push_back(post);
}
for(i = 0; i < MAX_BASE_COMMENTS; i++)
{
/* generate a base thread */
/* rotate the Forum Groups Around, then pick one.
*/
int rnd = (int) (RSRandom::random_f32() * 10.0);
for(j = 0; j < rnd; j++)
{
RsPostedPost head = mPosts.front();
mPosts.pop_front();
mPosts.push_back(head);
}
RsPostedPost parent = mPosts.front();
/* now create a new child msg */
RsPostedComment comment;
/* fill in key data
* GroupId
* MsgId
* OrigMsgId
* ThreadId
* ParentId
* PublishTS (take Forum TS + a bit ).
*
* ChildTS ????
*/
snprintf(name, DUMMY_NAME_MAX_LEN, "%s => Comment_%d", parent.mMeta.mMsgName.c_str(), i+1);
comment.mMeta.mMsgName = name;
//comment.mMsg = name;
comment.mMeta.mGroupId = parent.mMeta.mGroupId;
comment.mMeta.mMsgId = genRandomId();
comment.mMeta.mOrigMsgId = comment.mMeta.mMsgId;
comment.mMeta.mThreadId = parent.mMeta.mThreadId;
comment.mMeta.mParentId = parent.mMeta.mOrigMsgId;
comment.mMeta.mPublishTs = parent.mMeta.mPublishTs + (RSRandom::random_f32() * 10000);
if (comment.mMeta.mPublishTs > now)
comment.mMeta.mPublishTs = now - 1;
mComments.push_back(comment);
}
for(i = 0; i < MAX_COMMENTS; i++)
{
/* generate a base thread */
/* rotate the Forum Groups Around, then pick one.
*/
int rnd = (int) (RSRandom::random_f32() * 10.0);
for(j = 0; j < rnd; j++)
{
RsPostedComment head = mComments.front();
mComments.pop_front();
mComments.push_back(head);
}
RsPostedComment parent = mComments.front();
/* now create a new child msg */
RsPostedComment comment;
/* fill in key data
* GroupId
* MsgId
* OrigMsgId
* ThreadId
* ParentId
* PublishTS (take Forum TS + a bit ).
*
* ChildTS ????
*/
snprintf(name, DUMMY_NAME_MAX_LEN, "%s => Comment_%d", parent.mMeta.mMsgName.c_str(), i+1);
comment.mMeta.mMsgName = name;
//comment.mMsg = name;
comment.mMeta.mGroupId = parent.mMeta.mGroupId;
comment.mMeta.mMsgId = genRandomId();
comment.mMeta.mOrigMsgId = comment.mMeta.mMsgId;
comment.mMeta.mThreadId = parent.mMeta.mThreadId;
comment.mMeta.mParentId = parent.mMeta.mOrigMsgId;
comment.mMeta.mPublishTs = parent.mMeta.mPublishTs + (RSRandom::random_f32() * 10000);
if (comment.mMeta.mPublishTs > now)
comment.mMeta.mPublishTs = now - 1;
mComments.push_back(comment);
}
for(i = 0; i < MAX_VOTES; i++)
{
/* generate a base thread */
/* rotate the Forum Groups Around, then pick one.
*/
int rnd = (int) (RSRandom::random_f32() * 10.0);
for(j = 0; j < rnd; j++)
{
RsPostedPost head = mPosts.front();
mPosts.pop_front();
mPosts.push_back(head);
}
RsPostedPost parent = mPosts.front();
/* now create a new child msg */
RsPostedVote vote;
snprintf(name, DUMMY_NAME_MAX_LEN, "%s => Vote_%d", parent.mMeta.mMsgName.c_str(), i+1);
vote.mMeta.mMsgName = name;
//vote.mMsg = name;
vote.mMeta.mGroupId = parent.mMeta.mGroupId;
vote.mMeta.mMsgId = genRandomId();
vote.mMeta.mOrigMsgId = vote.mMeta.mMsgId;
vote.mMeta.mThreadId = parent.mMeta.mThreadId;
vote.mMeta.mParentId = parent.mMeta.mOrigMsgId;
vote.mMeta.mPublishTs = parent.mMeta.mPublishTs + (RSRandom::random_f32() * 10000);
if (vote.mMeta.mPublishTs > now)
vote.mMeta.mPublishTs = now - 1;
mVotes.push_back(vote);
}
mUpdated = true;
/* Then - at the end, we push them all into the Proxy */
for(git = mGroups.begin(); git != mGroups.end(); git++)
{
/* pushback */
mPostedProxy->addGroup(*git);
}
for(pit = mPosts.begin(); pit != mPosts.end(); pit++)
{
/* pushback */
mPostedProxy->addPost(*pit);
}
for(cit = mComments.begin(); cit != mComments.end(); cit++)
{
/* pushback */
#define COMMENT_FRAC_FOR_LATER (0.70)
if (RSRandom::random_f32() > COMMENT_FRAC_FOR_LATER)
{
mPostedProxy->addComment(*cit);
}
else
{
mDummyLaterComments.push_back(*cit);
}
}
for(vit = mVotes.begin(); vit != mVotes.end(); vit++)
{
/* pushback */
#define VOTE_FRAC_FOR_LATER (0.70)
if (RSRandom::random_f32() > VOTE_FRAC_FOR_LATER)
{
mPostedProxy->addVote(*vit);
}
else
{
mDummyLaterVotes.push_back(*vit);
}
}
return true;
}
#define EXTRA_COMMENT_ADD (20)
#define EXTRA_VOTE_ADD (50)
bool p3PostedService::addExtraDummyData()
{
std::cerr << "p3PostedService::addExtraDummyData()";
std::cerr << std::endl;
int i = 0;
std::list<RsPostedVote>::iterator vit;
std::list<RsPostedComment>::iterator cit;
for(cit = mDummyLaterComments.begin(); (cit != mDummyLaterComments.end()) && (i < EXTRA_COMMENT_ADD); i++)
{
mPostedProxy->addComment(*cit);
cit = mDummyLaterComments.erase(cit);
}
i = 0;
for(vit = mDummyLaterVotes.begin(); (vit != mDummyLaterVotes.end()) && (i < EXTRA_VOTE_ADD); i++)
{
mPostedProxy->addVote(*vit);
vit = mDummyLaterVotes.erase(vit);
}
return true;
}
#endif

View File

@ -1,120 +0,0 @@
/*
* libretroshare/src/services: p3wire.h
*
* Wire interface for RetroShare.
*
* Copyright 2012-2012 by Robert Fernie.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License Version 2 as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA.
*
* Please report all bugs and problems to "retroshare@lunamutt.com".
*
*/
#ifndef P3_WIRE_SERVICE_VEG_HEADER
#define P3_WIRE_SERVICE_VEG_HEADER
#include "services/p3gxsserviceVEG.h"
#include "retroshare/rswireVEG.h"
#include <map>
#include <string>
/*
* Wire Service
*
*/
class WireDataProxy: public GxsDataProxyVEG
{
public:
bool getGroup(const std::string &id, RsWireGroup &group);
bool getPulse(const std::string &id, RsWirePulse &pulse);
bool addGroup(const RsWireGroup &group);
bool addPulse(const RsWirePulse &pulse);
/* These Functions must be overloaded to complete the service */
virtual bool convertGroupToMetaData(void *groupData, RsGroupMetaData &meta);
virtual bool convertMsgToMetaData(void *msgData, RsMsgMetaData &meta);
};
class p3WireVEG: public p3GxsDataServiceVEG, public RsWireVEG
{
public:
p3WireVEG(uint16_t type);
virtual int tick();
public:
virtual bool updated();
/* Data Requests */
virtual bool requestGroupInfo( uint32_t &token, uint32_t ansType, const RsTokReqOptionsVEG &opts, const std::list<std::string> &groupIds);
virtual bool requestMsgInfo( uint32_t &token, uint32_t ansType, const RsTokReqOptionsVEG &opts, const std::list<std::string> &groupIds);
virtual bool requestMsgRelatedInfo(uint32_t &token, uint32_t ansType, const RsTokReqOptionsVEG &opts, const std::list<std::string> &msgIds);
/* Generic Lists */
virtual bool getGroupList( const uint32_t &token, std::list<std::string> &groupIds);
virtual bool getMsgList( const uint32_t &token, std::list<std::string> &msgIds);
/* Generic Summary */
virtual bool getGroupSummary( const uint32_t &token, std::list<RsGroupMetaData> &groupInfo);
virtual bool getMsgSummary( const uint32_t &token, std::list<RsMsgMetaData> &msgInfo);
/* Actual Data -> specific to Interface */
/* Specific Service Data */
virtual bool getGroupData(const uint32_t &token, RsWireGroup &group);
virtual bool getMsgData(const uint32_t &token, RsWirePulse &page);
/* Poll */
virtual uint32_t requestStatus(const uint32_t token);
/* Cancel Request */
virtual bool cancelRequest(const uint32_t &token);
//////////////////////////////////////////////////////////////////////////////
virtual bool setMessageStatus(const std::string &msgId, const uint32_t status, const uint32_t statusMask);
virtual bool setGroupStatus(const std::string &groupId, const uint32_t status, const uint32_t statusMask);
virtual bool setGroupSubscribeFlags(const std::string &groupId, uint32_t subscribeFlags, uint32_t subscribeMask);
virtual bool setMessageServiceString(const std::string &msgId, const std::string &str);
virtual bool setGroupServiceString(const std::string &grpId, const std::string &str);
virtual bool groupRestoreKeys(const std::string &groupId);
virtual bool groupShareKeys(const std::string &groupId, std::list<std::string>& peers);
virtual bool createGroup(uint32_t &token, RsWireGroup &group, bool isNew);
virtual bool createPulse(uint32_t &token, RsWirePulse &pulse, bool isNew);
private:
std::string genRandomId();
WireDataProxy *mWireProxy;
RsMutex mWireMtx;
/***** below here is locked *****/
bool mUpdated;
};
#endif