You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

210 lines
8.2 KiB

  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. /* ######################################################################
  4. Package Cache Generator - Generator for the cache structure.
  5. This builds the cache structure from the abstract package list parser.
  6. Each archive source has it's own list parser that is instantiated by
  7. the caller to provide data for the generator.
  8. Parts of the cache are created by this generator class while other
  9. parts are created by the list parser. The list parser is responsible
  10. for creating version, depends and provides structures, and some of
  11. their contents
  12. ##################################################################### */
  13. /*}}}*/
  14. #ifndef PKGLIB_PKGCACHEGEN_H
  15. #define PKGLIB_PKGCACHEGEN_H
  16. #include <apt-pkg/md5.h>
  17. #include <apt-pkg/mmap.h>
  18. #include <apt-pkg/pkgcache.h>
  19. #include <apt-pkg/cacheiterators.h>
  20. #include <apt-pkg/macros.h>
  21. #include <vector>
  22. #include <string>
  23. #include <map>
  24. class FileFd;
  25. class pkgSourceList;
  26. class OpProgress;
  27. class pkgIndexFile;
  28. class APT_HIDDEN pkgCacheGenerator /*{{{*/
  29. {
  30. private:
  31. APT_HIDDEN map_stringitem_t WriteStringInMap(std::string const &String) { return WriteStringInMap(String.c_str()); };
  32. APT_HIDDEN map_stringitem_t WriteStringInMap(const char *String);
  33. APT_HIDDEN map_stringitem_t WriteStringInMap(const char *String, const unsigned long &Len);
  34. APT_HIDDEN map_pointer_t AllocateInMap(const unsigned long &size);
  35. std::map<std::string,map_stringitem_t> strMixed;
  36. std::map<std::string,map_stringitem_t> strSections;
  37. std::map<std::string,map_stringitem_t> strPkgNames;
  38. std::map<std::string,map_stringitem_t> strVersions;
  39. public:
  40. class ListParser;
  41. friend class ListParser;
  42. template<typename Iter> class Dynamic {
  43. public:
  44. static std::vector<Iter*> toReMap;
  45. explicit Dynamic(Iter &I) {
  46. toReMap.push_back(&I);
  47. }
  48. ~Dynamic() {
  49. toReMap.pop_back();
  50. }
  51. };
  52. protected:
  53. DynamicMMap &Map;
  54. pkgCache Cache;
  55. OpProgress *Progress;
  56. std::string RlsFileName;
  57. pkgCache::ReleaseFile *CurrentRlsFile;
  58. std::string PkgFileName;
  59. pkgCache::PackageFile *CurrentFile;
  60. // Flag file dependencies
  61. bool FoundFileDeps;
  62. bool NewGroup(pkgCache::GrpIterator &Grp,const std::string &Name);
  63. bool NewPackage(pkgCache::PkgIterator &Pkg,const std::string &Name, const std::string &Arch);
  64. bool NewFileVer(pkgCache::VerIterator &Ver,ListParser &List);
  65. bool NewFileDesc(pkgCache::DescIterator &Desc,ListParser &List);
  66. bool NewDepends(pkgCache::PkgIterator &Pkg, pkgCache::VerIterator &Ver,
  67. map_pointer_t const Version, uint8_t const Op,
  68. uint8_t const Type, map_pointer_t* &OldDepLast);
  69. map_pointer_t NewVersion(pkgCache::VerIterator &Ver,const std::string &VerStr,map_pointer_t const Next) APT_DEPRECATED
  70. { return NewVersion(Ver, VerStr, 0, 0, Next); }
  71. map_pointer_t NewVersion(pkgCache::VerIterator &Ver,const std::string &VerStr,
  72. map_pointer_t const ParentPkg, unsigned short const Hash,
  73. map_pointer_t const Next);
  74. map_pointer_t NewDescription(pkgCache::DescIterator &Desc,const std::string &Lang,const MD5SumValue &md5sum,map_stringitem_t const idxmd5str);
  75. bool NewProvides(pkgCache::VerIterator &Ver, pkgCache::PkgIterator &Pkg,
  76. map_stringitem_t const ProvidesVersion, uint8_t const Flags);
  77. public:
  78. enum StringType { MIXED, PKGNAME, VERSIONNUMBER, SECTION };
  79. map_stringitem_t StoreString(StringType const type, const char * S, unsigned int const Size);
  80. inline map_stringitem_t StoreString(enum StringType const type, const std::string &S) {return StoreString(type, S.c_str(),S.length());};
  81. void DropProgress() {Progress = 0;};
  82. bool SelectFile(const std::string &File,pkgIndexFile const &Index, std::string const &Architecture, std::string const &Component, unsigned long Flags = 0);
  83. bool SelectReleaseFile(const std::string &File, const std::string &Site, unsigned long Flags = 0);
  84. bool MergeList(ListParser &List,pkgCache::VerIterator *Ver = 0);
  85. inline pkgCache &GetCache() {return Cache;};
  86. inline pkgCache::PkgFileIterator GetCurFile()
  87. {return pkgCache::PkgFileIterator(Cache,CurrentFile);};
  88. inline pkgCache::RlsFileIterator GetCurRlsFile()
  89. {return pkgCache::RlsFileIterator(Cache,CurrentRlsFile);};
  90. bool HasFileDeps() {return FoundFileDeps;};
  91. bool MergeFileProvides(ListParser &List);
  92. bool FinishCache(OpProgress *Progress) APT_DEPRECATED APT_CONST;
  93. APT_PUBLIC static bool MakeStatusCache(pkgSourceList &List,OpProgress *Progress,
  94. MMap **OutMap = 0,bool AllowMem = false);
  95. APT_PUBLIC static bool MakeOnlyStatusCache(OpProgress *Progress,DynamicMMap **OutMap);
  96. void ReMap(void const * const oldMap, void const * const newMap);
  97. pkgCacheGenerator(DynamicMMap *Map,OpProgress *Progress);
  98. virtual ~pkgCacheGenerator();
  99. private:
  100. void * const d;
  101. APT_HIDDEN bool MergeListGroup(ListParser &List, std::string const &GrpName);
  102. APT_HIDDEN bool MergeListPackage(ListParser &List, pkgCache::PkgIterator &Pkg);
  103. APT_HIDDEN bool MergeListVersion(ListParser &List, pkgCache::PkgIterator &Pkg,
  104. std::string const &Version, pkgCache::VerIterator* &OutVer);
  105. APT_HIDDEN bool AddImplicitDepends(pkgCache::GrpIterator &G, pkgCache::PkgIterator &P,
  106. pkgCache::VerIterator &V);
  107. APT_HIDDEN bool AddImplicitDepends(pkgCache::VerIterator &V, pkgCache::PkgIterator &D);
  108. APT_HIDDEN bool AddNewDescription(ListParser &List, pkgCache::VerIterator &Ver,
  109. std::string const &lang, MD5SumValue const &CurMd5, map_stringitem_t &md5idx);
  110. };
  111. /*}}}*/
  112. // This is the abstract package list parser class. /*{{{*/
  113. class APT_HIDDEN pkgCacheGenerator::ListParser
  114. {
  115. pkgCacheGenerator *Owner;
  116. friend class pkgCacheGenerator;
  117. // Some cache items
  118. pkgCache::VerIterator OldDepVer;
  119. map_pointer_t *OldDepLast;
  120. // Flag file dependencies
  121. bool FoundFileDeps;
  122. void * const d;
  123. protected:
  124. inline map_stringitem_t StoreString(pkgCacheGenerator::StringType const type, std::string const &S) {return Owner->StoreString(type, S);};
  125. inline map_stringitem_t StoreString(pkgCacheGenerator::StringType const type, const char *S,unsigned int Size) {return Owner->StoreString(type, S, Size);};
  126. inline map_stringitem_t WriteString(const std::string &S) {return Owner->WriteStringInMap(S);};
  127. inline map_stringitem_t WriteString(const char *S,unsigned int Size) {return Owner->WriteStringInMap(S,Size);};
  128. bool NewDepends(pkgCache::VerIterator &Ver,const std::string &Package, const std::string &Arch,
  129. const std::string &Version,uint8_t const Op,
  130. uint8_t const Type);
  131. bool NewProvides(pkgCache::VerIterator &Ver,const std::string &PkgName,
  132. const std::string &PkgArch, const std::string &Version,
  133. uint8_t const Flags);
  134. bool NewProvidesAllArch(pkgCache::VerIterator &Ver, std::string const &Package,
  135. std::string const &Version, uint8_t const Flags);
  136. public:
  137. // These all operate against the current section
  138. virtual std::string Package() = 0;
  139. virtual std::string Architecture() = 0;
  140. virtual bool ArchitectureAll() = 0;
  141. virtual std::string Version() = 0;
  142. virtual bool NewVersion(pkgCache::VerIterator &Ver) = 0;
  143. virtual std::string Description(std::string const &lang) = 0;
  144. virtual std::vector<std::string> AvailableDescriptionLanguages() = 0;
  145. virtual MD5SumValue Description_md5() = 0;
  146. virtual unsigned short VersionHash() = 0;
  147. /** compare currently parsed version with given version
  148. *
  149. * \param Hash of the currently parsed version
  150. * \param Ver to compare with
  151. */
  152. virtual bool SameVersion(unsigned short const Hash, pkgCache::VerIterator const &Ver);
  153. virtual bool UsePackage(pkgCache::PkgIterator &Pkg,
  154. pkgCache::VerIterator &Ver) = 0;
  155. virtual map_filesize_t Offset() = 0;
  156. virtual map_filesize_t Size() = 0;
  157. virtual bool Step() = 0;
  158. inline bool HasFileDeps() {return FoundFileDeps;};
  159. virtual bool CollectFileProvides(pkgCache &/*Cache*/,
  160. pkgCache::VerIterator &/*Ver*/) {return true;};
  161. ListParser();
  162. virtual ~ListParser();
  163. };
  164. /*}}}*/
  165. bool pkgMakeStatusCache(pkgSourceList &List,OpProgress &Progress,
  166. MMap **OutMap = 0,bool AllowMem = false);
  167. bool pkgMakeOnlyStatusCache(OpProgress &Progress,DynamicMMap **OutMap);
  168. #endif