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