acquire-method.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. /* ######################################################################
  4. Acquire Method - Method helper class + functions
  5. These functions are designed to be used within the method task to
  6. ease communication with APT.
  7. ##################################################################### */
  8. /*}}}*/
  9. /** \addtogroup acquire
  10. * @{
  11. *
  12. * \file acquire-method.h
  13. */
  14. #ifndef PKGLIB_ACQUIRE_METHOD_H
  15. #define PKGLIB_ACQUIRE_METHOD_H
  16. #include <apt-pkg/hashes.h>
  17. #include <apt-pkg/macros.h>
  18. #include <stdarg.h>
  19. #include <time.h>
  20. #include <string>
  21. #include <vector>
  22. #ifndef APT_8_CLEANER_HEADERS
  23. #include <apt-pkg/configuration.h>
  24. #include <apt-pkg/strutl.h>
  25. #endif
  26. class pkgAcqMethod
  27. {
  28. protected:
  29. struct FetchItem
  30. {
  31. FetchItem *Next;
  32. std::string Uri;
  33. std::string DestFile;
  34. int DestFileFd;
  35. time_t LastModified;
  36. bool IndexFile;
  37. bool FailIgnore;
  38. HashStringList ExpectedHashes;
  39. // a maximum size we will download, this can be the exact filesize
  40. // for when we know it or a arbitrary limit when we don't know the
  41. // filesize (like a InRelease file)
  42. unsigned long long MaximumSize;
  43. FetchItem();
  44. virtual ~FetchItem();
  45. private:
  46. void * const d;
  47. };
  48. struct FetchResult
  49. {
  50. HashStringList Hashes;
  51. std::vector<std::string> GPGVOutput;
  52. time_t LastModified;
  53. bool IMSHit;
  54. std::string Filename;
  55. unsigned long long Size;
  56. unsigned long long ResumePoint;
  57. void TakeHashes(class Hashes &Hash);
  58. FetchResult();
  59. virtual ~FetchResult();
  60. private:
  61. void * const d;
  62. };
  63. // State
  64. std::vector<std::string> Messages;
  65. FetchItem *Queue;
  66. FetchItem *QueueBack;
  67. std::string FailReason;
  68. std::string UsedMirror;
  69. std::string IP;
  70. // Handlers for messages
  71. virtual bool Configuration(std::string Message);
  72. virtual bool Fetch(FetchItem * /*Item*/) {return true;};
  73. virtual bool URIAcquire(std::string const &/*Message*/, FetchItem *Itm) { return Fetch(Itm); };
  74. // Outgoing messages
  75. void Fail(bool Transient = false);
  76. inline void Fail(const char *Why, bool Transient = false) {Fail(std::string(Why),Transient);};
  77. virtual void Fail(std::string Why, bool Transient = false);
  78. virtual void URIStart(FetchResult &Res);
  79. virtual void URIDone(FetchResult &Res,FetchResult *Alt = 0);
  80. bool MediaFail(std::string Required,std::string Drive);
  81. virtual void Exit() {};
  82. void PrintStatus(char const * const header, const char* Format, va_list &args) const;
  83. public:
  84. enum CnfFlags {SingleInstance = (1<<0),
  85. Pipeline = (1<<1), SendConfig = (1<<2),
  86. LocalOnly = (1<<3), NeedsCleanup = (1<<4),
  87. Removable = (1<<5)};
  88. void Log(const char *Format,...);
  89. void Status(const char *Format,...);
  90. void Redirect(const std::string &NewURI);
  91. int Run(bool Single = false);
  92. inline void SetFailReason(std::string Msg) {FailReason = Msg;};
  93. inline void SetIP(std::string aIP) {IP = aIP;};
  94. pkgAcqMethod(const char *Ver,unsigned long Flags = 0);
  95. virtual ~pkgAcqMethod();
  96. void DropPrivsOrDie();
  97. private:
  98. APT_HIDDEN void Dequeue();
  99. };
  100. /** @} */
  101. #endif