From e40c469aa45783f7f532446a6e7ec95d1f5259ee Mon Sep 17 00:00:00 2001 From: chrisparker126 Date: Mon, 26 Jul 2010 22:09:33 +0000 Subject: [PATCH] added config saving feature to distrib services. you can now save configurations that is local to a particular distrib service (forum, channels, and blogs) -- needs full rs-gui recompile - added ability of forum's to save 'msg read' status (meant to supercede current similar feature implement in qt gui side) - updated test for distrib items, added forum items test - added doxygen comments for rsinit and others. git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3314 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- libretroshare/src/rsiface/rsforums.h | 5 +- libretroshare/src/rsiface/rsinit.h | 55 ++++++++++++--- libretroshare/src/services/p3blogs.cc | 12 ++++ libretroshare/src/services/p3blogs.h | 4 +- libretroshare/src/services/p3channels.cc | 11 +++ libretroshare/src/services/p3channels.h | 3 + libretroshare/src/services/p3distrib.cc | 41 +++++++++++- libretroshare/src/services/p3distrib.h | 10 +++ libretroshare/src/services/p3forums.cc | 67 ++++++++++++++++++- libretroshare/src/services/p3forums.h | 10 ++- .../src/tests/serialiser/distribitem_test.cc | 28 ++++++-- .../src/tests/serialiser/distribitem_test.h | 2 + 12 files changed, 227 insertions(+), 21 deletions(-) diff --git a/libretroshare/src/rsiface/rsforums.h b/libretroshare/src/rsiface/rsforums.h index 9c20ba8ab..6ffcd5ec3 100644 --- a/libretroshare/src/rsiface/rsforums.h +++ b/libretroshare/src/rsiface/rsforums.h @@ -65,7 +65,7 @@ class ForumMsgInfo ForumMsgInfo() { msgflags = 0 ; - ts = childTS = 0 ; + ts = childTS = status = 0 ; } std::string forumId; std::string threadId; @@ -80,6 +80,7 @@ class ForumMsgInfo std::wstring msg; time_t ts; time_t childTS; + uint32_t status; }; @@ -132,7 +133,7 @@ virtual bool getForumList(std::list &forumList) = 0; virtual bool getForumThreadList(std::string fId, std::list &msgs) = 0; virtual bool getForumThreadMsgList(std::string fId, std::string pId, std::list &msgs) = 0; virtual bool getForumMessage(std::string fId, std::string mId, ForumMsgInfo &msg) = 0; - +virtual bool setMessageStatus(const std::string& fId,const std::string& mId,const uint32_t status) = 0; virtual bool ForumMessageSend(ForumMsgInfo &info) = 0; virtual bool forumSubscribe(std::string fId, bool subscribe) = 0; diff --git a/libretroshare/src/rsiface/rsinit.h b/libretroshare/src/rsiface/rsinit.h index 43e4caba1..cee38ca9c 100644 --- a/libretroshare/src/rsiface/rsinit.h +++ b/libretroshare/src/rsiface/rsinit.h @@ -27,7 +27,7 @@ */ -/* Initialisation Class (not publicly disclosed to RsIFace) */ + /**** * #define RS_USE_PGPSSL 1 @@ -35,21 +35,43 @@ #define RS_USE_PGPSSL 1 +/*! + * Initialisation Class (not publicly disclosed to RsIFace) + */ class RsInit { public: /* reorganised RsInit system */ - /* PreLogin */ + /*! + * PreLogin + * Call before init retroshare, initialises rsinitconfig's public attributes + */ static void InitRsConfig() ; + + /*! + * Should be called to load up ssl cert and private key, and intialises gpg + * this must be called before accessing rsserver (e.g. ::startupretroshare) + * @param argc passed from executable + * @param argv commandline arguments passed to executable + * @param strictCheck set to true if you want rs to continue executing if invalid argument passed and vice versa + * @return one is initialisation has been successful + */ static int InitRetroShare(int argc, char **argv, bool strictCheck=true); + /*! + * This return directory seperator for different platforms, not an issue anymore as C library can distinguish + * @returns directory of seperator used for different platforms + * + */ static char dirSeperator(); static bool isPortable(); - /* Account Details (Combined GPG+SSL Setup) */ + /*! + * Account Details (Combined GPG+SSL Setup) + */ static bool getPreferedAccountId(std::string &id); static bool getPGPEngineFileName(std::string &fileName); static bool getAccountIds(std::list &ids); @@ -60,22 +82,31 @@ class RsInit static bool ValidateCertificate(std::string &userName) ; - /* Generating GPGme Account */ + /*! + * Generating GPGme Account + */ static int GetPGPLogins(std::list &pgpIds); static int GetPGPLoginDetails(std::string id, std::string &name, std::string &email); static bool GeneratePGPCertificate(std::string name, std::string email, std::string passwd, std::string &pgpId, std::string &errString); - /* Login PGP */ + /*! + * Login GGP + */ static bool SelectGPGAccount(const std::string& gpgId); static bool LoadGPGPassword(std::string passwd); - /* Create SSL Certificates */ + /*! + * Create SSL Certificates + */ static bool GenerateSSLCertificate(std::string name, std::string org, std::string loc, std::string country, std::string passwd, std::string &sslId, std::string &errString); - /* Login SSL */ + /*! + * intialises directories for passwords and ssl keys + */ static bool LoadPassword(std::string id, std::string passwd) ; - /** Final Certificate load. This can be called if: + /*! + * Final Certificate load. This can be called if: * a) InitRetroshare() returns true -> autoLoad/password Set. * b) SelectGPGAccount() && LoadPassword() * @@ -85,9 +116,12 @@ class RsInit static int LockAndLoadCertificates(bool autoLoginNT); - /* Post Login Options */ + /*! + * Post Login Options + */ static std::string RsConfigDirectory(); - static std::string RsProfileConfigDirectory(); + + static std::string RsProfileConfigDirectory(); static bool setStartMinimised() ; static int getSslPwdLen(); @@ -97,6 +131,7 @@ class RsInit private: + /* PreLogin */ static std::string getHomePath() ; static void setupBaseDir(); diff --git a/libretroshare/src/services/p3blogs.cc b/libretroshare/src/services/p3blogs.cc index e8f64fddc..66493109f 100644 --- a/libretroshare/src/services/p3blogs.cc +++ b/libretroshare/src/services/p3blogs.cc @@ -510,7 +510,19 @@ void p3Blogs::locked_notifyGroupChanged(GroupInfo &grp, uint32_t flags) return p3GroupDistrib::locked_notifyGroupChanged(grp, flags); } +//TODO: if you want to enable config saving and loading implement this +bool p3Blogs::childLoadList(std::list& configSaves) +{ + return true; +} +//TODO: +std::list p3Blogs::childSaveList() +{ + std::list saveL; + + return saveL; +} /****************************************/ diff --git a/libretroshare/src/services/p3blogs.h b/libretroshare/src/services/p3blogs.h index 87942e664..e520120b1 100644 --- a/libretroshare/src/services/p3blogs.h +++ b/libretroshare/src/services/p3blogs.h @@ -118,8 +118,8 @@ virtual RsSerialType *createSerialiser(); virtual bool locked_checkDistribMsg(RsDistribMsg *msg); virtual RsDistribGrp *locked_createPublicDistribGrp(GroupInfo &info); virtual RsDistribGrp *locked_createPrivateDistribGrp(GroupInfo &info); - - +virtual bool childLoadList(std::list& configSaves); +virtual std::list childSaveList(); /****************************************/ private: diff --git a/libretroshare/src/services/p3channels.cc b/libretroshare/src/services/p3channels.cc index f3db91671..1044de656 100644 --- a/libretroshare/src/services/p3channels.cc +++ b/libretroshare/src/services/p3channels.cc @@ -757,6 +757,17 @@ void p3Channels::cleanUpOldFiles(){ return; } +//TODO: if you want to config saving and loading for channel distrib service implement this method further +bool p3Channels::childLoadList(std::list& configSaves) +{ + return true; +} + +std::list p3Channels::childSaveList() +{ + return saveList; +} + /****************************************/ #if 0 diff --git a/libretroshare/src/services/p3channels.h b/libretroshare/src/services/p3channels.h index 7fd8ccb26..b311c05b8 100644 --- a/libretroshare/src/services/p3channels.h +++ b/libretroshare/src/services/p3channels.h @@ -92,6 +92,8 @@ virtual RsSerialType *createSerialiser(); virtual bool locked_checkDistribMsg(RsDistribMsg *msg); virtual RsDistribGrp *locked_createPublicDistribGrp(GroupInfo &info); virtual RsDistribGrp *locked_createPrivateDistribGrp(GroupInfo &info); +virtual bool childLoadList(std::list& configSaves); +virtual std::list childSaveList(); /****************************************/ @@ -102,6 +104,7 @@ bool cpyMsgFileToChFldr(std::string path, std::string fname, std::string chId, b RsFiles *mRsFiles; std::string mChannelsDir; + std::list saveList; }; diff --git a/libretroshare/src/services/p3distrib.cc b/libretroshare/src/services/p3distrib.cc index 9b8b18ef7..fd461ab4d 100644 --- a/libretroshare/src/services/p3distrib.cc +++ b/libretroshare/src/services/p3distrib.cc @@ -1424,6 +1424,27 @@ std::list p3GroupDistrib::saveList(bool &cleanup) } + std::list childSaveL = childSaveList(); + std::list::iterator cit = childSaveL.begin(); + RsSerialType *childSer = createSerialiser(); + uint32_t pktSize = 0; + unsigned char *data = NULL; + + for(; cit != childSaveL.end() ; cit++) + { + RsDistribConfigData* childConfig = new RsDistribConfigData(); + + pktSize = childSer->size(*cit); + data = new unsigned char[pktSize]; + childSer->serialise(*cit, data, &pktSize); + childConfig->service_data.setBinData(data, pktSize); + delete[] data; + saveData.push_back(childConfig); + saveCleanupList.push_back(childConfig); + } + + delete childSer; + return saveData; } @@ -1445,6 +1466,12 @@ void p3GroupDistrib::saveDone() bool p3GroupDistrib::loadList(std::list load) { std::list::iterator lit; + + /* for child config data */ + std::list childLoadL; + RsSerialType* childSer = createSerialiser(); + uint32_t pktSize; + for(lit = load.begin(); lit != load.end(); lit++) { /* decide what type it is */ @@ -1452,6 +1479,7 @@ bool p3GroupDistrib::loadList(std::list load) RsDistribGrp *newGrp = NULL; RsDistribGrpKey *newKey = NULL; RsDistribSignedMsg *newMsg = NULL; + RsDistribConfigData* newChildConfig = NULL; if ((newGrp = dynamic_cast(*lit))) { @@ -1469,12 +1497,23 @@ bool p3GroupDistrib::loadList(std::list load) newMsg->PeerId(mOwnId); loadMsg(newMsg, mOwnId, false); /* false so it'll pushed to PendingPublish list */ } + else if ((newChildConfig = dynamic_cast(*lit))) + { + RsItem* childConfigItem = childSer->deserialise(newChildConfig->service_data.bin_data, + &newChildConfig->service_data.bin_len); + + childLoadL.push_back(childConfigItem); + + } } /* no need to republish until something new comes in */ RsStackMutex stack(distribMtx); /******* STACK LOCKED MUTEX ***********/ - mGroupsRepublish = false; + childLoadList(childLoadL); // send configurations down to child + + mGroupsRepublish = false; + delete childSer; return true; } diff --git a/libretroshare/src/services/p3distrib.h b/libretroshare/src/services/p3distrib.h index 929cb3fa4..f26395185 100644 --- a/libretroshare/src/services/p3distrib.h +++ b/libretroshare/src/services/p3distrib.h @@ -420,6 +420,16 @@ class p3GroupDistrib: public CacheSource, public CacheStore, public p3Config, pu virtual void saveDone(); virtual bool loadList(std::list load); + /*! + * called by top class, child can use to save configs + */ + virtual std::list childSaveList() = 0; + + /*! + * called by top class, child can use to load configs + */ + virtual bool childLoadList(std::list& configSaves) = 0; + /***************************************************************************************/ /***************************************************************************************/ diff --git a/libretroshare/src/services/p3forums.cc b/libretroshare/src/services/p3forums.cc index c59c064c8..a99c8452b 100644 --- a/libretroshare/src/services/p3forums.cc +++ b/libretroshare/src/services/p3forums.cc @@ -262,9 +262,18 @@ bool p3Forums::ForumMessageSend(ForumMsgInfo &info) { bool signIt = (info.msgflags == RS_DISTRIB_AUTHEN_REQ); - createForumMsg(info.forumId, info.parentId, + std::string mId = createForumMsg(info.forumId, info.parentId, info.title, info.msg, signIt); + setMessageStatus(info.forumId, mId, FORUM_MSG_STATUS_READ); + + return true; +} + +bool p3Forums::setMessageStatus(const std::string& fId,const std::string& mId,const uint32_t status) +{ + setReadStatus(fId, mId, status); + return true; } @@ -517,4 +526,60 @@ void p3Forums::loadDummyData() mForumsChanged = true; } +std::list p3Forums::childSaveList() +{ + return mSaveList; +} +void p3Forums::setReadStatus(const std::string& forumId, const std::string& msgId, const uint32_t status) +{ + RsStackMutex stack(distribMtx); + + std::list::iterator lit = mReadStatus.begin(); + + for(; lit != mReadStatus.end(); lit++) + { + + if((*lit)->forumId == forumId) + { + (*lit)->msgReadStatus[msgId] = status; + break; + } + + } + + // if forum id does not exist create one + if(lit == mReadStatus.end()) + { + RsForumReadStatus* rsi = new RsForumReadStatus(); + rsi->forumId = forumId; + rsi->msgReadStatus[msgId] = status; + mReadStatus.push_back(rsi); + mSaveList.push_back(rsi); + } + + return; +} + +bool p3Forums::childLoadList(std::list& configSaves) +{ + RsForumReadStatus* drs = NULL; + std::list::iterator it; + + for(it = configSaves.begin(); it != configSaves.end(); it++) + { + if(NULL != (drs = dynamic_cast(*it))) + { + mReadStatus.push_back(drs); + mSaveList.push_back(drs); + } + else + { + std::cerr << "p3Forums::childLoadList(): Configs items loaded were incorrect!" + << std::endl; + return false; + } + } + + return true; +} diff --git a/libretroshare/src/services/p3forums.h b/libretroshare/src/services/p3forums.h index 0041f5454..a6c94b849 100644 --- a/libretroshare/src/services/p3forums.h +++ b/libretroshare/src/services/p3forums.h @@ -67,6 +67,7 @@ class RsForumMsg: public RsDistribMsg #endif +const uint32_t FORUM_MSG_STATUS_READ = 1; class p3Forums: public p3GroupDistrib, public RsForums { @@ -90,8 +91,9 @@ virtual bool getForumList(std::list &forumList); virtual bool getForumThreadList(std::string fId, std::list &msgs); virtual bool getForumThreadMsgList(std::string fId, std::string tId, std::list &msgs); virtual bool getForumMessage(std::string fId, std::string mId, ForumMsgInfo &msg); - +virtual void setReadStatus(const std::string& forumId,const std::string& msgId,const uint32_t status); virtual bool ForumMessageSend(ForumMsgInfo &info); +virtual bool setMessageStatus(const std::string& fId, const std::string& mId,const uint32_t status); virtual bool forumSubscribe(std::string fId, bool subscribe); @@ -115,6 +117,8 @@ virtual RsSerialType *createSerialiser(); virtual bool locked_checkDistribMsg(RsDistribMsg *msg); virtual RsDistribGrp *locked_createPublicDistribGrp(GroupInfo &info); virtual RsDistribGrp *locked_createPrivateDistribGrp(GroupInfo &info); +virtual bool childLoadList(std::list& ); +virtual std::list childSaveList(); /****************************************/ @@ -128,6 +132,10 @@ std::string createForumMsg(std::string fId, std::string pId, bool mForumsChanged; std::string mForumsDir; +std::list mSaveList; // store save data + +std::list mReadStatus; + }; diff --git a/libretroshare/src/tests/serialiser/distribitem_test.cc b/libretroshare/src/tests/serialiser/distribitem_test.cc index 1ef5f48e0..fc1e662c4 100644 --- a/libretroshare/src/tests/serialiser/distribitem_test.cc +++ b/libretroshare/src/tests/serialiser/distribitem_test.cc @@ -65,7 +65,6 @@ void init_item(RsTlvSecurityKey& sk) void init_item(RsTlvKeySignature& ks) { randString(SHORT_STR, ks.keyId); - randString(LARGE_STR, ks.sslCert); std::string signData; randString(LARGE_STR, signData); @@ -154,7 +153,6 @@ bool operator==(const RsTlvKeySignature& ks1, const RsTlvKeySignature& ks2) { if(ks1.keyId != ks2.keyId) return false; - if(ks1.sslCert != ks2.sslCert) return false; if(!(ks1.signData == ks2.signData)) return false; return true; @@ -350,6 +348,7 @@ RsSerialType* init_item(RsChannelMsg& chMsg) randString(SHORT_STR, chMsg.subject); randString(SHORT_STR, chMsg.threadId); chMsg.timestamp = rand()%31452; + init_item(chMsg.thumbnail); init_item(chMsg.attachment); return new RsChannelSerialiser(); @@ -365,6 +364,8 @@ bool operator==(const RsChannelMsg& chMsg1,const RsChannelMsg& chMsg2) if(chMsg1.subject != chMsg2.subject) return false; if(chMsg2.threadId != chMsg2.threadId) return false; if(chMsg1.timestamp != chMsg2.timestamp) return false; + if(!(chMsg1.thumbnail.binData == chMsg2.thumbnail.binData)) return false; + if(chMsg1.thumbnail.image_type != chMsg2.thumbnail.image_type) return false; return true; } @@ -372,24 +373,42 @@ bool operator==(const RsChannelMsg& chMsg1,const RsChannelMsg& chMsg2) RsSerialType* init_item(RsForumMsg& fMsg) { + fMsg.timestamp = rand()%242; + randString(SHORT_STR, fMsg.grpId); + randString(LARGE_STR, fMsg.msg); + randString(SHORT_STR, fMsg.parentId); + randString(SHORT_STR, fMsg.srcId); + randString(SHORT_STR, fMsg.threadId); + randString(SHORT_STR, fMsg.title); + return new RsForumSerialiser(); } -bool operator==(RsForumMsg& fMsg1, RsForumMsg& fMsg2) +bool operator==(const RsForumMsg& fMsg1, const RsForumMsg& fMsg2) { + if(fMsg1.grpId != fMsg2.grpId) return false; + if(fMsg1.msg != fMsg2.msg) return false; + if(fMsg1.parentId != fMsg2.parentId) return false; + if(fMsg1.srcId != fMsg2.srcId) return false; + if(fMsg1.threadId != fMsg2.threadId) return false; + if(fMsg1.timestamp != fMsg2.timestamp) return false; + if(fMsg1.title != fMsg2.title) return false; + return true; } RsSerialType* init_item(RsBlogMsg& bMsg) { + return new RsBlogSerialiser(); } bool operator==(RsBlogMsg& bMsg1, RsBlogMsg& bMsg2) { + return true; } @@ -469,7 +488,8 @@ int main(){ test_RsDistribItem(); REPORT("Serialise/Deserialise RsDistribGrpKey"); test_RsDistribItem(); REPORT("Serialise/Deserialise RsDistribSignedMsg"); test_RsDistribItem(); REPORT("Serialise/Deserialise RsChannelMsg"); - //test_RsDistribItem(); REPORT("Serialise/Deserialise RsForumMsg"); + test_RsDistribItem(); REPORT("Serialise/Deserialise RsForumMsg"); + //test_RsDistribItem(); REPORT("Serialise/Deserialise RsForumReadStatus"); //test_RsDistribItem(); REPORT("Serialise/Deserialise RsBlogMsg"); diff --git a/libretroshare/src/tests/serialiser/distribitem_test.h b/libretroshare/src/tests/serialiser/distribitem_test.h index 6f7b4a9fb..b7c2adf8f 100644 --- a/libretroshare/src/tests/serialiser/distribitem_test.h +++ b/libretroshare/src/tests/serialiser/distribitem_test.h @@ -38,6 +38,7 @@ RsSerialType* init_item(RsDistribGrpKey&); RsSerialType* init_item(RsDistribSignedMsg&); RsSerialType* init_item(RsChannelMsg&); RsSerialType* init_item(RsForumMsg&); +RsSerialType* init_item(RsForumReadStatus&); RsSerialType* init_item(RsBlogMsg&); bool operator==(const RsDistribGrp& , const RsDistribGrp& ); @@ -45,6 +46,7 @@ bool operator==(const RsDistribGrpKey& , const RsDistribGrpKey& ); bool operator==(const RsDistribSignedMsg& , const RsDistribSignedMsg& ); bool operator==(const RsChannelMsg& , const RsChannelMsg& ); bool operator==(const RsForumMsg& , const RsForumMsg& ); +bool operator==(const RsForumReadStatus&, const RsForumReadStatus& ); bool operator==(const RsBlogMsg& , const RsBlogMsg& ); void init_item(RsTlvSecurityKey&);