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.
 
 
 
 
 
 

140 lines
4.2 KiB

  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. /* ######################################################################
  4. SourceList - Manage a list of sources
  5. The Source List class provides access to a list of sources. It
  6. can read them from a file and generate a list of all the distinct
  7. sources.
  8. All sources have a type associated with them that defines the layout
  9. of the archive. The exact format of the file is documented in
  10. files.sgml.
  11. The types are mapped through a list of type definitions which handle
  12. the actual construction of the back end type. After loading a source
  13. list all you have is a list of package index files that have the ability
  14. to be Acquired.
  15. ##################################################################### */
  16. /*}}}*/
  17. #ifndef PKGLIB_SOURCELIST_H
  18. #define PKGLIB_SOURCELIST_H
  19. #include <apt-pkg/pkgcache.h>
  20. #include <apt-pkg/cacheiterators.h>
  21. #include <apt-pkg/macros.h>
  22. #include <time.h>
  23. #include <string>
  24. #include <vector>
  25. #include <map>
  26. #ifndef APT_8_CLEANER_HEADERS
  27. #include <apt-pkg/tagfile.h>
  28. #endif
  29. #ifndef APT_8_CLEANER_HEADERS
  30. #include <apt-pkg/metaindex.h>
  31. using std::string;
  32. using std::vector;
  33. #endif
  34. class FileFd;
  35. class pkgTagSection;
  36. class pkgAcquire;
  37. class pkgIndexFile;
  38. class metaIndex;
  39. class pkgSourceList
  40. {
  41. void * const d;
  42. std::vector<pkgIndexFile*> VolatileFiles;
  43. public:
  44. // List of supported source list types
  45. class Type
  46. {
  47. public:
  48. // Global list of Items supported
  49. static Type **GlobalList;
  50. static unsigned long GlobalListLen;
  51. static Type *GetType(const char *Type) APT_PURE;
  52. char const * const Name;
  53. char const * const Label;
  54. bool FixupURI(std::string &URI) const;
  55. virtual bool ParseStanza(std::vector<metaIndex *> &List,
  56. pkgTagSection &Tags,
  57. unsigned int const stanza_n,
  58. FileFd &Fd);
  59. virtual bool ParseLine(std::vector<metaIndex *> &List,
  60. const char *Buffer,
  61. unsigned int const CurLine,std::string const &File) const;
  62. virtual bool CreateItem(std::vector<metaIndex *> &List,std::string const &URI,
  63. std::string const &Dist,std::string const &Section,
  64. std::map<std::string, std::string> const &Options) const = 0;
  65. Type(char const * const Name, char const * const Label);
  66. virtual ~Type();
  67. };
  68. typedef std::vector<metaIndex *>::const_iterator const_iterator;
  69. protected:
  70. std::vector<metaIndex *> SrcList;
  71. private:
  72. APT_HIDDEN bool ParseFileDeb822(std::string const &File);
  73. APT_HIDDEN bool ParseFileOldStyle(std::string const &File);
  74. public:
  75. bool ReadMainList();
  76. bool Read(std::string const &File);
  77. // CNC:2003-03-03
  78. void Reset();
  79. bool ReadAppend(std::string const &File);
  80. bool ReadSourceDir(std::string const &Dir);
  81. // List accessors
  82. inline const_iterator begin() const {return SrcList.begin();};
  83. inline const_iterator end() const {return SrcList.end();};
  84. inline unsigned int size() const {return SrcList.size();};
  85. inline bool empty() const {return SrcList.empty();};
  86. bool FindIndex(pkgCache::PkgFileIterator File,
  87. pkgIndexFile *&Found) const;
  88. bool GetIndexes(pkgAcquire *Owner, bool GetAll=false) const;
  89. // query last-modified time
  90. time_t GetLastModifiedTime();
  91. /** \brief add file for parsing, but not to the cache
  92. *
  93. * pkgIndexFiles origining from pkgSourcesList are included in
  94. * srcpkgcache, the status files added via #AddStatusFiles are
  95. * included in pkgcache, but these files here are not included in
  96. * any cache to have the possibility of having a file included just
  97. * for a single run like a local .deb/.dsc file.
  98. *
  99. * The volatile files do not count as "normal" sourceslist entries,
  100. * can't be iterated over with #begin and #end and can't be
  101. * downloaded, but they can be found via #FindIndex.
  102. *
  103. * @param File is an index file; pointer-ownership is transferred
  104. */
  105. void AddVolatileFile(pkgIndexFile * const File);
  106. /** @return list of files registered with #AddVolatileFile */
  107. std::vector<pkgIndexFile*> GetVolatileFiles() const;
  108. pkgSourceList();
  109. virtual ~pkgSourceList();
  110. };
  111. #endif