libzypp 8.13.6
|
00001 /*---------------------------------------------------------------------\ 00002 | ____ _ __ __ ___ | 00003 | |__ / \ / / . \ . \ | 00004 | / / \ V /| _/ _/ | 00005 | / /__ | | | | | | | 00006 | /_____||_| |_| |_| | 00007 | | 00008 \---------------------------------------------------------------------*/ 00012 #ifndef ZYPP_MEDIA_MEDIABLOCKLIST_H 00013 #define ZYPP_MEDIA_MEDIABLOCKLIST_H 00014 00015 #include <sys/types.h> 00016 #include <vector> 00017 00018 #include "zypp/Digest.h" 00019 00020 namespace zypp { 00021 namespace media { 00022 00026 struct MediaBlock { 00027 off_t off; 00028 size_t size; 00029 }; 00030 00031 class MediaBlockList { 00032 public: 00033 MediaBlockList(off_t filesize=off_t(-1)); 00034 00039 inline bool haveBlocks() const { 00040 return haveblocks; 00041 } 00047 size_t addBlock(off_t off, size_t size); 00048 00052 inline MediaBlock getBlock(size_t blkno) const { 00053 return blocks[blkno]; 00054 } 00058 inline size_t numBlocks() const { 00059 return blocks.size(); 00060 } 00061 00065 inline void setFilesize(off_t newfilesize=off_t(-1)) { 00066 filesize = newfilesize; 00067 } 00068 inline off_t getFilesize() const { 00069 return filesize; 00070 } 00071 inline bool haveFilesize() const { 00072 return filesize != off_t(-1); 00073 } 00074 00078 void setFileChecksum(std::string ctype, int cl, unsigned char *c); 00079 bool createFileDigest(Digest &digest) const; 00080 bool verifyFileDigest(Digest &digest) const; 00081 inline bool haveFileChecksum() const { 00082 return !fsumtype.empty() && fsum.size(); 00083 } 00084 00088 void setChecksum(size_t blkno, std::string cstype, int csl, unsigned char *cs, size_t cspad=0); 00089 bool checkChecksum(size_t blkno, const unsigned char *buf, size_t bufl) const; 00090 bool createDigest(Digest &digest) const; 00091 bool verifyDigest(size_t blkno, Digest &digest) const; 00092 inline bool haveChecksum(size_t blkno) const { 00093 return chksumlen && chksums.size() >= chksumlen * (blkno + 1); 00094 } 00095 00099 void setRsum(size_t blkno, int rsl, unsigned int rs, size_t rspad=0); 00100 bool checkRsum(size_t blkno, const unsigned char *buf, size_t bufl) const; 00101 unsigned int updateRsum(unsigned int rs, const char *bytes, size_t len) const; 00102 bool verifyRsum(size_t blkno, unsigned int rs) const; 00103 inline bool haveRsum(size_t blkno) const { 00104 return rsumlen && rsums.size() >= blkno + 1; 00105 } 00106 00111 void reuseBlocks(FILE *wfp, std::string filename); 00112 00116 std::string asString() const; 00117 00118 private: 00119 void writeBlock(size_t blkno, FILE *fp, const unsigned char *buf, size_t bufl, size_t start, std::vector<bool> &found) const; 00120 bool checkChecksumRotated(size_t blkno, const unsigned char *buf, size_t bufl, size_t start) const; 00121 00122 off_t filesize; 00123 std::string fsumtype; 00124 std::vector<unsigned char> fsum; 00125 00126 bool haveblocks; 00127 std::vector<MediaBlock> blocks; 00128 00129 std::string chksumtype; 00130 int chksumlen; 00131 size_t chksumpad; 00132 std::vector<unsigned char> chksums; 00133 00134 std::string rsumtype; 00135 int rsumlen; 00136 size_t rsumpad; 00137 std::vector<unsigned int> rsums; 00138 }; 00139 00140 inline std::ostream & operator<<(std::ostream &str, const MediaBlockList &bl) 00141 { return str << bl.asString(); } 00142 00143 } // namespace media 00144 } // namespace zypp 00145 00146 #endif // ZYPP_MEDIA_MEDIABLOCKLIST_H 00147