diff --git a/libretroshare/src/_rsserver/p3blog.cc b/libretroshare/src/_rsserver/p3blog.cc new file mode 100644 index 000000000..f071fafb5 --- /dev/null +++ b/libretroshare/src/_rsserver/p3blog.cc @@ -0,0 +1,62 @@ +/* + * libretroshare/src/rsserver: p3blog.cc + * + * RetroShare C++ Interface. + * + * Copyright 2007-2008 by Chris Evi-Parker. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License Version 2 as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA. + * + * Please report all bugs and problems to "retroshare@lunamutt.com". + * + */ + +#include "_rsserver/p3Blog.h" + +RsQblog* rsQblog = NULL; + +p3Blog::p3Blog(p3Qblog* qblog) : + mQblog(qblog) +{ + return; +} + +p3Blog::~p3Blog() +{ + return; +} + +bool p3Blog::getBlogs(std::map< std::string, std::multimap > &blogs) +{ + return mQblog->getBlogs(blogs); +} + + + +bool p3Blog::sendBlog(const std::wstring &msg) +{ + return mQblog->sendBlog(msg); +} + +bool p3Blog::getPeerLatestBlog(std::string id, uint32_t &ts, std::wstring &post) +{ + //return mQblog->getPeerLatestBlog(id, ts, post); + 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 ;)"; + + return true; + +} + diff --git a/libretroshare/src/_rsserver/p3blog.h b/libretroshare/src/_rsserver/p3blog.h new file mode 100644 index 000000000..fb6b36a1e --- /dev/null +++ b/libretroshare/src/_rsserver/p3blog.h @@ -0,0 +1,57 @@ + + + +#ifndef P3BLOG_H_ +#define P3BLOG_H_ + +/* + * libretroshare/src/rsserver: p3blog.h + * + * RetroShare C++ Interface. + * + * Copyright 2007-2008 by Chris Evi-Parker. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License Version 2 as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA. + * + * Please report all bugs and problems to "retroshare@lunamutt.com". + * + */ + +#include "_rsiface/rsQblog.h" +#include "services/p3Qblog.h" + +/*! + * Interface class using composition (p3Qblog is an attribute) + * See derived class for documentation of derived functions + */ +class p3Blog : public RsQblog +{ + public: + + p3Blog(p3Qblog* qblog); + virtual ~p3Blog(); + + virtual bool sendBlog(const std::wstring &msg); + virtual bool getBlogs(std::map< std::string, std::multimap > &blogs); + virtual bool getPeerLatestBlog(std::string id, uint32_t &ts, std::wstring &post); + + private: + + /// to make rsCore blog-service calls + p3Qblog* mQblog; +}; + + +#endif /*P3BLOG_H_*/ diff --git a/libretroshare/src/_rsserver/p3discovery.cc b/libretroshare/src/_rsserver/p3discovery.cc new file mode 100644 index 000000000..ed636e4df --- /dev/null +++ b/libretroshare/src/_rsserver/p3discovery.cc @@ -0,0 +1,59 @@ +/* + * libretroshare/src/rsserver: p3discovery.cc + * + * RetroShare C++ Interface. + * + * Copyright 2008-2008 by Robert Fernie. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License Version 2 as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA. + * + * Please report all bugs and problems to "retroshare@lunamutt.com". + * + */ + +#include "_rsserver/p3discovery.h" +#include +#include + +RsDisc *rsDisc = NULL; + +p3Discovery::p3Discovery(p3disc *disc): + mDisc(disc) +{ +} + +p3Discovery::~p3Discovery() +{ +} + +bool p3Discovery::getDiscFriends(std::string id, std::list &friends) +{ + if (mDisc) + { + return mDisc->potentialproxies(id, friends); + } + return false; +} + +bool p3Discovery::getDiscVersions(std::map &versions) +{ + if (mDisc) + { + mDisc->getversions(versions); + return true; + } + return false; +} + diff --git a/libretroshare/src/_rsserver/p3discovery.h b/libretroshare/src/_rsserver/p3discovery.h new file mode 100644 index 000000000..ea5a1eb3a --- /dev/null +++ b/libretroshare/src/_rsserver/p3discovery.h @@ -0,0 +1,47 @@ +#ifndef P3DISCOVERY_H +#define P3DISCOVERY_H + +/* + * libretroshare/src/rsserver: p3discovery.h + * + * RetroShare C++ Interface. + * + * Copyright 2008-2008 by Robert Fernie. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License Version 2 as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA. + * + * Please report all bugs and problems to "retroshare@lunamutt.com". + * + */ + +#include "_rsiface/rsdisc.h" +#include "services/p3disc.h" + +class p3Discovery: public RsDisc +{ +public: + p3Discovery(p3disc *disc); + virtual ~p3Discovery(); + + virtual bool getDiscFriends(std::string id, std::list &friends); + virtual bool getDiscVersions(std::map &versions); + +private: + + p3disc *mDisc; +}; + +#endif + diff --git a/libretroshare/src/_rsserver/p3face.cc b/libretroshare/src/_rsserver/p3face.cc new file mode 100644 index 000000000..90e342ae4 --- /dev/null +++ b/libretroshare/src/_rsserver/p3face.cc @@ -0,0 +1,239 @@ +/* + * "$Id: p3face-msgs.cc,v 1.7 2007-05-05 16:10:06 rmf24 Exp $" + * + * RetroShare C++ Interface. + * + * Copyright 2004-2006 by Robert Fernie. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License Version 2 as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA. + * + * Please report all bugs and problems to "retroshare@lunamutt.com". + * + */ + + +#include "p3face.h" +#include "util/rsdir.h" + +#include +#include + +#include "util/rsdebug.h" + + +#include +#include + +const int p3facemsgzone = 11453; + +void RsServer::lockRsCore() +{ + // std::cerr << "RsServer::lockRsCore()" << std::endl; + coreMutex.lock(); +} + +void RsServer::unlockRsCore() +{ + // std::cerr << "RsServer::unlockRsCore()" << std::endl; + coreMutex.unlock(); +} + + /* Flagging Persons / Channels / Files in or out of a set (CheckLists) */ +int RsServer::ClearInChat() +{ + lockRsCore(); /* LOCK */ + + mInChatList.clear(); + + unlockRsCore(); /* UNLOCK */ + + return 1; +} + + +/* Flagging Persons / Channels / Files in or out of a set (CheckLists) */ +int RsServer::SetInChat(std::string id, bool in) /* friend : chat msgs */ +{ + /* so we send this.... */ + lockRsCore(); /* LOCK */ + + //std::cerr << "Set InChat(" << id << ") to " << (in ? "True" : "False") << std::endl; + std::list::iterator it; + it = std::find(mInChatList.begin(), mInChatList.end(), id); + if (it == mInChatList.end()) + { + if (in) + { + mInChatList.push_back(id); + } + } + else + { + if (!in) + { + mInChatList.erase(it); + } + } + + unlockRsCore(); /* UNLOCK */ + + return 1; +} + + +int RsServer::ClearInMsg() +{ + lockRsCore(); /* LOCK */ + + mInMsgList.clear(); + + unlockRsCore(); /* UNLOCK */ + + return 1; +} + + +int RsServer::SetInMsg(std::string id, bool in) /* friend : msgs */ +{ + /* so we send this.... */ + lockRsCore(); /* LOCK */ + + //std::cerr << "Set InMsg(" << id << ") to " << (in ? "True" : "False") << std::endl; + std::list::iterator it; + it = std::find(mInMsgList.begin(), mInMsgList.end(), id); + if (it == mInMsgList.end()) + { + if (in) + { + mInMsgList.push_back(id); + } + } + else + { + if (!in) + { + mInMsgList.erase(it); + } + } + + unlockRsCore(); /* UNLOCK */ + return 1; +} + +bool RsServer::IsInChat(std::string id) /* friend : chat msgs */ +{ + /* so we send this.... */ + lockRsCore(); /* LOCK */ + + std::list::iterator it; + it = std::find(mInChatList.begin(), mInChatList.end(), id); + bool inChat = (it != mInChatList.end()); + + unlockRsCore(); /* UNLOCK */ + + return inChat; +} + + +bool RsServer::IsInMsg(std::string id) /* friend : msg recpts*/ +{ + /* so we send this.... */ + lockRsCore(); /* LOCK */ + + std::list::iterator it; + it = std::find(mInMsgList.begin(), mInMsgList.end(), id); + bool inMsg = (it != mInMsgList.end()); + + unlockRsCore(); /* UNLOCK */ + + return inMsg; +} + + + + +int RsServer::ClearInBroadcast() +{ + return 1; +} + +int RsServer::ClearInSubscribe() +{ + return 1; +} + +int RsServer::SetInBroadcast(std::string id, bool in) /* channel : channel broadcast */ +{ + return 1; +} + +int RsServer::SetInSubscribe(std::string id, bool in) /* channel : subscribed channels */ +{ + return 1; +} + +int RsServer::ClearInRecommend() +{ + /* find in people ... set chat flag */ + RsIface &iface = getIface(); + iface.lockData(); /* LOCK IFACE */ + + std::list &recs = iface.mRecommendList; + std::list::iterator it; + + for(it = recs.begin(); it != recs.end(); it++) + { + it -> inRecommend = false; + } + + iface.unlockData(); /* UNLOCK IFACE */ + + return 1; +} + + +int RsServer::SetInRecommend(std::string id, bool in) /* file : recommended file */ +{ + /* find in people ... set chat flag */ + RsIface &iface = getIface(); + iface.lockData(); /* LOCK IFACE */ + + std::list &recs = iface.mRecommendList; + std::list::iterator it; + + for(it = recs.begin(); it != recs.end(); it++) + { + if (it -> fname == id) + { + /* set flag */ + it -> inRecommend = in; + //std::cerr << "Set InRecommend (" << id << ") to " << (in ? "True" : "False") << std::endl; + } + } + + iface.unlockData(); /* UNLOCK IFACE */ + + return 1; +} + +std::string make_path_unix(std::string path) +{ + for(unsigned int i = 0; i < path.length(); i++) + { + if (path[i] == '\\') + path[i] = '/'; + } + return path; +} diff --git a/libretroshare/src/_rsserver/p3face.h b/libretroshare/src/_rsserver/p3face.h new file mode 100644 index 000000000..052cf30e7 --- /dev/null +++ b/libretroshare/src/_rsserver/p3face.h @@ -0,0 +1,181 @@ +#ifndef P3FACE_H +#define P3FACE_H + +/* + * "$Id: p3face.h,v 1.9 2007-05-05 16:10:06 rmf24 Exp $" + * + * RetroShare C++ Interface. + * + * Copyright 2004-2006 by Robert Fernie. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License Version 2 as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA. + * + * Please report all bugs and problems to "retroshare@lunamutt.com". + * + */ + +//#include "server/filedexserver.h" +#include "ft/ftserver.h" +//#include "pqi/pqissl.h" + +#include "pqi/p3cfgmgr.h" +#include "pqi/p3connmgr.h" +#include "pqi/pqipersongrp.h" + +#include "_rsiface/rsiface.h" +#include "_rsiface/rstypes.h" +#include "util/rsthreads.h" + +#include "services/p3disc.h" +#include "services/p3msgservice.h" +#include "services/p3chatservice.h" +#include "services/p3ranking.h" +#include "services/p3Qblog.h" + +/* The Main Interface Class - for controlling the server */ + +/* The init functions are actually Defined in p3face-startup.cc + */ +//RsInit *InitRsConfig(); +//void CleanupRsConfig(RsInit *); +//int InitRetroShare(int argc, char **argv, RsInit *config); +//int LoadCertificates(RsInit *config); + +RsControl *createRsControl(RsIface &iface, NotifyBase ¬ify); + + +class RsServer: public RsControl, public RsThread +{ +public: + /****************************************/ + /* p3face-startup.cc: init... */ + virtual int StartupRetroShare(); + + public: + /****************************************/ + /* p3face.cc: main loop / util fns / locking. */ + + RsServer(RsIface &i, NotifyBase &callback); + virtual ~RsServer(); + + /* Thread Fn: Run the Core */ + virtual void run(); + +public: // no longer private:!!! + /* locking stuff */ + void lockRsCore(); + + void unlockRsCore(); + +private: + + /* mutex */ + RsMutex coreMutex; + + /* General Internal Helper Functions + (Must be Locked) + */ +#if 0 + cert *intFindCert(RsCertId id); + RsCertId intGetCertId(cert *c); +#endif + + /****************************************/ + /****************************************/ + /* p3face-msg Operations */ + +public: + virtual const std::string& certificateFileName() ; + + /* Flagging Persons / Channels / Files in or out of a set (CheckLists) */ + virtual int SetInChat(std::string id, bool in); /* friend : chat msgs */ + virtual int SetInMsg(std::string id, bool in); /* friend : msg receipients */ + virtual int SetInBroadcast(std::string id, bool in); /* channel : channel broadcast */ + virtual int SetInSubscribe(std::string id, bool in); /* channel : subscribed channels */ + virtual int SetInRecommend(std::string id, bool in); /* file : recommended file */ + virtual int ClearInChat(); + virtual int ClearInMsg(); + virtual int ClearInBroadcast(); + virtual int ClearInSubscribe(); + virtual int ClearInRecommend(); + + virtual bool IsInChat(std::string id); /* friend : chat msgs */ + virtual bool IsInMsg(std::string id); /* friend : msg recpts*/ + + +private: + + std::list mInChatList, mInMsgList; + + void initRsMI(RsMsgItem *msg, MessageInfo &mi); + + /****************************************/ + /****************************************/ + /****************************************/ +public: + /* Config */ + + virtual int ConfigGetDataRates(float &inKb, float &outKb); + virtual int ConfigSetDataRates( int totalDownload, int totalUpload ); + virtual int ConfigSetBootPrompt( bool on ); + + virtual void ConfigFinalSave( ); + /************* Rs shut down function: in upnp 'port lease time' bug *****************/ + + /** + * This function is responsible for ensuring Retroshare exits in a legal state: + * i.e. releases all held resources and saves current configuration + */ + virtual void rsGlobalShutDown( ); +private: + int UpdateAllConfig(); + + /****************************************/ +private: + + // The real Server Parts. + //filedexserver *server; + ftServer *ftserver; + + p3ConnectMgr *mConnMgr; + p3AuthMgr *mAuthMgr; + + pqipersongrp *pqih; + + //sslroot *sslr; + + /* services */ + p3disc *ad; + p3MsgService *msgSrv; + p3ChatService *chatSrv; + + /* caches (that need ticking) */ + p3Ranking *mRanking; + p3Qblog *mQblog; + + /* Config */ + p3ConfigMgr *mConfigMgr; + p3GeneralConfig *mGeneralConfig; + + // Worker Data..... +}; + +/* Helper function to convert windows paths + * into unix (ie switch \ to /) for FLTK's file chooser + */ + +std::string make_path_unix(std::string winpath); + +#endif diff --git a/libretroshare/src/_rsserver/rsserver.pri b/libretroshare/src/_rsserver/rsserver.pri new file mode 100644 index 000000000..d18a1a735 --- /dev/null +++ b/libretroshare/src/_rsserver/rsserver.pri @@ -0,0 +1,10 @@ +INCLUDEPATH += $$PWD \ + ../$$PWP +DEPENDPATH += $$PWD +HEADERS = $$PWP/p3face.h \ + $$PWP/p3blog.h \ + $$PWP/p3discovery.h + +SOURCES += p3face.cc \ + $$PWP/p3blog.cc \ + $$PWP/p3discovery.cc diff --git a/libretroshare/src/libretroshare.pro b/libretroshare/src/libretroshare.pro index 4c0de6198..d8605fb07 100644 --- a/libretroshare/src/libretroshare.pro +++ b/libretroshare/src/libretroshare.pro @@ -1,4 +1,5 @@ include(_rsiface/rsiface.pri) +include(_rsserver/rsserver.pri) TEMPLATE = lib CONFIG += static TARGET = retroshare