XRootD
Loading...
Searching...
No Matches
XrdZip::CDFH Struct Reference

#include <XrdZipCDFH.hh>

+ Collaboration diagram for XrdZip::CDFH:

Public Member Functions

 CDFH (const char *buffer, const uint32_t maxSize=0)
 
 CDFH (LFH *lfh, mode_t mode, uint64_t lfhOffset)
 
bool HasDataDescriptor ()
 
bool IsZIP64 () const
 
void ParseExtra (const char *buffer, uint16_t length)
 
void Serialize (buffer_t &buffer)
 Serialize the object into a buffer.
 

Static Public Member Functions

static size_t CalcSize (const cdvec_t &cdvec, uint32_t orgcdsz, uint32_t orgcdcnt)
 
static uint64_t GetOffset (const CDFH &cdfh)
 
static std::tuple< cdvec_t, cdmap_tParse (const char *&buffer, uint32_t bufferSize)
 
static std::tuple< cdvec_t, cdmap_tParse (const char *buffer, uint32_t bufferSize, uint16_t nbCdRecords)
 
static void Serialize (uint32_t orgcdcnt, const buffer_t &orgcdbuf, const cdvec_t &cdvec, buffer_t &buffer)
 

Public Attributes

uint16_t cdfhSize
 
std::string comment
 
uint16_t commentLength
 
uint32_t compressedSize
 
uint16_t compressionMethod
 
uint32_t externAttr
 
std::unique_ptr< Extraextra
 
uint16_t extraLength
 
std::string filename
 
uint16_t filenameLength
 
uint16_t generalBitFlag
 
uint16_t internAttr
 
uint16_t minZipVersion
 
uint16_t nbDisk
 
uint32_t offset
 
dos_timestmp timestmp
 
uint32_t uncompressedSize
 
uint32_t ZCRC32
 
uint16_t zipVersion
 

Static Public Attributes

static const uint16_t cdfhBaseSize = 46
 
static const uint32_t cdfhSign = 0x02014b50
 

Detailed Description

Definition at line 66 of file XrdZipCDFH.hh.

Constructor & Destructor Documentation

◆ CDFH() [1/2]

XrdZip::CDFH::CDFH ( LFH lfh,
mode_t  mode,
uint64_t  lfhOffset 
)
inline

Definition at line 161 of file XrdZipCDFH.hh.

161 :
162 zipVersion( ( 3 << 8 ) | 63 ),
163 generalBitFlag( lfh->generalBitFlag ),
164 compressionMethod( lfh->compressionMethod ),
165 timestmp( lfh->timestmp ),
166 ZCRC32( lfh->ZCRC32 ),
167 compressedSize( lfh->compressedSize ),
168 uncompressedSize( lfh->uncompressedSize ),
169 filenameLength( lfh->filenameLength ),
170 commentLength( 0 ),
171 nbDisk( 0 ),
172 internAttr( 0 ),
173 externAttr( mode << 16 ),
174 filename( lfh->filename ),
175 extra( new Extra( lfh->extra.get(), lfhOffset ) )
176 {
177 if ( lfhOffset >= ovrflw<uint32_t>::value )
179 else
180 offset = lfhOffset;
181
182 extraLength = extra->totalSize;
183
184 if ( extraLength == 0 )
185 minZipVersion = 10;
186 else
187 minZipVersion = 45;
188
190 }
uint32_t uncompressedSize
uint32_t offset
uint16_t cdfhSize
uint16_t nbDisk
std::unique_ptr< Extra > extra
uint16_t internAttr
std::string filename
uint32_t externAttr
uint16_t zipVersion
static const uint16_t cdfhBaseSize
uint16_t extraLength
uint16_t compressionMethod
uint16_t generalBitFlag
uint32_t ZCRC32
uint16_t commentLength
uint16_t minZipVersion
uint32_t compressedSize
uint16_t filenameLength
dos_timestmp timestmp
static const UINT value

