pkgcache.h 10 KB

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