pkgcache.h 10.0 KB

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