simplified qblog for blogging only, hopefully test everything out soon

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@731 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
chrisparker126 2008-09-21 20:30:34 +00:00
parent a52c34a551
commit d14a1ffb39
6 changed files with 223 additions and 478 deletions

View file

@ -25,15 +25,15 @@
* Please report all bugs and problems to "retroshare@lunamutt.com". * Please report all bugs and problems to "retroshare@lunamutt.com".
* *
*/ */
#include <iostream> #include <iostream>
#include <string> #include <string>
#include <list> #include <list>
#include <map> #include <map>
#include "rsiface/rstypes.h" #include "../rsiface/rstypes.h"
/* delcare interafce for everyone o use */ /* delcare interafce for everyone o use */
class RsQblog; class RsQblog;
extern RsQblog *rsQblog; extern RsQblog *rsQblog;
@ -42,60 +42,23 @@ extern RsQblog *rsQblog;
class RsQblog class RsQblog
{ {
public: public:
RsQblog() { return; } RsQblog() { return; }
virtual ~RsQblog() { return; } virtual ~RsQblog() { return; }
/**
* choose whether to filter or not
* @param filterSwitch
*/
virtual bool setFilterSwitch(bool &filterSwitch) = 0;
/**
* retrieve usrs filterSwitch status
*/
virtual bool getFilterSwitch(void) = 0;
/**
* add user id to filter list
* @param usr id to add to filter list
*/
virtual bool addToFilter(std::string &usrId) = 0;
/**
* remove friend from filter list
* @param id The user's frined's id
*/
virtual bool removeFiltFriend(std::string &usrId) = 0;
/** /**
* send blog info, will send to a data structure for transmission * send blog info, will send to a data structure for transmission
* @param msg The msg the usr wants to send * @param msg The msg the usr wants to send
*/ */
virtual bool sendBlog(const std::wstring &msg) = 0; virtual bool sendBlog(const std::wstring &msg) = 0;
/** /**
* retrieve blog of a usr * retrieve blog of a usr
* @param blogs contains the blog msgs of usr along with time posted for sorting * @param blogs contains the blog msgs of usr along with time posted for sorting
*/ */
virtual bool getBlogs(std::map< std::string, std::multimap<long int, std::wstring> > &blogs) = 0; virtual bool getBlogs(std::map< std::string, std::multimap<long int, std::wstring> > &blogs) = 0;
/**
* set usr profile, send an empty second pair to delete entry
* @param entry profile entry
*/
virtual bool setProfile(std::pair<std::wstring, std::wstring> entry) = 0;
/**
* add fav file, send file info with only name to delete that entry
* @param entry file info entry
*/
virtual bool setFavorites(FileInfo favFile) = 0;
/** /**
* Stuff DrBob Added for Profile View! * Stuff DrBob Added for Profile View!
@ -107,22 +70,8 @@ extern RsQblog *rsQblog;
* @param ts Timestamp of the Blog Post. * @param ts Timestamp of the Blog Post.
* @param post the actual Blog Post. * @param post the actual Blog Post.
*/ */
virtual bool getPeerLatestBlog(std::string id, uint32_t &ts, std::wstring &post) = 0; virtual bool getPeerLatestBlog(std::string id, uint32_t &ts, std::wstring &post) = 0;
/**
* get users Profile.
* @param id the user id
* @param entries set of profile information.
*/
virtual bool getPeerProfile(std::string id, std::list< std::pair<std::wstring, std::wstring> > &entries) = 0;
/**
* get users fav files
* @param id the user whose info you want.
* @param favs list of Files
*/
virtual bool getPeerFavourites(std::string id, std::list<FileInfo> &favs) = 0;
}; };
#endif /*RSQBLOG_H_*/ #endif /*RSQBLOG_H_*/

View file

@ -22,114 +22,41 @@
* Please report all bugs and problems to "retroshare@lunamutt.com". * Please report all bugs and problems to "retroshare@lunamutt.com".
* *
*/ */
#include "rsserver/p3Blog.h"
RsQblog* rsQblog = NULL; #include "../rsserver/p3Blog.h"
RsQblog* rsQblog = NULL;
p3Blog::p3Blog(p3Qblog* qblog) : p3Blog::p3Blog(p3Qblog* qblog) :
mQblog(qblog) mQblog(qblog)
{ {
return; return;
} }
p3Blog::~p3Blog() p3Blog::~p3Blog()
{ {
return; return;
} }
bool p3Blog::addToFilter(std::string &usrId)
{
return mQblog->addToFilter(usrId);
}
bool p3Blog::getBlogs(std::map< std::string, std::multimap<long int, std::wstring> > &blogs) bool p3Blog::getBlogs(std::map< std::string, std::multimap<long int, std::wstring> > &blogs)
{ {
return mQblog->getBlogs(blogs); return mQblog->getBlogs(blogs);
} }
bool p3Blog::getFilterSwitch(void)
{
return mQblog->getFilterSwitch();
}
bool p3Blog::sendBlog(const std::wstring &msg) bool p3Blog::sendBlog(const std::wstring &msg)
{ {
return mQblog->sendBlog(msg); return mQblog->sendBlog(msg);
} }
bool p3Blog::setFilterSwitch(bool &filterSwitch)
{
return mQblog->setFilterSwitch(filterSwitch);
}
bool p3Blog::removeFiltFriend(std::string &usrId)
{
return mQblog->removeFiltFriend(usrId);
}
bool p3Blog::setFavorites(FileInfo favFile)
{
//TODO
//return mQblog->setFavorites(favFile);
}
bool p3Blog::setProfile(std::pair<std::wstring, std::wstring> entry)
{
//TODO
//return mQblog->setProfile(entry);
}
bool p3Blog::getPeerLatestBlog(std::string id, uint32_t &ts, std::wstring &post) bool p3Blog::getPeerLatestBlog(std::string id, uint32_t &ts, std::wstring &post)
{ {
//return mQblog->getPeerLatestBlog(id, ts, post); //return mQblog->getPeerLatestBlog(id, ts, post);
// dummy info.
ts = time(NULL); ts = time(NULL);
post = L"Hmmm, not much, just eating prawn crackers at the moment... but I'll post this every second if you want ;)"; post = L"Hmmm, not much, just eating prawn crackers at the moment... but I'll post this every second if you want ;)";
return true; return true;
}
bool p3Blog::getPeerProfile(std::string id, std::list< std::pair<std::wstring, std::wstring> > &entries)
{
//return mQblog->getPeerProfile(id, entries);
std::wstring a = L"phone number";
std::wstring b = L"0845 XXX 43639434363878735453";
entries.push_back(make_pair(a,b));
a = L"Favourite Film";
b = L"Prawn Crackers revenge";
entries.push_back(make_pair(a,b));
a = L"Favourite Music";
b = L"Eric Clapton, Neil Diamond, Folk, Country and Western";
entries.push_back(make_pair(a,b));
return true;
}
bool p3Blog::getPeerFavourites(std::string id, std::list<FileInfo> &favs)
{
//return mQblog->getPeerFavourites(id, favs);
FileInfo a;
a.fname = "Prawn Crackers - Full Script.txt";
a.size = 1000553;
a.hash = "XXXXXXXXXXXXXXXXXXXXXX";
favs.push_back(a);
return true;
} }

View file

@ -29,8 +29,8 @@
* *
*/ */
#include "rsiface/rsQblog.h" #include "../rsiface/rsQblog.h"
#include "services/p3Qblog.h" #include "../services/p3Qblog.h"
/*! /*!
* Interface class using composition (p3Qblog is an attribute) * Interface class using composition (p3Qblog is an attribute)
@ -39,26 +39,18 @@
class p3Blog : public RsQblog class p3Blog : public RsQblog
{ {
public: public:
p3Blog(p3Qblog* qblog); p3Blog(p3Qblog* qblog);
virtual ~p3Blog(); virtual ~p3Blog();
virtual bool setFilterSwitch(bool &filterSwitch);
virtual bool getFilterSwitch(void);
virtual bool addToFilter(std::string &usrId);
virtual bool removeFiltFriend(std::string &usrId);
virtual bool sendBlog(const std::wstring &msg); virtual bool sendBlog(const std::wstring &msg);
virtual bool getBlogs(std::map< std::string, std::multimap<long int, std::wstring> > &blogs); virtual bool getBlogs(std::map< std::string, std::multimap<long int, std::wstring> > &blogs);
virtual bool setFavorites(FileInfo favFile);
virtual bool setProfile(std::pair<std::wstring, std::wstring> entry);
virtual bool getPeerLatestBlog(std::string id, uint32_t &ts, std::wstring &post); virtual bool getPeerLatestBlog(std::string id, uint32_t &ts, std::wstring &post);
virtual bool getPeerProfile(std::string id, std::list< std::pair<std::wstring, std::wstring> > &entries);
virtual bool getPeerFavourites(std::string id, std::list<FileInfo> &favs);
private: private:
/// to make rsCore blog-service calls /// to make rsCore blog-service calls
p3Qblog* mQblog; p3Qblog* mQblog;
}; };

View file

@ -77,7 +77,7 @@
// COMMENT THIS FOR UNFINISHED SERVICES // COMMENT THIS FOR UNFINISHED SERVICES
/**** /****
#define RS_RELEASE 1 #define RS_RELEASE 1
****/ ****/
/**************** PQI_USE_XPGP ******************/ /**************** PQI_USE_XPGP ******************/
@ -136,7 +136,7 @@ RsInit *InitRsConfig()
strcpy(config->logfname, ""); strcpy(config->logfname, "");
config -> autoLogin = true; // Always on now. config -> autoLogin = true; // Always on now.
config -> startMinimised = false; config -> startMinimised = false;
config -> passwd = ""; config -> passwd = "";
config -> havePasswd = false; config -> havePasswd = false;
config -> haveDebugLevel = false; config -> haveDebugLevel = false;
@ -208,7 +208,7 @@ int InitRetroShare(int argc, char **argv, RsInit *config)
*/ */
#ifdef PTW32_STATIC_LIB #ifdef PTW32_STATIC_LIB
#include <pthread.h> #include <pthread.h>
#endif #endif
int InitRetroShare(int argcIgnored, char **argvIgnored, RsInit *config) int InitRetroShare(int argcIgnored, char **argvIgnored, RsInit *config)
{ {
@ -226,8 +226,8 @@ int InitRetroShare(int argcIgnored, char **argvIgnored, RsInit *config)
char dupline[cmdlen+1]; char dupline[cmdlen+1];
strcpy(dupline, wholeline); strcpy(dupline, wholeline);
/* break wholeline down .... /* break wholeline down ....
* NB. This is very simplistic, and will not * NB. This is very simplistic, and will not
* handle multiple spaces, or quotations etc, only for debugging purposes * handle multiple spaces, or quotations etc, only for debugging purposes
*/ */
argv[0] = dupline; argv[0] = dupline;
@ -251,13 +251,13 @@ int InitRetroShare(int argcIgnored, char **argvIgnored, RsInit *config)
*/ */
#ifdef PTW32_STATIC_LIB #ifdef PTW32_STATIC_LIB
pthread_win32_process_attach_np(); pthread_win32_process_attach_np();
#endif #endif
#endif #endif
/******************************** WINDOWS/UNIX SPECIFIC PART ******************/ /******************************** WINDOWS/UNIX SPECIFIC PART ******************/
int c; int c;
/* getopt info: every availiable option is listet here. if it is followed by a ':' it /* getopt info: every availiable option is listet here. if it is followed by a ':' it
needs an argument. If it is followed by a '::' the argument is optional. needs an argument. If it is followed by a '::' the argument is optional.
*/ */
while((c = getopt(argc, argv,"hesamui:p:c:w:l:d:")) != -1) while((c = getopt(argc, argv,"hesamui:p:c:w:l:d:")) != -1)
@ -355,7 +355,7 @@ int InitRetroShare(int argcIgnored, char **argvIgnored, RsInit *config)
// set the default Debug Level... // set the default Debug Level...
if (config->haveDebugLevel) if (config->haveDebugLevel)
{ {
if ((config->debugLevel > 0) && if ((config->debugLevel > 0) &&
(config->debugLevel <= PQL_DEBUG_ALL)) (config->debugLevel <= PQL_DEBUG_ALL))
{ {
std::cerr << "Setting Debug Level to: "; std::cerr << "Setting Debug Level to: ";
@ -372,7 +372,7 @@ int InitRetroShare(int argcIgnored, char **argvIgnored, RsInit *config)
} }
// set the debug file. // set the debug file.
if (config->haveLogFile) if (config->haveLogFile)
{ {
setDebugFile(config->logfname); setDebugFile(config->logfname);
} }
@ -440,10 +440,10 @@ int InitRetroShare(int argcIgnored, char **argvIgnored, RsInit *config)
/**************** PQI_USE_XPGP ******************/ /**************** PQI_USE_XPGP ******************/
#if defined(PQI_USE_XPGP) #if defined(PQI_USE_XPGP)
/* do a null init to allow the SSL libray to startup! */ /* do a null init to allow the SSL libray to startup! */
getAuthMgr() -> InitAuth(NULL, NULL, NULL); getAuthMgr() -> InitAuth(NULL, NULL, NULL);
#else /* X509 Certificates */ #else /* X509 Certificates */
/**************** PQI_USE_XPGP ******************/ /**************** PQI_USE_XPGP ******************/
getAuthMgr() -> InitAuth(NULL, NULL, NULL, NULL); getAuthMgr() -> InitAuth(NULL, NULL, NULL, NULL);
#endif /* X509 Certificates */ #endif /* X509 Certificates */
/**************** PQI_USE_XPGP ******************/ /**************** PQI_USE_XPGP ******************/
@ -463,7 +463,7 @@ int InitRetroShare(int argcIgnored, char **argvIgnored, RsInit *config)
} }
/* /*
* The Real RetroShare Startup Function. * The Real RetroShare Startup Function.
*/ */
@ -476,7 +476,7 @@ int RsServer::StartupRetroShare(RsInit *config)
/* (1) Load up own certificate (DONE ALREADY) - just CHECK */ /* (1) Load up own certificate (DONE ALREADY) - just CHECK */
/**************************************************************************/ /**************************************************************************/
mAuthMgr = getAuthMgr(); mAuthMgr = getAuthMgr();
/**************** PQI_USE_XPGP ******************/ /**************** PQI_USE_XPGP ******************/
#if defined(PQI_USE_XPGP) #if defined(PQI_USE_XPGP)
@ -516,7 +516,7 @@ int RsServer::StartupRetroShare(RsInit *config)
/**************************************************************************/ /**************************************************************************/
// Load up Certificates, and Old Configuration (if present) // Load up Certificates, and Old Configuration (if present)
std::string certConfigFile = config->basedir.c_str(); std::string certConfigFile = config->basedir.c_str();
std::string certNeighDir = config->basedir.c_str(); std::string certNeighDir = config->basedir.c_str();
std::string emergencySaveDir = config->basedir.c_str(); std::string emergencySaveDir = config->basedir.c_str();
@ -590,7 +590,7 @@ int RsServer::StartupRetroShare(RsInit *config)
std::string remotecachedir = config_dir + "/cache/remote"; std::string remotecachedir = config_dir + "/cache/remote";
mRanking = new p3Ranking(mConnMgr, RS_SERVICE_TYPE_RANK, /* declaration of cache enable service rank */ mRanking = new p3Ranking(mConnMgr, RS_SERVICE_TYPE_RANK, /* declaration of cache enable service rank */
mCacheStrapper, mCacheTransfer, mCacheStrapper, mCacheTransfer,
localcachedir, remotecachedir, 3600 * 24 * 30 * 6); // 6 Months localcachedir, remotecachedir, 3600 * 24 * 30 * 6); // 6 Months
CachePair cp(mRanking, mRanking, CacheId(RS_SERVICE_TYPE_RANK, 0)); CachePair cp(mRanking, mRanking, CacheId(RS_SERVICE_TYPE_RANK, 0));
@ -601,37 +601,38 @@ int RsServer::StartupRetroShare(RsInit *config)
pqih -> addService(gameLauncher); pqih -> addService(gameLauncher);
p3PhotoService *photoService = new p3PhotoService(RS_SERVICE_TYPE_PHOTO, /* .... for photo service */ p3PhotoService *photoService = new p3PhotoService(RS_SERVICE_TYPE_PHOTO, /* .... for photo service */
mCacheStrapper, mCacheTransfer, mCacheStrapper, mCacheTransfer,
localcachedir, remotecachedir); localcachedir, remotecachedir);
CachePair cp2(photoService, photoService, CacheId(RS_SERVICE_TYPE_PHOTO, 0)); CachePair cp2(photoService, photoService, CacheId(RS_SERVICE_TYPE_PHOTO, 0));
mCacheStrapper -> addCachePair(cp2); mCacheStrapper -> addCachePair(cp2);
mQblog = new p3Qblog(mConnMgr, RS_SERVICE_TYPE_QBLOG, /* ...then for Qblog */ mQblog = new p3Qblog(mConnMgr, RS_SERVICE_TYPE_QBLOG, /* ...then for Qblog */
mCacheStrapper, mCacheTransfer, mCacheStrapper, mCacheTransfer,
localcachedir, remotecachedir, 3600 * 24 * 30 * 6); // 6 Months localcachedir, remotecachedir, 3600 * 24 * 30 * 6); // 6 Months
CachePair cp3(mQblog, mQblog, CacheId(RS_SERVICE_TYPE_QBLOG, 0)); CachePair cp3(mQblog, mQblog, CacheId(RS_SERVICE_TYPE_QBLOG, 0));
mCacheStrapper -> addCachePair(cp3); mCacheStrapper -> addCachePair(cp3);
p3Forums *mForums = new p3Forums(RS_SERVICE_TYPE_FORUM, p3Forums *mForums = new p3Forums(RS_SERVICE_TYPE_FORUM,
mCacheStrapper, mCacheTransfer, mCacheStrapper, mCacheTransfer,
localcachedir, remotecachedir); localcachedir, remotecachedir);
CachePair cp4(mForums, mForums, CacheId(RS_SERVICE_TYPE_FORUM, 0)); CachePair cp4(mForums, mForums, CacheId(RS_SERVICE_TYPE_FORUM, 0));
mCacheStrapper -> addCachePair(cp4); mCacheStrapper -> addCachePair(cp4);
pqih -> addService(mForums); /* This must be also ticked as a service */ pqih -> addService(mForums); /* This must be also ticked as a service */
p3Channels *mChannels = new p3Channels(RS_SERVICE_TYPE_CHANNEL, p3Channels *mChannels = new p3Channels(RS_SERVICE_TYPE_CHANNEL,
mCacheStrapper, mCacheTransfer, mCacheStrapper, mCacheTransfer,
localcachedir, remotecachedir, localcachedir); localcachedir, remotecachedir, localcachedir);
CachePair cp5(mChannels, mChannels, CacheId(RS_SERVICE_TYPE_CHANNEL, 0)); CachePair cp5(mChannels, mChannels, CacheId(RS_SERVICE_TYPE_CHANNEL, 0));
mCacheStrapper -> addCachePair(cp5); mCacheStrapper -> addCachePair(cp5);
pqih -> addService(mChannels); /* This must be also ticked as a service */ pqih -> addService(mChannels); /* This must be also ticked as a service */
#else #else
mQblog = NULL; //mQblog = NULL;
//mForums = NULL; //mForums = NULL;
#endif #endif
@ -650,7 +651,7 @@ int RsServer::StartupRetroShare(RsInit *config)
/**************************************************************************/ /**************************************************************************/
mConfigMgr->addConfiguration("server.cfg", server); mConfigMgr->addConfiguration("server.cfg", server);
mConfigMgr->addConfiguration("peers.cfg", mConnMgr); mConfigMgr->addConfiguration("peers.cfg", mConnMgr);
mConfigMgr->addConfiguration("general.cfg", mGeneralConfig); mConfigMgr->addConfiguration("general.cfg", mGeneralConfig);
mConfigMgr->addConfiguration("msgs.cfg", msgSrv); mConfigMgr->addConfiguration("msgs.cfg", msgSrv);
@ -797,7 +798,7 @@ int RsServer::StartupRetroShare(RsInit *config)
rsChannels = mChannels; rsChannels = mChannels;
rsStatus = new p3Status(); rsStatus = new p3Status();
rsQblog = new p3Blog(mQblog); rsQblog = new p3Blog(mQblog);
#else #else
rsGameLauncher = NULL; rsGameLauncher = NULL;
rsPhoto = NULL; rsPhoto = NULL;
@ -856,14 +857,14 @@ int LoadCertificates(RsInit *config, bool autoLoginNT)
/**************** PQI_USE_XPGP ******************/ /**************** PQI_USE_XPGP ******************/
#if defined(PQI_USE_XPGP) #if defined(PQI_USE_XPGP)
if (0 < authMgr -> InitAuth(config->load_cert.c_str(), if (0 < authMgr -> InitAuth(config->load_cert.c_str(),
config->load_key.c_str(), config->load_key.c_str(),
config->passwd.c_str())) config->passwd.c_str()))
#else /* X509 Certificates */ #else /* X509 Certificates */
/**************** PQI_USE_XPGP ******************/ /**************** PQI_USE_XPGP ******************/
if (0 < authMgr -> InitAuth(config->load_cert.c_str(), if (0 < authMgr -> InitAuth(config->load_cert.c_str(),
config->load_key.c_str(), config->load_key.c_str(),
ca_loc.c_str(), ca_loc.c_str(),
config->passwd.c_str())) config->passwd.c_str()))
#endif /* X509 Certificates */ #endif /* X509 Certificates */
/**************** PQI_USE_XPGP ******************/ /**************** PQI_USE_XPGP ******************/
@ -936,12 +937,12 @@ bool LoadPassword(RsInit *config, std::string passwd)
* (2) returns false if fails, with error msg to errString. * (2) returns false if fails, with error msg to errString.
*/ */
bool RsGenerateCertificate(RsInit *config, bool RsGenerateCertificate(RsInit *config,
std::string name, std::string name,
std::string org, std::string org,
std::string loc, std::string loc,
std::string country, std::string country,
std::string passwd, std::string passwd,
std::string &errString) std::string &errString)
{ {
// In the XPGP world this is easy... // In the XPGP world this is easy...
@ -951,13 +952,13 @@ bool RsGenerateCertificate(RsInit *config,
// then load as if they had entered a passwd. // then load as if they had entered a passwd.
// check password. // check password.
if (passwd.length() < 4) if (passwd.length() < 4)
{ {
errString = "Password is Unsatisfactory (must be 4+ chars)"; errString = "Password is Unsatisfactory (must be 4+ chars)";
return false; return false;
} }
if (name.length() < 3) if (name.length() < 3)
{ {
errString = "Name is too short (must be 3+ chars)"; errString = "Name is too short (must be 3+ chars)";
return false; return false;
@ -968,7 +969,7 @@ bool RsGenerateCertificate(RsInit *config,
// Create the filename. // Create the filename.
std::string basename = config->basedir + config->dirSeperator; std::string basename = config->basedir + config->dirSeperator;
basename += configKeyDir + config->dirSeperator; basename += configKeyDir + config->dirSeperator;
basename += "user"; basename += "user";
std::string key_name = basename + "_pk.pem"; std::string key_name = basename + "_pk.pem";
std::string cert_name = basename + "_cert.pem"; std::string cert_name = basename + "_cert.pem";
@ -976,13 +977,13 @@ bool RsGenerateCertificate(RsInit *config,
/**************** PQI_USE_XPGP ******************/ /**************** PQI_USE_XPGP ******************/
#if defined(PQI_USE_XPGP) #if defined(PQI_USE_XPGP)
if (!generate_xpgp(cert_name.c_str(), key_name.c_str(), if (!generate_xpgp(cert_name.c_str(), key_name.c_str(),
passwd.c_str(), passwd.c_str(),
name.c_str(), name.c_str(),
"", //ui -> gen_email -> value(), "", //ui -> gen_email -> value(),
org.c_str(), org.c_str(),
loc.c_str(), loc.c_str(),
"", //ui -> gen_state -> value(), "", //ui -> gen_state -> value(),
country.c_str(), country.c_str(),
nbits)) nbits))
#else /* X509 Certificates */ #else /* X509 Certificates */
@ -995,7 +996,7 @@ bool RsGenerateCertificate(RsInit *config,
return false; return false;
} }
/* set the load passwd to the gen version /* set the load passwd to the gen version
* and try to load it! * and try to load it!
*/ */
@ -1022,7 +1023,7 @@ bool RsGenerateCertificate(RsInit *config,
void load_check_basedir(RsInit *config) void load_check_basedir(RsInit *config)
{ {
// get the default configuration location. // get the default configuration location.
if (config->basedir == "") if (config->basedir == "")
{ {
// if unix. homedir + /.pqiPGPrc // if unix. homedir + /.pqiPGPrc
@ -1122,7 +1123,7 @@ void load_check_basedir(RsInit *config)
} }
// have a config directories. // have a config directories.
// Check for config file. // Check for config file.
std::string initfile = config->basedir + config->dirSeperator; std::string initfile = config->basedir + config->dirSeperator;
initfile += configInitFile; initfile += configInitFile;
@ -1149,7 +1150,7 @@ void load_check_basedir(RsInit *config)
fclose(ifd); fclose(ifd);
} }
// we have now // we have now
// 1) checked or created the config dirs. // 1) checked or created the config dirs.
// 2) loaded the config_init file - if possible. // 2) loaded the config_init file - if possible.
return; return;
@ -1205,7 +1206,7 @@ int check_create_directory(std::string dir)
std::cerr << "check_create_directory()"; std::cerr << "check_create_directory()";
std::cerr <<std::endl<< "\tcreated:" <<dir<<std::endl; std::cerr <<std::endl<< "\tcreated:" <<dir<<std::endl;
} }
else if (!S_ISDIR(buf.st_mode)) else if (!S_ISDIR(buf.st_mode))
{ {
// Some other type - error. // Some other type - error.
@ -1297,7 +1298,7 @@ typedef struct _CRYPTPROTECT_PROMPTSTRUCT {
DWORD dwPromptFlags; DWORD dwPromptFlags;
HWND hwndApp; HWND hwndApp;
LPCWSTR szPrompt; LPCWSTR szPrompt;
} CRYPTPROTECT_PROMPTSTRUCT, } CRYPTPROTECT_PROMPTSTRUCT,
*PCRYPTPROTECT_PROMPTSTRUCT; *PCRYPTPROTECT_PROMPTSTRUCT;
/* definitions for the two functions */ /* definitions for the two functions */
@ -1309,7 +1310,7 @@ extern BOOL WINAPI CryptProtectData(
PVOID pvReserved, PVOID pvReserved,
/* PVOID prompt, */ /* PVOID prompt, */
/* CRYPTPROTECT_PROMPTSTRUCT* pPromptStruct, */ /* CRYPTPROTECT_PROMPTSTRUCT* pPromptStruct, */
CRYPTPROTECT_PROMPTSTRUCT* pPromptStruct, CRYPTPROTECT_PROMPTSTRUCT* pPromptStruct,
DWORD dwFlags, DWORD dwFlags,
DATA_BLOB* pDataOut DATA_BLOB* pDataOut
); );
@ -1322,7 +1323,7 @@ extern BOOL WINAPI CryptUnprotectData(
PVOID pvReserved, PVOID pvReserved,
/* PVOID prompt, */ /* PVOID prompt, */
/* CRYPTPROTECT_PROMPTSTRUCT* pPromptStruct, */ /* CRYPTPROTECT_PROMPTSTRUCT* pPromptStruct, */
CRYPTPROTECT_PROMPTSTRUCT* pPromptStruct, CRYPTPROTECT_PROMPTSTRUCT* pPromptStruct,
DWORD dwFlags, DWORD dwFlags,
DATA_BLOB* pDataOut DATA_BLOB* pDataOut
); );
@ -1354,13 +1355,13 @@ bool RsStoreAutoLogin(RsInit *config)
DWORD cbDataInput = strlen((char *)pbDataInput)+1; DWORD cbDataInput = strlen((char *)pbDataInput)+1;
BYTE *pbDataEnt =(BYTE *) strdup(entropy.c_str()); BYTE *pbDataEnt =(BYTE *) strdup(entropy.c_str());
DWORD cbDataEnt = strlen((char *)pbDataEnt)+1; DWORD cbDataEnt = strlen((char *)pbDataEnt)+1;
DataIn.pbData = pbDataInput; DataIn.pbData = pbDataInput;
DataIn.cbData = cbDataInput; DataIn.cbData = cbDataInput;
DataEnt.pbData = pbDataEnt; DataEnt.pbData = pbDataEnt;
DataEnt.cbData = cbDataEnt; DataEnt.cbData = cbDataEnt;
LPWSTR pDescrOut = NULL; LPWSTR pDescrOut = NULL;
CRYPTPROTECT_PROMPTSTRUCT prom; CRYPTPROTECT_PROMPTSTRUCT prom;
prom.cbSize = sizeof(prom); prom.cbSize = sizeof(prom);
prom.dwPromptFlags = 0; prom.dwPromptFlags = 0;
@ -1407,7 +1408,7 @@ bool RsStoreAutoLogin(RsInit *config)
{ {
fwrite(DataOut.pbData, 1, DataOut.cbData, fp); fwrite(DataOut.pbData, 1, DataOut.cbData, fp);
fclose(fp); fclose(fp);
std::cerr << "AutoLogin Data saved: "; std::cerr << "AutoLogin Data saved: ";
std::cerr << std::endl; std::cerr << std::endl;
} }
@ -1459,7 +1460,7 @@ bool RsTryAutoLogin(RsInit *config)
BYTE *pbDataEnt =(BYTE *) strdup(entropy.c_str()); BYTE *pbDataEnt =(BYTE *) strdup(entropy.c_str());
DWORD cbDataEnt = strlen((char *)pbDataEnt)+1; DWORD cbDataEnt = strlen((char *)pbDataEnt)+1;
DataEnt.pbData = pbDataEnt; DataEnt.pbData = pbDataEnt;
DataEnt.cbData = cbDataEnt; DataEnt.cbData = cbDataEnt;
char *dataptr = NULL; char *dataptr = NULL;
@ -1497,11 +1498,11 @@ bool RsTryAutoLogin(RsInit *config)
BYTE *pbDataInput =(BYTE *) dataptr; BYTE *pbDataInput =(BYTE *) dataptr;
DWORD cbDataInput = datalen; DWORD cbDataInput = datalen;
DataIn.pbData = pbDataInput; DataIn.pbData = pbDataInput;
DataIn.cbData = cbDataInput; DataIn.cbData = cbDataInput;
CRYPTPROTECT_PROMPTSTRUCT prom; CRYPTPROTECT_PROMPTSTRUCT prom;
prom.cbSize = sizeof(prom); prom.cbSize = sizeof(prom);
prom.dwPromptFlags = 0; prom.dwPromptFlags = 0;
@ -1509,7 +1510,7 @@ bool RsTryAutoLogin(RsInit *config)
bool isDecrypt = CryptUnprotectData( bool isDecrypt = CryptUnprotectData(
&DataIn, &DataIn,
NULL, NULL,
&DataEnt, /* entropy.c_str(), */ &DataEnt, /* entropy.c_str(), */
NULL, // Reserved NULL, // Reserved
&prom, // Opt. Prompt &prom, // Opt. Prompt
@ -1568,7 +1569,7 @@ bool RsClearAutoLogin(std::string basedir)
{ {
fwrite(" ", 1, 1, fp); fwrite(" ", 1, 1, fp);
fclose(fp); fclose(fp);
std::cerr << "AutoLogin Data cleared! "; std::cerr << "AutoLogin Data cleared! ";
std::cerr << std::endl; std::cerr << std::endl;
return true; return true;

View file

@ -24,42 +24,41 @@
*/ */
#include "serialiser/rsqblogitems.h" #include "serialiser/rsqblogitems.h"
#include "services/p3Qblog.h" #include "p3Qblog.h"
#include <utility> #include <utility>
#include <ctime> #include <ctime>
#include <iomanip> #include <iomanip>
#include "pqi/pqibin.h" #include "pqi/pqibin.h"
#include "pqi/p3authmgr.h" #include "pqi/p3authmgr.h"
const uint32_t RANK_MAX_FWD_OFFSET = (60 * 60 * 24 * 2); /* 2 Days */ const uint32_t BLOG_MAX_FWD_OFFSET = (60 * 60 * 24 * 2); /* 2 Days */
const uint32_t FRIEND_QBLOG_REPOST_PERIOD = 60; /* every minute for testing */ const uint32_t FRIEND_QBLOG_REPOST_PERIOD = 60; /* every minute for testing */
/****
* #define QBLOG_DEBUG 1
****/
p3Qblog::p3Qblog(p3ConnectMgr *connMgr, #define QBLOG_DEBUG 1
p3Qblog::p3Qblog(p3ConnectMgr *connMgr,
uint16_t type, CacheStrapper *cs, CacheTransfer *cft, uint16_t type, CacheStrapper *cs, CacheTransfer *cft,
std::string sourcedir, std::string storedir, std::string sourcedir, std::string storedir,
uint32_t storePeriod) uint32_t storePeriod)
:CacheSource(type, true, cs, sourcedir), :CacheSource(type, true, cs, sourcedir),
CacheStore(type, true, cs, cft, storedir), CacheStore(type, true, cs, cft, storedir),
mConnMgr(connMgr), mFilterSwitch(false), mConnMgr(connMgr),
mStorePeriod(storePeriod), mPostsUpdated(false), mProfileUpdated(false) mStorePeriod(storePeriod), mPostsUpdated(false), mProfileUpdated(false)
{ {
{ {
RsStackMutex stack(mBlogMtx); RsStackMutex stack(mBlogMtx);
mOwnId = mConnMgr->getOwnId(); // get your own usr Id mOwnId = mConnMgr->getOwnId(); // get your own usr Id
loadDummy(); // load dummy data loadDummy(); // load dummy data
#ifdef QBLOG_DEBUG #ifdef QBLOG_DEBUG
/*if(!ok) /*if(!ok)
std::cerr << "initialization failed: could not retrieve friend list"; */ std::cerr << "initialization failed: could not retrieve friend list"; */
#endif #endif
} }
return; return;
} }
@ -67,7 +66,7 @@ std::ostream &operator<<(std::ostream& out, const std::wstring wstr)
{ {
std::string str(wstr.begin(), wstr.end()); std::string str(wstr.begin(), wstr.end());
out << str; out << str;
return out; return out;
} }
@ -76,7 +75,7 @@ bool p3Qblog::loadLocalCache(const CacheData &data)
std::string filename = data.path + '/' + data.name; std::string filename = data.path + '/' + data.name;
std::string hash = data.hash; std::string hash = data.hash;
std::string source = data.pid; std::string source = data.pid;
#ifdef QBLOG_DEBUG #ifdef QBLOG_DEBUG
std::cerr << "p3Ranking::loadLocalCache()"; std::cerr << "p3Ranking::loadLocalCache()";
std::cerr << std::endl; std::cerr << std::endl;
@ -91,7 +90,7 @@ bool p3Qblog::loadLocalCache(const CacheData &data)
#endif #endif
loadBlogFile(filename, source); loadBlogFile(filename, source);
{ {
RsStackMutex stack(mBlogMtx); RsStackMutex stack(mBlogMtx);
mPostsUpdated = true; // there is nothing to tick/repost (i.e. comes from cache) mPostsUpdated = true; // there is nothing to tick/repost (i.e. comes from cache)
@ -101,7 +100,7 @@ bool p3Qblog::loadLocalCache(const CacheData &data)
{ {
refreshCache(data); refreshCache(data);
} }
return true; return true;
} }
@ -129,7 +128,7 @@ int p3Qblog::loadCache(const CacheData &data)
CacheStore::lockData(); /***** LOCK ****/ CacheStore::lockData(); /***** LOCK ****/
locked_storeCacheEntry(data); locked_storeCacheEntry(data);
CacheStore::unlockData(); /***** UNLOCK ****/ CacheStore::unlockData(); /***** UNLOCK ****/
return 1; return 1;
@ -140,37 +139,37 @@ bool p3Qblog::loadBlogFile(std::string filename, std::string src)
/* create the serialiser to load info */ /* create the serialiser to load info */
RsSerialiser *rsSerialiser = new RsSerialiser(); RsSerialiser *rsSerialiser = new RsSerialiser();
rsSerialiser->addSerialType(new RsQblogMsgSerialiser()); rsSerialiser->addSerialType(new RsQblogMsgSerialiser());
uint32_t bioflags = BIN_FLAGS_HASH_DATA | BIN_FLAGS_READABLE; uint32_t bioflags = BIN_FLAGS_HASH_DATA | BIN_FLAGS_READABLE;
BinInterface *bio = new BinFileInterface(filename.c_str(), bioflags); BinInterface *bio = new BinFileInterface(filename.c_str(), bioflags);
pqistreamer *stream = new pqistreamer(rsSerialiser, src, bio, 0); pqistreamer *stream = new pqistreamer(rsSerialiser, src, bio, 0);
#ifdef QBLOG_DEBUG #ifdef QBLOG_DEBUG
std::cerr << "p3Qblog::loadBlogFile()"; std::cerr << "p3Qblog::loadBlogFile()";
std::cerr << std::endl; std::cerr << std::endl;
std::cerr << "\tSource: " << src; std::cerr << "\tSource: " << src;
std::cerr << std::endl; std::cerr << std::endl;
std::cerr << "\tFilename: " << filename; std::cerr << "\tFilename: " << filename;
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
/* will load file info to these items */ /* will load file info to these items */
RsItem *item; RsItem *item;
RsQblogMsg *newBlog; RsQblogMsg *newBlog;
stream->tick(); // tick to read stream->tick(); // tick to read
time_t now = time(NULL); time_t now = time(NULL);
time_t min, max; time_t min, max;
{ /********** STACK LOCKED MTX ******/ { /********** STACK LOCKED MTX ******/
RsStackMutex stack(mBlogMtx); RsStackMutex stack(mBlogMtx);
min = now - mStorePeriod; min = now - mStorePeriod;
max = now + RANK_MAX_FWD_OFFSET; max = now + BLOG_MAX_FWD_OFFSET;
} /********** STACK LOCKED MTX ******/ } /********** STACK LOCKED MTX ******/
while(NULL != (item = stream->GetItem())) while(NULL != (item = stream->GetItem()))
{ {
#ifdef QBLOG_DEBUG #ifdef QBLOG_DEBUG
@ -179,7 +178,7 @@ bool p3Qblog::loadBlogFile(std::string filename, std::string src)
item->print(std::cerr, 10); item->print(std::cerr, 10);
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
if (NULL == (newBlog = dynamic_cast<RsQblogMsg *>(item))) if (NULL == (newBlog = dynamic_cast<RsQblogMsg *>(item)))
{ {
#ifdef QBLOG_DEBUG #ifdef QBLOG_DEBUG
@ -189,8 +188,8 @@ bool p3Qblog::loadBlogFile(std::string filename, std::string src)
delete item; delete item;
} }
/* check timestamp */ /* check timestamp: delete if here longer than store period or more than two days */
else if (((time_t) newBlog->sendTime < min) || else if (((time_t) newBlog->sendTime < min) ||
((time_t) newBlog->sendTime > max)) ((time_t) newBlog->sendTime > max))
{ {
#ifdef QBLOG_DEBUG #ifdef QBLOG_DEBUG
@ -209,10 +208,10 @@ bool p3Qblog::loadBlogFile(std::string filename, std::string src)
addBlog(newBlog); // add received blog to list addBlog(newBlog); // add received blog to list
} }
stream->tick(); // tick to read stream->tick(); // tick to read
} }
delete stream; // stream finished with/return resource delete stream; // stream finished with/return resource
return true; return true;
} }
@ -225,12 +224,12 @@ bool p3Qblog::addBlog(RsQblogMsg *newBlog)
newBlog->print(std::cerr, 10); // check whats in the blog item newBlog->print(std::cerr, 10); // check whats in the blog item
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
{ {
RsStackMutex Stack(mBlogMtx); RsStackMutex Stack(mBlogMtx);
mUsrBlogSet[newBlog->PeerId()].insert(std::make_pair(newBlog->sendTime, newBlog->message)); mUsrBlogSet[newBlog->PeerId()].insert(std::make_pair(newBlog->sendTime, newBlog->message));
#ifdef QBLOG_DEBUG #ifdef QBLOG_DEBUG
std::cerr << "p3Qblog::addBlog()"; std::cerr << "p3Qblog::addBlog()";
std::cerr << std::endl; std::cerr << std::endl;
@ -240,16 +239,15 @@ bool p3Qblog::addBlog(RsQblogMsg *newBlog)
std::cerr << std::endl; std::cerr << std::endl;
std::cerr << "\tmUsrBlogSet: blog" << newBlog->message; std::cerr << "\tmUsrBlogSet: blog" << newBlog->message;
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
mPostsUpdated = false; // need to figure how this should work/ wherre this should be placed mPostsUpdated = false; // need to figure how this should work/ where this should be placed
} }
return true; return true;
} }
bool p3Qblog::postBlogs(void) bool p3Qblog::postBlogs(void)
{ {
#ifdef QBLOG_DEBUG #ifdef QBLOG_DEBUG
std::cerr << "p3Qblog::postBlogs()"; std::cerr << "p3Qblog::postBlogs()";
std::cerr << std::endl; std::cerr << std::endl;
@ -258,32 +256,32 @@ bool p3Qblog::postBlogs(void)
std::string path = CacheSource::getCacheDir(); std::string path = CacheSource::getCacheDir();
std::ostringstream out; std::ostringstream out;
uint16_t subid = 1; uint16_t subid = 1;
out << "qblogs-" << time(NULL) << ".rsqb"; // create blog file name based on time posted out << "qblogs-" << time(NULL) << ".rsqb"; // create blog file name based on time posted
/* determine filename */ /* determine filename */
std::string tmpname = out.str(); std::string tmpname = out.str();
std::string fname = path + "/" + tmpname; std::string fname = path + "/" + tmpname;
#ifdef RANK_DEBUG #ifdef QBLOG_DEBUG
std::cerr << "p3Ranking::publishMsgs() Storing to: " << fname; std::cerr << "p3Qblog::postBlogs() Storing to: " << fname;
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
RsSerialiser *rsSerialiser = new RsSerialiser(); RsSerialiser *rsSerialiser = new RsSerialiser();
rsSerialiser->addSerialType(new RsQblogMsgSerialiser()); rsSerialiser->addSerialType(new RsQblogMsgSerialiser());
uint32_t bioflags = BIN_FLAGS_HASH_DATA | BIN_FLAGS_WRITEABLE; uint32_t bioflags = BIN_FLAGS_HASH_DATA | BIN_FLAGS_WRITEABLE;
BinInterface *bio = new BinFileInterface(fname.c_str(), bioflags); BinInterface *bio = new BinFileInterface(fname.c_str(), bioflags);
pqistreamer *stream = new pqistreamer(rsSerialiser, mOwnId, bio, pqistreamer *stream = new pqistreamer(rsSerialiser, mOwnId, bio,
BIN_FLAGS_NO_DELETE); BIN_FLAGS_NO_DELETE);
{ {
RsStackMutex stack(mBlogMtx); /********** STACK LOCKED MTX ******/ RsStackMutex stack(mBlogMtx); /********** STACK LOCKED MTX ******/
/* iterate through list */ /* iterate through list */
std::list<RsQblogMsg*>::iterator it; std::list<RsQblogMsg*>::iterator it;
for(it = mBlogs.begin(); it != mBlogs.end(); it++) for(it = mBlogs.begin(); it != mBlogs.end(); it++)
{ {
/* only post own blogs */ /* only post own blogs */
@ -291,14 +289,14 @@ bool p3Qblog::postBlogs(void)
{ {
/*write to serialiser*/ /*write to serialiser*/
RsItem *item = *it; RsItem *item = *it;
#ifdef QBLOG_DEBUG #ifdef QBLOG_DEBUG
std::cerr << "p3Qblog::postBlogs() Storing Item:"; std::cerr << "p3Qblog::postBlogs() Storing Item:";
std::cerr << std::endl; std::cerr << std::endl;
item->print(std::cerr, 10); item->print(std::cerr, 10);
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
stream->SendItem(item); stream->SendItem(item);
stream->tick(); /* tick to write */ stream->tick(); /* tick to write */
} }
@ -308,34 +306,34 @@ bool p3Qblog::postBlogs(void)
std::cerr << "p3Ranking::postBlogs() Skipping friend blog items:"; std::cerr << "p3Ranking::postBlogs() Skipping friend blog items:";
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
continue; continue;
} }
} }
} }
stream->tick(); /* Tick for final write! */ stream->tick(); /* Tick for final write! */
/* flag as new info */ /* flag as new info */
CacheData data; CacheData data;
{ /********** STACK LOCKED MTX ******/ { /********** STACK LOCKED MTX ******/
RsStackMutex stack(mBlogMtx); RsStackMutex stack(mBlogMtx);
data.pid = mOwnId; data.pid = mOwnId;
} /********** STACK LOCKED MTX ******/ } /********** STACK LOCKED MTX ******/
data.cid = CacheId(CacheSource::getCacheType(), subid); data.cid = CacheId(CacheSource::getCacheType(), subid);
data.path = path; data.path = path;
data.name = tmpname; data.name = tmpname;
data.hash = bio->gethash(); data.hash = bio->gethash();
data.size = bio->bytecount(); data.size = bio->bytecount();
data.recvd = time(NULL); data.recvd = time(NULL);
#ifdef RANK_DEBUG #ifdef QBLOG_DEBUG
std::cerr << "p3Ranking::postBlogs() refreshing Cache"; std::cerr << "p3Ranking::postBlogs() refreshing Cache";
std::cerr << std::endl; std::cerr << std::endl;
std::cerr << "\tCache Path: " << data.path; std::cerr << "\tCache Path: " << data.path;
@ -347,137 +345,64 @@ bool p3Qblog::postBlogs(void)
std::cerr << "\tCache Size: " << data.size; std::cerr << "\tCache Size: " << data.size;
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
if(data.size > 0) /* don't refresh zero sized caches */ if(data.size > 0) /* don't refresh zero sized caches */
{ {
refreshCache(data); refreshCache(data);
} }
delete stream; delete stream;
return true; return true;
} }
p3Qblog::~p3Qblog() p3Qblog::~p3Qblog()
{ {
return; return;
} }
bool p3Qblog::getFilterSwitch(void)
{
{
RsStackMutex stack(mBlogMtx); // might be pointless
return mFilterSwitch;
}
}
bool p3Qblog::setFilterSwitch(bool &filterSwitch)
{
{
RsStackMutex stack(mBlogMtx);
mFilterSwitch = filterSwitch;
#ifdef QBLOG_DEBUG
std::cerr << "p3Qblog::setFilterSwitch() " << mFilterSwitch;
std::cerr << std::endl;
#endif
}
return true;
}
bool p3Qblog::removeFiltFriend(std::string &usrId)
{
std::list<std::string>::iterator it;
{
RsStackMutex stack(mBlogMtx);
/* search through list to remove friend */
for(it = mFilterList.begin(); it != mFilterList.end(); it++)
{
if(it->compare(usrId))
{
#ifdef QBLOG_DEBUG
std::cerr << "p3Qblog::removeFilterFriend() it " << *it;
std::cerr << std::endl;
#endif
mFilterList.erase(it); // remove friend from list
return true;
}
}
}
#ifdef QBLOG_DEBUG
std::cerr << "usr could not be found!" << std::endl;
#endif
return false; // could not find friend
}
bool p3Qblog::addToFilter(std::string& usrId)
{
{
RsStackMutex stack(mBlogMtx);
std::list<std::string>::iterator it;
/* search through list in case friend already exist */
for(it = mFilterList.begin(); it != mFilterList.end(); it++)
{
if(it->compare(usrId))
{
#ifdef QBLOG_DEBUG
std::cerr << "usr already in list!" << *it;
std::cerr << std::endl;
#endif
return false; // user already in list, not added
}
}
mFilterList.push_back(usrId);
}
return true;
}
bool p3Qblog::getBlogs(std::map< std::string, std::multimap<long int, std::wstring> > &blogs) bool p3Qblog::getBlogs(std::map< std::string, std::multimap<long int, std::wstring> > &blogs)
{ {
{ {
RsStackMutex stack(mBlogMtx); RsStackMutex stack(mBlogMtx);
if(mUsrBlogSet.empty()) // return error blogs are empty if(mUsrBlogSet.empty()) // return error blogs are empty
{ {
std::cerr << "usr blog set empty!" << std::endl; std::cerr << "usr blog set empty!" << std::endl;
return false; return false;
} }
blogs = mUsrBlogSet; blogs = mUsrBlogSet;
return true;
#ifdef QBOG_DEBUG #ifdef QBLOG_DEBUG
std::cerr << "p3Qblog::getBlogs() number of blogs: " << mUsrBlogSet.size(); std::cerr << "p3Qblog::getBlogs() number of blogs: " << mUsrBlogSet.size();
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
} }
return true;
} }
bool p3Qblog::sendBlog(const std::wstring &msg) bool p3Qblog::sendBlog(const std::wstring &msg)
{ {
time_t blogTimeStamp; time_t blogTimeStamp;
{ {
RsStackMutex stack(mBlogMtx); RsStackMutex stack(mBlogMtx);
mUsrBlogSet[mOwnId].insert(std::make_pair(blogTimeStamp, msg)); mUsrBlogSet[mOwnId].insert(std::make_pair(blogTimeStamp, msg));
RsQblogMsg *blog = new RsQblogMsg(); RsQblogMsg *blog = new RsQblogMsg();
blog->clear(); blog->clear();
blog->sendTime = blogTimeStamp; blog->sendTime = blogTimeStamp;
blog->message = msg; blog->message = msg;
#ifdef QBLOG_DEBUG #ifdef QBLOG_DEBUG
std::cerr << "p3Qblog::sendBlogFile()"; std::cerr << "p3Qblog::sendBlogFile()";
std::cerr << std::endl; std::cerr << std::endl;
@ -486,45 +411,12 @@ bool p3Qblog::sendBlog(const std::wstring &msg)
std::cerr << "\tblogItem->message" << blog->message; std::cerr << "\tblogItem->message" << blog->message;
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
mBlogs.push_back(blog); mBlogs.push_back(blog);
} }
return true; return true;
} }
bool p3Qblog::getPeerProfile(std::string id, std::list< std::pair<std::wstring, std::wstring> > &entries)
{
// TODO
return true;
}
bool p3Qblog::setProfile(std::pair<std::wstring, std::wstring> entry)
{
//TODO
return true;
}
bool p3Qblog::setFavorites(FileInfo favFile)
{
//TODO
return true;
}
bool p3Qblog::getPeerLatestBlog(std::string id, uint32_t &ts, std::wstring &post)
{
//TODO
return true;
}
bool p3Qblog::getPeerFavourites(std::string id, std::list<FileInfo> &favs)
{
//TODO
return true;
}
void p3Qblog::loadDummy(void) void p3Qblog::loadDummy(void)
{ {
std::list<std::string> peers; std::list<std::string> peers;
@ -535,40 +427,40 @@ void p3Qblog::loadDummy(void)
//for(int i = 0; i < 50; i++) //for(int i = 0; i < 50; i++)
// std::cerr << "nothing in peer list!!!" << std::endl; // std::cerr << "nothing in peer list!!!" << std::endl;
} }
srand(60); srand(60);
long int now = time(NULL); // the present time long int now = time(NULL); // the present time
std::multimap<long int, std::wstring> emptySet; // time/blog map std::multimap<long int, std::wstring> emptySet; // time/blog map
//std::string statusSet[5] = { "great", "rubbish", "ecstatic", "save me", "emo depression"}; //std::string statusSet[5] = { "great", "rubbish", "ecstatic", "save me", "emo depression"};
//std::string songs[5] = { "broken spleen", "niobium", "ewe (a sheep)", "velvet stuff", "chun li kicks"}; //std::string songs[5] = { "broken spleen", "niobium", "ewe (a sheep)", "velvet stuff", "chun li kicks"};
/* the usr dummy usr blogs */ /* the usr dummy usr blogs */
std::string B1 = "I think we should eat more cheese"; std::string B1 = "I think we should eat more cheese";
std::string B2 = "today was so cool, i got attacked by fifty ninja while buying a loaf so i used my paper bag to suffocate each of them to death at hyper speed"; std::string B2 = "today was so cool, i got attacked by fifty ninja while buying a loaf so i used my paper bag to suffocate each of them to death at hyper speed";
std::string B3 = "Nuthins up"; std::string B3 = "Nuthins up";
std::string B4 = "stop bothering me"; std::string B4 = "stop bothering me";
std::string B5 = "I'm really a boring person and having nothin interesting to say"; std::string B5 = "I'm really a boring person and having nothin interesting to say";
std::string blogs[5] = {B1, B2, B3, B4, B5}; std::string blogs[5] = {B1, B2, B3, B4, B5};
/* fill up maps: first usrblogset with empty blogs */ /* fill up maps: first usrblogset with empty blogs */
std::list<std::string>::iterator it; std::list<std::string>::iterator it;
mUsrBlogSet.insert(std::make_pair(mOwnId, emptySet)); mUsrBlogSet.insert(std::make_pair(mOwnId, emptySet));
for(it = peers.begin(); it!=peers.end();it++) for(it = peers.begin(); it!=peers.end();it++)
{ {
mUsrBlogSet.insert(std::make_pair(*it, emptySet)); mUsrBlogSet.insert(std::make_pair(*it, emptySet));
} }
/* now fill up blog map */ /* now fill up blog map */
for(int i=0; i < 50 ; i++) for(int i=0; i < 50 ; i++)
{ {
std::list<std::string>::iterator it = peers.begin(); std::list<std::string>::iterator it = peers.begin();
@ -577,7 +469,7 @@ void p3Qblog::loadDummy(void)
int b = rand() % 5; int b = rand() % 5;
cnv_wstr.assign(blogs[b].begin(), blogs[b].end()); cnv_wstr.assign(blogs[b].begin(), blogs[b].end());
mUsrBlogSet[mOwnId].insert(std::make_pair(timeStamp, cnv_wstr )); // store a random blog mUsrBlogSet[mOwnId].insert(std::make_pair(timeStamp, cnv_wstr )); // store a random blog
for(;it!=peers.end(); it++) for(;it!=peers.end(); it++)
{ {
timeStamp = now + rand() % 2134223; // a random time for each blog timeStamp = now + rand() % 2134223; // a random time for each blog
@ -586,10 +478,10 @@ void p3Qblog::loadDummy(void)
mUsrBlogSet[*it].insert(std::make_pair(timeStamp, cnv_wstr)); // store a random blog mUsrBlogSet[*it].insert(std::make_pair(timeStamp, cnv_wstr)); // store a random blog
} }
} }
return; return;
} }
bool p3Qblog::sort(void) bool p3Qblog::sort(void)
@ -601,12 +493,12 @@ bool p3Qblog::sort(void)
void p3Qblog::tick() void p3Qblog::tick()
{ {
bool postUpdated = false; // so stack mutex is not enabled during postblog call bool postUpdated = false; // so stack mutex is not enabled during postblog call
{ {
RsStackMutex stack(mBlogMtx); RsStackMutex stack(mBlogMtx);
postUpdated = mPostsUpdated; postUpdated = mPostsUpdated;
} }
if(!postUpdated) if(!postUpdated)
{ {
if(!postBlogs()) if(!postBlogs())

View file

@ -25,7 +25,7 @@
* Please report all bugs and problems to "retroshare@lunamutt.com". * Please report all bugs and problems to "retroshare@lunamutt.com".
* *
*/ */
#include <iostream> #include <iostream>
#include <string> #include <string>
@ -42,7 +42,6 @@
#include "rsiface/rstypes.h" #include "rsiface/rstypes.h"
class RsQblogMsg; /* to populate maps of blogs */ class RsQblogMsg; /* to populate maps of blogs */
class RsQblogProfile; /* to populate profile information */
/*! /*!
* contains definitions of the interface and blog information to be manipulated * contains definitions of the interface and blog information to be manipulated
@ -54,105 +53,90 @@ class RsQblogProfile; /* to populate profile information */
* overloads extractor to make printing wstrings easier * overloads extractor to make printing wstrings easier
*/ */
friend std::ostream &operator<<(std::ostream &out, const std::wstring); friend std::ostream &operator<<(std::ostream &out, const std::wstring);
public: public:
p3Qblog(p3ConnectMgr *connMgr, p3Qblog(p3ConnectMgr *connMgr,
uint16_t type, CacheStrapper *cs, CacheTransfer *cft, uint16_t type, CacheStrapper *cs, CacheTransfer *cft,
std::string sourcedir, std::string storedir, std::string sourcedir, std::string storedir,
uint32_t storePeriod); uint32_t storePeriod);
virtual ~p3Qblog (); virtual ~p3Qblog ();
public: public:
/******************************* CACHE SOURCE / STORE Interface *********************/ /******************************* CACHE SOURCE / STORE Interface *********************/
/// overloaded functions from Cache Source /// overloaded functions from Cache Source
virtual bool loadLocalCache(const CacheData &data); virtual bool loadLocalCache(const CacheData &data);
/// overloaded functions from Cache Store /// overloaded functions from Cache Store
virtual int loadCache(const CacheData &data); virtual int loadCache(const CacheData &data);
/******************************* CACHE SOURCE / STORE Interface *********************/ /******************************* CACHE SOURCE / STORE Interface *********************/
public: public:
virtual bool setFilterSwitch(bool &filterSwitch);
virtual bool getFilterSwitch(void);
virtual bool addToFilter(std::string &usrId);
virtual bool removeFiltFriend(std::string &usrId);
virtual bool sendBlog(const std::wstring &msg); virtual bool sendBlog(const std::wstring &msg);
virtual bool getBlogs(std::map< std::string, std::multimap<long int, std::wstring> > &blogs); virtual bool getBlogs(std::map< std::string, std::multimap<long int, std::wstring> > &blogs);
virtual bool getPeerLatestBlog(std::string id, uint32_t &ts, std::wstring &post); virtual bool getPeerLatestBlog(std::string id, uint32_t &ts, std::wstring &post);
virtual bool getPeerProfile(std::string id, std::list< std::pair<std::wstring, std::wstring> > &entries);
virtual bool getPeerFavourites(std::string id, std::list<FileInfo> &favs);
virtual bool setFavorites(FileInfo favFile);
virtual bool setProfile(std::pair<std::wstring, std::wstring> entry);
/** /**
* to be run by server, update method * to be run by server, update method
*/ */
void tick(); void tick();
private: private:
/********************* begining of private utility methods **************************/ /********************* begining of private utility methods **************************/
/* /*
* to load and transform cache source to normal attribute format of a blog message * to load and transform cache source to normal attribute format of a blog message
* @param filename * @param filename
* @param source * @param source
*/ */
bool loadBlogFile(std::string filename, std::string src); bool loadBlogFile(std::string filename, std::string src);
/* /*
* add a blog item to maps * add a blog item to maps
* @param newBlog a blog item from a peer or yourself * @param newBlog a blog item from a peer or yourself
*/ */
bool addBlog(RsQblogMsg *newBlog); bool addBlog(RsQblogMsg *newBlog);
/* /*
* post our blog to our friends, connectivity method * post our blog to our friends, connectivity method
*/ */
bool postBlogs(void); bool postBlogs(void);
/* /*
* sort usr/blog maps in time order * sort usr/blog maps in time order
*/ */
bool sort(void); bool sort(void);
/************************* end of private methods **************************/ /************************* end of private methods **************************/
/// handles connection to peers /// handles connection to peers
p3ConnectMgr *mConnMgr; p3ConnectMgr *mConnMgr;
/// for locking files provate members below /// for locking files provate members below
RsMutex mBlogMtx; RsMutex mBlogMtx;
/// the current usr /// the current usr
std::string mOwnId; std::string mOwnId;
/// contains the list of ids usr only wants to see /// contain usrs and their blogs
std::list<std::string> mFilterList; std::map< std::string, std::multimap<long int, std::wstring> > mUsrBlogSet;
/// determines whether filter is activated or not
bool mFilterSwitch;
/// contain usrs and their blogs
std::map< std::string, std::multimap<long int, std::wstring> > mUsrBlogSet;
///fills up above sets ///fills up above sets
std::list<RsQblogMsg*> mBlogs; std::list<RsQblogMsg*> mBlogs;
///profile information
std::map<std::string, RsQblogProfile > mProfiles;
///how long to keep posts ///how long to keep posts
uint32_t mStorePeriod; uint32_t mStorePeriod;
/// to track blog updates /// to track blog updates
bool mPostsUpdated; bool mPostsUpdated;
/// to track profile updates /// to track profile updates
bool mProfileUpdated; bool mProfileUpdated;
/* /*
* load dummy data * load dummy data
*/ */
void loadDummy(void); void loadDummy(void);
}; };
#endif /*P3QBLOG_H_*/ #endif /*P3QBLOG_H_*/