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
|
/*
Kopete Oscar Protocol
offlinemessagestask.cpp - Offline messages handling
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 "config.h"
#include "offlinemessagestask.h"
#include <time.h>
#include "transfer.h"
#include "buffer.h"
#include "connection.h"
#include <kdebug.h>
OfflineMessagesTask::OfflineMessagesTask( Task* parent )
: ICQTask( parent )
{
tzset();
m_sequence = 0;
}
OfflineMessagesTask::~OfflineMessagesTask()
{
}
void OfflineMessagesTask::onGo()
{
kdDebug( OSCAR_RAW_DEBUG ) << k_funcinfo << "Requesting offline messages" << endl;
FLAP f = { 0x02, 0, 0 };
SNAC s = { 0x0015, 0x0002, 0x0000, client()->snacSequence() };
setRequestType( 0x003c ); //offline message request
setSequence( f.sequence );
Buffer* buf = addInitialData();
Transfer* t = createTransfer( f, s, buf );
send( t );
}
bool OfflineMessagesTask::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<OfflineMessagesTask*>(this)->parseInitialData( buf );
if ( requestType() == 0x0041 || requestType() == 0x0042 )
return true;
return false;
}
bool OfflineMessagesTask::take( Transfer* t )
{
if ( forMe( t ) )
{
setTransfer( t );
if ( requestType() == 0x0041 ) // Offline message
handleOfflineMessage();
else if ( requestType() == 0x0042 ) // end-of-offline messages
endOfMessages();
setTransfer( 0 );
return true;
}
return false;
}
void OfflineMessagesTask::handleOfflineMessage()
{
TLV tlv1 = transfer()->buffer()->getTLV();
Buffer* buffer = new Buffer( tlv1.data, tlv1.length );
buffer->getLEWord(); // data chunk size
DWORD receiverUin = buffer->getLEDWord(); // target uin
buffer->getLEWord(); // request type
buffer->getLEWord(); // request sequence number: 0x0002
DWORD senderUin = buffer->getLEDWord();
WORD year = buffer->getLEWord();
BYTE month = buffer->getByte();
BYTE day = buffer->getByte();
BYTE hour = buffer->getByte();
BYTE minute = buffer->getByte();
BYTE type = buffer->getByte(); // msg type
BYTE flags = buffer->getByte(); // msg flags
WORD msgLength = buffer->getLEWord();
TQByteArray msg = buffer->getBlock( msgLength );
TQDate date(year, month, day);
TQTime time(hour,minute);
#ifndef HAVE_TM_GMTOFF
int tz = -( ::timezone );
#else
int tz;
time_t now;
struct tm *tm;
now = ::time(NULL);
tm = ::localtime(&now);
/* daylight = tm->tm_isdst; // another linuxism */
tz = (tm->tm_gmtoff) / (60 * 60);
#endif
time = time.addSecs( tz );
TQDateTime hackyTime( date, time );
Oscar::Message message( Oscar::Message::UserDefined, msg, type, flags, hackyTime );
message.setSender( TQString::number( senderUin ) );
message.setReceiver( TQString::number( receiverUin ) );
kdDebug( OSCAR_RAW_DEBUG ) << k_funcinfo << "Received offline message '" << msg.data() << "' from " << senderUin << endl;
emit receivedOfflineMessage( message );
}
void OfflineMessagesTask::endOfMessages()
{
kdDebug( OSCAR_RAW_DEBUG ) << k_funcinfo << "End of Offline Messages" << endl;
TLV tlv1 = transfer()->buffer()->getTLV();
Buffer* buffer = new Buffer( tlv1.data, tlv1.length );
buffer->skipBytes( 8 );
m_sequence = buffer->getLEWord();
deleteOfflineMessages();
setSuccess( true );
}
void OfflineMessagesTask::deleteOfflineMessages()
{
FLAP f = { 0x02, 0, 0 };
SNAC s = { 0x0015, 0x0002, 0x0000, client()->snacSequence() };
setRequestType( 0x003E ); //delete offline messages
setSequence( m_sequence );
Buffer* buf = addInitialData();
Transfer* t = createTransfer( f, s, buf );
send( t );
}
#include "offlinemessagestask.moc"
|