]>
Commit | Line | Data |
---|---|---|
578bfd0a AL |
1 | // -*- mode: cpp; mode: fold -*- |
2 | // Description /*{{{*/ | |
6a3da7a6 | 3 | // $Id: pkgcache.h,v 1.25 2001/07/01 22:28:24 jgg Exp $ |
578bfd0a AL |
4 | /* ###################################################################### |
5 | ||
6 | Cache - Structure definitions for the cache file | |
7 | ||
094a497d | 8 | Please see doc/apt-pkg/cache.sgml for a more detailed description of |
578bfd0a AL |
9 | this format. Also be sure to keep that file up-to-date!! |
10 | ||
11 | Clients should always use the CacheIterators classes for access to the | |
12 | cache. They provide a simple STL-like method for traversing the links | |
13 | of the datastructure. | |
14 | ||
15 | See pkgcachegen.h for information about generating cache structures. | |
16 | ||
17 | ##################################################################### */ | |
18 | /*}}}*/ | |
578bfd0a AL |
19 | #ifndef PKGLIB_PKGCACHE_H |
20 | #define PKGLIB_PKGCACHE_H | |
21 | ||
6c139d6e | 22 | |
578bfd0a AL |
23 | #include <string> |
24 | #include <time.h> | |
094a497d | 25 | #include <apt-pkg/mmap.h> |
0a843901 AL |
26 | |
27 | using std::string; | |
b2e465d6 AL |
28 | |
29 | class pkgVersioningSystem; | |
92fcbfc1 | 30 | class pkgCache /*{{{*/ |
578bfd0a AL |
31 | { |
32 | public: | |
33 | // Cache element predeclarations | |
34 | struct Header; | |
35 | struct Package; | |
36 | struct PackageFile; | |
37 | struct Version; | |
a52f938b | 38 | struct Description; |
578bfd0a AL |
39 | struct Provides; |
40 | struct Dependency; | |
41 | struct StringItem; | |
dcb79bae | 42 | struct VerFile; |
a52f938b | 43 | struct DescFile; |
578bfd0a AL |
44 | |
45 | // Iterators | |
46 | class PkgIterator; | |
47 | class VerIterator; | |
a52f938b | 48 | class DescIterator; |
578bfd0a AL |
49 | class DepIterator; |
50 | class PrvIterator; | |
51 | class PkgFileIterator; | |
dcb79bae | 52 | class VerFileIterator; |
a52f938b | 53 | class DescFileIterator; |
b2e465d6 AL |
54 | friend class PkgIterator; |
55 | friend class VerIterator; | |
a52f938b | 56 | friend class DescInterator; |
b2e465d6 AL |
57 | friend class DepIterator; |
58 | friend class PrvIterator; | |
59 | friend class PkgFileIterator; | |
60 | friend class VerFileIterator; | |
a52f938b | 61 | friend class DescFileIterator; |
b2e465d6 AL |
62 | |
63 | class Namespace; | |
dcb79bae | 64 | |
f55a958f | 65 | // These are all the constants used in the cache structures |
308c7d30 IJ |
66 | |
67 | // WARNING - if you change these lists you must also edit | |
68 | // the stringification in pkgcache.cc and also consider whether | |
69 | // the cache file will become incompatible. | |
6c139d6e AL |
70 | struct Dep |
71 | { | |
72 | enum DepType {Depends=1,PreDepends=2,Suggests=3,Recommends=4, | |
f8ae7e8b | 73 | Conflicts=5,Replaces=6,Obsoletes=7,DpkgBreaks=8,Enhances=9}; |
6c139d6e AL |
74 | enum DepCompareOp {Or=0x10,NoOp=0,LessEq=0x1,GreaterEq=0x2,Less=0x3, |
75 | Greater=0x4,Equals=0x5,NotEquals=0x6}; | |
76 | }; | |
77 | ||
78 | struct State | |
79 | { | |
fbfb2a7c | 80 | enum VerPriority {Important=1,Required=2,Standard=3,Optional=4,Extra=5}; |
6c139d6e AL |
81 | enum PkgSelectedState {Unknown=0,Install=1,Hold=2,DeInstall=3,Purge=4}; |
82 | enum PkgInstState {Ok=0,ReInstReq=1,HoldInst=2,HoldReInstReq=3}; | |
83 | enum PkgCurrentState {NotInstalled=0,UnPacked=1,HalfConfigured=2, | |
9d06bc80 MV |
84 | HalfInstalled=4,ConfigFiles=5,Installed=6, |
85 | TriggersAwaited=7,TriggersPending=8}; | |
6c139d6e AL |
86 | }; |
87 | ||
88 | struct Flag | |
89 | { | |
138d4b3d | 90 | enum PkgFlags {Auto=(1<<0),Essential=(1<<3),Important=(1<<4)}; |
3c124dde | 91 | enum PkgFFlags {NotSource=(1<<0),NotAutomatic=(1<<1)}; |
6c139d6e | 92 | }; |
578bfd0a AL |
93 | |
94 | protected: | |
95 | ||
96 | // Memory mapped cache file | |
97 | string CacheFile; | |
98 | MMap ⤅ | |
99 | ||
171c75f1 | 100 | unsigned long sHash(const string &S) const; |
f9eec0e7 | 101 | unsigned long sHash(const char *S) const; |
578bfd0a AL |
102 | |
103 | public: | |
104 | ||
105 | // Pointers to the arrays of items | |
106 | Header *HeaderP; | |
107 | Package *PkgP; | |
dcb79bae | 108 | VerFile *VerFileP; |
a52f938b | 109 | DescFile *DescFileP; |
578bfd0a AL |
110 | PackageFile *PkgFileP; |
111 | Version *VerP; | |
a52f938b | 112 | Description *DescP; |
578bfd0a AL |
113 | Provides *ProvideP; |
114 | Dependency *DepP; | |
115 | StringItem *StringItemP; | |
116 | char *StrP; | |
dcb79bae | 117 | |
578bfd0a AL |
118 | virtual bool ReMap(); |
119 | inline bool Sync() {return Map.Sync();}; | |
981d20eb | 120 | inline MMap &GetMap() {return Map;}; |
b2e465d6 AL |
121 | inline void *DataEnd() {return ((unsigned char *)Map.Data()) + Map.Size();}; |
122 | ||
578bfd0a | 123 | // String hashing function (512 range) |
171c75f1 | 124 | inline unsigned long Hash(const string &S) const {return sHash(S);}; |
578bfd0a AL |
125 | inline unsigned long Hash(const char *S) const {return sHash(S);}; |
126 | ||
0149949b AL |
127 | // Usefull transformation things |
128 | const char *Priority(unsigned char Priority); | |
129 | ||
578bfd0a | 130 | // Accessors |
171c75f1 | 131 | PkgIterator FindPkg(const string &Name); |
578bfd0a AL |
132 | Header &Head() {return *HeaderP;}; |
133 | inline PkgIterator PkgBegin(); | |
134 | inline PkgIterator PkgEnd(); | |
ad00ae81 AL |
135 | inline PkgFileIterator FileBegin(); |
136 | inline PkgFileIterator FileEnd(); | |
b2e465d6 AL |
137 | |
138 | // Make me a function | |
139 | pkgVersioningSystem *VS; | |
140 | ||
141 | // Converters | |
142 | static const char *CompTypeDeb(unsigned char Comp); | |
143 | static const char *CompType(unsigned char Comp); | |
144 | static const char *DepType(unsigned char Dep); | |
ad00ae81 | 145 | |
b2e465d6 | 146 | pkgCache(MMap *Map,bool DoMap = true); |
578bfd0a AL |
147 | virtual ~pkgCache() {}; |
148 | }; | |
92fcbfc1 DK |
149 | /*}}}*/ |
150 | // Header structure /*{{{*/ | |
578bfd0a AL |
151 | struct pkgCache::Header |
152 | { | |
153 | // Signature information | |
154 | unsigned long Signature; | |
155 | short MajorVersion; | |
156 | short MinorVersion; | |
157 | bool Dirty; | |
158 | ||
159 | // Size of structure values | |
160 | unsigned short HeaderSz; | |
161 | unsigned short PackageSz; | |
162 | unsigned short PackageFileSz; | |
163 | unsigned short VersionSz; | |
a52f938b | 164 | unsigned short DescriptionSz; |
578bfd0a AL |
165 | unsigned short DependencySz; |
166 | unsigned short ProvidesSz; | |
dcb79bae | 167 | unsigned short VerFileSz; |
a52f938b | 168 | unsigned short DescFileSz; |
dcb79bae | 169 | |
578bfd0a AL |
170 | // Structure counts |
171 | unsigned long PackageCount; | |
172 | unsigned long VersionCount; | |
a52f938b | 173 | unsigned long DescriptionCount; |
578bfd0a AL |
174 | unsigned long DependsCount; |
175 | unsigned long PackageFileCount; | |
a7e66b17 | 176 | unsigned long VerFileCount; |
a52f938b | 177 | unsigned long DescFileCount; |
a7e66b17 | 178 | unsigned long ProvidesCount; |
578bfd0a AL |
179 | |
180 | // Offsets | |
349cd3b8 AL |
181 | map_ptrloc FileList; // struct PackageFile |
182 | map_ptrloc StringList; // struct StringItem | |
b2e465d6 AL |
183 | map_ptrloc VerSysName; // StringTable |
184 | map_ptrloc Architecture; // StringTable | |
ad00ae81 | 185 | unsigned long MaxVerFileSize; |
a52f938b | 186 | unsigned long MaxDescFileSize; |
578bfd0a AL |
187 | |
188 | /* Allocation pools, there should be one of these for each structure | |
189 | excluding the header */ | |
a52f938b | 190 | DynamicMMap::Pool Pools[8]; |
578bfd0a AL |
191 | |
192 | // Rapid package name lookup | |
349cd3b8 | 193 | map_ptrloc HashTable[2*1048]; |
578bfd0a AL |
194 | |
195 | bool CheckSizes(Header &Against) const; | |
196 | Header(); | |
197 | }; | |
92fcbfc1 DK |
198 | /*}}}*/ |
199 | struct pkgCache::Package /*{{{*/ | |
578bfd0a AL |
200 | { |
201 | // Pointers | |
349cd3b8 AL |
202 | map_ptrloc Name; // Stringtable |
203 | map_ptrloc VersionList; // Version | |
349cd3b8 | 204 | map_ptrloc CurrentVer; // Version |
349cd3b8 | 205 | map_ptrloc Section; // StringTable (StringItem) |
578bfd0a AL |
206 | |
207 | // Linked list | |
349cd3b8 AL |
208 | map_ptrloc NextPackage; // Package |
209 | map_ptrloc RevDepends; // Dependency | |
210 | map_ptrloc ProvidesList; // Provides | |
a52f938b | 211 | |
578bfd0a AL |
212 | // Install/Remove/Purge etc |
213 | unsigned char SelectedState; // What | |
214 | unsigned char InstState; // Flags | |
215 | unsigned char CurrentState; // State | |
216 | ||
09fab244 | 217 | unsigned int ID; |
f55a958f | 218 | unsigned long Flags; |
578bfd0a | 219 | }; |
92fcbfc1 DK |
220 | /*}}}*/ |
221 | struct pkgCache::PackageFile /*{{{*/ | |
578bfd0a AL |
222 | { |
223 | // Names | |
349cd3b8 AL |
224 | map_ptrloc FileName; // Stringtable |
225 | map_ptrloc Archive; // Stringtable | |
efc487fb | 226 | map_ptrloc Codename; // Stringtable |
349cd3b8 AL |
227 | map_ptrloc Component; // Stringtable |
228 | map_ptrloc Version; // Stringtable | |
229 | map_ptrloc Origin; // Stringtable | |
230 | map_ptrloc Label; // Stringtable | |
231 | map_ptrloc Architecture; // Stringtable | |
b2e465d6 AL |
232 | map_ptrloc Site; // Stringtable |
233 | map_ptrloc IndexType; // Stringtable | |
b0b4efb9 | 234 | unsigned long Size; |
3c124dde | 235 | unsigned long Flags; |
578bfd0a AL |
236 | |
237 | // Linked list | |
349cd3b8 | 238 | map_ptrloc NextFile; // PackageFile |
09fab244 | 239 | unsigned int ID; |
578bfd0a AL |
240 | time_t mtime; // Modification time for the file |
241 | }; | |
92fcbfc1 DK |
242 | /*}}}*/ |
243 | struct pkgCache::VerFile /*{{{*/ | |
dcb79bae | 244 | { |
349cd3b8 AL |
245 | map_ptrloc File; // PackageFile |
246 | map_ptrloc NextFile; // PkgVerFile | |
247 | map_ptrloc Offset; // File offset | |
6d3176fb | 248 | unsigned long Size; |
dcb79bae | 249 | }; |
92fcbfc1 DK |
250 | /*}}}*/ |
251 | struct pkgCache::DescFile /*{{{*/ | |
a52f938b OS |
252 | { |
253 | map_ptrloc File; // PackageFile | |
254 | map_ptrloc NextFile; // PkgVerFile | |
255 | map_ptrloc Offset; // File offset | |
6d3176fb | 256 | unsigned long Size; |
a52f938b | 257 | }; |
92fcbfc1 DK |
258 | /*}}}*/ |
259 | struct pkgCache::Version /*{{{*/ | |
578bfd0a | 260 | { |
349cd3b8 AL |
261 | map_ptrloc VerStr; // Stringtable |
262 | map_ptrloc Section; // StringTable (StringItem) | |
263 | map_ptrloc Arch; // StringTable | |
17caf1b1 | 264 | |
578bfd0a | 265 | // Lists |
349cd3b8 AL |
266 | map_ptrloc FileList; // VerFile |
267 | map_ptrloc NextVer; // Version | |
a52f938b | 268 | map_ptrloc DescriptionList; // Description |
349cd3b8 AL |
269 | map_ptrloc DependsList; // Dependency |
270 | map_ptrloc ParentPkg; // Package | |
271 | map_ptrloc ProvidesList; // Provides | |
578bfd0a | 272 | |
349cd3b8 AL |
273 | map_ptrloc Size; // These are the .deb size |
274 | map_ptrloc InstalledSize; | |
204fbdcc | 275 | unsigned short Hash; |
09fab244 | 276 | unsigned int ID; |
578bfd0a AL |
277 | unsigned char Priority; |
278 | }; | |
92fcbfc1 DK |
279 | /*}}}*/ |
280 | struct pkgCache::Description /*{{{*/ | |
a52f938b OS |
281 | { |
282 | // Language Code store the description translation language code. If | |
283 | // the value has a 0 lenght then this is readed using the Package | |
284 | // file else the Translation-CODE are used. | |
285 | map_ptrloc language_code; // StringTable | |
286 | map_ptrloc md5sum; // StringTable | |
287 | ||
288 | // Linked list | |
289 | map_ptrloc FileList; // DescFile | |
290 | map_ptrloc NextDesc; // Description | |
291 | map_ptrloc ParentPkg; // Package | |
292 | ||
09fab244 | 293 | unsigned int ID; |
a52f938b | 294 | }; |
92fcbfc1 DK |
295 | /*}}}*/ |
296 | struct pkgCache::Dependency /*{{{*/ | |
578bfd0a | 297 | { |
349cd3b8 AL |
298 | map_ptrloc Version; // Stringtable |
299 | map_ptrloc Package; // Package | |
300 | map_ptrloc NextDepends; // Dependency | |
301 | map_ptrloc NextRevDepends; // Dependency | |
302 | map_ptrloc ParentVer; // Version | |
578bfd0a AL |
303 | |
304 | // Specific types of depends | |
6a3da7a6 | 305 | map_ptrloc ID; |
578bfd0a AL |
306 | unsigned char Type; |
307 | unsigned char CompareOp; | |
578bfd0a | 308 | }; |
92fcbfc1 DK |
309 | /*}}}*/ |
310 | struct pkgCache::Provides /*{{{*/ | |
578bfd0a | 311 | { |
349cd3b8 AL |
312 | map_ptrloc ParentPkg; // Pacakge |
313 | map_ptrloc Version; // Version | |
314 | map_ptrloc ProvideVersion; // Stringtable | |
315 | map_ptrloc NextProvides; // Provides | |
316 | map_ptrloc NextPkgProv; // Provides | |
578bfd0a | 317 | }; |
92fcbfc1 DK |
318 | /*}}}*/ |
319 | struct pkgCache::StringItem /*{{{*/ | |
578bfd0a | 320 | { |
349cd3b8 AL |
321 | map_ptrloc String; // Stringtable |
322 | map_ptrloc NextItem; // StringItem | |
578bfd0a | 323 | }; |
92fcbfc1 | 324 | /*}}}*/ |
094a497d | 325 | #include <apt-pkg/cacheiterators.h> |
578bfd0a AL |
326 | |
327 | inline pkgCache::PkgIterator pkgCache::PkgBegin() | |
328 | {return PkgIterator(*this);}; | |
329 | inline pkgCache::PkgIterator pkgCache::PkgEnd() | |
330 | {return PkgIterator(*this,PkgP);}; | |
ad00ae81 | 331 | inline pkgCache::PkgFileIterator pkgCache::FileBegin() |
b2e465d6 | 332 | {return PkgFileIterator(*this,PkgFileP + HeaderP->FileList);}; |
ad00ae81 AL |
333 | inline pkgCache::PkgFileIterator pkgCache::FileEnd() |
334 | {return PkgFileIterator(*this,PkgFileP);}; | |
578bfd0a | 335 | |
b2e465d6 | 336 | // Oh I wish for Real Name Space Support |
92fcbfc1 | 337 | class pkgCache::Namespace /*{{{*/ |
b2e465d6 AL |
338 | { |
339 | public: | |
340 | ||
341 | typedef pkgCache::PkgIterator PkgIterator; | |
342 | typedef pkgCache::VerIterator VerIterator; | |
a52f938b | 343 | typedef pkgCache::DescIterator DescIterator; |
b2e465d6 AL |
344 | typedef pkgCache::DepIterator DepIterator; |
345 | typedef pkgCache::PrvIterator PrvIterator; | |
346 | typedef pkgCache::PkgFileIterator PkgFileIterator; | |
347 | typedef pkgCache::VerFileIterator VerFileIterator; | |
348 | typedef pkgCache::Version Version; | |
a52f938b | 349 | typedef pkgCache::Description Description; |
b2e465d6 AL |
350 | typedef pkgCache::Package Package; |
351 | typedef pkgCache::Header Header; | |
352 | typedef pkgCache::Dep Dep; | |
353 | typedef pkgCache::Flag Flag; | |
354 | }; | |
92fcbfc1 | 355 | /*}}}*/ |
578bfd0a | 356 | #endif |