acquire-item.h 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167
  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/hashes.h>
  19. #include <apt-pkg/weakptr.h>
  20. #include <apt-pkg/pkgcache.h>
  21. #include <apt-pkg/cacheiterators.h>
  22. #include <string>
  23. #include <vector>
  24. #ifndef APT_8_CLEANER_HEADERS
  25. #include <apt-pkg/indexfile.h>
  26. #include <apt-pkg/vendor.h>
  27. #include <apt-pkg/sourcelist.h>
  28. #include <apt-pkg/pkgrecords.h>
  29. #include <apt-pkg/indexrecords.h>
  30. #endif
  31. /** \addtogroup acquire
  32. * @{
  33. *
  34. * \file acquire-item.h
  35. */
  36. class indexRecords;
  37. class pkgRecords;
  38. class pkgSourceList;
  39. class IndexTarget;
  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. */
  52. class pkgAcquire::Item : public WeakPointable
  53. {
  54. protected:
  55. /** \brief The acquire object with which this item is associated. */
  56. pkgAcquire *Owner;
  57. /** \brief Insert this item into its owner's queue.
  58. *
  59. * \param Item Metadata about this item (its URI and
  60. * description).
  61. */
  62. inline void QueueURI(ItemDesc &Item)
  63. {Owner->Enqueue(Item);};
  64. /** \brief Remove this item from its owner's queue. */
  65. inline void Dequeue() {Owner->Dequeue(this);};
  66. /** \brief Rename a file without modifying its timestamp.
  67. *
  68. * Many item methods call this as their final action.
  69. *
  70. * \param From The file to be renamed.
  71. *
  72. * \param To The new name of \a From. If \a To exists it will be
  73. * overwritten.
  74. */
  75. void Rename(std::string From,std::string To);
  76. public:
  77. /** \brief The current status of this item. */
  78. enum ItemState
  79. {
  80. /** \brief The item is waiting to be downloaded. */
  81. StatIdle,
  82. /** \brief The item is currently being downloaded. */
  83. StatFetching,
  84. /** \brief The item has been successfully downloaded. */
  85. StatDone,
  86. /** \brief An error was encountered while downloading this
  87. * item.
  88. */
  89. StatError,
  90. /** \brief The item was downloaded but its authenticity could
  91. * not be verified.
  92. */
  93. StatAuthError,
  94. /** \brief The item was could not be downloaded because of
  95. * a transient network error (e.g. network down)
  96. */
  97. StatTransientNetworkError
  98. } Status;
  99. /** \brief Contains a textual description of the error encountered
  100. * if #ItemState is #StatError or #StatAuthError.
  101. */
  102. std::string ErrorText;
  103. /** \brief The size of the object to fetch. */
  104. unsigned long long FileSize;
  105. /** \brief How much of the object was already fetched. */
  106. unsigned long long PartialSize;
  107. /** \brief If not \b NULL, contains the name of a subprocess that
  108. * is operating on this object (for instance, "gzip" or "gpgv").
  109. */
  110. const char *Mode;
  111. /** \brief A client-supplied unique identifier.
  112. *
  113. * This field is initalized to 0; it is meant to be filled in by
  114. * clients that wish to use it to uniquely identify items.
  115. *
  116. * \todo it's unused in apt itself
  117. */
  118. unsigned long ID;
  119. /** \brief If \b true, the entire object has been successfully fetched.
  120. *
  121. * Subclasses should set this to \b true when appropriate.
  122. */
  123. bool Complete;
  124. /** \brief If \b true, the URI of this object is "local".
  125. *
  126. * The only effect of this field is to exclude the object from the
  127. * download progress indicator's overall statistics.
  128. */
  129. bool Local;
  130. std::string UsedMirror;
  131. /** \brief The number of fetch queues into which this item has been
  132. * inserted.
  133. *
  134. * There is one queue for each source from which an item could be
  135. * downloaded.
  136. *
  137. * \sa pkgAcquire
  138. */
  139. unsigned int QueueCounter;
  140. /** \brief The number of additional fetch items that are expected
  141. * once this item is done.
  142. *
  143. * Some items like pkgAcqMeta{Index,Sig} will queue additional
  144. * items. This variable can be set by the methods if it knows
  145. * in advance how many items to expect to get a more accurate
  146. * progress.
  147. */
  148. unsigned int ExpectedAdditionalItems;
  149. /** \brief The name of the file into which the retrieved object
  150. * will be written.
  151. */
  152. std::string DestFile;
  153. /** \brief Invoked by the acquire worker when the object couldn't
  154. * be fetched.
  155. *
  156. * This is a branch of the continuation of the fetch process.
  157. *
  158. * \param Message An RFC822-formatted message from the acquire
  159. * method describing what went wrong. Use LookupTag() to parse
  160. * it.
  161. *
  162. * \param Cnf The method via which the worker tried to fetch this object.
  163. *
  164. * \sa pkgAcqMethod
  165. */
  166. virtual void Failed(std::string Message,pkgAcquire::MethodConfig *Cnf);
  167. /** \brief Invoked by the acquire worker when the object was
  168. * fetched successfully.
  169. *
  170. * Note that the object might \e not have been written to
  171. * DestFile; check for the presence of an Alt-Filename entry in
  172. * Message to find the file to which it was really written.
  173. *
  174. * Done is often used to switch from one stage of the processing
  175. * to the next (e.g. fetching, unpacking, copying). It is one
  176. * branch of the continuation of the fetch process.
  177. *
  178. * \param Message Data from the acquire method. Use LookupTag()
  179. * to parse it.
  180. * \param Size The size of the object that was fetched.
  181. * \param Hashes The HashSums of the object that was fetched.
  182. * \param Cnf The method via which the object was fetched.
  183. *
  184. * \sa pkgAcqMethod
  185. */
  186. virtual void Done(std::string Message, unsigned long long Size, HashStringList const &Hashes,
  187. pkgAcquire::MethodConfig *Cnf);
  188. /** \brief Invoked when the worker starts to fetch this object.
  189. *
  190. * \param Message RFC822-formatted data from the worker process.
  191. * Use LookupTag() to parse it.
  192. *
  193. * \param Size The size of the object being fetched.
  194. *
  195. * \sa pkgAcqMethod
  196. */
  197. virtual void Start(std::string Message,unsigned long long Size);
  198. /** \brief Custom headers to be sent to the fetch process.
  199. *
  200. * \return a string containing RFC822-style headers that are to be
  201. * inserted into the 600 URI Acquire message sent to the fetch
  202. * subprocess. The headers are inserted after a newline-less
  203. * line, so they should (if nonempty) have a leading newline and
  204. * no trailing newline.
  205. */
  206. virtual std::string Custom600Headers() const {return std::string();};
  207. /** \brief A "descriptive" URI-like string.
  208. *
  209. * \return a URI that should be used to describe what is being fetched.
  210. */
  211. virtual std::string DescURI() const = 0;
  212. /** \brief Short item description.
  213. *
  214. * \return a brief description of the object being fetched.
  215. */
  216. virtual std::string ShortDesc() const {return DescURI();}
  217. /** \brief Invoked by the worker when the download is completely done. */
  218. virtual void Finished() {};
  219. /** \brief HashSums
  220. *
  221. * \return the HashSums of this object, if applicable; otherwise, an
  222. * empty list.
  223. */
  224. HashStringList HashSums() const {return ExpectedHashes;};
  225. std::string HashSum() const {HashStringList const hashes = HashSums(); HashString const * const hs = hashes.find(NULL); return hs != NULL ? hs->toStr() : ""; };
  226. /** \return the acquire process with which this item is associated. */
  227. pkgAcquire *GetOwner() const {return Owner;};
  228. /** \return \b true if this object is being fetched from a trusted source. */
  229. virtual bool IsTrusted() const {return false;};
  230. // report mirror problems
  231. /** \brief Report mirror problem
  232. *
  233. * This allows reporting mirror failures back to a centralized
  234. * server. The apt-report-mirror-failure script is called for this
  235. *
  236. * \param FailCode A short failure string that is send
  237. */
  238. void ReportMirrorFailure(std::string FailCode);
  239. /** \brief Initialize an item.
  240. *
  241. * Adds the item to the list of items known to the acquire
  242. * process, but does not place it into any fetch queues (you must
  243. * manually invoke QueueURI() to do so).
  244. *
  245. * \param Owner The new owner of this item.
  246. * \param ExpectedHashes of the file represented by this item
  247. */
  248. Item(pkgAcquire *Owner, HashStringList const &ExpectedHashes);
  249. /** \brief Remove this item from its owner's queue by invoking
  250. * pkgAcquire::Remove.
  251. */
  252. virtual ~Item();
  253. protected:
  254. enum RenameOnErrorState {
  255. HashSumMismatch,
  256. SizeMismatch,
  257. InvalidFormat
  258. };
  259. /** \brief Rename failed file and set error
  260. *
  261. * \param state respresenting the error we encountered
  262. */
  263. bool RenameOnError(RenameOnErrorState const state);
  264. /** \brief The HashSums of the item is supposed to have than done */
  265. HashStringList ExpectedHashes;
  266. /** \brief The item that is currently being downloaded. */
  267. pkgAcquire::ItemDesc Desc;
  268. };
  269. /*}}}*/
  270. /** \brief Information about an index patch (aka diff). */ /*{{{*/
  271. struct DiffInfo {
  272. /** The filename of the diff. */
  273. std::string file;
  274. /** The sha1 hash of the diff. */
  275. std::string sha1;
  276. /** The size of the diff. */
  277. unsigned long size;
  278. };
  279. /*}}}*/
  280. /** \brief An item that is responsible for fetching a SubIndex {{{
  281. *
  282. * The MetaIndex file includes only records for important indexes
  283. * and records for these SubIndex files so these can carry records
  284. * for addition files like PDiffs and Translations
  285. */
  286. class pkgAcqSubIndex : public pkgAcquire::Item
  287. {
  288. protected:
  289. /** \brief If \b true, debugging information will be written to std::clog. */
  290. bool Debug;
  291. public:
  292. // Specialized action members
  293. virtual void Failed(std::string Message,pkgAcquire::MethodConfig *Cnf);
  294. virtual void Done(std::string Message,unsigned long long Size, HashStringList const &Hashes,
  295. pkgAcquire::MethodConfig *Cnf);
  296. virtual std::string DescURI() const {return Desc.URI;};
  297. virtual std::string Custom600Headers() const;
  298. virtual bool ParseIndex(std::string const &IndexFile);
  299. /** \brief Create a new pkgAcqSubIndex.
  300. *
  301. * \param Owner The Acquire object that owns this item.
  302. *
  303. * \param URI The URI of the list file to download.
  304. *
  305. * \param URIDesc A long description of the list file to download.
  306. *
  307. * \param ShortDesc A short description of the list file to download.
  308. *
  309. * \param ExpectedHashes The list file's hashsums which are expected.
  310. */
  311. pkgAcqSubIndex(pkgAcquire *Owner, std::string const &URI,std::string const &URIDesc,
  312. std::string const &ShortDesc, HashStringList const &ExpectedHashes);
  313. };
  314. /*}}}*/
  315. /** \brief Common base class for all classes that deal with fetching {{{
  316. indexes
  317. */
  318. class pkgAcqBaseIndex : public pkgAcquire::Item
  319. {
  320. protected:
  321. /** \brief Pointer to the IndexTarget data
  322. */
  323. const struct IndexTarget * Target;
  324. indexRecords *MetaIndexParser;
  325. pkgAcqBaseIndex(pkgAcquire *Owner,
  326. struct IndexTarget const * const Target,
  327. HashStringList const &ExpectedHashes,
  328. indexRecords *MetaIndexParser)
  329. : Item(Owner, ExpectedHashes), Target(Target),
  330. MetaIndexParser(MetaIndexParser) {};
  331. };
  332. /*}}}*/
  333. /** \brief An item that is responsible for fetching an index file of {{{
  334. * package list diffs and starting the package list's download.
  335. *
  336. * This item downloads the Index file and parses it, then enqueues
  337. * additional downloads of either the individual patches (using
  338. * pkgAcqIndexDiffs) or the entire Packages file (using pkgAcqIndex).
  339. *
  340. * \sa pkgAcqIndexDiffs, pkgAcqIndex
  341. */
  342. class pkgAcqDiffIndex : public pkgAcqBaseIndex
  343. {
  344. protected:
  345. /** \brief If \b true, debugging information will be written to std::clog. */
  346. bool Debug;
  347. /** \brief The URI of the index file to recreate at our end (either
  348. * by downloading it or by applying partial patches).
  349. */
  350. std::string RealURI;
  351. /** \brief The index file which will be patched to generate the new
  352. * file.
  353. */
  354. std::string CurrentPackagesFile;
  355. /** \brief A description of the Packages file (stored in
  356. * pkgAcquire::ItemDesc::Description).
  357. */
  358. std::string Description;
  359. public:
  360. // Specialized action members
  361. virtual void Failed(std::string Message,pkgAcquire::MethodConfig *Cnf);
  362. virtual void Done(std::string Message,unsigned long long Size, HashStringList const &Hashes,
  363. pkgAcquire::MethodConfig *Cnf);
  364. virtual std::string DescURI() const {return RealURI + "Index";};
  365. virtual std::string Custom600Headers() const;
  366. /** \brief Parse the Index file for a set of Packages diffs.
  367. *
  368. * Parses the Index file and creates additional download items as
  369. * necessary.
  370. *
  371. * \param IndexDiffFile The name of the Index file.
  372. *
  373. * \return \b true if the Index file was successfully parsed, \b
  374. * false otherwise.
  375. */
  376. bool ParseDiffIndex(std::string IndexDiffFile);
  377. /** \brief Create a new pkgAcqDiffIndex.
  378. *
  379. * \param Owner The Acquire object that owns this item.
  380. *
  381. * \param URI The URI of the list file to download.
  382. *
  383. * \param URIDesc A long description of the list file to download.
  384. *
  385. * \param ShortDesc A short description of the list file to download.
  386. *
  387. * \param ExpectedHashes The list file's hashsums which are expected.
  388. */
  389. pkgAcqDiffIndex(pkgAcquire *Owner,
  390. struct IndexTarget const * const Target,
  391. HashStringList const &ExpectedHashes,
  392. indexRecords *MetaIndexParser);
  393. };
  394. /*}}}*/
  395. /** \brief An item that is responsible for fetching client-merge patches {{{
  396. * that need to be applied to a given package index file.
  397. *
  398. * Instead of downloading and applying each patch one by one like its
  399. * sister #pkgAcqIndexDiffs this class will download all patches at once
  400. * and call rred with all the patches downloaded once. Rred will then
  401. * merge and apply them in one go, which should be a lot faster – but is
  402. * incompatible with server-based merges of patches like reprepro can do.
  403. *
  404. * \sa pkgAcqDiffIndex, pkgAcqIndex
  405. */
  406. class pkgAcqIndexMergeDiffs : public pkgAcqBaseIndex
  407. {
  408. protected:
  409. /** \brief If \b true, debugging output will be written to
  410. * std::clog.
  411. */
  412. bool Debug;
  413. /** \brief URI of the package index file that is being
  414. * reconstructed.
  415. */
  416. std::string RealURI;
  417. /** \brief description of the file being downloaded. */
  418. std::string Description;
  419. /** \brief information about the current patch */
  420. struct DiffInfo const patch;
  421. /** \brief list of all download items for the patches */
  422. std::vector<pkgAcqIndexMergeDiffs*> const * const allPatches;
  423. /** The current status of this patch. */
  424. enum DiffState
  425. {
  426. /** \brief The diff is currently being fetched. */
  427. StateFetchDiff,
  428. /** \brief The diff is currently being applied. */
  429. StateApplyDiff,
  430. /** \brief the work with this diff is done */
  431. StateDoneDiff,
  432. /** \brief something bad happened and fallback was triggered */
  433. StateErrorDiff
  434. } State;
  435. public:
  436. /** \brief Called when the patch file failed to be downloaded.
  437. *
  438. * This method will fall back to downloading the whole index file
  439. * outright; its arguments are ignored.
  440. */
  441. virtual void Failed(std::string Message,pkgAcquire::MethodConfig *Cnf);
  442. virtual void Done(std::string Message,unsigned long long Size, HashStringList const &Hashes,
  443. pkgAcquire::MethodConfig *Cnf);
  444. virtual std::string DescURI() const {return RealURI + "Index";};
  445. /** \brief Create an index merge-diff item.
  446. *
  447. * \param Owner The pkgAcquire object that owns this item.
  448. *
  449. * \param URI The URI of the package index file being
  450. * reconstructed.
  451. *
  452. * \param URIDesc A long description of this item.
  453. *
  454. * \param ShortDesc A brief description of this item.
  455. *
  456. * \param ExpectedHashes The expected md5sum of the completely
  457. * reconstructed package index file; the index file will be tested
  458. * against this value when it is entirely reconstructed.
  459. *
  460. * \param patch contains infos about the patch this item is supposed
  461. * to download which were read from the index
  462. *
  463. * \param allPatches contains all related items so that each item can
  464. * check if it was the last one to complete the download step
  465. */
  466. pkgAcqIndexMergeDiffs(pkgAcquire *Owner,
  467. struct IndexTarget const * const Target,
  468. HashStringList const &ExpectedHash,
  469. indexRecords *MetaIndexParser,
  470. DiffInfo const &patch,
  471. std::vector<pkgAcqIndexMergeDiffs*> const * const allPatches);
  472. };
  473. /*}}}*/
  474. /** \brief An item that is responsible for fetching server-merge patches {{{
  475. * that need to be applied to a given package index file.
  476. *
  477. * After downloading and applying a single patch, this item will
  478. * enqueue a new pkgAcqIndexDiffs to download and apply the remaining
  479. * patches. If no patch can be found that applies to an intermediate
  480. * file or if one of the patches cannot be downloaded, falls back to
  481. * downloading the entire package index file using pkgAcqIndex.
  482. *
  483. * \sa pkgAcqDiffIndex, pkgAcqIndex
  484. */
  485. class pkgAcqIndexDiffs : public pkgAcqBaseIndex
  486. {
  487. private:
  488. /** \brief Queue up the next diff download.
  489. *
  490. * Search for the next available diff that applies to the file
  491. * that currently exists on disk, and enqueue it by calling
  492. * QueueURI().
  493. *
  494. * \return \b true if an applicable diff was found, \b false
  495. * otherwise.
  496. */
  497. bool QueueNextDiff();
  498. /** \brief Handle tasks that must be performed after the item
  499. * finishes downloading.
  500. *
  501. * Dequeues the item and checks the resulting file's hashsums
  502. * against ExpectedHashes after the last patch was applied.
  503. * There is no need to check the md5/sha1 after a "normal"
  504. * patch because QueueNextDiff() will check the sha1 later.
  505. *
  506. * \param allDone If \b true, the file was entirely reconstructed,
  507. * and its md5sum is verified.
  508. */
  509. void Finish(bool allDone=false);
  510. protected:
  511. /** \brief If \b true, debugging output will be written to
  512. * std::clog.
  513. */
  514. bool Debug;
  515. /** \brief The URI of the package index file that is being
  516. * reconstructed.
  517. */
  518. std::string RealURI;
  519. /** A description of the file being downloaded. */
  520. std::string Description;
  521. /** The patches that remain to be downloaded, including the patch
  522. * being downloaded right now. This list should be ordered so
  523. * that each diff appears before any diff that depends on it.
  524. *
  525. * \todo These are indexed by sha1sum; why not use some sort of
  526. * dictionary instead of relying on ordering and stripping them
  527. * off the front?
  528. */
  529. std::vector<DiffInfo> available_patches;
  530. /** Stop applying patches when reaching that sha1 */
  531. std::string ServerSha1;
  532. /** The current status of this patch. */
  533. enum DiffState
  534. {
  535. /** \brief The diff is in an unknown state. */
  536. StateFetchUnkown,
  537. /** \brief The diff is currently being fetched. */
  538. StateFetchDiff,
  539. /** \brief The diff is currently being uncompressed. */
  540. StateUnzipDiff, // FIXME: No longer used
  541. /** \brief The diff is currently being applied. */
  542. StateApplyDiff
  543. } State;
  544. public:
  545. /** \brief Called when the patch file failed to be downloaded.
  546. *
  547. * This method will fall back to downloading the whole index file
  548. * outright; its arguments are ignored.
  549. */
  550. virtual void Failed(std::string Message,pkgAcquire::MethodConfig *Cnf);
  551. virtual void Done(std::string Message,unsigned long long Size, HashStringList const &Hashes,
  552. pkgAcquire::MethodConfig *Cnf);
  553. virtual std::string DescURI() const {return RealURI + "Index";};
  554. /** \brief Create an index diff item.
  555. *
  556. * After filling in its basic fields, this invokes Finish(true) if
  557. * \a diffs is empty, or QueueNextDiff() otherwise.
  558. *
  559. * \param Owner The pkgAcquire object that owns this item.
  560. *
  561. * \param URI The URI of the package index file being
  562. * reconstructed.
  563. *
  564. * \param URIDesc A long description of this item.
  565. *
  566. * \param ShortDesc A brief description of this item.
  567. *
  568. * \param ExpectedHashes The expected md5sum of the completely
  569. * reconstructed package index file; the index file will be tested
  570. * against this value when it is entirely reconstructed.
  571. *
  572. * \param ServerSha1 is the sha1sum of the current file on the server
  573. *
  574. * \param diffs The remaining diffs from the index of diffs. They
  575. * should be ordered so that each diff appears before any diff
  576. * that depends on it.
  577. */
  578. pkgAcqIndexDiffs(pkgAcquire *Owner,
  579. struct IndexTarget const * const Target,
  580. HashStringList const &ExpectedHash,
  581. indexRecords *MetaIndexParser,
  582. std::string ServerSha1,
  583. std::vector<DiffInfo> diffs=std::vector<DiffInfo>());
  584. };
  585. /*}}}*/
  586. /** \brief An acquire item that is responsible for fetching an index {{{
  587. * file (e.g., Packages or Sources).
  588. *
  589. * \sa pkgAcqDiffIndex, pkgAcqIndexDiffs, pkgAcqIndexTrans
  590. *
  591. * \todo Why does pkgAcqIndex have protected members?
  592. */
  593. class pkgAcqIndex : public pkgAcqBaseIndex
  594. {
  595. protected:
  596. /** \brief If \b true, the index file has been decompressed. */
  597. bool Decompression;
  598. /** \brief If \b true, the partially downloaded file will be
  599. * removed when the download completes.
  600. */
  601. bool Erase;
  602. /** \brief Verify for correctness by checking if a "Package"
  603. * tag is found in the index. This can be set to
  604. * false for optional index targets
  605. *
  606. */
  607. // FIXME: instead of a bool it should use a verify string that will
  608. // then be used in the pkgAcqIndex::Done method to ensure that
  609. // the downloaded file contains the expected tag
  610. bool Verify;
  611. /** \brief The object that is actually being fetched (minus any
  612. * compression-related extensions).
  613. */
  614. std::string RealURI;
  615. /** \brief The compression-related file extensions that are being
  616. * added to the downloaded file one by one if first fails (e.g., "gz bz2").
  617. */
  618. std::string CompressionExtension;
  619. public:
  620. // Specialized action members
  621. virtual void Failed(std::string Message,pkgAcquire::MethodConfig *Cnf);
  622. virtual void Done(std::string Message,unsigned long long Size, HashStringList const &Hashes,
  623. pkgAcquire::MethodConfig *Cnf);
  624. virtual std::string Custom600Headers() const;
  625. virtual std::string DescURI() const {return Desc.URI;};
  626. /** \brief Create a pkgAcqIndex.
  627. *
  628. * \param Owner The pkgAcquire object with which this item is
  629. * associated.
  630. *
  631. * \param URI The URI of the index file that is to be downloaded.
  632. *
  633. * \param URIDesc A "URI-style" description of this index file.
  634. *
  635. * \param ShortDesc A brief description of this index file.
  636. *
  637. * \param ExpectedHashes The expected hashsum of this index file.
  638. *
  639. * \param compressExt The compression-related extension with which
  640. * this index file should be downloaded, or "" to autodetect
  641. * Compression types can be set with config Acquire::CompressionTypes,
  642. * default is ".lzma" or ".bz2" (if the needed binaries are present)
  643. * fallback is ".gz" or none.
  644. */
  645. pkgAcqIndex(pkgAcquire *Owner,std::string URI,std::string URIDesc,
  646. std::string ShortDesc, HashStringList const &ExpectedHashes,
  647. std::string compressExt="");
  648. pkgAcqIndex(pkgAcquire *Owner,
  649. IndexTarget const * const Target,
  650. HashStringList const &ExpectedHash,
  651. indexRecords *MetaIndexParser);
  652. void Init(std::string const &URI, std::string const &URIDesc,
  653. std::string const &ShortDesc);
  654. };
  655. /*}}}*/
  656. /** \brief An acquire item that is responsible for fetching a {{{
  657. * translated index file.
  658. *
  659. * The only difference from pkgAcqIndex is that transient failures
  660. * are suppressed: no error occurs if the translated index file is
  661. * missing.
  662. */
  663. class pkgAcqIndexTrans : public pkgAcqIndex
  664. {
  665. public:
  666. virtual void Failed(std::string Message,pkgAcquire::MethodConfig *Cnf);
  667. virtual std::string Custom600Headers() const;
  668. /** \brief Create a pkgAcqIndexTrans.
  669. *
  670. * \param Owner The pkgAcquire object with which this item is
  671. * associated.
  672. *
  673. * \param URI The URI of the index file that is to be downloaded.
  674. *
  675. * \param URIDesc A "URI-style" description of this index file.
  676. *
  677. * \param ShortDesc A brief description of this index file.
  678. */
  679. pkgAcqIndexTrans(pkgAcquire *Owner,std::string URI,std::string URIDesc,
  680. std::string ShortDesc);
  681. pkgAcqIndexTrans(pkgAcquire *Owner, IndexTarget const * const Target,
  682. HashStringList const &ExpectedHashes, indexRecords *MetaIndexParser);
  683. };
  684. /*}}}*/
  685. /** \brief Information about an index file. */ /*{{{*/
  686. class IndexTarget
  687. {
  688. public:
  689. /** \brief A URI from which the index file can be downloaded. */
  690. std::string URI;
  691. /** \brief A description of the index file. */
  692. std::string Description;
  693. /** \brief A shorter description of the index file. */
  694. std::string ShortDesc;
  695. /** \brief The key by which this index file should be
  696. * looked up within the meta signature file.
  697. */
  698. std::string MetaKey;
  699. virtual bool IsOptional() const {
  700. return false;
  701. }
  702. virtual bool IsSubIndex() const {
  703. return false;
  704. }
  705. };
  706. /*}}}*/
  707. /** \brief Information about an optional index file. */ /*{{{*/
  708. class OptionalIndexTarget : public IndexTarget
  709. {
  710. virtual bool IsOptional() const {
  711. return true;
  712. }
  713. };
  714. /*}}}*/
  715. /** \brief Information about an subindex index file. */ /*{{{*/
  716. class SubIndexTarget : public IndexTarget
  717. {
  718. virtual bool IsSubIndex() const {
  719. return true;
  720. }
  721. };
  722. /*}}}*/
  723. /** \brief Information about an subindex index file. */ /*{{{*/
  724. class OptionalSubIndexTarget : public OptionalIndexTarget
  725. {
  726. virtual bool IsSubIndex() const {
  727. return true;
  728. }
  729. };
  730. /*}}}*/
  731. /** \brief An acquire item that downloads the detached signature {{{
  732. * of a meta-index (Release) file, then queues up the release
  733. * file itself.
  734. *
  735. * \todo Why protected members?
  736. *
  737. * \sa pkgAcqMetaIndex
  738. */
  739. class pkgAcqMetaSig : public pkgAcquire::Item
  740. {
  741. protected:
  742. /** \brief The last good signature file */
  743. std::string LastGoodSig;
  744. /** \brief The URI of the signature file. Unlike Desc.URI, this is
  745. * never modified; it is used to determine the file that is being
  746. * downloaded.
  747. */
  748. std::string RealURI;
  749. /** \brief The URI of the meta-index file to be fetched after the signature. */
  750. std::string MetaIndexURI;
  751. /** \brief A "URI-style" description of the meta-index file to be
  752. * fetched after the signature.
  753. */
  754. std::string MetaIndexURIDesc;
  755. /** \brief A brief description of the meta-index file to be fetched
  756. * after the signature.
  757. */
  758. std::string MetaIndexShortDesc;
  759. /** \brief A package-system-specific parser for the meta-index file. */
  760. indexRecords* MetaIndexParser;
  761. /** \brief The index files which should be looked up in the meta-index
  762. * and then downloaded.
  763. *
  764. * \todo Why a list of pointers instead of a list of structs?
  765. */
  766. const std::vector<IndexTarget*>* IndexTargets;
  767. public:
  768. // Specialized action members
  769. virtual void Failed(std::string Message,pkgAcquire::MethodConfig *Cnf);
  770. virtual void Done(std::string Message,unsigned long long Size, HashStringList const &Hashes,
  771. pkgAcquire::MethodConfig *Cnf);
  772. virtual std::string Custom600Headers() const;
  773. virtual std::string DescURI() const {return RealURI; };
  774. /** \brief Create a new pkgAcqMetaSig. */
  775. pkgAcqMetaSig(pkgAcquire *Owner,std::string URI,std::string URIDesc, std::string ShortDesc,
  776. std::string MetaIndexURI, std::string MetaIndexURIDesc, std::string MetaIndexShortDesc,
  777. const std::vector<IndexTarget*>* IndexTargets,
  778. indexRecords* MetaIndexParser);
  779. virtual ~pkgAcqMetaSig();
  780. };
  781. /*}}}*/
  782. /** \brief An item that is responsible for downloading the meta-index {{{
  783. * file (i.e., Release) itself and verifying its signature.
  784. *
  785. * Once the download and verification are complete, the downloads of
  786. * the individual index files are queued up using pkgAcqDiffIndex.
  787. * If the meta-index file had a valid signature, the expected hashsums
  788. * of the index files will be the md5sums listed in the meta-index;
  789. * otherwise, the expected hashsums will be "" (causing the
  790. * authentication of the index files to be bypassed).
  791. */
  792. class pkgAcqMetaIndex : public pkgAcquire::Item
  793. {
  794. protected:
  795. /** \brief The URI that is actually being downloaded; never
  796. * modified by pkgAcqMetaIndex.
  797. */
  798. std::string RealURI;
  799. /** \brief The file in which the signature for this index was stored.
  800. *
  801. * If empty, the signature and the md5sums of the individual
  802. * indices will not be checked.
  803. */
  804. std::string SigFile;
  805. /** \brief The index files to download. */
  806. const std::vector<IndexTarget*>* IndexTargets;
  807. /** \brief The parser for the meta-index file. */
  808. indexRecords* MetaIndexParser;
  809. /** \brief If \b true, the index's signature is currently being verified.
  810. */
  811. bool AuthPass;
  812. // required to deal gracefully with problems caused by incorrect ims hits
  813. bool IMSHit;
  814. /** \brief Check that the release file is a release file for the
  815. * correct distribution.
  816. *
  817. * \return \b true if no fatal errors were encountered.
  818. */
  819. bool VerifyVendor(std::string Message);
  820. /** \brief Called when a file is finished being retrieved.
  821. *
  822. * If the file was not downloaded to DestFile, a copy process is
  823. * set up to copy it to DestFile; otherwise, Complete is set to \b
  824. * true and the file is moved to its final location.
  825. *
  826. * \param Message The message block received from the fetch
  827. * subprocess.
  828. */
  829. void RetrievalDone(std::string Message);
  830. /** \brief Called when authentication succeeded.
  831. *
  832. * Sanity-checks the authenticated file, queues up the individual
  833. * index files for download, and saves the signature in the lists
  834. * directory next to the authenticated list file.
  835. *
  836. * \param Message The message block received from the fetch
  837. * subprocess.
  838. */
  839. void AuthDone(std::string Message);
  840. /** \brief Starts downloading the individual index files.
  841. *
  842. * \param verify If \b true, only indices whose expected hashsum
  843. * can be determined from the meta-index will be downloaded, and
  844. * the hashsums of indices will be checked (reporting
  845. * #StatAuthError if there is a mismatch). If verify is \b false,
  846. * no hashsum checking will be performed.
  847. */
  848. void QueueIndexes(bool verify);
  849. public:
  850. // Specialized action members
  851. virtual void Failed(std::string Message,pkgAcquire::MethodConfig *Cnf);
  852. virtual void Done(std::string Message,unsigned long long Size, HashStringList const &Hashes,
  853. pkgAcquire::MethodConfig *Cnf);
  854. virtual std::string Custom600Headers() const;
  855. virtual std::string DescURI() const {return RealURI; };
  856. /** \brief Create a new pkgAcqMetaIndex. */
  857. pkgAcqMetaIndex(pkgAcquire *Owner,
  858. std::string URI,std::string URIDesc, std::string ShortDesc,
  859. std::string SigFile,
  860. const std::vector<IndexTarget*>* IndexTargets,
  861. indexRecords* MetaIndexParser);
  862. };
  863. /*}}}*/
  864. /** \brief An item repsonsible for downloading clearsigned metaindexes {{{*/
  865. class pkgAcqMetaClearSig : public pkgAcqMetaIndex
  866. {
  867. /** \brief The URI of the meta-index file for the detached signature */
  868. std::string MetaIndexURI;
  869. /** \brief A "URI-style" description of the meta-index file */
  870. std::string MetaIndexURIDesc;
  871. /** \brief A brief description of the meta-index file */
  872. std::string MetaIndexShortDesc;
  873. /** \brief The URI of the detached meta-signature file if the clearsigned one failed. */
  874. std::string MetaSigURI;
  875. /** \brief A "URI-style" description of the meta-signature file */
  876. std::string MetaSigURIDesc;
  877. /** \brief A brief description of the meta-signature file */
  878. std::string MetaSigShortDesc;
  879. public:
  880. void Failed(std::string Message,pkgAcquire::MethodConfig *Cnf);
  881. virtual std::string Custom600Headers() const;
  882. /** \brief Create a new pkgAcqMetaClearSig. */
  883. pkgAcqMetaClearSig(pkgAcquire *Owner,
  884. std::string const &URI, std::string const &URIDesc, std::string const &ShortDesc,
  885. std::string const &MetaIndexURI, std::string const &MetaIndexURIDesc, std::string const &MetaIndexShortDesc,
  886. std::string const &MetaSigURI, std::string const &MetaSigURIDesc, std::string const &MetaSigShortDesc,
  887. const std::vector<IndexTarget*>* IndexTargets,
  888. indexRecords* MetaIndexParser);
  889. virtual ~pkgAcqMetaClearSig();
  890. };
  891. /*}}}*/
  892. /** \brief An item that is responsible for fetching a package file. {{{
  893. *
  894. * If the package file already exists in the cache, nothing will be
  895. * done.
  896. */
  897. class pkgAcqArchive : public pkgAcquire::Item
  898. {
  899. protected:
  900. /** \brief The package version being fetched. */
  901. pkgCache::VerIterator Version;
  902. /** \brief The list of sources from which to pick archives to
  903. * download this package from.
  904. */
  905. pkgSourceList *Sources;
  906. /** \brief A package records object, used to look up the file
  907. * corresponding to each version of the package.
  908. */
  909. pkgRecords *Recs;
  910. /** \brief A location in which the actual filename of the package
  911. * should be stored.
  912. */
  913. std::string &StoreFilename;
  914. /** \brief The next file for this version to try to download. */
  915. pkgCache::VerFileIterator Vf;
  916. /** \brief How many (more) times to try to find a new source from
  917. * which to download this package version if it fails.
  918. *
  919. * Set from Acquire::Retries.
  920. */
  921. unsigned int Retries;
  922. /** \brief \b true if this version file is being downloaded from a
  923. * trusted source.
  924. */
  925. bool Trusted;
  926. /** \brief Queue up the next available file for this version. */
  927. bool QueueNext();
  928. public:
  929. virtual void Failed(std::string Message,pkgAcquire::MethodConfig *Cnf);
  930. virtual void Done(std::string Message,unsigned long long Size, HashStringList const &Hashes,
  931. pkgAcquire::MethodConfig *Cnf);
  932. virtual std::string DescURI() const {return Desc.URI;};
  933. virtual std::string ShortDesc() const {return Desc.ShortDesc;};
  934. virtual void Finished();
  935. virtual bool IsTrusted() const;
  936. /** \brief Create a new pkgAcqArchive.
  937. *
  938. * \param Owner The pkgAcquire object with which this item is
  939. * associated.
  940. *
  941. * \param Sources The sources from which to download version
  942. * files.
  943. *
  944. * \param Recs A package records object, used to look up the file
  945. * corresponding to each version of the package.
  946. *
  947. * \param Version The package version to download.
  948. *
  949. * \param[out] StoreFilename A location in which the actual filename of
  950. * the package should be stored. It will be set to a guessed
  951. * basename in the constructor, and filled in with a fully
  952. * qualified filename once the download finishes.
  953. */
  954. pkgAcqArchive(pkgAcquire *Owner,pkgSourceList *Sources,
  955. pkgRecords *Recs,pkgCache::VerIterator const &Version,
  956. std::string &StoreFilename);
  957. };
  958. /*}}}*/
  959. /** \brief Retrieve an arbitrary file to the current directory. {{{
  960. *
  961. * The file is retrieved even if it is accessed via a URL type that
  962. * normally is a NOP, such as "file". If the download fails, the
  963. * partial file is renamed to get a ".FAILED" extension.
  964. */
  965. class pkgAcqFile : public pkgAcquire::Item
  966. {
  967. /** \brief How many times to retry the download, set from
  968. * Acquire::Retries.
  969. */
  970. unsigned int Retries;
  971. /** \brief Should this file be considered a index file */
  972. bool IsIndexFile;
  973. public:
  974. // Specialized action members
  975. virtual void Failed(std::string Message,pkgAcquire::MethodConfig *Cnf);
  976. virtual void Done(std::string Message,unsigned long long Size, HashStringList const &CalcHashes,
  977. pkgAcquire::MethodConfig *Cnf);
  978. virtual std::string DescURI() const {return Desc.URI;};
  979. virtual std::string Custom600Headers() const;
  980. /** \brief Create a new pkgAcqFile object.
  981. *
  982. * \param Owner The pkgAcquire object with which this object is
  983. * associated.
  984. *
  985. * \param URI The URI to download.
  986. *
  987. * \param Hashes The hashsums of the file to download, if they are known;
  988. * otherwise empty list.
  989. *
  990. * \param Size The size of the file to download, if it is known;
  991. * otherwise 0.
  992. *
  993. * \param Desc A description of the file being downloaded.
  994. *
  995. * \param ShortDesc A brief description of the file being
  996. * downloaded.
  997. *
  998. * \param DestDir The directory the file should be downloaded into.
  999. *
  1000. * \param DestFilename The filename+path the file is downloaded to.
  1001. *
  1002. * \param IsIndexFile The file is considered a IndexFile and cache-control
  1003. * headers like "cache-control: max-age=0" are send
  1004. *
  1005. * If DestFilename is empty, download to DestDir/\<basename\> if
  1006. * DestDir is non-empty, $CWD/\<basename\> otherwise. If
  1007. * DestFilename is NOT empty, DestDir is ignored and DestFilename
  1008. * is the absolute name to which the file should be downloaded.
  1009. */
  1010. pkgAcqFile(pkgAcquire *Owner, std::string URI, HashStringList const &Hashes, unsigned long long Size,
  1011. std::string Desc, std::string ShortDesc,
  1012. const std::string &DestDir="", const std::string &DestFilename="",
  1013. bool IsIndexFile=false);
  1014. };
  1015. /*}}}*/
  1016. /** @} */
  1017. #endif