tell download methods the expected hashes
[ntk/apt.git] / apt-pkg / acquire-method.h
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
6 Acquire Method - Method helper class + functions
7
8 These functions are designed to be used within the method task to
9 ease communication with APT.
10
11 ##################################################################### */
12 /*}}}*/
13
14 /** \addtogroup acquire
15 * @{
16 *
17 * \file acquire-method.h
18 */
19
20 #ifndef PKGLIB_ACQUIRE_METHOD_H
21 #define PKGLIB_ACQUIRE_METHOD_H
22
23 #include <apt-pkg/hashes.h>
24 #include <apt-pkg/macros.h>
25
26 #include <stdarg.h>
27 #include <time.h>
28
29 #include <string>
30 #include <vector>
31
32 #ifndef APT_8_CLEANER_HEADERS
33 #include <apt-pkg/configuration.h>
34 #include <apt-pkg/strutl.h>
35 #endif
36
37 class pkgAcqMethod
38 {
39 protected:
40
41 struct FetchItem
42 {
43 FetchItem *Next;
44
45 std::string Uri;
46 std::string DestFile;
47 time_t LastModified;
48 bool IndexFile;
49 bool FailIgnore;
50 HashStringList ExpectedHashes;
51 };
52
53 struct FetchResult
54 {
55 HashStringList Hashes;
56 std::vector<std::string> GPGVOutput;
57 time_t LastModified;
58 bool IMSHit;
59 std::string Filename;
60 unsigned long long Size;
61 unsigned long long ResumePoint;
62
63 void TakeHashes(class Hashes &Hash);
64 FetchResult();
65 };
66
67 // State
68 std::vector<std::string> Messages;
69 FetchItem *Queue;
70 FetchItem *QueueBack;
71 std::string FailReason;
72 std::string UsedMirror;
73 std::string IP;
74
75 // Handlers for messages
76 virtual bool Configuration(std::string Message);
77 virtual bool Fetch(FetchItem * /*Item*/) {return true;};
78
79 // Outgoing messages
80 void Fail(bool Transient = false);
81 inline void Fail(const char *Why, bool Transient = false) {Fail(std::string(Why),Transient);};
82 virtual void Fail(std::string Why, bool Transient = false);
83 virtual void URIStart(FetchResult &Res);
84 virtual void URIDone(FetchResult &Res,FetchResult *Alt = 0);
85
86 bool MediaFail(std::string Required,std::string Drive);
87 virtual void Exit() {};
88
89 void PrintStatus(char const * const header, const char* Format, va_list &args) const;
90
91 public:
92 enum CnfFlags {SingleInstance = (1<<0),
93 Pipeline = (1<<1), SendConfig = (1<<2),
94 LocalOnly = (1<<3), NeedsCleanup = (1<<4),
95 Removable = (1<<5)};
96
97 void Log(const char *Format,...);
98 void Status(const char *Format,...);
99
100 void Redirect(const std::string &NewURI);
101
102 int Run(bool Single = false);
103 inline void SetFailReason(std::string Msg) {FailReason = Msg;};
104 inline void SetIP(std::string aIP) {IP = aIP;};
105
106 pkgAcqMethod(const char *Ver,unsigned long Flags = 0);
107 virtual ~pkgAcqMethod() {};
108
109 private:
110 APT_HIDDEN void Dequeue();
111 };
112
113 /** @} */
114
115 #endif