protocol.cpp

00001 /* 00002 $Id: protocol_8cpp-source.html,v 1.1 2004/10/05 21:12:02 mentat Exp $ 00003 00004 GNU Messenger - The secure instant messenger 00005 Copyright (C) 1999-2001 Emil Styrke <emil@lysator.liu.se> 00006 Copyright (C) 2002-2004 Jesse Lovelace <jesse at aslogicsys dot com> 00007 00008 This program is free software; you can redistribute it and/or modify 00009 it under the terms of the GNU General Public License as published by 00010 the Free Software Foundation; either version 2 of the License, or 00011 (at your option) any later version. 00012 00013 This program is distributed in the hope that it will be useful, 00014 but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 GNU General Public License for more details. 00017 00018 You should have received a copy of the GNU General Public License 00019 along with this program; if not, write to the Free Software 00020 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00021 */ 00022 00023 #include <list> 00024 00025 #include "gm/protocol.h" 00026 #include "gm/manager.h" 00027 #include "gm/basenetwork.h" 00028 00029 namespace GNUMessenger { 00030 00031 using namespace std; 00032 00033 Protocol::Protocol(const XMLNode &conf,ProtocolManager *manager, 00034 const string &name="unnamedProto"): 00035 m_conf(conf), m_manager(manager), m_name(name), m_state(S_offline) 00036 { 00037 if (m_manager) { 00038 m_manager->addProtocol(this); 00039 } 00040 } 00041 00042 Protocol::~Protocol() 00043 { 00044 for(list<Network *>::iterator it = m_nets.begin(); 00045 it != m_nets.end(); it++) { 00046 if (m_manager) 00047 m_manager->removeNet(*it); 00048 else 00049 delete *it; 00050 *it = 0; 00051 } 00052 } 00053 00054 void Protocol::setContacts(vector<Contact>& cnts) 00055 { 00056 for (unsigned int i = 0; i < cnts.size(); i++) { 00057 cnts[i].setStatus(getProtocol(), Contact::Offline); 00058 m_buddies[formatId(cnts[i].getServerId(getProtocol()))] = cnts[i]; 00059 } 00060 00061 } 00062 00063 void Protocol::handleData(Network *net, const VBuffer& data) 00064 { 00065 handleData(net, string((const char *)data.data(), data.size())); 00066 } 00067 00068 void Protocol::changeSettings(XMLNode& conf) 00069 { 00070 m_conf = conf; 00071 reset(); 00072 } 00073 00074 void Protocol::eventLoggedIn() 00075 { 00076 LOG_DEBUG("Protocol::eventLoggedIn()"); 00077 map<string, Contact>::iterator it = m_buddies.begin(); 00078 00079 if (m_manager) 00080 m_manager->protoLoggedIn(getProtocol()); 00081 00082 } 00083 00084 void Protocol::eventLoggedOut() 00085 { 00086 LOG_DEBUG("Protocol::eventLoggedOut()"); 00087 map<string, Contact>::iterator it = m_buddies.begin(); 00088 for ( ;it != m_buddies.end(); it++) 00089 (it->second).setStatus(getProtocol(), Contact::Offline); 00090 00091 if (m_manager) 00092 m_manager->protoLoggedOut(getProtocol()); 00093 } 00094 00095 void Protocol::eventRecvdMessageNotBuddy(const Contact &c, const string &message) 00096 { 00097 LOG_DEBUG("Not buddy msg: " << message); 00098 00099 if (m_manager != NULL) 00100 m_manager->protoRecvdMessageAnony(getProtocol(),c,message); 00101 00102 } 00103 00104 void Protocol::eventRecvdMessage(const Contact &c, const string &message) 00105 { 00106 LOG_DEBUG("eventRecvdMessage: " << message); 00107 00108 if (m_manager != NULL) 00109 m_manager->protoRecvdMessage(getProtocol(),c,message); 00110 00111 } 00112 00113 void Protocol::eventStatusChange(const Contact &c) 00114 { 00115 if (m_manager) 00116 m_manager->protoStatusChange(getProtocol(),c); 00117 else 00118 LOG_THROW("eventStatusChange pointer is null", PointerError); 00119 } 00120 00121 void Protocol::eventError(int err_no,const string &error) 00122 { 00123 if (m_manager) 00124 m_manager->protoError(getProtocol(),err_no,error); 00125 } 00126 00127 void Protocol::eventStateChange(State state) 00128 { 00129 m_state = state; 00130 if (m_manager) 00131 m_manager->protoStateChange(getProtocol(),state); 00132 } 00133 00134 void Protocol::eventGotPubkey(const Contact& c, const string &key) 00135 { 00136 if (m_manager) 00137 m_manager->protoGotPubkey(c,key); 00138 } 00139 00140 void Protocol::eventGotInfo(const Contact& c, const string& info) 00141 { 00142 if (m_manager) 00143 m_manager->protoGotInfo(c, info, getProtocol()); 00144 } 00145 00146 Network *Protocol::addNet() 00147 { 00148 Network *n = m_manager->createNet(this); 00149 00150 n->setOwner(this); 00151 m_nets.push_back(n); 00152 00153 return n; 00154 } 00155 00156 void Protocol::removeNet(Network *n) 00157 { 00158 m_nets.remove(n); 00159 m_manager->removeNet(n); 00160 00161 } 00162 00163 void Protocol::eventGotContacts(const vector<buddy>& c) 00164 { 00165 if (m_manager) 00166 m_manager->protoGotContacts(getProtocol(), c); 00167 } 00168 00169 void Protocol::eventGotCustom(const XMLNode &n) 00170 { 00171 if (m_manager) 00172 m_manager->protoCustom(getProtocol(),n); 00173 } 00174 00175 unsigned long Protocol::getSentBytes() const 00176 { 00177 unsigned long temp = 0; 00178 for(list<Network *>::const_iterator it = m_nets.begin(); 00179 it != m_nets.end(); it++) { 00180 temp += (*it)->getSentBytes(); 00181 } 00182 return temp; 00183 } 00184 00185 unsigned long Protocol::getSentPackets() const 00186 { 00187 unsigned long temp = 0; 00188 for(list<Network *>::const_iterator it = m_nets.begin(); 00189 it != m_nets.end(); it++) { 00190 temp += (*it)->getSentPackets(); 00191 } 00192 return temp; 00193 } 00194 00195 unsigned long Protocol::getRecvBytes() const 00196 { 00197 unsigned long temp = 0; 00198 for(list<Network *>::const_iterator it = m_nets.begin(); 00199 it != m_nets.end(); it++) { 00200 temp += (*it)->getRecvBytes(); 00201 } 00202 return temp; 00203 } 00204 00205 unsigned long Protocol::getRecvPackets() const 00206 { 00207 unsigned long temp = 0; 00208 for(list<Network *>::const_iterator it = m_nets.begin(); 00209 it != m_nets.end(); it++) { 00210 temp += (*it)->getRecvPackets(); 00211 } 00212 return temp; 00213 } 00214 00215 vector<string> Protocol::getRemoteIPs() const 00216 { 00217 vector<string> ips; 00218 for(list<Network *>::const_iterator it = m_nets.begin(); 00219 it != m_nets.end(); it++) { 00220 ips.push_back((*it)->getRemoteIP()); 00221 } 00222 return ips; 00223 } 00224 00225 } // !GNUMessenger 00226 /* 00227 ----- 00228 $Log: protocol.cpp,v $ 00229 Revision 1.4 2004/10/04 05:14:20 mentat 00230 Adding info get support and HTTP. 00231 00232 Revision 1.3 2004/10/03 18:39:40 mentat 00233 Merging in hash_map changes to TOC and getInfo methods. 00234 00235 Revision 1.2.2.1 2004/10/03 18:36:03 mentat 00236 Added hash_map to toc protocol and working in getInfo methods. 00237 00238 Revision 1.2 2004/10/03 15:22:57 mentat 00239 Fixed a pure virtual function error and improved TOC. 00240 00241 Revision 1.1.1.1 2004/10/03 06:17:37 mentat 00242 Initial re-import. 00243 00244 Revision 1.3 2003/04/13 18:43:58 mentat 00245 Heavy commits. 00246 00247 Revision 1.2 2003/04/09 21:19:56 mentat 00248 Updating to compile. 00249 00250 Revision 1.1 2003/03/02 16:19:05 mentat 00251 Importing new sources. 00252 00253 00254 00255 */

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