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
This commit is contained in:
chrisparker126 2010-07-26 22:09:33 +00:00
parent cee8600a93
commit e40c469aa4
12 changed files with 227 additions and 21 deletions

View File

@ -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<ForumInfo> &forumList) = 0;
virtual bool getForumThreadList(std::string fId, std::list<ThreadInfoSummary> &msgs) = 0;
virtual bool getForumThreadMsgList(std::string fId, std::string pId, std::list<ThreadInfoSummary> &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;

View File

@ -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<std::string> &ids);
@ -60,22 +82,31 @@ class RsInit
static bool ValidateCertificate(std::string &userName) ;
/* Generating GPGme Account */
/*!
* Generating GPGme Account
*/
static int GetPGPLogins(std::list<std::string> &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,8 +116,11 @@ class RsInit
static int LockAndLoadCertificates(bool autoLoginNT);
/* Post Login Options */
/*!
* Post Login Options
*/
static std::string RsConfigDirectory();
static std::string RsProfileConfigDirectory();
static bool setStartMinimised() ;
@ -97,6 +131,7 @@ class RsInit
private:
/* PreLogin */
static std::string getHomePath() ;
static void setupBaseDir();

View File

@ -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<RsItem* >& configSaves)
{
return true;
}
//TODO:
std::list<RsItem *> p3Blogs::childSaveList()
{
std::list<RsItem *> saveL;
return saveL;
}
/****************************************/

View File

@ -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<RsItem* >& configSaves);
virtual std::list<RsItem *> childSaveList();
/****************************************/
private:

View File

@ -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<RsItem* >& configSaves)
{
return true;
}
std::list<RsItem *> p3Channels::childSaveList()
{
return saveList;
}
/****************************************/
#if 0

View File

@ -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<RsItem* >& configSaves);
virtual std::list<RsItem *> childSaveList();
/****************************************/
@ -102,6 +104,7 @@ bool cpyMsgFileToChFldr(std::string path, std::string fname, std::string chId, b
RsFiles *mRsFiles;
std::string mChannelsDir;
std::list<RsItem *> saveList;
};

View File

@ -1424,6 +1424,27 @@ std::list<RsItem *> p3GroupDistrib::saveList(bool &cleanup)
}
std::list<RsItem *> childSaveL = childSaveList();
std::list<RsItem *>::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<RsItem *> load)
{
std::list<RsItem *>::iterator lit;
/* for child config data */
std::list<RsItem* > 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<RsItem *> load)
RsDistribGrp *newGrp = NULL;
RsDistribGrpKey *newKey = NULL;
RsDistribSignedMsg *newMsg = NULL;
RsDistribConfigData* newChildConfig = NULL;
if ((newGrp = dynamic_cast<RsDistribGrp *>(*lit)))
{
@ -1469,12 +1497,23 @@ bool p3GroupDistrib::loadList(std::list<RsItem *> load)
newMsg->PeerId(mOwnId);
loadMsg(newMsg, mOwnId, false); /* false so it'll pushed to PendingPublish list */
}
else if ((newChildConfig = dynamic_cast<RsDistribConfigData *>(*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;
}

View File

@ -420,6 +420,16 @@ class p3GroupDistrib: public CacheSource, public CacheStore, public p3Config, pu
virtual void saveDone();
virtual bool loadList(std::list<RsItem *> load);
/*!
* called by top class, child can use to save configs
*/
virtual std::list<RsItem *> childSaveList() = 0;
/*!
* called by top class, child can use to load configs
*/
virtual bool childLoadList(std::list<RsItem *>& configSaves) = 0;
/***************************************************************************************/
/***************************************************************************************/

View File

@ -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<RsItem* > p3Forums::childSaveList()
{
return mSaveList;
}
void p3Forums::setReadStatus(const std::string& forumId, const std::string& msgId, const uint32_t status)
{
RsStackMutex stack(distribMtx);
std::list<RsForumReadStatus *>::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<RsItem* >& configSaves)
{
RsForumReadStatus* drs = NULL;
std::list<RsItem* >::iterator it;
for(it = configSaves.begin(); it != configSaves.end(); it++)
{
if(NULL != (drs = dynamic_cast<RsForumReadStatus* >(*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;
}

View File

@ -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<ForumInfo> &forumList);
virtual bool getForumThreadList(std::string fId, std::list<ThreadInfoSummary> &msgs);
virtual bool getForumThreadMsgList(std::string fId, std::string tId, std::list<ThreadInfoSummary> &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<RsItem *>& );
virtual std::list<RsItem *> childSaveList();
/****************************************/
@ -128,6 +132,10 @@ std::string createForumMsg(std::string fId, std::string pId,
bool mForumsChanged;
std::string mForumsDir;
std::list<RsItem *> mSaveList; // store save data
std::list<RsForumReadStatus *> mReadStatus;
};

View File

@ -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<RsDistribGrpKey>(); REPORT("Serialise/Deserialise RsDistribGrpKey");
test_RsDistribItem<RsDistribSignedMsg>(); REPORT("Serialise/Deserialise RsDistribSignedMsg");
test_RsDistribItem<RsChannelMsg>(); REPORT("Serialise/Deserialise RsChannelMsg");
//test_RsDistribItem<RsForumMsg>(); REPORT("Serialise/Deserialise RsForumMsg");
test_RsDistribItem<RsForumMsg>(); REPORT("Serialise/Deserialise RsForumMsg");
//test_RsDistribItem<RsForumReadStatus>(); REPORT("Serialise/Deserialise RsForumReadStatus");
//test_RsDistribItem<RsBlogMsg>(); REPORT("Serialise/Deserialise RsBlogMsg");

View File

@ -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&);