* merged with the apt--mvo branch
[ntk/apt.git] / apt-pkg / pkgcache.h
CommitLineData
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
27using std::string;
b2e465d6
AL
28
29class pkgVersioningSystem;
578bfd0a
AL
30class pkgCache
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,
308c7d30 73 Conflicts=5,Replaces=6,Obsoletes=7,DpkgBreaks=8};
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,
a005475e 84 HalfInstalled=4,ConfigFiles=5,Installed=6};
6c139d6e
AL
85 };
86
87 struct Flag
88 {
138d4b3d 89 enum PkgFlags {Auto=(1<<0),Essential=(1<<3),Important=(1<<4)};
3c124dde 90 enum PkgFFlags {NotSource=(1<<0),NotAutomatic=(1<<1)};
6c139d6e 91 };
578bfd0a
AL
92
93 protected:
94
95 // Memory mapped cache file
96 string CacheFile;
97 MMap &Map;
98
171c75f1 99 unsigned long sHash(const string &S) const;
f9eec0e7 100 unsigned long sHash(const char *S) const;
578bfd0a
AL
101
102 public:
103
104 // Pointers to the arrays of items
105 Header *HeaderP;
106 Package *PkgP;
dcb79bae 107 VerFile *VerFileP;
a52f938b 108 DescFile *DescFileP;
578bfd0a
AL
109 PackageFile *PkgFileP;
110 Version *VerP;
a52f938b 111 Description *DescP;
578bfd0a
AL
112 Provides *ProvideP;
113 Dependency *DepP;
114 StringItem *StringItemP;
115 char *StrP;
dcb79bae 116
578bfd0a
AL
117 virtual bool ReMap();
118 inline bool Sync() {return Map.Sync();};
981d20eb 119 inline MMap &GetMap() {return Map;};
b2e465d6
AL
120 inline void *DataEnd() {return ((unsigned char *)Map.Data()) + Map.Size();};
121
578bfd0a 122 // String hashing function (512 range)
171c75f1 123 inline unsigned long Hash(const string &S) const {return sHash(S);};
578bfd0a
AL
124 inline unsigned long Hash(const char *S) const {return sHash(S);};
125
0149949b
AL
126 // Usefull transformation things
127 const char *Priority(unsigned char Priority);
128
578bfd0a 129 // Accessors
171c75f1 130 PkgIterator FindPkg(const string &Name);
578bfd0a
AL
131 Header &Head() {return *HeaderP;};
132 inline PkgIterator PkgBegin();
133 inline PkgIterator PkgEnd();
ad00ae81
AL
134 inline PkgFileIterator FileBegin();
135 inline PkgFileIterator FileEnd();
b2e465d6
AL
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);
ad00ae81 144
b2e465d6 145 pkgCache(MMap *Map,bool DoMap = true);
578bfd0a
AL
146 virtual ~pkgCache() {};
147};
148
149// Header structure
150struct 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;
a52f938b 163 unsigned short DescriptionSz;
578bfd0a
AL
164 unsigned short DependencySz;
165 unsigned short ProvidesSz;
dcb79bae 166 unsigned short VerFileSz;
a52f938b 167 unsigned short DescFileSz;
dcb79bae 168
578bfd0a
AL
169 // Structure counts
170 unsigned long PackageCount;
171 unsigned long VersionCount;
a52f938b 172 unsigned long DescriptionCount;
578bfd0a
AL
173 unsigned long DependsCount;
174 unsigned long PackageFileCount;
a7e66b17 175 unsigned long VerFileCount;
a52f938b 176 unsigned long DescFileCount;
a7e66b17 177 unsigned long ProvidesCount;
578bfd0a
AL
178
179 // Offsets
349cd3b8
AL
180 map_ptrloc FileList; // struct PackageFile
181 map_ptrloc StringList; // struct StringItem
b2e465d6
AL
182 map_ptrloc VerSysName; // StringTable
183 map_ptrloc Architecture; // StringTable
ad00ae81 184 unsigned long MaxVerFileSize;
a52f938b 185 unsigned long MaxDescFileSize;
578bfd0a
AL
186
187 /* Allocation pools, there should be one of these for each structure
188 excluding the header */
a52f938b 189 DynamicMMap::Pool Pools[8];
578bfd0a
AL
190
191 // Rapid package name lookup
349cd3b8 192 map_ptrloc HashTable[2*1048];
578bfd0a
AL
193
194 bool CheckSizes(Header &Against) const;
195 Header();
196};
197
198struct pkgCache::Package
199{
200 // Pointers
349cd3b8
AL
201 map_ptrloc Name; // Stringtable
202 map_ptrloc VersionList; // Version
349cd3b8 203 map_ptrloc CurrentVer; // Version
349cd3b8 204 map_ptrloc Section; // StringTable (StringItem)
578bfd0a
AL
205
206 // Linked list
349cd3b8
AL
207 map_ptrloc NextPackage; // Package
208 map_ptrloc RevDepends; // Dependency
209 map_ptrloc ProvidesList; // Provides
a52f938b 210
578bfd0a
AL
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;
f55a958f 217 unsigned long Flags;
578bfd0a
AL
218};
219
220struct pkgCache::PackageFile
221{
222 // Names
349cd3b8
AL
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
b2e465d6
AL
230 map_ptrloc Site; // Stringtable
231 map_ptrloc IndexType; // Stringtable
b0b4efb9 232 unsigned long Size;
3c124dde 233 unsigned long Flags;
578bfd0a
AL
234
235 // Linked list
349cd3b8 236 map_ptrloc NextFile; // PackageFile
578bfd0a 237 unsigned short ID;
578bfd0a
AL
238 time_t mtime; // Modification time for the file
239};
240
dcb79bae
AL
241struct pkgCache::VerFile
242{
349cd3b8
AL
243 map_ptrloc File; // PackageFile
244 map_ptrloc NextFile; // PkgVerFile
245 map_ptrloc Offset; // File offset
dcb79bae
AL
246 unsigned short Size;
247};
248
a52f938b
OS
249struct 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
578bfd0a
AL
257struct pkgCache::Version
258{
349cd3b8
AL
259 map_ptrloc VerStr; // Stringtable
260 map_ptrloc Section; // StringTable (StringItem)
261 map_ptrloc Arch; // StringTable
17caf1b1 262
578bfd0a 263 // Lists
349cd3b8
AL
264 map_ptrloc FileList; // VerFile
265 map_ptrloc NextVer; // Version
a52f938b 266 map_ptrloc DescriptionList; // Description
349cd3b8
AL
267 map_ptrloc DependsList; // Dependency
268 map_ptrloc ParentPkg; // Package
269 map_ptrloc ProvidesList; // Provides
578bfd0a 270
349cd3b8
AL
271 map_ptrloc Size; // These are the .deb size
272 map_ptrloc InstalledSize;
204fbdcc 273 unsigned short Hash;
578bfd0a
AL
274 unsigned short ID;
275 unsigned char Priority;
276};
277
a52f938b
OS
278struct 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
578bfd0a
AL
294struct pkgCache::Dependency
295{
349cd3b8
AL
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
578bfd0a
AL
301
302 // Specific types of depends
6a3da7a6 303 map_ptrloc ID;
578bfd0a
AL
304 unsigned char Type;
305 unsigned char CompareOp;
578bfd0a
AL
306};
307
308struct pkgCache::Provides
309{
349cd3b8
AL
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
578bfd0a
AL
315};
316
317struct pkgCache::StringItem
318{
349cd3b8
AL
319 map_ptrloc String; // Stringtable
320 map_ptrloc NextItem; // StringItem
578bfd0a
AL
321};
322
094a497d 323#include <apt-pkg/cacheiterators.h>
578bfd0a
AL
324
325inline pkgCache::PkgIterator pkgCache::PkgBegin()
326 {return PkgIterator(*this);};
327inline pkgCache::PkgIterator pkgCache::PkgEnd()
328 {return PkgIterator(*this,PkgP);};
ad00ae81 329inline pkgCache::PkgFileIterator pkgCache::FileBegin()
b2e465d6 330 {return PkgFileIterator(*this,PkgFileP + HeaderP->FileList);};
ad00ae81
AL
331inline pkgCache::PkgFileIterator pkgCache::FileEnd()
332 {return PkgFileIterator(*this,PkgFileP);};
578bfd0a 333
b2e465d6
AL
334// Oh I wish for Real Name Space Support
335class pkgCache::Namespace
336{
337 public:
338
339 typedef pkgCache::PkgIterator PkgIterator;
340 typedef pkgCache::VerIterator VerIterator;
a52f938b 341 typedef pkgCache::DescIterator DescIterator;
b2e465d6
AL
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;
a52f938b 347 typedef pkgCache::Description Description;
b2e465d6
AL
348 typedef pkgCache::Package Package;
349 typedef pkgCache::Header Header;
350 typedef pkgCache::Dep Dep;
351 typedef pkgCache::Flag Flag;
352};
353
578bfd0a 354#endif