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 00023 #include "Qt.h" 00024 #include "VendorCode.h" 00025 #include "../GgepBlock.h" 00026 00027 using namespace Gnutella::Packets::Extensions; 00028 using namespace Gnutella::Packets::Extensions::Ggeps; 00029 00030 const Ggep::GgepId VendorCode::Id ("VC", 2); 00031 00032 VendorCode::VendorCode (const GgepId &id, int flags, int dataSize) 00033 : Ggep (id, flags, dataSize) 00034 { 00035 } 00036 00037 VendorCode::VendorCode (VendorCode_ vendorCode, Version version) 00038 : Ggep (Id) 00039 { 00040 vendorCode_ = vendorCode; 00041 version_ = version; 00042 } 00043 00044 const VendorCode * VendorCode::findIn (const GgepBlock &ggepBlock) 00045 { 00046 const VendorCode *res = 0; 00047 foreach (const Ggep *extension, ggepBlock.extensions()) { 00048 res = dynamic_cast <const VendorCode *> (extension); 00049 if (res != 0) 00050 return res; 00051 } 00052 return 0; 00053 } 00054 00055 VendorCode * VendorCode::copy() const 00056 { 00057 return new VendorCode (*this); 00058 } 00059 00060 bool VendorCode::prepareReadData (const QByteArray &rawData) 00061 { 00062 return rawData.length () == Gnutella::Packets::VendorCode::VendorCodeLength + 1; // VendorCode + 1 byte version 00063 } 00064 00065 void VendorCode::readData (QDataStream &stream) 00066 { 00067 uchar guessStyleVersion; 00068 00069 stream >> vendorCode_; 00070 stream >> guessStyleVersion; 00071 00072 version_ = Version (guessStyleVersion >> 4, guessStyleVersion & 0x0F); 00073 } 00074 00075 int VendorCode::prepareWriteData() const 00076 { 00077 return Gnutella::Packets::VendorCode::VendorCodeLength + 1; // VendorCode + 1 byte version 00078 } 00079 00080 void VendorCode::writeData (QDataStream &stream) const 00081 { 00082 uchar guessStyleVersion = (version_.majorVersion() << 4) 00083 | (version_.minorVersion() & 0x0F); 00084 00089 stream << vendorCode_; 00090 stream << guessStyleVersion; 00091 }