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