~ubuntu-branches/ubuntu/karmic/centerim/karmic

« back to all changes in this revision

Viewing changes to src/hooks/icqhook.cc

  • Committer: Bazaar Package Importer
  • Author(s): Alessio Treglia
  • Date: 2009-03-26 19:51:53 UTC
  • mfrom: (1.1.5 upstream) (3.1.2 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090326195153-dxo63t1lwbp2m592
Tags: 4.22.7-1ubuntu1
* Merge from debian unstable, Ubuntu remaining changes:
  - Packages that Depend/Recommend/Suggest firefox (metapackage) must
    must alternatively Depend/Recommend/Suggest abrowser.
* Bugfix-only release, fixed bugs: LP: #146308 and LP: #186381.

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
#include "imlogger.h"
33
33
#include "icqgroups.h"
34
34
#include "icqcontacts.h"
 
35
#include "impgp.h"
35
36
 
36
37
#include "accountmanager.h"
37
38
#include "eventmanager.h"
75
76
    fcapabs.insert(hookcapab::visibility);
76
77
    fcapabs.insert(hookcapab::cltemporary);
77
78
    fcapabs.insert(hookcapab::changeabout);
 
79
    
 
80
#ifdef HAVE_GPGME
 
81
    fcapabs.insert(hookcapab::pgp);
 
82
#endif
78
83
 
79
84
    cli.connected.connect(this, &icqhook::connected_cb);
80
85
    cli.disconnected.connect(this, &icqhook::disconnected_cb);
114
119
}
115
120
 
116
121
void icqhook::init() {
117
 
    manualstatus = conf.getstatus(proto);
 
122
    manualstatus = conf->getstatus(proto);
118
123
 
119
 
    if(conf.getdebug())
 
124
    if(conf->getdebug())
120
125
        cli.logger.connect(this, &icqhook::logger_cb);
121
126
}
122
127
 
