manager.h

00001 /* 00002 $Id: manager_8h-source.html,v 1.1 2004/10/05 21:12:02 mentat Exp $ 00003 00004 GNU Messenger - The secure instant messenger 00005 00006 Copyright (C) 1999-2001 Henrik Abelsson <henrik@abelsson.com> 00007 Copyright (C) 2002-2004 Jesse Lovelace <jesse at aslogicsys dot com> 00008 00009 This program is free software; you can redistribute it and/or modify 00010 it under the terms of the GNU General Public License as published by 00011 the Free Software Foundation; either version 2 of the License, or 00012 (at your option) any later version. 00013 00014 This program is distributed in the hope that it will be useful, 00015 but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 GNU General Public License for more details. 00018 00019 You should have received a copy of the GNU General Public License 00020 along with this program; if not, write to the Free Software 00021 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00022 */ 00023 00024 #ifndef GM_PROTOCOL_MANAGER_H 00025 #define GM_PROTOCOL_MANAGER_H 00026 00027 #include <string> 00028 #include <vector> 00029 00030 #include "gm/xml_manager.h" 00031 #include "gm/protocol.h" 00032 #include "gm/basenetwork.h" 00033 00034 namespace GNUMessenger 00035 { 00036 using namespace std; 00037 00049 class ProtocolManager 00050 { 00051 public: 00053 class InvalidContact: public Exception 00054 { 00055 public: 00056 InvalidContact(const string& str): Exception(str) {} 00057 }; 00058 00060 class InvalidNetwork: public Exception 00061 { 00062 public: 00063 InvalidNetwork(const string& str): Exception(str) {} 00064 }; 00065 00067 class NetworkError: public Exception 00068 { 00069 public: 00070 NetworkError(const string& str): Exception(str) {} 00071 }; 00072 00075 ProtocolManager(XMLManager& auth):m_auth(auth), m_shutdown(false) {} 00076 00082 virtual ~ProtocolManager(); 00083 00085 bool removeProtocol(const string& proto); 00086 00093 bool loadProtocol(const string& name); 00094 00096 void shutdown(); 00097 00099 int getState(const string &proto); 00100 00105 string screenName(const string &proto); 00106 00110 bool update(const string &proto); 00111 00114 void updateAll(); 00115 00117 bool hasProtocol(const string& name); 00118 00121 bool changeSettings(const string& proto, XMLNode& conf); 00122 00124 bool isGM(const Contact& c); 00125 00127 void forceKeyX(const Contact& c); 00128 00131 void changeCipher(const Contact& c, int cipherType, int keysize = -1, int blocksize = -1); 00132 00135 Contact getContact(const string& name); 00136 00138 list<Network*> getNets(const string &proto); 00139 00141 list<Network*> getNetsAll(); 00142 00148 bool login(const string &proto); 00149 00156 bool logout(const string &proto); 00157 00162 bool setAway(const string& proto, const string& msg); 00163 00166 void setAllAway(const string& msg); 00167 00172 bool setInfo(const string& proto, const string& info); 00173 00176 void setAllInfo(const string& info); 00177 00179 void getInfo(const Contact& contact); 00180 00189 bool sendMessage(const string& proto,const Contact& recipient, const string &message); 00190 00199 bool sendMessage(const string& proto, const Contact& recipient, const VBuffer& data); 00200 00209 bool sendMessage(const Contact& c, const string& message); 00210 00219 bool sendMessage(const Contact& c, const VBuffer& data); 00220 00223 void addContact(const Contact& c); 00224 00226 bool delContact(const string& proto, const Contact& c); 00227 00232 vector<string> protocols() const; 00233 00235 unsigned long getSentBytes(const string& proto) const; 00236 unsigned long getSentPackets(const string& proto) const; 00237 00238 unsigned long getRecvBytes(const string& proto) const; 00239 unsigned long getRecvPackets(const string& proto) const; 00240 00241 vector<string> getRemoteIPs(const string& proto) const; 00242 00243 private: 00244 00245 friend class Protocol; 00246 00248 void protoRecvdMessage(const string& proto, const Contact& c, const string& message); 00249 void protoRecvdMessageAnony(const string& proto, const Contact& c, const string& message); 00250 void protoStatusChange(const string& proto, const Contact& c); 00251 void protoError(const string& proto, int err_no, const string& error); 00252 void protoStateChange(const string &proto, Protocol::State st); 00253 void protoGotPubkey(const Contact& c, const string& key); 00254 void protoGotContacts(const string& proto, const vector<buddy>& c); 00255 void protoCustom(const string& proto, const XMLNode &n); 00256 void protoGotInfo(const Contact& c, const string& info, const string& proto); 00257 00258 protected: 00259 00262 void protoLoggedIn(const string& proto); 00263 void protoLoggedOut(const string& proto); 00264 00273 Protocol *protocol(const string &proto); 00274 00275 const Protocol * protocol(const string &proto) const; 00276 00280 virtual Network *createNet(Protocol *protocol)=0; 00281 00282 virtual NetworkServer * createServer(Protocol *protocol)=0; 00283 00285 virtual void removeNet(Network *n) { delete n; } 00286 00287 00295 bool addProtocol(Protocol * proto); 00296 00297 bool isOnline(const string& proto) const; 00298 00299 void sendEncryptedMessage(const string& proto, const Contact& c, const string& mess) {} 00300 void sendEncryptedMessage(const string& proto, const Contact& c, const VBuffer& data) {} 00301 void receiveEncryptedMessage(const string& proto, const Contact& c, const string& mess) {} 00302 void receiveEncryptedMessage(const string& proto, const Contact& c, const VBuffer& data) {} 00303 00305 virtual void c_loggedIn(const string &proto) {} 00306 virtual void c_loggedOut(const string &proto) {} 00307 virtual void c_recvdMessage(const string &proto, const Contact &c, const string &message) = 0; 00308 virtual void c_recvdMessageAnony(const string& protocol, const Contact& c, const string& message) = 0; 00309 virtual void c_statusChange(const string &proto, const Contact &c) {} 00310 virtual void c_error(const string &proto, int err_no, const string &error) {} 00311 virtual void c_stateChange(const string &proto, Protocol::State st) {} 00312 virtual void c_gotPubkey(const Contact& c, const string &key) {} 00313 virtual void c_gotBuddy(const string &proto, const Contact &c) {} 00314 virtual void c_gotContacts(const string& proto, const vector<buddy>& c) {} 00315 virtual void c_custom(const string &proto, const XMLNode &n) {} 00316 virtual void c_gotInfo(const Contact& c, const string& info, const string& proto) {} 00317 00318 XMLManager& m_auth; 00319 00320 private: 00321 // lists all enabled protocols, no necc logged in 00322 map<string, Protocol *> m_provider; 00323 00324 // lists only the protocols that are logged in and ready to go 00325 map<string, bool> m_online; 00326 00327 // has shutdown been called? @todo this could fck up if we add stuff 00328 // after a shutdown... 00329 bool m_shutdown; 00330 }; 00331 00332 } // !GNUMessenger 00333 00334 #endif // !GM_PROTOCOL_MANAGER

Generated on Tue Oct 5 14:41:47 2004 for GNU Messenger by doxygen 1.3.8