1 /*
2    Kopete Oscar Protocol
3    Send extended status info to the server
4 
5    Copyright (c) 2004 Matt Rogers <mattr@kde.org>
6 
7    Kopete (c) 2002-2004 by the Kopete developers <kopete-devel@kde.org>
8 
9    *************************************************************************
10    *                                                                       *
11    * This library is free software; you can redistribute it and/or         *
12    * modify it under the terms of the GNU Lesser General Public            *
13    * License as published by the Free Software Foundation; either          *
14    * version 2 of the License, or (at your option) any later version.      *
15    *                                                                       *
16    *************************************************************************
17 */
18 #include "senddcinfotask.h"
19 
20 #include <kdebug.h>
21 #include "connection.h"
22 #include "buffer.h"
23 #include "oscarsettings.h"
24 #include "oscartypes.h"
25 #include "oscarutils.h"
26 #include "transfer.h"
27 
SendDCInfoTask(Task * parent,Oscar::DWORD status)28 SendDCInfoTask::SendDCInfoTask(Task* parent, Oscar::DWORD status): Task(parent), mStatus(status)
29 {
30 	mSendMood = false;
31 	mSendMessage = false;
32 	mMood = -1;
33 }
34 
~SendDCInfoTask()35 SendDCInfoTask::~SendDCInfoTask()
36 {
37 }
38 
setIcqMood(int mood)39 void SendDCInfoTask::setIcqMood( int mood )
40 {
41 	mMood = mood;
42 	mSendMood = true;
43 }
44 
setStatusMessage(const QString & message)45 void SendDCInfoTask::setStatusMessage( const QString &message )
46 {
47 	mMessage = message;
48 	mSendMessage = true;
49 }
50 
onGo()51 void SendDCInfoTask::onGo()
52 {
53 	FLAP f = { 0x02, 0, 0 };
54 	SNAC s = { 0x0001, 0x001E, 0x0000, client()->snacSequence() };
55 	Buffer* buffer = new Buffer();
56 
57 	kDebug(OSCAR_RAW_DEBUG) << "Sending DC Info";
58 
59 	/** \TODO Support something more than online in the status flags
60 	 *  \TODO Support something more than DC Disabled in the status flags
61 	 */
62 	/*
63 	if (status & ICQ_STATUS_SET_INVIS)
64 		sendChangeVisibility(0x03);
65 	else
66 		sendChangeVisibility(0x04);
67 	*/
68 
69 	/* This is TLV 0x06 */
70 	//### Don't hardcode this value
71 	//Right now, it's always coded to not support DC
72 	Oscar::DWORD statusFlag = 0x01000000;
73 	if ( client()->settings()->webAware() )
74 	{
75 		kDebug(OSCAR_RAW_DEBUG) << "setting web aware on";
76 		statusFlag |= 0x00010000;
77 	}
78 	if ( client()->settings()->hideIP() )
79 	{
80 		kDebug(OSCAR_RAW_DEBUG) << "setting hide ip on";
81 		statusFlag |= 0x10000000;  // Direct connection upon authorization, hides IP
82 	}
83 	Buffer tlv06;
84 	tlv06.addDWord( statusFlag | mStatus );
85 	buffer->addTLV( 0x0006, tlv06.buffer() );
86 
87 	/* Fill in the DC Info
88 	 * We don't support Direct Connection yet. So fill in some
89 	 * dummy values
90 	 */
91 	Buffer tlv0C;
92 	tlv0C.addDWord( 0x00000000 );
93 	tlv0C.addWord( 0x0000 );
94 	tlv0C.addWord( 0x0000 );
95 
96 	tlv0C.addByte( 0x00 ); // Mode, TODO: currently fixed to "Direct Connection disabled"
97 	tlv0C.addWord( ICQ_TCP_VERSION ); // icq tcp protocol version, v8 currently
98 
99 	tlv0C.addDWord( 0x00000000 ); // Direct Connection Cookie
100 	tlv0C.addDWord( 0x00000050 ); // web front port
101 	tlv0C.addDWord( 0x00000003 ); // number of following client features
102 	tlv0C.addDWord( 0x00000000 ); // InfoUpdateTime
103 	tlv0C.addDWord( 0x00000000 ); // PhoneStatusTime
104 	tlv0C.addDWord( 0x00000000 ); // PhoneBookTime
105 	tlv0C.addWord( 0x0000 );
106 	buffer->addTLV( 0x000C, tlv0C.buffer() );
107 
108 	buffer->addTLV16( 0x0008, 0x0A06 ); // we support online status messages
109 
110 	if ( mSendMood || mSendMessage )
111 	{
112 		Buffer tlv1D;
113 
114 		if ( mSendMessage )
115 		{
116 			Buffer tlv02;
117 			tlv02.addWord( 0x0002 );
118 			tlv02.addByte( 0x04 );
119 			QByteArray msgData = mMessage.toUtf8();
120 			msgData.truncate( 251 );
121 			tlv02.addByte( msgData.length() + 4 );
122 			tlv02.addWord( msgData.length() );
123 			tlv02.addString( msgData );
124 			tlv02.addWord( 0x0000 );
125 			tlv1D.addString( tlv02.buffer() );
126 		}
127 
128 		if ( mSendMood )
129 		{
130 			QString mood = QStringLiteral( "icqmood%1" ).arg( mMood );
131 			tlv1D.addTLV( 0x000E, mood.toLatin1() );
132 		}
133 
134 		buffer->addTLV( 0x001D, tlv1D.buffer() );
135 	}
136 
137 	Transfer* t = createTransfer( f, s, buffer );
138 	send( t );
139 	setSuccess( 0, QString() );
140 }
141 
142