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