]> git.saurik.com Git - apt.git/blob - apt-pkg/acquire-item.h
* merged from apt--mvo
[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 Three item classes are provided to provide functionality for
13 downloading of Index, Translation and Packages files.
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,
52 StatAuthError, StatTransientNetworkError} Status;
53 string ErrorText;
54 unsigned long FileSize;
55 unsigned long PartialSize;
56 const char *Mode;
57 unsigned long ID;
58 bool Complete;
59 bool Local;
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 Item(pkgAcquire *Owner);
83 virtual ~Item();
84 };
85
86 // Item class for index files
87 class pkgAcqIndex : public pkgAcquire::Item
88 {
89 protected:
90
91 bool Decompression;
92 bool Erase;
93 pkgAcquire::ItemDesc Desc;
94 string RealURI;
95 string ExpectedMD5;
96 string CompressionExtension;
97
98 public:
99
100 // Specialized action members
101 virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf);
102 virtual void Done(string Message,unsigned long Size,string Md5Hash,
103 pkgAcquire::MethodConfig *Cnf);
104 virtual string Custom600Headers();
105 virtual string DescURI() {return RealURI + CompressionExtension;};
106
107 pkgAcqIndex(pkgAcquire *Owner,string URI,string URIDesc,
108 string ShortDesct, string ExpectedMD5, string compressExt="");
109 };
110
111 // Item class for translated package index files
112 class pkgAcqIndexTrans : public pkgAcqIndex
113 {
114 public:
115
116 virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf);
117 pkgAcqIndexTrans(pkgAcquire *Owner,string URI,string URIDesc,
118 string ShortDesct);
119 };
120
121 struct IndexTarget
122 {
123 string URI;
124 string Description;
125 string ShortDesc;
126 string MetaKey;
127 };
128
129 // Item class for index signatures
130 class pkgAcqMetaSig : public pkgAcquire::Item
131 {
132 protected:
133
134 pkgAcquire::ItemDesc Desc;
135 string RealURI,MetaIndexURI,MetaIndexURIDesc,MetaIndexShortDesc;
136 indexRecords* MetaIndexParser;
137 const vector<struct IndexTarget*>* IndexTargets;
138
139 public:
140
141 // Specialized action members
142 virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf);
143 virtual void Done(string Message,unsigned long Size,string Md5Hash,
144 pkgAcquire::MethodConfig *Cnf);
145 virtual string Custom600Headers();
146 virtual string DescURI() {return RealURI; };
147
148 pkgAcqMetaSig(pkgAcquire *Owner,string URI,string URIDesc, string ShortDesc,
149 string MetaIndexURI, string MetaIndexURIDesc, string MetaIndexShortDesc,
150 const vector<struct IndexTarget*>* IndexTargets,
151 indexRecords* MetaIndexParser);
152 };
153
154 // Item class for index signatures
155 class pkgAcqMetaIndex : public pkgAcquire::Item
156 {
157 protected:
158
159 pkgAcquire::ItemDesc Desc;
160 string RealURI; // FIXME: is this redundant w/ Desc.URI?
161 string SigFile;
162 const vector<struct IndexTarget*>* IndexTargets;
163 indexRecords* MetaIndexParser;
164 bool AuthPass;
165 // required to deal gracefully with problems caused by incorrect ims hits
166 bool IMSHit;
167
168 bool VerifyVendor(string Message);
169 void RetrievalDone(string Message);
170 void AuthDone(string Message);
171 void QueueIndexes(bool verify);
172
173 public:
174
175 // Specialized action members
176 virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf);
177 virtual void Done(string Message,unsigned long Size,string Md5Hash,
178 pkgAcquire::MethodConfig *Cnf);
179 virtual string Custom600Headers();
180 virtual string DescURI() {return RealURI; };
181
182 pkgAcqMetaIndex(pkgAcquire *Owner,
183 string URI,string URIDesc, string ShortDesc,
184 string SigFile,
185 const vector<struct IndexTarget*>* IndexTargets,
186 indexRecords* MetaIndexParser);
187 };
188
189 // Item class for archive files
190 class pkgAcqArchive : public pkgAcquire::Item
191 {
192 protected:
193
194 // State information for the retry mechanism
195 pkgCache::VerIterator Version;
196 pkgAcquire::ItemDesc Desc;
197 pkgSourceList *Sources;
198 pkgRecords *Recs;
199 string MD5;
200 string &StoreFilename;
201 pkgCache::VerFileIterator Vf;
202 unsigned int Retries;
203 bool Trusted;
204
205 // Queue the next available file for download.
206 bool QueueNext();
207
208 public:
209
210 // Specialized action members
211 virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf);
212 virtual void Done(string Message,unsigned long Size,string Md5Hash,
213 pkgAcquire::MethodConfig *Cnf);
214 virtual string MD5Sum() {return MD5;};
215 virtual string DescURI() {return Desc.URI;};
216 virtual string ShortDesc() {return Desc.ShortDesc;};
217 virtual void Finished();
218 virtual bool IsTrusted();
219
220 pkgAcqArchive(pkgAcquire *Owner,pkgSourceList *Sources,
221 pkgRecords *Recs,pkgCache::VerIterator const &Version,
222 string &StoreFilename);
223 };
224
225 // Fetch a generic file to the current directory
226 class pkgAcqFile : public pkgAcquire::Item
227 {
228 pkgAcquire::ItemDesc Desc;
229 string Md5Hash;
230 unsigned int Retries;
231
232 public:
233
234 // Specialized action members
235 virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf);
236 virtual void Done(string Message,unsigned long Size,string Md5Hash,
237 pkgAcquire::MethodConfig *Cnf);
238 virtual string MD5Sum() {return Md5Hash;};
239 virtual string DescURI() {return Desc.URI;};
240
241 // If DestFilename is empty, download to DestDir/<basename> if
242 // DestDir is non-empty, $CWD/<basename> otherwise. If
243 // DestFilename is NOT empty, DestDir is ignored and DestFilename
244 // is the absolute name to which the file should be downloaded.
245 pkgAcqFile(pkgAcquire *Owner, string URI, string MD5, unsigned long Size,
246 string Desc, string ShortDesc,
247 const string &DestDir="", const string &DestFilename="");
248 };
249
250 #endif