Added basic GXS Wiki Service.

* Filled in p3wiki and rswiki
 * tweaked VEG files to prevent clashes.
 * added serialiser header.

Still to do: 
 * complete design of Wiki Links, and the like.
 * Finish serialiser




git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-gxs-b1@5692 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
drbob 2012-10-19 00:16:35 +00:00
parent c5d750c0ea
commit d4bf742268
7 changed files with 521 additions and 6 deletions

View File

@ -602,7 +602,8 @@ HEADERS += retroshare/rsgame.h \
gxs/gxssecurity.h \ gxs/gxssecurity.h \
gxs/rsgxsifaceimpl.h \ gxs/rsgxsifaceimpl.h \
services/p3posted.h \ services/p3posted.h \
retroshare/rsposted.h retroshare/rsposted.h \
SOURCES += serialiser/rsnxsitems.cc \ SOURCES += serialiser/rsnxsitems.cc \
gxs/rsdataservice.cc \ gxs/rsdataservice.cc \
@ -619,7 +620,25 @@ HEADERS += retroshare/rsgame.h \
gxs/gxssecurity.cc \ gxs/gxssecurity.cc \
gxs/gxssecurity.cc \ gxs/gxssecurity.cc \
gxs/rsgxsifaceimpl.cc \ gxs/rsgxsifaceimpl.cc \
services/p3posted.cc services/p3posted.cc \
# Identity Service
#HEADERS += retroshare/rsidentity.h \
# gxs/rsgixs.h \
# services/p3idservice.h \
# serialiser/rsiditems.h \
#SOURCES += services/p3idservice.cc \
# serialiser/rsiditems.cc \
# Wiki Service
HEADERS += retroshare/rswiki.h \
services/p3wiki.h \
serialiser/rswikiitems.h \
SOURCES += services/p3wiki.cc \
# serialiser/rswikiitems.cc \
} }
newservices { newservices {

View File

@ -0,0 +1,131 @@
#ifndef RETROSHARE_WIKI_GUI_INTERFACE_H
#define RETROSHARE_WIKI_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 "gxs/rstokenservice.h"
#include "gxs/rsgxsifaceimpl.h"
/* The Main Interface Class - for information about your Peers */
class RsWiki;
extern RsWiki *rsWiki;
/* so the basic idea of Wiki is a set of Collections about subjects.
*
* Collection: RS
* - page: DHT
* - edit
* - edit
* - official revision. (new version of thread head).
*
* A collection will be moderated by it creator - important to prevent stupid changes.
* We need a way to swap out / replace / fork collections if moderator is rubbish.
*
* This should probably be done that the collection level.
* and enable all the references to be modified.
*
* Collection1 (RS DHT)
* : Turtle Link: Collection 0x54e4dafc34
* - Page 1
* - Page 2
* - Link to Self:Page 1
* - Link to Turtle:Page 1
*
*
*/
#define FLAG_MSG_TYPE_WIKI_SNAPSHOT 0x0001
#define FLAG_MSG_TYPE_WIKI_COMMENT 0x0002
class CollectionRef
{
public:
std::string KeyWord;
std::string CollectionId;
};
class RsWikiCollection
{
public:
RsGroupMetaData mMeta;
std::string mDescription;
std::string mCategory;
std::string mHashTags;
//std::map<std::string, CollectionRef> linkReferences;
};
class RsWikiSnapshot
{
public:
RsMsgMetaData mMeta;
std::string mPage; // all the text is stored here.
std::string mHashTags;
};
class RsWikiComment
{
public:
RsMsgMetaData mMeta;
std::string mComment;
};
class RsWiki: public RsGxsIfaceImpl
{
public:
RsWiki(RsGenExchange *gxs): RsGxsIfaceImpl(gxs) { return; }
virtual ~RsWiki() { return; }
/* Specific Service Data */
virtual bool getCollections(const uint32_t &token, std::vector<RsWikiCollection> &collections) = 0;
virtual bool getSnapshots(const uint32_t &token, std::vector<RsWikiSnapshot> &snapshots) = 0;
virtual bool getComments(const uint32_t &token, std::vector<RsWikiComment> &comments) = 0;
virtual bool submitCollection(uint32_t &token, RsWikiCollection &collection) = 0;
virtual bool submitSnapshot(uint32_t &token, RsWikiSnapshot &snapshot) = 0;
virtual bool submitComment(uint32_t &token, RsWikiComment &comment) = 0;
};
#endif

View File

@ -1,5 +1,5 @@
#ifndef RETROSHARE_WIKI_GUI_INTERFACE_H #ifndef RETROSHARE_WIKI_VEG_GUI_INTERFACE_H
#define RETROSHARE_WIKI_GUI_INTERFACE_H #define RETROSHARE_WIKI_VEG_GUI_INTERFACE_H
/* /*
* libretroshare/src/retroshare: rswiki.h * libretroshare/src/retroshare: rswiki.h

View File

@ -0,0 +1,112 @@
/*
* libretroshare/src/serialiser: rswikiitems.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".
*
*/
#ifndef RS_WIKI_ITEMS_H
#define RS_WIKI_ITEMS_H
#include <map>
#include "serialiser/rsserviceids.h"
#include "serialiser/rsserial.h"
#include "serialiser/rstlvtypes.h"
#include "rsgxsitems.h"
#include "retroshare/rswiki.h"
const uint8_t RS_PKT_SUBTYPE_WIKI_COLLECTION_ITEM = 0x02;
const uint8_t RS_PKT_SUBTYPE_WIKI_SNAPSHOT_ITEM = 0x03;
const uint8_t RS_PKT_SUBTYPE_WIKI_COMMENT_ITEM = 0x04;
class RsGxsWikiCollectionItem : public RsGxsGrpItem
{
public:
RsGxsWikiCollectionItem(): RsGxsGrpItem(RS_SERVICE_GXSV1_TYPE_WIKI,
RS_PKT_SUBTYPE_WIKI_COLLECTION_ITEM) { return;}
virtual ~RsGxsWikiCollectionItem() { return;}
void clear();
std::ostream &print(std::ostream &out, uint16_t indent = 0);
RsWikiCollection collection;
};
class RsGxsWikiSnapshotItem : public RsGxsMsgItem
{
public:
RsGxsWikiSnapshotItem(): RsGxsMsgItem(RS_SERVICE_GXSV1_TYPE_WIKI,
RS_PKT_SUBTYPE_WIKI_SNAPSHOT_ITEM) {return; }
virtual ~RsGxsWikiSnapshotItem() { return;}
void clear();
std::ostream &print(std::ostream &out, uint16_t indent = 0);
RsWikiSnapshot snapshot;
};
class RsGxsWikiCommentItem : public RsGxsMsgItem
{
public:
RsGxsWikiCommentItem(): RsGxsMsgItem(RS_SERVICE_GXSV1_TYPE_WIKI,
RS_PKT_SUBTYPE_WIKI_COMMENT_ITEM) { return; }
virtual ~RsGxsWikiCommentItem() { return; }
void clear();
std::ostream &print(std::ostream &out, uint16_t indent = 0);
RsWikiComment comment;
};
class RsGxsWikiSerialiser : public RsSerialType
{
public:
RsGxsWikiSerialiser()
:RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_GXSV1_TYPE_WIKI)
{ return; }
virtual ~RsGxsWikiSerialiser() { 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 sizeGxsWikiCollectionItem(RsGxsWikiCollectionItem *item);
bool serialiseGxsWikiCollectionItem (RsGxsWikiCollectionItem *item, void *data, uint32_t *size);
RsGxsWikiCollectionItem * deserialiseGxsWikiCollectionItem(void *data, uint32_t *size);
uint32_t sizeGxsWikiSnapshotItem(RsGxsWikiSnapshotItem *item);
bool serialiseGxsWikiSnapshotItem (RsGxsWikiSnapshotItem *item, void *data, uint32_t *size);
RsGxsWikiSnapshotItem * deserialiseGxsWikiSnapshotItem(void *data, uint32_t *size);
uint32_t sizeGxsWikiCommentItem(RsGxsWikiCommentItem *item);
bool serialiseGxsWikiCommentItem (RsGxsWikiCommentItem *item, void *data, uint32_t *size);
RsGxsWikiCommentItem * deserialiseGxsWikiCommentItem(void *data, uint32_t *size);
};
#endif /* RS_WIKI_ITEMS_H */

View File

@ -0,0 +1,184 @@
/*
* libretroshare/src/services p3wiki.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/p3wiki.h"
#include "serialiser/rswikiitems.h"
/****
* #define WIKI_DEBUG 1
****/
RsWiki *rsWiki = NULL;
p3Wiki::p3Wiki(RsGeneralDataService* gds, RsNetworkExchangeService* nes)
:RsGenExchange(gds, nes, NULL, RS_SERVICE_GXSV1_TYPE_WIKI), RsWiki(this)
{
}
void p3Wiki::notifyChanges(std::vector<RsGxsNotify*>& changes)
{
receiveChanges(changes);
}
/* Specific Service Data */
bool p3Wiki::getCollections(const uint32_t &token, std::vector<RsWikiCollection> &collections)
{
std::vector<RsGxsGrpItem*> grpData;
bool ok = RsGenExchange::getGroupData(token, grpData);
if(ok)
{
std::vector<RsGxsGrpItem*>::iterator vit = grpData.begin();
for(; vit != grpData.end(); vit++)
{
RsGxsWikiCollectionItem* item = dynamic_cast<RsGxsWikiCollectionItem*>(*vit);
RsWikiCollection collection = item->collection;
collection.mMeta = item->collection.mMeta;
delete item;
collections.push_back(collection);
}
}
return ok;
}
bool p3Wiki::getSnapshots(const uint32_t &token, std::vector<RsWikiSnapshot> &snapshots)
{
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++)
{
RsGxsWikiSnapshotItem* item = dynamic_cast<RsGxsWikiSnapshotItem*>(*vit);
if(item)
{
RsWikiSnapshot snapshot = item->snapshot;
snapshot.mMeta = item->meta;
snapshots.push_back(snapshot);
delete item;
}
else
{
std::cerr << "Not a WikiSnapshot Item, deleting!" << std::endl;
delete *vit;
}
}
}
}
return ok;
}
bool p3Wiki::getComments(const uint32_t &token, std::vector<RsWikiComment> &comments)
{
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++)
{
RsGxsWikiCommentItem* item = dynamic_cast<RsGxsWikiCommentItem*>(*vit);
if(item)
{
RsWikiComment comment = item->comment;
comment.mMeta = item->meta;
comments.push_back(comment);
delete item;
}
else
{
std::cerr << "Not a WikiComment Item, deleting!" << std::endl;
delete *vit;
}
}
}
}
return ok;
return false;
}
bool p3Wiki::submitCollection(uint32_t &token, RsWikiCollection &collection)
{
RsGxsWikiCollectionItem* collectionItem = new RsGxsWikiCollectionItem();
collectionItem->collection = collection;
collectionItem->meta = collection.mMeta;
RsGenExchange::publishGroup(token, collectionItem);
return true;
}
bool p3Wiki::submitSnapshot(uint32_t &token, RsWikiSnapshot &snapshot)
{
RsGxsWikiSnapshotItem* snapshotItem = new RsGxsWikiSnapshotItem();
snapshotItem->snapshot = snapshot;
snapshotItem->meta = snapshot.mMeta;
snapshotItem->meta.mMsgFlags = FLAG_MSG_TYPE_WIKI_SNAPSHOT;
RsGenExchange::publishMsg(token, snapshotItem);
return true;
}
bool p3Wiki::submitComment(uint32_t &token, RsWikiComment &comment)
{
RsGxsWikiCommentItem* commentItem = new RsGxsWikiCommentItem();
commentItem->comment = comment;
commentItem->meta = comment.mMeta;
commentItem->meta.mMsgFlags = FLAG_MSG_TYPE_WIKI_COMMENT;
RsGenExchange::publishMsg(token, commentItem);
return true;
}

