]>
Commit | Line | Data |
---|---|---|
0118833a AL |
1 | // -*- mode: cpp; mode: fold -*- |
2 | // Description /*{{{*/ | |
b3d44315 | 3 | // $Id: acquire-item.h,v 1.26.2.3 2004/01/02 18:51:00 mdz Exp $ |
0118833a AL |
4 | /* ###################################################################### |
5 | ||
6 | Acquire Item - Item to acquire | |
7 | ||
8 | When an item is instantiated it will add it self to the local list in | |
9 | the Owner Acquire class. Derived classes will then call QueueURI to | |
17caf1b1 | 10 | register all the URI's they wish to fetch at the initial moment. |
0118833a AL |
11 | |
12 | Two item classes are provided to provide functionality for downloading | |
13 | of Index files and downloading of Packages. | |
14 | ||
b185acc2 | 15 | A Archive class is provided for downloading .deb files. It does Md5 |
17caf1b1 | 16 | checking and source location as well as a retry algorithm. |
b185acc2 | 17 | |
0118833a AL |
18 | ##################################################################### */ |
19 | /*}}}*/ | |
20 | #ifndef PKGLIB_ACQUIRE_ITEM_H | |
21 | #define PKGLIB_ACQUIRE_ITEM_H | |
22 | ||
23 | #include <apt-pkg/acquire.h> | |
b2e465d6 | 24 | #include <apt-pkg/indexfile.h> |
b3d44315 MV |
25 | #include <apt-pkg/vendor.h> |
26 | #include <apt-pkg/sourcelist.h> | |
03e39e59 | 27 | #include <apt-pkg/pkgrecords.h> |
b3d44315 | 28 | #include <apt-pkg/indexrecords.h> |
0118833a AL |
29 | |
30 | #ifdef __GNUG__ | |
31 | #pragma interface "apt-pkg/acquire-item.h" | |
32 | #endif | |
33 | ||
34 | // Item to acquire | |
35 | class pkgAcquire::Item | |
36 | { | |
37 | protected: | |
38 | ||
17caf1b1 | 39 | // Some private helper methods for registering URIs |
0118833a | 40 | pkgAcquire *Owner; |
8267fe24 AL |
41 | inline void QueueURI(ItemDesc &Item) |
42 | {Owner->Enqueue(Item);}; | |
681d76d0 | 43 | inline void Dequeue() {Owner->Dequeue(this);}; |
0118833a | 44 | |
17caf1b1 | 45 | // Safe rename function with timestamp preservation |
8b89e57f AL |
46 | void Rename(string From,string To); |
47 | ||
0118833a AL |
48 | public: |
49 | ||
c88edf1d | 50 | // State of the item |
b3d44315 | 51 | enum {StatIdle, StatFetching, StatDone, StatError, StatAuthError} Status; |
c88edf1d | 52 | string ErrorText; |
8267fe24 | 53 | unsigned long FileSize; |
6b1ff003 | 54 | unsigned long PartialSize; |
b2e465d6 | 55 | const char *Mode; |
b98f2859 | 56 | unsigned long ID; |
8267fe24 | 57 | bool Complete; |
a6568219 | 58 | bool Local; |
30e1eab5 | 59 | |
0a8a80e5 | 60 | // Number of queues we are inserted into |
0118833a | 61 | unsigned int QueueCounter; |
0118833a | 62 | |
0a8a80e5 AL |
63 | // File to write the fetch into |
64 | string DestFile; | |
7d8afa39 | 65 | |
17caf1b1 | 66 | // Action members invoked by the worker |
7d8afa39 | 67 | virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf); |
459681d3 AL |
68 | virtual void Done(string Message,unsigned long Size,string Md5Hash, |
69 | pkgAcquire::MethodConfig *Cnf); | |
8267fe24 | 70 | virtual void Start(string Message,unsigned long Size); |
17caf1b1 | 71 | virtual string Custom600Headers() {return string();}; |
36375005 | 72 | virtual string DescURI() = 0; |
b3d44315 | 73 | virtual string ShortDesc() {return DescURI();} |
ab559b35 | 74 | virtual void Finished() {}; |
17caf1b1 AL |
75 | |
76 | // Inquire functions | |
f7a08e33 | 77 | virtual string MD5Sum() {return string();}; |
c5ccf175 | 78 | pkgAcquire *GetOwner() {return Owner;}; |
b3d44315 | 79 | virtual bool IsTrusted() {return false;}; |
c5ccf175 | 80 | |
0118833a AL |
81 | Item(pkgAcquire *Owner); |
82 | virtual ~Item(); | |
83 | }; | |
84 | ||
ac5b205a | 85 | // item for index diffs |
002d9943 MV |
86 | |
87 | struct DiffInfo { | |
88 | string file; | |
89 | string sha1; | |
90 | unsigned long size; | |
91 | }; | |
92 | ||
2237bd01 MV |
93 | class pkgAcqDiffIndex : public pkgAcquire::Item |
94 | { | |
95 | protected: | |
96 | bool Debug; | |
002d9943 | 97 | pkgAcquire::ItemDesc Desc; |
2237bd01 | 98 | string RealURI; |
002d9943 MV |
99 | string ExpectedMD5; |
100 | string CurrentPackagesFile; | |
101 | string Description; | |
2237bd01 MV |
102 | |
103 | public: | |
104 | // Specialized action members | |
105 | virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf); | |
106 | virtual void Done(string Message,unsigned long Size,string Md5Hash, | |
107 | pkgAcquire::MethodConfig *Cnf); | |
108 | virtual string DescURI() {return RealURI + "Index";}; | |
109 | virtual string Custom600Headers(); | |
110 | ||
111 | // helpers | |
112 | bool ParseDiffIndex(string IndexDiffFile); | |
113 | ||
114 | pkgAcqDiffIndex(pkgAcquire *Owner,string URI,string URIDesc, | |
115 | string ShortDesct, string ExpectedMD5); | |
002d9943 | 116 | }; |
2237bd01 | 117 | |
ac5b205a MV |
118 | class pkgAcqIndexDiffs : public pkgAcquire::Item |
119 | { | |
120 | protected: | |
121 | bool Debug; | |
122 | pkgAcquire::ItemDesc Desc; | |
123 | string RealURI; | |
124 | string ExpectedMD5; | |
4a0a786f | 125 | |
ac5b205a | 126 | // this is the SHA-1 sum we expect after the patching |
ac5b205a | 127 | string Description; |
94dc9d7d | 128 | vector<DiffInfo> available_patches; |
4a0a786f | 129 | enum {StateFetchIndex,StateFetchDiff,StateUnzipDiff,StateApplyDiff} State; |
6cb30d01 | 130 | |
ac5b205a MV |
131 | public: |
132 | ||
133 | // Specialized action members | |
134 | virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf); | |
135 | virtual void Done(string Message,unsigned long Size,string Md5Hash, | |
136 | pkgAcquire::MethodConfig *Cnf); | |
137 | virtual string DescURI() {return RealURI + "Index";}; | |
ac5b205a MV |
138 | |
139 | // various helpers | |
ac5b205a MV |
140 | bool QueueNextDiff(); |
141 | bool ApplyDiff(string PatchFile); | |
142 | void Finish(bool allDone=false); | |
143 | ||
144 | pkgAcqIndexDiffs(pkgAcquire *Owner,string URI,string URIDesc, | |
145 | string ShortDesct, string ExpectedMD5, | |
6cb30d01 | 146 | vector<DiffInfo> diffs=vector<DiffInfo>()); |
ac5b205a MV |
147 | }; |
148 | ||
0118833a AL |
149 | // Item class for index files |
150 | class pkgAcqIndex : public pkgAcquire::Item | |
151 | { | |
152 | protected: | |
153 | ||
8b89e57f | 154 | bool Decompression; |
bfd22fc0 | 155 | bool Erase; |
8267fe24 | 156 | pkgAcquire::ItemDesc Desc; |
b2e465d6 | 157 | string RealURI; |
b3d44315 | 158 | string ExpectedMD5; |
13e8426f MV |
159 | string CompressionExtension; |
160 | ||
0118833a AL |
161 | public: |
162 | ||
17caf1b1 | 163 | // Specialized action members |
debc84b2 | 164 | virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf); |
459681d3 AL |
165 | virtual void Done(string Message,unsigned long Size,string Md5Hash, |
166 | pkgAcquire::MethodConfig *Cnf); | |
0a8a80e5 | 167 | virtual string Custom600Headers(); |
13e8426f | 168 | virtual string DescURI() {return RealURI + CompressionExtension;}; |
0118833a | 169 | |
b2e465d6 | 170 | pkgAcqIndex(pkgAcquire *Owner,string URI,string URIDesc, |
b3d44315 | 171 | string ShortDesct, string ExpectedMD5, string compressExt=""); |
0118833a AL |
172 | }; |
173 | ||
b3d44315 MV |
174 | struct IndexTarget |
175 | { | |
176 | string URI; | |
177 | string Description; | |
178 | string ShortDesc; | |
179 | string MetaKey; | |
180 | }; | |
181 | ||
182 | // Item class for index signatures | |
183 | class pkgAcqMetaSig : public pkgAcquire::Item | |
0118833a AL |
184 | { |
185 | protected: | |
186 | ||
8267fe24 | 187 | pkgAcquire::ItemDesc Desc; |
b3d44315 MV |
188 | string RealURI,MetaIndexURI,MetaIndexURIDesc,MetaIndexShortDesc; |
189 | indexRecords* MetaIndexParser; | |
190 | const vector<struct IndexTarget*>* IndexTargets; | |
191 | ||
0118833a AL |
192 | public: |
193 | ||
17caf1b1 | 194 | // Specialized action members |
681d76d0 | 195 | virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf); |
459681d3 | 196 | virtual void Done(string Message,unsigned long Size,string Md5Hash, |
b3d44315 | 197 | pkgAcquire::MethodConfig *Cnf); |
0a8a80e5 | 198 | virtual string Custom600Headers(); |
b3d44315 MV |
199 | virtual string DescURI() {return RealURI; }; |
200 | ||
201 | pkgAcqMetaSig(pkgAcquire *Owner,string URI,string URIDesc, string ShortDesc, | |
202 | string MetaIndexURI, string MetaIndexURIDesc, string MetaIndexShortDesc, | |
203 | const vector<struct IndexTarget*>* IndexTargets, | |
204 | indexRecords* MetaIndexParser); | |
205 | }; | |
206 | ||
207 | // Item class for index signatures | |
208 | class pkgAcqMetaIndex : public pkgAcquire::Item | |
209 | { | |
210 | protected: | |
211 | ||
212 | pkgAcquire::ItemDesc Desc; | |
213 | string RealURI; // FIXME: is this redundant w/ Desc.URI? | |
214 | string SigFile; | |
215 | const vector<struct IndexTarget*>* IndexTargets; | |
216 | indexRecords* MetaIndexParser; | |
217 | bool AuthPass; | |
ce424cd4 MV |
218 | // required to deal gracefully with problems caused by incorrect ims hits |
219 | bool IMSHit; | |
b3d44315 | 220 | |
ce424cd4 | 221 | bool VerifyVendor(string Message); |
b3d44315 MV |
222 | void RetrievalDone(string Message); |
223 | void AuthDone(string Message); | |
224 | void QueueIndexes(bool verify); | |
225 | ||
226 | public: | |
0a8a80e5 | 227 | |
b3d44315 MV |
228 | // Specialized action members |
229 | virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf); | |
230 | virtual void Done(string Message,unsigned long Size,string Md5Hash, | |
231 | pkgAcquire::MethodConfig *Cnf); | |
232 | virtual string Custom600Headers(); | |
233 | virtual string DescURI() {return RealURI; }; | |
234 | ||
235 | pkgAcqMetaIndex(pkgAcquire *Owner, | |
236 | string URI,string URIDesc, string ShortDesc, | |
237 | string SigFile, | |
238 | const vector<struct IndexTarget*>* IndexTargets, | |
239 | indexRecords* MetaIndexParser); | |
0118833a AL |
240 | }; |
241 | ||
03e39e59 AL |
242 | // Item class for archive files |
243 | class pkgAcqArchive : public pkgAcquire::Item | |
244 | { | |
245 | protected: | |
246 | ||
17caf1b1 | 247 | // State information for the retry mechanism |
03e39e59 AL |
248 | pkgCache::VerIterator Version; |
249 | pkgAcquire::ItemDesc Desc; | |
250 | pkgSourceList *Sources; | |
251 | pkgRecords *Recs; | |
252 | string MD5; | |
30e1eab5 | 253 | string &StoreFilename; |
b185acc2 | 254 | pkgCache::VerFileIterator Vf; |
7d8afa39 | 255 | unsigned int Retries; |
b3d44315 | 256 | bool Trusted; |
17caf1b1 AL |
257 | |
258 | // Queue the next available file for download. | |
b185acc2 | 259 | bool QueueNext(); |
03e39e59 AL |
260 | |
261 | public: | |
262 | ||
17caf1b1 | 263 | // Specialized action members |
7d8afa39 | 264 | virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf); |
459681d3 AL |
265 | virtual void Done(string Message,unsigned long Size,string Md5Hash, |
266 | pkgAcquire::MethodConfig *Cnf); | |
17caf1b1 | 267 | virtual string MD5Sum() {return MD5;}; |
36375005 | 268 | virtual string DescURI() {return Desc.URI;}; |
b3d44315 | 269 | virtual string ShortDesc() {return Desc.ShortDesc;}; |
ab559b35 | 270 | virtual void Finished(); |
b3d44315 | 271 | virtual bool IsTrusted(); |
03e39e59 AL |
272 | |
273 | pkgAcqArchive(pkgAcquire *Owner,pkgSourceList *Sources, | |
30e1eab5 AL |
274 | pkgRecords *Recs,pkgCache::VerIterator const &Version, |
275 | string &StoreFilename); | |
03e39e59 AL |
276 | }; |
277 | ||
36375005 AL |
278 | // Fetch a generic file to the current directory |
279 | class pkgAcqFile : public pkgAcquire::Item | |
280 | { | |
281 | pkgAcquire::ItemDesc Desc; | |
b3c39978 | 282 | string Md5Hash; |
08cfc005 | 283 | unsigned int Retries; |
36375005 AL |
284 | |
285 | public: | |
286 | ||
287 | // Specialized action members | |
08cfc005 | 288 | virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf); |
459681d3 AL |
289 | virtual void Done(string Message,unsigned long Size,string Md5Hash, |
290 | pkgAcquire::MethodConfig *Cnf); | |
b3c39978 | 291 | virtual string MD5Sum() {return Md5Hash;}; |
36375005 | 292 | virtual string DescURI() {return Desc.URI;}; |
46e00f9d MV |
293 | |
294 | // If DestFilename is empty, download to DestDir/<basename> if | |
295 | // DestDir is non-empty, $CWD/<basename> otherwise. If | |
296 | // DestFilename is NOT empty, DestDir is ignored and DestFilename | |
297 | // is the absolute name to which the file should be downloaded. | |
298 | pkgAcqFile(pkgAcquire *Owner, string URI, string MD5, unsigned long Size, | |
299 | string Desc, string ShortDesc, | |
300 | const string &DestDir="", const string &DestFilename=""); | |
36375005 AL |
301 | }; |
302 | ||
0118833a | 303 | #endif |