sourcelist.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. public:
  43. // List of supported source list types
  44. class Type
  45. {
  46. public:
  47. // Global list of Items supported
  48. static Type **GlobalList;
  49. static unsigned long GlobalListLen;
  50. static Type *GetType(const char *Type) APT_PURE;
  51. char const * const Name;
  52. char const * const Label;
  53. bool FixupURI(std::string &URI) const;
  54. virtual bool ParseStanza(std::vector<metaIndex *> &List,
  55. pkgTagSection &Tags,
  56. unsigned int const stanza_n,
  57. FileFd &Fd);
  58. virtual bool ParseLine(std::vector<metaIndex *> &List,
  59. const char *Buffer,
  60. unsigned int const CurLine,std::string const &File) const;
  61. virtual bool CreateItem(std::vector<metaIndex *> &List,std::string const &URI,
  62. std::string const &Dist,std::string const &Section,
  63. std::map<std::string, std::string> const &Options) const = 0;
  64. Type(char const * const Name, char const * const Label);
  65. virtual ~Type();
  66. };
  67. typedef std::vector<metaIndex *>::const_iterator const_iterator;
  68. protected:
  69. std::vector<metaIndex *> SrcList;
  70. private:
  71. APT_HIDDEN bool ParseFileDeb822(std::string const &File);
  72. APT_HIDDEN bool ParseFileOldStyle(std::string const &File);
  73. public:
  74. bool ReadMainList();
  75. bool Read(std::string const &File);
  76. // CNC:2003-03-03
  77. void Reset();
  78. bool ReadAppend(std::string const &File);
  79. bool ReadSourceDir(std::string const &Dir);
  80. // List accessors
  81. inline const_iterator begin() const {return SrcList.begin();};
  82. inline const_iterator end() const {return SrcList.end();};
  83. inline unsigned int size() const {return SrcList.size();};
  84. inline bool empty() const {return SrcList.empty();};
  85. bool FindIndex(pkgCache::PkgFileIterator File,
  86. pkgIndexFile *&Found) const;
  87. bool GetIndexes(pkgAcquire *Owner, bool GetAll=false) const;
  88. // query last-modified time
  89. time_t GetLastModifiedTime();
  90. pkgSourceList();
  91. virtual ~pkgSourceList();
  92. };
  93. #endif