diff --git a/libretroshare/src/retroshare/rsplugin.h b/libretroshare/src/retroshare/rsplugin.h index 81fc45bbb..83abec566 100644 --- a/libretroshare/src/retroshare/rsplugin.h +++ b/libretroshare/src/retroshare/rsplugin.h @@ -42,6 +42,7 @@ class RsTurtle ; class RsDht ; class RsDisc ; class RsMsgs ; +class RsForums; class p3LinkMgr ; class MainPage ; class QIcon ; @@ -98,6 +99,7 @@ public: RsTurtle *mTurtle; RsDisc *mDisc; RsDht *mDht; + RsForums *mForums; }; class RsPlugin diff --git a/libretroshare/src/rsserver/rsinit.cc b/libretroshare/src/rsserver/rsinit.cc index 3c2f5dee8..017412ae9 100644 --- a/libretroshare/src/rsserver/rsinit.cc +++ b/libretroshare/src/rsserver/rsinit.cc @@ -2222,18 +2222,6 @@ int RsServer::StartupRetroShare() rsDisc = new p3Discovery(ad); rsMsgs = new p3Msgs(msgSrv, chatSrv); - // set interfaces for plugins - // - RsPlugInInterfaces interfaces; - interfaces.mFiles = rsFiles; - interfaces.mPeers = rsPeers; - interfaces.mMsgs = rsMsgs; - interfaces.mTurtle = rsTurtle; - interfaces.mDisc = rsDisc; - interfaces.mDht = rsDht; - - mPluginsManager->setInterfaces(interfaces); - // connect components to turtle router. ftserver->connectToTurtleRouter(tr) ; @@ -2264,6 +2252,20 @@ int RsServer::StartupRetroShare() pqih -> addService(mBlogs); /* This must be also ticked as a service */ #endif + + // set interfaces for plugins + // + RsPlugInInterfaces interfaces; + interfaces.mFiles = rsFiles; + interfaces.mPeers = rsPeers; + interfaces.mMsgs = rsMsgs; + interfaces.mTurtle = rsTurtle; + interfaces.mDisc = rsDisc; + interfaces.mDht = rsDht; + interfaces.mForums = mForums; + + mPluginsManager->setInterfaces(interfaces); + // now add plugin objects inside the loop: // - client services provided by plugins. // - cache services provided by plugins. diff --git a/plugins/FeedReader/FeedReaderPlugin.cpp b/plugins/FeedReader/FeedReaderPlugin.cpp index be1cc88b7..8efae4674 100644 --- a/plugins/FeedReader/FeedReaderPlugin.cpp +++ b/plugins/FeedReader/FeedReaderPlugin.cpp @@ -83,8 +83,9 @@ FeedReaderPlugin::FeedReaderPlugin() mFeedNotify = NULL; } -void FeedReaderPlugin::setInterfaces(RsPlugInInterfaces &/*interfaces*/) +void FeedReaderPlugin::setInterfaces(RsPlugInInterfaces &interfaces) { + mInterfaces = interfaces; } ConfigPage *FeedReaderPlugin::qt_config_page() const @@ -112,7 +113,7 @@ FeedNotify *FeedReaderPlugin::qt_feedNotify() RsPQIService *FeedReaderPlugin::rs_pqi_service() const { if (mFeedReader == NULL) { - mFeedReader = new p3FeedReader(mPlugInHandler); + mFeedReader = new p3FeedReader(mPlugInHandler, mInterfaces.mForums); rsFeedReader = mFeedReader; mNotify = new FeedReaderNotify(); diff --git a/plugins/FeedReader/FeedReaderPlugin.h b/plugins/FeedReader/FeedReaderPlugin.h index bc268c8cb..4b1799925 100644 --- a/plugins/FeedReader/FeedReaderPlugin.h +++ b/plugins/FeedReader/FeedReaderPlugin.h @@ -56,6 +56,7 @@ public: virtual FeedNotify *qt_feedNotify(); private: + RsPlugInInterfaces mInterfaces; mutable p3FeedReader *mFeedReader; mutable FeedReaderNotify *mNotify; mutable RsPluginHandler *mPlugInHandler; diff --git a/plugins/FeedReader/services/p3FeedReader.cc b/plugins/FeedReader/services/p3FeedReader.cc index cfd589c53..60d9a836a 100644 --- a/plugins/FeedReader/services/p3FeedReader.cc +++ b/plugins/FeedReader/services/p3FeedReader.cc @@ -36,7 +36,7 @@ RsFeedReader *rsFeedReader = NULL; * #define FEEDREADER_DEBUG *********/ -p3FeedReader::p3FeedReader(RsPluginHandler* pgHandler) +p3FeedReader::p3FeedReader(RsPluginHandler* pgHandler, RsForums *forums) : RsPQIService(RS_SERVICE_TYPE_PLUGIN_FEEDREADER, CONFIG_TYPE_FEEDREADER, 5, pgHandler), mFeedReaderMtx("p3FeedReader"), mDownloadMutex("p3FeedReaderDownload"), mProcessMutex("p3FeedReaderProcess"), mPreviewMutex("p3FeedReaderPreview") { @@ -49,6 +49,7 @@ p3FeedReader::p3FeedReader(RsPluginHandler* pgHandler) mStandardUseProxy = false; mStandardProxyPort = 0; mLastClean = 0; + mForums = forums; mNotify = NULL; mSaveInBackground = false; @@ -525,11 +526,15 @@ RsFeedAddResult p3FeedReader::setFeed(const std::string &feedId, const FeedInfo } if (!forumId.empty()) { - /* name or description changed, update forum */ - if (!rsForums->setForumInfo(forumId, forumInfo)) { + if (mForums) { + /* name or description changed, update forum */ + if (!mForums->setForumInfo(forumId, forumInfo)) { #ifdef FEEDREADER_DEBUG - std::cerr << "p3FeedReader::setFeed - can't change forum " << forumId << std::endl; + std::cerr << "p3FeedReader::setFeed - can't change forum " << forumId << std::endl; #endif + } + } else { + std::cerr << "p3FeedReader::setFeed - can't change forum " << forumId << ", member mForums is not set" << std::endl; } } @@ -1836,55 +1841,59 @@ void p3FeedReader::onProcessSuccess_addMsgs(const std::string &feedId, std::list RsFeedReaderErrorState errorState = RS_FEED_ERRORSTATE_OK; if (forum && !msgs.empty()) { - if (fi->forumId.empty()) { - /* create new forum */ - std::wstring forumName; - librs::util::ConvertUtf8ToUtf16(fi->name, forumName); - forumName.insert(0, FEEDREADER_FORUM_PREFIX); + if (mForums) { + if (fi->forumId.empty()) { + /* create new forum */ + std::wstring forumName; + librs::util::ConvertUtf8ToUtf16(fi->name, forumName); + forumName.insert(0, FEEDREADER_FORUM_PREFIX); - long todo; // search for existing forum? + long todo; // search for existing forum? - /* search for existing own forum */ -// std::list forumList; -// if (rsForums->getForumList(forumList)) { -// std::wstring wName = StringToWString(name); -// for (std::list::iterator it = forumList.begin(); it != forumList.end(); ++it) { -// if (it->forumName == wName) { -// std::cout << "DEBUG_RSS2FORUM: Found existing forum " << it->forumId << " for " << name << std::endl; -// return it->forumId; + /* search for existing own forum */ +// std::list forumList; +// if (mForums->getForumList(forumList)) { +// std::wstring wName = StringToWString(name); +// for (std::list::iterator it = forumList.begin(); it != forumList.end(); ++it) { +// if (it->forumName == wName) { +// std::cout << "DEBUG_RSS2FORUM: Found existing forum " << it->forumId << " for " << name << std::endl; +// return it->forumId; +// } // } // } -// } - std::wstring forumDescription; - librs::util::ConvertUtf8ToUtf16(fi->description, forumDescription); - /* create anonymous public forum */ - fi->forumId = rsForums->createForum(forumName, forumDescription, RS_DISTRIB_PUBLIC | RS_DISTRIB_AUTHEN_ANON); - forumId = fi->forumId; + std::wstring forumDescription; + librs::util::ConvertUtf8ToUtf16(fi->description, forumDescription); + /* create anonymous public forum */ + fi->forumId = mForums->createForum(forumName, forumDescription, RS_DISTRIB_PUBLIC | RS_DISTRIB_AUTHEN_ANON); + forumId = fi->forumId; - if (fi->forumId.empty()) { - errorState = RS_FEED_ERRORSTATE_PROCESS_FORUM_CREATE; + if (fi->forumId.empty()) { + errorState = RS_FEED_ERRORSTATE_PROCESS_FORUM_CREATE; #ifdef FEEDREADER_DEBUG - std::cerr << "p3FeedReader::onProcessSuccess_filterMsg - can't create forum for feed " << feedId << " (" << fi->name << ") - ignore all messages" << std::endl; - } else { - std::cerr << "p3FeedReader::onProcessSuccess_filterMsg - forum " << fi->forumId << " (" << fi->name << ") created" << std::endl; -#endif - } - } else { - /* check forum */ - ForumInfo forumInfo; - if (rsForums->getForumInfo(fi->forumId, forumInfo)) { - if ((forumInfo.subscribeFlags & RS_DISTRIB_ADMIN) == 0) { - errorState = RS_FEED_ERRORSTATE_PROCESS_FORUM_NO_ADMIN; - } else if ((forumInfo.forumFlags & RS_DISTRIB_AUTHEN_REQ) || (forumInfo.forumFlags & RS_DISTRIB_AUTHEN_ANON) == 0) { - errorState = RS_FEED_ERRORSTATE_PROCESS_FORUM_NOT_ANONYMOUS; + std::cerr << "p3FeedReader::onProcessSuccess_filterMsg - can't create forum for feed " << feedId << " (" << fi->name << ") - ignore all messages" << std::endl; } else { - forumId = fi->forumId; + std::cerr << "p3FeedReader::onProcessSuccess_filterMsg - forum " << fi->forumId << " (" << fi->name << ") created" << std::endl; +#endif } } else { - errorState = RS_FEED_ERRORSTATE_PROCESS_FORUM_NOT_FOUND; + /* check forum */ + ForumInfo forumInfo; + if (mForums->getForumInfo(fi->forumId, forumInfo)) { + if ((forumInfo.subscribeFlags & RS_DISTRIB_ADMIN) == 0) { + errorState = RS_FEED_ERRORSTATE_PROCESS_FORUM_NO_ADMIN; + } else if ((forumInfo.forumFlags & RS_DISTRIB_AUTHEN_REQ) || (forumInfo.forumFlags & RS_DISTRIB_AUTHEN_ANON) == 0) { + errorState = RS_FEED_ERRORSTATE_PROCESS_FORUM_NOT_ANONYMOUS; + } else { + forumId = fi->forumId; + } + } else { + errorState = RS_FEED_ERRORSTATE_PROCESS_FORUM_NOT_FOUND; + } } + } else { + std::cerr << "p3FeedReader::onProcessSuccess_addMsgs - can't process forum, member mForums is not set" << std::endl; } } @@ -1938,31 +1947,35 @@ void p3FeedReader::onProcessSuccess_addMsgs(const std::string &feedId, std::list } if (!forumId.empty() && !forumMsgs.empty()) { - /* add messages as forum messages */ - std::list::iterator msgIt; - for (msgIt = forumMsgs.begin(); msgIt != forumMsgs.end(); ++msgIt) { - RsFeedReaderMsg &mi = *msgIt; + if (mForums) { + /* add messages as forum messages */ + std::list::iterator msgIt; + for (msgIt = forumMsgs.begin(); msgIt != forumMsgs.end(); ++msgIt) { + RsFeedReaderMsg &mi = *msgIt; - /* convert to forum messages */ - ForumMsgInfo forumMsgInfo; - forumMsgInfo.forumId = forumId; - librs::util::ConvertUtf8ToUtf16(mi.title, forumMsgInfo.title); + /* convert to forum messages */ + ForumMsgInfo forumMsgInfo; + forumMsgInfo.forumId = forumId; + librs::util::ConvertUtf8ToUtf16(mi.title, forumMsgInfo.title); - std::string description = mi.descriptionTransformed.empty() ? mi.description : mi.descriptionTransformed; - /* add link */ - if (!mi.link.empty()) { - description += "
" + mi.link + ""; - } - librs::util::ConvertUtf8ToUtf16(description, forumMsgInfo.msg); + std::string description = mi.descriptionTransformed.empty() ? mi.description : mi.descriptionTransformed; + /* add link */ + if (!mi.link.empty()) { + description += "
" + mi.link + ""; + } + librs::util::ConvertUtf8ToUtf16(description, forumMsgInfo.msg); - if (rsForums->ForumMessageSend(forumMsgInfo)) { - /* set to new */ - rsForums->setMessageStatus(forumMsgInfo.forumId, forumMsgInfo.msgId, 0, FORUM_MSG_STATUS_MASK); - } else { + if (mForums->ForumMessageSend(forumMsgInfo)) { + /* set to new */ + mForums->setMessageStatus(forumMsgInfo.forumId, forumMsgInfo.msgId, 0, FORUM_MSG_STATUS_MASK); + } else { #ifdef FEEDREADER_DEBUG - std::cerr << "p3FeedReader::onProcessSuccess_filterMsg - can't add forum message " << mi.title << " for feed " << forumId << std::endl; + std::cerr << "p3FeedReader::onProcessSuccess_filterMsg - can't add forum message " << mi.title << " for feed " << forumId << std::endl; #endif + } } + } else { + std::cerr << "p3FeedReader::onProcessSuccess_addMsgs - can't process forum, member mForums is not set" << std::endl; } } @@ -2070,23 +2083,27 @@ void p3FeedReader::setFeedInfo(const std::string &feedId, const std::string &nam } if (!forumId.empty()) { - ForumInfo forumInfo; - if (rsForums->getForumInfo(forumId, forumInfo)) { - if (forumInfo.forumName != forumInfoNew.forumName || forumInfo.forumDesc != forumInfoNew.forumDesc) { - /* name or description changed, update forum */ + if (mForums) { + ForumInfo forumInfo; + if (mForums->getForumInfo(forumId, forumInfo)) { + if (forumInfo.forumName != forumInfoNew.forumName || forumInfo.forumDesc != forumInfoNew.forumDesc) { + /* name or description changed, update forum */ #ifdef FEEDREADER_DEBUG - std::cerr << "p3FeedReader::setFeed - change forum " << forumId << std::endl; + std::cerr << "p3FeedReader::setFeed - change forum " << forumId << std::endl; #endif - if (!rsForums->setForumInfo(forumId, forumInfoNew)) { + if (!mForums->setForumInfo(forumId, forumInfoNew)) { #ifdef FEEDREADER_DEBUG - std::cerr << "p3FeedReader::setFeed - can't change forum " << forumId << std::endl; + std::cerr << "p3FeedReader::setFeed - can't change forum " << forumId << std::endl; #endif + } } + } else { +#ifdef FEEDREADER_DEBUG + std::cerr << "p3FeedReader::setFeed - can't get forum info " << forumId << std::endl; +#endif } } else { -#ifdef FEEDREADER_DEBUG - std::cerr << "p3FeedReader::setFeed - can't get forum info " << forumId << std::endl; -#endif + std::cerr << "p3FeedReader::setFeedInfo - can't process forum, member mForums is not set" << std::endl; } } } diff --git a/plugins/FeedReader/services/p3FeedReader.h b/plugins/FeedReader/services/p3FeedReader.h index 61c933564..cd2c8859d 100644 --- a/plugins/FeedReader/services/p3FeedReader.h +++ b/plugins/FeedReader/services/p3FeedReader.h @@ -33,7 +33,7 @@ class p3FeedReaderThread; class p3FeedReader : public RsPQIService, public RsFeedReader { public: - p3FeedReader(RsPluginHandler *pgHandler); + p3FeedReader(RsPluginHandler *pgHandler, RsForums *forums); /****************** FeedReader Interface *************/ virtual void stop(); @@ -97,6 +97,7 @@ private: void stopPreviewThreads_locked(); time_t mLastClean; + RsForums *mForums; RsFeedReaderNotify *mNotify; RsMutex mFeedReaderMtx;