summaryrefslogtreecommitdiffstats
path: root/kopete/protocols/oscar/liboscar/transfer.h
blob: 0ec4fc4115d537a3db39e4d947cde1cb9c9c8de5 (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
/*
    transfer.h - Kopete Groupwise Protocol

    Copyright (c) 2004      SUSE Linux AG	 	 http://www.suse.com

    Kopete (c) 2002-2004 by the Kopete developers <[email protected]>

    *************************************************************************
    *                                                                       *
    * 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.      *
    *                                                                       *
    *************************************************************************
*/

#ifndef TRANSFER_H
#define TRANSFER_H

#include "oscartypes.h"
#include "buffer.h"


using namespace Oscar;

class Transfer
{
public:
        enum TransferType { RawTransfer, FlapTransfer, SnacTransfer, DIMTransfer, FileTransfer };
        Transfer();
	Transfer( Buffer* buf );
        virtual ~Transfer();

        virtual TransferType type() const;
	
	virtual TQByteArray toWire();

	//! Set the data buffer
	void setBuffer( Buffer* buffer );

	//! Get the data buffer
	Buffer* buffer();
	
	const Buffer* buffer() const; //used for const transfer objects
	
	//! Get the validity of the data after the flap header
	bool dataValid() const;
	
	TQString toString() const;
	
	void populateWireBuffer( int offset, const TQByteArray& buffer );

protected:
	//! The wire-format representation of our buffer
	TQByteArray m_wireFormat;

	//! The high-level representation of our data
	Buffer* m_buffer;

private:

	//! Flag to indicate whether we're a valid transfer
	bool m_isBufferValid;
	
};

class FlapTransfer : public Transfer
{
public:

	FlapTransfer( Buffer* buffer, BYTE chan = 0, WORD seq = 0, WORD len = 0 );
	FlapTransfer( FLAP f, Buffer* buffer );
	FlapTransfer();
	virtual ~FlapTransfer();

	virtual TransferType type() const;
	virtual TQByteArray toWire();


	//! Set the FLAP channel
	void setFlapChannel( BYTE channel );

	//! Get the FLAP channel
	BYTE flapChannel() const;

	//! Set the FLAP sequence
	void setFlapSequence( WORD seq );

	//! Get the FLAP sequence
	WORD flapSequence() const;

	//! Set the length of the data after the FLAP
	void setFlapLength( WORD len );

	//! Get the length of the data after the FLAP
	WORD flapLength() const;

	//! Get the validity of the FLAP header
	bool flapValid() const;
	
private:
	BYTE m_flapChannel;
	WORD m_flapSequence;
	WORD m_flapLength;

	bool m_isFlapValid;
	
};

/**
@author Matt Rogers
*/
class SnacTransfer : public FlapTransfer
{
public:

	/*SnacTransfer();*/
	SnacTransfer( Buffer*, BYTE chan = 0, WORD seq = 0, WORD len = 0, WORD service = 0,
		 WORD subtype = 0, WORD flags = 0, DWORD reqId = 0 );
	SnacTransfer( struct FLAP f, struct SNAC s, Buffer* buffer );
	SnacTransfer();
	virtual ~SnacTransfer();

	TransferType type() const;
	virtual TQByteArray toWire();


	//! Set the SNAC service
	void setSnacService( WORD service );

	//! Get the SNAC service
	WORD snacService() const;

	//! Set the SNAC subtype
	void setSnacSubtype( WORD subtype );

	//! Get the SNAC subtype
	WORD snacSubtype() const;

	//! Set the SNAC flags
	void setSnacFlags( WORD flags );

	//! Get the SNAC flags
	WORD snacFlags() const;

	//! Set the SNAC request id
	void setSnacRequest( DWORD id );

	//! Get the SNAC request id
	DWORD snacRequest() const;

	//! Get the validity of the SNAC header
	bool snacValid() const;
	
	//! Get the SNAC header
	SNAC snac() const;

private:

	WORD m_snacService;
	WORD m_snacSubtype;
	WORD m_snacFlags;
	WORD m_snacReqId;
	
	bool m_isSnacValid;
};

#endif