GNUMessenger::ProtocolManager Class Reference

The ProtocolManager class is a very important part of the GNU Messenger. More...

#include <manager.h>

Collaboration diagram for GNUMessenger::ProtocolManager:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 ProtocolManager (XMLManager &auth)
 Creates a ProtocolManager with a reference to a ContactManager.
virtual ~ProtocolManager ()
 The Protocol Manager destructor will delete all of the protocols associated with the manager.
bool removeProtocol (const string &proto)
 May throw InvalidNetwork.
bool loadProtocol (const string &name)
 Loads a protocol from its settings in the XML Manager if they exists.
void shutdown ()
 Shutdown and delete all protocols and nets.
int getState (const string &proto)
 May throw InvalidNetwork.
string screenName (const string &proto)
 Returns the login (screen-name) used for a protocol.
bool update (const string &proto)
 Call these in a non-event based system.
void updateAll ()
 Calls update() on all protocols.
bool hasProtocol (const string &name)
 Is this protocol configured?
bool changeSettings (const string &proto, XMLNode &conf)
 Send new settings to a specified protocol may throw InvalidNetwork.
bool isGM (const Contact &c)
 returns wether or not the session for that contact is a GM session and would support cryptography
void forceKeyX (const Contact &c)
 if the session is encrypted, will initiate a new Key Exchange, never throws
void changeCipher (const Contact &c, int cipherType, int keysize=-1, int blocksize=-1)
 if the session is encrypted, will change the local cipher type, never throws keysize and blocksize are in bytes
Contact getContact (const string &name)
 returns the contact, best copy for program use because has active sessions will throw if contact is invalid
list< Network * > getNets (const string &proto)
 Returns all Network* associated with a given protocol.
list< Network * > getNetsAll ()
 Returns all Network*s currently configured.
bool login (const string &proto)
 Tells a specified protocol to try and connect with the server.
bool logout (const string &proto)
 Tells a specified protocol to logout.
bool setAway (const string &proto, const string &msg)
 Sets the away message for the protocol.
void setAllAway (const string &msg)
 Sets the away message for all active protocols.
bool setInfo (const string &proto, const string &info)
 Set the information/profile for a protocol.
void setAllInfo (const string &info)
 Set the information/profile for all protocols active.
void getInfo (const Contact &contact)
 Get info about a particular user--async call.
bool sendMessage (const string &proto, const Contact &recipient, const string &message)
 Tries to send a message on a given protocol.
bool sendMessage (const string &proto, const Contact &recipient, const VBuffer &data)
 Tries to send a message on a given protocol.
bool sendMessage (const Contact &c, const string &message)
 Tries to send a message via any available route.
bool sendMessage (const Contact &c, const VBuffer &data)
 Tries to send a message via any available route.
void addContact (const Contact &c)
 Add a contact to the protocols contact list or updates the contact if they exists already.
bool delContact (const string &proto, const Contact &c)
 Removes a contact from a protocol's list of contacts.
vector< string > protocols () const
 Returns a vector of configured protocol names.
unsigned long getSentBytes (const string &proto) const
 Return the number of bytes sent, recv-ed, packets, etc.
unsigned long getSentPackets (const string &proto) const
unsigned long getRecvBytes (const string &proto) const
unsigned long getRecvPackets (const string &proto) const
vector< string > getRemoteIPs (const string &proto) const

Protected Member Functions

void protoLoggedIn (const string &proto)
 Status changes -- I moved these from the callbacks area because the State change function basically calls theses if done right (i think).
void protoLoggedOut (const string &proto)
Protocolprotocol (const string &proto)
 Retrieves the Protocol pointer of a given protocol.
const Protocolprotocol (const string &proto) const
virtual NetworkcreateNet (Protocol *protocol)=0
 This should create a new system dependant Network pointer and return it.
virtual NetworkServercreateServer (Protocol *protocol)=0
virtual void removeNet (Network *n)
 Removes a socket from event handling AND deletes it.
bool addProtocol (Protocol *proto)
 Add a new protocol.
bool isOnline (const string &proto) const
void sendEncryptedMessage (const string &proto, const Contact &c, const string &mess)
void sendEncryptedMessage (const string &proto, const Contact &c, const VBuffer &data)
void receiveEncryptedMessage (const string &proto, const Contact &c, const string &mess)
void receiveEncryptedMessage (const string &proto, const Contact &c, const VBuffer &data)
virtual void c_loggedIn (const string &proto)
 Call-backs (to client).
