]> git.saurik.com Git - apt.git/blame - apt-pkg/pkgcache.h
* merged the apt--curl-https branch
[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#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
30using std::string;
b2e465d6
AL
31
32class pkgVersioningSystem;
578bfd0a
AL
33class 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
308c7d30
IJ
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.
6c139d6e
AL
73 struct Dep
74 {
75 enum DepType {Depends=1,PreDepends=2,Suggests=3,Recommends=4,
308c7d30 76 Conflicts=5,Replaces=6,Obsoletes=7,DpkgBreaks=8};
6c139d6e
AL
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 {
fbfb2a7c 83 enum VerPriority {Important=1,Required=2,Standard=3,Optional=4,Extra=5};
6c139d6e
AL
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,
a005475e 87 HalfInstalled=4,ConfigFiles=5,Installed=6};
6c139d6e
AL
88 };
89
90 struct Flag
91 {
138d4b3d 92 enum PkgFlags {Auto=(1<<0),Essential=(1<<3),Important=(1<<4)};
3c124dde 93 enum PkgFFlags {NotSource=(1<<0),NotAutomatic=(1<<1)};
6c139d6e 94 };
578bfd0a
AL
95
96 protected:
97
98 // Memory mapped cache file
99 string CacheFile;
100 MMap &Map;
101
171c75f1 102 unsigned long sHash(const string &S) const;
f9eec0e7 103 unsigned long sHash(const char *S) const;
578bfd0a
AL
104
105 public:
106
107 // Pointers to the arrays of items
108 Header *HeaderP;
109 Package *PkgP;
dcb79bae 110 VerFile *VerFileP;
a52f938b 111 DescFile *DescFileP;
578bfd0a
AL
112 PackageFile *PkgFileP;
113 Version *VerP;
a52f938b 114 Description *DescP;
578bfd0a
AL
115 Provides *ProvideP;
116 Dependency *DepP;
117 StringItem *StringItemP;
118 char *StrP;
dcb79bae 119
578bfd0a
AL
120 virtual bool ReMap();
121 inline bool Sync() {return Map.Sync();};
981d20eb 122 inline MMap &GetMap() {return Map;};
b2e465d6
AL
123 inline void *DataEnd() {return ((unsigned char *)Map.Data()) + Map.Size();};
124
578bfd0a 125 // String hashing function (512 range)
171c75f1 126 inline unsigned long Hash(const string &S) const {return sHash(S);};
578bfd0a
AL
127 inline unsigned long Hash(const char *S) const {return sHash(S);};
128
0149949b
AL
129 // Usefull transformation things
130 const char *Priority(unsigned char Priority);
131
578bfd0a 132 // Accessors
171c75f1 133 PkgIterator FindPkg(const string &Name);
578bfd0a
AL
134 Header &Head() {return *HeaderP;};
135 inline PkgIterator PkgBegin();
136 inline PkgIterator PkgEnd();
ad00ae81
AL
137 inline PkgFileIterator FileBegin();
138 inline PkgFileIterator FileEnd();
b2e465d6
AL
139
140 // Make me a function
141 pkgVersioningSystem *VS;
142
143 // Converters
144 static const char *CompTypeDeb(unsigned char Comp);
145 static const char *CompType(unsigned char Comp);
146 static const char *DepType(unsigned char Dep);
ad00ae81 147
b2e465d6 148 pkgCache(MMap *Map,bool DoMap = true);
578bfd0a
AL
149 virtual ~pkgCache() {};
150};
151
152// Header structure
153struct pkgCache::Header
154{
155 // Signature information
156 unsigned long Signature;
157 short MajorVersion;
158 short MinorVersion;
159 bool Dirty;
160
161 // Size of structure values
162 unsigned short HeaderSz;
163 unsigned short PackageSz;
164 unsigned short PackageFileSz;
165 unsigned short VersionSz;
a52f938b 166 unsigned short DescriptionSz;
578bfd0a
AL
167 unsigned short DependencySz;
168 unsigned short ProvidesSz;
dcb79bae 169 unsigned short VerFileSz;
a52f938b 170 unsigned short DescFileSz;
dcb79bae 171
578bfd0a
AL
172 // Structure counts
173 unsigned long PackageCount;
174 unsigned long VersionCount;
a52f938b 175 unsigned long DescriptionCount;
578bfd0a
AL
176 unsigned long DependsCount;
177 unsigned long PackageFileCount;
a7e66b17 178 unsigned long VerFileCount;
a52f938b 179 unsigned long DescFileCount;
a7e66b17 180 unsigned long ProvidesCount;
578bfd0a
AL
181
182 // Offsets
349cd3b8
AL
183 map_ptrloc FileList; // struct PackageFile
184 map_ptrloc StringList; // struct StringItem
b2e465d6
AL
185 map_ptrloc VerSysName; // StringTable
186 map_ptrloc Architecture; // StringTable
ad00ae81 187 unsigned long MaxVerFileSize;
a52f938b 188 unsigned long MaxDescFileSize;
578bfd0a
AL
189
190 /* Allocation pools, there should be one of these for each structure
191 excluding the header */
a52f938b 192 DynamicMMap::Pool Pools[8];
578bfd0a
AL
193
194 // Rapid package name lookup
349cd3b8 195 map_ptrloc HashTable[2*1048];
578bfd0a
AL
196
197 bool CheckSizes(Header &Against) const;
198 Header();
199};
200
201struct pkgCache::Package
202{
203 // Pointers
349cd3b8
AL
204 map_ptrloc Name; // Stringtable
205 map_ptrloc VersionList; // Version
349cd3b8 206 map_ptrloc CurrentVer; // Version
349cd3b8 207 map_ptrloc Section; // StringTable (StringItem)
578bfd0a
AL
208
209 // Linked list
349cd3b8
AL
210 map_ptrloc NextPackage; // Package
211 map_ptrloc RevDepends; // Dependency
212 map_ptrloc ProvidesList; // Provides
a52f938b 213
578bfd0a
AL
214 // Install/Remove/Purge etc
215 unsigned char SelectedState; // What
216 unsigned char InstState; // Flags
217 unsigned char CurrentState; // State
218
219 unsigned short ID;
f55a958f 220 unsigned long Flags;
578bfd0a
AL
221};
222
223struct pkgCache::PackageFile
224{
225 // Names
349cd3b8
AL
226 map_ptrloc FileName; // Stringtable
227 map_ptrloc Archive; // Stringtable
228 map_ptrloc Component; // Stringtable
229 map_ptrloc Version; // Stringtable
230 map_ptrloc Origin; // Stringtable
231 map_ptrloc Label; // Stringtable
232 map_ptrloc Architecture; // Stringtable
b2e465d6
AL
233 map_ptrloc Site; // Stringtable
234 map_ptrloc IndexType; // Stringtable
b0b4efb9 235 unsigned long Size;
3c124dde 236 unsigned long Flags;
578bfd0a
AL
237
238 // Linked list
349cd3b8 239 map_ptrloc NextFile; // PackageFile
578bfd0a 240 unsigned short ID;
578bfd0a
AL
241 time_t mtime; // Modification time for the file
242};
243
dcb79bae
AL
244struct pkgCache::VerFile
245{
349cd3b8
AL
246 map_ptrloc File; // PackageFile
247 map_ptrloc NextFile; // PkgVerFile
248 map_ptrloc Offset; // File offset
dcb79bae
AL
249 unsigned short Size;
250};
251
a52f938b
OS
252struct pkgCache::DescFile
253{
254 map_ptrloc File; // PackageFile
255 map_ptrloc NextFile; // PkgVerFile
256 map_ptrloc Offset; // File offset
257 unsigned short Size;
258};
259
578bfd0a
AL
260struct pkgCache::Version
261{
349cd3b8
AL
262 map_ptrloc VerStr; // Stringtable
263 map_ptrloc Section; // StringTable (StringItem)
264 map_ptrloc Arch; // StringTable
17caf1b1 265
578bfd0a 266 // Lists
349cd3b8
AL
267 map_ptrloc FileList; // VerFile
268 map_ptrloc NextVer; // Version
a52f938b 269 map_ptrloc DescriptionList; // Description
349cd3b8
AL
270 map_ptrloc DependsList; // Dependency
271 map_ptrloc ParentPkg; // Package
272 map_ptrloc ProvidesList; // Provides
578bfd0a 273
349cd3b8
AL
274 map_ptrloc Size; // These are the .deb size
275 map_ptrloc InstalledSize;
204fbdcc 276 unsigned short Hash;
578bfd0a
AL
277 unsigned short ID;
278 unsigned char Priority;
279};
280
a52f938b
OS
281struct pkgCache::Description
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};
296
578bfd0a
AL
297struct pkgCache::Dependency
298{
349cd3b8
AL
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
578bfd0a
AL
304
305 // Specific types of depends
6a3da7a6 306 map_ptrloc ID;
578bfd0a
AL
307 unsigned char Type;
308 unsigned char CompareOp;
578bfd0a
AL
309};
310
311struct pkgCache::Provides
312{
349cd3b8
AL
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
578bfd0a
AL
318};
319
320struct pkgCache::StringItem
321{
349cd3b8
AL
322 map_ptrloc String; // Stringtable
323 map_ptrloc NextItem; // StringItem
578bfd0a
AL
324};
325
094a497d 326#include <apt-pkg/cacheiterators.h>
578bfd0a
AL
327
328inline pkgCache::PkgIterator pkgCache::PkgBegin()
329 {return PkgIterator(*this);};
330inline pkgCache::PkgIterator pkgCache::PkgEnd()
331 {return PkgIterator(*this,PkgP);};
ad00ae81 332inline pkgCache::PkgFileIterator pkgCache::FileBegin()
b2e465d6 333 {return PkgFileIterator(*this,PkgFileP + HeaderP->FileList);};
ad00ae81
AL
334inline pkgCache::PkgFileIterator pkgCache::FileEnd()
335 {return PkgFileIterator(*this,PkgFileP);};
578bfd0a 336
b2e465d6
AL
337// Oh I wish for Real Name Space Support
338class pkgCache::Namespace
339{
340 public:
341
342 typedef pkgCache::PkgIterator PkgIterator;
343 typedef pkgCache::VerIterator VerIterator;
a52f938b 344 typedef pkgCache::DescIterator DescIterator;
b2e465d6
AL
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;
a52f938b 350 typedef pkgCache::Description Description;
b2e465d6
AL
351 typedef pkgCache::Package Package;
352 typedef pkgCache::Header Header;
353 typedef pkgCache::Dep Dep;
354 typedef pkgCache::Flag Flag;
355};
356
578bfd0a 357#endif