acquire-method.h 3.2 KB

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