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
|
/*
Kopete Oscar Protocol
ssiauthtask.cpp - SSI Authentication Task
Copyright (c) 2004 Gustavo Pichorim Boiko <[email protected]>
Kopete (c) 2002-2004 by the Kopete developers <[email protected]>
*************************************************************************
* *
* 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 "ssiauthtask.h"
#include "ssimanager.h"
#include "transfer.h"
#include "buffer.h"
#include "connection.h"
#include "oscarutils.h"
#include <kdebug.h>
SSIAuthTask::SSIAuthTask( Task* parent )
: Task( parent )
{
m_manager = parent->client()->ssiManager();
}
SSIAuthTask::~SSIAuthTask()
{
}
bool SSIAuthTask::forMe( const Transfer* t ) const
{
const SnacTransfer* st = dynamic_cast<const SnacTransfer*> ( t );
if ( !st )
return false;
if ( st->snacService() != 0x0013 )
return false;
switch ( st->snacSubtype() )
{
case 0x0015: // Future authorization granted
case 0x0019: // Authorization request
case 0x001b: // Authorization reply
case 0x001c: // "You were added" message
return true;
break;
default:
return false;
}
}
bool SSIAuthTask::take( Transfer* t )
{
if ( forMe( t ) )
{
setTransfer( t );
SnacTransfer* st = dynamic_cast<SnacTransfer*> ( t );
switch ( st->snacSubtype() )
{
case 0x0015: // Future authorization granted
handleFutureAuthGranted();
break;
case 0x0019: // Authorization request
handleAuthRequested();
break;
case 0x001b: // Authorization reply
handleAuthReplied();
break;
case 0x001c: // "You were added" message
handleAddedMessage();
break;
}
setTransfer( 0 );
return true;
}
return false;
}
void SSIAuthTask::grantFutureAuth( const TQString& uin, const TQString& reason )
{
FLAP f = { 0x02, 0, 0 };
SNAC s = { 0x0013, 0x0014, 0x0000, client()->snacSequence() };
Buffer* buf = new Buffer();
buf->addBUIN( uin.latin1() );
buf->addBSTR( reason.utf8() );
buf->addWord( 0x0000 ); // Unknown
Transfer* t = createTransfer( f, s, buf );
send( t );
}
void SSIAuthTask::sendAuthRequest( const TQString& uin, const TQString& reason )
{
FLAP f = { 0x02, 0, 0 };
SNAC s = { 0x0013, 0x0018, 0x0000, client()->snacSequence() };
Buffer* buf = new Buffer();
buf->addBUIN( uin.latin1() );
buf->addBSTR( reason.utf8() );
buf->addWord( 0x0000 ); // Unknown
Transfer* t = createTransfer( f, s, buf );
send( t );
}
void SSIAuthTask::sendAuthReply( const TQString& uin, const TQString& reason, bool auth )
{
FLAP f = { 0x02, 0, 0 };
SNAC s = { 0x0013, 0x001A, 0x0000, client()->snacSequence() };
Buffer* buf = new Buffer();
buf->addBUIN( uin.latin1() );
buf->addByte( auth ? 0x01 : 0x00 ); // accepted / declined
buf->addBSTR( reason.utf8() );
Transfer* t = createTransfer( f, s, buf );
send( t );
}
void SSIAuthTask::handleFutureAuthGranted()
{
Buffer* buf = transfer()->buffer();
TQString uin = Oscar::normalize( buf->getBUIN() );
TQByteArray reason = buf->getBSTR();
buf->getWord(); // 0x0000 - Unknown
kdDebug( OSCAR_RAW_DEBUG ) << k_funcinfo << "Future authorization granted from " << uin << endl;
kdDebug( OSCAR_RAW_DEBUG ) << k_funcinfo << "Reason: " << reason << endl;
emit futureAuthGranted( uin, TQString::fromUtf8( reason.data(), reason.size() ) );
}
void SSIAuthTask::handleAuthRequested()
{
Buffer* buf = transfer()->buffer();
TQString uin = Oscar::normalize( buf->getBUIN() );
TQByteArray reason = buf->getBSTR();
buf->getWord(); // 0x0000 - Unknown
kdDebug( OSCAR_RAW_DEBUG ) << k_funcinfo << "Authorization requested from " << uin << endl;
kdDebug( OSCAR_RAW_DEBUG ) << k_funcinfo << "Reason: " << reason << endl;
emit authRequested( uin, TQString::fromUtf8( reason.data(), reason.size() ) );
}
void SSIAuthTask::handleAuthReplied()
{
Buffer* buf = transfer()->buffer();
TQString uin = Oscar::normalize( buf->getBUIN() );
bool accepted = buf->getByte();
TQByteArray reason = buf->getBSTR();
if ( accepted )
kdDebug( OSCAR_RAW_DEBUG ) << k_funcinfo << "Authorization request accepted by " << uin << endl;
else
kdDebug( OSCAR_RAW_DEBUG ) << k_funcinfo << "Authorization request declined by " << uin << endl;
kdDebug( OSCAR_RAW_DEBUG ) << k_funcinfo << "Reason: " << reason << endl;
emit authReplied( uin, TQString::fromUtf8( reason.data(), reason.size() ), accepted );
}
void SSIAuthTask::handleAddedMessage()
{
Buffer* buf = transfer()->buffer();
TQString uin = Oscar::normalize( buf->getBUIN() );
kdDebug( OSCAR_RAW_DEBUG ) << k_funcinfo << "User " << uin << " added you to the contact list" << endl;
emit contactAddedYou( uin );
}
#include "ssiauthtask.moc"
//kate: tab-width 4; indent-mode csands;
|