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