1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
|
// Kopete Oscar Protocol - Server redirections
// Copyright (C) 2005 Matt Rogers <mattr@kde.org>
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
// 02110-1301 USA
#include "serverredirecttask.h"
#include <kdebug.h>
#include "buffer.h"
#include "connection.h"
#include "transfer.h"
ServerRedirectTask::ServerRedirectTask( Task* parent )
:Task( parent ), m_service( 0 )
{
}
void ServerRedirectTask::setService( WORD family )
{
m_service = family;
}
void ServerRedirectTask::setChatParams( WORD exchange, QByteArray cookie, WORD instance )
{
m_chatExchange = exchange;
m_chatCookie.duplicate( cookie );
kdDebug(OSCAR_RAW_DEBUG) << k_funcinfo << "cookie is" << m_chatCookie << endl;
m_chatInstance = instance;
}
void ServerRedirectTask::setChatRoom( const QString& roomName )
{
m_chatRoom = roomName;
}
void ServerRedirectTask::onGo()
{
if ( m_service != 0 )
requestNewService();
}
bool ServerRedirectTask::forMe( const Transfer* transfer )
{
const SnacTransfer* st = dynamic_cast<const SnacTransfer*>( transfer );
if ( !st )
return false;
if ( st->snacService() == 1 && st->snacSubtype() == 0x0005 )
return true;
else
return false;
}
bool ServerRedirectTask::take( Transfer* transfer )
{
if ( !forMe( transfer ) )
return false;
setTransfer( transfer );
bool value = handleRedirect();
setSuccess( 0, QString::null );
setTransfer( 0 );
return value;
}
void ServerRedirectTask::requestNewService()
{
FLAP f = { 0x02, 0, 0x00 };
SNAC s = { 0x0001, 0x0004, 0x0000, client()->snacSequence() };
Buffer* b = new Buffer();
b->addWord( m_service );
kdDebug(OSCAR_RAW_DEBUG) << k_funcinfo << "Requesting server for service " << m_service << endl;
if ( m_service == 0x000E )
{
b->addWord( 0x0001 );
b->addWord( m_chatCookie.size() + 5 );
b->addWord( m_chatExchange );
b->addByte( m_chatCookie.size() );
b->addString( m_chatCookie );
b->addWord( m_chatInstance );
}
Transfer* t = createTransfer( f, s, b );
send( t );
}
bool ServerRedirectTask::handleRedirect()
{
//TLVs 0x0D, 0x05, 0x06
//family id
//server
//auth cookie
Buffer* b = transfer()->buffer();
WORD typeD = b->getWord();
WORD typeDLen = b->getWord();
if ( typeD == 0x000D && typeDLen == 0x0002)
{
WORD realService = b->getWord();
if ( realService != m_service )
{
kdDebug(OSCAR_RAW_DEBUG) << k_funcinfo << "wrong service for this task" << endl;
kdDebug(OSCAR_RAW_DEBUG ) << k_funcinfo << "should be " << m_service << " is "
<< realService << endl;
return false;
}
}
else
return false;
TLV server = b->getTLV();
m_newHost = QString( server.data );
kdDebug(OSCAR_RAW_DEBUG) << k_funcinfo << "Host for service " << m_service
<< " is " << m_newHost << endl;
if ( m_newHost.isEmpty() )
return false;
TLV cookie = b->getTLV();
if ( cookie.length == 0 || cookie.data.isEmpty() )
return false;
else
m_cookie = cookie.data;
emit haveServer( m_newHost, m_cookie, m_service );
return true;
}
QByteArray ServerRedirectTask::cookie() const
{
return m_cookie;
}
QString ServerRedirectTask::newHost() const
{
return m_newHost;
}
WORD ServerRedirectTask::service() const
{
return m_service;
}
WORD ServerRedirectTask::chatExchange() const
{
return m_chatExchange;
}
QString ServerRedirectTask::chatRoomName() const
{
return m_chatRoom;
}
#include "serverredirecttask.moc"
//kate: indent-mode csands; tab-width 4;
|