summaryrefslogtreecommitdiffstats
path: root/kopete/protocols/oscar/liboscar/serverversionstask.cpp
blob: 336f3b02125ae23e127a33939e70594e460e491a (plain)
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
/*
    Kopete Oscar Protocol
    serverversionstask.cpp - Handles the snac family versions

    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 "serverversionstask.h"

#include <kdebug.h>

#include "connection.h"
#include "buffer.h"
#include "oscartypes.h"
#include "oscarutils.h"
#include "transfer.h"


using namespace Oscar;

ServerVersionsTask::ServerVersionsTask( Task* parent )
 : Task( parent )
{
    m_family = 0;
}


ServerVersionsTask::~ServerVersionsTask()
{
}


bool ServerVersionsTask::forMe( const Transfer* transfer ) const
{
	const SnacTransfer* st = dynamic_cast<const SnacTransfer*> ( transfer );
	
	if (!st)
		return false;
	
	if ( st->snacService() == 1 )
	{
		switch ( st->snacSubtype() )
		{
		case 0x03:
		case 0x17:
		case 0x18:
			return true;
			break;
		default:
			return false;
		}
	}
	return false;
}

bool ServerVersionsTask::take( Transfer* transfer )
{	
	SnacTransfer* st = dynamic_cast<SnacTransfer*> ( transfer );
	if (!st)
		return false;
	
	if ( forMe( transfer ) )
	{
		switch ( st->snacSubtype() )
		{
			case 0x03:
				setTransfer( transfer );
				handleFamilies();
				setTransfer( 0 );
				return true;
				break;
			case 0x18:
				setTransfer( transfer );
				handleServerVersions();
				setTransfer( 0 );
				return true;
				break;
			default:
				return false;
		}
	}
	return false;
}

void ServerVersionsTask::handleFamilies()
{
	kdDebug(OSCAR_RAW_DEBUG) << k_funcinfo 
		<< "RECV SNAC 0x01, 0x03 - got the list of families server supports" << endl;

	Buffer* outbuf = transfer()->buffer();
	if ( outbuf->length() % 2 != 0 )
	{
		setError( -1, TQString() );
		return;
	}

	while ( outbuf->length () != 0 )
	{
		m_familiesList.append( outbuf->getWord() );
	}
	client()->addToSupportedFamilies( m_familiesList );
	requestFamilyVersions(); // send back a CLI_FAMILIES packet
}

void ServerVersionsTask::requestFamilyVersions()
{
	bool isIcq = client()->isIcq();
	int listLength = m_familiesList.count();

	FLAP f = { 0x02, 0, 0 };
	SNAC s = { 0x0001, 0x0017, 0x0000, client()->snacSequence() };
	WORD val;
	Buffer* outbuf = new Buffer();

	kdDebug(OSCAR_RAW_DEBUG) << k_funcinfo << "SEND SNAC 0x01, 0x17 - Snac family versions we want" << endl;

	for ( int i = 0; i < listLength; i++ )
	{
		outbuf->addWord( m_familiesList[i] );
		if ( m_familiesList[i] == 0x0001 )
			val = 0x0003;
		else
		{
			if ( m_familiesList[i] == 0x0013 )
			{
				if ( isIcq )
					val = 0x0004; // for ICQ2002
				else
					val = 0x0003;
			}
			else
				val = 0x0001;
		}

		outbuf->addWord(val);
	}

	Transfer* st = createTransfer( f, s, outbuf );
	st->toString();
	send( st );
}

void ServerVersionsTask::handleServerVersions()
{
	kdDebug(OSCAR_RAW_DEBUG) << k_funcinfo <<
		"RECV SNAC 0x01, 0x18, got list of families this server understands" << endl;

	Buffer* buffer = transfer()->buffer();
	int numFamilies = m_familiesList.count();
	for ( int srvFamCount = 0; srvFamCount < numFamilies; srvFamCount++ )
	{
		kdDebug(OSCAR_RAW_DEBUG) << k_funcinfo << "server version=" << buffer->getWord()
			 << ", server family=" << buffer->getWord() << endl;
	}
	setSuccess( 0, TQString() );
}

#include "serverversionstask.moc"