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

« back to all changes in this revision

Viewing changes to protocols/yahoo/libkyahoo/messagereceivertask.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
    Kopete Yahoo Protocol
 
3
    Receive Messages
 
4
 
 
5
    Copyright (c) 2005 André Duffeck <duffeck@kde.org>
 
6
 
 
7
    *************************************************************************
 
8
    *                                                                       *
 
9
    * This library is free software; you can redistribute it and/or         *
 
10
    * modify it under the terms of the GNU Lesser General Public            *
 
11
    * License as published by the Free Software Foundation; either          *
 
12
    * version 2 of the License, or (at your option) any later version.      *
 
13
    *                                                                       *
 
14
    *************************************************************************
 
15
*/
 
16
 
 
17
#include <qstring.h>
 
18
 
 
19
#include "messagereceivertask.h"
 
20
#include "transfer.h"
 
21
#include "ymsgtransfer.h"
 
22
#include "yahootypes.h"
 
23
#include "client.h"
 
24
#include <kdebug.h>
 
25
 
 
26
using namespace KYahoo;
 
27
 
 
28
MessageReceiverTask::MessageReceiverTask(Task* parent) : Task(parent)
 
29
{
 
30
        kDebug(YAHOO_RAW_DEBUG) ;
 
31
}
 
32
 
 
33
MessageReceiverTask::~MessageReceiverTask()
 
34
{
 
35
}
 
36
 
 
37
bool MessageReceiverTask::take( Transfer* transfer )
 
38
{
 
39
        if ( !forMe( transfer ) )
 
40
                return false;
 
41
 
 
42
        YMSGTransfer *t = 0L;
 
43
        t = dynamic_cast<YMSGTransfer*>(transfer);
 
44
        if (!t)
 
45
                return false;
 
46
        
 
47
        if( t->service() == Yahoo::ServiceNotify )
 
48
        {
 
49
                parseNotify( t );
 
50
        }
 
51
        else
 
52
        {
 
53
                if( t->service() == Yahoo::ServiceAnimatedAudibleIcon )
 
54
                {
 
55
                        parseAnimatedAudibleIcon( t );
 
56
                }
 
57
                else
 
58
                {
 
59
                        parseMessage( t );
 
60
                }
 
61
        }
 
62
 
 
63
        return true;
 
64
}
 
65
 
 
66
bool MessageReceiverTask::forMe( const Transfer* transfer ) const
 
67
{
 
68
        const YMSGTransfer *t = 0L;
 
69
        t = dynamic_cast<const YMSGTransfer*>(transfer);
 
70
        if (!t)
 
71
                return false;
 
72
 
 
73
        if ( t->service() == Yahoo::ServiceMessage ||
 
74
                t->service() == Yahoo::ServiceGameMsg ||
 
75
                t->service() == Yahoo::ServiceSysMessage ||
 
76
                t->service() == Yahoo::ServiceNotify ||
 
77
                t->service() == Yahoo::ServiceAnimatedAudibleIcon )     
 
78
                return true;
 
79
        else
 
80
                return false;
 
81
}
 
82
 
 
83
void MessageReceiverTask::parseMessage( YMSGTransfer *t )
 
84
{
 
85
        kDebug(YAHOO_RAW_DEBUG) ;
 
86
 
 
87
        int cnt = t->paramCount( 5 );
 
88
        for( int i = 0; i < cnt; ++i )
 
89
        {
 
90
                QString to = t->nthParam( 5, i );
 
91
                QString timestamp = t->nthParamSeparated( 15, i, 4 );
 
92
                QString utf8 = t->nthParamSeparated( 97, i, 4 );
 
93
                QString from = t->nthParamSeparated( 1, i, 4 ).isEmpty() ? t->nthParam( 4, i ) : t->nthParamSeparated( 1, i, 4 );
 
94
                QString msg = t->nthParamSeparated( 14, i, 4 );
 
95
                QString sysmsg = t->nthParamSeparated( 16, i, 4 );
 
96
 
 
97
                // The arrangement of the key->value pairs is different when there is only one message in the packet.
 
98
                // Separating by key "5" (sender) doesn't work in that case, because the "1" and "4" keys are sent before the "5" key
 
99
                if( cnt == 1 )
 
100
                        from = t->firstParam( 1 ).isEmpty() ? t->firstParam( 4 ) : t->firstParam( 1 );
 
101
 
 
102
                if( !sysmsg.isEmpty() )
 
103
                {
 
104
                        client()->notifyError( "Server message received: ", sysmsg, Client::Error );
 
105
                        continue;
 
106
                }
 
107
        
 
108
                if( msg.isEmpty() )
 
109
                {
 
110
                        kDebug(YAHOO_RAW_DEBUG) << "Got a empty message. Dropped.";
 
111
                        continue;
 
112
                }
 
113
        
 
114
                if( utf8.startsWith( '1' ) )
 
115
                        msg = QString::fromUtf8( msg.toLatin1() );
 
116
        
 
117
                if( t->service() == Yahoo::ServiceSysMessage )
 
118
                        emit systemMessage( sysmsg );
 
119
                else
 
120
                {       
 
121
                        if( msg.startsWith( "<ding>" ) )
 
122
                                emit gotBuzz( from, timestamp.toLong() );
 
123
                        else
 
124
                                emit gotIm( from, msg, timestamp.toLong(), 0);
 
125
                }
 
126
        }
 
127
}
 
