verificationpacket.h

Go to the documentation of this file.
00001 // This file is part of par2cmdline (a PAR 2.0 compatible file verification and
00002 // repair tool). See https://parchive.sourceforge.net for details of PAR 2.0.
00003 //
00004 // Copyright (c) 2003 Peter Brian Clements
00005 //
00006 // par2cmdline is free software; you can redistribute it and/or modify
00007 // it under the terms of the GNU General Public License as published by
00008 // the Free Software Foundation; either version 2 of the License, or
00009 // (at your option) any later version.
00010 //
00011 // par2cmdline is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00014 // GNU General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU General Public License
00017 // along with this program; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
00019 
00020 #ifndef __VERIFICATIONPACKET_H__
00021 #define __VERIFICATIONPACKET_H__
00022 
00023 // The file verification packet stores details that allow individual blocks
00024 // of valid data within a damaged file to be identified.
00025 
00026 class VerificationPacket : public CriticalPacket
00027 {
00028 public:
00029   // Construct the packet
00030   VerificationPacket(void) {};
00031   ~VerificationPacket(void) {};
00032 
00033   // Create a packet large enough for the specified number of blocks
00034   bool Create(u32 blockcount);
00035 
00036   // Set the fileid (computed from the file description packet).
00037   void FileId(const MD5Hash &fileid);
00038 
00039   // Set the block hash and block crc for a specific data block.
00040   void SetBlockHashAndCRC(u32 blocknumber, const MD5Hash &hash, u32 crc);
00041 
00042   // Load a verification packet from a specified file
00043   bool Load(DiskFile *diskfile, u64 offset, PACKET_HEADER &header);
00044 
00045   // Get the FileId
00046   const MD5Hash& FileId(void) const;
00047 
00048   // Get the block count
00049   u32 BlockCount(void) const;
00050 
00051   // Get a specific verification entry
00052   const FILEVERIFICATIONENTRY* VerificationEntry(u32 blocknumber) const;
00053 
00054 protected:
00055   u32 blockcount;
00056 };
00057 
00058 inline const MD5Hash& VerificationPacket::FileId(void) const
00059 {
00060   assert(packetdata != 0);
00061 
00062   return ((FILEVERIFICATIONPACKET*)packetdata)->fileid;
00063 }
00064 
00065 inline u32 VerificationPacket::BlockCount(void) const
00066 {
00067   assert(packetdata != 0);
00068 
00069   return blockcount;
00070 }
00071 
00072 inline const FILEVERIFICATIONENTRY* VerificationPacket::VerificationEntry(u32 blocknumber) const
00073 {
00074   assert(packetdata != 0);
00075 
00076 // return &((FILEVERIFICATIONPACKET*)packetdata)->entries()[blocknumber];
00077   return &((FILEVERIFICATIONPACKET*)packetdata)->entries[blocknumber];
00078 }
00079 
00080 
00081 #endif // __VERIFICATIONPACKET_H__

Generated on Sun Oct 12 01:45:31 2008 for NNTPGrab by  1.5.4