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