~ubuntu-branches/ubuntu/saucy/kopete/saucy-proposed

« back to all changes in this revision

Viewing changes to protocols/wlm/wlmlibmsn.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2013-06-21 02:22:39 UTC
  • Revision ID: package-import@ubuntu.com-20130621022239-63l3zc8p0nf26pt6
Tags: upstream-4.10.80
ImportĀ upstreamĀ versionĀ 4.10.80

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * msntest.cpp
 
3
 * libmsn
 
4
 *
 
5
 * Created by Meredydd Luff.
 
6
 * Refactored by Tiago Salem Herrmann
 
7
 * Copyright (c) 2004 Meredydd Luff. All rights reserved.
 
8
 * Copyright (c) 2007 Tiago Salem Herrmann. All rights reserved.
 
9
 *
 
10
 * This program is free software; you can redistribute it and/or modify
 
11
 * it under the terms of the GNU General Public License as published by
 
12
 * the Free Software Foundation; either version 2 of the License, or
 
13
 * (at your option) any later version.
 
14
 *
 
15
 * This program is distributed in the hope that it will be useful,
 
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
18
 * GNU General Public License for more details.
 
19
 *
 
20
 * You should have received a copy of the GNU General Public License
 
21
 * along with this program; see the file COPYING. If not, write to
 
22
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 
23
 * Boston, MA 02110-1301, USA.
 
24
 */
 
25
 
 
26
#include "wlmlibmsn.h"
 
27
#include "wlmserver.h"
 
28
#include "wlmaccount.h"
 
29
 
 
30
#include "kopetemessage.h"
 
31
#include "kopetecontact.h"
 
32
#include "kopeteuiglobal.h"
 
33
 
 
34
// include first to not get compile errors on windows
 
35
#include <msn/msn.h>
 
36
 
 
37
#include <errno.h>
 
38
#include <sys/types.h>
 
39
#include <unistd.h>
 
40
#include <sys/stat.h>
 
41
#include <stdlib.h>
 
42
#include <string.h>
 
43
 
 
44
#include <sys/socket.h>
 
45
#include <arpa/inet.h>
 
46
#include <netinet/in.h>
 
47
#include <netdb.h>
 
48
#include <fcntl.h>
 
49
 
 
50
#include <string>
 
51
#include <iostream>
 
52
#include <kdebug.h>
 
53
#include <kmime/kmime_util.h>
 
54
 
 
55
#include <QObject>
 
56
#include <QApplication>
 
57
#include <QPushButton>
 
58
#include <QList>
 
59
#include <QEventLoop>
 
60
#include <QSslSocket>
 
61
 
 
62
namespace WlmUtils {
 
63
QString passport(const MSN::Passport& pass)
 
64
{
 
65
    return QString::fromLatin1(pass.c_str());
 
66
}
 
67
 
 
68
QString latin1(const std::string& s)
 
69
{
 
70
    return QString::fromLatin1(s.c_str());
 
71
}
 
72
 
 
73
QString utf8(const std::string& s)
 
74
{
 
75
    return QString::fromUtf8(s.c_str());
 
76
}
 
77
}
 
78
 
 
79
void
 
80
Callbacks::registerSocket (void *s, int reading, int writing, bool isSSL)
 
81
{
 
82
    Q_UNUSED( writing );
 
83
    Q_UNUSED( isSSL );
 
84
 
 
85
    WlmSocket *a = (WlmSocket*)s;
 
86
    if (!a)
 
87
        return;
 
88
 
 
89
    if (reading)
 
90
    {
 
91
        QObject::disconnect(a, SIGNAL (readyRead()),0,0);
 
92
        QObject::connect (a, SIGNAL (readyRead()), a,
 
93
                  SLOT (incomingData()));
 
94
    }
 
95
}
 
96
 
 
97
void
 
98
Callbacks::closeSocket (void *s)
 
99
{
 
100
    WlmSocket *a = (WlmSocket*)s;
 
101
    if (a)
 
102
    {
 
103
        a->close ();
 
104
        socketList.removeAll (a);
 
105
        a->deleteLater();
 
106
    }
 
107
}
 
108
 
 
109
void
 
110
Callbacks::unregisterSocket (void *s)
 
111
{
 
112
    WlmSocket *a = (WlmSocket*)s;
 
113
    if (a)
 
114
    {
 
115
        QObject::disconnect(a, SIGNAL (readyRead()),0,0);
 
116
    }
 
117
}
 
118
 
 
119
void
 
120
Callbacks::gotFriendlyName (MSN::NotificationServerConnection * conn,
 
121
                            std::string friendlyname)
 
122
{
 
123
    Q_UNUSED( conn );
 
124
    emit gotDisplayName( WlmUtils::utf8(friendlyname) );
 
125
}
 
126
 
 
127
void
 
128
Callbacks::fileTransferInviteResponse (MSN::SwitchboardServerConnection * conn, 
 
129
                            unsigned int sessionID, bool response)
 
130
{
 
131
    emit slotfileTransferInviteResponse (conn, sessionID, response);
 
132
}
 
