pkgcache.h 9.8 KB

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