sourcelist.h 3.4 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 *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. const char *Name;
  55. const char *Label;
  56. bool FixupURI(std::string &URI) const;
  57. virtual bool ParseStanza(std::vector<metaIndex *> &List,
  58. pkgTagSection &Tags,
  59. int stanza_n,
  60. FileFd &Fd);
  61. virtual bool ParseLine(std::vector<metaIndex *> &List,
  62. const char *Buffer,
  63. unsigned long 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();
  68. virtual ~Type() {};
  69. };
  70. typedef std::vector<metaIndex *>::const_iterator const_iterator;
  71. protected:
  72. std::vector<metaIndex *> SrcList;
  73. int ParseFileDeb822(std::string File);
  74. bool ParseFileOldStyle(std::string File);
  75. public:
  76. bool ReadMainList();
  77. bool Read(std::string File);
  78. // CNC:2003-03-03
  79. void Reset();
  80. bool ReadAppend(std::string File);
  81. bool ReadSourceDir(std::string Dir);
  82. // List accessors
  83. inline const_iterator begin() const {return SrcList.begin();};
  84. inline const_iterator end() const {return SrcList.end();};
  85. inline unsigned int size() const {return SrcList.size();};
  86. inline bool empty() const {return SrcList.empty();};
  87. bool FindIndex(pkgCache::PkgFileIterator File,
  88. pkgIndexFile *&Found) const;
  89. bool GetIndexes(pkgAcquire *Owner, bool GetAll=false) const;
  90. // query last-modified time
  91. time_t GetLastModifiedTime();
  92. pkgSourceList();
  93. explicit pkgSourceList(std::string File);
  94. virtual ~pkgSourceList();
  95. };
  96. #endif