133
 
 
134
void
 
135
Callbacks::gotContactDisplayPicture (MSN::SwitchboardServerConnection * conn,
 
136
                                     MSN::Passport passport,
 
137
                                     std::string filename)
 
138
{
 
139
    Q_UNUSED( conn );
 
140
    emit gotDisplayPicture(WlmUtils::passport(passport), WlmUtils::utf8(filename));
 
141
}
 
142
 
 
143
void
 
144
Callbacks::gotMessageSentACK (MSN::SwitchboardServerConnection * conn,
 
145
                              int trID)
 
146
{
 
147
    emit messageSentACK (conn, trID);
 
148
}
 
149
 
 
150
void
 
151
Callbacks::gotBuddyListInfo (MSN::NotificationServerConnection * conn,
 
152
                             MSN::ListSyncInfo * info)
 
153
{
 
154
    // IMPORTANT
 
155
    // Here you need to fill a vector with all your contacts
 
156
    // both received by the server and previous ones.
 
157
    // Next pass this vector to the function completeConnection()
 
158
    // if you do not call completeConnection(), the service will
 
159
    // not work.
 
160
    std::map < std::string, MSN::Buddy * >::iterator i =
 
161
        info->contactList.begin ();
 
162
    std::map < std::string, int >allContacts;
 
163
 
 
164
    for (; i != info->contactList.end (); ++i)
 
165
    {
 
166
        MSN::Buddy * contact = (*i).second;
 
167
        if (contact->lists & MSN::LST_AB       // only if it is the address book
 
168
           && contact->properties["isMessengerUser"] == "true")
 
169
        {
 
170
            allContacts[contact->userName.c_str ()] = 0;
 
171
            allContacts[contact->userName.c_str ()] |= MSN::LST_AB;
 
172
            std::list < MSN::Buddy::PhoneNumber >::iterator pns = contact->phoneNumbers.begin ();
 
173
            std::list < MSN::Group * >::iterator g = contact->groups.begin ();
 
174
        }
 
175
        if (contact->lists & MSN::LST_AL)
 
176
        {
 
177
            allContacts[contact->userName.c_str ()] |= MSN::LST_AL;
 
178
        }
 
179
 
 
180
        if (contact->lists & MSN::LST_BL)
 
181
        {
 
182
            allContacts[contact->userName.c_str ()] |= MSN::LST_BL;
 
183
        }
 
184
 
 
185
        if (contact->lists & MSN::LST_RL)
 
186
        {
 
187
            //printf ("-RL %s \n", contact->userName.c_str ());
 
188
        }
 
189
        if (contact->lists & MSN::LST_PL)
 
190
        {
 
191
            //printf ("-PL %s \n", contact->userName.c_str ());
 
192
        }
 
193
    }
 
194
    //printf ("Available Groups:\n");
 
195
    std::map < std::string, MSN::Group >::iterator g = info->groups.begin ();
 
196
 
 
197
    for (; g != info->groups.end (); g++)
 
198
    {
 
199
        //printf ("    %s: %s\n", (*g).second.groupID.c_str (),
 
200
        //        (*g).second.name.c_str ());
 
201
    }
 
202
 
 
203
    // this will send the ADL command to the server
 
204
    // It is necessary. Do not forget to add *all* your contacts to allContacts,
 
205
    // (both Forward, allow and block lists) or you probably will
 
206
    // loose someone.
 
207
    // A contact cannot be present both on allow and block lists or the
 
208
    // server will return an error, so you need to let your application
 
209
    // choose the better list to put it in.
 
210
    m_server->m_account->groupListReceivedFromServer (info->groups);
 
211
    m_server->m_account->addressBookReceivedFromServer (info->contactList);
 
212
    conn->completeConnection (allContacts, info);
 
213
}
 
214
 
 
215
void
 
216
Callbacks::gotLatestListSerial (MSN::NotificationServerConnection * conn,
 
217
                                std::string lastChange)
 
218
{
 
219
    Q_UNUSED( conn );
 
220
    Q_UNUSED( lastChange );
 
221
}
 
222
 
 
223
void
 
224
Callbacks::gotGTC (MSN::NotificationServerConnection * conn, char c)
 
225
{
 
226
    Q_UNUSED( conn );
 
227
    Q_UNUSED( c );
 
228
}
 
229
 
 
230
void
 
231
Callbacks::gotOIMDeleteConfirmation (MSN::NotificationServerConnection * conn,
 
232
                                     bool success, std::string id)
 
233
{
 
234
    Q_UNUSED( conn );
 
235
 
 
236
    if (success)
 
237
    {
 
238
        emit deletedOIM (WlmUtils::latin1(id), success);
 
239
        std::cout << "OIM " << id << " removed successfully." << std::endl;
 
240
    }
 
241
    else
 
242
        std::cout << "OIM " << id << " not removed successfully." << std::endl;
 
243
 
 
244
}
 
245
 
 
246
void
 
