00001 /* Copyright (C) 2006-2008 by Marc Maurer <uwog@uwog.net> 00002 * 00003 * This program is free software; you can redistribute it and/or 00004 * modify it under the terms of the GNU General Public License 00005 * as published by the Free Software Foundation; either version 2 00006 * of the License, or (at your option) any later version. 00007 * 00008 * This program is distributed in the hope that it will be useful, 00009 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00011 * GNU General Public License for more details. 00012 * 00013 * You should have received a copy of the GNU General Public License 00014 * along with this program; if not, write to the Free Software 00015 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 00016 * 02110-1301 USA. 00017 */ 00018 00019 #ifndef __TCPACCOUNTHANDLER__ 00020 #define __TCPACCOUNTHANDLER__ 00021 00022 #include <boost/shared_ptr.hpp> 00023 #include <core/account/xp/AccountHandler.h> 00024 00025 #include "IOServerHandler.h" 00026 #include "TCPBuddy.h" 00027 00028 #define DEFAULT_TCP_PORT 25509 /* log2(e + pi) * 10^4 */ 00029 00030 extern AccountHandlerConstructor TCPAccountHandlerConstructor; 00031 00032 class TCPAccountHandler : public AccountHandler 00033 { 00034 public: 00035 TCPAccountHandler(); 00036 virtual ~TCPAccountHandler(); 00037 00038 // housekeeping 00039 static UT_UTF8String getStaticStorageType(); 00040 virtual UT_UTF8String getStorageType() 00041 { return getStaticStorageType(); } 00042 virtual UT_UTF8String getDescription(); 00043 virtual UT_UTF8String getDisplayType(); 00044 00045 // dialog management 00046 virtual void storeProperties(); 00047 00048 // connection management 00049 virtual ConnectResult connect(); 00050 virtual bool disconnect(); 00051 virtual bool isOnline(); 00052 00053 // user management 00054 void addBuddy(BuddyPtr pBuddy); 00055 virtual BuddyPtr constructBuddy(const PropertyMap& props); 00056 virtual BuddyPtr constructBuddy(const std::string& descriptor, BuddyPtr pBuddy); 00057 virtual bool recognizeBuddyIdentifier(const std::string& identifier); 00058 virtual bool allowsManualBuddies() 00059 { return false; } 00060 virtual void forceDisconnectBuddy(BuddyPtr buddy); 00061 virtual bool hasPersistentAccessControl() 00062 { return false; } 00063 virtual bool defaultShareState(BuddyPtr /*pBuddy*/); 00064 00065 // session management 00066 virtual bool allowsSessionTakeover() 00067 { return false; } 00068 00069 // packet management 00070 virtual bool send(const Packet* packet); 00071 virtual bool send(const Packet*, BuddyPtr pBuddy); 00072 00073 // event management 00074 void handleEvent(boost::shared_ptr<Session> session_ptr); 00075 00076 private: 00077 void _teardownAndDestroyHandler(); 00078 void _handleMessages(boost::shared_ptr<Session> session_ptr); 00079 00080 // user management 00081 TCPBuddyPtr _getBuddy(boost::shared_ptr<Session> session_ptr); 00082 00083 // connection management 00084 virtual UT_sint32 _getPort(const PropertyMap& props); 00085 void _handleAccept(IOServerHandler* pHandler, boost::shared_ptr<Session> session); 00086 00087 asio::io_service m_io_service; 00088 asio::io_service::work m_work; 00089 asio::thread* m_thread; 00090 bool m_bConnected; // TODO: drop this, ask the IO handler 00091 IOServerHandler* m_pDelegator; 00092 00093 std::map<TCPBuddyPtr, boost::shared_ptr<Session> > m_clients; // mapping buddies and their accompanying session 00094 }; 00095 00096 #endif /* __TCPACCOUNTHANDLER__ */