From d4bf742268f31599e2d3eb9e51587ba62cbaa91f Mon Sep 17 00:00:00 2001 From: drbob Date: Fri, 19 Oct 2012 00:16:35 +0000 Subject: [PATCH] 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 --- libretroshare/src/libretroshare.pro | 23 ++- libretroshare/src/retroshare/rswiki.h | 131 +++++++++++++ libretroshare/src/retroshare/rswikiVEG.h | 4 +- libretroshare/src/serialiser/rswikiitems.h | 112 +++++++++++ libretroshare/src/services/p3wiki.cc | 184 ++++++++++++++++++ libretroshare/src/services/p3wiki.h | 69 +++++++ libretroshare/src/services/p3wikiserviceVEG.h | 4 +- 7 files changed, 521 insertions(+), 6 deletions(-) create mode 100644 libretroshare/src/retroshare/rswiki.h create mode 100644 libretroshare/src/serialiser/rswikiitems.h create mode 100644 libretroshare/src/services/p3wiki.cc create mode 100644 libretroshare/src/services/p3wiki.h diff --git a/libretroshare/src/libretroshare.pro b/libretroshare/src/libretroshare.pro index 127875236..3e211f0ea 100644 --- a/libretroshare/src/libretroshare.pro +++ b/libretroshare/src/libretroshare.pro @@ -602,7 +602,8 @@ HEADERS += retroshare/rsgame.h \ gxs/gxssecurity.h \ gxs/rsgxsifaceimpl.h \ services/p3posted.h \ - retroshare/rsposted.h + retroshare/rsposted.h \ + SOURCES += serialiser/rsnxsitems.cc \ gxs/rsdataservice.cc \ @@ -619,7 +620,25 @@ HEADERS += retroshare/rsgame.h \ gxs/gxssecurity.cc \ gxs/gxssecurity.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 { diff --git a/libretroshare/src/retroshare/rswiki.h b/libretroshare/src/retroshare/rswiki.h new file mode 100644 index 000000000..07e527791 --- /dev/null +++ b/libretroshare/src/retroshare/rswiki.h @@ -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 +#include +#include + +#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 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 &collections) = 0; +virtual bool getSnapshots(const uint32_t &token, std::vector &snapshots) = 0; +virtual bool getComments(const uint32_t &token, std::vector &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 diff --git a/libretroshare/src/retroshare/rswikiVEG.h b/libretroshare/src/retroshare/rswikiVEG.h index 75616c8d4..8431ee3d8 100644 --- a/libretroshare/src/retroshare/rswikiVEG.h +++ b/libretroshare/src/retroshare/rswikiVEG.h @@ -1,5 +1,5 @@ -#ifndef RETROSHARE_WIKI_GUI_INTERFACE_H -#define RETROSHARE_WIKI_GUI_INTERFACE_H +#ifndef RETROSHARE_WIKI_VEG_GUI_INTERFACE_H +#define RETROSHARE_WIKI_VEG_GUI_INTERFACE_H /* * libretroshare/src/retroshare: rswiki.h diff --git a/libretroshare/src/serialiser/rswikiitems.h b/libretroshare/src/serialiser/rswikiitems.h new file mode 100644 index 000000000..2b356c400 --- /dev/null +++ b/libretroshare/src/serialiser/rswikiitems.h @@ -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 + +#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 */ diff --git a/libretroshare/src/services/p3wiki.cc b/libretroshare/src/services/p3wiki.cc new file mode 100644 index 000000000..563b5b04f --- /dev/null +++ b/libretroshare/src/services/p3wiki.cc @@ -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& changes) +{ + receiveChanges(changes); +} + + /* Specific Service Data */ +bool p3Wiki::getCollections(const uint32_t &token, std::vector &collections) +{ + std::vector grpData; + bool ok = RsGenExchange::getGroupData(token, grpData); + + if(ok) + { + std::vector::iterator vit = grpData.begin(); + + for(; vit != grpData.end(); vit++) + { + RsGxsWikiCollectionItem* item = dynamic_cast(*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 &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& msgItems = mit->second; + std::vector::iterator vit = msgItems.begin(); + + for(; vit != msgItems.end(); vit++) + { + RsGxsWikiSnapshotItem* item = dynamic_cast(*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 &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& msgItems = mit->second; + std::vector::iterator vit = msgItems.begin(); + + for(; vit != msgItems.end(); vit++) + { + RsGxsWikiCommentItem* item = dynamic_cast(*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; +} + + diff --git a/libretroshare/src/services/p3wiki.h b/libretroshare/src/services/p3wiki.h new file mode 100644 index 000000000..10bd1edd3 --- /dev/null +++ b/libretroshare/src/services/p3wiki.h @@ -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 +#include + +/* + * Wiki Service + * + * + */ + +class p3Wiki: public RsGenExchange, public RsWiki +{ +public: + p3Wiki(RsGeneralDataService* gds, RsNetworkExchangeService* nes); + +protected: + +virtual void notifyChanges(std::vector& changes) ; + +public: + + /* Specific Service Data */ +virtual bool getCollections(const uint32_t &token, std::vector &collections); +virtual bool getSnapshots(const uint32_t &token, std::vector &snapshots); +virtual bool getComments(const uint32_t &token, std::vector &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 diff --git a/libretroshare/src/services/p3wikiserviceVEG.h b/libretroshare/src/services/p3wikiserviceVEG.h index 4aba5345a..f172f4d3f 100644 --- a/libretroshare/src/services/p3wikiserviceVEG.h +++ b/libretroshare/src/services/p3wikiserviceVEG.h @@ -23,8 +23,8 @@ * */ -#ifndef P3_WIKI_SERVICE_HEADER -#define P3_WIKI_SERVICE_HEADER +#ifndef P3_WIKI_SERVICE_VEG_HEADER +#define P3_WIKI_SERVICE_VEG_HEADER #include "services/p3gxsserviceVEG.h" #include "retroshare/rswikiVEG.h"