247
Callbacks::gotOIMSendConfirmation (MSN::NotificationServerConnection * conn,
 
248
                                   bool success, int id)
 
249
{
 
250
    Q_UNUSED( conn );
 
251
 
 
252
    if (success)
 
253
        std::cout << "OIM " << id << " sent successfully." << std::endl;
 
254
    else
 
255
        std::cout << "OIM " << id << " not sent successfully." << std::endl;
 
256
}
 
257
 
 
258
void
 
259
Callbacks::gotOIM (MSN::NotificationServerConnection * conn, bool success,
 
260
                   std::string id, std::string message)
 
261
{
 
262
    Q_UNUSED( conn );
 
263
 
 
264
    if (success)
 
265
        emit receivedOIM(WlmUtils::latin1(id), WlmUtils::utf8(message));
 
266
    else
 
267
        std::cout << "Error retreiving OIM " << id << std::endl;
 
268
}
 
269
 
 
270
void
 
271
Callbacks::gotOIMList (MSN::NotificationServerConnection * conn,
 
272
                       std::vector < MSN::eachOIM > OIMs)
 
273
{
 
274
    Q_UNUSED( conn );
 
275
    emit receivedOIMList (OIMs);
 
276
}
 
277
 
 
278
void
 
279
Callbacks::connectionReady (MSN::Connection * conn)
 
280
{
 
281
    Q_UNUSED( conn );
 
282
    emit connectionCompleted ();
 
283
}
 
284
 
 
285
void
 
286
Callbacks::gotBLP (MSN::NotificationServerConnection * conn, char c)
 
287
{
 
288
    Q_UNUSED( conn );
 
289
    Q_UNUSED( c );
 
290
}
 
291
 
 
292
void
 
293
Callbacks::addedListEntry (MSN::NotificationServerConnection * conn,
 
294
                           MSN::ContactList list, MSN::Passport username,
 
295
                           std::string friendlyname)
 
296
{
 
297
    Q_UNUSED( conn );
 
298
    emit gotNewContact (list, WlmUtils::passport(username), WlmUtils::utf8(friendlyname));
 
299
    // after adding the user you need to delete it from the pending list.
 
300
    // it will be added automatically by the msn service
 
301
 
 
302
    // on regular lists you'll never receive the contacts displayname
 
303
    // it is not needed anyway
 
304
}
 
305
 
 
306
void
 
307
Callbacks::removedListEntry (MSN::NotificationServerConnection * conn,
 
308
                             MSN::ContactList list, MSN::Passport username)
 
309
{
 
310
    Q_UNUSED( conn );
 
311
    emit gotRemovedContactFromList (list, WlmUtils::passport(username));
 
312
}
 
313
 
 
314
void
 
315
Callbacks::addedGroup (MSN::NotificationServerConnection * conn, bool added,
 
316
                       std::string groupName, std::string groupID)
 
317
{
 
318
    Q_UNUSED( conn );
 
319
/*    if (added)
 
320
        printf ("A group named %s (%s) was added\n", groupName.c_str (),
 
321
                groupID.c_str ());
 
322
    else
 
323
        printf ("Group (%s) was NOT added\n", groupName.c_str ());
 
324
*/
 
325
    emit gotAddedGroup (added, WlmUtils::utf8(groupName), WlmUtils::latin1(groupID));
 
326
}
 
327
 
 
328
void
 
329
Callbacks::removedGroup (MSN::NotificationServerConnection * conn,
 
330
                         bool removed, std::string groupID)
 
331
{
 
332
    Q_UNUSED( conn );
 
333
/*
 
334
    if (removed)
 
335
        printf ("A group with ID %s was removed\n", groupID.c_str ());
 
336
    else
 
337
        printf ("Group (%s) was NOT removed\n", groupID.c_str ());
 
338
*/
 
339
    emit gotRemovedGroup (removed, WlmUtils::latin1(groupID));
 
340
}
 
341
 
 
342
void
 
343
Callbacks::renamedGroup (MSN::NotificationServerConnection * conn,
 
344
                         bool renamed, std::string newGroupName,
 
345
                         std::string groupID)
 
346
{
 
347
    Q_UNUSED( conn );
 
348
    Q_UNUSED( renamed );
 
349
    Q_UNUSED( newGroupName );
 
350
    Q_UNUSED( groupID );
 
351
/*
 
352
    if (renamed)
 
353
        printf ("A group with ID %s was renamed to %s\n", groupID.c_str (),
 
354
                newGroupName.c_str ());
 
355
    else
 
356
        printf ("A group with ID %s was NOT renamed to %s\n",
 
357
                groupID.c_str (), newGroupName.c_str ());
 
358
*/
 
359
}
 
360
 
 
361
void
 
362
Callbacks::showError (MSN::Connection * conn, std::string msg)
 
