* add "purge" commandline argument, closes: #133421)
[ntk/apt.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
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,
73 Conflicts=5,Replaces=6,Obsoletes=7,DpkgBreaks=8};
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 };
86
87 struct Flag
88 {
89 enum PkgFlags {Auto=(1<<0),Essential=(1<<3),Important=(1<<4)};
90 enum PkgFFlags {NotSource=(1<<0),NotAutomatic=(1<<1)};
91 };
92
93 protected:
94
95 // Memory mapped cache file
96 string CacheFile;
97 MMap &Map;
98
99 unsigned long sHash(const string &S) const;
100 unsigned long sHash(const char *S) const;
101
102 public:
103
104 // Pointers to the arrays of items
105 Header *HeaderP;
106 Package *PkgP;
107 VerFile *VerFileP;
108 DescFile *DescFileP;
109 PackageFile *PkgFileP;
110 Version *VerP;
111 Description *DescP;
112 Provides *ProvideP;
113 Dependency *DepP;
114 StringItem *StringItemP;
115 char *StrP;
116
117 virtual bool ReMap();
118 inline bool Sync() {return Map.Sync();};
119 inline MMap &GetMap() {return Map;};
120 inline void *DataEnd() {return ((unsigned char *)Map.Data()) + Map.Size();};
121
122 // String hashing function (512 range)
123 inline unsigned long Hash(const string &S) const {return sHash(S);};
124 inline unsigned long Hash(const char *S) const {return sHash(S);};
125
126 // Usefull transformation things
127 const char *Priority(unsigned char Priority);
128
129 // Accessors
130 PkgIterator FindPkg(const string &Name);
131 Header &Head() {return *HeaderP;};
132 inline PkgIterator PkgBegin();
133 inline PkgIterator PkgEnd();
134 inline PkgFileIterator FileBegin();
135 inline PkgFileIterator FileEnd();
136
137 // Make me a function
138 pkgVersioningSystem *VS;
139
140 // Converters
141 static const char *CompTypeDeb(unsigned char Comp);
142 static const char *CompType(unsigned char Comp);
143 static const char *DepType(unsigned char Dep);
144
145 pkgCache(MMap *Map,bool DoMap = true);
146 virtual ~pkgCache() {};
147 };
148
149 // Header structure
150 struct pkgCache::Header
151 {
152 // Signature information
153 unsigned long Signature;
154 short MajorVersion;
155 short MinorVersion;
156 bool Dirty;
157
158 // Size of structure values
159 unsigned short HeaderSz;
160 unsigned short PackageSz;
161 unsigned short PackageFileSz;
162 unsigned short VersionSz;
163 unsigned short DescriptionSz;
164 unsigned short DependencySz;
165 unsigned short ProvidesSz;
166 unsigned short VerFileSz;
167 unsigned short DescFileSz;
168
169 // Structure counts
170 unsigned long PackageCount;
171 unsigned long VersionCount;
172 unsigned long DescriptionCount;
173 unsigned long DependsCount;
174 unsigned long PackageFileCount;
175 unsigned long VerFileCount;
176 unsigned long DescFileCount;
177 unsigned long ProvidesCount;
178
179 // Offsets
180 map_ptrloc FileList; // struct PackageFile
181 map_ptrloc StringList; // struct StringItem
182 map_ptrloc VerSysName; // StringTable
183 map_ptrloc Architecture; // StringTable
184 unsigned long MaxVerFileSize;
185 unsigned long MaxDescFileSize;
186
187 /* Allocation pools, there should be one of these for each structure
188 excluding the header */
189 DynamicMMap::Pool Pools[8];
190
191 // Rapid package name lookup
192 map_ptrloc HashTable[2*1048];
193
194 bool CheckSizes(Header &Against) const;
195 Header();
196 };
197
198 struct pkgCache::Package
199 {
200 // Pointers
201 map_ptrloc Name; // Stringtable
202 map_ptrloc VersionList; // Version
203 map_ptrloc CurrentVer; // Version
204 map_ptrloc Section; // StringTable (StringItem)
205
206 // Linked list
207 map_ptrloc NextPackage; // Package
208 map_ptrloc RevDepends; // Dependency
209 map_ptrloc ProvidesList; // Provides
210
211 // Install/Remove/Purge etc
212 unsigned char SelectedState; // What
213 unsigned char InstState; // Flags
214 unsigned char CurrentState; // State
215
216 unsigned short ID;
217 unsigned long Flags;
218 };
219
220 struct pkgCache::PackageFile
221 {
222 // Names
223 map_ptrloc FileName; // Stringtable
224 map_ptrloc Archive; // Stringtable
225 map_ptrloc Component; // Stringtable
226 map_ptrloc Version; // Stringtable
227 map_ptrloc Origin; // Stringtable
228 map_ptrloc Label; // Stringtable
229 map_ptrloc Architecture; // Stringtable
230 map_ptrloc Site; // Stringtable
231 map_ptrloc IndexType; // Stringtable
232 unsigned long Size;
233 unsigned long Flags;
234
235 // Linked list
236 map_ptrloc NextFile; // PackageFile
237 unsigned short ID;
238 time_t mtime; // Modification time for the file
239 };
240
241 struct pkgCache::VerFile
242 {
243 map_ptrloc File; // PackageFile
244 map_ptrloc NextFile; // PkgVerFile
245 map_ptrloc Offset; // File offset
246 unsigned short Size;
247 };
248
249 struct pkgCache::DescFile
250 {
251 map_ptrloc File; // PackageFile
252 map_ptrloc NextFile; // PkgVerFile
253 map_ptrloc Offset; // File offset
254 unsigned short Size;
255 };
256
257 struct pkgCache::Version
258 {
259 map_ptrloc VerStr; // Stringtable
260 map_ptrloc Section; // StringTable (StringItem)
261 map_ptrloc Arch; // StringTable
262
263 // Lists
264 map_ptrloc FileList; // VerFile
265 map_ptrloc NextVer; // Version
266 map_ptrloc DescriptionList; // Description
267 map_ptrloc DependsList; // Dependency
268 map_ptrloc ParentPkg; // Package
269 map_ptrloc ProvidesList; // Provides
270
271 map_ptrloc Size; // These are the .deb size
272 map_ptrloc InstalledSize;
273 unsigned short Hash;
274 unsigned short ID;
275 unsigned char Priority;
276 };
277
278 struct pkgCache::Description
279 {
280 // Language Code store the description translation language code. If
281 // the value has a 0 lenght then this is readed using the Package
282 // file else the Translation-CODE are used.
283 map_ptrloc language_code; // StringTable
284 map_ptrloc md5sum; // StringTable
285
286 // Linked list
287 map_ptrloc FileList; // DescFile
288 map_ptrloc NextDesc; // Description
289 map_ptrloc ParentPkg; // Package
290
291 unsigned short ID;
292 };
293
294 struct pkgCache::Dependency
295 {
296 map_ptrloc Version; // Stringtable
297 map_ptrloc Package; // Package
298 map_ptrloc NextDepends; // Dependency
299 map_ptrloc NextRevDepends; // Dependency
300 map_ptrloc ParentVer; // Version
301
302 // Specific types of depends
303 map_ptrloc ID;
304 unsigned char Type;
305 unsigned char CompareOp;
306 };
307
308 struct pkgCache::Provides
309 {
310 map_ptrloc ParentPkg; // Pacakge
311 map_ptrloc Version; // Version
312 map_ptrloc ProvideVersion; // Stringtable
313 map_ptrloc NextProvides; // Provides
314 map_ptrloc NextPkgProv; // Provides
315 };
316
317 struct pkgCache::StringItem
318 {
319 map_ptrloc String; // Stringtable
320 map_ptrloc NextItem; // StringItem
321 };
322
323 #include <apt-pkg/cacheiterators.h>
324
325 inline pkgCache::PkgIterator pkgCache::PkgBegin()
326 {return PkgIterator(*this);};
327 inline pkgCache::PkgIterator pkgCache::PkgEnd()
328 {return PkgIterator(*this,PkgP);};
329 inline pkgCache::PkgFileIterator pkgCache::FileBegin()
330 {return PkgFileIterator(*this,PkgFileP + HeaderP->FileList);};
331 inline pkgCache::PkgFileIterator pkgCache::FileEnd()
332 {return PkgFileIterator(*this,PkgFileP);};
333
334 // Oh I wish for Real Name Space Support
335 class pkgCache::Namespace
336 {
337 public:
338
339 typedef pkgCache::PkgIterator PkgIterator;
340 typedef pkgCache::VerIterator VerIterator;
341 typedef pkgCache::DescIterator DescIterator;
342 typedef pkgCache::DepIterator DepIterator;
343 typedef pkgCache::PrvIterator PrvIterator;
344 typedef pkgCache::PkgFileIterator PkgFileIterator;
345 typedef pkgCache::VerFileIterator VerFileIterator;
346 typedef pkgCache::Version Version;
347 typedef pkgCache::Description Description;
348 typedef pkgCache::Package Package;
349 typedef pkgCache::Header Header;
350 typedef pkgCache::Dep Dep;
351 typedef pkgCache::Flag Flag;
352 };
353
354 #endif