virtual void c_loggedOut (const string &proto)
virtual void c_recvdMessage (const string &proto, const Contact &c, const string &message)=0
virtual void c_recvdMessageAnony (const string &protocol, const Contact &c, const string &message)=0
virtual void c_statusChange (const string &proto, const Contact &c)
virtual void c_error (const string &proto, int err_no, const string &error)
virtual void c_stateChange (const string &proto, Protocol::State st)
virtual void c_gotPubkey (const Contact &c, const string &key)
virtual void c_gotBuddy (const string &proto, const Contact &c)
virtual void c_gotContacts (const string &proto, const vector< buddy > &c)
virtual void c_custom (const string &proto, const XMLNode &n)
virtual void c_gotInfo (const Contact &c, const string &info, const string &proto)

Protected Attributes

XMLManagerm_auth

Detailed Description

The ProtocolManager class is a very important part of the GNU Messenger.

It controls all of the Protocols and there associated Network sockets and interfaces with the client via callbacks. It is an abstract base class which requires a client implementation to derive certain functionality.

Author:
Henrik Abelsson

Jesse Lovelace

Definition at line 49 of file manager.h.


Constructor & Destructor Documentation

GNUMessenger::ProtocolManager::~ProtocolManager  )  [virtual]
 

The Protocol Manager destructor will delete all of the protocols associated with the manager.

The protocol's destructor will use removeNet to try and destroy the Network objects (read Sockets) in a well-defined way. Definition at line 36 of file manager.cpp.

References shutdown().

00037 { 00038 if (!m_shutdown) 00039 shutdown(); 00040 }

Here is the call graph for this function:


Member Function Documentation

bool GNUMessenger::ProtocolManager::addProtocol Protocol proto  )  [protected]
 

Add a new protocol.

Parameters:
proto A pointer to a Protocol object if the function returns false the pointer is NEVER valid (either it was NULL to begin with or was deleted due to a duplicate).
Returns:
True if protocol is valid and added to provider list
Note:
Don't call directly...will be called internally by the protocols.
Definition at line 95 of file manager.cpp.

References GNUMessenger::XMLManager::contacts(), GNUMessenger::ContactManager::getContactsOfProtocol(), and GNUMessenger::Protocol::getProtocol().

Referenced by GNUMessenger::Protocol::Protocol().

00096 { 00097 LOG_DEBUG("ProtocolManager::addProtocol: " << proto->getProtocol()); 00098 00099 if (m_provider.find(proto->getProtocol()) == m_provider.end()) { 00100 00101 LOG_DEBUG( "Adding " << proto->getProtocol() << " to protocol manager"); 00102 m_provider[proto->getProtocol()]=proto; 00104 vector<Contact> contacts; 00105 00106 LOG_DEBUG("Loading in contacts to protocol..."); 00107 m_auth.contacts().getContactsOfProtocol(proto->getProtocol(), contacts); 00108 00109 proto->setContacts(contacts); 00110 00111 } else { 00112 LOG_ERROR("Cannot add duplicate protocols to the provider list, deleting: " << proto->getProtocol()); 00113 00114 delete proto; 00115 return false; 00116 } 00117 return true; 00118 00119 }

Here is the call graph for this function:

virtual Network* GNUMessenger::ProtocolManager::createNet Protocol protocol  )  [protected, pure virtual]
 

This should create a new system dependant Network pointer and return it.

It's called when a protocol needs a new socket. Also should add the Network to any event monitoring the Socket supports.

bool GNUMessenger::ProtocolManager::loadProtocol const string &  name  ) 
 

Loads a protocol from its settings in the XML Manager if they exists.

Returns false if the protocol could not be loaded.

Parameters:
name The name of the protocol to be loaded
Definition at line 77 of file manager.cpp.

References GNUMessenger::SettingsManager::getNet(), and GNUMessenger::XMLManager::settings().

00078 { 00079 LOG_DEBUG("ProtocolManager::loadProtocol:" << name); 00080 XMLNode config; 00081 00082 if (m_auth.settings().getNet("toc", config)) { 00083 00084 new TocProtocol(config, this); 00085 00086 return true; 00087 } 00088 00089 LOG_ERROR("Could not find protocol settings."); 00090 00091 return false; 00092 00093 }