363
{
 
364
    std::cout << "MSN: Error: " << msg.c_str () << std::endl;
 
365
    QString a = WlmUtils::latin1(msg);
 
366
    // FIXME This is really ugly the libmsn should send some error code instead of msg
 
367
    if (a.contains("Wrong Password"))
 
368
        emit mainConnectionError(WrongPassword);
 
369
    else if (a.contains("You have logged onto MSN twice at once"))
 
370
        emit mainConnectionError(OtherClient);
 
371
    else if (conn == mainConnection)
 
372
        emit mainConnectionError(Unknown);
 
373
}
 
374
 
 
375
void
 
376
Callbacks::buddyChangedStatus (MSN::NotificationServerConnection * conn,
 
377
                               MSN::Passport buddy, std::string friendlyname,
 
378
                               MSN::BuddyStatus status, unsigned int clientID,
 
379
                               std::string msnobject)
 
380
{
 
381
    Q_UNUSED( conn );
 
382
    emit contactChangedStatus (WlmUtils::passport(buddy), WlmUtils::utf8(friendlyname),
 
383
                               status, clientID, WlmUtils::utf8(msnobject));
 
384
}
 
385
 
 
386
void
 
387
Callbacks::buddyOffline (MSN::NotificationServerConnection * conn,
 
388
                         MSN::Passport buddy)
 
389
{
 
390
    Q_UNUSED( conn );
 
391
    emit contactDisconnected(WlmUtils::passport(buddy));
 
392
}
 
393
 
 
394
void
 
395
Callbacks::gotSwitchboard (MSN::SwitchboardServerConnection * conn,
 
396
                           const void *tag)
 
397
{
 
398
    emit gotNewSwitchboard (dynamic_cast<MSN::SwitchboardServerConnection* >(conn), tag);
 
399
}
 
400
 
 
401
void
 
402
Callbacks::buddyJoinedConversation (MSN::SwitchboardServerConnection * conn,
 
403
                                    MSN::Passport username,
 
404
                                    std::string friendlyname, int is_initial)
 
405
{
 
406
    Q_UNUSED( is_initial );
 
407
 
 
408
    emit joinedConversation (conn, WlmUtils::passport(username), WlmUtils::utf8(friendlyname));
 
409
    const std::pair<std::string, std::string> *ctx = static_cast<const std::pair<std::string, std::string> *>(conn->auth.tag);
 
410
    delete ctx;
 
411
    conn->auth.tag = NULL;
 
412
 
 
413
/*    if (conn->auth.tag)
 
414
    {
 
415
        const std::pair<std::string, std::string> *ctx = static_cast<const std::pair<std::string, std::string> *>(conn->auth.tag);
 
416
        // Example of sending a custom emoticon
 
417
//      conn->myNotificationServer()->msnobj.addMSNObject("/tmp/emoticon.gif",2);
 
418
//      std::string obj;
 
419
//      conn->myNotificationServer()->msnobj.getMSNObjectXML("/tmp/emoticon.gif", 2, obj);
 
420
//      conn->sendEmoticon("(EMOTICON)", obj);
 
421
 
 
422
        conn->sendMessage(ctx->second);
 
423
        delete ctx;
 
424
        conn->auth.tag = NULL;
 
425
 
 
426
        //Example of sending a file
 
427
//      MSN::fileTransferInvite ft;
 
428
//      ft.filename = "/tmp/filetosend.txt";
 
429
//      ft.friendlyname = "filetosend2.txt";
 
430
//      ft.sessionId = sessionID++;
 
431
//      ft.type = MSN::FILE_TRANSFER_WITHOUT_PREVIEW;
 
432
//      conn->sendFile(ft);
 
433
 
 
434
//      conn->sendNudge();
 
435
//      conn->sendAction("Action message here");
 
436
 
 
437
        // Exemple of requesting a display picture.
 
438
//      std::string filename2("/tmp/displayPicture.bin"+MSN::toStr(sessionID));
 
439
        // lastObject is the msnobject received on each contact status change
 
440
        // you should generate a random sessionID
 
441
//      conn->requestFile(sessionID++, filename2, lastObject);
 
442
 
 
443
        // Example of sending a voice clip
 
444
//      conn->myNotificationServer()->msnobj.addMSNObject("/tmp/voiceclip.wav",11);
 
445
//      std::string obj;
 
446
//      conn->myNotificationServer()->msnobj.getMSNObjectXML("/tmp/voiceclip.wav", 11, obj);
 
447
//      conn->sendVoiceClip(obj);
 
448
        // exemple of sending an ink
 
449
//      std::string ink("base64 data here...");
 
450
//      conn->sendInk(ink);
 
451
    }
 
452
    */
 
453
}
 
454
 
 
455
void
 
456
Callbacks::buddyLeftConversation (MSN::SwitchboardServerConnection * conn,
 
457
                                  MSN::Passport username)
 
458
{
 
459
    emit leftConversation (conn, WlmUtils::passport(username));
 
460
 
 
461
}
 
462
 
 
463
void
 
464
Callbacks::gotInstantMessage (MSN::SwitchboardServerConnection * conn,
 
465
                              MSN::Passport username,
 
466
                              std::string friendlyname, MSN::Message * msg)
 
