Ggep.h

Go to the documentation of this file.
00001 /*
00002 
00003 Copyright (C) 2005-2007 by Peter Dimov.
00004 
00005 This file is part of Calitko (http://www.calitko.org).
00006 
00007 Calitko is free software; you can redistribute it and/or modify
00008 it under the terms of the GNU General Public License as published by
00009 the Free Software Foundation; either version 2 of the License, or
00010 (at your option) any later version.
00011 
00012 Calitko 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 Calitko; if not, write to the Free Software
00019 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00020 
00021 */
00022 #ifndef PROTOCOLS__GNUTELLA__PACKETS__EXTENSIONS__GGEP_H
00023 #define PROTOCOLS__GNUTELLA__PACKETS__EXTENSIONS__GGEP_H
00024 
00025 #include "Imports.h"
00026 
00027 namespace Protocols {
00028 namespace Gnutella {
00029 namespace Packets {
00030 namespace Extensions {
00031 
00032 class BinaryReader;
00033 class BinaryWriter;
00034 
00036 
00045 class Ggep
00046 {
00047 public:
00049     static const uchar LastExtension    = 0x80;
00050     static const int     MaxIdLength    = 8;
00051 
00052     enum HeaderFlag
00053     {
00054         Encoding        = 0x40,
00055         Compression     = 0x20,
00056         Reserved        = 0x10,
00057         IDLength        = 0x0F
00058     };
00059 
00060 
00061     Q_DECLARE_FLAGS(HeaderFlags, HeaderFlag)
00062 
00063     
00064 
00067     typedef QByteArray GgepId;
00068 
00069     static Ggep *   fromId (const GgepId &id,
00070                             int flags,
00071                             const QByteArray &rawData);
00072 
00073                     Ggep (int flags);
00074     virtual         ~Ggep();
00075     virtual Ggep *  copy() const = 0;
00076 
00077     virtual GgepId  id() const = 0;
00078 
00079     bool            isFlagSet (HeaderFlag flag) const;
00080     void            setFlag (HeaderFlag flag);
00081     void            resetFlag (HeaderFlag flag);
00082 
00083     bool            parse (const QByteArray &);
00084     QByteArray      rawData() const;
00085     bool            operator== (const Ggep &ggep) const;
00086     bool            operator!= (const Ggep &ggep) const;
00087 
00088 protected:
00089     virtual void    readData (BinaryReader &reader) = 0;
00090     virtual void    writeData (BinaryWriter &writer) const = 0;
00091 
00092     HeaderFlags     flags;
00093 };
00094 
00095 Q_DECLARE_OPERATORS_FOR_FLAGS(Ggep::HeaderFlags)
00096 
00097 inline bool Ggep::isFlagSet (HeaderFlag flag) const
00098 { return flags & flag; }
00099 
00100 inline void Ggep::setFlag (HeaderFlag flag)
00101 { flags |= flag; }
00102 
00103 inline void Ggep::resetFlag (HeaderFlag flag)
00104 { flags &= ~flag; }
00105 
00106 } // namespace Extensions
00107 } // namespace Packets
00108 } // namespace Gnutella
00109 } // namespace Protocols
00110 
00111 #endif // PROTOCOLS__GNUTELLA__PACKETS__EXTENSIONS__GGEP_H