]> git.saurik.com Git - apt-legacy.git/blob - apt-pkg/pkgcache.h
Fix compilation of http when embedding into Cydia.
[apt-legacy.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 #include <apt-pkg/srkstring.h>
27
28 using std::string;
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 Description;
40 struct Provides;
41 struct Dependency;
42 struct StringItem;
43 struct VerFile;
44 struct DescFile;
45 struct Tag;
46
47 // Iterators
48 class PkgIterator;
49 class VerIterator;
50 class DescIterator;
51 class DepIterator;
52 class PrvIterator;
53 class PkgFileIterator;
54 class VerFileIterator;
55 class DescFileIterator;
56 class TagIterator;
57 friend class PkgIterator;
58 friend class VerIterator;
59 friend class DescInterator;
60 friend class DepIterator;
61 friend class PrvIterator;
62 friend class PkgFileIterator;
63 friend class VerFileIterator;
64 friend class DescFileIterator;
65 friend class TagIterator;
66
67 class Namespace;
68
69 // These are all the constants used in the cache structures
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.
74 struct Dep
75 {
76 enum DepType {Depends=1,PreDepends=2,Suggests=3,Recommends=4,
77 Conflicts=5,Replaces=6,Obsoletes=7,DpkgBreaks=8,Enhances=9};
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,
88 HalfInstalled=4,ConfigFiles=5,Installed=6,
89 TriggersAwaited=7,TriggersPending=8};
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;
106 unsigned long sHash(const srkString &S) const;
107
108 public:
109
110 // Pointers to the arrays of items
111 Header *HeaderP;
112 Package *PkgP;
113 VerFile *VerFileP;
114 DescFile *DescFileP;
115 PackageFile *PkgFileP;
116 Version *VerP;
117 Tag *TagP;
118 Description *DescP;
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);};
132 inline unsigned long Hash(const srkString &S) const {return sHash(S);};
133
134 // Usefull transformation things
135 const char *Priority(unsigned char Priority);
136
137 // Accessors
138 PkgIterator FindPkg(const string &Name);
139 PkgIterator FindPkg(const srkString &Name);
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 };
157 /*}}}*/
158 // Header structure /*{{{*/
159 struct 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;
172 unsigned short TagSz;
173 unsigned short DescriptionSz;
174 unsigned short DependencySz;
175 unsigned short ProvidesSz;
176 unsigned short VerFileSz;
177 unsigned short DescFileSz;
178
179 // Structure counts
180 unsigned long PackageCount;
181 unsigned long VersionCount;
182 unsigned long TagCount;
183 unsigned long DescriptionCount;
184 unsigned long DependsCount;
185 unsigned long PackageFileCount;
186 unsigned long VerFileCount;
187 unsigned long DescFileCount;
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;
196 unsigned long MaxDescFileSize;
197
198 /* Allocation pools, there should be one of these for each structure
199 excluding the header */
200 DynamicMMap::Pool Pools[8];
201
202 // Rapid package name lookup
203 map_ptrloc HashTable[2*1048];
204
205 bool CheckSizes(Header &Against) const;
206 Header();
207 };
208 /*}}}*/
209 struct pkgCache::Package /*{{{*/
210 {
211 // Pointers
212 map_ptrloc Name; // Stringtable
213 map_ptrloc Display; // Stringtable
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
222 map_ptrloc TagList; // Tag
223
224 // Install/Remove/Purge etc
225 unsigned char SelectedState; // What
226 unsigned char InstState; // Flags
227 unsigned char CurrentState; // State
228
229 unsigned int ID;
230 unsigned long Flags;
231 };
232
233 struct 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 int ID;
251 time_t mtime; // Modification time for the file
252 };
253 /*}}}*/
254 struct pkgCache::VerFile /*{{{*/
255 {
256 map_ptrloc File; // PackageFile
257 map_ptrloc NextFile; // PkgVerFile
258 map_ptrloc Offset; // File offset
259 unsigned short Size;
260 };
261 /*}}}*/
262 struct pkgCache::Tag /*{{{*/
263 {
264 map_ptrloc Name; // Stringtable
265 map_ptrloc NextTag; // Tag
266 };
267 /*}}}*/
268 struct pkgCache::DescFile /*{{{*/
269 {
270 map_ptrloc File; // PackageFile
271 map_ptrloc NextFile; // PkgVerFile
272 map_ptrloc Offset; // File offset
273 unsigned short Size;
274 };
275 /*}}}*/
276 struct pkgCache::Version /*{{{*/
277 {
278 map_ptrloc VerStr; // Stringtable
279 map_ptrloc Display; // Stringtable
280 map_ptrloc Section; // StringTable (StringItem)
281 map_ptrloc Arch; // StringTable
282
283 // Lists
284 map_ptrloc FileList; // VerFile
285 map_ptrloc NextVer; // Version
286 map_ptrloc DescriptionList; // Description
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 ID1;
295 unsigned char Priority;
296 unsigned short ID2;
297 };
298 /*}}}*/
299 struct pkgCache::Description /*{{{*/
300 {
301 // Language Code store the description translation language code. If
302 // the value has a 0 lenght then this is readed using the Package
303 // file else the Translation-CODE are used.
304 map_ptrloc language_code; // StringTable
305 map_ptrloc md5sum; // StringTable
306
307 // Linked list
308 map_ptrloc FileList; // DescFile
309 map_ptrloc NextDesc; // Description
310 map_ptrloc ParentPkg; // Package
311
312 unsigned int ID;
313 };
314 /*}}}*/
315 struct pkgCache::Dependency /*{{{*/
316 {
317 map_ptrloc Version; // Stringtable
318 map_ptrloc Package; // Package
319 map_ptrloc NextDepends; // Dependency
320 map_ptrloc NextRevDepends; // Dependency
321 map_ptrloc ParentVer; // Version
322
323 // Specific types of depends
324 map_ptrloc ID;
325 unsigned char Type;
326 unsigned char CompareOp;
327 };
328 /*}}}*/
329 struct pkgCache::Provides /*{{{*/
330 {
331 map_ptrloc ParentPkg; // Pacakge
332 map_ptrloc Version; // Version
333 map_ptrloc ProvideVersion; // Stringtable
334 map_ptrloc NextProvides; // Provides
335 map_ptrloc NextPkgProv; // Provides
336 };
337 /*}}}*/
338 struct pkgCache::StringItem /*{{{*/
339 {
340 map_ptrloc String; // Stringtable
341 map_ptrloc NextItem; // StringItem
342 };
343 /*}}}*/
344 #include <apt-pkg/cacheiterators.h>
345
346 inline pkgCache::PkgIterator pkgCache::PkgBegin()
347 {return PkgIterator(*this);};
348 inline pkgCache::PkgIterator pkgCache::PkgEnd()
349 {return PkgIterator(*this,PkgP);};
350 inline pkgCache::PkgFileIterator pkgCache::FileBegin()
351 {return PkgFileIterator(*this,PkgFileP + HeaderP->FileList);};
352 inline pkgCache::PkgFileIterator pkgCache::FileEnd()
353 {return PkgFileIterator(*this,PkgFileP);};
354
355 // Oh I wish for Real Name Space Support
356 class pkgCache::Namespace /*{{{*/
357 {
358 public:
359
360 typedef pkgCache::PkgIterator PkgIterator;
361 typedef pkgCache::VerIterator VerIterator;
362 typedef pkgCache::TagIterator TagIterator;
363 typedef pkgCache::DescIterator DescIterator;
364 typedef pkgCache::DepIterator DepIterator;
365 typedef pkgCache::PrvIterator PrvIterator;
366 typedef pkgCache::PkgFileIterator PkgFileIterator;
367 typedef pkgCache::VerFileIterator VerFileIterator;
368 typedef pkgCache::Version Version;
369 typedef pkgCache::Description Description;
370 typedef pkgCache::Package Package;
371 typedef pkgCache::Header Header;
372 typedef pkgCache::Dep Dep;
373 typedef pkgCache::Flag Flag;
374 };
375 /*}}}*/
376 #endif