]>
Commit | Line | Data |
---|---|---|
acdafb44 JF |
1 | // -*- mode: cpp; mode: fold -*- |
2 | // Description /*{{{*/ | |
3 | // $Id: pkgcache.h,v 1.25 2001/07/01 22:28:24 jgg Exp $ | |
4 | /* ###################################################################### | |
5 | ||
6 | Cache - Structure definitions for the cache file | |
7 | ||
8 | Please see doc/apt-pkg/cache.sgml for a more detailed description of | |
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 | /*}}}*/ | |
19 | #ifndef PKGLIB_PKGCACHE_H | |
20 | #define PKGLIB_PKGCACHE_H | |
21 | ||
22 | ||
23 | #include <string> | |
24 | #include <time.h> | |
25 | #include <apt-pkg/mmap.h> | |
26 | ||
27 | using std::string; | |
28 | ||
29 | class pkgVersioningSystem; | |
0e5943eb | 30 | class pkgCache /*{{{*/ |
acdafb44 JF |
31 | { |
32 | public: | |
33 | // Cache element predeclarations | |
34 | struct Header; | |
35 | struct Package; | |
36 | struct PackageFile; | |
37 | struct Version; | |
38 | struct Description; | |
39 | struct Provides; | |
40 | struct Dependency; | |
41 | struct StringItem; | |
42 | struct VerFile; | |
43 | struct DescFile; | |
44 | ||
45 | // Iterators | |
46 | class PkgIterator; | |
47 | class VerIterator; | |
48 | class DescIterator; | |
49 | class DepIterator; | |
50 | class PrvIterator; | |
51 | class PkgFileIterator; | |
52 | class VerFileIterator; | |
53 | class DescFileIterator; | |
54 | friend class PkgIterator; | |
55 | friend class VerIterator; | |
56 | friend class DescInterator; | |
57 | friend class DepIterator; | |
58 | friend class PrvIterator; | |
59 | friend class PkgFileIterator; | |
60 | friend class VerFileIterator; | |
61 | friend class DescFileIterator; | |
62 | ||
63 | class Namespace; | |
64 | ||
65 | // These are all the constants used in the cache structures | |
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. | |
70 | struct Dep | |
71 | { | |
72 | enum DepType {Depends=1,PreDepends=2,Suggests=3,Recommends=4, | |
0e5943eb | 73 | Conflicts=5,Replaces=6,Obsoletes=7,DpkgBreaks=8,Enhances=9}; |
acdafb44 JF |
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 | { | |
80 | enum VerPriority {Important=1,Required=2,Standard=3,Optional=4,Extra=5}; | |
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, | |
84 | HalfInstalled=4,ConfigFiles=5,Installed=6, | |
85 | TriggersAwaited=7,TriggersPending=8}; | |
86 | }; | |
87 | ||
88 | struct Flag | |
89 | { | |
90 | enum PkgFlags {Auto=(1<<0),Essential=(1<<3),Important=(1<<4)}; | |
91 | enum PkgFFlags {NotSource=(1<<0),NotAutomatic=(1<<1)}; | |
92 | }; | |
93 | ||
94 | protected: | |
95 | ||
96 | // Memory mapped cache file | |
97 | string CacheFile; | |
98 | MMap ⤅ | |
99 | ||
100 | unsigned long sHash(const string &S) const; | |
101 | unsigned long sHash(const char *S) const; | |
102 | ||
103 | public: | |
104 | ||
105 | // Pointers to the arrays of items | |
106 | Header *HeaderP; | |
107 | Package *PkgP; | |
108 | VerFile *VerFileP; | |
109 | DescFile *DescFileP; | |
110 | PackageFile *PkgFileP; | |
111 | Version *VerP; | |
112 | Description *DescP; | |
113 | Provides *ProvideP; | |
114 | Dependency *DepP; | |
115 | StringItem *StringItemP; | |
116 | char *StrP; | |
117 | ||
118 | virtual bool ReMap(); | |
119 | inline bool Sync() {return Map.Sync();}; | |
120 | inline MMap &GetMap() {return Map;}; | |
121 | inline void *DataEnd() {return ((unsigned char *)Map.Data()) + Map.Size();}; | |
122 | ||
123 | // String hashing function (512 range) | |
124 | inline unsigned long Hash(const string &S) const {return sHash(S);}; | |
125 | inline unsigned long Hash(const char *S) const {return sHash(S);}; | |
126 | ||
127 | // Usefull transformation things | |
128 | const char *Priority(unsigned char Priority); | |
129 | ||
130 | // Accessors | |
131 | PkgIterator FindPkg(const string &Name); | |
132 | Header &Head() {return *HeaderP;}; | |
133 | inline PkgIterator PkgBegin(); | |
134 | inline PkgIterator PkgEnd(); | |
135 | inline PkgFileIterator FileBegin(); | |
136 | inline PkgFileIterator FileEnd(); | |
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); | |
145 | ||
146 | pkgCache(MMap *Map,bool DoMap = true); | |
147 | virtual ~pkgCache() {}; | |
148 | }; | |
0e5943eb JF |
149 | /*}}}*/ |
150 | // Header structure /*{{{*/ | |
acdafb44 JF |
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; | |
164 | unsigned short DescriptionSz; | |
165 | unsigned short DependencySz; | |
166 | unsigned short ProvidesSz; | |
167 | unsigned short VerFileSz; | |
168 | unsigned short DescFileSz; | |
169 | ||
170 | // Structure counts | |
171 | unsigned long PackageCount; | |
172 | unsigned long VersionCount; | |
173 | unsigned long DescriptionCount; | |
174 | unsigned long DependsCount; | |
175 | unsigned long PackageFileCount; | |
176 | unsigned long VerFileCount; | |
177 | unsigned long DescFileCount; | |
178 | unsigned long ProvidesCount; | |
179 | ||
180 | // Offsets | |
181 | map_ptrloc FileList; // struct PackageFile | |
182 | map_ptrloc StringList; // struct StringItem | |
183 | map_ptrloc VerSysName; // StringTable | |
184 | map_ptrloc Architecture; // StringTable | |
185 | unsigned long MaxVerFileSize; | |
186 | unsigned long MaxDescFileSize; | |
187 | ||
188 | /* Allocation pools, there should be one of these for each structure | |
189 | excluding the header */ | |
190 | DynamicMMap::Pool Pools[8]; | |
191 | ||
192 | // Rapid package name lookup | |
193 | map_ptrloc HashTable[2*1048]; | |
194 | ||
195 | bool CheckSizes(Header &Against) const; | |
196 | Header(); | |
197 | }; | |
0e5943eb JF |
198 | /*}}}*/ |
199 | struct pkgCache::Package /*{{{*/ | |
acdafb44 JF |
200 | { |
201 | // Pointers | |
202 | map_ptrloc Name; // Stringtable | |
203 | map_ptrloc Display; // Stringtable | |
204 | map_ptrloc VersionList; // Version | |
205 | map_ptrloc CurrentVer; // Version | |
206 | map_ptrloc Section; // StringTable (StringItem) | |
207 | ||
208 | // Linked list | |
209 | map_ptrloc NextPackage; // Package | |
210 | map_ptrloc RevDepends; // Dependency | |
211 | map_ptrloc ProvidesList; // Provides | |
212 | ||
213 | // Install/Remove/Purge etc | |
214 | unsigned char SelectedState; // What | |
215 | unsigned char InstState; // Flags | |
216 | unsigned char CurrentState; // State | |
217 | ||
218 | unsigned short ID; | |
219 | unsigned long Flags; | |
220 | }; | |
221 | ||
222 | struct pkgCache::PackageFile | |
223 | { | |
224 | // Names | |
225 | map_ptrloc FileName; // Stringtable | |
226 | map_ptrloc Archive; // Stringtable | |
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 | |
232 | map_ptrloc Site; // Stringtable | |
233 | map_ptrloc IndexType; // Stringtable | |
234 | unsigned long Size; | |
235 | unsigned long Flags; | |
236 | ||
237 | // Linked list | |
238 | map_ptrloc NextFile; // PackageFile | |
239 | unsigned short ID; | |
240 | time_t mtime; // Modification time for the file | |
241 | }; | |
0e5943eb JF |
242 | /*}}}*/ |
243 | struct pkgCache::VerFile /*{{{*/ | |
acdafb44 JF |
244 | { |
245 | map_ptrloc File; // PackageFile | |
246 | map_ptrloc NextFile; // PkgVerFile | |
247 | map_ptrloc Offset; // File offset | |
248 | unsigned short Size; | |
249 | }; | |
0e5943eb JF |
250 | /*}}}*/ |
251 | struct pkgCache::DescFile /*{{{*/ | |
acdafb44 JF |
252 | { |
253 | map_ptrloc File; // PackageFile | |
254 | map_ptrloc NextFile; // PkgVerFile | |
255 | map_ptrloc Offset; // File offset | |
256 | unsigned short Size; | |
257 | }; | |
0e5943eb JF |
258 | /*}}}*/ |
259 | struct pkgCache::Version /*{{{*/ | |
acdafb44 JF |
260 | { |
261 | map_ptrloc VerStr; // Stringtable | |
262 | map_ptrloc Display; // Stringtable | |
263 | map_ptrloc Section; // StringTable (StringItem) | |
264 | map_ptrloc Arch; // StringTable | |
265 | ||
266 | // Lists | |
267 | map_ptrloc FileList; // VerFile | |
268 | map_ptrloc NextVer; // Version | |
269 | map_ptrloc DescriptionList; // Description | |
270 | map_ptrloc DependsList; // Dependency | |
271 | map_ptrloc ParentPkg; // Package | |
272 | map_ptrloc ProvidesList; // Provides | |
273 | ||
274 | map_ptrloc Size; // These are the .deb size | |
275 | map_ptrloc InstalledSize; | |
276 | unsigned short Hash; | |
277 | unsigned short ID; | |
278 | unsigned char Priority; | |
279 | }; | |
0e5943eb JF |
280 | /*}}}*/ |
281 | struct pkgCache::Description /*{{{*/ | |
acdafb44 JF |
282 | { |
283 | // Language Code store the description translation language code. If | |
284 | // the value has a 0 lenght then this is readed using the Package | |
285 | // file else the Translation-CODE are used. | |
286 | map_ptrloc language_code; // StringTable | |
287 | map_ptrloc md5sum; // StringTable | |
288 | ||
289 | // Linked list | |
290 | map_ptrloc FileList; // DescFile | |
291 | map_ptrloc NextDesc; // Description | |
292 | map_ptrloc ParentPkg; // Package | |
293 | ||
294 | unsigned short ID; | |
295 | }; | |
0e5943eb JF |
296 | /*}}}*/ |
297 | struct pkgCache::Dependency /*{{{*/ | |
acdafb44 JF |
298 | { |
299 | map_ptrloc Version; // Stringtable | |
300 | map_ptrloc Package; // Package | |
301 | map_ptrloc NextDepends; // Dependency | |
302 | map_ptrloc NextRevDepends; // Dependency | |
303 | map_ptrloc ParentVer; // Version | |
304 | ||
305 | // Specific types of depends | |
306 | map_ptrloc ID; | |
307 | unsigned char Type; | |
308 | unsigned char CompareOp; | |
309 | }; | |
0e5943eb JF |
310 | /*}}}*/ |
311 | struct pkgCache::Provides /*{{{*/ | |
acdafb44 JF |
312 | { |
313 | map_ptrloc ParentPkg; // Pacakge | |
314 | map_ptrloc Version; // Version | |
315 | map_ptrloc ProvideVersion; // Stringtable | |
316 | map_ptrloc NextProvides; // Provides | |
317 | map_ptrloc NextPkgProv; // Provides | |
318 | }; | |
0e5943eb JF |
319 | /*}}}*/ |
320 | struct pkgCache::StringItem /*{{{*/ | |
acdafb44 JF |
321 | { |
322 | map_ptrloc String; // Stringtable | |
323 | map_ptrloc NextItem; // StringItem | |
324 | }; | |
0e5943eb | 325 | /*}}}*/ |
acdafb44 JF |
326 | #include <apt-pkg/cacheiterators.h> |
327 | ||
328 | inline pkgCache::PkgIterator pkgCache::PkgBegin() | |
329 | {return PkgIterator(*this);}; | |
330 | inline pkgCache::PkgIterator pkgCache::PkgEnd() | |
331 | {return PkgIterator(*this,PkgP);}; | |
332 | inline pkgCache::PkgFileIterator pkgCache::FileBegin() | |
333 | {return PkgFileIterator(*this,PkgFileP + HeaderP->FileList);}; | |
334 | inline pkgCache::PkgFileIterator pkgCache::FileEnd() | |
335 | {return PkgFileIterator(*this,PkgFileP);}; | |
336 | ||
337 | // Oh I wish for Real Name Space Support | |
0e5943eb | 338 | class pkgCache::Namespace /*{{{*/ |
acdafb44 JF |
339 | { |
340 | public: | |
341 | ||
342 | typedef pkgCache::PkgIterator PkgIterator; | |
343 | typedef pkgCache::VerIterator VerIterator; | |
344 | typedef pkgCache::DescIterator DescIterator; | |
345 | typedef pkgCache::DepIterator DepIterator; | |
346 | typedef pkgCache::PrvIterator PrvIterator; | |
347 | typedef pkgCache::PkgFileIterator PkgFileIterator; | |
348 | typedef pkgCache::VerFileIterator VerFileIterator; | |
349 | typedef pkgCache::Version Version; | |
350 | typedef pkgCache::Description Description; | |
351 | typedef pkgCache::Package Package; | |
352 | typedef pkgCache::Header Header; | |
353 | typedef pkgCache::Dep Dep; | |
354 | typedef pkgCache::Flag Flag; | |
355 | }; | |
0e5943eb | 356 | /*}}}*/ |
acdafb44 | 357 | #endif |