sourcelist.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. The vendor machanism is similar, except the vendor types are hard
  16. wired. Before loading the source list the vendor list is loaded.
  17. This doesn't load key data, just the checks to perform.
  18. ##################################################################### */
  19. /*}}}*/
  20. #ifndef PKGLIB_SOURCELIST_H
  21. #define PKGLIB_SOURCELIST_H
  22. #include <apt-pkg/pkgcache.h>
  23. #include <apt-pkg/cacheiterators.h>
  24. #include <apt-pkg/macros.h>
  25. #include <time.h>
  26. #include <string>
  27. #include <vector>
  28. #include <map>
  29. #ifndef APT_8_CLEANER_HEADERS
  30. #include <apt-pkg/tagfile.h>
  31. #endif
  32. #ifndef APT_8_CLEANER_HEADERS
  33. #include <apt-pkg/metaindex.h>
  34. using std::string;
  35. using std::vector;
  36. #endif
  37. class FileFd;
  38. class pkgTagSection;
  39. class pkgAcquire;
  40. class pkgIndexFile;
  41. class metaIndex;
  42. class pkgSourceList
  43. {
  44. void * const d;
  45. public:
  46. // List of supported source list types
  47. class Type
  48. {
  49. public:
  50. // Global list of Items supported
  51. static Type **GlobalList;
  52. static unsigned long GlobalListLen;
  53. static Type *GetType(const char *Type) APT_PURE;
  54. char const * const Name;
  55. char const * const Label;
  56. bool FixupURI(std::string &URI) const;
  57. virtual bool ParseStanza(std::vector<metaIndex *> &List,
  58. pkgTagSection &Tags,
  59. unsigned int const stanza_n,
  60. FileFd &Fd);
  61. virtual bool ParseLine(std::vector<metaIndex *> &List,
  62. const char *Buffer,
  63. unsigned int const CurLine,std::string const &File) const;
  64. virtual bool CreateItem(std::vector<metaIndex *> &List,std::string const &URI,
  65. std::string const &Dist,std::string const &Section,
  66. std::map<std::string, std::string> const &Options) const = 0;
  67. Type(char const * const Name, char const * const Label);
  68. virtual ~Type();
  69. };
  70. typedef std::vector<metaIndex *>::const_iterator const_iterator;
  71. protected:
  72. std::vector<metaIndex *> SrcList;
  73. private:
  74. APT_HIDDEN bool ParseFileDeb822(std::string const &File);
  75. APT_HIDDEN bool ParseFileOldStyle(std::string const &File);
  76. public:
  77. bool ReadMainList();
  78. bool Read(std::string const &File);
  79. // CNC:2003-03-03
  80. void Reset();
  81. bool ReadAppend(std::string const &File);
  82. bool ReadSourceDir(std::string const &Dir);
  83. // List accessors
  84. inline const_iterator begin() const {return SrcList.begin();};
  85. inline const_iterator end() const {return SrcList.end();};
  86. inline unsigned int size() const {return SrcList.size();};
  87. inline bool empty() const {return SrcList.empty();};
  88. bool FindIndex(pkgCache::PkgFileIterator File,
  89. pkgIndexFile *&Found) const;
  90. bool GetIndexes(pkgAcquire *Owner, bool GetAll=false) const;
  91. // query last-modified time
  92. time_t GetLastModifiedTime();
  93. pkgSourceList();
  94. virtual ~pkgSourceList();
  95. };
  96. #endif