]>
Commit | Line | Data |
---|---|---|
0118833a AL |
1 | // -*- mode: cpp; mode: fold -*- |
2 | // Description /*{{{*/ | |
7db98ffc | 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 | 11 | |
770c32ec | 12 | Three item classes are provided to provide functionality for |
a52f938b | 13 | downloading of Index, Translation and Packages files. |
0118833a | 14 | |
495e5cb2 | 15 | A Archive class is provided for downloading .deb files. It does Hash |
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> |
7db98ffc MZ |
25 | #include <apt-pkg/vendor.h> |
26 | #include <apt-pkg/sourcelist.h> | |
03e39e59 | 27 | #include <apt-pkg/pkgrecords.h> |
7db98ffc | 28 | #include <apt-pkg/indexrecords.h> |
495e5cb2 | 29 | #include <apt-pkg/hashes.h> |
0118833a | 30 | |
3174e150 MV |
31 | /** \addtogroup acquire |
32 | * @{ | |
33 | * | |
34 | * \file acquire-item.h | |
35 | */ | |
36 | ||
92fcbfc1 | 37 | /** \brief Represents the process by which a pkgAcquire object should {{{ |
3174e150 MV |
38 | * retrieve a file or a collection of files. |
39 | * | |
40 | * By convention, Item subclasses should insert themselves into the | |
41 | * acquire queue when they are created by calling QueueURI(), and | |
42 | * remove themselves by calling Dequeue() when either Done() or | |
43 | * Failed() is invoked. Item objects are also responsible for | |
44 | * notifying the download progress indicator (accessible via | |
45 | * #Owner->Log) of their status. | |
46 | * | |
47 | * \see pkgAcquire | |
48 | */ | |
0118833a AL |
49 | class pkgAcquire::Item |
50 | { | |
51 | protected: | |
52 | ||
3174e150 | 53 | /** \brief The acquire object with which this item is associated. */ |
0118833a | 54 | pkgAcquire *Owner; |
3174e150 MV |
55 | |
56 | /** \brief Insert this item into its owner's queue. | |
57 | * | |
58 | * \param ItemDesc Metadata about this item (its URI and | |
59 | * description). | |
60 | */ | |
8267fe24 AL |
61 | inline void QueueURI(ItemDesc &Item) |
62 | {Owner->Enqueue(Item);}; | |
3174e150 MV |
63 | |
64 | /** \brief Remove this item from its owner's queue. */ | |
681d76d0 | 65 | inline void Dequeue() {Owner->Dequeue(this);}; |
0118833a | 66 | |
3174e150 MV |
67 | /** \brief Rename a file without modifying its timestamp. |
68 | * | |
69 | * Many item methods call this as their final action. | |
70 | * | |
71 | * \param From The file to be renamed. | |
72 | * | |
73 | * \param To The new name of #From. If #To exists it will be | |
74 | * overwritten. | |
75 | */ | |
8b89e57f AL |
76 | void Rename(string From,string To); |
77 | ||
0118833a AL |
78 | public: |
79 | ||
3174e150 MV |
80 | /** \brief The current status of this item. */ |
81 | enum ItemState | |
82 | { | |
83 | /** \brief The item is waiting to be downloaded. */ | |
84 | StatIdle, | |
85 | ||
86 | /** \brief The item is currently being downloaded. */ | |
87 | StatFetching, | |
88 | ||
89 | /** \brief The item has been successfully downloaded. */ | |
90 | StatDone, | |
91 | ||
92 | /** \brief An error was encountered while downloading this | |
93 | * item. | |
94 | */ | |
95 | StatError, | |
96 | ||
97 | /** \brief The item was downloaded but its authenticity could | |
98 | * not be verified. | |
99 | */ | |
6ca714d5 MV |
100 | StatAuthError, |
101 | ||
102 | /** \brief The item was could not be downloaded because of | |
103 | * a transient network error (e.g. network down) | |
104 | */ | |
105 | StatTransientNetworkError | |
3174e150 MV |
106 | } Status; |
107 | ||
108 | /** \brief Contains a textual description of the error encountered | |
109 | * if #Status is #StatError or #StatAuthError. | |
110 | */ | |
c88edf1d | 111 | string ErrorText; |
3174e150 MV |
112 | |
113 | /** \brief The size of the object to fetch. */ | |
8267fe24 | 114 | unsigned long FileSize; |
3174e150 MV |
115 | |
116 | /** \brief How much of the object was already fetched. */ | |
117 | unsigned long PartialSize; | |
118 | ||
119 | /** \brief If not \b NULL, contains the name of a subprocess that | |
120 | * is operating on this object (for instance, "gzip" or "gpgv"). | |
121 | */ | |
b2e465d6 | 122 | const char *Mode; |
3174e150 MV |
123 | |
124 | /** \brief A client-supplied unique identifier. | |
125 | * | |
126 | * This field is initalized to 0; it is meant to be filled in by | |
127 | * clients that wish to use it to uniquely identify items. | |
128 | * | |
129 | * \todo it's unused in apt itself | |
130 | */ | |
b98f2859 | 131 | unsigned long ID; |
3174e150 MV |
132 | |
133 | /** \brief If \b true, the entire object has been successfully fetched. | |
134 | * | |
135 | * Subclasses should set this to \b true when appropriate. | |
136 | */ | |
8267fe24 | 137 | bool Complete; |
3174e150 MV |
138 | |
139 | /** \brief If \b true, the URI of this object is "local". | |
140 | * | |
141 | * The only effect of this field is to exclude the object from the | |
142 | * download progress indicator's overall statistics. | |
143 | */ | |
a6568219 | 144 | bool Local; |
30e1eab5 | 145 | |
3174e150 MV |
146 | /** \brief The number of fetch queues into which this item has been |
147 | * inserted. | |
148 | * | |
149 | * There is one queue for each source from which an item could be | |
150 | * downloaded. | |
151 | * | |
152 | * \sa pkgAcquire | |
153 | */ | |
0118833a | 154 | unsigned int QueueCounter; |
0118833a | 155 | |
3174e150 MV |
156 | /** \brief The name of the file into which the retrieved object |
157 | * will be written. | |
158 | */ | |
0a8a80e5 | 159 | string DestFile; |
7d8afa39 | 160 | |
3174e150 MV |
161 | /** \brief Invoked by the acquire worker when the object couldn't |
162 | * be fetched. | |
163 | * | |
164 | * This is a branch of the continuation of the fetch process. | |
165 | * | |
166 | * \param Message An RFC822-formatted message from the acquire | |
167 | * method describing what went wrong. Use LookupTag() to parse | |
168 | * it. | |
169 | * | |
170 | * \param Cnf The method via which the worker tried to fetch this object. | |
171 | * | |
172 | * \sa pkgAcqMethod | |
173 | */ | |
7d8afa39 | 174 | virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf); |
3174e150 MV |
175 | |
176 | /** \brief Invoked by the acquire worker when the object was | |
177 | * fetched successfully. | |
178 | * | |
179 | * Note that the object might \e not have been written to | |
180 | * DestFile; check for the presence of an Alt-Filename entry in | |
181 | * Message to find the file to which it was really written. | |
182 | * | |
183 | * Done is often used to switch from one stage of the processing | |
184 | * to the next (e.g. fetching, unpacking, copying). It is one | |
185 | * branch of the continuation of the fetch process. | |
186 | * | |
187 | * \param Message Data from the acquire method. Use LookupTag() | |
188 | * to parse it. | |
189 | * \param Size The size of the object that was fetched. | |
495e5cb2 | 190 | * \param Hash The HashSum of the object that was fetched. |
3174e150 MV |
191 | * \param Cnf The method via which the object was fetched. |
192 | * | |
193 | * \sa pkgAcqMethod | |
194 | */ | |
495e5cb2 | 195 | virtual void Done(string Message,unsigned long Size,string Hash, |
459681d3 | 196 | pkgAcquire::MethodConfig *Cnf); |
3174e150 MV |
197 | |
198 | /** \brief Invoked when the worker starts to fetch this object. | |
199 | * | |
200 | * \param Message RFC822-formatted data from the worker process. | |
201 | * Use LookupTag() to parse it. | |
202 | * | |
203 | * \param Size The size of the object being fetched. | |
204 | * | |
205 | * \sa pkgAcqMethod | |
206 | */ | |
8267fe24 | 207 | virtual void Start(string Message,unsigned long Size); |
3174e150 MV |
208 | |
209 | /** \brief Custom headers to be sent to the fetch process. | |
210 | * | |
211 | * \return a string containing RFC822-style headers that are to be | |
212 | * inserted into the 600 URI Acquire message sent to the fetch | |
213 | * subprocess. The headers are inserted after a newline-less | |
214 | * line, so they should (if nonempty) have a leading newline and | |
215 | * no trailing newline. | |
216 | */ | |
17caf1b1 | 217 | virtual string Custom600Headers() {return string();}; |
3174e150 MV |
218 | |
219 | /** \brief A "descriptive" URI-like string. | |
220 | * | |
221 | * \return a URI that should be used to describe what is being fetched. | |
222 | */ | |
36375005 | 223 | virtual string DescURI() = 0; |
3174e150 MV |
224 | /** \brief Short item description. |
225 | * | |
226 | * \return a brief description of the object being fetched. | |
227 | */ | |
7db98ffc | 228 | virtual string ShortDesc() {return DescURI();} |
3174e150 MV |
229 | |
230 | /** \brief Invoked by the worker when the download is completely done. */ | |
ab559b35 | 231 | virtual void Finished() {}; |
17caf1b1 | 232 | |
495e5cb2 | 233 | /** \brief HashSum |
3174e150 | 234 | * |
495e5cb2 | 235 | * \return the HashSum of this object, if applicable; otherwise, an |
3174e150 MV |
236 | * empty string. |
237 | */ | |
495e5cb2 | 238 | virtual string HashSum() {return string();}; |
3174e150 MV |
239 | |
240 | /** \return the acquire process with which this item is associated. */ | |
c5ccf175 | 241 | pkgAcquire *GetOwner() {return Owner;}; |
3174e150 MV |
242 | |
243 | /** \return \b true if this object is being fetched from a trusted source. */ | |
7db98ffc | 244 | virtual bool IsTrusted() {return false;}; |
3174e150 MV |
245 | |
246 | /** \brief Initialize an item. | |
247 | * | |
248 | * Adds the item to the list of items known to the acquire | |
249 | * process, but does not place it into any fetch queues (you must | |
250 | * manually invoke QueueURI() to do so). | |
251 | * | |
252 | * Initializes all fields of the item other than Owner to 0, | |
253 | * false, or the empty string. | |
254 | * | |
255 | * \param Owner The new owner of this item. | |
256 | */ | |
0118833a | 257 | Item(pkgAcquire *Owner); |
3174e150 MV |
258 | |
259 | /** \brief Remove this item from its owner's queue by invoking | |
260 | * pkgAcquire::Remove. | |
261 | */ | |
0118833a AL |
262 | virtual ~Item(); |
263 | }; | |
92fcbfc1 DK |
264 | /*}}}*/ |
265 | /** \brief Information about an index patch (aka diff). */ /*{{{*/ | |
002d9943 | 266 | struct DiffInfo { |
3174e150 | 267 | /** The filename of the diff. */ |
002d9943 | 268 | string file; |
3174e150 MV |
269 | |
270 | /** The sha1 hash of the diff. */ | |
002d9943 | 271 | string sha1; |
3174e150 MV |
272 | |
273 | /** The size of the diff. */ | |
002d9943 MV |
274 | unsigned long size; |
275 | }; | |
92fcbfc1 DK |
276 | /*}}}*/ |
277 | /** \brief An item that is responsible for fetching an index file of {{{ | |
3174e150 MV |
278 | * package list diffs and starting the package list's download. |
279 | * | |
280 | * This item downloads the Index file and parses it, then enqueues | |
281 | * additional downloads of either the individual patches (using | |
282 | * pkgAcqIndexDiffs) or the entire Packages file (using pkgAcqIndex). | |
283 | * | |
284 | * \sa pkgAcqIndexDiffs, pkgAcqIndex | |
285 | */ | |
2237bd01 MV |
286 | class pkgAcqDiffIndex : public pkgAcquire::Item |
287 | { | |
288 | protected: | |
3174e150 | 289 | /** \brief If \b true, debugging information will be written to std::clog. */ |
2237bd01 | 290 | bool Debug; |
3174e150 MV |
291 | |
292 | /** \brief The item that is currently being downloaded. */ | |
002d9943 | 293 | pkgAcquire::ItemDesc Desc; |
3174e150 MV |
294 | |
295 | /** \brief The URI of the index file to recreate at our end (either | |
296 | * by downloading it or by applying partial patches). | |
297 | */ | |
2237bd01 | 298 | string RealURI; |
3174e150 | 299 | |
495e5cb2 | 300 | /** \brief The Hash that the real index file should have after |
3174e150 MV |
301 | * all patches have been applied. |
302 | */ | |
495e5cb2 | 303 | HashString ExpectedHash; |
3174e150 MV |
304 | |
305 | /** \brief The index file which will be patched to generate the new | |
306 | * file. | |
307 | */ | |
002d9943 | 308 | string CurrentPackagesFile; |
3174e150 MV |
309 | |
310 | /** \brief A description of the Packages file (stored in | |
311 | * pkgAcquire::ItemDesc::Description). | |
312 | */ | |
002d9943 | 313 | string Description; |
2237bd01 MV |
314 | |
315 | public: | |
316 | // Specialized action members | |
317 | virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf); | |
318 | virtual void Done(string Message,unsigned long Size,string Md5Hash, | |
319 | pkgAcquire::MethodConfig *Cnf); | |
320 | virtual string DescURI() {return RealURI + "Index";}; | |
321 | virtual string Custom600Headers(); | |
322 | ||
3174e150 MV |
323 | /** \brief Parse the Index file for a set of Packages diffs. |
324 | * | |
325 | * Parses the Index file and creates additional download items as | |
326 | * necessary. | |
327 | * | |
328 | * \param IndexDiffFile The name of the Index file. | |
329 | * | |
330 | * \return \b true if the Index file was successfully parsed, \b | |
331 | * false otherwise. | |
332 | */ | |
2237bd01 MV |
333 | bool ParseDiffIndex(string IndexDiffFile); |
334 | ||
3174e150 MV |
335 | |
336 | /** \brief Create a new pkgAcqDiffIndex. | |
337 | * | |
338 | * \param Owner The Acquire object that owns this item. | |
339 | * | |
340 | * \param URI The URI of the list file to download. | |
341 | * | |
342 | * \param URIDesc A long description of the list file to download. | |
343 | * | |
344 | * \param ShortDesc A short description of the list file to download. | |
345 | * | |
495e5cb2 | 346 | * \param ExpectedHash The list file's MD5 signature. |
3174e150 | 347 | */ |
2237bd01 | 348 | pkgAcqDiffIndex(pkgAcquire *Owner,string URI,string URIDesc, |
495e5cb2 | 349 | string ShortDesc, HashString ExpectedHash); |
002d9943 | 350 | }; |
92fcbfc1 DK |
351 | /*}}}*/ |
352 | /** \brief An item that is responsible for fetching all the patches {{{ | |
3174e150 MV |
353 | * that need to be applied to a given package index file. |
354 | * | |
355 | * After downloading and applying a single patch, this item will | |
356 | * enqueue a new pkgAcqIndexDiffs to download and apply the remaining | |
357 | * patches. If no patch can be found that applies to an intermediate | |
358 | * file or if one of the patches cannot be downloaded, falls back to | |
359 | * downloading the entire package index file using pkgAcqIndex. | |
360 | * | |
361 | * \sa pkgAcqDiffIndex, pkgAcqIndex | |
362 | */ | |
ac5b205a MV |
363 | class pkgAcqIndexDiffs : public pkgAcquire::Item |
364 | { | |
3174e150 MV |
365 | private: |
366 | ||
367 | /** \brief Queue up the next diff download. | |
368 | * | |
369 | * Search for the next available diff that applies to the file | |
370 | * that currently exists on disk, and enqueue it by calling | |
371 | * QueueURI(). | |
372 | * | |
373 | * \return \b true if an applicable diff was found, \b false | |
374 | * otherwise. | |
375 | */ | |
376 | bool QueueNextDiff(); | |
377 | ||
378 | /** \brief Handle tasks that must be performed after the item | |
379 | * finishes downloading. | |
380 | * | |
381 | * Dequeues the item and checks the resulting file's md5sum | |
495e5cb2 | 382 | * against ExpectedHash after the last patch was applied. |
3174e150 MV |
383 | * There is no need to check the md5/sha1 after a "normal" |
384 | * patch because QueueNextDiff() will check the sha1 later. | |
385 | * | |
386 | * \param allDone If \b true, the file was entirely reconstructed, | |
387 | * and its md5sum is verified. | |
388 | */ | |
389 | void Finish(bool allDone=false); | |
390 | ||
ac5b205a | 391 | protected: |
3174e150 MV |
392 | |
393 | /** \brief If \b true, debugging output will be written to | |
394 | * std::clog. | |
395 | */ | |
ac5b205a | 396 | bool Debug; |
3174e150 MV |
397 | |
398 | /** \brief A description of the item that is currently being | |
399 | * downloaded. | |
400 | */ | |
ac5b205a | 401 | pkgAcquire::ItemDesc Desc; |
3174e150 MV |
402 | |
403 | /** \brief The URI of the package index file that is being | |
404 | * reconstructed. | |
405 | */ | |
ac5b205a | 406 | string RealURI; |
3174e150 | 407 | |
495e5cb2 | 408 | /** \brief The HashSum of the package index file that is being |
3174e150 MV |
409 | * reconstructed. |
410 | */ | |
495e5cb2 | 411 | HashString ExpectedHash; |
4a0a786f | 412 | |
3174e150 | 413 | /** A description of the file being downloaded. */ |
ac5b205a | 414 | string Description; |
3174e150 MV |
415 | |
416 | /** The patches that remain to be downloaded, including the patch | |
417 | * being downloaded right now. This list should be ordered so | |
418 | * that each diff appears before any diff that depends on it. | |
419 | * | |
420 | * \todo These are indexed by sha1sum; why not use some sort of | |
421 | * dictionary instead of relying on ordering and stripping them | |
422 | * off the front? | |
423 | */ | |
94dc9d7d | 424 | vector<DiffInfo> available_patches; |
3174e150 MV |
425 | /** The current status of this patch. */ |
426 | enum DiffState | |
427 | { | |
428 | /** \brief The diff is in an unknown state. */ | |
429 | StateFetchUnkown, | |
430 | ||
431 | /** \brief The diff is currently being fetched. */ | |
432 | StateFetchDiff, | |
433 | ||
434 | /** \brief The diff is currently being uncompressed. */ | |
435 | StateUnzipDiff, | |
436 | ||
437 | /** \brief The diff is currently being applied. */ | |
438 | StateApplyDiff | |
439 | } State; | |
6cb30d01 | 440 | |
ac5b205a MV |
441 | public: |
442 | ||
3174e150 MV |
443 | /** \brief Called when the patch file failed to be downloaded. |
444 | * | |
445 | * This method will fall back to downloading the whole index file | |
446 | * outright; its arguments are ignored. | |
447 | */ | |
ac5b205a | 448 | virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf); |
3174e150 | 449 | |
ac5b205a MV |
450 | virtual void Done(string Message,unsigned long Size,string Md5Hash, |
451 | pkgAcquire::MethodConfig *Cnf); | |
452 | virtual string DescURI() {return RealURI + "Index";}; | |
ac5b205a | 453 | |
3174e150 MV |
454 | /** \brief Create an index diff item. |
455 | * | |
456 | * After filling in its basic fields, this invokes Finish(true) if | |
457 | * #diffs is empty, or QueueNextDiff() otherwise. | |
458 | * | |
459 | * \param Owner The pkgAcquire object that owns this item. | |
460 | * | |
461 | * \param URI The URI of the package index file being | |
462 | * reconstructed. | |
463 | * | |
464 | * \param URIDesc A long description of this item. | |
465 | * | |
466 | * \param ShortDesc A brief description of this item. | |
467 | * | |
495e5cb2 | 468 | * \param ExpectedHash The expected md5sum of the completely |
3174e150 MV |
469 | * reconstructed package index file; the index file will be tested |
470 | * against this value when it is entirely reconstructed. | |
471 | * | |
472 | * \param diffs The remaining diffs from the index of diffs. They | |
473 | * should be ordered so that each diff appears before any diff | |
474 | * that depends on it. | |
475 | */ | |
ac5b205a | 476 | pkgAcqIndexDiffs(pkgAcquire *Owner,string URI,string URIDesc, |
495e5cb2 | 477 | string ShortDesc, HashString ExpectedHash, |
6cb30d01 | 478 | vector<DiffInfo> diffs=vector<DiffInfo>()); |
ac5b205a | 479 | }; |
92fcbfc1 DK |
480 | /*}}}*/ |
481 | /** \brief An acquire item that is responsible for fetching an index {{{ | |
3174e150 MV |
482 | * file (e.g., Packages or Sources). |
483 | * | |
484 | * \sa pkgAcqDiffIndex, pkgAcqIndexDiffs, pkgAcqIndexTrans | |
485 | * | |
486 | * \todo Why does pkgAcqIndex have protected members? | |
487 | */ | |
0118833a AL |
488 | class pkgAcqIndex : public pkgAcquire::Item |
489 | { | |
490 | protected: | |
3174e150 MV |
491 | |
492 | /** \brief If \b true, the index file has been decompressed. */ | |
8b89e57f | 493 | bool Decompression; |
3174e150 MV |
494 | |
495 | /** \brief If \b true, the partially downloaded file will be | |
496 | * removed when the download completes. | |
497 | */ | |
bfd22fc0 | 498 | bool Erase; |
3174e150 MV |
499 | |
500 | /** \brief The download request that is currently being | |
501 | * processed. | |
502 | */ | |
8267fe24 | 503 | pkgAcquire::ItemDesc Desc; |
3174e150 MV |
504 | |
505 | /** \brief The object that is actually being fetched (minus any | |
506 | * compression-related extensions). | |
507 | */ | |
b2e465d6 | 508 | string RealURI; |
3174e150 | 509 | |
495e5cb2 MV |
510 | /** \brief The expected hashsum of the decompressed index file. */ |
511 | HashString ExpectedHash; | |
3174e150 MV |
512 | |
513 | /** \brief The compression-related file extension that is being | |
514 | * added to the downloaded file (e.g., ".gz" or ".bz2"). | |
515 | */ | |
13e8426f MV |
516 | string CompressionExtension; |
517 | ||
0118833a AL |
518 | public: |
519 | ||
17caf1b1 | 520 | // Specialized action members |
debc84b2 | 521 | virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf); |
459681d3 AL |
522 | virtual void Done(string Message,unsigned long Size,string Md5Hash, |
523 | pkgAcquire::MethodConfig *Cnf); | |
0a8a80e5 | 524 | virtual string Custom600Headers(); |
13e8426f | 525 | virtual string DescURI() {return RealURI + CompressionExtension;}; |
8a8feb29 | 526 | virtual string HashSum() {return ExpectedHash.toStr(); }; |
0118833a | 527 | |
3174e150 MV |
528 | /** \brief Create a pkgAcqIndex. |
529 | * | |
530 | * \param Owner The pkgAcquire object with which this item is | |
531 | * associated. | |
532 | * | |
533 | * \param URI The URI of the index file that is to be downloaded. | |
534 | * | |
535 | * \param URIDesc A "URI-style" description of this index file. | |
536 | * | |
537 | * \param ShortDesc A brief description of this index file. | |
538 | * | |
495e5cb2 | 539 | * \param ExpectedHash The expected hashsum of this index file. |
3174e150 MV |
540 | * |
541 | * \param compressExt The compression-related extension with which | |
542 | * this index file should be downloaded, or "" to autodetect | |
543 | * (".bz2" is used if bzip2 is installed, ".gz" otherwise). | |
544 | */ | |
b2e465d6 | 545 | pkgAcqIndex(pkgAcquire *Owner,string URI,string URIDesc, |
495e5cb2 | 546 | string ShortDesc, HashString ExpectedHash, string compressExt=""); |
0118833a | 547 | }; |
92fcbfc1 DK |
548 | /*}}}*/ |
549 | /** \brief An acquire item that is responsible for fetching a {{{ | |
3174e150 MV |
550 | * translated index file. |
551 | * | |
552 | * The only difference from pkgAcqIndex is that transient failures | |
553 | * are suppressed: no error occurs if the translated index file is | |
554 | * missing. | |
555 | */ | |
a52f938b OS |
556 | class pkgAcqIndexTrans : public pkgAcqIndex |
557 | { | |
558 | public: | |
559 | ||
560 | virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf); | |
3174e150 MV |
561 | |
562 | /** \brief Create a pkgAcqIndexTrans. | |
563 | * | |
564 | * \param Owner The pkgAcquire object with which this item is | |
565 | * associated. | |
566 | * | |
567 | * \param URI The URI of the index file that is to be downloaded. | |
568 | * | |
569 | * \param URIDesc A "URI-style" description of this index file. | |
570 | * | |
571 | * \param ShortDesc A brief description of this index file. | |
572 | * | |
495e5cb2 | 573 | * \param ExpectedHash The expected hashsum of this index file. |
3174e150 MV |
574 | * |
575 | * \param compressExt The compression-related extension with which | |
576 | * this index file should be downloaded, or "" to autodetect | |
577 | * (".bz2" is used if bzip2 is installed, ".gz" otherwise). | |
578 | */ | |
a52f938b | 579 | pkgAcqIndexTrans(pkgAcquire *Owner,string URI,string URIDesc, |
3174e150 | 580 | string ShortDesc); |
a52f938b | 581 | }; |
92fcbfc1 DK |
582 | /*}}}*/ |
583 | /** \brief Information about an index file. */ /*{{{*/ | |
7db98ffc MZ |
584 | struct IndexTarget |
585 | { | |
3174e150 | 586 | /** \brief A URI from which the index file can be downloaded. */ |
7db98ffc | 587 | string URI; |
3174e150 MV |
588 | |
589 | /** \brief A description of the index file. */ | |
7db98ffc | 590 | string Description; |
3174e150 MV |
591 | |
592 | /** \brief A shorter description of the index file. */ | |
7db98ffc | 593 | string ShortDesc; |
3174e150 MV |
594 | |
595 | /** \brief The key by which this index file should be | |
596 | * looked up within the meta signature file. | |
597 | */ | |
7db98ffc MZ |
598 | string MetaKey; |
599 | }; | |
92fcbfc1 DK |
600 | /*}}}*/ |
601 | /** \brief An acquire item that downloads the detached signature {{{ | |
3174e150 MV |
602 | * of a meta-index (Release) file, then queues up the release |
603 | * file itself. | |
604 | * | |
605 | * \todo Why protected members? | |
606 | * | |
607 | * \sa pkgAcqMetaIndex | |
608 | */ | |
7db98ffc | 609 | class pkgAcqMetaSig : public pkgAcquire::Item |
0118833a AL |
610 | { |
611 | protected: | |
ef942597 MV |
612 | /** \brief The last good signature file */ |
613 | string LastGoodSig; | |
614 | ||
615 | ||
3174e150 | 616 | /** \brief The fetch request that is currently being processed. */ |
8267fe24 | 617 | pkgAcquire::ItemDesc Desc; |
3174e150 MV |
618 | |
619 | /** \brief The URI of the signature file. Unlike Desc.URI, this is | |
620 | * never modified; it is used to determine the file that is being | |
621 | * downloaded. | |
622 | */ | |
623 | string RealURI; | |
624 | ||
625 | /** \brief The URI of the meta-index file to be fetched after the signature. */ | |
626 | string MetaIndexURI; | |
627 | ||
628 | /** \brief A "URI-style" description of the meta-index file to be | |
629 | * fetched after the signature. | |
630 | */ | |
631 | string MetaIndexURIDesc; | |
632 | ||
633 | /** \brief A brief description of the meta-index file to be fetched | |
634 | * after the signature. | |
635 | */ | |
636 | string MetaIndexShortDesc; | |
637 | ||
638 | /** \brief A package-system-specific parser for the meta-index file. */ | |
7db98ffc | 639 | indexRecords* MetaIndexParser; |
3174e150 MV |
640 | |
641 | /** \brief The index files which should be looked up in the meta-index | |
642 | * and then downloaded. | |
643 | * | |
644 | * \todo Why a list of pointers instead of a list of structs? | |
645 | */ | |
7db98ffc MZ |
646 | const vector<struct IndexTarget*>* IndexTargets; |
647 | ||
0118833a AL |
648 | public: |
649 | ||
17caf1b1 | 650 | // Specialized action members |
681d76d0 | 651 | virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf); |
459681d3 | 652 | virtual void Done(string Message,unsigned long Size,string Md5Hash, |
7db98ffc | 653 | pkgAcquire::MethodConfig *Cnf); |
0a8a80e5 | 654 | virtual string Custom600Headers(); |
7db98ffc MZ |
655 | virtual string DescURI() {return RealURI; }; |
656 | ||
3174e150 | 657 | /** \brief Create a new pkgAcqMetaSig. */ |
7db98ffc MZ |
658 | pkgAcqMetaSig(pkgAcquire *Owner,string URI,string URIDesc, string ShortDesc, |
659 | string MetaIndexURI, string MetaIndexURIDesc, string MetaIndexShortDesc, | |
660 | const vector<struct IndexTarget*>* IndexTargets, | |
661 | indexRecords* MetaIndexParser); | |
662 | }; | |
92fcbfc1 DK |
663 | /*}}}*/ |
664 | /** \brief An item that is responsible for downloading the meta-index {{{ | |
3174e150 MV |
665 | * file (i.e., Release) itself and verifying its signature. |
666 | * | |
667 | * Once the download and verification are complete, the downloads of | |
668 | * the individual index files are queued up using pkgAcqDiffIndex. | |
495e5cb2 | 669 | * If the meta-index file had a valid signature, the expected hashsums |
3174e150 | 670 | * of the index files will be the md5sums listed in the meta-index; |
495e5cb2 | 671 | * otherwise, the expected hashsums will be "" (causing the |
3174e150 MV |
672 | * authentication of the index files to be bypassed). |
673 | */ | |
7db98ffc MZ |
674 | class pkgAcqMetaIndex : public pkgAcquire::Item |
675 | { | |
676 | protected: | |
3174e150 | 677 | /** \brief The fetch command that is currently being processed. */ |
7db98ffc | 678 | pkgAcquire::ItemDesc Desc; |
3174e150 MV |
679 | |
680 | /** \brief The URI that is actually being downloaded; never | |
681 | * modified by pkgAcqMetaIndex. | |
682 | */ | |
683 | string RealURI; | |
684 | ||
685 | /** \brief The file in which the signature for this index was stored. | |
686 | * | |
687 | * If empty, the signature and the md5sums of the individual | |
688 | * indices will not be checked. | |
689 | */ | |
7db98ffc | 690 | string SigFile; |
3174e150 MV |
691 | |
692 | /** \brief The index files to download. */ | |
7db98ffc | 693 | const vector<struct IndexTarget*>* IndexTargets; |
3174e150 MV |
694 | |
695 | /** \brief The parser for the meta-index file. */ | |
7db98ffc | 696 | indexRecords* MetaIndexParser; |
3174e150 MV |
697 | |
698 | /** \brief If \b true, the index's signature is currently being verified. | |
699 | */ | |
7db98ffc | 700 | bool AuthPass; |
ce424cd4 MV |
701 | // required to deal gracefully with problems caused by incorrect ims hits |
702 | bool IMSHit; | |
7db98ffc | 703 | |
3174e150 MV |
704 | /** \brief Check that the release file is a release file for the |
705 | * correct distribution. | |
706 | * | |
707 | * \return \b true if no fatal errors were encountered. | |
708 | */ | |
ce424cd4 | 709 | bool VerifyVendor(string Message); |
3174e150 MV |
710 | |
711 | /** \brief Called when a file is finished being retrieved. | |
712 | * | |
713 | * If the file was not downloaded to DestFile, a copy process is | |
714 | * set up to copy it to DestFile; otherwise, Complete is set to \b | |
715 | * true and the file is moved to its final location. | |
716 | * | |
717 | * \param Message The message block received from the fetch | |
718 | * subprocess. | |
719 | */ | |
7db98ffc | 720 | void RetrievalDone(string Message); |
3174e150 MV |
721 | |
722 | /** \brief Called when authentication succeeded. | |
723 | * | |
724 | * Sanity-checks the authenticated file, queues up the individual | |
725 | * index files for download, and saves the signature in the lists | |
726 | * directory next to the authenticated list file. | |
727 | * | |
728 | * \param Message The message block received from the fetch | |
729 | * subprocess. | |
730 | */ | |
7db98ffc | 731 | void AuthDone(string Message); |
3174e150 MV |
732 | |
733 | /** \brief Starts downloading the individual index files. | |
734 | * | |
495e5cb2 | 735 | * \param verify If \b true, only indices whose expected hashsum |
3174e150 | 736 | * can be determined from the meta-index will be downloaded, and |
495e5cb2 | 737 | * the hashsums of indices will be checked (reporting |
3174e150 | 738 | * #StatAuthError if there is a mismatch). If verify is \b false, |
495e5cb2 | 739 | * no hashsum checking will be performed. |
3174e150 | 740 | */ |
7db98ffc MZ |
741 | void QueueIndexes(bool verify); |
742 | ||
743 | public: | |
0a8a80e5 | 744 | |
7db98ffc MZ |
745 | // Specialized action members |
746 | virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf); | |
495e5cb2 | 747 | virtual void Done(string Message,unsigned long Size, string Hash, |
7db98ffc MZ |
748 | pkgAcquire::MethodConfig *Cnf); |
749 | virtual string Custom600Headers(); | |
750 | virtual string DescURI() {return RealURI; }; | |
751 | ||
3174e150 | 752 | /** \brief Create a new pkgAcqMetaIndex. */ |
7db98ffc MZ |
753 | pkgAcqMetaIndex(pkgAcquire *Owner, |
754 | string URI,string URIDesc, string ShortDesc, | |
755 | string SigFile, | |
756 | const vector<struct IndexTarget*>* IndexTargets, | |
757 | indexRecords* MetaIndexParser); | |
0118833a | 758 | }; |
92fcbfc1 DK |
759 | /*}}}*/ |
760 | /** \brief An item that is responsible for fetching a package file. {{{ | |
3174e150 MV |
761 | * |
762 | * If the package file already exists in the cache, nothing will be | |
763 | * done. | |
764 | */ | |
03e39e59 AL |
765 | class pkgAcqArchive : public pkgAcquire::Item |
766 | { | |
767 | protected: | |
3174e150 | 768 | /** \brief The package version being fetched. */ |
03e39e59 | 769 | pkgCache::VerIterator Version; |
3174e150 MV |
770 | |
771 | /** \brief The fetch command that is currently being processed. */ | |
03e39e59 | 772 | pkgAcquire::ItemDesc Desc; |
3174e150 MV |
773 | |
774 | /** \brief The list of sources from which to pick archives to | |
775 | * download this package from. | |
776 | */ | |
03e39e59 | 777 | pkgSourceList *Sources; |
3174e150 MV |
778 | |
779 | /** \brief A package records object, used to look up the file | |
780 | * corresponding to each version of the package. | |
781 | */ | |
03e39e59 | 782 | pkgRecords *Recs; |
3174e150 | 783 | |
495e5cb2 | 784 | /** \brief The hashsum of this package. */ |
8a8feb29 | 785 | HashString ExpectedHash; |
3174e150 MV |
786 | |
787 | /** \brief A location in which the actual filename of the package | |
788 | * should be stored. | |
789 | */ | |
30e1eab5 | 790 | string &StoreFilename; |
3174e150 MV |
791 | |
792 | /** \brief The next file for this version to try to download. */ | |
b185acc2 | 793 | pkgCache::VerFileIterator Vf; |
3174e150 MV |
794 | |
795 | /** \brief How many (more) times to try to find a new source from | |
796 | * which to download this package version if it fails. | |
797 | * | |
798 | * Set from Acquire::Retries. | |
799 | */ | |
7d8afa39 | 800 | unsigned int Retries; |
3174e150 MV |
801 | |
802 | /** \brief \b true if this version file is being downloaded from a | |
803 | * trusted source. | |
804 | */ | |
7db98ffc | 805 | bool Trusted; |
17caf1b1 | 806 | |
3174e150 | 807 | /** \brief Queue up the next available file for this version. */ |
b185acc2 | 808 | bool QueueNext(); |
03e39e59 AL |
809 | |
810 | public: | |
811 | ||
7d8afa39 | 812 | virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf); |
495e5cb2 | 813 | virtual void Done(string Message,unsigned long Size,string Hash, |
459681d3 | 814 | pkgAcquire::MethodConfig *Cnf); |
36375005 | 815 | virtual string DescURI() {return Desc.URI;}; |
7db98ffc | 816 | virtual string ShortDesc() {return Desc.ShortDesc;}; |
ab559b35 | 817 | virtual void Finished(); |
8a8feb29 | 818 | virtual string HashSum() {return ExpectedHash.toStr(); }; |
7db98ffc | 819 | virtual bool IsTrusted(); |
03e39e59 | 820 | |
3174e150 MV |
821 | /** \brief Create a new pkgAcqArchive. |
822 | * | |
823 | * \param Owner The pkgAcquire object with which this item is | |
824 | * associated. | |
825 | * | |
826 | * \param Sources The sources from which to download version | |
827 | * files. | |
828 | * | |
829 | * \param Recs A package records object, used to look up the file | |
830 | * corresponding to each version of the package. | |
831 | * | |
832 | * \param Version The package version to download. | |
833 | * | |
834 | * \param StoreFilename A location in which the actual filename of | |
835 | * the package should be stored. It will be set to a guessed | |
836 | * basename in the constructor, and filled in with a fully | |
837 | * qualified filename once the download finishes. | |
838 | */ | |
03e39e59 | 839 | pkgAcqArchive(pkgAcquire *Owner,pkgSourceList *Sources, |
30e1eab5 AL |
840 | pkgRecords *Recs,pkgCache::VerIterator const &Version, |
841 | string &StoreFilename); | |
03e39e59 | 842 | }; |
92fcbfc1 DK |
843 | /*}}}*/ |
844 | /** \brief Retrieve an arbitrary file to the current directory. {{{ | |
3174e150 MV |
845 | * |
846 | * The file is retrieved even if it is accessed via a URL type that | |
847 | * normally is a NOP, such as "file". If the download fails, the | |
848 | * partial file is renamed to get a ".FAILED" extension. | |
849 | */ | |
36375005 AL |
850 | class pkgAcqFile : public pkgAcquire::Item |
851 | { | |
3174e150 | 852 | /** \brief The currently active download process. */ |
36375005 | 853 | pkgAcquire::ItemDesc Desc; |
3174e150 | 854 | |
495e5cb2 | 855 | /** \brief The hashsum of the file to download, if it is known. */ |
8a8feb29 | 856 | HashString ExpectedHash; |
3174e150 MV |
857 | |
858 | /** \brief How many times to retry the download, set from | |
859 | * Acquire::Retries. | |
860 | */ | |
08cfc005 | 861 | unsigned int Retries; |
36375005 AL |
862 | |
863 | public: | |
864 | ||
865 | // Specialized action members | |
08cfc005 | 866 | virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf); |
495e5cb2 | 867 | virtual void Done(string Message,unsigned long Size,string CalcHash, |
459681d3 | 868 | pkgAcquire::MethodConfig *Cnf); |
36375005 | 869 | virtual string DescURI() {return Desc.URI;}; |
8a8feb29 | 870 | virtual string HashSum() {return ExpectedHash.toStr(); }; |
3174e150 MV |
871 | |
872 | /** \brief Create a new pkgAcqFile object. | |
873 | * | |
874 | * \param Owner The pkgAcquire object with which this object is | |
875 | * associated. | |
876 | * | |
877 | * \param URI The URI to download. | |
878 | * | |
495e5cb2 | 879 | * \param Hash The hashsum of the file to download, if it is known; |
3174e150 MV |
880 | * otherwise "". |
881 | * | |
882 | * \param Size The size of the file to download, if it is known; | |
883 | * otherwise 0. | |
884 | * | |
885 | * \param Desc A description of the file being downloaded. | |
886 | * | |
887 | * \param ShortDesc A brief description of the file being | |
888 | * downloaded. | |
39c7baef MV |
889 | * |
890 | * \param DestDir The directory the file should be downloaded into. | |
891 | * | |
892 | * \param DestFilename The filename+path the file is downloaded to. | |
893 | * | |
894 | * | |
895 | * If DestFilename is empty, download to DestDir/<basename> if | |
896 | * DestDir is non-empty, $CWD/<basename> otherwise. If | |
897 | * DestFilename is NOT empty, DestDir is ignored and DestFilename | |
898 | * is the absolute name to which the file should be downloaded. | |
3174e150 | 899 | */ |
39c7baef | 900 | |
495e5cb2 | 901 | pkgAcqFile(pkgAcquire *Owner, string URI, string Hash, unsigned long Size, |
46e00f9d MV |
902 | string Desc, string ShortDesc, |
903 | const string &DestDir="", const string &DestFilename=""); | |
36375005 | 904 | }; |
92fcbfc1 | 905 | /*}}}*/ |
3174e150 MV |
906 | /** @} */ |
907 | ||
0118833a | 908 | #endif |