Here is the call graph for this function:

bool GNUMessenger::ProtocolManager::login const string &  proto  ) 
 

Tells a specified protocol to try and connect with the server.

Parameters:
proto The protocol identifier
Returns:
True if already online or protocol exists
Note:
Does not mean connection was successful, that is Network implementation specific
Definition at line 253 of file manager.cpp.
00254 { 00255 LOG_DEBUG("ProtocolManager::login: " << proto); 00256 if (m_provider.count(proto)) { 00257 if (!isOnline(proto)) 00258 m_provider[proto]->login(); 00259 return true; 00260 } 00261 return false; 00262 }

bool GNUMessenger::ProtocolManager::logout const string &  proto  ) 
 

Tells a specified protocol to logout.

Parameters:
proto The protocol identifier
Returns:
True if protocol exists or already logged out
Note:
There is a pretty good chance that this operation will always complete, but, like login() it is implementation specific.
Definition at line 264 of file manager.cpp.

Referenced by removeProtocol().

00265 { 00266 LOG_DEBUG("ProtocolManager::logout: " << proto); 00267 if (m_provider.count(proto)) { 00268 LOG_DEBUG("Proto not found."); 00269 if (isOnline(proto)) 00270 m_provider[proto]->logout(); 00271 return true; 00272 } 00273 return false; 00274 00275 }

Protocol * GNUMessenger::ProtocolManager::protocol const string &  proto  )  [protected]
 

Retrieves the Protocol pointer of a given protocol.

Parameters:
proto The protocol identifier
Returns:
A pointer to the protocol object
Note:
Be very careful to remove this protocol from the provider list or a pointer error may occur. That is why this function is protected
Definition at line 177 of file manager.cpp.

Referenced by getSentBytes(), and removeProtocol().

00178 { 00179 map<string, Protocol *>::iterator it = m_provider.find(proto); 00180 if (it != m_provider.end()) 00181 return it->second; 00182 else 00183 return NULL; 00184 }

vector< string > GNUMessenger::ProtocolManager::protocols  )  const
 

Returns a vector of configured protocol names.

Returns:
Const vector of string protocol identifiers
Note:
These are not necessarily online protocols, merely configured ones
Definition at line 168 of file manager.cpp.
00169 { 00170 vector<string> tmp; 00171 for (map<string, Protocol*>::const_iterator i=m_provider.begin();i!=m_provider.end();i++) 00172 tmp.push_back(i->first); 00173 00174 return tmp; 00175 }

string GNUMessenger::ProtocolManager::screenName const string &  proto  ) 
 

Returns the login (screen-name) used for a protocol.

Parameters:
proto The protocol identifier
Returns:
A string of the login name or empty string if proto does not exists
Definition at line 195 of file manager.cpp.
00196 { 00197 if (m_provider.count(proto)) 00198 return m_provider[proto]->getLoginName(); 00199 else 00200 return ""; 00201 }

bool GNUMessenger::ProtocolManager::sendMessage const Contact c,
const VBuffer data
 

Tries to send a message via any available route.

Parameters:
c The intended reciever of the data
data The actual data sent (as data buffer)
Returns:
True if a protocol exists in for which the Contact is listed as online
Note:
This is no guarentee that the data was actually recieved, if it is not, a protocol error should be reported
Definition at line 310 of file manager.cpp.

References GNUMessenger::Contact::getProtocol(), and sendMessage().

00311 { 00312 LOG_DEBUG("Send message (data) with protocol " << c.getProtocol()); 00313 00314 if (c.getProtocol().length() == 0) { 00315 LOG_DEBUG("Cannot send, no protocol online"); 00316 return false; 00317 } 00318 00319 return sendMessage(c.getProtocol(), c, data); 00320 00321 }

Here is the call graph for this function:

bool GNUMessenger::ProtocolManager::sendMessage const Contact c,
const string &  message
 

Tries to send a message via any available route.

Parameters:
c The intended reciever of the data
message The actual message sent (as a string buffer)
Returns:
True if a protocol exists in for which the Contact is listed as online
Note:
This is no guarentee that the message was actually recieved, if it is not, a protocol error should be reported
Definition at line 297 of file manager.cpp.

References GNUMessenger::Contact::getProtocol(), and sendMessage().

