13 #include <sys/types.h>
56 memcpy(&
fsum[0], c, cl);
76 if (dig.empty() || dig.size() <
fsum.size())
78 return memcmp(&dig[0], &
fsum[0],
fsum.size()) ? false :
true;
97 memcpy(&
chksums[csl * blkno], cs, csl);
128 size_t size =
blocks[blkno].size;
138 if (dig.empty() || dig.size() <
size_t(
chksumlen))
149 s = (rs >> 16) & 65535;
151 for (; len > 0 ; len--)
153 unsigned short c = (
unsigned char)*bytes++;
157 return (s & 65535) << 16 | (m & 65535);
165 size_t size =
blocks[blkno].size;
171 s = (rs >> 16) & 65535;
174 rs = (s & 65535) << 16 | (m & 65535);
187 return rs ==
rsums[blkno];
193 if (blkno >=
blocks.size() || bufl <
blocks[blkno].size)
202 if (blkno >=
blocks.size() || bufl <
blocks[blkno].size)
216 std::vector<unsigned char> buf (
chksumlen,
'\0' );
225 if (blkno >=
blocks.size() || bufl <
blocks[blkno].size)
232 size_t size =
blocks[blkno].size;
233 size_t len = bufl - start > size ? size : bufl - start;
234 dig.
update((
const char *)buf + start, len);
236 dig.
update((
const char *)buf, size - len);
244 if (blkno >=
blocks.size() || bufl <
blocks[blkno].size)
246 off_t off =
blocks[blkno].off;
247 size_t size =
blocks[blkno].size;
248 if (fseeko(fp, off, SEEK_SET))
252 size_t len = bufl - start > size ? size : bufl - start;
253 if (fwrite(buf + start, len, 1, fp) != 1)
255 if (size > len && fwrite(buf, size - len, 1, fp) != 1)
258 found[
blocks.size()] =
true;
262 fetchnext(FILE *fp,
unsigned char *bp,
size_t blksize,
size_t pushback,
unsigned char *pushbackp)
270 memmove(bp, pushbackp, pushback);
293 if (!
chksumlen || (fp = fopen(filename.c_str(),
"r")) == 0)
295 size_t nblks =
blocks.size();
296 std::vector<bool> found;
297 found.resize(nblks + 1);
300 size_t blksize =
blocks[0].size;
304 unsigned int hm =
rsums.size() * 2;
305 while (hm & (hm - 1))
310 unsigned int *ht =
new unsigned int[hm + 1];
311 memset(ht, 0, (hm + 1) *
sizeof(
unsigned int));
312 for (
unsigned int i = 0; i <
rsums.size(); i++)
314 if (
blocks[i].size != blksize && (i != nblks - 1 ||
rsumpad != blksize))
316 unsigned int r =
rsums[i];
317 unsigned int h = r & hm;
324 unsigned char *buf =
new unsigned char[blksize];
325 unsigned char *buf2 =
new unsigned char[blksize];
327 unsigned char *pushbackp = 0;
329 if ((blksize & (blksize - 1)) == 0)
330 for (bshift = 0; size_t(1 << bshift) != blksize; bshift++)
334 memset(buf, 0, blksize);
337 int sql = nblks > 1 &&
chksumlen < 16 ? 2 : 1;
340 for (
size_t i = 0; i < blksize; i++)
366 b += a - (oc << bshift);
368 b += a - oc * blksize;
371 if (
size_t(i) != blksize - 1)
377 r = ((
unsigned int)b & 255);
379 r = ((
unsigned int)b & 65535);
381 r = ((
unsigned int)a & 255) << 16 | ((
unsigned int)b & 65535);
383 r = ((
unsigned int)a & 65535) << 16 | ((
unsigned int)b & 65535);
384 unsigned int h = r & hm;
386 for (; ht[h]; h = (h + hh++) & hm)
388 size_t blkno = ht[h] - 1;
389 if (
rsums[blkno] != r)
395 if (eof || blkno + 1 >= nblks)
397 pushback =
fetchnext(fp, buf2, blksize, pushback, pushbackp);
401 if (!
checkRsum(blkno + 1, buf2, blksize))
408 writeBlock(blkno, wfp, buf, blksize, i + 1, found);
411 writeBlock(blkno + 1, wfp, buf2, blksize, 0, found);
418 pushback =
fetchnext(fp, buf2, blksize, pushback, pushbackp);
426 writeBlock(blkno, wfp, buf2, blksize, 0, found);
430 memset(buf, 0, blksize);
446 unsigned char *buf =
new unsigned char[bufl];
447 for (
size_t blkno = 0; blkno <
blocks.size(); ++blkno)
449 if (off >
blocks[blkno].off)
451 size_t blksize =
blocks[blkno].size;
456 buf =
new unsigned char[bufl];
458 size_t skip =
blocks[blkno].off - off;
461 size_t l = skip > bufl ? bufl : skip;
462 if (fread(buf, l, 1, fp) != 1)
467 if (fread(buf, blksize, 1, fp) != 1)
470 writeBlock(blkno, wfp, buf, blksize, 0, found);
477 std::vector<MediaBlock> nblocks;
478 std::vector<unsigned char> nchksums;
479 std::vector<unsigned int> nrsums;
481 for (
size_t blkno = 0; blkno <
blocks.size(); ++blkno)
486 nblocks.push_back(
blocks[blkno]);
489 nchksums.resize(nblocks.size() *
chksumlen);
493 nrsums.push_back(
rsums[blkno]);
513 s =
"[ BlockList, filesize unknown\n";
515 s +=
" No block information\n";
520 for (i = 0; i <
blocks.size(); ++i)
522 long long off=
blocks[i].off;
523 long long size=
blocks[i].size;
Compute Message Digests (MD5, SHA1 etc)
bool update(const char *bytes, size_t len)
feed data into digest computation algorithm
std::vector< unsigned char > digestVector()
get vector of unsigned char representation of the digest
bool create(const std::string &name)
initialize creation of a new message digest
std::string form(const char *format,...) __attribute__((format(printf
Printf style construction of std::string.
Easy-to use interface to the ZYPP dependency resolver.