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 "Push.h" 00025 00026 using namespace Gnutella::Packets; 00027 00029 enum Constants 00030 { 00031 MinimalPayloadLength = 26 00032 }; 00033 00037 Push::Push (const QByteArray &rawHeader, const QByteArray &rawPayload) 00038 : Packet (rawHeader, rawPayload) 00039 { 00040 parse(); 00041 } 00042 00043 Push::~Push() 00044 { 00045 } 00046 00047 bool Push::prepareReadPayload (const QByteArray &rawPayload) 00048 { 00049 if (payloadLength() < MinimalPayloadLength) 00050 return false; 00051 00052 const char *extensionRawData = rawPayload.constData() + MinimalPayloadLength; 00053 int extensionSize = rawPayload.length() - MinimalPayloadLength; 00054 QByteArray extensionData = QByteArray::fromRawData (extensionRawData, extensionSize); 00055 00056 p.ggepBlock.prepareRead (extensionData); 00057 return true; 00058 } 00059 00060 void Push::readPayload (QDataStream &stream) 00061 { 00062 stream >> p.serventId; 00063 stream >> p.fileIndex; 00064 Gnutella::Packets::operator>> (stream, p.ipAddress); 00065 stream >> p.port; 00066 stream >> p.ggepBlock; 00067 } 00068 00069 int Push::prepareWritePayload() const 00070 { 00071 return MinimalPayloadLength + p.ggepBlock.prepareWrite(); 00072 } 00073 00074 void Push::writePayload (QDataStream &stream) const 00075 { 00076 stream << p.serventId; 00077 stream << p.fileIndex; 00078 Gnutella::Packets::operator<< (stream, p.ipAddress); 00079 stream << p.port; 00080 stream << p.ggepBlock; 00081 }