00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
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 }
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255