summaryrefslogtreecommitdiffstats
path: root/kopete/protocols/oscar/liboscar/usersearchtask.cpp
blob: 545706a5359251ac3545d055810f7168847a2daf (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
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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
/*
   Kopete Oscar Protocol
   usersearchtask.cpp - Search for contacts

   Copyright (c) 2004 Gustavo Pichorim Boiko <gustavo.boiko@kdemail.net>

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

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

UserSearchTask::UserSearchTask( Task* parent )
 : ICQTask( parent )
{
}


UserSearchTask::~UserSearchTask()
{
}

void UserSearchTask::onGo()
{
}

bool UserSearchTask::forMe( const Transfer* t ) const
{
	const SnacTransfer* st = dynamic_cast<const SnacTransfer*>( t );
	
	if ( !st )
		return false;
	
	if ( st->snacService() != 0x0015 || st->snacSubtype() != 0x0003 )
		return false;
		
	Buffer buf( st->buffer()->buffer(), st->buffer()->length() );
	const_cast<UserSearchTask*>(this)->parseInitialData( buf );
	
	if ( requestType() == 0x07da && ( requestSubType() == 0x01a4 || requestSubType() == 0x01ae ) )
		return true;

	return false;
}

bool UserSearchTask::take( Transfer* t )
{
	if ( forMe( t ) )
	{
		setTransfer( t );
		
		Q_UINT16 seq = 0;
		SnacTransfer* st = dynamic_cast<SnacTransfer*>( t );
		if ( st )
			seq = st->snacRequest();
		
		TLV tlv1 = transfer()->buffer()->getTLV();
		
		if ( seq == 0 )
		{
			setTransfer( 0 );
			return false;
		}
			
		Buffer* buffer = new Buffer( tlv1.data, tlv1.length );
		ICQSearchResult result;
		buffer->getLEWord(); // data chunk size
		/*DWORD receiverUin =*/ buffer->getLEDWord(); // target uin
		buffer->getLEWord(); // request type
		buffer->getLEWord(); // request sequence number: 0x0002
		buffer->getLEWord(); // request subtype
		
		BYTE success = buffer->getByte(); // Success byte: always 0x0a
		
		if ( ( success == 0x32 ) || ( success == 0x14 ) || ( success == 0x1E ) )
			result.uin = 1;
		else
			result.fill( buffer );
		
		m_results.append( result );
		
		emit foundUser( result );
		
		// Last user found reply
		if ( requestSubType() == 0x01ae )
		{
			int moreUsersCount = buffer->getLEDWord();
			emit searchFinished( moreUsersCount );
			setSuccess( 0, TQString::null );
		}
		setTransfer( 0 );
	}
	return true;
}

void UserSearchTask::searchUserByUIN( const TQString& uin )
{
	//create a new result list
	m_type = UINSearch;
	
	FLAP f = { 0x02, 0, 0 };
	SNAC s = { 0x0015, 0x0002, 0x0000, client()->snacSequence() };
	
	setRequestType( 0x07D0 ); //meta-information request
	setRequestSubType( 0x0569 ); //subtype: META_SEARCH_BY_UIN
	setSequence( f.sequence );
	Buffer* tlvdata = new Buffer();
	tlvdata->addLEWord( 0x0136 ); //tlv of type 0x0136 with length 4. all little endian
	tlvdata->addLEWord( 0x0004 );
	tlvdata->addLEDWord( uin.toULong() );
	Buffer* buf = addInitialData( tlvdata );
	delete tlvdata;
	
	Transfer* t = createTransfer( f, s, buf );
	send( t );
}