467
{
 
468
    Q_UNUSED( friendlyname );
 
469
 
 
470
    Kopete::Message kmsg;
 
471
    kmsg.setPlainBody(WlmUtils::utf8(msg->getBody()));
 
472
    QFont font (WlmUtils::latin1(msg->getFontName()));
 
473
    if (msg->getFontEffects () & MSN::Message::BOLD_FONT)
 
474
        font.setBold (true);
 
475
    if (msg->getFontEffects () & MSN::Message::ITALIC_FONT)
 
476
        font.setItalic (true);
 
477
    if (msg->getFontEffects () & MSN::Message::UNDERLINE_FONT)
 
478
        font.setUnderline (true);
 
479
    if (msg->getFontEffects () & MSN::Message::STRIKETHROUGH_FONT)
 
480
        font.setStrikeOut (true);
 
481
 
 
482
    QColor color (msg->getColor ()[0], msg->getColor ()[1],
 
483
                  msg->getColor ()[2]);
 
484
    kmsg.setForegroundColor (color);
 
485
 
 
486
    kmsg.setFont (font);
 
487
    emit messageReceived (conn, WlmUtils::passport(username), kmsg);
 
488
}
 
489
 
 
490
void
 
491
Callbacks::gotEmoticonNotification (MSN::SwitchboardServerConnection * conn,
 
492
                                    MSN::Passport username, std::string alias,
 
493
                                    std::string msnobject)
 
494
{
 
495
    emit slotGotEmoticonNotification(conn, WlmUtils::passport(username),
 
496
                                     WlmUtils::utf8(alias), WlmUtils::utf8(msnobject));
 
497
}
 
498
 
 
499
void
 
500
Callbacks::failedSendingMessage (MSN::Connection * conn)
 
501
{
 
502
    Q_UNUSED( conn );
 
503
    //printf ("**************************************************\n");
 
504
    //printf ("ERROR:  Your last message failed to send correctly\n");
 
505
    //printf ("**************************************************\n");
 
506
}
 
507
 
 
508
void
 
509
Callbacks::buddyTyping (MSN::SwitchboardServerConnection * conn,
 
510
                        MSN::Passport username, std::string friendlyname)
 
511
{
 
512
    Q_UNUSED( friendlyname );
 
513
    emit receivedTypingNotification (conn, WlmUtils::passport(username));
 
514
 
 
515
}
 
516
 
 
517
void
 
518
Callbacks::gotNudge (MSN::SwitchboardServerConnection * conn,
 
519
                     MSN::Passport username)
 
520
{
 
521
    emit receivedNudge (conn, WlmUtils::passport(username));
 
522
}
 
523
 
 
524
void
 
525
Callbacks::gotVoiceClipNotification (MSN::SwitchboardServerConnection * conn,
 
526
                         MSN::Passport username, std::string msnobject)
 
527
{
 
528
    emit slotGotVoiceClipNotification(conn, WlmUtils::passport(username), WlmUtils::utf8(msnobject));
 
529
}
 
530
 
 
531
void
 
532
Callbacks::gotWinkNotification (MSN::SwitchboardServerConnection * conn,
 
533
                    MSN::Passport username, std::string msnobject)
 
534
{
 
535
    emit slotGotWinkNotification(conn, WlmUtils::passport(username), WlmUtils::utf8(msnobject));
 
536
}
 
537
 
 
538
void
 
539
Callbacks::gotInk (MSN::SwitchboardServerConnection * conn,
 
540
                   MSN::Passport username, std::string image)
 
541
{
 
542
    emit slotGotInk(conn, WlmUtils::passport(username), QByteArray(image.c_str()));
 
543
}
 
544
 
 
545
void
 
546
Callbacks::gotActionMessage (MSN::SwitchboardServerConnection * conn,
 
547
                             MSN::Passport username, std::string message)
 
548
{
 
549
    Q_UNUSED( conn );
 
550
    Q_UNUSED( username );
 
551
    Q_UNUSED( message );
 
552
}
 
553
 
 
554
void
 
555
Callbacks::gotInitialEmailNotification (MSN::NotificationServerConnection *
 
556
                                        conn, int msgs_inbox,
 
557
                                        int unread_inbox, int msgs_folders,
 
558
                                        int unread_folders)
 
559
{
 
560
    Q_UNUSED( conn );
 
561
    Q_UNUSED( msgs_inbox );
 
562
    Q_UNUSED( msgs_folders );
 
563
    Q_UNUSED( unread_folders );
 
564
 
 
565
    if (unread_inbox > 0)
 
566
        emit initialEmailNotification (unread_inbox);
 
567
}
 
568
 
 
569
void
 
570
Callbacks::gotNewEmailNotification (MSN::NotificationServerConnection * conn,
 
571
                                    std::string from, std::string subject)
 
572
{
 
573
    Q_UNUSED( conn );
 
574
    emit newEmailNotification (WlmUtils::utf8(from), KMime::decodeRFC2047String(subject.c_str()));
 
575
}
 
576
 
 
577
void
 
