]>
Commit | Line | Data |
---|---|---|
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 | #include <apt-pkg/md5.h> | |
23 | #include <apt-pkg/mmap.h> | |
24 | #include <apt-pkg/pkgcache.h> | |
25 | #include <apt-pkg/cacheiterators.h> | |
26 | #include <apt-pkg/macros.h> | |
27 | ||
28 | #include <vector> | |
29 | #include <string> | |
30 | ||
31 | class FileFd; | |
32 | class pkgSourceList; | |
33 | class OpProgress; | |
34 | class pkgIndexFile; | |
35 | ||
36 | class pkgCacheGenerator /*{{{*/ | |
37 | { | |
38 | private: | |
39 | ||
40 | pkgCache::StringItem *UniqHash[26]; | |
41 | APT_HIDDEN map_stringitem_t WriteStringInMap(std::string const &String) { return WriteStringInMap(String.c_str()); }; | |
42 | APT_HIDDEN map_stringitem_t WriteStringInMap(const char *String); | |
43 | APT_HIDDEN map_stringitem_t WriteStringInMap(const char *String, const unsigned long &Len); | |
44 | APT_HIDDEN map_pointer_t AllocateInMap(const unsigned long &size); | |
45 | ||
46 | public: | |
47 | ||
48 | class ListParser; | |
49 | friend class ListParser; | |
50 | ||
51 | template<typename Iter> class Dynamic { | |
52 | public: | |
53 | static std::vector<Iter*> toReMap; | |
54 | Dynamic(Iter &I) { | |
55 | toReMap.push_back(&I); | |
56 | } | |
57 | ||
58 | ~Dynamic() { | |
59 | toReMap.pop_back(); | |
60 | } | |
61 | }; | |
62 | ||
63 | protected: | |
64 | ||
65 | DynamicMMap ⤅ | |
66 | pkgCache Cache; | |
67 | OpProgress *Progress; | |
68 | ||
69 | std::string PkgFileName; | |
70 | pkgCache::PackageFile *CurrentFile; | |
71 | ||
72 | // Flag file dependencies | |
73 | bool FoundFileDeps; | |
74 | ||
75 | bool NewGroup(pkgCache::GrpIterator &Grp,const std::string &Name); | |
76 | bool NewPackage(pkgCache::PkgIterator &Pkg,const std::string &Name, const std::string &Arch); | |
77 | bool NewFileVer(pkgCache::VerIterator &Ver,ListParser &List); | |
78 | bool NewFileDesc(pkgCache::DescIterator &Desc,ListParser &List); | |
79 | bool NewDepends(pkgCache::PkgIterator &Pkg, pkgCache::VerIterator &Ver, | |
80 | std::string const &Version, unsigned int const &Op, | |
81 | unsigned int const &Type, map_pointer_t* &OldDepLast); | |
82 | bool NewDepends(pkgCache::PkgIterator &Pkg, pkgCache::VerIterator &Ver, | |
83 | map_pointer_t const Version, unsigned int const &Op, | |
84 | unsigned int const &Type, map_pointer_t* &OldDepLast); | |
85 | map_pointer_t NewVersion(pkgCache::VerIterator &Ver,const std::string &VerStr,map_pointer_t const Next) APT_DEPRECATED | |
86 | { return NewVersion(Ver, VerStr, 0, 0, Next); } | |
87 | map_pointer_t NewVersion(pkgCache::VerIterator &Ver,const std::string &VerStr, | |
88 | map_pointer_t const ParentPkg, unsigned short const Hash, | |
89 | map_pointer_t const Next); | |
90 | map_pointer_t NewDescription(pkgCache::DescIterator &Desc,const std::string &Lang,const MD5SumValue &md5sum,map_stringitem_t const idxmd5str); | |
91 | ||
92 | public: | |
93 | ||
94 | map_stringitem_t WriteUniqString(const char *S,unsigned int const Size); | |
95 | inline map_stringitem_t WriteUniqString(const std::string &S) {return WriteUniqString(S.c_str(),S.length());}; | |
96 | ||
97 | void DropProgress() {Progress = 0;}; | |
98 | bool SelectFile(const std::string &File,const std::string &Site,pkgIndexFile const &Index, | |
99 | unsigned long Flags = 0); | |
100 | bool MergeList(ListParser &List,pkgCache::VerIterator *Ver = 0); | |
101 | inline pkgCache &GetCache() {return Cache;}; | |
102 | inline pkgCache::PkgFileIterator GetCurFile() | |
103 | {return pkgCache::PkgFileIterator(Cache,CurrentFile);}; | |
104 | ||
105 | bool HasFileDeps() {return FoundFileDeps;}; | |
106 | bool MergeFileProvides(ListParser &List); | |
107 | bool FinishCache(OpProgress *Progress) APT_DEPRECATED APT_CONST; | |
108 | ||
109 | static bool MakeStatusCache(pkgSourceList &List,OpProgress *Progress, | |
110 | MMap **OutMap = 0,bool AllowMem = false); | |
111 | static bool MakeOnlyStatusCache(OpProgress *Progress,DynamicMMap **OutMap); | |
112 | static DynamicMMap* CreateDynamicMMap(FileFd *CacheF, unsigned long Flags = 0); | |
113 | ||
114 | void ReMap(void const * const oldMap, void const * const newMap); | |
115 | ||
116 | pkgCacheGenerator(DynamicMMap *Map,OpProgress *Progress); | |
117 | ~pkgCacheGenerator(); | |
118 | ||
119 | private: | |
120 | APT_HIDDEN bool MergeListGroup(ListParser &List, std::string const &GrpName); | |
121 | APT_HIDDEN bool MergeListPackage(ListParser &List, pkgCache::PkgIterator &Pkg); | |
122 | APT_HIDDEN bool MergeListVersion(ListParser &List, pkgCache::PkgIterator &Pkg, | |
123 | std::string const &Version, pkgCache::VerIterator* &OutVer); | |
124 | ||
125 | APT_HIDDEN bool AddImplicitDepends(pkgCache::GrpIterator &G, pkgCache::PkgIterator &P, | |
126 | pkgCache::VerIterator &V); | |
127 | APT_HIDDEN bool AddImplicitDepends(pkgCache::VerIterator &V, pkgCache::PkgIterator &D); | |
128 | ||
129 | APT_HIDDEN bool AddNewDescription(ListParser &List, pkgCache::VerIterator &Ver, | |
130 | std::string const &lang, MD5SumValue const &CurMd5, map_stringitem_t &md5idx); | |
131 | }; | |
132 | /*}}}*/ | |
133 | // This is the abstract package list parser class. /*{{{*/ | |
134 | class pkgCacheGenerator::ListParser | |
135 | { | |
136 | pkgCacheGenerator *Owner; | |
137 | friend class pkgCacheGenerator; | |
138 | ||
139 | // Some cache items | |
140 | pkgCache::VerIterator OldDepVer; | |
141 | map_pointer_t *OldDepLast; | |
142 | ||
143 | // Flag file dependencies | |
144 | bool FoundFileDeps; | |
145 | ||
146 | protected: | |
147 | ||
148 | inline map_stringitem_t WriteUniqString(std::string S) {return Owner->WriteUniqString(S);}; | |
149 | inline map_stringitem_t WriteUniqString(const char *S,unsigned int Size) {return Owner->WriteUniqString(S,Size);}; | |
150 | inline map_stringitem_t WriteString(const std::string &S) {return Owner->WriteStringInMap(S);}; | |
151 | inline map_stringitem_t WriteString(const char *S,unsigned int Size) {return Owner->WriteStringInMap(S,Size);}; | |
152 | bool NewDepends(pkgCache::VerIterator &Ver,const std::string &Package, const std::string &Arch, | |
153 | const std::string &Version,unsigned int Op, | |
154 | unsigned int Type); | |
155 | bool NewProvides(pkgCache::VerIterator &Ver,const std::string &PkgName, | |
156 | const std::string &PkgArch, const std::string &Version); | |
157 | ||
158 | public: | |
159 | ||
160 | // These all operate against the current section | |
161 | virtual std::string Package() = 0; | |
162 | virtual std::string Architecture() = 0; | |
163 | virtual bool ArchitectureAll() = 0; | |
164 | virtual std::string Version() = 0; | |
165 | virtual bool NewVersion(pkgCache::VerIterator &Ver) = 0; | |
166 | virtual std::string Description(std::string const &lang) = 0; | |
167 | virtual std::vector<std::string> AvailableDescriptionLanguages() = 0; | |
168 | virtual MD5SumValue Description_md5() = 0; | |
169 | virtual unsigned short VersionHash() = 0; | |
170 | /** compare currently parsed version with given version | |
171 | * | |
172 | * \param Hash of the currently parsed version | |
173 | * \param Ver to compare with | |
174 | */ | |
175 | #if (APT_PKG_MAJOR >= 4 && APT_PKG_MINOR >= 13) | |
176 | virtual | |
177 | #endif | |
178 | APT_PURE bool SameVersion(unsigned short const Hash, pkgCache::VerIterator const &Ver); | |
179 | virtual bool UsePackage(pkgCache::PkgIterator &Pkg, | |
180 | pkgCache::VerIterator &Ver) = 0; | |
181 | virtual map_filesize_t Offset() = 0; | |
182 | virtual map_filesize_t Size() = 0; | |
183 | ||
184 | virtual bool Step() = 0; | |
185 | ||
186 | inline bool HasFileDeps() {return FoundFileDeps;}; | |
187 | virtual bool CollectFileProvides(pkgCache &/*Cache*/, | |
188 | pkgCache::VerIterator &/*Ver*/) {return true;}; | |
189 | ||
190 | ListParser() : FoundFileDeps(false) {}; | |
191 | virtual ~ListParser() {}; | |
192 | }; | |
193 | /*}}}*/ | |
194 | ||
195 | bool pkgMakeStatusCache(pkgSourceList &List,OpProgress &Progress, | |
196 | MMap **OutMap = 0,bool AllowMem = false); | |
197 | bool pkgMakeOnlyStatusCache(OpProgress &Progress,DynamicMMap **OutMap); | |
198 | ||
199 | #endif |