View File

@ -0,0 +1,69 @@
/*
* 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_HEADER
#define P3_WIKI_SERVICE_HEADER
#include "retroshare/rswiki.h"
#include "gxs/rsgenexchange.h"
#include <map>
#include <string>
/*
* Wiki Service
*
*
*/
class p3Wiki: public RsGenExchange, public RsWiki
{
public:
p3Wiki(RsGeneralDataService* gds, RsNetworkExchangeService* nes);
protected:
virtual void notifyChanges(std::vector<RsGxsNotify*>& changes) ;
public:
/* Specific Service Data */
virtual bool getCollections(const uint32_t &token, std::vector<RsWikiCollection> &collections);
virtual bool getSnapshots(const uint32_t &token, std::vector<RsWikiSnapshot> &snapshots);
virtual bool getComments(const uint32_t &token, std::vector<RsWikiComment> &comments);
virtual bool submitCollection(uint32_t &token, RsWikiCollection &collection);
virtual bool submitSnapshot(uint32_t &token, RsWikiSnapshot &snapshot);
virtual bool submitComment(uint32_t &token, RsWikiComment &comment);
private:
//std::string genRandomId();
// RsMutex mWikiMtx;
};
#endif

View File

@ -23,8 +23,8 @@
* *
*/ */
#ifndef P3_WIKI_SERVICE_HEADER #ifndef P3_WIKI_SERVICE_VEG_HEADER
#define P3_WIKI_SERVICE_HEADER #define P3_WIKI_SERVICE_VEG_HEADER
#include "services/p3gxsserviceVEG.h" #include "services/p3gxsserviceVEG.h"
#include "retroshare/rswikiVEG.h" #include "retroshare/rswikiVEG.h"