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