apt @VERSION@
|
00001 // -*- mode: cpp; mode: fold -*- 00002 // Description /*{{{*/ 00073 /*}}}*/ 00074 #ifndef PKGLIB_PKGCACHE_H 00075 #define PKGLIB_PKGCACHE_H 00076 00077 00078 #include <string> 00079 #include <time.h> 00080 #include <apt-pkg/mmap.h> 00081 00082 using std::string; 00083 00084 class pkgVersioningSystem; 00085 class pkgCache /*{{{*/ 00086 { 00087 public: 00088 // Cache element predeclarations 00089 struct Header; 00090 struct Group; 00091 struct Package; 00092 struct PackageFile; 00093 struct Version; 00094 struct Description; 00095 struct Provides; 00096 struct Dependency; 00097 struct StringItem; 00098 struct VerFile; 00099 struct DescFile; 00100 00101 // Iterators 00102 template<typename Str, typename Itr> class Iterator; 00103 class GrpIterator; 00104 class PkgIterator; 00105 class VerIterator; 00106 class DescIterator; 00107 class DepIterator; 00108 class PrvIterator; 00109 class PkgFileIterator; 00110 class VerFileIterator; 00111 class DescFileIterator; 00112 00113 class Namespace; 00114 00115 // These are all the constants used in the cache structures 00116 00117 // WARNING - if you change these lists you must also edit 00118 // the stringification in pkgcache.cc and also consider whether 00119 // the cache file will become incompatible. 00120 struct Dep 00121 { 00122 enum DepType {Depends=1,PreDepends=2,Suggests=3,Recommends=4, 00123 Conflicts=5,Replaces=6,Obsoletes=7,DpkgBreaks=8,Enhances=9}; 00129 enum DepCompareOp {Or=0x10,NoOp=0,LessEq=0x1,GreaterEq=0x2,Less=0x3, 00130 Greater=0x4,Equals=0x5,NotEquals=0x6}; 00131 }; 00132 00133 struct State 00134 { 00138 enum VerPriority {Important=1,Required=2,Standard=3,Optional=4,Extra=5}; 00139 enum PkgSelectedState {Unknown=0,Install=1,Hold=2,DeInstall=3,Purge=4}; 00140 enum PkgInstState {Ok=0,ReInstReq=1,HoldInst=2,HoldReInstReq=3}; 00141 enum PkgCurrentState {NotInstalled=0,UnPacked=1,HalfConfigured=2, 00142 HalfInstalled=4,ConfigFiles=5,Installed=6, 00143 TriggersAwaited=7,TriggersPending=8}; 00144 }; 00145 00146 struct Flag 00147 { 00148 enum PkgFlags {Auto=(1<<0),Essential=(1<<3),Important=(1<<4)}; 00149 enum PkgFFlags {NotSource=(1<<0),NotAutomatic=(1<<1),ButAutomaticUpgrades=(1<<2)}; 00150 }; 00151 00152 protected: 00153 00154 // Memory mapped cache file 00155 string CacheFile; 00156 MMap ⤅ 00157 00158 unsigned long sHash(const string &S) const; 00159 unsigned long sHash(const char *S) const; 00160 00161 public: 00162 00163 // Pointers to the arrays of items 00164 Header *HeaderP; 00165 Group *GrpP; 00166 Package *PkgP; 00167 VerFile *VerFileP; 00168 DescFile *DescFileP; 00169 PackageFile *PkgFileP; 00170 Version *VerP; 00171 Description *DescP; 00172 Provides *ProvideP; 00173 Dependency *DepP; 00174 StringItem *StringItemP; 00175 char *StrP; 00176 00177 virtual bool ReMap(bool const &Errorchecks = true); 00178 inline bool Sync() {return Map.Sync();}; 00179 inline MMap &GetMap() {return Map;}; 00180 inline void *DataEnd() {return ((unsigned char *)Map.Data()) + Map.Size();}; 00181 00182 // String hashing function (512 range) 00183 inline unsigned long Hash(const string &S) const {return sHash(S);}; 00184 inline unsigned long Hash(const char *S) const {return sHash(S);}; 00185 00186 // Useful transformation things 00187 const char *Priority(unsigned char Priority); 00188 00189 // Accessors 00190 GrpIterator FindGrp(const string &Name); 00191 PkgIterator FindPkg(const string &Name); 00192 PkgIterator FindPkg(const string &Name, const string &Arch); 00193 00194 Header &Head() {return *HeaderP;}; 00195 inline GrpIterator GrpBegin(); 00196 inline GrpIterator GrpEnd(); 00197 inline PkgIterator PkgBegin(); 00198 inline PkgIterator PkgEnd(); 00199 inline PkgFileIterator FileBegin(); 00200 inline PkgFileIterator FileEnd(); 00201 00202 inline bool MultiArchCache() const { return MultiArchEnabled; }; 00203 00204 // Make me a function 00205 pkgVersioningSystem *VS; 00206 00207 // Converters 00208 static const char *CompTypeDeb(unsigned char Comp); 00209 static const char *CompType(unsigned char Comp); 00210 static const char *DepType(unsigned char Dep); 00211 00212 pkgCache(MMap *Map,bool DoMap = true); 00213 virtual ~pkgCache() {}; 00214 00215 private: 00216 bool MultiArchEnabled; 00217 PkgIterator SingleArchFindPkg(const string &Name); 00218 inline char const * const NativeArch() const; 00219 }; 00220 /*}}}*/ 00221 // Header structure /*{{{*/ 00222 struct pkgCache::Header 00223 { 00229 unsigned long Signature; 00231 short MajorVersion; 00232 short MinorVersion; 00238 bool Dirty; 00239 00247 unsigned short HeaderSz; 00248 unsigned short GroupSz; 00249 unsigned short PackageSz; 00250 unsigned short PackageFileSz; 00251 unsigned short VersionSz; 00252 unsigned short DescriptionSz; 00253 unsigned short DependencySz; 00254 unsigned short ProvidesSz; 00255 unsigned short VerFileSz; 00256 unsigned short DescFileSz; 00257 00263 unsigned long GroupCount; 00264 unsigned long PackageCount; 00265 unsigned long VersionCount; 00266 unsigned long DescriptionCount; 00267 unsigned long DependsCount; 00268 unsigned long PackageFileCount; 00269 unsigned long VerFileCount; 00270 unsigned long DescFileCount; 00271 unsigned long ProvidesCount; 00272 00277 map_ptrloc FileList; 00283 map_ptrloc StringList; 00285 map_ptrloc VerSysName; 00287 map_ptrloc Architecture; 00289 unsigned long MaxVerFileSize; 00291 unsigned long MaxDescFileSize; 00292 00301 DynamicMMap::Pool Pools[9]; 00302 00314 map_ptrloc PkgHashTable[2*1048]; 00315 map_ptrloc GrpHashTable[2*1048]; 00316 00318 unsigned long CacheFileSize; 00319 00320 bool CheckSizes(Header &Against) const; 00321 Header(); 00322 }; 00323 /*}}}*/ 00324 // Group structure /*{{{*/ 00331 struct pkgCache::Group 00332 { 00334 map_ptrloc Name; // StringItem 00335 00336 // Linked List 00338 map_ptrloc FirstPackage; // Package 00340 map_ptrloc LastPackage; // Package 00342 map_ptrloc Next; // Group 00344 unsigned int ID; 00345 00346 }; 00347 /*}}}*/ 00348 // Package structure /*{{{*/ 00360 struct pkgCache::Package 00361 { 00363 map_ptrloc Name; // StringItem 00365 map_ptrloc Arch; // StringItem 00375 map_ptrloc VersionList; // Version 00377 map_ptrloc CurrentVer; // Version 00382 map_ptrloc Section; // StringItem 00384 map_ptrloc Group; // Group the Package belongs to 00385 00386 // Linked list 00388 map_ptrloc NextPackage; // Package 00390 map_ptrloc RevDepends; // Dependency 00392 map_ptrloc ProvidesList; // Provides 00393 00394 // Install/Remove/Purge etc 00396 unsigned char SelectedState; // What 00402 unsigned char InstState; // Flags 00404 unsigned char CurrentState; // State 00405 00412 unsigned int ID; 00414 unsigned long Flags; 00415 }; 00416 /*}}}*/ 00417 // Package File structure /*{{{*/ 00423 struct pkgCache::PackageFile 00424 { 00426 map_ptrloc FileName; // StringItem 00431 map_ptrloc Archive; // StringItem 00432 map_ptrloc Codename; // StringItem 00433 map_ptrloc Component; // StringItem 00434 map_ptrloc Version; // StringItem 00435 map_ptrloc Origin; // StringItem 00436 map_ptrloc Label; // StringItem 00437 map_ptrloc Architecture; // StringItem 00439 map_ptrloc Site; // StringItem 00443 map_ptrloc IndexType; // StringItem 00449 unsigned long Size; 00451 time_t mtime; 00452 00453 /* @TODO document PackageFile::Flags */ 00454 unsigned long Flags; 00455 00456 // Linked list 00458 map_ptrloc NextFile; // PackageFile 00460 unsigned int ID; 00461 }; 00462 /*}}}*/ 00463 // VerFile structure /*{{{*/ 00468 struct pkgCache::VerFile 00469 { 00471 map_ptrloc File; // PackageFile 00473 map_ptrloc NextFile; // PkgVerFile 00475 map_ptrloc Offset; // File offset 00476 /* @TODO document pkgCache::VerFile::Size */ 00477 unsigned long Size; 00478 }; 00479 /*}}}*/ 00480 // DescFile structure /*{{{*/ 00482 struct pkgCache::DescFile 00483 { 00485 map_ptrloc File; // PackageFile 00487 map_ptrloc NextFile; // PkgVerFile 00489 map_ptrloc Offset; // File offset 00490 /* @TODO document pkgCache::DescFile::Size */ 00491 unsigned long Size; 00492 }; 00493 /*}}}*/ 00494 // Version structure /*{{{*/ 00500 struct pkgCache::Version 00501 { 00503 map_ptrloc VerStr; // StringItem 00505 map_ptrloc Section; // StringItem 00506 00508 enum VerMultiArch { None = 0, 00509 All = (1<<0), 00510 Foreign = (1<<1), 00511 Same = (1<<2), 00512 Allowed = (1<<3), 00513 AllForeign = All | Foreign, 00514 AllAllowed = All | Allowed }; 00519 unsigned char MultiArch; 00520 00527 map_ptrloc FileList; // VerFile 00529 map_ptrloc NextVer; // Version 00531 map_ptrloc DescriptionList; // Description 00533 map_ptrloc DependsList; // Dependency 00537 map_ptrloc ParentPkg; // Package 00539 map_ptrloc ProvidesList; // Provides 00540 00544 unsigned long long Size; // These are the .deb size 00546 unsigned long long InstalledSize; 00551 unsigned short Hash; 00553 unsigned int ID; 00555 unsigned char Priority; 00556 }; 00557 /*}}}*/ 00558 // Description structure /*{{{*/ 00560 struct pkgCache::Description 00561 { 00566 map_ptrloc language_code; // StringItem 00571 map_ptrloc md5sum; // StringItem 00572 00573 /* @TODO document pkgCache::Description::FileList */ 00574 map_ptrloc FileList; // DescFile 00576 map_ptrloc NextDesc; // Description 00578 map_ptrloc ParentPkg; // Package 00579 00581 unsigned int ID; 00582 }; 00583 /*}}}*/ 00584 // Dependency structure /*{{{*/ 00591 struct pkgCache::Dependency 00592 { 00594 map_ptrloc Version; // StringItem 00599 map_ptrloc Package; // Package 00601 map_ptrloc NextDepends; // Dependency 00603 map_ptrloc NextRevDepends; // Dependency 00605 map_ptrloc ParentVer; // Version 00606 00608 map_ptrloc ID; 00610 unsigned char Type; 00614 unsigned char CompareOp; 00615 }; 00616 /*}}}*/ 00617 // Provides structure /*{{{*/ 00626 struct pkgCache::Provides 00627 { 00629 map_ptrloc ParentPkg; // Package 00631 map_ptrloc Version; // Version 00637 map_ptrloc ProvideVersion; // StringItem 00639 map_ptrloc NextProvides; // Provides 00641 map_ptrloc NextPkgProv; // Provides 00642 }; 00643 /*}}}*/ 00644 // StringItem structure /*{{{*/ 00653 struct pkgCache::StringItem 00654 { 00656 map_ptrloc String; // StringItem 00658 map_ptrloc NextItem; // StringItem 00659 }; 00660 /*}}}*/ 00661 00662 00663 inline char const * const pkgCache::NativeArch() const 00664 { return StrP + HeaderP->Architecture; }; 00665 00666 #include <apt-pkg/cacheiterators.h> 00667 00668 inline pkgCache::GrpIterator pkgCache::GrpBegin() 00669 {return GrpIterator(*this);}; 00670 inline pkgCache::GrpIterator pkgCache::GrpEnd() 00671 {return GrpIterator(*this,GrpP);}; 00672 inline pkgCache::PkgIterator pkgCache::PkgBegin() 00673 {return PkgIterator(*this);}; 00674 inline pkgCache::PkgIterator pkgCache::PkgEnd() 00675 {return PkgIterator(*this,PkgP);}; 00676 inline pkgCache::PkgFileIterator pkgCache::FileBegin() 00677 {return PkgFileIterator(*this,PkgFileP + HeaderP->FileList);}; 00678 inline pkgCache::PkgFileIterator pkgCache::FileEnd() 00679 {return PkgFileIterator(*this,PkgFileP);}; 00680 00681 // Oh I wish for Real Name Space Support 00682 class pkgCache::Namespace /*{{{*/ 00683 { 00684 public: 00685 typedef pkgCache::GrpIterator GrpIterator; 00686 typedef pkgCache::PkgIterator PkgIterator; 00687 typedef pkgCache::VerIterator VerIterator; 00688 typedef pkgCache::DescIterator DescIterator; 00689 typedef pkgCache::DepIterator DepIterator; 00690 typedef pkgCache::PrvIterator PrvIterator; 00691 typedef pkgCache::PkgFileIterator PkgFileIterator; 00692 typedef pkgCache::VerFileIterator VerFileIterator; 00693 typedef pkgCache::Version Version; 00694 typedef pkgCache::Description Description; 00695 typedef pkgCache::Package Package; 00696 typedef pkgCache::Header Header; 00697 typedef pkgCache::Dep Dep; 00698 typedef pkgCache::Flag Flag; 00699 }; 00700 /*}}}*/ 00701 #endif