| 1 | // -*- mode: cpp; mode: fold -*- |
| 2 | // Description /*{{{*/ |
| 3 | // $Id: pkgcachegen.h,v 1.19 2002/07/08 03:13:30 jgg Exp $ |
| 4 | /* ###################################################################### |
| 5 | |
| 6 | Package Cache Generator - Generator for the cache structure. |
| 7 | |
| 8 | This builds the cache structure from the abstract package list parser. |
| 9 | Each archive source has it's own list parser that is instantiated by |
| 10 | the caller to provide data for the generator. |
| 11 | |
| 12 | Parts of the cache are created by this generator class while other |
| 13 | parts are created by the list parser. The list parser is responsible |
| 14 | for creating version, depends and provides structures, and some of |
| 15 | their contents |
| 16 | |
| 17 | ##################################################################### */ |
| 18 | /*}}}*/ |
| 19 | #ifndef PKGLIB_PKGCACHEGEN_H |
| 20 | #define PKGLIB_PKGCACHEGEN_H |
| 21 | |
| 22 | |
| 23 | #include <apt-pkg/pkgcache.h> |
| 24 | #include <apt-pkg/md5.h> |
| 25 | #include <apt-pkg/macros.h> |
| 26 | |
| 27 | #include <vector> |
| 28 | |
| 29 | class pkgSourceList; |
| 30 | class OpProgress; |
| 31 | class MMap; |
| 32 | class pkgIndexFile; |
| 33 | |
| 34 | class pkgCacheGenerator /*{{{*/ |
| 35 | { |
| 36 | private: |
| 37 | |
| 38 | pkgCache::StringItem *UniqHash[26]; |
| 39 | map_ptrloc WriteStringInMap(std::string const &String) { return WriteStringInMap(String.c_str()); }; |
| 40 | map_ptrloc WriteStringInMap(const char *String); |
| 41 | map_ptrloc WriteStringInMap(const char *String, const unsigned long &Len); |
| 42 | map_ptrloc AllocateInMap(const unsigned long &size); |
| 43 | |
| 44 | public: |
| 45 | |
| 46 | class ListParser; |
| 47 | friend class ListParser; |
| 48 | |
| 49 | template<typename Iter> class Dynamic { |
| 50 | public: |
| 51 | static std::vector<Iter*> toReMap; |
| 52 | Dynamic(Iter &I) { |
| 53 | toReMap.push_back(&I); |
| 54 | } |
| 55 | |
| 56 | ~Dynamic() { |
| 57 | toReMap.pop_back(); |
| 58 | } |
| 59 | }; |
| 60 | |
| 61 | protected: |
| 62 | |
| 63 | DynamicMMap ⤅ |
| 64 | pkgCache Cache; |
| 65 | OpProgress *Progress; |
| 66 | |
| 67 | std::string PkgFileName; |
| 68 | pkgCache::PackageFile *CurrentFile; |
| 69 | |
| 70 | // Flag file dependencies |
| 71 | bool FoundFileDeps; |
| 72 | |
| 73 | bool NewGroup(pkgCache::GrpIterator &Grp,const std::string &Name); |
| 74 | bool NewPackage(pkgCache::PkgIterator &Pkg,const std::string &Name, const std::string &Arch); |
| 75 | bool NewFileVer(pkgCache::VerIterator &Ver,ListParser &List); |
| 76 | bool NewFileDesc(pkgCache::DescIterator &Desc,ListParser &List); |
| 77 | bool NewDepends(pkgCache::PkgIterator &Pkg, pkgCache::VerIterator &Ver, |
| 78 | std::string const &Version, unsigned int const &Op, |
| 79 | unsigned int const &Type, map_ptrloc* &OldDepLast); |
| 80 | bool NewDepends(pkgCache::PkgIterator &Pkg, pkgCache::VerIterator &Ver, |
| 81 | map_ptrloc const Version, unsigned int const &Op, |
| 82 | unsigned int const &Type, map_ptrloc* &OldDepLast); |
| 83 | __deprecated unsigned long NewVersion(pkgCache::VerIterator &Ver,const std::string &VerStr,unsigned long Next) |
| 84 | { return NewVersion(Ver, VerStr, 0, 0, Next); } |
| 85 | unsigned long NewVersion(pkgCache::VerIterator &Ver,const std::string &VerStr, |
| 86 | map_ptrloc const ParentPkg, unsigned long const Hash, |
| 87 | unsigned long Next); |
| 88 | map_ptrloc NewDescription(pkgCache::DescIterator &Desc,const std::string &Lang,const MD5SumValue &md5sum,map_ptrloc Next); |
| 89 | |
| 90 | public: |
| 91 | |
| 92 | unsigned long WriteUniqString(const char *S,unsigned int Size); |
| 93 | inline unsigned long WriteUniqString(const std::string &S) {return WriteUniqString(S.c_str(),S.length());}; |
| 94 | |
| 95 | void DropProgress() {Progress = 0;}; |
| 96 | bool SelectFile(const std::string &File,const std::string &Site,pkgIndexFile const &Index, |
| 97 | unsigned long Flags = 0); |
| 98 | bool MergeList(ListParser &List,pkgCache::VerIterator *Ver = 0); |
| 99 | inline pkgCache &GetCache() {return Cache;}; |
| 100 | inline pkgCache::PkgFileIterator GetCurFile() |
| 101 | {return pkgCache::PkgFileIterator(Cache,CurrentFile);}; |
| 102 | |
| 103 | bool HasFileDeps() {return FoundFileDeps;}; |
| 104 | bool MergeFileProvides(ListParser &List); |
| 105 | __deprecated bool FinishCache(OpProgress *Progress); |
| 106 | |
| 107 | static bool MakeStatusCache(pkgSourceList &List,OpProgress *Progress, |
| 108 | MMap **OutMap = 0,bool AllowMem = false); |
| 109 | static bool MakeOnlyStatusCache(OpProgress *Progress,DynamicMMap **OutMap); |
| 110 | static DynamicMMap* CreateDynamicMMap(FileFd *CacheF, unsigned long Flags = 0); |
| 111 | |
| 112 | void ReMap(void const * const oldMap, void const * const newMap); |
| 113 | |
| 114 | pkgCacheGenerator(DynamicMMap *Map,OpProgress *Progress); |
| 115 | ~pkgCacheGenerator(); |
| 116 | |
| 117 | private: |
| 118 | bool MergeListGroup(ListParser &List, std::string const &GrpName); |
| 119 | bool MergeListPackage(ListParser &List, pkgCache::PkgIterator &Pkg); |
| 120 | bool MergeListVersion(ListParser &List, pkgCache::PkgIterator &Pkg, |
| 121 | std::string const &Version, pkgCache::VerIterator* &OutVer); |
| 122 | |
| 123 | bool AddImplicitDepends(pkgCache::GrpIterator &G, pkgCache::PkgIterator &P, |
| 124 | pkgCache::VerIterator &V); |
| 125 | bool AddImplicitDepends(pkgCache::VerIterator &V, pkgCache::PkgIterator &D); |
| 126 | }; |
| 127 | /*}}}*/ |
| 128 | // This is the abstract package list parser class. /*{{{*/ |
| 129 | class pkgCacheGenerator::ListParser |
| 130 | { |
| 131 | pkgCacheGenerator *Owner; |
| 132 | friend class pkgCacheGenerator; |
| 133 | |
| 134 | // Some cache items |
| 135 | pkgCache::VerIterator OldDepVer; |
| 136 | map_ptrloc *OldDepLast; |
| 137 | |
| 138 | // Flag file dependencies |
| 139 | bool FoundFileDeps; |
| 140 | |
| 141 | protected: |
| 142 | |
| 143 | inline unsigned long WriteUniqString(std::string S) {return Owner->WriteUniqString(S);}; |
| 144 | inline unsigned long WriteUniqString(const char *S,unsigned int Size) {return Owner->WriteUniqString(S,Size);}; |
| 145 | inline unsigned long WriteString(const std::string &S) {return Owner->WriteStringInMap(S);}; |
| 146 | inline unsigned long WriteString(const char *S,unsigned int Size) {return Owner->WriteStringInMap(S,Size);}; |
| 147 | bool NewDepends(pkgCache::VerIterator &Ver,const std::string &Package, const std::string &Arch, |
| 148 | const std::string &Version,unsigned int Op, |
| 149 | unsigned int Type); |
| 150 | bool NewProvides(pkgCache::VerIterator &Ver,const std::string &PkgName, |
| 151 | const std::string &PkgArch, const std::string &Version); |
| 152 | |
| 153 | public: |
| 154 | |
| 155 | // These all operate against the current section |
| 156 | virtual std::string Package() = 0; |
| 157 | virtual std::string Architecture() = 0; |
| 158 | virtual bool ArchitectureAll() = 0; |
| 159 | virtual std::string Version() = 0; |
| 160 | virtual bool NewVersion(pkgCache::VerIterator &Ver) = 0; |
| 161 | virtual std::string Description() = 0; |
| 162 | virtual std::string DescriptionLanguage() = 0; |
| 163 | virtual MD5SumValue Description_md5() = 0; |
| 164 | virtual unsigned short VersionHash() = 0; |
| 165 | virtual bool UsePackage(pkgCache::PkgIterator &Pkg, |
| 166 | pkgCache::VerIterator &Ver) = 0; |
| 167 | virtual unsigned long Offset() = 0; |
| 168 | virtual unsigned long Size() = 0; |
| 169 | |
| 170 | virtual bool Step() = 0; |
| 171 | |
| 172 | inline bool HasFileDeps() {return FoundFileDeps;}; |
| 173 | virtual bool CollectFileProvides(pkgCache &Cache, |
| 174 | pkgCache::VerIterator &Ver) {return true;}; |
| 175 | |
| 176 | ListParser() : FoundFileDeps(false) {}; |
| 177 | virtual ~ListParser() {}; |
| 178 | }; |
| 179 | /*}}}*/ |
| 180 | |
| 181 | bool pkgMakeStatusCache(pkgSourceList &List,OpProgress &Progress, |
| 182 | MMap **OutMap = 0,bool AllowMem = false); |
| 183 | bool pkgMakeOnlyStatusCache(OpProgress &Progress,DynamicMMap **OutMap); |
| 184 | |
| 185 | #endif |