protocol.h

00001 /* 00002 $Id: protocol_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 PROTOCOL_H 00025 #define PROTOCOL_H 00026 00027 #include <string> 00028 #include <list> 00029 #include "gm/exception.h" 00030 #include "gm/xmlnode.h" 00031 #include "gm/contact.h" 00032 00033 namespace GNUMessenger 00034 { 00035 00036 using namespace std; 00037 00038 class ProtocolManager; 00039 class Network; 00040 class Folder; 00041 class VBuffer; 00042 00044 struct buddy { 00045 string name; 00046 string group; 00047 string proto; 00048 }; 00049 00061 class Protocol 00062 { 00063 public: 00064 00066 class InvalidLogin: public Exception 00067 { 00068 public: 00069 InvalidLogin(const string& msg):Exception(msg) {} 00070 }; 00071 00073 class ProtocolError: public Exception 00074 { 00075 public: 00076 ProtocolError(const string& msg):Exception(msg) {} 00077 }; 00078 00079 enum Errors { E_invalidLogin, E_userTaken, E_protocol, E_network, E_success }; 00080 enum State { S_offline = 0, S_invalid, S_online, S_connecting, S_disconnecting }; 00081 enum Status { S_available, S_away, S_na, S_occupied, S_dnd, S_ffc, S_off }; 00082 00088 Protocol(const XMLNode &xml, ProtocolManager *manager, const string &name); 00089 00095 virtual ~Protocol(); 00096 00101 virtual void changeSettings(XMLNode& conf); 00102 00108 virtual void reset() = 0; 00109 00114 virtual inline State getState() const {return m_state;} 00115 00120 virtual inline Status getStatus() const {return m_status;} 00121 00125 virtual inline const string& getProtocol() { return m_name; } 00126 00130 virtual const string getLoginName()=0; 00131 00136 virtual void update() {} 00137 00144 virtual void login()=0; 00145 00150 virtual void logout() = 0; 00151 00152 virtual void shutdown() = 0; 00153 00164 virtual bool sendMessage(const Contact &recipient, const string &message)=0; 00165 00177 virtual bool sendMessage(const Contact &recipient, const VBuffer& data) { return false; } 00178 00179 virtual void addContact(const Contact &contact)=0; 00180 virtual void delContact(const Contact &contact)=0; 00181 00182 virtual void newUser(const string& userName, const VBuffer& password)=0; 00183 00184 virtual void setAway(const string& msg = "") {} 00185 virtual void setInfo(const string& info = "") {} 00186 00187 virtual void handleData(Network *net)=0; 00188 virtual void handleData(Network *net, const string& data)=0; 00189 virtual void handleData(Network *net, const VBuffer& data); 00190 00191 virtual void connectionError(Network *net,int error)=0; 00192 virtual void connectedToServer(Network *net) {} 00193 00197 virtual void clearBuddies() { m_buddies.clear(); } 00198 00203 void setConfig(XMLNode conf) { m_conf=conf;} 00204 00208 virtual list<Network *> getNetworks() { return m_nets; } 00209 00210 00212 unsigned long getSentBytes() const; 00213 unsigned long getSentPackets() const; 00214 00215 unsigned long getRecvBytes() const; 00216 unsigned long getRecvPackets() const; 00217 00222 vector<string> getRemoteIPs() const; 00223 00228 virtual void setContacts(vector<Contact>& cnts); 00229 00233 virtual void getInfo(const string& contact) = 0; 00234 00235 protected: 00236 00237 // format the ID for the protocol; 00238 virtual string formatId(const string& id) { return id; } 00239 00240 void eventLoggedIn(); 00241 void eventLoggedOut(); 00242 void eventRecvdMessage(const Contact &c, const string &message); 00243 void eventRecvdMessageNotBuddy(const Contact &c, const string& message); 00244 void eventStatusChange(const Contact &c); 00245 void eventError(int err_no,const string &error); 00246 void eventStateChange(State state); 00247 void eventGotPubkey(const Contact& c, const string &key); 00248 void eventGotCustom(const XMLNode &n); 00249 void eventGotContacts(const vector<buddy>& c); 00250 void eventGotInfo(const Contact& c, const string& info); 00251 00252 protected: 00253 00254 virtual Network *addNet(); 00255 virtual void removeNet(Network *); 00256 00257 Status m_status; 00258 00260 XMLNode m_conf; 00261 00262 // Not used, but should be 00263 typedef map<string, Contact> buddy_t; 00264 00265 // list of buddies who use this protocol 00266 map<string, Contact> m_buddies; 00267 00268 // list of network sockets associated with this protocol 00269 list<Network *> m_nets; 00270 00271 private: 00272 00273 State m_state; 00275 string m_name; 00277 ProtocolManager *m_manager; 00278 }; 00279 00280 } // end namespace gnumess 00281 00282 #endif // end PROTOCOL_H

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