From 3b8f6997bb2e74ed971fb3c8e777de5d932027d4 Mon Sep 17 00:00:00 2001 From: Gioacchino Mazzurco Date: Fri, 27 Sep 2019 16:21:08 +0200 Subject: [PATCH 1/3] Avoid crash when subscribeToChannel is fed with invaled channel id Fix a couple compiler warning too --- libretroshare/src/gxs/rsdataservice.cc | 5 ++ libretroshare/src/gxs/rsgxsdataaccess.cc | 8 +-- libretroshare/src/retroshare/rsgxschannels.h | 3 +- libretroshare/src/services/p3gxschannels.cc | 4 +- libretroshare/src/services/p3gxschannels.h | 59 ++++++++++---------- 5 files changed, 42 insertions(+), 37 deletions(-) diff --git a/libretroshare/src/gxs/rsdataservice.cc b/libretroshare/src/gxs/rsdataservice.cc index b10c4aec9..2f2940541 100644 --- a/libretroshare/src/gxs/rsdataservice.cc +++ b/libretroshare/src/gxs/rsdataservice.cc @@ -1493,6 +1493,11 @@ int RsDataService::retrieveGxsGrpMetaData(RsGxsGrpMetaTemporaryMap& grp) std::cerr << "RsDataService::retrieveGxsGrpMetaData() " << mDbName << ", Requests: " << requestedGroups << ", Results: " << resultCount << ", Time: " << timer.duration() << std::endl; #endif + /* Remove not found entries as stated in the documentation */ + for(auto i = grp.begin(); i != grp.end();) + if(!i->second) i = grp.erase(i); + else ++i; + return 1; } diff --git a/libretroshare/src/gxs/rsgxsdataaccess.cc b/libretroshare/src/gxs/rsgxsdataaccess.cc index 1206696f7..59c828e60 100644 --- a/libretroshare/src/gxs/rsgxsdataaccess.cc +++ b/libretroshare/src/gxs/rsgxsdataaccess.cc @@ -1009,18 +1009,14 @@ bool RsGxsDataAccess::getGroupSummary(GroupMetaReq* req) } bool RsGxsDataAccess::getGroupList(GroupIdReq* req) -{ - getGroupList(req->mGroupIds, req->Options, req->mGroupIdResult); - - return true; -} +{ return getGroupList(req->mGroupIds, req->Options, req->mGroupIdResult); } bool RsGxsDataAccess::getGroupList(const std::list& grpIdsIn, const RsTokReqOptions& opts, std::list& grpIdsOut) { RsGxsGrpMetaTemporaryMap grpMeta; for(auto lit = grpIdsIn.begin(); lit != grpIdsIn.end(); ++lit) - grpMeta[*lit] = NULL; + grpMeta[*lit] = nullptr; mDataStore->retrieveGxsGrpMetaData(grpMeta); diff --git a/libretroshare/src/retroshare/rsgxschannels.h b/libretroshare/src/retroshare/rsgxschannels.h index 1b90f7924..82a209f18 100644 --- a/libretroshare/src/retroshare/rsgxschannels.h +++ b/libretroshare/src/retroshare/rsgxschannels.h @@ -101,7 +101,6 @@ class RsGxsChannels: public RsGxsIfaceHelper, public RsGxsCommentService { public: explicit RsGxsChannels(RsGxsIface& gxs) : RsGxsIfaceHelper(gxs) {} - virtual ~RsGxsChannels() {} /** * @brief Create channel. Blocking API. @@ -544,4 +543,6 @@ public: RS_DEPRECATED_FOR(turtleChannelRequest) virtual bool retrieveDistantGroup(const RsGxsGroupId& group_id,RsGxsChannelGroup& distant_group)=0; ////////////////////////////////////////////////////////////////////////////// + + virtual ~RsGxsChannels(); }; diff --git a/libretroshare/src/services/p3gxschannels.cc b/libretroshare/src/services/p3gxschannels.cc index f09f4d98c..1a7ee9642 100644 --- a/libretroshare/src/services/p3gxschannels.cc +++ b/libretroshare/src/services/p3gxschannels.cc @@ -1015,7 +1015,7 @@ bool p3GxsChannels::getChannelsInfo( opts.mReqType = GXS_REQUEST_TYPE_GROUP_DATA; if( !requestGroupInfo(token, opts, chanIds) || waitToken(token) != RsTokenService::COMPLETE ) return false; - return getGroupData(token, channelsInfo); + return getGroupData(token, channelsInfo) && !channelsInfo.empty(); } bool p3GxsChannels::getContentSummaries( @@ -2532,3 +2532,5 @@ void p3GxsChannels::cleanTimedOutCallbacks() else ++cbpt; } // RS_STACK_MUTEX(mDistantChannelsCallbacksMapMutex) } + +RsGxsChannels::~RsGxsChannels() = default; diff --git a/libretroshare/src/services/p3gxschannels.h b/libretroshare/src/services/p3gxschannels.h index 766049624..2978dcd0e 100644 --- a/libretroshare/src/services/p3gxschannels.h +++ b/libretroshare/src/services/p3gxschannels.h @@ -111,13 +111,13 @@ virtual bool getChannelDownloadDirectory(const RsGxsGroupId &groupId, std::strin /// @see RsGxsChannels::turtleSearchRequest virtual bool turtleSearchRequest(const std::string& matchString, const std::function& multiCallback, - rstime_t maxWait = 300 ); + rstime_t maxWait = 300 ) override; /// @see RsGxsChannels::turtleChannelRequest virtual bool turtleChannelRequest( const RsGxsGroupId& channelId, const std::function& multiCallback, - rstime_t maxWait = 300 ); + rstime_t maxWait = 300 ) override; /// @see RsGxsChannels::localSearchRequest virtual bool localSearchRequest(const std::string& matchString, @@ -178,26 +178,26 @@ virtual bool ExtraFileRemove(const RsFileHash &hash); /// Implementation of @see RsGxsChannels::getChannelsSummaries - virtual bool getChannelsSummaries(std::list& channels); + bool getChannelsSummaries(std::list& channels) override; /// Implementation of @see RsGxsChannels::getChannelsInfo - virtual bool getChannelsInfo( + bool getChannelsInfo( const std::list& chanIds, - std::vector& channelsInfo ); + std::vector& channelsInfo ) override; /// Implementation of @see RsGxsChannels::getChannelContent - virtual bool getChannelContent( const RsGxsGroupId& channelId, - const std::set& contentsIds, - std::vector& posts, - std::vector& comments ); + bool getChannelContent( const RsGxsGroupId& channelId, + const std::set& contentsIds, + std::vector& posts, + std::vector& comments ) override; /// Implementation of @see RsGxsChannels::getContentSummaries - virtual bool getContentSummaries( + bool getContentSummaries( const RsGxsGroupId& channelId, std::vector& summaries ) override; /// Implementation of @see RsGxsChannels::createChannelV2 - virtual bool createChannelV2( + bool createChannelV2( const std::string& name, const std::string& description, const RsGxsImage& thumbnail = RsGxsImage(), const RsGxsId& authorId = RsGxsId(), @@ -207,12 +207,8 @@ virtual bool ExtraFileRemove(const RsFileHash &hash); std::string& errorMessage = RS_DEFAULT_STORAGE_PARAM(std::string) ) override; - /// @deprecated Implementation of @see RsGxsChannels::createComment - RS_DEPRECATED_FOR(createCommentV2) - virtual bool createComment(RsGxsComment& comment) override; - /// Implementation of @see RsGxsChannels::createComment - virtual bool createCommentV2( + bool createCommentV2( const RsGxsGroupId& channelId, const RsGxsMessageId& threadId, const std::string& comment, @@ -224,11 +220,7 @@ virtual bool ExtraFileRemove(const RsFileHash &hash); ) override; /// Implementation of @see RsGxsChannels::editChannel - virtual bool editChannel(RsGxsChannelGroup& channel) override; - - /// @deprecated Implementation of @see RsGxsChannels::createPost - RS_DEPRECATED_FOR(createPostV2) - virtual bool createPost(RsGxsChannelPost& post) override; + bool editChannel(RsGxsChannelGroup& channel) override; /// Implementation of @see RsGxsChannels::createPostV2 bool createPostV2( @@ -241,12 +233,8 @@ virtual bool ExtraFileRemove(const RsFileHash &hash); std::string& errorMessage = RS_DEFAULT_STORAGE_PARAM(std::string) ) override; - /// @deprecated Implementation of @see RsGxsChannels::createVote - RS_DEPRECATED_FOR(createVoteV2) - virtual bool createVote(RsGxsVote& vote) override; - /// Implementation of @see RsGxsChannels::createVoteV2 - virtual bool createVoteV2( + bool createVoteV2( const RsGxsGroupId& channelId, const RsGxsMessageId& postId, const RsGxsMessageId& commentId, const RsGxsId& authorId, RsGxsVoteType vote, @@ -255,8 +243,8 @@ virtual bool ExtraFileRemove(const RsFileHash &hash); ) override; /// Implementation of @see RsGxsChannels::subscribeToChannel - virtual bool subscribeToChannel( const RsGxsGroupId &groupId, - bool subscribe ); + bool subscribeToChannel( const RsGxsGroupId &groupId, + bool subscribe ) override; /// Implementation of @see RsGxsChannels::setPostRead virtual bool markRead(const RsGxsGrpMsgIdPair& msgId, bool read); @@ -266,7 +254,20 @@ virtual bool ExtraFileRemove(const RsFileHash &hash); /// Implementation of @see RsGxsChannels::createChannel RS_DEPRECATED_FOR(createChannelV2) - virtual bool createChannel(RsGxsChannelGroup& channel) override; + bool createChannel(RsGxsChannelGroup& channel) override; + + /// @deprecated Implementation of @see RsGxsChannels::createPost + RS_DEPRECATED_FOR(createPostV2) + bool createPost(RsGxsChannelPost& post) override; + + /// @deprecated Implementation of @see RsGxsChannels::createComment + RS_DEPRECATED_FOR(createCommentV2) + bool createComment(RsGxsComment& comment) override; + + /// @deprecated Implementation of @see RsGxsChannels::createVote + RS_DEPRECATED_FOR(createVoteV2) + bool createVote(RsGxsVote& vote) override; + protected: // Overloaded from GxsTokenQueue for Request callbacks. From 25e966d039d3a334cb5455f9bb10ff6bc0038013 Mon Sep 17 00:00:00 2001 From: defnax Date: Sun, 29 Sep 2019 17:32:14 +0200 Subject: [PATCH 2/3] added atach picture button to forum post --- .../src/gui/gxsforums/CreateGxsForumMsg.cpp | 32 ++++++++++++++++++ .../src/gui/gxsforums/CreateGxsForumMsg.h | 2 ++ .../src/gui/gxsforums/CreateGxsForumMsg.ui | 33 ++++++++++++++++++- 3 files changed, 66 insertions(+), 1 deletion(-) diff --git a/retroshare-gui/src/gui/gxsforums/CreateGxsForumMsg.cpp b/retroshare-gui/src/gui/gxsforums/CreateGxsForumMsg.cpp index 1e1b7c43f..f10332a30 100644 --- a/retroshare-gui/src/gui/gxsforums/CreateGxsForumMsg.cpp +++ b/retroshare-gui/src/gui/gxsforums/CreateGxsForumMsg.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include #include @@ -103,6 +104,8 @@ CreateGxsForumMsg::CreateGxsForumMsg(const RsGxsGroupId &fId, const RsGxsMessage connect(ui.buttonBox, SIGNAL(rejected()), this, SLOT(reject())); connect(ui.emoticonButton, SIGNAL(clicked()), this, SLOT(smileyWidgetForums())); connect(ui.attachFileButton, SIGNAL(clicked()), this, SLOT(addFile())); + connect(ui.attachPictureButton, SIGNAL(clicked()), this, SLOT(addPicture())); + connect(ui.forumMessage, SIGNAL(textChanged()), this, SLOT(checkLength())); connect(ui.generateCheckBox, SIGNAL(toggled(bool)), ui.generateSpinBox, SLOT(setEnabled(bool))); setAcceptDrops(true); @@ -337,6 +340,23 @@ void CreateGxsForumMsg::loadFormInformation() //ui.forumMessage->setText(""); } +static const uint32_t MAX_ALLOWED_GXS_MESSAGE_SIZE = 199000; + +void CreateGxsForumMsg::checkLength() +{ + QString text; + RsHtml::optimizeHtml(ui.forumMessage, text); + std::wstring msg = text.toStdWString(); + int charRemains = MAX_ALLOWED_GXS_MESSAGE_SIZE - msg.length(); + if(charRemains >= 0) + text = tr("It remains %1 characters after HTML conversion.").arg(charRemains); + else + text = tr("Warning: This message is too big of %1 characters after HTML conversion.").arg((0-charRemains)); + ui.buttonBox->button(QDialogButtonBox::Ok)->setToolTip(text); + ui.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(charRemains>=0); + ui.infoLabel->setText(text); +} + void CreateGxsForumMsg::createMsg() { QString name = misc::removeNewLine(ui.forumSubject->text()); @@ -489,6 +509,18 @@ void CreateGxsForumMsg::addFile() } } +void CreateGxsForumMsg::addPicture() +{ + QString file; + if (misc::getOpenFileName(window(), RshareSettings::LASTDIR_IMAGES, tr("Load Picture File"), "Pictures (*.png *.xpm *.jpg *.jpeg)", file)) { + QString encodedImage; + if (RsHtml::makeEmbeddedImage(file, encodedImage, 640*480, MAX_ALLOWED_GXS_MESSAGE_SIZE - 200)) { + QTextDocumentFragment fragment = QTextDocumentFragment::fromHtml(encodedImage); + ui.forumMessage->textCursor().insertFragment(fragment); + } + } +} + void CreateGxsForumMsg::fileHashingFinished(QList hashedFiles) { //std::cerr << "CreateGxsForumMsg::fileHashingFinished() started." << std::endl; diff --git a/retroshare-gui/src/gui/gxsforums/CreateGxsForumMsg.h b/retroshare-gui/src/gui/gxsforums/CreateGxsForumMsg.h index 3b551bda0..4951795c1 100644 --- a/retroshare-gui/src/gui/gxsforums/CreateGxsForumMsg.h +++ b/retroshare-gui/src/gui/gxsforums/CreateGxsForumMsg.h @@ -51,6 +51,8 @@ private slots: void smileyWidgetForums(); void addSmileys(); void addFile(); + void addPicture(); + void checkLength(); void reject(); protected: diff --git a/retroshare-gui/src/gui/gxsforums/CreateGxsForumMsg.ui b/retroshare-gui/src/gui/gxsforums/CreateGxsForumMsg.ui index 37b11b308..4c6838558 100644 --- a/retroshare-gui/src/gui/gxsforums/CreateGxsForumMsg.ui +++ b/retroshare-gui/src/gui/gxsforums/CreateGxsForumMsg.ui @@ -200,6 +200,29 @@ + + + + Qt::NoFocus + + + Attach a Picture + + + + :/icons/png/attach-image.png:/icons/png/attach-image.png + + + + 24 + 24 + + + + true + + + @@ -259,6 +282,13 @@ p, li { white-space: pre-wrap; } + + + + + + + @@ -268,7 +298,7 @@ p, li { white-space: pre-wrap; } Attach files via drag and drop - + @@ -369,6 +399,7 @@ p, li { white-space: pre-wrap; } + From 5c46a8fd4d8a2dab4e24bbb74bc229a70e08eb4d Mon Sep 17 00:00:00 2001 From: Phenom Date: Sun, 29 Sep 2019 13:37:49 +0200 Subject: [PATCH 3/3] Fix implicitly-declared operator= warnings /libretroshare/src/gxs/rsgds.h:54: warning: implicitly-declared 'ContentValue& ContentValue::operator=(const ContentValue&)' is deprecated [-Wdeprecated-copy] 54 | MsgLocMetaData(const MsgLocMetaData& meta){ msgId = meta.msgId; val = meta.val;} /libretroshare/src/gxs/rsgds.h:69: warning: implicitly-declared 'ContentValue& ContentValue::operator=(const ContentValue&)' is deprecated [-Wdeprecated-copy] 69 | GrpLocMetaData(const GrpLocMetaData& meta){ grpId = meta.grpId; val = meta.val;} From 248 to 146 warnings. --- libretroshare/src/gxs/rsgds.h | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/libretroshare/src/gxs/rsgds.h b/libretroshare/src/gxs/rsgds.h index 2235249a7..4e67f9d8c 100644 --- a/libretroshare/src/gxs/rsgds.h +++ b/libretroshare/src/gxs/rsgds.h @@ -48,13 +48,12 @@ public: * This allows modification of local * meta data items of a message */ -class MsgLocMetaData { +struct MsgLocMetaData { + MsgLocMetaData() = default; + MsgLocMetaData(const MsgLocMetaData& meta): msgId(meta.msgId), val(meta.val) {} -public: - MsgLocMetaData(const MsgLocMetaData& meta){ msgId = meta.msgId; val = meta.val;} - MsgLocMetaData() {} - RsGxsGrpMsgIdPair msgId; - ContentValue val; + RsGxsGrpMsgIdPair msgId; + ContentValue val; }; typedef std::map RsGxsGrpMetaTemporaryMap; @@ -63,14 +62,12 @@ typedef std::map RsGxsGrpMetaTemporaryMap; * This allows modification of local * meta data items of a group */ -class GrpLocMetaData { - -public: - GrpLocMetaData(const GrpLocMetaData& meta){ grpId = meta.grpId; val = meta.val;} - GrpLocMetaData(){} - RsGxsGroupId grpId; - ContentValue val; +struct GrpLocMetaData { + GrpLocMetaData() = default; + GrpLocMetaData(const GrpLocMetaData& meta): grpId(meta.grpId), val(meta.val) {} + RsGxsGroupId grpId; + ContentValue val; }; /*!