void UserSearchTask::searchWhitePages( const ICQWPSearchInfo& info )
{
	m_type = WhitepageSearch;
	
	FLAP f = { 0x02, 0, 0 };
	SNAC s = { 0x0015, 0x0002, 0x0000, client()->snacSequence() };
	
	setRequestType( 0x07D0 );
	setRequestSubType( 0x055F );
	setSequence( f.sequence );
	Buffer* tlvData = new Buffer();
	/*
		search.addLEWord(0x0533); // subtype: 1331
	
	//LNTS FIRST
	search.addLEWord(first.length());
	if(first.length()>0)
		search.addLEString(first.latin1(), first.length());
	
	// LNTS LAST
	search.addLEWord(last.length());
	if(last.length()>0)
		search.addLEString(last.latin1(), last.length());
	
	// LNTS NICK
	search.addLEWord(nick.length());
	if(nick.length()>0)
		search.addLEString(nick.latin1(), nick.length());
	
	// LNTS EMAIL
	search.addLEWord(mail.length());
	if(mail.length()>0)
		search.addLEString(mail.latin1(), mail.length());
	
	// WORD.L MINAGE
	search.addLEWord(minage);
	
	// WORD.L MAXAGE
	search.addLEWord(maxage);
	
	// BYTE xx SEX 1=fem, 2=mal, 0=dontcare
	if (sex==1)
		search.addLEByte(0x01);
	else if(sex==2)
		search.addLEByte(0x02);
	else
		search.addLEByte(0x00);
	
	// BYTE xx LANGUAGE
	search.addLEByte(lang);
	
	// LNTS CITY
	search.addLEWord(city.length());
	if(city.length()>0)
		search.addLEString(city.latin1(), city.length());
	
	// LNTS STATE
	search.addLEWord(state.length());
	if(state.length()>0)
		search.addLEString(state.latin1(), state.length());
	
	// WORD.L xx xx COUNTRY
	search.addLEWord(country);
	
	// LNTS COMPANY
	search.addLEWord(company.length());
	if(company.length()>0)
		search.addLEString(company.latin1(), company.length());
	
	// LNTS DEPARTMENT
	search.addLEWord(department.length());
	if(department.length()>0)
		search.addLEString(department.latin1(), department.length());
	
	// LNTS POSITION
	search.addLEWord(position.length());
	if(position.length()>0)
		search.addLEString(position.latin1(), position.length());
	
	// BYTE xx OCCUPATION
	search.addLEByte(occupation);
	
	//WORD.L xx xx PAST
	search.addLEWord(0x0000);
	
	//LNTS PASTDESC - The past description to search for.
	search.addLEWord(0x0000);
	
	// WORD.L xx xx INTERESTS - The interests category to search for.
	search.addLEWord(0x0000);
	
	// LNTS INTERDESC - The interests description to search for.
	search.addLEWord(0x0000);
	
	// WORD.L xx xx AFFILIATION - The affiliation to search for.
	search.addLEWord(0x0000);
	
	// LNTS AFFIDESC - The affiliation description to search for.
	search.addLEWord(0x0000);
	
	// WORD.L xx xx HOMEPAGE - The home page category to search for.
	search.addLEWord(0x0000);
	
	// LNTS HOMEDESC - The home page description to search for.
	search.addLEWord(0x0000);
	
	// BYTE xx ONLINE 1=online onliners, 0=dontcare
	if(onlineOnly)
		search.addLEByte(0x01);
	else
		search.addLEByte(0x00);
	*/
	if ( !info.firstName.isEmpty() )
	{
		Buffer bufFileName;
		bufFileName.addLEWord( info.firstName.length() );
		bufFileName.addLEString( info.firstName, info.firstName.length() );
		tlvData->addLETLV( 0x0140, bufFileName.length(), bufFileName.buffer() );
	}

	if ( !info.lastName.isEmpty() )
	{
		Buffer bufLastName;
		bufLastName.addLEWord( info.lastName.length() );
		bufLastName.addLEString( info.lastName, info.lastName.length() );
		tlvData->addLETLV( 0x014A, bufLastName.length(), bufLastName.buffer() );
	}

	if ( !info.nickName.isEmpty() )
	{
		Buffer bufNickName;
		bufNickName.addLEWord( info.nickName.length() );
		bufNickName.addLEString( info.nickName, info.nickName.length() );
		tlvData->addLETLV( 0x0154, bufNickName.length(), bufNickName.buffer() );
	}

	if ( !info.email.isEmpty() )
	{
		Buffer bufEmail;
		bufEmail.addLEWord( info.email.length() );
		bufEmail.addLEString( info.email, info.email.length() );
		tlvData->addLETLV( 0x015E, bufEmail.length(), bufEmail.buffer() );
	}

	if ( info.age > 0 )
	{
		Buffer bufAge;
		bufAge.addWord( info.age );
		bufAge.addWord( info.age );
		tlvData->addLETLV( 0x0168, bufAge.length(), bufAge.buffer() );
	}

	if ( info.gender > 0 )
		tlvData->addLETLV8( 0x017C, info.gender );

	if ( info.language > 0 )
		tlvData->addLETLV16( 0x0186, info.language );

	if ( info.country > 0 )
		tlvData->addLETLV16( 0x01A4, info.country );

	if ( !info.city.isEmpty() )
	{
		Buffer bufCity;
		bufCity.addLEWord( info.city.length() );
		bufCity.addLEString( info.city, info.city.length() );
		tlvData->addLETLV( 0x0190, bufCity.length(), bufCity.buffer() );
	}

	if ( info.occupation > 0 )
		tlvData->addLETLV16( 0x01CC, info.occupation );

	if ( info.onlineOnly )
		tlvData->addLETLV8( 0x0230, 0x01 );
	
	Buffer* buf = addInitialData( tlvData );
	delete tlvData; //we're done with it
	
	Transfer* t = createTransfer( f, s, buf );
	send( t );
}


#include "usersearchtask.moc"

//kate: indent-mode csands; tab-width 4; space-indent off; replace-tabs off;