summaryrefslogtreecommitdiffstats
path: root/kopete/protocols/oscar/liboscar/userinfotask.cpp
blob: 4cda87a0e9bd312d6e8d8e5562fbafc0ca86b590 (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
/*
Kopete Oscar Protocol
userinfotask.h - Handle sending and receiving info requests for users

Copyright (c) 2004-2005 Matt Rogers <mattr@kde.org>

Kopete (c) 2002-2005 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 "userinfotask.h"

#include <kdebug.h>

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



UserInfoTask::UserInfoTask( Task* tqparent )
: Task( tqparent )
{
}


UserInfoTask::~UserInfoTask()
{
}

bool UserInfoTask::forMe( const Transfer * transfer ) const
{
	const SnacTransfer* st = dynamic_cast<const SnacTransfer*>( transfer );
	if ( !st )
		return false;
	
	if ( st->snacService() == 0x0002 && st->snacSubtype() == 0x0006 )
	{
		if ( m_contactSequenceMap.tqfind( st->snacRequest() ) == m_contactSequenceMap.end() )
			return false;
		else
		{
			//kdDebug(OSCAR_RAW_DEBUG) << k_funcinfo << "Found sequence. taking packet" << endl;
			return true;
		}
	}
	else
		return false;
}

bool UserInfoTask::take( Transfer * transfer )
{
	if ( forMe( transfer ) )
	{
		setTransfer( transfer );
		TQ_UINT16 seq = 0;
		SnacTransfer* st = dynamic_cast<SnacTransfer*>( transfer );
		if ( st )
			seq = st->snacRequest();
		
		if ( seq != 0 )
		{
			//AFAIK location info packets always have user info
			Buffer* b = transfer->buffer();
			UserDetails ud;
			ud.fill( b );
			m_sequenceInfoMap[seq] = ud;
			emit gotInfo( seq );
			
			TQValueList<TLV> list = b->getTLVList();
			TQValueList<TLV>::iterator it = list.begin();
			TQString profile;
			TQString away;
			for ( ; ( *it ); ++it )
			{
				switch( ( *it ).type )
				{
				case 0x0001: //profile text encoding
					kdDebug(OSCAR_RAW_DEBUG) << k_funcinfo << "text encoding is " << TQString( ( *it ).data )<< endl;
					break;
				case 0x0002: //profile text
					kdDebug(OSCAR_RAW_DEBUG) << k_funcinfo << "The profile is '" << TQString( ( *it ).data ) << "'" << endl;
					profile = TQString( ( *it ).data ); // aim always seems to use us-ascii encoding
					emit receivedProfile( m_contactSequenceMap[seq], profile );
					break;
				case 0x0003: //away message encoding
					kdDebug(OSCAR_RAW_DEBUG) << k_funcinfo << "Away message encoding is " << TQString( ( *it ).data ) << endl;
					break;
				case 0x0004: //away message
					kdDebug(OSCAR_RAW_DEBUG) << k_funcinfo << "Away message is '" << TQString( ( *it ).data ) << "'" << endl;
					away = TQString( (*it ).data ); // aim always seems to use us-ascii encoding
					emit receivedAwayMessage( m_contactSequenceMap[seq], away );
					break;
				case 0x0005: //capabilities
					break;
				default: //unknown
					kdDebug(14151) << k_funcinfo << "Unknown user info type " << ( *it ).type << endl;
					break;
				};
			}
			list.clear();
		}
		setTransfer( 0 );
		return true;
	}
	return false;
}

void UserInfoTask::onGo()
{
	if ( m_contactSequenceMap[m_seq].isEmpty() )
	{
		kdDebug( OSCAR_RAW_DEBUG ) << k_funcinfo << "Info requested for empty contact!" << endl;
		return;
	}
	
	FLAP f = { 0x02, 0, 0 };
	SNAC s = { 0x0002, 0x0005, 0, m_seq };
	Buffer* buffer = new Buffer();
	
	buffer->addWord( m_typesSequenceMap[m_seq] );
	buffer->addBUIN( m_contactSequenceMap[m_seq].local8Bit() );
	
	Transfer* t = createTransfer( f, s, buffer );
	send( t );
}

void UserInfoTask::requestInfoFor( const TQString& contact, unsigned int types )
{
	TQ_UINT16 seq = client()->snacSequence();
	kdDebug(OSCAR_RAW_DEBUG) << k_funcinfo << "setting sequence " << seq << " for contact " << contact << endl;
	m_contactSequenceMap[seq] = contact;
	m_typesSequenceMap[seq] = types;
	m_seq = seq;
	onGo();
}

UserDetails UserInfoTask::getInfoFor( TQ_UINT16 sequence ) const
{
	return m_sequenceInfoMap[sequence];
}



//kate: indent-mode csands; tab-width 4;


#include "userinfotask.moc"