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