pkgcache.h 9.8 KB

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