578
Callbacks::gotInboxUrl (MSN::NotificationServerConnection * conn,
 
579
                        MSN::hotmailInfo info)
 
580
{
 
581
    Q_UNUSED( conn );
 
582
    emit inboxUrl (info);
 
583
}
 
584
 
 
585
void
 
586
Callbacks::fileTransferProgress (MSN::SwitchboardServerConnection * conn,
 
587
                                 unsigned int sessionID,
 
588
                                 unsigned long long transferred,
 
589
                                 unsigned long long total)
 
590
{
 
591
    Q_UNUSED( total );
 
592
    emit gotFileTransferProgress (conn, sessionID, transferred);
 
593
}
 
594
 
 
595
void
 
596
Callbacks::fileTransferFailed (MSN::SwitchboardServerConnection * conn,
 
597
                               unsigned int sessionID, MSN::fileTransferError error)
 
598
{
 
599
    emit gotFileTransferFailed (conn, sessionID, error);
 
600
}
 
601
 
 
602
void
 
603
Callbacks::fileTransferSucceeded (MSN::SwitchboardServerConnection * conn,
 
604
                               unsigned int sessionID)
 
605
{
 
606
    //printf ("File transfer successfully completed. session: %d\n", sessionID);
 
607
    emit gotFileTransferSucceeded (conn, sessionID);
 
608
}
 
609
 
 
610
void
 
611
Callbacks::gotNewConnection (MSN::Connection * conn)
 
612
{
 
613
    if (dynamic_cast < MSN::NotificationServerConnection * >(conn))
 
614
        dynamic_cast <MSN::NotificationServerConnection *>(conn)->synchronizeContactList ();
 
615
}
 
616
 
 
617
void
 
618
Callbacks::buddyChangedPersonalInfo (MSN::NotificationServerConnection * conn,
 
619
                                     MSN::Passport fromPassport,
 
620
                                     MSN::personalInfo pInfo)
 
621
{
 
622
    Q_UNUSED( conn );
 
623
    // MSN::personalInfo shows all the data you can grab from the contact
 
624
    //printf ("User %s Personal Message: %s\n", fromPassport.c_str (),
 
625
    //        pInfo.PSM.c_str ());
 
626
    emit gotContactPersonalInfo (WlmUtils::passport(fromPassport), pInfo);
 
627
}
 
628
 
 
629
void
 
630
Callbacks::closingConnection (MSN::Connection * conn)
 
631
{
 
632
    if (dynamic_cast < MSN::SwitchboardServerConnection * >(conn))
 
633
        emit SwitchboardServerConnectionTerminated (
 
634
                dynamic_cast <MSN::SwitchboardServerConnection* >(conn));
 
635
    if (dynamic_cast < MSN::NotificationServerConnection * >(conn))
 
636
        emit NotificationServerConnectionTerminated (
 
637
                dynamic_cast <MSN::NotificationServerConnection* >(conn));
 
638
}
 
639
 
 
640
void
 
641
Callbacks::changedStatus (MSN::NotificationServerConnection * conn,
 
642
                          MSN::BuddyStatus state)
 
643
{
 
644
    Q_UNUSED( conn );
 
645
    //printf ("Your state is now: %s\n",
 
646
    //        MSN::buddyStatusToString (state).c_str ());
 
647
    emit changedStatus (state);
 
648
/*  MSN::personalInfo pInfo;
 
649
    pInfo.PSM="my personal message";
 
650
    pInfo.mediaType="Music";
 
651
    pInfo.mediaIsEnabled=1;
 
652
    pInfo.mediaFormat="{0} - {1}";
 
653
    pInfo.mediaLines.push_back("Artist");
 
654
    pInfo.mediaLines.push_back("Song");
 
655
    conn->setPersonalStatus(pInfo);
 
656
*/
 
657
}
 
658
 
 
659
size_t 
 
660
Callbacks::getDataFromSocket (void *sock, char *data, size_t size)
 
661
{
 
662
    WlmSocket *a = (WlmSocket*)sock;
 
663
    if (!a)
 
664
        return 0;
 
665
 
 
666
    return a->read(data, size);
 
667
}
 
668
 
 
669
size_t 
 
670
Callbacks::writeDataToSocket (void *sock, char *data, size_t size)
 
671
{
 
672
    WlmSocket *a = (WlmSocket*)sock;
 
673
    if (!a)
 
674
        return 0;
 
675
 
 
676
    return a->write(data, size);
 
677
}
 
678
 
 
679
void *
 
680
Callbacks::connectToServer (std::string hostname, int port, bool * connected, bool isSSL)
 
681
{
 
682
    WlmSocket *a = new WlmSocket (mainConnection, isSSL, m_server);
 
683
    if(!a)
 
684
        return NULL;
 
685
 
 
686
    connect( a, SIGNAL(sslErrors(QList<QSslError>)), a, SLOT(ignoreSslErrors()) );
 
687
    connect( a, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(emitSocketError(QAbstractSocket::SocketError)) );
 
688
 
 
689
    if(!isSSL)
 
690
        a->connectToHost (WlmUtils::latin1(hostname), port);
 
691
    else
 
692
        a->connectToHostEncrypted (WlmUtils::latin1(hostname), port);
 
693
 
 
694
    *connected = false;
 
695
    socketList.append (a);
 
696
    return (void*)a;
 
697
}
 
