acquire-method.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. #ifndef PKGLIB_ACQUIRE_METHOD_H
  11. #define PKGLIB_ACQUIRE_METHOD_H
  12. #include <apt-pkg/configuration.h>
  13. #include <apt-pkg/strutl.h>
  14. class Hashes;
  15. class pkgAcqMethod
  16. {
  17. protected:
  18. struct FetchItem
  19. {
  20. FetchItem *Next;
  21. string Uri;
  22. string DestFile;
  23. time_t LastModified;
  24. bool IndexFile;
  25. };
  26. struct FetchResult
  27. {
  28. string MD5Sum;
  29. string SHA1Sum;
  30. vector<string> GPGVOutput;
  31. time_t LastModified;
  32. bool IMSHit;
  33. string Filename;
  34. unsigned long Size;
  35. unsigned long ResumePoint;
  36. void TakeHashes(Hashes &Hash);
  37. FetchResult();
  38. };
  39. // State
  40. vector<string> Messages;
  41. FetchItem *Queue;
  42. FetchItem *QueueBack;
  43. string FailReason;
  44. string UsedMirror;
  45. string IP;
  46. // Handlers for messages
  47. virtual bool Configuration(string Message);
  48. virtual bool Fetch(FetchItem * /*Item*/) {return true;};
  49. // Outgoing messages
  50. void Fail(bool Transient = false);
  51. inline void Fail(const char *Why, bool Transient = false) {Fail(string(Why),Transient);};
  52. virtual void Fail(string Why, bool Transient = false);
  53. virtual void URIStart(FetchResult &Res);
  54. virtual void URIDone(FetchResult &Res,FetchResult *Alt = 0);
  55. bool MediaFail(string Required,string Drive);
  56. virtual void Exit() {};
  57. public:
  58. enum CnfFlags {SingleInstance = (1<<0),
  59. Pipeline = (1<<1), SendConfig = (1<<2),
  60. LocalOnly = (1<<3), NeedsCleanup = (1<<4),
  61. Removable = (1<<5)};
  62. void Log(const char *Format,...);
  63. void Status(const char *Format,...);
  64. int Run(bool Single = false);
  65. inline void SetFailReason(string Msg) {FailReason = Msg;};
  66. inline void SetIP(string aIP) {IP = aIP;};
  67. pkgAcqMethod(const char *Ver,unsigned long Flags = 0);
  68. virtual ~pkgAcqMethod() {};
  69. };
  70. #endif