128
 
 
129
void MessageReceiverTask::parseAnimatedAudibleIcon( YMSGTransfer *t )
 
130
{
 
131
        // added by michaelacole
 
132
        kDebug(YAHOO_RAW_DEBUG) ;
 
133
 
 
134
        int cnt = t->paramCount( 5 );
 
135
        for( int i = 0; i < cnt; ++i )
 
136
        {
 
137
                QString to = t->nthParam( 5, i );
 
138
                QString from = t->nthParamSeparated( 1, i, 4 ).isEmpty() ? t->nthParam( 4, i ) : t->nthParamSeparated( 1, i, 4 );
 
139
                QString msg = t->nthParamSeparated( 231, i, 4 );
 
140
                QString msg2 = t->nthParamSeparated( 230, i, 4 );
 
141
                QString utf8 = t->nthParamSeparated( 97, i, 4 );
 
142
                QString timestamp = t->nthParamSeparated( 15, i, 4 );
 
143
 
 
144
                // The arrangement of the key->value pairs is different when there is only one message in the packet.
 
145
                // Separating by key "5" (sender) doesn't work in that case, because the "1" and "4" keys are sent before the "5" key
 
146
                if( cnt == 1 )
 
147
                        from = t->firstParam( 1 ).isEmpty() ? t->firstParam( 4 ) : t->firstParam( 1 );
 
148
 
 
149
                if( msg.isEmpty() )
 
150
                {
 
151
                        kDebug(YAHOO_RAW_DEBUG) << "Got a empty message. Dropped.";
 
152
                        continue;
 
153
                }
 
154
 
 
155
                if( utf8.startsWith( '1' ) )
 
156
                {
 
157
                        msg = QString::fromUtf8( msg.toLatin1() );
 
158
                }
 
159
                
 
160
                msg = "ANIMATED AUDIBLE SENT TO YOU WITH TEXT " + msg;
 
161
                emit gotIm( from, msg, timestamp.toLong(), 0);
 
162
                msg2 = "http://us.dl1.yimg.com//download.yahoo.com/dl/aud/"+msg2.mid(5,2)+"/" + msg2 + ".swf";
 
163
                emit gotIm( from, msg2,timestamp.toLong(), 0);
 
164
 
 
165
        }
 
166
}
 
167
 
 
168
void MessageReceiverTask::parseNotify( YMSGTransfer *t )
 
169
{
 
170
        kDebug(YAHOO_RAW_DEBUG) ;
 
171
 
 
172
        QString from = t->firstParam( 4 );
 
173
        //QString to = t->firstParam( 5 );
 
174
        QString type = t->firstParam( 49 );
 
175
        QString stat = t->firstParam( 13 );
 
176
        QString ind = t->firstParam( 14 );
 
177
 
 
178
        if( type.startsWith( "TYPING" ) )
 
179
                emit gotTypingNotify( from, stat.toInt() );
 
180
        else if( type.startsWith( "GAME" ) )
 
181
                ;
 
182
        else if( type.startsWith( "WEBCAMINVITE" ) )
 
183
        {
 
184
                if( ind.startsWith(' ') )
 
185
                {
 
186
                        kDebug(YAHOO_RAW_DEBUG) << "Got a WebcamInvitation.";
 
187
                        emit gotWebcamInvite( from );
 
188
                }
 
189
                else
 
190
                {
 
191
                        kDebug(YAHOO_RAW_DEBUG) << "Got a WebcamRequest-Response: " << ind.toInt();
 
192
                }
 
193
        }
 
194
}
 
195
 
 
196
#include "messagereceivertask.moc"