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