]> git.saurik.com Git - apt.git/blob - apt-pkg/acquire-item.h
Merge remote-tracking branch 'donkult/debian/experimental' into debian/experimental
[apt.git] / apt-pkg / acquire-item.h
1 // -*- mode: cpp; mode: fold -*-
2 // Description /*{{{*/
3 // $Id: acquire-item.h,v 1.26.2.3 2004/01/02 18:51:00 mdz Exp $
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
10 register all the URI's they wish to fetch at the initial moment.
11
12 Three item classes are provided to provide functionality for
13 downloading of Index, Translation and Packages files.
14
15 A Archive class is provided for downloading .deb files. It does Hash
16 checking and source location as well as a retry algorithm.
17
18 ##################################################################### */
19 /*}}}*/
20 #ifndef PKGLIB_ACQUIRE_ITEM_H
21 #define PKGLIB_ACQUIRE_ITEM_H
22
23 #include <apt-pkg/acquire.h>
24 #include <apt-pkg/hashes.h>
25 #include <apt-pkg/weakptr.h>
26 #include <apt-pkg/pkgcache.h>
27 #include <apt-pkg/cacheiterators.h>
28
29 #include <string>
30 #include <vector>
31
32 #ifndef APT_8_CLEANER_HEADERS
33 #include <apt-pkg/indexfile.h>
34 #include <apt-pkg/vendor.h>
35 #include <apt-pkg/sourcelist.h>
36 #include <apt-pkg/pkgrecords.h>
37 #include <apt-pkg/indexrecords.h>
38 #endif
39
40 /** \addtogroup acquire
41 * @{
42 *
43 * \file acquire-item.h
44 */
45
46 class indexRecords;
47 class pkgRecords;
48 class pkgSourceList;
49 class IndexTarget;
50
51 /** \brief Represents the process by which a pkgAcquire object should {{{
52 * retrieve a file or a collection of files.
53 *
54 * By convention, Item subclasses should insert themselves into the
55 * acquire queue when they are created by calling QueueURI(), and
56 * remove themselves by calling Dequeue() when either Done() or
57 * Failed() is invoked. Item objects are also responsible for
58 * notifying the download progress indicator (accessible via
59 * #Owner->Log) of their status.
60 *
61 * \see pkgAcquire
62 */
63 class pkgAcquire::Item : public WeakPointable
64 {
65 protected:
66
67 /** \brief The acquire object with which this item is associated. */
68 pkgAcquire *Owner;
69
70 /** \brief Insert this item into its owner's queue.
71 *
72 * \param Item Metadata about this item (its URI and
73 * description).
74 */
75 inline void QueueURI(ItemDesc &Item)
76 {Owner->Enqueue(Item);};
77
78 /** \brief Remove this item from its owner's queue. */
79 inline void Dequeue() {Owner->Dequeue(this);};
80
81 /** \brief Rename a file without modifying its timestamp.
82 *
83 * Many item methods call this as their final action.
84 *
85 * \param From The file to be renamed.
86 *
87 * \param To The new name of \a From. If \a To exists it will be
88 * overwritten.
89 */
90 void Rename(std::string From,std::string To);
91
92 public:
93
94 /** \brief The current status of this item. */
95 enum ItemState
96 {
97 /** \brief The item is waiting to be downloaded. */
98 StatIdle,
99
100 /** \brief The item is currently being downloaded. */
101 StatFetching,
102
103 /** \brief The item has been successfully downloaded. */
104 StatDone,
105
106 /** \brief An error was encountered while downloading this
107 * item.
108 */
109 StatError,
110
111 /** \brief The item was downloaded but its authenticity could
112 * not be verified.
113 */
114 StatAuthError,
115
116 /** \brief The item was could not be downloaded because of
117 * a transient network error (e.g. network down)
118 */
119 StatTransientNetworkError
120 } Status;
121
122 /** \brief Contains a textual description of the error encountered
123 * if #ItemState is #StatError or #StatAuthError.
124 */
125 std::string ErrorText;
126
127 /** \brief The size of the object to fetch. */
128 unsigned long long FileSize;
129
130 /** \brief How much of the object was already fetched. */
131 unsigned long long PartialSize;
132
133 /** \brief If not \b NULL, contains the name of a subprocess that
134 * is operating on this object (for instance, "gzip" or "gpgv").
135 */
136 APT_DEPRECATED const char *Mode;
137
138 /** \brief contains the name of the subprocess that is operating on this object
139 * (for instance, "gzip", "rred" or "gpgv"). This is obsoleting #Mode from above
140 * as it can manage the lifetime of included string properly. */
141 std::string ActiveSubprocess;
142
143 /** \brief A client-supplied unique identifier.
144 *
145 * This field is initalized to 0; it is meant to be filled in by
146 * clients that wish to use it to uniquely identify items.
147 *
148 * \todo it's unused in apt itself
149 */
150 unsigned long ID;
151
152 /** \brief If \b true, the entire object has been successfully fetched.
153 *
154 * Subclasses should set this to \b true when appropriate.
155 */
156 bool Complete;
157
158 /** \brief If \b true, the URI of this object is "local".
159 *
160 * The only effect of this field is to exclude the object from the
161 * download progress indicator's overall statistics.
162 */
163 bool Local;
164 std::string UsedMirror;
165
166 /** \brief The number of fetch queues into which this item has been
167 * inserted.
168 *
169 * There is one queue for each source from which an item could be
170 * downloaded.
171 *
172 * \sa pkgAcquire
173 */
174 unsigned int QueueCounter;
175
176 /** \brief The number of additional fetch items that are expected
177 * once this item is done.
178 *
179 * Some items like pkgAcqMeta{Index,Sig} will queue additional
180 * items. This variable can be set by the methods if it knows
181 * in advance how many items to expect to get a more accurate
182 * progress.
183 */
184 unsigned int ExpectedAdditionalItems;
185
186 /** \brief The name of the file into which the retrieved object
187 * will be written.
188 */
189 std::string DestFile;
190
191 /** \brief Invoked by the acquire worker when the object couldn't
192 * be fetched.
193 *
194 * This is a branch of the continuation of the fetch process.
195 *
196 * \param Message An RFC822-formatted message from the acquire
197 * method describing what went wrong. Use LookupTag() to parse
198 * it.
199 *
200 * \param Cnf The method via which the worker tried to fetch this object.
201 *
202 * \sa pkgAcqMethod
203 */
204 virtual void Failed(std::string Message,pkgAcquire::MethodConfig *Cnf);
205
206 /** \brief Invoked by the acquire worker when the object was
207 * fetched successfully.
208 *
209 * Note that the object might \e not have been written to
210 * DestFile; check for the presence of an Alt-Filename entry in
211 * Message to find the file to which it was really written.
212 *
213 * Done is often used to switch from one stage of the processing
214 * to the next (e.g. fetching, unpacking, copying). It is one
215 * branch of the continuation of the fetch process.
216 *
217 * \param Message Data from the acquire method. Use LookupTag()
218 * to parse it.
219 * \param Size The size of the object that was fetched.
220 * \param Hashes The HashSums of the object that was fetched.
221 * \param Cnf The method via which the object was fetched.
222 *
223 * \sa pkgAcqMethod
224 */
225 virtual void Done(std::string Message, unsigned long long Size, HashStringList const &Hashes,
226 pkgAcquire::MethodConfig *Cnf);
227
228 /** \brief Invoked when the worker starts to fetch this object.
229 *
230 * \param Message RFC822-formatted data from the worker process.
231 * Use LookupTag() to parse it.
232 *
233 * \param Size The size of the object being fetched.
234 *
235 * \sa pkgAcqMethod
236 */
237 virtual void Start(std::string Message,unsigned long long Size);
238
239 /** \brief Custom headers to be sent to the fetch process.
240 *
241 * \return a string containing RFC822-style headers that are to be
242 * inserted into the 600 URI Acquire message sent to the fetch
243 * subprocess. The headers are inserted after a newline-less
244 * line, so they should (if nonempty) have a leading newline and
245 * no trailing newline.
246 */
247 virtual std::string Custom600Headers() const {return std::string();};
248
249 /** \brief A "descriptive" URI-like string.
250 *
251 * \return a URI that should be used to describe what is being fetched.
252 */
253 virtual std::string DescURI() = 0;
254 /** \brief Short item description.
255 *
256 * \return a brief description of the object being fetched.
257 */
258 virtual std::string ShortDesc() {return DescURI();}
259
260 /** \brief Invoked by the worker when the download is completely done. */
261 virtual void Finished() {};
262
263 /** \brief HashSums
264 *
265 * \return the HashSums of this object, if applicable; otherwise, an
266 * empty list.
267 */
268 HashStringList HashSums() const {return ExpectedHashes;};
269 std::string HashSum() const {HashStringList const hashes = HashSums(); HashString const * const hs = hashes.find(NULL); return hs != NULL ? hs->toStr() : ""; };
270
271 /** \return the acquire process with which this item is associated. */
272 pkgAcquire *GetOwner() const {return Owner;};
273
274 /** \return \b true if this object is being fetched from a trusted source. */
275 virtual bool IsTrusted() const {return false;};
276
277 // report mirror problems
278 /** \brief Report mirror problem
279 *
280 * This allows reporting mirror failures back to a centralized
281 * server. The apt-report-mirror-failure script is called for this
282 *
283 * \param FailCode A short failure string that is send
284 */
285 void ReportMirrorFailure(std::string FailCode);
286
287
288 /** \brief Initialize an item.
289 *
290 * Adds the item to the list of items known to the acquire
291 * process, but does not place it into any fetch queues (you must
292 * manually invoke QueueURI() to do so).
293 *
294 * \param Owner The new owner of this item.
295 * \param ExpectedHashes of the file represented by this item
296 */
297 Item(pkgAcquire *Owner,
298 HashStringList const &ExpectedHashes=HashStringList());
299
300 /** \brief Remove this item from its owner's queue by invoking
301 * pkgAcquire::Remove.
302 */
303 virtual ~Item();
304
305 protected:
306
307 enum RenameOnErrorState {
308 HashSumMismatch,
309 SizeMismatch,
310 InvalidFormat
311 };
312
313 /** \brief Rename failed file and set error
314 *
315 * \param state respresenting the error we encountered
316 */
317 bool RenameOnError(RenameOnErrorState const state);
318
319 /** \brief The HashSums of the item is supposed to have than done */
320 HashStringList ExpectedHashes;
321
322 /** \brief The item that is currently being downloaded. */
323 pkgAcquire::ItemDesc Desc;
324 };
325 /*}}}*/
326 /** \brief Information about an index patch (aka diff). */ /*{{{*/
327 struct DiffInfo {
328 /** The filename of the diff. */
329 std::string file;
330
331 /** The hashes of the diff */
332 HashStringList result_hashes;
333
334 /** The hashes of the file after the diff is applied */
335 HashStringList patch_hashes;
336
337 /** The size of the file after the diff is applied */
338 unsigned long long result_size;
339
340 /** The size of the diff itself */
341 unsigned long long patch_size;
342 };
343 /*}}}*/
344 /** \brief An item that is responsible for fetching a SubIndex {{{
345 *
346 * The MetaIndex file includes only records for important indexes
347 * and records for these SubIndex files so these can carry records
348 * for addition files like PDiffs and Translations
349 */
350 class pkgAcqSubIndex : public pkgAcquire::Item
351 {
352 protected:
353 /** \brief If \b true, debugging information will be written to std::clog. */
354 bool Debug;
355
356 public:
357 // Specialized action members
358 virtual void Failed(std::string Message,pkgAcquire::MethodConfig *Cnf);
359 virtual void Done(std::string Message,unsigned long long Size, HashStringList const &Hashes,
360 pkgAcquire::MethodConfig *Cnf);
361 virtual std::string DescURI() {return Desc.URI;};
362 virtual std::string Custom600Headers() const;
363 virtual bool ParseIndex(std::string const &IndexFile);
364
365 /** \brief Create a new pkgAcqSubIndex.
366 *
367 * \param Owner The Acquire object that owns this item.
368 *
369 * \param URI The URI of the list file to download.
370 *
371 * \param URIDesc A long description of the list file to download.
372 *
373 * \param ShortDesc A short description of the list file to download.
374 *
375 * \param ExpectedHashes The list file's hashsums which are expected.
376 */
377 pkgAcqSubIndex(pkgAcquire *Owner, std::string const &URI,std::string const &URIDesc,
378 std::string const &ShortDesc, HashStringList const &ExpectedHashes);
379 };
380 /*}}}*/
381
382 /** \brief Common base class for all classes that deal with fetching {{{
383 indexes
384 */
385 class pkgAcqBaseIndex : public pkgAcquire::Item
386 {
387 protected:
388 /** \brief Pointer to the IndexTarget data
389 */
390 const struct IndexTarget * Target;
391 indexRecords *MetaIndexParser;
392
393 pkgAcqBaseIndex(pkgAcquire *Owner,
394 struct IndexTarget const * const Target,
395 HashStringList const &ExpectedHashes,
396 indexRecords *MetaIndexParser)
397 : Item(Owner, ExpectedHashes), Target(Target),
398 MetaIndexParser(MetaIndexParser) {};
399
400 };
401 /*}}}*/
402 /** \brief An item that is responsible for fetching an index file of {{{
403 * package list diffs and starting the package list's download.
404 *
405 * This item downloads the Index file and parses it, then enqueues
406 * additional downloads of either the individual patches (using
407 * pkgAcqIndexDiffs) or the entire Packages file (using pkgAcqIndex).
408 *
409 * \sa pkgAcqIndexDiffs, pkgAcqIndex
410 */
411 class pkgAcqDiffIndex : public pkgAcqBaseIndex
412 {
413 protected:
414 /** \brief If \b true, debugging information will be written to std::clog. */
415 bool Debug;
416
417 /** \brief The URI of the index file to recreate at our end (either
418 * by downloading it or by applying partial patches).
419 */
420 std::string RealURI;
421
422 /** \brief The index file which will be patched to generate the new
423 * file.
424 */
425 std::string CurrentPackagesFile;
426
427 /** \brief A description of the Packages file (stored in
428 * pkgAcquire::ItemDesc::Description).
429 */
430 std::string Description;
431
432 public:
433 // Specialized action members
434 virtual void Failed(std::string Message,pkgAcquire::MethodConfig *Cnf);
435 virtual void Done(std::string Message,unsigned long long Size, HashStringList const &Hashes,
436 pkgAcquire::MethodConfig *Cnf);
437 virtual std::string DescURI() {return RealURI + "Index";};
438 virtual std::string Custom600Headers() const;
439
440 /** \brief Parse the Index file for a set of Packages diffs.
441 *
442 * Parses the Index file and creates additional download items as
443 * necessary.
444 *
445 * \param IndexDiffFile The name of the Index file.
446 *
447 * \return \b true if the Index file was successfully parsed, \b
448 * false otherwise.
449 */
450 bool ParseDiffIndex(std::string IndexDiffFile);
451
452
453 /** \brief Create a new pkgAcqDiffIndex.
454 *
455 * \param Owner The Acquire object that owns this item.
456 *
457 * \param URI The URI of the list file to download.
458 *
459 * \param URIDesc A long description of the list file to download.
460 *
461 * \param ShortDesc A short description of the list file to download.
462 *
463 * \param ExpectedHashes The list file's hashsums which are expected.
464 */
465 pkgAcqDiffIndex(pkgAcquire *Owner,
466 struct IndexTarget const * const Target,
467 HashStringList const &ExpectedHashes,
468 indexRecords *MetaIndexParser);
469 };
470 /*}}}*/
471 /** \brief An item that is responsible for fetching client-merge patches {{{
472 * that need to be applied to a given package index file.
473 *
474 * Instead of downloading and applying each patch one by one like its
475 * sister #pkgAcqIndexDiffs this class will download all patches at once
476 * and call rred with all the patches downloaded once. Rred will then
477 * merge and apply them in one go, which should be a lot faster – but is
478 * incompatible with server-based merges of patches like reprepro can do.
479 *
480 * \sa pkgAcqDiffIndex, pkgAcqIndex
481 */
482 class pkgAcqIndexMergeDiffs : public pkgAcqBaseIndex
483 {
484 protected:
485
486 /** \brief If \b true, debugging output will be written to
487 * std::clog.
488 */
489 bool Debug;
490
491 /** \brief URI of the package index file that is being
492 * reconstructed.
493 */
494 std::string RealURI;
495
496 /** \brief description of the file being downloaded. */
497 std::string Description;
498
499 /** \brief information about the current patch */
500 struct DiffInfo const patch;
501
502 /** \brief list of all download items for the patches */
503 std::vector<pkgAcqIndexMergeDiffs*> const * const allPatches;
504
505 /** The current status of this patch. */
506 enum DiffState
507 {
508 /** \brief The diff is currently being fetched. */
509 StateFetchDiff,
510
511 /** \brief The diff is currently being applied. */
512 StateApplyDiff,
513
514 /** \brief the work with this diff is done */
515 StateDoneDiff,
516
517 /** \brief something bad happened and fallback was triggered */
518 StateErrorDiff
519 } State;
520
521 public:
522 /** \brief Called when the patch file failed to be downloaded.
523 *
524 * This method will fall back to downloading the whole index file
525 * outright; its arguments are ignored.
526 */
527 virtual void Failed(std::string Message,pkgAcquire::MethodConfig *Cnf);
528 virtual void Done(std::string Message,unsigned long long Size, HashStringList const &Hashes,
529 pkgAcquire::MethodConfig *Cnf);
530 virtual std::string DescURI() {return RealURI + "Index";};
531
532 /** \brief Create an index merge-diff item.
533 *
534 * \param Owner The pkgAcquire object that owns this item.
535 *
536 * \param URI The URI of the package index file being
537 * reconstructed.
538 *
539 * \param URIDesc A long description of this item.
540 *
541 * \param ShortDesc A brief description of this item.
542 *
543 * \param ExpectedHashes The expected md5sum of the completely
544 * reconstructed package index file; the index file will be tested
545 * against this value when it is entirely reconstructed.
546 *
547 * \param patch contains infos about the patch this item is supposed
548 * to download which were read from the index
549 *
550 * \param allPatches contains all related items so that each item can
551 * check if it was the last one to complete the download step
552 */
553 pkgAcqIndexMergeDiffs(pkgAcquire *Owner,
554 struct IndexTarget const * const Target,
555 HashStringList const &ExpectedHash,
556 indexRecords *MetaIndexParser,
557 DiffInfo const &patch,
558 std::vector<pkgAcqIndexMergeDiffs*> const * const allPatches);
559 };
560 /*}}}*/
561 /** \brief An item that is responsible for fetching server-merge patches {{{
562 * that need to be applied to a given package index file.
563 *
564 * After downloading and applying a single patch, this item will
565 * enqueue a new pkgAcqIndexDiffs to download and apply the remaining
566 * patches. If no patch can be found that applies to an intermediate
567 * file or if one of the patches cannot be downloaded, falls back to
568 * downloading the entire package index file using pkgAcqIndex.
569 *
570 * \sa pkgAcqDiffIndex, pkgAcqIndex
571 */
572 class pkgAcqIndexDiffs : public pkgAcqBaseIndex
573 {
574 private:
575
576 /** \brief Queue up the next diff download.
577 *
578 * Search for the next available diff that applies to the file
579 * that currently exists on disk, and enqueue it by calling
580 * QueueURI().
581 *
582 * \return \b true if an applicable diff was found, \b false
583 * otherwise.
584 */
585 APT_HIDDEN bool QueueNextDiff();
586
587 /** \brief Handle tasks that must be performed after the item
588 * finishes downloading.
589 *
590 * Dequeues the item and checks the resulting file's hashsums
591 * against ExpectedHashes after the last patch was applied.
592 * There is no need to check the md5/sha1 after a "normal"
593 * patch because QueueNextDiff() will check the sha1 later.
594 *
595 * \param allDone If \b true, the file was entirely reconstructed,
596 * and its md5sum is verified.
597 */
598 APT_HIDDEN void Finish(bool allDone=false);
599
600 protected:
601
602 /** \brief If \b true, debugging output will be written to
603 * std::clog.
604 */
605 bool Debug;
606
607 /** \brief The URI of the package index file that is being
608 * reconstructed.
609 */
610 std::string RealURI;
611
612 /** A description of the file being downloaded. */
613 std::string Description;
614
615 /** The patches that remain to be downloaded, including the patch
616 * being downloaded right now. This list should be ordered so
617 * that each diff appears before any diff that depends on it.
618 *
619 * \todo These are indexed by sha1sum; why not use some sort of
620 * dictionary instead of relying on ordering and stripping them
621 * off the front?
622 */
623 std::vector<DiffInfo> available_patches;
624
625 /** The current status of this patch. */
626 enum DiffState
627 {
628 /** \brief The diff is in an unknown state. */
629 StateFetchUnkown,
630
631 /** \brief The diff is currently being fetched. */
632 StateFetchDiff,
633
634 /** \brief The diff is currently being uncompressed. */
635 StateUnzipDiff, // FIXME: No longer used
636
637 /** \brief The diff is currently being applied. */
638 StateApplyDiff
639 } State;
640
641 public:
642
643 /** \brief Called when the patch file failed to be downloaded.
644 *
645 * This method will fall back to downloading the whole index file
646 * outright; its arguments are ignored.
647 */
648 virtual void Failed(std::string Message,pkgAcquire::MethodConfig *Cnf);
649
650 virtual void Done(std::string Message,unsigned long long Size, HashStringList const &Hashes,
651 pkgAcquire::MethodConfig *Cnf);
652 virtual std::string DescURI() {return RealURI + "Index";};
653
654 /** \brief Create an index diff item.
655 *
656 * After filling in its basic fields, this invokes Finish(true) if
657 * \a diffs is empty, or QueueNextDiff() otherwise.
658 *
659 * \param Owner The pkgAcquire object that owns this item.
660 *
661 * \param URI The URI of the package index file being
662 * reconstructed.
663 *
664 * \param URIDesc A long description of this item.
665 *
666 * \param ShortDesc A brief description of this item.
667 *
668 * \param ExpectedHashes The expected hashsums of the completely
669 * reconstructed package index file; the index file will be tested
670 * against this value when it is entirely reconstructed.
671 *
672 * \param diffs The remaining diffs from the index of diffs. They
673 * should be ordered so that each diff appears before any diff
674 * that depends on it.
675 */
676 pkgAcqIndexDiffs(pkgAcquire *Owner,
677 struct IndexTarget const * const Target,
678 HashStringList const &ExpectedHash,
679 indexRecords *MetaIndexParser,
680 std::vector<DiffInfo> diffs=std::vector<DiffInfo>());
681 };
682 /*}}}*/
683 /** \brief An acquire item that is responsible for fetching an index {{{
684 * file (e.g., Packages or Sources).
685 *
686 * \sa pkgAcqDiffIndex, pkgAcqIndexDiffs, pkgAcqIndexTrans
687 *
688 * \todo Why does pkgAcqIndex have protected members?
689 */
690 class pkgAcqIndex : public pkgAcqBaseIndex
691 {
692 protected:
693
694 /** \brief If \b true, the index file has been decompressed. */
695 bool Decompression;
696
697 /** \brief If \b true, the partially downloaded file will be
698 * removed when the download completes.
699 */
700 bool Erase;
701
702 // Unused, used to be used to verify that "Packages: " header was there
703 bool __DELME_ON_NEXT_ABI_BREAK_Verify;
704
705 /** \brief The object that is actually being fetched (minus any
706 * compression-related extensions).
707 */
708 std::string RealURI;
709
710 /** \brief The compression-related file extensions that are being
711 * added to the downloaded file one by one if first fails (e.g., "gz bz2").
712 */
713 std::string CompressionExtension;
714
715
716 /** \brief Do the changes needed to fetch via AptByHash (if needed) */
717 void InitByHashIfNeeded(const std::string MetaKey);
718
719 /** \brief Get the full pathname of the final file for the given URI
720 */
721 std::string GetFinalFilename(std::string const &URI,
722 std::string const &compExt);
723
724 /** \brief Schedule file for verification after a IMS hit */
725 void ReverifyAfterIMS(std::string const &FileName);
726
727 public:
728
729 // Specialized action members
730 virtual void Failed(std::string Message,pkgAcquire::MethodConfig *Cnf);
731 virtual void Done(std::string Message,unsigned long long Size, HashStringList const &Hashes,
732 pkgAcquire::MethodConfig *Cnf);
733 virtual std::string Custom600Headers() const;
734 virtual std::string DescURI() {return Desc.URI;};
735
736 /** \brief Create a pkgAcqIndex.
737 *
738 * \param Owner The pkgAcquire object with which this item is
739 * associated.
740 *
741 * \param URI The URI of the index file that is to be downloaded.
742 *
743 * \param URIDesc A "URI-style" description of this index file.
744 *
745 * \param ShortDesc A brief description of this index file.
746 *
747 * \param ExpectedHashes The expected hashsum of this index file.
748 *
749 * \param compressExt The compression-related extension with which
750 * this index file should be downloaded, or "" to autodetect
751 * Compression types can be set with config Acquire::CompressionTypes,
752 * default is ".lzma" or ".bz2" (if the needed binaries are present)
753 * fallback is ".gz" or none.
754 */
755 pkgAcqIndex(pkgAcquire *Owner,std::string URI,std::string URIDesc,
756 std::string ShortDesc, HashStringList const &ExpectedHashes,
757 std::string compressExt="");
758 pkgAcqIndex(pkgAcquire *Owner,
759 IndexTarget const * const Target,
760 HashStringList const &ExpectedHash,
761 indexRecords *MetaIndexParser);
762 void Init(std::string const &URI, std::string const &URIDesc,
763 std::string const &ShortDesc);
764 };
765 /*}}}*/
766 /** \brief An acquire item that is responsible for fetching a {{{
767 * translated index file.
768 *
769 * The only difference from pkgAcqIndex is that transient failures
770 * are suppressed: no error occurs if the translated index file is
771 * missing.
772 */
773 class pkgAcqIndexTrans : public pkgAcqIndex
774 {
775 public:
776
777 virtual void Failed(std::string Message,pkgAcquire::MethodConfig *Cnf);
778 virtual std::string Custom600Headers() const;
779
780 /** \brief Create a pkgAcqIndexTrans.
781 *
782 * \param Owner The pkgAcquire object with which this item is
783 * associated.
784 *
785 * \param URI The URI of the index file that is to be downloaded.
786 *
787 * \param URIDesc A "URI-style" description of this index file.
788 *
789 * \param ShortDesc A brief description of this index file.
790 */
791 pkgAcqIndexTrans(pkgAcquire *Owner,std::string URI,std::string URIDesc,
792 std::string ShortDesc);
793 pkgAcqIndexTrans(pkgAcquire *Owner, IndexTarget const * const Target,
794 HashStringList const &ExpectedHashes, indexRecords *MetaIndexParser);
795 };
796 /*}}}*/
797 /** \brief Information about an index file. */ /*{{{*/
798 class IndexTarget
799 {
800 public:
801 /** \brief A URI from which the index file can be downloaded. */
802 std::string URI;
803
804 /** \brief A description of the index file. */
805 std::string Description;
806
807 /** \brief A shorter description of the index file. */
808 std::string ShortDesc;
809
810 /** \brief The key by which this index file should be
811 * looked up within the meta signature file.
812 */
813 std::string MetaKey;
814
815 virtual bool IsOptional() const {
816 return false;
817 }
818 virtual bool IsSubIndex() const {
819 return false;
820 }
821 };
822 /*}}}*/
823 /** \brief Information about an optional index file. */ /*{{{*/
824 class OptionalIndexTarget : public IndexTarget
825 {
826 virtual bool IsOptional() const {
827 return true;
828 }
829 };
830 /*}}}*/
831 /** \brief Information about an subindex index file. */ /*{{{*/
832 class SubIndexTarget : public IndexTarget
833 {
834 virtual bool IsSubIndex() const {
835 return true;
836 }
837 };
838 /*}}}*/
839 /** \brief Information about an subindex index file. */ /*{{{*/
840 class OptionalSubIndexTarget : public OptionalIndexTarget
841 {
842 virtual bool IsSubIndex() const {
843 return true;
844 }
845 };
846 /*}}}*/
847
848 /** \brief An acquire item that downloads the detached signature {{{
849 * of a meta-index (Release) file, then queues up the release
850 * file itself.
851 *
852 * \todo Why protected members?
853 *
854 * \sa pkgAcqMetaIndex
855 */
856 class pkgAcqMetaSig : public pkgAcquire::Item
857 {
858 protected:
859 /** \brief The last good signature file */
860 std::string LastGoodSig;
861
862 /** \brief The URI of the signature file. Unlike Desc.URI, this is
863 * never modified; it is used to determine the file that is being
864 * downloaded.
865 */
866 std::string RealURI;
867
868 /** \brief The URI of the meta-index file to be fetched after the signature. */
869 std::string MetaIndexURI;
870
871 /** \brief A "URI-style" description of the meta-index file to be
872 * fetched after the signature.
873 */
874 std::string MetaIndexURIDesc;
875
876 /** \brief A brief description of the meta-index file to be fetched
877 * after the signature.
878 */
879 std::string MetaIndexShortDesc;
880
881 /** \brief A package-system-specific parser for the meta-index file. */
882 indexRecords* MetaIndexParser;
883
884 /** \brief The index files which should be looked up in the meta-index
885 * and then downloaded.
886 *
887 * \todo Why a list of pointers instead of a list of structs?
888 */
889 const std::vector<IndexTarget*>* IndexTargets;
890
891 public:
892
893 // Specialized action members
894 virtual void Failed(std::string Message,pkgAcquire::MethodConfig *Cnf);
895 virtual void Done(std::string Message,unsigned long long Size, HashStringList const &Hashes,
896 pkgAcquire::MethodConfig *Cnf);
897 virtual std::string Custom600Headers() const;
898 virtual std::string DescURI() {return RealURI; };
899
900 /** \brief Create a new pkgAcqMetaSig. */
901 pkgAcqMetaSig(pkgAcquire *Owner,std::string URI,std::string URIDesc, std::string ShortDesc,
902 std::string MetaIndexURI, std::string MetaIndexURIDesc, std::string MetaIndexShortDesc,
903 const std::vector<IndexTarget*>* IndexTargets,
904 indexRecords* MetaIndexParser);
905 virtual ~pkgAcqMetaSig();
906 };
907 /*}}}*/
908 /** \brief An item that is responsible for downloading the meta-index {{{
909 * file (i.e., Release) itself and verifying its signature.
910 *
911 * Once the download and verification are complete, the downloads of
912 * the individual index files are queued up using pkgAcqDiffIndex.
913 * If the meta-index file had a valid signature, the expected hashsums
914 * of the index files will be the md5sums listed in the meta-index;
915 * otherwise, the expected hashsums will be "" (causing the
916 * authentication of the index files to be bypassed).
917 */
918 class pkgAcqMetaIndex : public pkgAcquire::Item
919 {
920 protected:
921 /** \brief The URI that is actually being downloaded; never
922 * modified by pkgAcqMetaIndex.
923 */
924 std::string RealURI;
925
926 /** \brief The file in which the signature for this index was stored.
927 *
928 * If empty, the signature and the md5sums of the individual
929 * indices will not be checked.
930 */
931 std::string SigFile;
932
933 /** \brief The index files to download. */
934 const std::vector<IndexTarget*>* IndexTargets;
935
936 /** \brief The parser for the meta-index file. */
937 indexRecords* MetaIndexParser;
938
939 /** \brief If \b true, the index's signature is currently being verified.
940 */
941 bool AuthPass;
942 // required to deal gracefully with problems caused by incorrect ims hits
943 bool IMSHit;
944
945 /** \brief Check that the release file is a release file for the
946 * correct distribution.
947 *
948 * \return \b true if no fatal errors were encountered.
949 */
950 bool VerifyVendor(std::string Message);
951
952 /** \brief Called when a file is finished being retrieved.
953 *
954 * If the file was not downloaded to DestFile, a copy process is
955 * set up to copy it to DestFile; otherwise, Complete is set to \b
956 * true and the file is moved to its final location.
957 *
958 * \param Message The message block received from the fetch
959 * subprocess.
960 */
961 void RetrievalDone(std::string Message);
962
963 /** \brief Called when authentication succeeded.
964 *
965 * Sanity-checks the authenticated file, queues up the individual
966 * index files for download, and saves the signature in the lists
967 * directory next to the authenticated list file.
968 *
969 * \param Message The message block received from the fetch
970 * subprocess.
971 */
972 void AuthDone(std::string Message);
973
974 /** \brief Starts downloading the individual index files.
975 *
976 * \param verify If \b true, only indices whose expected hashsum
977 * can be determined from the meta-index will be downloaded, and
978 * the hashsums of indices will be checked (reporting
979 * #StatAuthError if there is a mismatch). If verify is \b false,
980 * no hashsum checking will be performed.
981 */
982 void QueueIndexes(bool verify);
983
984 public:
985
986 // Specialized action members
987 virtual void Failed(std::string Message,pkgAcquire::MethodConfig *Cnf);
988 virtual void Done(std::string Message,unsigned long long Size, HashStringList const &Hashes,
989 pkgAcquire::MethodConfig *Cnf);
990 virtual std::string Custom600Headers() const;
991 virtual std::string DescURI() {return RealURI; };
992
993 /** \brief Create a new pkgAcqMetaIndex. */
994 pkgAcqMetaIndex(pkgAcquire *Owner,
995 std::string URI,std::string URIDesc, std::string ShortDesc,
996 std::string SigFile,
997 const std::vector<IndexTarget*>* IndexTargets,
998 indexRecords* MetaIndexParser);
999 };
1000 /*}}}*/
1001 /** \brief An item repsonsible for downloading clearsigned metaindexes {{{*/
1002 class pkgAcqMetaClearSig : public pkgAcqMetaIndex
1003 {
1004 /** \brief The URI of the meta-index file for the detached signature */
1005 std::string MetaIndexURI;
1006
1007 /** \brief A "URI-style" description of the meta-index file */
1008 std::string MetaIndexURIDesc;
1009
1010 /** \brief A brief description of the meta-index file */
1011 std::string MetaIndexShortDesc;
1012
1013 /** \brief The URI of the detached meta-signature file if the clearsigned one failed. */
1014 std::string MetaSigURI;
1015
1016 /** \brief A "URI-style" description of the meta-signature file */
1017 std::string MetaSigURIDesc;
1018
1019 /** \brief A brief description of the meta-signature file */
1020 std::string MetaSigShortDesc;
1021
1022 public:
1023 void Failed(std::string Message,pkgAcquire::MethodConfig *Cnf);
1024 virtual std::string Custom600Headers() const;
1025
1026 /** \brief Create a new pkgAcqMetaClearSig. */
1027 pkgAcqMetaClearSig(pkgAcquire *Owner,
1028 std::string const &URI, std::string const &URIDesc, std::string const &ShortDesc,
1029 std::string const &MetaIndexURI, std::string const &MetaIndexURIDesc, std::string const &MetaIndexShortDesc,
1030 std::string const &MetaSigURI, std::string const &MetaSigURIDesc, std::string const &MetaSigShortDesc,
1031 const std::vector<IndexTarget*>* IndexTargets,
1032 indexRecords* MetaIndexParser);
1033 virtual ~pkgAcqMetaClearSig();
1034 };
1035 /*}}}*/
1036 /** \brief An item that is responsible for fetching a package file. {{{
1037 *
1038 * If the package file already exists in the cache, nothing will be
1039 * done.
1040 */
1041 class pkgAcqArchive : public pkgAcquire::Item
1042 {
1043 protected:
1044 /** \brief The package version being fetched. */
1045 pkgCache::VerIterator Version;
1046
1047 /** \brief The list of sources from which to pick archives to
1048 * download this package from.
1049 */
1050 pkgSourceList *Sources;
1051
1052 /** \brief A package records object, used to look up the file
1053 * corresponding to each version of the package.
1054 */
1055 pkgRecords *Recs;
1056
1057 /** \brief A location in which the actual filename of the package
1058 * should be stored.
1059 */
1060 std::string &StoreFilename;
1061
1062 /** \brief The next file for this version to try to download. */
1063 pkgCache::VerFileIterator Vf;
1064
1065 /** \brief How many (more) times to try to find a new source from
1066 * which to download this package version if it fails.
1067 *
1068 * Set from Acquire::Retries.
1069 */
1070 unsigned int Retries;
1071
1072 /** \brief \b true if this version file is being downloaded from a
1073 * trusted source.
1074 */
1075 bool Trusted;
1076
1077 /** \brief Queue up the next available file for this version. */
1078 bool QueueNext();
1079
1080 public:
1081
1082 virtual void Failed(std::string Message,pkgAcquire::MethodConfig *Cnf);
1083 virtual void Done(std::string Message,unsigned long long Size, HashStringList const &Hashes,
1084 pkgAcquire::MethodConfig *Cnf);
1085 virtual std::string DescURI() {return Desc.URI;};
1086 virtual std::string ShortDesc() {return Desc.ShortDesc;};
1087 virtual void Finished();
1088 virtual bool IsTrusted() const;
1089
1090 /** \brief Create a new pkgAcqArchive.
1091 *
1092 * \param Owner The pkgAcquire object with which this item is
1093 * associated.
1094 *
1095 * \param Sources The sources from which to download version
1096 * files.
1097 *
1098 * \param Recs A package records object, used to look up the file
1099 * corresponding to each version of the package.
1100 *
1101 * \param Version The package version to download.
1102 *
1103 * \param[out] StoreFilename A location in which the actual filename of
1104 * the package should be stored. It will be set to a guessed
1105 * basename in the constructor, and filled in with a fully
1106 * qualified filename once the download finishes.
1107 */
1108 pkgAcqArchive(pkgAcquire *Owner,pkgSourceList *Sources,
1109 pkgRecords *Recs,pkgCache::VerIterator const &Version,
1110 std::string &StoreFilename);
1111 };
1112 /*}}}*/
1113 /** \brief Retrieve an arbitrary file to the current directory. {{{
1114 *
1115 * The file is retrieved even if it is accessed via a URL type that
1116 * normally is a NOP, such as "file". If the download fails, the
1117 * partial file is renamed to get a ".FAILED" extension.
1118 */
1119 class pkgAcqFile : public pkgAcquire::Item
1120 {
1121 /** \brief How many times to retry the download, set from
1122 * Acquire::Retries.
1123 */
1124 unsigned int Retries;
1125
1126 /** \brief Should this file be considered a index file */
1127 bool IsIndexFile;
1128
1129 public:
1130
1131 // Specialized action members
1132 virtual void Failed(std::string Message,pkgAcquire::MethodConfig *Cnf);
1133 virtual void Done(std::string Message,unsigned long long Size, HashStringList const &CalcHashes,
1134 pkgAcquire::MethodConfig *Cnf);
1135 virtual std::string DescURI() {return Desc.URI;};
1136 virtual std::string Custom600Headers() const;
1137
1138 /** \brief Create a new pkgAcqFile object.
1139 *
1140 * \param Owner The pkgAcquire object with which this object is
1141 * associated.
1142 *
1143 * \param URI The URI to download.
1144 *
1145 * \param Hashes The hashsums of the file to download, if they are known;
1146 * otherwise empty list.
1147 *
1148 * \param Size The size of the file to download, if it is known;
1149 * otherwise 0.
1150 *
1151 * \param Desc A description of the file being downloaded.
1152 *
1153 * \param ShortDesc A brief description of the file being
1154 * downloaded.
1155 *
1156 * \param DestDir The directory the file should be downloaded into.
1157 *
1158 * \param DestFilename The filename+path the file is downloaded to.
1159 *
1160 * \param IsIndexFile The file is considered a IndexFile and cache-control
1161 * headers like "cache-control: max-age=0" are send
1162 *
1163 * If DestFilename is empty, download to DestDir/\<basename\> if
1164 * DestDir is non-empty, $CWD/\<basename\> otherwise. If
1165 * DestFilename is NOT empty, DestDir is ignored and DestFilename
1166 * is the absolute name to which the file should be downloaded.
1167 */
1168
1169 pkgAcqFile(pkgAcquire *Owner, std::string URI, HashStringList const &Hashes, unsigned long long Size,
1170 std::string Desc, std::string ShortDesc,
1171 const std::string &DestDir="", const std::string &DestFilename="",
1172 bool IsIndexFile=false);
1173 };
1174 /*}}}*/
1175 /** @} */
1176
1177 #endif