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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
|
/*
Kopete Oscar Protocol
logintask.cpp - Handles logging into to the AIM or ICQ service
Copyright (c) 2004 Matt Rogers <mattr@kde.org>
Kopete (c) 2002-2004 by the Kopete developers <kopete-devel@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 of the License, or (at your option) any later version. *
* *
*************************************************************************
*/
#include "logintask.h"
#include <tqtimer.h>
#include <kdebug.h>
#include <klocale.h>
#include "aimlogintask.h"
#include "connection.h"
#include "closeconnectiontask.h"
#include "icqlogintask.h"
#include "oscarutils.h"
#include "rateinfotask.h"
#include "serverversionstask.h"
#include "transfer.h"
/**
* Stage One Task Implementation
*/
StageOneLoginTask::StageOneLoginTask( Task* parent )
: Task ( parent )
{
m_aimTask = 0L;
m_icqTask = 0L;
m_closeTask = 0L;
}
StageOneLoginTask::~StageOneLoginTask()
{
delete m_aimTask;
delete m_icqTask;
delete m_closeTask;
}
bool StageOneLoginTask::take( Transfer* transfer )
{
if ( forMe( transfer ) )
{
if ( client()->isIcq() )
{
kdDebug(OSCAR_RAW_DEBUG) << k_funcinfo << "Starting ICQ login" << endl;
m_icqTask = new IcqLoginTask( client()->rootTask() );
m_closeTask = new CloseConnectionTask( client()->rootTask() );
//connect finished signal
connect( m_closeTask, TQT_SIGNAL( finished() ), this, TQT_SLOT( closeTaskFinished() ) );
m_icqTask->go( true );
}
else
{
kdDebug(OSCAR_RAW_DEBUG) << k_funcinfo << "Starting AIM login" << endl;
kdDebug(OSCAR_RAW_DEBUG) << k_funcinfo << "Sending the FLAP version back" << endl;
//send the flap version response
FLAP f = { 0x01, 0 , 0 };
Buffer *outbuf = new Buffer;
outbuf->addDWord(0x00000001); //flap version
f.length = outbuf->length();
Transfer* ft = createTransfer( f, outbuf );
send( ft );
m_aimTask = new AimLoginTask( client()->rootTask() );
connect( m_aimTask, TQT_SIGNAL( finished() ), this, TQT_SLOT( aimTaskFinished() ) );
m_aimTask->go( true );
}
return true;
}
return false;
}
void StageOneLoginTask::closeTaskFinished()
{
kdDebug(OSCAR_RAW_DEBUG) << k_funcinfo << endl;
m_cookie = m_closeTask->cookie();
m_bosPort = m_closeTask->bosPort();
m_bosServer = m_closeTask->bosHost();
m_closeTask->safeDelete();
setSuccess( m_closeTask->statusCode(), m_closeTask->statusString() );
}
void StageOneLoginTask::aimTaskFinished()
{
kdDebug(OSCAR_RAW_DEBUG) << k_funcinfo << endl;
m_cookie = m_aimTask->cookie();
m_bosPort = m_aimTask->bosPort();
m_bosServer = m_aimTask->bosHost();
setSuccess( m_aimTask->statusCode(), m_aimTask->statusString() );
}
bool StageOneLoginTask::forMe( Transfer* transfer ) const
{
FlapTransfer* ft = dynamic_cast<FlapTransfer*> ( transfer );
if (!ft)
return false;
return ( ft && ft->flapChannel() == 1 );
}
const TQByteArray& StageOneLoginTask::loginCookie() const
{
return m_cookie;
}
const TQString& StageOneLoginTask::bosServer() const
{
return m_bosServer;
}
const TQString& StageOneLoginTask::bosPort() const
{
return m_bosPort;
}
/**
* Stage Two Task Implementation
*/
StageTwoLoginTask::StageTwoLoginTask( Task* parent )
: Task( parent )
{
//Create our tasks
Task* rootTask = client()->rootTask();
m_versionTask = new ServerVersionsTask( rootTask );
m_rateTask = new RateInfoTask( rootTask );
TQObject::connect( m_versionTask, TQT_SIGNAL( finished() ), this, TQT_SLOT( versionTaskFinished() ) );
TQObject::connect( m_rateTask, TQT_SIGNAL( finished() ), this, TQT_SLOT( rateTaskFinished() ) );
}
StageTwoLoginTask::~StageTwoLoginTask()
{
delete m_versionTask;
}
bool StageTwoLoginTask::take( Transfer* transfer )
{
bool yes = forMe( transfer );
return yes;
}
bool StageTwoLoginTask::forMe( Transfer* transfer ) const
{
FlapTransfer* ft = dynamic_cast<FlapTransfer*>( transfer );
if (!ft)
return false;
int channel = ft->flapChannel();
if ( channel == 1 )
return true;
else
return false;
}
void StageTwoLoginTask::onGo()
{
if ( !m_cookie.isEmpty() )
{
//send the flap back
FLAP f = { 0x01, 0, 0 };
Buffer* outbuf = new Buffer();
outbuf->addDWord( 0x00000001 );
outbuf->addTLV( 0x06, m_cookie.size(), m_cookie.data() );
Transfer* ft = createTransfer( f, outbuf );
kdDebug(OSCAR_RAW_DEBUG) << k_funcinfo << "Sending the login cookie back" << endl;
send( ft );
}
else
setError( -1, TQString() );
return;
}
void StageTwoLoginTask::setCookie( const TQByteArray& newCookie )
{
m_cookie.duplicate( newCookie );
}
const TQByteArray& StageTwoLoginTask::cookie()
{
return m_cookie;
}
void StageTwoLoginTask::versionTaskFinished()
{
//start the rate info task
m_rateTask->go(true);
}
void StageTwoLoginTask::rateTaskFinished()
{
setSuccess( 0, TQString() );
}
#include "logintask.moc"
//kate: tab-width 4; indent-mode csands;
|