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