Upstream tarball 20080418
[amule.git] / src / Packet.h
blobdb0d7fd54fc7f85a600502d6fe7bfd2b657ac5f1
1 //
2 // This file is part of the aMule Project.
3 //
4 // Copyright (c) 2003-2008 aMule Team ( admin@amule.org / http://www.amule.org )
5 // Copyright (c) 2002 Merkur ( devs@emule-project.net / http://www.emule-project.net )
6 //
7 // Any parts of this program derived from the xMule, lMule or eMule project,
8 // or contributed by third-party developers are copyrighted by their
9 // respective authors.
11 // This program is free software; you can redistribute it and/or modify
12 // it under the terms of the GNU General Public License as published by
13 // the Free Software Foundation; either version 2 of the License, or
14 // (at your option) any later version.
16 // This program is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 // GNU General Public License for more details.
20 //
21 // You should have received a copy of the GNU General Public License
22 // along with this program; if not, write to the Free Software
23 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 #ifndef PACKET_H
27 #define PACKET_H
29 #include "Types.h" // Needed for int8, int32, uint8 and uint32
31 class CMemFile;
32 class wxString;
34 // CLIENT TO SERVER
36 // PACKET CLASS
37 // TODO some parts could need some work to make it more efficient
39 class CPacket {
40 public:
41 CPacket(CPacket &p);
42 CPacket(uint8 protocol);
43 CPacket(byte* header); // only used for receiving packets
44 CPacket(const CMemFile& datafile, uint8 protocol, uint8 ucOpcode);
45 CPacket(int8 in_opcode, uint32 in_size, uint8 protocol, bool bFromPF = true);
46 CPacket(byte* pPacketPart, uint32 nSize, bool bLast, bool bFromPF = true); // only used for splitted packets!
48 ~CPacket();
50 void AllocDataBuffer();
51 byte* GetHeader();
52 byte* GetUDPHeader();
53 byte* GetPacket();
54 byte* DetachPacket();
55 uint32 GetRealPacketSize() const { return size + 6; }
56 bool IsSplitted() { return m_bSplitted; }
57 bool IsLastSplitted() { return m_bLastSplitted; }
58 void PackPacket();
59 bool UnPackPacket(uint32 uMaxDecompressedSize = 50000);
60 // -khaos--+++> Returns either -1, 0 or 1. -1 is unset, 0 is from complete file, 1 is from part file
61 bool IsFromPF() { return m_bFromPF; }
63 uint8 GetOpCode() const { return opcode; }
64 void SetOpCode(uint8 oc) { opcode = oc; }
65 uint32 GetPacketSize() const { return size; }
66 uint8 GetProtocol() const { return prot; }
67 void SetProtocol(uint8 p) { prot = p; }
68 const byte* GetDataBuffer(void) const { return pBuffer; }
69 void Copy16ToDataBuffer(const void* data);
70 void CopyToDataBuffer(unsigned int offset, const byte* data, unsigned int n);
71 void CopyUInt32ToDataBuffer(uint32 data, unsigned int offset = 0);
73 private:
74 //! CPacket is not assignable.
75 CPacket& operator=(const CPacket&);
77 uint32 size;
78 uint8 opcode;
79 uint8 prot;
80 bool m_bSplitted;
81 bool m_bLastSplitted;
82 bool m_bPacked;
83 bool m_bFromPF;
84 byte head[6];
85 byte* tempbuffer;
86 byte* completebuffer;
87 byte* pBuffer;
90 #endif // PACKET_H
91 // File_checked_for_headers