]>
Commit | Line | Data |
---|---|---|
0118833a AL |
1 | // -*- mode: cpp; mode: fold -*- |
2 | // Description /*{{{*/ | |
b3d44315 | 3 | // $Id: acquire-item.h,v 1.26.2.3 2004/01/02 18:51:00 mdz Exp $ |
0118833a AL |
4 | /* ###################################################################### |
5 | ||
6 | Acquire Item - Item to acquire | |
7 | ||
8 | When an item is instantiated it will add it self to the local list in | |
9 | the Owner Acquire class. Derived classes will then call QueueURI to | |
17caf1b1 | 10 | register all the URI's they wish to fetch at the initial moment. |
0118833a | 11 | |
770c32ec | 12 | Three item classes are provided to provide functionality for |
a52f938b | 13 | downloading of Index, Translation and Packages files. |
0118833a | 14 | |
b185acc2 | 15 | A Archive class is provided for downloading .deb files. It does Md5 |
17caf1b1 | 16 | checking and source location as well as a retry algorithm. |
b185acc2 | 17 | |
0118833a AL |
18 | ##################################################################### */ |
19 | /*}}}*/ | |
20 | #ifndef PKGLIB_ACQUIRE_ITEM_H | |
21 | #define PKGLIB_ACQUIRE_ITEM_H | |
22 | ||
23 | #include <apt-pkg/acquire.h> | |
b2e465d6 | 24 | #include <apt-pkg/indexfile.h> |
b3d44315 MV |
25 | #include <apt-pkg/vendor.h> |
26 | #include <apt-pkg/sourcelist.h> | |
03e39e59 | 27 | #include <apt-pkg/pkgrecords.h> |
b3d44315 | 28 | #include <apt-pkg/indexrecords.h> |
0118833a | 29 | |
0118833a | 30 | |
3174e150 MV |
31 | /** \addtogroup acquire |
32 | * @{ | |
33 | * | |
34 | * \file acquire-item.h | |
35 | */ | |
36 | ||
37 | /** \brief Represents the process by which a pkgAcquire object should | |
38 | * retrieve a file or a collection of files. | |
39 | * | |
40 | * By convention, Item subclasses should insert themselves into the | |
41 | * acquire queue when they are created by calling QueueURI(), and | |
42 | * remove themselves by calling Dequeue() when either Done() or | |
43 | * Failed() is invoked. Item objects are also responsible for | |
44 | * notifying the download progress indicator (accessible via | |
45 | * #Owner->Log) of their status. | |
46 | * | |
47 | * \see pkgAcquire | |
48 | */ | |
0118833a AL |
49 | class pkgAcquire::Item |
50 | { | |
51 | protected: | |
52 | ||
3174e150 | 53 | /** \brief The acquire object with which this item is associated. */ |
0118833a | 54 | pkgAcquire *Owner; |
3174e150 MV |
55 | |
56 | /** \brief Insert this item into its owner's queue. | |
57 | * | |
58 | * \param ItemDesc Metadata about this item (its URI and | |
59 | * description). | |
60 | */ | |
8267fe24 AL |
61 | inline void QueueURI(ItemDesc &Item) |
62 | {Owner->Enqueue(Item);}; | |
3174e150 MV |
63 | |
64 | /** \brief Remove this item from its owner's queue. */ | |
681d76d0 | 65 | inline void Dequeue() {Owner->Dequeue(this);}; |
0118833a | 66 | |
3174e150 MV |
67 | /** \brief Rename a file without modifying its timestamp. |
68 | * | |
69 | * Many item methods call this as their final action. | |
70 | * | |
71 | * \param From The file to be renamed. | |
72 | * | |
73 | * \param To The new name of #From. If #To exists it will be | |
74 | * overwritten. | |
75 | */ | |
8b89e57f AL |
76 | void Rename(string From,string To); |
77 | ||
0118833a AL |
78 | public: |
79 | ||
3174e150 MV |
80 | /** \brief The current status of this item. */ |
81 | enum ItemState | |
82 | { | |
83 | /** \brief The item is waiting to be downloaded. */ | |
84 | StatIdle, | |
85 | ||
86 | /** \brief The item is currently being downloaded. */ | |
87 | StatFetching, | |
88 | ||
89 | /** \brief The item has been successfully downloaded. */ | |
90 | StatDone, | |
91 | ||
92 | /** \brief An error was encountered while downloading this | |
93 | * item. | |
94 | */ | |
95 | StatError, | |
96 | ||
97 | /** \brief The item was downloaded but its authenticity could | |
98 | * not be verified. | |
99 | */ | |
6ca714d5 MV |
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 | |
3174e150 MV |
106 | } Status; |
107 | ||
108 | /** \brief Contains a textual description of the error encountered | |
109 | * if #Status is #StatError or #StatAuthError. | |
110 | */ | |
c88edf1d | 111 | string ErrorText; |
3174e150 MV |
112 | |
113 | /** \brief The size of the object to fetch. */ | |
8267fe24 | 114 | unsigned long FileSize; |
3174e150 MV |
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 | */ | |
b2e465d6 | 122 | const char *Mode; |
3174e150 MV |
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 | */ | |
b98f2859 | 131 | unsigned long ID; |
3174e150 MV |
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 | */ | |
8267fe24 | 137 | bool Complete; |
3174e150 MV |
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 | */ | |
a6568219 | 144 | bool Local; |
36280399 | 145 | string UsedMirror; |
30e1eab5 | 146 | |
3174e150 MV |
147 | /** \brief The number of fetch queues into which this item has been |
148 | * inserted. | |
149 | * | |
150 | * There is one queue for each source from which an item could be | |
151 | * downloaded. | |
152 | * | |
153 | * \sa pkgAcquire | |
154 | */ | |
0118833a | 155 | unsigned int QueueCounter; |
0118833a | 156 | |
3174e150 MV |
157 | /** \brief The name of the file into which the retrieved object |
158 | * will be written. | |
159 | */ | |
0a8a80e5 | 160 | string DestFile; |
7d8afa39 | 161 | |
3174e150 MV |
162 | /** \brief Invoked by the acquire worker when the object couldn't |
163 | * be fetched. | |
164 | * | |
165 | * This is a branch of the continuation of the fetch process. | |
166 | * | |
167 | * \param Message An RFC822-formatted message from the acquire | |
168 | * method describing what went wrong. Use LookupTag() to parse | |
169 | * it. | |
170 | * | |
171 | * \param Cnf The method via which the worker tried to fetch this object. | |
172 | * | |
173 | * \sa pkgAcqMethod | |
174 | */ | |
7d8afa39 | 175 | virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf); |
3174e150 MV |
176 | |
177 | /** \brief Invoked by the acquire worker when the object was | |
178 | * fetched successfully. | |
179 | * | |
180 | * Note that the object might \e not have been written to | |
181 | * DestFile; check for the presence of an Alt-Filename entry in | |
182 | * Message to find the file to which it was really written. | |
183 | * | |
184 | * Done is often used to switch from one stage of the processing | |
185 | * to the next (e.g. fetching, unpacking, copying). It is one | |
186 | * branch of the continuation of the fetch process. | |
187 | * | |
188 | * \param Message Data from the acquire method. Use LookupTag() | |
189 | * to parse it. | |
190 | * \param Size The size of the object that was fetched. | |
191 | * \param Md5Hash The MD5Sum of the object that was fetched. | |
192 | * \param Cnf The method via which the object was fetched. | |
193 | * | |
194 | * \sa pkgAcqMethod | |
195 | */ | |
459681d3 AL |
196 | virtual void Done(string Message,unsigned long Size,string Md5Hash, |
197 | pkgAcquire::MethodConfig *Cnf); | |
3174e150 MV |
198 | |
199 | /** \brief Invoked when the worker starts to fetch this object. | |
200 | * | |
201 | * \param Message RFC822-formatted data from the worker process. | |
202 | * Use LookupTag() to parse it. | |
203 | * | |
204 | * \param Size The size of the object being fetched. | |
205 | * | |
206 | * \sa pkgAcqMethod | |
207 | */ | |
8267fe24 | 208 | virtual void Start(string Message,unsigned long Size); |
3174e150 MV |
209 | |
210 | /** \brief Custom headers to be sent to the fetch process. | |
211 | * | |
212 | * \return a string containing RFC822-style headers that are to be | |
213 | * inserted into the 600 URI Acquire message sent to the fetch | |
214 | * subprocess. The headers are inserted after a newline-less | |
215 | * line, so they should (if nonempty) have a leading newline and | |
216 | * no trailing newline. | |
217 | */ | |
17caf1b1 | 218 | virtual string Custom600Headers() {return string();}; |
3174e150 MV |
219 | |
220 | /** \brief A "descriptive" URI-like string. | |
221 | * | |
222 | * \return a URI that should be used to describe what is being fetched. | |
223 | */ | |
36375005 | 224 | virtual string DescURI() = 0; |
3174e150 MV |
225 | /** \brief Short item description. |
226 | * | |
227 | * \return a brief description of the object being fetched. | |
228 | */ | |
b3d44315 | 229 | virtual string ShortDesc() {return DescURI();} |
3174e150 MV |
230 | |
231 | /** \brief Invoked by the worker when the download is completely done. */ | |
ab559b35 | 232 | virtual void Finished() {}; |
17caf1b1 | 233 | |
3174e150 MV |
234 | /** \brief MD5Sum. |
235 | * | |
236 | * \return the MD5Sum of this object, if applicable; otherwise, an | |
237 | * empty string. | |
238 | */ | |
f7a08e33 | 239 | virtual string MD5Sum() {return string();}; |
3174e150 MV |
240 | |
241 | /** \return the acquire process with which this item is associated. */ | |
c5ccf175 | 242 | pkgAcquire *GetOwner() {return Owner;}; |
3174e150 MV |
243 | |
244 | /** \return \b true if this object is being fetched from a trusted source. */ | |
b3d44315 | 245 | virtual bool IsTrusted() {return false;}; |
c5ccf175 | 246 | |
36280399 | 247 | // report mirror problems |
702c84fb MV |
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 | */ | |
36280399 MV |
255 | void ReportMirrorFailure(string FailCode); |
256 | ||
3174e150 MV |
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 | */ | |
0118833a | 269 | Item(pkgAcquire *Owner); |
3174e150 MV |
270 | |
271 | /** \brief Remove this item from its owner's queue by invoking | |
272 | * pkgAcquire::Remove. | |
273 | */ | |
0118833a AL |
274 | virtual ~Item(); |
275 | }; | |
276 | ||
3174e150 | 277 | /** \brief Information about an index patch (aka diff). */ |
002d9943 | 278 | struct DiffInfo { |
3174e150 | 279 | /** The filename of the diff. */ |
002d9943 | 280 | string file; |
3174e150 MV |
281 | |
282 | /** The sha1 hash of the diff. */ | |
002d9943 | 283 | string sha1; |
3174e150 MV |
284 | |
285 | /** The size of the diff. */ | |
002d9943 MV |
286 | unsigned long size; |
287 | }; | |
288 | ||
3174e150 MV |
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 | */ | |
2237bd01 MV |
298 | class pkgAcqDiffIndex : public pkgAcquire::Item |
299 | { | |
300 | protected: | |
3174e150 | 301 | /** \brief If \b true, debugging information will be written to std::clog. */ |
2237bd01 | 302 | bool Debug; |
3174e150 MV |
303 | |
304 | /** \brief The item that is currently being downloaded. */ | |
002d9943 | 305 | pkgAcquire::ItemDesc Desc; |
3174e150 MV |
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 | */ | |
2237bd01 | 310 | string RealURI; |
3174e150 MV |
311 | |
312 | /** \brief The MD5Sum that the real index file should have after | |
313 | * all patches have been applied. | |
314 | */ | |
002d9943 | 315 | string ExpectedMD5; |
3174e150 MV |
316 | |
317 | /** \brief The index file which will be patched to generate the new | |
318 | * file. | |
319 | */ | |
002d9943 | 320 | string CurrentPackagesFile; |
3174e150 MV |
321 | |
322 | /** \brief A description of the Packages file (stored in | |
323 | * pkgAcquire::ItemDesc::Description). | |
324 | */ | |
002d9943 | 325 | string Description; |
2237bd01 MV |
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 | ||
3174e150 MV |
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 | */ | |
2237bd01 MV |
345 | bool ParseDiffIndex(string IndexDiffFile); |
346 | ||
3174e150 MV |
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 ExpectedMD5 The list file's MD5 signature. | |
359 | */ | |
2237bd01 | 360 | pkgAcqDiffIndex(pkgAcquire *Owner,string URI,string URIDesc, |
3174e150 | 361 | string ShortDesc, string ExpectedMD5); |
002d9943 | 362 | }; |
2237bd01 | 363 | |
3174e150 MV |
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 | */ | |
ac5b205a | 375 | class pkgAcqIndexDiffs : public pkgAcquire::Item |
0118833a | 376 | { |
3174e150 MV |
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 ExpectedMD5 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 | ||
0118833a | 403 | protected: |
3174e150 MV |
404 | |
405 | /** \brief If \b true, debugging output will be written to | |
406 | * std::clog. | |
407 | */ | |
ac5b205a | 408 | bool Debug; |
3174e150 MV |
409 | |
410 | /** \brief A description of the item that is currently being | |
411 | * downloaded. | |
412 | */ | |
ac5b205a | 413 | pkgAcquire::ItemDesc Desc; |
3174e150 MV |
414 | |
415 | /** \brief The URI of the package index file that is being | |
416 | * reconstructed. | |
417 | */ | |
ac5b205a | 418 | string RealURI; |
3174e150 MV |
419 | |
420 | /** \brief The MD5Sum of the package index file that is being | |
421 | * reconstructed. | |
422 | */ | |
ac5b205a | 423 | string ExpectedMD5; |
4a0a786f | 424 | |
3174e150 | 425 | /** A description of the file being downloaded. */ |
ac5b205a | 426 | string Description; |
3174e150 MV |
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 | */ | |
94dc9d7d | 436 | vector<DiffInfo> available_patches; |
3174e150 MV |
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; | |
6cb30d01 | 452 | |
ac5b205a | 453 | public: |
0118833a | 454 | |
3174e150 MV |
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 | */ | |
ac5b205a | 460 | virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf); |
3174e150 | 461 | |
ac5b205a MV |
462 | virtual void Done(string Message,unsigned long Size,string Md5Hash, |
463 | pkgAcquire::MethodConfig *Cnf); | |
464 | virtual string DescURI() {return RealURI + "Index";}; | |
ac5b205a | 465 | |
3174e150 MV |
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 ExpectedMD5 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 | */ | |
ac5b205a | 488 | pkgAcqIndexDiffs(pkgAcquire *Owner,string URI,string URIDesc, |
3174e150 | 489 | string ShortDesc, string ExpectedMD5, |
6cb30d01 | 490 | vector<DiffInfo> diffs=vector<DiffInfo>()); |
ac5b205a MV |
491 | }; |
492 | ||
3174e150 MV |
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 | */ | |
0118833a AL |
500 | class pkgAcqIndex : public pkgAcquire::Item |
501 | { | |
502 | protected: | |
3174e150 MV |
503 | |
504 | /** \brief If \b true, the index file has been decompressed. */ | |
8b89e57f | 505 | bool Decompression; |
3174e150 MV |
506 | |
507 | /** \brief If \b true, the partially downloaded file will be | |
508 | * removed when the download completes. | |
509 | */ | |
bfd22fc0 | 510 | bool Erase; |
3174e150 MV |
511 | |
512 | /** \brief The download request that is currently being | |
513 | * processed. | |
514 | */ | |
8267fe24 | 515 | pkgAcquire::ItemDesc Desc; |
3174e150 MV |
516 | |
517 | /** \brief The object that is actually being fetched (minus any | |
518 | * compression-related extensions). | |
519 | */ | |
b2e465d6 | 520 | string RealURI; |
3174e150 MV |
521 | |
522 | /** \brief The expected md5sum of the decompressed index file. */ | |
b3d44315 | 523 | string ExpectedMD5; |
3174e150 MV |
524 | |
525 | /** \brief The compression-related file extension that is being | |
526 | * added to the downloaded file (e.g., ".gz" or ".bz2"). | |
527 | */ | |
13e8426f MV |
528 | string CompressionExtension; |
529 | ||
0118833a AL |
530 | public: |
531 | ||
17caf1b1 | 532 | // Specialized action members |
debc84b2 | 533 | virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf); |
459681d3 AL |
534 | virtual void Done(string Message,unsigned long Size,string Md5Hash, |
535 | pkgAcquire::MethodConfig *Cnf); | |
0a8a80e5 | 536 | virtual string Custom600Headers(); |
13e8426f | 537 | virtual string DescURI() {return RealURI + CompressionExtension;}; |
0118833a | 538 | |
3174e150 MV |
539 | /** \brief Create a pkgAcqIndex. |
540 | * | |
541 | * \param Owner The pkgAcquire object with which this item is | |
542 | * associated. | |
543 | * | |
544 | * \param URI The URI of the index file that is to be downloaded. | |
545 | * | |
546 | * \param URIDesc A "URI-style" description of this index file. | |
547 | * | |
548 | * \param ShortDesc A brief description of this index file. | |
549 | * | |
550 | * \param ExpectedMD5 The expected md5sum of this index file. | |
551 | * | |
552 | * \param compressExt The compression-related extension with which | |
553 | * this index file should be downloaded, or "" to autodetect | |
554 | * (".bz2" is used if bzip2 is installed, ".gz" otherwise). | |
555 | */ | |
b2e465d6 | 556 | pkgAcqIndex(pkgAcquire *Owner,string URI,string URIDesc, |
b3d44315 | 557 | string ShortDesct, string ExpectedMD5, string compressExt=""); |
0118833a AL |
558 | }; |
559 | ||
3174e150 MV |
560 | /** \brief An acquire item that is responsible for fetching a |
561 | * translated index file. | |
562 | * | |
563 | * The only difference from pkgAcqIndex is that transient failures | |
564 | * are suppressed: no error occurs if the translated index file is | |
565 | * missing. | |
566 | */ | |
a52f938b OS |
567 | class pkgAcqIndexTrans : public pkgAcqIndex |
568 | { | |
569 | public: | |
570 | ||
571 | virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf); | |
3174e150 MV |
572 | |
573 | /** \brief Create a pkgAcqIndexTrans. | |
574 | * | |
575 | * \param Owner The pkgAcquire object with which this item is | |
576 | * associated. | |
577 | * | |
578 | * \param URI The URI of the index file that is to be downloaded. | |
579 | * | |
580 | * \param URIDesc A "URI-style" description of this index file. | |
581 | * | |
582 | * \param ShortDesc A brief description of this index file. | |
583 | * | |
584 | * \param ExpectedMD5 The expected md5sum of this index file. | |
585 | * | |
586 | * \param compressExt The compression-related extension with which | |
587 | * this index file should be downloaded, or "" to autodetect | |
588 | * (".bz2" is used if bzip2 is installed, ".gz" otherwise). | |
589 | */ | |
a52f938b | 590 | pkgAcqIndexTrans(pkgAcquire *Owner,string URI,string URIDesc, |
3174e150 | 591 | string ShortDesc); |
a52f938b OS |
592 | }; |
593 | ||
3174e150 | 594 | /** \brief Information about an index file. */ |
b3d44315 MV |
595 | struct IndexTarget |
596 | { | |
3174e150 | 597 | /** \brief A URI from which the index file can be downloaded. */ |
b3d44315 | 598 | string URI; |
3174e150 MV |
599 | |
600 | /** \brief A description of the index file. */ | |
b3d44315 | 601 | string Description; |
3174e150 MV |
602 | |
603 | /** \brief A shorter description of the index file. */ | |
b3d44315 | 604 | string ShortDesc; |
3174e150 MV |
605 | |
606 | /** \brief The key by which this index file should be | |
607 | * looked up within the meta signature file. | |
608 | */ | |
b3d44315 MV |
609 | string MetaKey; |
610 | }; | |
611 | ||
3174e150 MV |
612 | /** \brief An acquire item that downloads the detached signature |
613 | * of a meta-index (Release) file, then queues up the release | |
614 | * file itself. | |
615 | * | |
616 | * \todo Why protected members? | |
617 | * | |
618 | * \sa pkgAcqMetaIndex | |
619 | */ | |
b3d44315 | 620 | class pkgAcqMetaSig : public pkgAcquire::Item |
0118833a AL |
621 | { |
622 | protected: | |
3174e150 | 623 | /** \brief The fetch request that is currently being processed. */ |
8267fe24 | 624 | pkgAcquire::ItemDesc Desc; |
3174e150 MV |
625 | |
626 | /** \brief The URI of the signature file. Unlike Desc.URI, this is | |
627 | * never modified; it is used to determine the file that is being | |
628 | * downloaded. | |
629 | */ | |
630 | string RealURI; | |
631 | ||
632 | /** \brief The URI of the meta-index file to be fetched after the signature. */ | |
633 | string MetaIndexURI; | |
634 | ||
635 | /** \brief A "URI-style" description of the meta-index file to be | |
636 | * fetched after the signature. | |
637 | */ | |
638 | string MetaIndexURIDesc; | |
639 | ||
640 | /** \brief A brief description of the meta-index file to be fetched | |
641 | * after the signature. | |
642 | */ | |
643 | string MetaIndexShortDesc; | |
644 | ||
645 | /** \brief A package-system-specific parser for the meta-index file. */ | |
b3d44315 | 646 | indexRecords* MetaIndexParser; |
3174e150 MV |
647 | |
648 | /** \brief The index files which should be looked up in the meta-index | |
649 | * and then downloaded. | |
650 | * | |
651 | * \todo Why a list of pointers instead of a list of structs? | |
652 | */ | |
b3d44315 MV |
653 | const vector<struct IndexTarget*>* IndexTargets; |
654 | ||
0118833a AL |
655 | public: |
656 | ||
17caf1b1 | 657 | // Specialized action members |
681d76d0 | 658 | virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf); |
459681d3 | 659 | virtual void Done(string Message,unsigned long Size,string Md5Hash, |
b3d44315 | 660 | pkgAcquire::MethodConfig *Cnf); |
0a8a80e5 | 661 | virtual string Custom600Headers(); |
b3d44315 MV |
662 | virtual string DescURI() {return RealURI; }; |
663 | ||
3174e150 | 664 | /** \brief Create a new pkgAcqMetaSig. */ |
b3d44315 MV |
665 | pkgAcqMetaSig(pkgAcquire *Owner,string URI,string URIDesc, string ShortDesc, |
666 | string MetaIndexURI, string MetaIndexURIDesc, string MetaIndexShortDesc, | |
667 | const vector<struct IndexTarget*>* IndexTargets, | |
668 | indexRecords* MetaIndexParser); | |
669 | }; | |
670 | ||
3174e150 MV |
671 | /** \brief An item that is responsible for downloading the meta-index |
672 | * file (i.e., Release) itself and verifying its signature. | |
673 | * | |
674 | * Once the download and verification are complete, the downloads of | |
675 | * the individual index files are queued up using pkgAcqDiffIndex. | |
676 | * If the meta-index file had a valid signature, the expected md5sums | |
677 | * of the index files will be the md5sums listed in the meta-index; | |
678 | * otherwise, the expected md5sums will be "" (causing the | |
679 | * authentication of the index files to be bypassed). | |
680 | */ | |
b3d44315 MV |
681 | class pkgAcqMetaIndex : public pkgAcquire::Item |
682 | { | |
683 | protected: | |
3174e150 | 684 | /** \brief The fetch command that is currently being processed. */ |
b3d44315 | 685 | pkgAcquire::ItemDesc Desc; |
3174e150 MV |
686 | |
687 | /** \brief The URI that is actually being downloaded; never | |
688 | * modified by pkgAcqMetaIndex. | |
689 | */ | |
690 | string RealURI; | |
691 | ||
692 | /** \brief The file in which the signature for this index was stored. | |
693 | * | |
694 | * If empty, the signature and the md5sums of the individual | |
695 | * indices will not be checked. | |
696 | */ | |
b3d44315 | 697 | string SigFile; |
3174e150 MV |
698 | |
699 | /** \brief The index files to download. */ | |
b3d44315 | 700 | const vector<struct IndexTarget*>* IndexTargets; |
3174e150 MV |
701 | |
702 | /** \brief The parser for the meta-index file. */ | |
b3d44315 | 703 | indexRecords* MetaIndexParser; |
3174e150 MV |
704 | |
705 | /** \brief If \b true, the index's signature is currently being verified. | |
706 | */ | |
b3d44315 | 707 | bool AuthPass; |
ce424cd4 MV |
708 | // required to deal gracefully with problems caused by incorrect ims hits |
709 | bool IMSHit; | |
b3d44315 | 710 | |
3174e150 MV |
711 | /** \brief Check that the release file is a release file for the |
712 | * correct distribution. | |
713 | * | |
714 | * \return \b true if no fatal errors were encountered. | |
715 | */ | |
ce424cd4 | 716 | bool VerifyVendor(string Message); |
3174e150 MV |
717 | |
718 | /** \brief Called when a file is finished being retrieved. | |
719 | * | |
720 | * If the file was not downloaded to DestFile, a copy process is | |
721 | * set up to copy it to DestFile; otherwise, Complete is set to \b | |
722 | * true and the file is moved to its final location. | |
723 | * | |
724 | * \param Message The message block received from the fetch | |
725 | * subprocess. | |
726 | */ | |
b3d44315 | 727 | void RetrievalDone(string Message); |
3174e150 MV |
728 | |
729 | /** \brief Called when authentication succeeded. | |
730 | * | |
731 | * Sanity-checks the authenticated file, queues up the individual | |
732 | * index files for download, and saves the signature in the lists | |
733 | * directory next to the authenticated list file. | |
734 | * | |
735 | * \param Message The message block received from the fetch | |
736 | * subprocess. | |
737 | */ | |
b3d44315 | 738 | void AuthDone(string Message); |
3174e150 MV |
739 | |
740 | /** \brief Starts downloading the individual index files. | |
741 | * | |
742 | * \param verify If \b true, only indices whose expected md5sum | |
743 | * can be determined from the meta-index will be downloaded, and | |
744 | * the md5sums of indices will be checked (reporting | |
745 | * #StatAuthError if there is a mismatch). If verify is \b false, | |
746 | * no md5sum checking will be performed. | |
747 | */ | |
b3d44315 MV |
748 | void QueueIndexes(bool verify); |
749 | ||
750 | public: | |
0a8a80e5 | 751 | |
b3d44315 MV |
752 | // Specialized action members |
753 | virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf); | |
754 | virtual void Done(string Message,unsigned long Size,string Md5Hash, | |
755 | pkgAcquire::MethodConfig *Cnf); | |
756 | virtual string Custom600Headers(); | |
757 | virtual string DescURI() {return RealURI; }; | |
758 | ||
3174e150 | 759 | /** \brief Create a new pkgAcqMetaIndex. */ |
b3d44315 MV |
760 | pkgAcqMetaIndex(pkgAcquire *Owner, |
761 | string URI,string URIDesc, string ShortDesc, | |
762 | string SigFile, | |
763 | const vector<struct IndexTarget*>* IndexTargets, | |
764 | indexRecords* MetaIndexParser); | |
0118833a AL |
765 | }; |
766 | ||
3174e150 MV |
767 | /** \brief An item that is responsible for fetching a package file. |
768 | * | |
769 | * If the package file already exists in the cache, nothing will be | |
770 | * done. | |
771 | */ | |
03e39e59 AL |
772 | class pkgAcqArchive : public pkgAcquire::Item |
773 | { | |
774 | protected: | |
3174e150 | 775 | /** \brief The package version being fetched. */ |
03e39e59 | 776 | pkgCache::VerIterator Version; |
3174e150 MV |
777 | |
778 | /** \brief The fetch command that is currently being processed. */ | |
03e39e59 | 779 | pkgAcquire::ItemDesc Desc; |
3174e150 MV |
780 | |
781 | /** \brief The list of sources from which to pick archives to | |
782 | * download this package from. | |
783 | */ | |
03e39e59 | 784 | pkgSourceList *Sources; |
3174e150 MV |
785 | |
786 | /** \brief A package records object, used to look up the file | |
787 | * corresponding to each version of the package. | |
788 | */ | |
03e39e59 | 789 | pkgRecords *Recs; |
3174e150 MV |
790 | |
791 | /** \brief The md5sum of this package. */ | |
03e39e59 | 792 | string MD5; |
3174e150 MV |
793 | |
794 | /** \brief A location in which the actual filename of the package | |
795 | * should be stored. | |
796 | */ | |
30e1eab5 | 797 | string &StoreFilename; |
3174e150 MV |
798 | |
799 | /** \brief The next file for this version to try to download. */ | |
b185acc2 | 800 | pkgCache::VerFileIterator Vf; |
3174e150 MV |
801 | |
802 | /** \brief How many (more) times to try to find a new source from | |
803 | * which to download this package version if it fails. | |
804 | * | |
805 | * Set from Acquire::Retries. | |
806 | */ | |
7d8afa39 | 807 | unsigned int Retries; |
3174e150 MV |
808 | |
809 | /** \brief \b true if this version file is being downloaded from a | |
810 | * trusted source. | |
811 | */ | |
b3d44315 | 812 | bool Trusted; |
17caf1b1 | 813 | |
3174e150 | 814 | /** \brief Queue up the next available file for this version. */ |
b185acc2 | 815 | bool QueueNext(); |
03e39e59 AL |
816 | |
817 | public: | |
818 | ||
7d8afa39 | 819 | virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf); |
459681d3 AL |
820 | virtual void Done(string Message,unsigned long Size,string Md5Hash, |
821 | pkgAcquire::MethodConfig *Cnf); | |
17caf1b1 | 822 | virtual string MD5Sum() {return MD5;}; |
36375005 | 823 | virtual string DescURI() {return Desc.URI;}; |
b3d44315 | 824 | virtual string ShortDesc() {return Desc.ShortDesc;}; |
ab559b35 | 825 | virtual void Finished(); |
3174e150 | 826 | |
b3d44315 | 827 | virtual bool IsTrusted(); |
03e39e59 | 828 | |
3174e150 MV |
829 | /** \brief Create a new pkgAcqArchive. |
830 | * | |
831 | * \param Owner The pkgAcquire object with which this item is | |
832 | * associated. | |
833 | * | |
834 | * \param Sources The sources from which to download version | |
835 | * files. | |
836 | * | |
837 | * \param Recs A package records object, used to look up the file | |
838 | * corresponding to each version of the package. | |
839 | * | |
840 | * \param Version The package version to download. | |
841 | * | |
842 | * \param StoreFilename A location in which the actual filename of | |
843 | * the package should be stored. It will be set to a guessed | |
844 | * basename in the constructor, and filled in with a fully | |
845 | * qualified filename once the download finishes. | |
846 | */ | |
03e39e59 | 847 | pkgAcqArchive(pkgAcquire *Owner,pkgSourceList *Sources, |
30e1eab5 AL |
848 | pkgRecords *Recs,pkgCache::VerIterator const &Version, |
849 | string &StoreFilename); | |
03e39e59 AL |
850 | }; |
851 | ||
3174e150 MV |
852 | /** \brief Retrieve an arbitrary file to the current directory. |
853 | * | |
854 | * The file is retrieved even if it is accessed via a URL type that | |
855 | * normally is a NOP, such as "file". If the download fails, the | |
856 | * partial file is renamed to get a ".FAILED" extension. | |
857 | */ | |
36375005 AL |
858 | class pkgAcqFile : public pkgAcquire::Item |
859 | { | |
3174e150 | 860 | /** \brief The currently active download process. */ |
36375005 | 861 | pkgAcquire::ItemDesc Desc; |
3174e150 MV |
862 | |
863 | /** \brief The md5sum of the file to download, if it is known. */ | |
b3c39978 | 864 | string Md5Hash; |
3174e150 MV |
865 | |
866 | /** \brief How many times to retry the download, set from | |
867 | * Acquire::Retries. | |
868 | */ | |
08cfc005 | 869 | unsigned int Retries; |
36375005 AL |
870 | |
871 | public: | |
872 | ||
873 | // Specialized action members | |
08cfc005 | 874 | virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf); |
459681d3 AL |
875 | virtual void Done(string Message,unsigned long Size,string Md5Hash, |
876 | pkgAcquire::MethodConfig *Cnf); | |
b3c39978 | 877 | virtual string MD5Sum() {return Md5Hash;}; |
36375005 | 878 | virtual string DescURI() {return Desc.URI;}; |
46e00f9d | 879 | |
3174e150 MV |
880 | /** \brief Create a new pkgAcqFile object. |
881 | * | |
882 | * \param Owner The pkgAcquire object with which this object is | |
883 | * associated. | |
884 | * | |
885 | * \param URI The URI to download. | |
886 | * | |
887 | * \param MD5 The md5sum of the file to download, if it is known; | |
888 | * otherwise "". | |
889 | * | |
890 | * \param Size The size of the file to download, if it is known; | |
891 | * otherwise 0. | |
892 | * | |
893 | * \param Desc A description of the file being downloaded. | |
894 | * | |
895 | * \param ShortDesc A brief description of the file being | |
896 | * downloaded. | |
39c7baef MV |
897 | * |
898 | * \param DestDir The directory the file should be downloaded into. | |
899 | * | |
900 | * \param DestFilename The filename+path the file is downloaded to. | |
901 | * | |
902 | * | |
903 | * If DestFilename is empty, download to DestDir/<basename> if | |
904 | * DestDir is non-empty, $CWD/<basename> otherwise. If | |
905 | * DestFilename is NOT empty, DestDir is ignored and DestFilename | |
906 | * is the absolute name to which the file should be downloaded. | |
3174e150 | 907 | */ |
39c7baef | 908 | |
46e00f9d MV |
909 | pkgAcqFile(pkgAcquire *Owner, string URI, string MD5, unsigned long Size, |
910 | string Desc, string ShortDesc, | |
911 | const string &DestDir="", const string &DestFilename=""); | |
36375005 AL |
912 | }; |
913 | ||
3174e150 MV |
914 | /** @} */ |
915 | ||
0118833a | 916 | #endif |