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