acquire-method.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. 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. };
  44. struct FetchResult
  45. {
  46. HashStringList Hashes;
  47. std::vector<std::string> GPGVOutput;
  48. time_t LastModified;
  49. bool IMSHit;
  50. std::string Filename;
  51. unsigned long long Size;
  52. unsigned long long ResumePoint;
  53. void TakeHashes(class Hashes &Hash);
  54. FetchResult();
  55. };
  56. // State
  57. std::vector<std::string> Messages;
  58. FetchItem *Queue;
  59. FetchItem *QueueBack;
  60. std::string FailReason;
  61. std::string UsedMirror;
  62. std::string IP;
  63. // Handlers for messages
  64. virtual bool Configuration(std::string Message);
  65. virtual bool Fetch(FetchItem * /*Item*/) {return true;};
  66. // Outgoing messages
  67. void Fail(bool Transient = false);
  68. inline void Fail(const char *Why, bool Transient = false) {Fail(std::string(Why),Transient);};
  69. virtual void Fail(std::string Why, bool Transient = false);
  70. virtual void URIStart(FetchResult &Res);
  71. virtual void URIDone(FetchResult &Res,FetchResult *Alt = 0);
  72. bool MediaFail(std::string Required,std::string Drive);
  73. virtual void Exit() {};
  74. void PrintStatus(char const * const header, const char* Format, va_list &args) const;
  75. public:
  76. enum CnfFlags {SingleInstance = (1<<0),
  77. Pipeline = (1<<1), SendConfig = (1<<2),
  78. LocalOnly = (1<<3), NeedsCleanup = (1<<4),
  79. Removable = (1<<5)};
  80. void Log(const char *Format,...);
  81. void Status(const char *Format,...);
  82. void Redirect(const std::string &NewURI);
  83. int Run(bool Single = false);
  84. inline void SetFailReason(std::string Msg) {FailReason = Msg;};
  85. inline void SetIP(std::string aIP) {IP = aIP;};
  86. pkgAcqMethod(const char *Ver,unsigned long Flags = 0);
  87. virtual ~pkgAcqMethod();
  88. void DropPrivsOrDie();
  89. private:
  90. APT_HIDDEN void Dequeue();
  91. };
  92. /** @} */
  93. #endif