pkgcache.h 10 KB

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