Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

G2Packet.h

Go to the documentation of this file.
00001 //
00002 // G2Packet.h
00003 //
00004 // Copyright (c) Shareaza Development Team, 2002-2005.
00005 // This file is part of SHAREAZA (www.shareaza.com)
00006 //
00007 // Shareaza is free software; you can redistribute it
00008 // and/or modify it under the terms of the GNU General Public License
00009 // as published by the Free Software Foundation; either version 2 of
00010 // the License, or (at your option) any later version.
00011 //
00012 // Shareaza is distributed in the hope that it will be useful,
00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 // GNU General Public License for more details.
00016 //
00017 // You should have received a copy of the GNU General Public License
00018 // along with Shareaza; if not, write to the Free Software
00019 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020 //
00021 
00022 #if !defined(AFX_G2PACKET_H__1790A2FA_5A60_4846_A7BD_629747EEC1C5__INCLUDED_)
00023 #define AFX_G2PACKET_H__1790A2FA_5A60_4846_A7BD_629747EEC1C5__INCLUDED_
00024 
00025 #pragma once
00026 
00027 #include "Packet.h"
00028 
00029 class CG1Packet;
00030 
00031 
00032 class CG2Packet : public CPacket
00033 {
00034 // Construction
00035 protected:
00036         CG2Packet();
00037         virtual ~CG2Packet();
00038 
00039 // Attributes
00040 public:
00041         CHAR    m_sType[9];
00042         BOOL    m_bCompound;
00043 
00044         CString m_sTypeCache;
00045 
00046 // Operations
00047 public:
00048         void    WritePacket(CG2Packet* pPacket);
00049         void    WritePacket(LPCSTR pszType, DWORD nLength, BOOL bCompound = FALSE);
00050         BOOL    ReadPacket(LPSTR pszType, DWORD& nLength, BOOL* pbCompound = NULL);
00051         BOOL    SkipCompound();
00052         BOOL    SkipCompound(DWORD& nLength, DWORD nRemaining = 0);
00053         BOOL    GetTo(GGUID* pGUID);
00054         BOOL    SeekToWrapped();
00055 public:
00056         virtual void    Reset();
00057         CG2Packet*              Clone() const;
00058         virtual CString ReadString(DWORD nMaximum = 0xFFFFFFFF);
00059         virtual void    WriteString(LPCTSTR pszString, BOOL bNull = TRUE);
00060         virtual int             GetStringLen(LPCTSTR pszString) const;
00061         virtual void    ToBuffer(CBuffer* pBuffer) const;
00062         virtual void    Debug(LPCTSTR pszReason) const;
00063 public:
00064         static CG2Packet* ReadBuffer(CBuffer* pBuffer);
00065 
00066         virtual void    WriteString(LPCSTR pszString, BOOL bNull = TRUE);
00067 
00068 // Inlines
00069 public:
00070         inline BOOL IsType(LPCSTR pszType) const
00071         {
00072                 return strcmp( pszType, m_sType ) == 0;
00073         }
00074 
00075         virtual inline LPCTSTR GetType() const
00076         {
00077                 if ( m_sTypeCache.IsEmpty() ) ((CG2Packet*)this)->m_sTypeCache = m_sType;
00078                 return m_sTypeCache;
00079         }
00080 
00081 // Packet Pool
00082 protected:
00083         class CG2PacketPool : public CPacketPool
00084         {
00085         public:
00086                 virtual ~CG2PacketPool() { Clear(); }
00087         protected:
00088                 virtual void NewPoolImpl(int nSize, CPacket*& pPool, int& nPitch);
00089                 virtual void FreePoolImpl(CPacket* pPool);
00090         };
00091 
00092         static CG2PacketPool POOL;
00093 
00094 // Construction
00095 public:
00096         inline static CG2Packet* New(LPCSTR pszType = NULL, BOOL bCompound = FALSE)
00097         {
00098                 CG2Packet* pPacket = (CG2Packet*)POOL.New();
00099 
00100                 if ( pszType != NULL )
00101                 {
00102                         strncpy( pPacket->m_sType, pszType, 9 );
00103                         pPacket->m_sType[8] = 0;
00104                 }
00105 
00106                 pPacket->m_bCompound = bCompound;
00107                 pPacket->m_sTypeCache.Empty();
00108 
00109                 return pPacket;
00110         }
00111 
00112         static CG2Packet* New(BYTE* pSource);
00113         static CG2Packet* New(LPCSTR pszType, CG1Packet* pWrap, int nMinTTL = 255);
00114 
00115         inline virtual void Delete()
00116         {
00117                 POOL.Delete( this );
00118         }
00119 
00120         friend class CG2Packet::CG2PacketPool;
00121 };
00122 
00123 inline void CG2Packet::CG2PacketPool::NewPoolImpl(int nSize, CPacket*& pPool, int& nPitch)
00124 {
00125         nPitch  = sizeof(CG2Packet);
00126         pPool   = new CG2Packet[ nSize ];
00127 }
00128 
00129 inline void CG2Packet::CG2PacketPool::FreePoolImpl(CPacket* pPacket)
00130 {
00131         delete [] (CG2Packet*)pPacket;
00132 }
00133 
00134 //
00135 // G2 Packet Flags
00136 //
00137 
00138 #define G2_FLAG_COMPOUND        0x04
00139 #define G2_FLAG_BIG_ENDIAN      0x02
00140 
00141 //
00142 // G2 Packet Types
00143 //
00144 
00145 #define G2_PACKET_TO                            "TO"
00146 #define G2_PACKET_PING                          "PI"
00147 #define G2_PACKET_PONG                          "PO"
00148 #define G2_PACKET_LNI                           "LNI"
00149 #define G2_PACKET_KHL                           "KHL"
00150 #define G2_PACKET_HAW                           "HAW"
00151 #define G2_PACKET_QHT                           "QHT"
00152 #define G2_PACKET_QUERY_KEY_REQ         "QKR"
00153 #define G2_PACKET_QUERY_KEY_ANS         "QKA"
00154 #define G2_PACKET_QUERY                         "Q2"
00155 #define G2_PACKET_HIT                           "QH2"
00156 #define G2_PACKET_QUERY_WRAP            "Q1"                    // Obsolete
00157 #define G2_PACKET_HIT_WRAP                      "QH1"
00158 #define G2_PACKET_QUERY_ACK                     "QA"
00159 #define G2_PACKET_PUSH                          "PUSH"
00160 #define G2_PACKET_PROFILE_CHALLENGE     "UPROC"
00161 #define G2_PACKET_PROFILE_DELIVERY      "UPROD"
00162 #define G2_PACKET_PROFILE_AVATAR        "UPROAVTR"
00163 #define G2_PACKET_CRAWL_REQ                     "CRAWLR"
00164 #define G2_PACKET_CRAWL_ANS                     "CRAWLA"
00165 #define G2_PACKET_PHYSICAL_FOLDER       "PF"
00166 #define G2_PACKET_VIRTUAL_FOLDER        "VF"
00167 #define G2_PACKET_DISCOVERY_REQ         "DISCR"
00168 #define G2_PACKET_DISCOVERY_ANS         "DISCA"
00169 #define G2_PACKET_DISCOVERY_HUB         "DISCH"
00170 #define G2_PACKET_DISCOVERY_LOG         "DISCL"
00171 
00172 //
00173 // G2 SS
00174 //
00175 
00176 #define G2_SS_PUSH              0x01
00177 #define G2_SS_BUSY              0x02
00178 #define G2_SS_STABLE    0x04
00179 
00180 #endif // !defined(AFX_G2PACKET_H__1790A2FA_5A60_4846_A7BD_629747EEC1C5__INCLUDED_)

Generated on Thu Dec 15 10:39:42 2005 for Shareaza 2.2.1.0 by  doxygen 1.4.2