indexfile.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. /* ######################################################################
  4. Index File - Abstraction for an index of archive/source file.
  5. There are 4 primary sorts of index files, all represented by this
  6. class:
  7. Binary index files
  8. Binary translation files
  9. Binary index files describing the local system
  10. Source index files
  11. They are all bundled together here, and the interfaces for
  12. sources.list, acquire, cache gen and record parsing all use this class
  13. to access the underlying representation.
  14. ##################################################################### */
  15. /*}}}*/
  16. #ifndef PKGLIB_INDEXFILE_H
  17. #define PKGLIB_INDEXFILE_H
  18. #include <apt-pkg/srcrecords.h>
  19. #include <apt-pkg/pkgrecords.h>
  20. #include <apt-pkg/pkgcache.h>
  21. #include <apt-pkg/cacheiterators.h>
  22. #include <apt-pkg/macros.h>
  23. #include <map>
  24. #include <string>
  25. #ifndef APT_8_CLEANER_HEADERS
  26. using std::string;
  27. #endif
  28. #ifndef APT_10_CLEANER_HEADERS
  29. class pkgAcquire;
  30. #endif
  31. class pkgCacheGenerator;
  32. class pkgCacheListParser;
  33. class OpProgress;
  34. class IndexTarget /*{{{*/
  35. /** \brief Information about an index file. */
  36. {
  37. public:
  38. /** \brief A URI from which the index file can be downloaded. */
  39. std::string URI;
  40. /** \brief A description of the index file. */
  41. std::string Description;
  42. /** \brief A shorter description of the index file. */
  43. std::string ShortDesc;
  44. /** \brief The key by which this index file should be
  45. looked up within the meta index file. */
  46. std::string MetaKey;
  47. /** \brief Is it okay if the file isn't found in the meta index */
  48. bool IsOptional;
  49. /** \brief If the file is downloaded compressed, do not unpack it */
  50. bool KeepCompressed;
  51. /** \brief options with which this target was created
  52. Prefer the usage of #Option if at all possible.
  53. Beware: Not all of these options are intended for public use */
  54. std::map<std::string, std::string> Options;
  55. IndexTarget(std::string const &MetaKey, std::string const &ShortDesc,
  56. std::string const &LongDesc, std::string const &URI, bool const IsOptional,
  57. bool const KeepCompressed, std::map<std::string, std::string> const &Options);
  58. enum OptionKeys {
  59. SITE,
  60. RELEASE,
  61. COMPONENT,
  62. LANGUAGE,
  63. ARCHITECTURE,
  64. BASE_URI,
  65. REPO_URI,
  66. CREATED_BY,
  67. TARGET_OF,
  68. FILENAME,
  69. EXISTING_FILENAME,
  70. PDIFFS,
  71. COMPRESSIONTYPES,
  72. DEFAULTENABLED,
  73. SOURCESENTRY,
  74. BY_HASH,
  75. KEEPCOMPRESSEDAS,
  76. FALLBACK_OF,
  77. IDENTIFIER,
  78. ALLOW_INSECURE,
  79. ALLOW_WEAK,
  80. ALLOW_DOWNGRADE_TO_INSECURE,
  81. };
  82. std::string Option(OptionKeys const Key) const;
  83. bool OptionBool(OptionKeys const Key) const;
  84. std::string Format(std::string format) const;
  85. };
  86. /*}}}*/
  87. class pkgIndexFile
  88. {
  89. void * const d;
  90. protected:
  91. bool Trusted;
  92. public:
  93. class Type
  94. {
  95. public:
  96. // Global list of Items supported
  97. static Type **GlobalList;
  98. static unsigned long GlobalListLen;
  99. static Type *GetType(const char * const Type) APT_PURE;
  100. const char *Label;
  101. virtual pkgRecords::Parser *CreatePkgParser(pkgCache::PkgFileIterator const &/*File*/) const {return 0;};
  102. virtual pkgSrcRecords::Parser *CreateSrcPkgParser(std::string const &/*File*/) const {return 0;};
  103. Type();
  104. virtual ~Type() {};
  105. };
  106. virtual const Type *GetType() const = 0;
  107. // Return descriptive strings of various sorts
  108. virtual std::string ArchiveInfo(pkgCache::VerIterator const &Ver) const;
  109. virtual std::string SourceInfo(pkgSrcRecords::Parser const &Record,
  110. pkgSrcRecords::File const &File) const;
  111. virtual std::string Describe(bool const Short = false) const = 0;
  112. // Interface for acquire
  113. virtual std::string ArchiveURI(std::string const &/*File*/) const {return std::string();};
  114. // Interface for the record parsers
  115. virtual pkgSrcRecords::Parser *CreateSrcParser() const {return 0;};
  116. // Interface for the Cache Generator
  117. virtual bool Exists() const = 0;
  118. virtual bool HasPackages() const = 0;
  119. virtual unsigned long Size() const = 0;
  120. virtual bool Merge(pkgCacheGenerator &/*Gen*/, OpProgress* const /*Prog*/) { return true; };
  121. virtual pkgCache::PkgFileIterator FindInCache(pkgCache &Cache) const;
  122. APT_DEPRECATED_MSG("These methods make no sense anymore with multi-language support") static bool TranslationsAvailable();
  123. /* No intern need for this method anymore as the check for correctness
  124. is already done in getLanguages(). Note also that this check is
  125. rather bad (doesn't take three character like ast into account).*/
  126. APT_DEPRECATED_MSG("These methods make no sense anymore with multi-language support") static bool CheckLanguageCode(const char * const Lang);
  127. /* As we have now possibly more than one LanguageCode this method is
  128. superseeded by a) private classmembers or b) getLanguages() */
  129. APT_DEPRECATED_MSG("These methods make no sense anymore with multi-language support") static std::string LanguageCode();
  130. bool IsTrusted() const { return Trusted; };
  131. explicit pkgIndexFile(bool const Trusted);
  132. virtual ~pkgIndexFile();
  133. };
  134. class pkgDebianIndexFile : public pkgIndexFile
  135. {
  136. protected:
  137. virtual std::string IndexFileName() const = 0;
  138. virtual std::string GetComponent() const = 0;
  139. virtual std::string GetArchitecture() const = 0;
  140. virtual std::string GetProgressDescription() const = 0;
  141. virtual uint8_t GetIndexFlags() const = 0;
  142. virtual bool OpenListFile(FileFd &Pkg, std::string const &FileName) = 0;
  143. APT_HIDDEN virtual pkgCacheListParser * CreateListParser(FileFd &Pkg);
  144. public:
  145. virtual bool Merge(pkgCacheGenerator &Gen, OpProgress* const Prog) APT_OVERRIDE;
  146. virtual pkgCache::PkgFileIterator FindInCache(pkgCache &Cache) const APT_OVERRIDE;
  147. explicit pkgDebianIndexFile(bool const Trusted);
  148. virtual ~pkgDebianIndexFile();
  149. };
  150. class pkgDebianIndexTargetFile : public pkgDebianIndexFile
  151. {
  152. void * const d;
  153. protected:
  154. IndexTarget const Target;
  155. virtual std::string IndexFileName() const APT_OVERRIDE;
  156. virtual std::string GetComponent() const APT_OVERRIDE;
  157. virtual std::string GetArchitecture() const APT_OVERRIDE;
  158. virtual std::string GetProgressDescription() const APT_OVERRIDE;
  159. virtual bool OpenListFile(FileFd &Pkg, std::string const &FileName) APT_OVERRIDE;
  160. public:
  161. virtual std::string ArchiveURI(std::string const &File) const APT_OVERRIDE;
  162. virtual std::string Describe(bool const Short = false) const APT_OVERRIDE;
  163. virtual bool Exists() const APT_OVERRIDE;
  164. virtual unsigned long Size() const APT_OVERRIDE;
  165. pkgDebianIndexTargetFile(IndexTarget const &Target, bool const Trusted);
  166. virtual ~pkgDebianIndexTargetFile();
  167. };
  168. class pkgDebianIndexRealFile : public pkgDebianIndexFile
  169. {
  170. void * const d;
  171. protected:
  172. std::string File;
  173. virtual std::string IndexFileName() const APT_OVERRIDE;
  174. virtual std::string GetProgressDescription() const APT_OVERRIDE;
  175. virtual bool OpenListFile(FileFd &Pkg, std::string const &FileName) APT_OVERRIDE;
  176. public:
  177. virtual std::string Describe(bool const /*Short*/ = false) const APT_OVERRIDE;
  178. virtual bool Exists() const APT_OVERRIDE;
  179. virtual unsigned long Size() const APT_OVERRIDE;
  180. virtual std::string ArchiveURI(std::string const &/*File*/) const APT_OVERRIDE;
  181. pkgDebianIndexRealFile(std::string const &File, bool const Trusted);
  182. virtual ~pkgDebianIndexRealFile();
  183. };
  184. #endif