00298 { 00299 LOG_DEBUG("ProtocolManager::sendMessage: " << c.getProtocol()); 00300 00301 if (c.getProtocol().length() == 0) { 00302 LOG_DEBUG("Cannot send, no protocol online"); 00303 return false; 00304 } 00305 00306 return sendMessage(c.getProtocol(), c, message); 00307 00308 }

Here is the call graph for this function:

bool GNUMessenger::ProtocolManager::sendMessage const string &  proto,
const Contact recipient,
const VBuffer data
 

Tries to send a message on a given protocol.

Parameters:
proto The protocol identifier
recipient The intended reciever of the data
data The actual data sent (as data buffer)
Returns:
True if protocol exists
Note:
This is no guarentee that the data was actually recieved, if it is not, a protocol error should be reported
Definition at line 288 of file manager.cpp.
00289 { 00290 if (isOnline(proto)) { 00291 m_provider[proto]->sendMessage(recipient, data); 00292 return true; 00293 } 00294 return false; 00295 }

bool GNUMessenger::ProtocolManager::sendMessage const string &  proto,
const Contact recipient,
const string &  message
 

Tries to send a message on a given protocol.

Parameters:
proto The protocol identifier
recipient The intended reciever of the message
message The actual message sent (as a string)
Returns:
True if protocol exists
Note:
This is no guarentee that the message was actually recieved, if it is not, a protocol error should be reported
Definition at line 277 of file manager.cpp.

Referenced by sendMessage().

00278 { 00279 LOG_DEBUG("ProtocolManager::sendMessage"); 00280 if (isOnline(proto)) { 00281 m_provider[proto]->sendMessage(recipient, message); 00282 return true; 00283 } 00284 LOG_DEBUG("That protocol is not online."); 00285 return false; 00286 }

void GNUMessenger::ProtocolManager::setAllAway const string &  msg  ) 
 

Sets the away message for all active protocols.

Parameters:
msg Message to set for all protocols.
Definition at line 231 of file manager.cpp.
00232 { 00233 for (map<string, Protocol*>::iterator i=m_provider.begin();i!=m_provider.end();i++) 00234 i->second->setAway(msg); 00235 }

void GNUMessenger::ProtocolManager::setAllInfo const string &  info  ) 
 

Set the information/profile for all protocols active.

Parameters:
info The information to set for all protocols.
Definition at line 247 of file manager.cpp.
00248 { 00249 for (map<string, Protocol*>::iterator i=m_provider.begin();i!=m_provider.end();i++) 00250 i->second->setInfo(info); 00251 }

bool GNUMessenger::ProtocolManager::setAway const string &  proto,
const string &  msg
 

Sets the away message for the protocol.

Parameters:
proto The protocol to set an away message for
msg The message to set
Returns:
True if protocol exists
Definition at line 220 of file manager.cpp.
00221 { 00222 LOG_DEBUG("ProtocolManager::setAway: " << proto); 00223 if (m_provider.count(proto)) { 00224 m_provider[proto]->setAway(msg); 00225 return true; 00226 } 00227 00228 return false; 00229 }

bool GNUMessenger::ProtocolManager::setInfo const string &  proto,
const string &  info
 

Set the information/profile for a protocol.

Parameters:
proto The protocol to set information for
info The information to set
Returns:
True if protocol exists
Definition at line 237 of file manager.cpp.
00238 { 00239 if (m_provider.count(proto)) { 00240 m_provider[proto]->setInfo(info); 00241 return true; 00242 } 00243 00244 return false; 00245 }

bool GNUMessenger::ProtocolManager::update const string &  proto  ) 
 

Call these in a non-event based system.

Parameters:
proto The protocol to update
Returns:
True if protocol exists
Definition at line 203 of file manager.cpp.
00204 { 00205 if (m_provider.find(proto) != m_provider.end()) 00206 { 00207 m_provider[proto]->update(); 00208 return true; 00209 } 00210 return false; 00211 }

void GNUMessenger::ProtocolManager::updateAll  ) 
 

Calls update() on all protocols.

Call in non-event based system. Definition at line 213 of file manager.cpp.

00214 { 00215 LOG_DEBUG("ProtocolManager::updateAll"); 00216 for (map<string, Protocol*>::iterator i=m_provider.begin();i!=m_provider.end();i++) 00217 i->second->update(); 00218 }


The documentation for this class was generated from the following files:
Generated on Tue Oct 5 14:41:55 2004 for GNU Messenger by doxygen 1.3.8