698
 
 
699
int
 
700
Callbacks::listenOnPort (int port)
 
701
{
 
702
    Q_UNUSED( port );
 
703
    // this callback is not used yet, 
 
704
    // so, for now we are returning a dummy 
 
705
    // value to avoid compiling issues
 
706
    return 0;
 
707
}
 
708
 
 
709
std::string Callbacks::getOurIP (void)
 
710
{
 
711
    // this callback is not used yet, 
 
712
    // so, for now we are returning a dummy 
 
713
    // value to avoid compiling issues
 
714
    return "";
 
715
}
 
716
 
 
717
void
 
718
Callbacks::log (int i, const char *s)
 
719
{
 
720
    Q_UNUSED( i );
 
721
    Q_UNUSED( s );
 
722
}
 
723
 
 
724
int
 
725
Callbacks::getSocketFileDescriptor (void *sock)
 
726
{
 
727
    WlmSocket *a = (WlmSocket*)sock;
 
728
    if(!a)
 
729
        return -1;
 
730
    return a->socketDescriptor();
 
731
}
 
732
 
 
733
std::string Callbacks::getSecureHTTPProxy ()
 
734
{
 
735
    return "";
 
736
}
 
737
 
 
738
void
 
739
Callbacks::askFileTransfer (MSN::SwitchboardServerConnection * conn,
 
740
                            MSN::fileTransferInvite ft)
 
741
{
 
742
    emit incomingFileTransfer (conn, ft);
 
743
/*
 
744
        switch(ft.type)
 
745
        {
 
746
                case MSN::FILE_TRANSFER_BACKGROUND_SHARING:
 
747
                        printf("User %s wants to share with you a background file named %s. Size: %llu. Accepting..\n", ft.userPassport.c_str(), ft.filename.c_str(), ft.filesize);
 
748
                        break;
 
749
                case MSN::FILE_TRANSFER_BACKGROUND_SHARING_CUSTOM:
 
750
                        printf("User %s wants to share with you a *custom background file named %s. Size: %llu. Accepting..\n", ft.userPassport.c_str(), ft.filename.c_str(), ft.filesize);
 
751
                        break;
 
752
                case MSN::FILE_TRANSFER_WITH_PREVIEW:
 
753
                        printf("User %s wants to send you a file *with preview named %s. Size: %llu. Accepting..\n", ft.userPassport.c_str(), ft.filename.c_str(), ft.filesize);
 
754
                        // ft.preview has the base64 encoded png file
 
755
                        break;
 
756
                case MSN::FILE_TRANSFER_WITHOUT_PREVIEW:
 
757
                        printf("User %s wants to send you a file *without preview named %s. Size: %llu. Accepting..\n", ft.userPassport.c_str(), ft.filename.c_str(), ft.filesize);
 
758
                        break;
 
759
                default:
 
760
                        printf("Unknown filetransfer type from %s..\n", ft.userPassport.c_str());
 
761
 
 
762
        }
 
763
        conn->fileTransferResponse(ft.sessionId, filename2, true);
 
764
*/
 
765
}
 
766
 
 
767
void
 
768
Callbacks::addedContactToGroup (MSN::NotificationServerConnection * conn,
 
769
                                bool added, std::string groupId,
 
770
                                std::string contactId)
 
771
{
 
772
    Q_UNUSED( conn );
 
773
/*
 
774
    if (added)
 
775
        printf ("User Id (%s) added to group Id (%s)\n", contactId.c_str (),
 
776
                groupId.c_str ());
 
777
    else
 
778
        printf ("User Id (%s) NOT added to group Id (%s)\n",
 
779
                contactId.c_str (), groupId.c_str ());
 
780
*/
 
781
    emit gotAddedContactToGroup (added, WlmUtils::latin1(groupId),
 
782
                                 WlmUtils::latin1(contactId));
 
783
}
 
784
 
 
785
void
 
786
Callbacks::removedContactFromGroup (MSN::NotificationServerConnection * conn,
 
787
                                    bool removed, std::string groupId,
 
788
                                    std::string contactId)
 
789
{
 
790
    Q_UNUSED( conn );
 
791
/*
 
792
    if (removed)
 
793
        printf ("User Id (%s) removed from group Id (%s)\n",
 
794
                contactId.c_str (), groupId.c_str ());
 
795
    else
 
796
        printf ("User Id (%s) NOT removed from group Id (%s)\n",
 
797
                contactId.c_str (), groupId.c_str ());
 
798
*/
 
799
    emit gotRemovedContactFromGroup (removed, WlmUtils::latin1(groupId),
 
800
                                     WlmUtils::latin1(contactId));
 
801
}
 
802
 
 
803
void
 
