8d58a39ba90131d2552f95b3243dc9eeadaa2f07
[ntk/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
60 // Number of queues we are inserted into
61 unsigned int QueueCounter;
62
63 // File to write the fetch into
64 string DestFile;
65
66 // Action members invoked by the worker
67 virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf);
68 virtual void Done(string Message,unsigned long Size,string Md5Hash,
69 pkgAcquire::MethodConfig *Cnf);
70 virtual void Start(string Message,unsigned long Size);
71 virtual string Custom600Headers() {return string();};
72 virtual string DescURI() = 0;
73 virtual string ShortDesc() {return DescURI();}
74 virtual void Finished() {};
75
76 // Inquire functions
77 virtual string MD5Sum() {return string();};
78 pkgAcquire *GetOwner() {return Owner;};
79 virtual bool IsTrusted() {return false;};
80
81 Item(pkgAcquire *Owner);
82 virtual ~Item();
83 };
84
85 // item for index diffs
86 class pkgAcqIndexDiffs : public pkgAcquire::Item
87 {
88 protected:
89 bool Debug;
90 pkgAcquire::ItemDesc Desc;
91 string RealURI;
92 string ExpectedMD5;
93 // this is the SHA-1 sum we expect after the patching
94 string ServerSha1;
95 string CurrentPackagesFile;
96 string Description;
97 struct DiffInfo {
98 string file;
99 string sha1;
100 unsigned long size;
101 };
102 vector<DiffInfo> available_patches;
103
104
105 public:
106
107 // Specialized action members
108 virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf);
109 virtual void Done(string Message,unsigned long Size,string Md5Hash,
110 pkgAcquire::MethodConfig *Cnf);
111 virtual string DescURI() {return RealURI + "Index";};
112 virtual string Custom600Headers();
113
114 // various helpers
115 bool ParseIndexDiff(string IndexDiffFile);
116 void QueueDiffIndex(string URI);
117 bool QueueNextDiff();
118 bool ApplyDiff(string PatchFile);
119 void Finish(bool allDone=false);
120
121 pkgAcqIndexDiffs(pkgAcquire *Owner,string URI,string URIDesc,
122 string ShortDesct, string ExpectedMD5,
123 vector<DiffInfo> diffs=vector<DiffInfo>());
124 };
125
126 // Item class for index files
127 class pkgAcqIndex : public pkgAcquire::Item
128 {
129 protected:
130
131 bool Decompression;
132 bool Erase;
133 pkgAcquire::ItemDesc Desc;
134 string RealURI;
135 string ExpectedMD5;
136
137 public:
138
139 // Specialized action members
140 virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf);
141 virtual void Done(string Message,unsigned long Size,string Md5Hash,
142 pkgAcquire::MethodConfig *Cnf);
143 virtual string Custom600Headers();
144 virtual string DescURI() {return RealURI + ".gz";};
145
146 pkgAcqIndex(pkgAcquire *Owner,string URI,string URIDesc,
147 string ShortDesct, string ExpectedMD5, string compressExt="");
148 };
149
150 struct IndexTarget
151 {
152 string URI;
153 string Description;
154 string ShortDesc;
155 string MetaKey;
156 };
157
158 // Item class for index signatures
159 class pkgAcqMetaSig : public pkgAcquire::Item
160 {
161 protected:
162
163 pkgAcquire::ItemDesc Desc;
164 string RealURI,MetaIndexURI,MetaIndexURIDesc,MetaIndexShortDesc;
165 indexRecords* MetaIndexParser;
166 const vector<struct IndexTarget*>* IndexTargets;
167
168 public:
169
170 // Specialized action members
171 virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf);
172 virtual void Done(string Message,unsigned long Size,string Md5Hash,
173 pkgAcquire::MethodConfig *Cnf);
174 virtual string Custom600Headers();
175 virtual string DescURI() {return RealURI; };
176
177 pkgAcqMetaSig(pkgAcquire *Owner,string URI,string URIDesc, string ShortDesc,
178 string MetaIndexURI, string MetaIndexURIDesc, string MetaIndexShortDesc,
179 const vector<struct IndexTarget*>* IndexTargets,
180 indexRecords* MetaIndexParser);
181 };
182
183 // Item class for index signatures
184 class pkgAcqMetaIndex : public pkgAcquire::Item
185 {
186 protected:
187
188 pkgAcquire::ItemDesc Desc;
189 string RealURI; // FIXME: is this redundant w/ Desc.URI?
190 string SigFile;
191 const vector<struct IndexTarget*>* IndexTargets;
192 indexRecords* MetaIndexParser;
193 bool AuthPass;
194
195 bool VerifyVendor();
196 void RetrievalDone(string Message);
197 void AuthDone(string Message);
198 void QueueIndexes(bool verify);
199
200 public:
201
202 // Specialized action members
203 virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf);
204 virtual void Done(string Message,unsigned long Size,string Md5Hash,
205 pkgAcquire::MethodConfig *Cnf);
206 virtual string Custom600Headers();
207 virtual string DescURI() {return RealURI; };
208
209 pkgAcqMetaIndex(pkgAcquire *Owner,
210 string URI,string URIDesc, string ShortDesc,
211 string SigFile,
212 const vector<struct IndexTarget*>* IndexTargets,
213 indexRecords* MetaIndexParser);
214 };
215
216 // Item class for archive files
217 class pkgAcqArchive : public pkgAcquire::Item
218 {
219 protected:
220
221 // State information for the retry mechanism
222 pkgCache::VerIterator Version;
223 pkgAcquire::ItemDesc Desc;
224 pkgSourceList *Sources;
225 pkgRecords *Recs;
226 string MD5;
227 string &StoreFilename;
228 pkgCache::VerFileIterator Vf;
229 unsigned int Retries;
230 bool Trusted;
231
232 // Queue the next available file for download.
233 bool QueueNext();
234
235 public:
236
237 // Specialized action members
238 virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf);
239 virtual void Done(string Message,unsigned long Size,string Md5Hash,
240 pkgAcquire::MethodConfig *Cnf);
241 virtual string MD5Sum() {return MD5;};
242 virtual string DescURI() {return Desc.URI;};
243 virtual string ShortDesc() {return Desc.ShortDesc;};
244 virtual void Finished();
245 virtual bool IsTrusted();
246
247 pkgAcqArchive(pkgAcquire *Owner,pkgSourceList *Sources,
248 pkgRecords *Recs,pkgCache::VerIterator const &Version,
249 string &StoreFilename);
250 };
251
252 // Fetch a generic file to the current directory
253 class pkgAcqFile : public pkgAcquire::Item
254 {
255 pkgAcquire::ItemDesc Desc;
256 string Md5Hash;
257 unsigned int Retries;
258
259 public:
260
261 // Specialized action members
262 virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf);
263 virtual void Done(string Message,unsigned long Size,string Md5Hash,
264 pkgAcquire::MethodConfig *Cnf);
265 virtual string MD5Sum() {return Md5Hash;};
266 virtual string DescURI() {return Desc.URI;};
267
268 pkgAcqFile(pkgAcquire *Owner,string URI,string MD5,unsigned long Size,
269 string Desc,string ShortDesc);
270 };
271
272 #endif