]> git.saurik.com Git - apt.git/blob - apt-pkg/indexfile.h
f267247c17409046eb910f906e4a8a1bbc98adf7
[apt.git] / apt-pkg / indexfile.h
1 // -*- mode: cpp; mode: fold -*-
2 // Description /*{{{*/
3 /* ######################################################################
4
5 Index File - Abstraction for an index of archive/source file.
6
7 There are 4 primary sorts of index files, all represented by this
8 class:
9
10 Binary index files
11 Binary translation files
12 Binary index files describing the local system
13 Source index files
14
15 They are all bundled together here, and the interfaces for
16 sources.list, acquire, cache gen and record parsing all use this class
17 to access the underlying representation.
18
19 ##################################################################### */
20 /*}}}*/
21 #ifndef PKGLIB_INDEXFILE_H
22 #define PKGLIB_INDEXFILE_H
23
24 #include <apt-pkg/srcrecords.h>
25 #include <apt-pkg/pkgrecords.h>
26 #include <apt-pkg/pkgcache.h>
27 #include <apt-pkg/cacheiterators.h>
28 #include <apt-pkg/macros.h>
29
30 #include <map>
31 #include <string>
32
33 #ifndef APT_8_CLEANER_HEADERS
34 using std::string;
35 #endif
36 #ifndef APT_10_CLEANER_HEADERS
37 class pkgAcquire;
38 #endif
39
40 class pkgCacheGenerator;
41 class pkgCacheListParser;
42 class OpProgress;
43
44 class IndexTarget /*{{{*/
45 /** \brief Information about an index file. */
46 {
47 public:
48 /** \brief A URI from which the index file can be downloaded. */
49 std::string URI;
50
51 /** \brief A description of the index file. */
52 std::string Description;
53
54 /** \brief A shorter description of the index file. */
55 std::string ShortDesc;
56
57 /** \brief The key by which this index file should be
58 looked up within the meta index file. */
59 std::string MetaKey;
60
61 /** \brief Is it okay if the file isn't found in the meta index */
62 bool IsOptional;
63
64 /** \brief If the file is downloaded compressed, do not unpack it */
65 bool KeepCompressed;
66
67 /** \brief options with which this target was created
68 Prefer the usage of #Option if at all possible.
69 Beware: Not all of these options are intended for public use */
70 std::map<std::string, std::string> Options;
71
72 IndexTarget(std::string const &MetaKey, std::string const &ShortDesc,
73 std::string const &LongDesc, std::string const &URI, bool const IsOptional,
74 bool const KeepCompressed, std::map<std::string, std::string> const &Options);
75
76 enum OptionKeys {
77 SITE,
78 RELEASE,
79 COMPONENT,
80 LANGUAGE,
81 ARCHITECTURE,
82 BASE_URI,
83 REPO_URI,
84 CREATED_BY,
85 TARGET_OF,
86 FILENAME,
87 EXISTING_FILENAME,
88 PDIFFS,
89 COMPRESSIONTYPES,
90 DEFAULTENABLED,
91 };
92 std::string Option(OptionKeys const Key) const;
93 bool OptionBool(OptionKeys const Key) const;
94 std::string Format(std::string format) const;
95 };
96 /*}}}*/
97
98 class pkgIndexFile
99 {
100 void * const d;
101 protected:
102 bool Trusted;
103
104 public:
105
106 class Type
107 {
108 public:
109
110 // Global list of Items supported
111 static Type **GlobalList;
112 static unsigned long GlobalListLen;
113 static Type *GetType(const char * const Type) APT_PURE;
114
115 const char *Label;
116
117 virtual pkgRecords::Parser *CreatePkgParser(pkgCache::PkgFileIterator const &/*File*/) const {return 0;};
118 virtual pkgSrcRecords::Parser *CreateSrcPkgParser(std::string const &/*File*/) const {return 0;};
119 Type();
120 virtual ~Type() {};
121 };
122
123 virtual const Type *GetType() const = 0;
124
125 // Return descriptive strings of various sorts
126 virtual std::string ArchiveInfo(pkgCache::VerIterator const &Ver) const;
127 virtual std::string SourceInfo(pkgSrcRecords::Parser const &Record,
128 pkgSrcRecords::File const &File) const;
129 virtual std::string Describe(bool const Short = false) const = 0;
130
131 // Interface for acquire
132 virtual std::string ArchiveURI(std::string const &/*File*/) const {return std::string();};
133
134 // Interface for the record parsers
135 virtual pkgSrcRecords::Parser *CreateSrcParser() const {return 0;};
136
137 // Interface for the Cache Generator
138 virtual bool Exists() const = 0;
139 virtual bool HasPackages() const = 0;
140 virtual unsigned long Size() const = 0;
141 virtual bool Merge(pkgCacheGenerator &/*Gen*/, OpProgress* const /*Prog*/) { return true; };
142 virtual pkgCache::PkgFileIterator FindInCache(pkgCache &Cache) const;
143
144 static bool TranslationsAvailable();
145 static bool CheckLanguageCode(const char * const Lang);
146 static std::string LanguageCode();
147
148 bool IsTrusted() const { return Trusted; };
149
150 explicit pkgIndexFile(bool const Trusted);
151 virtual ~pkgIndexFile();
152 };
153
154 class pkgDebianIndexFile : public pkgIndexFile
155 {
156 protected:
157 virtual std::string IndexFileName() const = 0;
158 virtual std::string GetComponent() const = 0;
159 virtual std::string GetArchitecture() const = 0;
160 virtual std::string GetProgressDescription() const = 0;
161 virtual uint8_t GetIndexFlags() const = 0;
162 virtual bool OpenListFile(FileFd &Pkg, std::string const &FileName) = 0;
163 APT_HIDDEN virtual pkgCacheListParser * CreateListParser(FileFd &Pkg);
164
165 public:
166 virtual bool Merge(pkgCacheGenerator &Gen, OpProgress* const Prog) APT_OVERRIDE;
167 virtual pkgCache::PkgFileIterator FindInCache(pkgCache &Cache) const APT_OVERRIDE;
168
169 pkgDebianIndexFile(bool const Trusted);
170 virtual ~pkgDebianIndexFile();
171 };
172
173 class pkgDebianIndexTargetFile : public pkgDebianIndexFile
174 {
175 void * const d;
176 protected:
177 IndexTarget const Target;
178
179 virtual std::string IndexFileName() const APT_OVERRIDE;
180 virtual std::string GetComponent() const APT_OVERRIDE;
181 virtual std::string GetArchitecture() const APT_OVERRIDE;
182 virtual std::string GetProgressDescription() const APT_OVERRIDE;
183 virtual bool OpenListFile(FileFd &Pkg, std::string const &FileName) APT_OVERRIDE;
184
185 public:
186 virtual std::string ArchiveURI(std::string const &File) const APT_OVERRIDE;
187 virtual std::string Describe(bool const Short = false) const APT_OVERRIDE;
188 virtual bool Exists() const APT_OVERRIDE;
189 virtual unsigned long Size() const APT_OVERRIDE;
190
191 pkgDebianIndexTargetFile(IndexTarget const &Target, bool const Trusted);
192 virtual ~pkgDebianIndexTargetFile();
193 };
194
195 class pkgDebianIndexRealFile : public pkgDebianIndexFile
196 {
197 void * const d;
198 protected:
199 std::string File;
200
201 virtual std::string IndexFileName() const APT_OVERRIDE;
202 virtual std::string GetProgressDescription() const APT_OVERRIDE;
203 virtual bool OpenListFile(FileFd &Pkg, std::string const &FileName) APT_OVERRIDE;
204 public:
205 virtual std::string Describe(bool const /*Short*/ = false) const APT_OVERRIDE;
206 virtual bool Exists() const APT_OVERRIDE;
207 virtual unsigned long Size() const APT_OVERRIDE;
208 virtual std::string ArchiveURI(std::string const &/*File*/) const APT_OVERRIDE;
209
210 pkgDebianIndexRealFile(std::string const &File, bool const Trusted);
211 virtual ~pkgDebianIndexRealFile();
212 };
213
214 #endif