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