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