123
128
void icqhook::connect() {
124
 
    icqconf::imaccount acc = conf.getourid(proto);
 
129
    icqconf::imaccount acc = conf->getourid(proto);
125
130
    int i, ptpmin, ptpmax;
126
131
    icqcontact *c;
127
132
 
128
133
    if(acc.additional["webaware"].empty()) acc.additional["webaware"] = "1";
129
 
    conf.setourid(acc);
 
134
    conf->setourid(acc);
130
135
 
131
136
    if(!acc.server.empty()) cli.setLoginServerHost(acc.server);
132
137
    if(acc.port) cli.setLoginServerPort(acc.port);
133
138
 
134
 
    if(!conf.getsmtphost().empty()) cli.setSMTPServerHost(conf.getsmtphost());
135
 
    if(conf.getsmtpport()) cli.setSMTPServerPort(conf.getsmtpport());
 
139
    if(!conf->getsmtphost().empty()) cli.setSMTPServerHost(conf->getsmtphost());
 
140
    if(conf->getsmtpport()) cli.setSMTPServerPort(conf->getsmtpport());
136
141
 
137
 
    if(!conf.getbindhost().empty()) cli.setClientBindHost(conf.getbindhost());
 
142
    if(!conf->getbindhost().empty()) cli.setClientBindHost(conf->getbindhost());
138
143
    
139
 
    conf.getpeertopeer(ptpmin, ptpmax);
 
144
    conf->getpeertopeer(ptpmin, ptpmax);
140
145
    if(ptpmax) {
141
146
        cli.setAcceptInDC(true);
142
147
        cli.setPortRangeLowerBound(ptpmin);
381
386
    ContactRef ic = cli.getContact(uin);
382
387
    MessageEvent *sev = 0;
383
388
    ICQMessageEvent *iev;
384
 
    icqcontact *c;
 
389
    icqcontact *c=clist.get(ev.getcontact());
385
390
 
386
391
    if(ev.getcontact().pname != proto)
387
392
        uin = 0;
396
401
        const immessage *m = static_cast<const immessage *> (&ev);
397
402
        string text = m->gettext(), sub;
398
403
 
 
404
#ifdef HAVE_GPGME
 
405
    if ( (c!=NULL) && (pgp.enabled(ev.getcontact())) ) {
 
406
        text = pgp.encrypt(text, c->getpgpkey(), proto);
 
407
        text = "-----BEGIN PGP MESSAGE-----\n\n" + text + "\n-----END PGP MESSAGE-----\n"; 
 
408
    }
 
409
#endif
 
410
 
399
411
        if(ic->getStatus() == STATUS_OFFLINE)
400
412
        if(text.size() > 450) {
401
413
            while(!text.empty()) {
459
471
 
460
472
            case imauthorization::Request:
461
473
                sev = new AuthReqEvent(ic, ruscrlfconv("kw", m->getmessage()));
462
 
                if(c = clist.get(ev.getcontact())) {
 
474
                if(c != NULL) {
463
475
                    icqcontact::basicinfo bi = c->getbasicinfo();
464
476
                    bi.authawait = true;
465
477
                    c->setbasicinfo(bi);
638
650
 
639
651
void icqhook::requestinfo(const imcontact &c) {
640
652
    if(logged() && c.uin) {
641
 
        if(c == imcontact(conf.getourid(icq).uin, icq)) {
 
653
        if(c == imcontact(conf->getourid(icq).uin, icq)) {
642
654
            // Our info is requested
643
655
            cli.fetchSelfDetailContactInfo();
644
656
        } else {
768
780
    ic->setWorkInfo(work);
769
781
    ic->setAuthReq(cbinfo.requiresauth);
770
782
 
771
 
    icqconf::imaccount acc = conf.getourid(icq);
 
783
    icqconf::imaccount acc = conf->getourid(icq);
772
784
    acc.additional["webaware"] = cbinfo.webaware ? "1" : "0";
773
785
    acc.additional["randomgroup"] = i2str(cbinfo.randomgroup);
774
 
    conf.setourid(acc);
 
786
    conf->setourid(acc);
775
787
 
776
788
    cli.setWebAware(cbinfo.webaware);
777
789
    cli.setRandomChatGroup(cbinfo.randomgroup);
1007
1019
 
1008
1020
    logger.putourstatus(icq, offline, manualstatus);
1009
1021
 
1010
 
    cli.setRandomChatGroup(strtoul(conf.getourid(icq).additional["randomgroup"].c_str(), 0, 0));
 
1022
    cli.setRandomChatGroup(strtoul(conf->getourid(icq).additional["randomgroup"].c_str(), 0, 0));
1011
1023
 
1012
1024
    log(logLogged);
1013
1025
    face.update();
1014
1026
 
1015
1027
    string buf;
1016
 
    ifstream f(conf.getconfigfname("icq-infoset").c_str());
 
1028
    ifstream f(conf->getconfigfname("icq-infoset").c_str());
1017
1029
 
1018
1030
    if(f.is_open()) {
1019
1031
        getstring(f, buf); cli.getSelfContact()->setAlias(buf);
1025
1037
        cli.getSelfContact()->getMainHomeInfo().timezone = (Timezone) getSystemTimezone();
1026
1038
        cli.uploadSelfDetails();
1027
1039
 
1028
 
        unlink(conf.getconfigfname("icq-infoset").c_str());
 
1040
        unlink(conf->getconfigfname("icq-infoset").c_str());
1029
1041
    }
1030
1042
 
1031
1043
    cli.fetchServerBasedContactList();
1122
1134
        else
1123
1135
            text = r->getMessage();
1124
1136
        if(text.substr(0, 6) == "{\\rtf1")
1125
 
            text = fixicqrtf(striprtf(text, converted?conf.getconvertto(proto):conf.getconvertfrom(proto)));
1126
 
 
1127
 
        em.store(immessage(ic, imevent::incoming, converted?text:rusconv("wk", text), r->getTime()));
 
1137
            text = fixicqrtf(striprtf(text, converted?conf->getconvertto(proto):conf->getconvertfrom(proto)));
 
1138
    
 
1139
        text = converted ? text : rusconv("wk", text);
 
1140
 
 
1141
#ifdef HAVE_GPGME
 
1142
        const string pgpBlockBegin = "-----BEGIN PGP MESSAGE-----";
 
1143
        const string pgpBlockEnd = "-----END PGP MESSAGE-----";
 
1144
        string enc;
 
1145
        int pgpDataBegin = text.find(pgpBlockBegin);
 
1146
        int pgpDataEnd = text.find(pgpBlockEnd);
 
1147
 
 
1148
        // find where actual PGP data starts
 
1149
        if (pgpDataBegin != string::npos) {
 
1150
            int a = text.find("\n\n", pgpDataBegin+1);
 
1151
            int b = text.find("\r\n\r\n", pgpDataBegin+1);
 
1152
 
 
1153
            if(a != string::npos) {
 
1154
                if(b != string::npos) {
 
1155
                    // if we found both, take the smaller value
 
1156
                    if (a<b) {
 
1157
                        pgpDataBegin = a;
 
1158
                    } else {
 
1159
                        pgpDataBegin = b;
 
1160
                    }
 
1161
                } else {
 
1162
                    // we didn't find second match, so just take first
 
1163
                    pgpDataBegin = a;
 
1164
                }
 
1165
            } else {
 
1166
                // we didn't find first, so take whatever is in second
 
1167
                pgpDataBegin = b;
 
1168
            }
 
1169
        }
 
1170
 
 
1171
        if((pgpDataBegin != string::npos) && (pgpDataEnd != string::npos)) {
 
1172
            pgpDataBegin++;
 
1173
            enc=text.substr(pgpDataBegin, pgpDataEnd-pgpDataBegin);
 
1174
 
 
1175
            icqcontact *c = clist.get(ic);
 
1176
 
 
1177
            if(c) {
 
1178
                if(!enc.empty()) {
 
1179
                    c->setusepgpkey(true);
 
1180
                    if(pgp.enabled(proto)) {
 
1181
                        string dec = pgp.decrypt(enc, proto);
 
1182
                        string logMsg;
 
1183
 
 
1184
                       if(dec.length() != 0) {
 
1185
                            logMsg="+ "+ic.totext()+" ("+c->getdispnick()+") PGP message decoded";
 
1186
                            text = dec;
 
1187
                        } else {
 
1188
                            // if we fail to decode message,
 
1189
                            // just display it as it is
 
1190
                            logMsg="+ "+ic.totext()+" ("+c->getdispnick()+") FAILED to decode PGP message";
 
1191
                        }
 
1192
                        logger.putmessage(logMsg);
 
1193
                        face.log(logMsg);
 
1194
                    } else {
 
1195
                        c->setusepgpkey(false);
 
1196
                    }
 
1197
                } else {
 
1198
                    c->setusepgpkey(false);
 
1199
                }
 
1200
            }
 
1201
        } 
 
1202
#endif
 
1203
 
 
1204
        em.store(immessage(ic, imevent::incoming, text, r->getTime()));
1128
1205
 
1129
1206
    } else if(ev->getType() == MessageEvent::URL) {
1130
1207
        URLMessageEvent *r = static_cast<URLMessageEvent *>(ev);
1250
1327
                            rusconv("wk", r->getAwayMessage())));
1251
1328
                    }
1252
1329
                } else {
1253
 
                    face.log(_("+ [icq] cannot fetch away msg from %s, %s"),
 
1330
                    face.log(_("+ [icq] cannot fetch away msg from %s, %s (maybe no away msg set)"),
1254
1331
                        c->getdispnick().c_str(), ic.totext().c_str());
1255
1332
                }
1256
1333
                break;
1394
1471
    if(c) ident += " (" + c->getdispnick() + ")";
1395
1472
 
1396
1473
    /* logger.putmessage(buf); */
1397
 
    ev->setAwayMessage(rusconv("kw", conf.getawaymsg(icq)));
 
1474
    ev->setAwayMessage(rusconv("kw", conf->getawaymsg(icq)));
1398
1475
}
1399
1476
 
1400
1477
void icqhook::search_result_cb(SearchResultEvent *ev) {
1432
1509
            c->setbasicinfo(binfo);
1433
1510
 
1434
1511
            foundguys.push_back(c);
1435
 
            searchdest->additem(conf.getcolor(cp_clist_icq), c, line);
 
1512
            searchdest->additem(conf->getcolor(cp_clist_icq), c, line);
1436
1513
            searchdest->redraw();
1437
1514
        }
1438
1515
 
1457
1534
        *
1458
1535
        */
1459
1536
 
1460
 
        icqconf::imaccount im = conf.getourid(icq);
 
1537
        icqconf::imaccount im = conf->getourid(icq);
1461
1538
        icqcontact::basicinfo cbinfo = c->getbasicinfo();
1462
1539
        cbinfo.webaware = im.additional["webaware"] == "1";
1463
1540
        cbinfo.randomgroup = strtoul(im.additional["randomgroup"].c_str(), 0, 0);
1473
1550
 
1474
1551
void icqhook::password_changed_cb(PasswordChangeEvent *ev) {
1475
1552
    if(ev->isSuccess()) {
1476
 
        icqconf::imaccount acc = conf.getourid(icq);
 
1553
        icqconf::imaccount acc = conf->getourid(icq);
1477
1554
        acc.password = ev->getPassword();
1478
 
        conf.setourid(acc);
 
1555
        conf->setourid(acc);
1479
1556
        log(logPasswordChanged);
1480
1557
    }
1481
1558
}