acquire-method.h 2.8 KB

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