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.
 
 
 
 
 
 

230 lines
7.4 KiB

  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/macros.h>
  19. #include <apt-pkg/pkgcache.h>
  20. #include <apt-pkg/pkgrecords.h>
  21. #include <apt-pkg/srcrecords.h>
  22. #include <map>
  23. #include <string>
  24. #ifndef APT_8_CLEANER_HEADERS
  25. using std::string;
  26. #endif
  27. #ifndef APT_10_CLEANER_HEADERS
  28. class pkgAcquire;
  29. #endif
  30. class pkgCacheGenerator;
  31. class pkgCacheListParser;
  32. class OpProgress;
  33. class IndexTarget /*{{{*/
  34. /** \brief Information about an index file. */
  35. {
  36. public:
  37. /** \brief A URI from which the index file can be downloaded. */
  38. std::string URI;
  39. /** \brief A description of the index file. */
  40. std::string Description;
  41. /** \brief A shorter description of the index file. */
  42. std::string ShortDesc;
  43. /** \brief The key by which this index file should be
  44. looked up within the meta index file. */
  45. std::string MetaKey;
  46. /** \brief Is it okay if the file isn't found in the meta index */
  47. bool IsOptional;
  48. /** \brief If the file is downloaded compressed, do not unpack it */
  49. bool KeepCompressed;
  50. /** \brief options with which this target was created
  51. Prefer the usage of #Option if at all possible.
  52. Beware: Not all of these options are intended for public use */
  53. std::map<std::string, std::string> Options;
  54. IndexTarget(std::string const &MetaKey, std::string const &ShortDesc,
  55. std::string const &LongDesc, std::string const &URI, bool const IsOptional,
  56. bool const KeepCompressed, std::map<std::string, std::string> const &Options);
  57. enum OptionKeys
  58. {
  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. INRELEASE_PATH,
  82. };
  83. std::string Option(OptionKeys const Key) const;
  84. bool OptionBool(OptionKeys const Key) const;
  85. std::string Format(std::string format) const;
  86. };
  87. /*}}}*/
  88. class pkgIndexFile
  89. {
  90. void * const d;
  91. protected:
  92. bool Trusted;
  93. public:
  94. class Type
  95. {
  96. public:
  97. // Global list of Items supported
  98. static Type **GlobalList;
  99. static unsigned long GlobalListLen;
  100. static Type *GetType(const char * const Type) APT_PURE;
  101. const char *Label;
  102. virtual pkgRecords::Parser *CreatePkgParser(pkgCache::PkgFileIterator const &/*File*/) const {return 0;};
  103. virtual pkgSrcRecords::Parser *CreateSrcPkgParser(std::string const &/*File*/) const {return 0;};
  104. Type();
  105. virtual ~Type() {};
  106. };
  107. virtual const Type *GetType() const = 0;
  108. // Return descriptive strings of various sorts
  109. virtual std::string ArchiveInfo(pkgCache::VerIterator const &Ver) const;
  110. virtual std::string SourceInfo(pkgSrcRecords::Parser const &Record,
  111. pkgSrcRecords::File const &File) const;
  112. virtual std::string Describe(bool const Short = false) const = 0;
  113. // Interface for acquire
  114. virtual std::string ArchiveURI(std::string const &/*File*/) const {return std::string();};
  115. // Interface for the record parsers
  116. virtual pkgSrcRecords::Parser *CreateSrcParser() const {return 0;};
  117. // Interface for the Cache Generator
  118. virtual bool Exists() const = 0;
  119. virtual bool HasPackages() const = 0;
  120. virtual unsigned long Size() const = 0;
  121. virtual bool Merge(pkgCacheGenerator &/*Gen*/, OpProgress* const /*Prog*/) { return true; };
  122. virtual pkgCache::PkgFileIterator FindInCache(pkgCache &Cache) const;
  123. APT_DEPRECATED_MSG("These methods make no sense anymore with multi-language support") static bool TranslationsAvailable();
  124. /* No intern need for this method anymore as the check for correctness
  125. is already done in getLanguages(). Note also that this check is
  126. rather bad (doesn't take three character like ast into account).*/
  127. APT_DEPRECATED_MSG("These methods make no sense anymore with multi-language support") static bool CheckLanguageCode(const char * const Lang);
  128. /* As we have now possibly more than one LanguageCode this method is
  129. superseded by a) private classmembers or b) getLanguages() */
  130. APT_DEPRECATED_MSG("These methods make no sense anymore with multi-language support") static std::string LanguageCode();
  131. bool IsTrusted() const { return Trusted; };
  132. explicit pkgIndexFile(bool const Trusted);
  133. virtual ~pkgIndexFile();
  134. };
  135. class pkgDebianIndexFile : public pkgIndexFile
  136. {
  137. protected:
  138. virtual std::string IndexFileName() const = 0;
  139. virtual std::string GetComponent() const = 0;
  140. virtual std::string GetArchitecture() const = 0;
  141. virtual std::string GetProgressDescription() const = 0;
  142. virtual uint8_t GetIndexFlags() const = 0;
  143. virtual bool OpenListFile(FileFd &Pkg, std::string const &FileName) = 0;
  144. APT_HIDDEN virtual pkgCacheListParser * CreateListParser(FileFd &Pkg);
  145. public:
  146. virtual bool Merge(pkgCacheGenerator &Gen, OpProgress* const Prog) APT_OVERRIDE;
  147. virtual pkgCache::PkgFileIterator FindInCache(pkgCache &Cache) const APT_OVERRIDE;
  148. explicit pkgDebianIndexFile(bool const Trusted);
  149. virtual ~pkgDebianIndexFile();
  150. };
  151. class pkgDebianIndexTargetFile : public pkgDebianIndexFile
  152. {
  153. void * const d;
  154. protected:
  155. IndexTarget const Target;
  156. virtual std::string IndexFileName() const APT_OVERRIDE;
  157. virtual std::string GetComponent() const APT_OVERRIDE;
  158. virtual std::string GetArchitecture() const APT_OVERRIDE;
  159. virtual std::string GetProgressDescription() const APT_OVERRIDE;
  160. virtual bool OpenListFile(FileFd &Pkg, std::string const &FileName) APT_OVERRIDE;
  161. public:
  162. virtual std::string ArchiveURI(std::string const &File) const APT_OVERRIDE;
  163. virtual std::string Describe(bool const Short = false) const APT_OVERRIDE;
  164. virtual bool Exists() const APT_OVERRIDE;
  165. virtual unsigned long Size() const APT_OVERRIDE;
  166. IndexTarget GetIndexTarget() const APT_HIDDEN;
  167. pkgDebianIndexTargetFile(IndexTarget const &Target, bool const Trusted);
  168. virtual ~pkgDebianIndexTargetFile();
  169. };
  170. class pkgDebianIndexRealFile : public pkgDebianIndexFile
  171. {
  172. void * const d;
  173. protected:
  174. std::string File;
  175. virtual std::string IndexFileName() const APT_OVERRIDE;
  176. virtual std::string GetProgressDescription() const APT_OVERRIDE;
  177. virtual bool OpenListFile(FileFd &Pkg, std::string const &FileName) APT_OVERRIDE;
  178. public:
  179. virtual std::string Describe(bool const /*Short*/ = false) const APT_OVERRIDE;
  180. virtual bool Exists() const APT_OVERRIDE;
  181. virtual unsigned long Size() const APT_OVERRIDE;
  182. virtual std::string ArchiveURI(std::string const &/*File*/) const APT_OVERRIDE;
  183. pkgDebianIndexRealFile(std::string const &File, bool const Trusted);
  184. virtual ~pkgDebianIndexRealFile();
  185. };
  186. #endif