libzypp: zypp-curl/parser/mediablocklist.h Source File

libzypp 17.38.11

mediablocklist.h
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
12#ifndef ZYPP_CURL_PARSER_MEDIABLOCKLIST_H
13#define ZYPP_CURL_PARSER_MEDIABLOCKLIST_H
14
15#include <sys/types.h>
16#include <vector>
17#include <optional>
18
19#include <zypp-core/Digest.h>
20
21namespace zypp {
22 namespace media {
23
27 struct MediaBlock {
28 MediaBlock( off_t off_r, size_t size_r )
29 : off( off_r )
30 , size( size_r )
31 {}
32 off_t off;
33 size_t size;
34};
35
36 class MediaBlockList {
37public:
38 MediaBlockList(off_t filesize=off_t(-1));
39
44 inline bool haveBlocks() const {
45 return haveblocks;
46 }
47
52 size_t addBlock(off_t off, size_t size);
53
57 inline const MediaBlock &getBlock(size_t blkno) const {
58 return blocks[blkno];
59 }
60
63 inline size_t numBlocks() const {
64 return blocks.size();
65 }
66
70 inline void setFilesize(off_t newfilesize=off_t(-1)) {
71 filesize = newfilesize;
72 }
73 inline off_t getFilesize() const {
74 return filesize;
75 }
76 inline bool haveFilesize() const {
77 return filesize != off_t(-1);
78 }
79
83 void setFileChecksum(std::string ctype, int cl, unsigned char *c);
84 std::string fileChecksumType () const;
85
86 const UByteArray &getFileChecksum( );
87 bool createFileDigest(Digest &digest) const;
88 bool verifyFileDigest(Digest &digest) const;
89 inline bool haveFileChecksum() const {
90 return !fsumtype.empty() && fsum.size();
91 }
92
96 void setChecksum(size_t blkno, const std::string& cstype, int csl, unsigned char *cs, size_t cspad=0);
97 bool checkChecksum(size_t blkno, const unsigned char *buf, size_t bufl) const;
98 UByteArray getChecksum( size_t blkno ) const;
99 std::string getChecksumType( ) const;
100 size_t checksumPad() const;
101 bool createDigest(Digest &digest) const;
102 bool verifyDigest(size_t blkno, Digest &digest) const;
103 inline bool haveChecksum(size_t blkno) const {
104 return chksumlen && chksums.size() >= chksumlen * (blkno + 1);
105 }
106
110 void setRsum(size_t blkno, int rsl, unsigned int rs, size_t rspad=0);
111
116 void setRsumSequence( uint seq );
117 bool checkRsum(size_t blkno, const unsigned char *buf, size_t bufl) const;
118 unsigned int updateRsum(unsigned int rs, const char *bytes, size_t len) const;
119 bool verifyRsum(size_t blkno, unsigned int rs) const;
120 inline bool haveRsum(size_t blkno) const {
121 return rsumlen && rsums.size() >= blkno + 1;
122 }
123
128 void reuseBlocksOld(FILE *wfp, const std::string& filename);
129 void reuseBlocks(FILE *wfp, const std::string& filename);
130
134 std::string asString() const;
135
136private:
137 void writeBlock(size_t blkno, FILE *fp, const unsigned char *buf, size_t bufl, size_t start, std::vector<bool> &found) const;
138 bool checkChecksumRotated(size_t blkno, const unsigned char *buf, size_t bufl, size_t start) const;
139
140 off_t filesize;
141 std::string fsumtype;
142 UByteArray fsum;
143
144 bool haveblocks;
145 std::vector<MediaBlock> blocks;
146
147 std::string chksumtype;
148 int chksumlen;
149 size_t chksumpad;
150 std::vector<unsigned char> chksums;
151
152 int rsumlen;
153 uint rsumseq; // < how many consecutive matches are required
154 size_t rsumpad;
155 std::vector<unsigned int> rsums;
156};
157
158 inline std::ostream & operator<<(std::ostream &str, const MediaBlockList &bl)
159{ return str << bl.asString(); }
160
161 } // namespace media
162} // namespace zypp
163
164#endif // ZYPP_CURL_PARSER_MEDIABLOCKLIST_H
zypp::Digest
Compute Message Digests (MD5, SHA1 etc).
Definition Digest.h:38
zypp::UByteArray
Definition ByteArray.h:52
zypp::media::MediaBlockList
Definition mediablocklist.h:36
zypp::media::MediaBlockList::rsums
std::vector< unsigned int > rsums
Definition mediablocklist.h:155
zypp::media::MediaBlockList::setRsum
void setRsum(size_t blkno, int rsl, unsigned int rs, size_t rspad=0)
set / verify the (weak) rolling checksum over a single block
Definition mediablocklist.cc:247
zypp::media::MediaBlockList::haveChecksum
bool haveChecksum(size_t blkno) const
Definition mediablocklist.h:103
zypp::media::MediaBlockList::getFilesize
off_t getFilesize() const
Definition mediablocklist.h:73
zypp::media::MediaBlockList::setFileChecksum
void setFileChecksum(std::string ctype, int cl, unsigned char *c)
set / verify the checksum over the whole file
Definition mediablocklist.cc:191
zypp::media::MediaBlockList::verifyRsum
bool verifyRsum(size_t blkno, unsigned int rs) const
Definition mediablocklist.cc:314
zypp::media::MediaBlockList::haveFileChecksum
bool haveFileChecksum() const
Definition mediablocklist.h:89
zypp::media::MediaBlockList::getFileChecksum
const UByteArray & getFileChecksum()
Definition mediablocklist.cc:205
zypp::media::MediaBlockList::writeBlock
void writeBlock(size_t blkno, FILE *fp, const unsigned char *buf, size_t bufl, size_t start, std::vector< bool > &found) const
Definition mediablocklist.cc:395
zypp::media::MediaBlockList::createDigest
bool createDigest(Digest &digest) const
Definition mediablocklist.cc:270
zypp::media::MediaBlockList::asString
std::string asString() const
return block list as string
Definition mediablocklist.cc:1062
zypp::media::MediaBlockList::setRsumSequence
void setRsumSequence(uint seq)
how many blocks in sequence need to have the correct checksums to be considered a match
Definition mediablocklist.cc:264
zypp::media::MediaBlockList::checksumPad
size_t checksumPad() const
Definition mediablocklist.cc:369
zypp::media::MediaBlockList::getBlock
const MediaBlock & getBlock(size_t blkno) const
return the offset/size of a block with number blkno
Definition mediablocklist.h:57
zypp::media::MediaBlockList::chksumlen
int chksumlen
Definition mediablocklist.h:148
zypp::media::MediaBlockList::getChecksum
UByteArray getChecksum(size_t blkno) const
Definition mediablocklist.cc:354
zypp::media::MediaBlockList::checkChecksumRotated
bool checkChecksumRotated(size_t blkno, const unsigned char *buf, size_t bufl, size_t start) const
Definition mediablocklist.cc:376
zypp::media::MediaBlockList::chksumtype
std::string chksumtype
Definition mediablocklist.h:147
zypp::media::MediaBlockList::chksums
std::vector< unsigned char > chksums
Definition mediablocklist.h:150
zypp::media::MediaBlockList::addBlock
size_t addBlock(off_t off, size_t size)
add a block with offset off and size size to the block list.
Definition mediablocklist.cc:183
zypp::media::MediaBlockList::updateRsum
unsigned int updateRsum(unsigned int rs, const char *bytes, size_t len) const
Definition mediablocklist.cc:296
zypp::media::MediaBlockList::reuseBlocks
void reuseBlocks(FILE *wfp, const std::string &filename)
Definition mediablocklist.cc:439
zypp::media::MediaBlockList::reuseBlocksOld
void reuseBlocksOld(FILE *wfp, const std::string &filename)
scan a file for blocks from our blocklist.
Definition mediablocklist.cc:769
zypp::media::MediaBlockList::verifyDigest
bool verifyDigest(size_t blkno, Digest &digest) const
Definition mediablocklist.cc:276
zypp::media::MediaBlockList::filesize
off_t filesize
Definition mediablocklist.h:140
zypp::media::MediaBlockList::haveBlocks
bool haveBlocks() const
do we have a blocklist describing the file?
Definition mediablocklist.h:44
zypp::media::MediaBlockList::checkRsum
bool checkRsum(size_t blkno, const unsigned char *buf, size_t bufl) const
Definition mediablocklist.cc:334
zypp::media::MediaBlockList::blocks
std::vector< MediaBlock > blocks
Definition mediablocklist.h:145
zypp::media::MediaBlockList::fsum
UByteArray fsum
Definition mediablocklist.h:142
zypp::media::MediaBlockList::rsumpad
size_t rsumpad
Definition mediablocklist.h:154
zypp::media::MediaBlockList::getChecksumType
std::string getChecksumType() const
Definition mediablocklist.cc:364
zypp::media::MediaBlockList::createFileDigest
bool createFileDigest(Digest &digest) const
Definition mediablocklist.cc:211
zypp::media::MediaBlockList::numBlocks
size_t numBlocks() const
return the number of blocks in the blocklist
Definition mediablocklist.h:63
zypp::media::MediaBlockList::verifyFileDigest
bool verifyFileDigest(Digest &digest) const
Definition mediablocklist.cc:217
zypp::media::MediaBlockList::fsumtype
std::string fsumtype
Definition mediablocklist.h:141
zypp::media::MediaBlockList::fileChecksumType
std::string fileChecksumType() const
Definition mediablocklist.cc:200
zypp::media::MediaBlockList::haveblocks
bool haveblocks
Definition mediablocklist.h:144
zypp::media::MediaBlockList::rsumlen
int rsumlen
Definition mediablocklist.h:152
zypp::media::MediaBlockList::haveRsum
bool haveRsum(size_t blkno) const
Definition mediablocklist.h:120
zypp::media::MediaBlockList::setFilesize
void setFilesize(off_t newfilesize=off_t(-1))
set / return the size of the whole file
Definition mediablocklist.h:70
zypp::media::MediaBlockList::haveFilesize
bool haveFilesize() const
Definition mediablocklist.h:76
zypp::media::MediaBlockList::rsumseq
uint rsumseq
Definition mediablocklist.h:153
zypp::media::MediaBlockList::checkChecksum
bool checkChecksum(size_t blkno, const unsigned char *buf, size_t bufl) const
Definition mediablocklist.cc:343
zypp::media::MediaBlockList::setChecksum
void setChecksum(size_t blkno, const std::string &cstype, int csl, unsigned char *cs, size_t cspad=0)
set / verify the (strong) checksum over a single block
Definition mediablocklist.cc:228
zypp::media::MediaBlockList::chksumpad
size_t chksumpad
Definition mediablocklist.h:149
zypp::media::MediaBlockList::MediaBlockList
MediaBlockList(off_t filesize=off_t(-1))
Definition mediablocklist.cc:172
str
String related utilities and Regular expression matching.
zypp::media
Definition MediaNetworkRequestExecutor.h:22
zypp::media::operator<<
std::ostream & operator<<(std::ostream &str, const MediaHandler &obj)
Definition MediaHandler.cc:1181
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition CodePitfalls.doc:2
zypp::media::MediaBlock
a single block from the blocklist, consisting of an offset and a size
Definition mediablocklist.h:27
zypp::media::MediaBlock::off
off_t off
Definition mediablocklist.h:32
zypp::media::MediaBlock::size
size_t size
Definition mediablocklist.h:33
zypp::media::MediaBlock::MediaBlock
MediaBlock(off_t off_r, size_t size_r)
Definition mediablocklist.h:28
Digest.h