References cdfhBaseSize, cdfhSize, commentLength, extra, extraLength, filenameLength, minZipVersion, and offset.

◆ CDFH() [2/2]

XrdZip::CDFH::CDFH ( const char *  buffer,
const uint32_t  maxSize = 0 
)
inline

Definition at line 195 of file XrdZipCDFH.hh.

196 {
197 zipVersion = to<uint16_t>(buffer + 4);
198 minZipVersion = to<uint16_t>(buffer + 6);
199 generalBitFlag = to<uint16_t>(buffer + 8);
200 compressionMethod = to<uint16_t>(buffer + 10);
201 timestmp.time = to<uint16_t>(buffer + 12);
202 timestmp.date = to<uint16_t>(buffer + 14);
203 ZCRC32 = to<uint32_t>(buffer + 16);
204 compressedSize = to<uint32_t>(buffer + 20);
205 uncompressedSize = to<uint32_t>(buffer + 24);
206 filenameLength = to<uint16_t>(buffer + 28);
207 extraLength = to<uint16_t>(buffer + 30);
208 commentLength = to<uint16_t>(buffer + 32);
209 nbDisk = to<uint16_t>(buffer + 34);
210 internAttr = to<uint16_t>(buffer + 36);
211 externAttr = to<uint32_t>(buffer + 38);
212 offset = to<uint32_t>(buffer + 42);
213 if(maxSize > 0 && (uint32_t)(cdfhBaseSize+filenameLength + extraLength + commentLength) > maxSize){
214 throw bad_data();
215 }
216 filename.assign( buffer + 46, filenameLength );
217
218 // now parse the 'extra' (may contain the zip64 extension to CDFH)
219 ParseExtra( buffer + 46 + filenameLength, extraLength );
220
222 }
void ParseExtra(const char *buffer, uint16_t length)

References cdfhBaseSize, cdfhSize, commentLength, compressedSize, compressionMethod, XrdZip::dos_timestmp::date, externAttr, extraLength, filename, filenameLength, generalBitFlag, internAttr, minZipVersion, nbDisk, offset, ParseExtra(), XrdZip::dos_timestmp::time, timestmp, uncompressedSize, ZCRC32, and zipVersion.

+ Here is the call graph for this function:

Member Function Documentation

◆ CalcSize()

static size_t XrdZip::CDFH::CalcSize ( const cdvec_t cdvec,
uint32_t  orgcdsz,
uint32_t  orgcdcnt 
)
inlinestatic

Definition at line 132 of file XrdZipCDFH.hh.

133 {
134 size_t size = 0;
135 auto itr = cdvec.begin() + orgcdcnt;
136 for( ; itr != cdvec.end() ; ++itr )
137 {
138 CDFH *cdfh = itr->get();
139 size += cdfh->cdfhSize;
140 }
141 return size + orgcdsz;
142 }
CDFH(LFH *lfh, mode_t mode, uint64_t lfhOffset)

References cdfhSize.

◆ GetOffset()

static uint64_t XrdZip::CDFH::GetOffset ( const CDFH cdfh)
inlinestatic

Definition at line 227 of file XrdZipCDFH.hh.

228 {
229 if( cdfh.offset != ovrflw<uint32_t>::value )
230 return cdfh.offset;
231 return cdfh.extra->offset;
232 }

References extra, and offset.

◆ HasDataDescriptor()

bool XrdZip::CDFH::HasDataDescriptor ( )
inline
Returns
: true if the data descriptor flag is on, false otherwise

Definition at line 324 of file XrdZipCDFH.hh.

325 {
327 }
static const uint16_t flag

References XrdZip::DataDescriptor::flag, and generalBitFlag.

Referenced by XrdCl::ZipArchive::GetOffset().

+ Here is the caller graph for this function:

◆ IsZIP64()

bool XrdZip::CDFH::IsZIP64 ( ) const
inline
Returns
: true if ZIP64 extension is present, false otherwise

