pkgcache.h 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703
  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. /**\file pkgcache.h
  4. \brief pkgCache - Structure definitions for the cache file
  5. The goal of the cache file is two fold:
  6. Firstly to speed loading and processing of the package file array and
  7. secondly to reduce memory consumption of the package file array.
  8. The implementation is aimed at an environment with many primary package
  9. files, for instance someone that has a Package file for their CD-ROM, a
  10. Package file for the latest version of the distribution on the CD-ROM and a
  11. package file for the development version. Always present is the information
  12. contained in the status file which might be considered a separate package
  13. file.
  14. Please understand, this is designed as a <b>Cache file</b> it is not meant to be
  15. used on any system other than the one it was created for. It is not meant to
  16. be authoritative either, i.e. if a system crash or software failure occurs it
  17. must be perfectly acceptable for the cache file to be in an inconsistent
  18. state. Furthermore at any time the cache file may be erased without losing
  19. any information.
  20. Also the structures and storage layout is optimized for use by the APT
  21. and may not be suitable for all purposes. However it should be possible
  22. to extend it with associate cache files that contain other information.
  23. To keep memory use down the cache file only contains often used fields and
  24. fields that are inexpensive to store, the Package file has a full list of
  25. fields. Also the client may assume that all items are perfectly valid and
  26. need not perform checks against their correctness. Removal of information
  27. from the cache is possible, but blanks will be left in the file, and
  28. unused strings will also be present. The recommended implementation is to
  29. simply rebuild the cache each time any of the data files change. It is
  30. possible to add a new package file to the cache without any negative side
  31. effects.
  32. <b>Note on Pointer access</b>
  33. Clients should always use the CacheIterators classes for access to the
  34. cache and the data in it. They also provide a simple STL-like method for
  35. traversing the links of the datastructure.
  36. Every item in every structure is stored as the index to that structure.
  37. What this means is that once the files is mmaped every data access has to
  38. go through a fix up stage to get a real memory pointer. This is done
  39. by taking the index, multiplying it by the type size and then adding
  40. it to the start address of the memory block. This sounds complex, but
  41. in C it is a single array dereference. Because all items are aligned to
  42. their size and indexes are stored as multiples of the size of the structure
  43. the format is immediately portable to all possible architectures - BUT the
  44. generated files are -NOT-.
  45. This scheme allows code like this to be written:
  46. <example>
  47. void *Map = mmap(...);
  48. Package *PkgList = (Package *)Map;
  49. Header *Head = (Header *)Map;
  50. char *Strings = (char *)Map;
  51. cout << (Strings + PkgList[Head->HashTable[0]]->Name) << endl;
  52. </example>
  53. Notice the lack of casting or multiplication. The net result is to return
  54. the name of the first package in the first hash bucket, without error
  55. checks.
  56. The generator uses allocation pools to group similarly sized structures in
  57. large blocks to eliminate any alignment overhead. The generator also
  58. assures that no structures overlap and all indexes are unique. Although
  59. at first glance it may seem like there is the potential for two structures
  60. to exist at the same point the generator never allows this to happen.
  61. (See the discussion of free space pools)
  62. See \ref pkgcachegen.h for more information about generating cache structures. */
  63. /*}}}*/
  64. #ifndef PKGLIB_PKGCACHE_H
  65. #define PKGLIB_PKGCACHE_H
  66. #include <string>
  67. #include <time.h>
  68. #include <apt-pkg/mmap.h>
  69. #ifndef APT_8_CLEANER_HEADERS
  70. using std::string;
  71. #endif
  72. class pkgVersioningSystem;
  73. class pkgCache /*{{{*/
  74. {
  75. public:
  76. // Cache element predeclarations
  77. struct Header;
  78. struct Group;
  79. struct Package;
  80. struct PackageFile;
  81. struct Version;
  82. struct Description;
  83. struct Provides;
  84. struct Dependency;
  85. struct StringItem;
  86. struct VerFile;
  87. struct DescFile;
  88. // Iterators
  89. template<typename Str, typename Itr> class Iterator;
  90. class GrpIterator;
  91. class PkgIterator;
  92. class VerIterator;
  93. class DescIterator;
  94. class DepIterator;
  95. class PrvIterator;
  96. class PkgFileIterator;
  97. class VerFileIterator;
  98. class DescFileIterator;
  99. class Namespace;
  100. // These are all the constants used in the cache structures
  101. // WARNING - if you change these lists you must also edit
  102. // the stringification in pkgcache.cc and also consider whether
  103. // the cache file will become incompatible.
  104. struct Dep
  105. {
  106. enum DepType {Depends=1,PreDepends=2,Suggests=3,Recommends=4,
  107. Conflicts=5,Replaces=6,Obsoletes=7,DpkgBreaks=8,Enhances=9};
  108. /** \brief available compare operators
  109. The lower 4 bits are used to indicate what operator is being specified and
  110. the upper 4 bits are flags. OR indicates that the next package is
  111. or'd with the current package. */
  112. enum DepCompareOp {Or=0x10,NoOp=0,LessEq=0x1,GreaterEq=0x2,Less=0x3,
  113. Greater=0x4,Equals=0x5,NotEquals=0x6};
  114. };
  115. struct State
  116. {
  117. /** \brief priority of a package version
  118. Zero is used for unparsable or absent Priority fields. */
  119. enum VerPriority {Important=1,Required=2,Standard=3,Optional=4,Extra=5};
  120. enum PkgSelectedState {Unknown=0,Install=1,Hold=2,DeInstall=3,Purge=4};
  121. enum PkgInstState {Ok=0,ReInstReq=1,HoldInst=2,HoldReInstReq=3};
  122. enum PkgCurrentState {NotInstalled=0,UnPacked=1,HalfConfigured=2,
  123. HalfInstalled=4,ConfigFiles=5,Installed=6,
  124. TriggersAwaited=7,TriggersPending=8};
  125. };
  126. struct Flag
  127. {
  128. enum PkgFlags {Auto=(1<<0),Essential=(1<<3),Important=(1<<4)};
  129. enum PkgFFlags {NotSource=(1<<0),NotAutomatic=(1<<1),ButAutomaticUpgrades=(1<<2)};
  130. };
  131. protected:
  132. // Memory mapped cache file
  133. std::string CacheFile;
  134. MMap &Map;
  135. unsigned long sHash(const std::string &S) const;
  136. unsigned long sHash(const char *S) const;
  137. public:
  138. // Pointers to the arrays of items
  139. Header *HeaderP;
  140. Group *GrpP;
  141. Package *PkgP;
  142. VerFile *VerFileP;
  143. DescFile *DescFileP;
  144. PackageFile *PkgFileP;
  145. Version *VerP;
  146. Description *DescP;
  147. Provides *ProvideP;
  148. Dependency *DepP;
  149. StringItem *StringItemP;
  150. char *StrP;
  151. virtual bool ReMap(bool const &Errorchecks = true);
  152. inline bool Sync() {return Map.Sync();};
  153. inline MMap &GetMap() {return Map;};
  154. inline void *DataEnd() {return ((unsigned char *)Map.Data()) + Map.Size();};
  155. // String hashing function (512 range)
  156. inline unsigned long Hash(const std::string &S) const {return sHash(S);};
  157. inline unsigned long Hash(const char *S) const {return sHash(S);};
  158. // Useful transformation things
  159. const char *Priority(unsigned char Priority);
  160. // Accessors
  161. GrpIterator FindGrp(const std::string &Name);
  162. PkgIterator FindPkg(const std::string &Name);
  163. PkgIterator FindPkg(const std::string &Name, const std::string &Arch);
  164. Header &Head() {return *HeaderP;};
  165. inline GrpIterator GrpBegin();
  166. inline GrpIterator GrpEnd();
  167. inline PkgIterator PkgBegin();
  168. inline PkgIterator PkgEnd();
  169. inline PkgFileIterator FileBegin();
  170. inline PkgFileIterator FileEnd();
  171. inline bool MultiArchCache() const { return MultiArchEnabled; };
  172. inline char const * const NativeArch() const;
  173. // Make me a function
  174. pkgVersioningSystem *VS;
  175. // Converters
  176. static const char *CompTypeDeb(unsigned char Comp);
  177. static const char *CompType(unsigned char Comp);
  178. static const char *DepType(unsigned char Dep);
  179. pkgCache(MMap *Map,bool DoMap = true);
  180. virtual ~pkgCache() {};
  181. private:
  182. bool MultiArchEnabled;
  183. PkgIterator SingleArchFindPkg(const std::string &Name);
  184. };
  185. /*}}}*/
  186. // Header structure /*{{{*/
  187. struct pkgCache::Header
  188. {
  189. /** \brief Signature information
  190. This must contain the hex value 0x98FE76DC which is designed to
  191. verify that the system loading the image has the same byte order
  192. and byte size as the system saving the image */
  193. unsigned long Signature;
  194. /** These contain the version of the cache file */
  195. short MajorVersion;
  196. short MinorVersion;
  197. /** \brief indicates if the cache should be erased
  198. Dirty is true if the cache file was opened for reading, the client
  199. expects to have written things to it and have not fully synced it.
  200. The file should be erased and rebuilt if it is true. */
  201. bool Dirty;
  202. /** \brief Size of structure values
  203. All *Sz variables contains the sizeof() that particular structure.
  204. It is used as an extra consistency check on the structure of the file.
  205. If any of the size values do not exactly match what the client expects
  206. then the client should refuse the load the file. */
  207. unsigned short HeaderSz;
  208. unsigned short GroupSz;
  209. unsigned short PackageSz;
  210. unsigned short PackageFileSz;
  211. unsigned short VersionSz;
  212. unsigned short DescriptionSz;
  213. unsigned short DependencySz;
  214. unsigned short ProvidesSz;
  215. unsigned short VerFileSz;
  216. unsigned short DescFileSz;
  217. /** \brief Structure counts
  218. These indicate the number of each structure contained in the cache.
  219. PackageCount is especially useful for generating user state structures.
  220. See Package::Id for more info. */
  221. unsigned long GroupCount;
  222. unsigned long PackageCount;
  223. unsigned long VersionCount;
  224. unsigned long DescriptionCount;
  225. unsigned long DependsCount;
  226. unsigned long PackageFileCount;
  227. unsigned long VerFileCount;
  228. unsigned long DescFileCount;
  229. unsigned long ProvidesCount;
  230. /** \brief index of the first PackageFile structure
  231. The PackageFile structures are singly linked lists that represent
  232. all package files that have been merged into the cache. */
  233. map_ptrloc FileList;
  234. /** \brief index of the first StringItem structure
  235. The cache contains a list of all the unique strings (StringItems).
  236. The parser reads this list into memory so it can match strings
  237. against it.*/
  238. map_ptrloc StringList;
  239. /** \brief String representing the version system used */
  240. map_ptrloc VerSysName;
  241. /** \brief Architecture(s) the cache was built against */
  242. map_ptrloc Architecture;
  243. /** \brief The maximum size of a raw entry from the original Package file */
  244. unsigned long MaxVerFileSize;
  245. /** \brief The maximum size of a raw entry from the original Translation file */
  246. unsigned long MaxDescFileSize;
  247. /** \brief The Pool structures manage the allocation pools that the generator uses
  248. Start indicates the first byte of the pool, Count is the number of objects
  249. remaining in the pool and ItemSize is the structure size (alignment factor)
  250. of the pool. An ItemSize of 0 indicates the pool is empty. There should be
  251. the same number of pools as there are structure types. The generator
  252. stores this information so future additions can make use of any unused pool
  253. blocks. */
  254. DynamicMMap::Pool Pools[9];
  255. /** \brief hash tables providing rapid group/package name lookup
  256. Each group/package name is inserted into the hash table using pkgCache::Hash(const &string)
  257. By iterating over each entry in the hash table it is possible to iterate over
  258. the entire list of packages. Hash Collisions are handled with a singly linked
  259. list of packages based at the hash item. The linked list contains only
  260. packages that match the hashing function.
  261. In the PkgHashTable is it possible that multiple packages have the same name -
  262. these packages are stored as a sequence in the list.
  263. Beware: The Hashmethod assumes that the hash table sizes are equal */
  264. map_ptrloc PkgHashTable[2*1048];
  265. map_ptrloc GrpHashTable[2*1048];
  266. /** \brief Size of the complete cache file */
  267. unsigned long CacheFileSize;
  268. bool CheckSizes(Header &Against) const;
  269. Header();
  270. };
  271. /*}}}*/
  272. // Group structure /*{{{*/
  273. /** \brief groups architecture depending packages together
  274. On or more packages with the same name form a group, so we have
  275. a simple way to access a package built for different architectures
  276. Group exists in a singly linked list of group records starting at
  277. the hash index of the name in the pkgCache::Header::GrpHashTable */
  278. struct pkgCache::Group
  279. {
  280. /** \brief Name of the group */
  281. map_ptrloc Name; // StringItem
  282. // Linked List
  283. /** \brief Link to the first package which belongs to the group */
  284. map_ptrloc FirstPackage; // Package
  285. /** \brief Link to the last package which belongs to the group */
  286. map_ptrloc LastPackage; // Package
  287. /** \brief Link to the next Group */
  288. map_ptrloc Next; // Group
  289. /** \brief unique sequel ID */
  290. unsigned int ID;
  291. };
  292. /*}}}*/
  293. // Package structure /*{{{*/
  294. /** \brief contains information for a single unique package
  295. There can be any number of versions of a given package.
  296. Package exists in a singly linked list of package records starting at
  297. the hash index of the name in the pkgCache::Header::PkgHashTable
  298. A package can be created for every architecture so package names are
  299. not unique, but it is guaranteed that packages with the same name
  300. are sequencel ordered in the list. Packages with the same name can be
  301. accessed with the Group.
  302. */
  303. struct pkgCache::Package
  304. {
  305. /** \brief Name of the package */
  306. map_ptrloc Name; // StringItem
  307. /** \brief Architecture of the package */
  308. map_ptrloc Arch; // StringItem
  309. /** \brief Base of a singly linked list of versions
  310. Each structure represents a unique version of the package.
  311. The version structures contain links into PackageFile and the
  312. original text file as well as detailed information about the size
  313. and dependencies of the specific package. In this way multiple
  314. versions of a package can be cleanly handled by the system.
  315. Furthermore, this linked list is guaranteed to be sorted
  316. from Highest version to lowest version with no duplicate entries. */
  317. map_ptrloc VersionList; // Version
  318. /** \brief index to the installed version */
  319. map_ptrloc CurrentVer; // Version
  320. /** \brief indicates the deduced section
  321. Should be the index to the string "Unknown" or to the section
  322. of the last parsed item. */
  323. map_ptrloc Section; // StringItem
  324. /** \brief index of the group this package belongs to */
  325. map_ptrloc Group; // Group the Package belongs to
  326. // Linked list
  327. /** \brief Link to the next package in the same bucket */
  328. map_ptrloc NextPackage; // Package
  329. /** \brief List of all dependencies on this package */
  330. map_ptrloc RevDepends; // Dependency
  331. /** \brief List of all "packages" this package provide */
  332. map_ptrloc ProvidesList; // Provides
  333. // Install/Remove/Purge etc
  334. /** \brief state that the user wishes the package to be in */
  335. unsigned char SelectedState; // What
  336. /** \brief installation state of the package
  337. This should be "ok" but in case the installation failed
  338. it will be different.
  339. */
  340. unsigned char InstState; // Flags
  341. /** \brief indicates if the package is installed */
  342. unsigned char CurrentState; // State
  343. /** \brief unique sequel ID
  344. ID is a unique value from 0 to Header->PackageCount assigned by the generator.
  345. This allows clients to create an array of size PackageCount and use it to store
  346. state information for the package map. For instance the status file emitter uses
  347. this to track which packages have been emitted already. */
  348. unsigned int ID;
  349. /** \brief some useful indicators of the package's state */
  350. unsigned long Flags;
  351. };
  352. /*}}}*/
  353. // Package File structure /*{{{*/
  354. /** \brief stores information about the files used to generate the cache
  355. Package files are referenced by Version structures to be able to know
  356. after the generation still from which Packages file includes this Version
  357. as we need this information later on e.g. for pinning. */
  358. struct pkgCache::PackageFile
  359. {
  360. /** \brief physical disk file that this PackageFile represents */
  361. map_ptrloc FileName; // StringItem
  362. /** \brief the release information
  363. Please see the files document for a description of what the
  364. release information means. */
  365. map_ptrloc Archive; // StringItem
  366. map_ptrloc Codename; // StringItem
  367. map_ptrloc Component; // StringItem
  368. map_ptrloc Version; // StringItem
  369. map_ptrloc Origin; // StringItem
  370. map_ptrloc Label; // StringItem
  371. map_ptrloc Architecture; // StringItem
  372. /** \brief The site the index file was fetched from */
  373. map_ptrloc Site; // StringItem
  374. /** \brief indicates what sort of index file this is
  375. @TODO enumerate at least the possible indexes */
  376. map_ptrloc IndexType; // StringItem
  377. /** \brief Size of the file
  378. Used together with the modification time as a
  379. simple check to ensure that the Packages
  380. file has not been altered since Cache generation. */
  381. unsigned long Size;
  382. /** \brief Modification time for the file */
  383. time_t mtime;
  384. /* @TODO document PackageFile::Flags */
  385. unsigned long Flags;
  386. // Linked list
  387. /** \brief Link to the next PackageFile in the Cache */
  388. map_ptrloc NextFile; // PackageFile
  389. /** \brief unique sequel ID */
  390. unsigned int ID;
  391. };
  392. /*}}}*/
  393. // VerFile structure /*{{{*/
  394. /** \brief associates a version with a PackageFile
  395. This allows a full description of all Versions in all files
  396. (and hence all sources) under consideration. */
  397. struct pkgCache::VerFile
  398. {
  399. /** \brief index of the package file that this version was found in */
  400. map_ptrloc File; // PackageFile
  401. /** \brief next step in the linked list */
  402. map_ptrloc NextFile; // PkgVerFile
  403. /** \brief position in the package file */
  404. map_ptrloc Offset; // File offset
  405. /* @TODO document pkgCache::VerFile::Size */
  406. unsigned long Size;
  407. };
  408. /*}}}*/
  409. // DescFile structure /*{{{*/
  410. /** \brief associates a description with a Translation file */
  411. struct pkgCache::DescFile
  412. {
  413. /** \brief index of the file that this description was found in */
  414. map_ptrloc File; // PackageFile
  415. /** \brief next step in the linked list */
  416. map_ptrloc NextFile; // PkgVerFile
  417. /** \brief position in the file */
  418. map_ptrloc Offset; // File offset
  419. /* @TODO document pkgCache::DescFile::Size */
  420. unsigned long Size;
  421. };
  422. /*}}}*/
  423. // Version structure /*{{{*/
  424. /** \brief information for a single version of a package
  425. The version list is always sorted from highest version to lowest
  426. version by the generator. Equal version numbers are either merged
  427. or handled as separate versions based on the Hash value. */
  428. struct pkgCache::Version
  429. {
  430. /** \brief complete version string */
  431. map_ptrloc VerStr; // StringItem
  432. /** \brief section this version is filled in */
  433. map_ptrloc Section; // StringItem
  434. /** \brief Multi-Arch capabilities of a package version */
  435. enum VerMultiArch { None = 0, /*!< is the default and doesn't trigger special behaviour */
  436. All = (1<<0), /*!< will cause that Ver.Arch() will report "all" */
  437. Foreign = (1<<1), /*!< can satisfy dependencies in another architecture */
  438. Same = (1<<2), /*!< can be co-installed with itself from other architectures */
  439. Allowed = (1<<3), /*!< other packages are allowed to depend on thispkg:any */
  440. AllForeign = All | Foreign,
  441. AllAllowed = All | Allowed };
  442. /** \brief stores the MultiArch capabilities of this version
  443. Flags used are defined in pkgCache::Version::VerMultiArch
  444. */
  445. unsigned char MultiArch;
  446. /** \brief references all the PackageFile's that this version came from
  447. FileList can be used to determine what distribution(s) the Version
  448. applies to. If FileList is 0 then this is a blank version.
  449. The structure should also have a 0 in all other fields excluding
  450. pkgCache::Version::VerStr and Possibly pkgCache::Version::NextVer. */
  451. map_ptrloc FileList; // VerFile
  452. /** \brief next (lower or equal) version in the linked list */
  453. map_ptrloc NextVer; // Version
  454. /** \brief next description in the linked list */
  455. map_ptrloc DescriptionList; // Description
  456. /** \brief base of the dependency list */
  457. map_ptrloc DependsList; // Dependency
  458. /** \brief links to the owning package
  459. This allows reverse dependencies to determine the package */
  460. map_ptrloc ParentPkg; // Package
  461. /** \brief list of pkgCache::Provides */
  462. map_ptrloc ProvidesList; // Provides
  463. /** \brief archive size for this version
  464. For Debian this is the size of the .deb file. */
  465. unsigned long long Size; // These are the .deb size
  466. /** \brief uncompressed size for this version */
  467. unsigned long long InstalledSize;
  468. /** \brief characteristic value representing this version
  469. No two packages in existence should have the same VerStr
  470. and Hash with different contents. */
  471. unsigned short Hash;
  472. /** \brief unique sequel ID */
  473. unsigned int ID;
  474. /** \brief parsed priority value */
  475. unsigned char Priority;
  476. };
  477. /*}}}*/
  478. // Description structure /*{{{*/
  479. /** \brief datamember of a linked list of available description for a version */
  480. struct pkgCache::Description
  481. {
  482. /** \brief Language code of this description (translation)
  483. If the value has a 0 length then this is read using the Package
  484. file else the Translation-CODE file is used. */
  485. map_ptrloc language_code; // StringItem
  486. /** \brief MD5sum of the original description
  487. Used to map Translations of a description to a version
  488. and to check that the Translation is up-to-date. */
  489. map_ptrloc md5sum; // StringItem
  490. /* @TODO document pkgCache::Description::FileList */
  491. map_ptrloc FileList; // DescFile
  492. /** \brief next translation for this description */
  493. map_ptrloc NextDesc; // Description
  494. /** \brief the text is a description of this package */
  495. map_ptrloc ParentPkg; // Package
  496. /** \brief unique sequel ID */
  497. unsigned int ID;
  498. };
  499. /*}}}*/
  500. // Dependency structure /*{{{*/
  501. /** \brief information for a single dependency record
  502. The records are split up like this to ease processing by the client.
  503. The base of the linked list is pkgCache::Version::DependsList.
  504. All forms of dependencies are recorded here including Depends,
  505. Recommends, Suggests, Enhances, Conflicts, Replaces and Breaks. */
  506. struct pkgCache::Dependency
  507. {
  508. /** \brief string of the version the dependency is applied against */
  509. map_ptrloc Version; // StringItem
  510. /** \brief index of the package this depends applies to
  511. The generator will - if the package does not already exist -
  512. create a blank (no version records) package. */
  513. map_ptrloc Package; // Package
  514. /** \brief next dependency of this version */
  515. map_ptrloc NextDepends; // Dependency
  516. /** \brief next reverse dependency of this package */
  517. map_ptrloc NextRevDepends; // Dependency
  518. /** \brief version of the package which has the reverse depends */
  519. map_ptrloc ParentVer; // Version
  520. /** \brief unique sequel ID */
  521. map_ptrloc ID;
  522. /** \brief Dependency type - Depends, Recommends, Conflicts, etc */
  523. unsigned char Type;
  524. /** \brief comparison operator specified on the depends line
  525. If the high bit is set then it is a logical OR with the previous record. */
  526. unsigned char CompareOp;
  527. };
  528. /*}}}*/
  529. // Provides structure /*{{{*/
  530. /** \brief handles virtual packages
  531. When a Provides: line is encountered a new provides record is added
  532. associating the package with a virtual package name.
  533. The provides structures are linked off the package structures.
  534. This simplifies the analysis of dependencies and other aspects A provides
  535. refers to a specific version of a specific package, not all versions need to
  536. provide that provides.*/
  537. struct pkgCache::Provides
  538. {
  539. /** \brief index of the package providing this */
  540. map_ptrloc ParentPkg; // Package
  541. /** \brief index of the version this provide line applies to */
  542. map_ptrloc Version; // Version
  543. /** \brief version in the provides line (if any)
  544. This version allows dependencies to depend on specific versions of a
  545. Provides, as well as allowing Provides to override existing packages.
  546. This is experimental. Note that Debian doesn't allow versioned provides */
  547. map_ptrloc ProvideVersion; // StringItem
  548. /** \brief next provides (based of package) */
  549. map_ptrloc NextProvides; // Provides
  550. /** \brief next provides (based of version) */
  551. map_ptrloc NextPkgProv; // Provides
  552. };
  553. /*}}}*/
  554. // StringItem structure /*{{{*/
  555. /** \brief used for generating single instances of strings
  556. Some things like Section Name are are useful to have as unique tags.
  557. It is part of a linked list based at pkgCache::Header::StringList
  558. All strings are simply inlined any place in the file that is natural
  559. for the writer. The client should make no assumptions about the positioning
  560. of strings. All StringItems should be null-terminated. */
  561. struct pkgCache::StringItem
  562. {
  563. /** \brief string this refers to */
  564. map_ptrloc String; // StringItem
  565. /** \brief Next link in the chain */
  566. map_ptrloc NextItem; // StringItem
  567. };
  568. /*}}}*/
  569. inline char const * const pkgCache::NativeArch() const
  570. { return StrP + HeaderP->Architecture; };
  571. #include <apt-pkg/cacheiterators.h>
  572. inline pkgCache::GrpIterator pkgCache::GrpBegin()
  573. {return GrpIterator(*this);};
  574. inline pkgCache::GrpIterator pkgCache::GrpEnd()
  575. {return GrpIterator(*this,GrpP);};
  576. inline pkgCache::PkgIterator pkgCache::PkgBegin()
  577. {return PkgIterator(*this);};
  578. inline pkgCache::PkgIterator pkgCache::PkgEnd()
  579. {return PkgIterator(*this,PkgP);};
  580. inline pkgCache::PkgFileIterator pkgCache::FileBegin()
  581. {return PkgFileIterator(*this,PkgFileP + HeaderP->FileList);};
  582. inline pkgCache::PkgFileIterator pkgCache::FileEnd()
  583. {return PkgFileIterator(*this,PkgFileP);};
  584. // Oh I wish for Real Name Space Support
  585. class pkgCache::Namespace /*{{{*/
  586. {
  587. public:
  588. typedef pkgCache::GrpIterator GrpIterator;
  589. typedef pkgCache::PkgIterator PkgIterator;
  590. typedef pkgCache::VerIterator VerIterator;
  591. typedef pkgCache::DescIterator DescIterator;
  592. typedef pkgCache::DepIterator DepIterator;
  593. typedef pkgCache::PrvIterator PrvIterator;
  594. typedef pkgCache::PkgFileIterator PkgFileIterator;
  595. typedef pkgCache::VerFileIterator VerFileIterator;
  596. typedef pkgCache::Version Version;
  597. typedef pkgCache::Description Description;
  598. typedef pkgCache::Package Package;
  599. typedef pkgCache::Header Header;
  600. typedef pkgCache::Dep Dep;
  601. typedef pkgCache::Flag Flag;
  602. };
  603. /*}}}*/
  604. #endif