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