acquire-method.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. // Outgoing messages
  68. void Fail(bool Transient = false);
  69. inline void Fail(const char *Why, bool Transient = false) {Fail(std::string(Why),Transient);};
  70. virtual void Fail(std::string Why, bool Transient = false);
  71. virtual void URIStart(FetchResult &Res);
  72. virtual void URIDone(FetchResult &Res,FetchResult *Alt = 0);
  73. bool MediaFail(std::string Required,std::string Drive);
  74. virtual void Exit() {};
  75. void PrintStatus(char const * const header, const char* Format, va_list &args) const;
  76. public:
  77. enum CnfFlags {SingleInstance = (1<<0),
  78. Pipeline = (1<<1), SendConfig = (1<<2),
  79. LocalOnly = (1<<3), NeedsCleanup = (1<<4),
  80. Removable = (1<<5)};
  81. void Log(const char *Format,...);
  82. void Status(const char *Format,...);
  83. void Redirect(const std::string &NewURI);
  84. int Run(bool Single = false);
  85. inline void SetFailReason(std::string Msg) {FailReason = Msg;};
  86. inline void SetIP(std::string aIP) {IP = aIP;};
  87. pkgAcqMethod(const char *Ver,unsigned long Flags = 0);
  88. virtual ~pkgAcqMethod();
  89. void DropPrivsOrDie();
  90. private:
  91. APT_HIDDEN void Dequeue();
  92. };
  93. /** @} */
  94. #endif