acquire-item.h 29 KB

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