Definition at line 316 of file XrdZipCDFH.hh.

317 {
318 return extra.get();
319 }

References extra.

Referenced by XrdCl::ZipArchive::GetOffset().

+ Here is the caller graph for this function:

◆ Parse() [1/2]

static std::tuple< cdvec_t, cdmap_t > XrdZip::CDFH::Parse ( const char *&  buffer,
uint32_t  bufferSize 
)
inlinestatic

Definition at line 105 of file XrdZipCDFH.hh.

106 {
107 cdvec_t cdvec;
108 cdmap_t cdmap;
109 size_t i = 0;
110 while( bufferSize > 0 )
111 {
112 if( bufferSize < sizeof( uint32_t ) ) throw bad_data();
113 // check the signature
114 uint32_t signature = to<uint32_t>( buffer );
115 if( signature != cdfhSign )
116 return std::make_tuple( std::move( cdvec ), std::move( cdmap ) );
117 // parse the record
118 std::unique_ptr<CDFH> cdfh( new CDFH( buffer ) );
119 if( bufferSize < cdfh->cdfhSize ) throw bad_data();
120 buffer += cdfh->cdfhSize;
121 bufferSize -= cdfh->cdfhSize;
122 cdmap[cdfh->filename] = i++;
123 cdvec.push_back( std::move( cdfh ) );
124 }
125
126 return std::make_tuple( std::move( cdvec ), std::move( cdmap ) );
127 }
std::vector< std::unique_ptr< CDFH > > cdvec_t
Definition XrdZipCDFH.hh:51
std::unordered_map< std::string, size_t > cdmap_t
Definition XrdZipCDFH.hh:56
static const uint32_t cdfhSign

References cdfhSign, and cdfhSize.

◆ Parse() [2/2]

static std::tuple< cdvec_t, cdmap_t > XrdZip::CDFH::Parse ( const char *  buffer,
uint32_t  bufferSize,
uint16_t  nbCdRecords 
)
inlinestatic

Definition at line 75 of file XrdZipCDFH.hh.

76 {
77 uint32_t offset = 0;
78 cdvec_t cdvec;
79 cdmap_t cdmap;
80 cdvec.reserve( nbCdRecords );
81
82 for( size_t i = 0; i < nbCdRecords; ++i )
83 {
84 if( bufferSize < cdfhBaseSize ) break;
85 // check the signature
86 uint32_t signature = to<uint32_t>( buffer + offset );
87 if( signature != cdfhSign ) throw bad_data();
88 // parse the record
89 std::unique_ptr<CDFH> cdfh( new CDFH( buffer + offset, bufferSize ) );
90 offset += cdfh->cdfhSize;
91 bufferSize -= cdfh->cdfhSize;
92 cdmap[cdfh->filename] = i;
93 cdvec.push_back( std::move( cdfh ) );
94 }
95
96 return std::make_tuple( std::move( cdvec ), std::move( cdmap ) );
97 }

References cdfhBaseSize, cdfhSign, and offset.

Referenced by XrdCl::ZipArchive::OpenArchive().

+ Here is the caller graph for this function:

◆ ParseExtra()

void XrdZip::CDFH::ParseExtra ( const char *  buffer,
uint16_t  length 
)
inline

Definition at line 237 of file XrdZipCDFH.hh.

