pkgcache.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  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 Group;
  27. struct Package;
  28. struct PackageFile;
  29. struct Version;
  30. struct Description;
  31. struct Provides;
  32. struct Dependency;
  33. struct StringItem;
  34. struct VerFile;
  35. struct DescFile;
  36. // Iterators
  37. template<typename Str, typename Itr> class Iterator;
  38. class GrpIterator;
  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. class Namespace;
  48. // These are all the constants used in the cache structures
  49. // WARNING - if you change these lists you must also edit
  50. // the stringification in pkgcache.cc and also consider whether
  51. // the cache file will become incompatible.
  52. struct Dep
  53. {
  54. enum DepType {Depends=1,PreDepends=2,Suggests=3,Recommends=4,
  55. Conflicts=5,Replaces=6,Obsoletes=7,DpkgBreaks=8,Enhances=9};
  56. enum DepCompareOp {Or=0x10,NoOp=0,LessEq=0x1,GreaterEq=0x2,Less=0x3,
  57. Greater=0x4,Equals=0x5,NotEquals=0x6};
  58. };
  59. struct State
  60. {
  61. enum VerPriority {Important=1,Required=2,Standard=3,Optional=4,Extra=5};
  62. enum PkgSelectedState {Unknown=0,Install=1,Hold=2,DeInstall=3,Purge=4};
  63. enum PkgInstState {Ok=0,ReInstReq=1,HoldInst=2,HoldReInstReq=3};
  64. enum PkgCurrentState {NotInstalled=0,UnPacked=1,HalfConfigured=2,
  65. HalfInstalled=4,ConfigFiles=5,Installed=6,
  66. TriggersAwaited=7,TriggersPending=8};
  67. };
  68. struct Flag
  69. {
  70. enum PkgFlags {Auto=(1<<0),Essential=(1<<3),Important=(1<<4)};
  71. enum PkgFFlags {NotSource=(1<<0),NotAutomatic=(1<<1)};
  72. };
  73. protected:
  74. // Memory mapped cache file
  75. string CacheFile;
  76. MMap &Map;
  77. unsigned long sHash(const string &S) const;
  78. unsigned long sHash(const char *S) const;
  79. public:
  80. // Pointers to the arrays of items
  81. Header *HeaderP;
  82. Group *GrpP;
  83. Package *PkgP;
  84. VerFile *VerFileP;
  85. DescFile *DescFileP;
  86. PackageFile *PkgFileP;
  87. Version *VerP;
  88. Description *DescP;
  89. Provides *ProvideP;
  90. Dependency *DepP;
  91. StringItem *StringItemP;
  92. char *StrP;
  93. virtual bool ReMap();
  94. inline bool Sync() {return Map.Sync();};
  95. inline MMap &GetMap() {return Map;};
  96. inline void *DataEnd() {return ((unsigned char *)Map.Data()) + Map.Size();};
  97. // String hashing function (512 range)
  98. inline unsigned long Hash(const string &S) const {return sHash(S);};
  99. inline unsigned long Hash(const char *S) const {return sHash(S);};
  100. // Usefull transformation things
  101. const char *Priority(unsigned char Priority);
  102. // Accessors
  103. GrpIterator FindGrp(const string &Name);
  104. PkgIterator FindPkg(const string &Name);
  105. PkgIterator FindPkg(const string &Name, string Arch);
  106. Header &Head() {return *HeaderP;};
  107. inline GrpIterator GrpBegin();
  108. inline GrpIterator GrpEnd();
  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. /*}}}*/
  123. // Header structure /*{{{*/
  124. struct pkgCache::Header
  125. {
  126. // Signature information
  127. unsigned long Signature;
  128. short MajorVersion;
  129. short MinorVersion;
  130. bool Dirty;
  131. // Size of structure values
  132. unsigned short HeaderSz;
  133. unsigned short PackageSz;
  134. unsigned short PackageFileSz;
  135. unsigned short VersionSz;
  136. unsigned short DescriptionSz;
  137. unsigned short DependencySz;
  138. unsigned short ProvidesSz;
  139. unsigned short VerFileSz;
  140. unsigned short DescFileSz;
  141. // Structure counts
  142. unsigned long GroupCount;
  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[9];
  161. // Rapid package and group name lookup
  162. // Notice: Increase only both table sizes as the
  163. // hashmethod assume the size of the Pkg one
  164. map_ptrloc PkgHashTable[2*1048];
  165. map_ptrloc GrpHashTable[2*1048];
  166. bool CheckSizes(Header &Against) const;
  167. Header();
  168. };
  169. /*}}}*/
  170. struct pkgCache::Group { /*{{{*/
  171. map_ptrloc Name; // Stringtable
  172. // Linked List
  173. map_ptrloc FirstPackage;// Package
  174. map_ptrloc LastPackage; // Package
  175. map_ptrloc Next; // Group
  176. };
  177. /*}}}*/
  178. struct pkgCache::Package /*{{{*/
  179. {
  180. // Pointers
  181. map_ptrloc Name; // Stringtable
  182. map_ptrloc Arch; // StringTable (StringItem)
  183. map_ptrloc VersionList; // Version
  184. map_ptrloc CurrentVer; // Version
  185. map_ptrloc Section; // StringTable (StringItem)
  186. map_ptrloc Group; // Group the Package belongs to
  187. // Linked list
  188. map_ptrloc NextPackage; // Package
  189. map_ptrloc RevDepends; // Dependency
  190. map_ptrloc ProvidesList; // Provides
  191. // Install/Remove/Purge etc
  192. unsigned char SelectedState; // What
  193. unsigned char InstState; // Flags
  194. unsigned char CurrentState; // State
  195. unsigned int ID;
  196. unsigned long Flags;
  197. };
  198. /*}}}*/
  199. struct pkgCache::PackageFile /*{{{*/
  200. {
  201. // Names
  202. map_ptrloc FileName; // Stringtable
  203. map_ptrloc Archive; // Stringtable
  204. map_ptrloc Codename; // Stringtable
  205. map_ptrloc Component; // Stringtable
  206. map_ptrloc Version; // Stringtable
  207. map_ptrloc Origin; // Stringtable
  208. map_ptrloc Label; // Stringtable
  209. map_ptrloc Architecture; // Stringtable
  210. map_ptrloc Site; // Stringtable
  211. map_ptrloc IndexType; // Stringtable
  212. unsigned long Size;
  213. unsigned long Flags;
  214. // Linked list
  215. map_ptrloc NextFile; // PackageFile
  216. unsigned int ID;
  217. time_t mtime; // Modification time for the file
  218. };
  219. /*}}}*/
  220. struct pkgCache::VerFile /*{{{*/
  221. {
  222. map_ptrloc File; // PackageFile
  223. map_ptrloc NextFile; // PkgVerFile
  224. map_ptrloc Offset; // File offset
  225. unsigned long Size;
  226. };
  227. /*}}}*/
  228. struct pkgCache::DescFile /*{{{*/
  229. {
  230. map_ptrloc File; // PackageFile
  231. map_ptrloc NextFile; // PkgVerFile
  232. map_ptrloc Offset; // File offset
  233. unsigned long Size;
  234. };
  235. /*}}}*/
  236. struct pkgCache::Version /*{{{*/
  237. {
  238. map_ptrloc VerStr; // Stringtable
  239. map_ptrloc Section; // StringTable (StringItem)
  240. enum {None, All, Foreign, Same, Allowed} MultiArch;
  241. // Lists
  242. map_ptrloc FileList; // VerFile
  243. map_ptrloc NextVer; // Version
  244. map_ptrloc DescriptionList; // Description
  245. map_ptrloc DependsList; // Dependency
  246. map_ptrloc ParentPkg; // Package
  247. map_ptrloc ProvidesList; // Provides
  248. map_ptrloc Size; // These are the .deb size
  249. map_ptrloc InstalledSize;
  250. unsigned short Hash;
  251. unsigned int ID;
  252. unsigned char Priority;
  253. };
  254. /*}}}*/
  255. struct pkgCache::Description /*{{{*/
  256. {
  257. // Language Code store the description translation language code. If
  258. // the value has a 0 lenght then this is readed using the Package
  259. // file else the Translation-CODE are used.
  260. map_ptrloc language_code; // StringTable
  261. map_ptrloc md5sum; // StringTable
  262. // Linked list
  263. map_ptrloc FileList; // DescFile
  264. map_ptrloc NextDesc; // Description
  265. map_ptrloc ParentPkg; // Package
  266. unsigned int ID;
  267. };
  268. /*}}}*/
  269. struct pkgCache::Dependency /*{{{*/
  270. {
  271. map_ptrloc Version; // Stringtable
  272. map_ptrloc Package; // Package
  273. map_ptrloc NextDepends; // Dependency
  274. map_ptrloc NextRevDepends; // Dependency
  275. map_ptrloc ParentVer; // Version
  276. // Specific types of depends
  277. map_ptrloc ID;
  278. unsigned char Type;
  279. unsigned char CompareOp;
  280. };
  281. /*}}}*/
  282. struct pkgCache::Provides /*{{{*/
  283. {
  284. map_ptrloc ParentPkg; // Pacakge
  285. map_ptrloc Version; // Version
  286. map_ptrloc ProvideVersion; // Stringtable
  287. map_ptrloc NextProvides; // Provides
  288. map_ptrloc NextPkgProv; // Provides
  289. };
  290. /*}}}*/
  291. struct pkgCache::StringItem /*{{{*/
  292. {
  293. map_ptrloc String; // Stringtable
  294. map_ptrloc NextItem; // StringItem
  295. };
  296. /*}}}*/
  297. #include <apt-pkg/cacheiterators.h>
  298. inline pkgCache::GrpIterator pkgCache::GrpBegin()
  299. {return GrpIterator(*this);};
  300. inline pkgCache::GrpIterator pkgCache::GrpEnd()
  301. {return GrpIterator(*this,GrpP);};
  302. inline pkgCache::PkgIterator pkgCache::PkgBegin()
  303. {return PkgIterator(*this);};
  304. inline pkgCache::PkgIterator pkgCache::PkgEnd()
  305. {return PkgIterator(*this,PkgP);};
  306. inline pkgCache::PkgFileIterator pkgCache::FileBegin()
  307. {return PkgFileIterator(*this,PkgFileP + HeaderP->FileList);};
  308. inline pkgCache::PkgFileIterator pkgCache::FileEnd()
  309. {return PkgFileIterator(*this,PkgFileP);};
  310. // Oh I wish for Real Name Space Support
  311. class pkgCache::Namespace /*{{{*/
  312. {
  313. public:
  314. typedef pkgCache::GrpIterator GrpIterator;
  315. typedef pkgCache::PkgIterator PkgIterator;
  316. typedef pkgCache::VerIterator VerIterator;
  317. typedef pkgCache::DescIterator DescIterator;
  318. typedef pkgCache::DepIterator DepIterator;
  319. typedef pkgCache::PrvIterator PrvIterator;
  320. typedef pkgCache::PkgFileIterator PkgFileIterator;
  321. typedef pkgCache::VerFileIterator VerFileIterator;
  322. typedef pkgCache::Version Version;
  323. typedef pkgCache::Description Description;
  324. typedef pkgCache::Package Package;
  325. typedef pkgCache::Header Header;
  326. typedef pkgCache::Dep Dep;
  327. typedef pkgCache::Flag Flag;
  328. };
  329. /*}}}*/
  330. #endif