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