indexfile.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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 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 options with which this target was created
  49. Prefer the usage of #Option if at all possible.
  50. Beware: Not all of these options are intended for public use */
  51. std::map<std::string, std::string> Options;
  52. IndexTarget(std::string const &MetaKey, std::string const &ShortDesc,
  53. std::string const &LongDesc, std::string const &URI, bool const IsOptional,
  54. std::map<std::string, std::string> const &Options);
  55. enum OptionKeys {
  56. SITE,
  57. RELEASE,
  58. COMPONENT,
  59. LANGUAGE,
  60. ARCHITECTURE,
  61. BASE_URI,
  62. REPO_URI,
  63. CREATED_BY,
  64. TARGET_OF,
  65. FILENAME,
  66. EXISTING_FILENAME,
  67. };
  68. std::string Option(OptionKeys const Key) const;
  69. std::string Format(std::string format) const;
  70. };
  71. /*}}}*/
  72. class pkgIndexFile
  73. {
  74. void *d;
  75. protected:
  76. bool Trusted;
  77. public:
  78. class Type
  79. {
  80. public:
  81. // Global list of Items supported
  82. static Type **GlobalList;
  83. static unsigned long GlobalListLen;
  84. static Type *GetType(const char *Type) APT_PURE;
  85. const char *Label;
  86. virtual pkgRecords::Parser *CreatePkgParser(pkgCache::PkgFileIterator /*File*/) const {return 0;};
  87. virtual pkgSrcRecords::Parser *CreateSrcPkgParser(std::string /*File*/) const {return 0;};
  88. Type();
  89. virtual ~Type() {};
  90. };
  91. virtual const Type *GetType() const = 0;
  92. // Return descriptive strings of various sorts
  93. virtual std::string ArchiveInfo(pkgCache::VerIterator Ver) const;
  94. virtual std::string SourceInfo(pkgSrcRecords::Parser const &Record,
  95. pkgSrcRecords::File const &File) const;
  96. virtual std::string Describe(bool Short = false) const = 0;
  97. // Interface for acquire
  98. virtual std::string ArchiveURI(std::string /*File*/) const {return std::string();};
  99. // Interface for the record parsers
  100. virtual pkgSrcRecords::Parser *CreateSrcParser() const {return 0;};
  101. // Interface for the Cache Generator
  102. virtual bool Exists() const = 0;
  103. virtual bool HasPackages() const = 0;
  104. virtual unsigned long Size() const = 0;
  105. virtual bool Merge(pkgCacheGenerator &/*Gen*/, OpProgress* /*Prog*/) const { return false; };
  106. APT_DEPRECATED virtual bool Merge(pkgCacheGenerator &Gen, OpProgress &Prog) const
  107. { return Merge(Gen, &Prog); };
  108. virtual bool MergeFileProvides(pkgCacheGenerator &/*Gen*/,OpProgress* /*Prog*/) const {return true;};
  109. APT_DEPRECATED virtual bool MergeFileProvides(pkgCacheGenerator &Gen, OpProgress &Prog) const
  110. {return MergeFileProvides(Gen, &Prog);};
  111. virtual pkgCache::PkgFileIterator FindInCache(pkgCache &Cache) const;
  112. static bool TranslationsAvailable();
  113. static bool CheckLanguageCode(const char *Lang);
  114. static std::string LanguageCode();
  115. bool IsTrusted() const { return Trusted; };
  116. pkgIndexFile(bool Trusted);
  117. virtual ~pkgIndexFile();
  118. };
  119. class pkgIndexTargetFile : public pkgIndexFile
  120. {
  121. void *d;
  122. protected:
  123. IndexTarget const Target;
  124. std::string IndexFileName() const;
  125. public:
  126. virtual std::string ArchiveURI(std::string File) const;
  127. virtual std::string Describe(bool Short = false) const;
  128. virtual bool Exists() const;
  129. virtual unsigned long Size() const;
  130. pkgIndexTargetFile(IndexTarget const &Target, bool const Trusted);
  131. virtual ~pkgIndexTargetFile();
  132. };
  133. #endif