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