]> git.saurik.com Git - apt.git/blob - apt-pkg/acquire-item.h
* use the new cool rred method for the patchting
[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
94 // this is the SHA-1 sum we expect after the patching
95 string ServerSha1;
96 string CurrentPackagesFile;
97 string Description;
98 struct DiffInfo {
99 string file;
100 string sha1;
101 unsigned long size;
102 };
103 vector<DiffInfo> available_patches;
104 enum {StateFetchIndex,StateFetchDiff,StateUnzipDiff,StateApplyDiff} State;
105
106 public:
107
108 // Specialized action members
109 virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf);
110 virtual void Done(string Message,unsigned long Size,string Md5Hash,
111 pkgAcquire::MethodConfig *Cnf);
112 virtual string DescURI() {return RealURI + "Index";};
113 virtual string Custom600Headers();
114
115 // various helpers
116 bool ParseIndexDiff(string IndexDiffFile);
117 void QueueDiffIndex(string URI);
118 bool QueueNextDiff();
119 bool ApplyDiff(string PatchFile);
120 void Finish(bool allDone=false);
121
122 pkgAcqIndexDiffs(pkgAcquire *Owner,string URI,string URIDesc,
123 string ShortDesct, string ExpectedMD5,
124 vector<DiffInfo> diffs=vector<DiffInfo>());
125 };
126
127 // Item class for index files
128 class pkgAcqIndex : public pkgAcquire::Item
129 {
130 protected:
131
132 bool Decompression;
133 bool Erase;
134 pkgAcquire::ItemDesc Desc;
135 string RealURI;
136 string ExpectedMD5;
137
138 public:
139
140 // Specialized action members
141 virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf);
142 virtual void Done(string Message,unsigned long Size,string Md5Hash,
143 pkgAcquire::MethodConfig *Cnf);
144 virtual string Custom600Headers();
145 virtual string DescURI() {return RealURI + ".gz";};
146
147 pkgAcqIndex(pkgAcquire *Owner,string URI,string URIDesc,
148 string ShortDesct, string ExpectedMD5, string compressExt="");
149 };
150
151 struct IndexTarget
152 {
153 string URI;
154 string Description;
155 string ShortDesc;
156 string MetaKey;
157 };
158
159 // Item class for index signatures
160 class pkgAcqMetaSig : public pkgAcquire::Item
161 {
162 protected:
163
164 pkgAcquire::ItemDesc Desc;
165 string RealURI,MetaIndexURI,MetaIndexURIDesc,MetaIndexShortDesc;
166 indexRecords* MetaIndexParser;
167 const vector<struct IndexTarget*>* IndexTargets;
168
169 public:
170
171 // Specialized action members
172 virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf);
173 virtual void Done(string Message,unsigned long Size,string Md5Hash,
174 pkgAcquire::MethodConfig *Cnf);
175 virtual string Custom600Headers();
176 virtual string DescURI() {return RealURI; };
177
178 pkgAcqMetaSig(pkgAcquire *Owner,string URI,string URIDesc, string ShortDesc,
179 string MetaIndexURI, string MetaIndexURIDesc, string MetaIndexShortDesc,
180 const vector<struct IndexTarget*>* IndexTargets,
181 indexRecords* MetaIndexParser);
182 };
183
184 // Item class for index signatures
185 class pkgAcqMetaIndex : public pkgAcquire::Item
186 {
187 protected:
188
189 pkgAcquire::ItemDesc Desc;
190 string RealURI; // FIXME: is this redundant w/ Desc.URI?
191 string SigFile;
192 const vector<struct IndexTarget*>* IndexTargets;
193 indexRecords* MetaIndexParser;
194 bool AuthPass;
195
196 bool VerifyVendor();
197 void RetrievalDone(string Message);
198 void AuthDone(string Message);
199 void QueueIndexes(bool verify);
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 Custom600Headers();
208 virtual string DescURI() {return RealURI; };
209
210 pkgAcqMetaIndex(pkgAcquire *Owner,
211 string URI,string URIDesc, string ShortDesc,
212 string SigFile,
213 const vector<struct IndexTarget*>* IndexTargets,
214 indexRecords* MetaIndexParser);
215 };
216
217 // Item class for archive files
218 class pkgAcqArchive : public pkgAcquire::Item
219 {
220 protected:
221
222 // State information for the retry mechanism
223 pkgCache::VerIterator Version;
224 pkgAcquire::ItemDesc Desc;
225 pkgSourceList *Sources;
226 pkgRecords *Recs;
227 string MD5;
228 string &StoreFilename;
229 pkgCache::VerFileIterator Vf;
230 unsigned int Retries;
231 bool Trusted;
232
233 // Queue the next available file for download.
234 bool QueueNext();
235
236 public:
237
238 // Specialized action members
239 virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf);
240 virtual void Done(string Message,unsigned long Size,string Md5Hash,
241 pkgAcquire::MethodConfig *Cnf);
242 virtual string MD5Sum() {return MD5;};
243 virtual string DescURI() {return Desc.URI;};
244 virtual string ShortDesc() {return Desc.ShortDesc;};
245 virtual void Finished();
246 virtual bool IsTrusted();
247
248 pkgAcqArchive(pkgAcquire *Owner,pkgSourceList *Sources,
249 pkgRecords *Recs,pkgCache::VerIterator const &Version,
250 string &StoreFilename);
251 };
252
253 // Fetch a generic file to the current directory
254 class pkgAcqFile : public pkgAcquire::Item
255 {
256 pkgAcquire::ItemDesc Desc;
257 string Md5Hash;
258 unsigned int Retries;
259
260 public:
261
262 // Specialized action members
263 virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf);
264 virtual void Done(string Message,unsigned long Size,string Md5Hash,
265 pkgAcquire::MethodConfig *Cnf);
266 virtual string MD5Sum() {return Md5Hash;};
267 virtual string DescURI() {return Desc.URI;};
268
269 pkgAcqFile(pkgAcquire *Owner,string URI,string MD5,unsigned long Size,
270 string Desc,string ShortDesc);
271 };
272
273 #endif