238 {
239 uint8_t ovrflws = Extra::NONE;
240 uint16_t exsize = 0;
241
242 // check if compressed size is overflown
244 {
245 ovrflws |= Extra::CPMSIZE;
246 exsize += sizeof( uint64_t );
247 }
248
249 // check if original size is overflown
251 {
252 ovrflws |= Extra::UCMPSIZE;
253 exsize += sizeof( uint64_t );
254 }
255
256 // check if offset is overflown
258 {
259 ovrflws |= Extra::OFFSET;
260 exsize += sizeof( uint64_t );
261 }
262
263 // check if number of disks is overflown
265 {
266 ovrflws |= Extra::NBDISK;
267 exsize += sizeof( uint32_t );
268 }
269
270 // if the expected size of ZIP64 extension is 0 we
271 // can skip parsing of 'extra'
272 if( exsize == 0 ) return;
273
274 // Parse the extra part
275 buffer = Extra::Find( buffer, length );
276 if( buffer )
277 {
278 extra.reset( new Extra() );
279 extra->FromBuffer( buffer, exsize, ovrflws );
280 }
281 }
static const char * Find(const char *buffer, uint16_t length)

References compressedSize, XrdZip::Extra::CPMSIZE, extra, XrdZip::Extra::Find(), nbDisk, XrdZip::Extra::NBDISK, XrdZip::Extra::NONE, offset, XrdZip::Extra::OFFSET, XrdZip::Extra::UCMPSIZE, and uncompressedSize.

Referenced by CDFH().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Serialize() [1/2]

void XrdZip::CDFH::Serialize ( buffer_t buffer)
inline

Serialize the object into a buffer.

Definition at line 286 of file XrdZipCDFH.hh.

287 {
288 copy_bytes( cdfhSign, buffer );
289 copy_bytes( zipVersion, buffer );
290 copy_bytes( minZipVersion, buffer );
291 copy_bytes( generalBitFlag, buffer );
292 copy_bytes( compressionMethod, buffer );
293 copy_bytes( timestmp.time, buffer );
294 copy_bytes( timestmp.date, buffer );
295 copy_bytes( ZCRC32, buffer );
296 copy_bytes( compressedSize, buffer );
297 copy_bytes( uncompressedSize, buffer );
298 copy_bytes( filenameLength, buffer );
299 copy_bytes( extraLength, buffer );
300 copy_bytes( commentLength, buffer );
301 copy_bytes( nbDisk, buffer );
302 copy_bytes( internAttr, buffer );
303 copy_bytes( externAttr, buffer );
304 copy_bytes( offset, buffer );
305 std::copy( filename.begin(), filename.end(), std::back_inserter( buffer ) );
306 if( extra )
307 extra->Serialize( buffer );
308
309 if ( commentLength > 0 )
310 std::copy( comment.begin(), comment.end(), std::back_inserter( buffer ) );
311 }
static void copy_bytes(const INT value, buffer_t &buffer)
std::string comment

References cdfhSign, comment, commentLength, compressedSize, compressionMethod, XrdZip::copy_bytes(), XrdZip::dos_timestmp::date, externAttr, extra, extraLength, filename, filenameLength, generalBitFlag, internAttr, minZipVersion, nbDisk, offset, XrdZip::dos_timestmp::time, timestmp, uncompressedSize, ZCRC32, and zipVersion.

+ Here is the call graph for this function:

◆ Serialize() [2/2]

static void XrdZip::CDFH::Serialize ( uint32_t  orgcdcnt,
const buffer_t orgcdbuf,
const cdvec_t cdvec,
buffer_t buffer 
)
inlinestatic

Definition at line 144 of file XrdZipCDFH.hh.

148 {
149 std::copy( orgcdbuf.begin(), orgcdbuf.end(), std::back_inserter( buffer ) );
150 auto itr = cdvec.begin() + orgcdcnt;
151 for( ; itr != cdvec.end() ; ++itr )
152 {
153 CDFH *cdfh = itr->get();
154 cdfh->Serialize( buffer );
155 }
156 }

References Serialize().

Referenced by Serialize().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ cdfhBaseSize

const uint16_t XrdZip::CDFH::cdfhBaseSize = 46
static

Definition at line 353 of file XrdZipCDFH.hh.

Referenced by CDFH(), CDFH(), and Parse().

◆ cdfhSign

const uint32_t XrdZip::CDFH::cdfhSign = 0x02014b50
static