804
Callbacks::addedContactToAddressBook (MSN::NotificationServerConnection *
 
805
                                      conn, bool added, std::string passport,
 
806
                                      std::string displayName,
 
807
                                      std::string guid)
 
808
{
 
809
    Q_UNUSED( conn );
 
810
/*
 
811
    if (added)
 
812
        printf ("User (%s - %s) added to AddressBook. Guid (%s)\n",
 
813
                passport.c_str (), displayName.c_str (), guid.c_str ());
 
814
    else
 
815
        printf ("User (%s - %s) NOT added to AddressBook.\n",
 
816
                passport.c_str (), displayName.c_str ());
 
817
*/
 
818
    emit gotAddedContactToAddressBook (added, WlmUtils::passport(passport),
 
819
                                       WlmUtils::utf8(displayName), WlmUtils::latin1(guid));
 
820
}
 
821
 
 
822
void
 
823
Callbacks::removedContactFromAddressBook (MSN::NotificationServerConnection *
 
824
                                          conn, bool removed,
 
825
                                          std::string contactId,
 
826
                                          std::string passport)
 
827
{
 
828
    Q_UNUSED( conn );
 
829
/*
 
830
    if (removed)
 
831
        printf ("User %s removed from AddressBook. Guid (%s)\n",
 
832
                passport.c_str (), contactId.c_str ());
 
833
    else
 
834
        printf ("User %s NOT removed from AddressBook. Guid (%s)\n",
 
835
                passport.c_str (), contactId.c_str ());
 
836
*/
 
837
    emit gotRemovedContactFromAddressBook (removed, WlmUtils::passport(passport),
 
838
                                           WlmUtils::latin1(contactId));
 
839
}
 
840
 
 
841
void
 
842
Callbacks::enabledContactOnAddressBook (MSN::NotificationServerConnection *
 
843
                                        conn, bool enabled,
 
844
                                        std::string contactId,
 
845
                                        std::string passport)
 
846
{
 
847
    Q_UNUSED( conn );
 
848
    Q_UNUSED( enabled );
 
849
    Q_UNUSED( contactId );
 
850
    Q_UNUSED( passport );
 
851
/*
 
852
    // this is used to enable a contact previously disabled from msn, but not fully removed
 
853
    if (enabled)
 
854
        printf ("User (%s) enabled on AddressBook. Guid (%s)\n",
 
855
                passport.c_str (), contactId.c_str ());
 
856
    else
 
857
        printf ("User (%s) NOT enabled on AddressBook. Guid (%s)\n",
 
858
                passport.c_str (), contactId.c_str ());
 
859
*/
 
860
}
 
861
 
 
862
void
 
863
Callbacks::disabledContactOnAddressBook (MSN::NotificationServerConnection *
 
864
                                         conn, bool disabled,
 
865
                                         std::string contactId)
 
866
{
 
867
    Q_UNUSED( conn );
 
868
    Q_UNUSED( disabled );
 
869
    Q_UNUSED( contactId );
 
870
    // this is used when you have disabled this user from msn, but not deleted from hotmail
 
871
    // I suggest to delete the contact instead of disable, since I haven't tested this too much yet
 
872
/*
 
873
    if (disabled)
 
874
        printf ("User disabled on AddressBook. Guid (%s)\n",
 
875
                contactId.c_str ());
 
876
    else
 
877
        printf ("User NOT disabled on AddressBook. Guid (%s)\n",
 
878
                contactId.c_str ());
 
879
*/
 
880
}
 
881
 
 
882
void Callbacks::gotVoiceClipFile(MSN::SwitchboardServerConnection * conn, unsigned int sessionID, std::string file)
 
883
{
 
884
    emit slotGotVoiceClipFile(conn, sessionID, WlmUtils::utf8(file));
 
885
}
 
886
 
 
887
void Callbacks::gotEmoticonFile(MSN::SwitchboardServerConnection * conn, unsigned int sessionID, std::string alias, std::string file)
 
888
{
 
889
    emit slotGotEmoticonFile(conn, sessionID, WlmUtils::utf8(alias), WlmUtils::utf8(file));
 
890
}
 
891
 
 
892
void Callbacks::gotWinkFile(MSN::SwitchboardServerConnection * conn, unsigned int sessionID, std::string file)
 
893
{
 
894
    emit slotGotWinkFile(conn, sessionID, WlmUtils::utf8(file));
 
895
}
 
896
 
 
897
void Callbacks::emitSocketError( QAbstractSocket::SocketError error )
 
898
{
 
899
    if ( !mainConnection )
 
900
        return;
 
901
 
 
902
    WlmSocket* socket = qobject_cast<WlmSocket*>(sender());
 
903
    Q_ASSERT( socket );
 
904
 
 
905
    MSN::Connection *c = mainConnection->connectionWithSocket((void*)socket);
 
906
    if ( !c )
 
907
        return;
 
908
 
 
909
    if ( c == mainConnection )
 
910
        emit socketError( error );
 
911
    else
 
912
        c->disconnect();
 
913
}
 
914
 
 
915
#include "wlmlibmsn.moc"