mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
Merge pull request #7 from G10h4ck/csoler-v0.6-GxsFix2
Fix compilation with deep search and remove dead code
This commit is contained in:
commit
ff92b36aa6
@ -264,7 +264,8 @@ private:
|
||||
static std::string timetToXapianDate(const rstime_t& time)
|
||||
{
|
||||
char date[] = "YYYYMMDD\0";
|
||||
std::strftime(date, 9, "%Y%m%d", std::gmtime(&time));
|
||||
time_t tTime = static_cast<time_t>(time);
|
||||
std::strftime(date, 9, "%Y%m%d", std::gmtime(&tTime));
|
||||
return date;
|
||||
}
|
||||
};
|
||||
|
@ -5140,11 +5140,13 @@ TurtleRequestId RsGxsNetService::turtleSearchRequest(const std::string& match_st
|
||||
return mGxsNetTunnel->turtleSearchRequest(match_string,this) ;
|
||||
}
|
||||
|
||||
#ifndef RS_DEEP_SEARCH
|
||||
static bool termSearch(const std::string& src, const std::string& substring)
|
||||
{
|
||||
/* always ignore case */
|
||||
return src.end() != std::search( src.begin(), src.end(), substring.begin(), substring.end(), RsRegularExpression::CompareCharIC() );
|
||||
}
|
||||
#endif // ndef RS_DEEP_SEARCH
|
||||
|
||||
bool RsGxsNetService::retrieveDistantSearchResults(TurtleRequestId req,std::map<RsGxsGroupId,RsGxsGroupSummary>& group_infos)
|
||||
{
|
||||
|
@ -118,6 +118,54 @@ JsonApiServer::JsonApiServer(uint16_t port, const std::string& bindAddress,
|
||||
mNewAccessRequestCallback(newAccessRequestCallback),
|
||||
configMutex("JsonApiServer config")
|
||||
{
|
||||
registerHandler("/rsLoginHelper/createLocation",
|
||||
[this](const std::shared_ptr<rb::Session> session)
|
||||
{
|
||||
size_t reqSize = session->get_request()->get_header("Content-Length", 0);
|
||||
session->fetch( reqSize, [this](
|
||||
const std::shared_ptr<rb::Session> session,
|
||||
const rb::Bytes& body )
|
||||
{
|
||||
INITIALIZE_API_CALL_JSON_CONTEXT;
|
||||
|
||||
RsLoginHelper::Location location;
|
||||
std::string password;
|
||||
std::string errorMessage;
|
||||
bool makeHidden = false;
|
||||
bool makeAutoTor = false;
|
||||
|
||||
// deserialize input parameters from JSON
|
||||
{
|
||||
RsGenericSerializer::SerializeContext& ctx(cReq);
|
||||
RsGenericSerializer::SerializeJob j(RsGenericSerializer::FROM_JSON);
|
||||
RS_SERIAL_PROCESS(location);
|
||||
RS_SERIAL_PROCESS(password);
|
||||
RS_SERIAL_PROCESS(makeHidden);
|
||||
RS_SERIAL_PROCESS(makeAutoTor);
|
||||
}
|
||||
|
||||
// call retroshare C++ API
|
||||
bool retval = rsLoginHelper->createLocation(
|
||||
location, password, errorMessage, makeHidden,
|
||||
makeAutoTor );
|
||||
|
||||
if(retval)
|
||||
authorizeToken(location.mLocationId.toStdString()+":"+password);
|
||||
|
||||
// serialize out parameters and return value to JSON
|
||||
{
|
||||
RsGenericSerializer::SerializeContext& ctx(cAns);
|
||||
RsGenericSerializer::SerializeJob j(RsGenericSerializer::TO_JSON);
|
||||
RS_SERIAL_PROCESS(location);
|
||||
RS_SERIAL_PROCESS(errorMessage);
|
||||
RS_SERIAL_PROCESS(retval);
|
||||
}
|
||||
|
||||
// return them to the API caller
|
||||
DEFAULT_API_CALL_JSON_RETURN(rb::OK);
|
||||
} );
|
||||
}, false);
|
||||
|
||||
registerHandler("/rsLoginHelper/attemptLogin",
|
||||
[this](const std::shared_ptr<rb::Session> session)
|
||||
{
|
||||
|
@ -292,20 +292,20 @@ struct RsLoginHelper
|
||||
|
||||
/**
|
||||
* @brief Creates a new RetroShare location, and log in once is created
|
||||
* @jsonapi{development,unauthenticated}
|
||||
* @jsonapi{development,manualwrapper}
|
||||
* @param[inout] location provide input information to generate the location
|
||||
* and storage to output the data of the generated location
|
||||
* @param[in] password to protect and unlock the associated PGP key
|
||||
* @param[out] errorMessage if some error occurred human readable error
|
||||
* message
|
||||
* @param[in] makeHidden pass true to create an hidden location. UNTESTED!
|
||||
* @param[in] makeAutoTor pass true to create an automatically configured
|
||||
* Tor hidden location. UNTESTED!
|
||||
* @param[out] errorMessage if some error occurred human readable error
|
||||
* message
|
||||
* @return true if success, false otherwise
|
||||
*/
|
||||
bool createLocation( RsLoginHelper::Location& location,
|
||||
const std::string& password, bool makeHidden,
|
||||
bool makeAutoTor, std::string& errorMessage );
|
||||
const std::string& password, std::string& errorMessage,
|
||||
bool makeHidden = false, bool makeAutoTor = false );
|
||||
|
||||
/**
|
||||
* @brief Check if RetroShare is already logged in, this usually return true
|
||||
|
@ -1952,7 +1952,7 @@ void RsLoginHelper::getLocations(std::vector<RsLoginHelper::Location>& store)
|
||||
|
||||
bool RsLoginHelper::createLocation(
|
||||
RsLoginHelper::Location& l, const std::string& password,
|
||||
bool makeHidden, bool makeAutoTor, std::string& errorMessage )
|
||||
std::string& errorMessage, bool makeHidden, bool makeAutoTor )
|
||||
{
|
||||
if(isLoggedIn()) return (errorMessage="Already Running", false);
|
||||
|
||||
|
@ -1045,119 +1045,38 @@ bool p3GxsChannels::getChannelsContent(
|
||||
bool p3GxsChannels::createChannel(RsGxsChannelGroup& channel)
|
||||
{
|
||||
uint32_t token;
|
||||
time_t beginCreation = time(nullptr);
|
||||
if( !createGroup(token, channel) || waitToken(token) != RsTokenService::COMPLETE )
|
||||
if( !createGroup(token, channel)
|
||||
|| waitToken(token) != RsTokenService::COMPLETE )
|
||||
return false;
|
||||
|
||||
if(RsGenExchange::getPublishedGroupMeta(token,channel.mMeta))
|
||||
if(RsGenExchange::getPublishedGroupMeta(token, channel.mMeta))
|
||||
{
|
||||
#ifdef RS_DEEP_SEARCH
|
||||
if(found) DeepSearch::indexChannelGroup(channel);
|
||||
DeepSearch::indexChannelGroup(channel);
|
||||
#endif // RS_DEEP_SEARCH
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
|
||||
// time_t endCreation = time(nullptr);
|
||||
//
|
||||
//
|
||||
// std::list<RsGroupMetaData> channels;
|
||||
// if(!getChannelsSummaries(channels)) return false;
|
||||
//
|
||||
// /* This is ugly but after digging and doing many tries of doing it the right
|
||||
// * way ending always into too big refactor chain reaction, I think this is
|
||||
// * not that bad, moreover seems the last created group tend to end up near
|
||||
// * the beginning of the list so it is fast founding it.
|
||||
// * The shortcoming of this is that if groups with same data are created in
|
||||
// * a burst (more then once in a second) is that the id of another similar
|
||||
// * group can be returned, but this is a pointy case.
|
||||
// * Order of conditions in the `if` matter for performances */
|
||||
// bool found = false;
|
||||
// for(const RsGroupMetaData& chan : channels)
|
||||
// {
|
||||
// if( IS_GROUP_ADMIN(chan.mSubscribeFlags)
|
||||
// && IS_GROUP_SUBSCRIBED(chan.mSubscribeFlags)
|
||||
// && chan.mPublishTs >= beginCreation
|
||||
// && chan.mPublishTs <= endCreation
|
||||
// && chan.mGroupFlags == channel.mMeta.mGroupFlags
|
||||
// && chan.mSignFlags == channel.mMeta.mSignFlags
|
||||
// && chan.mCircleType == channel.mMeta.mCircleType
|
||||
// && chan.mAuthorId == channel.mMeta.mAuthorId
|
||||
// && chan.mCircleId == channel.mMeta.mCircleId
|
||||
// && chan.mServiceString == channel.mMeta.mServiceString
|
||||
// && chan.mGroupName == channel.mMeta.mGroupName )
|
||||
// {
|
||||
// channel.mMeta = chan;
|
||||
// found = true;
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
return false;
|
||||
}
|
||||
|
||||
bool p3GxsChannels::createPost(RsGxsChannelPost& post)
|
||||
{
|
||||
uint32_t token;
|
||||
time_t beginCreation = time(nullptr);
|
||||
if( !createPost(token, post)
|
||||
|| waitToken(token) != RsTokenService::COMPLETE ) return false;
|
||||
time_t endCreation = time(nullptr);
|
||||
|
||||
if(RsGenExchange::getPublishedMsgMeta(token,post.mMeta))
|
||||
{
|
||||
#ifdef RS_DEEP_SEARCH
|
||||
if(found) DeepSearch::indexChannelGroup(post);
|
||||
DeepSearch::indexChannelPost(post);
|
||||
#endif // RS_DEEP_SEARCH
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
|
||||
// std::list<RsGxsGroupId> chanIds; chanIds.push_back(post.mMeta.mGroupId);
|
||||
// std::vector<RsGxsChannelPost> posts;
|
||||
// std::vector<RsGxsComment> comments;
|
||||
// if(!getChannelsContent(chanIds, posts, comments)) return false;
|
||||
//
|
||||
// /* This is ugly but after digging and doing many tries of doing it the right
|
||||
// * way ending always into too big refactor chain reaction, I think this is
|
||||
// * not that bad.
|
||||
// * The shortcoming of this is that if posts with same data are created in
|
||||
// * a burst (more then once in a second) is that the id of another similar
|
||||
// * post could be returned, but this is a pointy case.
|
||||
// * Order of conditions in the `if` matter for performances */
|
||||
// bool found = false;
|
||||
// for(const RsGxsChannelPost& itPost : posts)
|
||||
// {
|
||||
// std::cout << __PRETTY_FUNCTION__ << " " << beginCreation << " "
|
||||
// << itPost.mMeta.mPublishTs << " " << endCreation << " "
|
||||
// << itPost.mMeta.mMsgId << std::endl;
|
||||
//
|
||||
// if( itPost.mMeta.mPublishTs >= beginCreation
|
||||
// && itPost.mMeta.mPublishTs <= endCreation
|
||||
// && itPost.mMeta.mMsgFlags == post.mMeta.mMsgFlags
|
||||
// && itPost.mMeta.mGroupId == post.mMeta.mGroupId
|
||||
// && itPost.mMeta.mThreadId == post.mMeta.mThreadId
|
||||
// && itPost.mMeta.mParentId == post.mMeta.mParentId
|
||||
// && itPost.mMeta.mAuthorId == post.mMeta.mAuthorId
|
||||
// && itPost.mMeta.mMsgName == post.mMeta.mMsgName
|
||||
// && itPost.mFiles.size() == post.mFiles.size()
|
||||
// && itPost.mMeta.mServiceString == post.mMeta.mServiceString
|
||||
// && itPost.mOlderVersions == post.mOlderVersions
|
||||
// && itPost.mMsg == post.mMsg )
|
||||
// {
|
||||
// post = itPost;
|
||||
// found = true;
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//#ifdef RS_DEEP_SEARCH
|
||||
// if(found) DeepSearch::indexChannelPost(post);
|
||||
//#endif // RS_DEEP_SEARCH
|
||||
//
|
||||
// return found;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
@ -1438,7 +1438,6 @@ void GxsForumThreadWidget::insertThreads()
|
||||
GxsForumsFillThread *thread = mFillThread;
|
||||
mFillThread = NULL;
|
||||
thread->stop();
|
||||
delete(thread);
|
||||
|
||||
mStateHelper->setLoading(mTokenTypeInsertThreads, false);
|
||||
}
|
||||
|
@ -74,7 +74,6 @@ void GxsForumsFillThread::stop()
|
||||
disconnect();
|
||||
mStopped = true;
|
||||
QApplication::processEvents();
|
||||
wait();
|
||||
}
|
||||
|
||||
void GxsForumsFillThread::calculateExpand(const RsGxsForumMsg &msg, QTreeWidgetItem *item)
|
||||
@ -125,7 +124,10 @@ void GxsForumsFillThread::run()
|
||||
}
|
||||
|
||||
if (requestStatus == RsTokenService::FAILED)
|
||||
{
|
||||
deleteLater();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// also get the forum meta data.
|
||||
@ -154,7 +156,10 @@ void GxsForumsFillThread::run()
|
||||
}
|
||||
|
||||
if (requestStatus == RsTokenService::FAILED)
|
||||
{
|
||||
deleteLater();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (wasStopped())
|
||||
@ -166,6 +171,7 @@ void GxsForumsFillThread::run()
|
||||
/* cancel request */
|
||||
service->cancelRequest(msg_token);
|
||||
service->cancelRequest(grp_token);
|
||||
deleteLater();
|
||||
return;
|
||||
}
|
||||
|
||||
@ -174,7 +180,10 @@ void GxsForumsFillThread::run()
|
||||
std::vector<RsGxsForumGroup> forum_groups;
|
||||
|
||||
if (!rsGxsForums->getGroupData(grp_token, forum_groups) || forum_groups.size() != 1)
|
||||
{
|
||||
deleteLater();
|
||||
return;
|
||||
}
|
||||
|
||||
RsGxsForumGroup forum_group = *forum_groups.begin();
|
||||
|
||||
@ -197,7 +206,10 @@ void GxsForumsFillThread::run()
|
||||
std::vector<RsGxsForumMsg> msgs_array;
|
||||
|
||||
if (!rsGxsForums->getMsgData(msg_token, msgs_array))
|
||||
{
|
||||
deleteLater();
|
||||
return;
|
||||
}
|
||||
|
||||
// now put everything into a map in order to make search log(n)
|
||||
|
||||
@ -240,6 +252,12 @@ void GxsForumsFillThread::run()
|
||||
std::list<RsGxsMessageId> msg_stack ;
|
||||
|
||||
for ( std::map<RsGxsMessageId,RsGxsForumMsg>::iterator msgIt = msgs.begin(); msgIt != msgs.end();++msgIt)
|
||||
{
|
||||
if(wasStopped())
|
||||
{
|
||||
deleteLater();
|
||||
return;
|
||||
}
|
||||
if(!msgIt->second.mMeta.mOrigMsgId.isNull() && msgIt->second.mMeta.mOrigMsgId != msgIt->second.mMeta.mMsgId)
|
||||
{
|
||||
#ifdef DEBUG_FORUMS
|
||||
@ -271,14 +289,26 @@ void GxsForumsFillThread::run()
|
||||
|
||||
mPostVersions[msgIt->second.mMeta.mOrigMsgId].push_back(QPair<time_t,RsGxsMessageId>(msgIt->second.mMeta.mPublishTs,msgIt->second.mMeta.mMsgId)) ;
|
||||
}
|
||||
}
|
||||
|
||||
// The following code assembles all new versions of a given post into the same array, indexed by the oldest version of the post.
|
||||
|
||||
for(QMap<RsGxsMessageId,QVector<QPair<time_t,RsGxsMessageId> > >::iterator it(mPostVersions.begin());it!=mPostVersions.end();++it)
|
||||
{
|
||||
if(wasStopped())
|
||||
{
|
||||
deleteLater();
|
||||
return;
|
||||
}
|
||||
QVector<QPair<time_t,RsGxsMessageId> >& v(*it) ;
|
||||
|
||||
for(int32_t i=0;i<v.size();++i)
|
||||
{
|
||||
if(wasStopped())
|
||||
{
|
||||
deleteLater();
|
||||
return;
|
||||
}
|
||||
if(v[i].second != it.key())
|
||||
{
|
||||
RsGxsMessageId sub_msg_id = v[i].second ;
|
||||
@ -294,6 +324,7 @@ void GxsForumsFillThread::run()
|
||||
mPostVersions.erase(it2) ; // it2 is never equal to it
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -311,6 +342,11 @@ void GxsForumsFillThread::run()
|
||||
#ifdef DEBUG_FORUMS
|
||||
std::cerr << "Original post: " << it.key() << std::endl;
|
||||
#endif
|
||||
if(wasStopped())
|
||||
{
|
||||
deleteLater();
|
||||
return;
|
||||
}
|
||||
// Finally, sort the posts from newer to older
|
||||
|
||||
qSort((*it).begin(),(*it).end(),decreasing_time_comp) ;
|
||||
@ -320,6 +356,11 @@ void GxsForumsFillThread::run()
|
||||
#endif
|
||||
for(int32_t i=1;i<(*it).size();++i)
|
||||
{
|
||||
if(wasStopped())
|
||||
{
|
||||
deleteLater();
|
||||
return;
|
||||
}
|
||||
msgs.erase((*it)[i].second) ;
|
||||
|
||||
#ifdef DEBUG_FORUMS
|
||||
@ -333,7 +374,14 @@ void GxsForumsFillThread::run()
|
||||
// to the newest version. So we create a map of which is the most recent version of each message, so that parent messages can be searched in it.
|
||||
|
||||
for(int i=1;i<(*it).size();++i)
|
||||
{
|
||||
if(wasStopped())
|
||||
{
|
||||
deleteLater();
|
||||
return;
|
||||
}
|
||||
most_recent_versions[(*it)[i].second] = (*it)[0].second ;
|
||||
}
|
||||
}
|
||||
mPostVersions = mTmp ;
|
||||
|
||||
@ -348,12 +396,20 @@ void GxsForumsFillThread::run()
|
||||
for ( std::map<RsGxsMessageId,RsGxsForumMsg>::iterator msgIt = msgs.begin(); msgIt != msgs.end();++msgIt)
|
||||
{
|
||||
|
||||
if (wasStopped())
|
||||
{
|
||||
deleteLater();
|
||||
return;
|
||||
}
|
||||
if(mFlatView || msgIt->second.mMeta.mParentId.isNull())
|
||||
{
|
||||
|
||||
/* add all threads */
|
||||
if (wasStopped())
|
||||
{
|
||||
deleteLater();
|
||||
return;
|
||||
}
|
||||
|
||||
const RsGxsForumMsg& msg = msgIt->second;
|
||||
|
||||
@ -422,7 +478,13 @@ void GxsForumsFillThread::run()
|
||||
|
||||
while (!threadStack.empty())
|
||||
{
|
||||
std::pair<RsGxsMessageId, QTreeWidgetItem*> threadPair = threadStack.front();
|
||||
if (wasStopped())
|
||||
{
|
||||
deleteLater();
|
||||
return;
|
||||
}
|
||||
|
||||
std::pair<RsGxsMessageId, QTreeWidgetItem*> threadPair = threadStack.front();
|
||||
threadStack.pop_front();
|
||||
|
||||
std::map<RsGxsMessageId, std::list<RsGxsMessageId> >::iterator it = kids_array.find(threadPair.first) ;
|
||||
@ -433,11 +495,14 @@ void GxsForumsFillThread::run()
|
||||
if(it == kids_array.end())
|
||||
continue ;
|
||||
|
||||
if (wasStopped())
|
||||
return;
|
||||
|
||||
for(std::list<RsGxsMessageId>::const_iterator it2(it->second.begin());it2!=it->second.end();++it2)
|
||||
{
|
||||
if(wasStopped())
|
||||
{
|
||||
deleteLater();
|
||||
return;
|
||||
}
|
||||
// We iterate through the top level thread items, and look for which message has the current item as parent.
|
||||
// When found, the item is put in the thread list itself, as a potential new parent.
|
||||
|
||||
@ -485,6 +550,8 @@ void GxsForumsFillThread::run()
|
||||
|
||||
std::cerr << "GxsForumsFillThread::run() stopped: " << (wasStopped() ? "yes" : "no") << std::endl;
|
||||
#endif
|
||||
if(wasStopped())
|
||||
deleteLater();
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user