pkgcache.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  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,Enhances=9};
  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. /*}}}*/
  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 PackageCount;
  143. unsigned long VersionCount;
  144. unsigned long DescriptionCount;
  145. unsigned long DependsCount;
  146. unsigned long PackageFileCount;
  147. unsigned long VerFileCount;
  148. unsigned long DescFileCount;
  149. unsigned long ProvidesCount;
  150. // Offsets
  151. map_ptrloc FileList; // struct PackageFile
  152. map_ptrloc StringList; // struct StringItem
  153. map_ptrloc VerSysName; // StringTable
  154. map_ptrloc Architecture; // StringTable
  155. unsigned long MaxVerFileSize;
  156. unsigned long MaxDescFileSize;
  157. /* Allocation pools, there should be one of these for each structure
  158. excluding the header */
  159. DynamicMMap::Pool Pools[8];
  160. // Rapid package name lookup
  161. map_ptrloc HashTable[2*1048];
  162. bool CheckSizes(Header &Against) const;
  163. Header();
  164. };
  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 int ID;
  182. unsigned long Flags;
  183. };
  184. /*}}}*/
  185. struct pkgCache::PackageFile /*{{{*/
  186. {
  187. // Names
  188. map_ptrloc FileName; // Stringtable
  189. map_ptrloc Archive; // Stringtable
  190. map_ptrloc Codename; // Stringtable
  191. map_ptrloc Component; // Stringtable
  192. map_ptrloc Version; // Stringtable
  193. map_ptrloc Origin; // Stringtable
  194. map_ptrloc Label; // Stringtable
  195. map_ptrloc Architecture; // Stringtable
  196. map_ptrloc Site; // Stringtable
  197. map_ptrloc IndexType; // Stringtable
  198. unsigned long Size;
  199. unsigned long Flags;
  200. // Linked list
  201. map_ptrloc NextFile; // PackageFile
  202. unsigned int ID;
  203. time_t mtime; // Modification time for the file
  204. };
  205. /*}}}*/
  206. struct pkgCache::VerFile /*{{{*/
  207. {
  208. map_ptrloc File; // PackageFile
  209. map_ptrloc NextFile; // PkgVerFile
  210. map_ptrloc Offset; // File offset
  211. unsigned long Size;
  212. };
  213. /*}}}*/
  214. struct pkgCache::DescFile /*{{{*/
  215. {
  216. map_ptrloc File; // PackageFile
  217. map_ptrloc NextFile; // PkgVerFile
  218. map_ptrloc Offset; // File offset
  219. unsigned long Size;
  220. };
  221. /*}}}*/
  222. struct pkgCache::Version /*{{{*/
  223. {
  224. map_ptrloc VerStr; // Stringtable
  225. map_ptrloc Section; // StringTable (StringItem)
  226. map_ptrloc Arch; // StringTable
  227. // Lists
  228. map_ptrloc FileList; // VerFile
  229. map_ptrloc NextVer; // Version
  230. map_ptrloc DescriptionList; // Description
  231. map_ptrloc DependsList; // Dependency
  232. map_ptrloc ParentPkg; // Package
  233. map_ptrloc ProvidesList; // Provides
  234. map_ptrloc Size; // These are the .deb size
  235. map_ptrloc InstalledSize;
  236. unsigned short Hash;
  237. unsigned int ID;
  238. unsigned char Priority;
  239. };
  240. /*}}}*/
  241. struct pkgCache::Description /*{{{*/
  242. {
  243. // Language Code store the description translation language code. If
  244. // the value has a 0 lenght then this is readed using the Package
  245. // file else the Translation-CODE are used.
  246. map_ptrloc language_code; // StringTable
  247. map_ptrloc md5sum; // StringTable
  248. // Linked list
  249. map_ptrloc FileList; // DescFile
  250. map_ptrloc NextDesc; // Description
  251. map_ptrloc ParentPkg; // Package
  252. unsigned int ID;
  253. };
  254. /*}}}*/
  255. struct pkgCache::Dependency /*{{{*/
  256. {
  257. map_ptrloc Version; // Stringtable
  258. map_ptrloc Package; // Package
  259. map_ptrloc NextDepends; // Dependency
  260. map_ptrloc NextRevDepends; // Dependency
  261. map_ptrloc ParentVer; // Version
  262. // Specific types of depends
  263. map_ptrloc ID;
  264. unsigned char Type;
  265. unsigned char CompareOp;
  266. };
  267. /*}}}*/
  268. struct pkgCache::Provides /*{{{*/
  269. {
  270. map_ptrloc ParentPkg; // Pacakge
  271. map_ptrloc Version; // Version
  272. map_ptrloc ProvideVersion; // Stringtable
  273. map_ptrloc NextProvides; // Provides
  274. map_ptrloc NextPkgProv; // Provides
  275. };
  276. /*}}}*/
  277. struct pkgCache::StringItem /*{{{*/
  278. {
  279. map_ptrloc String; // Stringtable
  280. map_ptrloc NextItem; // StringItem
  281. };
  282. /*}}}*/
  283. #include <apt-pkg/cacheiterators.h>
  284. inline pkgCache::PkgIterator pkgCache::PkgBegin()
  285. {return PkgIterator(*this);};
  286. inline pkgCache::PkgIterator pkgCache::PkgEnd()
  287. {return PkgIterator(*this,PkgP);};
  288. inline pkgCache::PkgFileIterator pkgCache::FileBegin()
  289. {return PkgFileIterator(*this,PkgFileP + HeaderP->FileList);};
  290. inline pkgCache::PkgFileIterator pkgCache::FileEnd()
  291. {return PkgFileIterator(*this,PkgFileP);};
  292. // Oh I wish for Real Name Space Support
  293. class pkgCache::Namespace /*{{{*/
  294. {
  295. public:
  296. typedef pkgCache::PkgIterator PkgIterator;
  297. typedef pkgCache::VerIterator VerIterator;
  298. typedef pkgCache::DescIterator DescIterator;
  299. typedef pkgCache::DepIterator DepIterator;
  300. typedef pkgCache::PrvIterator PrvIterator;
  301. typedef pkgCache::PkgFileIterator PkgFileIterator;
  302. typedef pkgCache::VerFileIterator VerFileIterator;
  303. typedef pkgCache::Version Version;
  304. typedef pkgCache::Description Description;
  305. typedef pkgCache::Package Package;
  306. typedef pkgCache::Header Header;
  307. typedef pkgCache::Dep Dep;
  308. typedef pkgCache::Flag Flag;
  309. };
  310. /*}}}*/
  311. #endif