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.3 KiB

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