]>
Commit | Line | Data |
---|---|---|
578bfd0a AL |
1 | // -*- mode: cpp; mode: fold -*- |
2 | // Description /*{{{*/ | |
45415543 | 3 | // $Id: pkgcachegen.h,v 1.19 2002/07/08 03:13:30 jgg Exp $ |
578bfd0a AL |
4 | /* ###################################################################### |
5 | ||
6 | Package Cache Generator - Generator for the cache structure. | |
7 | ||
8 | This builds the cache structure from the abstract package list parser. | |
6fc33863 AL |
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 | |
578bfd0a AL |
16 | |
17 | ##################################################################### */ | |
18 | /*}}}*/ | |
578bfd0a AL |
19 | #ifndef PKGLIB_PKGCACHEGEN_H |
20 | #define PKGLIB_PKGCACHEGEN_H | |
21 | ||
a52f938b | 22 | #include <apt-pkg/md5.h> |
453b82a3 DK |
23 | #include <apt-pkg/mmap.h> |
24 | #include <apt-pkg/pkgcache.h> | |
25 | #include <apt-pkg/cacheiterators.h> | |
5a8e963b | 26 | #include <apt-pkg/macros.h> |
b35d2f5f | 27 | |
7635093c | 28 | #include <vector> |
453b82a3 | 29 | #include <string> |
78a5476f | 30 | #include <map> |
a9fe5928 | 31 | |
453b82a3 | 32 | class FileFd; |
b35d2f5f AL |
33 | class pkgSourceList; |
34 | class OpProgress; | |
b2e465d6 | 35 | class pkgIndexFile; |
578bfd0a | 36 | |
92fcbfc1 | 37 | class pkgCacheGenerator /*{{{*/ |
578bfd0a | 38 | { |
f9eec0e7 | 39 | private: |
4ad8619b DK |
40 | APT_HIDDEN map_stringitem_t WriteStringInMap(std::string const &String) { return WriteStringInMap(String.c_str()); }; |
41 | APT_HIDDEN map_stringitem_t WriteStringInMap(const char *String); | |
42 | APT_HIDDEN map_stringitem_t WriteStringInMap(const char *String, const unsigned long &Len); | |
43 | APT_HIDDEN map_pointer_t AllocateInMap(const unsigned long &size); | |
7e58ab0c | 44 | |
78a5476f DK |
45 | std::map<std::string,map_stringitem_t> strMixed; |
46 | std::map<std::string,map_stringitem_t> strSections; | |
47 | std::map<std::string,map_stringitem_t> strPkgNames; | |
48 | std::map<std::string,map_stringitem_t> strVersions; | |
49 | ||
578bfd0a AL |
50 | public: |
51 | ||
52 | class ListParser; | |
b2e465d6 | 53 | friend class ListParser; |
a9fe5928 DK |
54 | |
55 | template<typename Iter> class Dynamic { | |
a9fe5928 | 56 | public: |
7635093c DK |
57 | static std::vector<Iter*> toReMap; |
58 | Dynamic(Iter &I) { | |
59 | toReMap.push_back(&I); | |
a9fe5928 DK |
60 | } |
61 | ||
62 | ~Dynamic() { | |
7635093c | 63 | toReMap.pop_back(); |
a9fe5928 DK |
64 | } |
65 | }; | |
66 | ||
578bfd0a | 67 | protected: |
a9fe5928 | 68 | |
578bfd0a AL |
69 | DynamicMMap ⤅ |
70 | pkgCache Cache; | |
ddc1d8d0 | 71 | OpProgress *Progress; |
404ec98e | 72 | |
8f3ba4e8 | 73 | std::string PkgFileName; |
578bfd0a | 74 | pkgCache::PackageFile *CurrentFile; |
45415543 AL |
75 | |
76 | // Flag file dependencies | |
77 | bool FoundFileDeps; | |
578bfd0a | 78 | |
8f3ba4e8 DK |
79 | bool NewGroup(pkgCache::GrpIterator &Grp,const std::string &Name); |
80 | bool NewPackage(pkgCache::PkgIterator &Pkg,const std::string &Name, const std::string &Arch); | |
f55a958f | 81 | bool NewFileVer(pkgCache::VerIterator &Ver,ListParser &List); |
a52f938b | 82 | bool NewFileDesc(pkgCache::DescIterator &Desc,ListParser &List); |
25396fb0 | 83 | bool NewDepends(pkgCache::PkgIterator &Pkg, pkgCache::VerIterator &Ver, |
8f3ba4e8 | 84 | std::string const &Version, unsigned int const &Op, |
4ad8619b | 85 | unsigned int const &Type, map_pointer_t* &OldDepLast); |
9c44383f | 86 | bool NewDepends(pkgCache::PkgIterator &Pkg, pkgCache::VerIterator &Ver, |
4ad8619b DK |
87 | map_pointer_t const Version, unsigned int const &Op, |
88 | unsigned int const &Type, map_pointer_t* &OldDepLast); | |
89 | map_pointer_t NewVersion(pkgCache::VerIterator &Ver,const std::string &VerStr,map_pointer_t const Next) APT_DEPRECATED | |
885594fc | 90 | { return NewVersion(Ver, VerStr, 0, 0, Next); } |
4ad8619b DK |
91 | map_pointer_t NewVersion(pkgCache::VerIterator &Ver,const std::string &VerStr, |
92 | map_pointer_t const ParentPkg, unsigned short const Hash, | |
93 | map_pointer_t const Next); | |
94 | map_pointer_t NewDescription(pkgCache::DescIterator &Desc,const std::string &Lang,const MD5SumValue &md5sum,map_stringitem_t const idxmd5str); | |
578bfd0a | 95 | |
b2e465d6 AL |
96 | public: |
97 | ||
78a5476f DK |
98 | enum StringType { MIXED, PKGNAME, VERSION, SECTION }; |
99 | map_stringitem_t StoreString(enum StringType const type, const char * S, unsigned int const Size); | |
100 | inline map_stringitem_t StoreString(enum StringType const type, const std::string &S) {return StoreString(type, S.c_str(),S.length());}; | |
813c8eea | 101 | |
ddc1d8d0 | 102 | void DropProgress() {Progress = 0;}; |
8f3ba4e8 | 103 | bool SelectFile(const std::string &File,const std::string &Site,pkgIndexFile const &Index, |
b2e465d6 | 104 | unsigned long Flags = 0); |
ddc1d8d0 | 105 | bool MergeList(ListParser &List,pkgCache::VerIterator *Ver = 0); |
ad00ae81 | 106 | inline pkgCache &GetCache() {return Cache;}; |
b0b4efb9 AL |
107 | inline pkgCache::PkgFileIterator GetCurFile() |
108 | {return pkgCache::PkgFileIterator(Cache,CurrentFile);}; | |
45415543 AL |
109 | |
110 | bool HasFileDeps() {return FoundFileDeps;}; | |
111 | bool MergeFileProvides(ListParser &List); | |
a02db58f | 112 | bool FinishCache(OpProgress *Progress) APT_DEPRECATED APT_CONST; |
2e5f4e45 DK |
113 | |
114 | static bool MakeStatusCache(pkgSourceList &List,OpProgress *Progress, | |
115 | MMap **OutMap = 0,bool AllowMem = false); | |
116 | static bool MakeOnlyStatusCache(OpProgress *Progress,DynamicMMap **OutMap); | |
dcdf1ef1 | 117 | static DynamicMMap* CreateDynamicMMap(FileFd *CacheF, unsigned long Flags = 0); |
25396fb0 | 118 | |
a9fe5928 DK |
119 | void ReMap(void const * const oldMap, void const * const newMap); |
120 | ||
b2e465d6 | 121 | pkgCacheGenerator(DynamicMMap *Map,OpProgress *Progress); |
578bfd0a | 122 | ~pkgCacheGenerator(); |
99a2ea5a DK |
123 | |
124 | private: | |
ce62f1de DK |
125 | APT_HIDDEN bool MergeListGroup(ListParser &List, std::string const &GrpName); |
126 | APT_HIDDEN bool MergeListPackage(ListParser &List, pkgCache::PkgIterator &Pkg); | |
127 | APT_HIDDEN bool MergeListVersion(ListParser &List, pkgCache::PkgIterator &Pkg, | |
99a2ea5a | 128 | std::string const &Version, pkgCache::VerIterator* &OutVer); |
5a8e963b | 129 | |
ce62f1de | 130 | APT_HIDDEN bool AddImplicitDepends(pkgCache::GrpIterator &G, pkgCache::PkgIterator &P, |
5a8e963b | 131 | pkgCache::VerIterator &V); |
ce62f1de | 132 | APT_HIDDEN bool AddImplicitDepends(pkgCache::VerIterator &V, pkgCache::PkgIterator &D); |
ffe3c68e DK |
133 | |
134 | APT_HIDDEN bool AddNewDescription(ListParser &List, pkgCache::VerIterator &Ver, | |
4ad8619b | 135 | std::string const &lang, MD5SumValue const &CurMd5, map_stringitem_t &md5idx); |
578bfd0a | 136 | }; |
92fcbfc1 DK |
137 | /*}}}*/ |
138 | // This is the abstract package list parser class. /*{{{*/ | |
f55ece0e AL |
139 | class pkgCacheGenerator::ListParser |
140 | { | |
141 | pkgCacheGenerator *Owner; | |
b2e465d6 | 142 | friend class pkgCacheGenerator; |
f55ece0e | 143 | |
f9eec0e7 AL |
144 | // Some cache items |
145 | pkgCache::VerIterator OldDepVer; | |
4ad8619b | 146 | map_pointer_t *OldDepLast; |
45415543 AL |
147 | |
148 | // Flag file dependencies | |
149 | bool FoundFileDeps; | |
f9eec0e7 | 150 | |
f55ece0e | 151 | protected: |
813c8eea | 152 | |
78a5476f DK |
153 | inline map_stringitem_t StoreString(pkgCacheGenerator::StringType const type, std::string const &S) {return Owner->StoreString(type, S);}; |
154 | inline map_stringitem_t StoreString(pkgCacheGenerator::StringType const type, const char *S,unsigned int Size) {return Owner->StoreString(type, S, Size);}; | |
155 | ||
4ad8619b DK |
156 | inline map_stringitem_t WriteString(const std::string &S) {return Owner->WriteStringInMap(S);}; |
157 | inline map_stringitem_t WriteString(const char *S,unsigned int Size) {return Owner->WriteStringInMap(S,Size);}; | |
8f3ba4e8 DK |
158 | bool NewDepends(pkgCache::VerIterator &Ver,const std::string &Package, const std::string &Arch, |
159 | const std::string &Version,unsigned int Op, | |
f55ece0e | 160 | unsigned int Type); |
8f3ba4e8 DK |
161 | bool NewProvides(pkgCache::VerIterator &Ver,const std::string &PkgName, |
162 | const std::string &PkgArch, const std::string &Version); | |
f55ece0e AL |
163 | |
164 | public: | |
165 | ||
166 | // These all operate against the current section | |
8f3ba4e8 DK |
167 | virtual std::string Package() = 0; |
168 | virtual std::string Architecture() = 0; | |
857e9c13 | 169 | virtual bool ArchitectureAll() = 0; |
8f3ba4e8 | 170 | virtual std::string Version() = 0; |
32b9a14c | 171 | virtual bool NewVersion(pkgCache::VerIterator &Ver) = 0; |
ffe3c68e DK |
172 | virtual std::string Description(std::string const &lang) = 0; |
173 | virtual std::vector<std::string> AvailableDescriptionLanguages() = 0; | |
a52f938b | 174 | virtual MD5SumValue Description_md5() = 0; |
204fbdcc | 175 | virtual unsigned short VersionHash() = 0; |
68134bda DK |
176 | /** compare currently parsed version with given version |
177 | * | |
178 | * \param Hash of the currently parsed version | |
179 | * \param Ver to compare with | |
180 | */ | |
181 | #if (APT_PKG_MAJOR >= 4 && APT_PKG_MINOR >= 13) | |
182 | virtual | |
183 | #endif | |
184 | APT_PURE bool SameVersion(unsigned short const Hash, pkgCache::VerIterator const &Ver); | |
32b9a14c DK |
185 | virtual bool UsePackage(pkgCache::PkgIterator &Pkg, |
186 | pkgCache::VerIterator &Ver) = 0; | |
4ad8619b DK |
187 | virtual map_filesize_t Offset() = 0; |
188 | virtual map_filesize_t Size() = 0; | |
f55ece0e AL |
189 | |
190 | virtual bool Step() = 0; | |
191 | ||
45415543 | 192 | inline bool HasFileDeps() {return FoundFileDeps;}; |
65512241 DK |
193 | virtual bool CollectFileProvides(pkgCache &/*Cache*/, |
194 | pkgCache::VerIterator &/*Ver*/) {return true;}; | |
45415543 | 195 | |
25613a61 | 196 | ListParser() : Owner(NULL), OldDepLast(NULL), FoundFileDeps(false) {}; |
f55ece0e AL |
197 | virtual ~ListParser() {}; |
198 | }; | |
92fcbfc1 | 199 | /*}}}*/ |
2e5f4e45 | 200 | |
b2e465d6 AL |
201 | bool pkgMakeStatusCache(pkgSourceList &List,OpProgress &Progress, |
202 | MMap **OutMap = 0,bool AllowMem = false); | |
203 | bool pkgMakeOnlyStatusCache(OpProgress &Progress,DynamicMMap **OutMap); | |
204 | ||
578bfd0a | 205 | #endif |