]> git.saurik.com Git - apt.git/blob - apt-pkg/pkgcache.h
Newer sub/guess scripts
[apt.git] / apt-pkg / pkgcache.h
1 // -*- mode: cpp; mode: fold -*-
2 // Description /*{{{*/
3 // $Id: pkgcache.h,v 1.23 2001/02/20 07:03:17 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 #ifdef __GNUG__
23 #pragma interface "apt-pkg/pkgcache.h"
24 #endif
25
26 #include <string>
27 #include <time.h>
28 #include <apt-pkg/mmap.h>
29
30 class pkgVersioningSystem;
31 class pkgCache
32 {
33 public:
34 // Cache element predeclarations
35 struct Header;
36 struct Package;
37 struct PackageFile;
38 struct Version;
39 struct Provides;
40 struct Dependency;
41 struct StringItem;
42 struct VerFile;
43
44 // Iterators
45 class PkgIterator;
46 class VerIterator;
47 class DepIterator;
48 class PrvIterator;
49 class PkgFileIterator;
50 class VerFileIterator;
51 friend class PkgIterator;
52 friend class VerIterator;
53 friend class DepIterator;
54 friend class PrvIterator;
55 friend class PkgFileIterator;
56 friend class VerFileIterator;
57
58 class Namespace;
59
60 // These are all the constants used in the cache structures
61 struct Dep
62 {
63 enum DepType {Depends=1,PreDepends=2,Suggests=3,Recommends=4,
64 Conflicts=5,Replaces=6,Obsoletes=7};
65 enum DepCompareOp {Or=0x10,NoOp=0,LessEq=0x1,GreaterEq=0x2,Less=0x3,
66 Greater=0x4,Equals=0x5,NotEquals=0x6};
67 };
68
69 struct State
70 {
71 enum VerPriority {Important=1,Required=2,Standard=3,Optional=4,Extra=5};
72 enum PkgSelectedState {Unknown=0,Install=1,Hold=2,DeInstall=3,Purge=4};
73 enum PkgInstState {Ok=0,ReInstReq=1,HoldInst=2,HoldReInstReq=3};
74 enum PkgCurrentState {NotInstalled=0,UnPacked=1,HalfConfigured=2,
75 HalfInstalled=4,ConfigFiles=5,Installed=6};
76 };
77
78 struct Flag
79 {
80 enum PkgFlags {Auto=(1<<0),Essential=(1<<3),Important=(1<<4)};
81 enum PkgFFlags {NotSource=(1<<0),NotAutomatic=(1<<1)};
82 };
83
84 protected:
85
86 // Memory mapped cache file
87 string CacheFile;
88 MMap &Map;
89
90 unsigned long sHash(string S) const;
91 unsigned long sHash(const char *S) const;
92
93 public:
94
95 // Pointers to the arrays of items
96 Header *HeaderP;
97 Package *PkgP;
98 VerFile *VerFileP;
99 PackageFile *PkgFileP;
100 Version *VerP;
101 Provides *ProvideP;
102 Dependency *DepP;
103 StringItem *StringItemP;
104 char *StrP;
105
106 virtual bool ReMap();
107 inline bool Sync() {return Map.Sync();};
108 inline MMap &GetMap() {return Map;};
109 inline void *DataEnd() {return ((unsigned char *)Map.Data()) + Map.Size();};
110
111 // String hashing function (512 range)
112 inline unsigned long Hash(string S) const {return sHash(S);};
113 inline unsigned long Hash(const char *S) const {return sHash(S);};
114
115 // Usefull transformation things
116 const char *Priority(unsigned char Priority);
117
118 // Accessors
119 PkgIterator FindPkg(string Name);
120 Header &Head() {return *HeaderP;};
121 inline PkgIterator PkgBegin();
122 inline PkgIterator PkgEnd();
123 inline PkgFileIterator FileBegin();
124 inline PkgFileIterator FileEnd();
125
126 // Make me a function
127 pkgVersioningSystem *VS;
128
129 // Converters
130 static const char *CompTypeDeb(unsigned char Comp);
131 static const char *CompType(unsigned char Comp);
132 static const char *DepType(unsigned char Dep);
133
134 pkgCache(MMap *Map,bool DoMap = true);
135 virtual ~pkgCache() {};
136 };
137
138 // Header structure
139 struct pkgCache::Header
140 {
141 // Signature information
142 unsigned long Signature;
143 short MajorVersion;
144 short MinorVersion;
145 bool Dirty;
146
147 // Size of structure values
148 unsigned short HeaderSz;
149 unsigned short PackageSz;
150 unsigned short PackageFileSz;
151 unsigned short VersionSz;
152 unsigned short DependencySz;
153 unsigned short ProvidesSz;
154 unsigned short VerFileSz;
155
156 // Structure counts
157 unsigned long PackageCount;
158 unsigned long VersionCount;
159 unsigned long DependsCount;
160 unsigned long PackageFileCount;
161 unsigned long VerFileCount;
162 unsigned long ProvidesCount;
163
164 // Offsets
165 map_ptrloc FileList; // struct PackageFile
166 map_ptrloc StringList; // struct StringItem
167 map_ptrloc VerSysName; // StringTable
168 map_ptrloc Architecture; // StringTable
169 unsigned long MaxVerFileSize;
170
171 /* Allocation pools, there should be one of these for each structure
172 excluding the header */
173 DynamicMMap::Pool Pools[7];
174
175 // Rapid package name lookup
176 map_ptrloc HashTable[2*1048];
177
178 bool CheckSizes(Header &Against) const;
179 Header();
180 };
181
182 struct pkgCache::Package
183 {
184 // Pointers
185 map_ptrloc Name; // Stringtable
186 map_ptrloc VersionList; // Version
187 map_ptrloc CurrentVer; // Version
188 map_ptrloc Section; // StringTable (StringItem)
189
190 // Linked list
191 map_ptrloc NextPackage; // Package
192 map_ptrloc RevDepends; // Dependency
193 map_ptrloc ProvidesList; // Provides
194
195 // Install/Remove/Purge etc
196 unsigned char SelectedState; // What
197 unsigned char InstState; // Flags
198 unsigned char CurrentState; // State
199
200 unsigned short ID;
201 unsigned long Flags;
202 };
203
204 struct pkgCache::PackageFile
205 {
206 // Names
207 map_ptrloc FileName; // Stringtable
208 map_ptrloc Archive; // Stringtable
209 map_ptrloc Component; // Stringtable
210 map_ptrloc Version; // Stringtable
211 map_ptrloc Origin; // Stringtable
212 map_ptrloc Label; // Stringtable
213 map_ptrloc Architecture; // Stringtable
214 map_ptrloc Site; // Stringtable
215 map_ptrloc IndexType; // Stringtable
216 unsigned long Size;
217 unsigned long Flags;
218
219 // Linked list
220 map_ptrloc NextFile; // PackageFile
221 unsigned short ID;
222 time_t mtime; // Modification time for the file
223 };
224
225 struct pkgCache::VerFile
226 {
227 map_ptrloc File; // PackageFile
228 map_ptrloc NextFile; // PkgVerFile
229 map_ptrloc Offset; // File offset
230 unsigned short Size;
231 };
232
233 struct pkgCache::Version
234 {
235 map_ptrloc VerStr; // Stringtable
236 map_ptrloc Section; // StringTable (StringItem)
237 map_ptrloc Arch; // StringTable
238
239 // Lists
240 map_ptrloc FileList; // VerFile
241 map_ptrloc NextVer; // Version
242 map_ptrloc DependsList; // Dependency
243 map_ptrloc ParentPkg; // Package
244 map_ptrloc ProvidesList; // Provides
245
246 map_ptrloc Size; // These are the .deb size
247 map_ptrloc InstalledSize;
248 unsigned short Hash;
249 unsigned short ID;
250 unsigned char Priority;
251 };
252
253 struct pkgCache::Dependency
254 {
255 map_ptrloc Version; // Stringtable
256 map_ptrloc Package; // Package
257 map_ptrloc NextDepends; // Dependency
258 map_ptrloc NextRevDepends; // Dependency
259 map_ptrloc ParentVer; // Version
260
261 // Specific types of depends
262 unsigned char Type;
263 unsigned char CompareOp;
264 unsigned short ID;
265 };
266
267 struct pkgCache::Provides
268 {
269 map_ptrloc ParentPkg; // Pacakge
270 map_ptrloc Version; // Version
271 map_ptrloc ProvideVersion; // Stringtable
272 map_ptrloc NextProvides; // Provides
273 map_ptrloc NextPkgProv; // Provides
274 };
275
276 struct pkgCache::StringItem
277 {
278 map_ptrloc String; // Stringtable
279 map_ptrloc NextItem; // StringItem
280 };
281
282 #include <apt-pkg/cacheiterators.h>
283
284 inline pkgCache::PkgIterator pkgCache::PkgBegin()
285 {return PkgIterator(*this);};
286 inline pkgCache::PkgIterator pkgCache::PkgEnd()
287 {return PkgIterator(*this,PkgP);};
288 inline pkgCache::PkgFileIterator pkgCache::FileBegin()
289 {return PkgFileIterator(*this,PkgFileP + HeaderP->FileList);};
290 inline pkgCache::PkgFileIterator pkgCache::FileEnd()
291 {return PkgFileIterator(*this,PkgFileP);};
292
293 // Oh I wish for Real Name Space Support
294 class pkgCache::Namespace
295 {
296 public:
297
298 typedef pkgCache::PkgIterator PkgIterator;
299 typedef pkgCache::VerIterator VerIterator;
300 typedef pkgCache::DepIterator DepIterator;
301 typedef pkgCache::PrvIterator PrvIterator;
302 typedef pkgCache::PkgFileIterator PkgFileIterator;
303 typedef pkgCache::VerFileIterator VerFileIterator;
304 typedef pkgCache::Version Version;
305 typedef pkgCache::Package Package;
306 typedef pkgCache::Header Header;
307 typedef pkgCache::Dep Dep;
308 typedef pkgCache::Flag Flag;
309 };
310
311 #endif