]> git.saurik.com Git - apt.git/blob - apt-pkg/acquire-item.h
* use pkgAcqMethod::FailReason() for consistent error reporting
[apt.git] / apt-pkg / acquire-item.h
1 // -*- mode: cpp; mode: fold -*-
2 // Description /*{{{*/
3 // $Id: acquire-item.h,v 1.26.2.3 2004/01/02 18:51:00 mdz Exp $
4 /* ######################################################################
5
6 Acquire Item - Item to acquire
7
8 When an item is instantiated it will add it self to the local list in
9 the Owner Acquire class. Derived classes will then call QueueURI to
10 register all the URI's they wish to fetch at the initial moment.
11
12 Two item classes are provided to provide functionality for downloading
13 of Index files and downloading of Packages.
14
15 A Archive class is provided for downloading .deb files. It does Md5
16 checking and source location as well as a retry algorithm.
17
18 ##################################################################### */
19 /*}}}*/
20 #ifndef PKGLIB_ACQUIRE_ITEM_H
21 #define PKGLIB_ACQUIRE_ITEM_H
22
23 #include <apt-pkg/acquire.h>
24 #include <apt-pkg/indexfile.h>
25 #include <apt-pkg/vendor.h>
26 #include <apt-pkg/sourcelist.h>
27 #include <apt-pkg/pkgrecords.h>
28 #include <apt-pkg/indexrecords.h>
29
30 #ifdef __GNUG__
31 #pragma interface "apt-pkg/acquire-item.h"
32 #endif
33
34 // Item to acquire
35 class pkgAcquire::Item
36 {
37 protected:
38
39 // Some private helper methods for registering URIs
40 pkgAcquire *Owner;
41 inline void QueueURI(ItemDesc &Item)
42 {Owner->Enqueue(Item);};
43 inline void Dequeue() {Owner->Dequeue(this);};
44
45 // Safe rename function with timestamp preservation
46 void Rename(string From,string To);
47
48 public:
49
50 // State of the item
51 enum {StatIdle, StatFetching, StatDone, StatError, StatAuthError} Status;
52 string ErrorText;
53 unsigned long FileSize;
54 unsigned long PartialSize;
55 const char *Mode;
56 unsigned long ID;
57 bool Complete;
58 bool Local;
59 string UsedMirror;
60
61 // Number of queues we are inserted into
62 unsigned int QueueCounter;
63
64 // File to write the fetch into
65 string DestFile;
66
67 // Action members invoked by the worker
68 virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf);
69 virtual void Done(string Message,unsigned long Size,string Md5Hash,
70 pkgAcquire::MethodConfig *Cnf);
71 virtual void Start(string Message,unsigned long Size);
72 virtual string Custom600Headers() {return string();};
73 virtual string DescURI() = 0;
74 virtual string ShortDesc() {return DescURI();}
75 virtual void Finished() {};
76
77 // Inquire functions
78 virtual string MD5Sum() {return string();};
79 pkgAcquire *GetOwner() {return Owner;};
80 virtual bool IsTrusted() {return false;};
81
82 // report mirror problems
83 void ReportMirrorFailure(string FailCode);
84
85 Item(pkgAcquire *Owner);
86 virtual ~Item();
87 };
88
89 // Item class for index files
90 class pkgAcqIndex : public pkgAcquire::Item
91 {
92 protected:
93
94 bool Decompression;
95 bool Erase;
96 pkgAcquire::ItemDesc Desc;
97 string RealURI;
98 string ExpectedMD5;
99 string CompressionExtension;
100
101 public:
102
103 // Specialized action members
104 virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf);
105 virtual void Done(string Message,unsigned long Size,string Md5Hash,
106 pkgAcquire::MethodConfig *Cnf);
107 virtual string Custom600Headers();
108 virtual string DescURI() {return RealURI + CompressionExtension;};
109
110 pkgAcqIndex(pkgAcquire *Owner,string URI,string URIDesc,
111 string ShortDesct, string ExpectedMD5, string compressExt="");
112 };
113
114 struct IndexTarget
115 {
116 string URI;
117 string Description;
118 string ShortDesc;
119 string MetaKey;
120 };
121
122 // Item class for index signatures
123 class pkgAcqMetaSig : public pkgAcquire::Item
124 {
125 protected:
126
127 pkgAcquire::ItemDesc Desc;
128 string RealURI,MetaIndexURI,MetaIndexURIDesc,MetaIndexShortDesc;
129 indexRecords* MetaIndexParser;
130 const vector<struct IndexTarget*>* IndexTargets;
131
132 public:
133
134 // Specialized action members
135 virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf);
136 virtual void Done(string Message,unsigned long Size,string Md5Hash,
137 pkgAcquire::MethodConfig *Cnf);
138 virtual string Custom600Headers();
139 virtual string DescURI() {return RealURI; };
140
141 pkgAcqMetaSig(pkgAcquire *Owner,string URI,string URIDesc, string ShortDesc,
142 string MetaIndexURI, string MetaIndexURIDesc, string MetaIndexShortDesc,
143 const vector<struct IndexTarget*>* IndexTargets,
144 indexRecords* MetaIndexParser);
145 };
146
147 // Item class for index signatures
148 class pkgAcqMetaIndex : public pkgAcquire::Item
149 {
150 protected:
151
152 pkgAcquire::ItemDesc Desc;
153 string RealURI; // FIXME: is this redundant w/ Desc.URI?
154 string SigFile;
155 const vector<struct IndexTarget*>* IndexTargets;
156 indexRecords* MetaIndexParser;
157 bool AuthPass;
158 // required to deal gracefully with problems caused by incorrect ims hits
159 bool IMSHit;
160
161 bool VerifyVendor(string Message);
162 void RetrievalDone(string Message);
163 void AuthDone(string Message);
164 void QueueIndexes(bool verify);
165
166 public:
167
168 // Specialized action members
169 virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf);
170 virtual void Done(string Message,unsigned long Size,string Md5Hash,
171 pkgAcquire::MethodConfig *Cnf);
172 virtual string Custom600Headers();
173 virtual string DescURI() {return RealURI; };
174
175 pkgAcqMetaIndex(pkgAcquire *Owner,
176 string URI,string URIDesc, string ShortDesc,
177 string SigFile,
178 const vector<struct IndexTarget*>* IndexTargets,
179 indexRecords* MetaIndexParser);
180 };
181
182 // Item class for archive files
183 class pkgAcqArchive : public pkgAcquire::Item
184 {
185 protected:
186
187 // State information for the retry mechanism
188 pkgCache::VerIterator Version;
189 pkgAcquire::ItemDesc Desc;
190 pkgSourceList *Sources;
191 pkgRecords *Recs;
192 string MD5;
193 string &StoreFilename;
194 pkgCache::VerFileIterator Vf;
195 unsigned int Retries;
196 bool Trusted;
197
198 // Queue the next available file for download.
199 bool QueueNext();
200
201 public:
202
203 // Specialized action members
204 virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf);
205 virtual void Done(string Message,unsigned long Size,string Md5Hash,
206 pkgAcquire::MethodConfig *Cnf);
207 virtual string MD5Sum() {return MD5;};
208 virtual string DescURI() {return Desc.URI;};
209 virtual string ShortDesc() {return Desc.ShortDesc;};
210 virtual void Finished();
211 virtual bool IsTrusted();
212
213 pkgAcqArchive(pkgAcquire *Owner,pkgSourceList *Sources,
214 pkgRecords *Recs,pkgCache::VerIterator const &Version,
215 string &StoreFilename);
216 };
217
218 // Fetch a generic file to the current directory
219 class pkgAcqFile : public pkgAcquire::Item
220 {
221 pkgAcquire::ItemDesc Desc;
222 string Md5Hash;
223 unsigned int Retries;
224
225 public:
226
227 // Specialized action members
228 virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf);
229 virtual void Done(string Message,unsigned long Size,string Md5Hash,
230 pkgAcquire::MethodConfig *Cnf);
231 virtual string MD5Sum() {return Md5Hash;};
232 virtual string DescURI() {return Desc.URI;};
233
234 // If DestFilename is empty, download to DestDir/<basename> if
235 // DestDir is non-empty, $CWD/<basename> otherwise. If
236 // DestFilename is NOT empty, DestDir is ignored and DestFilename
237 // is the absolute name to which the file should be downloaded.
238 pkgAcqFile(pkgAcquire *Owner, string URI, string MD5, unsigned long Size,
239 string Desc, string ShortDesc,
240 const string &DestDir="", const string &DestFilename="");
241 };
242
243 #endif