Definition at line 352 of file XrdZipCDFH.hh.

Referenced by Parse(), Parse(), and Serialize().

◆ cdfhSize

uint16_t XrdZip::CDFH::cdfhSize

Definition at line 347 of file XrdZipCDFH.hh.

Referenced by CDFH(), CDFH(), CalcSize(), and Parse().

◆ comment

std::string XrdZip::CDFH::comment

Definition at line 346 of file XrdZipCDFH.hh.

Referenced by Serialize().

◆ commentLength

uint16_t XrdZip::CDFH::commentLength

Definition at line 339 of file XrdZipCDFH.hh.

Referenced by CDFH(), CDFH(), and Serialize().

◆ compressedSize

uint32_t XrdZip::CDFH::compressedSize

Definition at line 335 of file XrdZipCDFH.hh.

Referenced by CDFH(), XrdCl::ZipArchive::GetOffset(), ParseExtra(), and Serialize().

◆ compressionMethod

uint16_t XrdZip::CDFH::compressionMethod

Definition at line 332 of file XrdZipCDFH.hh.

Referenced by CDFH(), XrdCl::ZipArchive::GetOffset(), and Serialize().

◆ externAttr

uint32_t XrdZip::CDFH::externAttr

Definition at line 342 of file XrdZipCDFH.hh.

Referenced by CDFH(), and Serialize().

◆ extra

std::unique_ptr<Extra> XrdZip::CDFH::extra

◆ extraLength

uint16_t XrdZip::CDFH::extraLength

Definition at line 338 of file XrdZipCDFH.hh.

Referenced by CDFH(), CDFH(), and Serialize().

◆ filename

std::string XrdZip::CDFH::filename

Definition at line 344 of file XrdZipCDFH.hh.

Referenced by CDFH(), XrdCl::ZipArchive::List(), and Serialize().

◆ filenameLength

uint16_t XrdZip::CDFH::filenameLength

Definition at line 337 of file XrdZipCDFH.hh.

Referenced by CDFH(), CDFH(), and Serialize().

◆ generalBitFlag

uint16_t XrdZip::CDFH::generalBitFlag

Definition at line 331 of file XrdZipCDFH.hh.

Referenced by CDFH(), HasDataDescriptor(), and Serialize().

◆ internAttr

uint16_t XrdZip::CDFH::internAttr

Definition at line 341 of file XrdZipCDFH.hh.

Referenced by CDFH(), and Serialize().

◆ minZipVersion

uint16_t XrdZip::CDFH::minZipVersion

Definition at line 330 of file XrdZipCDFH.hh.

Referenced by CDFH(), CDFH(), and Serialize().

◆ nbDisk

uint16_t XrdZip::CDFH::nbDisk

Definition at line 340 of file XrdZipCDFH.hh.

Referenced by CDFH(), ParseExtra(), and Serialize().

◆ offset

uint32_t XrdZip::CDFH::offset

Definition at line 343 of file XrdZipCDFH.hh.

Referenced by CDFH(), CDFH(), GetOffset(), Parse(), ParseExtra(), and Serialize().

◆ timestmp

dos_timestmp XrdZip::CDFH::timestmp

Definition at line 333 of file XrdZipCDFH.hh.

Referenced by CDFH(), and Serialize().

◆ uncompressedSize

uint32_t XrdZip::CDFH::uncompressedSize

Definition at line 336 of file XrdZipCDFH.hh.

Referenced by CDFH(), XrdCl::ZipArchive::List(), ParseExtra(), and Serialize().

◆ ZCRC32

uint32_t XrdZip::CDFH::ZCRC32

Definition at line 334 of file XrdZipCDFH.hh.

Referenced by CDFH(), and Serialize().

◆ zipVersion

uint16_t XrdZip::CDFH::zipVersion

Definition at line 329 of file XrdZipCDFH.hh.

Referenced by CDFH(), and Serialize().


The documentation for this struct was generated from the following file: