mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
Addition of improvements to photo service - can now add local photos - but these are not shared over the network yet.
Added HashFile() utility function. Also added updated() functions to ranking and photos, so the GUI can update itself when necessary. git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@381 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
0c7af5a691
commit
fb229c96da
@ -73,10 +73,12 @@ class RsPhotoDetails
|
||||
std::string srcid;
|
||||
|
||||
std::string hash;
|
||||
uint64_t size;
|
||||
|
||||
std::string name;
|
||||
std::wstring location;
|
||||
std::wstring comment;
|
||||
|
||||
std::string location;
|
||||
std::string date;
|
||||
|
||||
uint32_t format;
|
||||
@ -95,9 +97,12 @@ class RsPhoto
|
||||
RsPhoto() { return; }
|
||||
virtual ~RsPhoto() { return; }
|
||||
|
||||
/* changed? */
|
||||
virtual bool updated() = 0;
|
||||
|
||||
/* access data */
|
||||
virtual bool getPhotoList(std::string id, std::list<std::string> hashs) = 0;
|
||||
virtual bool getShowList(std::string id, std::list<std::string> showIds) = 0;
|
||||
virtual bool getPhotoList(std::string id, std::list<std::string> &hashs) = 0;
|
||||
virtual bool getShowList(std::string id, std::list<std::string> &showIds) = 0;
|
||||
virtual bool getShowDetails(std::string id, std::string showId, RsPhotoShowDetails &detail) = 0;
|
||||
virtual bool getPhotoDetails(std::string id, std::string photoId, RsPhotoDetails &detail) = 0;
|
||||
|
||||
|
@ -69,6 +69,9 @@ class RsRanks
|
||||
RsRanks() { return; }
|
||||
virtual ~RsRanks() { return; }
|
||||
|
||||
/* needs update? */
|
||||
virtual bool updated() = 0;
|
||||
|
||||
/* Set Sort Methods */
|
||||
virtual bool setSortPeriod(uint32_t period) = 0;
|
||||
virtual bool setSortMethod(uint32_t type) = 0;
|
||||
|
@ -50,13 +50,19 @@ p3Photo::~p3Photo()
|
||||
return;
|
||||
}
|
||||
|
||||
/* needs update? */
|
||||
bool p3Photo::updated()
|
||||
{
|
||||
return mPhoto->updated();
|
||||
}
|
||||
|
||||
/* access data */
|
||||
bool p3Photo::getPhotoList(std::string id, std::list<std::string> hashs)
|
||||
bool p3Photo::getPhotoList(std::string id, std::list<std::string> &hashs)
|
||||
{
|
||||
return mPhoto->getPhotoList(id, hashs);
|
||||
}
|
||||
|
||||
bool p3Photo::getShowList(std::string id, std::list<std::string> showIds)
|
||||
bool p3Photo::getShowList(std::string id, std::list<std::string> &showIds)
|
||||
{
|
||||
return mPhoto -> getShowList(id, showIds);
|
||||
}
|
||||
|
@ -36,9 +36,12 @@ class p3Photo: public RsPhoto
|
||||
p3Photo(p3PhotoService *p3ps);
|
||||
virtual ~p3Photo();
|
||||
|
||||
/* changed? */
|
||||
virtual bool updated();
|
||||
|
||||
/* access data */
|
||||
virtual bool getPhotoList(std::string id, std::list<std::string> hashs);
|
||||
virtual bool getShowList(std::string id, std::list<std::string> showIds);
|
||||
virtual bool getPhotoList(std::string id, std::list<std::string> &hashs);
|
||||
virtual bool getShowList(std::string id, std::list<std::string> &showIds);
|
||||
virtual bool getShowDetails(std::string id, std::string showId, RsPhotoShowDetails &detail);
|
||||
virtual bool getPhotoDetails(std::string id, std::string photoId, RsPhotoDetails &detail);
|
||||
|
||||
|
@ -37,6 +37,11 @@ p3Rank::~p3Rank()
|
||||
{
|
||||
return;
|
||||
}
|
||||
/* needs update? */
|
||||
bool p3Rank::updated()
|
||||
{
|
||||
return mRank->updated();
|
||||
}
|
||||
|
||||
/* Set Sort Methods */
|
||||
bool p3Rank::setSortPeriod(uint32_t period)
|
||||
|
@ -36,6 +36,9 @@ class p3Rank: public RsRanks
|
||||
p3Rank(p3Ranking *ranking);
|
||||
virtual ~p3Rank();
|
||||
|
||||
/* needs update? */
|
||||
virtual bool updated();
|
||||
|
||||
/* Set Sort Methods */
|
||||
virtual bool setSortPeriod(uint32_t period);
|
||||
virtual bool setSortMethod(uint32_t type);
|
||||
|
@ -28,6 +28,8 @@
|
||||
#include "pqi/pqibin.h"
|
||||
#include "pqi/p3authmgr.h"
|
||||
|
||||
#include "util/rsdir.h"
|
||||
|
||||
std::string generateRandomShowId();
|
||||
|
||||
#define PHOTO_DEBUG 1
|
||||
@ -45,7 +47,8 @@ PhotoSet::PhotoSet()
|
||||
p3PhotoService::p3PhotoService(uint16_t type, CacheStrapper *cs, CacheTransfer *cft,
|
||||
std::string sourcedir, std::string storedir)
|
||||
:CacheSource(type, true, cs, sourcedir),
|
||||
CacheStore(type, true, cs, cft, storedir)
|
||||
CacheStore(type, true, cs, cft, storedir),
|
||||
mUpdated(true)
|
||||
{
|
||||
|
||||
{ RsStackMutex stack(mPhotoMtx); /********** STACK LOCKED MTX ******/
|
||||
@ -112,6 +115,7 @@ bool p3PhotoService::loadLocalCache(const CacheData &data)
|
||||
{
|
||||
RsStackMutex stack(mPhotoMtx); /********** STACK LOCKED MTX ******/
|
||||
mRepublish = false;
|
||||
mUpdated = true;
|
||||
}
|
||||
|
||||
if (data.size > 0) /* don't refresh zero sized caches */
|
||||
@ -247,6 +251,8 @@ bool p3PhotoService::loadPhotoItem(RsPhotoItem *item)
|
||||
PhotoSet &pset = locked_getPhotoSet(item->PeerId());
|
||||
pset.photos[item->photoId] = item;
|
||||
|
||||
mUpdated = true;
|
||||
|
||||
return true;
|
||||
|
||||
|
||||
@ -270,6 +276,7 @@ bool p3PhotoService::loadPhotoShowItem(RsPhotoShowItem *item)
|
||||
pset.shows[item->showId] = item;
|
||||
|
||||
//mRepublish = true;
|
||||
mUpdated = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -395,8 +402,19 @@ void p3PhotoService::publishPhotos()
|
||||
/******************* External Interface *****************************************/
|
||||
/********************************************************************************/
|
||||
|
||||
bool p3PhotoService::updated()
|
||||
{
|
||||
RsStackMutex stack(mPhotoMtx); /********** STACK LOCKED MTX ******/
|
||||
|
||||
if (mUpdated)
|
||||
{
|
||||
mUpdated = false;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool p3PhotoService::getPhotoList(std::string id, std::list<std::string> photoIds)
|
||||
bool p3PhotoService::getPhotoList(std::string id, std::list<std::string> &photoIds)
|
||||
{
|
||||
#ifdef PHOTO_DEBUG
|
||||
std::cerr << "p3PhotoService::getPhotoList() pid: " << id;
|
||||
@ -411,6 +429,10 @@ bool p3PhotoService::getPhotoList(std::string id, std::list<std::string> photoId
|
||||
std::map<std::string, RsPhotoItem *>::iterator pit;
|
||||
for(pit = pset.photos.begin(); pit != pset.photos.end(); pit++)
|
||||
{
|
||||
#ifdef PHOTO_DEBUG
|
||||
std::cerr << "p3PhotoService::getPhotoList() PhotoId: " << pit->first;
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
photoIds.push_back(pit->first);
|
||||
}
|
||||
|
||||
@ -418,7 +440,7 @@ bool p3PhotoService::getPhotoList(std::string id, std::list<std::string> photoId
|
||||
}
|
||||
|
||||
|
||||
bool p3PhotoService::getShowList(std::string id, std::list<std::string> showIds)
|
||||
bool p3PhotoService::getShowList(std::string id, std::list<std::string> &showIds)
|
||||
{
|
||||
#ifdef PHOTO_DEBUG
|
||||
std::cerr << "p3PhotoService::getShowList() pid: " << id;
|
||||
@ -433,6 +455,10 @@ bool p3PhotoService::getShowList(std::string id, std::list<std::string> showIds)
|
||||
std::map<std::string, RsPhotoShowItem *>::iterator sit;
|
||||
for(sit = pset.shows.begin(); sit != pset.shows.end(); sit++)
|
||||
{
|
||||
#ifdef PHOTO_DEBUG
|
||||
std::cerr << "p3PhotoService::getShowList() ShowId: " << sit->first;
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
showIds.push_back(sit->first);
|
||||
}
|
||||
|
||||
@ -478,6 +504,17 @@ bool p3PhotoService::getPhotoDetails(std::string id, std::string photoId, RsPhot
|
||||
}
|
||||
|
||||
/* extract Photo details */
|
||||
detail.id = item->PeerId();
|
||||
detail.srcid = item->srcId;
|
||||
detail.hash = item->photoId;
|
||||
detail.size = item->size;
|
||||
detail.name = item->name;
|
||||
detail.location = item->location;
|
||||
detail.comment = item->comment;
|
||||
detail.date = item->date;
|
||||
detail.format = 0;
|
||||
detail.isAvailable = item->isAvailable;
|
||||
detail.path = item->path;
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -587,11 +624,15 @@ bool p3PhotoService::removePhotoFromShow(std::string showId, std::string photoId
|
||||
std::string p3PhotoService::addPhoto(std::string path) /* add from file */
|
||||
{
|
||||
/* check file exists */
|
||||
std::string hash;
|
||||
uint64_t size;
|
||||
|
||||
/* copy to outgoing directory */
|
||||
if (!RsDirUtil::getFileHash(path, hash, size))
|
||||
{
|
||||
return hash;
|
||||
}
|
||||
|
||||
/* hash it */
|
||||
std::string hash = "PHOTO HASH";
|
||||
/* copy to outgoing directory TODO */
|
||||
|
||||
/* create item */
|
||||
RsPhotoItem *item = new RsPhotoItem();
|
||||
@ -603,8 +644,11 @@ std::string p3PhotoService::addPhoto(std::string path) /* add from file */
|
||||
|
||||
item->srcId = item->PeerId();
|
||||
item->photoId = hash;
|
||||
item->name = hash;
|
||||
item->name = RsDirUtil::getTopDir(path);
|
||||
item->path = path;
|
||||
item->size = size;
|
||||
item->isAvailable = true;
|
||||
item->comment = L"No Comment Yet!";
|
||||
|
||||
/* add in */
|
||||
loadPhotoItem(item);
|
||||
|
@ -75,9 +75,12 @@ virtual int loadCache(const CacheData &data);
|
||||
|
||||
/************* Extern Interface *******/
|
||||
|
||||
/* things changed */
|
||||
bool updated();
|
||||
|
||||
/* access data */
|
||||
bool getPhotoList(std::string id, std::list<std::string> hashs);
|
||||
bool getShowList(std::string id, std::list<std::string> showIds);
|
||||
bool getPhotoList(std::string id, std::list<std::string> &hashs);
|
||||
bool getShowList(std::string id, std::list<std::string> &showIds);
|
||||
bool getShowDetails(std::string id, std::string showId, RsPhotoShowDetails &detail);
|
||||
bool getPhotoDetails(std::string id, std::string photoId, RsPhotoDetails &detail);
|
||||
|
||||
@ -130,8 +133,11 @@ void createDummyData();
|
||||
bool mRepublish;
|
||||
std::string mOwnId;
|
||||
|
||||
bool mUpdated;
|
||||
|
||||
std::map<std::string, PhotoSet> mPhotos;
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -48,7 +48,7 @@ p3Ranking::p3Ranking(uint16_t type, CacheStrapper *cs, CacheTransfer *cft,
|
||||
uint32_t storePeriod)
|
||||
:CacheSource(type, true, cs, sourcedir),
|
||||
CacheStore(type, true, cs, cft, storedir),
|
||||
mStorePeriod(storePeriod)
|
||||
mStorePeriod(storePeriod), mUpdated(true)
|
||||
{
|
||||
|
||||
{ RsStackMutex stack(mRankMtx); /********** STACK LOCKED MTX ******/
|
||||
@ -385,6 +385,8 @@ void p3Ranking::addRankMsg(RsRankLinkMsg *msg)
|
||||
}
|
||||
|
||||
locked_reSortGroup(it->second);
|
||||
|
||||
mUpdated = true;
|
||||
}
|
||||
}
|
||||
|
||||
@ -714,8 +716,17 @@ void p3Ranking::tick()
|
||||
}
|
||||
}
|
||||
|
||||
bool p3Ranking::updated()
|
||||
{
|
||||
RsStackMutex stack(mRankMtx); /********** STACK LOCKED MTX ******/
|
||||
|
||||
|
||||
if (mUpdated)
|
||||
{
|
||||
mUpdated = false;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/***** NEW CONTENT *****/
|
||||
std::string p3Ranking::newRankMsg(std::wstring link, std::wstring title, std::wstring comment)
|
||||
|
@ -83,6 +83,9 @@ virtual int loadCache(const CacheData &data);
|
||||
|
||||
/************* Extern Interface *******/
|
||||
|
||||
/* changed */
|
||||
virtual bool updated();
|
||||
|
||||
/* Set Sort Methods */
|
||||
virtual bool setSortPeriod(uint32_t period);
|
||||
virtual bool setSortMethod(uint32_t type);
|
||||
@ -124,6 +127,7 @@ void createDummyData();
|
||||
uint32_t mStorePeriod;
|
||||
|
||||
std::string mOwnId;
|
||||
bool mUpdated;
|
||||
|
||||
std::map<std::string, RankGroup> mData;
|
||||
std::multimap<float, std::string> mRankings;
|
||||
|
@ -276,4 +276,55 @@ bool RsDirUtil::cleanupDirectory(std::string cleandir, std::list<std::string> k
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
#include <openssl/sha.h>
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
|
||||
|
||||
/* Function to hash, and get details of a file */
|
||||
bool RsDirUtil::getFileHash(std::string filepath,
|
||||
std::string &hash, uint64_t &size)
|
||||
{
|
||||
FILE *fd;
|
||||
int len;
|
||||
SHA_CTX *sha_ctx = new SHA_CTX;
|
||||
unsigned char sha_buf[SHA_DIGEST_LENGTH];
|
||||
unsigned char gblBuf[512];
|
||||
|
||||
if (NULL == (fd = fopen(filepath.c_str(), "rb")))
|
||||
return false;
|
||||
|
||||
/* determine size */
|
||||
fseek(fd, 0, SEEK_END);
|
||||
size = ftell(fd);
|
||||
fseek(fd, 0, SEEK_SET);
|
||||
|
||||
SHA1_Init(sha_ctx);
|
||||
while((len = fread(gblBuf,1, 512, fd)) > 0)
|
||||
{
|
||||
SHA1_Update(sha_ctx, gblBuf, len);
|
||||
}
|
||||
|
||||
/* reading failed for some reason */
|
||||
if (ferror(fd))
|
||||
{
|
||||
delete sha_ctx;
|
||||
fclose(fd);
|
||||
return false;
|
||||
}
|
||||
|
||||
SHA1_Final(&sha_buf[0], sha_ctx);
|
||||
|
||||
std::ostringstream tmpout;
|
||||
for(int i = 0; i < SHA_DIGEST_LENGTH; i++)
|
||||
{
|
||||
tmpout << std::setw(2) << std::setfill('0') << std::hex << (unsigned int) (sha_buf[i]);
|
||||
}
|
||||
hash = tmpout.str();
|
||||
|
||||
delete sha_ctx;
|
||||
fclose(fd);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -46,6 +46,9 @@ int breakupDirList(std::string path,
|
||||
bool checkCreateDirectory(std::string dir);
|
||||
bool cleanupDirectory(std::string dir, std::list<std::string> keepFiles);
|
||||
|
||||
bool getFileHash(std::string filepath,
|
||||
std::string &hash, uint64_t &size);
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user