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