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